Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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
34#ifndef STAGE_CTRL_ACTIONS_H
35#define STAGE_CTRL_ACTIONS_H
36
37#include "stage/gtk-base.hpp"
42#include "lib/format-string.hpp"
43#include "lib/nocopy.hpp"
44
45#include <string>
46
47
48namespace stage {
49namespace ctrl {
50 namespace error = lumiera::error;
51
52 using Gtk::Action;
53 using Gtk::ActionGroup;
54 using Gtk::ToggleAction;
55 using Gtk::AccelKey;
56 using Gtk::StockID;
57 using Glib::ustring;
58 using ::util::_Fmt;
59 using std::string;
60
61 namespace Stock = Gtk::Stock;
62
63
64
69 class Actions
71 {
73
74 public:
75 Actions (GlobalCtx& globals)
76 : globalCtx_{globals}
78 { }
79
80
89 void
90 populateMainActions (Gtk::UIManager& uiManager)
91 {
92 //----- Create the Action Group -----//
93 actionGroup = ActionGroup::create();
94 auto menu = [&](auto id, auto menuName) {actionGroup->add (Action::create(id, menuName)); };
95 auto entry = [&](auto closure, auto ...args) {actionGroup->add (Action::create(args...), closure);};
96
97
98 menu("FileMenu", _("_File"));
99 entry ([&]() { globalCtx_.director_.newProject(); } , "FileNewProject", Stock::NEW, _("_New Project..."));
100 entry ([&]() { globalCtx_.director_.saveSnapshot(); } , "FileSave", Stock::SAVE, _("_Save Project"));
101 entry ([&]() { globalCtx_.director_.forkProject(); } , "FileSaveAs", Stock::SAVE_AS, _("_Save Project As..."));
102 entry ([&]() { globalCtx_.director_.openFile(); } , "FileOpen", Stock::OPEN, _("_Open..."));
103 entry ([&]() { globalCtx_.director_.render(); } , "FileRender", _("_Render...")), AccelKey("<shift>R");
104 entry ([&]() { globalCtx_.uiManager_.terminateUI(); } , "FileQuit", Stock::QUIT);
105
106
107 menu("EditMenu", _("_Edit"));
108 entry ([&]() { unimplemented ("Edit/Undo"); } , "EditUndo", Stock::UNDO);
109 entry ([&]() { unimplemented ("Edit/Redo"); } , "EditRedo", Stock::REDO);
110 entry ([&]() { unimplemented ("Edit/Cut"); } , "EditCut", Stock::CUT);
111 entry ([&]() { unimplemented ("Edit/Copy"); } , "EditCopy", Stock::COPY);
112 entry ([&]() { unimplemented ("Edit/Pasta"); } , "EditPaste", Stock::PASTE);
113 entry ([&]() { globalCtx_.director_.editSetup(); } , "EditPreferences", Stock::PREFERENCES);
114
115
116 menu("SequenceMenu", _("_Sequence"));
117 entry ([&]() { globalCtx_.director_.newSequence(); } , "SequenceAdd", _("_Add..."));
118
119
120 menu("TrackMenu", _("_Track"));
121 entry ([&]() { globalCtx_.director_.newTrack(); } , "TrackAdd", _("_Add..."));
122
123
124 menu("HelpMenu", _("_Help"));
125 entry ([&]() { globalCtx_.wizard_.show_HelpAbout(); } , "HelpAbout", Stock::ABOUT);
126 entry ([&]() { globalCtx_.wizard_.launchTestCtrl(); } , "HelpTest", _("Self _Tests..."));
127
128
129 menu("WindowMenu", _("_Window"));
130 entry ([&]() { globalCtx_.windowLoc_.newWindow(); } , "WindowNewWindow", StockID("new_window"));
131 entry ([&]() { globalCtx_.windowLoc_.closeWindow();} , "WindowCloseWindow", _("Close Window"));
132 actionGroup->add(Action::create("WindowShowPanel", _("_Show Panel")));
133
134
135 menu("ViewMenu", _("_View"));
136 assetsPanelAction = ToggleAction::create("ViewAssets", StockID("panel_assets"));
137 assetsPanelAction->signal_toggled().connect ( [&]() { onMenu_view_assets(); });
139
140 infoboxPanelAction = ToggleAction::create("ViewInfoBox", StockID("panel_infobox"));
141 infoboxPanelAction->signal_toggled().connect ( [&]() { onMenu_view_infobox(); });
143
144 timelinePanelAction = ToggleAction::create("ViewTimeline", StockID("panel_timeline"));
145 timelinePanelAction->signal_toggled().connect( [&]() { onMenu_view_timeline(); });
147
148 viewerPanelAction = ToggleAction::create("ViewViewer", StockID("panel_viewer"));
149 viewerPanelAction->signal_toggled().connect( [&]() { onMenu_view_viewer(); });
151
152 playPanelAction = ToggleAction::create("ViewPlay", StockID("panel_play"));
153 playPanelAction->signal_toggled().connect( [&]() { onMenu_view_play(); });
155
156 uiManager.insert_action_group(actionGroup);
157
158
159
160 //----- Create the UI layout -----//
161 string ui_info = R"***(
162 <ui>
163 <menubar name='MenuBar'>
164 <menu action='FileMenu'>
165 <menuitem action='FileNewProject'/>
166 <menuitem action='FileSave'/>
167 <menuitem action='FileSaveAs'/>
168 <menuitem action='FileOpen'/>
169 <separator/>
170 <menuitem action='FileRender'/>
171 <separator/>
172 <menuitem action='FileQuit'/>
173 </menu>
174 <menu action='EditMenu'>
175 <menuitem action='EditUndo'/>
176 <menuitem action='EditRedo'/>
177 <separator/>
178 <menuitem action='EditCut'/>
179 <menuitem action='EditCopy'/>
180 <menuitem action='EditPaste'/>
181 <separator/>
182 <menuitem action='EditPreferences'/>
183 </menu>
184 <menu action='ViewMenu'>
185 <menuitem action='ViewAssets'/>
186 <menuitem action='ViewInfoBox'/>
187 <menuitem action='ViewTimeline'/>
188 <menuitem action='ViewViewer'/>
189 <menuitem action='ViewPlay'/>
190 </menu>
191 <menu action='SequenceMenu'>
192 <menuitem action='SequenceAdd'/>
193 </menu>
194 <menu action='TrackMenu'>
195 <menuitem action='TrackAdd'/>
196 </menu>
197 <menu action='WindowMenu'>
198 <menuitem action='WindowNewWindow'/>
199 <menuitem action='WindowCloseWindow'/>
200 <menu action='WindowShowPanel'/>
201 </menu>
202 <menu action='HelpMenu'>
203 <menuitem action='HelpAbout'/>
204 <menuitem action='HelpTest'/>
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 (stage, "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());
261// is_updating_action_state = false;
262 */
263 }
264
265
266
267 private: /* ===== Internals ===== */
268
269
279 void
280 populateShowPanelActions (Gtk::UIManager& uiManager)
281 {
283
284 Glib::RefPtr<Gtk::ActionGroup> actionGroup = ActionGroup::create();
285 for (uint i = 0; i < count; i++)
286 {
287 const gchar *stock_id = workspace::PanelManager::getPanelStockID(i);
288 cuString panelName = ustring::compose("Panel%1", i);
289 actionGroup->add(Action::create(panelName, StockID(stock_id)),
290 [i,this]() {
292 .getPanelManager()
293 .showPanel (i);
294 });
295 }
296
297 uiManager.insert_action_group (actionGroup);
298
299 for (uint i = 0; i < count; i++)
300 {
301 cuString name = ustring::compose("Panel%1", i);
302 uiManager.add_ui (uiManager.new_merge_id(),
303 "/MenuBar/WindowMenu/WindowShowPanel",
304 name, name);
305 }
306 }
307
308
309
310
311 /* ============ View Actions ========== */
312
313 void
315 {
317 //if(!is_updating_action_state)
318 // workspaceWindow.assetsPanel->show(
319 // assetsPanelAction->get_active()); //////global -> InteractionDirector
320 unimplemented ("view assets");
321 }
322
323 void
325 {
327 //if(!is_updating_action_state)
328 // workspaceWindow.infoboxPanel->show(
329 // infoboxPanelAction->get_active()); //////global -> InteractionDirector
330 unimplemented ("view infobox");
331 }
332
333 void
335 {
337 //if(!is_updating_action_state)
338 // workspaceWindow.timelinePanel->show(timelinePanActionselAction->get_active());
339 unimplemented ("view timeline");
340 }
341
342 void
344 {
346 //if(!is_updating_action_state)
347 // workspaceWindow.viewerPanel->show(viewerPanelAction->get_active()); //////global -> InteractionDirector
348 unimplemented ("view viewer");
349 }
350
351 void
353 {
356 //if(!is_updating_action_state)
357 // workspaceWindow.playPanel->show(viewerPanelAction->get_active()); //////global -> InteractionDirector
358 unimplemented ("view player");
359 }
360
361
362 // Temporary Junk
363 void
365 {
366 WARN (stage, "%s is not yet implemented. So sorry.", todo);
367 }
368
369
370
371 private: /* ===== Actions ===== */
372
373 Glib::RefPtr<Gtk::ActionGroup> actionGroup;
374
375 Glib::RefPtr<Gtk::ToggleAction> assetsPanelAction;
376 Glib::RefPtr<Gtk::ToggleAction> infoboxPanelAction;
377 Glib::RefPtr<Gtk::ToggleAction> timelinePanelAction;
378 Glib::RefPtr<Gtk::ToggleAction> viewerPanelAction;
379 Glib::RefPtr<Gtk::ToggleAction> playPanelAction;
380
381
382 private: /* ===== Internals ===== */
384 };
385
386
387}}// namespace stage::ctrl
388#endif /*STAGE_CTRL_ACTIONS_H*/
Inline string literal.
Definition symbol.hpp:78
A helper class which registers global user actions and populates the main menu and toolbar.
Definition actions.hpp:71
Glib::RefPtr< Gtk::ActionGroup > actionGroup
Definition actions.hpp:373
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 onMenu_view_timeline()
Definition actions.hpp:334
Glib::RefPtr< Gtk::ToggleAction > playPanelAction
Definition actions.hpp:379
Glib::RefPtr< Gtk::ToggleAction > viewerPanelAction
Definition actions.hpp:378
Glib::RefPtr< Gtk::ToggleAction > assetsPanelAction
Definition actions.hpp:375
void populateShowPanelActions(Gtk::UIManager &uiManager)
Populates the menu entries to show specific panels within the current window.
Definition actions.hpp:280
void populateMainActions(Gtk::UIManager &uiManager)
Populates the uiManager with the main set of global actions.
Definition actions.hpp:90
Glib::RefPtr< Gtk::ToggleAction > timelinePanelAction
Definition actions.hpp:377
Actions(GlobalCtx &globals)
Definition actions.hpp:75
GlobalCtx & globalCtx_
Definition actions.hpp:72
Glib::RefPtr< Gtk::ToggleAction > infoboxPanelAction
Definition actions.hpp:376
void unimplemented(Literal todo)
Definition actions.hpp:364
A global circle of top-level UI management facilities.
WindowLocator windowLoc_
interact::Wizard wizard_
InteractionDirector director_
void terminateUI()
Cause the main event loop to terminate, so the application as a whole unwinds.
void closeWindow()
close (and thus destroy) the current active window.
workspace::WorkspaceWindow & findActiveWindow()
find and retrieve a WorkspaceWindow (top-level window) marked as 'active' by GTK.
void newSequence()
Establish a pristine new sequence within the session.
void newTrack()
Establish a empty new track close to the current scope.
void saveSnapshot()
Save a snapshot of the current project's contents and the UI state.
void forkProject()
Continue evolution of the currently active project under a new identity.
void editSetup()
Edit global configuration and setup.
void openFile()
Select and open a file to perform a suitable operation.
void newProject()
setup a new editing project, possibly close the current one.
void show_HelpAbout()
show the notorious "about Lumiera" dialog.
Definition wizard.cpp:81
void launchTestCtrl()
Launch a non modal child window to trigger self-test actions.
Definition wizard.cpp:117
static int getPanelDescriptionCount()
Gets the number of panel descriptions.
static const gchar * getPanelStockID(const int index)
Gets a panel description's stock id.
The main Lumiera workspace window.
Any copy and copy construction prohibited.
Definition nocopy.hpp:38
A front-end for using printf-style formatting.
Front-end for printf-style string template interpolation.
Dependency context to hold all the global UI top-level entities.
A set of basic GTK includes for the UI.
#define _(String)
Definition gtk-base.hpp:68
unsigned int uint
Definition integral.hpp:29
LumieraError< LERR_(CONFIG), Invalid > Config
Definition error.hpp:212
Lumiera GTK UI implementation root.
Definition guifacade.cpp:37
const uString cuString
Definition gtk-base.hpp:93
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Management of dockable panels.
Manager for all top level application windows.
This file contains the definition of the main workspace window parent, which is the toplevel parent o...