diff --git a/RainmeterStudio.Core/Model/IDocument.cs b/RainmeterStudio.Core/Model/IDocument.cs
index b0df2577..c42598be 100644
--- a/RainmeterStudio.Core/Model/IDocument.cs
+++ b/RainmeterStudio.Core/Model/IDocument.cs
@@ -8,7 +8,7 @@ namespace RainmeterStudio.Core.Model
{
public interface IDocument : INotifyPropertyChanged
{
- Reference Reference { get; }
+ Reference Reference { get; set; }
bool IsDirty { get; set; }
}
}
diff --git a/RainmeterStudio.TextEditor/TextEditorControl.xaml.cs b/RainmeterStudio.TextEditor/TextEditorControl.xaml.cs
index 237b74d8..a64e00ff 100644
--- a/RainmeterStudio.TextEditor/TextEditorControl.xaml.cs
+++ b/RainmeterStudio.TextEditor/TextEditorControl.xaml.cs
@@ -26,7 +26,11 @@ namespace RainmeterStudio.TextEditorPlugin
InitializeComponent();
_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();
}
}
}
diff --git a/RainmeterStudio/RainmeterStudio.csproj b/RainmeterStudio/RainmeterStudio.csproj
index 7f8faf8a..18be2ea4 100644
--- a/RainmeterStudio/RainmeterStudio.csproj
+++ b/RainmeterStudio/RainmeterStudio.csproj
@@ -97,7 +97,7 @@
CreateProjectDialog.xaml
-
+
ProjectPanel.xaml
@@ -124,7 +124,7 @@
MainWindow.xaml
Code
-
+
Designer
MSBuild:Compile
diff --git a/RainmeterStudio/UI/Controller/DocumentController.cs b/RainmeterStudio/UI/Controller/DocumentController.cs
index f5fb811a..56409bee 100644
--- a/RainmeterStudio/UI/Controller/DocumentController.cs
+++ b/RainmeterStudio/UI/Controller/DocumentController.cs
@@ -8,6 +8,7 @@ using RainmeterStudio.Core.Model.Events;
using RainmeterStudio.UI.Dialogs;
using RainmeterStudio.UI.ViewModel;
using RainmeterStudio.Core.Model;
+using System.IO;
namespace RainmeterStudio.UI.Controller
{
@@ -53,7 +54,7 @@ namespace RainmeterStudio.UI.Controller
remove { DocumentManager.DocumentClosed -= value; }
}
- public Window OwnerWindow { get; set; }
+ public MainWindow OwnerWindow { get; set; }
public DocumentController(DocumentManager documentManager, ProjectManager projectManager)
{
@@ -75,10 +76,25 @@ namespace RainmeterStudio.UI.Controller
return;
var format = dialog.SelectedTemplate;
- var path = dialog.SelectedName;
-
+
// 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)
diff --git a/RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml.cs b/RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml.cs
index 88cf948b..9d9cc748 100644
--- a/RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml.cs
+++ b/RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml.cs
@@ -19,6 +19,7 @@ using RainmeterStudio.Core.Utils;
using RainmeterStudio.Properties;
using RainmeterStudio.Resources;
using RainmeterStudio.UI.Controller;
+using RainmeterStudio.UI.ViewModel;
namespace RainmeterStudio.UI.Dialogs
{
@@ -36,7 +37,12 @@ namespace RainmeterStudio.UI.Dialogs
{
get
{
- return listTemplates.SelectedItem as IProjectTemplate;
+ var item = listTemplates.SelectedItem as ProjectTemplateViewModel;
+
+ if (item != null)
+ return item.Template;
+
+ return null;
}
set
{
diff --git a/RainmeterStudio/UI/MainWindow.xaml b/RainmeterStudio/UI/MainWindow.xaml
index eca4c8e7..b79f5156 100644
--- a/RainmeterStudio/UI/MainWindow.xaml
+++ b/RainmeterStudio/UI/MainWindow.xaml
@@ -1,7 +1,7 @@
-
+
diff --git a/RainmeterStudio/UI/MainWindow.xaml.cs b/RainmeterStudio/UI/MainWindow.xaml.cs
index 2f1171f3..c21c794e 100644
--- a/RainmeterStudio/UI/MainWindow.xaml.cs
+++ b/RainmeterStudio/UI/MainWindow.xaml.cs
@@ -15,6 +15,7 @@ using RainmeterStudio.Business;
using RainmeterStudio.Core.Model.Events;
using RainmeterStudio.Storage;
using RainmeterStudio.UI.Controller;
+using RainmeterStudio.UI.Panels;
using Xceed.Wpf.AvalonDock.Layout;
namespace RainmeterStudio.UI
@@ -27,6 +28,8 @@ namespace RainmeterStudio.UI
public DocumentController DocumentController { get; set; }
public ProjectController ProjectController { get; set; }
+ public ProjectPanel ProjectPanel { get { return projectPanel; } }
+
public MainWindow(ProjectController projCtrl, DocumentController docCtrl)
{
InitializeComponent();
@@ -52,7 +55,7 @@ namespace RainmeterStudio.UI
// Spawn a new window
LayoutDocument document = new LayoutDocument();
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;
documentPane.Children.Add(document);
diff --git a/RainmeterStudio/UI/ProjectPanel.xaml b/RainmeterStudio/UI/Panels/ProjectPanel.xaml
similarity index 93%
rename from RainmeterStudio/UI/ProjectPanel.xaml
rename to RainmeterStudio/UI/Panels/ProjectPanel.xaml
index 310ea463..c5990a20 100644
--- a/RainmeterStudio/UI/ProjectPanel.xaml
+++ b/RainmeterStudio/UI/Panels/ProjectPanel.xaml
@@ -1,4 +1,4 @@
-
-
+
diff --git a/RainmeterStudio/UI/ProjectPanel.xaml.cs b/RainmeterStudio/UI/Panels/ProjectPanel.xaml.cs
similarity index 82%
rename from RainmeterStudio/UI/ProjectPanel.xaml.cs
rename to RainmeterStudio/UI/Panels/ProjectPanel.xaml.cs
index 459de0b8..c292158f 100644
--- a/RainmeterStudio/UI/ProjectPanel.xaml.cs
+++ b/RainmeterStudio/UI/Panels/ProjectPanel.xaml.cs
@@ -21,7 +21,7 @@ using RainmeterStudio.Storage;
using RainmeterStudio.UI.Controller;
using RainmeterStudio.UI.ViewModel;
-namespace RainmeterStudio.UI
+namespace RainmeterStudio.UI.Panels
{
///
/// Interaction logic for SkinsPanel.xaml
@@ -37,7 +37,7 @@ namespace RainmeterStudio.UI
}
set
{
- // Unsubscribe from old project
+ // Unsubscribe from old controller
if (_controller != null)
{
Controller.ActiveProjectChanged -= Controller_ActiveProjectChanged;
@@ -64,6 +64,26 @@ namespace RainmeterStudio.UI
#endregion
+ ///
+ /// Gets the selected tree view item
+ ///
+ public Tree ActiveItem
+ {
+ get
+ {
+ var selected = treeProjectItems.SelectedItem as Tree;
+
+ if (selected == null)
+ {
+ return Controller.ActiveProject.Root;
+ }
+ else
+ {
+ return selected.Data.Reference;
+ }
+ }
+ }
+
private bool _canExpand = false;
private bool CanExpand
{
@@ -75,11 +95,8 @@ namespace RainmeterStudio.UI
{
_canExpand = value;
- if (ExpandAllCommand != null)
- ExpandAllCommand.NotifyCanExecuteChanged();
-
- if (CollapseAllCommand != null)
- CollapseAllCommand.NotifyCanExecuteChanged();
+ ExpandAllCommand.NotifyCanExecuteChanged();
+ CollapseAllCommand.NotifyCanExecuteChanged();
}
}
@@ -149,7 +166,7 @@ namespace RainmeterStudio.UI
refTree.Remove(project);
// Transform to reference view model and return
- return refTree.TransformData((data) => new ReferenceViewModel(data));
+ return refTree.Transform((node) => new Tree(new ReferenceViewModel(node)));
}
private Tree GetProjectItems()
@@ -158,7 +175,7 @@ namespace RainmeterStudio.UI
Tree refTree = Controller.ActiveProject.Root;
// Transform to reference view model and return
- return refTree.TransformData((data) => new ReferenceViewModel(data));
+ return refTree.Transform((node) => new Tree(new ReferenceViewModel(node)));
}
private void ExpandAll()
diff --git a/RainmeterStudio/UI/ViewModel/ReferenceViewModel.cs b/RainmeterStudio/UI/ViewModel/ReferenceViewModel.cs
index 0bdc44a3..3ef23576 100644
--- a/RainmeterStudio/UI/ViewModel/ReferenceViewModel.cs
+++ b/RainmeterStudio/UI/ViewModel/ReferenceViewModel.cs
@@ -17,7 +17,7 @@ namespace RainmeterStudio.UI.ViewModel
///
/// Gets the linked reference
///
- public Reference Reference { get; private set; }
+ public Tree Reference { get; private set; }
///
/// Gets or sets the name
@@ -26,11 +26,11 @@ namespace RainmeterStudio.UI.ViewModel
{
get
{
- return Reference.Name;
+ return Reference.Data.Name;
}
set
{
- Reference.Name = value;
+ Reference.Data.Name = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Name"));
@@ -44,11 +44,11 @@ namespace RainmeterStudio.UI.ViewModel
{
get
{
- return Reference.Path;
+ return Reference.Data.Path;
}
set
{
- Reference.Path = value;
+ Reference.Data.Path = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Path"));
@@ -115,7 +115,7 @@ namespace RainmeterStudio.UI.ViewModel
/// Creates a new instance of reference view model
///
/// Reference
- public ReferenceViewModel(Reference reference)
+ public ReferenceViewModel(Tree reference)
{
Reference = reference;
}