Browse Source

Merged WPF port of ResourceEditor addin for issue #539.

pull/517/head
Andreas Weizel 12 years ago
parent
commit
91a697da68
  1. 32
      src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.addin
  2. 75
      src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj
  3. 50
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/BitmapExtensions.cs
  4. 98
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs
  5. 36
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs
  6. 15
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs
  7. 24
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs
  8. 15
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs
  9. 107
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/ResourceItemCommand.cs
  10. 81
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs
  11. 213
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEditorDisplayBinding.cs
  12. 481
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs
  13. 245
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs
  14. 7
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BinaryView.xaml
  15. 41
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BinaryView.xaml.cs
  16. 7
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BooleanView.xaml
  17. 41
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BooleanView.xaml.cs
  18. 58
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/IResourceEditorView.cs
  19. 21
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/IResourceItemView.cs
  20. 19
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml
  21. 101
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml.cs
  22. 14
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml
  23. 112
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml.cs
  24. 159
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml
  25. 203
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml.cs
  26. 76
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceItemIcons.cs
  27. 12
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/TextView.xaml
  28. 56
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/TextView.xaml.cs

32
src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.addin

@ -30,30 +30,28 @@
<Path name="/SharpDevelop/ResourceEditor/ResourceList/ContextMenu"> <Path name="/SharpDevelop/ResourceEditor/ResourceList/ContextMenu">
<MenuItem id="AddStringEntry" <MenuItem id="AddStringEntry"
label="${res:ResourceEditor.ResourceEdit.ContextMenu.AddStringEntry}" label="${res:ResourceEditor.ResourceEdit.ContextMenu.AddStringEntry}"
class="ResourceEditor.AddStringCommand" class="ResourceEditor.Commands.AddStringCommand"
shortcut = "Insert" /> shortcut = "Insert" />
<MenuItem id="AddFile" <MenuItem id="AddFile"
label="${res:ResourceEditor.ResourceEdit.ContextMenu.AddFiles}" label="${res:ResourceEditor.ResourceEdit.ContextMenu.AddFiles}"
class="ResourceEditor.AddNewFileCommand" /> class="ResourceEditor.Commands.AddNewFileCommand" />
<MenuItem id="Separator1" <MenuItem id="Separator1"
type = "Separator" /> type = "Separator" />
<Condition name = "Ownerstate" ownerstate="ItemsSelected" action="Disable"> <MenuItem id="SaveAs"
<MenuItem id="SaveAs" label="${res:XML.MainMenu.FileMenu.SaveAs}"
label="${res:XML.MainMenu.FileMenu.SaveAs}" class="ResourceEditor.Commands.SaveEntryAsCommand" />
class="ResourceEditor.SaveEntryAsCommand" /> <MenuItem id="Rename"
<MenuItem id="Rename" label="${res:ResourceEditor.ResourceEdit.ContextMenu.Rename}"
label="${res:ResourceEditor.ResourceEdit.ContextMenu.Rename}" class="ResourceEditor.Commands.RenameEntryCommand"
class="ResourceEditor.RenameEntryCommand" shortcut="F2" />
shortcut="F2" /> <MenuItem id="CopyResourceName"
<MenuItem id="CopyResourceName" label="${res:ResourceEditor.ResourceEdit.ContextMenu.CopyResourceName}"
label="${res:ResourceEditor.ResourceEdit.ContextMenu.CopyResourceName}" class="ResourceEditor.Commands.CopyResourceNameCommand" />
class="ResourceEditor.CopyResourceNameCommand" /> <MenuItem id="EditResourceComment"
<MenuItem id="EditResourceComment" label="${res:ResourceEditor.ResourceEdit.ContextMenu.EditComment}"
label="${res:ResourceEditor.ResourceEdit.ContextMenu.EditComment}" class="ResourceEditor.Commands.EditCommentCommand" />
class="ResourceEditor.EditCommentCommand" />
</Condition>
<Include id = "Delete" item = "/SharpDevelop/Workbench/MainMenu/Edit/Delete"/> <Include id = "Delete" item = "/SharpDevelop/Workbench/MainMenu/Edit/Delete"/>
<MenuItem id = "Separator2" type = "Separator"/> <MenuItem id = "Separator2" type = "Separator"/>

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

@ -40,49 +40,60 @@
<OutputPath>..\..\..\..\..\AddIns\DisplayBindings\ResourceEditor\</OutputPath> <OutputPath>..\..\..\..\..\AddIns\DisplayBindings\ResourceEditor\</OutputPath>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="PresentationCore">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="PresentationFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Design" /> <Reference Include="System.Design" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Configuration\AssemblyInfo.cs" /> <Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\BitmapExtensions.cs" />
<Compile Include="Src\Commands\AddNewFileCommand.cs" /> <Compile Include="Src\Commands\AddNewFileCommand.cs" />
<Compile Include="Src\Commands\AddStringEntryCommand.cs" /> <Compile Include="Src\Commands\AddStringEntryCommand.cs" />
<Compile Include="Src\Commands\ClipboardCommands.cs" />
<Compile Include="Src\Commands\CopyResourceNameCommand.cs" /> <Compile Include="Src\Commands\CopyResourceNameCommand.cs" />
<Compile Include="Src\Commands\EditCommentCommand.cs" /> <Compile Include="Src\Commands\EditCommentCommand.cs" />
<Compile Include="Src\Commands\RenameEntryCommand.cs" /> <Compile Include="Src\Commands\RenameEntryCommand.cs" />
<Compile Include="Src\Commands\ResourceItemCommand.cs" />
<Compile Include="Src\Commands\SaveEntryAsCommand.cs" /> <Compile Include="Src\Commands\SaveEntryAsCommand.cs" />
<Compile Include="Src\ResourceEditorDisplayBinding.cs" /> <Compile Include="Src\ResourceEditorDisplayBinding.cs" />
<Compile Include="Src\ResourceEdit\AbstractImageView.cs"> <Compile Include="Src\ViewModels\ResourceEditorViewModel.cs" />
<SubType>Component</SubType> <Compile Include="Src\ViewModels\ResourceItem.cs" />
<Compile Include="Src\Views\BinaryView.xaml.cs">
<DependentUpon>BinaryView.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Src\ResourceEdit\BinaryView.cs"> <Compile Include="Src\Views\BooleanView.xaml.cs">
<SubType>UserControl</SubType> <DependentUpon>BooleanView.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Src\ResourceEdit\BitmapView.cs"> <Compile Include="Src\Views\ImageViewBase.xaml.cs">
<SubType>Component</SubType> <DependentUpon>ImageViewBase.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Src\ResourceEdit\BooleanView.cs"> <Compile Include="Src\Views\InPlaceEditLabel.xaml.cs">
<SubType>Component</SubType> <DependentUpon>InPlaceEditLabel.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Src\ResourceEdit\CursorView.cs"> <Compile Include="Src\Views\IResourceEditorView.cs" />
<SubType>Component</SubType> <Compile Include="Src\Views\IResourceItemView.cs" />
<Compile Include="Src\Views\ResourceEditorView.xaml.cs">
<DependentUpon>ResourceEditorView.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Src\ResourceEdit\IconView.cs"> <Compile Include="Src\Views\ResourceItemIcons.cs" />
<SubType>Component</SubType> <Compile Include="Src\Views\TextView.xaml.cs">
</Compile> <DependentUpon>TextView.xaml</DependentUpon>
<Compile Include="Src\ResourceEdit\IResourceView.cs" /> <SubType>Code</SubType>
<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>
<None Include="ResourceEditor.addin"> <None Include="ResourceEditor.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
@ -108,6 +119,10 @@
<Name>ICSharpCode.Core</Name> <Name>ICSharpCode.Core</Name>
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.Core.Presentation\ICSharpCode.Core.Presentation.csproj">
<Project>{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}</Project>
<Name>ICSharpCode.Core.Presentation</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.Core.WinForms\ICSharpCode.Core.WinForms.csproj"> <ProjectReference Include="..\..\..\..\Main\ICSharpCode.Core.WinForms\ICSharpCode.Core.WinForms.csproj">
<Project>{857CA1A3-FC88-4BE0-AB6A-D1EE772AB288}</Project> <Project>{857CA1A3-FC88-4BE0-AB6A-D1EE772AB288}</Project>
<Name>ICSharpCode.Core.WinForms</Name> <Name>ICSharpCode.Core.WinForms</Name>
@ -119,5 +134,17 @@
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Src\ViewModels" />
<Folder Include="Src\Views" />
</ItemGroup>
<ItemGroup>
<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>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project> </Project>

