Browse Source

Finished context menu commands of ResourceEditor.

pull/517/head
Andreas Weizel 12 years ago
parent
commit
844a90bb3d
  1. 35
      src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj
  2. 90
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs
  3. 38
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs
  4. 15
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs
  5. 20
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs
  6. 9
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs
  7. 107
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/ResourceItemCommand.cs
  8. 35
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs
  9. 61
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs
  10. 110
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs
  11. 8
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml
  12. 14
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml
  13. 112
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml.cs
  14. 44
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml
  15. 78
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml.cs

35
src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj

@ -63,37 +63,9 @@
<Compile Include="Src\Commands\CopyResourceNameCommand.cs" /> <Compile Include="Src\Commands\CopyResourceNameCommand.cs" />
<Compile Include="Src\Commands\EditCommentCommand.cs" /> <Compile Include="Src\Commands\EditCommentCommand.cs" />
<Compile Include="Src\Commands\RenameEntryCommand.cs" /> <Compile Include="Src\Commands\RenameEntryCommand.cs" />
<Compile Include="Src\Commands\ResourceItemCommand.cs" />
<Compile Include="Src\Commands\SaveEntryAsCommand.cs" /> <Compile Include="Src\Commands\SaveEntryAsCommand.cs" />
<Compile Include="Src\ResourceEditorDisplayBinding.cs" /> <Compile Include="Src\ResourceEditorDisplayBinding.cs" />
<Compile Include="Src\ResourceEdit\AbstractImageView.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Src\ResourceEdit\BinaryView.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Src\ResourceEdit\BitmapView.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Src\ResourceEdit\BooleanView.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Src\ResourceEdit\CursorView.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Src\ResourceEdit\IconView.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Src\ResourceEdit\IResourceView.cs" />
<Compile Include="Src\ResourceEdit\ResourceEditor.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Src\ResourceEdit\ResourceItem.cs" />
<Compile Include="Src\ResourceEdit\ResourceList.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Src\ResourceEdit\TextView.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Src\ViewModels\ResourceEditorViewModel.cs" /> <Compile Include="Src\ViewModels\ResourceEditorViewModel.cs" />
<Compile Include="Src\ViewModels\ResourceItem.cs" /> <Compile Include="Src\ViewModels\ResourceItem.cs" />
<Compile Include="Src\Views\BinaryView.xaml.cs"> <Compile Include="Src\Views\BinaryView.xaml.cs">
@ -108,6 +80,10 @@
<DependentUpon>ImageViewBase.xaml</DependentUpon> <DependentUpon>ImageViewBase.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Src\Views\InPlaceEditLabel.xaml.cs">
<DependentUpon>InPlaceEditLabel.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\Views\IResourceEditorView.cs" /> <Compile Include="Src\Views\IResourceEditorView.cs" />
<Compile Include="Src\Views\IResourceItemView.cs" /> <Compile Include="Src\Views\IResourceItemView.cs" />
<Compile Include="Src\Views\ResourceEditorView.xaml.cs"> <Compile Include="Src\Views\ResourceEditorView.xaml.cs">
@ -166,6 +142,7 @@
<Page Include="Src\Views\BinaryView.xaml" /> <Page Include="Src\Views\BinaryView.xaml" />
<Page Include="Src\Views\BooleanView.xaml" /> <Page Include="Src\Views\BooleanView.xaml" />
<Page Include="Src\Views\ImageViewBase.xaml" /> <Page Include="Src\Views\ImageViewBase.xaml" />
<Page Include="Src\Views\InPlaceEditLabel.xaml" />
<Page Include="Src\Views\ResourceEditorView.xaml" /> <Page Include="Src\Views\ResourceEditorView.xaml" />
<Page Include="Src\Views\TextView.xaml" /> <Page Include="Src\Views\TextView.xaml" />
</ItemGroup> </ItemGroup>

90
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs

