Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 2184c84

Browse files
committed
Migrated some basic functions of ResourceEditor to WPF.
1 parent 5ad6289 commit 2184c84

24 files changed

+1636
-337
lines changed

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

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,26 @@
4040
<OutputPath>..\..\..\..\..\AddIns\DisplayBindings\ResourceEditor\</OutputPath>
4141
</PropertyGroup>
4242
<ItemGroup>
43+
<Reference Include="PresentationCore">
44+
<RequiredTargetFramework>3.0</RequiredTargetFramework>
45+
</Reference>
46+
<Reference Include="PresentationFramework">
47+
<RequiredTargetFramework>3.0</RequiredTargetFramework>
48+
</Reference>
4349
<Reference Include="System" />
4450
<Reference Include="System.Drawing" />
4551
<Reference Include="System.Windows.Forms" />
4652
<Reference Include="System.Design" />
53+
<Reference Include="System.Xaml">
54+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
55+
</Reference>
56+
<Reference Include="WindowsBase" />
4757
</ItemGroup>
4858
<ItemGroup>
4959
<Compile Include="Configuration\AssemblyInfo.cs" />
60+
<Compile Include="Src\BitmapExtensions.cs" />
5061
<Compile Include="Src\Commands\AddNewFileCommand.cs" />
5162
<Compile Include="Src\Commands\AddStringEntryCommand.cs" />
52-
<Compile Include="Src\Commands\ClipboardCommands.cs" />
5363
<Compile Include="Src\Commands\CopyResourceNameCommand.cs" />
5464
<Compile Include="Src\Commands\EditCommentCommand.cs" />
5565
<Compile Include="Src\Commands\RenameEntryCommand.cs" />
@@ -84,6 +94,31 @@
8494
<Compile Include="Src\ResourceEdit\TextView.cs">
8595
<SubType>Component</SubType>
8696
</Compile>
97+
<Compile Include="Src\ViewModels\ResourceEditorViewModel.cs" />
98+
<Compile Include="Src\ViewModels\ResourceItem.cs" />
99+
<Compile Include="Src\Views\BinaryView.xaml.cs">
100+
<DependentUpon>BinaryView.xaml</DependentUpon>
101+
<SubType>Code</SubType>
102+
</Compile>
103+
<Compile Include="Src\Views\BooleanView.xaml.cs">
104+
<DependentUpon>BooleanView.xaml</DependentUpon>
105+
<SubType>Code</SubType>
106+
</Compile>
107+
<Compile Include="Src\Views\ImageViewBase.xaml.cs">
108+
<DependentUpon>ImageViewBase.xaml</DependentUpon>
109+
<SubType>Code</SubType>
110+
</Compile>
111+
<Compile Include="Src\Views\IResourceEditorView.cs" />
112+
<Compile Include="Src\Views\IResourceItemView.cs" />
113+
<Compile Include="Src\Views\ResourceEditorView.xaml.cs">
114+
<DependentUpon>ResourceEditorView.xaml</DependentUpon>
115+
<SubType>Code</SubType>
116+
</Compile>
117+
<Compile Include="Src\Views\ResourceItemIcons.cs" />
118+
<Compile Include="Src\Views\TextView.xaml.cs">
119+
<DependentUpon>TextView.xaml</DependentUpon>
120+
<SubType>Code</SubType>
121+
</Compile>
87122
<None Include="ResourceEditor.addin">
88123
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
89124
</None>
@@ -108,6 +143,10 @@
108143
<Name>ICSharpCode.Core</Name>
109144
<Private>False</Private>
110145
</ProjectReference>
146+
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.Core.Presentation\ICSharpCode.Core.Presentation.csproj">
147+
<Project>{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}</Project>
148+
<Name>ICSharpCode.Core.Presentation</Name>
149+
</ProjectReference>
111150
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.Core.WinForms\ICSharpCode.Core.WinForms.csproj">
112151
<Project>{857CA1A3-FC88-4BE0-AB6A-D1EE772AB288}</Project>
113152
<Name>ICSharpCode.Core.WinForms</Name>
@@ -119,5 +158,16 @@
119158
<Private>False</Private>
120159
</ProjectReference>
121160
</ItemGroup>
161+
<ItemGroup>
162+
<Folder Include="Src\ViewModels" />
163+
<Folder Include="Src\Views" />
164+
</ItemGroup>
165+
<ItemGroup>
166+
<Page Include="Src\Views\BinaryView.xaml" />
167+
<Page Include="Src\Views\BooleanView.xaml" />
168+
<Page Include="Src\Views\ImageViewBase.xaml" />
169+
<Page Include="Src\Views\ResourceEditorView.xaml" />
170+
<Page Include="Src\Views\TextView.xaml" />
171+
</ItemGroup>
122172
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
123173
</Project>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
// software and associated documentation files (the "Software"), to deal in the Software
5+
// without restriction, including without limitation the rights to use, copy, modify, merge,
6+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7+
// to whom the Software is furnished to do so, subject to the following conditions:
8+
//
9+
// The above copyright notice and this permission notice shall be included in all copies or
10+
// substantial portions of the Software.
11+
//
12+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17+
// DEALINGS IN THE SOFTWARE.
18+
19+
using System;
20+
using System.Runtime.InteropServices;
21+
using System.Windows;
22+
using System.Windows.Interop;
23+
using System.Windows.Media.Imaging;
24+
25+
namespace ResourceEditor
26+
{
27+
/// <summary>
28+
/// Bitmap conversion extensions for WinForms -> WPF
29+
/// </summary>
30+
public static class BitmapExtensions
31+
{
32+
[DllImport("gdi32.dll")]
33+
[return: MarshalAs(UnmanagedType.Bool)]
34+
public static extern bool DeleteObject(IntPtr hObject);
35+
36+
public static BitmapSource ToBitmapSource(this System.Drawing.Bitmap bitmap)
37+
{
38+
BitmapSource bs;
39+
IntPtr hBitmap = bitmap.GetHbitmap();
40+
try {
41+
bs = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero,
42+
Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
43+
bs.Freeze();
44+
} finally {
45+
DeleteObject(hBitmap);
46+
}
47+
return bs;
48+
}
49+
}
50+
}

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

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,84 +17,87 @@
1717
// DEALINGS IN THE SOFTWARE.
1818

1919
using System;
20-
using System.Drawing;
2120
using System.IO;
2221
using System.Runtime.Serialization.Formatters.Binary;
23-
using System.Windows.Forms;
2422

2523
using ICSharpCode.Core;
2624
using ICSharpCode.SharpDevelop;
2725
using ICSharpCode.SharpDevelop.Gui;
26+
using Microsoft.Win32;
27+
using ResourceEditor.ViewModels;
2828

2929
namespace ResourceEditor
3030
{
3131
class AddNewFileCommand : AbstractMenuCommand
3232
{
3333
public override void Run()
3434
{
35-
ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor;
35+
ResourceEditorViewModel editor = ((ResourceEditViewContent) SD.Workbench.ActiveViewContent).ResourceEditor;
3636

37-
if(editor.ResourceList.WriteProtected) {
38-
return;
39-
}
37+
// TODO Reactivate this
38+
// if (editor.ResourceList.WriteProtected) {
39+
// return;
40+
// }
4041

41-
using (OpenFileDialog fdiag = new OpenFileDialog()) {
42-
fdiag.AddExtension = true;
43-
fdiag.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.AllFiles}|*.*");
44-
fdiag.Multiselect = true;
45-
fdiag.CheckFileExists = true;
46-
47-
if (fdiag.ShowDialog(SD.WinForms.MainWin32Window) == DialogResult.OK) {
48-
foreach (string filename in fdiag.FileNames) {
49-
string oresname = Path.ChangeExtension(Path.GetFileName(filename), null);
50-
if (oresname == "") oresname = "new";
51-
52-
string resname = oresname;
53-
54-
int i = 0;
55-
TestName:
56-
if (editor.ResourceList.Resources.ContainsKey(resname)) {
57-
if (i == 10) {
58-
continue;
59-
}
60-
i++;
61-
resname = oresname + "_" + i.ToString();
62-
goto TestName;
63-
}
64-
65-
object tmp = loadResource(filename);
66-
if (tmp == null) {
67-
continue;
68-
}
69-
editor.ResourceList.Resources.Add(resname, new ResourceItem(resname, tmp));
70-
71-
}
72-
editor.ResourceList.InitializeListView();
73-
}
74-
}
75-
editor.ResourceList.OnChanged();
42+
// using (OpenFileDialog fdiag = new OpenFileDialog()) {
43+
// fdiag.AddExtension = true;
44+
// fdiag.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.AllFiles}|*.*");
45+
// fdiag.Multiselect = true;
46+
// fdiag.CheckFileExists = true;
47+
//
48+
// if (fdiag.ShowDialog()) {
49+
// foreach (string filename in fdiag.FileNames) {
50+
// string oresname = Path.ChangeExtension(Path.GetFileName(filename), null);
51+
// if (oresname == "")
52+
// oresname = "new";
53+
//
54+
// string resname = oresname;
55+
//
56+
// int i = 0;
57+
// TestName:
58+
// if (editor.ResourceList.Resources.ContainsKey(resname)) {
59+
// if (i == 10) {
60+
// continue;
61+
// }
62+
// i++;
63+
// resname = oresname + "_" + i.ToString();
64+
// goto TestName;
65+
// }
66+
//
67+
// object tmp = loadResource(filename);
68+
// if (tmp == null) {
69+
// continue;
70+
// }
71+
// editor.ResourceList.Resources.Add(resname, new ResourceItem(resname, tmp));
72+
//
73+
// }
74+
// editor.ResourceList.InitializeListView();
75+
// }
76+
// }
77+
// editor.ResourceList.OnChanged();
7678
}
7779

7880
object loadResource(string name)
7981
{
8082
switch (Path.GetExtension(name).ToUpperInvariant()) {
8183
case ".CUR":
8284
try {
83-
return new Cursor(name);
85+
return new System.Windows.Forms.Cursor(name);
8486
} catch {
8587
return null;
8688
}
8789
case ".ICO":
8890
try {
89-
return new Icon(name);
91+
return new System.Drawing.Icon(name);
9092
} catch {
9193
return null;
9294
}
9395
default:
9496
// try to read a bitmap
9597
try {
96-
return new Bitmap(name);
97-
} catch {}
98+
return new System.Drawing.Bitmap(name);
99+
} catch {
100+
}
98101

99102
// try to read a serialized object
100103
try {
@@ -104,8 +107,11 @@ object loadResource(string name)
104107
object o = c.Deserialize(r);
105108
r.Close();
106109
return o;
107-
} catch { r.Close(); }
108-
} catch { }
110+
} catch {
111+
r.Close();
112+
}
113+
} catch {
114+
}
109115

