diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj b/src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj
index 4f4746dc44..3c6e01d491 100644
--- a/src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj
+++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj
@@ -63,37 +63,9 @@
+
-
- Component
-
-
- UserControl
-
-
- Component
-
-
- Component
-
-
- Component
-
-
- Component
-
-
-
- UserControl
-
-
-
- Component
-
-
- Component
-
@@ -108,6 +80,10 @@
ImageViewBase.xaml
Code
+
+ InPlaceEditLabel.xaml
+ Code
+
@@ -166,6 +142,7 @@
+
diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs
index 28b3a62ac5..3473396345 100644
--- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs
+++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs
@@ -28,56 +28,50 @@ using ResourceEditor.ViewModels;
namespace ResourceEditor.Commands
{
- class AddNewFileCommand : SimpleCommand
+ class AddNewFileCommand : ResourceItemCommand
{
- public override void Execute(object parameter)
+ public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable resourceItems)
{
- ResourceEditorViewModel editor = ((ResourceEditViewContent) SD.Workbench.ActiveViewContent).ResourceEditor;
-
- // TODO Reactivate this
// if (editor.ResourceList.WriteProtected) {
// return;
// }
-// using (OpenFileDialog fdiag = new OpenFileDialog()) {
-// fdiag.AddExtension = true;
-// fdiag.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.AllFiles}|*.*");
-// fdiag.Multiselect = true;
-// fdiag.CheckFileExists = true;
-//
-// if (fdiag.ShowDialog()) {
-// foreach (string filename in fdiag.FileNames) {
-// string oresname = Path.ChangeExtension(Path.GetFileName(filename), null);
-// if (oresname == "")
-// oresname = "new";
-//
-// string resname = oresname;
-//
-// int i = 0;
-// TestName:
-// if (editor.ResourceList.Resources.ContainsKey(resname)) {
-// if (i == 10) {
-// continue;
-// }
-// i++;
-// resname = oresname + "_" + i.ToString();
-// goto TestName;
-// }
-//
-// object tmp = loadResource(filename);
-// if (tmp == null) {
-// continue;
-// }
-// editor.ResourceList.Resources.Add(resname, new ResourceItem(resname, tmp));
-//
-// }
-// editor.ResourceList.InitializeListView();
-// }
-// }
-// editor.ResourceList.OnChanged();
+ var editor = ResourceEditor;
+ OpenFileDialog fdiag = new OpenFileDialog();
+ fdiag.AddExtension = true;
+ fdiag.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.AllFiles}|*.*");
+ fdiag.Multiselect = true;
+ fdiag.CheckFileExists = true;
+
+ if ((bool)fdiag.ShowDialog()) {
+ foreach (string filename in fdiag.FileNames) {
+ string oresname = Path.ChangeExtension(Path.GetFileName(filename), null);
+ if (oresname == "")
+ oresname = "new";
+
+ string resname = oresname;
+
+ int i = 0;
+ TestName:
+ if (editor.ContainsResourceName(resname)) {
+ if (i == 10) {
+ continue;
+ }
+ i++;
+ resname = oresname + "_" + i;
+ goto TestName;
+ }
+
+ object tmp = LoadResource(filename);
+ if (tmp == null) {
+ continue;
+ }
+ editor.ResourceItems.Add(new ResourceItem(editor, resname, tmp));
+ }
+ }
}
- object loadResource(string name)
+ object LoadResource(string name)
{
switch (Path.GetExtension(name).ToUpperInvariant()) {
case ".CUR":
@@ -93,13 +87,13 @@ namespace ResourceEditor.Commands
return null;
}
default:
- // try to read a bitmap
+ // Try to read a bitmap
try {
return new System.Drawing.Bitmap(name);
} catch {
}
- // try to read a serialized object
+ // Try to read a serialized object
try {
Stream r = File.Open(name, FileMode.Open);
try {
@@ -113,17 +107,15 @@ namespace ResourceEditor.Commands
} catch {
}
- // try to read a byte array :)
+ // Try to read a byte array
try {
FileStream s = new FileStream(name, FileMode.Open);
BinaryReader r = new BinaryReader(s);
- Byte[] d = new Byte[(int) s.Length];
- d = r.ReadBytes((int) s.Length);
+ Byte[] d = new Byte[(int)s.Length];
+ d = r.ReadBytes((int)s.Length);
s.Close();
return d;
} catch (Exception) {
-
-
string message = ResourceService.GetString("ResourceEditor.Messages.CantLoadResource");
MessageService.ShowWarning(message + " " + name + ".");
}
diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs
index 199ac36c9e..bde41d841a 100644
--- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs
+++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs
@@ -24,33 +24,29 @@ using ResourceEditor.ViewModels;
namespace ResourceEditor.Commands
{
- class AddStringCommand : SimpleCommand
+ class AddStringCommand : ResourceItemCommand
{
- public override void Execute(object parameter)
+ public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable resourceItems)
{
- ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor;
-
- // TODO Reactivate this
// if(editor.ResourceList.WriteProtected) {
// return;
// }
//
-// int count = 1;
-// string newNameBase = " new string entry ";
-// string newName = newNameBase + count.ToString();
-// string type = "System.String";
-//
-// while(editor.ResourceList.Resources.ContainsKey(newName)) {
-// count++;
-// newName = newNameBase + count.ToString();
-// }
-//
-// ResourceItem item = new ResourceItem(newName, "");
-// editor.ResourceList.Resources.Add(newName, item);
-// ListViewItem lv = new ListViewItem(new string[] { newName, type, "" }, item.ImageIndex);
-// editor.ResourceList.Items.Add(lv);
-// editor.ResourceList.OnChanged();
-// lv.BeginEdit();
+ var editor = ResourceEditor;
+ int count = 1;
+ string newNameBase = " new string entry ";
+ string newName = newNameBase + count;
+
+ while (editor.ContainsResourceName(newName)) {
+ count++;
+ newName = newNameBase + count;
+ }
+
+ ResourceItem item = new ResourceItem(editor, newName, "");
+ editor.ResourceItems.Add(item);
+ editor.SelectedItems.Clear();
+ editor.SelectedItems.Add(item);
+ editor.StartEditing();
}
}
}
diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs
index 7073ea16bc..4adb6e4b4e 100644
--- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs
+++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs
@@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
+using System.Linq;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
@@ -25,16 +26,14 @@ using ResourceEditor.ViewModels;
namespace ResourceEditor.Commands
{
- class CopyResourceNameCommand : SimpleCommand
+ class CopyResourceNameCommand : ResourceItemCommand
{
- public override void Execute(object parameter)
+ public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable resourceItems)
{
- ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor;
-
- // TODO Reactivate this
-// if(editor.ResourceList.SelectedItems.Count > 0) {
-// Clipboard.SetText(editor.ResourceList.SelectedItems[0].Text);
-// }
+ var firstSelectedItem = resourceItems.First();
+ if (firstSelectedItem != null) {
+ Clipboard.SetText(firstSelectedItem.Name);
+ }
}
}
}
diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs
index 36c0254e3a..10b3d72c0b 100644
--- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs
+++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs
@@ -24,20 +24,16 @@ using ResourceEditor.ViewModels;
namespace ResourceEditor.Commands
{
- class EditCommentCommand : SimpleCommand
+ class EditCommentCommand : ResourceItemCommand
{
- public override void Execute(object parameter)
+ public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable resourceItems)
{
- ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor;
-
- if (editor.SelectedItems.Count != 0) {
- var selectedItem = editor.SelectedItems.OfType().FirstOrDefault();
- string newValue = SD.MessageService.ShowInputBox("${res:ResourceEditor.ResourceEdit.ContextMenu.EditComment}",
- "${res:ResourceEditor.ResourceEdit.ContextMenu.EditCommentText}",
- selectedItem.Comment);
- if (newValue != null && newValue != selectedItem.Comment) {
- selectedItem.Comment = newValue;
- }
+ var selectedItem = resourceItems.First();
+ string newValue = SD.MessageService.ShowInputBox("${res:ResourceEditor.ResourceEdit.ContextMenu.EditComment}",
+ "${res:ResourceEditor.ResourceEdit.ContextMenu.EditCommentText}",
+ selectedItem.Comment);
+ if (newValue != null && newValue != selectedItem.Comment) {
+ selectedItem.Comment = newValue;
}
}
}
diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs
index 21f20b630a..f64c1bde83 100644
--- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs
+++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs
@@ -23,12 +23,13 @@ using ResourceEditor.ViewModels;
namespace ResourceEditor.Commands
{
- class RenameEntryCommand : SimpleCommand
+ class RenameEntryCommand : ResourceItemCommand
{
- public override void Execute(object parameter)
+ public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable resourceItems)
{
- ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor;
- editor.StartEditing();
+ var editor = ResourceEditor;
+ if (editor != null)
+ editor.StartEditing();
}
}
}
diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/ResourceItemCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/ResourceItemCommand.cs
new file mode 100644
index 0000000000..ba1a0aa692
--- /dev/null
+++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/ResourceItemCommand.cs
@@ -0,0 +1,107 @@
+// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this
+// software and associated documentation files (the "Software"), to deal in the Software
+// without restriction, including without limitation the rights to use, copy, modify, merge,
+// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
+// to whom the Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all copies or
+// substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using ICSharpCode.SharpDevelop;
+using ResourceEditor.ViewModels;
+
+namespace ResourceEditor.Commands
+{
+ ///
+ /// Represents a -related command.
+ ///
+ public class ResourceItemCommand : SimpleCommand
+ {
+ ///
+ /// Defines whether this command supports multiselection of items.
+ /// If not, command will be disabled by default, when more than 1 item is selected.
+ ///
+ public virtual bool SupportsMultiSelections {
+ get {
+ return false;
+ }
+ }
+
+ ///
+ /// Returns list of resource item types for which this command may be enabled or null to allow any type.
+ ///
+ public virtual IEnumerable AllowedTypes {
+ get {
+ return null;
+ }
+ }
+
+ public override bool CanExecute(object parameter)
+ {
+ if (ResourceEditor == null)
+ return false;
+
+ var selectedResourceItems = GetSelectedItems();
+ if (!selectedResourceItems.Any())
+ return false;
+ if (!SupportsMultiSelections && (selectedResourceItems.Count() > 1))
+ return false;
+
+ return CanExecuteWithResourceItems(selectedResourceItems);
+ }
+
+ ///
+ /// Checks whether this command can be executed for the current set of selected resource items.
+ ///
+ /// List of selected resource items. Will always contain at least one element.
+ /// True, when command can be executed, false otherwise.
+ public virtual bool CanExecuteWithResourceItems(IEnumerable resourceItems)
+ {
+ return true;
+ }
+
+ public override void Execute(object parameter)
+ {
+ var selectedResourceItems = GetSelectedItems();
+ if (!selectedResourceItems.Any())
+ return;
+ if (!SupportsMultiSelections && (selectedResourceItems.Count() > 1))
+ return;
+ ExecuteWithResourceItems(selectedResourceItems);
+ }
+
+ ///
+ /// Executes command for the given set of selected resource items.
+ ///
+ /// List of selected resource items. Will always contain at least one element.
+ public virtual void ExecuteWithResourceItems(IEnumerable resourceItems)
+ {
+ }
+
+ public ResourceEditorViewModel ResourceEditor {
+ get {
+ return ((ResourceEditViewContent) SD.Workbench.ActiveViewContent).ResourceEditor;
+ }
+ }
+
+ IEnumerable GetSelectedItems()
+ {
+ var editor = ResourceEditor;
+ if (editor != null)
+ return editor.SelectedItems.OfType() ?? new ResourceEditor.ViewModels.ResourceItem[0];
+ return new ResourceEditor.ViewModels.ResourceItem[0];
+ }
+ }
+}
diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs
index f9f10807be..b41b673ddb 100644
--- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs
+++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs
@@ -20,6 +20,7 @@ using System;
using System.Drawing;
using System.IO;
+using System.Linq;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
@@ -28,20 +29,22 @@ using ResourceEditor.ViewModels;
namespace ResourceEditor.Commands
{
- class SaveEntryAsCommand : SimpleCommand
+ class SaveEntryAsCommand : ResourceItemCommand
{
- public override void Execute(object parameter)
- {
- ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor;
-
- if (editor.SelectedItems.Count != 1) {
- return;
- }
-
- ResourceItem firstSelectedItem = (editor.SelectedItems[0] as ResourceItem);
- if (firstSelectedItem == null) {
- return;
+ public override System.Collections.Generic.IEnumerable AllowedTypes {
+ get {
+ return new ResourceItemEditorType[] {
+ ResourceItemEditorType.Bitmap,
+ ResourceItemEditorType.Icon,
+ ResourceItemEditorType.Cursor,
+ ResourceItemEditorType.Binary
+ };
}
+ }
+
+ public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable resourceItems)
+ {
+ var firstSelectedItem = resourceItems.First();
var sdialog = new Microsoft.Win32.SaveFileDialog();
sdialog.AddExtension = true;
@@ -64,22 +67,22 @@ namespace ResourceEditor.Commands
}
bool? dr = sdialog.ShowDialog();
- if (dr.HasValue && dr.Value) {
+ if (!dr.HasValue || !dr.Value) {
return;
}
try {
if (firstSelectedItem.ResourceValue is Icon) {
FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create);
- ((Icon)firstSelectedItem.ResourceValue).Save(fstr);
+ ((Icon) firstSelectedItem.ResourceValue).Save(fstr);
fstr.Close();
} else if (firstSelectedItem.ResourceValue is Image) {
- Image img = (Image)firstSelectedItem.ResourceValue;
+ Image img = (Image) firstSelectedItem.ResourceValue;
img.Save(sdialog.FileName);
} else {
FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create);
BinaryWriter wr = new BinaryWriter(fstr);
- wr.Write((byte[])firstSelectedItem.ResourceValue);
+ wr.Write((byte[]) firstSelectedItem.ResourceValue);
fstr.Close();
}
} catch (Exception ex) {
diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs
index 6563e7ffbc..58869076fc 100644
--- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs
+++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs
@@ -72,7 +72,7 @@ namespace ResourceEditor.ViewModels
new FrameworkPropertyMetadata());
public string SearchTerm {
- get { return (string)GetValue(SearchTermProperty); }
+ get { return (string) GetValue(SearchTermProperty); }
set { SetValue(SearchTermProperty, value); }
}
@@ -100,6 +100,16 @@ namespace ResourceEditor.ViewModels
}
}
+ ///
+ /// Checks whether a resource name is existing in currently open file.
+ ///
+ /// Resource name to check.
+ /// True if name exists, false otherwise.
+ public bool ContainsResourceName(string name)
+ {
+ return resourceItemNames.Contains(name);
+ }
+
public void AddItemView(ResourceItemEditorType itemType, IResourceItemView view)
{
itemViews[itemType] = view;
@@ -112,6 +122,7 @@ namespace ResourceEditor.ViewModels
set {
if (view != null) {
view.SelectionChanged -= View_SelectionChanged;
+ view.EditingStarted -= View_EditingStarted;
view.EditingFinished -= View_EditingFinished;
view.EditingCancelled -= View_EditingCancelled;
ResourceItems.CollectionChanged -= ResourceItems_CollectionChanged;
@@ -133,6 +144,7 @@ namespace ResourceEditor.ViewModels
return true;
};
view.SelectionChanged += View_SelectionChanged;
+ view.EditingStarted += View_EditingStarted;
view.EditingFinished += View_EditingFinished;
view.EditingCancelled += View_EditingCancelled;
ResourceItems.CollectionChanged += ResourceItems_CollectionChanged;
@@ -198,11 +210,11 @@ namespace ResourceEditor.ViewModels
public void StartEditing()
{
- if (editedResourceItem != null) {
- editedResourceItem.IsEditing = false;
- editedResourceItem = null;
- originalNameOfEditedItem = null;
- }
+// if (editedResourceItem != null) {
+// editedResourceItem.IsEditing = false;
+// editedResourceItem = null;
+// originalNameOfEditedItem = null;
+// }
// Start editing currently selected item
var firstSelectedItem = SelectedItems.OfType().FirstOrDefault();
@@ -213,24 +225,29 @@ namespace ResourceEditor.ViewModels
}
}
+ void View_EditingStarted(object sender, EventArgs e)
+ {
+ StartEditing();
+ }
+
void View_EditingFinished(object sender, EventArgs e)
{
- if (editedResourceItem != null) {
- editedResourceItem.IsEditing = false;
- editedResourceItem = null;
- originalNameOfEditedItem = null;
- MakeDirty();
- }
+// if (editedResourceItem != null) {
+// editedResourceItem.IsEditing = false;
+// editedResourceItem = null;
+// originalNameOfEditedItem = null;
+// MakeDirty();
+// }
}
void View_EditingCancelled(object sender, EventArgs e)
{
- if (editedResourceItem != null) {
- editedResourceItem.IsEditing = false;
- editedResourceItem.Name = originalNameOfEditedItem;
- editedResourceItem = null;
- originalNameOfEditedItem = null;
- }
+// if (editedResourceItem != null) {
+// editedResourceItem.IsEditing = false;
+// editedResourceItem.Name = originalNameOfEditedItem;
+// editedResourceItem = null;
+// originalNameOfEditedItem = null;
+// }
}
void StartUpdate()
@@ -258,13 +275,13 @@ namespace ResourceEditor.ViewModels
rx.UseResXDataNodes = true;
IDictionaryEnumerator n = rx.GetEnumerator();
while (n.MoveNext()) {
- ResXDataNode node = (ResXDataNode)n.Value;
+ ResXDataNode node = (ResXDataNode) n.Value;
resourceItems.Add(new ResourceItem(this, node.Name, node.GetValue(typeResolver), node.Comment));
}
n = rx.GetMetadataEnumerator();
while (n.MoveNext()) {
- ResXDataNode node = (ResXDataNode)n.Value;
+ ResXDataNode node = (ResXDataNode) n.Value;
metadataItems.Add(new ResourceItem(this, node.Name, node.GetValue(typeResolver)));
}
@@ -390,12 +407,12 @@ namespace ResourceEditor.ViewModels
return;
if (dob.GetDataPresent(typeof(Hashtable).FullName)) {
- Hashtable tmphash = (Hashtable)dob.GetData(typeof(Hashtable));
+ Hashtable tmphash = (Hashtable) dob.GetData(typeof(Hashtable));
foreach (DictionaryEntry entry in tmphash) {
object resourceValue = GetClonedResource(entry.Value);
ResourceItem item;
- if (!resourceItemNames.Contains((string)entry.Key)) {
+ if (!resourceItemNames.Contains((string) entry.Key)) {
item = new ResourceItem(this, entry.Key.ToString(), resourceValue);
} else {
int count = 1;
diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs
index c3b65a3922..a5e3ada11b 100644
--- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs
+++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs
@@ -20,6 +20,7 @@ using System;
using System.ComponentModel;
using System.Drawing;
using System.Resources;
+using System.Windows;
using System.Windows.Forms;
using ICSharpCode.SharpDevelop;
@@ -39,66 +40,45 @@ namespace ResourceEditor.ViewModels
Binary
}
- public class ResourceItem : INotifyPropertyChanged
+ public class ResourceItem : DependencyObject
{
- string name;
- object resourceValue;
- string comment;
ResourceItemEditorType resourceType;
ResourceEditorViewModel resourceEditor;
- bool isEditing;
+ string nameBeforeEditing;
public ResourceItem(ResourceEditorViewModel resourceEditor, string name, object resourceValue)
{
this.resourceEditor = resourceEditor;
- this.name = name;
- this.resourceValue = resourceValue;
+ this.Name = name;
+ this.ResourceValue = resourceValue;
this.resourceType = GetResourceTypeFromValue(resourceValue);
}
public ResourceItem(ResourceEditorViewModel resourceEditor, string name, object resourceValue, string comment)
{
this.resourceEditor = resourceEditor;
- this.name = name;
- this.resourceValue = resourceValue;
+ this.Name = name;
+ this.ResourceValue = resourceValue;
this.resourceType = GetResourceTypeFromValue(resourceValue);
- this.comment = comment;
+ this.Comment = comment;
}
- #region INotifyPropertyChanged implementation
-
- public event PropertyChangedEventHandler PropertyChanged;
-
- void OnPropertyChanged(string propertyName)
- {
- if (PropertyChanged != null) {
- PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
- }
- }
-
- #endregion
+ public static readonly DependencyProperty NameProperty =
+ DependencyProperty.Register("Name", typeof(string), typeof(ResourceItem),
+ new FrameworkPropertyMetadata());
public string Name {
- get {
- return name;
- }
- set {
- name = value;
- OnPropertyChanged("Name");
- }
+ get { return (string)GetValue(NameProperty); }
+ set { SetValue(NameProperty, value); }
}
+ public static readonly DependencyProperty ResourceValueProperty =
+ DependencyProperty.Register("ResourceValue", typeof(object), typeof(ResourceItem),
+ new FrameworkPropertyMetadata());
+
public object ResourceValue {
- get {
- return resourceValue;
- }
- set {
- resourceValue = value;
- OnPropertyChanged("ResourceValue");
- OnPropertyChanged("ResourceType");
- OnPropertyChanged("Content");
- resourceEditor.MakeDirty();
- }
+ get { return (object)GetValue(ResourceValueProperty); }
+ set { SetValue(ResourceValueProperty, value); }
}
public string DisplayedResourceType {
@@ -113,13 +93,39 @@ namespace ResourceEditor.ViewModels
}
}
+ public static readonly DependencyProperty IsEditingProperty =
+ DependencyProperty.Register("IsEditing", typeof(bool), typeof(ResourceItem),
+ new FrameworkPropertyMetadata());
+
public bool IsEditing {
- get {
- return isEditing;
- }
- set {
- isEditing = value;
- OnPropertyChanged("IsEditing");
+ get { return (bool)GetValue(IsEditingProperty); }
+ set { SetValue(IsEditingProperty, value); }
+ }
+
+ protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
+ {
+ base.OnPropertyChanged(e);
+
+ if (e.Property == IsEditingProperty) {
+ bool previouslyEditing = (bool)e.OldValue;
+ bool isEditing = (bool)e.NewValue;
+ if (!previouslyEditing && isEditing) {
+ // Save initial name to compare it later on cancellation
+ nameBeforeEditing = Name;
+ } else if (previouslyEditing && !isEditing) {
+ // Make dirty, if name has changed after finishing edit
+ if (nameBeforeEditing != Name) {
+ // Check if new name is valid
+ if (!String.IsNullOrEmpty(Name) && !resourceEditor.ContainsResourceName(Name)) {
+ resourceEditor.MakeDirty();
+ } else {
+ // New name was not valid, revert it to the value before editing
+ Name = nameBeforeEditing;
+ }
+ }
+ }
+ } else {
+ resourceEditor.MakeDirty();
}
}
@@ -152,15 +158,13 @@ namespace ResourceEditor.ViewModels
}
}
+ public static readonly DependencyProperty CommentProperty =
+ DependencyProperty.Register("Comment", typeof(string), typeof(ResourceItem),
+ new FrameworkPropertyMetadata());
+
public string Comment {
- get {
- return comment;
- }
- set {
- comment = value;
- OnPropertyChanged("Comment");
- resourceEditor.MakeDirty();
- }
+ get { return (string)GetValue(CommentProperty); }
+ set { SetValue(CommentProperty, value); }
}
public override string ToString()
diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml
index 8e7e41dd9d..782a0202e3 100644
--- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml
+++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml
@@ -8,6 +8,12 @@
-
+
+
+
\ No newline at end of file
diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml
new file mode 100644
index 0000000000..4bf5a835fe
--- /dev/null
+++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml.cs
new file mode 100644
index 0000000000..b3bffff133
--- /dev/null
+++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml.cs
@@ -0,0 +1,112 @@
+// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this
+// software and associated documentation files (the "Software"), to deal in the Software
+// without restriction, including without limitation the rights to use, copy, modify, merge,
+// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
+// to whom the Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all copies or
+// substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+
+namespace ResourceEditor.Views
+{
+ ///
+ /// Interaction logic for InPlaceEditLabel.xaml
+ ///
+ public partial class InPlaceEditLabel : UserControl
+ {
+ string textBeforeEditing;
+
+ public InPlaceEditLabel()
+ {
+ InitializeComponent();
+ editingTextBox.Visibility = Visibility.Collapsed;
+ readOnlyTextBlock.Visibility = Visibility.Visible;
+ readOnlyTextBlock.DataContext = this;
+ editingTextBox.DataContext = this;
+ }
+
+ public static readonly DependencyProperty TextProperty =
+ DependencyProperty.Register("Text", typeof(string), typeof(InPlaceEditLabel),
+ new FrameworkPropertyMetadata());
+
+ public string Text {
+ get { return (string)GetValue(TextProperty); }
+ set { SetValue(TextProperty, value); }
+ }
+
+ public static readonly DependencyProperty IsEditingProperty =
+ DependencyProperty.Register("IsEditing", typeof(bool), typeof(InPlaceEditLabel),
+ new FrameworkPropertyMetadata());
+
+ public bool IsEditing {
+ get { return (bool)GetValue(IsEditingProperty); }
+ set { SetValue(IsEditingProperty, value); }
+ }
+
+ protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
+ {
+ base.OnPropertyChanged(e);
+
+ if (e.Property == IsEditingProperty) {
+ if ((bool)e.NewValue) {
+ editingTextBox.Visibility = Visibility.Visible;
+ readOnlyTextBlock.Visibility = Visibility.Collapsed;
+ editingTextBox.Focus();
+ textBeforeEditing = this.Text;
+ editingTextBox.SelectAll();
+ } else {
+ editingTextBox.Visibility = Visibility.Collapsed;
+ readOnlyTextBlock.Visibility = Visibility.Visible;
+ }
+ }
+ }
+
+ protected override void OnKeyUp(KeyEventArgs e)
+ {
+ base.OnKeyUp(e);
+
+ if (e.Key == Key.Enter) {
+ IsEditing = false;
+ } else if (e.Key == Key.Escape) {
+ // Cancel editing and restore original text
+ this.Text = textBeforeEditing;
+ IsEditing = false;
+ }
+ }
+
+ void EditingTextBox_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
+ {
+ if ((bool)e.NewValue) {
+ // Auto-select whole text as soon as TextBox becomes visible
+// editingTextBox.Focus();
+// editingTextBox.SelectAll();
+// textBeforeEditing = this.Text;
+ }
+ }
+
+ void EditingTextBox_LostFocus(object sender, RoutedEventArgs e)
+ {
+ // When losing focus, also stop editing
+ IsEditing = false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml
index e79013d2d7..131d6a480e 100644
--- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml
+++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml
@@ -26,7 +26,12 @@
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
@@ -100,7 +86,7 @@
-
+
diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml.cs
index 8a8124c532..049759c0d0 100644
--- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml.cs
+++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml.cs
@@ -18,21 +18,80 @@
using System;
using System.Collections;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
using System.Linq;
-using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
-using System.Windows.Documents;
using System.Windows.Input;
-using System.Windows.Media;
using ICSharpCode.Core.Presentation;
using ResourceEditor.ViewModels;
namespace ResourceEditor.Views
{
+ ///
+ /// TextBox implementation for in-place editing of resource item fields.
+ ///
+ public class InPlaceEditTextBox : TextBox
+ {
+ string textBeforeEditing;
+
+ public static readonly DependencyProperty IsEditingProperty =
+ DependencyProperty.Register("IsEditing", typeof(bool), typeof(InPlaceEditTextBox),
+ new FrameworkPropertyMetadata());
+
+ public bool IsEditing {
+ get { return (bool) GetValue(IsEditingProperty); }
+ set { SetValue(IsEditingProperty, value); }
+ }
+
+ public InPlaceEditTextBox() : base()
+ {
+ this.Visibility = Visibility.Collapsed;
+ }
+
+ protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
+ {
+ base.OnPropertyChanged(e);
+
+ if (e.Property == IsEditingProperty) {
+ if ((bool) e.NewValue) {
+ this.Visibility = Visibility.Visible;
+ } else {
+ this.Visibility = Visibility.Collapsed;
+ }
+ }
+ if (e.Property == VisibilityProperty) {
+ if ((Visibility) e.NewValue == Visibility.Visible) {
+ // Auto-select whole text as soon as TextBox becomes visible
+ this.Focus();
+ this.SelectAll();
+ textBeforeEditing = this.Text;
+ }
+ }
+ }
+
+ protected override void OnKeyUp(KeyEventArgs e)
+ {
+ base.OnKeyUp(e);
+
+ if (e.Key == Key.Enter) {
+ IsEditing = false;
+ } else if (e.Key == Key.Escape) {
+ // Cancel editing and restore original text
+ this.Text = textBeforeEditing;
+ IsEditing = false;
+ }
+ }
+
+ protected override void OnLostFocus(RoutedEventArgs e)
+ {
+ base.OnLostFocus(e);
+
+ // When losing focus, also stop editing
+ IsEditing = false;
+ }
+ }
+
///
/// Interaction logic for ResourceEditorView.xaml
///
@@ -48,7 +107,7 @@ namespace ResourceEditor.Views
public ResourceEditorView()
{
InitializeComponent();
- itemCollectionViewSource = (CollectionViewSource)this.Resources["resourceItemListViewSource"];
+ itemCollectionViewSource = (CollectionViewSource) this.Resources["resourceItemListViewSource"];
}
public IList SelectedItems {
@@ -123,7 +182,7 @@ namespace ResourceEditor.Views
void ResourceItemsListView_KeyUp(object sender, KeyEventArgs e)
{
- if (e.Key == Key.Enter) {
+ /*if (e.Key == Key.Enter) {
if (EditingFinished != null) {
EditingFinished(this, new EventArgs());
}
@@ -131,6 +190,11 @@ namespace ResourceEditor.Views
if (EditingCancelled != null) {
EditingCancelled(this, new EventArgs());
}
+ } else*/
+ if (e.Key == Key.F2) {
+ if (EditingStarted != null) {
+ EditingStarted(this, new EventArgs());
+ }
}
e.Handled = false;