Browse Source

Issue #539 (ResourceEditor): Fixed some issues with creating new entries, filtering, handling of invalid names + code cleanup.

pull/517/head
Andreas Weizel 12 years ago
parent
commit
62b90db634
  1. 14
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs
  2. 10
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/ResourceItemCommand.cs
  3. 88
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/AbstractImageView.cs
  4. 139
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/BinaryView.cs
  5. 92
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/BitmapView.cs
  6. 86
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/BooleanView.cs
  7. 65
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/CursorView.cs
  8. 73
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/IResourceView.cs
  9. 57
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/IconView.cs
  10. 157
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/ResourceEditor.cs
  11. 116
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/ResourceItem.cs
  12. 317
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/ResourceList.cs
  13. 70
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/TextView.cs
  14. 13
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEditorDisplayBinding.cs
  15. 12
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs
  16. 20
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs
  17. 2
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml
  18. 11
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml.cs
  19. 6
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml
  20. 42
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml.cs
  21. 6
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml
  22. 77
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml.cs

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

@ -17,16 +17,14 @@ @@ -17,16 +17,14 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using System.Linq;
using ResourceEditor.ViewModels;
namespace ResourceEditor.Commands
{
class AddStringCommand : ResourceItemCommand
{
public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceItem> resourceItems)
{
// if(editor.ResourceList.WriteProtected) {
// return;
@ -34,7 +32,7 @@ namespace ResourceEditor.Commands @@ -34,7 +32,7 @@ namespace ResourceEditor.Commands
//
var editor = ResourceEditor;
int count = 1;
string newNameBase = " new string entry ";
string newNameBase = "New string entry ";
string newName = newNameBase + count;
while (editor.ContainsResourceName(newName)) {
@ -42,7 +40,13 @@ namespace ResourceEditor.Commands @@ -42,7 +40,13 @@ namespace ResourceEditor.Commands
newName = newNameBase + count;
}
var selectedItem = GetSelectedItems().FirstOrDefault();
ResourceItem item = new ResourceItem(editor, newName, "");
item.IsNew = true;
if (selectedItem != null)
item.SortingCriteria = selectedItem.Name;
else
item.SortingCriteria = item.Name;
editor.ResourceItems.Add(item);
editor.SelectedItems.Clear();
editor.SelectedItems.Add(item);

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

@ -67,7 +67,7 @@ namespace ResourceEditor.Commands @@ -67,7 +67,7 @@ namespace ResourceEditor.Commands
/// </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)
public virtual bool CanExecuteWithResourceItems(IEnumerable<ResourceItem> resourceItems)
{
return true;
}
@ -86,7 +86,7 @@ namespace ResourceEditor.Commands @@ -86,7 +86,7 @@ namespace ResourceEditor.Commands
/// 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 virtual void ExecuteWithResourceItems(IEnumerable<ResourceItem> resourceItems)
{
}
@ -96,12 +96,12 @@ namespace ResourceEditor.Commands @@ -96,12 +96,12 @@ namespace ResourceEditor.Commands
}
}
IEnumerable<ResourceEditor.ViewModels.ResourceItem> GetSelectedItems()
protected IEnumerable<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];
return editor.SelectedItems.OfType<ResourceItem>() ?? new ResourceItem[0];
return new ResourceItem[0];
}
}
}

88
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/AbstractImageView.cs

@ -1,88 +0,0 @@ @@ -1,88 +0,0 @@
// 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.Drawing;
using System.Windows.Forms;
namespace ResourceEditor
{
/// <summary>
/// This control is used for displaying images. Large images
/// can be scrolled.
/// </summary>
abstract class AbstractImageView : ScrollableControl, IResourceView
{
protected PictureBox pictureBox;
public event ResourceChangedEventHandler ResourceChanged;
public abstract ResourceItem ResourceItem
{
get;
set;
}
public abstract bool WriteProtected
{
get;
set;
}
protected void resized(object sender, EventArgs e)
{
adjustMargin();
}
protected AbstractImageView(ResourceItem item)
{
Dock = DockStyle.Fill;
AutoScroll = true;
pictureBox = new PictureBox();
pictureBox.BorderStyle = BorderStyle.FixedSingle;
this.SizeChanged += new EventHandler(resized);
pictureBox.SizeMode = PictureBoxSizeMode.AutoSize;
Controls.Add(this.pictureBox);
ResourceItem = item;
}
protected void OnResourceChanged(string resourceName, object val)
{
if(ResourceChanged != null) {
ResourceChanged(this, new ResourceEventArgs(resourceName, val));
}
}
protected void adjustMargin()
{
int deltaY = Height - pictureBox.Image.Height;
int deltaX = Width - pictureBox.Image.Width;
if(deltaY > 0) {
pictureBox.Top = deltaY / 2;
}
pictureBox.Top = Math.Max(pictureBox.Top, 20);
if(deltaX > 0) {
pictureBox.Left = deltaX / 2;
}
pictureBox.Left = Math.Max(pictureBox.Left, 20);
AutoScrollMargin = new Size(pictureBox.Left / 2, pictureBox.Top / 2);
}
}
}