50
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/BitmapExtensions.cs

@ -0,0 +1,50 @@
// 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.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
namespace ResourceEditor
{
/// <summary>
/// Bitmap conversion extensions for WinForms -> WPF
/// </summary>
public static class BitmapExtensions
{
[DllImport("gdi32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeleteObject(IntPtr hObject);
public static BitmapSource ToBitmapSource(this System.Drawing.Bitmap bitmap)
{
BitmapSource bs;
IntPtr hBitmap = bitmap.GetHbitmap();
try {
bs = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero,
Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
bs.Freeze();
} finally {
DeleteObject(hBitmap);
}
return bs;
}
}
}

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

@ -17,86 +17,83 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Drawing;
using System.IO; using System.IO;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using Microsoft.Win32;
using ResourceEditor.ViewModels;
namespace ResourceEditor namespace ResourceEditor.Commands
{ {
class AddNewFileCommand : AbstractMenuCommand class AddNewFileCommand : ResourceItemCommand
{ {
public override void Run() public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceItem> resourceItems)
{ {
ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor; // if (editor.ResourceList.WriteProtected) {
// return;
// }
if(editor.ResourceList.WriteProtected) { var editor = ResourceEditor;
return; OpenFileDialog fdiag = new OpenFileDialog();
} fdiag.AddExtension = true;
fdiag.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.AllFiles}|*.*");
using (OpenFileDialog fdiag = new OpenFileDialog()) { fdiag.Multiselect = true;
fdiag.AddExtension = true; fdiag.CheckFileExists = true;
fdiag.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.AllFiles}|*.*");
fdiag.Multiselect = true;
fdiag.CheckFileExists = true;
if (fdiag.ShowDialog(SD.WinForms.MainWin32Window) == DialogResult.OK) { if ((bool)fdiag.ShowDialog()) {
foreach (string filename in fdiag.FileNames) { foreach (string filename in fdiag.FileNames) {
string oresname = Path.ChangeExtension(Path.GetFileName(filename), null); string oresname = Path.ChangeExtension(Path.GetFileName(filename), null);
if (oresname == "") oresname = "new"; if (oresname == "")
oresname = "new";
string resname = oresname; string resname = oresname;
int i = 0; int i = 0;
TestName: TestName:
if (editor.ResourceList.Resources.ContainsKey(resname)) { if (editor.ContainsResourceName(resname)) {
if (i == 10) { if (i == 10) {
continue;
}
i++;
resname = oresname + "_" + i.ToString();
goto TestName;
}
object tmp = loadResource(filename);
if (tmp == null) {
continue; continue;
} }
editor.ResourceList.Resources.Add(resname, new ResourceItem(resname, tmp)); i++;
resname = oresname + "_" + i;
goto TestName;
}
object tmp = LoadResource(filename);
if (tmp == null) {
continue;
} }
editor.ResourceList.InitializeListView(); editor.ResourceItems.Add(new ResourceItem(editor, resname, tmp));
} }
} }
editor.ResourceList.OnChanged();
} }
object loadResource(string name) object LoadResource(string name)
{ {
switch (Path.GetExtension(name).ToUpperInvariant()) { switch (Path.GetExtension(name).ToUpperInvariant()) {
case ".CUR": case ".CUR":
try { try {
return new Cursor(name); return new System.Windows.Forms.Cursor(name);
} catch { } catch {
return null; return null;
} }
case ".ICO": case ".ICO":
try { try {
return new Icon(name); return new System.Drawing.Icon(name);
} catch { } catch {
return null; return null;
} }
default: default:
// try to read a bitmap // Try to read a bitmap
try { try {
return new Bitmap(name); return new System.Drawing.Bitmap(name);
} catch {} } catch {
}
// try to read a serialized object // Try to read a serialized object
try { try {
Stream r = File.Open(name, FileMode.Open); Stream r = File.Open(name, FileMode.Open);
try { try {
@ -104,20 +101,21 @@ namespace ResourceEditor
object o = c.Deserialize(r); object o = c.Deserialize(r);
r.Close(); r.Close();
return o; return o;
} catch { r.Close(); } } catch {
} catch { } r.Close();
}
} catch {
}
// try to read a byte array :) // Try to read a byte array
try { try {
FileStream s = new FileStream(name, FileMode.Open); FileStream s = new FileStream(name, FileMode.Open);
BinaryReader r = new BinaryReader(s); BinaryReader r = new BinaryReader(s);
Byte[] d = new Byte[(int) s.Length]; Byte[] d = new Byte[(int)s.Length];
d = r.ReadBytes((int) s.Length); d = r.ReadBytes((int)s.Length);
s.Close(); s.Close();
return d; return d;
} catch(Exception) { } catch (Exception) {
string message = ResourceService.GetString("ResourceEditor.Messages.CantLoadResource"); string message = ResourceService.GetString("ResourceEditor.Messages.CantLoadResource");
MessageService.ShowWarning(message + " " + name + "."); MessageService.ShowWarning(message + " " + name + ".");
} }

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

@ -20,35 +20,33 @@ using System;
using System.Windows.Forms; using System.Windows.Forms;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ResourceEditor.ViewModels;
namespace ResourceEditor namespace ResourceEditor.Commands
{ {
class AddStringCommand : AbstractMenuCommand class AddStringCommand : ResourceItemCommand
{ {
public override void Run() public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{ {
ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor; // if(editor.ResourceList.WriteProtected) {
// return;
if(editor.ResourceList.WriteProtected) { // }
return; //
} var editor = ResourceEditor;
int count = 1; int count = 1;
string newNameBase = " new string entry "; string newNameBase = " new string entry ";
string newName = newNameBase + count.ToString(); string newName = newNameBase + count;
string type = "System.String";
while(editor.ResourceList.Resources.ContainsKey(newName)) { while (editor.ContainsResourceName(newName)) {
count++; count++;
newName = newNameBase + count.ToString(); newName = newNameBase + count;
} }
ResourceItem item = new ResourceItem(newName, ""); ResourceItem item = new ResourceItem(editor, newName, "");
editor.ResourceList.Resources.Add(newName, item); editor.ResourceItems.Add(item);
ListViewItem lv = new ListViewItem(new string[] { newName, type, "" }, item.ImageIndex); editor.SelectedItems.Clear();
editor.ResourceList.Items.Add(lv); editor.SelectedItems.Add(item);
editor.ResourceList.OnChanged(); editor.StartEditing();
lv.BeginEdit();
} }
} }
} }

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

@ -17,21 +17,22 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ResourceEditor.ViewModels;
namespace ResourceEditor namespace ResourceEditor.Commands
{ {
class CopyResourceNameCommand : AbstractMenuCommand class CopyResourceNameCommand : ResourceItemCommand
{ {
public override void Run() public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{ {
ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor; var firstSelectedItem = resourceItems.First();
if (firstSelectedItem != null) {
if(editor.ResourceList.SelectedItems.Count > 0) { Clipboard.SetText(firstSelectedItem.Name);
Clipboard.SetText(editor.ResourceList.SelectedItems[0].Text);
} }
} }
} }

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

@ -17,25 +17,23 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Linq;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ResourceEditor.ViewModels;
namespace ResourceEditor namespace ResourceEditor.Commands
{ {
class EditCommentCommand : AbstractMenuCommand class EditCommentCommand : ResourceItemCommand
{ {
public override void Run() public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{ {
ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor; var selectedItem = resourceItems.First();
if (editor.ResourceList.SelectedItems.Count != 0) { string newValue = SD.MessageService.ShowInputBox("${res:ResourceEditor.ResourceEdit.ContextMenu.EditComment}",
var item = editor.ResourceList.SelectedItems[0].SubItems[3]; "${res:ResourceEditor.ResourceEdit.ContextMenu.EditCommentText}",
string resourceName = editor.ResourceList.SelectedItems[0].Text; selectedItem.Comment);
string newValue = SD.MessageService.ShowInputBox("${res:ResourceEditor.ResourceEdit.ContextMenu.EditComment}", if (newValue != null && newValue != selectedItem.Comment) {
"${res:ResourceEditor.ResourceEdit.ContextMenu.EditCommentText}", selectedItem.Comment = newValue;
item.Text);
if (newValue != null && newValue != item.Text) {
editor.ResourceList.SetCommentValue(resourceName, newValue);
}
} }
} }
} }

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

@ -19,18 +19,17 @@
using System; using System;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ResourceEditor.ViewModels;
namespace ResourceEditor namespace ResourceEditor.Commands
{ {
class RenameEntryCommand : AbstractMenuCommand class RenameEntryCommand : ResourceItemCommand
{ {
public override void Run() public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{ {
ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor; var editor = ResourceEditor;
if (editor != null)
if(editor.ResourceList.SelectedItems.Count != 0) { editor.StartEditing();
editor.ResourceList.SelectedItems[0].BeginEdit();
}
} }
} }
} }

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

@ -0,0 +1,107 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.SharpDevelop;
using ResourceEditor.ViewModels;
namespace ResourceEditor.Commands
{
/// <summary>
/// Represents a <see cref="ResourceEditor.ViewModels.ResourceItem"/>-related command.
/// </summary>
public class ResourceItemCommand : SimpleCommand
{
/// <summary>
/// Defines whether this command supports multiselection of items.
/// If not, command will be disabled by default, when more than 1 item is selected.
/// </summary>
public virtual bool SupportsMultiSelections {
get {
return false;
}
}
/// <summary>
/// Returns list of resource item types for which this command may be enabled or <c>null</c> to allow any type.
/// </summary>
public virtual IEnumerable<ResourceItemEditorType> AllowedTypes {
get {
return null;
}
}
public override bool CanExecute(object parameter)
{
if (ResourceEditor == null)
return false;
var selectedResourceItems = GetSelectedItems();
if (!selectedResourceItems.Any())
return false;
if (!SupportsMultiSelections && (selectedResourceItems.Count() > 1))
return false;
return CanExecuteWithResourceItems(selectedResourceItems);
}
/// <summary>
/// Checks whether this command can be executed for the current set of selected resource items.
/// </summary>
/// <param name="resourceItems">List of selected resource items. Will always contain at least one element.</param>
/// <returns><c>True</c>, when command can be executed, <c>false</c> otherwise.</returns>
public virtual bool CanExecuteWithResourceItems(IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{
return true;
}
public override void Execute(object parameter)
{
var selectedResourceItems = GetSelectedItems();
if (!selectedResourceItems.Any())
return;
if (!SupportsMultiSelections && (selectedResourceItems.Count() > 1))
return;
ExecuteWithResourceItems(selectedResourceItems);
}
/// <summary>
/// Executes command for the given set of selected resource items.
/// </summary>
/// <param name="resourceItems">List of selected resource items. Will always contain at least one element.</param>
public virtual void ExecuteWithResourceItems(IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{
}
public ResourceEditorViewModel ResourceEditor {
get {
return ((ResourceEditViewContent) SD.Workbench.ActiveViewContent).ResourceEditor;
}
}
IEnumerable<ResourceEditor.ViewModels.ResourceItem> GetSelectedItems()
{
var editor = ResourceEditor;
if (editor != null)
return editor.SelectedItems.OfType<ResourceEditor.ViewModels.ResourceItem>() ?? new ResourceEditor.ViewModels.ResourceItem[0];
return new ResourceEditor.ViewModels.ResourceItem[0];
}
}
}

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

@ -19,73 +19,74 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Windows.Forms;
using System.Linq;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using Microsoft.Win32;
using ResourceEditor.ViewModels;
namespace ResourceEditor namespace ResourceEditor.Commands
{ {
class SaveEntryAsCommand : AbstractMenuCommand class SaveEntryAsCommand : ResourceItemCommand
{ {
public override void Run() public override System.Collections.Generic.IEnumerable<ResourceItemEditorType> AllowedTypes {
{ get {
ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor; return new ResourceItemEditorType[] {
ResourceList list = editor.ResourceList; ResourceItemEditorType.Bitmap,
ResourceItemEditorType.Icon,
if(list.SelectedItems.Count != 1) { ResourceItemEditorType.Cursor,
return; ResourceItemEditorType.Binary
} };
string key = list.SelectedItems[0].Text;
if(! list.Resources.ContainsKey(key)) {
return;
} }
}
public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{
var firstSelectedItem = resourceItems.First();
ResourceItem item = list.Resources[key]; var sdialog = new Microsoft.Win32.SaveFileDialog();
SaveFileDialog sdialog = new SaveFileDialog();
sdialog.AddExtension = true; sdialog.AddExtension = true;
sdialog.FileName = key; sdialog.FileName = firstSelectedItem.Name;
if (item.ResourceValue is Bitmap) { if (firstSelectedItem.ResourceValue is System.Drawing.Bitmap) {
sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.ImageFiles} (*.png)|*.png"); sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.ImageFiles} (*.png)|*.png");
sdialog.DefaultExt = ".png"; sdialog.DefaultExt = ".png";
} else if (item.ResourceValue is Icon) { } else if (firstSelectedItem.ResourceValue is System.Drawing.Icon) {
sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.Icons}|*.ico"); sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.Icons}|*.ico");
sdialog.DefaultExt = ".ico"; sdialog.DefaultExt = ".ico";
} else if (item.ResourceValue is Cursor) { } else if (firstSelectedItem.ResourceValue is System.Windows.Forms.Cursor) {
sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.CursorFiles} (*.cur)|*.cur"); sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.CursorFiles} (*.cur)|*.cur");
sdialog.DefaultExt = ".cur"; sdialog.DefaultExt = ".cur";
} else if (item.ResourceValue is byte[]){ } else if (firstSelectedItem.ResourceValue is byte[]) {
sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.BinaryFiles} (*.*)|*.*"); sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.BinaryFiles} (*.*)|*.*");
sdialog.DefaultExt = ".bin"; sdialog.DefaultExt = ".bin";
} else { } else {
return; return;
} }
DialogResult dr = sdialog.ShowDialog(SD.WinForms.MainWin32Window); bool? dr = sdialog.ShowDialog();
sdialog.Dispose(); if (!dr.HasValue || !dr.Value) {
if (dr != DialogResult.OK) {
return; return;
} }
try { try {
if (item.ResourceValue is Icon) { if (firstSelectedItem.ResourceValue is Icon) {
FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create); FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create);
((Icon)item.ResourceValue).Save(fstr); ((Icon) firstSelectedItem.ResourceValue).Save(fstr);
fstr.Close(); fstr.Close();
} else if(item.ResourceValue is Image) { } else if (firstSelectedItem.ResourceValue is Image) {
Image img = (Image)item.ResourceValue; Image img = (Image) firstSelectedItem.ResourceValue;
img.Save(sdialog.FileName); img.Save(sdialog.FileName);
} else { } else {
FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create); FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create);
BinaryWriter wr = new BinaryWriter(fstr); BinaryWriter wr = new BinaryWriter(fstr);
wr.Write((byte[])item.ResourceValue); wr.Write((byte[]) firstSelectedItem.ResourceValue);
fstr.Close(); fstr.Close();
} }
} catch(Exception ex) { } catch (Exception ex) {
MessageBox.Show(ex.Message, "Can't save resource to " + sdialog.FileName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); SD.MessageService.ShowWarning("Can't save resource to " + sdialog.FileName + ": " + ex.Message);
} }
} }
} }

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

@ -27,6 +27,8 @@ using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.WinForms; using ICSharpCode.SharpDevelop.WinForms;
using ICSharpCode.SharpDevelop.Workbench; using ICSharpCode.SharpDevelop.Workbench;
using ResourceEditor.ViewModels;
using ResourceEditor.Views;
namespace ResourceEditor namespace ResourceEditor
{ {
@ -39,7 +41,7 @@ namespace ResourceEditor
public IViewContent CreateContentForFile(OpenedFile file) public IViewContent CreateContentForFile(OpenedFile file)
{ {
return new ResourceEditWrapper(file); return new ResourceEditViewContent(file);
} }
public bool IsPreferredBindingForFile(FileName fileName) public bool IsPreferredBindingForFile(FileName fileName)
@ -53,211 +55,60 @@ namespace ResourceEditor
} }
} }
public class ResourceEditWrapper : AbstractViewContentHandlingLoadErrors, IClipboardHandler public class ResourceEditViewContent : AbstractViewContentHandlingLoadErrors
{ {
ResourceEditorControl resourceEditor = new ResourceEditorControl(); readonly ResourceEditorViewModel resourceEditor = new ResourceEditorViewModel();
readonly ResourceEditorView resourceEditorView = new ResourceEditorView();
public ResourceEditorControl ResourceEditor { public ResourceEditViewContent(OpenedFile file)
get { return resourceEditor; } {
this.TabPageText = "Resource editor";
resourceEditor.View = resourceEditorView;
// Register different resource item viewers
resourceEditor.AddItemView(ResourceItemEditorType.String, new Views.TextView());
resourceEditor.AddItemView(ResourceItemEditorType.Bitmap, new Views.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);
} }
public ResourceEditorViewModel ResourceEditor {
get { return resourceEditor; }
}
public override bool IsReadOnly { public override bool IsReadOnly {
get { get {
return false; return false;
} }
} }
void SetDirty(object sender, EventArgs e) void SetDirty(object sender, EventArgs e)
{ {
PrimaryFile.MakeDirty(); PrimaryFile.MakeDirty();
SD.WinForms.InvalidateCommands(); // SD.WinForms.InvalidateCommands();
}
public ResourceEditWrapper(OpenedFile file)
{
this.TabPageText = "Resource editor";
UserContent = resourceEditor;
resourceEditor.ResourceList.Changed += SetDirty;
resourceEditor.ResourceList.ItemSelectionChanged += (sender, e) => SD.WinForms.InvalidateCommands();
this.Files.Add(file);
} }
public override void Dispose() public override void Dispose()
{ {
base.Dispose(); base.Dispose();
resourceEditor.Dispose(); // resourceEditor.Dispose();
} }
protected override void LoadInternal(OpenedFile file, Stream stream) protected override void LoadInternal(OpenedFile file, Stream stream)
{ {
resourceEditor.ResourceList.LoadFile(file.FileName, stream); resourceEditor.LoadFile(file.FileName, stream);
} }
protected override void SaveInternal(OpenedFile file, Stream stream) protected override void SaveInternal(OpenedFile file, Stream stream)
{ {
resourceEditor.ResourceList.SaveFile(file.FileName, stream); resourceEditor.SaveFile(file.FileName, stream);
}
public bool EnableCut
{
get {
if (resourceEditor.ResourceList.IsEditing) {
return false;
}
return resourceEditor.ResourceList.SelectedItems.Count > 0;
}
}
public bool EnableCopy
{
get {
if (resourceEditor.ResourceList.IsEditing) {
return false;
}
return resourceEditor.ResourceList.SelectedItems.Count > 0;
}
}
public bool EnablePaste
{
get {
if (resourceEditor.ResourceList.IsEditing) {
return false;
}
return true;
}
}
public bool EnableDelete
{
get {
if (resourceEditor.ResourceList.IsEditing) {
return false;
}
return resourceEditor.ResourceList.SelectedItems.Count > 0;
}
}
public bool EnableSelectAll
{
get {
if (resourceEditor.ResourceList.IsEditing) {
return false;
}
return true;
}
}
public void Cut()
{
if (resourceEditor.ResourceList.WriteProtected || resourceEditor.ResourceList.SelectedItems.Count < 1)
return;
Hashtable tmphash = new Hashtable();
foreach (ListViewItem item in resourceEditor.ResourceList.SelectedItems) {
tmphash.Add(item.Text, resourceEditor.ResourceList.Resources[item.Text].ResourceValue);
resourceEditor.ResourceList.Resources.Remove(item.Text);
resourceEditor.ResourceList.Items.Remove(item);
}
resourceEditor.ResourceList.OnChanged();
SD.Clipboard.SetDataObject(tmphash);
}
public void Copy()
{
if (resourceEditor.ResourceList.SelectedItems.Count < 1) {
return;
}
Hashtable tmphash = new Hashtable();
foreach (ListViewItem item in resourceEditor.ResourceList.SelectedItems) {
object resourceValue = GetClonedResource(resourceEditor.ResourceList.Resources[item.Text].ResourceValue);
tmphash.Add(item.Text, resourceValue); // copy a clone to clipboard
}
SD.Clipboard.SetDataObject(tmphash);
}
public void Paste()
{
if (resourceEditor.ResourceList.WriteProtected) {
return;
}
IDataObject dob = Clipboard.GetDataObject();
if (dob == null)
return;
if (dob.GetDataPresent(typeof(Hashtable).FullName)) {
Hashtable tmphash = (Hashtable)dob.GetData(typeof(Hashtable));
foreach (DictionaryEntry entry in tmphash) {
object resourceValue = GetClonedResource(entry.Value);
ResourceItem item;
if (!resourceEditor.ResourceList.Resources.ContainsKey((string)entry.Key)) {
item = new ResourceItem(entry.Key.ToString(), resourceValue);
} else {
int count = 1;
string newNameBase = entry.Key.ToString() + " ";
string newName = newNameBase + count.ToString();
while(resourceEditor.ResourceList.Resources.ContainsKey(newName)) {
count++;
newName = newNameBase + count.ToString();
}
item = new ResourceItem(newName, resourceValue);
}
resourceEditor.ResourceList.Resources.Add(item.Name, item);
resourceEditor.ResourceList.OnChanged();
}
resourceEditor.ResourceList.InitializeListView();
}
}
/// <summary>
/// Clones a resource if the <paramref name="resource"/>
/// is cloneable.
/// </summary>
/// <param name="resource">A resource to clone.</param>
/// <returns>A cloned resource if the object implements
/// the ICloneable interface, otherwise the
/// <paramref name="resource"/> object.</returns>
object GetClonedResource(object resource)
{
object clonedResource = null;
ICloneable cloneableResource = resource as ICloneable;
if (cloneableResource != null) {
clonedResource = cloneableResource.Clone();
} else {
clonedResource = resource;
}
return clonedResource;
}
public void Delete()
{
var resourceList = resourceEditor.ResourceList;
if (resourceList.WriteProtected || resourceList.SelectedItems.Count == 0)
return;
if (!SD.MessageService.AskQuestion("${res:ResourceEditor.DeleteEntry.Confirm}", "${res:ResourceEditor.DeleteEntry.Title}"))
return;
foreach (ListViewItem item in resourceList.SelectedItems) {
resourceList.Resources.Remove(item.Text);
resourceList.Items.Remove(item);
// and set dirty flag
resourceList.OnChanged();
}
}
public void SelectAll()
{
foreach (ListViewItem i in resourceEditor.ResourceList.Items) {
i.Selected=true;
}
} }
} }
} }

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

