From kde-kimageshop Fri Feb 15 01:17:00 2013 From: Sven Langkamp Date: Fri, 15 Feb 2013 01:17:00 +0000 To: kde-kimageshop Subject: Re: Action system refactor Message-Id: X-MARC-Message: https://marc.info/?l=kde-kimageshop&m=136089103726089 On Wed, Feb 13, 2013 at 9:41 PM, Sven Langkamp wrote: > Hi, > > > I recently got a bit fed up with the way in which we handle action > enable/disable. Currently every place that adds new actions needs to > implement a updateGUI method and update every action manually. In > several place this updating logic is broke because it doesn't cover > all the cases. I started a refactoring to clear this situation. > > The basic idea is as following: There is a central class which updates > the action (KisActionManager), every KisAction (inherits from KAction > and is a drop in replacement) has flags to control activation and > condition that need to be met. > > Exampe: > m_fillForegroundColor = new KisAction(i18n("Fill with Foreground > Color"), this); > m_fillForegroundColor->setActivationFlags(KisAction::ACTIVE_DEVICE); > m_fillForegroundColor->setActivationConditions(KisAction::ACTIVE_NODE_EDITABLE); > actionManager->addAction("fill_selection_foreground_color", > m_fillForegroundColor, collection); > > In this case the action would be enabled if there is an active device > and the active node is editable. There can ActivationFlags be multiple > flags/conditions by combing them like option1 | option2. The action > will only be active if one of the flags and all of the conditions are > active. > > Currently I have identified these: > enum ActivationFlag { > NONE = 0, > ACTIVE_NODE = 1, > ACTIVE_DEVICE = 2, > ACTIVE_LAYER = 4, > ACTIVE_SHAPE_LAYER = 8, > PIXELS_SELECTED = 16, > SHAPES_SELECTED = 32, > PIXEL_SELECTION_WITH_PIXELS = 64, > PIXELS_IN_CLIPBOARD = 128, > SHAPES_IN_CLIPBOARD = 256 > }; > > enum ActivationCondition { > NO_CONDITION = 0, > ACTIVE_NODE_EDITABLE = 1, > SELECTION_EDITABLE = 2 > }; > > The advantage of the system is that for many actions no explicit > update is needed, it's easier to see what the action does and it's > consistent. One downside is that not every action is covered by this > e.g. some action need special cases so some of the updateGUI code will > remain. > > Comments? > > > Sven After going through porting more action I noticed that a few things are currently underdefined e.g. if a layer shoud be able to be mirrored if one of it's children is locked or if a the layer is invisible. I think some artists needs to go through all the action and define when it should be enabled and disabled. I have made a function to dump all the flags and conditions. Current state is this: -------- Copy merged -------- Action will activate on: Pixels selected Action will only activate if the following conditions are met: - -------- &Invert Selection -------- Action will activate on: Pixel selection with pixels Action will only activate if the following conditions are met: Selection is editable -------- Copy Selection to New Layer -------- Action will activate on: Pixels selected Action will only activate if the following conditions are met: - -------- Cut Selection to New Layer -------- Action will activate on: Action will only activate if the following conditions are met: Active Node editable -------- Fill with Foreground Color -------- Action will activate on: Active device Action will only activate if the following conditions are met: Active Node editable -------- Fill with Background Color -------- Action will activate on: Active device Action will only activate if the following conditions are met: Active Node editable -------- Fill with Pattern -------- Action will activate on: Active device Action will only activate if the following conditions are met: Active Node editable -------- Stroke selected shapes -------- Action will activate on: Shapes selected Action will only activate if the following conditions are met: - -------- Size Canvas to Size of Selection -------- Action will activate on: Pixels selected Action will only activate if the following conditions are met: - -------- Save Layer as Image... -------- Action will activate on: Active layer Action will only activate if the following conditions are met: - -------- Size Canvas to Size of Current Layer -------- Action will activate on: Active layer Action will only activate if the following conditions are met: - -------- Mirror Horizontally -------- Action will activate on: Active node Action will only activate if the following conditions are met: Active Node editable -------- Mirror Vertically -------- Action will activate on: Active node Action will only activate if the following conditions are met: Active Node editable -------- Duplicate current layer -------- Action will activate on: Active layer Action will only activate if the following conditions are met: - -------- Delete current layer -------- Action will activate on: Active layer Action will only activate if the following conditions are met: - -------- Activate next layer -------- Action will activate on: Active layer Action will only activate if the following conditions are met: - -------- Activate previous layer -------- Action will activate on: Active layer Action will only activate if the following conditions are met: - -------- Select from Color Range... -------- Action will activate on: Active device Action will only activate if the following conditions are met: Selection is editable -------- Select Opaque -------- Action will activate on: Active device Action will only activate if the following conditions are met: Selection is editable -------- Grow Selection... -------- Action will activate on: Pixel selection with pixels Action will only activate if the following conditions are met: Selection is editable -------- Shrink Selection... -------- Action will activate on: Pixel selection with pixels Action will only activate if the following conditions are met: Selection is editable -------- Border Selection... -------- Action will activate on: Pixel selection with pixels Action will only activate if the following conditions are met: Selection is editable -------- Feather Selection... -------- Action will activate on: Pixel selection with pixels Action will only activate if the following conditions are met: Selection is editable -------- Smooth... -------- Action will activate on: Pixel selection with pixels Action will only activate if the following conditions are met: Selection is editable -------- &Scale... -------- Action will activate on: Pixels selected Action will only activate if the following conditions are met: Selection is editable _______________________________________________ kimageshop mailing list kimageshop@kde.org https://mail.kde.org/mailman/listinfo/kimageshop