1 // frmContactEditorXToken.cpp - frmContactEditorXToken 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 "frmContactEditorXToken.h"
20 #include <wx/tokenzr.h>
21 #include "../common/textprocessing.h"
23 frmContactEditorXToken::frmContactEditorXToken( wxWindow* parent )
25 frmContactEditorXTokenADT( parent )
30 void frmContactEditorXToken::ProcessAction( wxCommandEvent& event )
35 if (EditorMode == FALSE){
40 coldata.SetId(XTokenListIndex);
41 coldata.SetData(XTokenListIndex);
42 ListCtrlIndex = XTokenListCtrlPtr->InsertItem(coldata);
44 // Get the X-Token value.
46 strValue = txtValue->GetValue();
47 XTokenListPtr->insert(std::make_pair(XTokenListIndex, strValue));
49 // Get the X-Token name.
51 strValue = txtTokenName->GetValue();
52 XTokenListTokensPtr->insert(std::make_pair(XTokenListIndex, strValue));
56 XTokenListCtrlPtr->SetItem(ListCtrlIndex, 0, strValue);
60 } else if (EditorMode == TRUE){
62 long longSelected = -1;
65 longSelected = XTokenListCtrlPtr->GetNextItem(longSelected,
67 wxLIST_STATE_SELECTED);
69 if (longSelected == -1){
73 // Update X-Token value.
75 XTokenListPtr->erase(XTokenListIndex);
76 strValue = txtValue->GetValue();
77 XTokenListPtr->insert(std::make_pair(XTokenListIndex, strValue));
79 // Update X-Token name.
81 XTokenListTokensPtr->erase(XTokenListIndex);
82 strValue = txtTokenName->GetValue();
83 XTokenListTokensPtr->insert(std::make_pair(XTokenListIndex, strValue));
87 XTokenListCtrlPtr->SetItem(longSelected, 0,strValue);
95 void frmContactEditorXToken::SetEditorMode(bool EditMode)
97 // Set if the editor is adding or editing an address.
101 if (EditMode == FALSE){
104 btnAction->SetLabel(_("Add"));
105 this->SetTitle(_("Add X-Token"));
107 } else if (EditMode == TRUE){
110 btnAction->SetLabel(_("Modify"));
111 this->SetTitle(_("Add X-Token"));
113 std::map<int,int>::iterator intiter;
114 std::map<int,wxString>::iterator striter;
117 // Get the X-Token name.
119 striter = XTokenListTokensPtr->find(XTokenListIndex);
121 if (striter->first == XTokenListIndex){
123 strValue = striter->second;
127 txtTokenName->SetValue(strValue);
131 // Get the X-Token value.
133 striter = XTokenListPtr->find(XTokenListIndex);
135 if (striter->first == XTokenListIndex){
137 strValue = striter->second;
141 txtValue->SetValue(strValue);
149 void frmContactEditorXToken::SetupPointers( std::map<int, wxString> *XTokenList,
150 std::map<int, wxString> *XTokenListTokens,
151 wxListCtrl *XTokenListCtrl,
155 XTokenListPtr = XTokenList;
156 XTokenListTokensPtr = XTokenListTokens;
157 XTokenListCtrlPtr = XTokenListCtrl;
158 XTokenListIndex = XTokenIndex;
162 void frmContactEditorXToken::CloseWindow( wxCommandEvent& event )