@ -28,56 +28,50 @@ using ResourceEditor.ViewModels;
namespace ResourceEditor.Commands namespace ResourceEditor.Commands
{ {
class AddNewFileCommand : SimpleCommand class AddNewFileCommand : ResourceItemCommand
{ {
public override void Execute(object parameter) public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceItem> resourceItems)
{ {
ResourceEditorViewModel editor = ((ResourceEditViewContent) SD.Workbench.ActiveViewContent).ResourceEditor;
// TODO Reactivate this
// if (editor.ResourceList.WriteProtected) { // if (editor.ResourceList.WriteProtected) {
// return; // return;
// } // }
// using (OpenFileDialog fdiag = new OpenFileDialog()) { var editor = ResourceEditor;
// fdiag.AddExtension = true; OpenFileDialog fdiag = new OpenFileDialog();
// fdiag.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.AllFiles}|*.*"); fdiag.AddExtension = true;
// fdiag.Multiselect = true; fdiag.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.AllFiles}|*.*");
// fdiag.CheckFileExists = true; fdiag.Multiselect = true;
// fdiag.CheckFileExists = true;
// if (fdiag.ShowDialog()) {
// foreach (string filename in fdiag.FileNames) { if ((bool)fdiag.ShowDialog()) {
// string oresname = Path.ChangeExtension(Path.GetFileName(filename), null); foreach (string filename in fdiag.FileNames) {
// if (oresname == "") string oresname = Path.ChangeExtension(Path.GetFileName(filename), null);
// oresname = "new"; if (oresname == "")
// oresname = "new";
// string resname = oresname;
// string resname = oresname;
// int i = 0;
// TestName: int i = 0;
// if (editor.ResourceList.Resources.ContainsKey(resname)) { TestName:
// if (i == 10) { if (editor.ContainsResourceName(resname)) {
// continue; if (i == 10) {
// } continue;
// i++; }
// resname = oresname + "_" + i.ToString(); i++;
// goto TestName; resname = oresname + "_" + i;
// } goto TestName;
// }
// object tmp = loadResource(filename);
// if (tmp == null) { object tmp = LoadResource(filename);
// continue; if (tmp == null) {
// } continue;
// editor.ResourceList.Resources.Add(resname, new ResourceItem(resname, tmp)); }
// editor.ResourceItems.Add(new ResourceItem(editor, resname, tmp));
// } }
// editor.ResourceList.InitializeListView(); }
// }
// }
// editor.ResourceList.OnChanged();
} }
object loadResource(string name) object LoadResource(string name)
{ {
switch (Path.GetExtension(name).ToUpperInvariant()) { switch (Path.GetExtension(name).ToUpperInvariant()) {
case ".CUR": case ".CUR":
@ -93,13 +87,13 @@ namespace ResourceEditor.Commands
return null; return null;
} }
default: default:
// try to read a bitmap // Try to read a bitmap
try { try {
return new System.Drawing.Bitmap(name); return new System.Drawing.Bitmap(name);
} catch { } catch {
} }
// try to read a serialized object // Try to read a serialized object
try { try {
Stream r = File.Open(name, FileMode.Open); Stream r = File.Open(name, FileMode.Open);
try { try {
@ -113,17 +107,15 @@ namespace ResourceEditor.Commands
} catch { } catch {
} }
// try to read a byte array :) // Try to read a byte array
try { try {
FileStream s = new FileStream(name, FileMode.Open); FileStream s = new FileStream(name, FileMode.Open);
BinaryReader r = new BinaryReader(s); BinaryReader r = new BinaryReader(s);
Byte[] d = new Byte[(int) s.Length]; Byte[] d = new Byte[(int)s.Length];
d = r.ReadBytes((int) s.Length); d = r.ReadBytes((int)s.Length);
s.Close(); s.Close();
return d; return d;
} catch (Exception) { } catch (Exception) {
string message = ResourceService.GetString("ResourceEditor.Messages.CantLoadResource"); string message = ResourceService.GetString("ResourceEditor.Messages.CantLoadResource");
MessageService.ShowWarning(message + " " + name + "."); MessageService.ShowWarning(message + " " + name + ".");
} }

38
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs

@ -24,33 +24,29 @@ using ResourceEditor.ViewModels;
namespace ResourceEditor.Commands namespace ResourceEditor.Commands
{ {
class AddStringCommand : SimpleCommand class AddStringCommand : ResourceItemCommand
{ {
public override void Execute(object parameter) public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{ {
ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor;
// TODO Reactivate this
// if(editor.ResourceList.WriteProtected) { // if(editor.ResourceList.WriteProtected) {
// return; // return;
// } // }
// //
// int count = 1; var editor = ResourceEditor;
// string newNameBase = " new string entry "; int count = 1;
// string newName = newNameBase + count.ToString(); string newNameBase = " new string entry ";
// string type = "System.String"; string newName = newNameBase + count;
//
// while(editor.ResourceList.Resources.ContainsKey(newName)) { while (editor.ContainsResourceName(newName)) {
// count++; count++;
// newName = newNameBase + count.ToString(); newName = newNameBase + count;
// } }
//
// ResourceItem item = new ResourceItem(newName, ""); ResourceItem item = new ResourceItem(editor, newName, "");
// editor.ResourceList.Resources.Add(newName, item); editor.ResourceItems.Add(item);
// ListViewItem lv = new ListViewItem(new string[] { newName, type, "" }, item.ImageIndex); editor.SelectedItems.Clear();
// editor.ResourceList.Items.Add(lv); editor.SelectedItems.Add(item);
// editor.ResourceList.OnChanged(); editor.StartEditing();
// lv.BeginEdit();
} }
} }
} }

15
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs

@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
@ -25,16 +26,14 @@ using ResourceEditor.ViewModels;
namespace ResourceEditor.Commands namespace ResourceEditor.Commands
{ {
class CopyResourceNameCommand : SimpleCommand class CopyResourceNameCommand : ResourceItemCommand
{ {
public override void Execute(object parameter) public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{ {
ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; var firstSelectedItem = resourceItems.First();
if (firstSelectedItem != null) {
// TODO Reactivate this Clipboard.SetText(firstSelectedItem.Name);
// if(editor.ResourceList.SelectedItems.Count > 0) { }
// Clipboard.SetText(editor.ResourceList.SelectedItems[0].Text);
// }
} }
} }
} }

20
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs

@ -24,20 +24,16 @@ using ResourceEditor.ViewModels;
namespace ResourceEditor.Commands namespace ResourceEditor.Commands
{ {
class EditCommentCommand : SimpleCommand class EditCommentCommand : ResourceItemCommand
{ {
public override void Execute(object parameter) public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{ {
ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; var selectedItem = resourceItems.First();
string newValue = SD.MessageService.ShowInputBox("${res:ResourceEditor.ResourceEdit.ContextMenu.EditComment}",
if (editor.SelectedItems.Count != 0) { "${res:ResourceEditor.ResourceEdit.ContextMenu.EditCommentText}",
var selectedItem = editor.SelectedItems.OfType<ResourceEditor.ViewModels.ResourceItem>().FirstOrDefault(); selectedItem.Comment);
string newValue = SD.MessageService.ShowInputBox("${res:ResourceEditor.ResourceEdit.ContextMenu.EditComment}", if (newValue != null && newValue != selectedItem.Comment) {
"${res:ResourceEditor.ResourceEdit.ContextMenu.EditCommentText}", selectedItem.Comment = newValue;
selectedItem.Comment);
if (newValue != null && newValue != selectedItem.Comment) {
selectedItem.Comment = newValue;
}
} }
} }
} }

9
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs

@ -23,12 +23,13 @@ using ResourceEditor.ViewModels;
namespace ResourceEditor.Commands namespace ResourceEditor.Commands
{ {
class RenameEntryCommand : SimpleCommand class RenameEntryCommand : ResourceItemCommand
{ {
public override void Execute(object parameter) public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{ {
ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; var editor = ResourceEditor;
editor.StartEditing(); if (editor != null)
editor.StartEditing();
} }
} }
} }

107
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
{
/// <summary>
/// Represents a <see cref="ResourceEditor.ViewModels.ResourceItem"/>-related command.
/// </summary>
public class ResourceItemCommand : SimpleCommand
{
/// <summary>
/// Defines whether this command supports multiselection of items.
/// If not, command will be disabled by default, when more than 1 item is selected.
/// </summary>
public virtual bool SupportsMultiSelections {
get {
return false;
}
}
/// <summary>
/// Returns list of resource item types for which this command may be enabled or <c>null</c> to allow any type.
/// </summary>
public virtual IEnumerable<ResourceItemEditorType> 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);
}
/// <summary>
/// Checks whether this command can be executed for the current set of selected resource items.
/// </summary>
/// <param name="resourceItems">List of selected resource items. Will always contain at least one element.</param>
/// <returns><c>True</c>, when command can be executed, <c>false</c> otherwise.</returns>
public virtual bool CanExecuteWithResourceItems(IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{
return true;
}
public override void Execute(object parameter)
{
var selectedResourceItems = GetSelectedItems();
if (!selectedResourceItems.Any())
return;
if (!SupportsMultiSelections && (selectedResourceItems.Count() > 1))
return;
ExecuteWithResourceItems(selectedResourceItems);
}
/// <summary>
/// Executes command for the given set of selected resource items.
/// </summary>
/// <param name="resourceItems">List of selected resource items. Will always contain at least one element.</param>
public virtual void ExecuteWithResourceItems(IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{
}
public ResourceEditorViewModel ResourceEditor {
get {
return ((ResourceEditViewContent) SD.Workbench.ActiveViewContent).ResourceEditor;
}
}
IEnumerable<ResourceEditor.ViewModels.ResourceItem> GetSelectedItems()
{
var editor = ResourceEditor;
if (editor != null)
return editor.SelectedItems.OfType<ResourceEditor.ViewModels.ResourceItem>() ?? new ResourceEditor.ViewModels.ResourceItem[0];
return new ResourceEditor.ViewModels.ResourceItem[0];
}
}
}

35
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs

@ -20,6 +20,7 @@ using System;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
@ -28,20 +29,22 @@ using ResourceEditor.ViewModels;
namespace ResourceEditor.Commands namespace ResourceEditor.Commands
{ {
class SaveEntryAsCommand : SimpleCommand class SaveEntryAsCommand : ResourceItemCommand
{ {
public override void Execute(object parameter) public override System.Collections.Generic.IEnumerable<ResourceItemEditorType> AllowedTypes {
{ get {
ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; return new ResourceItemEditorType[] {
ResourceItemEditorType.Bitmap,
if (editor.SelectedItems.Count != 1) { ResourceItemEditorType.Icon,
return; ResourceItemEditorType.Cursor,
} ResourceItemEditorType.Binary
};
ResourceItem firstSelectedItem = (editor.SelectedItems[0] as ResourceItem);
if (firstSelectedItem == null) {
return;
} }
}
public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{
var firstSelectedItem = resourceItems.First();
var sdialog = new Microsoft.Win32.SaveFileDialog(); var sdialog = new Microsoft.Win32.SaveFileDialog();
sdialog.AddExtension = true; sdialog.AddExtension = true;
@ -64,22 +67,22 @@ namespace ResourceEditor.Commands
} }
bool? dr = sdialog.ShowDialog(); bool? dr = sdialog.ShowDialog();
if (dr.HasValue && dr.Value) { if (!dr.HasValue || !dr.Value) {
return; return;
} }
try { try {
if (firstSelectedItem.ResourceValue is Icon) { if (firstSelectedItem.ResourceValue is Icon) {
FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create); FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create);
((Icon)firstSelectedItem.ResourceValue).Save(fstr); ((Icon) firstSelectedItem.ResourceValue).Save(fstr);
fstr.Close(); fstr.Close();
} else if (firstSelectedItem.ResourceValue is Image) { } else if (firstSelectedItem.ResourceValue is Image) {
Image img = (Image)firstSelectedItem.ResourceValue; Image img = (Image) firstSelectedItem.ResourceValue;
img.Save(sdialog.FileName); img.Save(sdialog.FileName);
} else { } else {
FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create); FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create);
BinaryWriter wr = new BinaryWriter(fstr); BinaryWriter wr = new BinaryWriter(fstr);
wr.Write((byte[])firstSelectedItem.ResourceValue); wr.Write((byte[]) firstSelectedItem.ResourceValue);
fstr.Close(); fstr.Close();
} }
} catch (Exception ex) { } catch (Exception ex) {

61
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs

@ -72,7 +72,7 @@ namespace ResourceEditor.ViewModels
new FrameworkPropertyMetadata()); new FrameworkPropertyMetadata());
public string SearchTerm { public string SearchTerm {
get { return (string)GetValue(SearchTermProperty); } get { return (string) GetValue(SearchTermProperty); }
set { SetValue(SearchTermProperty, value); } set { SetValue(SearchTermProperty, value); }
} }
@ -100,6 +100,16 @@ namespace ResourceEditor.ViewModels
} }
} }
/// <summary>
/// Checks whether a resource name is existing in currently open file.
/// </summary>
/// <param name="name">Resource name to check.</param>
/// <returns><c>True</c> if name exists, <c>false</c> otherwise.</returns>
public bool ContainsResourceName(string name)
{
return resourceItemNames.Contains(name);
}
public void AddItemView(ResourceItemEditorType itemType, IResourceItemView view) public void AddItemView(ResourceItemEditorType itemType, IResourceItemView view)
{ {
itemViews[itemType] = view; itemViews[itemType] = view;
@ -112,6 +122,7 @@ namespace ResourceEditor.ViewModels
set { set {
if (view != null) { if (view != null) {
view.SelectionChanged -= View_SelectionChanged; view.SelectionChanged -= View_SelectionChanged;
view.EditingStarted -= View_EditingStarted;
view.EditingFinished -= View_EditingFinished; view.EditingFinished -= View_EditingFinished;
view.EditingCancelled -= View_EditingCancelled; view.EditingCancelled -= View_EditingCancelled;
ResourceItems.CollectionChanged -= ResourceItems_CollectionChanged; ResourceItems.CollectionChanged -= ResourceItems_CollectionChanged;
@ -133,6 +144,7 @@ namespace ResourceEditor.ViewModels
return true; return true;
}; };
view.SelectionChanged += View_SelectionChanged; view.SelectionChanged += View_SelectionChanged;
view.EditingStarted += View_EditingStarted;
view.EditingFinished += View_EditingFinished; view.EditingFinished += View_EditingFinished;
view.EditingCancelled += View_EditingCancelled; view.EditingCancelled += View_EditingCancelled;
ResourceItems.CollectionChanged += ResourceItems_CollectionChanged; ResourceItems.CollectionChanged += ResourceItems_CollectionChanged;
@ -198,11 +210,11 @@ namespace ResourceEditor.ViewModels
public void StartEditing() public void StartEditing()
{ {
if (editedResourceItem != null) { // if (editedResourceItem != null) {
editedResourceItem.IsEditing = false; // editedResourceItem.IsEditing = false;
editedResourceItem = null; // editedResourceItem = null;
originalNameOfEditedItem = null; // originalNameOfEditedItem = null;
} // }
// Start editing currently selected item // Start editing currently selected item
var firstSelectedItem = SelectedItems.OfType<ResourceItem>().FirstOrDefault(); var firstSelectedItem = SelectedItems.OfType<ResourceItem>().FirstOrDefault();
@ -213,24 +225,29 @@ namespace ResourceEditor.ViewModels
} }
} }
void View_EditingStarted(object sender, EventArgs e)
{
StartEditing();
}
void View_EditingFinished(object sender, EventArgs e) void View_EditingFinished(object sender, EventArgs e)
{ {
if (editedResourceItem != null) { // if (editedResourceItem != null) {
editedResourceItem.IsEditing = false; // editedResourceItem.IsEditing = false;
editedResourceItem = null; // editedResourceItem = null;
originalNameOfEditedItem = null; // originalNameOfEditedItem = null;
MakeDirty(); // MakeDirty();
} // }
} }
void View_EditingCancelled(object sender, EventArgs e) void View_EditingCancelled(object sender, EventArgs e)
{ {
if (editedResourceItem != null) { // if (editedResourceItem != null) {
editedResourceItem.IsEditing = false; // editedResourceItem.IsEditing = false;
editedResourceItem.Name = originalNameOfEditedItem; // editedResourceItem.Name = originalNameOfEditedItem;
editedResourceItem = null; // editedResourceItem = null;
originalNameOfEditedItem = null; // originalNameOfEditedItem = null;
} // }
} }
void StartUpdate() void StartUpdate()
@ -258,13 +275,13 @@ namespace ResourceEditor.ViewModels
rx.UseResXDataNodes = true; rx.UseResXDataNodes = true;
IDictionaryEnumerator n = rx.GetEnumerator(); IDictionaryEnumerator n = rx.GetEnumerator();
while (n.MoveNext()) { 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)); resourceItems.Add(new ResourceItem(this, node.Name, node.GetValue(typeResolver), node.Comment));
} }
n = rx.GetMetadataEnumerator(); n = rx.GetMetadataEnumerator();
while (n.MoveNext()) { while (n.MoveNext()) {
ResXDataNode node = (ResXDataNode)n.Value; ResXDataNode node = (ResXDataNode) n.Value;
metadataItems.Add(new ResourceItem(this, node.Name, node.GetValue(typeResolver))); metadataItems.Add(new ResourceItem(this, node.Name, node.GetValue(typeResolver)));
} }
@ -390,12 +407,12 @@ namespace ResourceEditor.ViewModels
return; return;
if (dob.GetDataPresent(typeof(Hashtable).FullName)) { 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) { foreach (DictionaryEntry entry in tmphash) {
object resourceValue = GetClonedResource(entry.Value); object resourceValue = GetClonedResource(entry.Value);
ResourceItem item; ResourceItem item;
if (!resourceItemNames.Contains((string)entry.Key)) { if (!resourceItemNames.Contains((string) entry.Key)) {
item = new ResourceItem(this, entry.Key.ToString(), resourceValue); item = new ResourceItem(this, entry.Key.ToString(), resourceValue);
} else { } else {
int count = 1; int count = 1;

110
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs

@ -20,6 +20,7 @@ using System;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Resources; using System.Resources;
using System.Windows;
using System.Windows.Forms; using System.Windows.Forms;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
@ -39,66 +40,45 @@ namespace ResourceEditor.ViewModels
Binary Binary
} }
public class ResourceItem : INotifyPropertyChanged public class ResourceItem : DependencyObject
{ {
string name;
object resourceValue;
string comment;
ResourceItemEditorType resourceType; ResourceItemEditorType resourceType;
ResourceEditorViewModel resourceEditor; ResourceEditorViewModel resourceEditor;
bool isEditing; string nameBeforeEditing;
public ResourceItem(ResourceEditorViewModel resourceEditor, string name, object resourceValue) public ResourceItem(ResourceEditorViewModel resourceEditor, string name, object resourceValue)
{ {
this.resourceEditor = resourceEditor; this.resourceEditor = resourceEditor;
this.name = name; this.Name = name;
this.resourceValue = resourceValue; this.ResourceValue = resourceValue;
this.resourceType = GetResourceTypeFromValue(resourceValue); this.resourceType = GetResourceTypeFromValue(resourceValue);
} }
public ResourceItem(ResourceEditorViewModel resourceEditor, string name, object resourceValue, string comment) public ResourceItem(ResourceEditorViewModel resourceEditor, string name, object resourceValue, string comment)
{ {
this.resourceEditor = resourceEditor; this.resourceEditor = resourceEditor;
this.name = name; this.Name = name;
this.resourceValue = resourceValue; this.ResourceValue = resourceValue;
this.resourceType = GetResourceTypeFromValue(resourceValue); this.resourceType = GetResourceTypeFromValue(resourceValue);
this.comment = comment; this.Comment = comment;
} }
#region INotifyPropertyChanged implementation public static readonly DependencyProperty NameProperty =
DependencyProperty.Register("Name", typeof(string), typeof(ResourceItem),
public event PropertyChangedEventHandler PropertyChanged; new FrameworkPropertyMetadata());
void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
public string Name { public string Name {
get { get { return (string)GetValue(NameProperty); }
return name; set { SetValue(NameProperty, value); }
}
set {
name = value;
OnPropertyChanged("Name");
}
} }
public static readonly DependencyProperty ResourceValueProperty =
DependencyProperty.Register("ResourceValue", typeof(object), typeof(ResourceItem),
new FrameworkPropertyMetadata());
public object ResourceValue { public object ResourceValue {
get { get { return (object)GetValue(ResourceValueProperty); }
return resourceValue; set { SetValue(ResourceValueProperty, value); }
}
set {
resourceValue = value;
OnPropertyChanged("ResourceValue");
OnPropertyChanged("ResourceType");
OnPropertyChanged("Content");
resourceEditor.MakeDirty();
}
} }
public string DisplayedResourceType { 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 { public bool IsEditing {
get { get { return (bool)GetValue(IsEditingProperty); }
return isEditing; set { SetValue(IsEditingProperty, value); }
} }
set {
isEditing = value; protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
OnPropertyChanged("IsEditing"); {
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 { public string Comment {
get { get { return (string)GetValue(CommentProperty); }
return comment; set { SetValue(CommentProperty, value); }
}
set {
comment = value;
OnPropertyChanged("Comment");
resourceEditor.MakeDirty();
}
} }
public override string ToString() public override string ToString()

8
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml

@ -8,6 +8,12 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Button Grid.Row="0" Content="{Binding UpdateLinkText}" Margin="2,2,2,2" HorizontalAlignment="Left" Click="Button_Click" /> <Button Grid.Row="0" Content="{Binding UpdateLinkText}" Margin="2,2,2,2" HorizontalAlignment="Left" Click="Button_Click" />
<Image Name="imagePreview" Grid.Row="1" Source="{Binding DisplayedImage}" Stretch="None" /> <ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" Margin="0,0,0,0">
<Image
Name="imagePreview"
Source="{Binding DisplayedImage}"
Stretch="None"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</ScrollViewer>
</Grid> </Grid>
</UserControl> </UserControl>

14
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml

@ -0,0 +1,14 @@
<UserControl x:Class="ResourceEditor.Views.InPlaceEditLabel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Margin="0,0,0,0">
<TextBlock Name="readOnlyTextBlock" Text="{Binding Text, Mode=TwoWay}" VerticalAlignment="Top" Margin="0,0,0,0" />
<TextBox
Name="editingTextBox"
Text="{Binding Text, Mode=TwoWay}"
VerticalAlignment="Top"
Margin="0,0,0,0"
IsVisibleChanged="EditingTextBox_IsVisibleChanged"
LostFocus="EditingTextBox_LostFocus" />
</Grid>
</UserControl>

112
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
{
/// <summary>
/// Interaction logic for InPlaceEditLabel.xaml
/// </summary>
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;
}
}
}

44
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml

@ -26,7 +26,12 @@
<DataTemplate x:Key="resourceItemNameTemplate" DataType="{x:Type resvm:ResourceItem}"> <DataTemplate x:Key="resourceItemNameTemplate" DataType="{x:Type resvm:ResourceItem}">
<Border BorderBrush="LightGray" BorderThickness="0,0,1,1" Margin="-6,-2,-6,-2"> <Border BorderBrush="LightGray" BorderThickness="0,0,1,1" Margin="-6,-2,-6,-2">
<StackPanel Orientation="Horizontal" Margin="6,2,6,2"> <Grid Margin="6,2,6,2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Width="16" Height="16" VerticalAlignment="Top" Margin="0,0,3,0"> <Image Grid.Column="0" Width="16" Height="16" VerticalAlignment="Top" Margin="0,0,3,0">
<Image.Style> <Image.Style>
<Style TargetType="Image"> <Style TargetType="Image">
@ -56,33 +61,14 @@
</Style> </Style>
</Image.Style> </Image.Style>
</Image> </Image>
<TextBlock Grid.Column="1" Text="{Binding Name}" VerticalAlignment="Top" HorizontalAlignment="Stretch"> <resv:InPlaceEditLabel Grid.Column="1"
<TextBlock.Style> Text="{Binding Name, Mode=TwoWay}"
<Style TargetType="TextBlock"> VerticalAlignment="Top"
<Setter Property="Visibility" Value="Collapsed" /> Margin="0,0,0,0"
<Style.Triggers> MinWidth="300"
<DataTrigger Binding="{Binding IsEditing}" Value="False"> IsEditing="{Binding IsEditing, Mode=TwoWay}">
<Setter Property="Visibility" Value="Visible" /> </resv:InPlaceEditLabel>
</DataTrigger> </Grid>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<TextBox Grid.Column="1"
Text="{Binding Name}" VerticalAlignment="Top" HorizontalAlignment="Stretch"
HorizontalScrollBarVisibility="Hidden">
<TextBox.Style>
<Style TargetType="TextBox">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsEditing}" Value="True">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</StackPanel>
</Border> </Border>
</DataTemplate> </DataTemplate>
@ -100,7 +86,7 @@
<DataTemplate x:Key="resourceItemCommentTemplate" DataType="{x:Type resvm:ResourceItem}"> <DataTemplate x:Key="resourceItemCommentTemplate" DataType="{x:Type resvm:ResourceItem}">
<Border BorderBrush="LightGray" BorderThickness="0,0,1,1" Margin="-6,-2,-6,-2"> <Border BorderBrush="LightGray" BorderThickness="0,0,1,1" Margin="-6,-2,-6,-2">
<TextBlock Text="{Binding Comment}" Margin="6,2,6,2" /> <TextBlock Text="{Binding Comment}" Margin="6,2,6,2" MinWidth="300" />
</Border> </Border>
</DataTemplate> </DataTemplate>
</UserControl.Resources> </UserControl.Resources>

78
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml.cs

@ -18,21 +18,80 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.Core.Presentation; using ICSharpCode.Core.Presentation;
using ResourceEditor.ViewModels; using ResourceEditor.ViewModels;
namespace ResourceEditor.Views namespace ResourceEditor.Views
{ {
/// <summary>
/// TextBox implementation for in-place editing of resource item fields.
/// </summary>
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;
}
}
/// <summary> /// <summary>
/// Interaction logic for ResourceEditorView.xaml /// Interaction logic for ResourceEditorView.xaml
/// </summary> /// </summary>
@ -48,7 +107,7 @@ namespace ResourceEditor.Views
public ResourceEditorView() public ResourceEditorView()
{ {
InitializeComponent(); InitializeComponent();
itemCollectionViewSource = (CollectionViewSource)this.Resources["resourceItemListViewSource"]; itemCollectionViewSource = (CollectionViewSource) this.Resources["resourceItemListViewSource"];
} }
public IList SelectedItems { public IList SelectedItems {
@ -123,7 +182,7 @@ namespace ResourceEditor.Views
void ResourceItemsListView_KeyUp(object sender, KeyEventArgs e) void ResourceItemsListView_KeyUp(object sender, KeyEventArgs e)
{ {
if (e.Key == Key.Enter) { /*if (e.Key == Key.Enter) {
if (EditingFinished != null) { if (EditingFinished != null) {
EditingFinished(this, new EventArgs()); EditingFinished(this, new EventArgs());
} }
@ -131,6 +190,11 @@ namespace ResourceEditor.Views
if (EditingCancelled != null) { if (EditingCancelled != null) {
EditingCancelled(this, new EventArgs()); EditingCancelled(this, new EventArgs());
} }
} else*/
if (e.Key == Key.F2) {
if (EditingStarted != null) {
EditingStarted(this, new EventArgs());
}
} }
e.Handled = false; e.Handled = false;

Loading…
Cancel
Save