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: panel_kanjilisteditor.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 "panel_kanjilisteditor.h"
26 #include "listmanager.h"
34 BEGIN_EVENT_TABLE(PanelKanjiListEditor
, wxPanel
)
35 EVT_BUTTON(ID_btnRevert
, PanelKanjiListEditor::OnRevert
)
36 EVT_BUTTON(ID_btnCommit
, PanelKanjiListEditor::OnCommit
)
37 EVT_TEXT(ID_textKanjiList
, PanelKanjiListEditor::OnTextChanged
)
40 PanelKanjiListEditor::PanelKanjiListEditor(wxWindow
*owner
) : RedrawablePanel(owner
) {
41 textKanjiList
= new wxTextCtrl(this, ID_textKanjiList
, wxEmptyString
,
42 wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
);
43 wxButton
*btnRevert
= new wxButton(this, ID_btnRevert
, _T("Revert"));
44 wxButton
*btnCommit
= new wxButton(this, ID_btnCommit
, _T("Commit"));
46 wxBoxSizer
*panelSizer
= new wxBoxSizer(wxVERTICAL
);
47 wxBoxSizer
*buttonSizer
= new wxBoxSizer(wxHORIZONTAL
);
49 buttonSizer
->AddStretchSpacer(1);
50 buttonSizer
->Add(btnRevert
);
51 buttonSizer
->AddStretchSpacer(1);
52 /*buttonSizer->AddStretchSpacer(1);*/
53 buttonSizer
->Add(btnCommit
);
54 buttonSizer
->AddStretchSpacer(1);
55 panelSizer
->Add(textKanjiList
, 1, wxEXPAND
| wxALL
, 10);
56 panelSizer
->Add(buttonSizer
, 0, wxEXPAND
| wxALIGN_CENTER
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
58 changeDetected
= false;
59 this->SetSizerAndFit(panelSizer
);
62 void PanelKanjiListEditor::Commit() {
63 ListManager
* lm
= ListManager::Get();
64 changeDetected
= false;
66 int result
= lm
->KList()->AddFromString(
67 textKanjiList
->GetValue().c_str());
71 Redraw(); /* Might be redundant now with the above Redraw() call... */
72 wxMessageBox(wxString::Format(_T("Changes Saved.\nTotal kanji in list: %d"), result
),
73 _T("Kanji List Editor"), wxOK
| wxICON_INFORMATION
, this);
76 void PanelKanjiListEditor::Revert() {
77 changeDetected
= false;
81 void PanelKanjiListEditor::OnRevert(wxCommandEvent
& ev
) {Revert();}
82 void PanelKanjiListEditor::OnCommit(wxCommandEvent
& ev
) {Commit();}
84 void PanelKanjiListEditor::OnTextChanged(wxCommandEvent
& ev
) {
85 changeDetected
= true;
88 bool PanelKanjiListEditor::ChangeDetected() {return changeDetected
;}
90 void PanelKanjiListEditor::Redraw() {
91 ListManager
* lm
= ListManager::Get();
92 textKanjiList
->ChangeValue(lm
->KList()->ToString(20));