Browse Source

SD2-581 - Unable to remove controls from toolbox using context menu. Toolbox context menu items remove, rename, move up, move down and delete are now working for forms designer specific tabs.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1221 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 20 years ago
parent
commit
55777f300b
  1. 54
      AddIns/ICSharpCode.SharpDevelop.addin
  2. 3
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/AddComponentsDialog.cs
  3. 70
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ComponentLibraryLoader.cs
  4. 9
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/SideTabItemDesigner.cs
  5. 37
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/ToolboxProvider.cs
  6. 20
      src/Main/Base/Project/Src/Commands/SideBarCommands.cs
  7. 141
      src/Main/Base/Project/Src/Gui/Components/SideBar/AxSideTab.cs
  8. 20
      src/Main/Base/Project/Src/Gui/Components/SideBar/AxSideTabItem.cs
  9. 61
      src/Main/Base/Project/Src/Gui/Components/SideBar/SharpDevelopSideBar.cs

54
AddIns/ICSharpCode.SharpDevelop.addin

@ -1005,15 +1005,17 @@
class = "ICSharpCode.SharpDevelop.Commands.SideBarDeleteTabHeader"/> class = "ICSharpCode.SharpDevelop.Commands.SideBarDeleteTabHeader"/>
</Condition> </Condition>
<MenuItem id = "RenameTab" <Condition name = "Ownerstate" ownerstate="CanBeRenamed" action="Disable">
label = "${res:SideBarComponent.ContextMenu.RenameTab}" <MenuItem id = "RenameTab"
class = "ICSharpCode.SharpDevelop.Commands.SideBarRenameTabHeader"/> label = "${res:SideBarComponent.ContextMenu.RenameTab}"
class = "ICSharpCode.SharpDevelop.Commands.SideBarRenameTabHeader"/>
</Condition>
<MenuItem id = "Separator1" type = "Separator" /> <MenuItem id = "Separator1" type = "Separator" />
<MenuItem id = "AddTab" <MenuItem id = "AddTab"
label = "${res:SideBarComponent.ContextMenu.AddTab}" label = "${res:SideBarComponent.ContextMenu.AddTab}"
class = "ICSharpCode.SharpDevelop.Commands.SideBarAddTabHeader"/> class = "ICSharpCode.SharpDevelop.Commands.SideBarAddTabHeader"/>
<MenuItem id = "Separator2" type = "Separator" /> <MenuItem id = "Separator2" type = "Separator" />
<Condition name = "Ownerstate" ownerstate="CanMoveUp" action="Disable"> <Condition name = "Ownerstate" ownerstate="CanMoveUp" action="Disable">
<MenuItem id = "MoveTabUp" <MenuItem id = "MoveTabUp"
@ -1031,25 +1033,29 @@
</Path> </Path>
<Path name = "/SharpDevelop/Workbench/SharpDevelopSideBar/SideTab/ContextMenu"> <Path name = "/SharpDevelop/Workbench/SharpDevelopSideBar/SideTab/ContextMenu">
<MenuItem id = "RenameTabItem" <Condition name = "Ownerstate" ownerstate="TabCanBeDeleted" action="Disable">
label = "${res:SideBarComponent.ContextMenu.RenameTabItem}" <MenuItem id = "DeleteTabItem"
class = "ICSharpCode.SharpDevelop.Commands.SideBarRenameTabItem" /> label = "${res:SideBarComponent.ContextMenu.DeleteTabItem}"
<MenuItem id = "DeleteTabItem" class = "ICSharpCode.SharpDevelop.Commands.SideBarDeleteTabItem"/>
label = "${res:SideBarComponent.ContextMenu.DeleteTabItem}" </Condition>
class = "ICSharpCode.SharpDevelop.Commands.SideBarDeleteTabItem"/>
<Condition name = "Ownerstate" ownerstate="TabCanBeDeleted"> <Condition name = "Ownerstate" ownerstate="CanBeRenamed" action="Disable">
<MenuItem id = "Separator1" type = "Separator" /> <MenuItem id = "RenameTabItem"
<Condition name = "Ownerstate" ownerstate="CanMoveItemUp" action="Disable"> label = "${res:SideBarComponent.ContextMenu.RenameTabItem}"
<MenuItem id = "MoveItemUp" class = "ICSharpCode.SharpDevelop.Commands.SideBarRenameTabItem" />
label = "${res:SideBarComponent.ContextMenu.MoveTabItemUp}" </Condition>
class = "ICSharpCode.SharpDevelop.Commands.SideBarMoveActiveItemUp"/>
</Condition> <MenuItem id = "Separator1" type = "Separator" />
<Condition name = "Ownerstate" ownerstate="CanMoveItemUp" action="Disable">
<Condition name = "Ownerstate" ownerstate="CanMoveItemDown" action="Disable"> <MenuItem id = "MoveItemUp"
<MenuItem id = "MoveItemDown" label = "${res:SideBarComponent.ContextMenu.MoveTabItemUp}"
label = "${res:SideBarComponent.ContextMenu.MoveTabItemDown}" class = "ICSharpCode.SharpDevelop.Commands.SideBarMoveActiveItemUp"/>
class = "ICSharpCode.SharpDevelop.Commands.SideBarMoveActiveItemDown"/> </Condition>
</Condition>
<Condition name = "Ownerstate" ownerstate="CanMoveItemDown" action="Disable">
<MenuItem id = "MoveItemDown"
label = "${res:SideBarComponent.ContextMenu.MoveTabItemDown}"
class = "ICSharpCode.SharpDevelop.Commands.SideBarMoveActiveItemDown"/>
</Condition> </Condition>
<Include id="CommonContextMenu" path="/SharpDevelop/Workbench/SharpDevelopSideBar/CommonContextMenu"/> <Include id="CommonContextMenu" path="/SharpDevelop/Workbench/SharpDevelopSideBar/CommonContextMenu"/>

