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

List:       kwrite-devel
Subject:    Bookmarks
From:       Tobias =?ISO-8859-1?Q?Gl=E4=DFer?= <tobi.web () gmx ! de>
Date:       2004-05-29 15:57:43
Message-ID: 1085846615.3488.6.camel () dhcppc2
[Download RAW message or body]

Hello folks,

I've made this nice little patch, which makes the bookmarks accessible
from the context menu.

It also has a few implementation benefits:
- Uses <Action /> tags, so the menu can be plugged and unplugged easily
and everywhere.
- Removes the ConnectAndDisconnect mess.
- Doesn't depend on EventFilters anymore.
- Fixes a little display bug, where the Set/Clear Bookmark toggle
  wasn't shown correctly in the context menu.

Greetz...

Tobias Gläßer


["tobgle-bookmarks-action.patch" (tobgle-bookmarks-action.patch)]

? tobgle-bookmarks-action.patch
Index: data/katepartreadonlyui.rc
===================================================================
RCS file: /home/kde/kdelibs/kate/data/katepartreadonlyui.rc,v
retrieving revision 1.25
diff -u -3 -p -r1.25 katepartreadonlyui.rc
--- data/katepartreadonlyui.rc	23 May 2004 17:00:06 -0000	1.25
+++ data/katepartreadonlyui.rc	29 May 2004 15:48:15 -0000
@@ -45,13 +45,7 @@
     <Action name="set_encoding" group="view_operations" />
   </Menu>
 
-  <Menu name="tools" noMerge="1"><text>&amp;Tools</text>
-    <Menu name="bookmarks"><text>&amp;Bookmarks</text>
-      <Action name="bookmarks_toggle" />
-      <Action name="bookmarks_clear" />
-      <Action name="bookmarks_next" />
-      <Action name="bookmarks_previous" />
-    </Menu>
+  <Action name="bookmarks" />
 
     <Separator group="tools_operations" />
     <Action name="set_filetype" group="tools_operations" />
@@ -88,7 +82,7 @@
   <Action name="edit_copy" group="popup_operations" />
   <Action name="edit_paste" group="popup_operations" />
   <Separator group="popup_operations" />
-  <Action name="bookmarks_toggle" group="popup_operations" />
+  <Action name="bookmarks" group="popup_operations" />
   <Separator group="popup_operations" />
 </Menu>
 
Index: data/katepartui.rc
===================================================================
RCS file: /home/kde/kdelibs/kate/data/katepartui.rc,v
retrieving revision 1.64
diff -u -3 -p -r1.64 katepartui.rc
--- data/katepartui.rc	23 May 2004 17:00:06 -0000	1.64
+++ data/katepartui.rc	29 May 2004 15:48:15 -0000
@@ -55,13 +55,9 @@
     <Separator group="view_operations" />
     <Action name="set_encoding" group="view_operations" />
   </Menu>
+ 
 
-  <Menu name="bookmarks"><text>&amp;Bookmarks</text>
-    <Action name="bookmarks_toggle" />
-    <Action name="bookmarks_clear" />
-    <Action name="bookmarks_next" />
-    <Action name="bookmarks_previous" />
-  </Menu>
+  <Action name="bookmarks" />
 
   <Menu name="tools" noMerge="1"><text>&amp;Tools</text>
     <Action name="tools_toggle_write_lock" group="tools_operations" />
@@ -92,7 +88,7 @@
   </Menu>
 </MenuBar>
 
-<Menu name="ktexteditor_popup" noMerge="1">
+<Menu name="ktexteditor_popup" noMerge="0">
   <Action name="edit_undo" group="popup_operations" />
   <Action name="edit_redo" group="popup_operations" />
   <Separator group="popup_operations" />
@@ -100,7 +96,7 @@
   <Action name="edit_copy" group="popup_operations" />
   <Action name="edit_paste" group="popup_operations" />
   <Separator group="popup_operations" />
-  <Action name="bookmarks_toggle" group="popup_operations" />
+  <Action name="bookmarks" group="popup_operations" />
   <Separator group="popup_operations" />
 </Menu>
 
