File: sql_editor_fe.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 (150 lines) | stat: -rw-r--r-- 4,358 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
#ifndef __SQL_EDITOR_FE_H__
#define __SQL_EDITOR_FE_H__

#include "sqlide/sql_editor_be.h"
#include <gtkmm.h>

#include "Scintilla.h"
#include "SciLexer.h"
#define PLAT_GTK 2
#define GTK
#include "ScintillaWidget.h"

class SqlEditorFE : public sigc::trackable
{
  public:
    typedef boost::shared_ptr<SqlEditorFE>  Ref;

    SqlEditorFE();
    Gtk::Widget& widget();
    Gtk::Container& container();
    

    static SqlEditorFE* from(Gtk::Widget *w);

  public:
    Sql_editor::Ref be() { return _be; }
    void be(Sql_editor::Ref be);
    void check_sql(bool sync= false);
    void background_action_cb(sigc::slot<void> slot) { _background_action_cb= slot; }
  
    bool is_dirty() { return _dirty; }
    void set_dirty(bool flag);

    void show_special_chars(bool flag);

    void show_find_panel(bool flag=true);
    void enable_replace_panel(bool flag);
  private:

    bool on_background_action_timer();

    Sql_editor::Ref _be;
    sigc::slot<void> _background_action_cb;
    sigc::connection _background_action_timer_conn;
    int _old_selection_start, _old_selection_end;

    void change_selected_range(int start, int end);
    void change_cursor_pos(int pos);

    bool on_find_key_press(GdkEventKey *key);
    void find_text_changed();

  public:
    std::string current_sql_statement();

  public:
    void set_text(const std::string& text);
    std::string get_text();
    std::string get_selected_text();
    void set_savepoint();
    bool get_modify();
    void scroll_to(const int line, const std::string& msg);
    void set_focus();
  
    void set_font(const std::string &font);

    sigc::signal<void>& signal_text_changed() {return _text_changed_signal;}
    sigc::signal<void>& signal_selection_changed() { return _selection_changed_signal; }

    int reset_sql_check_state();
    int process_sql_statement_border(int begin_lineno, int begin_line_pos, int end_lineno, int end_line_pos);
    int process_sql_error(const int err_tok_line, const int err_tok_line_pos, const int err_tok_len, const std::string &err_msg);

    bool sql_got_errors() const { return _errors_count != 0; }

    void insert_text(const std::string &text);
    void replace_selected_text(const std::string &text);

  public:
    enum FindResult
    {
      FoundMatch,
      NoMoreMatches,
      WrappedAround,
      NoMatches
    };
    void select_all();
    void copy();
    void delete_();
    void paste();
    bool has_selection();
    bool is_editable();
    FindResult find_text(const std::string &text, bool match_case=false, bool match_whole_word=false, bool forward=true);
  
    bool can_undo();
    bool can_redo();
    void undo();
    void redo();

    void toggle_wrap_lines();

  private:
    enum ReplaceType
    {
      Replace,
      ReplaceAll,
      FindReplace
    };
    void notify(SCNotification *notification);
    bool margin_click(int position, int modifiers);
    void fold_changed(int line, int levelNow, int levelPrev);
    void expand(int &line, bool doExpand, bool force=false, int visLevels=0, int level=-1);
    void fold_code(bool expanding);
    void fold_open_all();
    void fold_close_all();
    void do_find(bool forward);
    void do_replace(ReplaceType type);
    void find_icon_press(Gtk::EntryIconPosition pos, const GdkEventButton *ev);
    void add_search_history(const std::string &entry);
    void clear_search_history();

    Gtk::VBox            _container;
    Glib::RefPtr<Gtk::Builder> _find_panel;
    Gtk::Widget         *_widget; // Gtkmm wrapped _editor
    GtkWidget           *_editor;
    ScintillaObject     *_sci;
    Gtk::Menu            _context_menu;

    Gtk::Entry          *_find_entry;
    Gtk::Entry          *_replace_entry;
    Gtk::Label          *_find_status;
    Gtk::Menu           *_search_menu;
    bool                _search_match_whole_word;
    bool                _search_ignore_case;
    bool                _search_wrap_around;

    sptr_t send_editor(unsigned int msg, uptr_t uparam = 0, sptr_t sparam = 0);
    sigc::signal<void>  _text_changed_signal;
    sigc::signal<void>  _selection_changed_signal;

    static void notify_signal(GtkWidget *w, gint wParam, gpointer lParam, SqlEditorFE *editor);
    int _errors_count;
  
    bool on_button_press_event(GdkEventButton *event);
    void activate_menu_action(const std::string &action);
  
    bool _dirty;
};

#endif