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

List:       kde-devel
Subject:    Re: handling complex logic to enable/disable actions
From:       Stefano Crocco <stefano.crocco () alice ! it>
Date:       2009-06-23 14:15:36
Message-ID: 200906231615.36958.stefano.crocco () alice ! it
[Download RAW message or body]

On Tuesday 23 June 2009, Andreas Pakulat wrote:
> |On 23.06.09 14:42:48, Stefano Crocco wrote:
> |> Hello to everyone,
> |>
> |> I'm developing an application for KDE, and I'm usingthe XML GUI
> |> framework to enable and disable actions. I know how to do it for simple
> |> situations. For example, if I have an action which starts an external
> |> process and one which stops it, I can write:
> |>
> |> <State name="process_started">
> |>   <enable>
> |>     <Action name="stop_process"/>
> |>   </enable>
> |>   <disable>
> |>     <Action name="start_process/>
> |>   </disable>
> |> </State>
> |>
> |> This way, when I set the "process_started" state, the "stop_process"
> |> action will be enabled and the "start_process" will be disabled.
> |>
> |> The problem arises if I need a more complex logic to find out whether an
> |> action should be enabled or not. For example, suppose that I have an
> |> action called "action1" which needs to be enabled only if there are both
> |> an open project and an open document. A first attempt would then be
> |> <State name="project_exists">
> |>   <enable>
> |>     <Action name="action1"/>
> |>   </enable>
> |> </State>
> |> <State name="document_exists">
> |>   <enable>
> |>     <Action name="action1"/>
> |>   </enable>
> |> </State>
> |> Of course, this won't work: as soon as the "project_exists" state is
> |> set, the action will be activated, even if the "document_exists" state
> |> isn't set.
> |>
> |> My question is: is it possible to use the XML GUI framework also to
> |> handle these more complex situations?
> |
> |Sure, but you're amount of states will "explode" with the number of checks
> |you have. The idea is instead of two states you'll have 4:
> |
> |project_exists_document_exists
> |project_not_exists_document_exists
> |project_exists_document_not_exists
> |project_not_exists_document_not_exists
> |
> |Then when a document is created check if a project exists and if there's
> |none, set the last state, if there is a project set the first one.
> |Obviously this can get rather complicated, but thats in general a problem
> |of having complex and many ui states. Of course at the place where you set
> |one of these 4 states you can just as well enable/disable the action
> |directly.
> |
> |Andreas

Thanks for the answer.
Sorry, my question wasn't clear. I know I could define four states instead of 
two. But, as you say, things would quickly become very difficult to manage. 
What I'd like to do is: define only the original two states and, somehow, tell 
the framework that the action should be only enabled if both the states are 
set. Ideally, my code should look like this:

void MainWindow::createProject()
{
  //code which creates a project
  stateChanged("project_exists");
}

void MainWindow::createDocument()
{
  //code which creates a document
  stateChanged("document_exists");
}

...
mainWindow->createProject();
//The action is disabled because only the project_exists status is set
mainWindow->createDocument();
//Now the action is enabled because both states are set

From the documentation of the XML GUI framework (in particular the 
KXMLGUIClient class), I gather this can't be done with the framework. Is this 
true? I was toying with the idea of creating a small framework to deal with 
states, but writing this mail and reflecting about your reply, made me realize 
that, given that the issue shouldn't be too common, perhaps it would be easier 
to manually manage these actions. What do you think?

Thanks

Stefano
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

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