The future of KAction
Simon Hausmann
hausmann at kde.org
Sat Nov 19 10:55:34 GMT 2005
On Tuesday 15 November 2005 18:53, Alexander Dymo wrote:
> On Tuesday 15 November 2005 15:02, Simon Hausmann wrote:
> > GuiEditor editor(this);
> > editor.startMenuBar();
> > editor.startMenu("file", "&File");
> > editor.addAction(newDocumentAction);
> > editor.addAction(fileOpenAction);
> > editor.addSeparator();
> > editor.startMenu("printTo", "&Print To");
> > editor.addActions(KPrinter::printToActions());
> > editor.menuFinished();
> > editor.addSeparator();
> > editor.addAction(quitAction);
> > editor.menuFinished();
> > ...
> > editor.startMenu("settings", "&Settings");
> > ...
> > editor.addActionGroup("plugin settings");
> > ...
> > editor.menuFinished();
> > ...
> > editor.menuFinished();
> > editor.startToolBar();
> > editor.addAction(newDocumentAction);
> > editor.addSeparator();
> > editor.addWidget(searchComboBox);
> > editor.show();
>
> That's much better than xml IMHO.
>
> > void Plugin::buildGui()
> > {
> > GuiEditor editor(this);
> >
> > editor.startMenuBar();
> > // .. in case the application doesn't want us to populate
> > // the settings menu or doesn't provide one in the first place
> > if (editor.tryToEditMenu("settings")) {
> > editor.addActionToGroup("plugin settings", mySettingsAction);
>
> Why do we need to call ::tryToEditMenu()? Plugin should never care whether
> the host application wants or doesn't want to add an action. It should
> just call
> editor.addActionToGroup("plugin settings", mySettingsAction);
Yes, I think you're right, placeholders should be global.
> If you really want to know whether your action was added, you can
> make ::addActionToGroup return bool.
>
>
> The application's part looks as following IMO:
>
> void MyWindow::setupUi() {
> GuiEditor editor(this);
> ...
> editor.installActionFilter(this); // not really necessary
> //because we used GuiEditor::GuiEditor(this)
> }
>
> bool MyWindow::actionFilter(KAction *action, const QString &menu,
> const QString &group)
> {
> if (menu == "settings")
> return false;
> else if ((menu == "view") && (group == "navigation"))
> {
> if (action->objectName() == "go back")
> return false;
> return true;
> }
> return true;
> }
I think it would be a lot easier to just make addActionGroup on the plugin's
side do nothing if the action group is not defined. The application can then
decide whether to provide such a placeholder or not.
Simon
More information about the kde-core-devel
mailing list