Browse Source

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3270 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61

shortcuts
Ivan Shumilin 17 years ago
parent
commit
8860d96aa4
  1. 9
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/App.xaml
  2. 22
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/App.xaml.cs
  3. 39
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/AssemblyInfo.cs
  4. 57
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/EventHandlerService.cs
  5. 31
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Files/1.xaml
  6. BIN
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Images/Delete.png
  7. BIN
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Images/Redo.png
  8. BIN
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Images/Undo.png
  9. 89
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/StandaloneDesigner.csproj
  10. 116
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Toolbox.cs
  11. 60
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml
  12. 112
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml.cs

9
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/App.xaml

@ -1,9 +0,0 @@ @@ -1,9 +0,0 @@
<Application x:Class="StandaloneDesigner.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml"
>
<Application.Resources>
</Application.Resources>
</Application>

22
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/App.xaml.cs

@ -1,22 +0,0 @@ @@ -1,22 +0,0 @@
using System;
using System.Windows;
using System.Data;
using System.Xml;
using System.Configuration;
namespace StandaloneDesigner
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public App()
{
InitializeComponent();
}
}
}

39
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/AssemblyInfo.cs

@ -1,39 +0,0 @@ @@ -1,39 +0,0 @@
#region Using directives
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Resources;
using System.Globalization;
using System.Windows;
using System.Runtime.InteropServices;
#endregion
// 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("StandaloneDesigner")]
[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)
)]

57
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/EventHandlerService.cs

@ -1,57 +0,0 @@ @@ -1,57 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision: 2667$</version>
// </file>
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using ICSharpCode.WpfDesign;
namespace StandaloneDesigner
{
sealed class EventHandlerService : IEventHandlerService
{
Window1 mainWindow;
public EventHandlerService(Window1 mainWindow)
{
this.mainWindow = mainWindow;
}
public void CreateEventHandler(DesignItemProperty eventProperty)
{
var item = eventProperty.DesignItem;
string handlerName = (string)eventProperty.ValueOnInstance;
if (string.IsNullOrEmpty(handlerName)) {
string prefix = item.Name;
if (string.IsNullOrEmpty(prefix)) {
//TODO
prefix = item.ComponentType.Name;
}
handlerName = prefix + eventProperty.Name;
eventProperty.SetValue(handlerName);
}
MessageBox.Show("show " + handlerName);
}
public DesignItemProperty GetDefaultEvent(DesignItem item)
{
object[] attributes = item.ComponentType.GetCustomAttributes(typeof(DefaultEventAttribute), true);
if (attributes.Length == 1) {
DefaultEventAttribute dae = (DefaultEventAttribute)attributes[0];
DesignItemProperty property = item.Properties.GetProperty(dae.Name);
if (property != null && property.IsEvent) {
return property;
}
}
return null;
}
}
}

31
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Files/1.xaml

@ -1,31 +0,0 @@ @@ -1,31 +0,0 @@
<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>

BIN
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Images/Delete.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 575 B

BIN
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Images/Redo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 724 B

BIN
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Images/Undo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 788 B

89
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/StandaloneDesigner.csproj

@ -1,89 +0,0 @@ @@ -1,89 +0,0 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<ProjectGuid>{84D65E9C-B66C-44C3-95FD-445EFE3ED322}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>WinExe</OutputType>
<RootNamespace>StandaloneDesigner</RootNamespace>
<AssemblyName>StandaloneDesigner</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>True</DebugSymbols>
<DebugType>Full</DebugType>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="ReachFramework" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.IdentityModel" />
<Reference Include="System.Printing" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Xml" />
<Reference Include="UIAutomationProvider" />
<Reference Include="UIAutomationTypes" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="App.xaml.cs">
<SubType>Code</SubType>
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="EventHandlerService.cs" />
<Compile Include="Toolbox.cs" />
<Compile Include="Window1.xaml.cs">
<SubType>Code</SubType>
<DependentUpon>Window1.xaml</DependentUpon>
</Compile>
<None Include="Files\1.xaml">
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Page Include="Window1.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<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>
<Resource Include="Images\Redo.png" />
<Resource Include="Images\Undo.png" />
<Resource Include="Images\Delete.png" />
</ItemGroup>
</Project>

116
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Toolbox.cs

@ -1,116 +0,0 @@ @@ -1,116 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 ICSharpCode.WpfDesign;
using ICSharpCode.WpfDesign.Designer;
using ICSharpCode.WpfDesign.Designer.Services;
namespace StandaloneDesigner
{
public partial class Toolbox : ListBox
{
public Toolbox()
{
this.SelectionMode = SelectionMode.Single;
}
IToolService toolService;
public IToolService ToolService {
get { return toolService; }
set {
if (toolService != null) {
toolService.CurrentToolChanged -= OnCurrentToolChanged;
}
toolService = value;
this.Items.Clear();
if (toolService != null) {
AddTool("Pointer", toolService.PointerTool);
foreach (Type t in DesignSurface.SupportedToolboxControls)
AddTool(t);
toolService.CurrentToolChanged += OnCurrentToolChanged;
OnCurrentToolChanged(null, null);
}
}
}
void AddTool(Type componentType)
{
AddTool(componentType.Name, new CreateComponentTool(componentType));
}
void AddTool(string title, ITool tool)
{
ListBoxItem item = new ListBoxItem();
item.Content = title;
item.Tag = tool;
this.Items.Add(item);
}
void OnCurrentToolChanged(object sender, EventArgs e)
{
Debug.WriteLine("Toolbox.OnCurrentToolChanged");
for (int i = 0; i < this.Items.Count; i++) {
if (((ListBoxItem)this.Items[i]).Tag == toolService.CurrentTool) {
this.SelectedIndex = i;
return;
}
}
this.SelectedIndex = -1;
}
protected override void OnSelectionChanged(SelectionChangedEventArgs e)
{
base.OnSelectionChanged(e);
Debug.WriteLine("Toolbox.OnSelectionChanged");
if (toolService != null && this.SelectedItem is ListBoxItem) {
toolService.CurrentTool = (ITool)(this.SelectedItem as ListBoxItem).Tag;
}
}
Point startPos;
bool canStartDrag;
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
{
startPos = e.GetPosition(this);
canStartDrag = true;
base.OnPreviewMouseLeftButtonDown(e);
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (canStartDrag && e.LeftButton == MouseButtonState.Pressed) {
if ((e.GetPosition(this) - startPos).LengthSquared > 4) {
canStartDrag = false;
if (this.SelectedItem == null)
return;
if (toolService != null && this.SelectedItem is ListBoxItem) {
ITool tool = (ITool)(this.SelectedItem as ListBoxItem).Tag;
if (tool is CreateComponentTool) {
DragDrop.DoDragDrop((ListBoxItem)this.SelectedItem, tool, DragDropEffects.Copy);
}
}
}
}
base.OnMouseMove(e);
}
}
}

60
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml

@ -1,60 +0,0 @@ @@ -1,60 +0,0 @@
<Window x:Class="StandaloneDesigner.Window1"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sd="http://sharpdevelop.net"
xmlns:my="clr-namespace:StandaloneDesigner"
SnapsToDevicePixels="True"
Title="StandaloneDesigner"
WindowState="Maximized">
<DockPanel>
<ToolBar DockPanel.Dock="Top"
Name="toolBar">
<Button Command="Undo">
<Image Source="Images/Undo.png"
Stretch="None" />
</Button>
<Button Command="Redo">
<Image Source="Images/Redo.png"
Stretch="None" />
</Button>
<Button Command="Delete">
<Image Source="Images/Delete.png"
Stretch="None" />
</Button>
</ToolBar>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="170" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="270" />
</Grid.ColumnDefinitions>
<my:Toolbox x:Name="toolbox" />
<GridSplitter HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Column="1" />
<TabControl TabStripPlacement="Bottom"
Name="tabControl"
SelectionChanged="tabControlSelectionChanged"
Grid.Column="2">
<TabItem Header="Code">
<TextBox Name="CodeTextBox"
AcceptsReturn="True"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto" />
</TabItem>
<TabItem Header="Design"
Name="designTab">
<sd:DesignSurface x:Name="designSurface" />
</TabItem>
</TabControl>
<GridSplitter HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Column="3" />
<sd:PropertyGridView x:Name="propertyGridView"
Grid.Column="4" />
</Grid>
</DockPanel>
</Window>

112
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml.cs

@ -1,112 +0,0 @@ @@ -1,112 +0,0 @@
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Xml;
using ICSharpCode.WpfDesign;
using ICSharpCode.WpfDesign.Designer;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.PropertyGrid;
using System.Threading;
using System.Windows.Threading;
namespace StandaloneDesigner
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
DragDropExceptionHandler.HandleException = delegate (Exception ex) {
MessageBox.Show(ex.ToString());
};
try {
InitializeComponent();
CodeTextBox.Text = File.ReadAllText("Files/1.xaml");
foreach (object o in toolBar.Items) {
if (o is Button) {
(o as Button).CommandTarget = designSurface;
}
}
} catch (Exception ex) {
MessageBox.Show(ex.ToString());
Close();
}
}
void tabControlSelectionChanged(object sender, RoutedEventArgs e)
{
if (e.Source != tabControl) return;
if (tabControl.SelectedItem == designTab) {
XamlLoadSettings settings = new XamlLoadSettings();
settings.CustomServiceRegisterFunctions.Add(
delegate(XamlDesignContext context) {
context.Services.AddService(typeof(IEventHandlerService), new EventHandlerService(this));
});
designSurface.LoadDesigner(new XmlTextReader(new StringReader(CodeTextBox.Text)), settings);
designSurface.DesignContext.Services.Selection.SelectionChanged += OnSelectionChanged;
toolbox.ToolService = designSurface.DesignContext.Services.Tool;
} else {
if (designSurface.DesignContext != null) {
propertyGridView.PropertyGrid.SelectedItems = null;
using (StringWriter writer = new StringWriter()) {
using (XmlTextWriter xmlWriter = new XmlTextWriter(writer)) {
xmlWriter.Formatting = Formatting.Indented;
designSurface.SaveDesigner(xmlWriter);
}
CodeTextBox.Text = writer.ToString();
}
}
designSurface.UnloadDesigner();
toolbox.ToolService = null;
}
}
ICollection<DesignItem> oldItems = new DesignItem[0];
void OnSelectionChanged(object sender, DesignItemCollectionEventArgs e)
{
ISelectionService selectionService = designSurface.DesignContext.Services.Selection;
ICollection<DesignItem> items = selectionService.SelectedItems;
if (!IsCollectionWithSameElements(items, oldItems)) {
propertyGridView.PropertyGrid.SelectedItems = items;
oldItems = items;
}
}
static bool IsCollectionWithSameElements(ICollection<DesignItem> a, ICollection<DesignItem> b)
{
return ContainsAll(a, b) && ContainsAll(b, a);
}
static bool ContainsAll(ICollection<DesignItem> a, ICollection<DesignItem> b)
{
foreach (DesignItem item in a) {
if (!b.Contains(item))
return false;
}
return true;
}
void TestButtonClick(object sender, EventArgs e)
{
DesignItem[] c = new List<DesignItem>(designSurface.DesignContext.Services.Selection.SelectedItems).ToArray();
if (c.Length < 2) return;
int index = 0;
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
timer.Tick += delegate {
index++;
designSurface.DesignContext.Services.Selection.SetSelectedComponents(new DesignItem[] { c[index % c.Length] });
};
timer.Start();
}
}
}
Loading…
Cancel
Save