File: sqlide_form.h

package info (click to toggle)
mysql-workbench 5.2.40%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 53,880 kB
  • sloc: cpp: 419,850; yacc: 74,784; xml: 54,510; python: 31,455; sh: 9,423; ansic: 4,736; makefile: 2,442; php: 529; java: 237
file content (233 lines) | stat: -rw-r--r-- 7,597 bytes parent folder | download
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#ifndef __DB_SQL_EDITOR_VIEW_H__
#define __DB_SQL_EDITOR_VIEW_H__

#include "mforms/toolbar.h"
#include "sqlide/wb_sql_editor_form.h"
#include "sqlide/sql_editor_fe.h"
#include "sqlide/recordset_view.h"
#include "linux_utilities/form_view_base.h"
#include "linux_utilities/notebooks.h"
#include "overview_panel.h"
//#include "gtk_helpers.h"
#include "active_label.h"
#include <glib.h>

class SqlSnippetsView;
class ToolbarManager;
class DbSqlEditorView;

//==============================================================================
//
//==============================================================================
class QueryOutputView
{
  public:
    QueryOutputView(const SqlEditorForm::Ref& be, DbSqlEditorView* db_sql_editor_view);

    Gtk::Widget& get_outer() {return _top_box;}
    void refresh();
    void output_text(const std::string& text, const bool bring_to_front);

  private:
    void mode_change_requested();
    int  on_history_entries_refresh();
    int  on_history_details_refresh();
    void on_history_entries_selection_changed();
    bool on_query_tooltip(int x, int y, bool keyboard_tooltip, const Glib::RefPtr<Gtk::Tooltip>& tooltip);


    void handle_action_output_context_menu(const std::string& action);
    void handle_history_context_menu(const std::string& action);
    void history_context_menu_responder();

    SqlEditorForm::Ref      _be;
    Gtk::VBox               _top_box;
    Gtk::Notebook           _note;
    Gtk::ComboBoxText       _mode;
    Gtk::Menu               _context_menu;

    // Text output part
    Gtk::ScrolledWindow     _text_swnd;
    Gtk::TextView           _text_output;

    // Action output
    GridView                _action_output;
    Gtk::ScrolledWindow     _action_swnd;

    // History output
    Gtk::HPaned             _history_box;
    Gtk::ScrolledWindow     _entries_swnd;
    GridView                _entries_grid;
    Gtk::ScrolledWindow     _details_swnd;
    GridView                _details_grid;

    sigc::connection        _on_history_entries_selection_changed_conn;
    DbSqlEditorView        *_db_sql_editor_view;
};


//==============================================================================
//
//==============================================================================
class QueryView : public sigc::trackable
{
  public:
    QueryView(const int editor_index, DbSqlEditorView* owner);
    ~QueryView();
    Gtk::Widget* get_outer() {return &_top_pane;}

    void update_label(const std::string& label);
    void update_recordset_caption();
    void update_resultsets();
    void close();
    void focus();

    void set_sql(const std::string& sql) {_editor.set_text(sql);}
    std::string get_sql() {return _editor.get_text();}

    void set_linked_label(ActiveLabel* lbl); // Label associated with the view in gtk::notebook
    void update_exec_sql_progress(float progress, const std::string &message);
    void execute_sql(bool current_statement_only);
    int index();

    Sql_editor::Ref     sql_editor_be() {return _editor.be();}

    SqlEditorFE *get_editor_fe() { return &_editor; }

    void save();
    std::string editor_path();

    void reenable_items_in_tab_menus();
    void stop_busy();

  private:
    void tab_reordered(Gtk::Widget*, guint)
    {
      recalc_rstab_indices();
    }
    void recalc_rstab_indices();
    void polish();
    void top_pane_changed();

    void on_sql_editor_selection_change();

    RecordsetView* active_recordset();
    void close_recordset(long long key, bool confirm);
    void close_recordset_by_ptr(RecordsetView *view, const bool confirm);

