Can now add new items to project.

This commit is contained in:
Tiberiu Chibici 2014-08-16 15:40:08 +03:00
parent fb2929e02a
commit 7f525d0d86
10 changed files with 75 additions and 29 deletions

View File

@ -8,7 +8,7 @@ namespace RainmeterStudio.Core.Model
{ {
public interface IDocument : INotifyPropertyChanged public interface IDocument : INotifyPropertyChanged
{ {
Reference Reference { get; } Reference Reference { get; set; }
bool IsDirty { get; set; } bool IsDirty { get; set; }
} }
} }

View File

@ -26,7 +26,11 @@ namespace RainmeterStudio.TextEditorPlugin
InitializeComponent(); InitializeComponent();
_document = document; _document = document;
text.Text = document.Lines.Aggregate((a, b) => a + "\n" + b);
StringBuilder txt = new StringBuilder();
document.Lines.ForEach((line) => txt.AppendLine(line));
text.Text = txt.ToString();
} }
} }
} }

View File

@ -97,7 +97,7 @@
<Compile Include="UI\Dialogs\CreateProjectDialog.xaml.cs"> <Compile Include="UI\Dialogs\CreateProjectDialog.xaml.cs">
<DependentUpon>CreateProjectDialog.xaml</DependentUpon> <DependentUpon>CreateProjectDialog.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="UI\ProjectPanel.xaml.cs"> <Compile Include="UI\Panels\ProjectPanel.xaml.cs">
<DependentUpon>ProjectPanel.xaml</DependentUpon> <DependentUpon>ProjectPanel.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="UI\UIManager.cs" /> <Compile Include="UI\UIManager.cs" />
@ -124,7 +124,7 @@
<DependentUpon>MainWindow.xaml</DependentUpon> <DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Page Include="UI\ProjectPanel.xaml"> <Page Include="UI\Panels\ProjectPanel.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>

View File

@ -8,6 +8,7 @@ using RainmeterStudio.Core.Model.Events;
using RainmeterStudio.UI.Dialogs; using RainmeterStudio.UI.Dialogs;
using RainmeterStudio.UI.ViewModel; using RainmeterStudio.UI.ViewModel;
using RainmeterStudio.Core.Model; using RainmeterStudio.Core.Model;
using System.IO;
namespace RainmeterStudio.UI.Controller namespace RainmeterStudio.UI.Controller
{ {
@ -53,7 +54,7 @@ namespace RainmeterStudio.UI.Controller
remove { DocumentManager.DocumentClosed -= value; } remove { DocumentManager.DocumentClosed -= value; }
} }
public Window OwnerWindow { get; set; } public MainWindow OwnerWindow { get; set; }
public DocumentController(DocumentManager documentManager, ProjectManager projectManager) public DocumentController(DocumentManager documentManager, ProjectManager projectManager)
{ {
@ -75,10 +76,25 @@ namespace RainmeterStudio.UI.Controller
return; return;
var format = dialog.SelectedTemplate; var format = dialog.SelectedTemplate;
var path = dialog.SelectedName;
// Call manager // Call manager
DocumentManager.Create(format.Template); var editor = DocumentManager.Create(format.Template);
// Set the reference
var name = dialog.SelectedName;
string folder = OwnerWindow.ProjectPanel.ActiveItem.Data.Path;
if (!Directory.Exists(folder))
folder = Path.GetDirectoryName(folder);
var reference = new Reference(name, Path.Combine(folder, name));
editor.AttachedDocument.Reference = reference;
// Save document
DocumentManager.Save(editor.AttachedDocument);
// Add to parent
OwnerWindow.ProjectPanel.ActiveItem.Add(reference);
} }
public void Create(IDocumentTemplate format) public void Create(IDocumentTemplate format)

View File

@ -19,6 +19,7 @@ using RainmeterStudio.Core.Utils;
using RainmeterStudio.Properties; using RainmeterStudio.Properties;
using RainmeterStudio.Resources; using RainmeterStudio.Resources;
using RainmeterStudio.UI.Controller; using RainmeterStudio.UI.Controller;
using RainmeterStudio.UI.ViewModel;
namespace RainmeterStudio.UI.Dialogs namespace RainmeterStudio.UI.Dialogs
{ {
@ -36,7 +37,12 @@ namespace RainmeterStudio.UI.Dialogs
{ {
get get
{ {
return listTemplates.SelectedItem as IProjectTemplate; var item = listTemplates.SelectedItem as ProjectTemplateViewModel;
if (item != null)
return item.Template;
return null;
} }
set set
{ {

View File

@ -1,7 +1,7 @@
<Window x:Class="RainmeterStudio.UI.MainWindow" <Window x:Class="RainmeterStudio.UI.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="clr-namespace:RainmeterStudio.UI" xmlns:uiPanels="clr-namespace:RainmeterStudio.UI.Panels"
xmlns:ad="clr-namespace:Xceed.Wpf.AvalonDock;assembly=Xceed.Wpf.AvalonDock" xmlns:ad="clr-namespace:Xceed.Wpf.AvalonDock;assembly=Xceed.Wpf.AvalonDock"
xmlns:adlayout="clr-namespace:Xceed.Wpf.AvalonDock.Layout;assembly=Xceed.Wpf.AvalonDock" xmlns:adlayout="clr-namespace:Xceed.Wpf.AvalonDock.Layout;assembly=Xceed.Wpf.AvalonDock"
xmlns:r="clr-namespace:RainmeterStudio.Resources" xmlns:r="clr-namespace:RainmeterStudio.Resources"
@ -104,7 +104,7 @@
<adlayout:LayoutAnchorablePaneGroup DockWidth="250" Orientation="Vertical"> <adlayout:LayoutAnchorablePaneGroup DockWidth="250" Orientation="Vertical">
<adlayout:LayoutAnchorablePane> <adlayout:LayoutAnchorablePane>
<adlayout:LayoutAnchorable Title="Project"> <adlayout:LayoutAnchorable Title="Project">
<ui:ProjectPanel x:Name="projectPanel" /> <uiPanels:ProjectPanel x:Name="projectPanel" />
</adlayout:LayoutAnchorable> </adlayout:LayoutAnchorable>
<adlayout:LayoutAnchorable Title="Outline" /> <adlayout:LayoutAnchorable Title="Outline" />
</adlayout:LayoutAnchorablePane> </adlayout:LayoutAnchorablePane>

View File

@ -15,6 +15,7 @@ using RainmeterStudio.Business;
using RainmeterStudio.Core.Model.Events; using RainmeterStudio.Core.Model.Events;
using RainmeterStudio.Storage; using RainmeterStudio.Storage;
using RainmeterStudio.UI.Controller; using RainmeterStudio.UI.Controller;
using RainmeterStudio.UI.Panels;
using Xceed.Wpf.AvalonDock.Layout; using Xceed.Wpf.AvalonDock.Layout;
namespace RainmeterStudio.UI namespace RainmeterStudio.UI
@ -27,6 +28,8 @@ namespace RainmeterStudio.UI
public DocumentController DocumentController { get; set; } public DocumentController DocumentController { get; set; }
public ProjectController ProjectController { get; set; } public ProjectController ProjectController { get; set; }
public ProjectPanel ProjectPanel { get { return projectPanel; } }
public MainWindow(ProjectController projCtrl, DocumentController docCtrl) public MainWindow(ProjectController projCtrl, DocumentController docCtrl)
{ {
InitializeComponent(); InitializeComponent();
@ -52,7 +55,7 @@ namespace RainmeterStudio.UI
// Spawn a new window // Spawn a new window
LayoutDocument document = new LayoutDocument(); LayoutDocument document = new LayoutDocument();
document.Content = e.Editor.EditorUI; document.Content = e.Editor.EditorUI;
document.Title = e.Editor.AttachedDocument.Reference.Name; document.Title = (e.Editor.AttachedDocument.Reference == null) ? "New document" : e.Editor.AttachedDocument.Reference.Name;
document.Closing += document_Closing; document.Closing += document_Closing;
documentPane.Children.Add(document); documentPane.Children.Add(document);

View File

@ -1,4 +1,4 @@
<UserControl x:Class="RainmeterStudio.UI.ProjectPanel" <UserControl x:Class="RainmeterStudio.UI.Panels.ProjectPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@ -55,7 +55,7 @@
<TreeView.ItemTemplate> <TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}"> <HierarchicalDataTemplate ItemsSource="{Binding Children}">
<DockPanel LastChildFill="True"> <DockPanel LastChildFill="True">
<Image DockPanel.Dock="Left" Width="16" Height="16" Source="{Binding Data.Reference, Converter={StaticResource IconConverter}}" /> <Image DockPanel.Dock="Left" Width="16" Height="16" Source="{Binding Data.Reference.Data, Converter={StaticResource IconConverter}}" />
<TextBlock Text="{Binding Data.Name}" /> <TextBlock Text="{Binding Data.Name}" />
</DockPanel> </DockPanel>
</HierarchicalDataTemplate> </HierarchicalDataTemplate>

View File

@ -21,7 +21,7 @@ using RainmeterStudio.Storage;
using RainmeterStudio.UI.Controller; using RainmeterStudio.UI.Controller;
using RainmeterStudio.UI.ViewModel; using RainmeterStudio.UI.ViewModel;
namespace RainmeterStudio.UI namespace RainmeterStudio.UI.Panels
{ {
/// <summary> /// <summary>
/// Interaction logic for SkinsPanel.xaml /// Interaction logic for SkinsPanel.xaml
@ -37,7 +37,7 @@ namespace RainmeterStudio.UI
} }
set set
{ {
// Unsubscribe from old project // Unsubscribe from old controller
if (_controller != null) if (_controller != null)
{ {
Controller.ActiveProjectChanged -= Controller_ActiveProjectChanged; Controller.ActiveProjectChanged -= Controller_ActiveProjectChanged;
@ -64,6 +64,26 @@ namespace RainmeterStudio.UI
#endregion #endregion
/// <summary>
/// Gets the selected tree view item
/// </summary>
public Tree<Reference> ActiveItem
{
get
{
var selected = treeProjectItems.SelectedItem as Tree<ReferenceViewModel>;
if (selected == null)
{
return Controller.ActiveProject.Root;
}
else
{
return selected.Data.Reference;
}
}
}
private bool _canExpand = false; private bool _canExpand = false;
private bool CanExpand private bool CanExpand
{ {
@ -75,10 +95,7 @@ namespace RainmeterStudio.UI
{ {
_canExpand = value; _canExpand = value;
if (ExpandAllCommand != null)
ExpandAllCommand.NotifyCanExecuteChanged(); ExpandAllCommand.NotifyCanExecuteChanged();
if (CollapseAllCommand != null)
CollapseAllCommand.NotifyCanExecuteChanged(); CollapseAllCommand.NotifyCanExecuteChanged();
} }
} }
@ -149,7 +166,7 @@ namespace RainmeterStudio.UI
refTree.Remove(project); refTree.Remove(project);
// Transform to reference view model and return // Transform to reference view model and return
return refTree.TransformData<Reference, ReferenceViewModel>((data) => new ReferenceViewModel(data)); return refTree.Transform<Reference, ReferenceViewModel>((node) => new Tree<ReferenceViewModel>(new ReferenceViewModel(node)));
} }
private Tree<ReferenceViewModel> GetProjectItems() private Tree<ReferenceViewModel> GetProjectItems()
@ -158,7 +175,7 @@ namespace RainmeterStudio.UI
Tree<Reference> refTree = Controller.ActiveProject.Root; Tree<Reference> refTree = Controller.ActiveProject.Root;
// Transform to reference view model and return // Transform to reference view model and return
return refTree.TransformData<Reference, ReferenceViewModel>((data) => new ReferenceViewModel(data)); return refTree.Transform<Reference, ReferenceViewModel>((node) => new Tree<ReferenceViewModel>(new ReferenceViewModel(node)));
} }
private void ExpandAll() private void ExpandAll()

View File

@ -17,7 +17,7 @@ namespace RainmeterStudio.UI.ViewModel
/// <summary> /// <summary>
/// Gets the linked reference /// Gets the linked reference
/// </summary> /// </summary>
public Reference Reference { get; private set; } public Tree<Reference> Reference { get; private set; }
/// <summary> /// <summary>
/// Gets or sets the name /// Gets or sets the name
@ -26,11 +26,11 @@ namespace RainmeterStudio.UI.ViewModel
{ {
get get
{ {
return Reference.Name; return Reference.Data.Name;
} }
set set
{ {
Reference.Name = value; Reference.Data.Name = value;
if (PropertyChanged != null) if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Name")); PropertyChanged(this, new PropertyChangedEventArgs("Name"));
@ -44,11 +44,11 @@ namespace RainmeterStudio.UI.ViewModel
{ {
get get
{ {
return Reference.Path; return Reference.Data.Path;
} }
set set
{ {
Reference.Path = value; Reference.Data.Path = value;
if (PropertyChanged != null) if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Path")); PropertyChanged(this, new PropertyChangedEventArgs("Path"));
@ -115,7 +115,7 @@ namespace RainmeterStudio.UI.ViewModel
/// Creates a new instance of reference view model /// Creates a new instance of reference view model
/// </summary> /// </summary>
/// <param name="reference">Reference</param> /// <param name="reference">Reference</param>
public ReferenceViewModel(Reference reference) public ReferenceViewModel(Tree<Reference> reference)
{ {
Reference = reference; Reference = reference;
} }