/
PluginsDlg.cpp
784 lines (564 loc) · 20.6 KB
/
PluginsDlg.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
// PluginsDlg.cpp : implementation file
//
#include "stdafx.h"
#include "..\..\mainfrm.h"
#include "..\..\mushclient.h"
#include "..\..\doc.h"
#include "..\..\TextDocument.h"
#include "PluginsDlg.h"
#include "..\..\winplace.h"
#ifdef _DEBUG
//#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPluginsDlg dialog
CPluginsDlg::CPluginsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPluginsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPluginsDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pDoc = NULL;
// default to sorting in name order
m_last_col = eColumnName;
m_reverse = FALSE;
}
void CPluginsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPluginsDlg)
DDX_Control(pDX, IDC_DISABLE, m_ctlDisable);
DDX_Control(pDX, IDC_ENABLE, m_ctlEnable);
DDX_Control(pDX, IDCANCEL, m_ctlCancel);
DDX_Control(pDX, IDC_SHOW_DESCRIPTION, m_ctlShowDescription);
DDX_Control(pDX, IDC_RELOAD, m_ctlReload);
DDX_Control(pDX, IDC_EDIT, m_ctlEdit);
DDX_Control(pDX, IDC_DELETE_PLUGIN, m_ctlDelete);
DDX_Control(pDX, IDC_ADD_PLUGIN, m_ctlAdd);
DDX_Control(pDX, IDC_PLUGINS_LIST, m_ctlPluginList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPluginsDlg, CDialog)
//{{AFX_MSG_MAP(CPluginsDlg)
ON_NOTIFY(LVN_COLUMNCLICK, IDC_PLUGINS_LIST, OnColumnclickPluginsList)
ON_BN_CLICKED(IDC_SHOW_DESCRIPTION, OnShowDescription)
ON_BN_CLICKED(IDC_ADD_PLUGIN, OnAddPlugin)
ON_BN_CLICKED(IDC_DELETE_PLUGIN, OnDeletePlugin)
ON_BN_CLICKED(IDC_RELOAD, OnReload)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_EDIT, OnEdit)
ON_NOTIFY(NM_DBLCLK, IDC_PLUGINS_LIST, OnDblclkPluginsList)
ON_WM_SIZE()
ON_NOTIFY(NM_RDBLCLK, IDC_PLUGINS_LIST, OnRdblclkPluginsList)
ON_BN_CLICKED(IDC_ENABLE, OnEnable)
ON_BN_CLICKED(IDC_DISABLE, OnDisable)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_KICKIDLE, OnKickIdle)
ON_UPDATE_COMMAND_UI(IDC_RELOAD, OnUpdateNeedSelection)
ON_UPDATE_COMMAND_UI(IDC_EDIT, OnUpdateNeedSelection)
ON_UPDATE_COMMAND_UI(IDC_OPEN_EXISTING, OnUpdateNeedSelection)
ON_UPDATE_COMMAND_UI(IDC_DELETE_PLUGIN, OnUpdateNeedSelection)
ON_UPDATE_COMMAND_UI(IDC_MOVE_UP, OnUpdateNeedSelection)
ON_UPDATE_COMMAND_UI(IDC_MOVE_DOWN, OnUpdateNeedSelection)
ON_UPDATE_COMMAND_UI(IDC_ENABLE, OnUpdateNeedSelection)
ON_UPDATE_COMMAND_UI(IDC_DISABLE, OnUpdateNeedSelection)
ON_UPDATE_COMMAND_UI(IDC_SHOW_DESCRIPTION, OnUpdateNeedDescription)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPluginsDlg message handlers
BOOL CPluginsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
int iColOrder [eColumnCount] = {0, 1, 2, 3, 4, 5, 6},
iColWidth [eColumnCount] = {50, 130, 55, 55, 80, 30, 20};
// set list control to display whole row when selected and to allow column drag/drop
App.RestoreColumnConfiguration ("Plugins List", eColumnCount, m_ctlPluginList,
iColOrder, iColWidth, m_last_col, m_reverse);
// for upgrading
if (iColWidth [eColumnEnabled] < 20)
iColWidth [eColumnEnabled] = 20;
// for upgrading
if (iColWidth [eColumnVersion] < 20)
iColWidth [eColumnVersion] = 20;
m_ctlPluginList.InsertColumn(eColumnName, TranslateHeading ("Name"), LVCFMT_LEFT, iColWidth [eColumnName]);
m_ctlPluginList.InsertColumn(eColumnPurpose, TranslateHeading ("Purpose"), LVCFMT_LEFT, iColWidth [eColumnPurpose]);
m_ctlPluginList.InsertColumn(eColumnAuthor, TranslateHeading ("Author"), LVCFMT_LEFT, iColWidth [eColumnAuthor]);
m_ctlPluginList.InsertColumn(eColumnLanguage, TranslateHeading ("Language"), LVCFMT_LEFT, iColWidth [eColumnLanguage]);
m_ctlPluginList.InsertColumn(eColumnFile, TranslateHeading ("File"), LVCFMT_LEFT, iColWidth [eColumnFile]);
m_ctlPluginList.InsertColumn(eColumnEnabled, TranslateHeading ("Enabled"), LVCFMT_LEFT, iColWidth [eColumnEnabled]);
m_ctlPluginList.InsertColumn(eColumnVersion, TranslateHeading ("Ver"), LVCFMT_RIGHT, iColWidth [eColumnVersion]);
// recover column sequence
m_ctlPluginList.SendMessage (LVM_SETCOLUMNORDERARRAY, eColumnCount, (DWORD) iColOrder);
CWindowPlacement wp;
wp.Restore ("Plugins List", this, false);
LoadList ();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
} // end of CPluginsDlg::OnInitDialog
static int CALLBACK CompareFunc ( LPARAM lParam1,
LPARAM lParam2,
LPARAM lParamSort)
{
CPlugin * item1 = (CPlugin *) lParam1;
CPlugin * item2 = (CPlugin *) lParam2;
int iResult;
switch (lParamSort & 0xFF) // which sort key
{
case eColumnName:
iResult = item1->m_strName.CompareNoCase (item2->m_strName);
break;
case eColumnPurpose:
iResult = item1->m_strPurpose.CompareNoCase (item2->m_strPurpose);
break;
case eColumnAuthor:
iResult = item1->m_strAuthor.CompareNoCase (item2->m_strAuthor);
if (iResult == 0)
iResult = item1->m_strName.CompareNoCase (item2->m_strName);
break;
case eColumnLanguage:
iResult = item1->m_strLanguage.CompareNoCase (item2->m_strLanguage);
if (iResult == 0)
iResult = item1->m_strName.CompareNoCase (item2->m_strName);
break;
case eColumnFile:
iResult = item1->m_strSource.CompareNoCase (item2->m_strSource);
break;
case eColumnEnabled:
iResult = item1->m_bEnabled < item2->m_bEnabled;
if (iResult == 0)
iResult = item1->m_strName.CompareNoCase (item2->m_strName);
break;
case eColumnVersion:
iResult = item1->m_dVersion < item2->m_dVersion;
if (iResult == 0)
iResult = item1->m_strName.CompareNoCase (item2->m_strName);
break;
default: return 0;
} // end of switch
// if reverse sort wanted, reverse sense of result
if (lParamSort & 0xFF00)
iResult *= -1;
return iResult;
} // end of CompareFunc
void CPluginsDlg::LoadList (void)
{
int nItem = 0;
m_ctlPluginList.DeleteAllItems ();
for (POSITION pos = m_pDoc->m_PluginList.GetHeadPosition(); pos; nItem++)
{
CPlugin * p = m_pDoc->m_PluginList.GetNext (pos);
m_ctlPluginList.InsertItem (nItem, p->m_strName); // eColumnName
m_ctlPluginList.SetItemText (nItem, eColumnPurpose, p->m_strPurpose);
m_ctlPluginList.SetItemText (nItem, eColumnAuthor, p->m_strAuthor);
m_ctlPluginList.SetItemText (nItem, eColumnLanguage, p->m_strLanguage);
m_ctlPluginList.SetItemText (nItem, eColumnFile, p->m_strSource);
m_ctlPluginList.SetItemText (nItem, eColumnEnabled, p->m_bEnabled ? "Yes" : "No");
m_ctlPluginList.SetItemText (nItem, eColumnVersion, CFormat ("%5.2f", p->m_dVersion));
m_ctlPluginList.SetItemData (nItem, (DWORD) p);
}
m_ctlPluginList.SortItems (CompareFunc, m_reverse << 8 | m_last_col);
// set the 1st item to be selected - we do this here because sorting the
// list means our first item is not necessarily the 1st item in the list
m_ctlPluginList.SetItemState (0, LVIS_FOCUSED | LVIS_SELECTED,
LVIS_FOCUSED | LVIS_SELECTED);
} // end of CPluginsDlg::LoadList
void CPluginsDlg::OnColumnclickPluginsList(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int col = pNMListView->iSubItem;
if (col == m_last_col)
m_reverse = !m_reverse;
else
m_reverse = FALSE;
m_last_col = col;
m_ctlPluginList.SortItems (CompareFunc, m_reverse << 8 | m_last_col);
*pResult = 0;
} // end of CPluginsDlg::OnColumnclickPluginsList
void CPluginsDlg::OnShowDescription()
{
// iterate through list
for (int nItem = -1;
(nItem = m_ctlPluginList.GetNextItem(nItem, LVNI_SELECTED)) != -1;)
{
CPlugin * p = (CPlugin *) m_ctlPluginList.GetItemData (nItem);
if (p->m_strDescription.IsEmpty ())
continue; // ignore ones without a description
CString strTitle = TFormat ("%s description", (LPCTSTR) p->m_strName);
m_pDoc->AppendToTheNotepad (strTitle,
p->m_strDescription,
true,
eNotepadPluginInfo);
// make sure they see it
m_pDoc->ActivateNotepad (strTitle);
} // end of doing all selected ones
} // end of CPluginsDlg::OnShowDescription
void CPluginsDlg::OnUpdateNeedSelection(CCmdUI* pCmdUI)
{
pCmdUI->Enable (m_ctlPluginList.GetSelectedCount () > 0);
} // end of CPluginsDlg::OnUpdateNeedSelection
void CPluginsDlg::OnUpdateNeedDescription(CCmdUI* pCmdUI)
{
if (m_ctlPluginList.GetSelectedCount () <= 0)
{
pCmdUI->Enable (FALSE);
return;
}
// iterate through list
for (int nItem = -1;
(nItem = m_ctlPluginList.GetNextItem(nItem, LVNI_SELECTED)) != -1;)
{
CPlugin * p = (CPlugin *) m_ctlPluginList.GetItemData (nItem);
// need a non-blank description for at least one of them
if (!p->m_strDescription.IsEmpty ())
{
pCmdUI->Enable (TRUE);
return;
} // one with a description
} // end of loop
pCmdUI->Enable (FALSE);
} // end of CPluginsDlg::OnUpdateNeedDescription
LRESULT CPluginsDlg::OnKickIdle(WPARAM, LPARAM)
{
UpdateDialogControls (AfxGetApp()->m_pMainWnd, false);
return 0;
} // end of CPluginsDlg::OnKickIdle
void CPluginsDlg::OnAddPlugin()
{
CFileDialog filedlg (TRUE, // loading the file
"", // default extension
"", // suggested name
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER,
"XML files (*.xml)|*.xml|"
"Text files (*.txt)|*.txt|"
"All files (*.*)|*.*|"
"|", // filter
this); // parent window
char szFileBuffer[4096];
szFileBuffer[0] = 0;
filedlg.m_ofn.lpstrFile = szFileBuffer;
filedlg.m_ofn.nMaxFile = sizeof(szFileBuffer);
filedlg.m_ofn.lpstrTitle = "Add plugin";
// use default world file directory
filedlg.m_ofn.lpstrInitialDir = Make_Absolute_Path (App.m_strPluginsDirectory);
ChangeToFileBrowsingDirectory ();
int nResult = filedlg.DoModal();
ChangeToStartupDirectory ();
if (nResult != IDOK)
{
DWORD reason = CommDlgExtendedError();
return; // cancelled dialog
}
bool bChanged = false;
CString strPath;
for (POSITION pos = filedlg.GetStartPosition (); pos; )
{
strPath = filedlg.GetNextPathName (pos);
try
{
// now load it
m_pDoc->InternalLoadPlugin (strPath);
bChanged = true;
} // end of try block
catch (CFileException * e)
{
::UMessageBox (TFormat ("Unable to open or read %s",
(LPCTSTR) strPath), MB_ICONEXCLAMATION);
e->Delete ();
} // end of catching a file exception
catch (CException* e)
{
::UMessageBox (TFormat ("There was a problem loading the plugin %s. "
"See the output window for more details",
(LPCTSTR) strPath), MB_ICONEXCLAMATION);
e->Delete ();
EditPlugin (strPath); // let them see the problem
}
} // end of doing each file
LoadList ();
if (bChanged)
{
m_pDoc->PluginListChanged ();
m_pDoc->SetModifiedFlag (TRUE);
}
} // end of CPluginsDlg::OnAddPlugin()
void CPluginsDlg::OnDeletePlugin()
{
CUIntArray arySelected;
int iCount = m_ctlPluginList.GetSelectedCount ();
int nItem,
i;
arySelected.SetSize (iCount);
// first, remember selected items
for (nItem = -1, i = 0;
(nItem = m_ctlPluginList.GetNextItem(nItem, LVNI_SELECTED)) != -1;)
arySelected [i++] = nItem;
bool bChanged = false;
// we do it this way because deleting items buggers up the position in the array
for (i = iCount - 1; i >= 0; i--)
{
nItem = arySelected [i];
CPlugin * p = (CPlugin *) m_ctlPluginList.GetItemData (nItem);
POSITION pos = m_pDoc->m_PluginList.Find (p);
if (pos)
{
m_pDoc->m_PluginList.RemoveAt (pos); // remove from list
delete p; // delete the plugin
bChanged = true;
}
else
::TMessageBox ("Plugin cannot be found, unexpectedly.", MB_ICONEXCLAMATION);
} // end of loop
LoadList ();
if (bChanged)
{
m_pDoc->PluginListChanged ();
m_pDoc->SetModifiedFlag (TRUE);
}
} // CPluginsDlg::OnDeletePlugin()
/*
void CPluginsDlg::OnMoveUp()
{
int nItem = m_ctlPluginList.GetNextItem(-1, LVNI_SELECTED);
if (nItem == -1)
return;
if (nItem == 0)
return; // already at top
CPlugin * p = (CPlugin *) m_ctlPluginList.GetItemData (nItem);
POSITION pos = m_pDoc->m_PluginList.Find (p);
if (!pos)
return;
CPlugin * p2 = (CPlugin *) m_ctlPluginList.GetItemData (nItem - 1);
POSITION pos2 = m_pDoc->m_PluginList.Find (p2);
if (!pos2)
return;
m_pDoc->m_PluginList.RemoveAt (pos); // remove from list (old position)
m_pDoc->m_PluginList.InsertBefore (pos2, p); // add before previous one
LoadList ();
}
void CPluginsDlg::OnMoveDown()
{
// TODO: Add your control notification handler code here
}
*/
void CPluginsDlg::OnReload()
{
bool bChanged = false;
// iterate through list
for (int nItem = -1;
(nItem = m_ctlPluginList.GetNextItem(nItem, LVNI_SELECTED)) != -1;)
{
CPlugin * p = (CPlugin *) m_ctlPluginList.GetItemData (nItem);
POSITION pos = m_pDoc->m_PluginList.Find (p);
if (pos)
{
CString strName = p->m_strSource;
m_pDoc->m_PluginList.RemoveAt (pos); // remove from list
delete p; // delete the plugin
try
{
bChanged = true;
// now reload it
m_pDoc->InternalLoadPlugin (strName);
} // end of try block
catch (CFileException * e)
{
::UMessageBox (TFormat ("Unable to open or read %s",
(LPCTSTR) strName), MB_ICONEXCLAMATION);
e->Delete ();
} // end of catching a file exception
catch (CArchiveException* e)
{
::UMessageBox (TFormat ("There was a problem loading the plugin %s. "
"See the output window for more details",
(LPCTSTR) strName), MB_ICONEXCLAMATION);
e->Delete ();
}
}
else
::TMessageBox ("Plugin cannot be found, unexpectedly.", MB_ICONEXCLAMATION);
} // end of loop
LoadList ();
if (bChanged)
m_pDoc->PluginListChanged ();
} // end of CPluginsDlg::OnReload
void CPluginsDlg::OnDestroy()
{
App.SaveColumnConfiguration ("Plugins List", eColumnCount, m_ctlPluginList,
m_last_col, m_reverse);
CDialog::OnDestroy();
CWindowPlacement wp;
wp.Save ("Plugins List", this);
} // end of CPluginsDlg::OnDestroy
void CPluginsDlg::EditPlugin (const CString strName)
{
if (m_pDoc->m_bEditScriptWithNotepad)
{
CTextDocument * pNewDoc =
(CTextDocument *) App.OpenDocumentFile (strName);
if (pNewDoc)
{
pNewDoc->SetTheFont ();
pNewDoc->m_pRelatedWorld = m_pDoc;
pNewDoc->m_iUniqueDocumentNumber = m_pDoc->m_iUniqueDocumentNumber;
}
else
::UMessageBox(TFormat ("Unable to edit the plugin file %s.",
(LPCTSTR) strName),
MB_ICONEXCLAMATION);
return;
} // end of using inbuilt notepad
m_pDoc->EditFileWithEditor (strName);
} // end of CPluginsDlg::EditPlugin
void CPluginsDlg::OnEdit()
{
// iterate through list
for (int nItem = -1;
(nItem = m_ctlPluginList.GetNextItem(nItem, LVNI_SELECTED)) != -1;)
{
CPlugin * p = (CPlugin *) m_ctlPluginList.GetItemData (nItem);
POSITION pos = m_pDoc->m_PluginList.Find (p);
if (!pos)
continue;
EditPlugin (p->m_strSource);
} // end of loop
} // end of CPluginsDlg::OnEdit
void CPluginsDlg::OnDblclkPluginsList(NMHDR* pNMHDR, LRESULT* pResult)
{
OnEdit ();
*pResult = 0;
} // end of CPluginsDlg::OnDblclkPluginsList
// helpful macro for adjusting button positions
#define ADJUST_BUTTON(ctl, item) \
ctl.MoveWindow (iBorder + (iWidth * (item - 1)) + (iGap * (item - 1)), \
iTopOfRow, iWidth, iHeight)
void CPluginsDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if (m_ctlPluginList.m_hWnd && m_ctlCancel.m_hWnd && m_ctlAdd.m_hWnd &&
m_ctlEnable.m_hWnd && m_ctlDisable.m_hWnd)
{
// move OK and Cancel buttons
int iHeight;
int iWidth;
int iTopOfRow;
int iBorder = 10;
const int iButtonCount = 4; // how many buttons
// Find button size - we assume all are the same
GetButtonSize (m_ctlDelete, iHeight, iWidth);
// ------------------------
// calculate gaps for middle buttons - I will assume all buttons are the same size here
// gap (between Add and Edit buttons) will be the width of the dialog
// less the gaps on the side of those buttons, less the width of the iButtonCount buttons themselves
int iGap = cx - (iBorder * 2) - (iWidth * iButtonCount);
// we need (iButtonCount - 1) gaps: Add --1-- Reinstall --2-- Enable --3-- Edit
// Remove --1-- Show Info --2-- Disable --3-- Close
iGap /= iButtonCount - 1;
// -----------------------
// ------------------------------------------------------------------------------------
// bottom row
// calculate top of row
iTopOfRow = cy - iHeight - 10;
// Remove button (1)
ADJUST_BUTTON (m_ctlDelete, 1);
// Show Info button (2)
ADJUST_BUTTON (m_ctlShowDescription, 2);
// Disable button (3)
ADJUST_BUTTON (m_ctlDisable, 3);
// Close button (4)
ADJUST_BUTTON (m_ctlCancel, 4);
// ------------------------------------------------------------------------------------
// top row
// calculate top of row
iTopOfRow -= (iHeight + 10);
// Add button (1)
ADJUST_BUTTON (m_ctlAdd, 1);
// Reinstall button (2)
ADJUST_BUTTON (m_ctlReload, 2);
// Enable button (3)
ADJUST_BUTTON (m_ctlEnable, 3);
// Edit button (4)
ADJUST_BUTTON (m_ctlEdit, 4);
// move text to just above it
m_ctlPluginList.MoveWindow(0, 0, cx, iTopOfRow - 10);
}
}
// RIGHT double-click plugin in list to see state file
void CPluginsDlg::OnRdblclkPluginsList(NMHDR* pNMHDR, LRESULT* pResult)
{
if (m_pDoc->m_strWorldID.IsEmpty ())
return;
// iterate through list
for (int nItem = -1;
(nItem = m_ctlPluginList.GetNextItem(nItem, LVNI_SELECTED)) != -1;)
{
CPlugin * p = (CPlugin *) m_ctlPluginList.GetItemData (nItem);
POSITION pos = m_pDoc->m_PluginList.Find (p);
if (!pos)
continue;
// no state file, don't bother
if (!(p->m_bSaveState))
continue;
// need a directory
CString strName = CString (Make_Absolute_Path (App.m_strPluginsDirectory)) + "state\\";
strName += m_pDoc->m_strWorldID; // world ID
strName += "-";
strName += p->m_strID; // plugin ID
strName += "-state.xml"; // suffix
if (m_pDoc->m_bEditScriptWithNotepad)
{
CTextDocument * pNewDoc =
(CTextDocument *) App.OpenDocumentFile (strName);
if (pNewDoc)
{
pNewDoc->SetTheFont ();
pNewDoc->m_pRelatedWorld = m_pDoc;
pNewDoc->m_iUniqueDocumentNumber = m_pDoc->m_iUniqueDocumentNumber;
}
else
::UMessageBox(TFormat ("Unable to edit the plugin state file %s.",
(LPCTSTR) strName),
MB_ICONEXCLAMATION);
continue;
} // end of using inbuilt notepad
m_pDoc->EditFileWithEditor (strName);
} // end of loop
*pResult = 0;
} // end of CPluginsDlg::OnRdblclkPluginsList
void CPluginsDlg::OnEnable()
{
bool bChanged = false;
// iterate through list
for (int nItem = -1;
(nItem = m_ctlPluginList.GetNextItem(nItem, LVNI_SELECTED)) != -1;)
{
CPlugin * p = (CPlugin *) m_ctlPluginList.GetItemData (nItem);
POSITION pos = m_pDoc->m_PluginList.Find (p);
if (!pos)
continue;
m_pDoc->EnablePlugin (p->m_strID, TRUE);
bChanged = true;
} // end of loop
LoadList ();
if (bChanged)
m_pDoc->PluginListChanged ();
} // end of CPluginsDlg::OnEnable
void CPluginsDlg::OnDisable()
{
bool bChanged = false;
// iterate through list
for (int nItem = -1;
(nItem = m_ctlPluginList.GetNextItem(nItem, LVNI_SELECTED)) != -1;)
{
CPlugin * p = (CPlugin *) m_ctlPluginList.GetItemData (nItem);
POSITION pos = m_pDoc->m_PluginList.Find (p);
if (!pos)
continue;
m_pDoc->EnablePlugin (p->m_strID, FALSE);
bChanged = true;
} // end of loop
LoadList ();
if (bChanged)
m_pDoc->PluginListChanged ();
} // end of CPluginsDlg::OnDisable