Browse Source

Implemented ToolBar CheckBox in Core.Presentation.

Fixed OverflowException when AvalonEditTextEditorAdapter.JumpTo was called with column==int.MaxValue.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4892 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
f112d92a15
  1. 2
      AddIns/ICSharpCode.SharpDevelop.addin
  2. 10
      src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditTextEditorAdapter.cs
  3. 5
      src/Main/Base/Project/Src/Gui/Pads/AbstractConsolePad.cs
  4. 1
      src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj
  5. 8
      src/Main/ICSharpCode.Core.Presentation/Menu/MenuCommand.cs
  6. 2
      src/Main/ICSharpCode.Core.Presentation/Menu/MenuService.cs
  7. 42
      src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarButton.cs
  8. 71
      src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarCheckBox.cs
  9. 3
      src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarService.cs

2
AddIns/ICSharpCode.SharpDevelop.addin

@ -2179,7 +2179,7 @@
type = "CheckBox" type = "CheckBox"
icon = "OutputPad.Toolbar.ToggleWordWrap" icon = "OutputPad.Toolbar.ToggleWordWrap"
tooltip = "${res:MainWindow.Windows.CompilerMessageView.ToggleWordWrapButton.ToolTip}" tooltip = "${res:MainWindow.Windows.CompilerMessageView.ToggleWordWrapButton.ToolTip}"
class = "ICSharpCode.SharpDevelop.Gui.ToggleConsoleWordWrapComman"/> class = "ICSharpCode.SharpDevelop.Gui.ToggleConsoleWordWrapCommand"/>
</Path> </Path>
<Path name="/SharpDevelop/Services/ParserService/SingleFileGacReferences"> <Path name="/SharpDevelop/Services/ParserService/SingleFileGacReferences">

10
src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditTextEditorAdapter.cs

@ -5,15 +5,15 @@
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using ICSharpCode.AvalonEdit.Document;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Threading;
using ICSharpCode.AvalonEdit.Editing; using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
using System.Windows.Threading;
namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit
{ {
@ -195,13 +195,15 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit
{ {
textEditor.TextArea.Selection = Selection.Empty; textEditor.TextArea.Selection = Selection.Empty;
textEditor.TextArea.Caret.Position = new TextViewPosition(line, column); textEditor.TextArea.Caret.Position = new TextViewPosition(line, column);
// might have jumped to a different location if column was outside the valid range
TextLocation actualLocation = textEditor.TextArea.Caret.Location;
if (textEditor.ActualHeight > 0) { if (textEditor.ActualHeight > 0) {
textEditor.ScrollTo(line, column); textEditor.ScrollTo(actualLocation.Line, actualLocation.Column);
} else { } else {
// we have to delay the scrolling if the text editor is not yet loaded // we have to delay the scrolling if the text editor is not yet loaded
textEditor.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action( textEditor.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(
delegate { delegate {
textEditor.ScrollTo(line, column); textEditor.ScrollTo(actualLocation.Line, actualLocation.Column);
})); }));
} }
} }

5
src/Main/Base/Project/Src/Gui/Pads/AbstractConsolePad.cs

@ -38,11 +38,12 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
this.panel = new DockPanel(); this.panel = new DockPanel();
this.console = new ConsoleControl();
// creating the toolbar accesses the WordWrap property, so we must do this after creating the console
this.toolbar = ToolBarService.CreateToolBar(this, toolBarTreePath); this.toolbar = ToolBarService.CreateToolBar(this, toolBarTreePath);
this.toolbar.SetValue(DockPanel.DockProperty, Dock.Top); this.toolbar.SetValue(DockPanel.DockProperty, Dock.Top);
this.console = new ConsoleControl();
this.panel.Children.Add(toolbar); this.panel.Children.Add(toolbar);
this.panel.Children.Add(console); this.panel.Children.Add(console);

1
src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj

@ -86,6 +86,7 @@
<Compile Include="SplitButton.cs" /> <Compile Include="SplitButton.cs" />
<Compile Include="StringParseExtension.cs" /> <Compile Include="StringParseExtension.cs" />
<Compile Include="ToolBar\ToolBarButton.cs" /> <Compile Include="ToolBar\ToolBarButton.cs" />
<Compile Include="ToolBar\ToolBarCheckBox.cs" />
<Compile Include="ToolBar\ToolBarComboBox.cs" /> <Compile Include="ToolBar\ToolBarComboBox.cs" />
<Compile Include="ToolBar\ToolBarDropDownButton.cs" /> <Compile Include="ToolBar\ToolBarDropDownButton.cs" />
<Compile Include="ToolBar\ToolBarService.cs" /> <Compile Include="ToolBar\ToolBarService.cs" />

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

