Patch #917 2006-03-12 17:00

pecan

Allow others to Enable/Disable items on toolbar
Download
917-Allow_others_to.patch (7.8 KB)
Category
 
Status
Out of date
Close date
2007-04-12 11:29
Assigned to
 
Index: src/sdk/manager.cpp
===================================================================
--- src/sdk/manager.cpp    (revision 2174)
+++ src/sdk/manager.cpp    (working copy)
@@ -50,6 +50,11 @@
 
 #include <wx/toolbar.h>
 
+int idEditUndo = XRCID("idEditUndo");
+int idEditRedo = XRCID("idEditRedo");
+int idEditCopy = XRCID("idEditCopy");
+int idEditCut = XRCID("idEditCut");
+int idEditPaste = XRCID("idEditPaste");
 
 
 
@@ -281,7 +286,80 @@
     return CfgMgrBldr::GetConfigManager(name_space);
 }
 
+// Allow others to request to disable/enable items on the main toolbar      //pecan 2006/03/13
+void Manager::SetMainMenuRequest(bool Enable, int MenuItem )            //pecan 2006/03/13
+{
+    if (Enable)
+    {
+        if (MenuItem == idEditUndo)  ++MenuUndoSetRequests;
+        if (MenuItem == idEditRedo)  ++MenuRedoSetRequests;
+        if (MenuItem == idEditCopy)  ++MenuCopySetRequests;
+        if (MenuItem == idEditCut )  ++MenuCutSetRequests;
+        if (MenuItem == idEditPaste) ++MenuPasteSetRequests;
+    }
+    else
+    {
+        if (MenuItem == idEditUndo)  {if (MenuUndoSetRequests)  --MenuUndoSetRequests;  }
+        if (MenuItem == idEditRedo)  {if (MenuRedoSetRequests)  --MenuRedoSetRequests;  }
+        if (MenuItem == idEditCopy)  {if (MenuCopySetRequests)  --MenuCopySetRequests;  }
+        if (MenuItem == idEditCut )  {if (MenuCutSetRequests)   --MenuCutSetRequests;   }
+        if (MenuItem == idEditPaste) {if (MenuPasteSetRequests) --MenuPasteSetRequests; }
+    }
+}
+void Manager::SetMainToolbarRequest(bool Enable, int ToolbarItem )      //pecan 2006/03/13
+{
+    if (Enable)
+    {
+        if (ToolbarItem == idEditUndo)  ++ToolbarUndoSetRequests;
+        if (ToolbarItem == idEditRedo)  ++ToolbarRedoSetRequests;
+        if (ToolbarItem == idEditCopy)  ++ToolbarCopySetRequests;
+        if (ToolbarItem == idEditCut )  ++ToolbarCutSetRequests;
+        if (ToolbarItem == idEditPaste) ++ToolbarPasteSetRequests;
+    }
+    else
+    {
+        if (ToolbarItem == idEditUndo)  {if (ToolbarUndoSetRequests)  --ToolbarUndoSetRequests;  }
+        if (ToolbarItem == idEditRedo)  {if (ToolbarRedoSetRequests)  --ToolbarRedoSetRequests;  }
+        if (ToolbarItem == idEditCopy)  {if (ToolbarCopySetRequests)  --ToolbarCopySetRequests;  }
+        if (ToolbarItem == idEditCut )  {if (ToolbarCutSetRequests)   --ToolbarCutSetRequests;   }
+        if (ToolbarItem == idEditPaste) {if (ToolbarPasteSetRequests) --ToolbarPasteSetRequests; }
+    }
+}
 
+// Return count of disable/enable request for the main toolbar              //pecan 2006/03/13
+int  Manager::GetMainMenuSetRequests(int MenuItem)                          //pecan 2006/03/13
+{
+    if (MenuItem == idEditUndo)  return MenuUndoSetRequests;
+    if (MenuItem == idEditRedo)  return MenuRedoSetRequests;
+    if (MenuItem == idEditCopy)  return MenuCopySetRequests;
+    if (MenuItem == idEditCut )  return MenuCutSetRequests;
+    if (MenuItem == idEditPaste) return MenuPasteSetRequests;
+    return 0;
+}
+int  Manager::GetMainToolbarSetRequests(int ToolbarItem)                    //pecan 2006/03/13
+{
+    if (ToolbarItem == idEditUndo)  return ToolbarUndoSetRequests;
+    if (ToolbarItem == idEditRedo)  return ToolbarRedoSetRequests;
+    if (ToolbarItem == idEditCopy)  return ToolbarCopySetRequests;
+    if (ToolbarItem == idEditCut )  return ToolbarCutSetRequests;
+    if (ToolbarItem == idEditPaste) return ToolbarPasteSetRequests;
+    return 0;
+}
+
 bool Manager::appShuttingDown = false;
 bool Manager::blockYields = false;
 bool Manager::isBatch = false;
