mirror of https://github.com/icsharpcode/ILSpy.git
6 changed files with 201 additions and 2 deletions
@ -0,0 +1,41 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Linq; |
||||||
|
using ICSharpCode.ILSpy; |
||||||
|
using ICSharpCode.ILSpy.TreeNodes; |
||||||
|
using ICSharpCode.TreeView; |
||||||
|
using Microsoft.Win32; |
||||||
|
using Mono.Cecil; |
||||||
|
|
||||||
|
namespace TestPlugin |
||||||
|
{ |
||||||
|
[ExportContextMenuEntry(Header = "_Save Assembly")] |
||||||
|
public class SaveAssembly : IContextMenuEntry |
||||||
|
{ |
||||||
|
public bool IsVisible(SharpTreeNode[] selectedNodes) |
||||||
|
{ |
||||||
|
return selectedNodes.All(n => n is AssemblyTreeNode); |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsEnabled(SharpTreeNode[] selectedNodes) |
||||||
|
{ |
||||||
|
return selectedNodes.Length == 1; |
||||||
|
} |
||||||
|
|
||||||
|
public void Execute(SharpTreeNode[] selectedNodes) |
||||||
|
{ |
||||||
|
AssemblyTreeNode node = (AssemblyTreeNode)selectedNodes[0]; |
||||||
|
AssemblyDefinition asm = node.LoadedAssembly.AssemblyDefinition as AssemblyDefinition; |
||||||
|
if (asm != null) { |
||||||
|
SaveFileDialog dlg = new SaveFileDialog(); |
||||||
|
dlg.FileName = node.LoadedAssembly.FileName; |
||||||
|
dlg.Filter = "Assembly|*.dll;*.exe"; |
||||||
|
if (dlg.ShowDialog(MainWindow.Instance) == true) { |
||||||
|
asm.MainModule.Write(dlg.FileName); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,8 @@ |
|||||||
|
<UserControl x:Class="TestPlugin.CustomOptionPage" |
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||||
|
<StackPanel> |
||||||
|
<CheckBox IsChecked="{Binding UselessOption1}">Useless option 1</CheckBox> |
||||||
|
<Slider Minimum="0" Maximum="100" Value="{Binding UselessOption2}"/> |
||||||
|
</StackPanel> |
||||||
|
</UserControl> |
@ -0,0 +1,94 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.ComponentModel; |
||||||
|
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.Xml.Linq; |
||||||
|
using ICSharpCode.ILSpy; |
||||||
|
|
||||||
|
namespace TestPlugin |
||||||
|
{ |
||||||
|
[ExportOptionPage("TestPlugin")] |
||||||
|
partial class CustomOptionPage : UserControl, IOptionPage |
||||||
|
{ |
||||||
|
static readonly XNamespace ns = "http://www.ilspy.net/testplugin"; |
||||||
|
|
||||||
|
public CustomOptionPage() |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
} |
||||||
|
|
||||||
|
public void Load(ILSpySettings settings) |
||||||
|
{ |
||||||
|
// For loading options, use ILSpySetting's indexer.
|
||||||
|
// If the specified section does exist, the indexer will return a new empty element.
|
||||||
|
XElement e = settings[ns + "CustomOptions"]; |
||||||
|
// Now load the options from the XML document:
|
||||||
|
Options s = new Options(); |
||||||
|
s.UselessOption1 = (bool?)e.Attribute("useless1") ?? s.UselessOption1; |
||||||
|
s.UselessOption2 = (double?)e.Attribute("useless2") ?? s.UselessOption2; |
||||||
|
this.DataContext = s; |
||||||
|
} |
||||||
|
|
||||||
|
public void Save(XElement root) |
||||||
|
{ |
||||||
|
Options s = (Options)this.DataContext; |
||||||
|
// Save the options back into XML:
|
||||||
|
XElement section = new XElement(ns + "CustomOptions"); |
||||||
|
section.SetAttributeValue("useless1", s.UselessOption1); |
||||||
|
section.SetAttributeValue("useless2", s.UselessOption2); |
||||||
|
|
||||||
|
// Replace the existing section in the settings file, or add a new section,
|
||||||
|
// if required.
|
||||||
|
XElement existingElement = root.Element(ns + "CustomOptions"); |
||||||
|
if (existingElement != null) |
||||||
|
existingElement.ReplaceWith(section); |
||||||
|
else |
||||||
|
root.Add(section); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class Options : INotifyPropertyChanged |
||||||
|
{ |
||||||
|
bool uselessOption1; |
||||||
|
|
||||||
|
public bool UselessOption1 { |
||||||
|
get { return uselessOption1; } |
||||||
|
set { |
||||||
|
if (uselessOption1 != value) { |
||||||
|
uselessOption1 = value; |
||||||
|
OnPropertyChanged("UselessOption1"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
double uselessOption2; |
||||||
|
|
||||||
|
public double UselessOption2 { |
||||||
|
get { return uselessOption2; } |
||||||
|
set { |
||||||
|
if (uselessOption2 != value) { |
||||||
|
uselessOption2 = value; |
||||||
|
OnPropertyChanged("UselessOption2"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public event PropertyChangedEventHandler PropertyChanged; |
||||||
|
|
||||||
|
protected virtual void OnPropertyChanged(string propertyName) |
||||||
|
{ |
||||||
|
if (PropertyChanged != null) { |
||||||
|
PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue