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 @@ @@ -63,37 +63,9 @@
<Compile Include="Src\Commands\CopyResourceNameCommand.cs" />
<Compile Include="Src\Commands\EditCommentCommand.cs" />
<Compile Include="Src\Commands\RenameEntryCommand.cs" />
<Compile Include="Src\Commands\ResourceItemCommand.cs" />
<Compile Include="Src\Commands\SaveEntryAsCommand.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\ResourceItem.cs" />
<Compile Include="Src\Views\BinaryView.xaml.cs">
@ -108,6 +80,10 @@ @@ -108,6 +80,10 @@
<DependentUpon>ImageViewBase.xaml</DependentUpon>
<SubType>Code</SubType>
</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\IResourceItemView.cs" />
<Compile Include="Src\Views\ResourceEditorView.xaml.cs">
@ -166,6 +142,7 @@ @@ -166,6 +142,7 @@
<Page Include="Src\Views\BinaryView.xaml" />
<Page Include="Src\Views\BooleanView.xaml" />
<Page Include="Src\Views\ImageViewBase.xaml" />
<Page Include="Src\Views\InPlaceEditLabel.xaml" />
<Page Include="Src\Views\ResourceEditorView.xaml" />
<Page Include="Src\Views\TextView.xaml" />
</ItemGroup>

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

@ -28,56 +28,50 @@ using ResourceEditor.ViewModels; @@ -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<ResourceItem> 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 @@ -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 @@ -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 + ".");
}

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

@ -24,33 +24,29 @@ using ResourceEditor.ViewModels; @@ -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<ResourceEditor.ViewModels.ResourceItem> 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();
}
}
}

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

@ -17,6 +17,7 @@ @@ -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; @@ -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<ResourceEditor.ViewModels.ResourceItem> 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);
}
}
}
}

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

@ -24,20 +24,16 @@ using ResourceEditor.ViewModels; @@ -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<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{
ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor;
if (editor.SelectedItems.Count != 0) {
var selectedItem = editor.SelectedItems.OfType<ResourceEditor.ViewModels.ResourceItem>().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;
}
}
}

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

@ -23,12 +23,13 @@ using ResourceEditor.ViewModels; @@ -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<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{
ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor;
editor.StartEditing();
var editor = ResourceEditor;
if (editor != null)
editor.StartEditing();
}
}
}

107
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/ResourceItemCommand.cs

@ -0,0 +1,107 @@ @@ -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; @@ -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; @@ -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<ResourceItemEditorType> AllowedTypes {
get {
return new ResourceItemEditorType[] {
ResourceItemEditorType.Bitmap,
ResourceItemEditorType.Icon,
ResourceItemEditorType.Cursor,
ResourceItemEditorType.Binary
};
}
}
public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{
var firstSelectedItem = resourceItems.First();
var sdialog = new Microsoft.Win32.SaveFileDialog();
sdialog.AddExtension = true;
@ -64,22 +67,22 @@ namespace ResourceEditor.Commands @@ -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) {

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

@ -72,7 +72,7 @@ namespace ResourceEditor.ViewModels @@ -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 @@ -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)
{
itemViews[itemType] = view;
@ -112,6 +122,7 @@ namespace ResourceEditor.ViewModels @@ -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 @@ -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 @@ -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<ResourceItem>().FirstOrDefault();
@ -213,24 +225,29 @@ namespace ResourceEditor.ViewModels @@ -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 @@ -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 @@ -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;

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

@ -20,6 +20,7 @@ using System; @@ -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 @@ -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 @@ -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 @@ -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()

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

@ -8,6 +8,12 @@ @@ -8,6 +8,12 @@
</Grid.RowDefinitions>
<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>
</UserControl>

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

@ -0,0 +1,14 @@ @@ -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 @@ @@ -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 @@ @@ -26,7 +26,12 @@
<DataTemplate x:Key="resourceItemNameTemplate" DataType="{x:Type resvm:ResourceItem}">
<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.Style>
<Style TargetType="Image">
@ -56,33 +61,14 @@ @@ -56,33 +61,14 @@
</Style>
</Image.Style>
</Image>
<TextBlock Grid.Column="1" Text="{Binding Name}" VerticalAlignment="Top" HorizontalAlignment="Stretch">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsEditing}" Value="False">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</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>
<resv:InPlaceEditLabel Grid.Column="1"
Text="{Binding Name, Mode=TwoWay}"
VerticalAlignment="Top"
Margin="0,0,0,0"
MinWidth="300"
IsEditing="{Binding IsEditing, Mode=TwoWay}">
</resv:InPlaceEditLabel>
</Grid>
</Border>
</DataTemplate>
@ -100,7 +86,7 @@ @@ -100,7 +86,7 @@
<DataTemplate x:Key="resourceItemCommentTemplate" DataType="{x:Type resvm:ResourceItem}">
<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>
</DataTemplate>
</UserControl.Resources>

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

@ -18,21 +18,80 @@ @@ -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
{
/// <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>
/// Interaction logic for ResourceEditorView.xaml
/// </summary>
@ -48,7 +107,7 @@ namespace ResourceEditor.Views @@ -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 @@ -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 @@ -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;

Loading…
Cancel
Save