139
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/BinaryView.cs

@ -1,139 +0,0 @@ @@ -1,139 +0,0 @@
// 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.Drawing;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.Core.WinForms;
namespace ResourceEditor
{
/// <summary>
/// This class displays binary data.
/// </summary>
class BinaryView : UserControl, IResourceView
{
TextBox byteDataTextBox = new TextBox();
CheckBox viewHexDumpCheckBox = new CheckBox();
ResourceItem resourceItem;
ASCIIEncoding enc = new ASCIIEncoding();
Regex rgex = new Regex(@"\p{Cc}");
public event ResourceChangedEventHandler ResourceChanged;
public BinaryView(ResourceItem item)
{
byteDataTextBox.ReadOnly = true;
byteDataTextBox.Multiline = true;
byteDataTextBox.Top = 24;
byteDataTextBox.Left = 0;
byteDataTextBox.Width = Width;
byteDataTextBox.Height = Height - 24;
byteDataTextBox.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Top;
byteDataTextBox.Font = WinFormsResourceService.LoadFont("Courier New", 10);
byteDataTextBox.ScrollBars = ScrollBars.Both;
byteDataTextBox.BackColor = SystemColors.Window;
viewHexDumpCheckBox.Location = new Point(8, 4);
viewHexDumpCheckBox.Size = new Size(Width - 16, 16);
viewHexDumpCheckBox.Text = StringParser.Parse("${res:ResourceEditor.ResourceEdit.ShowAsHexDump}");
viewHexDumpCheckBox.CheckedChanged += new EventHandler(CheckEvt);
Controls.Add(byteDataTextBox);
Controls.Add(viewHexDumpCheckBox);
byteDataTextBox.Select();
ResourceItem = item;
}
public bool WriteProtected
{
get {
return true;
}
set {
}
}
public ResourceItem ResourceItem
{
get {
return resourceItem;
}
set {
resourceItem = value;
showData();
}
}
protected void OnResourceChanged(string resourceName, object val)
{
if(ResourceChanged != null) {
ResourceChanged(this, new ResourceEventArgs(resourceName, val));
}
}
void showData()
{
byte[] bytes= (byte[])ResourceItem.ResourceValue;
string regText = enc.GetString(bytes).Replace("\x0", ".");
if (viewHexDumpCheckBox.Checked) {
// Hex Dump
StringBuilder sb = new StringBuilder();
string byteString = BitConverter.ToString(bytes).Replace("-", " ");
string stext = rgex.Replace(regText, ".");
byteDataTextBox.Text = "";
int max = bytes.Length;
int last = max % 16;
int i = 0;
int count = 16;
do {
sb.Append(String.Format("{0:X8} ", i) +
byteString.Substring(i*3, (count * 3) - 1) + " " +
stext.Substring(i, count) + "\r\n");
i += 16;
if (i >= (max - last)) {
count = last;
}
} while (i < max);
byteDataTextBox.Text = sb.ToString();
} else {
// Regular Text
byteDataTextBox.Text = regText;
}
}
public void CheckEvt(object sender, EventArgs e)
{
showData();
}
}
}

92
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/BitmapView.cs

@ -1,92 +0,0 @@ @@ -1,92 +0,0 @@
// 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.Drawing;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
namespace ResourceEditor
{
/// <summary>
/// This control is used for displaying images. Large images
/// can be scrolled.
/// </summary>
class BitmapView : AbstractImageView
{
ResourceItem resourceItem;
LinkLabel updateLinkLabel;
public BitmapView(ResourceItem item) : base(item)
{
updateLinkLabel = new LinkLabel();
updateLinkLabel.Text = ResourceService.GetString("ResourceEditor.BitmapView.UpdateBitmap");
updateLinkLabel.Location = new Point(4, 4);
updateLinkLabel.AutoSize = true;
updateLinkLabel.Click += new EventHandler(updateBitmapLinkLabelClick);
Controls.Add(updateLinkLabel);
}
void updateBitmapLinkLabelClick(object sender, EventArgs e)
{
using(OpenFileDialog fileDialog = new OpenFileDialog())
{
Bitmap bitmap;
fileDialog.AddExtension = true;
fileDialog.Filter = "All files (*.*)|*.*";
fileDialog.CheckFileExists = true;
if(fileDialog.ShowDialog(SD.WinForms.MainWin32Window) == DialogResult.OK) {
try {
bitmap = new Bitmap(fileDialog.FileName);
} catch {
MessageService.ShowWarning("Can't load bitmap file.");
return;
}
ResourceItem = new ResourceItem(resourceItem.Name, bitmap);
OnResourceChanged(resourceItem.Name, bitmap);
}
}
}
public override bool WriteProtected
{
get {
return true;
}
set {
}
}
public override ResourceItem ResourceItem
{
get {
return resourceItem;
}
set {
resourceItem = value;
pictureBox.Image = (Bitmap)value.ResourceValue;
adjustMargin();
}
}
}
}

86
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/BooleanView.cs

@ -1,86 +0,0 @@ @@ -1,86 +0,0 @@
// 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.Drawing;
using System.Windows.Forms;
namespace ResourceEditor
{
class BooleanView : Panel, IResourceView
{
public event ResourceChangedEventHandler ResourceChanged;
private ResourceItem resourceItem;
private RadioButton trueRadioButton = new RadioButton();
private RadioButton falseRadioButton = new RadioButton();
public BooleanView(ResourceItem item)
{
trueRadioButton.Location = new Point(4, 4);
trueRadioButton.Text = "True";
trueRadioButton.CheckedChanged += new EventHandler(valueChanged);
Controls.Add(trueRadioButton);
falseRadioButton.Location = new Point(4, 24);
falseRadioButton.Text = "False";
falseRadioButton.CheckedChanged += new EventHandler(valueChanged);
Controls.Add(falseRadioButton);
ResourceItem = item;
}
public bool WriteProtected
{
get {
return ! trueRadioButton.Enabled;
}
set {
trueRadioButton.Enabled = ! value;
falseRadioButton.Enabled = ! value;
}
}
public ResourceItem ResourceItem
{
get {
return resourceItem;
}
set {
this.resourceItem = value;
if((bool)resourceItem.ResourceValue == true) {
trueRadioButton.Checked = true;
} else {
falseRadioButton.Checked = true;
}
}
}
protected void OnResourceChanged(string resourceName, object val)
{
if(ResourceChanged != null) {
ResourceChanged(this, new ResourceEventArgs(resourceName, val));
}
}
void valueChanged(object sender, EventArgs e)
{
OnResourceChanged(resourceItem.Name, trueRadioButton.Checked);
}
}
}

65
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/CursorView.cs

@ -1,65 +0,0 @@ @@ -1,65 +0,0 @@
// 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.Drawing;
using System.Windows.Forms;
namespace ResourceEditor
{
/// <summary>
/// This control is used for displaying images. Large images
/// can be scrolled.
/// </summary>
class CursorView : AbstractImageView
{
ResourceItem resourceItem;
public CursorView(ResourceItem item) : base(item)
{
}
public override bool WriteProtected
{
get {
return true;
}
set {
}
}
public override ResourceItem ResourceItem
{
get {
return resourceItem;
}
set {
resourceItem = value;
Cursor c = (Cursor)resourceItem.ResourceValue;
Bitmap a = new Bitmap(c.Size.Width, c.Size.Height);
Graphics g = Graphics.FromImage(a);
g.FillRectangle(new SolidBrush(Color.DarkCyan), 0, 0, a.Width, a.Height);
c.Draw(g, new Rectangle(0, 0, a.Width, a.Height));
pictureBox.Image = a;
g.Dispose();
adjustMargin();
}
}
}
}

73
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/IResourceView.cs

@ -1,73 +0,0 @@ @@ -1,73 +0,0 @@
// 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;
namespace ResourceEditor
{
delegate void ResourceChangedEventHandler(object sender, ResourceEventArgs e);
interface IResourceView : IDisposable
{
bool WriteProtected
{
get;
set;
}
ResourceItem ResourceItem
{
get;
set;
}
event ResourceChangedEventHandler ResourceChanged;
}
class ResourceEventArgs
{
string resourceName;
object resourceValue;
public ResourceEventArgs(string resourceName, object resourceValue)
{
this.resourceName = resourceName;
this.resourceValue = resourceValue;
}
public string ResourceName
{
get {
return resourceName;
}
set {
resourceName = value;
}
}
public object ResourceValue
{
get {
return resourceValue;
}
set {
resourceValue = value;
}
}
}
}

57
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/IconView.cs

@ -1,57 +0,0 @@ @@ -1,57 +0,0 @@
// 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.Drawing;
namespace ResourceEditor
{
/// <summary>
/// This control is used for displaying images. Large images
/// can be scrolled.
/// </summary>
class IconView : AbstractImageView
{
ResourceItem resourceItem;
public IconView(ResourceItem item) : base(item)
{
}
public override bool WriteProtected
{
get {
return true;
}
set {
}
}
public override ResourceItem ResourceItem
{
get {
return resourceItem;
}
set {
resourceItem = value;
pictureBox.Image = ((Icon)value.ResourceValue).ToBitmap();
adjustMargin();
}
}
}
}

157
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/ResourceEditor.cs

