// frmContactEditorNotes.cpp - frmContactEditorNotes form.
//
// (c) 2012-2015 Xestia Software Development.
//
// This file is part of Xestia Address Book.
//
// Xestia Address Book is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by the
// Free Software Foundation, version 3 of the license.
//
// Xestia Address Book is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with Xestia Address Book. If not, see
#include "frmContactEditorNotes.h"
frmContactEditorNotes::frmContactEditorNotes( wxWindow* parent )
:
frmContactEditorNotesADT( parent )
{
// Setup the editor window.
EditorMode = FALSE;
priorityCtrl = new XABPriorityCtrl(tabPriority);
szrPriority->Add(priorityCtrl, 1, wxEXPAND, 5);
szrPriority->Layout();
// Setup the language combo box.
std::vector LanguageCodeList = GetLanguageCodeList();
wxArrayString LanguageList;
for (auto LanguageItem : LanguageCodeList){
LanguageList.Add((wxString)LanguageItem, 1);
}
cmbLanguage->Append(LanguageList);
}
void frmContactEditorNotes::ProcessAction( wxCommandEvent& event )
{
// Process action.
long ListCtrlIndex;
if (EditorMode == FALSE){
// Add the note to the list.
wxString strAddress;
wxString strValue;
// Add note.
NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
// Add note type.
if (EditSectionType == CE_GENERAL){
NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("")));
} else if (EditSectionType == CE_HOME) {
NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("home")));
} else if (EditSectionType == CE_WORK) {
NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("work")));
}
// Add note priority.
if (priorityCtrl->IsPriorityChecked()){
NotesListPrefPtr->insert(std::make_pair(NotesListIndex, priorityCtrl->GetValue()));
} else {
NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));
}
// Add note language.
strValue.Clear();
if (!strValue.IsEmpty()){
NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));
} else {
NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
}
// Add the data to the form.
wxListItem coldata;
coldata.SetId(NotesListIndex);
coldata.SetData(NotesListIndex);
coldata.SetText(txtNote->GetValue());
ListCtrlIndex = NotesListCtrlPtr->InsertItem(coldata);
if (priorityCtrl->IsPriorityChecked()){
NotesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
}
this->Close();
} else if (EditorMode == TRUE){
// Edit the note.
wxString strAddress;
wxString strValue;
long longSelected = -1;
// Update the note.
NotesListPtr->erase(NotesListIndex);
NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
// Update the note preference.
NotesListPrefPtr->erase(NotesListIndex);
if (priorityCtrl->IsPriorityChecked()){
NotesListPrefPtr->insert(std::make_pair(NotesListIndex, priorityCtrl->GetValue()));
} else {
NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));
}
// Update the language.
strValue.Clear();
NotesListLangPtr->erase(NotesListIndex);
if (!strValue.IsEmpty()){
NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));
} else {
NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
}
// Update the form.
longSelected = NotesListCtrlPtr->GetNextItem(longSelected,
wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
if (longSelected == -1){
return;
}
NotesListCtrlPtr->SetItem(longSelected, 0, txtNote->GetValue());
if (priorityCtrl->IsPriorityChecked()){
NotesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
} else {
NotesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
}
this->Close();
}
}
void frmContactEditorNotes::SetEditorMode(bool EditMode, SectionType SectType)
{
// Set the editor mode.
// Set if the editor is adding or editing an address.
// FALSE = Add
// TRUE = Edit
if (EditMode == FALSE){
EditorMode = FALSE;
btnAction->SetLabel(_("Add"));
this->SetTitle(_("Add Note"));
} else if (EditMode == TRUE){
EditorMode = TRUE;
btnAction->SetLabel(_("Modify"));
this->SetTitle(_("Modify Note"));
std::map::iterator intiter;
std::map::iterator striter;
wxString strValue;
// Get the note.
striter = NotesListPtr->find(NotesListIndex);
if (striter->first == NotesListIndex){
strValue = striter->second;
}
txtNote->SetValue(strValue);
// Get the language.
striter = NotesListLangPtr->find(NotesListIndex);
strValue.clear();
if (striter->first == NotesListIndex &&
striter != NotesListLangPtr->end()){
strValue = striter->second;
}
cmbLanguage->SetValue(strValue);
// Get the priority.
intiter = NotesListPrefPtr->find(NotesListIndex);
if (intiter->first == NotesListIndex && intiter->second > 0 &&
intiter != NotesListPrefPtr->end()){
priorityCtrl->SetValue(intiter->second);
priorityCtrl->EnablePriority(true);
}
}
EditSectionType = SectType;
}
void frmContactEditorNotes::CloseWindow( wxCommandEvent& event )
{
// Close the window.
this->Close();
}
void frmContactEditorNotes::SetupPointers(std::map *NotesList,
std::map *NotesListLang,
std::map *NotesListAltID,
std::map *NotesListPID,
std::map *NotesListType,
std::map *NotesListTokens,
std::map *NotesListPref,
wxListCtrl *NotesListCtrl,
int NotesIndex )
{
// Setup the pointers.
NotesListPtr = NotesList;
NotesListLangPtr = NotesListLang;
NotesListAltIDPtr = NotesListAltID;
NotesListPIDPtr = NotesListPID;
NotesListTypePtr = NotesListType;
NotesListTokensPtr = NotesListTokens;
NotesListPrefPtr = NotesListPref;
NotesListCtrlPtr = NotesListCtrl;
NotesListIndex = NotesIndex;
}