+
+// Reference counts of requests to set Menu/Tool items
+// from plugins and other windows
+int  Manager::MenuUndoSetRequests     = 0;
+int  Manager::MenuRedoSetRequests     = 0;
+int  Manager::MenuCutSetRequests      = 0;
+int  Manager::MenuCopySetRequests     = 0;
+int  Manager::MenuPasteSetRequests    = 0;
+
+int  Manager::ToolbarUndoSetRequests  = 0;
+int  Manager::ToolbarRedoSetRequests  = 0;
+int  Manager::ToolbarCutSetRequests   = 0;
+int  Manager::ToolbarCopySetRequests  = 0;
+int  Manager::ToolbarPasteSetRequests = 0;
Index: src/sdk/manager.h
===================================================================
--- src/sdk/manager.h    (revision 2174)
+++ src/sdk/manager.h    (working copy)
@@ -39,7 +39,19 @@
     static bool appShuttingDown;
     static bool blockYields;
     static bool isBatch;
+    static int  Manager::MenuUndoSetRequests;                  //pecan 2006/03/13
+    static int  Manager::MenuRedoSetRequests;
+    static int  Manager::MenuCutSetRequests;
+    static int  Manager::MenuCopySetRequests;
+    static int  Manager::MenuPasteSetRequests;
 
+    static int  Manager::ToolbarUndoSetRequests;
+    static int  Manager::ToolbarRedoSetRequests;
+    static int  Manager::ToolbarCutSetRequests;
+    static int  Manager::ToolbarCopySetRequests;
+    static int  Manager::ToolbarPasteSetRequests;
+
+
     Manager();
     ~Manager();
 
@@ -115,6 +127,13 @@
download for full patch...
pecan 2006-03-12 17:01

Since SetToolBar() cannot be used in CodeBlocks without

mangling the layout, this patch sets the MainFrame

toolbar address in Manager so a user/plugin can use

Manager::Get()->GetMainToolbar(). It allows the user

to enable/disable cut/copy/paste etc.

thanks

pecan

mandrav 2006-03-13 09:54

Plugins are not allowed to alter toolbar items not belonging to them.

What would this help you to achieve?

pecan 2006-03-13 15:07

I'm writing a plugin to copy/paste/drag/drop items to/from the project windows panel. I'ts called ScrapList (using treeListCtrl like a scrap book), and holds items that can fall off the "recent" menu items.

In future, it will hold snippets of code dragged from the editors, file/project/workspace names copied/dragged from the project panels, and editor marks set by bookmark/debugger etc. These will all be reset by dragging/copying back into the project panels.

It needs to enable/disable copy/paste drag/drop from both the menu items (already done) and the toolbar items to be consistent. This is done by chaining drag/drop and handing them off to the MainFrame drag/drop target. MainFrame thinks the user did it from the menu/toolbar.

It seems to me that a printer plugin should be able to enable the printer icon on the tool bar; that a cut/paste plugin on any window should be able to set copy/paste etc.

I could put up a toolbar but I think it'd look awfully dumb for plugins to put up multiple toolbars/menus with copy/paste on 'em.

thanks

pecan

pecan 2006-03-13 21:22

Been playing in the CB debugger. It sure would be nice if the debugger would enable copy/paste so we could document some of our bugs. As it is now, I have to get out of the CB debugger and back into the command line GDB to copy/paste a backtrace.

The menu copy/paste and (most) tool bar items are used so ubiqitously that any serious plugin should be able to offer its services to the user.

It is going to be so confusing to the user to have to choose between toolbars for common actions.

If directly manipulating a "non-owned" windows toolbar is not acceptable, is there something that I could code up that would allow arbiter code to hide or show or grant requests to show/enable/disable items on the main toolbar?

thanks

pecan

pecan 2006-03-13 21:56

How about an interface call from plugins to Manager that request enable/disabling the menu/tool bar cut/copy/paste/print/do/undo items.

Something like "Manager::Get->PleaseEnable(menucopyitem | toolbarpasteitem);" Or Manager::Get->PleaseDisable...etc etc.

Manger could monitor the situation with reference counting like freeze/thaw. MainFrame::UpdateUI would look at the request flags kept by Manager and enable/disable as it sees fit.

Thanks

pecan

pecan 2006-03-14 06:03

I have re-written the patch so that others can *requests* MainFrame::UpdateUI to enable/disable the menu/toolbar cut/copy/paste/undo/redo.

I hope this is more acceptable to the CB philosophy.

thanks

pecan

mandrav 2006-03-14 22:01

OK, I see your point, although I think your DragScroll plugin will "betray" you here since it auto-focuses the editor window ;)

Let me think it over. I 'd like to generalize this a bit...