@ -1,157 +0,0 @@ @@ -1,157 +0,0 @@
// 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.Drawing;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.WinForms;
namespace ResourceEditor
{
public class ResourceEditorControl : UserControl, IOwnerState
{
ResourceList resourceList;
Splitter splitter;
Panel panel;
IResourceView currentView = null;
[Flags]
public enum ListViewViewState {
Nothing = 0,
ItemsSelected = 1,
}
protected ListViewViewState internalState = ListViewViewState.Nothing;
public Enum InternalState {
get {
return internalState;
}
}
public ResourceList ResourceList
{
get {
return resourceList;
}
}
public ResourceEditorControl()
{
InitializeComponent();
resourceList.SelectedIndexChanged += ResourceListSelectionChanged;
}
void ResourceListSelectionChanged(object sender, EventArgs e)
{
if(resourceList.SelectedItems.Count == 0) {
internalState = ListViewViewState.Nothing;
ShowResource(null);
} else {
internalState = ListViewViewState.ItemsSelected;
}
if(resourceList.SelectedItems.Count != 1) {
return;
}
object key = resourceList.SelectedItems[0].Text;
ResourceItem item = (ResourceItem)resourceList.Resources[key.ToString()];
ShowResource(item);
}
void InitializeComponent()
{
resourceList = new ResourceList(this);
resourceList.Dock = DockStyle.Top;
Controls.Add(resourceList);
panel = new Panel();
panel.BackColor = SystemColors.Info;
panel.Dock = DockStyle.Fill;
splitter = new Splitter();
splitter.Dock = DockStyle.Top;
Controls.Add(panel);
Controls.Add(splitter);
Controls.Add(resourceList);
this.Resize += InitializeLayout;
}
void InitializeLayout(object sender, EventArgs e)
{
resourceList.Height = Convert.ToInt32(0.75 * Height);
}
void ShowView(Control viewer)
{
// remove old view if there is one
if(panel.Controls.Count == 1) {
Control control = panel.Controls[0];
panel.Controls.Remove(control);
control.Dispose();
}
if(viewer != null) {
viewer.Dock = DockStyle.Fill;
panel.Controls.Add(viewer);
currentView = (IResourceView)viewer;
currentView.WriteProtected = resourceList.WriteProtected;
currentView.ResourceChanged += ViewResourceChanged;
}
}
void ViewResourceChanged(object sender, ResourceEventArgs e)
{
resourceList.SetResourceValue(e.ResourceName, e.ResourceValue);
}
void ShowResource(ResourceItem item)
{
if(item == null) {
ShowView(null);
return;
}
if (item.ResourceValue is Icon) {
IconView iv = new IconView(item);
ShowView(iv);
} else if(item.ResourceValue is Bitmap) {
BitmapView bv = new BitmapView(item);
ShowView(bv);
} else if(item.ResourceValue is Cursor) {
CursorView cv = new CursorView(item);
ShowView(cv);
} else if(item.ResourceValue is string) {
TextView tv = new TextView(item);
ShowView(tv);
} else if(item.ResourceValue is byte[]) {
BinaryView bv = new BinaryView(item);
ShowView(bv);
} else if(item.ResourceValue is bool) {
BooleanView bv = new BooleanView(item);
ShowView(bv);
} else {
ShowView(null);
}
}
}
}

116
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/ResourceItem.cs

@ -1,116 +0,0 @@ @@ -1,116 +0,0 @@
// 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.Drawing;
using System.Resources;
using System.Windows.Forms;
namespace ResourceEditor
{
public class ResourceItem
{
public ResourceItem(string name, object resourceValue)
{
this.Name = name;
this.ResourceValue = resourceValue;
}
public ResourceItem(string name, object resourceValue, string comment)
{
this.Name = name;
this.ResourceValue = resourceValue;
this.Comment = comment;
}
public string Name { get; set; }
public object ResourceValue { get; set; }
public string Comment { get; set; }
public int ImageIndex
{
get {
if (this.ResourceValue == null) {
return -1;
}
switch(this.ResourceValue.GetType().ToString()) {
case "System.String":
return 0;
case "System.Drawing.Bitmap":
return 1;
case "System.Drawing.Icon":
return 2;
case "System.Windows.Forms.Cursor":
return 3;
case "System.Byte[]":
return 4;
default:
return 5;
}
}
}
public override string ToString()
{
if (ResourceValue == null) {
return "(Nothing/null)";
}
string type = ResourceValue.GetType().FullName;
string tmp = String.Empty;
switch (type) {
case "System.String":
tmp = ResourceValue.ToString();
break;
case "System.Byte[]":
tmp = "[Size = " + ((byte[])ResourceValue).Length + "]";
break;
case "System.Drawing.Bitmap":
Bitmap bmp = ResourceValue as Bitmap;
tmp = "[Width = " + bmp.Size.Width + ", Height = " + bmp.Size.Height + "]";
break;
case "System.Drawing.Icon":
Icon icon = ResourceValue as Icon;
tmp = "[Width = " + icon.Size.Width + ", Height = " + icon.Size.Height + "]";
break;
case "System.Windows.Forms.Cursor":
Cursor c = ResourceValue as Cursor;
tmp = "[Width = " + c.Size.Width + ", Height = " + c.Size.Height + "]";
break;
case "System.Boolean":
tmp = ResourceValue.ToString();
break;
default:
tmp = ResourceValue.ToString();
break;
}
return tmp;
}
public ResXDataNode ToResXDataNode(Func<Type, string> typeNameConverter = null)
{
var node = new ResXDataNode(Name, ResourceValue, typeNameConverter) {
Comment = Comment
};
return node;
}
}
}

317
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/ResourceList.cs

@ -1,317 +0,0 @@ @@ -1,317 +0,0 @@
// 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;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Drawing.Printing;
using System.IO;
using System.Resources;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.Core.WinForms;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Widgets.ListViewSorting;
namespace ResourceEditor
{
/// <summary>
/// This class allows viewing and editing of windows resource files
/// both in XML as in normal format.
/// </summary>
public class ResourceList : ListView
{
ColumnHeader name = new ColumnHeader();
ColumnHeader type = new ColumnHeader();
ColumnHeader content = new ColumnHeader();
ColumnHeader comment = new ColumnHeader();
Dictionary<string, ResourceItem> resources = new Dictionary<string, ResourceItem>();
Dictionary<string, ResourceItem> metadata = new Dictionary<string, ResourceItem>();
ImageList images = new ImageList();
bool writeProtected = false;
int editListViewItemIndex = -1;
ListViewItemSorter sorter;
public event EventHandler Changed;
public bool WriteProtected
{
get {
return writeProtected;
}
set {
writeProtected = value;
}
}
public Dictionary<string, ResourceItem> Resources
{
get {
return resources;
}
}
public PrintDocument PrintDocument
{
get {
return null;
}
}
public bool IsEditing {
get {
return editListViewItemIndex != -1;
}
}
public ResourceList(ResourceEditorControl editor)
{
name.Text = ResourceService.GetString("Global.Name");
name.Width = 250;
type.Text = ResourceService.GetString("ResourceEditor.ResourceEdit.TypeColumn");
type.Width = 170;
content.Text = ResourceService.GetString("ResourceEditor.ResourceEdit.ContentColumn");
content.Width = 300;
comment.Text = ResourceService.GetString("ResourceEditor.ResourceEdit.CommentColumn");
comment.Width = 300;
Columns.AddRange(new ColumnHeader[] {name, type, content, comment});
FullRowSelect = true;
AutoArrange = true;
Alignment = ListViewAlignment.Left;
View = View.Details;
GridLines = true;
LabelEdit = true;
Dock = DockStyle.Fill;
HideSelection = false;
BorderStyle = System.Windows.Forms.BorderStyle.None;
images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.string"));
images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.bmp"));
images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.icon"));
images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.cursor"));
images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.bin"));
images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.obj"));
SmallImageList = images;
// Set up sorting:
// User can sort the list by name and by type,
// whereas sorting by type also implicitly sorts by name.
IListViewItemComparer textComparer = new ListViewTextColumnComparer();
IListViewItemComparer typeNameComparer = new ListViewMultipleColumnsComparer(textComparer, 1, textComparer, 0);
sorter = new ListViewItemSorter(this,
new IListViewItemComparer[] {
textComparer,
typeNameComparer,
null,
null
});
sorter.SortColumnIndex = 0;
sorter.SortOrder = SortOrder.Ascending;
ContextMenuStrip = MenuService.CreateContextMenu(editor, "/SharpDevelop/ResourceEditor/ResourceList/ContextMenu");
}
protected override void Dispose(bool disposing)
{
try {
if (disposing) {
if (sorter != null) {
sorter.Dispose();
sorter = null;
}
}
} finally {
base.Dispose(disposing);
}
}
public void LoadFile(FileName filename, Stream stream)
{
resources.Clear();
metadata.Clear();
switch (Path.GetExtension(filename).ToLowerInvariant()) {
case ".resx":
ResXResourceReader rx = new ResXResourceReader(stream);
ITypeResolutionService typeResolver = null;
rx.BasePath = Path.GetDirectoryName(filename);
rx.UseResXDataNodes = true;
IDictionaryEnumerator n = rx.GetEnumerator();
while (n.MoveNext()) {
if (!resources.ContainsKey(n.Key.ToString())) {
ResXDataNode node = (ResXDataNode)n.Value;
resources.Add(n.Key.ToString(), new ResourceItem(node.Name, node.GetValue(typeResolver), node.Comment));
}
}
n = rx.GetMetadataEnumerator();
while (n.MoveNext()) {
if (!metadata.ContainsKey(n.Key.ToString())) {
ResXDataNode node = (ResXDataNode)n.Value;
metadata.Add(n.Key.ToString(), new ResourceItem(node.Name, node.GetValue(typeResolver)));
}
}
rx.Close();
break;
case ".resources":
ResourceReader rr=null;
try {
rr = new ResourceReader(stream);
foreach (DictionaryEntry entry in rr) {
if (!resources.ContainsKey(entry.Key.ToString()))
resources.Add(entry.Key.ToString(), new ResourceItem(entry.Key.ToString(), entry.Value));
}
}
finally {
if (rr != null) {
rr.Close();
}
}
break;
}
InitializeListView();
}
public void SaveFile(FileName filename, Stream stream)
{
switch (Path.GetExtension(filename).ToLowerInvariant()) {
case ".resx":
// write XML resource
ResXResourceWriter rxw = new ResXResourceWriter(stream, t => ResXConverter.ConvertTypeName(t, filename));
foreach (KeyValuePair<string, ResourceItem> entry in resources) {
if (entry.Value != null) {
ResourceItem item = entry.Value;
rxw.AddResource(item.ToResXDataNode(t => ResXConverter.ConvertTypeName(t, filename)));
}
}
foreach (KeyValuePair<string, ResourceItem> entry in metadata) {
if (entry.Value != null) {
ResourceItem item = entry.Value;
rxw.AddMetadata(item.Name, item.ResourceValue);
}
}
rxw.Generate();
rxw.Close();
break;
default:
// write default resource
ResourceWriter rw = new ResourceWriter(stream);
foreach (KeyValuePair<string, ResourceItem> entry in resources) {
ResourceItem item = (ResourceItem)entry.Value;
rw.AddResource(item.Name, item.ResourceValue);
}
rw.Generate();
rw.Close();
break;
}
}
public void SetResourceValue(string resourceName, object resourceValue)
{
ResourceItem item = ((ResourceItem)Resources[resourceName]);
item.ResourceValue = resourceValue;
SelectedItems[0].SubItems[2].Text = item.ToString();
OnChanged();
}
public void SetCommentValue(string resourceName, string commentValue)
{
ResourceItem item = ((ResourceItem)Resources[resourceName]);
item.Comment = commentValue;
SelectedItems[0].SubItems[3].Text = item.Comment;
OnChanged();
}
public void OnChanged()
{
if (Changed != null) {
Changed(this, null);
}
}
public void InitializeListView()
{
BeginUpdate();
// Suspend sorting to improve performance
ListViewItemSorter = null;
Items.Clear();
foreach (KeyValuePair<string, ResourceItem> entry in resources) {
ResourceItem item = entry.Value;
string tmp = item.ToString();
string type = item.ResourceValue == null ? "(Nothing/null)" : item.ResourceValue.GetType().FullName;
ListViewItem lv = new ListViewItem(new String[] {item.Name, type, tmp, item.Comment}, item.ImageIndex);
Items.Add(lv);
}
ListViewItemSorter = sorter;
EndUpdate();
}
protected override void OnAfterLabelEdit(LabelEditEventArgs e)
{
editListViewItemIndex = -1;
if (writeProtected) {
e.CancelEdit = true;
return;
}
string oldName = this.Items[e.Item].Text;
string newName = e.Label;
if(newName == null) {
// no change
return;
}
ResourceItem item = (ResourceItem)resources[oldName];
if(resources.ContainsKey(newName)) {
MessageService.ShowWarning("${res:ResourceEditor.ResourceList.KeyAlreadyDefinedWarning}");
e.CancelEdit = true;
return;
}
resources.Remove(oldName);
item.Name = newName;
resources.Add(newName, item);
OnChanged();
}
protected override void OnBeforeLabelEdit(LabelEditEventArgs e)
{
base.OnBeforeLabelEdit(e);
if (!e.CancelEdit) {
editListViewItemIndex = e.Item;
}
}
}
}