@ -0,0 +1,481 @@
// 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.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO;
using System.Linq;
using System.Resources;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Project.Commands;
using ResourceEditor.Views;
namespace ResourceEditor.ViewModels
{
public class ChangedDirtyStateEventArgs : EventArgs
{
public ChangedDirtyStateEventArgs(bool isDirty)
{
this.IsDirty = isDirty;
}
public bool IsDirty {
get;
private set;
}
}
/// <summary>
/// Main view model for resource editor.
/// </summary>
public class ResourceEditorViewModel : DependencyObject
{
readonly ObservableCollection<ResourceItem> resourceItems;
readonly HashSet<string> resourceItemNames;
readonly ObservableCollection<ResourceItem> metadataItems;
readonly Dictionary<ResourceItemEditorType, IResourceItemView> itemViews;
bool longUpdateRunning;
ResourceItem editedResourceItem;
string originalNameOfEditedItem;
IResourceEditorView view;
public event EventHandler<ChangedDirtyStateEventArgs> DirtyStateChanged;
public static readonly DependencyProperty SearchTermProperty =
DependencyProperty.Register("SearchTerm", typeof(string), typeof(ResourceEditorViewModel),
new FrameworkPropertyMetadata());
public string SearchTerm {
get { return (string) GetValue(SearchTermProperty); }
set { SetValue(SearchTermProperty, value); }
}
public IList SelectedItems {
get {
if (view != null) {
return view.SelectedItems;
}
return null;
}
}
public ResourceEditorViewModel()
{
resourceItems = new ObservableCollection<ResourceItem>();
resourceItemNames = new HashSet<string>();
metadataItems = new ObservableCollection<ResourceItem>();
itemViews = new Dictionary<ResourceItemEditorType, IResourceItemView>();
}
public ObservableCollection<ResourceItem> ResourceItems {
get {
return resourceItems;
}
}
/// <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;
}
public IResourceEditorView View {
get {
return view;
}
set {
if (view != null) {
view.SelectionChanged -= View_SelectionChanged;
view.EditingStarted -= View_EditingStarted;
view.EditingFinished -= View_EditingFinished;
view.EditingCancelled -= View_EditingCancelled;
ResourceItems.CollectionChanged -= ResourceItems_CollectionChanged;
}
view = value;
if (view != null) {
// Bind this model to new view
view.DataContext = this;
view.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, (s, e) => Cut(), (s, e) => e.CanExecute = EnableCut));
view.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, (s, e) => Copy(), (s, e) => e.CanExecute = EnableCopy));
view.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, (s, e) => Paste(), (s, e) => e.CanExecute = EnablePaste));
view.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, (s, e) => Delete(), (s, e) => e.CanExecute = EnableDelete));
view.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, (s, e) => SelectAll(), (s, e) => e.CanExecute = EnableSelectAll));
view.FilterPredicate = resourceItem => {
if (SearchTerm != null)
return resourceItem.Name.IndexOf(SearchTerm, StringComparison.OrdinalIgnoreCase) >= 0;
return true;
};
view.SelectionChanged += View_SelectionChanged;
view.EditingStarted += View_EditingStarted;
view.EditingFinished += View_EditingFinished;
view.EditingCancelled += View_EditingCancelled;
ResourceItems.CollectionChanged += ResourceItems_CollectionChanged;
}
}
}
void ResourceItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
switch (e.Action) {
case NotifyCollectionChangedAction.Remove:
if (e.OldItems != null) {
var oldItems = e.OldItems.OfType<ResourceItem>();
foreach (var item in oldItems) {
resourceItemNames.Remove(item.Name);
}
}
break;
case NotifyCollectionChangedAction.Add:
if (e.NewItems != null) {
var newItems = e.NewItems.OfType<ResourceItem>();
foreach (var item in newItems) {
if (!resourceItemNames.Contains(item.Name))
resourceItemNames.Add(item.Name);
}
}
break;
case NotifyCollectionChangedAction.Reset:
resourceItemNames.Clear();
break;
}
// Changes in collection of ResourceItems => make dirty
MakeDirty();
}
void View_SelectionChanged(object sender, EventArgs e)
{
if (longUpdateRunning)
return;
ResourceItem selectedItem = SelectedItems.OfType<ResourceItem>().FirstOrDefault();
if (selectedItem != null) {
if (itemViews.ContainsKey(selectedItem.ResourceType)) {
var itemView = itemViews[selectedItem.ResourceType];
itemView.ResourceItem = selectedItem;
view.SetItemView(itemView);
}
}
}
void OnChangedDirtyState(bool isDirty)
{
if (DirtyStateChanged != null) {
DirtyStateChanged(this, new ChangedDirtyStateEventArgs(isDirty));
}
}
public void MakeDirty()
{
OnChangedDirtyState(true);
}
public void StartEditing()
{
// if (editedResourceItem != null) {
// editedResourceItem.IsEditing = false;
// editedResourceItem = null;
// originalNameOfEditedItem = null;
// }
// Start editing currently selected item
var firstSelectedItem = SelectedItems.OfType<ResourceItem>().FirstOrDefault();
if (firstSelectedItem != null) {
editedResourceItem = firstSelectedItem;
originalNameOfEditedItem = editedResourceItem.Name;
firstSelectedItem.IsEditing = true;
}
}
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();
// }
}
void View_EditingCancelled(object sender, EventArgs e)
{
// if (editedResourceItem != null) {
// editedResourceItem.IsEditing = false;
// editedResourceItem.Name = originalNameOfEditedItem;
// editedResourceItem = null;
// originalNameOfEditedItem = null;
// }
}
void StartUpdate()
{
// When loading many items at once, temporarily unbind view from model
view.DataContext = null;
}
void EndUpdate()
{
view.DataContext = this;
}
public void LoadFile(FileName filename, Stream stream)
{
StartUpdate();
resourceItems.Clear();
metadataItems.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()) {
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;
metadataItems.Add(new ResourceItem(this, node.Name, node.GetValue(typeResolver)));
}
rx.Close();
break;
case ".resources":
ResourceReader rr = null;
try {
rr = new ResourceReader(stream);
foreach (DictionaryEntry entry in rr) {
resourceItems.Add(new ResourceItem(this, entry.Key.ToString(), entry.Value));
}
} finally {
if (rr != null) {
rr.Close();
}
}
break;
}
EndUpdate();
}
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 (ResourceItem entry in resourceItems) {
if (entry != null) {
rxw.AddResource(entry.ToResXDataNode(t => ResXConverter.ConvertTypeName(t, filename)));
}
}
foreach (ResourceItem entry in metadataItems) {
if (entry != null) {
rxw.AddMetadata(entry.Name, entry.ResourceValue);
}
}
rxw.Generate();
rxw.Close();
break;
default:
// write default resource
ResourceWriter rw = new ResourceWriter(stream);
foreach (ResourceItem entry in resourceItems) {
rw.AddResource(entry.Name, entry.ResourceValue);
}
rw.Generate();
rw.Close();
break;
}
}
#region Standard clipboard commands
public bool EnableCut {
get {
return SelectedItems.Count > 0;
}
}
public bool EnableCopy {
get {
return SelectedItems.Count > 0;
}
}
public bool EnablePaste {
get {
return true;
}
}
public bool EnableDelete {
get {
return SelectedItems.Count > 0;
}
}
public bool EnableSelectAll {
get {
return true;
}
}
public void Cut()
{
// if (resourceEditor.ResourceList.WriteProtected || resourceEditor.ResourceList.SelectedItems.Count < 1)
// return;
if (SelectedItems.Count == 0)
return;
Hashtable tmphash = new Hashtable();
foreach (var selectedItem in SelectedItems.OfType<ResourceItem>().ToList()) {
tmphash.Add(selectedItem.Name, selectedItem.ResourceValue);
resourceItems.Remove(selectedItem);
}
SD.Clipboard.SetDataObject(tmphash);
}
public void Copy()
{
if (SelectedItems.Count == 0)
return;
Hashtable tmphash = new Hashtable();
foreach (var selectedItem in SelectedItems.OfType<ResourceItem>().ToList()) {
object resourceValue = GetClonedResource(selectedItem.ResourceValue);
tmphash.Add(selectedItem.Name, resourceValue);
}
SD.Clipboard.SetDataObject(tmphash);
}
public void Paste()
{
// if (resourceEditor.ResourceList.WriteProtected) {
// return;
// }
IDataObject dob = Clipboard.GetDataObject();
if (dob == null)
return;
if (dob.GetDataPresent(typeof(Hashtable).FullName)) {
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)) {
item = new ResourceItem(this, entry.Key.ToString(), resourceValue);
} else {
int count = 1;
string newNameBase = entry.Key + " ";
string newName = newNameBase + count;
while (resourceItemNames.Contains(newName)) {
count++;
newName = newNameBase + count;
}
item = new ResourceItem(this, newName, resourceValue);
}
resourceItems.Add(item);
// TODO Set selection to new element?
}
}
}
/// <summary>
/// Clones a resource if the <paramref name="resource"/>
/// is cloneable.
/// </summary>
/// <param name="resource">A resource to clone.</param>
/// <returns>A cloned resource if the object implements
/// the ICloneable interface, otherwise the
/// <paramref name="resource"/> object.</returns>
object GetClonedResource(object resource)
{
object clonedResource = null;
ICloneable cloneableResource = resource as ICloneable;
if (cloneableResource != null) {
clonedResource = cloneableResource.Clone();
} else {
clonedResource = resource;
}
return clonedResource;
}
public void Delete()
{
// if (resourceList.WriteProtected || resourceList.SelectedItems.Count == 0)
// return;
if (SelectedItems.Count > 0) {
if (!SD.MessageService.AskQuestion("${res:ResourceEditor.DeleteEntry.Confirm}", "${res:ResourceEditor.DeleteEntry.Title}"))
return;
foreach (var item in SelectedItems.OfType<ResourceItem>().ToList()) {
resourceItems.Remove(item);
}
}
}
public void SelectAll()
{
longUpdateRunning = true;
foreach (var i in resourceItems)
SelectedItems.Add(i);
longUpdateRunning = false;
}
#endregion
}
}

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

