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 )
37 if (EditorMode == FALSE){
42 coldata.SetId(XTokenListIndex);
43 coldata.SetData(XTokenListIndex);
44 ListCtrlIndex = XTokenListCtrlPtr->InsertItem(coldata);
46 // Get the X-Token value.
48 strValue = txtValue->GetValue();
49 XTokenListPtr->insert(std::make_pair(XTokenListIndex, strValue));
51 // Get the X-Token name.
53 strValue = txtTokenName->GetValue();
54 XTokenListTokensPtr->insert(std::make_pair(XTokenListIndex, strValue));
58 XTokenListCtrlPtr->SetItem(ListCtrlIndex, 0, strValue);
62 } else if (EditorMode == TRUE){
64 long longSelected = -1;
67 longSelected = XTokenListCtrlPtr->GetNextItem(longSelected,
69 wxLIST_STATE_SELECTED);
71 if (longSelected == -1){
75 // Update X-Token value.
77 XTokenListPtr->erase(XTokenListIndex);
78 strValue = txtValue->GetValue();
79 XTokenListPtr->insert(std::make_pair(XTokenListIndex, strValue));
81 // Update X-Token name.
83 XTokenListTokensPtr->erase(XTokenListIndex);
84 strValue = txtTokenName->GetValue();
85 XTokenListTokensPtr->insert(std::make_pair(XTokenListIndex, strValue));
89 XTokenListCtrlPtr->SetItem(longSelected, 0,strValue);
97 void frmContactEditorXToken::SetEditorMode(bool EditMode)
99 // Set if the editor is adding or editing an address.
103 if (EditMode == FALSE){
106 btnAction->SetLabel(_("Add"));
107 this->SetTitle(_("Add X-Token"));
109 } else if (EditMode == TRUE){
112 btnAction->SetLabel(_("Modify"));
113 this->SetTitle(_("Add X-Token"));
115 std::map<int,int>::iterator intiter;
116 std::map<int,wxString>::iterator striter;
119 // Get the X-Token name.
121 striter = XTokenListTokensPtr->find(XTokenListIndex);
123 if (striter->first == XTokenListIndex &&
124 striter != XTokenListTokensPtr->end()){
126 strValue = striter->second;
130 txtTokenName->SetValue(strValue);
134 // Get the X-Token value.
136 striter = XTokenListPtr->find(XTokenListIndex);
138 if (striter->first == XTokenListIndex &&
139 striter != XTokenListPtr->end()){
141 strValue = striter->second;
145 txtValue->SetValue(strValue);
153 void frmContactEditorXToken::SetupPointers( std::map<int, wxString> *XTokenList,
154 std::map<int, wxString> *XTokenListTokens,
155 wxListCtrl *XTokenListCtrl,
159 // Setup the pointers.
161 XTokenListPtr = XTokenList;
162 XTokenListTokensPtr = XTokenListTokens;
163 XTokenListCtrlPtr = XTokenListCtrl;
164 XTokenListIndex = XTokenIndex;
168 void frmContactEditorXToken::CloseWindow( wxCommandEvent& event )