Browse Source

Cut/Copy/Paste: use WPF routed commands.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3921 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
376c978294
  1. 41
      AddIns/ICSharpCode.SharpDevelop.addin
  2. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  3. 197
      src/Main/Base/Project/Src/Commands/EditCommands.cs
  4. 6
      src/Main/Base/Project/Src/Gui/AbstractViewContentHandlingLoadErrors.cs
  5. 2
      src/Main/Base/Project/Src/Gui/Pads/ToolsPad.cs
  6. 14
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonPadContent.cs
  7. 12
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs
  8. 16
      src/Main/Base/Project/Src/Gui/WorkbenchSingleton.cs
  9. 53
      src/Main/Base/Project/Src/Util/ExtensionMethods.cs
  10. 192
      src/Main/Base/Project/Src/Util/SDWindowsFormsHost.cs
  11. 6
      src/Main/Core/Project/Src/Services/MessageService/MessageService.cs
  12. 22
      src/Main/ICSharpCode.Core.Presentation/Menu/MenuCommand.cs
  13. 2
      src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarButton.cs

41
AddIns/ICSharpCode.SharpDevelop.addin

@ -817,34 +817,28 @@
<ToolbarItem id = "Cut" <ToolbarItem id = "Cut"
icon = "Icons.16x16.CutIcon" icon = "Icons.16x16.CutIcon"
tooltip = "${res:XML.MainMenu.EditMenu.Cut.Description}" tooltip = "${res:XML.MainMenu.EditMenu.Cut.Description}"
loadclasslazy = "false" command = "Cut"/>
class = "ICSharpCode.SharpDevelop.Commands.Cut"/>
<ToolbarItem id = "Copy" <ToolbarItem id = "Copy"
icon = "Icons.16x16.CopyIcon" icon = "Icons.16x16.CopyIcon"
tooltip = "${res:XML.MainMenu.EditMenu.Copy.Description}" tooltip = "${res:XML.MainMenu.EditMenu.Copy.Description}"
loadclasslazy = "false" command = "Copy"/>
class = "ICSharpCode.SharpDevelop.Commands.Copy"/>
<ToolbarItem id = "Paste" <ToolbarItem id = "Paste"
icon = "Icons.16x16.PasteIcon" icon = "Icons.16x16.PasteIcon"
tooltip = "${res:XML.MainMenu.EditMenu.Paste.Description}" tooltip = "${res:XML.MainMenu.EditMenu.Paste.Description}"
loadclasslazy = "false" command = "Paste"/>
class = "ICSharpCode.SharpDevelop.Commands.Paste"/>
<ToolbarItem id = "Delete" <ToolbarItem id = "Delete"
icon = "Icons.16x16.DeleteIcon" icon = "Icons.16x16.DeleteIcon"
tooltip = "${res:XML.MainMenu.EditMenu.Delete.Description}" tooltip = "${res:XML.MainMenu.EditMenu.Delete.Description}"
loadclasslazy = "false" command = "Delete"/>
class = "ICSharpCode.SharpDevelop.Commands.Delete"/>
<ToolbarItem id = "UndoRedoSeparator" type = "Separator"/> <ToolbarItem id = "UndoRedoSeparator" type = "Separator"/>
<ToolbarItem id = "Undo" <ToolbarItem id = "Undo"
icon = "Icons.16x16.UndoIcon" icon = "Icons.16x16.UndoIcon"
tooltip = "${res:XML.MainMenu.EditMenu.Undo.Description}" tooltip = "${res:XML.MainMenu.EditMenu.Undo.Description}"
loadclasslazy = "false" command = "Undo"/>
class = "ICSharpCode.SharpDevelop.Commands.Undo"/>
<ToolbarItem id = "Redo" <ToolbarItem id = "Redo"
icon = "Icons.16x16.RedoIcon" icon = "Icons.16x16.RedoIcon"
tooltip = "${res:XML.MainMenu.EditMenu.Redo.Description}" tooltip = "${res:XML.MainMenu.EditMenu.Redo.Description}"
loadclasslazy = "false" command = "Redo"/>
class = "ICSharpCode.SharpDevelop.Commands.Redo"/>
<ToolbarItem id = "CompileSeparator" type = "Separator"/> <ToolbarItem id = "CompileSeparator" type = "Separator"/>
@ -1256,43 +1250,37 @@
icon = "Icons.16x16.UndoIcon" icon = "Icons.16x16.UndoIcon"
type = "Item" type = "Item"
shortcut = "Control|Z" shortcut = "Control|Z"
loadclasslazy = "false" command = "Undo"/>
class = "ICSharpCode.SharpDevelop.Commands.Undo"/>
<MenuItem id = "Redo" <MenuItem id = "Redo"
label = "${res:XML.MainMenu.EditMenu.Redo}" label = "${res:XML.MainMenu.EditMenu.Redo}"
icon = "Icons.16x16.RedoIcon" icon = "Icons.16x16.RedoIcon"
type = "Item" type = "Item"
shortcut = "Control|Y" shortcut = "Control|Y"
loadclasslazy = "false" command = "Redo"/>
class = "ICSharpCode.SharpDevelop.Commands.Redo"/>
<MenuItem id = "Separator1" type = "Separator" /> <MenuItem id = "Separator1" type = "Separator" />
<MenuItem id = "Cut" <MenuItem id = "Cut"
label = "${res:XML.MainMenu.EditMenu.Cut}" label = "${res:XML.MainMenu.EditMenu.Cut}"
icon = "Icons.16x16.CutIcon" icon = "Icons.16x16.CutIcon"
type = "Item" type = "Item"
shortcut = "Control|X" shortcut = "Control|X"
loadclasslazy = "false" command = "Cut"/>
class = "ICSharpCode.SharpDevelop.Commands.Cut"/>
<MenuItem id = "Copy" <MenuItem id = "Copy"
label = "${res:XML.MainMenu.EditMenu.Copy}" label = "${res:XML.MainMenu.EditMenu.Copy}"
icon = "Icons.16x16.CopyIcon" icon = "Icons.16x16.CopyIcon"
type = "Item" type = "Item"
shortcut = "Control|C" shortcut = "Control|C"
loadclasslazy = "false" command = "Copy"/>
class = "ICSharpCode.SharpDevelop.Commands.Copy"/>
<MenuItem id = "Paste" <MenuItem id = "Paste"
label = "${res:XML.MainMenu.EditMenu.Paste}" label = "${res:XML.MainMenu.EditMenu.Paste}"
icon = "Icons.16x16.PasteIcon" icon = "Icons.16x16.PasteIcon"
type = "Item" type = "Item"
shortcut = "Control|V" shortcut = "Control|V"
loadclasslazy = "false" command = "Paste"/>
class = "ICSharpCode.SharpDevelop.Commands.Paste"/>
<MenuItem id = "Delete" <MenuItem id = "Delete"
label = "${res:XML.MainMenu.EditMenu.Delete}" label = "${res:XML.MainMenu.EditMenu.Delete}"
icon = "Icons.16x16.DeleteIcon" icon = "Icons.16x16.DeleteIcon"
type = "Item" type = "Item"
loadclasslazy = "false" command = "Delete"/>
class = "ICSharpCode.SharpDevelop.Commands.Delete"/>
<MenuItem id = "Separator2" type = "Separator" /> <MenuItem id = "Separator2" type = "Separator" />
<Condition name = "WindowActive" activewindow="ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.ITextEditorControlProvider" action="Disable"> <Condition name = "WindowActive" activewindow="ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.ITextEditorControlProvider" action="Disable">
<MenuItem id = "Insert" label = "${res:XML.MainMenu.EditMenu.Insert}" type="Menu"> <MenuItem id = "Insert" label = "${res:XML.MainMenu.EditMenu.Insert}" type="Menu">
@ -1318,8 +1306,7 @@
label = "${res:XML.MainMenu.EditMenu.SelectAll}" label = "${res:XML.MainMenu.EditMenu.SelectAll}"
type = "Item" type = "Item"
shortcut = "Control|A" shortcut = "Control|A"
loadclasslazy = "false" command = "SelectAll"/>
class = "ICSharpCode.SharpDevelop.Commands.SelectAll"/>
<MenuItem id = "Separator4" type = "Separator" /> <MenuItem id = "Separator4" type = "Separator" />
<ComplexCondition action="Disable"> <ComplexCondition action="Disable">
<Or> <Or>
@ -2204,7 +2191,7 @@
label = "${res:XML.MainMenu.EditMenu.Copy}" label = "${res:XML.MainMenu.EditMenu.Copy}"
type = "Item" type = "Item"
icon = "Icons.16x16.CopyIcon" icon = "Icons.16x16.CopyIcon"
class = "ICSharpCode.SharpDevelop.Commands.Copy"/> command = "Copy"/>
</Path> </Path>
<Path name="/SharpDevelop/Pads/TaskList/Toolbar"> <Path name="/SharpDevelop/Pads/TaskList/Toolbar">

1
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -725,6 +725,7 @@
<Compile Include="Src\Project\CompilableProject.cs" /> <Compile Include="Src\Project\CompilableProject.cs" />
<Compile Include="Src\Project\MSBuildInternals.cs" /> <Compile Include="Src\Project\MSBuildInternals.cs" />
<Compile Include="Src\Util\Pair.cs" /> <Compile Include="Src\Util\Pair.cs" />
<Compile Include="Src\Util\SDWindowsFormsHost.cs" />
<Compile Include="Src\Util\Set.cs" /> <Compile Include="Src\Util\Set.cs" />
<Compile Include="Src\Util\ReadOnlyCollectionWrapper.cs" /> <Compile Include="Src\Util\ReadOnlyCollectionWrapper.cs" />
<Compile Include="Src\Project\Items\ItemType.cs" /> <Compile Include="Src\Project\Items\ItemType.cs" />

197
src/Main/Base/Project/Src/Commands/EditCommands.cs

@ -14,203 +14,6 @@ using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.SharpDevelop.Commands namespace ICSharpCode.SharpDevelop.Commands
{ {
public class Undo : AbstractMenuCommand
{
public override bool IsEnabled {
get {
IUndoHandler editable = (WorkbenchSingleton.Workbench.ActiveContent as IUndoHandler) ?? (WorkbenchSingleton.ActiveControl as IUndoHandler);
if (editable != null) {
return editable.EnableUndo;
} else {
TextBoxBase textBox = WorkbenchSingleton.ActiveControl as TextBoxBase;
if (textBox != null) {
return textBox.CanUndo;
}
}
return false;
}
}
public override void Run()
{
IUndoHandler editable = (WorkbenchSingleton.Workbench.ActiveContent as IUndoHandler) ?? (WorkbenchSingleton.ActiveControl as IUndoHandler);
if (editable != null) {
editable.Undo();
} else {
TextBoxBase textBox = WorkbenchSingleton.ActiveControl as TextBoxBase;
if (textBox != null) {
textBox.Undo();
}
}
}
}
public class Redo : AbstractMenuCommand
{
public override bool IsEnabled {
get {
IUndoHandler editable = (WorkbenchSingleton.Workbench.ActiveContent as IUndoHandler) ?? (WorkbenchSingleton.ActiveControl as IUndoHandler);
if (editable != null) {
return editable.EnableRedo;
}
return false;
}
}
public override void Run()
{
IUndoHandler editable = (WorkbenchSingleton.Workbench.ActiveContent as IUndoHandler) ?? (WorkbenchSingleton.ActiveControl as IUndoHandler);
if (editable != null) {
editable.Redo();
}
}
}
public abstract class AbstractClipboardCommand : AbstractMenuCommand
{
protected abstract bool GetEnabled(IClipboardHandler editable);
protected abstract void Run(IClipboardHandler editable);
public static IClipboardHandler GetClipboardHandlerWrapper(Control ctl)
{
TextBoxBase tb = ctl as TextBoxBase;
if (tb != null)
return new TextBoxWrapper(tb);
ComboBox cb = ctl as ComboBox;
if (cb != null && cb.DropDownStyle != ComboBoxStyle.DropDownList)
return new ComboBoxWrapper(cb);
return ctl as IClipboardHandler;
}
private class TextBoxWrapper : IClipboardHandler
{
TextBoxBase textBox;
public TextBoxWrapper(TextBoxBase textBox) {
this.textBox = textBox;
}
public bool EnableCut {
get { return !textBox.ReadOnly && textBox.SelectionLength > 0; }
}
public bool EnableCopy {
get { return textBox.SelectionLength > 0; }
}
public bool EnablePaste {
get { return !textBox.ReadOnly; }
}
public bool EnableDelete {
get { return !textBox.ReadOnly && textBox.SelectionLength > 0; }
}
public bool EnableSelectAll {
get { return textBox.TextLength > 0; }
}
public void Cut() { textBox.Cut(); }
public void Copy() { textBox.Copy(); }
public void Paste() { textBox.Paste(); }
public void Delete() { textBox.SelectedText = ""; }
public void SelectAll() { textBox.SelectAll(); }
}
private class ComboBoxWrapper : IClipboardHandler
{
ComboBox comboBox;
public ComboBoxWrapper(ComboBox comboBox) {
this.comboBox = comboBox;
}
public bool EnableCut {
get { return comboBox.SelectionLength > 0; }
}
public bool EnableCopy {
get { return comboBox.SelectionLength > 0; }
}
public bool EnablePaste {
get { return ClipboardHandling.GetClipboardContainsText(); }
}
public bool EnableDelete {
get { return true; }
}
public bool EnableSelectAll {
get { return comboBox.Text.Length > 0; }
}
public void Cut() { ClipboardWrapper.SetText(comboBox.SelectedText); comboBox.SelectedText = ""; }
public void Copy() { ClipboardWrapper.SetText(comboBox.SelectedText); }
public void Paste() { comboBox.SelectedText = ClipboardWrapper.GetText(); }
public void Delete() { comboBox.SelectedText = ""; }
public void SelectAll() { comboBox.SelectAll(); }
}
public override bool IsEnabled {
get {
IClipboardHandler editable = WorkbenchSingleton.Workbench.ActiveContent as IClipboardHandler;
if (editable == null)
editable = GetClipboardHandlerWrapper(WorkbenchSingleton.ActiveControl);
if (editable != null) {
return GetEnabled(editable);
}
return false;
}
}
public override void Run()
{
IClipboardHandler editable = WorkbenchSingleton.Workbench.ActiveContent as IClipboardHandler;
if (editable == null)
editable = GetClipboardHandlerWrapper(WorkbenchSingleton.ActiveControl);
if (editable != null) {
Run(editable);
}
}
}
public class Cut : AbstractClipboardCommand
{
protected override bool GetEnabled(IClipboardHandler editable) {
return editable.EnableCut;
}
protected override void Run(IClipboardHandler editable) {
editable.Cut();
}
}
public class Copy : AbstractClipboardCommand
{
protected override bool GetEnabled(IClipboardHandler editable) {
return editable.EnableCopy;
}
protected override void Run(IClipboardHandler editable) {
editable.Copy();
}
}
public class Paste : AbstractClipboardCommand
{
protected override bool GetEnabled(IClipboardHandler editable) {
return editable.EnablePaste;
}
protected override void Run(IClipboardHandler editable) {
editable.Paste();
}
}
public class Delete : AbstractClipboardCommand
{
protected override bool GetEnabled(IClipboardHandler editable) {
return editable.EnableDelete;
}
protected override void Run(IClipboardHandler editable) {
editable.Delete();
}
}
public class SelectAll : AbstractClipboardCommand
{
protected override bool GetEnabled(IClipboardHandler editable) {
return editable.EnableSelectAll;
}
protected override void Run(IClipboardHandler editable) {
editable.SelectAll();
}
}
public class WordCount : AbstractMenuCommand public class WordCount : AbstractMenuCommand
{ {
public override void Run() public override void Run()

6
src/Main/Base/Project/Src/Gui/AbstractViewContentHandlingLoadErrors.cs

@ -50,7 +50,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (userContent != value) { if (userContent != value) {
userContent = value; userContent = value;
if (errorList.Count == 0) { if (errorList.Count == 0) {
contentControl.SetContent(userContent); contentControl.SetContent(userContent, this);
} }
} }
} }
@ -91,7 +91,7 @@ namespace ICSharpCode.SharpDevelop.Gui
errorTextBox.Background = SystemColors.WindowBrush; errorTextBox.Background = SystemColors.WindowBrush;
} }
errorTextBox.Text = String.Concat(this.LoadErrorHeaderText, ex.ToString()); errorTextBox.Text = String.Concat(this.LoadErrorHeaderText, ex.ToString());
contentControl.SetContent(errorTextBox); contentControl.SetContent(errorTextBox, this);
} }
Dictionary<OpenedFile, LoadError> errorList = new Dictionary<OpenedFile, LoadError>(); Dictionary<OpenedFile, LoadError> errorList = new Dictionary<OpenedFile, LoadError>();
@ -111,7 +111,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (errorList.Count > 0) { if (errorList.Count > 0) {
errorList.Remove(file); errorList.Remove(file);
if (errorList.Count == 0) { if (errorList.Count == 0) {
contentControl.SetContent(userContent); contentControl.SetContent(userContent, this);
} else { } else {
ShowError(errorList.Values.First().exception); ShowError(errorList.Values.First().exception);
} }

2
src/Main/Base/Project/Src/Gui/Pads/ToolsPad.cs

@ -45,7 +45,7 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
IToolsHost th = WorkbenchSingleton.Workbench.ActiveViewContent as IToolsHost; IToolsHost th = WorkbenchSingleton.Workbench.ActiveViewContent as IToolsHost;
if (th != null && th.ToolsContent != null) { if (th != null && th.ToolsContent != null) {
contentControl.SetContent(th.ToolsContent); contentControl.SetContent(th.ToolsContent, th);
} else { } else {
contentControl.SetContent(StringParser.Parse("${res:SharpDevelop.SideBar.NoToolsAvailableForCurrentDocument}")); contentControl.SetContent(StringParser.Parse("${res:SharpDevelop.SideBar.NoToolsAvailableForCurrentDocument}"));
} }

14
src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonPadContent.cs

@ -18,12 +18,12 @@ namespace ICSharpCode.SharpDevelop.Gui
sealed class AvalonPadContent : DockableContent, IDisposable sealed class AvalonPadContent : DockableContent, IDisposable
{ {
PadDescriptor descriptor; PadDescriptor descriptor;
IPadContent content; IPadContent padInstance;
AvalonDockLayout layout; AvalonDockLayout layout;
TextBlock placeholder; TextBlock placeholder;
public IPadContent PadContent { public IPadContent PadContent {
get { return content; } get { return padInstance; }
} }
public AvalonPadContent(AvalonDockLayout layout, PadDescriptor descriptor) public AvalonPadContent(AvalonDockLayout layout, PadDescriptor descriptor)
@ -49,9 +49,9 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
if (placeholder != null && placeholder.IsVisible && !layout.Busy) { if (placeholder != null && placeholder.IsVisible && !layout.Busy) {
placeholder.IsVisibleChanged -= AvalonPadContent_IsVisibleChanged; placeholder.IsVisibleChanged -= AvalonPadContent_IsVisibleChanged;
content = descriptor.PadContent; padInstance = descriptor.PadContent;
if (content != null) { if (padInstance != null) {
this.SetContent(content.Content); this.SetContent(padInstance.Content, padInstance);
placeholder = null; placeholder = null;
} }
} }
@ -59,8 +59,8 @@ namespace ICSharpCode.SharpDevelop.Gui
public void Dispose() public void Dispose()
{ {
if (content != null) { if (padInstance != null) {
content.Dispose(); padInstance.Dispose();
} }
} }
} }

12
src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs

@ -120,7 +120,7 @@ namespace ICSharpCode.SharpDevelop.Gui
window.RegisterNewContent(item); window.RegisterNewContent(item);
if (Count == 1) { if (Count == 1) {
window.SetContent(item.Content); window.SetContent(item.Content, item);
} else { } else {
if (Count == 2) { if (Count == 2) {
window.CreateViewTabControl(); window.CreateViewTabControl();
@ -129,13 +129,13 @@ namespace ICSharpCode.SharpDevelop.Gui
TabItem oldPage = new TabItem(); TabItem oldPage = new TabItem();
oldPage.Header = StringParser.Parse(oldItem.TabPageText); oldPage.Header = StringParser.Parse(oldItem.TabPageText);
oldPage.SetContent(oldItem.Content); oldPage.SetContent(oldItem.Content, oldItem);
window.viewTabControl.Items.Add(oldPage); window.viewTabControl.Items.Add(oldPage);
} }
TabItem newPage = new TabItem(); TabItem newPage = new TabItem();
newPage.Header = StringParser.Parse(item.TabPageText); newPage.Header = StringParser.Parse(item.TabPageText);
newPage.SetContent(item.Content); newPage.SetContent(item.Content, item);
window.viewTabControl.Items.Insert(index, newPage); window.viewTabControl.Items.Insert(index, newPage);
} }
@ -151,7 +151,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (Count < 2) { if (Count < 2) {
window.ClearContent(); window.ClearContent();
if (Count == 1) { if (Count == 1) {
window.SetContent(this[0].Content); window.SetContent(this[0].Content, this[0]);
} }
} else { } else {
window.viewTabControl.Items.RemoveAt(index); window.viewTabControl.Items.RemoveAt(index);
@ -169,10 +169,10 @@ namespace ICSharpCode.SharpDevelop.Gui
if (Count == 1) { if (Count == 1) {
window.ClearContent(); window.ClearContent();
window.SetContent(item.Content); window.SetContent(item.Content, item);
} else { } else {
TabItem page = (TabItem)window.viewTabControl.Items[index]; TabItem page = (TabItem)window.viewTabControl.Items[index];
page.SetContent(item.Content); page.SetContent(item.Content, item);
page.Header = StringParser.Parse(item.TabPageText); page.Header = StringParser.Parse(item.TabPageText);
} }
window.UpdateActiveViewContent(); window.UpdateActiveViewContent();

16
src/Main/Base/Project/Src/Gui/WorkbenchSingleton.cs

@ -57,22 +57,6 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
public static Control ActiveControl {
get {
return null;
/*
ContainerControl container = WorkbenchSingleton.MainForm;
Control ctl;
do {
ctl = container.ActiveControl;
if (ctl == null)
return container;
container = ctl as ContainerControl;
} while(container != null);
return ctl;*/
}
}
/// <remarks> /// <remarks>
/// This method handles the redraw all event for specific changed IDE properties /// This method handles the redraw all event for specific changed IDE properties
/// </remarks> /// </remarks>

53
src/Main/Base/Project/Src/Util/ExtensionMethods.cs

@ -126,52 +126,39 @@ namespace ICSharpCode.SharpDevelop
/// inside the host isn't) /// inside the host isn't)
/// </summary> /// </summary>
public static void SetContent(this ContentControl contentControl, object content) public static void SetContent(this ContentControl contentControl, object content)
{
SetContent(contentControl, content, null);
}
public static void SetContent(this ContentControl contentControl, object content, object serviceObject)
{ {
if (contentControl == null) if (contentControl == null)
throw new ArgumentNullException("contentControl"); throw new ArgumentNullException("contentControl");
// serviceObject = object implementing the old clipboard/undo interfaces
// to allow WinForms AddIns to handle WPF commands
var host = contentControl.Content as SDWindowsFormsHost; var host = contentControl.Content as SDWindowsFormsHost;
if (host != null) { if (host != null) {
if (host.Child == content) if (host.Child == content) {
host.ServiceObject = serviceObject;
return; return;
}
host.Dispose(); host.Dispose();
} }
if (content is WinForms.Control) { if (content is WinForms.Control) {
contentControl.Content = new SDWindowsFormsHost((WinForms.Control)content); contentControl.Content = new SDWindowsFormsHost {
Child = (WinForms.Control)content,
ServiceObject = serviceObject,
DisposeChild = false
};
} else if (content is string) { } else if (content is string) {
contentControl.Content = new TextBlock(new Run(content.ToString())) { TextWrapping = TextWrapping.Wrap }; contentControl.Content = new TextBlock {
Text = content.ToString(),
TextWrapping = TextWrapping.Wrap
};
} else { } else {
contentControl.Content = content; contentControl.Content = content;
} }
} }
/// <summary>
/// WindowsFormsHost that prevents its child from being disposed.
/// The default WindowsFormsHost disposes its child when the WPF application shuts down,
/// but some events in SharpDevelop occur after the WPF shutdown (e.g. SolutionClosed), so we must
/// not dispose pads that could still be handling them.
/// </summary>
class SDWindowsFormsHost : WinForms.Integration.WindowsFormsHost
{
public SDWindowsFormsHost(WinForms.Control child)
{
this.Child = child;
child.Disposed += child_Disposed;
}
void child_Disposed(object sender, EventArgs e)
{
Dispose();
}
protected override void Dispose(bool disposing)
{
if (disposing && Child != null) {
Child.Disposed -= child_Disposed;
// prevent child from being disposed
Child = null;
}
base.Dispose(disposing);
}
}
} }
} }

