2004-05-02 20:51:36 +00:00
|
|
|
// WorkspaceMenu.cc for Fluxbox
|
2006-02-16 06:53:05 +00:00
|
|
|
// Copyright (c) 2004 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org)
|
2004-05-02 20:51:36 +00:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
#include "WorkspaceMenu.hh"
|
|
|
|
|
|
|
|
#include "Screen.hh"
|
|
|
|
#include "Workspace.hh"
|
2004-09-06 21:12:10 +00:00
|
|
|
#include "WorkspaceCmd.hh"
|
2004-05-02 20:51:36 +00:00
|
|
|
#include "MenuCreator.hh"
|
2008-01-11 07:41:22 +00:00
|
|
|
#include "FbTk/CommandParser.hh"
|
2005-07-04 18:19:09 +00:00
|
|
|
#include "FbCommands.hh"
|
2006-02-20 21:04:35 +00:00
|
|
|
#include "Layer.hh"
|
2004-09-06 21:12:10 +00:00
|
|
|
|
2004-06-07 11:46:05 +00:00
|
|
|
#include "FbTk/I18n.hh"
|
2004-05-02 20:51:36 +00:00
|
|
|
#include "FbTk/SimpleCommand.hh"
|
2005-07-04 18:19:09 +00:00
|
|
|
#include "FbTk/MacroCommand.hh"
|
2004-05-02 20:51:36 +00:00
|
|
|
#include "FbTk/RefCount.hh"
|
|
|
|
#include "FbTk/MenuItem.hh"
|
2005-06-08 23:03:12 +00:00
|
|
|
#include "FbTk/MenuSeparator.hh"
|
2004-09-06 21:12:10 +00:00
|
|
|
#include "FbTk/MultiButtonMenuItem.hh"
|
2008-09-18 20:27:16 +00:00
|
|
|
#include "FbTk/MemFun.hh"
|
2004-05-02 20:51:36 +00:00
|
|
|
|
2011-02-24 10:16:16 +00:00
|
|
|
namespace {
|
2004-06-07 22:01:11 +00:00
|
|
|
|
2005-06-08 23:03:12 +00:00
|
|
|
// the menu consists of (* means static)
|
|
|
|
// - icons * 0
|
|
|
|
// --------------------- * 1
|
|
|
|
// - workspaces 2
|
|
|
|
// --------------------- * 3
|
|
|
|
// - new workspace * 4
|
|
|
|
// - edit workspace name * 5
|
|
|
|
// - remove last * 6
|
|
|
|
//
|
|
|
|
|
2011-02-24 10:16:16 +00:00
|
|
|
const unsigned int IDX_AFTER_ICONS = 2;
|
|
|
|
const unsigned int NR_STATIC_ITEMS = 6;
|
|
|
|
|
|
|
|
void add_workspaces(WorkspaceMenu& menu, BScreen& screen) {
|
|
|
|
for (size_t i = 0; i < screen.numberOfWorkspaces(); ++i) {
|
|
|
|
Workspace* w = screen.getWorkspace(i);
|
|
|
|
w->menu().setInternalMenu();
|
|
|
|
FbTk::MultiButtonMenuItem* submenu = new FbTk::MultiButtonMenuItem(5, FbTk::BiDiString(w->name()), &w->menu());
|
|
|
|
FbTk::RefCount<FbTk::Command<void> > jump_cmd(new JumpToWorkspaceCmd(w->workspaceID()));
|
|
|
|
submenu->setCommand(3, jump_cmd);
|
|
|
|
menu.insert(submenu, i + IDX_AFTER_ICONS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end of anonymous namespace
|
2005-06-08 23:03:12 +00:00
|
|
|
|
2004-05-02 20:51:36 +00:00
|
|
|
WorkspaceMenu::WorkspaceMenu(BScreen &screen):
|
|
|
|
FbMenu(screen.menuTheme(),
|
|
|
|
screen.imageControl(),
|
2011-03-23 11:02:15 +00:00
|
|
|
*screen.layerManager().getLayer(ResourceLayer::MENU)) {
|
2004-05-02 20:51:36 +00:00
|
|
|
|
|
|
|
init(screen);
|
|
|
|
}
|
|
|
|
|
2008-09-18 20:27:16 +00:00
|
|
|
void WorkspaceMenu::workspaceInfoChanged( BScreen& screen ) {
|
|
|
|
while (numberOfItems() > NR_STATIC_ITEMS) {
|
|
|
|
remove(IDX_AFTER_ICONS);
|
|
|
|
}
|
2011-02-24 10:16:16 +00:00
|
|
|
::add_workspaces(*this, screen);
|
2008-09-22 05:32:02 +00:00
|
|
|
updateMenu();
|
2008-09-18 20:27:16 +00:00
|
|
|
}
|
|
|
|
|
2008-09-21 11:44:48 +00:00
|
|
|
void WorkspaceMenu::workspaceChanged(BScreen& screen) {
|
|
|
|
FbTk::MenuItem *item = 0;
|
|
|
|
for (unsigned int i = 0; i < screen.numberOfWorkspaces(); ++i) {
|
|
|
|
item = find(i + IDX_AFTER_ICONS);
|
|
|
|
if (item && item->isSelected()) {
|
|
|
|
setItemSelected(i + IDX_AFTER_ICONS, false);
|
2008-09-22 05:32:02 +00:00
|
|
|
updateMenu();
|
2008-09-21 11:44:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setItemSelected(screen.currentWorkspace()->workspaceID() + IDX_AFTER_ICONS, true);
|
2008-09-22 05:32:02 +00:00
|
|
|
updateMenu();
|
2008-09-21 11:44:48 +00:00
|
|
|
}
|
|
|
|
|
2004-05-02 20:51:36 +00:00
|
|
|
void WorkspaceMenu::init(BScreen &screen) {
|
2008-09-18 20:27:16 +00:00
|
|
|
|
2008-09-21 11:44:48 +00:00
|
|
|
join(screen.currentWorkspaceSig(),
|
|
|
|
FbTk::MemFun(*this, &WorkspaceMenu::workspaceChanged));
|
|
|
|
join(screen.workspaceCountSig(),
|
|
|
|
FbTk::MemFun(*this, &WorkspaceMenu::workspaceInfoChanged));
|
2008-09-21 13:25:47 +00:00
|
|
|
join(screen.workspaceNamesSig(),
|
|
|
|
FbTk::MemFun(*this, &WorkspaceMenu::workspaceInfoChanged));
|
2008-09-18 20:27:16 +00:00
|
|
|
|
2004-05-02 20:51:36 +00:00
|
|
|
using namespace FbTk;
|
2004-06-07 11:46:05 +00:00
|
|
|
_FB_USES_NLS;
|
2004-05-02 20:51:36 +00:00
|
|
|
|
|
|
|
removeAll();
|
|
|
|
|
2006-06-21 14:41:16 +00:00
|
|
|
setLabel(_FB_XTEXT(Workspace, MenuTitle, "Workspaces", "Title of main workspace menu"));
|
|
|
|
insert(_FB_XTEXT(Menu, Icons, "Icons", "Iconic windows menu title"),
|
2005-06-08 23:03:12 +00:00
|
|
|
MenuCreator::createMenuType("iconmenu", screen.screenNumber()));
|
|
|
|
insert(new FbTk::MenuSeparator());
|
2004-05-02 20:51:36 +00:00
|
|
|
|
2011-02-24 10:16:16 +00:00
|
|
|
::add_workspaces(*this, screen);
|
|
|
|
setItemSelected(screen.currentWorkspace()->workspaceID() + IDX_AFTER_ICONS, true);
|
2005-07-04 18:19:09 +00:00
|
|
|
|
2008-01-11 07:41:22 +00:00
|
|
|
RefCount<Command<void> > saverc_cmd(new FbCommands::SaveResources());
|
2005-07-04 18:19:09 +00:00
|
|
|
|
|
|
|
MacroCommand *new_workspace_macro = new MacroCommand();
|
2008-01-11 07:41:22 +00:00
|
|
|
RefCount<Command<void> > addworkspace(new SimpleCommand<BScreen>(screen, (SimpleCommand<BScreen>::Action)&BScreen::addWorkspace));
|
2005-07-04 18:19:09 +00:00
|
|
|
new_workspace_macro->add(addworkspace);
|
|
|
|
new_workspace_macro->add(saverc_cmd);
|
2008-01-11 07:41:22 +00:00
|
|
|
RefCount<Command<void> > new_workspace_cmd(new_workspace_macro);
|
2005-07-04 18:19:09 +00:00
|
|
|
|
|
|
|
MacroCommand *remove_workspace_macro = new MacroCommand();
|
2008-01-11 07:41:22 +00:00
|
|
|
RefCount<Command<void> > rmworkspace(new SimpleCommand<BScreen>(screen, (SimpleCommand<BScreen>::Action)&BScreen::removeLastWorkspace));
|
2005-07-04 18:19:09 +00:00
|
|
|
remove_workspace_macro->add(rmworkspace);
|
|
|
|
remove_workspace_macro->add(saverc_cmd);
|
2008-01-11 07:41:22 +00:00
|
|
|
RefCount<Command<void> > remove_last_cmd(remove_workspace_macro);
|
2005-07-04 18:19:09 +00:00
|
|
|
|
2008-01-11 07:41:22 +00:00
|
|
|
RefCount<Command<void> > start_edit(FbTk::CommandParser<void>::instance().parse("setworkspacenamedialog"));
|
2005-06-08 23:03:12 +00:00
|
|
|
|
|
|
|
insert(new FbTk::MenuSeparator());
|
2006-06-21 14:41:16 +00:00
|
|
|
insert(_FB_XTEXT(Workspace, NewWorkspace, "New Workspace", "Add a new workspace"),
|
2005-07-04 18:19:09 +00:00
|
|
|
new_workspace_cmd);
|
2006-06-21 14:41:16 +00:00
|
|
|
insert(_FB_XTEXT(Toolbar, EditWkspcName, "Edit current workspace name", "Edit current workspace name"),
|
2005-06-08 23:03:12 +00:00
|
|
|
start_edit);
|
2006-06-21 14:41:16 +00:00
|
|
|
insert(_FB_XTEXT(Workspace, RemoveLast, "Remove Last", "Remove the last workspace"),
|
2005-07-04 18:19:09 +00:00
|
|
|
remove_last_cmd);
|
2011-02-24 10:16:16 +00:00
|
|
|
|
2004-12-13 14:03:17 +00:00
|
|
|
updateMenu();
|
2004-05-02 20:51:36 +00:00
|
|
|
}
|