File: wb_command_ui.h

package info (click to toggle)
mysql-workbench 6.3.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 113,932 kB
  • ctags: 87,814
  • sloc: ansic: 955,521; cpp: 427,465; python: 59,728; yacc: 59,129; xml: 54,204; sql: 7,091; objc: 965; makefile: 638; sh: 613; java: 237; perl: 30; ruby: 6; php: 1
file content (122 lines) | stat: -rw-r--r-- 4,081 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* 
 * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 of the
 * License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#ifndef _WB_COMMAND_UI_H_
#define _WB_COMMAND_UI_H_

#include "wb_backend_public_interface.h"

#include "base/trackable.h"

#include "grt/grt_manager.h"
#include "grts/structs.app.h"
#include "mdc_events.h"

namespace mforms
{
  class MenuBar;
  class MenuItem;
  class ToolBar;
  class ToolBarItem;
};

namespace wb
{
  struct ParsedCommand;
  class WBContext;

  struct WBShortcut
  {
    std::string shortcut;
    mdc::KeyInfo key;
    mdc::EventState modifiers;
    
    std::string name;
    std::string command;
  };
  
  
  // Manager menus and toolbars.
  class MYSQLWBBACKEND_PUBLIC_FUNC CommandUI: public base::trackable
  {
//    friend class WBContextUI;
    
    struct BuiltinCommand
    {
      boost::function<void ()> execute;
      boost::function<bool ()> validate;
    };

    WBContext *_wb;
    // dynamic UI stuff
    grt::ListRef<app_ShortcutItem> _shortcuts;

    std::map<std::string, BuiltinCommand> _builtin_commands;
    boost::signals2::signal<void ()> _validate_edit_menu_items;
    bec::ArgumentPool _argpool;
    bool _include_se;

    bool validate_command_item(const app_CommandItemRef &item, const ParsedCommand &cmd);
    void update_item_state(const app_ToolbarItemRef &item, const ParsedCommand &cmd, mforms::ToolBarItem *tb_item);
    void update_item_state(const app_CommandItemRef &item, const ParsedCommand &cmd, mforms::MenuItem *menu_item);

    void append_shortcut_items(const grt::ListRef<app_ShortcutItem> &plist, const std::string &context,
      std::vector<WBShortcut> *items);

    bool execute_builtin_command(const std::string &name);
    bool validate_builtin_command(const std::string &name);
    bool validate_plugin_command(app_PluginRef plugin);
    
  private:
    void add_recent_menu(mforms::MenuItem *parent);
    void add_plugins_menu_items(mforms::MenuItem *parent, const std::string &group);
    void add_plugins_menu(mforms::MenuItem *parent, const std::string &context);
    void add_menu_items_for_context(const std::string &context, mforms::MenuItem *parent, const app_MenuItemRef &menu);
    void add_scripts_menu(mforms::MenuItem *parent);
    
    void menu_will_show(mforms::MenuItem *parent);
  public:
    mforms::MenuBar *create_menubar_for_context(const std::string &context);
 
    void revalidate_menu_bar(mforms::MenuBar *menu);   
    void revalidate_edit_menu_items();
  public:
    CommandUI(WBContext *wb);

    mforms::ToolBar *create_toolbar(const std::string &toolbar_file);
    mforms::ToolBar *create_toolbar(const std::string &toolbar_file, const boost::function<void (std::string)> &activate_slot);
    
    void load_data();

    void activate_command(const std::string &command);
    bool activate_command(const std::string &command, bec::ArgumentPool argpool);
    
    std::vector<WBShortcut> get_shortcuts_for_context(const std::string &context);

    void add_frontend_commands(const std::list<std::string> &commands);
    void remove_frontend_commands(const std::list<std::string> &commands);
    void add_builtin_command(const std::string &name, 
                             const boost::function<void ()> &slot,
                             const boost::function<bool ()> &validate= boost::function<bool ()>());
    void remove_builtin_command(const std::string &name);    
  };
};


#endif /* _WB_COMMAND_UI_H_ */