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

List:       kde-core-devel
Subject:    Re: PATCH: defining actions enabled/disabled status in XML
From:       Simon Hausmann <hausmann () kde ! org>
Date:       2001-11-01 11:13:54
[Download RAW message or body]

On Thu, Nov 01, 2001 at 12:44:11PM +0200, Guillaume Laurent wrote:
> I'd like to commit the attached patch to CVS Head. What it does is allowing 
> the definition of "state changes" in an XML rc file, to make easier the 
> management of actions' enable/disable status. This is done through a new slot 
> in KMainWindow : stateChanged(const QString&);
> 
> For instance, you can define something like :
> 
> <State name="file_changed">
>   <enable>
>     <Action name="file_save"/>
>     <Action name="edit_undo"/>
>   </enable>
> </State>
> 
> in your application's rc file, then in the relevant place of your code just do
> stateChanged("file_changed"), which will enable the "file_save" and 
> "edit_undo" actions.
> 
> Another example :
> 
> <State name="file_loaded">
>   <enable>
>     <Action name="file_close"/>
>   </enable>
>   <disable>
>     <Action name="file_save"/>
>   </disable>
> </State>
> 
> Then after loading a file you simply call stateChanged("file_loaded"), which 
> will enable "file_close" and disable "file_save".
> 
> The state names are free form strings.

Excellent idea!

Implementation looks good to me. Just some minor comments (I'm a
nitpicker ;-)

1) Just an idea, but how about reflecting the notion of the state in
   the API a bit more, by having sth. like an ActionState structure:
   
   struct ActionState (TODO: find better name ;)
   {
       QStringList actionsToEnable;
       QStringList actionsToDisable;
   };

   Along with a

   QMap<QString, ActionState> m_actionStates;

   instead of two maps as storage.

2) The stateChanged method sounds generally useful. Why not move it
   to KXMLGUIClient? (it should still be possible to declare it as
   slot in kmainwindow, I think)


Simon

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

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