22 changed files with 76 additions and 1397 deletions
@ -1,88 +0,0 @@ |
|||||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Drawing; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
namespace ResourceEditor |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// This control is used for displaying images. Large images
|
|
||||||
/// can be scrolled.
|
|
||||||
/// </summary>
|
|
||||||
abstract class AbstractImageView : ScrollableControl, IResourceView |
|
||||||
{ |
|
||||||
protected PictureBox pictureBox; |
|
||||||
|
|
||||||
public event ResourceChangedEventHandler ResourceChanged; |
|
||||||
|
|
||||||
public abstract ResourceItem ResourceItem |
|
||||||
{ |
|
||||||
get; |
|
||||||
set; |
|
||||||
} |
|
||||||
|
|
||||||
public abstract bool WriteProtected |
|
||||||
{ |
|
||||||
get; |
|
||||||
set; |
|
||||||
} |
|
||||||
|
|
||||||
protected void resized(object sender, EventArgs e) |
|
||||||
{ |
|
||||||
adjustMargin(); |
|
||||||
} |
|
||||||
|
|
||||||
protected AbstractImageView(ResourceItem item) |
|
||||||
{ |
|
||||||
Dock = DockStyle.Fill; |
|
||||||
AutoScroll = true; |
|
||||||
pictureBox = new PictureBox(); |
|
||||||
pictureBox.BorderStyle = BorderStyle.FixedSingle; |
|
||||||
this.SizeChanged += new EventHandler(resized); |
|
||||||
pictureBox.SizeMode = PictureBoxSizeMode.AutoSize; |
|
||||||
Controls.Add(this.pictureBox); |
|
||||||
ResourceItem = item; |
|
||||||
} |
|
||||||
|
|
||||||
protected void OnResourceChanged(string resourceName, object val) |
|
||||||
{ |
|
||||||
if(ResourceChanged != null) { |
|
||||||
ResourceChanged(this, new ResourceEventArgs(resourceName, val)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
protected void adjustMargin() |
|
||||||
{ |
|
||||||
int deltaY = Height - pictureBox.Image.Height; |
|
||||||
int deltaX = Width - pictureBox.Image.Width; |
|
||||||
|
|
||||||
if(deltaY > 0) { |
|
||||||
pictureBox.Top = deltaY / 2; |
|
||||||
} |
|
||||||
pictureBox.Top = Math.Max(pictureBox.Top, 20); |
|
||||||
|
|
||||||
if(deltaX > 0) { |
|
||||||
pictureBox.Left = deltaX / 2; |
|
||||||
} |
|
||||||
pictureBox.Left = Math.Max(pictureBox.Left, 20); |
|
||||||
AutoScrollMargin = new Size(pictureBox.Left / 2, pictureBox.Top / 2); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,139 +0,0 @@ |
|||||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Drawing; |
|
||||||
using System.Text; |
|
||||||
using System.Text.RegularExpressions; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
using ICSharpCode.Core; |
|
||||||
using ICSharpCode.Core.WinForms; |
|
||||||
|
|
||||||
namespace ResourceEditor |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// This class displays binary data.
|
|
||||||
/// </summary>
|
|
||||||
class BinaryView : UserControl, IResourceView |
|
||||||
{ |
|
||||||
TextBox byteDataTextBox = new TextBox(); |
|
||||||
CheckBox viewHexDumpCheckBox = new CheckBox(); |
|
||||||
|
|
||||||
ResourceItem resourceItem; |
|
||||||
|
|
||||||
ASCIIEncoding enc = new ASCIIEncoding(); |
|
||||||
Regex rgex = new Regex(@"\p{Cc}"); |
|
||||||
|
|
||||||
public event ResourceChangedEventHandler ResourceChanged; |
|
||||||
|
|
||||||
public BinaryView(ResourceItem item) |
|
||||||
{ |
|
||||||
|
|
||||||
|
|
||||||
byteDataTextBox.ReadOnly = true; |
|
||||||
byteDataTextBox.Multiline = true; |
|
||||||
|
|
||||||
byteDataTextBox.Top = 24; |
|
||||||
byteDataTextBox.Left = 0; |
|
||||||
byteDataTextBox.Width = Width; |
|
||||||
byteDataTextBox.Height = Height - 24; |
|
||||||
byteDataTextBox.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Top; |
|
||||||
byteDataTextBox.Font = WinFormsResourceService.LoadFont("Courier New", 10); |
|
||||||
byteDataTextBox.ScrollBars = ScrollBars.Both; |
|
||||||
byteDataTextBox.BackColor = SystemColors.Window; |
|
||||||
|
|
||||||
viewHexDumpCheckBox.Location = new Point(8, 4); |
|
||||||
viewHexDumpCheckBox.Size = new Size(Width - 16, 16); |
|
||||||
viewHexDumpCheckBox.Text = StringParser.Parse("${res:ResourceEditor.ResourceEdit.ShowAsHexDump}"); |
|
||||||
viewHexDumpCheckBox.CheckedChanged += new EventHandler(CheckEvt); |
|
||||||
|
|
||||||
Controls.Add(byteDataTextBox); |
|
||||||
Controls.Add(viewHexDumpCheckBox); |
|
||||||
byteDataTextBox.Select(); |
|
||||||
ResourceItem = item; |
|
||||||
} |
|
||||||
|
|
||||||
public bool WriteProtected |
|
||||||
{ |
|
||||||
get { |
|
||||||
return true; |
|
||||||
} |
|
||||||
set { |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public ResourceItem ResourceItem |
|
||||||
{ |
|
||||||
get { |
|
||||||
return resourceItem; |
|
||||||
} |
|
||||||
set { |
|
||||||
resourceItem = value; |
|
||||||
showData(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
protected void OnResourceChanged(string resourceName, object val) |
|
||||||
{ |
|
||||||
if(ResourceChanged != null) { |
|
||||||
ResourceChanged(this, new ResourceEventArgs(resourceName, val)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void showData() |
|
||||||
{ |
|
||||||
byte[] bytes= (byte[])ResourceItem.ResourceValue; |
|
||||||
string regText = enc.GetString(bytes).Replace("\x0", "."); |
|
||||||
|
|
||||||
if (viewHexDumpCheckBox.Checked) { |
|
||||||
// Hex Dump
|
|
||||||
StringBuilder sb = new StringBuilder(); |
|
||||||
|
|
||||||
string byteString = BitConverter.ToString(bytes).Replace("-", " "); |
|
||||||
string stext = rgex.Replace(regText, "."); |
|
||||||
|
|
||||||
byteDataTextBox.Text = ""; |
|
||||||
int max = bytes.Length; |
|
||||||
int last = max % 16; |
|
||||||
|
|
||||||
int i = 0; |
|
||||||
int count = 16; |
|
||||||
do { |
|
||||||
sb.Append(String.Format("{0:X8} ", i) + |
|
||||||
byteString.Substring(i*3, (count * 3) - 1) + " " + |
|
||||||
stext.Substring(i, count) + "\r\n"); |
|
||||||
i += 16; |
|
||||||
if (i >= (max - last)) { |
|
||||||
count = last; |
|
||||||
} |
|
||||||
} while (i < max); |
|
||||||
byteDataTextBox.Text = sb.ToString(); |
|
||||||
} else { |
|
||||||
// Regular Text
|
|
||||||
byteDataTextBox.Text = regText; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void CheckEvt(object sender, EventArgs e) |
|
||||||
{ |
|
||||||
showData(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,92 +0,0 @@ |
|||||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Drawing; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
using ICSharpCode.Core; |
|
||||||
using ICSharpCode.SharpDevelop; |
|
||||||
|
|
||||||
namespace ResourceEditor |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// This control is used for displaying images. Large images
|
|
||||||
/// can be scrolled.
|
|
||||||
/// </summary>
|
|
||||||
class BitmapView : AbstractImageView |
|
||||||
{ |
|
||||||
ResourceItem resourceItem; |
|
||||||
LinkLabel updateLinkLabel; |
|
||||||
|
|
||||||
public BitmapView(ResourceItem item) : base(item) |
|
||||||
{ |
|
||||||
|
|
||||||
updateLinkLabel = new LinkLabel(); |
|
||||||
updateLinkLabel.Text = ResourceService.GetString("ResourceEditor.BitmapView.UpdateBitmap"); |
|
||||||
updateLinkLabel.Location = new Point(4, 4); |
|
||||||
updateLinkLabel.AutoSize = true; |
|
||||||
updateLinkLabel.Click += new EventHandler(updateBitmapLinkLabelClick); |
|
||||||
Controls.Add(updateLinkLabel); |
|
||||||
} |
|
||||||
|
|
||||||
void updateBitmapLinkLabelClick(object sender, EventArgs e) |
|
||||||
{ |
|
||||||
using(OpenFileDialog fileDialog = new OpenFileDialog()) |
|
||||||
{ |
|
||||||
Bitmap bitmap; |
|
||||||
fileDialog.AddExtension = true; |
|
||||||
fileDialog.Filter = "All files (*.*)|*.*"; |
|
||||||
fileDialog.CheckFileExists = true; |
|
||||||
|
|
||||||
if(fileDialog.ShowDialog(SD.WinForms.MainWin32Window) == DialogResult.OK) { |
|
||||||
try { |
|
||||||
bitmap = new Bitmap(fileDialog.FileName); |
|
||||||
} catch { |
|
||||||
|
|
||||||
MessageService.ShowWarning("Can't load bitmap file."); |
|
||||||
return; |
|
||||||
} |
|
||||||
ResourceItem = new ResourceItem(resourceItem.Name, bitmap); |
|
||||||
OnResourceChanged(resourceItem.Name, bitmap); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public override bool WriteProtected |
|
||||||
{ |
|
||||||
get { |
|
||||||
return true; |
|
||||||
} |
|
||||||
set { |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public override ResourceItem ResourceItem |
|
||||||
{ |
|
||||||
get { |
|
||||||
return resourceItem; |
|
||||||
} |
|
||||||
set { |
|
||||||
resourceItem = value; |
|
||||||
pictureBox.Image = (Bitmap)value.ResourceValue; |
|
||||||
adjustMargin(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,86 +0,0 @@ |
|||||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Drawing; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
namespace ResourceEditor |
|
||||||
{ |
|
||||||
class BooleanView : Panel, IResourceView |
|
||||||
{ |
|
||||||
public event ResourceChangedEventHandler ResourceChanged; |
|
||||||
private ResourceItem resourceItem; |
|
||||||
|
|
||||||
private RadioButton trueRadioButton = new RadioButton(); |
|
||||||
private RadioButton falseRadioButton = new RadioButton(); |
|
||||||
|
|
||||||
public BooleanView(ResourceItem item) |
|
||||||
{ |
|
||||||
trueRadioButton.Location = new Point(4, 4); |
|
||||||
trueRadioButton.Text = "True"; |
|
||||||
trueRadioButton.CheckedChanged += new EventHandler(valueChanged); |
|
||||||
Controls.Add(trueRadioButton); |
|
||||||
|
|
||||||
falseRadioButton.Location = new Point(4, 24); |
|
||||||
falseRadioButton.Text = "False"; |
|
||||||
falseRadioButton.CheckedChanged += new EventHandler(valueChanged); |
|
||||||
Controls.Add(falseRadioButton); |
|
||||||
|
|
||||||
ResourceItem = item; |
|
||||||
} |
|
||||||
|
|
||||||
public bool WriteProtected |
|
||||||
{ |
|
||||||
get { |
|
||||||
return ! trueRadioButton.Enabled; |
|
||||||
} |
|
||||||
set { |
|
||||||
trueRadioButton.Enabled = ! value; |
|
||||||
falseRadioButton.Enabled = ! value; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public ResourceItem ResourceItem |
|
||||||
{ |
|
||||||
get { |
|
||||||
return resourceItem; |
|
||||||
} |
|
||||||
set { |
|
||||||
this.resourceItem = value; |
|
||||||
if((bool)resourceItem.ResourceValue == true) { |
|
||||||
trueRadioButton.Checked = true; |
|
||||||
} else { |
|
||||||
falseRadioButton.Checked = true; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
protected void OnResourceChanged(string resourceName, object val) |
|
||||||
{ |
|
||||||
if(ResourceChanged != null) { |
|
||||||
ResourceChanged(this, new ResourceEventArgs(resourceName, val)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void valueChanged(object sender, EventArgs e) |
|
||||||
{ |
|
||||||
OnResourceChanged(resourceItem.Name, trueRadioButton.Checked); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,65 +0,0 @@ |
|||||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Drawing; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
namespace ResourceEditor |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// This control is used for displaying images. Large images
|
|
||||||
/// can be scrolled.
|
|
||||||
/// </summary>
|
|
||||||
class CursorView : AbstractImageView |
|
||||||
{ |
|
||||||
ResourceItem resourceItem; |
|
||||||
|
|
||||||
public CursorView(ResourceItem item) : base(item) |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
public override bool WriteProtected |
|
||||||
{ |
|
||||||
get { |
|
||||||
return true; |
|
||||||
} |
|
||||||
set { |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public override ResourceItem ResourceItem |
|
||||||
{ |
|
||||||
get { |
|
||||||
return resourceItem; |
|
||||||
} |
|
||||||
set { |
|
||||||
resourceItem = value; |
|
||||||
|
|
||||||
Cursor c = (Cursor)resourceItem.ResourceValue; |
|
||||||
Bitmap a = new Bitmap(c.Size.Width, c.Size.Height); |
|
||||||
Graphics g = Graphics.FromImage(a); |
|
||||||
g.FillRectangle(new SolidBrush(Color.DarkCyan), 0, 0, a.Width, a.Height); |
|
||||||
c.Draw(g, new Rectangle(0, 0, a.Width, a.Height)); |
|
||||||
pictureBox.Image = a; |
|
||||||
g.Dispose(); |
|
||||||
adjustMargin(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,73 +0,0 @@ |
|||||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
|
|
||||||
namespace ResourceEditor |
|
||||||
{ |
|
||||||
delegate void ResourceChangedEventHandler(object sender, ResourceEventArgs e); |
|
||||||
|
|
||||||
interface IResourceView : IDisposable |
|
||||||
{ |
|
||||||
bool WriteProtected |
|
||||||
{ |
|
||||||
get; |
|
||||||
set; |
|
||||||
} |
|
||||||
|
|
||||||
ResourceItem ResourceItem |
|
||||||
{ |
|
||||||
get; |
|
||||||
set; |
|
||||||
} |
|
||||||
|
|
||||||
event ResourceChangedEventHandler ResourceChanged; |
|
||||||
} |
|
||||||
|
|
||||||
class ResourceEventArgs |
|
||||||
{ |
|
||||||
string resourceName; |
|
||||||
object resourceValue; |
|
||||||
|
|
||||||
public ResourceEventArgs(string resourceName, object resourceValue) |
|
||||||
{ |
|
||||||
this.resourceName = resourceName; |
|
||||||
this.resourceValue = resourceValue; |
|
||||||
} |
|
||||||
|
|
||||||
public string ResourceName |
|
||||||
{ |
|
||||||
get { |
|
||||||
return resourceName; |
|
||||||
} |
|
||||||
set { |
|
||||||
resourceName = value; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public object ResourceValue |
|
||||||
{ |
|
||||||
get { |
|
||||||
return resourceValue; |
|
||||||
} |
|
||||||
set { |
|
||||||
resourceValue = value; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,57 +0,0 @@ |
|||||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Drawing; |
|
||||||
|
|
||||||
namespace ResourceEditor |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// This control is used for displaying images. Large images
|
|
||||||
/// can be scrolled.
|
|
||||||
/// </summary>
|
|
||||||
class IconView : AbstractImageView |
|
||||||
{ |
|
||||||
ResourceItem resourceItem; |
|
||||||
|
|
||||||
public IconView(ResourceItem item) : base(item) |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
public override bool WriteProtected |
|
||||||
{ |
|
||||||
get { |
|
||||||
return true; |
|
||||||
} |
|
||||||
set { |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public override ResourceItem ResourceItem |
|
||||||
{ |
|
||||||
get { |
|
||||||
return resourceItem; |
|
||||||
} |
|
||||||
set { |
|
||||||
resourceItem = value; |
|
||||||
pictureBox.Image = ((Icon)value.ResourceValue).ToBitmap(); |
|
||||||
adjustMargin(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,157 +0,0 @@ |
|||||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Drawing; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
using ICSharpCode.Core; |
|
||||||
using ICSharpCode.SharpDevelop.WinForms; |
|
||||||
|
|
||||||
namespace ResourceEditor |
|
||||||
{ |
|
||||||
public class ResourceEditorControl : UserControl, IOwnerState |
|
||||||
{ |
|
||||||
ResourceList resourceList; |
|
||||||
Splitter splitter; |
|
||||||
Panel panel; |
|
||||||
IResourceView currentView = null; |
|
||||||
|
|
||||||
[Flags] |
|
||||||
public enum ListViewViewState { |
|
||||||
Nothing = 0, |
|
||||||
ItemsSelected = 1, |
|
||||||
} |
|
||||||
|
|
||||||
protected ListViewViewState internalState = ListViewViewState.Nothing; |
|
||||||
|
|
||||||
public Enum InternalState { |
|
||||||
get { |
|
||||||
return internalState; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public ResourceList ResourceList |
|
||||||
{ |
|
||||||
get { |
|
||||||
return resourceList; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public ResourceEditorControl() |
|
||||||
{ |
|
||||||
InitializeComponent(); |
|
||||||
resourceList.SelectedIndexChanged += ResourceListSelectionChanged; |
|
||||||
} |
|
||||||
|
|
||||||
void ResourceListSelectionChanged(object sender, EventArgs e) |
|
||||||
{ |
|
||||||
if(resourceList.SelectedItems.Count == 0) { |
|
||||||
internalState = ListViewViewState.Nothing; |
|
||||||
ShowResource(null); |
|
||||||
} else { |
|
||||||
internalState = ListViewViewState.ItemsSelected; |
|
||||||
} |
|
||||||
|
|
||||||
if(resourceList.SelectedItems.Count != 1) { |
|
||||||
return; |
|
||||||
} |
|
||||||
object key = resourceList.SelectedItems[0].Text; |
|
||||||
ResourceItem item = (ResourceItem)resourceList.Resources[key.ToString()]; |
|
||||||
ShowResource(item); |
|
||||||
} |
|
||||||
|
|
||||||
void InitializeComponent() |
|
||||||
{ |
|
||||||
resourceList = new ResourceList(this); |
|
||||||
resourceList.Dock = DockStyle.Top; |
|
||||||
Controls.Add(resourceList); |
|
||||||
|
|
||||||
panel = new Panel(); |
|
||||||
panel.BackColor = SystemColors.Info; |
|
||||||
panel.Dock = DockStyle.Fill; |
|
||||||
|
|
||||||
splitter = new Splitter(); |
|
||||||
splitter.Dock = DockStyle.Top; |
|
||||||
|
|
||||||
Controls.Add(panel); |
|
||||||
Controls.Add(splitter); |
|
||||||
Controls.Add(resourceList); |
|
||||||
|
|
||||||
this.Resize += InitializeLayout; |
|
||||||
} |
|
||||||
|
|
||||||
void InitializeLayout(object sender, EventArgs e) |
|
||||||
{ |
|
||||||
resourceList.Height = Convert.ToInt32(0.75 * Height); |
|
||||||
} |
|
||||||
|
|
||||||
void ShowView(Control viewer) |
|
||||||
{ |
|
||||||
// remove old view if there is one
|
|
||||||
if(panel.Controls.Count == 1) { |
|
||||||
Control control = panel.Controls[0]; |
|
||||||
panel.Controls.Remove(control); |
|
||||||
control.Dispose(); |
|
||||||
} |
|
||||||
|
|
||||||
if(viewer != null) { |
|
||||||
viewer.Dock = DockStyle.Fill; |
|
||||||
panel.Controls.Add(viewer); |
|
||||||
currentView = (IResourceView)viewer; |
|
||||||
currentView.WriteProtected = resourceList.WriteProtected; |
|
||||||
currentView.ResourceChanged += ViewResourceChanged; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void ViewResourceChanged(object sender, ResourceEventArgs e) |
|
||||||
{ |
|
||||||
resourceList.SetResourceValue(e.ResourceName, e.ResourceValue); |
|
||||||
} |
|
||||||
|
|
||||||
void ShowResource(ResourceItem item) |
|
||||||
{ |
|
||||||
if(item == null) { |
|
||||||
ShowView(null); |
|
||||||
return; |
|
||||||
} |
|
||||||
if (item.ResourceValue is Icon) { |
|
||||||
IconView iv = new IconView(item); |
|
||||||
ShowView(iv); |
|
||||||
} else if(item.ResourceValue is Bitmap) { |
|
||||||
BitmapView bv = new BitmapView(item); |
|
||||||
ShowView(bv); |
|
||||||
} else if(item.ResourceValue is Cursor) { |
|
||||||
CursorView cv = new CursorView(item); |
|
||||||
ShowView(cv); |
|
||||||
} else if(item.ResourceValue is string) { |
|
||||||
TextView tv = new TextView(item); |
|
||||||
ShowView(tv); |
|
||||||
} else if(item.ResourceValue is byte[]) { |
|
||||||
BinaryView bv = new BinaryView(item); |
|
||||||
ShowView(bv); |
|
||||||
} else if(item.ResourceValue is bool) { |
|
||||||
BooleanView bv = new BooleanView(item); |
|
||||||
ShowView(bv); |
|
||||||
} else { |
|
||||||
ShowView(null); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,116 +0,0 @@ |
|||||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Drawing; |
|
||||||
using System.Resources; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
namespace ResourceEditor |
|
||||||
{ |
|
||||||
public class ResourceItem |
|
||||||
{ |
|
||||||
public ResourceItem(string name, object resourceValue) |
|
||||||
{ |
|
||||||
this.Name = name; |
|
||||||
this.ResourceValue = resourceValue; |
|
||||||
} |
|
||||||
|
|
||||||
public ResourceItem(string name, object resourceValue, string comment) |
|
||||||
{ |
|
||||||
this.Name = name; |
|
||||||
this.ResourceValue = resourceValue; |
|
||||||
this.Comment = comment; |
|
||||||
} |
|
||||||
|
|
||||||
public string Name { get; set; } |
|
||||||
|
|
||||||
public object ResourceValue { get; set; } |
|
||||||
|
|
||||||
public string Comment { get; set; } |
|
||||||
|
|
||||||
public int ImageIndex |
|
||||||
{ |
|
||||||
get { |
|
||||||
if (this.ResourceValue == null) { |
|
||||||
return -1; |
|
||||||
} |
|
||||||
switch(this.ResourceValue.GetType().ToString()) { |
|
||||||
case "System.String": |
|
||||||
return 0; |
|
||||||
case "System.Drawing.Bitmap": |
|
||||||
return 1; |
|
||||||
case "System.Drawing.Icon": |
|
||||||
return 2; |
|
||||||
case "System.Windows.Forms.Cursor": |
|
||||||
return 3; |
|
||||||
case "System.Byte[]": |
|
||||||
return 4; |
|
||||||
default: |
|
||||||
return 5; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public override string ToString() |
|
||||||
{ |
|
||||||
if (ResourceValue == null) { |
|
||||||
return "(Nothing/null)"; |
|
||||||
} |
|
||||||
|
|
||||||
string type = ResourceValue.GetType().FullName; |
|
||||||
string tmp = String.Empty; |
|
||||||
|
|
||||||
switch (type) { |
|
||||||
case "System.String": |
|
||||||
tmp = ResourceValue.ToString(); |
|
||||||
break; |
|
||||||
case "System.Byte[]": |
|
||||||
tmp = "[Size = " + ((byte[])ResourceValue).Length + "]"; |
|
||||||
break; |
|
||||||
case "System.Drawing.Bitmap": |
|
||||||
Bitmap bmp = ResourceValue as Bitmap; |
|
||||||
tmp = "[Width = " + bmp.Size.Width + ", Height = " + bmp.Size.Height + "]"; |
|
||||||
break; |
|
||||||
case "System.Drawing.Icon": |
|
||||||
Icon icon = ResourceValue as Icon; |
|
||||||
tmp = "[Width = " + icon.Size.Width + ", Height = " + icon.Size.Height + "]"; |
|
||||||
break; |
|
||||||
case "System.Windows.Forms.Cursor": |
|
||||||
Cursor c = ResourceValue as Cursor; |
|
||||||
tmp = "[Width = " + c.Size.Width + ", Height = " + c.Size.Height + "]"; |
|
||||||
break; |
|
||||||
case "System.Boolean": |
|
||||||
tmp = ResourceValue.ToString(); |
|
||||||
break; |
|
||||||
default: |
|
||||||
tmp = ResourceValue.ToString(); |
|
||||||
break; |
|
||||||
} |
|
||||||
return tmp; |
|
||||||
} |
|
||||||
|
|
||||||
public ResXDataNode ToResXDataNode(Func<Type, string> typeNameConverter = null) |
|
||||||
{ |
|
||||||
var node = new ResXDataNode(Name, ResourceValue, typeNameConverter) { |
|
||||||
Comment = Comment |
|
||||||
}; |
|
||||||
return node; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,317 +0,0 @@ |
|||||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Collections; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.ComponentModel.Design; |
|
||||||
using System.Drawing.Printing; |
|
||||||
using System.IO; |
|
||||||
using System.Resources; |
|
||||||
using System.Windows.Forms; |
|
||||||
using ICSharpCode.Core; |
|
||||||
using ICSharpCode.Core.WinForms; |
|
||||||
using ICSharpCode.SharpDevelop.Project; |
|
||||||
using ICSharpCode.SharpDevelop.Widgets.ListViewSorting; |
|
||||||
|
|
||||||
namespace ResourceEditor |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// This class allows viewing and editing of windows resource files
|
|
||||||
/// both in XML as in normal format.
|
|
||||||
/// </summary>
|
|
||||||
public class ResourceList : ListView |
|
||||||
{ |
|
||||||
ColumnHeader name = new ColumnHeader(); |
|
||||||
ColumnHeader type = new ColumnHeader(); |
|
||||||
ColumnHeader content = new ColumnHeader(); |
|
||||||
ColumnHeader comment = new ColumnHeader(); |
|
||||||
|
|
||||||
Dictionary<string, ResourceItem> resources = new Dictionary<string, ResourceItem>(); |
|
||||||
Dictionary<string, ResourceItem> metadata = new Dictionary<string, ResourceItem>(); |
|
||||||
ImageList images = new ImageList(); |
|
||||||
|
|
||||||
bool writeProtected = false; |
|
||||||
int editListViewItemIndex = -1; |
|
||||||
|
|
||||||
ListViewItemSorter sorter; |
|
||||||
|
|
||||||
public event EventHandler Changed; |
|
||||||
|
|
||||||
public bool WriteProtected |
|
||||||
{ |
|
||||||
get { |
|
||||||
return writeProtected; |
|
||||||
} |
|
||||||
set { |
|
||||||
writeProtected = value; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public Dictionary<string, ResourceItem> Resources |
|
||||||
{ |
|
||||||
get { |
|
||||||
return resources; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public PrintDocument PrintDocument |
|
||||||
{ |
|
||||||
get { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public bool IsEditing { |
|
||||||
get { |
|
||||||
return editListViewItemIndex != -1; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public ResourceList(ResourceEditorControl editor) |
|
||||||
{ |
|
||||||
name.Text = ResourceService.GetString("Global.Name"); |
|
||||||
name.Width = 250; |
|
||||||
|
|
||||||
type.Text = ResourceService.GetString("ResourceEditor.ResourceEdit.TypeColumn"); |
|
||||||
type.Width = 170; |
|
||||||
|
|
||||||
content.Text = ResourceService.GetString("ResourceEditor.ResourceEdit.ContentColumn"); |
|
||||||
content.Width = 300; |
|
||||||
|
|
||||||
comment.Text = ResourceService.GetString("ResourceEditor.ResourceEdit.CommentColumn"); |
|
||||||
comment.Width = 300; |
|
||||||
|
|
||||||
Columns.AddRange(new ColumnHeader[] {name, type, content, comment}); |
|
||||||
|
|
||||||
FullRowSelect = true; |
|
||||||
AutoArrange = true; |
|
||||||
Alignment = ListViewAlignment.Left; |
|
||||||
View = View.Details; |
|
||||||
GridLines = true; |
|
||||||
LabelEdit = true; |
|
||||||
Dock = DockStyle.Fill; |
|
||||||
HideSelection = false; |
|
||||||
|
|
||||||
BorderStyle = System.Windows.Forms.BorderStyle.None; |
|
||||||
|
|
||||||
images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.string")); |
|
||||||
images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.bmp")); |
|
||||||
images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.icon")); |
|
||||||
images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.cursor")); |
|
||||||
images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.bin")); |
|
||||||
images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.obj")); |
|
||||||
SmallImageList = images; |
|
||||||
|
|
||||||
// Set up sorting:
|
|
||||||
// User can sort the list by name and by type,
|
|
||||||
// whereas sorting by type also implicitly sorts by name.
|
|
||||||
IListViewItemComparer textComparer = new ListViewTextColumnComparer(); |
|
||||||
IListViewItemComparer typeNameComparer = new ListViewMultipleColumnsComparer(textComparer, 1, textComparer, 0); |
|
||||||
sorter = new ListViewItemSorter(this, |
|
||||||
new IListViewItemComparer[] { |
|
||||||
textComparer, |
|
||||||
typeNameComparer, |
|
||||||
null, |
|
||||||
null |
|
||||||
}); |
|
||||||
sorter.SortColumnIndex = 0; |
|
||||||
sorter.SortOrder = SortOrder.Ascending; |
|
||||||
|
|
||||||
ContextMenuStrip = MenuService.CreateContextMenu(editor, "/SharpDevelop/ResourceEditor/ResourceList/ContextMenu"); |
|
||||||
} |
|
||||||
|
|
||||||
protected override void Dispose(bool disposing) |
|
||||||
{ |
|
||||||
try { |
|
||||||
if (disposing) { |
|
||||||
if (sorter != null) { |
|
||||||
sorter.Dispose(); |
|
||||||
sorter = null; |
|
||||||
} |
|
||||||
} |
|
||||||
} finally { |
|
||||||
base.Dispose(disposing); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void LoadFile(FileName filename, Stream stream) |
|
||||||
{ |
|
||||||
resources.Clear(); |
|
||||||
metadata.Clear(); |
|
||||||
switch (Path.GetExtension(filename).ToLowerInvariant()) { |
|
||||||
case ".resx": |
|
||||||
ResXResourceReader rx = new ResXResourceReader(stream); |
|
||||||
ITypeResolutionService typeResolver = null; |
|
||||||
rx.BasePath = Path.GetDirectoryName(filename); |
|
||||||
rx.UseResXDataNodes = true; |
|
||||||
IDictionaryEnumerator n = rx.GetEnumerator(); |
|
||||||
while (n.MoveNext()) { |
|
||||||
if (!resources.ContainsKey(n.Key.ToString())) { |
|
||||||
ResXDataNode node = (ResXDataNode)n.Value; |
|
||||||
resources.Add(n.Key.ToString(), new ResourceItem(node.Name, node.GetValue(typeResolver), node.Comment)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
n = rx.GetMetadataEnumerator(); |
|
||||||
while (n.MoveNext()) { |
|
||||||
if (!metadata.ContainsKey(n.Key.ToString())) { |
|
||||||
ResXDataNode node = (ResXDataNode)n.Value; |
|
||||||
metadata.Add(n.Key.ToString(), new ResourceItem(node.Name, node.GetValue(typeResolver))); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
rx.Close(); |
|
||||||
break; |
|
||||||
case ".resources": |
|
||||||
ResourceReader rr=null; |
|
||||||
try { |
|
||||||
rr = new ResourceReader(stream); |
|
||||||
foreach (DictionaryEntry entry in rr) { |
|
||||||
if (!resources.ContainsKey(entry.Key.ToString())) |
|
||||||
resources.Add(entry.Key.ToString(), new ResourceItem(entry.Key.ToString(), entry.Value)); |
|
||||||
} |
|
||||||
} |
|
||||||
finally { |
|
||||||
if (rr != null) { |
|
||||||
rr.Close(); |
|
||||||
} |
|
||||||
} |
|
||||||
break; |
|
||||||
} |
|
||||||
InitializeListView(); |
|
||||||
} |
|
||||||
|
|
||||||
public void SaveFile(FileName filename, Stream stream) |
|
||||||
{ |
|
||||||
switch (Path.GetExtension(filename).ToLowerInvariant()) { |
|
||||||
case ".resx": |
|
||||||
// write XML resource
|
|
||||||
ResXResourceWriter rxw = new ResXResourceWriter(stream, t => ResXConverter.ConvertTypeName(t, filename)); |
|
||||||
foreach (KeyValuePair<string, ResourceItem> entry in resources) { |
|
||||||
if (entry.Value != null) { |
|
||||||
ResourceItem item = entry.Value; |
|
||||||
rxw.AddResource(item.ToResXDataNode(t => ResXConverter.ConvertTypeName(t, filename))); |
|
||||||
} |
|
||||||
} |
|
||||||
foreach (KeyValuePair<string, ResourceItem> entry in metadata) { |
|
||||||
if (entry.Value != null) { |
|
||||||
ResourceItem item = entry.Value; |
|
||||||
rxw.AddMetadata(item.Name, item.ResourceValue); |
|
||||||
} |
|
||||||
} |
|
||||||
rxw.Generate(); |
|
||||||
rxw.Close(); |
|
||||||
break; |
|
||||||
default: |
|
||||||
// write default resource
|
|
||||||
ResourceWriter rw = new ResourceWriter(stream); |
|
||||||
foreach (KeyValuePair<string, ResourceItem> entry in resources) { |
|
||||||
ResourceItem item = (ResourceItem)entry.Value; |
|
||||||
rw.AddResource(item.Name, item.ResourceValue); |
|
||||||
} |
|
||||||
rw.Generate(); |
|
||||||
rw.Close(); |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void SetResourceValue(string resourceName, object resourceValue) |
|
||||||
{ |
|
||||||
ResourceItem item = ((ResourceItem)Resources[resourceName]); |
|
||||||
item.ResourceValue = resourceValue; |
|
||||||
SelectedItems[0].SubItems[2].Text = item.ToString(); |
|
||||||
OnChanged(); |
|
||||||
} |
|
||||||
|
|
||||||
public void SetCommentValue(string resourceName, string commentValue) |
|
||||||
{ |
|
||||||
ResourceItem item = ((ResourceItem)Resources[resourceName]); |
|
||||||
item.Comment = commentValue; |
|
||||||
SelectedItems[0].SubItems[3].Text = item.Comment; |
|
||||||
OnChanged(); |
|
||||||
} |
|
||||||
|
|
||||||
public void OnChanged() |
|
||||||
{ |
|
||||||
if (Changed != null) { |
|
||||||
Changed(this, null); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void InitializeListView() |
|
||||||
{ |
|
||||||
BeginUpdate(); |
|
||||||
// Suspend sorting to improve performance
|
|
||||||
ListViewItemSorter = null; |
|
||||||
Items.Clear(); |
|
||||||
|
|
||||||
foreach (KeyValuePair<string, ResourceItem> entry in resources) { |
|
||||||
ResourceItem item = entry.Value; |
|
||||||
|
|
||||||
string tmp = item.ToString(); |
|
||||||
string type = item.ResourceValue == null ? "(Nothing/null)" : item.ResourceValue.GetType().FullName; |
|
||||||
|
|
||||||
ListViewItem lv = new ListViewItem(new String[] {item.Name, type, tmp, item.Comment}, item.ImageIndex); |
|
||||||
Items.Add(lv); |
|
||||||
} |
|
||||||
|
|
||||||
ListViewItemSorter = sorter; |
|
||||||
EndUpdate(); |
|
||||||
} |
|
||||||
|
|
||||||
protected override void OnAfterLabelEdit(LabelEditEventArgs e) |
|
||||||
{ |
|
||||||
editListViewItemIndex = -1; |
|
||||||
|
|
||||||
if (writeProtected) { |
|
||||||
e.CancelEdit = true; |
|
||||||
return; |
|
||||||
} |
|
||||||
string oldName = this.Items[e.Item].Text; |
|
||||||
string newName = e.Label; |
|
||||||
|
|
||||||
if(newName == null) { |
|
||||||
// no change
|
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
ResourceItem item = (ResourceItem)resources[oldName]; |
|
||||||
|
|
||||||
if(resources.ContainsKey(newName)) { |
|
||||||
|
|
||||||
MessageService.ShowWarning("${res:ResourceEditor.ResourceList.KeyAlreadyDefinedWarning}"); |
|
||||||
e.CancelEdit = true; |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
resources.Remove(oldName); |
|
||||||
item.Name = newName; |
|
||||||
resources.Add(newName, item); |
|
||||||
OnChanged(); |
|
||||||
} |
|
||||||
|
|
||||||
protected override void OnBeforeLabelEdit(LabelEditEventArgs e) |
|
||||||
{ |
|
||||||
base.OnBeforeLabelEdit(e); |
|
||||||
if (!e.CancelEdit) { |
|
||||||
editListViewItemIndex = e.Item; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,70 +0,0 @@ |
|||||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
namespace ResourceEditor |
|
||||||
{ |
|
||||||
class TextView : TextBox, IResourceView |
|
||||||
{ |
|
||||||
public event ResourceChangedEventHandler ResourceChanged; |
|
||||||
private ResourceItem resourceItem; |
|
||||||
|
|
||||||
public TextView(ResourceItem item) |
|
||||||
{ |
|
||||||
this.Multiline = true; |
|
||||||
this.ResourceItem = item; |
|
||||||
this.ScrollBars = ScrollBars.Both; |
|
||||||
this.TextChanged += new EventHandler(textChanged); |
|
||||||
} |
|
||||||
|
|
||||||
public bool WriteProtected |
|
||||||
{ |
|
||||||
get { |
|
||||||
return ! Enabled; |
|
||||||
} |
|
||||||
set { |
|
||||||
Enabled = ! value; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public ResourceItem ResourceItem |
|
||||||
{ |
|
||||||
get { |
|
||||||
return resourceItem; |
|
||||||
} |
|
||||||
set { |
|
||||||
resourceItem = value; |
|
||||||
Text = (string)value.ResourceValue; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
protected void OnResourceChanged(string resourceName, object val) |
|
||||||
{ |
|
||||||
if(ResourceChanged != null) { |
|
||||||
ResourceChanged(this, new ResourceEventArgs(resourceName, val)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void textChanged(object sender, EventArgs e) |
|
||||||
{ |
|
||||||
OnResourceChanged(resourceItem.Name, Text); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
Loading…
Reference in new issue