File: editor_stored_note_fe.cpp

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 (117 lines) | stat: -rw-r--r-- 3,303 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
/*
 * Copyright (c) 2009, 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/wb_editor_storednote.h"
#include "gtk_helpers.h"
#include <gtkmm/textview.h>
#include <gtkmm/button.h>
#include <gtkmm/entry.h>
#include <gtkmm/box.h>
#include <gtkmm/messagedialog.h>

class StoredNoteEditor : public PluginEditorBase
{
  StoredNoteEditorBE *_be;
  Glib::RefPtr<Gtk::Builder> _xml;

  virtual bec::BaseEditor *get_be()
  {
    return _be;
  }
  
  void apply();
  void discard();
 
  virtual bool can_close();
public:
  StoredNoteEditor(grt::Module *m, bec::GRTManager *grtm, const grt::BaseListRef &args)
    : PluginEditorBase(m, grtm, args), _be(0)
  {
    set_border_width(8);
    
    _xml= Gtk::Builder::create_from_file(grtm->get_data_file_path("modules/data/editor_storednote.glade"));

    Gtk::VBox* box(0);
    _xml->get_widget("vbox1", box);
    box->reparent(*this);

    show_all();
    
    switch_edited_object(grtm, args);
    
    Gtk::Button* btn(0);
    _xml->get_widget("apply", btn);
    btn->signal_clicked().connect(sigc::mem_fun(this, &StoredNoteEditor::apply));

    _xml->get_widget("discard", btn);
    btn->signal_clicked().connect(sigc::mem_fun(this, &StoredNoteEditor::discard));
  }

  virtual ~StoredNoteEditor()
  {
    delete _be;
  }
  
  virtual bool switch_edited_object(bec::GRTManager *grtm, const grt::BaseListRef &args)
  {    
    Gtk::VBox *vbox;
    _xml->get_widget("editor_placeholder", vbox);
 
    delete _be;
    _be = new StoredNoteEditorBE(grtm, GrtStoredNoteRef::cast_from(args[0]));

    embed_code_editor(_be->get_sql_editor()->get_container(), vbox, false);
    _be->load_text();
    return true;
  }
  
};

//------------------------------------------------------------------------------
void StoredNoteEditor::apply()
{
  _be->commit_changes();
}

//------------------------------------------------------------------------------
void StoredNoteEditor::discard()
{
  _be->load_text();
}

//------------------------------------------------------------------------------
bool StoredNoteEditor::can_close()
{
  if (!_be->can_close())
  {
    Gtk::MessageDialog dlg("<b>There are unsaved changes in the editor</b>\nPlease Apply or Revert these changes before closing.",
                           true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true);

    dlg.run();
    return false;
  }

  return true;
}

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