@ -57,6 +57,14 @@ namespace ICSharpCode.Core.Presentation
commandCreated = true; commandCreated = true;
} }
public ICommand GetAddInCommand()
{
if (!commandCreated) {
CreateCommand();
}
return addInCommand;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification="We're displaying the message to the user.")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification="We're displaying the message to the user.")]
void CreateCommand() void CreateCommand()
{ {

2
src/Main/ICSharpCode.Core.Presentation/Menu/MenuService.cs

@ -219,7 +219,7 @@ namespace ICSharpCode.Core.Presentation
} }
/// <summary> /// <summary>
/// Converts from the Windows-Forms style label format (accessor key marked with '&') /// Converts from the Windows-Forms style label format (accessor key marked with '&amp;')
/// to a WPF label format (accessor key marked with '_'). /// to a WPF label format (accessor key marked with '_').
/// </summary> /// </summary>
public static string ConvertLabel(string label) public static string ConvertLabel(string label)

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

@ -56,46 +56,4 @@ namespace ICSharpCode.Core.Presentation
this.Visibility = Visibility.Visible; this.Visibility = Visibility.Visible;
} }
} }
sealed class ToolBarCheckBox : CheckBox, IStatusUpdate
{
readonly Codon codon;
readonly object caller;
public ToolBarCheckBox(Codon codon, object caller, bool createCommand)
{
ToolTipService.SetShowOnDisabled(this, true);
this.codon = codon;
this.caller = caller;
this.Command = CommandWrapper.GetCommand(codon, caller, createCommand);
if (codon.Properties.Contains("icon")) {
var image = PresentationResourceService.GetImage(StringParser.Parse(codon.Properties["icon"]));
image.Height = 16;
image.SetResourceReference(StyleProperty, ToolBarService.ImageStyleKey);
this.Content = new PixelSnapper(image);
} else {
this.Content = codon.Id;
}
UpdateText();
SetResourceReference(FrameworkElement.StyleProperty, ToolBar.ButtonStyleKey);
}
public void UpdateText()
{
if (codon.Properties.Contains("tooltip")) {
this.ToolTip = StringParser.Parse(codon.Properties["tooltip"]);
}
}
public void UpdateStatus()
{
if (codon.GetFailedAction(caller) == ConditionFailedAction.Exclude)
this.Visibility = Visibility.Collapsed;
else
this.Visibility = Visibility.Visible;
}
}
} }

71
src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarCheckBox.cs

@ -0,0 +1,71 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
namespace ICSharpCode.Core.Presentation
{
sealed class ToolBarCheckBox : CheckBox, IStatusUpdate
{
readonly Codon codon;
readonly object caller;
BindingExpressionBase isCheckedBinding;
public ToolBarCheckBox(Codon codon, object caller)
{
ToolTipService.SetShowOnDisabled(this, true);
this.codon = codon;
this.caller = caller;
this.Command = CommandWrapper.GetCommand(codon, caller, true);
CommandWrapper wrapper = this.Command as CommandWrapper;
if (wrapper != null) {
ICheckableMenuCommand cmd = wrapper.GetAddInCommand() as ICheckableMenuCommand;
if (cmd != null) {
isCheckedBinding = SetBinding(IsCheckedProperty, new Binding("IsChecked") { Source = cmd, Mode = BindingMode.OneWay });
}
}
if (codon.Properties.Contains("icon")) {
var image = PresentationResourceService.GetImage(StringParser.Parse(codon.Properties["icon"]));
image.Height = 16;
image.SetResourceReference(StyleProperty, ToolBarService.ImageStyleKey);
this.Content = new PixelSnapper(image);
} else {
this.Content = codon.Id;
}
UpdateText();
SetResourceReference(FrameworkElement.StyleProperty, ToolBar.CheckBoxStyleKey);
}
public void UpdateText()
{
if (codon.Properties.Contains("tooltip")) {
this.ToolTip = StringParser.Parse(codon.Properties["tooltip"]);
}
}
public void UpdateStatus()
{
if (codon.GetFailedAction(caller) == ConditionFailedAction.Exclude)
this.Visibility = Visibility.Collapsed;
else
this.Visibility = Visibility.Visible;
}
protected override void OnClick()
{
base.OnClick();
isCheckedBinding.UpdateTarget();
}
}
}

3
src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarService.cs

@ -60,8 +60,7 @@ namespace ICSharpCode.Core.Presentation
case "Separator": case "Separator":
return new ConditionalSeparator(codon, caller, true); return new ConditionalSeparator(codon, caller, true);
case "CheckBox": case "CheckBox":
return "CheckBox"; return new ToolBarCheckBox(codon, caller);
//return new ToolBarCheckBox(codon, caller);
case "Item": case "Item":
return new ToolBarButton(codon, caller, createCommand); return new ToolBarButton(codon, caller, createCommand);
case "ComboBox": case "ComboBox":

Loading…
Cancel
Save