110116
// try to read a byte array :)
111117
try {
@@ -115,7 +121,7 @@ object loadResource(string name)
115121
d = r.ReadBytes((int) s.Length);
116122
s.Close();
117123
return d;
118-
} catch(Exception) {
124+
} catch (Exception) {
119125

120126

121127
string message = ResourceService.GetString("ResourceEditor.Messages.CantLoadResource");

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,37 @@
2020
using System.Windows.Forms;
2121
using ICSharpCode.Core;
2222
using ICSharpCode.SharpDevelop;
23+
using ResourceEditor.ViewModels;
2324

2425
namespace ResourceEditor
2526
{
2627
class AddStringCommand : AbstractMenuCommand
2728
{
2829
public override void Run()
2930
{
30-
ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor;
31+
ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor;
3132

32-
if(editor.ResourceList.WriteProtected) {
33-
return;
34-
}
35-
36-
int count = 1;
37-
string newNameBase = " new string entry ";
38-
string newName = newNameBase + count.ToString();
39-
string type = "System.String";
40-
41-
while(editor.ResourceList.Resources.ContainsKey(newName)) {
42-
count++;
43-
newName = newNameBase + count.ToString();
44-
}
45-
46-
ResourceItem item = new ResourceItem(newName, "");
47-
editor.ResourceList.Resources.Add(newName, item);
48-
ListViewItem lv = new ListViewItem(new string[] { newName, type, "" }, item.ImageIndex);
49-
editor.ResourceList.Items.Add(lv);
50-
editor.ResourceList.OnChanged();
51-
lv.BeginEdit();
33+
// TODO Reactivate this
34+
// if(editor.ResourceList.WriteProtected) {
35+
// return;
36+
// }
37+
//
38+
// int count = 1;
39+
// string newNameBase = " new string entry ";
40+
// string newName = newNameBase + count.ToString();
41+
// string type = "System.String";
42+
//
43+
// while(editor.ResourceList.Resources.ContainsKey(newName)) {
44+
// count++;
45+
// newName = newNameBase + count.ToString();
46+
// }
47+
//
48+
// ResourceItem item = new ResourceItem(newName, "");
49+
// editor.ResourceList.Resources.Add(newName, item);
50+
// ListViewItem lv = new ListViewItem(new string[] { newName, type, "" }, item.ImageIndex);
51+
// editor.ResourceList.Items.Add(lv);
52+
// editor.ResourceList.OnChanged();
53+
// lv.BeginEdit();
5254
}
5355
}
5456
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@
2121
using ICSharpCode.Core;
2222
using ICSharpCode.SharpDevelop;
2323
using ICSharpCode.SharpDevelop.Gui;
24+
using ResourceEditor.ViewModels;
2425

2526
namespace ResourceEditor
2627
{
2728
class CopyResourceNameCommand : AbstractMenuCommand
2829
{
2930
public override void Run()
3031
{
31-
ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor;
32+
ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor;
3233

33-
if(editor.ResourceList.SelectedItems.Count > 0) {
34-
Clipboard.SetText(editor.ResourceList.SelectedItems[0].Text);
35-
}
34+
// TODO Reactivate this
35+
// if(editor.ResourceList.SelectedItems.Count > 0) {
36+
// Clipboard.SetText(editor.ResourceList.SelectedItems[0].Text);
37+
// }
3638
}
3739
}
3840
}

0 commit comments

Comments
 (0)