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 sliPriority->Disable();
31 void frmContactEditorNotes::EnablePriority( wxCommandEvent& event )
33 if (chkUsePref->IsChecked()){
34 sliPriority->Enable();
36 sliPriority->Disable();
40 void frmContactEditorNotes::ProcessAction( wxCommandEvent& event )
44 if (EditorMode == FALSE){
46 // Add the note to the list.
53 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
57 if (EditSectionType == CE_GENERAL){
59 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("")));
61 } else if (EditSectionType == CE_HOME) {
63 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("home")));
65 } else if (EditSectionType == CE_WORK) {
67 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("work")));
73 if (chkUsePref->IsChecked()){
75 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, sliPriority->GetValue()));
79 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));
87 if (!strValue.IsEmpty()){
89 NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));
93 NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
97 // Add the data to the form.
101 coldata.SetId(NotesListIndex);
102 coldata.SetData(NotesListIndex);
103 coldata.SetText(txtNote->GetValue());
104 ListCtrlIndex = NotesListCtrlPtr->InsertItem(coldata);
106 if (chkUsePref->IsChecked()){
108 NotesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
114 } else if (EditorMode == TRUE){
120 long longSelected = -1;
124 NotesListPtr->erase(NotesListIndex);
125 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
127 // Update the note preference.
129 NotesListPrefPtr->erase(NotesListIndex);
131 if (chkUsePref->IsChecked()){
133 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, sliPriority->GetValue()));
137 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));
141 // Update the language.
145 NotesListLangPtr->erase(NotesListIndex);
147 if (!strValue.IsEmpty()){
149 NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));
153 NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
159 longSelected = NotesListCtrlPtr->GetNextItem(longSelected,
161 wxLIST_STATE_SELECTED);
163 if (longSelected == -1){
167 NotesListCtrlPtr->SetItem(longSelected, 0, txtNote->GetValue());
169 if (chkUsePref->IsChecked()){
171 NotesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
175 NotesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
185 void frmContactEditorNotes::SetEditorMode(bool EditMode, SectionType SectType)
187 // Set if the editor is adding or editing an address.
191 if (EditMode == FALSE){
194 btnAction->SetLabel(_("Add"));
195 this->SetTitle(_("Add Note"));
197 } else if (EditMode == TRUE){
200 btnAction->SetLabel(_("Modify"));
201 this->SetTitle(_("Modify Note"));
203 std::map<int,int>::iterator intiter;
204 std::map<int,wxString>::iterator striter;
209 striter = NotesListPtr->find(NotesListIndex);
211 if (striter->first == NotesListIndex){
213 strValue = striter->second;
217 txtNote->SetValue(strValue);
221 striter = NotesListLangPtr->find(NotesListIndex);
223 if (striter->first == NotesListIndex){
225 strValue = striter->second;
229 cmbLanguage->SetValue(strValue);
233 intiter = NotesListPrefPtr->find(NotesListIndex);
235 if (intiter->first == NotesListIndex && intiter->second > 0){
237 sliPriority->SetValue(intiter->second);
238 sliPriority->Enable();
239 chkUsePref->SetValue(TRUE);
245 EditSectionType = SectType;
249 void frmContactEditorNotes::CloseWindow( wxCommandEvent& event )
255 void frmContactEditorNotes::SetupPointers(std::map<int, wxString> *NotesList,
256 std::map<int, wxString> *NotesListLang,
257 std::map<int, wxString> *NotesListAltID,
258 std::map<int, wxString> *NotesListPID,
259 std::map<int, wxString> *NotesListType,
260 std::map<int, wxString> *NotesListTokens,
261 std::map<int, int> *NotesListPref,
262 wxListCtrl *NotesListCtrl,
266 NotesListPtr = NotesList;
267 NotesListLangPtr = NotesListLang;
268 NotesListAltIDPtr = NotesListAltID;
269 NotesListPIDPtr = NotesListPID;
270 NotesListTypePtr = NotesListType;
271 NotesListTokensPtr = NotesListTokens;
272 NotesListPrefPtr = NotesListPref;
273 NotesListCtrlPtr = NotesListCtrl;
274 NotesListIndex = NotesIndex;