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

List:       kde-core-devel
Subject:    Re: The future of KAction
From:       Alexander Dymo <adymo () mksat ! net>
Date:       2005-11-15 17:53:52
Message-ID: 200511151953.52294.adymo () mksat ! net
[Download RAW message or body]

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);
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;
}
[prev in list] [next in list] [prev in thread] [next in thread] 

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