192
src/Main/Base/Project/Src/Util/SDWindowsFormsHost.cs

@ -0,0 +1,192 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.Core.WinForms;
using System;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using System.Windows.Input;
using ICSharpCode.SharpDevelop.DefaultEditor;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.SharpDevelop
{
/// <summary>
/// WindowsFormsHost used in SharpDevelop.
/// </summary>
public class SDWindowsFormsHost : WindowsFormsHost
{
public SDWindowsFormsHost()
{
this.DisposeChild = true;
CreateBindings();
}
#region Binding
void CreateBindings()
{
AddBinding(ApplicationCommands.Copy, (IClipboardHandler c) => c.Copy(), c => c.EnableCopy);
AddBinding(ApplicationCommands.Cut, (IClipboardHandler c) => c.Cut(), c => c.EnableCut);
AddBinding(ApplicationCommands.Paste, (IClipboardHandler c) => c.Paste(), c => c.EnablePaste);
AddBinding(ApplicationCommands.Delete, (IClipboardHandler c) => c.Delete(), c => c.EnableDelete);
AddBinding(ApplicationCommands.SelectAll, (IClipboardHandler c) => c.SelectAll(), c => c.EnableSelectAll);
AddBinding(ApplicationCommands.Help, (IContextHelpProvider h) => h.ShowHelp(), h => true);
AddBinding(ApplicationCommands.Undo, (IUndoHandler u) => u.Undo(), u => u.EnableUndo);
AddBinding(ApplicationCommands.Redo, (IUndoHandler u) => u.Redo(), u => u.EnableRedo);
}
void AddBinding<T>(ICommand command, Action<T> execute, Predicate<T> canExecute) where T : class
{
ExecutedRoutedEventHandler onExected = (sender, e) => {
var cbh = GetInterface<T>();
if (cbh != null) {
e.Handled = true;
if (canExecute(cbh))
execute(cbh);
}
};
CanExecuteRoutedEventHandler onCanExecute = (sender, e) => {
var cbh = GetInterface<T>();
if (cbh != null) {
e.Handled = true;
e.CanExecute = canExecute(cbh);
}
};
this.CommandBindings.Add(new CommandBinding(command, onExected, onCanExecute));
}
#endregion
#region Service Object
/// <summary>
/// Gets/Sets the object that implements the IClipboardHandler, IUndoHandler etc. interfaces...
/// </summary>
public object ServiceObject { get; set; }
T GetInterface<T>() where T : class
{
T instance = this.ServiceObject as T;
if (instance == null) {
instance = GetServiceWrapper(GetActiveControl()) as T;
}
return instance;
}
Control GetActiveControl()
{
ContainerControl container = null;
Control ctl = this.Child;
while (ctl != null) {
container = ctl as ContainerControl;
if (container == null)
return ctl;
ctl = container.ActiveControl;
}
return container;
}
static object GetServiceWrapper(Control ctl)
{
TextBoxBase tb = ctl as TextBoxBase;
if (tb != null)
return new TextBoxWrapper(tb);
ComboBox cb = ctl as ComboBox;
if (cb != null && cb.DropDownStyle != ComboBoxStyle.DropDownList)
return new ComboBoxWrapper(cb);
return ctl;
}
sealed class TextBoxWrapper : IClipboardHandler, IUndoHandler
{
TextBoxBase textBox;
public TextBoxWrapper(TextBoxBase textBox) {
this.textBox = textBox;
}
public bool EnableCut {
get { return !textBox.ReadOnly && textBox.SelectionLength > 0; }
}
public bool EnableCopy {
get { return textBox.SelectionLength > 0; }
}
public bool EnablePaste {
get { return !textBox.ReadOnly && ClipboardHandling.GetClipboardContainsText(); }
}
public bool EnableDelete {
get { return !textBox.ReadOnly && textBox.SelectionLength > 0; }
}
public bool EnableSelectAll {
get { return textBox.TextLength > 0; }
}
public void Cut() { textBox.Cut(); }
public void Copy() { textBox.Copy(); }
public void Paste() { textBox.Paste(); }
public void Delete() { textBox.SelectedText = ""; }
public void SelectAll() { textBox.SelectAll(); }
public bool EnableUndo { get { return textBox.CanUndo; } }
public bool EnableRedo { get { return false; } }
public void Undo()
{
textBox.Undo();
}
public void Redo()
{
}
}
sealed class ComboBoxWrapper : IClipboardHandler
{
ComboBox comboBox;
public ComboBoxWrapper(ComboBox comboBox) {
this.comboBox = comboBox;
}
public bool EnableCut {
get { return comboBox.SelectionLength > 0; }
}
public bool EnableCopy {
get { return comboBox.SelectionLength > 0; }
}
public bool EnablePaste {
get { return ClipboardHandling.GetClipboardContainsText(); }
}
public bool EnableDelete {
get { return true; }
}
public bool EnableSelectAll {
get { return comboBox.Text.Length > 0; }
}
public void Cut() { ClipboardWrapper.SetText(comboBox.SelectedText); comboBox.SelectedText = ""; }
public void Copy() { ClipboardWrapper.SetText(comboBox.SelectedText); }
public void Paste() { comboBox.SelectedText = ClipboardWrapper.GetText(); }
public void Delete() { comboBox.SelectedText = ""; }
public void SelectAll() { comboBox.SelectAll(); }
}
#endregion
/// <summary>
/// Gets/Sets whether the windows forms control will be disposed
/// when the WindowsFormsHost is disposed.
/// The default value is true.
/// </summary>
/// <remarks>
/// The default WindowsFormsHost disposes its child when the WPF application shuts down,
/// but some events in SharpDevelop occur after the WPF shutdown (e.g. SolutionClosed), so we must
/// not dispose pads that could still be handling them.
/// </remarks>
public bool DisposeChild { get; set; }
protected override void Dispose(bool disposing)
{
if (disposing && !this.DisposeChild && Child != null) {
// prevent child from being disposed
Child = null;
}
base.Dispose(disposing);
}
}
}