70
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/TextView.cs

@ -1,70 +0,0 @@ @@ -1,70 +0,0 @@
// 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.Windows.Forms;
namespace ResourceEditor
{
class TextView : TextBox, IResourceView
{
public event ResourceChangedEventHandler ResourceChanged;
private ResourceItem resourceItem;
public TextView(ResourceItem item)
{
this.Multiline = true;
this.ResourceItem = item;
this.ScrollBars = ScrollBars.Both;
this.TextChanged += new EventHandler(textChanged);
}
public bool WriteProtected
{
get {
return ! Enabled;
}
set {
Enabled = ! value;
}
}
public ResourceItem ResourceItem
{
get {
return resourceItem;
}
set {
resourceItem = value;
Text = (string)value.ResourceValue;
}
}
protected void OnResourceChanged(string resourceName, object val)
{
if(ResourceChanged != null) {
ResourceChanged(this, new ResourceEventArgs(resourceName, val));
}
}
void textChanged(object sender, EventArgs e)
{
OnResourceChanged(resourceItem.Name, Text);
}
}
}

13
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEditorDisplayBinding.cs

@ -66,16 +66,14 @@ namespace ResourceEditor @@ -66,16 +66,14 @@ namespace ResourceEditor
resourceEditor.View = resourceEditorView;
// Register different resource item viewers
resourceEditor.AddItemView(ResourceItemEditorType.String, new Views.TextView());
resourceEditor.AddItemView(ResourceItemEditorType.Bitmap, new Views.ImageViewBase());
resourceEditor.AddItemView(ResourceItemEditorType.String, new TextView());
resourceEditor.AddItemView(ResourceItemEditorType.Bitmap, new ImageViewBase());
resourceEditor.DirtyStateChanged += (sender, e) => {
if (e.IsDirty)
SetDirty(sender, new EventArgs());
};
UserContent = resourceEditorView;
// resourceEditor.ResourceList.Changed += SetDirty;
// resourceEditor.ResourceList.ItemSelectionChanged += (sender, e) => SD.WinForms.InvalidateCommands();
this.Files.Add(file);
}
@ -92,13 +90,6 @@ namespace ResourceEditor @@ -92,13 +90,6 @@ namespace ResourceEditor
void SetDirty(object sender, EventArgs e)
{
PrimaryFile.MakeDirty();
// SD.WinForms.InvalidateCommands();
}
public override void Dispose()
{
base.Dispose();
// resourceEditor.Dispose();
}
protected override void LoadInternal(OpenedFile file, Stream stream)

