Lumiera  0.pre.03
»edit your freedom«
actions.hpp
Go to the documentation of this file.
1 /*
2  ACTIONS.hpp - Definition of a helper class for user actions / menu
3 
4  Copyright (C) Lumiera.org
5  2008, Joel Holdsworth <joel@airwebreathe.org.uk>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
41 #ifndef STAGE_CTRL_ACTIONS_H
42 #define STAGE_CTRL_ACTIONS_H
43 
44 #include "stage/gtk-base.hpp"
49 #include "lib/format-string.hpp"
50 #include "lib/nocopy.hpp"
51 
52 #include <string>
53 
54 
55 namespace stage {
56 namespace ctrl {
57  namespace error = lumiera::error;
58 
59  using Gtk::Action;
60  using Gtk::ActionGroup;
61  using Gtk::ToggleAction;
62  using Gtk::AccelKey;
63  using Gtk::StockID;
64  using Glib::ustring;
65  using ::util::_Fmt;
66  using std::string;
67 
68  namespace Stock = Gtk::Stock;
69 
70 
71 
76  class Actions
78  {
79  GlobalCtx& globalCtx_;
80 
81  public:
82  Actions (GlobalCtx& globals)
83  : globalCtx_{globals}
84  , is_updating_action_state(false)
85  { }
86 
87 
96  void
97  populateMainActions (Gtk::UIManager& uiManager)
98  {
99  //----- Create the Action Group -----//
100  actionGroup = ActionGroup::create();
101  auto menu = [&](auto id, auto menuName) {actionGroup->add (Action::create(id, menuName)); };
102  auto entry = [&](auto closure, auto ...args) {actionGroup->add (Action::create(args...), closure);};
103 
104 
105  menu("FileMenu", _("_File"));
106  entry ([&]() { globalCtx_.director_.newProject(); } , "FileNewProject", Stock::NEW, _("_New Project..."));
107  entry ([&]() { globalCtx_.director_.saveSnapshot(); } , "FileSave", Stock::SAVE, _("_Save Project"));
108  entry ([&]() { globalCtx_.director_.forkProject(); } , "FileSaveAs", Stock::SAVE_AS, _("_Save Project As..."));
109  entry ([&]() { globalCtx_.director_.openFile(); } , "FileOpen", Stock::OPEN, _("_Open..."));
110  entry ([&]() { globalCtx_.director_.render(); } , "FileRender", _("_Render...")), AccelKey("<shift>R");
111  entry ([&]() { globalCtx_.uiManager_.terminateUI(); } , "FileQuit", Stock::QUIT);
112 
113 
114  menu("EditMenu", _("_Edit"));
115  entry ([&]() { unimplemented ("Edit/Undo"); } , "EditUndo", Stock::UNDO);
116  entry ([&]() { unimplemented ("Edit/Redo"); } , "EditRedo", Stock::REDO);
117  entry ([&]() { unimplemented ("Edit/Cut"); } , "EditCut", Stock::CUT);
118  entry ([&]() { unimplemented ("Edit/Copy"); } , "EditCopy", Stock::COPY);
119  entry ([&]() { unimplemented ("Edit/Pasta"); } , "EditPaste", Stock::PASTE);
120  entry ([&]() { globalCtx_.director_.editSetup(); } , "EditPreferences", Stock::PREFERENCES);
121 
122 
123  menu("SequenceMenu", _("_Sequence"));
124  entry ([&]() { globalCtx_.director_.newSequence(); } , "SequenceAdd", _("_Add..."));
125 
126 
127  menu("TrackMenu", _("_Track"));
128  entry ([&]() { globalCtx_.director_.newTrack(); } , "TrackAdd", _("_Add..."));
129 
130 
131  menu("HelpMenu", _("_Help"));
132  entry ([&]() { globalCtx_.wizard_.show_HelpAbout(); } , "HelpAbout", Stock::ABOUT);
133  entry ([&]() { globalCtx_.wizard_.launchTestCtrl(); } , "HelpTest", _("Self _Tests..."));
134 
135 
136  menu("WindowMenu", _("_Window"));
137  entry ([&]() { globalCtx_.windowLoc_.newWindow(); } , "WindowNewWindow", StockID("new_window"));
138  entry ([&]() { globalCtx_.windowLoc_.closeWindow();} , "WindowCloseWindow", _("Close Window"));
139  actionGroup->add(Action::create("WindowShowPanel", _("_Show Panel")));
140 
141 
142  menu("ViewMenu", _("_View"));
143  assetsPanelAction = ToggleAction::create("ViewAssets", StockID("panel_assets"));
144  assetsPanelAction->signal_toggled().connect ( [&]() { onMenu_view_assets(); });
145  actionGroup->add(assetsPanelAction);
146 
147  infoboxPanelAction = ToggleAction::create("ViewInfoBox", StockID("panel_infobox"));
148  infoboxPanelAction->signal_toggled().connect ( [&]() { onMenu_view_infobox(); });
149  actionGroup->add(infoboxPanelAction);
150 
151  timelinePanelAction = ToggleAction::create("ViewTimeline", StockID("panel_timeline"));
152  timelinePanelAction->signal_toggled().connect( [&]() { onMenu_view_timeline(); });
153  actionGroup->add(timelinePanelAction);
154 
155  viewerPanelAction = ToggleAction::create("ViewViewer", StockID("panel_viewer"));
156  viewerPanelAction->signal_toggled().connect( [&]() { onMenu_view_viewer(); });
157  actionGroup->add(viewerPanelAction);
158 
159  uiManager.insert_action_group(actionGroup);
160 
161 
162 
163  //----- Create the UI layout -----//
164  string ui_info = R"***(
165  <ui>
166  <menubar name='MenuBar'>
167  <menu action='FileMenu'>
168  <menuitem action='FileNewProject'/>
169  <menuitem action='FileSave'/>
170  <menuitem action='FileSaveAs'/>
171  <menuitem action='FileOpen'/>
172  <separator/>
173  <menuitem action='FileRender'/>
174  <separator/>
175  <menuitem action='FileQuit'/>
176  </menu>
177  <menu action='EditMenu'>
178  <menuitem action='EditUndo'/>
179  <menuitem action='EditRedo'/>
180  <separator/>
181  <menuitem action='EditCut'/>
182  <menuitem action='EditCopy'/>
183  <menuitem action='EditPaste'/>
184  <separator/>
185  <menuitem action='EditPreferences'/>
186  </menu>
187  <menu action='ViewMenu'>
188  <menuitem action='ViewAssets'/>
189  <menuitem action='ViewInfoBox'/>
190  <menuitem action='ViewTimeline'/>
191  <menuitem action='ViewViewer'/>
192  </menu>
193  <menu action='SequenceMenu'>
194  <menuitem action='SequenceAdd'/>
195  </menu>
196  <menu action='TrackMenu'>
197  <menuitem action='TrackAdd'/>
198  </menu>
199  <menu action='WindowMenu'>
200  <menuitem action='WindowNewWindow'/>
201  <menuitem action='WindowCloseWindow'/>
202  <menu action='WindowShowPanel'/>
203  </menu>
204  <menu action='HelpMenu'>
205  <menuitem action='HelpAbout'/>
206  <menuitem action='HelpTest'/>
207  </menu>
208  </menubar>
209  <toolbar name='ToolBar'>
210  <toolitem action='FileNewProject'/>
211  <toolitem action='FileOpen'/>
212  <toolitem action='FileSave'/>
213  <separator/>
214  <toolitem action='EditUndo'/>
215  <toolitem action='EditRedo'/>
216  <separator/>
217  <toolitem action='EditCut'/>
218  <toolitem action='EditCopy'/>
219  <toolitem action='EditPaste'/>
220  </toolbar>
221  </ui>
222  )***";
223  try
224  {
225  uiManager.add_ui_from_string (ui_info);
226  }
227  catch(Glib::Error& ex)
228  {
229  ERROR (stage, "Building menus failed: %s", ex.what().data());
230  throw error::Config(_Fmt("global menu definition rejected: %s") % ex.what());
231  }
232 
233  //----- Add Extra Actions -----//
234  populateShowPanelActions (uiManager);
235  }
236 
237 
238 
247  void
249  {
252  /* unfinished, disabled by Joel with changeset 6151415 (from 4.4.2009)
253  *
254  REQUIRE(currentWindow.assetsPanel != NULL);
255  REQUIRE(currentWindow.timelinePanel != NULL);
256  REQUIRE(currentWindow.viewerPanel != NULL);
257 
258 // is_updating_action_state = true;
259  assetsPanelAction->set_active (currentWindow.assetsPanel->is_shown());
260  timelinePanelAction->set_active(currentWindow.timelinePanel->is_shown());
261  viewerPanelAction->set_active (currentWindow.viewerPanel->is_shown());
262 // is_updating_action_state = false;
263  */
264  }
265 
266 
267 
268  private: /* ===== Internals ===== */
269 
270 
280  void
281  populateShowPanelActions (Gtk::UIManager& uiManager)
282  {
284 
285  Glib::RefPtr<Gtk::ActionGroup> actionGroup = ActionGroup::create();
286  for (uint i = 0; i < count; i++)
287  {
288  const gchar *stock_id = workspace::PanelManager::getPanelStockID(i);
289  cuString panelName = ustring::compose("Panel%1", i);
290  actionGroup->add(Action::create(panelName, StockID(stock_id)),
291  [i,this]() {
292  globalCtx_.windowLoc_.findActiveWindow()
293  .getPanelManager()
294  .showPanel (i);
295  });
296  }
297 
298  uiManager.insert_action_group (actionGroup);
299 
300  for (uint i = 0; i < count; i++)
301  {
302  cuString name = ustring::compose("Panel%1", i);
303  uiManager.add_ui (uiManager.new_merge_id(),
304  "/MenuBar/WindowMenu/WindowShowPanel",
305  name, name);
306  }
307  }
308 
309 
310 
311 
312  /* ============ View Actions ========== */
313 
314  void
315  onMenu_view_assets()
316  {
318  //if(!is_updating_action_state)
319  // workspaceWindow.assetsPanel->show(
320  // assetsPanelAction->get_active()); //////global -> InteractionDirector
321  unimplemented ("view assets");
322  }
323 
324  void
325  onMenu_view_infobox()
326  {
328  //if(!is_updating_action_state)
329  // workspaceWindow.infoboxPanel->show(
330  // infoboxPanelAction->get_active()); //////global -> InteractionDirector
331  unimplemented ("view infobox");
332  }
333 
334  void
335  onMenu_view_timeline()
336  {
338  //if(!is_updating_action_state)
339  // workspaceWindow.timelinePanel->show(timelinePanActionselAction->get_active());
340  unimplemented ("view timeline");
341  }
342 
343  void
344  onMenu_view_viewer()
345  {
347  //if(!is_updating_action_state)
348  // workspaceWindow.viewerPanel->show(viewerPanelAction->get_active()); //////global -> InteractionDirector
349  unimplemented ("view viewer");
350  }
351 
352 
353  // Temporary Junk
354  void
355  unimplemented (const char* todo)
356  {
357  WARN (stage, "%s is not yet implemented. So sorry.", todo);
358  }
359 
360 
361 
362  private: /* ===== Actions ===== */
363 
364  Glib::RefPtr<Gtk::ActionGroup> actionGroup;
365 
366  Glib::RefPtr<Gtk::ToggleAction> assetsPanelAction;
367  Glib::RefPtr<Gtk::ToggleAction> infoboxPanelAction;
368  Glib::RefPtr<Gtk::ToggleAction> timelinePanelAction;
369  Glib::RefPtr<Gtk::ToggleAction> viewerPanelAction;
370 
371 
372  private: /* ===== Internals ===== */
373  bool is_updating_action_state;
374  };
375 
376 
377 }}// namespace stage::ctrl
378 #endif /*STAGE_CTRL_ACTIONS_H*/
void saveSnapshot()
Save a snapshot of the current project&#39;s contents and the UI state.
void show_HelpAbout()
show the notorious "about Lumiera" dialog.
Definition: wizard.cpp:90
void newSequence()
Establish a pristine new sequence within the session.
Dependency context to hold all the global UI top-level entities.
AnyPair entry(Query< TY > const &query, typename WrapReturn< TY >::Wrapper &obj)
helper to simplify creating mock table entries, wrapped correctly
void terminateUI()
Cause the main event loop to terminate, so the application as a whole unwinds.
Definition: ui-manager.cpp:156
Any copy and copy construction prohibited.
Definition: nocopy.hpp:46
Management of dockable panels.
void newTrack()
Establish a empty new track close to the current scope.
void newProject()
setup a new editing project, possibly close the current one.
Front-end for printf-style string template interpolation.
void populateShowPanelActions(Gtk::UIManager &uiManager)
Populates the menu entries to show specific panels within the current window.
Definition: actions.hpp:281
A front-end for using printf-style formatting.
void forkProject()
Continue evolution of the currently active project under a new identity.
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:199
Mix-Ins to allow or prohibit various degrees of copying and cloning.
void editSetup()
Edit global configuration and setup.
static int getPanelDescriptionCount()
Gets the number of panel descriptions.
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
static const gchar * getPanelStockID(const int index)
Gets a panel description&#39;s stock id.
A helper class which registers global user actions and populates the main menu and toolbar...
Definition: actions.hpp:76
workspace::WorkspaceWindow & findActiveWindow()
find and retrieve a WorkspaceWindow (top-level window) marked as &#39;active&#39; by GTK. ...
panel::Panel & showPanel(const int description_index)
Shows a panel given a description index.
Manager for all top level application windows.
void render()
Start a render process.
void closeWindow()
close (and thus destroy) the current active window.
The main Lumiera workspace window.
A global circle of top-level UI management facilities.
Definition: global-ctx.hpp:79
This file contains the definition of the main workspace window parent, which is the toplevel parent o...
void updateActionState(workspace::WorkspaceWindow &currentWindow)
Updates the state of the menu/toolbar actions to reflect the current state of the workspace...
Definition: actions.hpp:248
void populateMainActions(Gtk::UIManager &uiManager)
Populates the uiManager with the main set of global actions.
Definition: actions.hpp:97
void launchTestCtrl()
Launch a non modal child window to trigger self-test actions.
Definition: wizard.cpp:126
A set of basic GTK includes for the UI.
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption
void openFile()
Select and open a file to perform a suitable operation.