1 // frmContactEditorNotes.cpp - frmContactEditorNotes form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmContactEditorNotes.h"
21 frmContactEditorNotes::frmContactEditorNotes( wxWindow* parent )
23 frmContactEditorNotesADT( parent )
26 // Setup the editor window.
29 sliPriority->Disable();
31 // Setup the language combo box.
33 std::vector<std::string> LanguageCodeList = GetLanguageCodeList();
35 wxArrayString LanguageList;
37 for (auto LanguageItem : LanguageCodeList){
39 LanguageList.Add((wxString)LanguageItem, 1);
43 cmbLanguage->Append(LanguageList);
47 void frmContactEditorNotes::EnablePriority( wxCommandEvent& event )
50 // Enable/disable the priority setting.
52 if (chkUsePref->IsChecked()){
53 sliPriority->Enable();
55 sliPriority->Disable();
60 void frmContactEditorNotes::ProcessAction( wxCommandEvent& event )
67 if (EditorMode == FALSE){
69 // Add the note to the list.
76 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
80 if (EditSectionType == CE_GENERAL){
82 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("")));
84 } else if (EditSectionType == CE_HOME) {
86 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("home")));
88 } else if (EditSectionType == CE_WORK) {
90 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("work")));
96 if (chkUsePref->IsChecked()){
98 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, sliPriority->GetValue()));
102 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));
106 // Add note language.
110 if (!strValue.IsEmpty()){
112 NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));
116 NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
120 // Add the data to the form.
124 coldata.SetId(NotesListIndex);
125 coldata.SetData(NotesListIndex);
126 coldata.SetText(txtNote->GetValue());
127 ListCtrlIndex = NotesListCtrlPtr->InsertItem(coldata);
129 if (chkUsePref->IsChecked()){
131 NotesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
137 } else if (EditorMode == TRUE){
143 long longSelected = -1;
147 NotesListPtr->erase(NotesListIndex);
148 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
150 // Update the note preference.
152 NotesListPrefPtr->erase(NotesListIndex);
154 if (chkUsePref->IsChecked()){
156 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, sliPriority->GetValue()));
160 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));
164 // Update the language.
168 NotesListLangPtr->erase(NotesListIndex);
170 if (!strValue.IsEmpty()){
172 NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));
176 NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
182 longSelected = NotesListCtrlPtr->GetNextItem(longSelected,
184 wxLIST_STATE_SELECTED);
186 if (longSelected == -1){
190 NotesListCtrlPtr->SetItem(longSelected, 0, txtNote->GetValue());
192 if (chkUsePref->IsChecked()){
194 NotesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
198 NotesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
208 void frmContactEditorNotes::SetEditorMode(bool EditMode, SectionType SectType)
211 // Set the editor mode.
213 // Set if the editor is adding or editing an address.
217 if (EditMode == FALSE){
220 btnAction->SetLabel(_("Add"));
221 this->SetTitle(_("Add Note"));
223 } else if (EditMode == TRUE){
226 btnAction->SetLabel(_("Modify"));
227 this->SetTitle(_("Modify Note"));
229 std::map<int,int>::iterator intiter;
230 std::map<int,wxString>::iterator striter;
235 striter = NotesListPtr->find(NotesListIndex);
237 if (striter->first == NotesListIndex){
239 strValue = striter->second;
243 txtNote->SetValue(strValue);
247 striter = NotesListLangPtr->find(NotesListIndex);
251 if (striter->first == NotesListIndex &&
252 striter != NotesListLangPtr->end()){
254 strValue = striter->second;
258 cmbLanguage->SetValue(strValue);
262 intiter = NotesListPrefPtr->find(NotesListIndex);
264 if (intiter->first == NotesListIndex && intiter->second > 0 &&
265 intiter != NotesListPrefPtr->end()){
267 sliPriority->SetValue(intiter->second);
268 sliPriority->Enable();
269 chkUsePref->SetValue(TRUE);
275 EditSectionType = SectType;
279 void frmContactEditorNotes::CloseWindow( wxCommandEvent& event )
289 void frmContactEditorNotes::SetupPointers(std::map<int, wxString> *NotesList,
290 std::map<int, wxString> *NotesListLang,
291 std::map<int, wxString> *NotesListAltID,
292 std::map<int, wxString> *NotesListPID,
293 std::map<int, wxString> *NotesListType,
294 std::map<int, wxString> *NotesListTokens,
295 std::map<int, int> *NotesListPref,
296 wxListCtrl *NotesListCtrl,
300 // Setup the pointers.
302 NotesListPtr = NotesList;
303 NotesListLangPtr = NotesListLang;
304 NotesListAltIDPtr = NotesListAltID;
305 NotesListPIDPtr = NotesListPID;
306 NotesListTypePtr = NotesListType;
307 NotesListTokensPtr = NotesListTokens;
308 NotesListPrefPtr = NotesListPref;
309 NotesListCtrlPtr = NotesListCtrl;
310 NotesListIndex = NotesIndex;