12
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); }
}
@ -139,7 +139,7 @@ namespace ResourceEditor.ViewModels @@ -139,7 +139,7 @@ namespace ResourceEditor.ViewModels
view.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, (s, e) => SelectAll(), (s, e) => e.CanExecute = EnableSelectAll));
view.FilterPredicate = resourceItem => {
if (SearchTerm != null)
if (!resourceItem.IsNew && (SearchTerm != null))
return resourceItem.Name.IndexOf(SearchTerm, StringComparison.OrdinalIgnoreCase) >= 0;
return true;
};
@ -275,13 +275,13 @@ namespace ResourceEditor.ViewModels @@ -275,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)));
}
@ -407,12 +407,12 @@ namespace ResourceEditor.ViewModels @@ -407,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;

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

@ -72,6 +72,15 @@ namespace ResourceEditor.ViewModels @@ -72,6 +72,15 @@ namespace ResourceEditor.ViewModels
set { SetValue(NameProperty, value); }
}
public static readonly DependencyProperty SortingCriteriaProperty =
DependencyProperty.Register("SortingCriteria", typeof(string), typeof(ResourceItem),
new FrameworkPropertyMetadata());
public string SortingCriteria {
get { return (string)GetValue(SortingCriteriaProperty); }
set { SetValue(SortingCriteriaProperty, value); }
}
public static readonly DependencyProperty ResourceValueProperty =
DependencyProperty.Register("ResourceValue", typeof(object), typeof(ResourceItem),
new FrameworkPropertyMetadata());
@ -102,11 +111,16 @@ namespace ResourceEditor.ViewModels @@ -102,11 +111,16 @@ namespace ResourceEditor.ViewModels
set { SetValue(IsEditingProperty, value); }
}
public bool IsNew {
get;
set;
}
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.Property == IsEditingProperty) {
if (e.Property.Name == IsEditingProperty.Name) {
bool previouslyEditing = (bool)e.OldValue;
bool isEditing = (bool)e.NewValue;
if (!previouslyEditing && isEditing) {
@ -117,14 +131,18 @@ namespace ResourceEditor.ViewModels @@ -117,14 +131,18 @@ namespace ResourceEditor.ViewModels
if (nameBeforeEditing != Name) {
// Check if new name is valid
if (!String.IsNullOrEmpty(Name) && !resourceEditor.ContainsResourceName(Name)) {
SortingCriteria = Name;
resourceEditor.MakeDirty();
} else {
// New name was not valid, revert it to the value before editing
Name = nameBeforeEditing;
}
}
IsNew = false;
}
} else {
if (e.Property.Name == NameProperty.Name)
SortingCriteria = Name;
resourceEditor.MakeDirty();
}
}

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

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

11
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml.cs

