forked from gopa810/gcal-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DlgStringManager.cpp
247 lines (203 loc) · 5.5 KB
/
DlgStringManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// DlgStringManager.cpp : implementation file
//
#include "stdafx.h"
#include "vcal5beta.h"
#include "DlgStringManager.h"
#include "DlgEditString.h"
#include "GCStrings.h"
#include "GCUserInterface.h"
#include "GCGlobal.h"
#include "TFile.h"
/////////////////////////////////////////////////////////////////////////////
// DlgStringManager dialog
DlgStringManager::DlgStringManager(CWnd* pParent /*=NULL*/)
: CDialog(DlgStringManager::IDD, pParent)
{
//{{AFX_DATA_INIT(DlgStringManager)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void DlgStringManager::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgStringManager)
DDX_Control(pDX, IDC_LIST1, m_List);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(DlgStringManager, CDialog)
//{{AFX_MSG_MAP(DlgStringManager)
ON_BN_CLICKED(IDC_BUTTON1, OnEdit)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnItemchangedList1)
ON_BN_CLICKED(IDC_BUTTON2, OnImport)
ON_BN_CLICKED(IDC_BUTTON3, OnExport)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnHelp)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// DlgStringManager message handlers
void DlgStringManager::OnEdit()
{
// TODO: Add your control notification handler code here
POSITION pos;
int i;
int id;
pos = m_List.GetFirstSelectedItemPosition();
if (pos)
{
i = m_List.GetNextSelectedItem(pos);
id = m_List.GetItemData(i);
// edit char
DlgEditString des;
des.m_orig = GCStrings::getString(id).c_str();
des.m_new = m_List.GetItemText(i, 1);
if (des.DoModal()==IDOK)
{
m_List.SetItemText(i, 1, des.m_new);
GCStrings::gstr_Modified = 1;
}
}
}
void DlgStringManager::OnOK()
{
// TODO: Add extra validation here
SaveStringsToMemory();
CDialog::OnOK();
}
BOOL DlgStringManager::OnInitDialog()
{
CDialog::OnInitDialog();
CString str1, str2;
m_List.InsertColumn(0, "ID", LVCFMT_RIGHT, 50, 0);
m_List.InsertColumn(1, "String", LVCFMT_LEFT, 250, 1);
m_List.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
InitListWithStrings();
GetDlgItem(IDC_BUTTON5)->EnableWindow(GCGlobal::application.m_bHelpAvailable);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void DlgStringManager::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
POSITION pos;
pos = m_List.GetFirstSelectedItemPosition();
if (pos != NULL)
{
GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE);
}
*pResult = 0;
}
void DlgStringManager::OnImport()
{
int i;
CString str;
// TODO: Add your control notification handler code here
CFileDialog cfd(TRUE, "srl", NULL, 0, "String Rich List File (*.srl)|*.srl||");
if (cfd.DoModal() == IDOK)
{
i = GCStrings::readFile(cfd.GetPathName());
if (i < 0)
MessageBox("Cannot open file", "Import Strings", MB_OK | MB_ICONSTOP);
else
{
InitListWithStrings();
str.Format("Imported %d strings", i);
MessageBox(str, "Import Strings", MB_OK | MB_ICONINFORMATION);
GCStrings::gstr_Modified = 1;
}
}
}
void DlgStringManager::OnExport()
{
// TODO: Add your control notification handler code here
int i;
CString str;
// TODO: Add your control notification handler code here
CFileDialog cfd(FALSE, "srl", NULL, 0, "String Rich List File (*.srl)|*.srl||");
if (cfd.DoModal() == IDOK)
{
SaveStringsToMemory();
i = GCStrings::writeFile(cfd.GetPathName());
if (i < 0)
MessageBox("Cannot write file", "Export Strings", MB_OK | MB_ICONSTOP);
else
{
str.Format("Exported %d strings", i);
MessageBox(str, "Export Strings", MB_OK | MB_ICONINFORMATION);
}
}
}
void DlgStringManager::OnButton4()
{
TFile::DeleteFileA(GCGlobal::getFileName(GSTR_TEXT_FILE));
GCStrings::readFile(GCGlobal::getFileName(GSTR_TEXT_FILE));
InitListWithStrings();
}
void DlgStringManager::InitListWithStrings()
{
TString str1;
int i, nn;
m_List.DeleteAllItems();
int mxx = GCStrings::getCount();
for(i = 0; i < mxx; i++)
{
if (GCStrings::getString(i).GetLength() > 0)
{
str1.Format("%6d", i);
nn = m_List.InsertItem(1, str1);
m_List.SetItemText(nn, 1, GCStrings::getString(i).c_str());
m_List.SetItemData(nn, i);
}
}
}
void DlgStringManager::OnHelp()
{
// TODO: Add your control notification handler code here
GCUserInterface::ShowHelp("ref-strman.htm");
}
void DlgStringManager::SaveStringsToMemory()
{
int i, m, ind;
CString str;
m = m_List.GetItemCount();
for(i = 0; i < m; i++)
{
ind = m_List.GetItemData(i);
str = m_List.GetItemText(i, 1);
GCStrings::setString(ind, (LPCTSTR)(str));
}
}
void DlgStringManager::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
CString strf;
CString str;
int i, m;
int ev = -1;
GetDlgItemText(IDC_EDIT1, strf);
m = m_List.GetItemCount();
for(i = 0; i < m; i++)
{
str = m_List.GetItemText(i, 1);
if (str.Find(strf, 0) >= 0 && strf.GetLength()>0)
{
//m_List.SetSelectionMark(i);
m_List.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
//m_List.SetCheck(i, TRUE);
if (ev < 0) {
m_List.EnsureVisible(i, FALSE);
ev = i;
}
// break;
}
else
{
m_List.SetItemState(i, 0, LVIS_SELECTED);
}
}
}