diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/PropertyDescriptionService.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/PropertyDescriptionService.cs new file mode 100644 index 0000000000..fcfd565dcb --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/PropertyDescriptionService.cs @@ -0,0 +1,55 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop; +using ICSharpCode.SharpDevelop.Project; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; + +namespace ICSharpCode.WpfDesign.AddIn +{ + public class PropertyDescriptionService : IPropertyDescriptionService + { + OpenedFile file; + + public PropertyDescriptionService(OpenedFile file) + { + if (file == null) + throw new ArgumentNullException("file"); + this.file = file; + } + + public object GetDescription(DesignItemProperty property) + { + IProjectContent pc = GetProjectContent(); + if (pc != null) { + string fullName = property.DeclaringType.FullName + "." + property.Name; + IDecoration dec = pc.GetElement(fullName); + if (dec != null) + return CodeCompletionData.GetDocumentation(dec.Documentation); + foreach (IProjectContent rpc in pc.ReferencedContents) { + dec = rpc.GetElement(fullName); + if (dec != null) + return CodeCompletionData.GetDocumentation(dec.Documentation); + } + } + return null; + } + + IProjectContent GetProjectContent() + { + if (ProjectService.OpenSolution != null) { + IProject p = ProjectService.OpenSolution.FindProjectContainingFile(file.FileName); + if (p != null) { + return ParserService.GetProjectContent(p); + } + } + return ParserService.DefaultProjectContent; + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/SharpDevelopElementHost.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/SharpDevelopElementHost.cs new file mode 100644 index 0000000000..768c36d569 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/SharpDevelopElementHost.cs @@ -0,0 +1,94 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Windows; +using System.Windows.Input; +using System.Windows.Forms.Integration; +using ICSharpCode.SharpDevelop.Gui; + +namespace ICSharpCode.WpfDesign.AddIn +{ + /// + /// Hosts a WPF element inside a Windows.Forms application. + /// + public class SharpDevelopElementHost : ElementHost, IUndoHandler, IClipboardHandler + { + static bool IsEnabled(ICommand command) + { + return command.CanExecute(null); + } + + static void Run(ICommand command) + { + command.Execute(null); + } + + public bool EnableUndo { + get { return IsEnabled(ApplicationCommands.Undo); } + } + + public bool EnableRedo { + get { return IsEnabled(ApplicationCommands.Redo); } + } + + public void Undo() + { + Run(ApplicationCommands.Undo); + } + + public void Redo() + { + Run(ApplicationCommands.Redo); + } + + public bool EnableCut { + get { return IsEnabled(ApplicationCommands.Undo); } + } + + public bool EnableCopy { + get { return IsEnabled(ApplicationCommands.Copy); } + } + + public bool EnablePaste { + get { return IsEnabled(ApplicationCommands.Paste); } + } + + public bool EnableDelete { + get { return IsEnabled(ApplicationCommands.Delete); } + } + + public bool EnableSelectAll { + get { return IsEnabled(ApplicationCommands.SelectAll); } + } + + public void Cut() + { + Run(ApplicationCommands.Cut); + } + + public void Copy() + { + Run(ApplicationCommands.Copy); + } + + public void Paste() + { + Run(ApplicationCommands.Paste); + } + + public void Delete() + { + Run(ApplicationCommands.Delete); + } + + public void SelectAll() + { + Run(ApplicationCommands.SelectAll); + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfToolbox.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfToolbox.cs index 40f68f2b30..c78e87b8e6 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfToolbox.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfToolbox.cs @@ -86,14 +86,35 @@ namespace ICSharpCode.WpfDesign.AddIn void OnCurrentToolChanged(object sender, EventArgs e) { - Debug.WriteLine("WpfToolbox.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; + object tagToFind; + if (toolService.CurrentTool == toolService.PointerTool) { + tagToFind = null; + } else { + tagToFind = toolService.CurrentTool; + } + if (sideBar.ActiveTab.ChoosedItem != null) { + if (sideBar.ActiveTab.ChoosedItem.Tag == tagToFind) + return; + } + foreach (SideTabItem item in sideBar.ActiveTab.Items) { + if (item.Tag == tagToFind) { + sideBar.ActiveTab.ChoosedItem = item; + sideBar.Refresh(); + return; + } + } + foreach (SideTab tab in sideBar.Tabs) { + foreach (SideTabItem item in tab.Items) { + if (item.Tag == tagToFind) { + sideBar.ActiveTab = tab; + sideBar.ActiveTab.ChoosedItem = item; + sideBar.Refresh(); + return; + } + } + } + sideBar.ActiveTab.ChoosedItem = null; + sideBar.Refresh(); } sealed class WpfSideBar : SharpDevelopSideBar diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs index 53234c1fbb..cd376f7b0b 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs @@ -6,6 +6,7 @@ // using System; +using System.Diagnostics; using System.Collections.Generic; using System.Text; using System.Windows.Forms; @@ -15,6 +16,7 @@ using System.Xml; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.WpfDesign.Designer; +using ICSharpCode.WpfDesign.Designer.Services; using ICSharpCode.WpfDesign.PropertyEditor; namespace ICSharpCode.WpfDesign.AddIn @@ -34,10 +36,11 @@ namespace ICSharpCode.WpfDesign.AddIn protected override void LoadInternal(OpenedFile file, System.IO.Stream stream) { + Debug.Assert(file == this.PrimaryFile); if (designer == null) { // initialize designer on first load DragDropExceptionHandler.HandleException = ICSharpCode.Core.MessageService.ShowError; - wpfHost = new ElementHost(); + wpfHost = new SharpDevelopElementHost(); designer = new DesignSurface(); wpfHost.Child = designer; this.UserControl = wpfHost; @@ -45,7 +48,9 @@ namespace ICSharpCode.WpfDesign.AddIn } using (XmlTextReader r = new XmlTextReader(stream)) { designer.LoadDesigner(r); + designer.DesignContext.Services.AddService(typeof(IPropertyDescriptionService), new PropertyDescriptionService(this.PrimaryFile)); designer.DesignContext.Services.Selection.SelectionChanged += OnSelectionChanged; + designer.DesignContext.Services.GetService().UndoStackChanged += OnUndoStackChanged; } } @@ -57,13 +62,18 @@ namespace ICSharpCode.WpfDesign.AddIn } } + void OnUndoStackChanged(object sender, EventArgs e) + { + this.PrimaryFile.MakeDirty(); + } + #region Property editor / SelectionChanged Designer.PropertyEditor propertyEditor; ElementHost propertyEditorHost; void InitPropertyEditor() { - propertyEditorHost = new ElementHost(); + propertyEditorHost = new SharpDevelopElementHost(); propertyEditor = new Designer.PropertyEditor(); propertyEditorHost.Child = propertyEditor; propertyContainer.PropertyGridReplacementControl = propertyEditorHost; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj index 71591c13fd..f67e246be6 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj @@ -52,12 +52,19 @@ Configuration\GlobalAssemblyInfo.cs + + + + {2D18BE89-D210-49EB-A9DD-2246FBB3DF6D} + ICSharpCode.TextEditor + False + {2748AD25-9C63-4E12-877B-4DCE96FBED54} ICSharpCode.SharpDevelop @@ -68,6 +75,11 @@ ICSharpCode.Core False + + {924EE450-603D-49C1-A8E5-4AFAA31CE6F3} + ICSharpCode.SharpDevelop.Dom + False + {8035765F-D51F-4A0C-A746-2FD100E19419} ICSharpCode.SharpDevelop.Widgets diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyNameTextBlock.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyNameTextBlock.cs index c4417f5323..b5905d278a 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyNameTextBlock.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyNameTextBlock.cs @@ -60,7 +60,12 @@ namespace ICSharpCode.WpfDesign.Designer.Controls DockPanel.SetDock(textBlock, Dock.Top); toolTipDockPanel.Children.Add(textBlock); object description = property.GetDescription(); - if (description != null) { + if (description is UIElement) { + toolTipDockPanel.Children.Add((UIElement)description); + } else if (description is string) { + textBlock.Inlines.Add(new LineBreak()); + textBlock.Inlines.Add((string)description); + } else if (description != null) { ContentControl cc = new ContentControl(); cc.Content = description; toolTipDockPanel.Children.Add(cc); diff --git a/src/Main/Base/Project/Src/Commands/EditCommands.cs b/src/Main/Base/Project/Src/Commands/EditCommands.cs index b88ba129d8..ca0b1a5d66 100644 --- a/src/Main/Base/Project/Src/Commands/EditCommands.cs +++ b/src/Main/Base/Project/Src/Commands/EditCommands.cs @@ -16,7 +16,7 @@ namespace ICSharpCode.SharpDevelop.Commands { public override bool IsEnabled { get { - IUndoHandler editable = WorkbenchSingleton.Workbench.ActiveContent as IUndoHandler; + IUndoHandler editable = (WorkbenchSingleton.Workbench.ActiveContent as IUndoHandler) ?? (WorkbenchSingleton.ActiveControl as IUndoHandler); if (editable != null) { return editable.EnableUndo; } else { @@ -31,7 +31,7 @@ namespace ICSharpCode.SharpDevelop.Commands public override void Run() { - IUndoHandler editable = WorkbenchSingleton.Workbench.ActiveContent as IUndoHandler; + IUndoHandler editable = (WorkbenchSingleton.Workbench.ActiveContent as IUndoHandler) ?? (WorkbenchSingleton.ActiveControl as IUndoHandler); if (editable != null) { editable.Undo(); } else { @@ -47,7 +47,7 @@ namespace ICSharpCode.SharpDevelop.Commands { public override bool IsEnabled { get { - IUndoHandler editable = WorkbenchSingleton.Workbench.ActiveContent as IUndoHandler; + IUndoHandler editable = (WorkbenchSingleton.Workbench.ActiveContent as IUndoHandler) ?? (WorkbenchSingleton.ActiveControl as IUndoHandler); if (editable != null) { return editable.EnableRedo; } @@ -57,7 +57,7 @@ namespace ICSharpCode.SharpDevelop.Commands public override void Run() { - IUndoHandler editable = WorkbenchSingleton.Workbench.ActiveContent as IUndoHandler; + IUndoHandler editable = (WorkbenchSingleton.Workbench.ActiveContent as IUndoHandler) ?? (WorkbenchSingleton.ActiveControl as IUndoHandler); if (editable != null) { editable.Redo(); } @@ -77,7 +77,7 @@ namespace ICSharpCode.SharpDevelop.Commands ComboBox cb = ctl as ComboBox; if (cb != null && cb.DropDownStyle != ComboBoxStyle.DropDownList) return new ComboBoxWrapper(cb); - return null; + return ctl as IClipboardHandler; } private class TextBoxWrapper : IClipboardHandler diff --git a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/OverrideCompletionDataProvider.cs b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/OverrideCompletionDataProvider.cs index 779cb53ff3..659175d889 100644 --- a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/OverrideCompletionDataProvider.cs +++ b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/OverrideCompletionDataProvider.cs @@ -99,14 +99,14 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor "override " + GetName(method, ConversionFlags.ShowReturnType | ConversionFlags.ShowParameterList | ConversionFlags.ShowAccessibility) - + "\n\n" + method.Documentation, + + "\n\n" + CodeCompletionData.GetDocumentation(method.Documentation), ClassBrowserIconService.GetIcon(method)) { this.member = method; } public OverrideCompletionData(IProperty property) - : base(property.Name, "override " + property.Name + "\n\n" + property.Documentation, + : base(property.Name, "override " + property.Name + "\n\n" + CodeCompletionData.GetDocumentation(property.Documentation), ClassBrowserIconService.GetIcon(property)) { this.member = property;