3
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/AddComponentsDialog.cs

@ -132,8 +132,7 @@ namespace ICSharpCode.FormsDesigner.Gui
newItem.ImageIndex = (int)images[t.FullName + ".bmp"]; newItem.ImageIndex = (int)images[t.FullName + ".bmp"];
} }
newItem.Checked = true; newItem.Checked = true;
ToolComponent toolComponent = new ToolComponent(t.FullName, new ComponentAssembly(assembly.FullName, loadPath)); ToolComponent toolComponent = new ToolComponent(t.FullName, new ComponentAssembly(assembly.FullName, loadPath), true);
toolComponent.IsEnabled = true;
newItem.Tag = toolComponent; newItem.Tag = toolComponent;
componentListView.Items.Add(newItem); componentListView.Items.Add(newItem);
ToolboxItem item = new ToolboxItem(t); ToolboxItem item = new ToolboxItem(t);

70
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ComponentLibraryLoader.cs

@ -87,11 +87,12 @@ namespace ICSharpCode.FormsDesigner.Gui
protected ToolComponent() protected ToolComponent()
{ {
} }
public ToolComponent(string fullName, ComponentAssembly assembly) public ToolComponent(string fullName, ComponentAssembly assembly, bool enabled)
{ {
this.fullName = fullName; this.fullName = fullName;
this.assemblyName = assembly.Name; this.assemblyName = assembly.Name;
this.hintPath = assembly.HintPath; this.hintPath = assembly.HintPath;
this.isEnabled = enabled;
} }
public string FileName { public string FileName {
get { get {
@ -239,6 +240,57 @@ namespace ICSharpCode.FormsDesigner.Gui
return newCategories; return newCategories;
} }
public void RemoveCategory(string name)
{
foreach (Category category in categories) {
if (category.Name == name) {
categories.Remove(category);
break;
}
}
}
public void DisableToolComponent(string categoryName, string fullName)
{
foreach (Category category in categories) {
if (category.Name == categoryName) {
foreach (ToolComponent component in category.ToolComponents) {
if (component.FullName == fullName) {
component.IsEnabled = false;
return;
}
}
}
}
}
/// <summary>
/// Swaps the order of the two specified tool components
/// </summary>
public void ExchangeToolComponents(string categoryName, string fullName1, string fullName2)
{
foreach (Category category in categories) {
if (category.Name == categoryName) {
int index1 = -1;
int index2 = -1;
for (int i = 0; i < category.ToolComponents.Count; ++i) {
ToolComponent component = (ToolComponent)category.ToolComponents[i];
if (component.FullName == fullName1) {
index1 = i;
} else if (component.FullName == fullName2) {
index2 = i;
}
if (index1 != -1 && index2 != -1) {
ToolComponent component1 = (ToolComponent)category.ToolComponents[index1];
category.ToolComponents[index1] = category.ToolComponents[index2];
category.ToolComponents[index2] = component1;
return;
}
}
}
}
}
public bool LoadToolComponentLibrary(string fileName) public bool LoadToolComponentLibrary(string fileName)
{ {
@ -273,7 +325,8 @@ namespace ICSharpCode.FormsDesigner.Gui
Category newCategory = new Category(name); Category newCategory = new Category(name);
foreach (XmlNode componentNode in node.ChildNodes) { foreach (XmlNode componentNode in node.ChildNodes) {
ToolComponent newToolComponent = new ToolComponent(componentNode.Attributes["class"].InnerText, ToolComponent newToolComponent = new ToolComponent(componentNode.Attributes["class"].InnerText,
(ComponentAssembly)assemblies[Int32.Parse(componentNode.Attributes["assembly"].InnerText)]); (ComponentAssembly)assemblies[Int32.Parse(componentNode.Attributes["assembly"].InnerText)],
IsEnabled(componentNode.Attributes["enabled"]));
newCategory.ToolComponents.Add(newToolComponent); newCategory.ToolComponents.Add(newToolComponent);
} }
categories.Add(newCategory); categories.Add(newCategory);
@ -381,5 +434,16 @@ namespace ICSharpCode.FormsDesigner.Gui
} }
doc.Save(fileName); doc.Save(fileName);
} }
bool IsEnabled(XmlAttribute attribute)
{
if (attribute != null && attribute.InnerText != null) {
bool enabled = true;
if (Boolean.TryParse(attribute.InnerText, out enabled)) {
return enabled;
}
}
return true;
}
} }
} }

