safer way of creating actions, according to mjansen

svn path=/trunk/KDE/kdelibs/; revision=963095
This commit is contained in:
Chani Armitage 2009-05-03 22:13:05 +00:00
parent 0768ea626d
commit 233e220ad9
4 changed files with 32 additions and 16 deletions

View File

@ -1417,15 +1417,15 @@ KActionCollection* AppletPrivate::defaultActions(QObject *parent)
KActionCollection *actions = new KActionCollection(parent);
actions->setConfigGroup("Shortcuts-Applet");
KAction *configAction = new KAction(i18n("Widget Settings"), actions);
KAction *configAction = actions->addAction("configure");
configAction->setText(i18n("Widget Settings"));
configAction->setIcon(KIcon("configure"));
configAction->setShortcut(KShortcut("alt+d, s"));
actions->addAction("configure", configAction);
KAction *closeApplet = new KAction("Remove this Widget", actions);
KAction *closeApplet = actions->addAction("remove");
closeApplet->setText("Remove this Widget");
closeApplet->setIcon(KIcon("edit-delete"));
closeApplet->setShortcut(KShortcut("alt+d, r"));
actions->addAction("remove", closeApplet);
return actions;
}

View File

@ -226,26 +226,26 @@ void ContainmentPrivate::addDefaultActions(KActionCollection *actions)
}
//add our own actions
KAction *appletBrowserAction = new KAction(i18n("Add Widgets..."), actions);
KAction *appletBrowserAction = actions->addAction("add widgets");
appletBrowserAction->setText(i18n("Add Widgets..."));
appletBrowserAction->setIcon(KIcon("list-add"));
appletBrowserAction->setShortcut(KShortcut("alt+d, a"));
actions->addAction("add widgets", appletBrowserAction);
KAction *action = new KAction(i18n("Next Widget"), actions);
KAction *action = actions->addAction("next applet");
action->setText(i18n("Next Widget"));
//no icon
action->setShortcut(KShortcut("alt+d, n"));
actions->addAction("next applet", action);
action = new KAction(i18n("Previous Widget"), actions);
action = actions->addAction("previous applet");
action->setText(i18n("Previous Widget"));
//no icon
action->setShortcut(KShortcut("alt+d, p"));
actions->addAction("previous applet", action);
KAction *zoomAction = new KAction(i18n("Zoom In"), actions);
KAction *zoomAction = actions->addAction("zoom in");
zoomAction->setText(i18n("Zoom In"));
zoomAction->setIcon(KIcon("zoom-in"));
//two shortcuts because I hate ctrl-+ but others expect it
zoomAction->setShortcuts(KShortcut("alt+d, +; alt+d, ="));
actions->addAction("zoom in", zoomAction);
}

View File

@ -84,24 +84,24 @@ public:
//some common actions
actions.setConfigGroup("Shortcuts");
KAction *lockAction = new KAction(i18n("Lock Widgets"), q);
KAction *lockAction = actions.addAction("lock widgets");
lockAction->setText(i18n("Lock Widgets"));
lockAction->setIcon(KIcon("object-locked"));
QObject::connect(lockAction, SIGNAL(triggered(bool)),
q, SLOT(toggleImmutability()));
lockAction->setShortcut(KShortcut("alt+d, l"));
lockAction->setShortcutContext(Qt::ApplicationShortcut);
actions.addAction("lock widgets", lockAction);
//FIXME this doesn't really belong here. desktop KCM maybe?
//but should the shortcuts be per-app or really-global?
//I don't know how to make kactioncollections use plasmarc
KAction *action = new KAction(i18n("Shortcut Settings"), q);
KAction *action = actions.addAction("configure shortcuts");
action->setText(i18n("Shortcut Settings"));
action->setIcon(KIcon("configure"));
QObject::connect(action, SIGNAL(triggered()),
q, SLOT(showShortcutConfig()));
//action->setShortcut(KShortcut("ctrl+h"));
action->setShortcutContext(Qt::ApplicationShortcut);
actions.addAction("configure shortcuts", action);
actions.readSettings();
@ -685,6 +685,11 @@ void Corona::addAction(QString name, QAction *action)
d->actions.addAction(name, action);
}
KAction* Corona::addAction(QString name)
{
return d->actions.addAction(name);
}
QList<QAction*> Corona::actions() const
{
return d->actions.actions();

View File

@ -30,6 +30,8 @@
class QGraphicsGridLayout;
class QAction;
class KAction;
namespace Plasma
{
@ -201,6 +203,15 @@ public:
*/
void addShortcuts(KActionCollection *newShortcuts);
/**
* @since 4.3
* Creates an action in our collection under the given name
* @return the new action
* FIXME I'm wrapping so much of kactioncollection API now, maybe I should just expose the
* collection itself :P
*/
KAction* addAction(QString name);
public Q_SLOTS:
/**
* Initializes the layout from a config file. This will first clear any existing