4 Website: http://www.vultaire.net/software/jben/
5 License: GNU General Public License (GPL) version 2
6 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt)
8 File: dialog_vocablisteditor.cpp
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>
24 #include "dialog_vocablisteditor.h"
25 #include <gtkmm/scrolledwindow.h>
26 #include <gtkmm/buttonbox.h>
27 #include <gtkmm/messagedialog.h>
28 #include <gtkmm/stock.h>
29 #include <glibmm/i18n.h>
30 #include <boost/format.hpp>
31 #include "listmanager.h"
32 #include "encoding_convert.h"
34 DialogVocabListEditor::DialogVocabListEditor(Gtk::Window
& parent
)
35 : StoredDialog(_("Vocab List Editor"), parent
, "gui.dlg.vocablisteditor.size"),
36 btnCancel(Gtk::Stock::CANCEL
),
37 btnApply(Gtk::Stock::APPLY
),
38 btnOK(Gtk::Stock::OK
),
42 tvList
.set_accepts_tab(false);
43 tvList
.set_wrap_mode(Gtk::WRAP_WORD_CHAR
);
44 tvList
.get_buffer()->signal_changed()
45 .connect(sigc::mem_fun(*this, &DialogVocabListEditor::OnTextChanged
));
46 btnCancel
.signal_clicked()
47 .connect(sigc::mem_fun(*this, &DialogVocabListEditor::OnCancel
));
48 btnApply
.signal_clicked()
49 .connect(sigc::mem_fun(*this, &DialogVocabListEditor::OnApply
));
50 btnOK
.signal_clicked()
51 .connect(sigc::mem_fun(*this, &DialogVocabListEditor::OnOK
));
53 .connect(sigc::mem_fun(*this, &DialogVocabListEditor::OnDeleteEvent
),
56 Gtk::ScrolledWindow
*pswTvList
= manage(new Gtk::ScrolledWindow
);
57 pswTvList
->add(tvList
);
58 pswTvList
->set_shadow_type(Gtk::SHADOW_IN
);
59 pswTvList
->set_policy(Gtk::POLICY_AUTOMATIC
, Gtk::POLICY_AUTOMATIC
);
61 Gtk::VBox
* pvb
= get_vbox();
63 pvb
->pack_start(*pswTvList
);
65 Gtk::ButtonBox
* phbb
= get_action_area();
66 phbb
->pack_start(btnCancel
);
67 phbb
->pack_start(btnApply
);
68 phbb
->pack_start(btnOK
);
74 void DialogVocabListEditor::OnTextChanged() {
78 void DialogVocabListEditor::OnCancel() {
79 Update(); /* Since the dialog is not destroyed, prepare it
83 response(Gtk::RESPONSE_OK
);
84 } else response(Gtk::RESPONSE_CANCEL
);
87 void DialogVocabListEditor::OnApply() {
90 ListManager
* lm
= ListManager::Get();
92 int result
= lm
->VList()->AddList
93 (utfconv_mw(tvList
.get_buffer()->get_text()).c_str(),
99 (*this, (boost::format(_("Changes Saved.\nTotal vocab in list: %d"))
101 md
.set_title(_("Vocab List Editor"));
105 void DialogVocabListEditor::OnOK() {
106 if(bChanged
) OnApply();
107 bChangesMade
= false;
108 response(Gtk::RESPONSE_OK
);
111 void DialogVocabListEditor::Update() {
112 bool bOldState
= bChanged
; /* Changing the text buffer will touch this flag,
113 so we'll save the state. */
114 ListManager
* lm
= ListManager::Get();
115 wstring ws
= lm
->VList()->ToString();
117 if(!ws
.empty()) s
= utfconv_wm(ws
);
118 tvList
.get_buffer()->set_text(s
);
119 bChanged
= bOldState
;
122 bool DialogVocabListEditor::OnDeleteEvent(GdkEventAny
* event
) {