9
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/SideTabItemDesigner.cs

@ -38,6 +38,7 @@ namespace ICSharpCode.FormsDesigner.Gui
///<summary>create a tabitem from a toolboxitem. It init Icon and name from the tag</summary> ///<summary>create a tabitem from a toolboxitem. It init Icon and name from the tag</summary>
public SideTabItemDesigner(ToolboxItem tag) : base(tag.DisplayName, tag) public SideTabItemDesigner(ToolboxItem tag) : base(tag.DisplayName, tag)
{ {
CanBeRenamed = false;
this.Icon = tag.Bitmap; this.Icon = tag.Bitmap;
ReloadToolBox(); ReloadToolBox();
} }
@ -45,6 +46,7 @@ namespace ICSharpCode.FormsDesigner.Gui
///<summary>create a tabitem from a toolboxitem. It init Icon from the tag</summary> ///<summary>create a tabitem from a toolboxitem. It init Icon from the tag</summary>
public SideTabItemDesigner(string name, ToolboxItem tag) : base(name, tag) public SideTabItemDesigner(string name, ToolboxItem tag) : base(name, tag)
{ {
CanBeRenamed = false;
this.Icon = tag.Bitmap; this.Icon = tag.Bitmap;
ReloadToolBox(); ReloadToolBox();
} }
@ -52,15 +54,14 @@ namespace ICSharpCode.FormsDesigner.Gui
///<summary>create a default tabitem : a pointer icon with an empty toolboxitem</summary> ///<summary>create a default tabitem : a pointer icon with an empty toolboxitem</summary>
public SideTabItemDesigner() : base("Pointer") public SideTabItemDesigner() : base("Pointer")
{ {
CanBeRenamed = false;
CanBeDeleted = false;
Bitmap pointerBitmap = new Bitmap(IconService.GetBitmap("Icons.16x16.FormsDesigner.PointerIcon"), 16, 16); Bitmap pointerBitmap = new Bitmap(IconService.GetBitmap("Icons.16x16.FormsDesigner.PointerIcon"), 16, 16);
// ToolboxItem toolboxItemPointer = new ToolboxItem(); // ToolboxItem toolboxItemPointer = new ToolboxItem();
// toolboxItemPointer.Bitmap = pointerBitmap; // toolboxItemPointer.Bitmap = pointerBitmap;
// toolboxItemPointer.DisplayName = "Pointer"; // toolboxItemPointer.DisplayName = "Pointer";
this.Icon = pointerBitmap; this.Icon = pointerBitmap;
this.Tag = null; //toolboxItemPointer; this.Tag = null;
ReloadToolBox(); ReloadToolBox();
} }