@ -17,15 +17,8 @@ @@ -17,15 +17,8 @@
// 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;
using System.Windows.Media.Imaging;
using ICSharpCode.SharpDevelop;
using ResourceEditor.ViewModels;
@ -36,7 +29,7 @@ namespace ResourceEditor.Views @@ -36,7 +29,7 @@ namespace ResourceEditor.Views
/// </summary>
public partial class ImageViewBase : UserControl, IResourceItemView
{
ResourceEditor.ViewModels.ResourceItem resourceItem;
ResourceItem resourceItem;
public ImageViewBase()
{
@ -68,7 +61,7 @@ namespace ResourceEditor.Views @@ -68,7 +61,7 @@ namespace ResourceEditor.Views
}
}
public ResourceEditor.ViewModels.ResourceItem ResourceItem {
public ResourceItem ResourceItem {
get {
return resourceItem;
}

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

@ -2,13 +2,13 @@ @@ -2,13 +2,13 @@
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" />
<TextBlock Name="readOnlyTextBlock" Text="{Binding Path=Text, Mode=TwoWay}" VerticalAlignment="Top" Margin="0,0,0,0" />
<TextBox
Name="editingTextBox"
Text="{Binding Text, Mode=TwoWay}"
Text="{Binding Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
VerticalAlignment="Top"
Margin="0,0,0,0"
IsVisibleChanged="EditingTextBox_IsVisibleChanged"
TextChanged="EditingTextBox_TextChanged"
LostFocus="EditingTextBox_LostFocus" />
</Grid>
</UserControl>

42
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml.cs

@ -17,14 +17,9 @@ @@ -17,14 +17,9 @@
// 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
{
@ -34,6 +29,7 @@ namespace ResourceEditor.Views @@ -34,6 +29,7 @@ namespace ResourceEditor.Views
public partial class InPlaceEditLabel : UserControl
{
string textBeforeEditing;
bool selectAllText;
public InPlaceEditLabel()
{
@ -66,13 +62,19 @@ namespace ResourceEditor.Views @@ -66,13 +62,19 @@ namespace ResourceEditor.Views
{
base.OnPropertyChanged(e);
if (e.Property == IsEditingProperty) {
if (e.Property.Name == IsEditingProperty.Name) {
if ((bool)e.NewValue) {
editingTextBox.Visibility = Visibility.Visible;
readOnlyTextBlock.Visibility = Visibility.Collapsed;
editingTextBox.Focus();
textBeforeEditing = this.Text;
editingTextBox.SelectAll();
if (editingTextBox.Text == this.Text) {
SelectAllText();
} else {
// This is a workaround for the case when TextBox.Text property is updated after this code,
// so we can still select everything as soon as Text property is updated.
selectAllText = true;
}
} else {
editingTextBox.Visibility = Visibility.Collapsed;
readOnlyTextBlock.Visibility = Visibility.Visible;
@ -80,6 +82,20 @@ namespace ResourceEditor.Views @@ -80,6 +82,20 @@ namespace ResourceEditor.Views
}
}
void EditingTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (selectAllText) {
SelectAllText();
selectAllText = false;
}
}
void SelectAllText()
{
editingTextBox.Focus();
editingTextBox.SelectAll();
}
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
@ -93,16 +109,6 @@ namespace ResourceEditor.Views @@ -93,16 +109,6 @@ namespace ResourceEditor.Views
}
}
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

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

@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
Source="{Binding ResourceItems}"
Filter="CollectionViewSource_Filter">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Name"/>
<scm:SortDescription PropertyName="SortingCriteria"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
@ -62,11 +62,11 @@ @@ -62,11 +62,11 @@
</Image.Style>
</Image>
<resv:InPlaceEditLabel Grid.Column="1"
Text="{Binding Name, Mode=TwoWay}"
Text="{Binding Path=Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
VerticalAlignment="Top"
Margin="0,0,0,0"
MinWidth="300"
IsEditing="{Binding IsEditing, Mode=TwoWay}">
IsEditing="{Binding Path=IsEditing, Mode=TwoWay}">
</resv:InPlaceEditLabel>
</Grid>
</Border>

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

@ -28,70 +28,6 @@ using ResourceEditor.ViewModels; @@ -28,70 +28,6 @@ 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>
@ -123,7 +59,7 @@ namespace ResourceEditor.Views @@ -123,7 +59,7 @@ namespace ResourceEditor.Views
resourceItemViewGrid.Children.Add(view.UIControl);
}
public Predicate<ResourceEditor.ViewModels.ResourceItem> FilterPredicate {
public Predicate<ResourceItem> FilterPredicate {
get;
set;
}
@ -148,7 +84,7 @@ namespace ResourceEditor.Views @@ -148,7 +84,7 @@ namespace ResourceEditor.Views
return;
}
var resourceItem = e.Item as ResourceEditor.ViewModels.ResourceItem;
var resourceItem = e.Item as ResourceItem;
if (resourceItem == null) {
// Away with non-ResourceItems (shouldn't happen anyway)
e.Accepted = false;
@ -182,15 +118,6 @@ namespace ResourceEditor.Views @@ -182,15 +118,6 @@ namespace ResourceEditor.Views
void ResourceItemsListView_KeyUp(object sender, KeyEventArgs e)
{
/*if (e.Key == Key.Enter) {
if (EditingFinished != null) {
EditingFinished(this, new EventArgs());
}
} else if (e.Key == Key.Escape) {
if (EditingCancelled != null) {
EditingCancelled(this, new EventArgs());
}
} else*/
if (e.Key == Key.F2) {
if (EditingStarted != null) {
EditingStarted(this, new EventArgs());

Loading…
Cancel
Save