@ -0,0 +1,245 @@
// 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.ComponentModel;
using System.Drawing;
using System.Resources;
using System.Windows;
using System.Windows.Forms;
using ICSharpCode.SharpDevelop;
namespace ResourceEditor.ViewModels
{
/// <summary>
/// Defines the type of resource item supported by editor.
/// </summary>
public enum ResourceItemEditorType
{
Unknown,
String,
Boolean,
Bitmap,
Icon,
Cursor,
Binary
}
public class ResourceItem : DependencyObject
{
ResourceItemEditorType resourceType;
ResourceEditorViewModel resourceEditor;
string nameBeforeEditing;
public ResourceItem(ResourceEditorViewModel resourceEditor, string name, object resourceValue)
{
this.resourceEditor = resourceEditor;
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.resourceType = GetResourceTypeFromValue(resourceValue);
this.Comment = comment;
}
public static readonly DependencyProperty NameProperty =
DependencyProperty.Register("Name", typeof(string), typeof(ResourceItem),
new FrameworkPropertyMetadata());
public string 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 (object)GetValue(ResourceValueProperty); }
set { SetValue(ResourceValueProperty, value); }
}
public string DisplayedResourceType {
get {
return ResourceValue == null ? "(Nothing/null)" : ResourceValue.GetType().FullName;
}
}
public ResourceItemEditorType ResourceType {
get {
return resourceType;
}
}
public static readonly DependencyProperty IsEditingProperty =
DependencyProperty.Register("IsEditing", typeof(bool), typeof(ResourceItem),
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) {
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();
}
}
ResourceItemEditorType GetResourceTypeFromValue(object val)
{
if (this.ResourceValue == null) {
return ResourceItemEditorType.Unknown;
}
switch (this.ResourceValue.GetType().ToString()) {
case "System.String":
return ResourceItemEditorType.String;
case "System.Drawing.Bitmap":
return ResourceItemEditorType.Bitmap;
case "System.Drawing.Icon":
return ResourceItemEditorType.Icon;
case "System.Windows.Forms.Cursor":
return ResourceItemEditorType.Cursor;
case "System.Byte[]":
return ResourceItemEditorType.Binary;
case "System.Boolean":
return ResourceItemEditorType.Boolean;
default:
return ResourceItemEditorType.Unknown;
}
}
public string Content {
get {
return ToString();
}
}
public static readonly DependencyProperty CommentProperty =
DependencyProperty.Register("Comment", typeof(string), typeof(ResourceItem),
new FrameworkPropertyMetadata());
public string Comment {
get { return (string)GetValue(CommentProperty); }
set { SetValue(CommentProperty, value); }
}
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;
}
public bool UpdateFromFile()
{
var fileDialog = new Microsoft.Win32.OpenFileDialog();
fileDialog.AddExtension = true;
fileDialog.Filter = "All files (*.*)|*.*";
fileDialog.CheckFileExists = true;
if (fileDialog.ShowDialog().Value) {
object newValue = null;
switch (resourceType) {
case ResourceItemEditorType.Bitmap:
try {
newValue = new Bitmap(fileDialog.FileName);
} catch {
SD.MessageService.ShowWarning("Can't load bitmap file.");
return false;
}
break;
}
if (newValue != null) {
ResourceValue = newValue;
return true;
}
}
return false;
}
}
}

