diff --git a/RainmeterStudio.Core/Model/Reference.cs b/RainmeterStudio.Core/Model/Reference.cs
index 30a4cd58..5d54d53a 100644
--- a/RainmeterStudio.Core/Model/Reference.cs
+++ b/RainmeterStudio.Core/Model/Reference.cs
@@ -201,6 +201,9 @@ namespace RainmeterStudio.Core.Model
}
}
+ ///
+ /// Gets the target kind
+ ///
[XmlAttribute("targetKind")]
public ReferenceTargetKind TargetKind
{
@@ -297,8 +300,8 @@ namespace RainmeterStudio.Core.Model
throw new ArgumentException("Reference must be removed from its current parent first.");
// Add and parent
- reference.Parent = this;
_children.Add(reference.Name, reference);
+ reference.Parent = this;
// Trigger event
if (CollectionChanged != null)
diff --git a/RainmeterStudio/Resources/Icons.resx b/RainmeterStudio/Resources/Icons.resx
index bc9ca10c..95040781 100644
--- a/RainmeterStudio/Resources/Icons.resx
+++ b/RainmeterStudio/Resources/Icons.resx
@@ -158,10 +158,10 @@
icons\16\folder.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
- icons\16\file_generic.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+ icons\16\page_white_delete.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
- icons\16\page_white_delete.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+ icons\16\file_generic.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
icons\16\project.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
diff --git a/RainmeterStudio/UI/Controller/DocumentController.cs b/RainmeterStudio/UI/Controller/DocumentController.cs
index d429b0f0..05bb5d28 100644
--- a/RainmeterStudio/UI/Controller/DocumentController.cs
+++ b/RainmeterStudio/UI/Controller/DocumentController.cs
@@ -168,7 +168,7 @@ namespace RainmeterStudio.UI.Controller
if (!Directory.Exists(folder))
folder = Path.GetDirectoryName(folder);
- var reference = new Reference(name, Path.Combine(folder, name));
+ var reference = new Reference(name, Path.Combine(folder, name), Reference.ReferenceTargetKind.File);
editor.AttachedDocument.Reference = reference;
// Save document
@@ -176,6 +176,7 @@ namespace RainmeterStudio.UI.Controller
// Add to parent
OwnerWindow.ProjectPanel.ActiveItem.Add(reference);
+ ProjectManager.SaveActiveProject();
}
///
diff --git a/RainmeterStudio/UI/MainWindow.xaml.cs b/RainmeterStudio/UI/MainWindow.xaml.cs
index 7c577af8..a6440d26 100644
--- a/RainmeterStudio/UI/MainWindow.xaml.cs
+++ b/RainmeterStudio/UI/MainWindow.xaml.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
@@ -48,6 +49,7 @@ namespace RainmeterStudio.UI
this.AddKeyBinding(DocumentController.DocumentSaveCommand);
this.AddKeyBinding(DocumentController.DocumentCloseCommand);
this.AddKeyBinding(ProjectController.ProjectCreateCommand);
+ this.AddKeyBinding(ProjectController.ProjectOpenCommand);
// Subscribe to events
DocumentController.DocumentOpened += documentController_DocumentOpened;
@@ -75,11 +77,51 @@ namespace RainmeterStudio.UI
documentPane.Children.Add(document);
documentPane.SelectedContentIndex = documentPane.IndexOf(document);
- e.Document.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler((obj, args) =>
+ e.Document.PropertyChanged += Document_PropertyChanged;
+ if (e.Document.Reference != null)
+ e.Document.Reference.PropertyChanged += Reference_PropertyChanged;
+ }
+
+ private void Document_PropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ IDocument document = (IDocument)sender;
+
+ // Find document object and update document title
+ foreach (var pair in _openedDocuments)
{
- // Update document title
- document.Title = GetDocumentTitle(e.Document);
- });
+ if (pair.Value.AttachedDocument == document)
+ {
+ pair.Key.Title = GetDocumentTitle(document);
+ }
+ }
+
+ // If the reference changed, subscribe to reference changes as well
+ if (e.PropertyName == "Reference" && document.Reference != null)
+ {
+ document.Reference.PropertyChanged += Reference_PropertyChanged;
+ }
+ }
+
+ void Reference_PropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ Reference reference = (Reference)sender;
+ bool found = false;
+
+ // Find documents with this reference and update document title
+ foreach (var pair in _openedDocuments)
+ {
+ if (pair.Value.AttachedDocument.Reference == reference)
+ {
+ pair.Key.Title = GetDocumentTitle(pair.Value.AttachedDocument);
+ found = true;
+ }
+ }
+
+ // No document found? Unsubscribe
+ if (found == false)
+ {
+ reference.PropertyChanged -= Reference_PropertyChanged;
+ }
}
private string GetDocumentTitle(IDocument document)
@@ -87,7 +129,11 @@ namespace RainmeterStudio.UI
string documentName;
// Get title
- if (ProjectController.ActiveProject == null || !ProjectController.ActiveProject.Contains(document.Reference))
+ if (document.Reference == null)
+ {
+ documentName = "New document";
+ }
+ else if (ProjectController.ActiveProject == null || !ProjectController.ActiveProject.Contains(document.Reference))
{
documentName = document.Reference.StoragePath ?? "New document";
}
diff --git a/RainmeterStudio/UI/Panels/ProjectPanel.xaml.cs b/RainmeterStudio/UI/Panels/ProjectPanel.xaml.cs
index d30265cb..311107e4 100644
--- a/RainmeterStudio/UI/Panels/ProjectPanel.xaml.cs
+++ b/RainmeterStudio/UI/Panels/ProjectPanel.xaml.cs
@@ -112,6 +112,10 @@ namespace RainmeterStudio.UI.Panels
private void Refresh()
{
+ // Clear current items
+ treeProjectItems.Items.Clear();
+
+ // No project
if (Controller == null || Controller.ActiveProject == null)
{
this.IsEnabled = false;
@@ -137,7 +141,6 @@ namespace RainmeterStudio.UI.Panels
}
// Add tree to tree view
- treeProjectItems.Items.Clear();
treeProjectItems.Items.Add(new ReferenceViewModel(refTree));
}
}