File: mysql_view_editor_fe.cpp

package info (click to toggle)
mysql-workbench 6.2.3%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 102,612 kB
  • ctags: 84,593
  • sloc: ansic: 804,682; cpp: 438,759; yacc: 59,129; python: 54,293; xml: 48,851; sql: 5,512; objc: 1,414; makefile: 505; sh: 455; java: 237; ruby: 6; perl: 5; php: 1
file content (177 lines) | stat: -rw-r--r-- 5,494 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
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
/* 
 * Copyright (c) 2008, 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#include "linux_utilities/plugin_editor_base.h"
#include "../backend/mysql_view_editor.h"
#include "grtdb/db_object_helpers.h"
#include "treemodel_wrapper.h"
#include "mysql_editor_priv_page.h"
#include "gtk/mforms_gtk.h"

//==============================================================================
//
//==============================================================================
class DbMySQLViewEditor : public PluginEditorBase
{
  MySQLViewEditorBE                 *_be;
  DbMySQLEditorPrivPage             *_privs_page;
  
  virtual bec::BaseEditor *get_be();
  
 public:
  DbMySQLViewEditor(grt::Module *m, bec::GRTManager *grtm, const grt::BaseListRef &args);
  
  virtual ~DbMySQLViewEditor();
  virtual void do_refresh_form_data();

  virtual bool switch_edited_object(bec::GRTManager *grtm, const grt::BaseListRef &args);
  
  bool comment_lost_focus(GdkEventFocus *ev, Gtk::TextView *view);

 private:
  virtual bool can_close() { return _be->can_close(); }
};

DbMySQLViewEditor::DbMySQLViewEditor(grt::Module *m, bec::GRTManager *grtm, const grt::BaseListRef &args)
    : PluginEditorBase(m ,grtm, args, "modules/data/editor_view.glade")
    , _be(new MySQLViewEditorBE(grtm, db_mysql_ViewRef::cast_from(args[0])))
{
  xml()->get_widget("mysql_view_editor_notebook", _editor_notebook);

  Gtk::Image *image;
  xml()->get_widget("view_editor_image", image);
  image->set(ImageCache::get_instance()->image_from_filename("db.View.editor.48x48.png", false));
  xml()->get_widget("view_editor_image2", image);
  image->set(ImageCache::get_instance()->image_from_filename("db.View.editor.48x48.png", false));

  _be->set_refresh_ui_slot(sigc::mem_fun(this, &DbMySQLViewEditor::refresh_form_data));
  
  _editor_notebook->reparent(*this);
  _editor_notebook->show();



  Gtk::VBox *ddl_win;
  xml()->get_widget("editor_placeholder", ddl_win);
  embed_code_editor(_be->get_sql_editor()->get_container(), ddl_win);
  _be->load_view_sql();

  if (!is_editing_live_object())
  {
    _privs_page     = new DbMySQLEditorPrivPage(_be);
    _editor_notebook->append_page(_privs_page->page(), "Privileges");

    Gtk::TextView *tview(0);
    xml()->get_widget("viewcomment", tview);
    tview->get_buffer()->set_text(_be->get_comment());

    tview->signal_focus_out_event().connect(sigc::bind(sigc::mem_fun(this, &DbMySQLViewEditor::comment_lost_focus), tview), false);
  }
  else
  {
    _editor_notebook->remove_page(1);
    _privs_page= NULL;
  }
    
  refresh_form_data();

  _be->reset_editor_undo_stack();

  show_all();
}

//------------------------------------------------------------------------------
DbMySQLViewEditor::~DbMySQLViewEditor()
{
  delete _privs_page;
  
  delete _be;
}

//------------------------------------------------------------------------------
bool DbMySQLViewEditor::switch_edited_object(bec::GRTManager *grtm, const grt::BaseListRef &args)
{
  MySQLViewEditorBE *old_be = _be;
  Gtk::VBox *ddl_win;
  xml()->get_widget("editor_placeholder", ddl_win);
 
  _be = new MySQLViewEditorBE(grtm, db_mysql_ViewRef::cast_from(args[0]));
  embed_code_editor(_be->get_sql_editor()->get_container(), ddl_win);
  _be->load_view_sql();

  if (!is_editing_live_object())
    _privs_page->switch_be(_be);
  
  _be->set_refresh_ui_slot(sigc::mem_fun(this, &DbMySQLViewEditor::refresh_form_data));

  do_refresh_form_data();
  
  delete old_be;
  old_be = 0;

  return true;
}

//------------------------------------------------------------------------------

bool DbMySQLViewEditor::comment_lost_focus(GdkEventFocus *ev, Gtk::TextView *view) {
  if(_be)
  {
    _be->set_comment(view->get_buffer()->get_text());
  }
  return false;
}

//------------------------------------------------------------------------------
bec::BaseEditor *DbMySQLViewEditor::get_be()
{
  return _be;
}

//------------------------------------------------------------------------------
void DbMySQLViewEditor::do_refresh_form_data()
{
  Gtk::Entry* entry(0);
  xml()->get_widget("view_name", entry);
  if (entry->get_text() != _be->get_name())
  {
    entry->set_text(_be->get_name());
    _signal_title_changed.emit(_be->get_title());
  }

  if (!_be->is_editing_live_object())
  {
    Gtk::TextView *tview(0);
    xml()->get_widget("viewcomment", tview);
    tview->get_buffer()->set_text(_be->get_comment());
  }
  //_sql_editor.set_text(_be->get_query());

  _be->load_view_sql();

  if (!is_editing_live_object())
    _privs_page->refresh();
}


//------------------------------------------------------------------------------
extern "C" 
{
  GUIPluginBase *createDbMysqlViewEditor(grt::Module *m, bec::GRTManager *grtm, const grt::BaseListRef &args)
  {
    return Gtk::manage(new DbMySQLViewEditor(m, grtm, args));
  }
};