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)
5  2008, Joel Holdsworth <joel@airwebreathe.org.uk>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
32 #ifndef STAGE_CTRL_ACTIONS_H
33 #define STAGE_CTRL_ACTIONS_H
34 
35 #include "stage/gtk-base.hpp"
40 #include "lib/format-string.hpp"
41 #include "lib/nocopy.hpp"
42 
43 #include <string>
44 
45 
46 namespace stage {
47 namespace ctrl {
48  namespace error = lumiera::error;
49 
50  using Gtk::Action;
51  using Gtk::ActionGroup;
52  using Gtk::ToggleAction;
53  using Gtk::AccelKey;
54  using Gtk::StockID;
55  using Glib::ustring;
56  using ::util::_Fmt;
57  using std::string;
58 
59  namespace Stock = Gtk::Stock;
60 
61 
62 
67  class Actions
69  {
70  GlobalCtx& globalCtx_;
71 
72  public:
73  Actions (GlobalCtx& globals)
74  : globalCtx_{globals}
75  , is_updating_action_state(false)
76  { }
77 
78 
87  void
88  populateMainActions (Gtk::UIManager& uiManager)
89  {
90  //----- Create the Action Group -----//
91  actionGroup = ActionGroup::create();
92  auto menu = [&](auto id, auto menuName) {actionGroup->add (Action::create(id, menuName)); };
93  auto entry = [&](auto closure, auto ...args) {actionGroup->add (Action::create(args...), closure);};
94 
95 
96  menu("FileMenu", _("_File"));
97  entry ([&]() { globalCtx_.director_.newProject(); } , "FileNewProject", Stock::NEW, _("_New Project..."));
98  entry ([&]() { globalCtx_.director_.saveSnapshot(); } , "FileSave", Stock::SAVE, _("_Save Project"));
99  entry ([&]() { globalCtx_.director_.forkProject(); } , "FileSaveAs", Stock::SAVE_AS, _("_Save Project As..."));
100  entry ([&]() { globalCtx_.director_.openFile(); } , "FileOpen", Stock::OPEN, _("_Open..."));
101  entry ([&]() { globalCtx_.director_.render(); } , "FileRender", _("_Render...")), AccelKey("<shift>R");
102  entry ([&]() { globalCtx_.uiManager_.terminateUI(); } , "FileQuit", Stock::QUIT);
103 
104 
105  menu("EditMenu", _("_Edit"));
106  entry ([&]() { unimplemented ("Edit/Undo"); } , "EditUndo", Stock::UNDO);
107  entry ([&]() { unimplemented ("Edit/Redo"); } , "EditRedo", Stock::REDO);
108  entry ([&]() { unimplemented ("Edit/Cut"); } , "EditCut", Stock::CUT);
109  entry ([&]() { unimplemented ("Edit/Copy"); } , "EditCopy", Stock::COPY);
110  entry ([&]() { unimplemented ("Edit/Pasta"); } , "EditPaste", Stock::PASTE);
111  entry ([&]() { globalCtx_.director_.editSetup(); } , "EditPreferences", Stock::PREFERENCES);
112 
113 
114  menu("SequenceMenu", _("_Sequence"));
115  entry ([&]() { globalCtx_.director_.newSequence(); } , "SequenceAdd", _("_Add..."));
116 
117 
118  menu("TrackMenu", _("_Track"));
119  entry ([&]() { globalCtx_.director_.newTrack(); } , "TrackAdd", _("_Add..."));
120 
121 
122  menu("HelpMenu", _("_Help"));
123  entry ([&]() { globalCtx_.wizard_.show_HelpAbout(); } , "HelpAbout", Stock::ABOUT);
124  entry ([&]() { globalCtx_.wizard_.launchTestCtrl(); } , "HelpTest", _("Self _Tests..."));
125 
126 
127  menu("WindowMenu", _("_Window"));
128  entry ([&]() { globalCtx_.windowLoc_.newWindow(); } , "WindowNewWindow", StockID("new_window"));
129  entry ([&]() { globalCtx_.windowLoc_.closeWindow();} , "WindowCloseWindow", _("Close Window"));
130  actionGroup->add(Action::create("WindowShowPanel", _("_Show Panel")));
131 
132 
133  menu("ViewMenu", _("_View"));
134  assetsPanelAction = ToggleAction::create("ViewAssets", StockID("panel_assets"));
135  assetsPanelAction->signal_toggled().connect ( [&]() { onMenu_view_assets(); });
136  actionGroup->add(assetsPanelAction);
137 
138  infoboxPanelAction = ToggleAction::create("ViewInfoBox", StockID("panel_infobox"));
139  infoboxPanelAction->signal_toggled().connect ( [&]() { onMenu_view_infobox(); });
140  actionGroup->add(infoboxPanelAction);
141 
142  timelinePanelAction = ToggleAction::create("ViewTimeline", StockID("panel_timeline"));
143  timelinePanelAction->signal_toggled().connect( [&]() { onMenu_view_timeline(); });
144  actionGroup->add(timelinePanelAction);
145 
146  viewerPanelAction = ToggleAction::create("ViewViewer", StockID("panel_viewer"));
147  viewerPanelAction->signal_toggled().connect( [&]() { onMenu_view_viewer(); });
148  actionGroup->add(viewerPanelAction);
149 
150  uiManager.insert_action_group(actionGroup);
151 
152 
153 
154  //----- Create the UI layout -----//
155  string ui_info = R"***(
156  <ui>
157  <menubar name='MenuBar'>
158  <menu action='FileMenu'>
159  <menuitem action='FileNewProject'/>
160  <menuitem action='FileSave'/>
161  <menuitem action='FileSaveAs'/>
162  <menuitem action='FileOpen'/>
163  <separator/>
164  <menuitem action='FileRender'/>
165  <separator/>
166  <menuitem action='FileQuit'/>
167  </menu>
168  <menu action='EditMenu'>
169  <menuitem action='EditUndo'/>
170  <menuitem action='EditRedo'/>
171  <separator/>
172  <menuitem action='EditCut'/>
173  <menuitem action='EditCopy'/>
174  <menuitem action='EditPaste'/>
175  <separator/>
176  <menuitem action='EditPreferences'/>
177  </menu>
178  <menu action='ViewMenu'>
179  <menuitem action='ViewAssets'/>
180  <menuitem action='ViewInfoBox'/>
181  <menuitem action='ViewTimeline'/>
182  <menuitem action='ViewViewer'/>
183  </menu>
184  <menu action='SequenceMenu'>
185  <menuitem action='SequenceAdd'/>
186  </menu>
187  <menu action='TrackMenu'>
188  <menuitem action='TrackAdd'/>
189  </menu>
190  <menu action='WindowMenu'>
191  <menuitem action='WindowNewWindow'/>
192  <menuitem action='WindowCloseWindow'/>
193  <menu action='WindowShowPanel'/>
194  </menu>
195  <menu action='HelpMenu'>
196  <menuitem action='HelpAbout'/>
197  <menuitem action='HelpTest'/>
198  </menu>
199  </menubar>
200  <toolbar name='ToolBar'>
201  <toolitem action='FileNewProject'/>
202  <toolitem action='FileOpen'/>
203  <toolitem action='FileSave'/>
204  <separator/>
205  <toolitem action='EditUndo'/>
206  <toolitem action='EditRedo'/>
207  <separator/>
208  <toolitem action='EditCut'/>
209  <toolitem action='EditCopy'/>
210  <toolitem action='EditPaste'/>
211  </toolbar>
212  </ui>
213  )***";
214  try
215  {
216  uiManager.add_ui_from_string (ui_info);
217  }
218  catch(Glib::Error& ex)
219  {
220  ERROR (stage, "Building menus failed: %s", ex.what().data());
221  throw error::Config(_Fmt("global menu definition rejected: %s") % ex.what());
222  }
223 
224  //----- Add Extra Actions -----//
225  populateShowPanelActions (uiManager);
226  }
227 
228 
229 
238  void
240  {
243  /* unfinished, disabled by Joel with changeset 6151415 (from 4.4.2009)
244  *
245  REQUIRE(currentWindow.assetsPanel != NULL);
246  REQUIRE(currentWindow.timelinePanel != NULL);
247  REQUIRE(currentWindow.viewerPanel != NULL);
248 
249 // is_updating_action_state = true;
250  assetsPanelAction->set_active (currentWindow.assetsPanel->is_shown());
251  timelinePanelAction->set_active(currentWindow.timelinePanel->is_shown());
252  viewerPanelAction->set_active (currentWindow.viewerPanel->is_shown());
253 // is_updating_action_state = false;
254  */
255  }
256 
257 
258 
259  private: /* ===== Internals ===== */
260 
261 
271  void
272  populateShowPanelActions (Gtk::UIManager& uiManager)
273  {
275 
276  Glib::RefPtr<Gtk::ActionGroup> actionGroup = ActionGroup::create();
277  for (uint i = 0; i < count; i++)
278  {
279  const gchar *stock_id = workspace::PanelManager::getPanelStockID(i);
280  cuString panelName = ustring::compose("Panel%1", i);
281  actionGroup->add(Action::create(panelName, StockID(stock_id)),
282  [i,this]() {
283  globalCtx_.windowLoc_.findActiveWindow()
284  .getPanelManager()
285  .showPanel (i);
286  });
287  }
288 
289  uiManager.insert_action_group (actionGroup);
290 
291  for (uint i = 0; i < count; i++)
292  {
293  cuString name = ustring::compose("Panel%1", i);
294  uiManager.add_ui (uiManager.new_merge_id(),
295  "/MenuBar/WindowMenu/WindowShowPanel",
296  name, name);
297  }
298  }
299 
300 
301 
302 
303  /* ============ View Actions ========== */
304 
305  void
306  onMenu_view_assets()
307  {
309  //if(!is_updating_action_state)
310  // workspaceWindow.assetsPanel->show(
311  // assetsPanelAction->get_active()); //////global -> InteractionDirector
312  unimplemented ("view assets");
313  }
314 
315  void
316  onMenu_view_infobox()
317  {
319  //if(!is_updating_action_state)
320  // workspaceWindow.infoboxPanel->show(
321  // infoboxPanelAction->get_active()); //////global -> InteractionDirector
322  unimplemented ("view infobox");
323  }
324 
325  void
326  onMenu_view_timeline()
327  {
329  //if(!is_updating_action_state)
330  // workspaceWindow.timelinePanel->show(timelinePanActionselAction->get_active());
331  unimplemented ("view timeline");
332  }
333 
334  void
335  onMenu_view_viewer()
336  {
338  //if(!is_updating_action_state)
339  // workspaceWindow.viewerPanel->show(viewerPanelAction->get_active()); //////global -> InteractionDirector
340  unimplemented ("view viewer");
341  }
342 
343 
344  // Temporary Junk
345  void
346  unimplemented (const char* todo)
347  {
348  WARN (stage, "%s is not yet implemented. So sorry.", todo);
349  }
350 
351 
352 
353  private: /* ===== Actions ===== */
354 
355  Glib::RefPtr<Gtk::ActionGroup> actionGroup;
356 
357  Glib::RefPtr<Gtk::ToggleAction> assetsPanelAction;
358  Glib::RefPtr<Gtk::ToggleAction> infoboxPanelAction;
359  Glib::RefPtr<Gtk::ToggleAction> timelinePanelAction;
360  Glib::RefPtr<Gtk::ToggleAction> viewerPanelAction;
361 
362 
363  private: /* ===== Internals ===== */
364  bool is_updating_action_state;
365  };
366 
367 
368 }}// namespace stage::ctrl
369 #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:81
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:147
Any copy and copy construction prohibited.
Definition: nocopy.hpp:37
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:272
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:190
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:37
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:67
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:70
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:239
void populateMainActions(Gtk::UIManager &uiManager)
Populates the uiManager with the main set of global actions.
Definition: actions.hpp:88
void launchTestCtrl()
Launch a non modal child window to trigger self-test actions.
Definition: wizard.cpp:117
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.