6
src/Main/Core/Project/Src/Services/MessageService/MessageService.cs

@ -125,7 +125,7 @@ namespace ICSharpCode.Core
/// </summary> /// </summary>
public static bool AskQuestion(string question) public static bool AskQuestion(string question)
{ {
return AskQuestion(StringParser.Parse(question), StringParser.Parse("${res:Global.QuestionText}")); return AskQuestion(question, StringParser.Parse("${res:Global.QuestionText}"));
} }
/// <summary> /// <summary>
@ -211,7 +211,9 @@ namespace ICSharpCode.Core
{ {
try { try {
return String.Format(StringParser.Parse(formatstring), formatitems); return String.Format(StringParser.Parse(formatstring), formatitems);
} catch (FormatException) { } catch (FormatException ex) {
LoggingService.Warn(ex);
StringBuilder b = new StringBuilder(StringParser.Parse(formatstring)); StringBuilder b = new StringBuilder(StringParser.Parse(formatstring));
foreach(string formatitem in formatitems) { foreach(string formatitem in formatitems) {
b.Append("\nItem: "); b.Append("\nItem: ");

22
src/Main/ICSharpCode.Core.Presentation/Menu/MenuCommand.cs

@ -8,6 +8,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
@ -17,6 +18,25 @@ namespace ICSharpCode.Core.Presentation
{ {
class CommandWrapper : System.Windows.Input.ICommand class CommandWrapper : System.Windows.Input.ICommand
{ {
public static System.Windows.Input.ICommand GetCommand(Codon codon, object caller, bool createCommand)
{
string commandName = codon.Properties["command"];
if (!string.IsNullOrEmpty(commandName)) {
PropertyInfo p = typeof(ApplicationCommands).GetProperty(commandName);
if (p == null) {
p = typeof(NavigationCommands).GetProperty(commandName);
}
if (p != null) {
return (System.Windows.Input.ICommand)p.GetValue(null, null);
} else {
MessageService.ShowError("Could not find WPF command '" + commandName + "'.");
// return dummy command
return new CommandWrapper(codon, caller, null);
}
}
return new CommandWrapper(codon, caller, createCommand);
}
bool commandCreated; bool commandCreated;
ICommand addInCommand; ICommand addInCommand;
readonly Codon codon; readonly Codon codon;
@ -101,7 +121,7 @@ namespace ICSharpCode.Core.Presentation
{ {
public MenuCommand(UIElement inputBindingOwner, Codon codon, object caller, bool createCommand) : base(codon, caller) public MenuCommand(UIElement inputBindingOwner, Codon codon, object caller, bool createCommand) : base(codon, caller)
{ {
this.Command = new CommandWrapper(codon, caller, createCommand); this.Command = CommandWrapper.GetCommand(codon, caller, createCommand);
if (!string.IsNullOrEmpty(codon.Properties["shortcut"])) { if (!string.IsNullOrEmpty(codon.Properties["shortcut"])) {
KeyGesture kg = MenuService.ParseShortcut(codon.Properties["shortcut"]); KeyGesture kg = MenuService.ParseShortcut(codon.Properties["shortcut"]);
inputBindingOwner.InputBindings.Add( inputBindingOwner.InputBindings.Add(

2
src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarButton.cs

@ -26,7 +26,7 @@ namespace ICSharpCode.Core.Presentation
this.codon = codon; this.codon = codon;
this.caller = caller; this.caller = caller;
this.Command = new CommandWrapper(codon, caller, createCommand); this.Command = CommandWrapper.GetCommand(codon, caller, createCommand);
if (codon.Properties.Contains("icon")) { if (codon.Properties.Contains("icon")) {
var image = PresentationResourceService.GetImage(StringParser.Parse(codon.Properties["icon"])); var image = PresentationResourceService.GetImage(StringParser.Parse(codon.Properties["icon"]));

Loading…
Cancel
Save