[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    PATCH: "configure toolbars" in toolbar context menu
From:       Hans Meine <hans_meine () gmx ! net>
Date:       2001-07-13 12:07:18
[Download RAW message or body]

Hi!

For a long time, I was wondering, why there was no "configure
toolbars" in the context menu. I think this is much more intuitive.

Now I looked into it and prepared a patch, but there are some things I
find not so nice and want to note:

1) Finding the right action is not really failsave. I thought most
programs would use the standardaction, but those I looked into
explicitely gave it another name ("configuretoolbars"). I thought
about it and made it possible to give the right action to the toolbar.
If this is not done, the toolbar looks for the stdname and
"configuretoolbars" in the actionCollection (which it has to look for,
too). Maybe this is not nice, but it makes it work out-of-the-box in
many programs (konq, koffice, ...)

2) KToolBar::mousePressEvent might wonder about the clicked ID, one of
the other authors could have a look at if this is OK.

3) Even more nice would be, if the menu entry could fire up the
toolbar editor with the right toolbar pre-selected. /me thinks this
should be done _somehow_ in the future, but maybe my patch is better
than nothing. (Maybe one of the gurus decides opening the toolbar
editor with this specific option directly would be feasible and more
elegant, too?)

Please try the patch and be as happy as I am with it! ;-)

-- 
Ciao,  /  /
      /--/
     /  / ANS                          .,* Hamburg, Germany *,.


["ktoolbar.diff" (text/x-patch)]

Index: ktoolbar.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/ktoolbar.h,v
retrieving revision 1.131
diff -b -u -3 -p -d -r1.131 ktoolbar.h
--- ktoolbar.h	2001/03/31 12:06:47	1.131
+++ ktoolbar.h	2001/07/13 12:05:17
@@ -50,6 +50,7 @@ class KPopupMenu;
 class KInstance;
 class KComboBox;
 class KXMLGUIClient;
+class KAction;
 
 class KToolBarPrivate;
 
@@ -917,6 +918,14 @@ public:
   //  void setXML(const QString& xmlfile, const QDomDocument& xml);
   /* @internal */
     void setXMLGUIClient( KXMLGUIClient *client );
+
+  /**
+   * Gives the "configure toolbars" action to the toolbar to plug
+   * it in it´s context menu. If you don´t call this, it will try
+   * to find it in the XMLGUIClient´s actionCollection by the std
+   * name or the name "configuretoolbars".
+   */
+    void setConfigureAction( KAction *configureAction );
 
   /**
    * Assign a (translated) text to this toolbar. This is used
Index: ktoolbar.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/ktoolbar.cpp,v
retrieving revision 1.265
diff -b -u -3 -p -d -r1.265 ktoolbar.cpp
--- ktoolbar.cpp	2001/05/27 10:23:52	1.265
+++ ktoolbar.cpp	2001/07/13 12:05:39
@@ -1,6 +1,6 @@
 /* This file is part of the KDE libraries
     Copyright
-    (C) 2000 Reinald Stadlbauer (reggie@kde.org)
+    (C) 2000 Reginald Stadlbauer (reggie@kde.org)
     (C) 1997, 1998 Stephan Kulow (coolo@kde.org)
     (C) 1997, 1998 Mark Donohoe (donohoe@kde.org)
     (C) 1997, 1998 Sven Radej (radej@kde.org)
@@ -41,6 +41,8 @@
 #include "kseparator.h"
 #include <klocale.h>
 #include <kapp.h>
+#include <kaction.h>
+#include <kstdaction.h>
 #include <kglobal.h>
 #include <kconfig.h>
 #include <kiconloader.h>
@@ -83,6 +85,8 @@ public:
         m_enableContext  = true;
 
         m_xmlguiClient   = 0;
+        m_configureAction = 0;
+        m_configurePlugged = false;
         hasRealPos = FALSE;
 
         oldPos = QMainWindow::Unmanaged;
@@ -107,6 +111,8 @@ public:
     QMainWindow::ToolBarDock oldPos;
 
     KXMLGUIClient *m_xmlguiClient;
+    KAction *m_configureAction;
+    bool m_configurePlugged;
 
     bool modified;
     bool positioned;
@@ -1127,6 +1133,10 @@ void KToolBar::setXMLGUIClient( KXMLGUIC
     d->m_xmlguiClient = client;
 }
 
+void KToolBar::setConfigureAction( KAction *configureAction )
+{
+    d->m_configureAction = configureAction;
+}
 
 void KToolBar::setText( const QString & txt )
 {
@@ -1194,7 +1204,7 @@ void KToolBar::mousePressEvent ( QMouseE
                 if ( i >= CONTEXT_ICONSIZES )
                     setIconSize( i - CONTEXT_ICONSIZES );
                 else
-                    kdWarning(220) << "No such menu item " << i << " in toolbar \
context menu" << endl; +                    return; // assume this was "configure \
toolbars", no need for setSettingsDirty()  }
             if ( mw->inherits("KMainWindow") )
                 static_cast<KMainWindow *>(mw)->setSettingsDirty();
@@ -1989,6 +1999,29 @@ KPopupMenu *KToolBar::contextMenu()
 
 void KToolBar::slotContextAboutToShow()
 {
+  if (!d->m_configurePlugged)
+  {
+    if (!d->m_configureAction)
+    {
+      // fallback: try to find "configure toolbars" action
+      KXMLGUIClient *xmlGuiClient = d->m_xmlguiClient;
+      if ( !xmlGuiClient && parentWidget() && parentWidget()->inherits( \
"KMainWindow" ) ) +        xmlGuiClient = (KMainWindow *)parentWidget();
+      if ( xmlGuiClient )
+      {
+        d->m_configureAction = \
xmlGuiClient->actionCollection()->action(KStdAction::stdName(KStdAction::ConfigureToolbars));
 +        if (!d->m_configureAction) // somehow this is ugly, but many progs \
explicitely name it "configuretoolbars" +          d->m_configureAction = \
xmlGuiClient->actionCollection()->action("configuretoolbars"); +      }
+    }
+    // "configure toolbars" action known/found, but not yet plugged
+    if ( d->m_configureAction )
+    {
+        d->m_configureAction->plug(context);
+        d->m_configurePlugged = true;
+    }
+  }
+  
   for(int i = CONTEXT_ICONS; i <= CONTEXT_TEXTUNDER; ++i)
     context->setItemChecked(i, false);
 



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic