File: wb_sql_editor_panel.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 (211 lines) | stat: -rw-r--r-- 5,488 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
/*
 * Copyright (c) 2014, 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 __MySQLWorkbench__wb_sql_editor_panel__
#define __MySQLWorkbench__wb_sql_editor_panel__

#include "workbench/wb_backend_public_interface.h"

#include "mforms/appview.h"
#include "mforms/box.h"
#include "mforms/splitter.h"
#include "mforms/tabview.h"
#include "mforms/tabview_dock.h"
#include "mforms/button.h"
#include "mforms/label.h"
#include "mforms/imagebox.h"
#include "mforms/dockingpoint.h"
#include "mforms/menubar.h"

#include <boost/signals2.hpp>

namespace mforms
{
  class TabView;
  class TabSwitcher;
  class ToolBar;
  class ToolBarItem;
  class ContextMenu;
  class TreeNodeView;
  class RecordGrid;
};

class SqlEditorForm;
class MySQLEditor;

class SqlEditorResult;

class MYSQLWBBACKEND_PUBLIC_FUNC SqlEditorPanel : public mforms::AppView
{
  friend class SqlEditorResult;

  SqlEditorForm *_form;
  boost::shared_ptr<MySQLEditor> _editor;

  mforms::Box _editor_box;

  mforms::Splitter _splitter;
  mforms::TabView _lower_tabview;
  mforms::TabViewDockingPoint _lower_dock_delegate;
  mforms::DockingPoint _lower_dock;
  mforms::ContextMenu _lower_tab_menu;

  mforms::Box _tab_action_box;
  mforms::Button _tab_action_apply;
  mforms::Button _tab_action_revert;
  mforms::ImageBox _tab_action_icon;
  mforms::Label _tab_action_info;

  std::string _title;
  std::string _filename;
  std::string _orig_encoding;
  std::string _caption;

  std::string _autosave_file_suffix;

  time_t _file_timestamp;

  int _rs_sequence;

  bool _busy;
  bool _was_empty;
  bool _is_scratch;

  mforms::ToolBar *setup_editor_toolbar();
  void update_title();

  void dock_result_panel(SqlEditorResult *result);
  void show_find_panel(mforms::CodeEditor *editor, bool show);

  void dispose_recordset(Recordset::Ptr rs_ptr);
  bool on_close_by_user();
  void on_recordset_context_menu_show(Recordset::Ptr rs_ptr);

  void lower_tab_switched();
  bool lower_tab_closing(int tab);
  void lower_tab_closed(mforms::View *page, int tab);
  void lower_tab_reordered(mforms::View*, int, int);

  void result_removed();

  void apply_clicked();
  void revert_clicked();

  void resultset_edited();
  void splitter_resized();

  void tab_menu_will_show();
  void rename_tab_clicked();
  void pin_tab_clicked();
  void close_tab_clicked();
  void close_other_tabs_clicked();

  bool is_pinned(int tab);
  void tab_pinned(int tab, bool flag);

  void limit_rows(mforms::ToolBarItem *);

public:
  typedef boost::shared_ptr<SqlEditorPanel> Ref;
  SqlEditorPanel(SqlEditorForm *owner, bool is_scratch, bool start_collapsed);
  ~SqlEditorPanel();

  boost::shared_ptr<MySQLEditor> editor_be() { return _editor; }
  db_query_QueryEditorRef grtobj();

  mforms::ToolBar *get_toolbar();
  virtual void set_title(const std::string &title);

  void update_limit_rows();

  SqlEditorForm *owner() { return _form; }

  bool is_scratch() { return _is_scratch; }
public:

  struct AutoSaveInfo
  {
    std::string orig_encoding;
    std::string type;
    std::string title;
    std::string filename;
    size_t first_visible_line;
    size_t caret_pos;
    bool word_wrap;
    bool show_special;

    AutoSaveInfo() : first_visible_line(0), caret_pos(0), word_wrap(false), show_special(false) {}
    AutoSaveInfo(const std::string &info_file);

    static AutoSaveInfo old_scratch(const std::string &scratch_file);
    static AutoSaveInfo old_autosave(const std::string &autosave_file);
  };

  enum LoadResult
  {
    Cancelled,
    Loaded,
    RunInstead
  };

  LoadResult load_from(const std::string &file, const std::string &encoding = "", bool keep_dirty=false);
  bool load_autosave(const AutoSaveInfo &info, const std::string &text_file);

  virtual bool can_close();
  virtual void close();

  bool save();
  bool save_as(const std::string &file);
  void revert_to_saved();

  void auto_save(const std::string &directory);
  void delete_auto_save(const std::string &directory);
  std::string autosave_file_suffix();

  void set_filename(const std::string &f);
  std::string filename() const { return _filename; }

  bool is_dirty() const;
  void check_external_file_changes();

  std::pair<const char*, size_t> text_data() const;

  void list_members();
  void jump_to_placeholder();

public:
  void query_started(bool retain_old_recordsets);
  void query_finished();
  void query_failed(const std::string &message);

  // recordset management
  SqlEditorResult *active_result_panel();

  SqlEditorResult *result_panel(int i);

  size_t result_panel_count();
  size_t resultset_count();

  SqlEditorResult* add_panel_for_recordset(Recordset::Ref rset);
  void add_panel_for_recordset_from_main(Recordset::Ref rset);

  std::list<SqlEditorResult*> dirty_result_panels();
};

#endif /* defined(__MySQLWorkbench__wb_sql_editor_panel__) */