Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3267 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
52 changed files with 2933 additions and 93 deletions
@ -0,0 +1,181 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Text; |
||||||
|
using System.Windows.Input; |
||||||
|
using System.Windows.Documents; |
||||||
|
using System.Windows.Controls.Primitives; |
||||||
|
using System.Windows.Controls; |
||||||
|
using System.Windows.Media; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Markup; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.Globalization; |
||||||
|
using System.Windows.Threading; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner |
||||||
|
{ |
||||||
|
public enum DisableMode |
||||||
|
{ |
||||||
|
Disable, Collapse |
||||||
|
} |
||||||
|
|
||||||
|
public class ActionArgs |
||||||
|
{ |
||||||
|
public FrameworkElement Element { get; internal set; } |
||||||
|
} |
||||||
|
|
||||||
|
public delegate void ActionHandler(ActionArgs e); |
||||||
|
public delegate bool CanActionHandler(ActionArgs e); |
||||||
|
|
||||||
|
public class Action |
||||||
|
{ |
||||||
|
public Action() |
||||||
|
{ |
||||||
|
Elements = new List<FrameworkElement>(); |
||||||
|
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Loaded, new System.Action(RegisterRequery)); |
||||||
|
} |
||||||
|
|
||||||
|
void RegisterRequery() |
||||||
|
{ |
||||||
|
CommandManager.RequerySuggested += new EventHandler(CommandManager_RequerySuggested); |
||||||
|
} |
||||||
|
|
||||||
|
void CommandManager_RequerySuggested(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
UpdateElements(); |
||||||
|
} |
||||||
|
|
||||||
|
public string Text { get; set; } |
||||||
|
public Shortcut Shortcut { get; set; } |
||||||
|
public ImageSource IconSource { get; set; } |
||||||
|
public DisableMode DisableMode { get; set; } |
||||||
|
public event ActionHandler Executed; |
||||||
|
public event CanActionHandler CanExecute; |
||||||
|
public List<FrameworkElement> Elements { get; private set; } |
||||||
|
|
||||||
|
public object ExecuteHost { |
||||||
|
get { |
||||||
|
if (Executed != null) return Executed.Target; |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void AttachTo(FrameworkElement f) |
||||||
|
{ |
||||||
|
SetText(f); |
||||||
|
SetShortcut(f); |
||||||
|
SetIcon(f); |
||||||
|
SetEvent(f); |
||||||
|
|
||||||
|
Elements.Add(f); |
||||||
|
} |
||||||
|
|
||||||
|
public void UpdateElements() |
||||||
|
{ |
||||||
|
if (CanExecute != null) { |
||||||
|
foreach (var f in Elements) { |
||||||
|
f.IsEnabled = CanExecute(new ActionArgs() { Element = f }); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SetText(FrameworkElement f) |
||||||
|
{ |
||||||
|
if (Text == null) return; |
||||||
|
if (f is ContentControl) { |
||||||
|
(f as ContentControl).Content = Text; |
||||||
|
} |
||||||
|
else if (f is HeaderedItemsControl) { |
||||||
|
(f as HeaderedItemsControl).Header = Text; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SetShortcut(FrameworkElement f) |
||||||
|
{ |
||||||
|
if (Shortcut == null) return; |
||||||
|
if (f is MenuItem) { |
||||||
|
(f as MenuItem).InputGestureText = Shortcut.ToString(); |
||||||
|
} |
||||||
|
if (ExecuteHost == null) return; |
||||||
|
(ExecuteHost as IInputElement).KeyDown += delegate(object sender, KeyEventArgs e) { |
||||||
|
if (e.Key == Shortcut.Key && Keyboard.Modifiers == Shortcut.Modifiers) { |
||||||
|
Executed(new ActionArgs() { Element = f }); |
||||||
|
} |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
void SetIcon(FrameworkElement f) |
||||||
|
{ |
||||||
|
if (IconSource == null) return; |
||||||
|
if (f is MenuItem) { |
||||||
|
(f as MenuItem).Icon = new Image() { Source = IconSource }; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SetEvent(FrameworkElement f) |
||||||
|
{ |
||||||
|
if (Executed == null) return; |
||||||
|
f.PreviewMouseLeftButtonUp += delegate { |
||||||
|
Executed(new ActionArgs() { Element = f }); |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static class ActionManager |
||||||
|
{ |
||||||
|
public static void SetAction(DependencyObject obj, object value) |
||||||
|
{ |
||||||
|
Action a = value as Action; |
||||||
|
if (a == null) { |
||||||
|
if (obj is FrameworkElement) { |
||||||
|
a = (Action)(obj as FrameworkElement).FindResource(value); |
||||||
|
} |
||||||
|
} |
||||||
|
a.AttachTo(obj as FrameworkElement); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[TypeConverter(typeof(ShortcutConverter))] |
||||||
|
public class Shortcut |
||||||
|
{ |
||||||
|
public ModifierKeys Modifiers; |
||||||
|
public Key Key; |
||||||
|
|
||||||
|
static KeyConverter KeyConverter = new KeyConverter(); |
||||||
|
static ModifierKeysConverter ModifierKeysConverter = new ModifierKeysConverter(); |
||||||
|
|
||||||
|
public static Shortcut FromString(string s) |
||||||
|
{ |
||||||
|
var result = new Shortcut(); |
||||||
|
var pos = s.LastIndexOf('+'); |
||||||
|
if (pos < 0) { |
||||||
|
result.Key = (Key)KeyConverter.ConvertFromString(s); |
||||||
|
} |
||||||
|
else { |
||||||
|
result.Modifiers = (ModifierKeys)ModifierKeysConverter.ConvertFromString(s.Substring(0, pos)); |
||||||
|
result.Key = (Key)KeyConverter.ConvertFromString(s.Substring(pos + 1)); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
public override string ToString() |
||||||
|
{ |
||||||
|
if (Modifiers == ModifierKeys.None) return KeyConverter.ConvertToString(Key); |
||||||
|
return ModifierKeysConverter.ConvertToString(Modifiers) + "+" + KeyConverter.ConvertToString(Key); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class ShortcutConverter : TypeConverter |
||||||
|
{ |
||||||
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) |
||||||
|
{ |
||||||
|
return sourceType == typeof(string); |
||||||
|
} |
||||||
|
|
||||||
|
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) |
||||||
|
{ |
||||||
|
return Shortcut.FromString((string)value); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
<Application x:Class="ICSharpCode.XamlDesigner.App" |
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||||
|
xmlns:Converters="clr-namespace:ICSharpCode.XamlDesigner.Converters" |
||||||
|
StartupUri="MainWindow.xaml"> |
||||||
|
<Application.Resources> |
||||||
|
|
||||||
|
<Converters:CollapsedWhenFalse x:Key="CollapsedWhenFalse" /> |
||||||
|
<Converters:FalseWhenZero x:Key="FalseWhenZero" /> |
||||||
|
|
||||||
|
<Style x:Key="TabButtonStyle" |
||||||
|
TargetType="ToggleButton"> |
||||||
|
<Setter Property="Width" |
||||||
|
Value="50" /> |
||||||
|
<Setter Property="ClickMode" |
||||||
|
Value="Press" /> |
||||||
|
<Setter Property="Margin" |
||||||
|
Value="3 3 0 3" /> |
||||||
|
</Style> |
||||||
|
|
||||||
|
</Application.Resources> |
||||||
|
</Application> |
@ -0,0 +1,37 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Configuration; |
||||||
|
using System.Data; |
||||||
|
using System.Linq; |
||||||
|
using System.Windows; |
||||||
|
using ICSharpCode.XamlDesigner.Configuration; |
||||||
|
using System.Windows.Threading; |
||||||
|
using System.Diagnostics; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner |
||||||
|
{ |
||||||
|
public partial class App |
||||||
|
{ |
||||||
|
public static string[] Args; |
||||||
|
|
||||||
|
protected override void OnStartup(StartupEventArgs e) |
||||||
|
{ |
||||||
|
DispatcherUnhandledException += App_DispatcherUnhandledException; |
||||||
|
Args = e.Args; |
||||||
|
System.Windows.Forms.Application.EnableVisualStyles(); |
||||||
|
base.OnStartup(e); |
||||||
|
} |
||||||
|
|
||||||
|
void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) |
||||||
|
{ |
||||||
|
Shell.ReportException(e.Exception); |
||||||
|
e.Handled = true; |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnExit(ExitEventArgs e) |
||||||
|
{ |
||||||
|
Settings.Default.Save(); |
||||||
|
base.OnExit(e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,32 @@ |
|||||||
|
<Button x:Class="ICSharpCode.XamlDesigner.BitmapButton" |
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||||
|
Focusable="False"> |
||||||
|
<Button.Template> |
||||||
|
<ControlTemplate TargetType="Button"> |
||||||
|
<Image x:Name="image1" |
||||||
|
Stretch="None" |
||||||
|
Source="{Binding ImageNormal}" /> |
||||||
|
<ControlTemplate.Triggers> |
||||||
|
<Trigger Property="IsMouseOver" |
||||||
|
Value="True"> |
||||||
|
<Setter Property="Source" |
||||||
|
Value="{Binding ImageHover}" |
||||||
|
TargetName="image1" /> |
||||||
|
</Trigger> |
||||||
|
<Trigger Property="IsPressed" |
||||||
|
Value="True"> |
||||||
|
<Setter Property="Source" |
||||||
|
Value="{Binding ImagePressed}" |
||||||
|
TargetName="image1" /> |
||||||
|
</Trigger> |
||||||
|
<Trigger Property="IsEnabled" |
||||||
|
Value="False"> |
||||||
|
<Setter Property="Source" |
||||||
|
Value="{Binding ImageDisabled}" |
||||||
|
TargetName="image1" /> |
||||||
|
</Trigger> |
||||||
|
</ControlTemplate.Triggers> |
||||||
|
</ControlTemplate> |
||||||
|
</Button.Template> |
||||||
|
</Button> |
@ -0,0 +1,45 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
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 System.Windows.Navigation; |
||||||
|
using System.Windows.Shapes; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner |
||||||
|
{ |
||||||
|
public partial class BitmapButton |
||||||
|
{ |
||||||
|
public BitmapButton() |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
DataContext = this; |
||||||
|
} |
||||||
|
|
||||||
|
public string ImageHover { |
||||||
|
get { return "Images/" + GetType().Name + ".Hover.png"; } |
||||||
|
} |
||||||
|
|
||||||
|
public string ImageNormal { |
||||||
|
get { return "Images/" + GetType().Name + ".Normal.png"; } |
||||||
|
} |
||||||
|
|
||||||
|
public string ImagePressed { |
||||||
|
get { return "Images/" + GetType().Name + ".Pressed.png"; } |
||||||
|
} |
||||||
|
|
||||||
|
public string ImageDisabled { |
||||||
|
get { return "Images/" + GetType().Name + ".Disabled.png"; } |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class CloseButton : BitmapButton |
||||||
|
{ |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
using System.Reflection; |
||||||
|
using System.Resources; |
||||||
|
using System.Runtime.CompilerServices; |
||||||
|
using System.Runtime.InteropServices; |
||||||
|
using System.Windows; |
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("XamlDesigner")] |
||||||
|
[assembly: AssemblyDescription("")] |
||||||
|
[assembly: AssemblyConfiguration("")] |
||||||
|
[assembly: AssemblyTrademark("")] |
||||||
|
[assembly: AssemblyCulture("")] |
||||||
|
|
||||||
|
//In order to begin building localizable applications, set
|
||||||
|
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
|
||||||
|
//inside a <PropertyGroup>. For example, if you are using US english
|
||||||
|
//in your source files, set the <UICulture> to en-US. Then uncomment
|
||||||
|
//the NeutralResourceLanguage attribute below. Update the "en-US" in
|
||||||
|
//the line below to match the UICulture setting in the project file.
|
||||||
|
|
||||||
|
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
|
||||||
|
|
||||||
|
|
||||||
|
[assembly: ThemeInfo( |
||||||
|
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||||
|
//(used if a resource is not found in the page,
|
||||||
|
// or application resource dictionaries)
|
||||||
|
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||||
|
//(used if a resource is not found in the page,
|
||||||
|
// app, or any theme specific resource dictionaries)
|
||||||
|
)] |
@ -0,0 +1,110 @@ |
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// This code was generated by a tool.
|
||||||
|
// Runtime Version:2.0.50727.3031
|
||||||
|
//
|
||||||
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
|
// the code is regenerated.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner.Configuration { |
||||||
|
|
||||||
|
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] |
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")] |
||||||
|
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { |
||||||
|
|
||||||
|
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); |
||||||
|
|
||||||
|
public static Settings Default { |
||||||
|
get { |
||||||
|
return defaultInstance; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[global::System.Configuration.UserScopedSettingAttribute()] |
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||||
|
[global::System.Configuration.DefaultSettingValueAttribute("0,0,0,0")] |
||||||
|
public global::System.Windows.Rect MainWindowRect { |
||||||
|
get { |
||||||
|
return ((global::System.Windows.Rect)(this["MainWindowRect"])); |
||||||
|
} |
||||||
|
set { |
||||||
|
this["MainWindowRect"] = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[global::System.Configuration.UserScopedSettingAttribute()] |
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||||
|
[global::System.Configuration.DefaultSettingValueAttribute(@"<DockingManager>
|
||||||
|
<ResizingPanel Orientation=""Horizontal""> |
||||||
|
<ResizingPanel ResizeWidth=""200"" Orientation=""Vertical""> |
||||||
|
<DockablePane ResizeHeight=""441.36166666666668"" Anchor=""Left""> |
||||||
|
<DockableContent Name=""content1"" AutoHide=""false"" /> |
||||||
|
</DockablePane> |
||||||
|
<DockablePane ResizeWidth=""200"" Anchor=""Left""> |
||||||
|
<DockableContent Name=""content2"" AutoHide=""false"" /> |
||||||
|
</DockablePane> |
||||||
|
</ResizingPanel> |
||||||
|
<ResizingPanel Orientation=""Vertical""> |
||||||
|
<DocumentPanePlaceHolder /> |
||||||
|
<DockablePane ResizeHeight=""138"" Anchor=""Bottom""> |
||||||
|
<DockableContent Name=""content3"" AutoHide=""false"" /> |
||||||
|
</DockablePane> |
||||||
|
</ResizingPanel> |
||||||
|
<DockablePane ResizeWidth=""271"" Anchor=""Right""> |
||||||
|
<DockableContent Name=""content4"" AutoHide=""false"" /> |
||||||
|
</DockablePane> |
||||||
|
</ResizingPanel> |
||||||
|
<Hidden /> |
||||||
|
<Windows /> |
||||||
|
</DockingManager>")]
|
||||||
|
public string AvalonDockLayout { |
||||||
|
get { |
||||||
|
return ((string)(this["AvalonDockLayout"])); |
||||||
|
} |
||||||
|
set { |
||||||
|
this["AvalonDockLayout"] = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[global::System.Configuration.UserScopedSettingAttribute()] |
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||||
|
public global::System.Collections.Specialized.StringCollection RecentFiles { |
||||||
|
get { |
||||||
|
return ((global::System.Collections.Specialized.StringCollection)(this["RecentFiles"])); |
||||||
|
} |
||||||
|
set { |
||||||
|
this["RecentFiles"] = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[global::System.Configuration.UserScopedSettingAttribute()] |
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||||
|
[global::System.Configuration.DefaultSettingValueAttribute(@"<?xml version=""1.0"" encoding=""utf-16""?>
|
||||||
|
<ArrayOfString xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
|
||||||
|
<string>%ProgramFiles%\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll</string> |
||||||
|
</ArrayOfString>")]
|
||||||
|
public global::System.Collections.Specialized.StringCollection AssemblyList { |
||||||
|
get { |
||||||
|
return ((global::System.Collections.Specialized.StringCollection)(this["AssemblyList"])); |
||||||
|
} |
||||||
|
set { |
||||||
|
this["AssemblyList"] = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[global::System.Configuration.UserScopedSettingAttribute()] |
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||||
|
[global::System.Configuration.DefaultSettingValueAttribute("Maximized")] |
||||||
|
public global::System.Windows.WindowState MainWindowState { |
||||||
|
get { |
||||||
|
return ((global::System.Windows.WindowState)(this["MainWindowState"])); |
||||||
|
} |
||||||
|
set { |
||||||
|
this["MainWindowState"] = value; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,46 @@ |
|||||||
|
<?xml version='1.0' encoding='utf-8'?> |
||||||
|
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="ICSharpCode.XamlDesigner.Configuration" GeneratedClassName="Settings"> |
||||||
|
<Profiles /> |
||||||
|
<Settings> |
||||||
|
<Setting Name="MainWindowRect" Type="System.Windows.Rect" Scope="User"> |
||||||
|
<Value Profile="(Default)">0,0,0,0</Value> |
||||||
|
</Setting> |
||||||
|
<Setting Name="AvalonDockLayout" Type="System.String" Scope="User"> |
||||||
|
<Value Profile="(Default)"><DockingManager> |
||||||
|
<ResizingPanel Orientation="Horizontal"> |
||||||
|
<ResizingPanel ResizeWidth="200" Orientation="Vertical"> |
||||||
|
<DockablePane ResizeHeight="441.36166666666668" Anchor="Left"> |
||||||
|
<DockableContent Name="content1" AutoHide="false" /> |
||||||
|
</DockablePane> |
||||||
|
<DockablePane ResizeWidth="200" Anchor="Left"> |
||||||
|
<DockableContent Name="content2" AutoHide="false" /> |
||||||
|
</DockablePane> |
||||||
|
</ResizingPanel> |
||||||
|
<ResizingPanel Orientation="Vertical"> |
||||||
|
<DocumentPanePlaceHolder /> |
||||||
|
<DockablePane ResizeHeight="138" Anchor="Bottom"> |
||||||
|
<DockableContent Name="content3" AutoHide="false" /> |
||||||
|
</DockablePane> |
||||||
|
</ResizingPanel> |
||||||
|
<DockablePane ResizeWidth="271" Anchor="Right"> |
||||||
|
<DockableContent Name="content4" AutoHide="false" /> |
||||||
|
</DockablePane> |
||||||
|
</ResizingPanel> |
||||||
|
<Hidden /> |
||||||
|
<Windows /> |
||||||
|
</DockingManager></Value> |
||||||
|
</Setting> |
||||||
|
<Setting Name="RecentFiles" Type="System.Collections.Specialized.StringCollection" Scope="User"> |
||||||
|
<Value Profile="(Default)" /> |
||||||
|
</Setting> |
||||||
|
<Setting Name="AssemblyList" Type="System.Collections.Specialized.StringCollection" Scope="User"> |
||||||
|
<Value Profile="(Default)"><?xml version="1.0" encoding="utf-16"?> |
||||||
|
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
||||||
|
<string>%ProgramFiles%\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll</string> |
||||||
|
</ArrayOfString></Value> |
||||||
|
</Setting> |
||||||
|
<Setting Name="MainWindowState" Type="System.Windows.WindowState" Scope="User"> |
||||||
|
<Value Profile="(Default)">Maximized</Value> |
||||||
|
</Setting> |
||||||
|
</Settings> |
||||||
|
</SettingsFile> |
@ -0,0 +1,51 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8" ?> |
||||||
|
<configuration> |
||||||
|
<configSections> |
||||||
|
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > |
||||||
|
<section name="ICSharpCode.XamlDesigner.Configuration.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> |
||||||
|
</sectionGroup> |
||||||
|
</configSections> |
||||||
|
<userSettings> |
||||||
|
<ICSharpCode.XamlDesigner.Configuration.Settings> |
||||||
|
<setting name="MainWindowRect" serializeAs="String"> |
||||||
|
<value>0,0,0,0</value> |
||||||
|
</setting> |
||||||
|
<setting name="AvalonDockLayout" serializeAs="String"> |
||||||
|
<value><DockingManager> |
||||||
|
<ResizingPanel Orientation="Horizontal"> |
||||||
|
<ResizingPanel ResizeWidth="200" Orientation="Vertical"> |
||||||
|
<DockablePane ResizeHeight="441.36166666666668" Anchor="Left"> |
||||||
|
<DockableContent Name="content1" AutoHide="false" /> |
||||||
|
</DockablePane> |
||||||
|
<DockablePane ResizeWidth="200" Anchor="Left"> |
||||||
|
<DockableContent Name="content2" AutoHide="false" /> |
||||||
|
</DockablePane> |
||||||
|
</ResizingPanel> |
||||||
|
<ResizingPanel Orientation="Vertical"> |
||||||
|
<DocumentPanePlaceHolder /> |
||||||
|
<DockablePane ResizeHeight="138" Anchor="Bottom"> |
||||||
|
<DockableContent Name="content3" AutoHide="false" /> |
||||||
|
</DockablePane> |
||||||
|
</ResizingPanel> |
||||||
|
<DockablePane ResizeWidth="271" Anchor="Right"> |
||||||
|
<DockableContent Name="content4" AutoHide="false" /> |
||||||
|
</DockablePane> |
||||||
|
</ResizingPanel> |
||||||
|
<Hidden /> |
||||||
|
<Windows /> |
||||||
|
</DockingManager></value> |
||||||
|
</setting> |
||||||
|
<setting name="AssemblyList" serializeAs="Xml"> |
||||||
|
<value> |
||||||
|
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
||||||
|
<string>%ProgramFiles%\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll</string> |
||||||
|
</ArrayOfString> |
||||||
|
</value> |
||||||
|
</setting> |
||||||
|
<setting name="MainWindowState" serializeAs="String"> |
||||||
|
<value>Maximized</value> |
||||||
|
</setting> |
||||||
|
</ICSharpCode.XamlDesigner.Configuration.Settings> |
||||||
|
</userSettings> |
||||||
|
</configuration> |
@ -0,0 +1,29 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
||||||
|
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/> |
||||||
|
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> |
||||||
|
<security> |
||||||
|
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> |
||||||
|
<!-- UAC Manifest Options |
||||||
|
If you want to change the Windows User Account Control level replace the |
||||||
|
requestedExecutionLevel node with one of the following. |
||||||
|
|
||||||
|
<requestedExecutionLevel level="asInvoker" uiAccess="false" /> |
||||||
|
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> |
||||||
|
<requestedExecutionLevel level="highestAvailable" uiAccess="false" /> |
||||||
|
|
||||||
|
If you want to utilize File and Registry Virtualization for backward |
||||||
|
compatibility then delete the requestedExecutionLevel node. |
||||||
|
--> |
||||||
|
<requestedExecutionLevel level="asInvoker" uiAccess="false" /> |
||||||
|
</requestedPrivileges> |
||||||
|
</security> |
||||||
|
</trustInfo> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<dependentAssembly> |
||||||
|
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*"></assemblyIdentity> |
||||||
|
</dependentAssembly> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
</asmv1:assembly> |
@ -0,0 +1,53 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Text; |
||||||
|
using System.Windows.Data; |
||||||
|
using System.Globalization; |
||||||
|
using System.Windows; |
||||||
|
using System.Collections; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner.Converters |
||||||
|
{ |
||||||
|
public class EnumToIntConverter : IValueConverter |
||||||
|
{ |
||||||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
||||||
|
{ |
||||||
|
return (int)value; |
||||||
|
} |
||||||
|
|
||||||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
||||||
|
{ |
||||||
|
return value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class CollapsedWhenFalse : IValueConverter |
||||||
|
{ |
||||||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
||||||
|
{ |
||||||
|
return (bool)value ? Visibility.Visible : Visibility.Collapsed; |
||||||
|
} |
||||||
|
|
||||||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
||||||
|
{ |
||||||
|
throw new NotImplementedException(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class FalseWhenZero : IValueConverter |
||||||
|
{ |
||||||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
||||||
|
{ |
||||||
|
if (value == null || (int)value == 0) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
||||||
|
{ |
||||||
|
throw new NotImplementedException(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,212 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Text; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.IO; |
||||||
|
using ICSharpCode.WpfDesign.Designer; |
||||||
|
using ICSharpCode.WpfDesign.Designer.Xaml; |
||||||
|
using System.Xml; |
||||||
|
using ICSharpCode.WpfDesign; |
||||||
|
using ICSharpCode.WpfDesign.Designer.Services; |
||||||
|
using System.Diagnostics; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner |
||||||
|
{ |
||||||
|
public class Document : INotifyPropertyChanged |
||||||
|
{ |
||||||
|
public Document(string tempName, string text) |
||||||
|
{ |
||||||
|
this.tempName = tempName; |
||||||
|
Text = text; |
||||||
|
IsDirty = false; |
||||||
|
} |
||||||
|
|
||||||
|
public Document(string filePath) |
||||||
|
{ |
||||||
|
this.filePath = filePath; |
||||||
|
ReloadFile(); |
||||||
|
} |
||||||
|
|
||||||
|
string tempName; |
||||||
|
DesignSurface designSurface = new DesignSurface(); |
||||||
|
|
||||||
|
string text; |
||||||
|
|
||||||
|
public string Text { |
||||||
|
get { |
||||||
|
return text; |
||||||
|
} |
||||||
|
set { |
||||||
|
if (text != value) { |
||||||
|
text = value; |
||||||
|
IsDirty = true; |
||||||
|
RaisePropertyChanged("Text"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
DocumentMode mode; |
||||||
|
|
||||||
|
void SetMode(DocumentMode newMode) |
||||||
|
{ |
||||||
|
mode = newMode; |
||||||
|
if (IsDesign) { |
||||||
|
UpdateDesign(); |
||||||
|
} |
||||||
|
else { |
||||||
|
UpdateXaml(); |
||||||
|
} |
||||||
|
RaisePropertyChanged("IsXaml"); |
||||||
|
RaisePropertyChanged("IsDesign"); |
||||||
|
RaisePropertyChanged("SelectionService"); |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsXaml { |
||||||
|
get { return mode == DocumentMode.Xaml; } |
||||||
|
set { if (value) SetMode(DocumentMode.Xaml); } |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsDesign { |
||||||
|
get { return mode == DocumentMode.Design; } |
||||||
|
set { if (value) SetMode(DocumentMode.Design); } |
||||||
|
} |
||||||
|
|
||||||
|
string filePath; |
||||||
|
|
||||||
|
public string FilePath { |
||||||
|
get { |
||||||
|
return filePath; |
||||||
|
} |
||||||
|
private set { |
||||||
|
filePath = value; |
||||||
|
RaisePropertyChanged("FilePath"); |
||||||
|
RaisePropertyChanged("FileName"); |
||||||
|
RaisePropertyChanged("Title"); |
||||||
|
RaisePropertyChanged("Name"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
bool isDirty; |
||||||
|
|
||||||
|
public bool IsDirty { |
||||||
|
get { |
||||||
|
return isDirty; |
||||||
|
} |
||||||
|
private set { |
||||||
|
isDirty = value; |
||||||
|
RaisePropertyChanged("IsDirty"); |
||||||
|
RaisePropertyChanged("Name"); |
||||||
|
RaisePropertyChanged("Title"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string FileName { |
||||||
|
get { |
||||||
|
if (FilePath == null) return null; |
||||||
|
return Path.GetFileName(FilePath); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string Name { |
||||||
|
get { |
||||||
|
return FileName ?? tempName; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string Title { |
||||||
|
get { |
||||||
|
return IsDirty ? Name + "*" : Name; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public DesignSurface DesignSurface { |
||||||
|
get { return designSurface; } |
||||||
|
} |
||||||
|
|
||||||
|
public DesignContext DesignContext { |
||||||
|
get { return designSurface.DesignContext; } |
||||||
|
} |
||||||
|
|
||||||
|
public UndoService UndoService { |
||||||
|
get { return DesignContext.Services.GetService<UndoService>(); } |
||||||
|
} |
||||||
|
|
||||||
|
public ISelectionService SelectionService { |
||||||
|
get { |
||||||
|
if (IsDesign && DesignContext != null) { |
||||||
|
return DesignContext.Services.Selection; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void ReloadFile() |
||||||
|
{ |
||||||
|
Text = File.ReadAllText(FilePath); |
||||||
|
UpdateDesign(); |
||||||
|
IsDirty = false; |
||||||
|
} |
||||||
|
|
||||||
|
public void Save() |
||||||
|
{ |
||||||
|
if (IsDesign) { |
||||||
|
UpdateXaml(); |
||||||
|
} |
||||||
|
File.WriteAllText(FilePath, Text); |
||||||
|
IsDirty = false; |
||||||
|
} |
||||||
|
|
||||||
|
public void SaveAs(string filePath) |
||||||
|
{ |
||||||
|
FilePath = filePath; |
||||||
|
Save(); |
||||||
|
} |
||||||
|
|
||||||
|
void UpdateXaml() |
||||||
|
{ |
||||||
|
var sb = new StringBuilder(); |
||||||
|
using (var xmlWriter = XmlWriter.Create(sb)) { |
||||||
|
try { |
||||||
|
DesignSurface.SaveDesigner(xmlWriter); |
||||||
|
Text = XamlFormatter.Format(sb.ToString()); |
||||||
|
} |
||||||
|
catch (Exception x) { |
||||||
|
Shell.ReportException(x); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void UpdateDesign() |
||||||
|
{ |
||||||
|
try { |
||||||
|
XamlLoadSettings settings = new XamlLoadSettings(); |
||||||
|
using (var xmlReader = XmlReader.Create(new StringReader(Text))) { |
||||||
|
DesignSurface.LoadDesigner(xmlReader, settings); |
||||||
|
} |
||||||
|
UndoService.UndoStackChanged += delegate { IsDirty = true; }; |
||||||
|
} |
||||||
|
catch (Exception x) { |
||||||
|
Shell.ReportException(x); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#region INotifyPropertyChanged Members
|
||||||
|
|
||||||
|
public event PropertyChangedEventHandler PropertyChanged; |
||||||
|
|
||||||
|
void RaisePropertyChanged(string name) |
||||||
|
{ |
||||||
|
if (PropertyChanged != null) { |
||||||
|
PropertyChanged(this, new PropertyChangedEventArgs(name)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
enum DocumentMode |
||||||
|
{ |
||||||
|
Xaml, Design |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
<UserControl |
||||||
|
x:Class="ICSharpCode.XamlDesigner.DocumentView" |
||||||
|
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||||
|
xmlns:Integration="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" |
||||||
|
xmlns:TextEditor="clr-namespace:ICSharpCode.TextEditor;assembly=ICSharpCode.TextEditor" |
||||||
|
> |
||||||
|
|
||||||
|
<!--<TabControl TabStripPlacement="Bottom"> |
||||||
|
<TabItem Header="Xaml" |
||||||
|
IsSelected="{Binding IsXaml}"> |
||||||
|
<Integration:WindowsFormsHost> |
||||||
|
<TextEditor:TextEditorControl x:Name="uxTextEditor" /> |
||||||
|
</Integration:WindowsFormsHost> |
||||||
|
</TabItem> |
||||||
|
<TabItem Header="Design" |
||||||
|
IsSelected="{Binding IsDesign}" |
||||||
|
Content="{Binding DesignSurface}" /> |
||||||
|
</TabControl>--> |
||||||
|
|
||||||
|
<DockPanel> |
||||||
|
<StackPanel Orientation="Horizontal" |
||||||
|
DockPanel.Dock="Bottom"> |
||||||
|
<ToggleButton IsChecked="{Binding IsXaml}" |
||||||
|
Content="Xaml" |
||||||
|
Style="{StaticResource TabButtonStyle}"/> |
||||||
|
<ToggleButton IsChecked="{Binding IsDesign}" |
||||||
|
Content="Design" |
||||||
|
Style="{StaticResource TabButtonStyle}" /> |
||||||
|
</StackPanel> |
||||||
|
<Grid> |
||||||
|
<Integration:WindowsFormsHost Visibility="{Binding IsXaml, Converter={StaticResource CollapsedWhenFalse}}"> |
||||||
|
<TextEditor:TextEditorControl x:Name="uxTextEditor" /> |
||||||
|
</Integration:WindowsFormsHost> |
||||||
|
<ContentPresenter Content="{Binding DesignSurface}" |
||||||
|
Visibility="{Binding IsDesign, Converter={StaticResource CollapsedWhenFalse}}"/> |
||||||
|
</Grid> |
||||||
|
</DockPanel> |
||||||
|
|
||||||
|
</UserControl> |
@ -0,0 +1,26 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
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 System.Windows.Navigation; |
||||||
|
using System.Windows.Shapes; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner |
||||||
|
{ |
||||||
|
public partial class DocumentView |
||||||
|
{ |
||||||
|
public DocumentView(Document doc) |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
uxTextEditor.SetHighlighting("XML"); |
||||||
|
uxTextEditor.DataBindings.Add("Text", doc, "Text", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,57 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Text; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Input; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner |
||||||
|
{ |
||||||
|
class DragListener |
||||||
|
{ |
||||||
|
public DragListener(IInputElement target) |
||||||
|
{ |
||||||
|
this.target = target; |
||||||
|
target.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(target_PreviewMouseLeftButtonDown); |
||||||
|
target.PreviewMouseMove += new MouseEventHandler(target_PreviewMouseMove); |
||||||
|
} |
||||||
|
|
||||||
|
public event MouseEventHandler DragStarted; |
||||||
|
|
||||||
|
IInputElement target; |
||||||
|
Window window; |
||||||
|
Point startPoint; |
||||||
|
bool readyToRaise; |
||||||
|
|
||||||
|
Point GetMousePosition() |
||||||
|
{ |
||||||
|
if (window == null) { |
||||||
|
window = Window.GetWindow(target as DependencyObject); |
||||||
|
} |
||||||
|
return Mouse.GetPosition(window); |
||||||
|
} |
||||||
|
|
||||||
|
bool IsMovementBigEnough() |
||||||
|
{ |
||||||
|
Point currentPoint = GetMousePosition(); |
||||||
|
return (Math.Abs(currentPoint.X - startPoint.X) >= SystemParameters.MinimumHorizontalDragDistance || |
||||||
|
Math.Abs(currentPoint.Y - startPoint.Y) >= SystemParameters.MinimumVerticalDragDistance); |
||||||
|
} |
||||||
|
|
||||||
|
void target_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) |
||||||
|
{ |
||||||
|
readyToRaise = true; |
||||||
|
startPoint = GetMousePosition(); |
||||||
|
} |
||||||
|
|
||||||
|
void target_PreviewMouseMove(object sender, MouseEventArgs e) |
||||||
|
{ |
||||||
|
if (readyToRaise && IsMovementBigEnough()) { |
||||||
|
readyToRaise = false; |
||||||
|
if (DragStarted != null) { |
||||||
|
DragStarted(target, e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,93 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Text; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Documents; |
||||||
|
using System.Windows.Media; |
||||||
|
using System.IO; |
||||||
|
using System.Collections.ObjectModel; |
||||||
|
using System.Collections.Specialized; |
||||||
|
using System.Collections; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner |
||||||
|
{ |
||||||
|
static class ExtensionMethods |
||||||
|
{ |
||||||
|
public static IEnumerable<string> Paths(this IDataObject data) |
||||||
|
{ |
||||||
|
string[] paths = (string[])data.GetData(DataFormats.FileDrop); |
||||||
|
if (paths != null) { |
||||||
|
foreach (var path in paths) { |
||||||
|
yield return path; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static T GetObject<T>(this IDataObject data) |
||||||
|
{ |
||||||
|
return (T)data.GetData(typeof(T).FullName); |
||||||
|
} |
||||||
|
|
||||||
|
public static T FindAncestor<T>(this DependencyObject d) where T : class |
||||||
|
{ |
||||||
|
while (true) { |
||||||
|
if (d == null) return null; |
||||||
|
if (d is T) return d as T; |
||||||
|
d = VisualTreeHelper.GetParent(d); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static Stream ToStream(this string s) |
||||||
|
{ |
||||||
|
return new MemoryStream(Encoding.UTF8.GetBytes(s)); |
||||||
|
} |
||||||
|
|
||||||
|
public static void AddRange<T>(this ObservableCollection<T> col, IEnumerable<T> items) |
||||||
|
{ |
||||||
|
foreach (var item in items) { |
||||||
|
col.Add(item); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static void KeepSyncronizedWith<S>(this IList target, ObservableCollection<S> source, Func<S, object> convert) |
||||||
|
{ |
||||||
|
target.Clear(); |
||||||
|
foreach (var item in source) { |
||||||
|
target.Add(convert(item)); |
||||||
|
} |
||||||
|
|
||||||
|
source.CollectionChanged += delegate(object sender, NotifyCollectionChangedEventArgs e) { |
||||||
|
switch (e.Action) { |
||||||
|
case NotifyCollectionChangedAction.Add: |
||||||
|
target.Add(convert((S)e.NewItems[0])); |
||||||
|
break; |
||||||
|
|
||||||
|
case NotifyCollectionChangedAction.Remove: |
||||||
|
target.RemoveAt(e.OldStartingIndex); |
||||||
|
break; |
||||||
|
|
||||||
|
case NotifyCollectionChangedAction.Move: |
||||||
|
target.RemoveAt(e.OldStartingIndex); |
||||||
|
target.Insert(e.NewStartingIndex, e.NewItems[0]); |
||||||
|
break; |
||||||
|
|
||||||
|
case NotifyCollectionChangedAction.Replace: |
||||||
|
target[e.NewStartingIndex] = convert((S)e.NewItems[0]); |
||||||
|
break; |
||||||
|
|
||||||
|
case NotifyCollectionChangedAction.Reset: |
||||||
|
target.Clear(); |
||||||
|
break; |
||||||
|
} |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
public static object GetDataContext(this RoutedEventArgs e) |
||||||
|
{ |
||||||
|
var f = e.OriginalSource as FrameworkElement; |
||||||
|
if (f != null) return f.DataContext; |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 389 B |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,118 @@ |
|||||||
|
<Window x:Class="ICSharpCode.XamlDesigner.MainWindow" |
||||||
|
x:Name="root" |
||||||
|
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||||
|
xmlns:sd="http://sharpdevelop.net" |
||||||
|
xmlns:AvalonDock="clr-namespace:AvalonDock;assembly=AvalonDock" |
||||||
|
xmlns:XamlDesigner="clr-namespace:ICSharpCode.XamlDesigner" |
||||||
|
SnapsToDevicePixels="True" |
||||||
|
AllowDrop="True" |
||||||
|
Title="{Binding Title}"> |
||||||
|
|
||||||
|
<Window.CommandBindings> |
||||||
|
|
||||||
|
<CommandBinding Command="New" |
||||||
|
Executed="NewCommand_Executed" /> |
||||||
|
|
||||||
|
<CommandBinding Command="Open" |
||||||
|
Executed="OpenCommand_Executed" /> |
||||||
|
|
||||||
|
<CommandBinding Command="Close" |
||||||
|
Executed="CloseCommand_Executed" |
||||||
|
CanExecute="CurrentDocument_CanExecute" |
||||||
|
PreviewExecuted="CloseCommand_PreviewExecuted"/> |
||||||
|
|
||||||
|
<CommandBinding Command="XamlDesigner:MainWindow.CloseAllCommand" |
||||||
|
Executed="CloseAllCommand_Executed" |
||||||
|
CanExecute="CurrentDocument_CanExecute" /> |
||||||
|
|
||||||
|
<CommandBinding Command="Save" |
||||||
|
Executed="SaveCommand_Executed" |
||||||
|
CanExecute="CurrentDocument_CanExecute" /> |
||||||
|
|
||||||
|
<CommandBinding Command="SaveAs" |
||||||
|
Executed="SaveAsCommand_Executed" |
||||||
|
CanExecute="CurrentDocument_CanExecute" /> |
||||||
|
|
||||||
|
<CommandBinding Command="XamlDesigner:MainWindow.SaveAllCommand" |
||||||
|
Executed="SaveAllCommand_Executed" |
||||||
|
CanExecute="CurrentDocument_CanExecute" /> |
||||||
|
|
||||||
|
<CommandBinding Command="XamlDesigner:MainWindow.ExitCommand" |
||||||
|
Executed="ExitCommand_Executed" /> |
||||||
|
|
||||||
|
</Window.CommandBindings> |
||||||
|
|
||||||
|
<DockPanel> |
||||||
|
|
||||||
|
<Menu DockPanel.Dock="Top"> |
||||||
|
<MenuItem Header="File"> |
||||||
|
<MenuItem Command="New" /> |
||||||
|
<MenuItem Command="Open" /> |
||||||
|
<Separator /> |
||||||
|
<MenuItem Command="Close" /> |
||||||
|
<MenuItem Command="XamlDesigner:MainWindow.CloseAllCommand" /> |
||||||
|
<Separator /> |
||||||
|
<MenuItem Command="Save" /> |
||||||
|
<MenuItem Command="SaveAs" /> |
||||||
|
<MenuItem Command="XamlDesigner:MainWindow.SaveAllCommand" /> |
||||||
|
<Separator /> |
||||||
|
<MenuItem Header="Recent Files" |
||||||
|
ItemsSource="{Binding RecentFiles}" |
||||||
|
IsEnabled="{Binding RecentFiles.Count, Converter={StaticResource FalseWhenZero}}" |
||||||
|
Click="RecentFiles_Click"/> |
||||||
|
<Separator /> |
||||||
|
<MenuItem Command="XamlDesigner:MainWindow.ExitCommand" /> |
||||||
|
</MenuItem> |
||||||
|
<MenuItem Header="Edit"> |
||||||
|
<MenuItem Command="Undo" /> |
||||||
|
<MenuItem Command="Redo" /> |
||||||
|
<Separator /> |
||||||
|
<MenuItem Command="Cut" /> |
||||||
|
<MenuItem Command="Copy" /> |
||||||
|
<MenuItem Command="Paste" /> |
||||||
|
<MenuItem Command="Delete" /> |
||||||
|
<MenuItem Command="SelectAll" /> |
||||||
|
<Separator /> |
||||||
|
<MenuItem Command="Find" /> |
||||||
|
</MenuItem> |
||||||
|
</Menu> |
||||||
|
|
||||||
|
<AvalonDock:DockingManager x:Name="uxDockingManager"> |
||||||
|
<AvalonDock:ResizingPanel> |
||||||
|
|
||||||
|
<AvalonDock:DocumentPane x:Name="uxDocumentPane" |
||||||
|
SelectedValue="{Binding CurrentDocument}" |
||||||
|
SelectedValuePath="DataContext"/> |
||||||
|
|
||||||
|
<AvalonDock:DockablePane> |
||||||
|
<AvalonDock:DockableContent x:Name="content1" Title="Toolbox"> |
||||||
|
<XamlDesigner:ToolboxView /> |
||||||
|
</AvalonDock:DockableContent> |
||||||
|
</AvalonDock:DockablePane> |
||||||
|
|
||||||
|
<AvalonDock:DockablePane> |
||||||
|
<AvalonDock:DockableContent x:Name="content2" Title="Outline"> |
||||||
|
<!--<XamlDesigner:SceneTreeView />--> |
||||||
|
</AvalonDock:DockableContent> |
||||||
|
</AvalonDock:DockablePane> |
||||||
|
|
||||||
|
<AvalonDock:DockablePane> |
||||||
|
<AvalonDock:DockableContent x:Name="content3" Title="Errors"> |
||||||
|
<!--<XamlDesigner:ErrorListView />--> |
||||||
|
</AvalonDock:DockableContent> |
||||||
|
</AvalonDock:DockablePane> |
||||||
|
|
||||||
|
<AvalonDock:DockablePane> |
||||||
|
<AvalonDock:DockableContent x:Name="content4" Title="Properties"> |
||||||
|
<sd:PropertyGridView x:Name="uxPropertyGridView" |
||||||
|
SelectedItems="{Binding DataContext.CurrentDocument.SelectionService.SelectedItems, ElementName=root, FallbackValue={x:Null}}"/> |
||||||
|
</AvalonDock:DockableContent> |
||||||
|
</AvalonDock:DockablePane> |
||||||
|
|
||||||
|
</AvalonDock:ResizingPanel> |
||||||
|
</AvalonDock:DockingManager> |
||||||
|
|
||||||
|
</DockPanel> |
||||||
|
|
||||||
|
</Window> |
@ -0,0 +1,181 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
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 System.Windows.Shapes; |
||||||
|
using ICSharpCode.XamlDesigner.Configuration; |
||||||
|
using System.ComponentModel; |
||||||
|
using Microsoft.Win32; |
||||||
|
using AvalonDock; |
||||||
|
using System.IO; |
||||||
|
using System.Collections.Specialized; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner |
||||||
|
{ |
||||||
|
public partial class MainWindow |
||||||
|
{ |
||||||
|
public MainWindow() |
||||||
|
{ |
||||||
|
RenameCommands(); |
||||||
|
|
||||||
|
Instance = this; |
||||||
|
DataContext = Shell.Instance; |
||||||
|
InitializeComponent(); |
||||||
|
|
||||||
|
Shell.Instance.PropertyGrid = uxPropertyGridView.PropertyGrid; |
||||||
|
AvalonDockWorkaround(); |
||||||
|
LoadSettings(); |
||||||
|
ProcessPaths(App.Args); |
||||||
|
} |
||||||
|
|
||||||
|
public static MainWindow Instance; |
||||||
|
|
||||||
|
OpenFileDialog openFileDialog; |
||||||
|
SaveFileDialog saveFileDialog; |
||||||
|
|
||||||
|
protected override void OnDragEnter(DragEventArgs e) |
||||||
|
{ |
||||||
|
ProcessDrag(e); |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnDragOver(DragEventArgs e) |
||||||
|
{ |
||||||
|
ProcessDrag(e); |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnDrop(DragEventArgs e) |
||||||
|
{ |
||||||
|
ProcessPaths(e.Data.Paths()); |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnClosing(CancelEventArgs e) |
||||||
|
{ |
||||||
|
if (Shell.Instance.PrepareExit()) { |
||||||
|
SaveSettings(); |
||||||
|
} |
||||||
|
else { |
||||||
|
e.Cancel = true; |
||||||
|
} |
||||||
|
base.OnClosing(e); |
||||||
|
} |
||||||
|
|
||||||
|
void RecentFiles_Click(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
var path = (string)(e.OriginalSource as MenuItem).Header; |
||||||
|
Shell.Instance.Open(path); |
||||||
|
} |
||||||
|
|
||||||
|
void ProcessDrag(DragEventArgs e) |
||||||
|
{ |
||||||
|
e.Effects = DragDropEffects.None; |
||||||
|
e.Handled = true; |
||||||
|
|
||||||
|
foreach (var path in e.Data.Paths()) { |
||||||
|
if (path.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) || |
||||||
|
path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase)) { |
||||||
|
e.Effects = DragDropEffects.Copy; |
||||||
|
break; |
||||||
|
} |
||||||
|
else if (path.EndsWith(".xaml", StringComparison.InvariantCultureIgnoreCase)) { |
||||||
|
e.Effects = DragDropEffects.Copy; |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void ProcessPaths(IEnumerable<string> paths) |
||||||
|
{ |
||||||
|
foreach (var path in paths) { |
||||||
|
if (path.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) || |
||||||
|
path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase)) { |
||||||
|
Toolbox.Instance.AddAssembly(path); |
||||||
|
} |
||||||
|
else if (path.EndsWith(".xaml", StringComparison.InvariantCultureIgnoreCase)) { |
||||||
|
Shell.Instance.Open(path); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string AskOpenFileName() |
||||||
|
{ |
||||||
|
if (openFileDialog == null) { |
||||||
|
openFileDialog = new OpenFileDialog(); |
||||||
|
openFileDialog.Filter = "Xaml Documents (*.xaml)|*.xaml"; |
||||||
|
} |
||||||
|
if ((bool)openFileDialog.ShowDialog()) { |
||||||
|
return openFileDialog.FileName; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public string AskSaveFileName(string initName) |
||||||
|
{ |
||||||
|
if (saveFileDialog == null) { |
||||||
|
saveFileDialog = new SaveFileDialog(); |
||||||
|
saveFileDialog.Filter = "Xaml Documents (*.xaml)|*.xaml"; |
||||||
|
} |
||||||
|
saveFileDialog.FileName = initName; |
||||||
|
if ((bool)saveFileDialog.ShowDialog()) { |
||||||
|
return saveFileDialog.FileName; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
void LoadSettings() |
||||||
|
{ |
||||||
|
WindowState = Settings.Default.MainWindowState; |
||||||
|
|
||||||
|
Rect r = Settings.Default.MainWindowRect; |
||||||
|
if (r != new Rect()) { |
||||||
|
Left = r.Left; |
||||||
|
Top = r.Top; |
||||||
|
Width = r.Width; |
||||||
|
Height = r.Height; |
||||||
|
} |
||||||
|
|
||||||
|
if (Settings.Default.AvalonDockLayout != null) { |
||||||
|
uxDockingManager.RestoreLayout(Settings.Default.AvalonDockLayout.ToStream()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SaveSettings() |
||||||
|
{ |
||||||
|
Settings.Default.MainWindowState = WindowState; |
||||||
|
if (WindowState == WindowState.Normal) { |
||||||
|
Settings.Default.MainWindowRect = new Rect(Left, Top, Width, Height); |
||||||
|
} |
||||||
|
|
||||||
|
var writer = new StringWriter(); |
||||||
|
uxDockingManager.SaveLayout(writer); |
||||||
|
Settings.Default.AvalonDockLayout = writer.ToString(); |
||||||
|
|
||||||
|
Shell.Instance.SaveSettings(); |
||||||
|
} |
||||||
|
|
||||||
|
#region AvalonDockWorkaround
|
||||||
|
|
||||||
|
void AvalonDockWorkaround() |
||||||
|
{ |
||||||
|
uxDocumentPane.Items.KeepSyncronizedWith(Shell.Instance.Documents, d => CreateContentFor(d)); |
||||||
|
} |
||||||
|
|
||||||
|
DocumentContent CreateContentFor(Document doc) |
||||||
|
{ |
||||||
|
var content = new DocumentContent() { |
||||||
|
DataContext = doc, |
||||||
|
Content = new DocumentView(doc) |
||||||
|
}; |
||||||
|
content.SetBinding(DocumentContent.TitleProperty, "Title"); |
||||||
|
return content; |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,71 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Text; |
||||||
|
using System.Windows.Input; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner |
||||||
|
{ |
||||||
|
public partial class MainWindow |
||||||
|
{ |
||||||
|
public static SimpleCommand CloseAllCommand = new SimpleCommand("Close All"); |
||||||
|
public static SimpleCommand SaveAllCommand = new SimpleCommand("Save All", ModifierKeys.Control | ModifierKeys.Shift, Key.S); |
||||||
|
public static SimpleCommand ExitCommand = new SimpleCommand("Exit"); |
||||||
|
|
||||||
|
static void RenameCommands() |
||||||
|
{ |
||||||
|
ApplicationCommands.Open.Text = "Open..."; |
||||||
|
ApplicationCommands.SaveAs.Text = "Save As..."; |
||||||
|
} |
||||||
|
|
||||||
|
void NewCommand_Executed(object sender, ExecutedRoutedEventArgs e) |
||||||
|
{ |
||||||
|
Shell.Instance.New(); |
||||||
|
} |
||||||
|
|
||||||
|
void OpenCommand_Executed(object sender, ExecutedRoutedEventArgs e) |
||||||
|
{ |
||||||
|
Shell.Instance.Open(); |
||||||
|
} |
||||||
|
|
||||||
|
void CloseCommand_Executed(object sender, ExecutedRoutedEventArgs e) |
||||||
|
{ |
||||||
|
Shell.Instance.CloseCurrentDocument(); |
||||||
|
} |
||||||
|
|
||||||
|
void CloseCommand_PreviewExecuted(object sender, ExecutedRoutedEventArgs e) |
||||||
|
{ |
||||||
|
Shell.Instance.CloseCurrentDocument(); |
||||||
|
} |
||||||
|
|
||||||
|
void CloseAllCommand_Executed(object sender, ExecutedRoutedEventArgs e) |
||||||
|
{ |
||||||
|
Shell.Instance.CloseAll(); |
||||||
|
} |
||||||
|
|
||||||
|
void SaveCommand_Executed(object sender, ExecutedRoutedEventArgs e) |
||||||
|
{ |
||||||
|
Shell.Instance.SaveCurrentDocument(); |
||||||
|
} |
||||||
|
|
||||||
|
void SaveAsCommand_Executed(object sender, ExecutedRoutedEventArgs e) |
||||||
|
{ |
||||||
|
Shell.Instance.SaveCurrentDocumentAs(); |
||||||
|
} |
||||||
|
|
||||||
|
void SaveAllCommand_Executed(object sender, ExecutedRoutedEventArgs e) |
||||||
|
{ |
||||||
|
Shell.Instance.SaveAll(); |
||||||
|
} |
||||||
|
|
||||||
|
void ExitCommand_Executed(object sender, ExecutedRoutedEventArgs e) |
||||||
|
{ |
||||||
|
Shell.Instance.Exit(); |
||||||
|
} |
||||||
|
|
||||||
|
void CurrentDocument_CanExecute(object sender, CanExecuteRoutedEventArgs e) |
||||||
|
{ |
||||||
|
e.CanExecute = Shell.Instance.CurrentDocument != null; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,4 @@ |
|||||||
|
<Window xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||||
|
|
||||||
|
</Window> |
@ -0,0 +1,107 @@ |
|||||||
|
<UserControl x:Class="ICSharpCode.XamlDesigner.Outline" |
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||||
|
xmlns:XamlDesigner="clr-namespace:ICSharpCode.XamlDesigner;assembly=" |
||||||
|
DataContext="{Binding CurrentDocument}"> |
||||||
|
<UserControl.Resources> |
||||||
|
|
||||||
|
<Style TargetType="{x:Type XamlDesigner:OutlineTree}"> |
||||||
|
<Setter Property="Template"> |
||||||
|
<Setter.Value> |
||||||
|
<ControlTemplate TargetType="{x:Type XamlDesigner:OutlineTree}"> |
||||||
|
<Grid> |
||||||
|
<ScrollViewer> |
||||||
|
<ItemsPresenter /> |
||||||
|
</ScrollViewer> |
||||||
|
<Border x:Name="PART_InsertLine" |
||||||
|
Background="#FFC73C" |
||||||
|
Height="2" |
||||||
|
VerticalAlignment="Top" |
||||||
|
Visibility="Collapsed" |
||||||
|
IsHitTestVisible="False" /> |
||||||
|
</Grid> |
||||||
|
</ControlTemplate> |
||||||
|
</Setter.Value> |
||||||
|
</Setter> |
||||||
|
</Style> |
||||||
|
|
||||||
|
<Style TargetType="{x:Type XamlDesigner:OutlineTreeItem}"> |
||||||
|
<Setter Property="Template"> |
||||||
|
<Setter.Value> |
||||||
|
<ControlTemplate TargetType="{x:Type XamlDesigner:OutlineTreeItem}"> |
||||||
|
<DockPanel Background="Transparent"> |
||||||
|
<Grid DockPanel.Dock="Top"> |
||||||
|
<Grid.ColumnDefinitions> |
||||||
|
<ColumnDefinition Width="Auto" /> |
||||||
|
<ColumnDefinition /> |
||||||
|
</Grid.ColumnDefinitions> |
||||||
|
<Border x:Name="Bg" |
||||||
|
Background="{TemplateBinding Background}" |
||||||
|
Grid.ColumnSpan="2" |
||||||
|
Margin="0 1 0 0" /> |
||||||
|
<ToggleButton x:Name="Expander" |
||||||
|
Width="19" |
||||||
|
Margin="{TemplateBinding Indent}" |
||||||
|
Style="{StaticResource ExpandCollapseToggleStyle}" |
||||||
|
ClickMode="Press" |
||||||
|
IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" /> |
||||||
|
<ContentPresenter x:Name="PART_Header" |
||||||
|
ContentSource="Header" |
||||||
|
Grid.Column="1" /> |
||||||
|
</Grid> |
||||||
|
<ItemsPresenter x:Name="ItemsHost" /> |
||||||
|
</DockPanel> |
||||||
|
<ControlTemplate.Triggers> |
||||||
|
<Trigger Property="IsExpanded" |
||||||
|
Value="false"> |
||||||
|
<Setter TargetName="ItemsHost" |
||||||
|
Property="Visibility" |
||||||
|
Value="Collapsed" /> |
||||||
|
</Trigger> |
||||||
|
<Trigger Property="HasItems" |
||||||
|
Value="false"> |
||||||
|
<Setter TargetName="Expander" |
||||||
|
Property="Visibility" |
||||||
|
Value="Hidden" /> |
||||||
|
</Trigger> |
||||||
|
<Trigger Property="IsSelected" |
||||||
|
Value="true"> |
||||||
|
<Setter TargetName="Bg" |
||||||
|
Property="Background" |
||||||
|
Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" /> |
||||||
|
<Setter Property="Foreground" |
||||||
|
Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" /> |
||||||
|
</Trigger> |
||||||
|
</ControlTemplate.Triggers> |
||||||
|
</ControlTemplate> |
||||||
|
</Setter.Value> |
||||||
|
</Setter> |
||||||
|
</Style> |
||||||
|
|
||||||
|
<Style TargetType="{x:Type XamlDesigner:TreeNode}"> |
||||||
|
<Setter Property="Template"> |
||||||
|
<Setter.Value> |
||||||
|
<ControlTemplate TargetType="{x:Type XamlDesigner:TreeNode}"> |
||||||
|
<StackPanel Orientation="Horizontal"> |
||||||
|
<Image Source="{TemplateBinding Image}" |
||||||
|
Stretch="None" /> |
||||||
|
<ContentPresenter VerticalAlignment="Center" |
||||||
|
Margin="5 0 0 0" /> |
||||||
|
</StackPanel> |
||||||
|
</ControlTemplate> |
||||||
|
</Setter.Value> |
||||||
|
</Setter> |
||||||
|
</Style> |
||||||
|
|
||||||
|
<HierarchicalDataTemplate DataType="{x:Type XamlDesigner:DocumentElement}" |
||||||
|
ItemsSource="{Binding Children}"> |
||||||
|
<XamlDesigner:TreeNode Image="Images/Tag.png" |
||||||
|
Content="{Binding XamlType.Name}" /> |
||||||
|
</HierarchicalDataTemplate> |
||||||
|
|
||||||
|
</UserControl.Resources> |
||||||
|
|
||||||
|
<XamlDesigner:OutlineTree ItemsSource="{Binding EnumerateRoot}" |
||||||
|
Selection="{Binding Selection, Mode=OneWay}" /> |
||||||
|
|
||||||
|
</UserControl> |
@ -0,0 +1,24 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
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 System.Windows.Navigation; |
||||||
|
using System.Windows.Shapes; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner |
||||||
|
{ |
||||||
|
public partial class Outline |
||||||
|
{ |
||||||
|
public Outline() |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,267 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Text; |
||||||
|
using System.Windows.Controls; |
||||||
|
using System.Windows; |
||||||
|
using System.Collections.ObjectModel; |
||||||
|
using System.Windows.Input; |
||||||
|
using System.Windows.Media; |
||||||
|
using System.Windows.Controls.Primitives; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner |
||||||
|
{ |
||||||
|
public class OutlineTree : TreeView |
||||||
|
{ |
||||||
|
public OutlineTree() |
||||||
|
{ |
||||||
|
AllowDrop = true; |
||||||
|
new DragListener(this).DragStarted += new MouseEventHandler(TreeList_DragStarted); |
||||||
|
DragEnter += new DragEventHandler(TreeList_DragEnter); |
||||||
|
DragOver += new DragEventHandler(TreeList_DragOver); |
||||||
|
Drop += new DragEventHandler(TreeList_Drop); |
||||||
|
|
||||||
|
//Selection = new ObservableCollection<object>();
|
||||||
|
} |
||||||
|
|
||||||
|
Border insertLine; |
||||||
|
OutlineTreeItem markedItem; |
||||||
|
OutlineTreeItem possibleSelection; |
||||||
|
List<OutlineTreeItem> selectionNodes = new List<OutlineTreeItem>(); |
||||||
|
|
||||||
|
public static readonly DependencyProperty SelectionProperty = |
||||||
|
DependencyProperty.Register("Selection", typeof(ObservableCollection<DocumentElement>), typeof(OutlineTree)); |
||||||
|
|
||||||
|
public ObservableCollection<DocumentElement> Selection { |
||||||
|
get { return (ObservableCollection<DocumentElement>)GetValue(SelectionProperty); } |
||||||
|
set { SetValue(SelectionProperty, value); } |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) |
||||||
|
{ |
||||||
|
base.OnPropertyChanged(e); |
||||||
|
} |
||||||
|
|
||||||
|
public override void OnApplyTemplate() |
||||||
|
{ |
||||||
|
base.OnApplyTemplate(); |
||||||
|
insertLine = (Border)Template.FindName("PART_InsertLine", this); |
||||||
|
} |
||||||
|
|
||||||
|
protected override DependencyObject GetContainerForItemOverride() |
||||||
|
{ |
||||||
|
return new OutlineTreeItem(); |
||||||
|
} |
||||||
|
|
||||||
|
protected override bool IsItemItsOwnContainerOverride(object item) |
||||||
|
{ |
||||||
|
return item is OutlineTreeItem; |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual DragDropEffects CanDrag(object obj) |
||||||
|
{ |
||||||
|
return DragDropEffects.Move; |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual DragDropEffects CanDrop(object obj, object parent, int index) |
||||||
|
{ |
||||||
|
return DragDropEffects.Move; |
||||||
|
} |
||||||
|
|
||||||
|
void TreeList_DragOver(object sender, DragEventArgs e) |
||||||
|
{ |
||||||
|
ProcessDrag(e); |
||||||
|
} |
||||||
|
|
||||||
|
void TreeList_DragEnter(object sender, DragEventArgs e) |
||||||
|
{ |
||||||
|
ProcessDrag(e); |
||||||
|
} |
||||||
|
|
||||||
|
void TreeList_Drop(object sender, DragEventArgs e) |
||||||
|
{ |
||||||
|
ProcessDrop(e); |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnDragLeave(DragEventArgs e) |
||||||
|
{ |
||||||
|
HideDropMarkers(); |
||||||
|
} |
||||||
|
|
||||||
|
void TreeList_DragStarted(object sender, MouseEventArgs e) |
||||||
|
{ |
||||||
|
possibleSelection = null; |
||||||
|
object obj = (e.OriginalSource as FrameworkElement).DataContext; |
||||||
|
if (obj != null) { |
||||||
|
DragDropEffects effects = CanDrag(obj); |
||||||
|
if (effects != DragDropEffects.None) { |
||||||
|
DragDrop.DoDragDrop(this, obj, effects); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void ProcessDrag(DragEventArgs e) |
||||||
|
{ |
||||||
|
e.Effects = DragDropEffects.Move; |
||||||
|
e.Handled = true; |
||||||
|
|
||||||
|
OutlineTreeItem treeItem = (e.OriginalSource as DependencyObject).FindAncestor<OutlineTreeItem>(); |
||||||
|
if (treeItem != null) { |
||||||
|
HideDropMarkers(); |
||||||
|
|
||||||
|
ContentPresenter header = treeItem.HeaderPresenter; |
||||||
|
Point p = e.GetPosition(header); |
||||||
|
int part = (int)(p.Y / (header.ActualHeight / 3)); |
||||||
|
|
||||||
|
if (part == 1) { |
||||||
|
markedItem = treeItem; |
||||||
|
markedItem.Background = insertLine.Background; |
||||||
|
} |
||||||
|
else { |
||||||
|
insertLine.Visibility = Visibility.Visible; |
||||||
|
p = header.TransformToVisual(this).Transform(new Point()); |
||||||
|
double y = part == 0 ? p.Y : p.Y + header.ActualHeight; |
||||||
|
insertLine.Margin = new Thickness(0, y, 0, 0); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void ProcessDrop(DragEventArgs e) |
||||||
|
{ |
||||||
|
HideDropMarkers(); |
||||||
|
} |
||||||
|
|
||||||
|
void HideDropMarkers() |
||||||
|
{ |
||||||
|
insertLine.Visibility = Visibility.Collapsed; |
||||||
|
if (markedItem != null) { |
||||||
|
markedItem.ClearValue(OutlineTreeItem.BackgroundProperty); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void Select(OutlineTreeItem item) |
||||||
|
{ |
||||||
|
item.IsSelected = true; |
||||||
|
Selection.Add(item.Element); |
||||||
|
selectionNodes.Add(item); |
||||||
|
} |
||||||
|
|
||||||
|
void SelectOnly(OutlineTreeItem item) |
||||||
|
{ |
||||||
|
foreach (var node in selectionNodes) { |
||||||
|
node.IsSelected = false; |
||||||
|
} |
||||||
|
Selection.Clear(); |
||||||
|
Select(item); |
||||||
|
} |
||||||
|
|
||||||
|
void Unselect(OutlineTreeItem item) |
||||||
|
{ |
||||||
|
item.IsSelected = false; |
||||||
|
Selection.Remove(item.Element); |
||||||
|
selectionNodes.Remove(item); |
||||||
|
} |
||||||
|
|
||||||
|
internal void HandleItemMouseDown(OutlineTreeItem item) |
||||||
|
{ |
||||||
|
bool control = Keyboard.IsKeyDown(Key.LeftCtrl); |
||||||
|
if (item.IsSelected) { |
||||||
|
if (control) { |
||||||
|
Unselect(item); |
||||||
|
} |
||||||
|
else { |
||||||
|
possibleSelection = item; |
||||||
|
} |
||||||
|
} |
||||||
|
else { |
||||||
|
if (control) { |
||||||
|
Select(item); |
||||||
|
} |
||||||
|
else { |
||||||
|
SelectOnly(item); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
internal void HandleItemMouseUp(OutlineTreeItem item) |
||||||
|
{ |
||||||
|
if (possibleSelection != null) { |
||||||
|
SelectOnly(possibleSelection); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class OutlineTreeItem : TreeViewItem |
||||||
|
{ |
||||||
|
public new static readonly DependencyProperty IsSelectedProperty = |
||||||
|
Selector.IsSelectedProperty.AddOwner(typeof(OutlineTreeItem)); |
||||||
|
|
||||||
|
public new bool IsSelected { |
||||||
|
get { return (bool)GetValue(IsSelectedProperty); } |
||||||
|
set { SetValue(IsSelectedProperty, value); } |
||||||
|
} |
||||||
|
|
||||||
|
public ContentPresenter HeaderPresenter { |
||||||
|
get { return (ContentPresenter)Template.FindName("PART_Header", this); } |
||||||
|
} |
||||||
|
|
||||||
|
public DocumentElement Element { |
||||||
|
get { return DataContext as DocumentElement; } |
||||||
|
} |
||||||
|
|
||||||
|
public static readonly DependencyProperty IndentProperty = |
||||||
|
DependencyProperty.Register("Indent", typeof(Thickness), typeof(OutlineTreeItem)); |
||||||
|
|
||||||
|
public Thickness Indent { |
||||||
|
get { return (Thickness)GetValue(IndentProperty); } |
||||||
|
set { SetValue(IndentProperty, value); } |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnVisualParentChanged(DependencyObject oldParent) |
||||||
|
{ |
||||||
|
base.OnVisualParentChanged(oldParent); |
||||||
|
OutlineTreeItem parent = ItemsControl.ItemsControlFromItemContainer(this) as OutlineTreeItem; |
||||||
|
Indent = parent == null ? new Thickness() : new Thickness(parent.Indent.Left + 19, 0, 0, 0); |
||||||
|
} |
||||||
|
|
||||||
|
protected override DependencyObject GetContainerForItemOverride() |
||||||
|
{ |
||||||
|
return new OutlineTreeItem(); |
||||||
|
} |
||||||
|
|
||||||
|
protected override bool IsItemItsOwnContainerOverride(object item) |
||||||
|
{ |
||||||
|
return item is OutlineTreeItem; |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnPreviewMouseDown(MouseButtonEventArgs e) |
||||||
|
{ |
||||||
|
if (e.Source is ToggleButton || e.Source is ItemsPresenter) return; |
||||||
|
|
||||||
|
OutlineTree tree = this.FindAncestor<OutlineTree>(); |
||||||
|
if (tree != null) { |
||||||
|
tree.HandleItemMouseDown(this); |
||||||
|
e.Handled = true; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) |
||||||
|
{ |
||||||
|
OutlineTree tree = this.FindAncestor<OutlineTree>(); |
||||||
|
if (tree != null) { |
||||||
|
tree.HandleItemMouseUp(this); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class TreeNode : ContentControl |
||||||
|
{ |
||||||
|
public static readonly DependencyProperty ImageProperty = |
||||||
|
DependencyProperty.Register("Image", typeof(ImageSource), typeof(TreeNode)); |
||||||
|
|
||||||
|
public ImageSource Image { |
||||||
|
get { return (ImageSource)GetValue(ImageProperty); } |
||||||
|
set { SetValue(ImageProperty, value); } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,238 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Text; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.Collections.ObjectModel; |
||||||
|
using ICSharpCode.WpfDesign.Designer.PropertyGrid; |
||||||
|
using ICSharpCode.XamlDesigner.Configuration; |
||||||
|
using System.Collections.Specialized; |
||||||
|
using System.IO; |
||||||
|
using System.Windows; |
||||||
|
using System.Diagnostics; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner |
||||||
|
{ |
||||||
|
public class Shell : INotifyPropertyChanged |
||||||
|
{ |
||||||
|
public Shell() |
||||||
|
{ |
||||||
|
Documents = new ObservableCollection<Document>(); |
||||||
|
RecentFiles = new ObservableCollection<string>(); |
||||||
|
LoadSettings(); |
||||||
|
} |
||||||
|
|
||||||
|
public static Shell Instance = new Shell(); |
||||||
|
public const string ApplicationTitle = "Xaml Designer"; |
||||||
|
|
||||||
|
//public Toolbox Toolbox { get; set; }
|
||||||
|
//public SceneTree SceneTree { get; set; }
|
||||||
|
public PropertyGrid PropertyGrid { get; internal set; } |
||||||
|
//public ErrorList ErrorList { get; set; }
|
||||||
|
|
||||||
|
public ObservableCollection<Document> Documents { get; private set; } |
||||||
|
public ObservableCollection<string> RecentFiles { get; private set; } |
||||||
|
|
||||||
|
Document currentDocument; |
||||||
|
|
||||||
|
public Document CurrentDocument { |
||||||
|
get { |
||||||
|
return currentDocument; |
||||||
|
} |
||||||
|
set { |
||||||
|
currentDocument = value; |
||||||
|
RaisePropertyChanged("CurrentDocument"); |
||||||
|
RaisePropertyChanged("Title"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string Title { |
||||||
|
get { |
||||||
|
if (CurrentDocument != null) { |
||||||
|
return CurrentDocument.Title + " - " + ApplicationTitle; |
||||||
|
} |
||||||
|
return ApplicationTitle; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void LoadSettings() |
||||||
|
{ |
||||||
|
if (Settings.Default.RecentFiles != null) { |
||||||
|
RecentFiles.AddRange(Settings.Default.RecentFiles.Cast<string>()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void SaveSettings() |
||||||
|
{ |
||||||
|
if (Settings.Default.RecentFiles == null) { |
||||||
|
Settings.Default.RecentFiles = new StringCollection(); |
||||||
|
} |
||||||
|
else { |
||||||
|
Settings.Default.RecentFiles.Clear(); |
||||||
|
} |
||||||
|
foreach (var f in RecentFiles) { |
||||||
|
Settings.Default.RecentFiles.Add(f); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static void ReportException(Exception x) |
||||||
|
{ |
||||||
|
MessageBox.Show(x.ToString()); |
||||||
|
} |
||||||
|
|
||||||
|
#region Files
|
||||||
|
|
||||||
|
bool IsSomethingDirty { |
||||||
|
get { |
||||||
|
foreach (var doc in Shell.Instance.Documents) { |
||||||
|
if (doc.IsDirty) return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static int nonameIndex = 1; |
||||||
|
|
||||||
|
public void New() |
||||||
|
{ |
||||||
|
Document doc = new Document("New" + nonameIndex++, File.ReadAllText("NewFileTemplate.xaml")); |
||||||
|
Documents.Add(doc); |
||||||
|
CurrentDocument = doc; |
||||||
|
} |
||||||
|
|
||||||
|
public void Open() |
||||||
|
{ |
||||||
|
var path = MainWindow.Instance.AskOpenFileName(); |
||||||
|
if (path != null) { |
||||||
|
Open(path); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void Open(string path) |
||||||
|
{ |
||||||
|
path = Path.GetFullPath(path); |
||||||
|
|
||||||
|
if (RecentFiles.Contains(path)) { |
||||||
|
RecentFiles.Remove(path); |
||||||
|
} |
||||||
|
RecentFiles.Insert(0, path); |
||||||
|
|
||||||
|
foreach (var doc in Documents) { |
||||||
|
if (doc.FilePath == path) { |
||||||
|
CurrentDocument = doc; |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
var newDoc = new Document(path); |
||||||
|
Documents.Add(newDoc); |
||||||
|
CurrentDocument = newDoc; |
||||||
|
} |
||||||
|
|
||||||
|
public bool Save(Document doc) |
||||||
|
{ |
||||||
|
if (doc.IsDirty) { |
||||||
|
if (doc.FilePath == null) { |
||||||
|
return SaveAs(doc); |
||||||
|
} |
||||||
|
doc.Save(); |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
public bool SaveAs(Document doc) |
||||||
|
{ |
||||||
|
var initName = doc.FileName ?? doc.Name + ".xaml"; |
||||||
|
var path = MainWindow.Instance.AskSaveFileName(initName); |
||||||
|
if (path != null) { |
||||||
|
doc.SaveAs(path); |
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
public bool SaveAll() |
||||||
|
{ |
||||||
|
foreach (var doc in Documents) { |
||||||
|
if (!Save(doc)) return false; |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
public bool Close(Document doc) |
||||||
|
{ |
||||||
|
if (doc.IsDirty) { |
||||||
|
var result = MessageBox.Show("Save \"" + doc.Name + "\" ?", Shell.ApplicationTitle, |
||||||
|
MessageBoxButton.YesNoCancel, MessageBoxImage.Warning); |
||||||
|
|
||||||
|
if (result == MessageBoxResult.Yes) { |
||||||
|
if (!Save(doc)) return false; |
||||||
|
} |
||||||
|
else if (result == MessageBoxResult.Cancel) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
Documents.Remove(doc); |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
public bool CloseAll() |
||||||
|
{ |
||||||
|
foreach (var doc in Documents) { |
||||||
|
if (!Close(doc)) return false; |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
public bool PrepareExit() |
||||||
|
{ |
||||||
|
if (IsSomethingDirty) { |
||||||
|
var result = MessageBox.Show("Save All?", Shell.ApplicationTitle, |
||||||
|
MessageBoxButton.YesNoCancel, MessageBoxImage.Warning); |
||||||
|
|
||||||
|
if (result == MessageBoxResult.Yes) { |
||||||
|
if (!SaveAll()) return false; |
||||||
|
} |
||||||
|
else if (result == MessageBoxResult.Cancel) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
public void Exit() |
||||||
|
{ |
||||||
|
MainWindow.Instance.Close(); |
||||||
|
} |
||||||
|
|
||||||
|
public void SaveCurrentDocument() |
||||||
|
{ |
||||||
|
Save(CurrentDocument); |
||||||
|
} |
||||||
|
|
||||||
|
public void SaveCurrentDocumentAs() |
||||||
|
{ |
||||||
|
SaveAs(CurrentDocument); |
||||||
|
} |
||||||
|
|
||||||
|
public void CloseCurrentDocument() |
||||||
|
{ |
||||||
|
Close(CurrentDocument); |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region INotifyPropertyChanged Members
|
||||||
|
|
||||||
|
public event PropertyChangedEventHandler PropertyChanged; |
||||||
|
|
||||||
|
void RaisePropertyChanged(string name) |
||||||
|
{ |
||||||
|
if (PropertyChanged != null) { |
||||||
|
PropertyChanged(this, new PropertyChangedEventArgs(name)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Text; |
||||||
|
using System.Windows.Input; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner |
||||||
|
{ |
||||||
|
public class SimpleCommand : RoutedUICommand |
||||||
|
{ |
||||||
|
public SimpleCommand(string text) |
||||||
|
{ |
||||||
|
Text = text; |
||||||
|
} |
||||||
|
|
||||||
|
public SimpleCommand(string text, ModifierKeys modifiers, Key key) |
||||||
|
{ |
||||||
|
InputGestures.Add(new KeyGesture(key, modifiers)); |
||||||
|
Text = text; |
||||||
|
} |
||||||
|
|
||||||
|
public SimpleCommand(string text, Key key) |
||||||
|
: this(text, ModifierKeys.None, key) |
||||||
|
{ |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
<Window xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||||
|
Title="WindowTitle" |
||||||
|
BorderThickness="10" |
||||||
|
Width="400" |
||||||
|
Height="300"> |
||||||
|
<StackPanel> |
||||||
|
<Canvas Height="50"> |
||||||
|
<Button>CB</Button> |
||||||
|
</Canvas> |
||||||
|
<TabControl MinHeight="150"> |
||||||
|
<TabItem Header="StackPanel"> |
||||||
|
<StackPanel> |
||||||
|
<Button>a</Button> |
||||||
|
</StackPanel> |
||||||
|
</TabItem> |
||||||
|
<TabItem Header="Button"> |
||||||
|
<Button>button on page 2</Button> |
||||||
|
</TabItem> |
||||||
|
<TabItem Header="Canvas"> |
||||||
|
<Canvas /> |
||||||
|
</TabItem> |
||||||
|
<TabItem Header="Grid"> |
||||||
|
<Grid /> |
||||||
|
</TabItem> |
||||||
|
<TabItem Header="DockPanel"> |
||||||
|
<DockPanel /> |
||||||
|
</TabItem> |
||||||
|
</TabControl> |
||||||
|
</StackPanel> |
||||||
|
</Window> |
@ -0,0 +1,41 @@ |
|||||||
|
<Window xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||||
|
<Canvas> |
||||||
|
<Button Content="bla-bla" |
||||||
|
Width="110" |
||||||
|
Height="76" |
||||||
|
Canvas.Left="59" |
||||||
|
Canvas.Top="158" /> |
||||||
|
<Ellipse Width="146" |
||||||
|
Height="63" |
||||||
|
Fill="#FF5DAF05" |
||||||
|
Canvas.Left="50" |
||||||
|
Canvas.Top="285" /> |
||||||
|
<Grid Width="279" |
||||||
|
Height="233" |
||||||
|
Background="#FFFFFFE1" |
||||||
|
Canvas.Left="255" |
||||||
|
Canvas.Top="167"> |
||||||
|
<Panel.Children> |
||||||
|
<TextBlock Width="59" |
||||||
|
Height="39" |
||||||
|
Margin="0,10,12,0" |
||||||
|
HorizontalAlignment="Right" |
||||||
|
VerticalAlignment="Top" |
||||||
|
FontSize="33" |
||||||
|
Text="Grid" |
||||||
|
Grid.Column="0" |
||||||
|
Grid.Row="0" /> |
||||||
|
</Panel.Children> |
||||||
|
</Grid> |
||||||
|
<StackPanel Width="345" |
||||||
|
Height="73" |
||||||
|
Background="#FFEDEDED" |
||||||
|
Canvas.Left="198" |
||||||
|
Canvas.Top="51" /> |
||||||
|
<TextBlock FontSize="14" |
||||||
|
Text="StackPanel" |
||||||
|
Canvas.Left="323" |
||||||
|
Canvas.Top="28" /> |
||||||
|
</Canvas> |
||||||
|
</Window> |
@ -0,0 +1,101 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Text; |
||||||
|
using System.Reflection; |
||||||
|
using System.Collections.ObjectModel; |
||||||
|
using ICSharpCode.XamlDesigner.Configuration; |
||||||
|
using System.Windows; |
||||||
|
using System.Collections.Specialized; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner |
||||||
|
{ |
||||||
|
public class Toolbox |
||||||
|
{ |
||||||
|
public Toolbox() |
||||||
|
{ |
||||||
|
AssemblyNodes = new ObservableCollection<AssemblyNode>(); |
||||||
|
LoadSettings(); |
||||||
|
} |
||||||
|
|
||||||
|
public static Toolbox Instance = new Toolbox(); |
||||||
|
public ObservableCollection<AssemblyNode> AssemblyNodes { get; private set; } |
||||||
|
|
||||||
|
public void AddAssembly(string path) |
||||||
|
{ |
||||||
|
AddAssembly(path, true); |
||||||
|
} |
||||||
|
|
||||||
|
void AddAssembly(string path, bool updateSettings) |
||||||
|
{ |
||||||
|
var assembly = Assembly.LoadFile(path); |
||||||
|
|
||||||
|
var node = new AssemblyNode(); |
||||||
|
node.Assembly = assembly; |
||||||
|
node.Path = path; |
||||||
|
foreach (var t in assembly.GetExportedTypes()) { |
||||||
|
if (IsControl(t)) { |
||||||
|
node.Controls.Add(new ControlNode() { Type = t }); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
node.Controls.Sort(delegate(ControlNode c1, ControlNode c2) { |
||||||
|
return c1.Name.CompareTo(c2.Name); |
||||||
|
}); |
||||||
|
|
||||||
|
AssemblyNodes.Add(node); |
||||||
|
|
||||||
|
if (updateSettings) { |
||||||
|
if (Settings.Default.AssemblyList == null) { |
||||||
|
Settings.Default.AssemblyList = new StringCollection(); |
||||||
|
} |
||||||
|
Settings.Default.AssemblyList.Add(path); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void Remove(AssemblyNode node) |
||||||
|
{ |
||||||
|
AssemblyNodes.Remove(node); |
||||||
|
Settings.Default.AssemblyList.Remove(node.Path); |
||||||
|
} |
||||||
|
|
||||||
|
public void LoadSettings() |
||||||
|
{ |
||||||
|
if (Settings.Default.AssemblyList != null) { |
||||||
|
foreach (var path in Settings.Default.AssemblyList) { |
||||||
|
AddAssembly(Environment.ExpandEnvironmentVariables(path), false); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static bool IsControl(Type t) |
||||||
|
{ |
||||||
|
return !t.IsAbstract && !t.IsGenericTypeDefinition && t.IsSubclassOf(typeof(FrameworkElement)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class AssemblyNode |
||||||
|
{ |
||||||
|
public AssemblyNode() |
||||||
|
{ |
||||||
|
Controls = new List<ControlNode>(); |
||||||
|
} |
||||||
|
|
||||||
|
public Assembly Assembly { get; set; } |
||||||
|
public List<ControlNode> Controls { get; private set; } |
||||||
|
public string Path { get; set; } |
||||||
|
|
||||||
|
public string Name { |
||||||
|
get { return Assembly.GetName().Name; } |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class ControlNode |
||||||
|
{ |
||||||
|
public Type Type { get; set; } |
||||||
|
|
||||||
|
public string Name { |
||||||
|
get { return Type.Name; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
<UserControl x:Class="ICSharpCode.XamlDesigner.ToolboxView" |
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||||
|
xmlns:XamlDesigner="clr-namespace:ICSharpCode.XamlDesigner;assembly="> |
||||||
|
<UserControl.Resources> |
||||||
|
|
||||||
|
<HierarchicalDataTemplate DataType="{x:Type XamlDesigner:AssemblyNode}" |
||||||
|
ItemsSource="{Binding Controls}"> |
||||||
|
<StackPanel Orientation="Horizontal" |
||||||
|
ToolTip="{Binding Path}"> |
||||||
|
<Border Background="White" |
||||||
|
Margin="-1 0 0 0" |
||||||
|
> |
||||||
|
<Image Source="Images/Reference.png" |
||||||
|
Height="16"/> |
||||||
|
</Border> |
||||||
|
<TextBlock Text="{Binding Name}" |
||||||
|
Margin="5 0" |
||||||
|
VerticalAlignment="Center"/> |
||||||
|
</StackPanel> |
||||||
|
</HierarchicalDataTemplate> |
||||||
|
|
||||||
|
<DataTemplate DataType="{x:Type XamlDesigner:ControlNode}"> |
||||||
|
<StackPanel Orientation="Horizontal" |
||||||
|
ToolTip="{Binding Type.FullName}"> |
||||||
|
<Border Background="White" |
||||||
|
Margin="-1 0 0 0"> |
||||||
|
<Image Source="Images/Tag.png" /> |
||||||
|
</Border> |
||||||
|
<TextBlock Text="{Binding Type.Name}" |
||||||
|
Margin="5 0" |
||||||
|
VerticalAlignment="Center"/> |
||||||
|
</StackPanel> |
||||||
|
</DataTemplate> |
||||||
|
|
||||||
|
</UserControl.Resources> |
||||||
|
|
||||||
|
<TreeView x:Name="uxTreeView" |
||||||
|
ItemsSource="{Binding AssemblyNodes}" |
||||||
|
BorderThickness="0" |
||||||
|
SelectedItemChanged="uxTreeView_SelectedItemChanged"/> |
||||||
|
|
||||||
|
</UserControl> |
@ -0,0 +1,69 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
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 System.Windows.Navigation; |
||||||
|
using System.Windows.Shapes; |
||||||
|
using System.Reflection; |
||||||
|
using System.Collections.ObjectModel; |
||||||
|
using System.Collections.Specialized; |
||||||
|
using ICSharpCode.WpfDesign.Designer.Services; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner |
||||||
|
{ |
||||||
|
public partial class ToolboxView |
||||||
|
{ |
||||||
|
public ToolboxView() |
||||||
|
{ |
||||||
|
DataContext = Toolbox.Instance; |
||||||
|
InitializeComponent(); |
||||||
|
|
||||||
|
new DragListener(this).DragStarted += new MouseEventHandler(Toolbox_DragStarted); |
||||||
|
} |
||||||
|
|
||||||
|
void Toolbox_DragStarted(object sender, MouseEventArgs e) |
||||||
|
{ |
||||||
|
PrepareTool(e.GetDataContext() as ControlNode, true); |
||||||
|
} |
||||||
|
|
||||||
|
void uxTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) |
||||||
|
{ |
||||||
|
PrepareTool(uxTreeView.SelectedItem as ControlNode, false); |
||||||
|
} |
||||||
|
|
||||||
|
void PrepareTool(ControlNode node, bool drag) |
||||||
|
{ |
||||||
|
if (node != null) { |
||||||
|
var tool = new CreateComponentTool(node.Type); |
||||||
|
if (Shell.Instance.CurrentDocument != null) { |
||||||
|
Shell.Instance.CurrentDocument.DesignContext.Services.Tool.CurrentTool = tool; |
||||||
|
if (drag) { |
||||||
|
DragDrop.DoDragDrop(this, tool, DragDropEffects.Copy); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnKeyDown(KeyEventArgs e) |
||||||
|
{ |
||||||
|
if (e.Key == Key.Delete) { |
||||||
|
Remove(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void Remove() |
||||||
|
{ |
||||||
|
AssemblyNode node = uxTreeView.SelectedItem as AssemblyNode; |
||||||
|
if (node != null) { |
||||||
|
Toolbox.Instance.Remove(node); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,168 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||||
|
<PropertyGroup> |
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||||
|
<ProductVersion>9.0.30428</ProductVersion> |
||||||
|
<SchemaVersion>2.0</SchemaVersion> |
||||||
|
<ProjectGuid>{27DA2B5C-2AAA-4478-AB00-3E184273C241}</ProjectGuid> |
||||||
|
<OutputType>WinExe</OutputType> |
||||||
|
<RootNamespace>ICSharpCode.XamlDesigner</RootNamespace> |
||||||
|
<AssemblyName>XamlDesigner</AssemblyName> |
||||||
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> |
||||||
|
<FileAlignment>512</FileAlignment> |
||||||
|
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
||||||
|
<WarningLevel>4</WarningLevel> |
||||||
|
<ApplicationManifest>Configuration\app.manifest</ApplicationManifest> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||||
|
<DebugSymbols>true</DebugSymbols> |
||||||
|
<DebugType>full</DebugType> |
||||||
|
<Optimize>false</Optimize> |
||||||
|
<OutputPath>bin\Debug\</OutputPath> |
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||||
|
<ErrorReport>prompt</ErrorReport> |
||||||
|
<WarningLevel>4</WarningLevel> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||||
|
<DebugType>pdbonly</DebugType> |
||||||
|
<Optimize>true</Optimize> |
||||||
|
<OutputPath>bin\Release\</OutputPath> |
||||||
|
<DefineConstants>TRACE</DefineConstants> |
||||||
|
<ErrorReport>prompt</ErrorReport> |
||||||
|
<WarningLevel>4</WarningLevel> |
||||||
|
</PropertyGroup> |
||||||
|
<ItemGroup> |
||||||
|
<Reference Include="AvalonDock, Version=1.1.1231.0, Culture=neutral, PublicKeyToken=85a1e0ada7ec13e4, processorArchitecture=MSIL"> |
||||||
|
<SpecificVersion>False</SpecificVersion> |
||||||
|
<HintPath>Libraries\AvalonDock.dll</HintPath> |
||||||
|
</Reference> |
||||||
|
<Reference Include="ICSharpCode.TextEditor, Version=3.0.0.3244, Culture=neutral, PublicKeyToken=4d61825e8dd49f1a, processorArchitecture=MSIL"> |
||||||
|
<SpecificVersion>False</SpecificVersion> |
||||||
|
<HintPath>Libraries\ICSharpCode.TextEditor.dll</HintPath> |
||||||
|
</Reference> |
||||||
|
<Reference Include="System" /> |
||||||
|
<Reference Include="System.Core"> |
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||||
|
</Reference> |
||||||
|
<Reference Include="System.Windows.Forms" /> |
||||||
|
<Reference Include="System.Xml.Linq"> |
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||||
|
</Reference> |
||||||
|
<Reference Include="System.Data.DataSetExtensions"> |
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||||
|
</Reference> |
||||||
|
<Reference Include="System.Data" /> |
||||||
|
<Reference Include="System.Xml" /> |
||||||
|
<Reference Include="UIAutomationProvider"> |
||||||
|
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||||
|
</Reference> |
||||||
|
<Reference Include="WindowsBase"> |
||||||
|
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||||
|
</Reference> |
||||||
|
<Reference Include="PresentationCore"> |
||||||
|
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||||
|
</Reference> |
||||||
|
<Reference Include="PresentationFramework"> |
||||||
|
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||||
|
</Reference> |
||||||
|
<Reference Include="WindowsFormsIntegration"> |
||||||
|
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||||
|
</Reference> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<ApplicationDefinition Include="App.xaml"> |
||||||
|
<Generator>MSBuild:Compile</Generator> |
||||||
|
<SubType>Designer</SubType> |
||||||
|
</ApplicationDefinition> |
||||||
|
<Compile Include="App.xaml.cs"> |
||||||
|
<DependentUpon>App.xaml</DependentUpon> |
||||||
|
<SubType>Code</SubType> |
||||||
|
</Compile> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs"> |
||||||
|
<Link>Configuration\GlobalAssemblyInfo.cs</Link> |
||||||
|
</Compile> |
||||||
|
<Compile Include="Configuration\AssemblyInfo.cs"> |
||||||
|
<SubType>Code</SubType> |
||||||
|
</Compile> |
||||||
|
<Compile Include="Configuration\Settings.Designer.cs"> |
||||||
|
<AutoGen>True</AutoGen> |
||||||
|
<DesignTimeSharedInput>True</DesignTimeSharedInput> |
||||||
|
<DependentUpon>Settings.settings</DependentUpon> |
||||||
|
</Compile> |
||||||
|
<Compile Include="Converters.cs" /> |
||||||
|
<Compile Include="Document.cs" /> |
||||||
|
<Compile Include="DocumentView.xaml.cs"> |
||||||
|
<DependentUpon>DocumentView.xaml</DependentUpon> |
||||||
|
</Compile> |
||||||
|
<Compile Include="DragListener.cs" /> |
||||||
|
<Compile Include="ExtensionMethods.cs" /> |
||||||
|
<Compile Include="MainWindow_Commands.cs" /> |
||||||
|
<Compile Include="Shell.cs" /> |
||||||
|
<Compile Include="MainWindow.xaml.cs"> |
||||||
|
<DependentUpon>MainWindow.xaml</DependentUpon> |
||||||
|
</Compile> |
||||||
|
<Compile Include="SimpleCommand.cs" /> |
||||||
|
<Compile Include="Toolbox.cs" /> |
||||||
|
<Compile Include="ToolboxView.xaml.cs"> |
||||||
|
<DependentUpon>ToolboxView.xaml</DependentUpon> |
||||||
|
</Compile> |
||||||
|
<Compile Include="XamlFormatter.cs" /> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<None Include="NewFileTemplate.xaml"> |
||||||
|
<SubType>Designer</SubType> |
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
||||||
|
</None> |
||||||
|
<Page Include="DocumentView.xaml"> |
||||||
|
<SubType>Designer</SubType> |
||||||
|
<Generator>MSBuild:Compile</Generator> |
||||||
|
</Page> |
||||||
|
<Page Include="MainWindow.xaml"> |
||||||
|
<SubType>Designer</SubType> |
||||||
|
<Generator>MSBuild:Compile</Generator> |
||||||
|
</Page> |
||||||
|
<None Include="TestFiles\1.xaml"> |
||||||
|
<SubType>Designer</SubType> |
||||||
|
</None> |
||||||
|
<None Include="TestFiles\2.xaml"> |
||||||
|
<SubType>Designer</SubType> |
||||||
|
</None> |
||||||
|
<Page Include="ToolboxView.xaml"> |
||||||
|
<Generator>MSBuild:Compile</Generator> |
||||||
|
<SubType>Designer</SubType> |
||||||
|
</Page> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<None Include="Configuration\app.config" /> |
||||||
|
<None Include="Configuration\app.manifest" /> |
||||||
|
<None Include="Configuration\Settings.settings"> |
||||||
|
<Generator>SettingsSingleFileGenerator</Generator> |
||||||
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput> |
||||||
|
</None> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<Resource Include="Images\Reference.png" /> |
||||||
|
<Resource Include="Images\Tag.png" /> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<ProjectReference Include="..\WpfDesign.Designer\Project\WpfDesign.Designer.csproj"> |
||||||
|
<Project>{78CC29AC-CC79-4355-B1F2-97936DF198AC}</Project> |
||||||
|
<Name>WpfDesign.Designer</Name> |
||||||
|
</ProjectReference> |
||||||
|
<ProjectReference Include="..\WpfDesign\Project\WpfDesign.csproj"> |
||||||
|
<Project>{66A378A1-E9F4-4AD5-8946-D0EC06C2902F}</Project> |
||||||
|
<Name>WpfDesign</Name> |
||||||
|
</ProjectReference> |
||||||
|
</ItemGroup> |
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
||||||
|
Other similar extension points exist, see Microsoft.Common.targets. |
||||||
|
<Target Name="BeforeBuild"> |
||||||
|
</Target> |
||||||
|
<Target Name="AfterBuild"> |
||||||
|
</Target> |
||||||
|
--> |
||||||
|
</Project> |
@ -0,0 +1,204 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Text; |
||||||
|
using System.Xml.Linq; |
||||||
|
|
||||||
|
namespace ICSharpCode.XamlDesigner |
||||||
|
{ |
||||||
|
public static class XamlFormatter |
||||||
|
{ |
||||||
|
public static char IndentChar = ' '; |
||||||
|
public static int Indenation = 2; |
||||||
|
public static int LengthBeforeNewLine = 60; |
||||||
|
|
||||||
|
static StringBuilder sb; |
||||||
|
static int currentColumn; |
||||||
|
static int nextColumn; |
||||||
|
|
||||||
|
public static string Format(string xaml) |
||||||
|
{ |
||||||
|
sb = new StringBuilder(); |
||||||
|
currentColumn = 0; |
||||||
|
nextColumn = 0; |
||||||
|
|
||||||
|
try { |
||||||
|
var doc = XDocument.Parse(xaml); |
||||||
|
WalkContainer(doc); |
||||||
|
return sb.ToString(); |
||||||
|
} |
||||||
|
catch { |
||||||
|
return xaml; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static void WalkContainer(XContainer node) |
||||||
|
{ |
||||||
|
foreach (var c in node.Nodes()) { |
||||||
|
if (c is XElement) { |
||||||
|
WalkElement(c as XElement); |
||||||
|
} |
||||||
|
else { |
||||||
|
NewLine(); |
||||||
|
Append(c.ToString()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static void WalkElement(XElement e) |
||||||
|
{ |
||||||
|
NewLine(); |
||||||
|
string prefix1 = e.GetPrefixOfNamespace(e.Name.Namespace); |
||||||
|
string name1 = prefix1 == null ? e.Name.LocalName : prefix1 + ":" + e.Name.LocalName; |
||||||
|
Append("<" + name1); |
||||||
|
|
||||||
|
List<AttributeString> list = new List<AttributeString>(); |
||||||
|
int length = name1.Length; |
||||||
|
|
||||||
|
foreach (var a in e.Attributes()) { |
||||||
|
string prefix2 = e.GetPrefixOfNamespace(a.Name.Namespace); |
||||||
|
var g = new AttributeString() { Name = a.Name, Prefix = prefix2, Value = a.Value }; |
||||||
|
list.Add(g); |
||||||
|
length += g.FinalString.Length; |
||||||
|
} |
||||||
|
|
||||||
|
list.Sort(AttributeComparrer.Instance); |
||||||
|
|
||||||
|
if (length > LengthBeforeNewLine) { |
||||||
|
nextColumn = currentColumn + 1; |
||||||
|
for (int i = 0; i < list.Count; i++) { |
||||||
|
if (i > 0) { |
||||||
|
NewLine(); |
||||||
|
} |
||||||
|
else { |
||||||
|
Append(" "); |
||||||
|
} |
||||||
|
Append(list[i].FinalString); |
||||||
|
} |
||||||
|
nextColumn -= name1.Length + 2; |
||||||
|
} |
||||||
|
else { |
||||||
|
foreach (var a in list) { |
||||||
|
Append(" " + a.FinalString); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (e.Nodes().Count() > 0) { |
||||||
|
Append(">"); |
||||||
|
nextColumn += Indenation; |
||||||
|
|
||||||
|
WalkContainer(e); |
||||||
|
|
||||||
|
nextColumn -= Indenation; |
||||||
|
NewLine(); |
||||||
|
Append("</" + e.Name.LocalName + ">"); |
||||||
|
} |
||||||
|
else { |
||||||
|
Append(" />"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static void NewLine() |
||||||
|
{ |
||||||
|
if (sb.Length > 0) { |
||||||
|
sb.AppendLine(); |
||||||
|
sb.Append(new string(' ', nextColumn)); |
||||||
|
currentColumn = nextColumn; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static void Append(string s) |
||||||
|
{ |
||||||
|
sb.Append(s); |
||||||
|
currentColumn += s.Length; |
||||||
|
} |
||||||
|
|
||||||
|
enum AttributeLayout |
||||||
|
{ |
||||||
|
X, |
||||||
|
XmlnsMicrosoft, |
||||||
|
Xmlns, |
||||||
|
XmlnsWithClr, |
||||||
|
SpecialOrder, |
||||||
|
ByName, |
||||||
|
Attached, |
||||||
|
WithPrefix |
||||||
|
} |
||||||
|
|
||||||
|
class AttributeString |
||||||
|
{ |
||||||
|
public XName Name; |
||||||
|
public string Prefix; |
||||||
|
public string Value; |
||||||
|
|
||||||
|
public string LocalName { |
||||||
|
get { return Name.LocalName; } |
||||||
|
} |
||||||
|
|
||||||
|
public string FinalName { |
||||||
|
get { |
||||||
|
return Prefix == null ? Name.LocalName : Prefix + ":" + Name.LocalName; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string FinalString { |
||||||
|
get { |
||||||
|
return FinalName + "=\"" + Value + "\""; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public AttributeLayout GetAttributeLayout() |
||||||
|
{ |
||||||
|
if (Prefix == "xmlns" || LocalName == "xmlns") { |
||||||
|
if (Value.StartsWith("http://schemas.microsoft.com")) return AttributeLayout.XmlnsMicrosoft; |
||||||
|
if (Value.StartsWith("clr")) return AttributeLayout.XmlnsWithClr; |
||||||
|
return AttributeLayout.Xmlns; |
||||||
|
} |
||||||
|
if (Prefix == "x") return AttributeLayout.X; |
||||||
|
if (Prefix != null) return AttributeLayout.WithPrefix; |
||||||
|
if (LocalName.Contains(".")) return AttributeLayout.Attached; |
||||||
|
if (AttributeComparrer.SpecialOrder.Contains(LocalName)) return AttributeLayout.SpecialOrder; |
||||||
|
return AttributeLayout.ByName; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class AttributeComparrer : IComparer<AttributeString> |
||||||
|
{ |
||||||
|
public static AttributeComparrer Instance = new AttributeComparrer(); |
||||||
|
|
||||||
|
public int Compare(AttributeString a1, AttributeString a2) |
||||||
|
{ |
||||||
|
var y1 = a1.GetAttributeLayout(); |
||||||
|
var y2 = a2.GetAttributeLayout(); |
||||||
|
if (y1 == y2) { |
||||||
|
if (y1 == AttributeLayout.SpecialOrder) { |
||||||
|
return |
||||||
|
Array.IndexOf(SpecialOrder, a1.LocalName).CompareTo( |
||||||
|
Array.IndexOf(SpecialOrder, a2.LocalName)); |
||||||
|
} |
||||||
|
return a1.FinalName.CompareTo(a2.FinalName); |
||||||
|
} |
||||||
|
return y1.CompareTo(y2); |
||||||
|
} |
||||||
|
|
||||||
|
public static string[] SpecialOrder = new string[] { |
||||||
|
"Name", |
||||||
|
"Content", |
||||||
|
"Command", |
||||||
|
"Executed", |
||||||
|
"CanExecute", |
||||||
|
"Width", |
||||||
|
"Height", |
||||||
|
"Margin", |
||||||
|
"HorizontalAlignment", |
||||||
|
"VerticalAlignment", |
||||||
|
"HorizontalContentAlignment", |
||||||
|
"VerticalContentAlignment", |
||||||
|
"StartPoint", |
||||||
|
"EndPoint", |
||||||
|
"Offset", |
||||||
|
"Color" |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue