diff options
Diffstat (limited to 'src/WorkspaceMenu.cc')
-rw-r--r-- | src/WorkspaceMenu.cc | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/WorkspaceMenu.cc b/src/WorkspaceMenu.cc new file mode 100644 index 0000000..575ddeb --- /dev/null +++ b/src/WorkspaceMenu.cc | |||
@@ -0,0 +1,115 @@ | |||
1 | // WorkspaceMenu.cc for Fluxbox | ||
2 | // Copyright (c) 2004 Henrik Kinnunen (fluxgen at users.sourceforge.net) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id: WorkspaceMenu.cc,v 1.1 2004/05/02 20:51:36 fluxgen Exp $ | ||
23 | |||
24 | #include "WorkspaceMenu.hh" | ||
25 | |||
26 | #include "Screen.hh" | ||
27 | #include "fluxbox.hh" | ||
28 | #include "Workspace.hh" | ||
29 | #include "MenuCreator.hh" | ||
30 | #include "I18n.hh" | ||
31 | |||
32 | #include "FbTk/SimpleCommand.hh" | ||
33 | #include "FbTk/RefCount.hh" | ||
34 | #include "FbTk/MenuItem.hh" | ||
35 | |||
36 | WorkspaceMenu::WorkspaceMenu(BScreen &screen): | ||
37 | FbMenu(screen.menuTheme(), | ||
38 | screen.imageControl(), | ||
39 | *screen.layerManager(). | ||
40 | getLayer(Fluxbox::instance()->getMenuLayer())) { | ||
41 | |||
42 | |||
43 | init(screen); | ||
44 | } | ||
45 | |||
46 | void WorkspaceMenu::update(FbTk::Subject *subj) { | ||
47 | if (subj != 0 && typeid(*subj) == typeid(BScreen::ScreenSubject)) { | ||
48 | BScreen::ScreenSubject &screen_subj = *static_cast<BScreen::ScreenSubject *>(subj); | ||
49 | BScreen &screen = screen_subj.screen(); | ||
50 | if (subj == &screen.currentWorkspaceSig()) { | ||
51 | FbTk::MenuItem *item = 0; | ||
52 | for (unsigned int i = 2; i < numberOfItems(); ++i) { | ||
53 | item = find(i); | ||
54 | if (item && item->isSelected()) { | ||
55 | setItemSelected(i, false); | ||
56 | FbTk::Menu::update(i); | ||
57 | break; | ||
58 | } | ||
59 | } | ||
60 | setItemSelected(screen.currentWorkspace()->workspaceID() + 2, true); | ||
61 | FbTk::Menu::update(screen.currentWorkspace()->workspaceID() + 2); | ||
62 | } else if (subj == &screen.workspaceCountSig() || | ||
63 | subj == &screen.workspaceNamesSig()) { | ||
64 | while (numberOfItems() != 3) { | ||
65 | remove(2); | ||
66 | } | ||
67 | // for each workspace add workspace name and it's menu | ||
68 | // to our workspace menu | ||
69 | for (size_t workspace = 0; workspace < screen.getCount(); | ||
70 | ++workspace) { | ||
71 | Workspace *wkspc = screen.getWorkspace(workspace); | ||
72 | wkspc->menu().setInternalMenu(); | ||
73 | insert(wkspc->name().c_str(), &wkspc->menu(), numberOfItems() - 1); | ||
74 | } | ||
75 | |||
76 | FbTk::Menu::update(-1); | ||
77 | } | ||
78 | } else { | ||
79 | FbTk::Menu::update(subj); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | void WorkspaceMenu::init(BScreen &screen) { | ||
84 | screen.currentWorkspaceSig().attach(this); | ||
85 | screen.workspaceCountSig().attach(this); | ||
86 | screen.workspaceNamesSig().attach(this); | ||
87 | I18n &i18n = *I18n::instance(); | ||
88 | using namespace FbTk; | ||
89 | using namespace FBNLS; | ||
90 | |||
91 | removeAll(); | ||
92 | |||
93 | setLabel(i18n.getMessage(WorkspacemenuSet, WorkspacemenuWorkspacesTitle, | ||
94 | "Workspace")); | ||
95 | RefCount<Command> new_workspace(new SimpleCommand<BScreen, int>(screen, &BScreen::addWorkspace)); | ||
96 | RefCount<Command> remove_last(new SimpleCommand<BScreen, int>(screen, &BScreen::removeLastWorkspace)); | ||
97 | insert(i18n.getMessage(WorkspacemenuSet, WorkspacemenuNewWorkspace, | ||
98 | "New Workspace"), | ||
99 | new_workspace); | ||
100 | insert(i18n.getMessage(WorkspacemenuSet, WorkspacemenuRemoveLast, | ||
101 | "Remove Last"), | ||
102 | remove_last); | ||
103 | // for each workspace add workspace name and it's menu to our workspace menu | ||
104 | for (size_t workspace = 0; workspace < screen.getCount(); ++workspace) { | ||
105 | Workspace *wkspc = screen.getWorkspace(workspace); | ||
106 | wkspc->menu().setInternalMenu(); | ||
107 | insert(wkspc->name().c_str(), &wkspc->menu()); | ||
108 | } | ||
109 | setItemSelected(screen.currentWorkspace()->workspaceID() + 2, true); | ||
110 | |||
111 | insert(i18n.getMessage(IconSet, IconIcons, | ||
112 | "Icons"), | ||
113 | MenuCreator::createMenuType("iconmenu", screen.screenNumber())); | ||
114 | FbMenu::update(); | ||
115 | } | ||