Browse Source

ToolBarSplitButton now supports disabling the button while leaving the dropdown enabled; addin files can now specify a disabledIcon for a ToolBarSplitButton's button.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1568 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Alpert 19 years ago
parent
commit
03c3f60c71
  1. 9
      data/schemas/AddIn.xsd
  2. 62
      src/Main/Core/Project/Src/AddInTree/AddIn/DefaultDoozers/ToolBarItem/Gui/ToolBarSplitButton.cs

9
data/schemas/AddIn.xsd

@ -857,7 +857,14 @@ @@ -857,7 +857,14 @@
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="type" use="optional">
<xs:attribute name="disabledIcon" use="optional" type="xs:string">
<xs:annotation>
<xs:documentation>
Icon for use when the tool bar item is disabled; currently supported only for items of type SplitButton.
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="type" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Separator" />

62
src/Main/Core/Project/Src/AddInTree/AddIn/DefaultDoozers/ToolBarItem/Gui/ToolBarSplitButton.cs

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
// </file>
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
@ -17,19 +18,29 @@ namespace ICSharpCode.Core @@ -17,19 +18,29 @@ namespace ICSharpCode.Core
Codon codon;
ArrayList subItems;
ICommand menuCommand = null;
Image imgButtonEnabled = null;
Image imgButtonDisabled = null;
bool buttonEnabled = true;
bool dropDownEnabled = true;
public ToolBarSplitButton(Codon codon, object caller, ArrayList subItems)
{
this.RightToLeft = RightToLeft.Inherit;
this.caller = caller;
this.codon = codon;
this.subItems = subItems;
this.subItems = subItems;
if (codon.Properties.Contains("label")){
Text = StringParser.Parse(codon.Properties["label"]);
}
if (Image == null && codon.Properties.Contains("icon")) {
Image = ResourceService.GetBitmap(StringParser.Parse(codon.Properties["icon"]));
if (imgButtonEnabled == null && codon.Properties.Contains("icon")) {
imgButtonEnabled = ResourceService.GetBitmap(StringParser.Parse(codon.Properties["icon"]));
}
if (imgButtonDisabled == null && codon.Properties.Contains("disabledIcon")) {
imgButtonDisabled = ResourceService.GetBitmap(StringParser.Parse(codon.Properties["disabledIcon"]));
}
if (imgButtonDisabled == null) {
imgButtonDisabled = imgButtonEnabled;
}
menuCommand = codon.AddIn.CreateObject(codon.Properties["class"]) as ICommand;
menuCommand.Owner = this;
@ -60,6 +71,9 @@ namespace ICSharpCode.Core @@ -60,6 +71,9 @@ namespace ICSharpCode.Core
}
protected override void OnDropDownShow(EventArgs e)
{
if (!dropDownEnabled) {
return;
}
if (codon != null && !this.DropDown.Visible)
{
CreateDropDownItems();
@ -69,11 +83,13 @@ namespace ICSharpCode.Core @@ -69,11 +83,13 @@ namespace ICSharpCode.Core
protected override void OnButtonClick(EventArgs e)
{
if (!buttonEnabled) {
return;
}
base.OnButtonClick(e);
menuCommand.Run();
}
public override bool Enabled {
get {
if (codon == null) {
@ -84,13 +100,39 @@ namespace ICSharpCode.Core @@ -84,13 +100,39 @@ namespace ICSharpCode.Core
bool isEnabled = failedAction != ConditionFailedAction.Disable;
if (menuCommand != null && menuCommand is IMenuCommand) {
isEnabled &= ((IMenuCommand)menuCommand).IsEnabled;
// menuCommand.IsEnabled is checked first so that it's get method can set dropDownEnabled as needed
isEnabled &= (((IMenuCommand)menuCommand).IsEnabled || dropDownEnabled);
}
return isEnabled;
}
}
public bool ButtonEnabled {
get {
return buttonEnabled;
}
set {
buttonEnabled = value;
UpdateButtonImage();
}
}
private void UpdateButtonImage()
{
Image = buttonEnabled ? imgButtonEnabled : imgButtonDisabled;
}
public bool DropDownEnabled {
get {
return dropDownEnabled;
}
set {
dropDownEnabled = value;
}
}
public virtual void UpdateStatus()
{
if (codon != null) {
@ -100,8 +142,12 @@ namespace ICSharpCode.Core @@ -100,8 +142,12 @@ namespace ICSharpCode.Core
base.Visible = isVisible;
}
if (this.Visible && codon.Properties.Contains("icon")) {
Image = ResourceService.GetBitmap(StringParser.Parse(codon.Properties["icon"]));
if (this.Visible) {
if (buttonEnabled && imgButtonEnabled!=null) {
Image = imgButtonEnabled;
} else if (imgButtonDisabled!=null) {
Image = imgButtonDisabled;
}
}
}
}

Loading…
Cancel
Save