Author: lluis
Date: 2006-08-08 07:24:40 -0400 (Tue, 08 Aug 2006)
New Revision: 63471

Modified:
   trunk/monodevelop/Core/src/MonoDevelop.Components/ChangeLog
   
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandCheckMenuItem.cs
   
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandManager.cs
   
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandMenu.cs
   
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandMenuItem.cs
   
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandToggleToolButton.cs
   
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandToolButton.cs
   
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandToolbar.cs
   
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/ICommandMenuItem.cs
   
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/ICommandUserItem.cs
Log:
2006-08-08 Lluis Sanchez Gual  <[EMAIL PROTECTED]>

        * MonoDevelop.Components.Commands/CommandToolbar.cs:
        * MonoDevelop.Components.Commands/CommandMenu.cs:
        * MonoDevelop.Components.Commands/CommandToolButton.cs:
        * MonoDevelop.Components.Commands/CommandToggleToolButton.cs:
        * MonoDevelop.Components.Commands/CommandManager.cs:
        * MonoDevelop.Components.Commands/ICommandMenuItem.cs:
        * MonoDevelop.Components.Commands/CommandCheckMenuItem.cs:
        * MonoDevelop.Components.Commands/ICommandUserItem.cs:
        * MonoDevelop.Components.Commands/CommandMenuItem.cs: Support specifying
          an initial command target for menus and toolbars.



Modified: trunk/monodevelop/Core/src/MonoDevelop.Components/ChangeLog
===================================================================
--- trunk/monodevelop/Core/src/MonoDevelop.Components/ChangeLog 2006-08-08 
11:24:22 UTC (rev 63470)
+++ trunk/monodevelop/Core/src/MonoDevelop.Components/ChangeLog 2006-08-08 
11:24:40 UTC (rev 63471)
@@ -1,3 +1,16 @@
+2006-08-08 Lluis Sanchez Gual  <[EMAIL PROTECTED]>
+
+       * MonoDevelop.Components.Commands/CommandToolbar.cs:
+       * MonoDevelop.Components.Commands/CommandMenu.cs:
+       * MonoDevelop.Components.Commands/CommandToolButton.cs:
+       * MonoDevelop.Components.Commands/CommandToggleToolButton.cs:
+       * MonoDevelop.Components.Commands/CommandManager.cs:
+       * MonoDevelop.Components.Commands/ICommandMenuItem.cs:
+       * MonoDevelop.Components.Commands/CommandCheckMenuItem.cs:
+       * MonoDevelop.Components.Commands/ICommandUserItem.cs:
+       * MonoDevelop.Components.Commands/CommandMenuItem.cs: Support specifying
+         an initial command target for menus and toolbars.
+
 2006-08-07 Lluis Sanchez Gual  <[EMAIL PROTECTED]>
 
        * MonoDevelop.Components.HtmlControl/MozillaControl.cs: Set the

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandCheckMenuItem.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandCheckMenuItem.cs
   2006-08-08 11:24:22 UTC (rev 63470)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandCheckMenuItem.cs
   2006-08-08 11:24:40 UTC (rev 63471)
@@ -37,6 +37,7 @@
                bool updating;
                bool isArrayItem;
                object arrayDataItem;
+               object initialTarget;
                
                public CommandCheckMenuItem (object commandId, CommandManager 
commandManager): base ("")
                {
@@ -47,18 +48,20 @@
                                this.DrawAsRadio = true; 
                }
                
-               void ICommandUserItem.Update ()
+               void ICommandUserItem.Update (object initialTarget)
                {
                        if (commandManager != null && !isArrayItem) {
-                               CommandInfo cinfo = 
commandManager.GetCommandInfo (commandId);
+                               CommandInfo cinfo = 
commandManager.GetCommandInfo (commandId, initialTarget);
+                               this.initialTarget = initialTarget;
                                Update (cinfo);
                        }
                }
                
-               void ICommandMenuItem.SetUpdateInfo (CommandInfo cmdInfo)
+               void ICommandMenuItem.SetUpdateInfo (CommandInfo cmdInfo, 
object initialTarget)
                {
                        isArrayItem = true;
                        arrayDataItem = cmdInfo.DataItem;
+                       this.initialTarget = initialTarget;
                        Update (cmdInfo);
                }
                
@@ -67,7 +70,7 @@
                        base.OnParentSet (parent);
                        if (Parent == null) return;
                        
-                       ((ICommandUserItem)this).Update ();
+                       ((ICommandUserItem)this).Update (null);
                        
                        // Make sure the accelerators allways work for this item
                        // while the menu is hidden
@@ -84,7 +87,7 @@
                        if (commandManager == null)
                                throw new InvalidOperationException ();
 
-                       commandManager.DispatchCommand (commandId, 
arrayDataItem);
+                       commandManager.DispatchCommand (commandId, 
arrayDataItem, initialTarget);
                }
                
                void Update (CommandInfo cmdInfo)

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandManager.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandManager.cs
 2006-08-08 11:24:22 UTC (rev 63470)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandManager.cs
 2006-08-08 11:24:40 UTC (rev 63471)
@@ -182,7 +182,7 @@
                                int n = menu.Children.Length;
                                menu.Insert (item, index);
                                if (item is ICommandUserItem)
-                                       ((ICommandUserItem)item).Update ();
+                                       ((ICommandUserItem)item).Update (null);
                                else
                                        item.Show ();
                                index += menu.Children.Length - n;
@@ -191,9 +191,16 @@
                
                public void ShowContextMenu (CommandEntrySet entrySet)
                {
-                       ShowContextMenu (CreateMenu (entrySet));
+                       ShowContextMenu (entrySet, null);
                }
                
+               public void ShowContextMenu (CommandEntrySet entrySet, object 
initialTarget)
+               {
+                       CommandMenu menu = (CommandMenu) CreateMenu (entrySet);
+                       menu.InitialCommandTarget = initialTarget;
+                       ShowContextMenu (menu);
+               }
+               
                public void ShowContextMenu (Gtk.Menu menu)
                {
                        menu.Popup (null, null, null, 0, 
Gtk.Global.CurrentEventTime);
@@ -209,17 +216,22 @@
 
                public bool DispatchCommand (object commandId)
                {
-                       return DispatchCommand (commandId, null);
+                       return DispatchCommand (commandId, null, null);
                }
                
                public bool DispatchCommand (object commandId, object dataItem)
                {
+                       return DispatchCommand (commandId, dataItem, null);
+               }
+
+               public bool DispatchCommand (object commandId, object dataItem, 
object initialTarget)
+               {
                        ActionCommand cmd = null;
                        try {
                                cmd = GetActionCommand (commandId);
                                
-                               int globalPos;
-                               object cmdTarget = GetFirstCommandTarget (out 
globalPos);
+                               int globalPos = -1;
+                               object cmdTarget = initialTarget != null ? 
initialTarget : GetFirstCommandTarget (out globalPos);
                                CommandInfo info = new CommandInfo (cmd);
                                
                                while (cmdTarget != null)
@@ -269,14 +281,14 @@
                        }
                }
                
-               internal CommandInfo GetCommandInfo (object commandId)
+               internal CommandInfo GetCommandInfo (object commandId, object 
initialTarget)
                {
                        ActionCommand cmd = GetActionCommand (commandId);
                        CommandInfo info = new CommandInfo (cmd);
                        
                        try {
-                               int globalPos;
-                               object cmdTarget = GetFirstCommandTarget (out 
globalPos);
+                               int globalPos = -1;
+                               object cmdTarget = initialTarget != null ? 
initialTarget : GetFirstCommandTarget (out globalPos);
                                
                                while (cmdTarget != null)
                                {
@@ -322,7 +334,7 @@
                        return (ArrayList) overloadedAccelCommands [commandId];
                }
                
-               internal bool DispatchCommandFromAccel (object commandId, 
object dataItem)
+               internal bool DispatchCommandFromAccel (object commandId, 
object dataItem, object initialTarget)
                {
                        // Dispatches a command that has been fired by an 
accelerator.
                        // The difference from a normal dispatch is that there 
may
@@ -336,16 +348,16 @@
                        Command cmd = GetCommand (commandId);
                        string accel = cmd.AccelKey;
                        if (accel == null || accel == "")
-                               return DispatchCommand (commandId, dataItem);
+                               return DispatchCommand (commandId, dataItem, 
initialTarget);
                        
                        ArrayList list = (ArrayList) overloadedAccelCommands 
[accel];
                        if (list == null)
                                // The command is not overloaded, so it can be 
handled normally.
-                               return DispatchCommand (commandId, dataItem);
+                               return DispatchCommand (commandId, dataItem, 
initialTarget);
                        
                        // Get the accelerator used to fire the command and 
make sure it has not changed.
-                       CommandInfo accelInfo = GetCommandInfo (commandId);
-                       bool res = DispatchCommand (commandId, 
accelInfo.DataItem);
+                       CommandInfo accelInfo = GetCommandInfo (commandId, 
initialTarget);
+                       bool res = DispatchCommand (commandId, 
accelInfo.DataItem, initialTarget);
 
                        // If the accelerator has changed, we can't handle 
overloading.
                        if (res || accel != accelInfo.AccelKey)
@@ -357,10 +369,10 @@
                        foreach (object altId in list) {
                                if (altId == commandId) // already handled 
above.
                                        continue;
-                               CommandInfo cinfo = GetCommandInfo (altId);
+                               CommandInfo cinfo = GetCommandInfo (altId, 
initialTarget);
                                if (cinfo.AccelKey != accel)    // Key changed 
by a handler, just ignore the command.
                                        continue;
-                               if (DispatchCommand (altId, cinfo.DataItem))
+                               if (DispatchCommand (altId, cinfo.DataItem, 
initialTarget))
                                        return true;
                        }
                        return false;

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandMenu.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandMenu.cs
    2006-08-08 11:24:22 UTC (rev 63470)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandMenu.cs
    2006-08-08 11:24:40 UTC (rev 63471)
@@ -33,6 +33,7 @@
        public class CommandMenu: Gtk.Menu
        {
                CommandManager manager;
+               object initialCommandTarget;
 
                public CommandMenu (CommandManager manager)
                {
@@ -40,6 +41,11 @@
                        this.AccelGroup = manager.AccelGroup;
                }
                
+               public object InitialCommandTarget {
+                       get { return initialCommandTarget; }
+                       set { initialCommandTarget = value; }
+               }
+               
                internal CommandManager CommandManager {
                        get {
                                if (manager == null) {
@@ -67,7 +73,13 @@
                        base.OnShown ();
                        foreach (Gtk.Widget item in Children) {
                                if (item is ICommandUserItem)
-                                       ((ICommandUserItem)item).Update ();
+                                       ((ICommandUserItem)item).Update 
(initialCommandTarget);
+                               else if (item is Gtk.MenuItem) {
+                                       CommandMenu men = 
((Gtk.MenuItem)item).Submenu as CommandMenu;
+                                       if (men != null)
+                                               men.InitialCommandTarget = 
initialCommandTarget;
+                                       item.Show ();
+                               }
                                else
                                        item.Show ();
                        }

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandMenuItem.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandMenuItem.cs
        2006-08-08 11:24:22 UTC (rev 63470)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandMenuItem.cs
        2006-08-08 11:24:40 UTC (rev 63471)
@@ -41,6 +41,7 @@
                ArrayList itemArray;
                string lastIcon;
                bool wasButtonActivation;
+               object initialTarget;
                
                public CommandMenuItem (object commandId, CommandManager 
commandManager): base ("")
                {
@@ -51,17 +52,19 @@
                                isArray = cmd.CommandArray;
                }
                
-               void ICommandUserItem.Update ()
+               void ICommandUserItem.Update (object initialTarget)
                {
                        if (commandManager != null && !isArrayItem) {
-                               CommandInfo cinfo = 
commandManager.GetCommandInfo (commandId);
+                               CommandInfo cinfo = 
commandManager.GetCommandInfo (commandId, initialTarget);
+                               this.initialTarget = initialTarget;
                                Update (cinfo);
                        }
                }
                
-               void ICommandMenuItem.SetUpdateInfo (CommandInfo cmdInfo)
+               void ICommandMenuItem.SetUpdateInfo (CommandInfo cmdInfo, 
object initialTarget)
                {
                        isArrayItem = true;
+                       this.initialTarget = initialTarget;
                        arrayDataItem = cmdInfo.DataItem;
                        Update (cmdInfo);
                }
@@ -71,7 +74,7 @@
                        base.OnParentSet (parent);
                        if (Parent == null) return;
                        
-                       ((ICommandUserItem)this).Update ();
+                       ((ICommandUserItem)this).Update (null);
                        
                        if (!isArrayItem) {
                                // Make sure the accelerators allways work for 
this item
@@ -96,11 +99,11 @@
                        
                        if (!wasButtonActivation) {
                                // It's being activated by an accelerator.
-                               commandManager.DispatchCommandFromAccel 
(commandId, arrayDataItem);
+                               commandManager.DispatchCommandFromAccel 
(commandId, arrayDataItem, initialTarget);
                        }
                        else {
                                wasButtonActivation = false;
-                               commandManager.DispatchCommand (commandId, 
arrayDataItem);
+                               commandManager.DispatchCommand (commandId, 
arrayDataItem, initialTarget);
                        }
                }
                
@@ -128,7 +131,7 @@
                                                } else {
                                                        item = 
CommandEntry.CreateMenuItem (commandManager, commandId, false);
                                                        ICommandMenuItem mi = 
(ICommandMenuItem) item; 
-                                                       mi.SetUpdateInfo (info);
+                                                       mi.SetUpdateInfo (info, 
initialTarget);
                                                }
                                                menu.Insert (item, ++i);
                                                itemArray.Add (item);
@@ -172,7 +175,7 @@
                                                } else {
                                                        item = 
CommandEntry.CreateMenuItem (commandManager, commandId, false);
                                                        ICommandMenuItem mi = 
(ICommandMenuItem) item; 
-                                                       mi.SetUpdateInfo (info);
+                                                       mi.SetUpdateInfo (info, 
initialTarget);
                                                }
                                                smenu.Add (item);
                                        }

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandToggleToolButton.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandToggleToolButton.cs
        2006-08-08 11:24:22 UTC (rev 63470)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandToggleToolButton.cs
        2006-08-08 11:24:40 UTC (rev 63471)
@@ -35,6 +35,7 @@
                CommandManager commandManager;
                object commandId;
                bool updating;
+               object initialTarget;
                
                public CommandToggleToolButton (object commandId, 
CommandManager commandManager): base ("")
                {
@@ -47,13 +48,14 @@
                        base.OnParentSet (parent);
                        if (Parent == null) return;
 
-                       ((ICommandUserItem)this).Update ();
+                       ((ICommandUserItem)this).Update (null);
                }
                
-               void ICommandUserItem.Update ()
+               void ICommandUserItem.Update (object initialTarget)
                {
                        if (commandManager != null) {
-                               CommandInfo cinfo = 
commandManager.GetCommandInfo (commandId);
+                               CommandInfo cinfo = 
commandManager.GetCommandInfo (commandId, initialTarget);
+                               this.initialTarget = initialTarget;
                                Update (cinfo);
                        }
                }
@@ -66,7 +68,7 @@
                        if (commandManager == null)
                                throw new InvalidOperationException ();
                                
-                       commandManager.DispatchCommand (commandId);
+                       commandManager.DispatchCommand (commandId, null, 
initialTarget);
                }
                
                void Update (CommandInfo cmdInfo)

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandToolButton.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandToolButton.cs
      2006-08-08 11:24:22 UTC (rev 63470)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandToolButton.cs
      2006-08-08 11:24:40 UTC (rev 63471)
@@ -36,6 +36,7 @@
                object commandId;
                static Gtk.Tooltips tips = new Gtk.Tooltips ();
                string lastDesc;
+               object initialTarget;
                
                public CommandToolButton (object commandId, CommandManager 
commandManager): base ("")
                {
@@ -49,13 +50,14 @@
                        base.OnParentSet (parent);
                        if (Parent == null) return;
 
-                       ((ICommandUserItem)this).Update ();
+                       ((ICommandUserItem)this).Update (null);
                }
                
-               void ICommandUserItem.Update ()
+               void ICommandUserItem.Update (object initialTarget)
                {
                        if (commandManager != null) {
-                               CommandInfo cinfo = 
commandManager.GetCommandInfo (commandId);
+                               CommandInfo cinfo = 
commandManager.GetCommandInfo (commandId, initialTarget);
+                               this.initialTarget = initialTarget;
                                Update (cinfo);
                        }
                }
@@ -67,7 +69,7 @@
                        if (commandManager == null)
                                throw new InvalidOperationException ();
                                
-                       commandManager.DispatchCommand (commandId);
+                       commandManager.DispatchCommand (commandId, null, 
initialTarget);
                }
                
                void Update (CommandInfo cmdInfo)

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandToolbar.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandToolbar.cs
 2006-08-08 11:24:22 UTC (rev 63470)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/CommandToolbar.cs
 2006-08-08 11:24:40 UTC (rev 63471)
@@ -33,11 +33,18 @@
 {
        public class CommandToolbar: DockToolbar
        {
+               object initialCommandTarget;
+               
                public CommandToolbar (CommandManager manager, string id, 
string title): base (id, title)
                {
                        manager.RegisterToolbar (this);
                }
                
+               internal object InitialCommandTarget {
+                       get { return initialCommandTarget; }
+                       set { initialCommandTarget = value; }
+               }
+               
                protected override void OnShown ()
                {
                        base.OnShown ();
@@ -48,7 +55,7 @@
                {
                        foreach (Gtk.Widget item in Children) {
                                if (item is ICommandUserItem)
-                                       ((ICommandUserItem)item).Update ();
+                                       ((ICommandUserItem)item).Update 
(initialCommandTarget);
                                else
                                        item.Show ();
                        }

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/ICommandMenuItem.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/ICommandMenuItem.cs
       2006-08-08 11:24:22 UTC (rev 63470)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/ICommandMenuItem.cs
       2006-08-08 11:24:40 UTC (rev 63471)
@@ -32,6 +32,6 @@
 {
        internal interface ICommandMenuItem: ICommandUserItem 
        {
-               void SetUpdateInfo (CommandInfo cmdInfo);
+               void SetUpdateInfo (CommandInfo cmdInfo, object initialTarget);
        }
 }

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/ICommandUserItem.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/ICommandUserItem.cs
       2006-08-08 11:24:22 UTC (rev 63470)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Components/MonoDevelop.Components.Commands/ICommandUserItem.cs
       2006-08-08 11:24:40 UTC (rev 63471)
@@ -32,6 +32,6 @@
 {
        internal interface ICommandUserItem 
        {
-               void Update ();
+               void Update (object initialTarget);
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to