7
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BinaryView.xaml

@ -0,0 +1,7 @@
<UserControl x:Class="ResourceEditor.Views.BinaryView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
</Grid>
</UserControl>

41
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BinaryView.xaml.cs

@ -0,0 +1,41 @@
// 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 BinaryView.xaml
/// </summary>
public partial class BinaryView : UserControl
{
public BinaryView()
{
InitializeComponent();
}
}
}

7
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BooleanView.xaml

@ -0,0 +1,7 @@
<UserControl x:Class="ResourceEditor.Views.BooleanView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
</Grid>
</UserControl>

41
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BooleanView.xaml.cs

@ -0,0 +1,41 @@
// 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 BooleanView.xaml
/// </summary>
public partial class BooleanView : UserControl
{
public BooleanView()
{
InitializeComponent();
}
}
}

58
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/IResourceEditorView.cs

@ -0,0 +1,58 @@
// 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.Collections.ObjectModel;
using System.Windows;
using System.Windows.Input;
namespace ResourceEditor.Views
{
/// <summary>
/// Base interface for resource editor main views.
/// </summary>
public interface IResourceEditorView
{
CommandBindingCollection CommandBindings {
get;
}
event EventHandler SelectionChanged;
IList SelectedItems {
get;
}
event EventHandler EditingStarted;
event EventHandler EditingFinished;
event EventHandler EditingCancelled;
void SetItemView(IResourceItemView view);
object DataContext {
get;
set;
}
Predicate<ResourceEditor.ViewModels.ResourceItem> FilterPredicate {
get;
set;
}
}
}