Index: part/katebookmarks.cpp
===================================================================
RCS file: /home/kde/kdelibs/kate/part/katebookmarks.cpp,v
retrieving revision 1.38
diff -u -3 -p -r1.38 katebookmarks.cpp
--- part/katebookmarks.cpp	21 May 2004 20:10:21 -0000	1.38
+++ part/katebookmarks.cpp	29 May 2004 15:48:16 -0000
@@ -64,7 +64,6 @@ KateBookmarks::KateBookmarks( KateView* 
   , m_sorting( sort )
 {
   connect (view->getDoc(), SIGNAL(marksChanged()), this, SLOT(marksChanged()));
-  m_view->installEventFilter( this );
   _tries=0;
   m_bookmarksMenu = 0L;
 }
@@ -99,67 +98,17 @@ void KateBookmarks::createActions( KActi
     this, SLOT(goPrevious()),
     ac, "bookmarks_previous");
   m_goPrevious->setWhatsThis(i18n("Go to the previous bookmark."));
+  
+  m_bookmarksMenu = (new KActionMenu(i18n("Bookmarks"), ac, \
"bookmarks"))->popupMenu();  
-  marksChanged ();
-}
-
-bool KateBookmarks::eventFilter( QObject *o, QEvent *e )
-{
-  if ( o == m_view && e->type() == QEvent::Show )
-    connectMenuAndDisConnectAgain();
-  return false;
-}
-
-
-void KateBookmarks::connectMenuAndDisConnectAgain()
-{
-  kdDebug()<<"KateBookmarks::connectMenuAndDisConnectAgain()"<<endl;
-
-  if (m_view->factory())
-    {
-        QPtrList<KXMLGUIClient> clients = m_view->factory()->clients();
-        QPtrListIterator<KXMLGUIClient> it(clients);
-        KXMLGUIClient *client;
-        while ((client = it.current()) != 0)
-        {
-            m_bookmarksMenu = \
                static_cast<QPopupMenu*>(client->factory()->container("bookmarks", \
                client));
-
-            if (m_bookmarksMenu)
-            {
-                // connect bookmarks menu aboutToshow
-                disconnect( m_bookmarksMenu, SIGNAL(aboutToShow()),
-                        0, 0);
-                connect( m_bookmarksMenu, SIGNAL(aboutToShow()),
-                        this, SLOT(bookmarkMenuAboutToShow()));
-
-                // anders: I ensure the next/prev actions are available
-                // and reset their texts (for edit shortcuts dialog, call me \
                picky!).
-                // TODO - come up with a better solution, please anyone?
-                disconnect( m_bookmarksMenu, SIGNAL(aboutToHide()),
-                        0, 0);
-                connect( m_bookmarksMenu, SIGNAL(aboutToHide()),
-                        this, SLOT(bookmarkMenuAboutToHide()) );
-
-                // ### don't remove the event filter, since in kate we will \
                otherwise loose
-                // the document menu :(
-          //      m_view->removeEventFilter( this );
-                return;
-            }
-            ++it;
-         }
-    }
-
-    // FUCKY-SUCKY -- try later
-    if ( _tries > 4 ) // give up
-    {
-      m_view->removeEventFilter( this );
-      return;
-    }
-
-    if ( m_view->isVisible() )
-      QTimer::singleShot( 0, this, SLOT(connectMenuAndDisConnectAgain()));
+  //connect the aboutToShow() and aboutToHide() signals with
+  //the bookmarkMenuAboutToShow() and bookmarkMenuAboutToHide() slots
+  disconnect( m_bookmarksMenu, SIGNAL(aboutToShow()), 0, 0);
+  connect( m_bookmarksMenu, SIGNAL(aboutToShow()), this, \
SLOT(bookmarkMenuAboutToShow())); +  disconnect( m_bookmarksMenu, \
SIGNAL(aboutToHide()), 0, 0); +  connect( m_bookmarksMenu, SIGNAL(aboutToHide()), \
this, SLOT(bookmarkMenuAboutToHide()) );  
-    _tries++;
+  marksChanged ();
 }
 
 void KateBookmarks::toggleBookmark ()
@@ -183,27 +132,21 @@ void KateBookmarks::clearBookmarks ()
   marksChanged ();
 }
 