    void rs_page_switched(GtkNotebookPage *page, guint index);
    void apply_recordset_changes();
    void discard_recordset_changes();
    int process_task_msg(int msgType, const std::string &message, const std::string &detail, RecordsetView *rsv);

    void init_tab_menu(mforms::Menu* menu);
    void tab_menu_handler(const std::string& action, ActiveLabel* sender, RecordsetView* qv);

    DbSqlEditorView         *_owner;
    Gtk::VBox                _editor_box;
    Gtk::VBox                _rs_box;
    Gtk::VPaned              _top_pane;
    SqlEditorFE              _editor;
    ActiveLabel             *_label; // label from the tabswitcher/notebook
    ActionAreaNotebook       _rs_tabs;
    mforms::ToolBar::Ptr    _query_toolbar;
    Gtk::HBox               _btn_box;
    Gtk::Button             _apply_btn;
    Gtk::Button             _cancel_btn;
    Gtk::Label              _editability_label;
    Gtk::Image              _editability_icon;

    sigc::connection        _polish_conn;
    bool                    _query_collapsed;
    bool                    _updating_results;
};


//==============================================================================
//
//==============================================================================
class DbSqlEditorView : public Gtk::VBox, public FormViewBase
{
  public:
    DbSqlEditorView(SqlEditorForm::Ref editor_be);
    static DbSqlEditorView *create(SqlEditorForm::Ref editor_be);
    virtual ~DbSqlEditorView();

    virtual void init();
    virtual bool on_close();
    virtual void dispose();

    virtual bec::BaseEditor* get_be() { return NULL; }
    virtual std::string get_title() { return _be->caption(); }
    virtual bec::UIForm *get_form() const { return _be.get(); }
    virtual Gtk::Widget *get_panel() { return this; }
    //virtual void toggle_sidebar();
    virtual bool show_find(bool replace);

    virtual bool perform_command(const std::string &command);

    SqlEditorForm::Ref be()
    {
      return _be;
    }

    void close_editor_tab(QueryView* qv);
    void output_text(const std::string &text, bool bring_to_front);

    virtual bool close_focused_tab();

    QueryView *active_view();
    std::vector<QueryView*> query_views();

    bec::GRTManager* grt_manager() {return _grtm;}

  protected:
    virtual void plugin_tab_added(PluginEditorBase *plugin);

  private:
    void polish();

    bool validate_explain_sql();
    void explain_sql();

    int  on_exec_sql_progress(float progress, const std::string &message);
    void recordset_list_changed(int editor_index, Recordset::Ref rset, bool added);
    int  on_sql_editor_text_insert(const std::string &text);
    int on_exec_sql_done();

    void update_resultsets(int editor_index, Recordset::Ref rset, bool added);
    void update_resultsets_from_main();
    std::deque<sigc::slot<void> >  _update_resultset_slots; // Slot will have editor index, resultset attached
    GMutex                        *_update_resultset_slots_lock;

    int  add_editor_tab(int active_sql_editor_index);
    void editor_page_switched(GtkNotebookPage *page, guint index);
    void editor_page_reordered(Gtk::Widget *page, guint index) {recalc_tab_indices();}

    void partial_refresh_ui(const int what);

    QueryView *find_view_by_index(const int index);
    void recalc_tab_indices();

    void init_tab_menu(mforms::Menu* menu);
    void tab_menu_handler(const std::string& action, ActiveLabel* sender, QueryView* qv);
    void reenable_items_in_tab_menus();

    SqlEditorForm::Ref    _be;
    Gtk::HPaned           _top_pane;
    Gtk::HPaned           _top_right_pane;
    Gtk::VPaned           _main_pane;
    QueryOutputView       _output;
    Gtk::Widget          *_side_palette;

    sigc::connection      _polish_conn;


    Glib::Dispatcher      _dispatch_rset_update;
    sigc::connection      _dispatch_rset_update_conn;
    bec::GRTManager      *_grtm;
    const bool            _right_aligned;
};


#endif // __DB_SQL_EDITOR_VIEW_H__