21
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/ClipboardCommands.cs → src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/IResourceItemView.cs

@ -16,21 +16,18 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using ICSharpCode.Core; using System.Windows;
using ICSharpCode.SharpDevelop;
namespace ResourceEditor namespace ResourceEditor.Views
{ {
/// <summary>
class SelectAllCommand : AbstractMenuCommand /// Interface for resource item views.
/// </summary>
public interface IResourceItemView
{ {
public override void Run() ResourceEditor.ViewModels.ResourceItem ResourceItem { get; set; }
{ FrameworkElement UIControl { get; }
ResourceEditWrapper editor = (ResourceEditWrapper)SD.Workbench.ActiveViewContent;
editor.SelectAll();
}
} }
} }

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

@ -0,0 +1,19 @@
<UserControl x:Class="ResourceEditor.Views.ImageViewBase"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</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">
<Image
Name="imagePreview"
Source="{Binding DisplayedImage}"
Stretch="None"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</ScrollViewer>
</Grid>
</UserControl>

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

@ -0,0 +1,101 @@
// 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;
using System.Windows.Media.Imaging;
using ICSharpCode.SharpDevelop;
using ResourceEditor.ViewModels;
namespace ResourceEditor.Views
{
/// <summary>
/// Interaction logic for ImageViewBase.xaml
/// </summary>
public partial class ImageViewBase : UserControl, IResourceItemView
{
ResourceEditor.ViewModels.ResourceItem resourceItem;
public ImageViewBase()
{
InitializeComponent();
DataContext = this;
}
public static readonly DependencyProperty DisplayedImageProperty =
DependencyProperty.Register("DisplayedImage", typeof(object), typeof(ImageViewBase),
new FrameworkPropertyMetadata());
public object DisplayedImage {
get { return (object)GetValue(DisplayedImageProperty); }
set { SetValue(DisplayedImageProperty, value); }
}
public static readonly DependencyProperty UpdateLinkTextProperty =
DependencyProperty.Register("UpdateLinkText", typeof(string), typeof(ImageViewBase),
new FrameworkPropertyMetadata());
public string UpdateLinkText {
get { return (string)GetValue(UpdateLinkTextProperty); }
set { SetValue(UpdateLinkTextProperty, value); }
}
public FrameworkElement UIControl {
get {
return this;
}
}
public ResourceEditor.ViewModels.ResourceItem ResourceItem {
get {
return resourceItem;
}
set {
resourceItem = value;
UpdateLinkText = "";
if (resourceItem != null) {
switch (resourceItem.ResourceType) {
case ResourceItemEditorType.Bitmap:
var gdiBitmap = resourceItem.ResourceValue as System.Drawing.Bitmap;
if (gdiBitmap != null) {
DisplayedImage = gdiBitmap.ToBitmapSource();
UpdateLinkText = SD.ResourceService.GetString("ResourceEditor.BitmapView.UpdateBitmap");
}
break;
}
}
}
}
void Button_Click(object sender, RoutedEventArgs e)
{
if (resourceItem != null) {
if (resourceItem.UpdateFromFile()) {
ResourceItem = resourceItem;
}
}
}
}
}

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

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

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