37
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/ToolboxProvider.cs

@ -55,6 +55,7 @@ namespace ICSharpCode.FormsDesigner
toolboxService = new ICSharpCode.FormsDesigner.Services.ToolboxService(); toolboxService = new ICSharpCode.FormsDesigner.Services.ToolboxService();
ReloadSideTabs(false); ReloadSideTabs(false);
toolboxService.SelectedItemUsed += new EventHandler(SelectedToolUsedHandler); toolboxService.SelectedItemUsed += new EventHandler(SelectedToolUsedHandler);
SharpDevelopSideBar.SideBar.SideTabDeleted += SideTabDeleted;
} }
return toolboxService; return toolboxService;
} }
@ -101,6 +102,8 @@ namespace ICSharpCode.FormsDesigner
{ {
bool reInsertTabs = false; bool reInsertTabs = false;
foreach(AxSideTab tab in SideTabs) { foreach(AxSideTab tab in SideTabs) {
tab.ItemRemoved -= SideTabItemRemoved;
tab.ItemsExchanged -= SideTabItemsExchanged;
if (SharpDevelopSideBar.SideBar.Tabs.Contains(tab)) { if (SharpDevelopSideBar.SideBar.Tabs.Contains(tab)) {
SharpDevelopSideBar.SideBar.Tabs.Remove(tab); SharpDevelopSideBar.SideBar.Tabs.Remove(tab);
reInsertTabs = true;; reInsertTabs = true;;
@ -113,6 +116,8 @@ namespace ICSharpCode.FormsDesigner
if (category.IsEnabled) { if (category.IsEnabled) {
try { try {
SideTabDesigner newTab = new SideTabDesigner(SharpDevelopSideBar.SideBar, category, toolboxService); SideTabDesigner newTab = new SideTabDesigner(SharpDevelopSideBar.SideBar, category, toolboxService);
newTab.ItemRemoved += SideTabItemRemoved;
newTab.ItemsExchanged += SideTabItemsExchanged;
SideTabs.Add(newTab); SideTabs.Add(newTab);
} catch (Exception e) { } catch (Exception e) {
ICSharpCode.Core.LoggingService.Warn("Can't add tab : " + e); ICSharpCode.Core.LoggingService.Warn("Can't add tab : " + e);
@ -120,6 +125,8 @@ namespace ICSharpCode.FormsDesigner
} }
} }
SideTabDesigner customTab = new CustomComponentsSideTab(SharpDevelopSideBar.SideBar, "Custom Components", toolboxService); SideTabDesigner customTab = new CustomComponentsSideTab(SharpDevelopSideBar.SideBar, "Custom Components", toolboxService);
customTab.ItemRemoved += SideTabItemRemoved;
customTab.ItemsExchanged += SideTabItemsExchanged;
SideTabs.Add(customTab); SideTabs.Add(customTab);
if (reInsertTabs) { if (reInsertTabs) {
foreach(AxSideTab tab in SideTabs) { foreach(AxSideTab tab in SideTabs) {
@ -247,5 +254,35 @@ namespace ICSharpCode.FormsDesigner
ProjectService.AddProjectItem(project, reference); ProjectService.AddProjectItem(project, reference);
project.Save(); project.Save();
} }
static void SideTabDeleted(object source, SideTabEventArgs e)
{
if (SideTabs.Contains(e.SideTab)) {
SideTabs.Remove(e.SideTab);
componentLibraryLoader.RemoveCategory(e.SideTab.Name);
SaveToolbox();
}
}
static void SideTabItemRemoved(object source, SideTabItemEventArgs e)
{
SideTabDesigner tab = source as SideTabDesigner;
ToolboxItem toolboxItem = e.Item.Tag as ToolboxItem;
if (tab != null && toolboxItem != null) {
componentLibraryLoader.DisableToolComponent(tab.Name, toolboxItem.TypeName);
SaveToolbox();
}
}
static void SideTabItemsExchanged(object source, SideTabItemExchangeEventArgs e)
{
SideTabDesigner tab = source as SideTabDesigner;
ToolboxItem toolboxItem1 = e.Item1.Tag as ToolboxItem;
ToolboxItem toolboxItem2 = e.Item2.Tag as ToolboxItem;
if (tab != null && toolboxItem1 != null && toolboxItem2 != null) {
componentLibraryLoader.ExchangeToolComponents(tab.Name, toolboxItem1.TypeName, toolboxItem2.TypeName);
SaveToolbox();
}
}
} }
} }

20
src/Main/Base/Project/Src/Commands/SideBarCommands.cs

@ -35,9 +35,6 @@ namespace ICSharpCode.SharpDevelop.Commands
{ {
SharpDevelopSideBar sideBar = (SharpDevelopSideBar)Owner; SharpDevelopSideBar sideBar = (SharpDevelopSideBar)Owner;
AxSideTabItem item = sideBar.ActiveTab.ChoosedItem; AxSideTabItem item = sideBar.ActiveTab.ChoosedItem;
if (item != null && MessageBox.Show(StringParser.Parse(ResourceService.GetString("SideBarComponent.ContextMenu.DeleteTabItemQuestion"), new string[,] { {"TabItem", item.Name}}), if (item != null && MessageBox.Show(StringParser.Parse(ResourceService.GetString("SideBarComponent.ContextMenu.DeleteTabItemQuestion"), new string[,] { {"TabItem", item.Name}}),
ResourceService.GetString("Global.QuestionText"), ResourceService.GetString("Global.QuestionText"),
MessageBoxButtons.YesNo, MessageBoxButtons.YesNo,
@ -128,15 +125,12 @@ namespace ICSharpCode.SharpDevelop.Commands
{ {
SharpDevelopSideBar sideBar = (SharpDevelopSideBar)Owner; SharpDevelopSideBar sideBar = (SharpDevelopSideBar)Owner;
AxSideTab selectedSideTab = sideBar.GetTabAt(sideBar.SideBarMousePosition.X, sideBar.SideBarMousePosition.Y); AxSideTab selectedSideTab = sideBar.GetTabAt(sideBar.SideBarMousePosition.X, sideBar.SideBarMousePosition.Y);
if (MessageBox.Show(StringParser.Parse(ResourceService.GetString("SideBarComponent.ContextMenu.DeleteTabHeaderQuestion"), new string[,] { {"TabHeader", selectedSideTab.Name}}), if (MessageBox.Show(StringParser.Parse(ResourceService.GetString("SideBarComponent.ContextMenu.DeleteTabHeaderQuestion"), new string[,] { {"TabHeader", selectedSideTab.Name}}),
ResourceService.GetString("Global.QuestionText"), ResourceService.GetString("Global.QuestionText"),
MessageBoxButtons.YesNo, MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2) == DialogResult.Yes) { MessageBoxDefaultButton.Button2) == DialogResult.Yes) {
sideBar.Tabs.Remove(selectedSideTab); sideBar.DeleteSideTab(selectedSideTab);
sideBar.Refresh(); sideBar.Refresh();
} }
} }
@ -156,11 +150,9 @@ namespace ICSharpCode.SharpDevelop.Commands
public override void Run() public override void Run()
{ {
SharpDevelopSideBar sideBar = (SharpDevelopSideBar)Owner; SharpDevelopSideBar sideBar = (SharpDevelopSideBar)Owner;
int index = sideBar.ActiveTab.Items.IndexOf(sideBar.ActiveTab.SelectedItem); int index = sideBar.ActiveTab.Items.IndexOf(sideBar.ActiveTab.ChoosedItem);
if (index > 0) { if (index > 0) {
AxSideTabItem item = sideBar.ActiveTab.Items[index]; sideBar.ActiveTab.Exchange(index -1, index);
sideBar.ActiveTab.Items[index] = sideBar.ActiveTab.Items[index - 1];
sideBar.ActiveTab.Items[index - 1] = item;
sideBar.Refresh(); sideBar.Refresh();
} }
} }
@ -171,11 +163,9 @@ namespace ICSharpCode.SharpDevelop.Commands
public override void Run() public override void Run()
{ {
SharpDevelopSideBar sideBar = (SharpDevelopSideBar)Owner; SharpDevelopSideBar sideBar = (SharpDevelopSideBar)Owner;
int index = sideBar.ActiveTab.Items.IndexOf(sideBar.ActiveTab.SelectedItem); int index = sideBar.ActiveTab.Items.IndexOf(sideBar.ActiveTab.ChoosedItem);
if (index >= 0 && index < sideBar.ActiveTab.Items.Count - 1) { if (index >= 0 && index < sideBar.ActiveTab.Items.Count - 1) {
AxSideTabItem item = sideBar.ActiveTab.Items[index]; sideBar.ActiveTab.Exchange(index, index + 1);
sideBar.ActiveTab.Items[index] = sideBar.ActiveTab.Items[index + 1];
sideBar.ActiveTab.Items[index + 1] = item;
sideBar.Refresh(); sideBar.Refresh();
} }
} }

141
src/Main/Base/Project/Src/Gui/Components/SideBar/AxSideTab.cs

@ -20,11 +20,74 @@ namespace ICSharpCode.SharpDevelop.Gui
Dragged Dragged
} }
public delegate void SideTabEventHandler(object source, SideTabEventArgs e);
public class SideTabEventArgs
{
AxSideTab tab;
public SideTabEventArgs(AxSideTab tab)
{
this.tab = tab;
}
public AxSideTab SideTab {
get {
return tab;
}
}
}
public delegate void SideTabItemEventHandler(object source, SideTabItemEventArgs e);
public class SideTabItemEventArgs
{
AxSideTabItem item;
public SideTabItemEventArgs(AxSideTabItem item)
{
this.item = item;
}
public AxSideTabItem Item {
get {
return item;
}
}
}
public delegate void SideTabItemExchangeEventHandler(object source, SideTabItemExchangeEventArgs e);
public class SideTabItemExchangeEventArgs
{
AxSideTabItem item1;
AxSideTabItem item2;
public SideTabItemExchangeEventArgs(AxSideTabItem item1, AxSideTabItem item2)
{
this.item1 = item1;
this.item2 = item2;
}
public AxSideTabItem Item1 {
get {
return item1;
}
}
public AxSideTabItem Item2 {
get {
return item2;
}
}
}
public class AxSideTab public class AxSideTab
{ {
string name; string name;
bool canDragDrop = true; bool canDragDrop = true;
bool canBeDeleted = true; bool canBeDeleted = true;
bool canBeRenamed = true;
bool isClipboardRing = false; bool isClipboardRing = false;
SideTabItemCollection items = new SideTabItemCollection(); SideTabItemCollection items = new SideTabItemCollection();
SideTabStatus sideTabStatus; SideTabStatus sideTabStatus;
@ -83,7 +146,7 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
public bool CanBeDeleted { public bool CanBeDeleted {
get { get {
return canBeDeleted; return canBeDeleted;
} }
@ -92,6 +155,15 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
public bool CanBeRenamed {
get {
return canBeRenamed;
}
set {
canBeRenamed = value;
}
}
public string Name { public string Name {
get { get {
return name; return name;
@ -166,6 +238,16 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
/// <summary>
/// A SideTabItem has been removed.
/// </summary>
public event SideTabItemEventHandler ItemRemoved;
/// <summary>
/// Two SideTabItems have exchanged locations.
/// </summary>
public event SideTabItemExchangeEventHandler ItemsExchanged;
public ISideTabItemFactory SideTabItemFactory { public ISideTabItemFactory SideTabItemFactory {
get { get {
return items.SideTabItemFactory; return items.SideTabItemFactory;
@ -187,14 +269,17 @@ namespace ICSharpCode.SharpDevelop.Gui
public AxSideTab(AxSideBar sideBar, string name) : this(sideBar.SideTabItemFactory) public AxSideTab(AxSideBar sideBar, string name) : this(sideBar.SideTabItemFactory)
{ {
this.name = name; this.name = name;
SetCanRename();
items.ItemRemoved += OnSideTabItemRemoved;
} }
public AxSideTab(string name) public AxSideTab(string name)
{ {
this.name = name; this.name = name;
SetCanRename();
items.ItemRemoved += OnSideTabItemRemoved;
} }
public bool ScrollDownButtonActivated { public bool ScrollDownButtonActivated {
get { get {
return scrollIndex > 0; return scrollIndex > 0;
@ -261,11 +346,13 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
return GetItemAt(pos.X, pos.Y); return GetItemAt(pos.X, pos.Y);
} }
public int ItemHeight { public int ItemHeight {
get { get {
return 20; return 20;
} }
} }
public void DrawTabContent(Graphics g, Font f, Rectangle rectangle) public void DrawTabContent(Graphics g, Font f, Rectangle rectangle)
{ {
for (int i = 0; i + ScrollIndex < Items.Count; ++i) { for (int i = 0; i + ScrollIndex < Items.Count; ++i) {
@ -280,11 +367,46 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
/// <summary>
/// Swaps two side tab items with the given indexes.
/// </summary>
public void Exchange(int a, int b)
{
AxSideTabItem itemA = Items[a];
AxSideTabItem itemB = Items[b];
Items[a] = itemB;
Items[b] = itemA;
OnExchange(itemA, itemB);
}
void SetCanRename()
{
if (name != null && name.StartsWith("${res:")) {
canBeRenamed = false;
}
}
void OnSideTabItemRemoved(object source, SideTabItemEventArgs e)
{
if (ItemRemoved != null) {
ItemRemoved(this, e);
}
}
void OnExchange(AxSideTabItem item1, AxSideTabItem item2)
{
if (ItemsExchanged != null) {
ItemsExchanged(this, new SideTabItemExchangeEventArgs(item1, item2));
}
}
public class SideTabItemCollection : ICollection, IEnumerable public class SideTabItemCollection : ICollection, IEnumerable
{ {
ArrayList list = new ArrayList(); ArrayList list = new ArrayList();
ISideTabItemFactory sideTabItemFactory = new DefaultSideTabItemFactory(); ISideTabItemFactory sideTabItemFactory = new DefaultSideTabItemFactory();
public event SideTabItemEventHandler ItemRemoved;
public ISideTabItemFactory SideTabItemFactory { public ISideTabItemFactory SideTabItemFactory {
get { get {
return sideTabItemFactory; return sideTabItemFactory;
@ -399,11 +521,24 @@ namespace ICSharpCode.SharpDevelop.Gui
public virtual void Remove(AxSideTabItem item) public virtual void Remove(AxSideTabItem item)
{ {
list.Remove(item); list.Remove(item);
OnItemRemoved(item);
} }
public virtual void RemoveAt(int index) public virtual void RemoveAt(int index)
{ {
list.RemoveAt(index); if (index < 0 || index >= list.Count) {
return;
}
AxSideTabItem item = this[index];
list.Remove(item);
OnItemRemoved(item);
}
void OnItemRemoved(AxSideTabItem item)
{
if (ItemRemoved != null) {
ItemRemoved(this, new SideTabItemEventArgs(item));
}
} }
} }
} }

20
src/Main/Base/Project/Src/Gui/Components/SideBar/AxSideTabItem.cs

@ -27,6 +27,8 @@ namespace ICSharpCode.SharpDevelop.Gui
object tag; object tag;
SideTabItemStatus sideTabItemStatus; SideTabItemStatus sideTabItemStatus;
Bitmap icon; Bitmap icon;
bool canBeRenamed = true;
bool canBeDeleted = true;
public Bitmap Icon { public Bitmap Icon {
get { get {
@ -64,6 +66,24 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
public bool CanBeRenamed {
get {
return canBeRenamed;
}
set {
canBeRenamed = value;
}
}
public bool CanBeDeleted {
get {
return canBeDeleted;
}
set {
canBeDeleted = value;
}
}
public AxSideTabItem(string name) public AxSideTabItem(string name)
{ {
int idx = name.IndexOf("\n"); int idx = name.IndexOf("\n");

61
src/Main/Base/Project/Src/Gui/Components/SideBar/SharpDevelopSideBar.cs

@ -34,7 +34,7 @@ namespace ICSharpCode.SharpDevelop.Gui
return new SharpDevelopSideTabItem(name, tag, bitmap); return new SharpDevelopSideTabItem(name, tag, bitmap);
} }
} }
public class SharpDevelopSideBar : AxSideBar, IOwnerState public class SharpDevelopSideBar : AxSideBar, IOwnerState
{ {
readonly static string contextMenuPath = "/SharpDevelop/Workbench/SharpDevelopSideBar/ContextMenu"; readonly static string contextMenuPath = "/SharpDevelop/Workbench/SharpDevelopSideBar/ContextMenu";
@ -62,7 +62,8 @@ namespace ICSharpCode.SharpDevelop.Gui
CanMoveDown = 2, CanMoveDown = 2,
TabCanBeDeleted = 4, TabCanBeDeleted = 4,
CanMoveItemUp = 8, CanMoveItemUp = 8,
CanMoveItemDown = 16 CanMoveItemDown = 16,
CanBeRenamed = 32
} }
protected SidebarState internalState = SidebarState.TabCanBeDeleted; protected SidebarState internalState = SidebarState.TabCanBeDeleted;
@ -172,17 +173,55 @@ namespace ICSharpCode.SharpDevelop.Gui
System.Diagnostics.Debug.Assert(false, "Can't find clipboard ring side tab category"); System.Diagnostics.Debug.Assert(false, "Can't find clipboard ring side tab category");
} }
public void DeleteSideTab(AxSideTab tab)
{
if (tab == null) {
return;
}
Tabs.Remove(tab);
OnSideTabDeleted(tab);
}
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Tab Context Menu // Tab Context Menu
void SetDeletedState(AxSideTab tab) void SetDeletedState(AxSideTabItem item)
{ {
if (tab.CanBeDeleted) { if (item != null) {
SetDeletedState(item.CanBeDeleted);
} else {
SetDeletedState(false);
}
}
void SetDeletedState(bool canBeDeleted)
{
if (canBeDeleted) {
internalState |= SidebarState.TabCanBeDeleted; internalState |= SidebarState.TabCanBeDeleted;
} else { } else {
internalState = internalState & ~SidebarState.TabCanBeDeleted; internalState = internalState & ~SidebarState.TabCanBeDeleted;
} }
} }
void SetRenameState(AxSideTabItem item)
{
if (item != null) {
SetRenameState(item.CanBeRenamed);
} else {
SetRenameState(false);
}
}
void SetRenameState(bool canBeRenamed)
{
if (canBeRenamed) {
internalState |= SidebarState.CanBeRenamed;
} else {
internalState = internalState & ~SidebarState.CanBeRenamed;
}
}
void SetContextMenu(object sender, MouseEventArgs e) void SetContextMenu(object sender, MouseEventArgs e)
{ {
@ -192,7 +231,8 @@ namespace ICSharpCode.SharpDevelop.Gui
if (index >= 0) { if (index >= 0) {
AxSideTab tab = Tabs[index]; AxSideTab tab = Tabs[index];
SetDeletedState(tab); SetDeletedState(tab.CanBeDeleted);
SetRenameState(tab.CanBeRenamed);
if (index > 0) { if (index > 0) {
internalState |= SidebarState.CanMoveUp; internalState |= SidebarState.CanMoveUp;
@ -240,7 +280,8 @@ namespace ICSharpCode.SharpDevelop.Gui
if (e.Button == MouseButtons.Right) { if (e.Button == MouseButtons.Right) {
// set moveup/down states correctly // set moveup/down states correctly
SetDeletedState(ActiveTab); SetDeletedState(ActiveTab.SelectedItem);
SetRenameState(ActiveTab.SelectedItem);
int index = ActiveTab.Items.IndexOf(ActiveTab.SelectedItem); int index = ActiveTab.Items.IndexOf(ActiveTab.SelectedItem);
if (index > 0) { if (index > 0) {
@ -329,5 +370,13 @@ namespace ICSharpCode.SharpDevelop.Gui
return el; return el;
} }
void OnSideTabDeleted(AxSideTab tab)
{
if (SideTabDeleted != null) {
SideTabDeleted(this, new SideTabEventArgs(tab));
}
}
public event SideTabEventHandler SideTabDeleted;
} }
} }

Loading…
Cancel
Save