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_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 "panel_vocablisteditor.h"
33 BEGIN_EVENT_TABLE(PanelVocabListEditor
, wxPanel
)
34 EVT_BUTTON(ID_btnRevert
, PanelVocabListEditor::OnRevert
)
35 EVT_BUTTON(ID_btnCommit
, PanelVocabListEditor::OnCommit
)
36 EVT_TEXT(ID_textVocabList
, PanelVocabListEditor::OnTextChanged
)
39 PanelVocabListEditor::PanelVocabListEditor(wxWindow
*owner
) : RedrawablePanel(owner
) {
40 textVocabList
= new wxTextCtrl(this, ID_textVocabList
, wxEmptyString
,
41 wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
);
42 wxButton
*btnRevert
= new wxButton(this, ID_btnRevert
, _T("Revert"));
43 wxButton
*btnCommit
= new wxButton(this, ID_btnCommit
, _T("Commit"));
45 wxBoxSizer
*panelSizer
= new wxBoxSizer(wxVERTICAL
);
46 wxBoxSizer
*buttonSizer
= new wxBoxSizer(wxHORIZONTAL
);
48 buttonSizer
->AddStretchSpacer(1);
49 buttonSizer
->Add(btnRevert
);
50 buttonSizer
->AddStretchSpacer(1);
51 buttonSizer
->Add(btnCommit
);
52 buttonSizer
->AddStretchSpacer(1);
53 panelSizer
->Add(textVocabList
, 1, wxEXPAND
| wxALL
, 10);
54 panelSizer
->Add(buttonSizer
, 0, wxEXPAND
| wxALIGN_CENTER
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
56 changeDetected
= false;
57 this->SetSizerAndFit(panelSizer
);
60 void PanelVocabListEditor::Commit() {
61 /* This function, when called explicitly, caused a hard lock and
62 LOTS of HDD activity. Step through this with GDB, and monitor
63 mem usage with top. */
64 changeDetected
= false;
65 jben
->vocabList
->Clear();
66 int result
= jben
->vocabList
->AddList(textVocabList
->GetValue());
70 Redraw(); /* Might be redundant now with the above Redraw() call... */
71 wxMessageBox(wxString::Format(_T("Changes Saved.\nTotal vocab in list: %d"), result
),
72 _T("Vocab List Editor"), wxOK
| wxICON_INFORMATION
, this);
75 void PanelVocabListEditor::Revert() {
76 changeDetected
= false;
80 void PanelVocabListEditor::OnRevert(wxCommandEvent
& ev
) {Revert();}
81 void PanelVocabListEditor::OnCommit(wxCommandEvent
& ev
) {Commit();}
83 void PanelVocabListEditor::OnTextChanged(wxCommandEvent
& ev
) {
84 changeDetected
= true;
87 bool PanelVocabListEditor::ChangeDetected() {return changeDetected
;}
89 void PanelVocabListEditor::Redraw() {
90 /*textVocabList->ChangeValue(jben->vocabList->ToString());*/
91 wxString s
= jben
->vocabList
->ToString();
92 textVocabList
->ChangeValue(s
);
93 textVocabList
->ChangeValue(s
);
94 textVocabList
->ChangeValue(s
);
95 textVocabList
->ChangeValue(s
);
96 textVocabList
->ChangeValue(s
);
97 textVocabList
->ChangeValue(s
);
98 textVocabList
->ChangeValue(s
);
99 textVocabList
->ChangeValue(s
);
100 textVocabList
->ChangeValue(s
);