@ -0,0 +1,112 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
namespace ResourceEditor.Views
{
/// <summary>
/// Interaction logic for InPlaceEditLabel.xaml
/// </summary>
public partial class InPlaceEditLabel : UserControl
{
string textBeforeEditing;
public InPlaceEditLabel()
{
InitializeComponent();
editingTextBox.Visibility = Visibility.Collapsed;
readOnlyTextBlock.Visibility = Visibility.Visible;
readOnlyTextBlock.DataContext = this;
editingTextBox.DataContext = this;
}
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(InPlaceEditLabel),
new FrameworkPropertyMetadata());
public string Text {
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
public static readonly DependencyProperty IsEditingProperty =
DependencyProperty.Register("IsEditing", typeof(bool), typeof(InPlaceEditLabel),
new FrameworkPropertyMetadata());
public bool IsEditing {
get { return (bool)GetValue(IsEditingProperty); }
set { SetValue(IsEditingProperty, value); }
}
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.Property == IsEditingProperty) {
if ((bool)e.NewValue) {
editingTextBox.Visibility = Visibility.Visible;
readOnlyTextBlock.Visibility = Visibility.Collapsed;
editingTextBox.Focus();
textBeforeEditing = this.Text;
editingTextBox.SelectAll();
} else {
editingTextBox.Visibility = Visibility.Collapsed;
readOnlyTextBlock.Visibility = Visibility.Visible;
}
}
}
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
if (e.Key == Key.Enter) {
IsEditing = false;
} else if (e.Key == Key.Escape) {
// Cancel editing and restore original text
this.Text = textBeforeEditing;
IsEditing = false;
}
}
void EditingTextBox_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if ((bool)e.NewValue) {
// Auto-select whole text as soon as TextBox becomes visible
// editingTextBox.Focus();
// editingTextBox.SelectAll();
// textBeforeEditing = this.Text;
}
}
void EditingTextBox_LostFocus(object sender, RoutedEventArgs e)
{
// When losing focus, also stop editing
IsEditing = false;
}
}
}

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

