[Monodevelop-patches-list] r2471 - in trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets: . Commands
Lluis Sanchez <lluis@ximian.com>
lluis at mono-cvs.ximian.com
Mon Apr 25 12:56:54 EDT 2005
Author: lluis
Date: 2005-04-25 12:56:54 -0400 (Mon, 25 Apr 2005)
New Revision: 2471
Added:
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ActionCommand.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ActionType.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/Command.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandArrayInfo.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandCheckMenuItem.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandEntry.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandEntrySet.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandHandler.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandHandlerAttribute.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandInfo.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandManager.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandMenu.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandMenuBar.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandMenuItem.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandToggleToolButton.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandToolButton.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandToolbar.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CustomCommand.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CustomMenuItem.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ICommandMenuItem.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ICommandRouter.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ICommandUserItem.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/LinkCommandEntry.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/MenuToolButton.cs
Modified:
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/ChangeLog
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Makefile.am
Log:
2005-04-25 Lluis Sanchez Gual <lluis at novell.com>
* Command/*: New command infrastructure.
* Makefile.am: Added new command files.
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/ChangeLog
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/ChangeLog 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/ChangeLog 2005-04-25 16:56:54 UTC (rev 2471)
@@ -1,3 +1,8 @@
+2005-04-25 Lluis Sanchez Gual <lluis at novell.com>
+
+ * Command/*: New command infrastructure.
+ * Makefile.am: Added new command files.
+
2005-04-17 John Luke <john.luke at gmail.com>
* Makefile.am: fix distcheck
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ActionCommand.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ActionCommand.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ActionCommand.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,104 @@
+//
+// ActionCommand.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ public class ActionCommand: Command
+ {
+ ActionType type;
+ bool commandArray;
+ Type defaultHandlerType;
+ CommandHandler defaultHandler;
+
+ public ActionCommand ()
+ {
+ }
+
+ public ActionCommand (object id, string text, string icon, string accelKey, ActionType type): base (id, text)
+ {
+ Icon = icon;
+ AccelKey = accelKey;
+ this.type = type;
+ }
+
+ public ActionType ActionType {
+ get { return type; }
+ set { type = value; }
+ }
+
+ public bool CommandArray {
+ get { return commandArray; }
+ set { commandArray = value; }
+ }
+
+ public Type DefaultHandlerType {
+ get { return defaultHandlerType; }
+ set {
+ if (!typeof (CommandHandler).IsAssignableFrom (value))
+ throw new ArgumentException ("Value must be a subclass of CommandHandler");
+
+ defaultHandlerType = value;
+ }
+ }
+
+ public virtual bool DispatchCommand (object dataItem)
+ {
+ if (defaultHandlerType == null)
+ return false;
+
+ if (defaultHandler == null)
+ defaultHandler = (CommandHandler) Activator.CreateInstance (defaultHandlerType);
+
+ defaultHandler.Run (dataItem);
+ return true;
+ }
+
+ public virtual void UpdateCommandInfo (CommandInfo info)
+ {
+ if (defaultHandlerType == null) {
+ info.Enabled = false;
+ if (!DisabledVisible)
+ info.Visible = false;
+ } else {
+ if (defaultHandler == null)
+ defaultHandler = (CommandHandler) Activator.CreateInstance (defaultHandlerType);
+
+ if (commandArray) {
+ info.ArrayInfo = new CommandArrayInfo (info);
+ defaultHandler.Update (info.ArrayInfo);
+ }
+ else
+ defaultHandler.Update (info);
+ }
+ }
+ }
+}
+
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ActionType.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ActionType.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ActionType.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,39 @@
+//
+// ActionType.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ public enum ActionType
+ {
+ Normal,
+ Check,
+ Radio
+ }
+}
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/Command.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/Command.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/Command.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,86 @@
+//
+// Command.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ public class Command
+ {
+ public static readonly object Separator = new Object ();
+
+ object id;
+ string text;
+ string description;
+ string icon;
+ string accelKey;
+ bool disabledVisible;
+ internal string AccelPath;
+
+ public Command ()
+ {
+ }
+
+ public Command (object id, string text)
+ {
+ this.id = id;
+ this.text = text;
+ }
+
+ public object Id {
+ get { return id; }
+ set { id = value; }
+ }
+
+ public string Text {
+ get { return text; }
+ set { text = value; }
+ }
+
+ public string Icon {
+ get { return icon; }
+ set { icon = value; }
+ }
+
+ public string AccelKey {
+ get { return accelKey; }
+ set { accelKey = value; }
+ }
+
+ public bool DisabledVisible {
+ get { return disabledVisible; }
+ set { disabledVisible = value; }
+ }
+
+ public string Description {
+ get { return description; }
+ set { description = value; }
+ }
+ }
+}
+
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandArrayInfo.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandArrayInfo.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandArrayInfo.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,61 @@
+//
+// CommandArrayInfo.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+
+namespace MonoDevelop.Commands
+{
+ public class CommandArrayInfo: IEnumerable
+ {
+ ArrayList list = new ArrayList ();
+ CommandInfo defaultInfo;
+
+ internal CommandArrayInfo (CommandInfo defaultInfo)
+ {
+ this.defaultInfo = defaultInfo;
+ }
+
+ public void Add (CommandInfo info, object dataItem)
+ {
+ info.DataItem = dataItem;
+ if (info.Text == null) info.Text = defaultInfo.Text;
+ if (info.Icon == null) info.Icon = defaultInfo.Icon;
+ list.Add (info);
+ }
+
+ public CommandInfo DefaultCommandInfo {
+ get { return defaultInfo; }
+ }
+
+ public IEnumerator GetEnumerator ()
+ {
+ return list.GetEnumerator ();
+ }
+ }
+}
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandCheckMenuItem.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandCheckMenuItem.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandCheckMenuItem.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,114 @@
+//
+// CommandCheckMenuItem.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ internal class CommandCheckMenuItem: Gtk.CheckMenuItem, ICommandMenuItem
+ {
+ CommandManager commandManager;
+ object commandId;
+ bool updating;
+ bool isArrayItem;
+ object arrayDataItem;
+
+ public CommandCheckMenuItem (object commandId, CommandManager commandManager): base ("")
+ {
+ this.commandId = commandId;
+ this.commandManager = commandManager;
+ ActionCommand cmd = commandManager.GetCommand (commandId) as ActionCommand;
+ if (cmd != null && cmd.ActionType == ActionType.Radio)
+ this.DrawAsRadio = true;
+ }
+
+ void ICommandUserItem.Update ()
+ {
+ if (commandManager != null && !isArrayItem) {
+ CommandInfo cinfo = commandManager.GetCommandInfo (commandId);
+ Update (cinfo);
+ }
+ }
+
+ void ICommandMenuItem.SetUpdateInfo (CommandInfo cmdInfo)
+ {
+ isArrayItem = true;
+ arrayDataItem = cmdInfo.DataItem;
+ Update (cmdInfo);
+ }
+
+ protected override void OnParentSet (Gtk.Widget parent)
+ {
+ base.OnParentSet (parent);
+ if (Parent == null) return;
+
+ ((ICommandUserItem)this).Update ();
+
+ // Make sure the accelerators allways work for this item
+ // while the menu is hidden
+ Sensitive = true;
+ Visible = true;
+ }
+
+ protected override void OnActivated ()
+ {
+ base.OnActivated ();
+
+ if (updating) return;
+
+ if (commandManager == null)
+ throw new InvalidOperationException ();
+
+ commandManager.DispatchCommand (commandId, arrayDataItem);
+ }
+
+ void Update (CommandInfo cmdInfo)
+ {
+ updating = true;
+ Gtk.AccelLabel child = (Gtk.AccelLabel)Child;
+ child.Xalign = 0;
+ if (cmdInfo.UseMarkup) {
+ child.Markup = cmdInfo.Text;
+ child.UseMarkup = true;
+ } else {
+ child.Text = cmdInfo.Text;
+ child.UseMarkup = false;
+ }
+ child.UseUnderline = true;
+ child.AccelWidget = this;
+ Sensitive = cmdInfo.Enabled;
+ child.ShowAll ();
+ Visible = cmdInfo.Visible;
+ Active = cmdInfo.Checked;
+ if (cmdInfo.AccelKey != null && cmdInfo.AccelKey != "")
+ this.AccelPath = commandManager.GetAccelPath (cmdInfo.AccelKey);
+
+ updating = false;
+ }
+ }
+}
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandEntry.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandEntry.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandEntry.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,101 @@
+//
+// CommandEntry.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ public class CommandEntry
+ {
+ object cmdId;
+
+ public CommandEntry (object cmdId)
+ {
+ this.cmdId = cmdId;
+ }
+
+ public object CommandId {
+ get { return cmdId; }
+ set { cmdId = value; }
+ }
+
+ internal protected virtual Gtk.MenuItem CreateMenuItem (CommandManager manager)
+ {
+ return CreateMenuItem (manager, cmdId, true);
+ }
+
+ internal protected virtual Gtk.ToolItem CreateToolItem (CommandManager manager)
+ {
+ if (cmdId == Command.Separator)
+ return new Gtk.SeparatorToolItem ();
+
+ Command cmd = manager.GetCommand (cmdId);
+ if (cmd is CustomCommand) {
+ Gtk.Widget child = (Gtk.Widget) Activator.CreateInstance (((CustomCommand)cmd).WidgetType);
+ Gtk.ToolItem ti = new Gtk.ToolItem ();
+ ti.Child = child;
+ return ti;
+ }
+
+ ActionCommand acmd = cmd as ActionCommand;
+ if (acmd == null)
+ throw new InvalidOperationException ("Unknown cmd type.");
+
+ if (acmd.CommandArray) {
+ CommandMenu menu = new CommandMenu (manager);
+ menu.Append (CreateMenuItem (manager));
+ return new MenuToolButton (menu, acmd.Icon);
+ }
+ else if (acmd.ActionType == ActionType.Normal)
+ return new CommandToolButton (cmdId, manager);
+ else
+ return new CommandToggleToolButton (cmdId, manager);
+ }
+
+ internal static Gtk.MenuItem CreateMenuItem (CommandManager manager, object cmdId, bool isArrayMaster)
+ {
+ if (cmdId == Command.Separator)
+ return new Gtk.SeparatorMenuItem ();
+
+ Command cmd = manager.GetCommand (cmdId);
+ if (cmd is CustomCommand) {
+ Gtk.Widget child = (Gtk.Widget) Activator.CreateInstance (((CustomCommand)cmd).WidgetType);
+ CustomMenuItem ti = new CustomMenuItem ();
+ ti.Child = child;
+ return ti;
+ }
+
+ ActionCommand acmd = cmd as ActionCommand;
+ if (acmd.ActionType == ActionType.Normal || (isArrayMaster && acmd.CommandArray))
+ return new CommandMenuItem (cmdId, manager);
+ else
+ return new CommandCheckMenuItem (cmdId, manager);
+ }
+ }
+}
+
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandEntrySet.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandEntrySet.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandEntrySet.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,124 @@
+//
+// CommandEntrySet.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+
+namespace MonoDevelop.Commands
+{
+ public class CommandEntrySet: CommandEntry, IEnumerable
+ {
+ ArrayList cmds = new ArrayList ();
+ string name;
+ string icon;
+ bool autoHide;
+
+ public CommandEntrySet (): base (null)
+ {
+ }
+
+ public CommandEntrySet (string name, string icon): base (null)
+ {
+ this.name = name;
+ this.icon = icon;
+ }
+
+ public string Name {
+ get { return name; }
+ set { name = value; }
+ }
+
+ public string Icon {
+ get { return icon; }
+ set { icon = value; }
+ }
+
+ // If true, the set will be automatically hidden if all
+ // items it contains are hidden or disabled
+ public bool AutoHide {
+ get { return autoHide; }
+ set { autoHide = value; }
+ }
+
+ public void Add (CommandEntry entry)
+ {
+ cmds.Add (entry);
+ }
+
+ public CommandEntry AddItem (object cmdId)
+ {
+ CommandEntry cmd = new CommandEntry (cmdId);
+ cmds.Add (cmd);
+ return cmd;
+ }
+
+ public CommandEntrySet AddItemSet (string name)
+ {
+ return AddItemSet (name, "");
+ }
+
+ public CommandEntrySet AddItemSet (string name, string icon)
+ {
+ CommandEntrySet cmdset = new CommandEntrySet (name, icon);
+ cmds.Add (cmdset);
+ return cmdset;
+ }
+
+ public IEnumerator GetEnumerator ()
+ {
+ return cmds.GetEnumerator ();
+ }
+
+ internal protected override Gtk.MenuItem CreateMenuItem (CommandManager manager)
+ {
+ Gtk.MenuItem mi = new Gtk.MenuItem (name != null ? name : "");
+ mi.Submenu = manager.CreateMenu (this);
+ return mi;
+ }
+
+ internal protected override Gtk.ToolItem CreateToolItem (CommandManager manager)
+ {
+ Gtk.Menu menu = manager.CreateMenu (this);
+ return new MenuToolButton (menu, icon);
+ }
+ }
+
+ public class AutoHideMenuItem: Gtk.ImageMenuItem
+ {
+ public AutoHideMenuItem (string name): base (name)
+ {
+ Console.WriteLine ("MM:" + name);
+ }
+/*
+ protected override void OnShown ()
+ {
+ base.OnShown ();
+ }
+*/ }
+}
+
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandHandler.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandHandler.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandHandler.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,53 @@
+//
+// CommandHandler.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ public class CommandHandler
+ {
+ internal protected virtual void Run ()
+ {
+ }
+
+ internal protected virtual void Run (object dataItem)
+ {
+ Run ();
+ }
+
+ internal protected virtual void Update (CommandInfo info)
+ {
+ }
+
+ internal protected virtual void Update (CommandArrayInfo info)
+ {
+ }
+ }
+}
+
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandHandlerAttribute.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandHandlerAttribute.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandHandlerAttribute.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,61 @@
+//
+// CommandMethodAttribute.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ public class CommandMethodAttribute: Attribute
+ {
+ object commandId;
+
+ internal CommandMethodAttribute (object commandId)
+ {
+ this.commandId = commandId;
+ }
+
+ public object CommandId {
+ get { return commandId; }
+ set { commandId = value; }
+ }
+ }
+
+ public class CommandHandlerAttribute: CommandMethodAttribute
+ {
+ public CommandHandlerAttribute (object commandId): base (commandId)
+ {
+ }
+ }
+
+ public class CommandUpdateHandlerAttribute: CommandMethodAttribute
+ {
+ public CommandUpdateHandlerAttribute (object commandId): base (commandId)
+ {
+ }
+ }
+}
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandInfo.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandInfo.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandInfo.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,103 @@
+//
+// CommandInfo.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ public class CommandInfo
+ {
+ string text;
+ string icon;
+ string accelKey;
+ string description;
+ bool enabled = true;
+ bool visible = true;
+ bool checkd;
+ bool useMarkup;
+ internal object DataItem;
+ internal CommandArrayInfo ArrayInfo;
+
+ internal CommandInfo (Command cmd)
+ {
+ text = cmd.Text;
+ icon = cmd.Icon;
+ accelKey = cmd.AccelKey;
+ }
+
+ public CommandInfo (string text)
+ {
+ Text = text;
+ }
+
+ public CommandInfo (string text, bool enabled, bool checkd)
+ {
+ Text = text;
+ }
+
+ public string Text {
+ get { return text; }
+ set { text = value; }
+ }
+
+ public string Icon {
+ get { return icon; }
+ set { icon = value; }
+ }
+
+ public string AccelKey {
+ get { return accelKey; }
+ set { accelKey = value; }
+ }
+
+ public string Description {
+ get { return description; }
+ set { description = value; }
+ }
+
+ public bool Enabled {
+ get { return enabled; }
+ set { enabled = value; }
+ }
+
+ public bool Visible {
+ get { return visible; }
+ set { visible = value; }
+ }
+
+ public bool Checked {
+ get { return checkd; }
+ set { checkd = value; }
+ }
+
+ public bool UseMarkup {
+ get { return useMarkup; }
+ set { useMarkup = value; }
+ }
+ }
+}
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandManager.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandManager.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandManager.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,439 @@
+//
+// CommandManager.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Reflection;
+using System.Collections;
+
+namespace MonoDevelop.Commands
+{
+ public class CommandManager
+ {
+ public static CommandManager Main = new CommandManager ();
+ Gtk.Window rootWidget;
+
+ Hashtable cmds = new Hashtable ();
+ Hashtable handlerInfo = new Hashtable ();
+ ArrayList toolbars = new ArrayList ();
+ ArrayList globalHandlers = new ArrayList ();
+
+ Gtk.AccelGroup accelGroup;
+
+ public CommandManager ()
+ {
+ GLib.Timeout.Add (500, new GLib.TimeoutHandler (UpdateStatus));
+ }
+
+ public void SetRootWindow (Gtk.Window root)
+ {
+ rootWidget = root;
+ if (rootWidget.IsRealized)
+ rootWidget.AddAccelGroup (AccelGroup);
+ else
+ rootWidget.Realized += new EventHandler (RootRealized);
+ }
+
+ public void RegisterCommand (Command cmd, string category)
+ {
+ cmds [cmd.Id] = cmd;
+ }
+
+ public void RegisterGlobalHandler (object handler)
+ {
+ if (!globalHandlers.Contains (handler))
+ globalHandlers.Add (handler);
+ }
+
+ public void UnregisterGlobalHandler (object handler)
+ {
+ globalHandlers.Remove (handler);
+ }
+
+ public Command GetCommand (object cmdId)
+ {
+ Command cmd = cmds [cmdId] as Command;
+ if (cmd == null)
+ throw new InvalidOperationException ("Invalid command id: " + cmdId);
+ return cmd;
+ }
+
+ public ActionCommand GetActionCommand (object cmdId)
+ {
+ ActionCommand cmd = cmds [cmdId] as ActionCommand;
+ if (cmd == null)
+ throw new InvalidOperationException ("Invalid action command id: " + cmdId);
+ return cmd;
+ }
+
+ public Gtk.MenuBar CreateMenuBar (string name, CommandEntrySet entrySet)
+ {
+ Gtk.MenuBar topMenu = new CommandMenuBar (this);
+ foreach (CommandEntry entry in entrySet)
+ topMenu.Append (entry.CreateMenuItem (this));
+ return topMenu;
+ }
+
+ public Gtk.Toolbar CreateToolbar (string name, CommandEntrySet entrySet)
+ {
+ return CreateToolbar (entrySet);
+ }
+
+ public Gtk.Menu CreateMenu (CommandEntrySet entrySet)
+ {
+ CommandMenu menu = new CommandMenu (this);
+ foreach (CommandEntry entry in entrySet)
+ menu.Append (entry.CreateMenuItem (this));
+ return menu;
+ }
+
+ public Gtk.Toolbar CreateToolbar (CommandEntrySet entrySet)
+ {
+ CommandToolbar toolbar = new CommandToolbar (this);
+ foreach (CommandEntry entry in entrySet)
+ toolbar.Add (entry.CreateToolItem (this));
+ return toolbar;
+ }
+
+ public bool DispatchCommand (object commandId)
+ {
+ return DispatchCommand (commandId, null);
+ }
+
+ public bool DispatchCommand (object commandId, object dataItem)
+ {
+ ActionCommand cmd = GetActionCommand (commandId);
+
+ int globalPos;
+ object cmdTarget = GetFirstCommandTarget (out globalPos);
+ CommandInfo info = new CommandInfo (cmd);
+
+ while (cmdTarget != null)
+ {
+ HandlerTypeInfo typeInfo = GetTypeHandlerInfo (cmdTarget);
+
+ CommandUpdaterInfo cui = typeInfo.GetCommandUpdater (commandId);
+ if (cui != null) {
+ if (cmd.CommandArray) {
+ // Make sure that the option is still active
+ CommandArrayInfo ainfo = new CommandArrayInfo (info);
+ cui.Run (cmdTarget, ainfo);
+ bool found = false;
+ foreach (CommandInfo ci in ainfo) {
+ if (Object.Equals (dataItem, ci.DataItem)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) return false;
+ } else {
+ cui.Run (cmdTarget, info);
+ if (!info.Enabled || !info.Visible) return false;
+ }
+ }
+
+ CommandHandlerInfo chi = typeInfo.GetCommandHandler (commandId);
+ if (chi != null) {
+ if (cmd.CommandArray)
+ chi.Run (cmdTarget, dataItem);
+ else
+ chi.Run (cmdTarget);
+ UpdateToolbars ();
+ return true;
+ }
+
+ cmdTarget = GetNextCommandTarget (cmdTarget, ref globalPos);
+ }
+
+ return cmd.DispatchCommand (dataItem);
+ }
+
+ internal CommandInfo GetCommandInfo (object commandId)
+ {
+ ActionCommand cmd = GetActionCommand (commandId);
+ CommandInfo info = new CommandInfo (cmd);
+
+ int globalPos;
+ object cmdTarget = GetFirstCommandTarget (out globalPos);
+
+ while (cmdTarget != null)
+ {
+ HandlerTypeInfo typeInfo = GetTypeHandlerInfo (cmdTarget);
+ CommandUpdaterInfo cui = typeInfo.GetCommandUpdater (commandId);
+
+ if (cui != null) {
+ if (cmd.CommandArray) {
+ info.ArrayInfo = new CommandArrayInfo (info);
+ cui.Run (cmdTarget, info.ArrayInfo);
+ return info;
+ }
+ else {
+ cui.Run (cmdTarget, info);
+ return info;
+ }
+ }
+
+ if (typeInfo.GetCommandHandler (commandId) != null) {
+ info.Enabled = true;
+ info.Visible = true;
+ return info;
+ }
+
+ cmdTarget = GetNextCommandTarget (cmdTarget, ref globalPos);
+ }
+
+ cmd.UpdateCommandInfo (info);
+ return info;
+ }
+
+ internal string GetAccelPath (string key)
+ {
+ string path = "<MonoDevelop>/MainWindow/" + key;
+ if (!Gtk.AccelMap.LookupEntry (path, new Gtk.AccelKey()) ) {
+ string[] keys = key.Split ('|');
+ Gdk.ModifierType mod = 0;
+ uint ckey = 0;
+ foreach (string keyp in keys) {
+ if (keyp == "Control") {
+ mod |= Gdk.ModifierType.ControlMask;
+ } else if (keyp == "Shift") {
+ mod |= Gdk.ModifierType.ShiftMask;
+ } else if (keyp == "Alt") {
+ mod |= Gdk.ModifierType.Mod1Mask;
+ } else {
+ ckey = Gdk.Keyval.FromName (keyp);
+ }
+ }
+ Gtk.AccelMap.AddEntry (path, ckey, mod);
+ }
+ return path;
+ }
+
+ void RootRealized (object sender, EventArgs e)
+ {
+ rootWidget.AddAccelGroup (AccelGroup);
+ }
+
+ internal Gtk.AccelGroup AccelGroup {
+ get {
+ if (accelGroup == null) {
+ accelGroup = new Gtk.AccelGroup ();
+ }
+ return accelGroup;
+ }
+ }
+
+ HandlerTypeInfo GetTypeHandlerInfo (object cmdTarget)
+ {
+ HandlerTypeInfo typeInfo = (HandlerTypeInfo) handlerInfo [cmdTarget.GetType ()];
+ if (typeInfo != null) return typeInfo;
+
+ Type type = cmdTarget.GetType ();
+ typeInfo = new HandlerTypeInfo ();
+
+ ArrayList handlers = new ArrayList ();
+ ArrayList updaters = new ArrayList ();
+
+ MethodInfo[] methods = type.GetMethods (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
+ foreach (MethodInfo method in methods) {
+ object attr = Attribute.GetCustomAttribute (method, typeof(CommandHandlerAttribute));
+ if (attr != null)
+ handlers.Add (new CommandHandlerInfo (method, (CommandHandlerAttribute) attr));
+
+ attr = Attribute.GetCustomAttribute (method, typeof(CommandUpdateHandlerAttribute));
+ if (attr != null)
+ updaters.Add (new CommandUpdaterInfo (method, (CommandUpdateHandlerAttribute) attr));
+ }
+
+ if (handlers.Count > 0)
+ typeInfo.CommandHandlers = (CommandHandlerInfo[]) handlers.ToArray (typeof(CommandHandlerInfo));
+ if (updaters.Count > 0)
+ typeInfo.CommandUpdaters = (CommandUpdaterInfo[]) updaters.ToArray (typeof(CommandUpdaterInfo));
+
+ handlerInfo [type] = typeInfo;
+ return typeInfo;
+ }
+
+ object GetFirstCommandTarget (out int globalPos)
+ {
+ object cmdTarget = GetActiveWidget (rootWidget);
+ if (cmdTarget == null) {
+ globalPos = 0;
+ if (globalHandlers.Count == 0) return null;
+ return globalHandlers [0];
+ } else {
+ globalPos = -1;
+ return cmdTarget;
+ }
+ }
+
+ object GetNextCommandTarget (object cmdTarget, ref int globalPos)
+ {
+ if (globalPos != -1) {
+ if (++globalPos < globalHandlers.Count)
+ return globalHandlers [globalPos];
+ else
+ return null;
+ }
+
+ if (cmdTarget is ICommandRouter)
+ cmdTarget = ((ICommandRouter)cmdTarget).GetNextCommandTarget ();
+ else if (cmdTarget is Gtk.Widget)
+ cmdTarget = ((Gtk.Widget)cmdTarget).Parent;
+ else
+ cmdTarget = null;
+
+ if (cmdTarget == null) {
+ if (globalHandlers.Count == 0) return null;
+ globalPos = 0;
+ return globalHandlers [0];
+ } else
+ return cmdTarget;
+ }
+
+ Gtk.Widget GetActiveWidget (Gtk.Widget widget)
+ {
+ if (widget is Gtk.Container) {
+ Gtk.Widget child = ((Gtk.Container)widget).FocusChild;
+ if (child != null)
+ return GetActiveWidget (child);
+ }
+ return widget;
+ }
+
+ bool UpdateStatus ()
+ {
+ UpdateToolbars ();
+ return true;
+ }
+
+ internal void RegisterToolbar (CommandToolbar toolbar)
+ {
+ toolbars.Add (toolbar);
+ }
+
+ void UpdateToolbars ()
+ {
+ foreach (CommandToolbar toolbar in toolbars) {
+ if (toolbar.Visible)
+ toolbar.Update ();
+ }
+ }
+ }
+
+ internal class HandlerTypeInfo
+ {
+ public CommandHandlerInfo[] CommandHandlers;
+ public CommandUpdaterInfo[] CommandUpdaters;
+
+ public CommandHandlerInfo GetCommandHandler (object commandId)
+ {
+ if (CommandHandlers == null) return null;
+ foreach (CommandHandlerInfo cui in CommandHandlers)
+ if (cui.CommandId.Equals (commandId))
+ return cui;
+ return null;
+ }
+
+ public CommandUpdaterInfo GetCommandUpdater (object commandId)
+ {
+ if (CommandUpdaters == null) return null;
+ foreach (CommandUpdaterInfo cui in CommandUpdaters)
+ if (cui.CommandId.Equals (commandId))
+ return cui;
+ return null;
+ }
+ }
+
+
+ internal class CommandMethodInfo
+ {
+ public object CommandId;
+ protected MethodInfo Method;
+
+ public CommandMethodInfo (MethodInfo method, CommandMethodAttribute attr)
+ {
+ this.Method = method;
+ CommandId = attr.CommandId;
+ }
+ }
+
+ internal class CommandUpdaterInfo: CommandMethodInfo
+ {
+ bool isArray;
+
+ public CommandUpdaterInfo (MethodInfo method, CommandUpdateHandlerAttribute attr): base (method, attr)
+ {
+ ParameterInfo[] pars = method.GetParameters ();
+ if (pars.Length == 1) {
+ Type t = pars[0].ParameterType;
+
+ if (t == typeof(CommandArrayInfo)) {
+ isArray = true;
+ return;
+ } else if (t == typeof(CommandInfo))
+ return;
+ }
+ throw new InvalidOperationException ("Invalid signature for command update handler: " + method.DeclaringType + "." + method.Name + "()");
+ }
+
+ public void Run (object cmdTarget, CommandInfo info)
+ {
+ if (isArray)
+ throw new InvalidOperationException ("Invalid signature for command update handler: " + Method.DeclaringType + "." + Method.Name + "()");
+ Method.Invoke (cmdTarget, new object[] {info} );
+ }
+
+ public void Run (object cmdTarget, CommandArrayInfo info)
+ {
+ if (!isArray)
+ throw new InvalidOperationException ("Invalid signature for command update handler: " + Method.DeclaringType + "." + Method.Name + "()");
+ Method.Invoke (cmdTarget, new object[] {info} );
+ }
+ }
+
+ internal class CommandHandlerInfo: CommandMethodInfo
+ {
+ public CommandHandlerInfo (MethodInfo method, CommandHandlerAttribute attr): base (method, attr)
+ {
+ ParameterInfo[] pars = method.GetParameters ();
+ if (pars.Length > 1)
+ throw new InvalidOperationException ("Invalid signature for command handler: " + method.DeclaringType + "." + method.Name + "()");
+ }
+
+ public void Run (object cmdTarget)
+ {
+ Method.Invoke (cmdTarget, null);
+ }
+
+ public void Run (object cmdTarget, object dataItem)
+ {
+ Method.Invoke (cmdTarget, new object[] {dataItem});
+ }
+ }
+}
+
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandMenu.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandMenu.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandMenu.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,90 @@
+//
+// CommandMenu.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ public class CommandMenu: Gtk.Menu
+ {
+ CommandManager manager;
+
+ public CommandMenu (CommandManager manager)
+ {
+ this.manager = manager;
+ this.AccelGroup = manager.AccelGroup;
+ }
+
+ internal CommandManager CommandManager {
+ get {
+ if (manager == null) {
+ Gtk.Widget w = Parent;
+ Console.WriteLine ("P:" + w);
+ while (w != null && !(w is CommandMenu) && !(w is CommandMenuBar)) {
+ w = w.Parent;
+ Console.WriteLine ("P:" + w);
+ }
+ if (w is CommandMenu)
+ manager = ((CommandMenu)w).CommandManager;
+ else if (w is CommandMenuBar)
+ manager = ((CommandMenuBar)w).CommandManager;
+ else
+ throw new InvalidOperationException ("Menu not bound to a CommandManager.");
+ }
+ return manager;
+ }
+ }
+
+ protected CommandMenu (IntPtr ptr): base (ptr)
+ {
+ }
+
+ protected override void OnShown ()
+ {
+ base.OnShown ();
+ foreach (Gtk.Widget item in Children) {
+ if (item is ICommandUserItem)
+ ((ICommandUserItem)item).Update ();
+ else
+ item.Show ();
+ }
+ }
+
+ protected override void OnHidden ()
+ {
+ base.OnHidden ();
+
+ // Make sure the accelerators allways work for this item
+ // while the menu is hidden
+ foreach (Gtk.MenuItem item in Children) {
+ item.Sensitive = true;
+ item.Visible = true;
+ }
+ }
+ }
+}
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandMenuBar.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandMenuBar.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandMenuBar.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,46 @@
+//
+// CommandMenuBar.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ public class CommandMenuBar: Gtk.MenuBar
+ {
+ CommandManager manager;
+
+ public CommandMenuBar (CommandManager manager)
+ {
+ this.manager = manager;
+ }
+
+ internal CommandManager CommandManager {
+ get { return manager; }
+ }
+ }
+}
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandMenuItem.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandMenuItem.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandMenuItem.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,143 @@
+//
+// CommandMenuItem.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+
+namespace MonoDevelop.Commands
+{
+ public class CommandMenuItem: Gtk.ImageMenuItem, ICommandMenuItem
+ {
+ CommandManager commandManager;
+ object commandId;
+ bool isArray;
+ bool isArrayItem;
+ object arrayDataItem;
+ ArrayList itemArray;
+ string lastIcon;
+
+ public CommandMenuItem (object commandId, CommandManager commandManager): base ("")
+ {
+ this.commandId = commandId;
+ this.commandManager = commandManager;
+ ActionCommand cmd = commandManager.GetCommand (commandId) as ActionCommand;
+ if (cmd != null)
+ isArray = cmd.CommandArray;
+ }
+
+ void ICommandUserItem.Update ()
+ {
+ if (commandManager != null && !isArrayItem) {
+ CommandInfo cinfo = commandManager.GetCommandInfo (commandId);
+ Update (cinfo);
+ }
+ }
+
+ void ICommandMenuItem.SetUpdateInfo (CommandInfo cmdInfo)
+ {
+ isArrayItem = true;
+ arrayDataItem = cmdInfo.DataItem;
+ Update (cmdInfo);
+ }
+
+ protected override void OnParentSet (Gtk.Widget parent)
+ {
+ base.OnParentSet (parent);
+ if (Parent == null) return;
+
+ ((ICommandUserItem)this).Update ();
+
+ // Make sure the accelerators allways work for this item
+ // while the menu is hidden
+ Sensitive = true;
+ Visible = true;
+ }
+
+ protected override void OnActivated ()
+ {
+ base.OnActivated ();
+
+ if (commandManager == null)
+ throw new InvalidOperationException ();
+
+ commandManager.DispatchCommand (commandId, arrayDataItem);
+ }
+
+ void Update (CommandInfo cmdInfo)
+ {
+ if (isArray && !isArrayItem)
+ {
+ this.Visible = false;
+ CommandMenu menu = (CommandMenu) Parent;
+
+ if (itemArray != null) {
+ foreach (Gtk.MenuItem item in itemArray)
+ menu.Remove (item);
+ }
+
+ itemArray = new ArrayList ();
+ int i = Array.IndexOf (menu.Children, this);
+
+ if (cmdInfo.ArrayInfo != null) {
+ foreach (CommandInfo info in cmdInfo.ArrayInfo) {
+ Gtk.MenuItem item = CommandEntry.CreateMenuItem (commandManager, commandId, false);
+ ICommandMenuItem mi = (ICommandMenuItem) item;
+ mi.SetUpdateInfo (info);
+ menu.Insert (item, ++i);
+ itemArray.Add (item);
+ }
+ }
+ }
+ else {
+ Gtk.AccelLabel child = (Gtk.AccelLabel)Child;
+ if (child == null) return;
+ child.Show ();
+ child.Xalign = 0;
+ if (cmdInfo.UseMarkup) {
+ child.Markup = cmdInfo.Text;
+ child.UseMarkup = true;
+ } else {
+ child.Text = cmdInfo.Text;
+ child.UseMarkup = false;
+ }
+ child.UseUnderline = true;
+ child.AccelWidget = this;
+ this.Sensitive = cmdInfo.Enabled;
+ this.Visible = cmdInfo.Visible;
+
+ if (cmdInfo.AccelKey != null && cmdInfo.AccelKey != "")
+ this.AccelPath = commandManager.GetAccelPath (cmdInfo.AccelKey);
+
+ if (cmdInfo.Icon != null && cmdInfo.Icon != "" && cmdInfo.Icon != lastIcon) {
+ Image = new Gtk.Image (cmdInfo.Icon, Gtk.IconSize.Menu);
+ lastIcon = cmdInfo.Icon;
+ }
+ }
+ }
+ }
+}
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandToggleToolButton.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandToggleToolButton.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandToggleToolButton.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,83 @@
+//
+// CommandToggleToolButton.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ public class CommandToggleToolButton: Gtk.ToggleToolButton, ICommandUserItem
+ {
+ CommandManager commandManager;
+ object commandId;
+ bool updating;
+
+ public CommandToggleToolButton (object commandId, CommandManager commandManager): base ("")
+ {
+ this.commandId = commandId;
+ this.commandManager = commandManager;
+ }
+
+ protected override void OnParentSet (Gtk.Widget parent)
+ {
+ base.OnParentSet (parent);
+ if (Parent == null) return;
+
+ ((ICommandUserItem)this).Update ();
+ }
+
+ void ICommandUserItem.Update ()
+ {
+ if (commandManager != null) {
+ CommandInfo cinfo = commandManager.GetCommandInfo (commandId);
+ Update (cinfo);
+ }
+ }
+
+ protected override void OnClicked ()
+ {
+ base.OnClicked ();
+ if (updating) return;
+
+ if (commandManager == null)
+ throw new InvalidOperationException ();
+
+ commandManager.DispatchCommand (commandId);
+ }
+
+ void Update (CommandInfo cmdInfo)
+ {
+ updating = true;
+ Label = cmdInfo.Text;
+ StockId = cmdInfo.Icon;
+ Sensitive = cmdInfo.Enabled;
+ Visible = cmdInfo.Visible;
+ Active = cmdInfo.Checked;
+ updating = false;
+ }
+ }
+}
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandToolButton.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandToolButton.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandToolButton.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,84 @@
+//
+// CommandToolButton.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ public class CommandToolButton: Gtk.ToolButton, ICommandUserItem
+ {
+ CommandManager commandManager;
+ object commandId;
+ static Gtk.Tooltips tips = new Gtk.Tooltips ();
+ string lastDesc;
+
+ public CommandToolButton (object commandId, CommandManager commandManager): base ("")
+ {
+ this.commandId = commandId;
+ this.commandManager = commandManager;
+ }
+
+ protected override void OnParentSet (Gtk.Widget parent)
+ {
+ base.OnParentSet (parent);
+ if (Parent == null) return;
+
+ ((ICommandUserItem)this).Update ();
+ }
+
+ void ICommandUserItem.Update ()
+ {
+ if (commandManager != null) {
+ CommandInfo cinfo = commandManager.GetCommandInfo (commandId);
+ Update (cinfo);
+ }
+ }
+
+ protected override void OnClicked ()
+ {
+ base.OnClicked ();
+
+ if (commandManager == null)
+ throw new InvalidOperationException ();
+
+ commandManager.DispatchCommand (commandId);
+ }
+
+ void Update (CommandInfo cmdInfo)
+ {
+ if (lastDesc != cmdInfo.Description) {
+ SetTooltip (tips, cmdInfo.Description, cmdInfo.Description);
+ lastDesc = cmdInfo.Description;
+ }
+ Label = cmdInfo.Text;
+ StockId = cmdInfo.Icon;
+ Sensitive = cmdInfo.Enabled;
+ Visible = cmdInfo.Visible;
+ }
+ }
+}
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandToolbar.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandToolbar.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandToolbar.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,63 @@
+//
+// CommandToolbar.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ public class CommandToolbar: Gtk.Toolbar
+ {
+ CommandManager manager;
+
+ public CommandToolbar (CommandManager manager)
+ {
+ this.manager = manager;
+ manager.RegisterToolbar (this);
+ }
+
+ internal CommandManager CommandManager {
+ get { return manager; }
+ }
+
+ protected override void OnShown ()
+ {
+ base.OnShown ();
+ Update ();
+ }
+
+ internal void Update ()
+ {
+ foreach (Gtk.Widget item in Children) {
+ if (item is ICommandUserItem)
+ ((ICommandUserItem)item).Update ();
+ else
+ item.Show ();
+ }
+ }
+ }
+}
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CustomCommand.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CustomCommand.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CustomCommand.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,56 @@
+//
+// CustomCommand.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ public class CustomCommand: Command
+ {
+ Type widgetType;
+
+ public CustomCommand ()
+ {
+ }
+
+ public CustomCommand (object id, string text, Type widgetType): base (id, text)
+ {
+ WidgetType = widgetType;
+ }
+
+ public Type WidgetType {
+ get { return widgetType; }
+ set {
+ if (!typeof(Gtk.Widget).IsAssignableFrom (value))
+ throw new ArgumentException ("Value is not a subclass of Gtk.Widget.");
+ widgetType = value;
+ }
+ }
+ }
+}
+
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CustomMenuItem.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CustomMenuItem.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CustomMenuItem.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,46 @@
+//
+// CustomMenuItem.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+
+namespace MonoDevelop.Commands
+{
+ public class CustomMenuItem: Gtk.MenuItem
+ {
+ protected override bool OnButtonPressEvent (Gdk.EventButton e)
+ {
+ return true;
+ }
+
+ protected override bool OnButtonReleaseEvent (Gdk.EventButton e)
+ {
+ return true;
+ }
+ }
+}
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ICommandMenuItem.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ICommandMenuItem.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ICommandMenuItem.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,37 @@
+//
+// ICommandMenuItem.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ internal interface ICommandMenuItem: ICommandUserItem
+ {
+ void SetUpdateInfo (CommandInfo cmdInfo);
+ }
+}
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ICommandRouter.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ICommandRouter.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ICommandRouter.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,37 @@
+//
+// ICommandRouter.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ public interface ICommandRouter
+ {
+ object GetNextCommandTarget ();
+ }
+}
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ICommandUserItem.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ICommandUserItem.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ICommandUserItem.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,37 @@
+//
+// ICommandUserItem.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ internal interface ICommandUserItem
+ {
+ void Update ();
+ }
+}
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/LinkCommandEntry.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/LinkCommandEntry.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/LinkCommandEntry.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,94 @@
+//
+// LinkCommandEntry.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Diagnostics;
+using MonoDevelop.Services;
+
+namespace MonoDevelop.Commands
+{
+ public class LinkCommandEntry: CommandEntry
+ {
+ static object Id = new object ();
+ string text;
+ string url;
+ string icon = Gtk.Stock.JumpTo;
+
+ public LinkCommandEntry (string text, string url): base (Id)
+ {
+ this.text = text;
+ this.url = url;
+ }
+
+ public LinkCommandEntry (string text, string url, string icon): base (Id)
+ {
+ this.text = text;
+ this.url = url;
+ this.icon = icon;
+ }
+
+ public string Text {
+ get { return text; }
+ set { text = value; }
+ }
+
+ public string Url {
+ get { return url; }
+ set { url = value; }
+ }
+
+ internal void HandleActivation (object sender, EventArgs e)
+ {
+ try {
+ Gnome.Url.Show (url);
+ } catch (Exception) {
+ string msg = String.Format (GettextCatalog.GetString ("Could not open the url {0}"), url);
+ Gtk.MessageDialog md = new Gtk.MessageDialog (null, Gtk.DialogFlags.Modal | Gtk.DialogFlags.DestroyWithParent, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, msg);
+ md.Run ();
+ md.Hide ();
+ }
+ }
+
+ internal protected override Gtk.MenuItem CreateMenuItem (CommandManager manager)
+ {
+ Gtk.ImageMenuItem item = new Gtk.ImageMenuItem (text != null ? text : url);
+ item.Image = new Gtk.Image (icon, Gtk.IconSize.Menu);
+ item.Activated += new EventHandler (HandleActivation);
+ return item;
+ }
+
+ internal protected override Gtk.ToolItem CreateToolItem (CommandManager manager)
+ {
+ Gtk.ToolButton item = new Gtk.ToolButton (text);
+ item.StockId = icon;
+ item.Clicked += new EventHandler (HandleActivation);
+ return item;
+ }
+ }
+}
+
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/MenuToolButton.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/MenuToolButton.cs 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/MenuToolButton.cs 2005-04-25 16:56:54 UTC (rev 2471)
@@ -0,0 +1,65 @@
+//
+// MenuToolButton.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ public class MenuToolButton: Gtk.ToolButton
+ {
+ Gtk.Menu menu;
+
+ public MenuToolButton (Gtk.Menu menu, string icon): base (icon)
+ {
+ this.menu = menu;
+ Child.ButtonPressEvent += new Gtk.ButtonPressEventHandler (OnButtonPress);
+ }
+
+ protected override void OnClicked ()
+ {
+ Console.WriteLine ("ccc");
+ base.OnClicked ();
+ }
+
+ [GLib.ConnectBeforeAttribute]
+ void OnButtonPress (object sender, Gtk.ButtonPressEventArgs e)
+ {
+ Console.WriteLine ("aaa");
+ menu.Popup (null, null, new Gtk.MenuPositionFunc (OnPosition), IntPtr.Zero, 3, Gtk.Global.CurrentEventTime);
+ e.RetVal = true;
+ }
+
+ void OnPosition (Gtk.Menu menu, out int x, out int y, out bool pushIn)
+ {
+ this.ParentWindow.GetOrigin (out x, out y);
+ x += this.Allocation.X;
+ y += this.Allocation.Y + this.Allocation.Height;
+ pushIn = true;
+ }
+ }
+}
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Makefile.am
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Makefile.am 2005-04-25 10:02:22 UTC (rev 2470)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Makefile.am 2005-04-25 16:56:54 UTC (rev 2471)
@@ -27,7 +27,31 @@
TabLabel/TabLabel.cs \
GladeWidgetExtract/GladeWidgetExtract.cs \
DragNotebook/DragNotebook.cs \
-DataGrid/DataGrid.cs
+DataGrid/DataGrid.cs \
+Commands/ActionCommand.cs \
+Commands/ActionType.cs \
+Commands/CommandArrayInfo.cs \
+Commands/CommandCheckMenuItem.cs \
+Commands/Command.cs \
+Commands/CommandEntry.cs \
+Commands/CommandEntrySet.cs \
+Commands/CommandHandlerAttribute.cs \
+Commands/CommandHandler.cs \
+Commands/CommandInfo.cs \
+Commands/CommandManager.cs \
+Commands/CommandMenuBar.cs \
+Commands/CommandMenu.cs \
+Commands/CommandMenuItem.cs \
+Commands/CommandToggleToolButton.cs \
+Commands/CommandToolbar.cs \
+Commands/CommandToolButton.cs \
+Commands/CustomCommand.cs \
+Commands/CustomMenuItem.cs \
+Commands/ICommandMenuItem.cs \
+Commands/ICommandRouter.cs \
+Commands/ICommandUserItem.cs \
+Commands/LinkCommandEntry.cs \
+Commands/MenuToolButton.cs
all: $(DLL)
More information about the Monodevelop-patches-list
mailing list