Patch to add key shourtcut names to action's tooltips
Lyubitskiy Alex
lalekz at gmail.com
Wed May 10 15:24:49 UTC 2006
Hmm, it's stange because I attached patch file to the letter.
Anyway, here is it:
Index: src/mainwindowshare.h
===================================================================
--- src/mainwindowshare.h (revision 539267)
+++ src/mainwindowshare.h (working copy)
@@ -36,6 +36,7 @@
void createActions();
void init();
+ void configureKeyTips();
public slots:
void slotGUICreated( KParts::Part * );
Index: src/mainwindowshare.cpp
===================================================================
--- src/mainwindowshare.cpp (revision 539267)
+++ src/mainwindowshare.cpp (working copy)
@@ -191,7 +191,32 @@
KDevPartController * partController = API::getInstance()->partController();
connect( partController, SIGNAL(activePartChanged(KParts::Part*)), this,
SLOT(slotActivePartChanged(KParts::Part* )) );
}
+
+void MainWindowShare::configureKeyTips()
+{
+ QPtrList<KXMLGUIClient> clients = m_pMainWnd->guiFactory()->clients();
+ for( QPtrListIterator<KXMLGUIClient> it( clients );
+ it.current(); ++it ) {
+ KActionCollection *actionCollection = (*it)->actionCollection();
+ for (int i = 0; i < actionCollection->count(); i++) {
+ KAction *action = actionCollection->action(i);
+
+ QString tooltip = action->toolTip();
+ if (tooltip.isEmpty())
+ tooltip = action->text().remove('&');
+ else {
+ int i = tooltip.findRev('(');
+ if (i > 0) tooltip = tooltip.left(i).stripWhiteSpace();
+ }
+ QString shortcut = action->shortcutText();
+ if (!shortcut.isEmpty())
+ tooltip += " (" + shortcut + ")";
+ action->setToolTip(tooltip);
+ }
+ }
+}
+
void MainWindowShare::slotReportBug()
{
KBugReport a(m_pMainWnd, true, KGlobal::instance()->aboutData() );
@@ -400,6 +425,8 @@
disconnect( action, SIGNAL(activated()), 0, 0 );
connect( action, SIGNAL(activated()), PartController::getInstance(),
SLOT(slotReload()) );
}
+
+ configureKeyTips();
}
// called when OK ar Apply is clicked in the EditToolbar Dialog
@@ -444,6 +471,7 @@
++it;
}
}
+ configureKeyTips();
}
}
Thanks, Lyubitskiy Alex
On 5/10/06, Jens Dagerbo wrote:
> Sounds like a good idea. But I think you forgot the patch... :)
>
> // jens
>
> On 5/10/06, Innocent <lalekz at gmail.com> wrote:
> > Hello,
> > A lot of functions in KDevelop have key shortcuts, and I think it's a
> > good idea to add shortcut names to the tooltips of the actions. For
> > example, instead of "Fullscreen" the tooltip for the "fullscreen" toolbar
> > action will contain "Fullscreen (Ctrl+Shift+F)".
> > At the moment, debugger component, for example, has hardcoded names
> > of shortcuts in its tooltips.
> > Of course, the best way is to ask kdelibs developers to add that feature
> > to KAction class. However, this can be only done for KDE4.
> > For the time being I offer the attached patch which just adds shortcut
> > names to existing tooltips by traversing all KParts and all actions in
> > their actionCollection()s. It also refreshes tips when one reconfigures
> > key shourtcuts by the dialog.
> >
> > Any comments?
> >
> > Thanks,
> > Alex Lyubitskiy
More information about the KDevelop-devel
mailing list