@ -0,0 +1,159 @@
<UserControl x:Class="ResourceEditor.Views.ResourceEditorView"
xmlns:resvm="clr-namespace:ResourceEditor.ViewModels"
xmlns:resv="clr-namespace:ResourceEditor.Views"
xmlns:core="clr-namespace:ICSharpCode.Core.Presentation;assembly=ICSharpCode.Core.Presentation"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
xmlns:sys="clr-namespace:System;assembly=System"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl.Resources>
<resv:ResourceItemIcons x:Key="resourceItemIcons" />
<CollectionViewSource
x:Key="resourceItemListViewSource"
Source="{Binding ResourceItems}"
Filter="CollectionViewSource_Filter">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Name"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
<Style x:Key="listViewItemStyle" TargetType="{x:Type ListViewItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
</Style>
<DataTemplate x:Key="resourceItemNameTemplate" DataType="{x:Type resvm:ResourceItem}">
<Border BorderBrush="LightGray" BorderThickness="0,0,1,1" 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">
<Style.Triggers>
<DataTrigger Binding="{Binding ResourceType}" Value="String">
<Setter Property="Source" Value="{Binding Source={StaticResource resourceItemIcons}, Path=StringResourceIcon}" />
</DataTrigger>
<DataTrigger Binding="{Binding ResourceType}" Value="Boolean">
<Setter Property="Source" Value="{Binding Source={StaticResource resourceItemIcons}, Path=BooleanResourceIcon}" />
</DataTrigger>
<DataTrigger Binding="{Binding ResourceType}" Value="Bitmap">
<Setter Property="Source" Value="{Binding Source={StaticResource resourceItemIcons}, Path=BitmapResourceIcon}" />
</DataTrigger>
<DataTrigger Binding="{Binding ResourceType}" Value="Icon">
<Setter Property="Source" Value="{Binding Source={StaticResource resourceItemIcons}, Path=IconResourceIcon}" />
</DataTrigger>
<DataTrigger Binding="{Binding ResourceType}" Value="Cursor">
<Setter Property="Source" Value="{Binding Source={StaticResource resourceItemIcons}, Path=CursorResourceIcon}" />
</DataTrigger>
<DataTrigger Binding="{Binding ResourceType}" Value="Binary">
<Setter Property="Source" Value="{Binding Source={StaticResource resourceItemIcons}, Path=BinaryResourceIcon}" />
</DataTrigger>
<DataTrigger Binding="{Binding ResourceType}" Value="Unknown">
<Setter Property="Source" Value="{Binding Source={StaticResource resourceItemIcons}, Path=UnknownResourceIcon}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
<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>
<DataTemplate x:Key="resourceItemTypeTemplate" DataType="{x:Type resvm:ResourceItem}">
<Border BorderBrush="LightGray" BorderThickness="0,0,1,1" Margin="-6,-2,-6,-2">
<TextBlock Text="{Binding DisplayedResourceType}" Margin="6,2,6,2" />
</Border>
</DataTemplate>
<DataTemplate x:Key="resourceItemContentTemplate" DataType="{x:Type resvm:ResourceItem}">
<Border BorderBrush="LightGray" BorderThickness="0,0,1,1" Margin="-6,-2,-6,-2">
<TextBlock Text="{Binding Content}" Margin="6,2,6,2" />
</Border>
</DataTemplate>
<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" MinWidth="300" />
</Border>
</DataTemplate>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height=".2*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Filter:" Margin="3,2,5,2" VerticalAlignment="Center" />
<TextBox
Grid.Column="1"
Name="searchTermTextBox"
Text="{Binding SearchTerm, UpdateSourceTrigger=PropertyChanged}"
Margin="0,2,3,2"
VerticalAlignment="Center"
KeyUp="FilterTextBox_KeyUp" />
<Button
Grid.Column="2"
Click="UpdateFilterButton_Click"
Margin="0,2,3,2"
Content="{core:Localize Global.UpdateButtonText}" />
</Grid>
<ListView
Name="resourceItemsListView"
Grid.Row="1"
ItemsSource="{Binding Source={StaticResource resourceItemListViewSource}}"
ItemContainerStyle="{StaticResource listViewItemStyle}"
MouseRightButtonUp="ListView_MouseRightButtonUp"
KeyUp="ResourceItemsListView_KeyUp"
SelectionChanged="ListView_SelectionChanged">
<ListView.View>
<GridView>
<GridViewColumn
Header="{core:Localize Global.Name}"
CellTemplate="{StaticResource resourceItemNameTemplate}" />
<GridViewColumn
Header="{core:Localize ResourceEditor.ResourceEdit.TypeColumn}"
CellTemplate="{StaticResource resourceItemTypeTemplate}" />
<GridViewColumn
Header="{core:Localize ResourceEditor.ResourceEdit.ContentColumn}"
CellTemplate="{StaticResource resourceItemContentTemplate}" />
<GridViewColumn
Header="{core:Localize ResourceEditor.ResourceEdit.CommentColumn}"
CellTemplate="{StaticResource resourceItemCommentTemplate}" />
</GridView>
</ListView.View>
</ListView>
<GridSplitter
Grid.Row="2"
Height="5"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"/>
<Grid Grid.Row="3" Name="resourceItemViewGrid"></Grid>
</Grid>
</UserControl>

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

@ -0,0 +1,203 @@
// 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.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
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>
public partial class ResourceEditorView : UserControl, IResourceEditorView
{
readonly CollectionViewSource itemCollectionViewSource;
public event EventHandler SelectionChanged;
public event EventHandler EditingStarted;
public event EventHandler EditingFinished;
public event EventHandler EditingCancelled;
public ResourceEditorView()
{
InitializeComponent();
itemCollectionViewSource = (CollectionViewSource) this.Resources["resourceItemListViewSource"];
}
public IList SelectedItems {
get {
return resourceItemsListView.SelectedItems;
}
}
public void SetItemView(IResourceItemView view)
{
resourceItemViewGrid.Children.Clear();
view.UIControl.Visibility = Visibility.Visible;
resourceItemViewGrid.Children.Add(view.UIControl);
}
public Predicate<ResourceEditor.ViewModels.ResourceItem> FilterPredicate {
get;
set;
}
void ListView_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
MenuService.ShowContextMenu(this, null, "/SharpDevelop/ResourceEditor/ResourceList/ContextMenu");
}
void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (SelectionChanged != null) {
SelectionChanged(this, new EventArgs());
}
}
void CollectionViewSource_Filter(object sender, FilterEventArgs e)
{
if (FilterPredicate == null) {
// No filtering without predicate
e.Accepted = true;
return;
}
var resourceItem = e.Item as ResourceEditor.ViewModels.ResourceItem;
if (resourceItem == null) {
// Away with non-ResourceItems (shouldn't happen anyway)
e.Accepted = false;
return;
}
e.Accepted = FilterPredicate(resourceItem);
}
void FilterTextBox_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter) {
// Apply filter text on Enter key
UpdateFilter();
} else if (e.Key == Key.Escape) {
// Clear the filter text on Esc key
searchTermTextBox.Clear();
UpdateFilter();
}
}
void UpdateFilterButton_Click(object sender, RoutedEventArgs e)
{
UpdateFilter();
}
void UpdateFilter()
{
// Update CollectionViewSource to re-evaluate filter predicate
itemCollectionViewSource.View.Refresh();
}
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());
}
}
e.Handled = false;
}
}
}

76
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceItemIcons.cs

@ -0,0 +1,76 @@
// 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.Media;
using ICSharpCode.SharpDevelop;
namespace ResourceEditor.Views
{
/// <summary>
/// Provides resource icons for different <see cref="ResourceEditor.ViewModels.ResourceItem"/> types.
/// </summary>
public class ResourceItemIcons
{
public ResourceItemIcons()
{
UnknownResourceIcon = SD.ResourceService.GetImageSource("Icons.16x16.ResourceEditor.obj");
StringResourceIcon = SD.ResourceService.GetImageSource("Icons.16x16.ResourceEditor.string");
BooleanResourceIcon = SD.ResourceService.GetImageSource("Icons.16x16.ResourceEditor.obj");
BitmapResourceIcon = SD.ResourceService.GetImageSource("Icons.16x16.ResourceEditor.bmp");
IconResourceIcon = SD.ResourceService.GetImageSource("Icons.16x16.ResourceEditor.icon");
CursorResourceIcon = SD.ResourceService.GetImageSource("Icons.16x16.ResourceEditor.cursor");
BinaryResourceIcon = SD.ResourceService.GetImageSource("Icons.16x16.ResourceEditor.bin");
}
public ImageSource UnknownResourceIcon {
get;
private set;
}
public ImageSource StringResourceIcon {
get;
private set;
}
public ImageSource BooleanResourceIcon {
get;
private set;
}
public ImageSource BitmapResourceIcon {
get;
private set;
}
public ImageSource IconResourceIcon {
get;
private set;
}
public ImageSource CursorResourceIcon {
get;
private set;
}
public ImageSource BinaryResourceIcon {
get;
private set;
}
}
}

12
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/TextView.xaml

@ -0,0 +1,12 @@
<UserControl x:Class="ResourceEditor.Views.TextView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<TextBox
Margin="0,0,0,0"
Text="{Binding Path=ResourceValue, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap"
AcceptsReturn="True"
VerticalScrollBarVisibility="Auto" />
</Grid>
</UserControl>

56
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/TextView.xaml.cs

@ -0,0 +1,56 @@
// 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 TextView.xaml
/// </summary>
public partial class TextView : UserControl, IResourceItemView
{
public TextView()
{
InitializeComponent();
}
public FrameworkElement UIControl {
get {
return this;
}
}
public ResourceEditor.ViewModels.ResourceItem ResourceItem {
get {
return DataContext as ViewModels.ResourceItem;
}
set {
DataContext = value;
}
}
}
}
Loading…
Cancel
Save