-void KateBookmarks::bookmarkMenuAboutToShow()
+void KateBookmarks::insertBookmarksInMenu( QPopupMenu& menu)
 {
-  QPtrList<KTextEditor::Mark> m = m_view->getDoc()->marks();
-
-  m_bookmarksMenu->clear();
-  m_bookmarkToggle->setChecked( m_view->getDoc()->mark( m_view->cursorLine() )
-                                & KTextEditor::MarkInterface::markType01 );
-  m_bookmarkToggle->plug( m_bookmarksMenu );
-  m_bookmarkClear->plug( m_bookmarksMenu );
-  KTextEditor::Mark *next = 0;
-  KTextEditor::Mark *prev = 0;
   uint line = m_view->cursorLine();
-
   const QRegExp re("&(?!&)");
-
   int idx( -1 );
+  int old_menu_count = menu.count();
+  KTextEditor::Mark *next = 0;
+  KTextEditor::Mark *prev = 0;
+
+  QPtrList<KTextEditor::Mark> m = m_view->getDoc()->marks();
   QMemArray<uint> sortArray( m.count() );
   QPtrListIterator<KTextEditor::Mark> it( m );
 
   if ( it.count() > 0 )
-    m_bookmarksMenu->insertSeparator();
+    menu.insertSeparator();
 
   for( int i = 0; *it; ++it, ++i )
   {
@@ -211,7 +154,7 @@ void KateBookmarks::bookmarkMenuAboutToS
     {
       QString bText = KStringHandler::rEmSqueeze
                       ( m_view->getDoc()->textLine( (*it)->line ),
-                        m_bookmarksMenu->fontMetrics(), 32 );
+                        menu.fontMetrics(), 32 );
       bText.replace(re, "&&"); // kill undesired accellerators!
 
       if ( m_sorting == Position )
@@ -221,7 +164,7 @@ void KateBookmarks::bookmarkMenuAboutToS
         idx = sortArray.find( (*it)->line ) + 3;
       }
 
-      m_bookmarksMenu->insertItem(
+      menu.insertItem(
           QString("%1 - \"%2\"").arg( (*it)->line+1 ).arg( bText ),
           m_view, SLOT(gotoLineNumber(int)), 0, (*it)->line, idx );
 
@@ -239,23 +182,39 @@ void KateBookmarks::bookmarkMenuAboutToS
     }
   }
 
-  idx = 3;
+  idx = ++old_menu_count;
   if ( next )
   {
     m_goNext->setText( i18n("&Next: %1 - \"%2\"").arg( next->line + 1 )
         .arg( KStringHandler::rsqueeze( m_view->getDoc()->textLine( next->line ), 24 \
                ) ) );
-    m_goNext->plug( m_bookmarksMenu, idx );
+    m_goNext->plug( &menu, idx );
     idx++;
   }
   if ( prev )
   {
     m_goPrevious->setText( i18n("&Previous: %1 - \"%2\"").arg(prev->line + 1 )
         .arg( KStringHandler::rsqueeze( m_view->getDoc()->textLine( prev->line ), 24 \
                ) ) );
-    m_goPrevious->plug( m_bookmarksMenu, idx );
+    m_goPrevious->plug( &menu, idx );
     idx++;
   }
   if ( next || prev )
-    m_bookmarksMenu->insertSeparator( idx );
+    menu.insertSeparator( idx );
+
+}
+
+void KateBookmarks::bookmarkMenuAboutToShow()
+{
+
+  QPtrList<KTextEditor::Mark> m = m_view->getDoc()->marks();
+
+  m_bookmarksMenu->clear();
+  m_bookmarkToggle->setChecked( m_view->getDoc()->mark( m_view->cursorLine() )
+                                & KTextEditor::MarkInterface::markType01 );
+  m_bookmarkToggle->plug( m_bookmarksMenu );
+  m_bookmarkClear->plug( m_bookmarksMenu );
+
+
+  insertBookmarksInMenu(*m_bookmarksMenu);
 }
 
 /*
Index: part/katebookmarks.h
===================================================================
RCS file: /home/kde/kdelibs/kate/part/katebookmarks.h,v
retrieving revision 1.18
diff -u -3 -p -r1.18 katebookmarks.h
--- part/katebookmarks.h	21 May 2004 20:10:21 -0000	1.18
+++ part/katebookmarks.h	29 May 2004 15:48:16 -0000
@@ -31,6 +31,7 @@ class KAction;
 class KToggleAction;
 class KActionCollection;
 class QPopupMenu;
+class QMenuData;
 
 class KateBookmarks : public QObject
 {
@@ -47,7 +48,7 @@ class KateBookmarks : public QObject
     void setSorting( Sorting s ) { m_sorting = s; };
 
   protected:
-    bool eventFilter( QObject *, class QEvent* );
+    void insertBookmarksInMenu( QPopupMenu& menu);
 
   private slots:
     void toggleBookmark();
@@ -60,7 +61,6 @@ class KateBookmarks : public QObject
     void goPrevious();
 
     void marksChanged ();
-    void connectMenuAndDisConnectAgain();
 
   private:
     KateView*                    m_view;
@@ -68,6 +68,7 @@ class KateBookmarks : public QObject
     KAction*                     m_bookmarkClear;
     KAction*                     m_goNext;
     KAction*                     m_goPrevious;
+
     Sorting                      m_sorting;
     QPopupMenu*          m_bookmarksMenu;
 



_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel


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

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