// frmContactEditorXToken.cpp - frmContactEditorXToken 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 "frmContactEditorXToken.h"
#include
#include "../common/textprocessing.h"
frmContactEditorXToken::frmContactEditorXToken( wxWindow* parent )
:
frmContactEditorXTokenADT( parent )
{
}
void frmContactEditorXToken::ProcessAction( wxCommandEvent& event )
{
// Process action.
long ListCtrlIndex;
if (EditorMode == FALSE){
wxString strValue;
wxListItem coldata;
coldata.SetId(XTokenListIndex);
coldata.SetData(XTokenListIndex);
ListCtrlIndex = XTokenListCtrlPtr->InsertItem(coldata);
// Get the X-Token value.
strValue = txtValue->GetValue();
XTokenListPtr->insert(std::make_pair(XTokenListIndex, strValue));
// Get the X-Token name.
strValue = txtTokenName->GetValue();
XTokenListTokensPtr->insert(std::make_pair(XTokenListIndex, strValue));
// Update form.
XTokenListCtrlPtr->SetItem(ListCtrlIndex, 0, strValue);
this->Close();
} else if (EditorMode == TRUE){
long longSelected = -1;
wxString strValue;
longSelected = XTokenListCtrlPtr->GetNextItem(longSelected,
wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
if (longSelected == -1){
return;
}
// Update X-Token value.
XTokenListPtr->erase(XTokenListIndex);
strValue = txtValue->GetValue();
XTokenListPtr->insert(std::make_pair(XTokenListIndex, strValue));
// Update X-Token name.
XTokenListTokensPtr->erase(XTokenListIndex);
strValue = txtTokenName->GetValue();
XTokenListTokensPtr->insert(std::make_pair(XTokenListIndex, strValue));
// Update form.
XTokenListCtrlPtr->SetItem(longSelected, 0,strValue);
this->Close();
}
}
void frmContactEditorXToken::SetEditorMode(bool EditMode)
{
// 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 X-Token"));
} else if (EditMode == TRUE){
EditorMode = TRUE;
btnAction->SetLabel(_("Modify"));
this->SetTitle(_("Add X-Token"));
std::map::iterator intiter;
std::map::iterator striter;
wxString strValue;
// Get the X-Token name.
striter = XTokenListTokensPtr->find(XTokenListIndex);
if (striter->first == XTokenListIndex &&
striter != XTokenListTokensPtr->end()){
strValue = striter->second;
}
txtTokenName->SetValue(strValue);
strValue.Clear();
// Get the X-Token value.
striter = XTokenListPtr->find(XTokenListIndex);
if (striter->first == XTokenListIndex &&
striter != XTokenListPtr->end()){
strValue = striter->second;
}
txtValue->SetValue(strValue);
strValue.Clear();
}
}
void frmContactEditorXToken::SetupPointers( std::map *XTokenList,
std::map *XTokenListTokens,
wxListCtrl *XTokenListCtrl,
int XTokenIndex )
{
// Setup the pointers.
XTokenListPtr = XTokenList;
XTokenListTokensPtr = XTokenListTokens;
XTokenListCtrlPtr = XTokenListCtrl;
XTokenListIndex = XTokenIndex;
}
void frmContactEditorXToken::CloseWindow( wxCommandEvent& event )
{
// Close the window.
this->Close();
}