Lumiera  0.pre.03
»edityourfreedom«
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 GUI_CTRL_ACTIONS_H
42 #define GUI_CTRL_ACTIONS_H
43 
44 #include "gui/gtk-base.hpp"
45 #include "gui/ctrl/global-ctx.hpp"
49 #include "lib/format-string.hpp"
50 #include "lib/nocopy.hpp"
51 
52 #include <string>
53 
54 
55 namespace gui {
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  {
80 
81  public:
82  Actions (GlobalCtx& globals)
83  : globalCtx_{globals}
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 
134 
135  menu("WindowMenu", _("_Window"));
136  entry ([&]() { globalCtx_.windowLoc_.newWindow(); } , "WindowNewWindow", StockID("new_window"));
137  entry ([&]() { globalCtx_.windowLoc_.closeWindow();} , "WindowCloseWindow", _("Close Window"));
138  actionGroup->add(Action::create("WindowShowPanel", _("_Show Panel")));
139 
140 
141  menu("ViewMenu", _("_View"));
142  assetsPanelAction = ToggleAction::create("ViewAssets", StockID("panel_assets"));
143  assetsPanelAction->signal_toggled().connect ( [&]() { onMenu_view_assets(); });
145 
146  infoboxPanelAction = ToggleAction::create("ViewInfoBox", StockID("panel_infobox"));
147  infoboxPanelAction->signal_toggled().connect ( [&]() { onMenu_view_infobox(); });
149 
150  timelinePanelAction = ToggleAction::create("ViewTimeline", StockID("panel_timeline"));
151  timelinePanelAction->signal_toggled().connect( [&]() { onMenu_view_timeline(); });
153 
154  viewerPanelAction = ToggleAction::create("ViewViewer", StockID("panel_viewer"));
155  viewerPanelAction->signal_toggled().connect( [&]() { onMenu_view_viewer(); });
157 
158  uiManager.insert_action_group(actionGroup);
159 
160 
161 
162  //----- Create the UI layout -----//
163  string ui_info = R"***(
164  <ui>
165  <menubar name='MenuBar'>
166  <menu action='FileMenu'>
167  <menuitem action='FileNewProject'/>
168  <menuitem action='FileSave'/>
169  <menuitem action='FileSaveAs'/>
170  <menuitem action='FileOpen'/>
171  <separator/>
172  <menuitem action='FileRender'/>
173  <separator/>
174  <menuitem action='FileQuit'/>
175  </menu>
176  <menu action='EditMenu'>
177  <menuitem action='EditUndo'/>
178  <menuitem action='EditRedo'/>
179  <separator/>
180  <menuitem action='EditCut'/>
181  <menuitem action='EditCopy'/>
182  <menuitem action='EditPaste'/>
183  <separator/>
184  <menuitem action='EditPreferences'/>
185  </menu>
186  <menu action='ViewMenu'>
187  <menuitem action='ViewAssets'/>
188  <menuitem action='ViewInfoBox'/>
189  <menuitem action='ViewTimeline'/>
190  <menuitem action='ViewViewer'/>
191  </menu>
192  <menu action='SequenceMenu'>
193  <menuitem action='SequenceAdd'/>
194  </menu>
195  <menu action='TrackMenu'>
196  <menuitem action='TrackAdd'/>
197  </menu>
198  <menu action='WindowMenu'>
199  <menuitem action='WindowNewWindow'/>
200  <menuitem action='WindowCloseWindow'/>
201  <menu action='WindowShowPanel'/>
202  </menu>
203  <menu action='HelpMenu'>
204  <menuitem action='HelpAbout'/>
205  </menu>
206  </menubar>
207  <toolbar name='ToolBar'>
208  <toolitem action='FileNewProject'/>
209  <toolitem action='FileOpen'/>
210  <toolitem action='FileSave'/>
211  <separator/>
212  <toolitem action='EditUndo'/>
213  <toolitem action='EditRedo'/>
214  <separator/>
215  <toolitem action='EditCut'/>
216  <toolitem action='EditCopy'/>
217  <toolitem action='EditPaste'/>
218  </toolbar>
219  </ui>
220  )***";
221  try
222  {
223  uiManager.add_ui_from_string (ui_info);
224  }
225  catch(Glib::Error& ex)
226  {
227  ERROR (gui, "Building menus failed: %s", ex.what().data());
228  throw error::Config(_Fmt("global menu definition rejected: %s") % ex.what());
229  }
230 
231  //----- Add Extra Actions -----//
232  populateShowPanelActions (uiManager);
233  }
234 
235 
236 
245  void
247  {
250  /* unfinished, disabled by Joel with changeset 6151415 (from 4.4.2009)
251  *
252  REQUIRE(currentWindow.assetsPanel != NULL);
253  REQUIRE(currentWindow.timelinePanel != NULL);
254  REQUIRE(currentWindow.viewerPanel != NULL);
255 
256 // is_updating_action_state = true;
257  assetsPanelAction->set_active (currentWindow.assetsPanel->is_shown());
258  timelinePanelAction->set_active(currentWindow.timelinePanel->is_shown());
259  viewerPanelAction->set_active (currentWindow.viewerPanel->is_shown());
260 // is_updating_action_state = false;
261  */
262  }
263 
264 
265 
266  private: /* ===== Internals ===== */
267 
268 
278  void
279  populateShowPanelActions (Gtk::UIManager& uiManager)
280  {
282 
283  Glib::RefPtr<Gtk::ActionGroup> actionGroup = ActionGroup::create();
284  for (uint i = 0; i < count; i++)
285  {
286  const gchar *stock_id = workspace::PanelManager::getPanelStockID(i);
287  cuString panelName = ustring::compose("Panel%1", i);
288  actionGroup->add(Action::create(panelName, StockID(stock_id)),
289  [i,this]() {
290  globalCtx_.windowLoc_.findActiveWindow()
291  .getPanelManager()
292  .showPanel (i);
293  });
294  }
295 
296  uiManager.insert_action_group (actionGroup);
297 
298  for (uint i = 0; i < count; i++)
299  {
300  cuString name = ustring::compose("Panel%1", i);
301  uiManager.add_ui (uiManager.new_merge_id(),
302  "/MenuBar/WindowMenu/WindowShowPanel",
303  name, name);
304  }
305  }
306 
307 
308 
309 
310  /* ============ View Actions ========== */
311 
312  void
314  {
316  //if(!is_updating_action_state)
317  // workspaceWindow.assetsPanel->show(
318  // assetsPanelAction->get_active()); //////global -> InteractionDirector
319  unimplemented ("view assets");
320  }
321 
322  void
324  {
326  //if(!is_updating_action_state)
327  // workspaceWindow.infoboxPanel->show(
328  // infoboxPanelAction->get_active()); //////global -> InteractionDirector
329  unimplemented ("view infobox");
330  }
331 
332  void
334  {
336  //if(!is_updating_action_state)
337  // workspaceWindow.timelinePanel->show(timelinePanActionselAction->get_active());
338  unimplemented ("view timeline");
339  }
340 
341  void
343  {
345  //if(!is_updating_action_state)
346  // workspaceWindow.viewerPanel->show(viewerPanelAction->get_active()); //////global -> InteractionDirector
347  unimplemented ("view viewer");
348  }
349 
350 
351  // Temporary Junk
352  void
353  unimplemented (const char* todo)
354  {
355  WARN (gui, "%s is not yet implemented. So sorry.", todo);
356  }
357 
358 
359 
360  private: /* ===== Actions ===== */
361 
362  Glib::RefPtr<Gtk::ActionGroup> actionGroup;
363 
364  Glib::RefPtr<Gtk::ToggleAction> assetsPanelAction;
365  Glib::RefPtr<Gtk::ToggleAction> infoboxPanelAction;
366  Glib::RefPtr<Gtk::ToggleAction> timelinePanelAction;
367  Glib::RefPtr<Gtk::ToggleAction> viewerPanelAction;
368 
369 
370  private: /* ===== Internals ===== */
372  };
373 
374 
375 }}// namespace gui::ctrl
376 #endif /*GUI_CTRL_ACTIONS_H*/
The main Lumiera workspace window.
workspace::WorkspaceWindow & findActiveWindow()
find and retrieve a WorkspaceWindow (top-level window) marked as &#39;active&#39; by GTK. ...
void saveSnapshot()
Save a snapshot of the current project&#39;s contents and the UI state.
void populateShowPanelActions(Gtk::UIManager &uiManager)
Populates the menu entries to show specific panels within the current window.
Definition: actions.hpp:279
InteractionDirector director_
Definition: global-ctx.hpp:88
void onMenu_view_timeline()
Definition: actions.hpp:333
#define _(String)
Definition: gtk-base.hpp:76
WindowLocator windowLoc_
Definition: global-ctx.hpp:87
Dependency context to hold all the global UI top-level entities.
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:47
void editSetup()
Edit global configuration and setup.
Glib::RefPtr< Gtk::ActionGroup > actionGroup
Definition: actions.hpp:362
Any copy and copy construction prohibited.
Definition: nocopy.hpp:46
void show_HelpAbout()
show the notorious "about Lumiera" dialog.
Definition: wizard.cpp:89
Management of dockable panels.
Front-end for printf-style string template interpolation.
Actions(GlobalCtx &globals)
Definition: actions.hpp:82
A front-end for using printf-style formatting.
interact::Wizard wizard_
Definition: global-ctx.hpp:89
void unimplemented(const char *todo)
Definition: actions.hpp:353
void render()
Start a render process.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
void terminateUI()
Cause the main event loop to terminate, so the application as a whole unwinds.
Definition: ui-manager.cpp:157
void populateMainActions(Gtk::UIManager &uiManager)
Populates the uiManager with the main set of global actions.
Definition: actions.hpp:97
void onMenu_view_assets()
Definition: actions.hpp:313
static const gchar * getPanelStockID(const int index)
Gets a panel description&#39;s stock id.
Glib::RefPtr< Gtk::ToggleAction > timelinePanelAction
Definition: actions.hpp:366
void onMenu_view_infobox()
Definition: actions.hpp:323
Manager for all top level application windows.
Glib::RefPtr< Gtk::ToggleAction > infoboxPanelAction
Definition: actions.hpp:365
void onMenu_view_viewer()
Definition: actions.hpp:342
bool is_updating_action_state
Definition: actions.hpp:371
void openFile()
Select and open a file to perform a suitable operation.
UiManager & uiManager_
Definition: global-ctx.hpp:85
void updateActionState(workspace::WorkspaceWindow &currentWindow)
Updates the state of the menu/toolbar actions to reflect the current state of the workspace...
Definition: actions.hpp:246
void closeWindow()
close (and thus destroy) the current active window.
void newSequence()
Establish a pristine new sequence within the session.
panel::Panel & showPanel(const int description_index)
Shows a panel given a description index.
static int getPanelDescriptionCount()
Gets the number of panel descriptions.
This file contains the definition of the main workspace window parent, which is the toplevel parent o...
A global circle of top-level UI management facilities.
Definition: global-ctx.hpp:79
A helper class which registers and handles user action events.
Definition: actions.hpp:76
_Clo< SIG, Types< ARG... > >::Type closure(SIG &f, std::tuple< ARG... > &args)
close the given function over all arguments, using the values from the argument tuple.
void newTrack()
Establish a empty new track close to the current scope.
A set of basic GTK includes for the UI.
LumieraError< LERR_(CONFIG), Invalid > Config
Definition: error.hpp:217
Glib::RefPtr< Gtk::ToggleAction > viewerPanelAction
Definition: actions.hpp:367
void forkProject()
Continue evolution of the currently active project under a new identity.
GlobalCtx & globalCtx_
Definition: actions.hpp:79
const uString cuString
Definition: gtk-base.hpp:91
void newProject()
setup a new editing project, possibly close the current one.
Glib::RefPtr< Gtk::ToggleAction > assetsPanelAction
Definition: actions.hpp:364