Fixed project item icons, and new document bug

This commit is contained in:
Tiberiu Chibici 2014-09-12 19:20:21 +03:00
parent 0090059531
commit 22baf7f6a5
5 changed files with 63 additions and 10 deletions

View File

@ -201,6 +201,9 @@ namespace RainmeterStudio.Core.Model
}
}
/// <summary>
/// Gets the target kind
/// </summary>
[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)

View File

@ -158,10 +158,10 @@
<value>icons\16\folder.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ProjectItemNone" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>icons\16\file_generic.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<value>icons\16\page_white_delete.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ProjectItemUnknown" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>icons\16\page_white_delete.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<value>icons\16\file_generic.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ProjectItem_rsproj" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>icons\16\project.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>

View File

@ -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();
}
/// <summary>

View File

@ -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";
}

View File

@ -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));
}
}