~ubuntu-branches/ubuntu/quantal/mysql-workbench/quantal

« back to all changes in this revision

Viewing changes to backend/wbprivate/workbench/wb_command_ui.h

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-03-01 21:57:30 UTC
  • Revision ID: package-import@ubuntu.com-20120301215730-o7y8av8y38n162ro
Tags: upstream-5.2.38+dfsg
ImportĀ upstreamĀ versionĀ 5.2.38+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License as
 
6
 * published by the Free Software Foundation; version 2 of the
 
7
 * License.
 
8
 * 
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
12
 * GNU General Public License for more details.
 
13
 * 
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
17
 * 02110-1301  USA
 
18
 */
 
19
 
 
20
#ifndef _WB_COMMAND_UI_H_
 
21
#define _WB_COMMAND_UI_H_
 
22
 
 
23
 
 
24
#include "wb_context.h"
 
25
#include "base/trackable.h"
 
26
 
 
27
namespace mforms
 
28
{
 
29
  class MenuBar;
 
30
  class MenuItem;
 
31
  class ToolBar;
 
32
  class ToolBarItem;
 
33
};
 
34
 
 
35
namespace wb
 
36
{
 
37
  struct ParsedCommand;
 
38
 
 
39
  // Manager menus and toolbars.
 
40
  class MYSQLWBBACKEND_PUBLIC_FUNC CommandUI: public base::trackable
 
41
  {
 
42
    friend class WBContextUI;
 
43
    
 
44
    struct BuiltinCommand
 
45
    {
 
46
      boost::function<void ()> execute;
 
47
      boost::function<bool ()> validate;
 
48
    };
 
49
 
 
50
    WBContext *_wb;
 
51
    // dynamic UI stuff
 
52
    grt::ListRef<app_ShortcutItem> _shortcuts;
 
53
 
 
54
    std::map<std::string, BuiltinCommand> _builtin_commands;
 
55
    boost::signals2::signal<void ()> _validate_edit_menu_items;
 
56
 
 
57
    bool validate_command_item(const app_CommandItemRef &item, const ParsedCommand &cmd);
 
58
    void update_item_state(const app_ToolbarItemRef &item, const ParsedCommand &cmd, mforms::ToolBarItem *tb_item);
 
59
    void update_item_state(const app_CommandItemRef &item, const ParsedCommand &cmd, mforms::MenuItem *menu_item);
 
60
 
 
61
    void append_shortcut_items(const grt::ListRef<app_ShortcutItem> &plist, const std::string &context,
 
62
      std::vector<WBShortcut> *items);
 
63
 
 
64
    bool execute_builtin_command(const std::string &name);
 
65
    bool validate_builtin_command(const std::string &name);
 
66
    bool validate_plugin_command(const std::string &name);
 
67
    
 
68
  private:
 
69
    void add_recent_menu(mforms::MenuItem *parent);
 
70
    void add_plugins_menu_items(mforms::MenuItem *parent, const std::string &group);
 
71
    void add_plugins_menu(mforms::MenuItem *parent, const std::string &context);
 
72
    void add_menu_items_for_context(const std::string &context, mforms::MenuItem *parent, const app_MenuItemRef &menu);    
 
73
    
 
74
    void menu_will_show(mforms::MenuItem *parent);
 
75
  public:
 
76
    mforms::MenuBar *create_menubar_for_context(const std::string &context);
 
77
    
 
78
    void revalidate_edit_menu_items();
 
79
    boost::signals2::signal<void ()>* signal_validate_edit_menu_items() { return &_validate_edit_menu_items; }
 
80
  public:
 
81
    CommandUI(WBContext *wb);
 
82
 
 
83
    mforms::ToolBar *create_toolbar(const std::string &toolbar_file);
 
84
    mforms::ToolBar *create_toolbar(const std::string &toolbar_file, const boost::function<void (std::string)> &activate_slot);
 
85
    
 
86
    void load_data();
 
87
 
 
88
    void activate_command(const std::string &command);
 
89
    bool activate_command(const std::string &command, bec::ArgumentPool argpool);
 
90
    
 
91
    std::vector<WBShortcut> get_shortcuts_for_context(const std::string &context);
 
92
 
 
93
    void add_frontend_commands(const std::list<std::string> &commands);
 
94
    void remove_frontend_commands(const std::list<std::string> &commands);
 
95
    void add_builtin_command(const std::string &name, 
 
96
                             const boost::function<void ()> &slot,
 
97
                             const boost::function<bool ()> &validate= boost::function<bool ()>());
 
98
    void remove_builtin_command(const std::string &name);    
 
99
  };
 
100
};
 
101
 
 
102
 
 
103
#endif /* _WB_COMMAND_UI_H_ */