~ubuntu-branches/ubuntu/trusty/fluxbox/trusty-proposed

« back to all changes in this revision

Viewing changes to src/MenuCreator.cc

  • Committer: Bazaar Package Importer
  • Author(s): Dmitry E. Oboukhov
  • Date: 2008-07-01 10:38:14 UTC
  • mfrom: (2.1.12 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080701103814-khx2b6il152x9p93
Tags: 1.0.0+deb1-8
* x-dev has been removed from build-depends (out-of-date package).
* Standards-Version bumped to 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// MenuCreator.cc for Fluxbox
2
 
// Copyright (c) 2004 Henrik Kinnunen (fluxgen at fluxbox dot org)
3
 
//                and Simon Bowden    (rathnor at users.sourceforge.net)
4
 
//
5
 
// Permission is hereby granted, free of charge, to any person obtaining a
6
 
// copy of this software and associated documentation files (the "Software"),
7
 
// to deal in the Software without restriction, including without limitation
8
 
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
 
// and/or sell copies of the Software, and to permit persons to whom the
10
 
// Software is furnished to do so, subject to the following conditions:
11
 
//
12
 
// The above copyright notice and this permission notice shall be included in
13
 
// all copies or substantial portions of the Software.
14
 
//
15
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18
 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 
// DEALINGS IN THE SOFTWARE.
22
 
 
23
 
// $Id: MenuCreator.cc 4110 2005-09-14 20:28:15Z fluxgen $
24
 
 
25
 
#include "MenuCreator.hh"
26
 
 
27
 
#include "Screen.hh"
28
 
#include "CommandParser.hh"
29
 
#include "fluxbox.hh"
30
 
#include "CommandParser.hh"
31
 
#include "Window.hh"
32
 
#include "WindowCmd.hh"
33
 
 
34
 
#include "FbMenu.hh"
35
 
#include "IconMenu.hh"
36
 
#include "WorkspaceMenu.hh"
37
 
#include "LayerMenu.hh"
38
 
#include "SendToMenu.hh"
39
 
 
40
 
#include "FbMenuParser.hh"
41
 
#include "StyleMenuItem.hh"
42
 
#include "RootCmdMenuItem.hh"
43
 
 
44
 
#include "FbTk/I18n.hh"
45
 
#include "FbTk/MultiButtonMenuItem.hh"
46
 
#include "FbTk/RefCount.hh"
47
 
#include "FbTk/MacroCommand.hh"
48
 
#include "FbTk/SimpleCommand.hh"
49
 
#include "FbTk/StringUtil.hh"
50
 
#include "FbTk/FileUtil.hh"
51
 
#include "FbTk/MenuSeparator.hh"
52
 
#include "FbTk/MenuIcon.hh"
53
 
 
54
 
#include <iostream>
55
 
using namespace std;
56
 
 
57
 
static void createStyleMenu(FbTk::Menu &parent, const std::string &label,
58
 
                            const std::string &directory) {
59
 
    // perform shell style ~ home directory expansion
60
 
    string stylesdir(FbTk::StringUtil::expandFilename(directory));
61
 
 
62
 
    if (!FbTk::FileUtil::isDirectory(stylesdir.c_str()))
63
 
        return;
64
 
 
65
 
    FbTk::Directory dir(stylesdir.c_str());
66
 
 
67
 
    // create a vector of all the filenames in the directory
68
 
    // add sort it
69
 
    std::vector<std::string> filelist(dir.entries());
70
 
    for (size_t file_index = 0; file_index < dir.entries(); ++file_index)
71
 
        filelist[file_index] = dir.readFilename();
72
 
 
73
 
    std::sort(filelist.begin(), filelist.end(), less<string>());
74
 
 
75
 
    // for each file in directory add filename and path to menu
76
 
    for (size_t file_index = 0; file_index < dir.entries(); file_index++) {
77
 
        std::string style(stylesdir + '/' + filelist[file_index]);
78
 
        // add to menu only if the file is a regular file, and not a
79
 
        // .file or a backup~ file
80
 
        if ((FbTk::FileUtil::isRegularFile(style.c_str()) &&
81
 
             (filelist[file_index][0] != '.') &&
82
 
             (style[style.length() - 1] != '~')) ||
83
 
            FbTk::FileUtil::isRegularFile((style + "/theme.cfg").c_str()) ||
84
 
            FbTk::FileUtil::isRegularFile((style + "/style.cfg").c_str()))
85
 
            parent.insert(new StyleMenuItem(filelist[file_index], style));
86
 
    }
87
 
    // update menu graphics
88
 
    parent.updateMenu();
89
 
    Fluxbox::instance()->saveMenuFilename(stylesdir.c_str());
90
 
 
91
 
}
92
 
 
93
 
static void createRootCmdMenu(FbTk::Menu &parent, const string &label,
94
 
                                const string &directory, const string &cmd) {
95
 
    // perform shell style ~ home directory expansion
96
 
    string rootcmddir(FbTk::StringUtil::expandFilename(directory));
97
 
 
98
 
    if (!FbTk::FileUtil::isDirectory(rootcmddir.c_str()))
99
 
        return;
100
 
 
101
 
    FbTk::Directory dir(rootcmddir.c_str());
102
 
 
103
 
    // create a vector of all the filenames in the directory
104
 
    // add sort it
105
 
    vector<string> filelist(dir.entries());
106
 
    for (size_t file_index = 0; file_index < dir.entries(); ++file_index)
107
 
        filelist[file_index] = dir.readFilename();
108
 
 
109
 
    sort(filelist.begin(), filelist.end(), less<string>());
110
 
 
111
 
    // for each file in directory add filename and path to menu
112
 
    for (size_t file_index = 0; file_index < dir.entries(); file_index++) {
113
 
 
114
 
        string rootcmd(rootcmddir+ '/' + filelist[file_index]);
115
 
        // add to menu only if the file is a regular file, and not a
116
 
        // .file or a backup~ file
117
 
        if ((FbTk::FileUtil::isRegularFile(rootcmd.c_str()) &&
118
 
             (filelist[file_index][0] != '.') &&
119
 
             (rootcmd[rootcmd.length() - 1] != '~')))
120
 
            parent.insert(new RootCmdMenuItem(filelist[file_index], rootcmd, cmd));
121
 
    }
122
 
    // update menu graphics
123
 
    parent.updateMenu();
124
 
    Fluxbox::instance()->saveMenuFilename(rootcmddir.c_str());
125
 
 
126
 
}
127
 
 
128
 
 
129
 
class ParseItem {
130
 
public:
131
 
    explicit ParseItem(FbTk::Menu *menu):m_menu(menu) {}
132
 
 
133
 
    inline void load(Parser &p) {
134
 
        p>>m_key>>m_label>>m_cmd>>m_icon;
135
 
    }
136
 
    inline const std::string &icon() const { return m_icon.second; }
137
 
    inline const std::string &command() const { return m_cmd.second; }
138
 
    inline const std::string &label() const { return m_label.second; }
139
 
    inline const std::string &key() const { return m_key.second; }
140
 
    inline FbTk::Menu *menu() { return m_menu; }
141
 
private:
142
 
    Parser::Item m_key, m_label, m_cmd, m_icon;
143
 
    FbTk::Menu *m_menu;
144
 
};
145
 
 
146
 
class MenuContext: public LayerObject {
147
 
public:
148
 
    void moveToLayer(int layer_number) {
149
 
        if (WindowCmd<void>::window() == 0)
150
 
            return;
151
 
        WindowCmd<void>::window()->moveToLayer(layer_number);
152
 
    }
153
 
    int layerNumber() const {
154
 
        if (WindowCmd<void>::window() == 0)
155
 
            return -1;
156
 
        return WindowCmd<void>::window()->layerItem().getLayerNum();
157
 
    }
158
 
};
159
 
 
160
 
static void translateMenuItem(Parser &parse, ParseItem &item);
161
 
 
162
 
 
163
 
static void parseMenu(Parser &pars, FbTk::Menu &menu) {
164
 
    ParseItem pitem(&menu);
165
 
    while (!pars.eof()) {
166
 
        pitem.load(pars);
167
 
        if (pitem.key() == "end")
168
 
            return;
169
 
        translateMenuItem(pars, pitem);
170
 
    }
171
 
}
172
 
 
173
 
static void translateMenuItem(Parser &parse, ParseItem &pitem) {
174
 
    if (pitem.menu() == 0)
175
 
        throw string("translateMenuItem: We must have a menu in ParseItem!");
176
 
 
177
 
    FbTk::Menu &menu = *pitem.menu();
178
 
    const std::string &str_key = pitem.key();
179
 
    const std::string &str_cmd = pitem.command();
180
 
    const std::string &str_label = pitem.label();
181
 
 
182
 
    const int screen_number = menu.screenNumber();
183
 
    _FB_USES_NLS;
184
 
 
185
 
    if (str_key == "end") {
186
 
        return;
187
 
    } else if (str_key == "nop") {
188
 
        menu.insert(str_label.c_str());
189
 
    } else if (str_key == "icons") {
190
 
        FbTk::Menu *submenu = MenuCreator::createMenuType("iconmenu", menu.screenNumber());
191
 
        if (submenu == 0)
192
 
            return;
193
 
        if (str_label.empty())
194
 
            menu.insert(_FBTEXT(Menu, Icons, "Icons", "Iconic windows menu title"));
195
 
        else
196
 
            menu.insert(str_label.c_str(), submenu);
197
 
    } else if (str_key == "exit") { // exit
198
 
        FbTk::RefCount<FbTk::Command> exit_cmd(CommandParser::instance().parseLine("exit"));
199
 
        if (str_label.empty())
200
 
            menu.insert(_FBTEXT(Menu, Exit, "Exit", "Exit Command"), exit_cmd);
201
 
        else
202
 
            menu.insert(str_label.c_str(), exit_cmd);
203
 
    } else if (str_key == "exec") {
204
 
        // execute and hide menu
205
 
        using namespace FbTk;
206
 
        RefCount<Command> exec_cmd(CommandParser::instance().parseLine("exec " + str_cmd));
207
 
        RefCount<Command> hide_menu(new SimpleCommand<FbTk::Menu>(menu,
208
 
                                                                  &Menu::hide));
209
 
        MacroCommand *exec_and_hide = new FbTk::MacroCommand();
210
 
        exec_and_hide->add(hide_menu);
211
 
        exec_and_hide->add(exec_cmd);
212
 
        RefCount<Command> exec_and_hide_cmd(exec_and_hide);
213
 
        menu.insert(str_label.c_str(), exec_and_hide_cmd);
214
 
    } else if (str_key == "macrocmd") {
215
 
        using namespace FbTk;
216
 
        RefCount<Command> macro_cmd(CommandParser::instance().parseLine("macrocmd " + str_cmd));
217
 
        RefCount<Command> hide_menu(new SimpleCommand<FbTk::Menu>(menu,
218
 
                                                                  &Menu::hide));
219
 
        MacroCommand *exec_and_hide = new FbTk::MacroCommand();
220
 
        exec_and_hide->add(hide_menu);
221
 
        exec_and_hide->add(macro_cmd);
222
 
        RefCount<Command> exec_and_hide_cmd(exec_and_hide);
223
 
        menu.insert(str_label.c_str(), exec_and_hide_cmd);
224
 
    } else if (str_key == "style") {    // style
225
 
        menu.insert(new StyleMenuItem(str_label, str_cmd));
226
 
    } else if (str_key == "config") {
227
 
        BScreen *screen = Fluxbox::instance()->findScreen(screen_number);
228
 
        if (screen != 0)
229
 
            menu.insert(str_label.c_str(), &screen->configMenu());
230
 
    } // end of config
231
 
    else if (str_key == "include") { // include
232
 
 
233
 
        // this will make sure we dont get stuck in a loop
234
 
        static size_t safe_counter = 0;
235
 
        if (safe_counter > 10)
236
 
            return;
237
 
 
238
 
        safe_counter++;
239
 
 
240
 
        string newfile = FbTk::StringUtil::expandFilename(str_label);
241
 
        if (FbTk::FileUtil::isDirectory(newfile.c_str())) {
242
 
            // inject every file in this directory into the current menu
243
 
            FbTk::Directory dir(newfile.c_str());
244
 
 
245
 
            std::vector<std::string> filelist(dir.entries());
246
 
            for (size_t file_index = 0; file_index < dir.entries(); ++file_index)
247
 
                filelist[file_index] = dir.readFilename();
248
 
            std::sort(filelist.begin(), filelist.end(), less<string>());
249
 
 
250
 
            for (size_t file_index = 0; file_index < dir.entries(); file_index++) {
251
 
                std::string thisfile(newfile + '/' + filelist[file_index]);
252
 
 
253
 
                if (FbTk::FileUtil::isRegularFile(thisfile.c_str()) &&
254
 
                        (filelist[file_index][0] != '.') &&
255
 
                        (thisfile[thisfile.length() - 1] != '~')) {
256
 
                    MenuCreator::createFromFile(thisfile, menu, false);
257
 
                    Fluxbox::instance()->saveMenuFilename(thisfile.c_str());
258
 
                }
259
 
            }
260
 
 
261
 
        } else {
262
 
            // inject this file into the current menu
263
 
            MenuCreator::createFromFile(newfile, menu, false);
264
 
            Fluxbox::instance()->saveMenuFilename(newfile.c_str());
265
 
        }
266
 
 
267
 
        safe_counter--;
268
 
 
269
 
    } // end of include
270
 
    else if (str_key == "submenu") {
271
 
 
272
 
        FbTk::Menu *submenu = MenuCreator::createMenu("", screen_number);
273
 
        if (submenu == 0)
274
 
            return;
275
 
 
276
 
        if (str_cmd.size())
277
 
            submenu->setLabel(str_cmd.c_str());
278
 
        else
279
 
            submenu->setLabel(str_label.c_str());
280
 
 
281
 
        parseMenu(parse, *submenu);
282
 
        submenu->updateMenu();
283
 
        menu.insert(str_label.c_str(), submenu);
284
 
        // save to screen list so we can delete it later
285
 
        BScreen *screen = Fluxbox::instance()->findScreen(screen_number);
286
 
        if (screen != 0)
287
 
            screen->saveMenu(*submenu);
288
 
 
289
 
    } // end of submenu
290
 
    else if (str_key == "stylesdir" || str_key == "stylesmenu") {
291
 
        createStyleMenu(menu, str_label,
292
 
                        str_key == "stylesmenu" ? str_cmd : str_label);
293
 
    } // end of stylesdir
294
 
    else if (str_key == "themesdir" || str_key == "themesmenu") {
295
 
        createStyleMenu(menu, str_label,
296
 
                        str_key == "themesmenu" ? str_cmd : str_label);
297
 
    } // end of themesdir
298
 
    else if (str_key == "wallpapers" || str_key == "wallpapermenu" ||
299
 
             str_key == "rootcommands") {
300
 
         createRootCmdMenu(menu, str_label, str_label,
301
 
                          str_cmd == "" ? "fbsetbg" : str_cmd);
302
 
    } // end of wallpapers
303
 
    else if (str_key == "workspaces") {
304
 
        BScreen *screen = Fluxbox::instance()->findScreen(screen_number);
305
 
        if (screen != 0) {
306
 
            screen->workspaceMenu().setInternalMenu();
307
 
            menu.insert(str_label.c_str(), &screen->workspaceMenu());
308
 
        }
309
 
    } else if (str_key == "separator") {
310
 
        menu.insert(new FbTk::MenuSeparator());
311
 
    }
312
 
    else { // ok, if we didn't find any special menu item we try with command parser
313
 
        // we need to attach command with arguments so command parser can parse it
314
 
        string line = str_key + " " + str_cmd;
315
 
        FbTk::RefCount<FbTk::Command> command(CommandParser::instance().parseLine(line));
316
 
        if (*command != 0) {
317
 
            // special NLS default labels
318
 
            if (str_label.empty()) {
319
 
                if (str_key == "reconfig" || str_key == "reconfigure") {
320
 
                    menu.insert(_FBTEXT(Menu, Reconfigure, "Reload Config", "Reload all the configs"), command);
321
 
                    return;
322
 
                } else if (str_key == "restart") {
323
 
                    menu.insert(_FBTEXT(Menu, Restart, "Restart", "Restart Command"), command);
324
 
                    return;
325
 
                }
326
 
            }
327
 
            menu.insert(str_label.c_str(), command);
328
 
        }
329
 
    }
330
 
    if (menu.numberOfItems() != 0) {
331
 
        FbTk::MenuItem *item = menu.find(menu.numberOfItems() - 1);
332
 
        if (item != 0 && !pitem.icon().empty())
333
 
            item->setIcon(pitem.icon().c_str(), menu.screenNumber());
334
 
    }
335
 
}
336
 
 
337
 
 
338
 
static void parseWindowMenu(Parser &parse, FbTk::Menu &menu) {
339
 
 
340
 
    ParseItem pitem(&menu);
341
 
    while (!parse.eof()) {
342
 
        pitem.load(parse);
343
 
        if (MenuCreator::createWindowMenuItem(pitem.key(), pitem.label(), menu))
344
 
            continue;
345
 
 
346
 
        if (pitem.key() == "end") {
347
 
            return;
348
 
        } else if (pitem.key() == "submenu") {
349
 
            FbTk::Menu *submenu = MenuCreator::createMenu(pitem.label(), menu.screenNumber());
350
 
            parseWindowMenu(parse, *submenu);
351
 
            submenu->updateMenu();
352
 
            menu.insert(pitem.label().c_str(), submenu);
353
 
 
354
 
        } else { // try non window menu specific stuff
355
 
            translateMenuItem(parse, pitem);
356
 
        }
357
 
    }
358
 
}
359
 
 
360
 
FbTk::Menu *MenuCreator::createMenu(const std::string &label, int screen_number) {
361
 
    BScreen *screen = Fluxbox::instance()->findScreen(screen_number);
362
 
    if (screen == 0)
363
 
        return 0;
364
 
 
365
 
    FbTk::Menu *menu = new FbMenu(screen->menuTheme(),
366
 
                                  screen->imageControl(),
367
 
                                  *screen->layerManager().
368
 
                                  getLayer(Fluxbox::instance()->getMenuLayer()));
369
 
    if (!label.empty())
370
 
        menu->setLabel(label.c_str());
371
 
 
372
 
    return menu;
373
 
}
374
 
 
375
 
bool getStart(FbMenuParser &parser, std::string &label) {
376
 
    ParseItem pitem(0);
377
 
    while (!parser.eof()) {
378
 
        // get first begin line
379
 
        pitem.load(parser);
380
 
        if (pitem.key() == "begin") {
381
 
            break;
382
 
        }
383
 
    }
384
 
    if (parser.eof())
385
 
        return false;
386
 
 
387
 
    label = pitem.label();
388
 
    return true;
389
 
}
390
 
 
391
 
FbTk::Menu *MenuCreator::createFromFile(const std::string &filename, int screen_number, bool require_begin) {
392
 
    std::string real_filename = FbTk::StringUtil::expandFilename(filename);
393
 
    FbMenuParser parser(real_filename);
394
 
    if (!parser.isLoaded())
395
 
        return 0;
396
 
 
397
 
    Fluxbox::instance()->saveMenuFilename(real_filename.c_str());
398
 
 
399
 
    std::string label;
400
 
    if (require_begin && !getStart(parser, label))
401
 
        return 0;
402
 
 
403
 
    FbTk::Menu *menu = createMenu(label, screen_number);
404
 
    if (menu != 0)
405
 
        parseMenu(parser, *menu);
406
 
 
407
 
    return menu;
408
 
}
409
 
 
410
 
 
411
 
bool MenuCreator::createFromFile(const std::string &filename,
412
 
                                 FbTk::Menu &inject_into, bool require_begin) {
413
 
 
414
 
    std::string real_filename = FbTk::StringUtil::expandFilename(filename);
415
 
    FbMenuParser parser(real_filename);
416
 
    if (!parser.isLoaded())
417
 
        return false;
418
 
 
419
 
    std::string label;
420
 
    if (require_begin && !getStart(parser, label))
421
 
        return false;
422
 
 
423
 
    parseMenu(parser, inject_into);
424
 
    return true;
425
 
}
426
 
 
427
 
 
428
 
bool MenuCreator::createWindowMenuFromFile(const std::string &filename,
429
 
                                           FbTk::Menu &inject_into,
430
 
                                           bool require_begin) {
431
 
    std::string real_filename = FbTk::StringUtil::expandFilename(filename);
432
 
    FbMenuParser parser(real_filename);
433
 
    if (!parser.isLoaded())
434
 
        return false;
435
 
 
436
 
    std::string label;
437
 
 
438
 
    if (require_begin && !getStart(parser, label))
439
 
        return false;
440
 
 
441
 
    parseWindowMenu(parser, inject_into);
442
 
    return true;
443
 
}
444
 
 
445
 
 
446
 
FbTk::Menu *MenuCreator::createMenuType(const std::string &type, int screen_num) {
447
 
    BScreen *screen = Fluxbox::instance()->findScreen(screen_num);
448
 
    if (screen == 0)
449
 
        return 0;
450
 
    if (type == "iconmenu") {
451
 
        return new IconMenu(*screen);
452
 
    } else if (type == "workspacemenu") {
453
 
        return new WorkspaceMenu(*screen);
454
 
    } else if (type == "windowmenu") {
455
 
        FbTk::Menu *menu = screen->createMenu("");
456
 
 
457
 
        menu->removeAll(); // clear old items
458
 
        menu->disableTitle(); // not titlebar
459
 
        if (screen->windowMenuFilename().empty() ||
460
 
            ! createWindowMenuFromFile(screen->windowMenuFilename(), *menu, true)) {
461
 
            char default_menu[][11] = {
462
 
                "shade", 
463
 
                "stick",
464
 
                "maximize",
465
 
                "iconify",
466
 
                "raise",
467
 
                "lower",
468
 
                "sendto",
469
 
                "layer",
470
 
                "extramenus",
471
 
                "separator",
472
 
                "close",
473
 
                0
474
 
            };
475
 
            for (int i=0; i < sizeof(default_menu); ++i)
476
 
                createWindowMenuItem(default_menu[i], "", *menu);
477
 
        }
478
 
        menu->reconfigure(); // update graphics
479
 
        return menu;
480
 
    }
481
 
 
482
 
    return 0;
483
 
}
484
 
 
485
 
bool MenuCreator::createWindowMenuItem(const std::string &type,
486
 
                                       const std::string &label,
487
 
                                       FbTk::Menu &menu) {
488
 
    typedef FbTk::RefCount<FbTk::Command> RefCmd;
489
 
    _FB_USES_NLS;
490
 
 
491
 
    if (type == "shade") {
492
 
        RefCmd shade_cmd(new WindowCmd<void>(&FluxboxWindow::shade));
493
 
        menu.insert(label.empty()?_FBTEXT(Windowmenu, Shade, "Shade", "Shade the window"):label.c_str(), shade_cmd);
494
 
    } else if (type == "maximize") {
495
 
        RefCmd maximize_cmd(new WindowCmd<void>(&FluxboxWindow::maximizeFull));
496
 
        RefCmd maximize_vert_cmd(new WindowCmd<void>(&FluxboxWindow::maximizeVertical));
497
 
        RefCmd maximize_horiz_cmd(new WindowCmd<void>(&FluxboxWindow::maximizeHorizontal));
498
 
        FbTk::MultiButtonMenuItem *maximize_item = 
499
 
            new FbTk::MultiButtonMenuItem(3, 
500
 
                                          label.empty()?
501
 
                                          _FBTEXT(Windowmenu, Maximize, 
502
 
                                                  "Maximize", "Maximize the window"):
503
 
                                          label.c_str());
504
 
        // create maximize item with:
505
 
        // button1: Maximize normal
506
 
        // button2: Maximize Vertical
507
 
        // button3: Maximize Horizontal
508
 
        maximize_item->setCommand(1, maximize_cmd);
509
 
        maximize_item->setCommand(2, maximize_vert_cmd);
510
 
        maximize_item->setCommand(3, maximize_horiz_cmd);
511
 
        menu.insert(maximize_item);
512
 
    } else if (type == "iconify") {
513
 
        RefCmd iconify_cmd(new WindowCmd<void>(&FluxboxWindow::iconify));
514
 
        menu.insert(label.empty()?_FBTEXT(Windowmenu, Iconify, "Iconify", "Iconify the window"):label.c_str(), iconify_cmd);
515
 
    } else if (type == "close") {
516
 
        RefCmd close_cmd(new WindowCmd<void>(&FluxboxWindow::close));
517
 
        menu.insert(label.empty()?_FBTEXT(Windowmenu, Close, "Close", "Close the window"):label.c_str(), close_cmd);
518
 
    } else if (type == "kill" || type == "killwindow") {
519
 
        RefCmd kill_cmd(new WindowCmd<void>(&FluxboxWindow::kill));
520
 
        menu.insert(label.empty()?_FBTEXT(Windowmenu, Kill, "Kill", "Kill the window"):label.c_str(), kill_cmd);
521
 
    } else if (type == "lower") {
522
 
        RefCmd lower_cmd(new WindowCmd<void>(&FluxboxWindow::lower));
523
 
        menu.insert(label.empty()?_FBTEXT(Windowmenu, Lower, "Lower", "Lower the window"):label.c_str(), lower_cmd);
524
 
    } else if (type == "raise") {
525
 
        RefCmd raise_cmd(new WindowCmd<void>(&FluxboxWindow::raise));
526
 
        menu.insert(label.empty()?_FBTEXT(Windowmenu, Raise, "Raise", "Raise the window"):label.c_str(), raise_cmd);
527
 
    } else if (type == "stick") {
528
 
        RefCmd stick_cmd(new WindowCmd<void>(&FluxboxWindow::stick));
529
 
        menu.insert(label.empty()?_FBTEXT(Windowmenu, Stick, "Stick", "Stick the window"):label.c_str(), stick_cmd);
530
 
    } 
531
 
    else if (type == "extramenus") {
532
 
        BScreen *screen = Fluxbox::instance()->findScreen(menu.screenNumber());
533
 
        BScreen::ExtraMenus::iterator it = screen->extraWindowMenus().begin();
534
 
        BScreen::ExtraMenus::iterator it_end = screen->extraWindowMenus().end();
535
 
        for (; it != it_end; ++it) {
536
 
            it->second->disableTitle();
537
 
            menu.insert(it->first, it->second);
538
 
        }
539
 
        
540
 
    } else if (type == "sendto") {
541
 
        menu.insert(label.empty() ? _FBTEXT(Windowmenu, SendTo, "Send To...", "Send to menu item name"):
542
 
                    label.c_str(), new SendToMenu(*Fluxbox::instance()->findScreen(menu.screenNumber())));
543
 
    }else if (type == "layer") {
544
 
        BScreen *screen = Fluxbox::instance()->findScreen(menu.screenNumber());
545
 
        if (screen == 0)
546
 
            return false;
547
 
 
548
 
        static MenuContext context;
549
 
 
550
 
        FbTk::Menu *submenu = new LayerMenu(screen->menuTheme(),
551
 
                                            screen->imageControl(),
552
 
                                            *screen->layerManager().
553
 
                                            getLayer(Fluxbox::instance()->getMenuLayer()),
554
 
                                            &context,
555
 
                                            false);
556
 
        submenu->disableTitle();
557
 
        menu.insert(label.empty()?_FBTEXT(Windowmenu, Layer, "Layer ...", "Layer menu"):label.c_str(), submenu);
558
 
 
559
 
 
560
 
    } else if (type == "separator") {
561
 
        menu.insert(new FbTk::MenuSeparator());
562
 
    } else
563
 
        return false;
564
 
 
565
 
    return true;
566
 
}