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"
20 #include "../common/textprocessing.h"
21 #include <wx/tokenzr.h>
23 frmContactEditorNotes::frmContactEditorNotes( wxWindow* parent )
25 frmContactEditorNotesADT( parent )
28 // Setup the editor window.
31 sliPriority->Disable();
34 void frmContactEditorNotes::EnablePriority( wxCommandEvent& event )
37 // Enable/disable the priority setting.
39 if (chkUsePref->IsChecked()){
40 sliPriority->Enable();
42 sliPriority->Disable();
47 void frmContactEditorNotes::ProcessAction( wxCommandEvent& event )
54 if (EditorMode == FALSE){
56 // Add the note to the list.
63 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
67 if (EditSectionType == CE_GENERAL){
69 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("")));
71 } else if (EditSectionType == CE_HOME) {
73 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("home")));
75 } else if (EditSectionType == CE_WORK) {
77 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("work")));
83 if (chkUsePref->IsChecked()){
85 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, sliPriority->GetValue()));
89 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));
97 if (!strValue.IsEmpty()){
99 NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));
103 NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
107 // Add the data to the form.
111 coldata.SetId(NotesListIndex);
112 coldata.SetData(NotesListIndex);
113 coldata.SetText(txtNote->GetValue());
114 ListCtrlIndex = NotesListCtrlPtr->InsertItem(coldata);
116 if (chkUsePref->IsChecked()){
118 NotesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
124 } else if (EditorMode == TRUE){
130 long longSelected = -1;
134 NotesListPtr->erase(NotesListIndex);
135 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
137 // Update the note preference.
139 NotesListPrefPtr->erase(NotesListIndex);
141 if (chkUsePref->IsChecked()){
143 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, sliPriority->GetValue()));
147 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));
151 // Update the language.
155 NotesListLangPtr->erase(NotesListIndex);
157 if (!strValue.IsEmpty()){
159 NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));
163 NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
169 longSelected = NotesListCtrlPtr->GetNextItem(longSelected,
171 wxLIST_STATE_SELECTED);
173 if (longSelected == -1){
177 NotesListCtrlPtr->SetItem(longSelected, 0, txtNote->GetValue());
179 if (chkUsePref->IsChecked()){
181 NotesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
185 NotesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
195 void frmContactEditorNotes::SetEditorMode(bool EditMode, SectionType SectType)
198 // Set the editor mode.
200 // Set if the editor is adding or editing an address.
204 if (EditMode == FALSE){
207 btnAction->SetLabel(_("Add"));
208 this->SetTitle(_("Add Note"));
210 } else if (EditMode == TRUE){
213 btnAction->SetLabel(_("Modify"));
214 this->SetTitle(_("Modify Note"));
216 std::map<int,int>::iterator intiter;
217 std::map<int,wxString>::iterator striter;
222 striter = NotesListPtr->find(NotesListIndex);
224 if (striter->first == NotesListIndex){
226 strValue = striter->second;
230 txtNote->SetValue(strValue);
234 striter = NotesListLangPtr->find(NotesListIndex);
236 if (striter->first == NotesListIndex &&
237 striter != NotesListLangPtr->end()){
239 strValue = striter->second;
243 cmbLanguage->SetValue(strValue);
247 intiter = NotesListPrefPtr->find(NotesListIndex);
249 if (intiter->first == NotesListIndex && intiter->second > 0 &&
250 intiter != NotesListPrefPtr->end()){
252 sliPriority->SetValue(intiter->second);
253 sliPriority->Enable();
254 chkUsePref->SetValue(TRUE);
260 EditSectionType = SectType;
264 void frmContactEditorNotes::CloseWindow( wxCommandEvent& event )
274 void frmContactEditorNotes::SetupPointers(std::map<int, wxString> *NotesList,
275 std::map<int, wxString> *NotesListLang,
276 std::map<int, wxString> *NotesListAltID,
277 std::map<int, wxString> *NotesListPID,
278 std::map<int, wxString> *NotesListType,
279 std::map<int, wxString> *NotesListTokens,
280 std::map<int, int> *NotesListPref,
281 wxListCtrl *NotesListCtrl,
285 // Setup the pointers.
287 NotesListPtr = NotesList;
288 NotesListLangPtr = NotesListLang;
289 NotesListAltIDPtr = NotesListAltID;
290 NotesListPIDPtr = NotesListPID;
291 NotesListTypePtr = NotesListType;
292 NotesListTokensPtr = NotesListTokens;
293 NotesListPrefPtr = NotesListPref;
294 NotesListCtrlPtr = NotesListCtrl;
295 NotesListIndex = NotesIndex;