treeviewdlg.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. // treeviewDlg.cpp : implementation file
  14. //
  15. #include "stdafx.h"
  16. #include "treeview.h"
  17. #include "treeviewDlg.h"
  18. #include "util.hpp"
  19. #include "jptree.hpp"
  20. #include "jfile.hpp"
  21. #include "jlib.hpp"
  22. #include "mpbase.hpp"
  23. #include "mpcomm.hpp"
  24. #include "daclient.hpp"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. #define DEFAULT_FILE_EXT "xml"
  31. #define DEFAULT_FILE_MASK "*.xml"
  32. #define DEFAULT_TITLE "Property Tree Inspector"
  33. #define CONNECT_SECTION "RemoteConnect"
  34. #define COVEN_SIZE "CovenSize"
  35. UINT WM_FINDREPLACE = ::RegisterWindowMessage(FINDMSGSTRING);
  36. // ROYMORE may be better to move these to a local Property Tree
  37. class CAboutDlg : public CDialog
  38. {
  39. public:
  40. CAboutDlg();
  41. // Dialog Data
  42. //{{AFX_DATA(CAboutDlg)
  43. enum { IDD = IDD_ABOUTBOX };
  44. //}}AFX_DATA
  45. // ClassWizard generated virtual function overrides
  46. //{{AFX_VIRTUAL(CAboutDlg)
  47. protected:
  48. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  49. //}}AFX_VIRTUAL
  50. // Implementation
  51. protected:
  52. //{{AFX_MSG(CAboutDlg)
  53. //}}AFX_MSG
  54. DECLARE_MESSAGE_MAP()
  55. };
  56. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  57. {
  58. //{{AFX_DATA_INIT(CAboutDlg)
  59. //}}AFX_DATA_INIT
  60. }
  61. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  62. {
  63. CDialog::DoDataExchange(pDX);
  64. //{{AFX_DATA_MAP(CAboutDlg)
  65. //}}AFX_DATA_MAP
  66. }
  67. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  68. //{{AFX_MSG_MAP(CAboutDlg)
  69. // No message handlers
  70. //}}AFX_MSG_MAP
  71. END_MESSAGE_MAP()
  72. class CExpanderThread : public Thread
  73. {
  74. private:
  75. CTreeviewDlg * dlg;
  76. CInspectorTreeCtrl * tree;
  77. bool expand;
  78. public:
  79. CExpanderThread(CTreeviewDlg * _dlg, bool _expand)
  80. {
  81. dlg = _dlg;
  82. tree = dlg->inspector.getTree();
  83. expand = _expand;
  84. }
  85. void process(HTREEITEM in, int lvl)
  86. {
  87. if(lvl > 0)
  88. {
  89. if(expand)
  90. {
  91. if(tree->ItemHasChildren(in) && !(tree->GetItemState(in, TVIS_EXPANDED) & TVIS_EXPANDED))
  92. {
  93. tree->Expand(in, TVE_EXPAND);
  94. lvl--;
  95. }
  96. }
  97. else if(tree->ItemHasChildren(in) && tree->GetItemState(in, TVIS_EXPANDED) & TVIS_EXPANDED)
  98. tree->Expand(in, TVE_COLLAPSE);
  99. HTREEITEM i = tree->GetChildItem(in);
  100. while(i)
  101. {
  102. process(i, lvl);
  103. i = tree->GetNextItem(i, TVGN_NEXT);
  104. }
  105. }
  106. }
  107. virtual int run()
  108. {
  109. process(tree->GetRootItem(), 1);
  110. dlg->endExpand();
  111. return 0;
  112. }
  113. };
  114. BEGIN_MESSAGE_MAP(CTreeviewDlg, CDialog)
  115. //{{AFX_MSG_MAP(CTreeviewDlg)
  116. ON_WM_SYSCOMMAND()
  117. ON_WM_PAINT()
  118. ON_WM_QUERYDRAGICON()
  119. ON_WM_SIZE()
  120. ON_COMMAND_EX(IDD_NEXT_FIELD, OnNextPrevField)
  121. ON_WM_CLOSE()
  122. ON_BN_CLICKED(IDC_EXIT, OnExit)
  123. ON_COMMAND(IDM_LOAD, OnMenuLoad)
  124. ON_COMMAND(IDM_SAVE, OnMenuSave)
  125. ON_COMMAND(IDM_EXIT, OnMenuExit)
  126. ON_COMMAND(IDM_EXPANDALL, OnMenuExpandall)
  127. ON_COMMAND(IDM_CONTRACTALL, OnMenuContractall)
  128. ON_COMMAND(IDM_FIND, OnMenuFind)
  129. ON_COMMAND(IDM_DELETE, OnMenuDelete)
  130. ON_COMMAND(IDM_DELETECONFIRM, OnMenuDeleteConfirm)
  131. ON_COMMAND(IDM_ABOUT, OnMenuAbout)
  132. ON_COMMAND(IDM_SHOWATTRIBS, OnMenuShowAttribs)
  133. ON_COMMAND(IDM_SHOWQUALIFIED, OnMenuShowQualified)
  134. ON_COMMAND(IDM_CONNECTREMOTE, OnMenuConnectRemote)
  135. ON_COMMAND(IDM_RECONNECT, OnMenuReconnect)
  136. ON_COMMAND(IDM_COMMIT, OnCommit)
  137. ON_WM_CREATE()
  138. ON_COMMAND_EX(IDD_PREV_FIELD, OnNextPrevField)
  139. //}}AFX_MSG_MAP
  140. ON_REGISTERED_MESSAGE(WM_FINDREPLACE, OnFindReplace)
  141. END_MESSAGE_MAP()
  142. CTreeviewDlg::CTreeviewDlg(LPCSTR fn, CWnd* pParent) : CDialog(CTreeviewDlg::IDD, pParent)
  143. {
  144. //{{AFX_DATA_INIT(CTreeviewDlg)
  145. // NOTE: the ClassWizard will add member initialization here
  146. //}}AFX_DATA_INIT
  147. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  148. InitModuleObjects();
  149. queryStderrLogMsgHandler()->setMessageFields(0);
  150. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  151. tooltipCtrl = NULL;
  152. hAccel = NULL;
  153. findReplaceDialog = NULL;
  154. expander = NULL;
  155. connection = NULL;
  156. cmdfname = fn ? strdup(fn) : NULL;
  157. }
  158. CTreeviewDlg::~CTreeviewDlg()
  159. {
  160. releaseAtoms();
  161. free(cmdfname);
  162. if(expander) delete expander;
  163. delete tooltipCtrl;
  164. }
  165. void CTreeviewDlg::setWindowTitle()
  166. {
  167. CString title(DEFAULT_TITLE);
  168. if(connection && connection->queryName())
  169. {
  170. title += " [";
  171. title += connection->queryName();
  172. title += "]";
  173. }
  174. SetWindowText(title);
  175. }
  176. void CTreeviewDlg::resetDialog()
  177. {
  178. inspector.KillTree();
  179. if(connection)
  180. {
  181. connection->Release();
  182. connection = NULL;
  183. }
  184. setWindowTitle();
  185. updateMenuState();
  186. }
  187. void CTreeviewDlg::DoDataExchange(CDataExchange* pDX)
  188. {
  189. CDialog::DoDataExchange(pDX);
  190. //{{AFX_DATA_MAP(CTreeviewDlg)
  191. // NOTE: the ClassWizard will add DDX and DDV calls here
  192. //}}AFX_DATA_MAP
  193. }
  194. BOOL CTreeviewDlg::OnInitDialog()
  195. {
  196. CDialog::OnInitDialog();
  197. hAccel = LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1));
  198. SetIcon(m_hIcon, TRUE); // Set big icon
  199. SetIcon(m_hIcon, FALSE); // Set small icon
  200. inspector.SubclassDlgItem(IDC_INSPECTOR, this);
  201. tooltipCtrl = new CToolTipCtrl;
  202. tooltipCtrl->Create(this);
  203. CRect DialogRect, rect;
  204. GetWindowRect(DialogRect);
  205. CWnd * wnd = GetDlgItemRect(IDC_EXIT, rect);
  206. CloseRightOffset = DialogRect.right - rect.left;
  207. CloseBottomOffset = DialogRect.bottom - rect.top;
  208. tooltipCtrl->AddTool(wnd, "Close the property inspector");
  209. wnd = GetDlgItemRect(IDC_INSPECTOR, rect);
  210. TreeRightMargin = DialogRect.right - rect.right;
  211. TreeBottomMargin = DialogRect.bottom - rect.bottom;
  212. if(cmdfname)
  213. _loadTree(cmdfname);
  214. else
  215. updateMenuState();
  216. return FALSE;
  217. }
  218. void CTreeviewDlg::OnSysCommand(UINT nID, LPARAM lParam)
  219. {
  220. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  221. {
  222. CAboutDlg dlgAbout;
  223. dlgAbout.DoModal();
  224. }
  225. else
  226. {
  227. CDialog::OnSysCommand(nID, lParam);
  228. }
  229. }
  230. BOOL CTreeviewDlg::PreTranslateMessage(MSG * msg)
  231. {
  232. if(tooltipCtrl) tooltipCtrl->RelayEvent(msg);
  233. if(msg->message >= WM_KEYFIRST && msg->message <= WM_KEYLAST)
  234. return ::TranslateAccelerator(m_hWnd, hAccel, msg);
  235. return CDialog::PreTranslateMessage(msg);
  236. }
  237. void CTreeviewDlg::OnPaint()
  238. {
  239. if (IsIconic())
  240. {
  241. CPaintDC dc(this);
  242. CRect rect;
  243. GetClientRect(&rect);
  244. SetWindowText(DEFAULT_TITLE);
  245. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  246. int x = (rect.Width() - GetSystemMetrics(SM_CXICON) + 1) / 2;
  247. int y = (rect.Height() - GetSystemMetrics(SM_CYICON) + 1) / 2;
  248. dc.DrawIcon(x, y, m_hIcon);
  249. }
  250. else
  251. {
  252. CDialog::OnPaint();
  253. }
  254. }
  255. void CTreeviewDlg::OnCommit()
  256. {
  257. if(connection) connection->commit();
  258. }
  259. HCURSOR CTreeviewDlg::OnQueryDragIcon()
  260. {
  261. return (HCURSOR) m_hIcon;
  262. }
  263. void CTreeviewDlg::OnSize(UINT nType, int cx, int cy)
  264. {
  265. CDialog::OnSize(nType, cx, cy);
  266. if(!IsIconic())
  267. {
  268. CRect rect, DialogRect;
  269. GetWindowRect(DialogRect);
  270. HDWP hDefer = BeginDeferWindowPos(16);
  271. CWnd * Wnd = GetDlgItemRect(IDC_EXIT, rect);
  272. if(Wnd)
  273. {
  274. int width = rect.Width();
  275. int height = rect.Height();
  276. rect.top = DialogRect.bottom - CloseBottomOffset;
  277. rect.bottom = rect.top + height;
  278. rect.left = DialogRect.right - CloseRightOffset;
  279. rect.right = rect.left + width;
  280. ScreenToClient(&rect);
  281. DeferWindowPos(hDefer, Wnd->m_hWnd, NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOZORDER | SWP_NOREDRAW);
  282. }
  283. Wnd = GetDlgItemRect(IDC_INSPECTOR, rect);
  284. if(Wnd)
  285. {
  286. rect.right = DialogRect.right - TreeRightMargin;
  287. rect.bottom = DialogRect.bottom - TreeBottomMargin;
  288. ScreenToClient(&rect);
  289. DeferWindowPos(hDefer, Wnd->m_hWnd, NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOZORDER | SWP_NOREDRAW);
  290. }
  291. EndDeferWindowPos(hDefer);
  292. Invalidate();
  293. }
  294. }
  295. void CTreeviewDlg::OnMenuSave()
  296. {
  297. if(connection && connection->getType() != CT_none)
  298. {
  299. CFileDialog fileDialog(FALSE, DEFAULT_FILE_EXT, DEFAULT_FILE_MASK, OFN_HIDEREADONLY | OFN_NOCHANGEDIR, "XML Files (*.xml)|*.xml||", this);
  300. while(fileDialog.DoModal() != IDCANCEL)
  301. {
  302. CString fullfname = fileDialog.GetPathName();
  303. if(!fullfname.IsEmpty())
  304. {
  305. if(fileDialog.GetFileExt().IsEmpty()) fullfname += ".xml";
  306. if(_saveTree(fullfname)) break;
  307. }
  308. }
  309. }
  310. setWindowTitle();
  311. }
  312. bool CTreeviewDlg::_loadTree(LPCSTR fname)
  313. {
  314. resetDialog();
  315. connection = createLocalConnection(fname);
  316. if(connection->getType() == CT_local)
  317. {
  318. inspector.NewTree(connection);
  319. setWindowTitle();
  320. updateMenuState();
  321. inspector.SetFocus();
  322. inspector.Invalidate();
  323. return true;
  324. }
  325. MessageBox("Tree failed to load", "Load Failure", MB_OK | MB_ICONEXCLAMATION);
  326. return false;
  327. }
  328. bool CTreeviewDlg::_saveTree(LPCSTR fname)
  329. {
  330. return connection && connection->getType() != CT_none && saveTree(fname, *connection->queryRoot()) ? true : false;
  331. }
  332. void CTreeviewDlg::OnMenuLoad()
  333. {
  334. CFileDialog fileDialog(TRUE, DEFAULT_FILE_EXT, DEFAULT_FILE_MASK, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR, "XML Files (*.xml)|*.xml||", this);
  335. while(fileDialog.DoModal() != IDCANCEL)
  336. {
  337. resetDialog();
  338. CString fullfname = fileDialog.GetPathName();
  339. if(!fullfname.IsEmpty() && _loadTree(fullfname)) break;
  340. }
  341. }
  342. BOOL CTreeviewDlg::OnNextPrevField(UINT cmdId)
  343. {
  344. static const UINT ctrls[] = {IDC_TREE_LIST_CTRL, IDC_EXIT};
  345. static const int ctrlsMax = sizeof(ctrls) / sizeof(UINT);
  346. UINT id = GetFocus()->GetDlgCtrlID();
  347. for(int i = 0; i < ctrlsMax; i++)
  348. {
  349. if(ctrls[i] == id)
  350. {
  351. if(cmdId == IDD_NEXT_FIELD)
  352. i = (++i % ctrlsMax);
  353. else
  354. i = i ? --i : ctrlsMax - 1;
  355. switch(ctrls[i])
  356. {
  357. case IDC_TREE_LIST_CTRL:
  358. inspector.SetFocus();
  359. return TRUE;
  360. default:
  361. GotoDlgCtrl(GetDlgItem(ctrls[i]));
  362. return TRUE;
  363. }
  364. }
  365. }
  366. return FALSE;
  367. }
  368. void CTreeviewDlg::OnMenuAbout()
  369. {
  370. CAboutDlg about;
  371. about.DoModal();
  372. }
  373. void CTreeviewDlg::OnMenuShowAttribs()
  374. {
  375. CMenu * menu = GetMenu();
  376. ASSERT(menu != NULL);
  377. if(menu->GetMenuState(IDM_SHOWATTRIBS, MF_BYCOMMAND) & MF_CHECKED)
  378. {
  379. menu->CheckMenuItem(IDM_SHOWATTRIBS, MF_BYCOMMAND | MF_UNCHECKED);
  380. inspector.showAttribs(false);
  381. }
  382. else
  383. {
  384. menu->CheckMenuItem(IDM_SHOWATTRIBS, MF_BYCOMMAND | MF_CHECKED);
  385. inspector.showAttribs();
  386. }
  387. }
  388. void CTreeviewDlg::OnMenuShowQualified()
  389. {
  390. CMenu * menu = GetMenu();
  391. ASSERT(menu != NULL);
  392. if(menu->GetMenuState(IDM_SHOWQUALIFIED, MF_BYCOMMAND) & MF_CHECKED)
  393. {
  394. menu->CheckMenuItem(IDM_SHOWQUALIFIED, MF_BYCOMMAND | MF_UNCHECKED);
  395. inspector.showQualified(false);
  396. }
  397. else
  398. {
  399. menu->CheckMenuItem(IDM_SHOWQUALIFIED, MF_BYCOMMAND | MF_CHECKED);
  400. inspector.showQualified();
  401. }
  402. }
  403. void CTreeviewDlg::OnMenuDelete()
  404. {
  405. inspector.getTree()->DeleteCurrentItem(false);
  406. }
  407. void CTreeviewDlg::OnMenuDeleteConfirm()
  408. {
  409. inspector.getTree()->DeleteCurrentItem();
  410. }
  411. void CTreeviewDlg::OnMenuFind()
  412. {
  413. findReplaceDialog = new CFindReplaceDialog(); // deleted by itself
  414. if(!findReplaceDialog->Create(TRUE, findStr, NULL, FR_DOWN, this))
  415. {
  416. delete findReplaceDialog;
  417. findReplaceDialog = NULL;
  418. }
  419. updateMenuState();
  420. inspector.BeginFind();
  421. }
  422. LRESULT CTreeviewDlg::OnFindReplace(WPARAM wParam, LPARAM lParam)
  423. {
  424. ASSERT(findReplaceDialog != NULL);
  425. if(findReplaceDialog->IsTerminating())
  426. {
  427. inspector.EndFind();
  428. findReplaceDialog = NULL; // will delete itself
  429. updateMenuState();
  430. }
  431. else if(findReplaceDialog->FindNext())
  432. {
  433. inspector.NextFind(findReplaceDialog->GetFindString(), findReplaceDialog->MatchCase(), findReplaceDialog->MatchWholeWord());
  434. }
  435. return 0;
  436. }
  437. void CTreeviewDlg::OnMenuExpandall()
  438. {
  439. if(expander) delete expander;
  440. expander = new CExpanderThread(this, true);
  441. updateMenuState();
  442. expander->start();
  443. }
  444. void CTreeviewDlg::OnMenuContractall()
  445. {
  446. if(expander) delete expander;
  447. expander = new CExpanderThread(this, false);
  448. updateMenuState();
  449. expander->start();
  450. }
  451. void CTreeviewDlg::endExpand()
  452. {
  453. expander->Release();
  454. expander = NULL;
  455. updateMenuState();
  456. }
  457. void CTreeviewDlg::OnMenuExit()
  458. {
  459. OnExit();
  460. }
  461. void CTreeviewDlg::OnMenuConnectRemote()
  462. {
  463. resetDialog();
  464. CConnectDlg ConnectDlg(this);
  465. if(ConnectDlg.DoModal() == IDOK)
  466. {
  467. connectedEpa.kill();
  468. for(int i = 0; i < ConnectDlg.GetCovenSize(); i++)
  469. {
  470. SocketEndpoint ep;
  471. toEp(ep, ConnectDlg.GetServerEndpoint(i));
  472. connectedEpa.append(ep);
  473. }
  474. connection = createRemoteConnection(connectedEpa);
  475. if(connection->getType() == CT_remote)
  476. {
  477. inspector.NewTree(connection);
  478. setWindowTitle();
  479. updateMenuState();
  480. }
  481. else
  482. MessageBox("Failed to connect to any of the remote Dali servers\nthat you listed in the connection details.", "Connection Failed", MB_OK | MB_ICONEXCLAMATION);
  483. }
  484. }
  485. void CTreeviewDlg::OnMenuReconnect()
  486. {
  487. if (!connectedEpa.ordinality())
  488. {
  489. OnMenuConnectRemote();
  490. return;
  491. }
  492. resetDialog();
  493. connection = createRemoteConnection(connectedEpa);
  494. if(connection->getType() == CT_remote)
  495. {
  496. inspector.NewTree(connection);
  497. setWindowTitle();
  498. updateMenuState();
  499. }
  500. else
  501. MessageBox("Failed to reconnect to any of the remote Dali servers\nthat you listed in the connection details.", "Connection Failed", MB_OK | MB_ICONEXCLAMATION);
  502. }
  503. void CTreeviewDlg::OnExit()
  504. {
  505. resetDialog();
  506. EndDialog(0);
  507. }
  508. void CTreeviewDlg::OnClose()
  509. {
  510. resetDialog();
  511. CDialog::OnClose();
  512. }
  513. CWnd * CTreeviewDlg::GetDlgItemRect(int nId, RECT & rect)
  514. {
  515. CWnd * r = GetDlgItem(nId);
  516. if(r) r->GetWindowRect(&rect);
  517. return r;
  518. }
  519. #define MENUENABLE(i) menu->EnableMenuItem(i, MF_ENABLED)
  520. #define MENUDISABLE(i) menu->EnableMenuItem(i, MF_GRAYED)
  521. void CTreeviewDlg::updateMenuState()
  522. {
  523. CMenu * menu = GetMenu();
  524. ASSERT(menu != NULL);
  525. if(findReplaceDialog || expander)
  526. {
  527. MENUDISABLE(IDM_LOAD);
  528. MENUDISABLE(IDM_SAVE);
  529. MENUDISABLE(IDM_CONNECTREMOTE);
  530. MENUDISABLE(IDM_RECONNECT);
  531. MENUDISABLE(IDM_FIND);
  532. MENUDISABLE(IDM_XFIND);
  533. MENUDISABLE(IDM_COMMIT);
  534. MENUDISABLE(IDM_REFRESH);
  535. MENUDISABLE(IDM_SHOWATTRIBS);
  536. MENUDISABLE(IDM_SHOWQUALIFIED);
  537. MENUDISABLE(IDM_CONTRACTALL);
  538. MENUDISABLE(IDM_EXPANDALL);
  539. }
  540. else
  541. {
  542. MENUDISABLE(IDM_XFIND);
  543. if(connection && connection->getType() != CT_none)
  544. {
  545. MENUENABLE(IDM_FIND);
  546. MENUENABLE(IDM_CONTRACTALL);
  547. MENUENABLE(IDM_EXPANDALL);
  548. MENUENABLE(IDM_SAVE);
  549. MENUENABLE(IDM_CONNECTREMOTE);
  550. MENUENABLE(IDM_RECONNECT);
  551. MENUENABLE(IDM_REFRESH);
  552. MENUENABLE(IDM_SHOWATTRIBS);
  553. MENUENABLE(IDM_SHOWQUALIFIED);
  554. if(connection->getType() == CT_remote)
  555. MENUENABLE(IDM_COMMIT);
  556. else
  557. MENUDISABLE(IDM_COMMIT);
  558. }
  559. else
  560. {
  561. MENUDISABLE(IDM_FIND);
  562. MENUDISABLE(IDM_CONTRACTALL);
  563. MENUDISABLE(IDM_EXPANDALL);
  564. MENUDISABLE(IDM_SAVE);
  565. MENUDISABLE(IDM_REFRESH);
  566. MENUDISABLE(IDM_SHOWATTRIBS);
  567. MENUDISABLE(IDM_SHOWQUALIFIED);
  568. MENUDISABLE(IDM_COMMIT);
  569. }
  570. }
  571. }
  572. bool saveTree(LPCSTR fname, IPropertyTree & pTree)
  573. {
  574. bool r = true; // let's be optimistic
  575. StringBuffer xml;
  576. toXML(&pTree, xml);
  577. IFile * f = createIFile(fname);
  578. if(f)
  579. {
  580. IFileIO * io = f->open(IFOcreate);
  581. if(io)
  582. {
  583. if(io->write(0, xml.length(), xml.str()) != xml.length())
  584. {
  585. showFIOErr(fname, false);
  586. r = false;
  587. }
  588. io->Release();
  589. }
  590. else
  591. {
  592. showFIOErr(fname, false);
  593. r = false;
  594. }
  595. f->Release();
  596. }
  597. else
  598. {
  599. showFIOErr(fname, false);
  600. r = false;
  601. }
  602. return r;
  603. }
  604. /////////////////////////////////////////////////////////////////////////////
  605. // CConnectDlg dialog
  606. CConnectDlg::CConnectDlg(CWnd* pParent) : CDialog(CConnectDlg::IDD, pParent)
  607. {
  608. //{{AFX_DATA_INIT(CConnectDlg)
  609. // NOTE: the ClassWizard will add member initialization here
  610. //}}AFX_DATA_INIT
  611. }
  612. CConnectDlg::~CConnectDlg()
  613. {
  614. killEndpoints();
  615. }
  616. void CConnectDlg::DoDataExchange(CDataExchange* pDX)
  617. {
  618. CDialog::DoDataExchange(pDX);
  619. //{{AFX_DATA_MAP(CConnectDlg)
  620. // NOTE: the ClassWizard will add DDX and DDV calls here
  621. //}}AFX_DATA_MAP
  622. }
  623. BEGIN_MESSAGE_MAP(CConnectDlg, CDialog)
  624. //{{AFX_MSG_MAP(CConnectDlg)
  625. ON_BN_CLICKED(IDC_REMOVESERVER_BUTTON, OnRemoveServerButton)
  626. ON_BN_CLICKED(IDC_ADDSERVER_BUTTON, OnAddServerButton)
  627. //}}AFX_MSG_MAP
  628. END_MESSAGE_MAP()
  629. /////////////////////////////////////////////////////////////////////////////
  630. // CConnectDlg message handlers
  631. void CConnectDlg::killEndpoints()
  632. {
  633. for(int i = 0; i < ServerEndpoints.GetSize(); i++) delete ServerEndpoints.GetAt(i);
  634. ServerEndpoints.RemoveAll();
  635. }
  636. LPCSTR CConnectDlg::GetServerEndpoint(int idx)
  637. {
  638. CString & t = *ServerEndpoints.GetAt(idx);
  639. return idx < ServerEndpoints.GetSize() ? (LPCSTR)t : NULL;
  640. }
  641. int CConnectDlg::GetCovenSize()
  642. {
  643. return CovenSize;
  644. }
  645. int CConnectDlg::GetDlgItemInt(UINT id)
  646. {
  647. CString tmp;
  648. GetDlgItem(id)->GetWindowText(tmp);
  649. return atoi(tmp);
  650. }
  651. void CConnectDlg::OnOK()
  652. {
  653. CListBox * listBox = static_cast <CListBox *> (GetDlgItem(IDC_SERVERS_LIST));
  654. CovenSize = listBox->GetCount();
  655. if(CovenSize > 0)
  656. {
  657. putProfile(CONNECT_SECTION, COVEN_SIZE, CovenSize);
  658. killEndpoints();
  659. for(int i = 0; i < CovenSize; i++)
  660. {
  661. CString * ep;
  662. char key[32] = "ServerEP_";
  663. itoa(i, &key[9], 10);
  664. ep = new CString();
  665. listBox->GetText(i, *ep);
  666. ServerEndpoints.Add(ep);
  667. putProfile(CONNECT_SECTION, key, *ep);
  668. }
  669. CDialog::OnOK();
  670. }
  671. else
  672. MessageBox("There must be at least 1 server in\nthe coven.", "Connection Configuration Error", MB_OK | MB_ICONEXCLAMATION);
  673. }
  674. void CConnectDlg::OnCancel()
  675. {
  676. CDialog::OnCancel();
  677. }
  678. BOOL CConnectDlg::OnInitDialog()
  679. {
  680. CDialog::OnInitDialog();
  681. CListBox * listBox = static_cast <CListBox *> (GetDlgItem(IDC_SERVERS_LIST));
  682. for(int i = 0; i < getProfileInt(CONNECT_SECTION, COVEN_SIZE); i++)
  683. {
  684. char key[32] = "ServerEP_";
  685. itoa(i, &key[9], 10);
  686. listBox->AddString(getProfileStr(CONNECT_SECTION, key));
  687. }
  688. CovenSize = 0;
  689. return TRUE;
  690. }
  691. void CConnectDlg::OnRemoveServerButton()
  692. {
  693. CListBox * lb = static_cast <CListBox *> (GetDlgItem(IDC_SERVERS_LIST));
  694. if(lb->GetCurSel() >= 0) lb->DeleteString(lb->GetCurSel());
  695. }
  696. void CConnectDlg::OnAddServerButton()
  697. {
  698. CEndpointDlg epd;
  699. if(epd.DoModal() == IDOK)
  700. {
  701. CListBox * lb = static_cast <CListBox *> (GetDlgItem(IDC_SERVERS_LIST));
  702. lb->AddString(epd.GetEndpointStr());
  703. }
  704. }
  705. /////////////////////////////////////////////////////////////////////////////
  706. // CEndpointDlg dialog
  707. CEndpointDlg::CEndpointDlg(CWnd* pParent) : CDialog(CEndpointDlg::IDD, pParent)
  708. {
  709. //{{AFX_DATA_INIT(CEndpointDlg)
  710. // NOTE: the ClassWizard will add member initialization here
  711. //}}AFX_DATA_INIT
  712. }
  713. void CEndpointDlg::DoDataExchange(CDataExchange* pDX)
  714. {
  715. CDialog::DoDataExchange(pDX);
  716. //{{AFX_DATA_MAP(CEndpointDlg)
  717. // NOTE: the ClassWizard will add DDX and DDV calls here
  718. //}}AFX_DATA_MAP
  719. }
  720. BEGIN_MESSAGE_MAP(CEndpointDlg, CDialog)
  721. //{{AFX_MSG_MAP(CEndpointDlg)
  722. //}}AFX_MSG_MAP
  723. END_MESSAGE_MAP()
  724. /////////////////////////////////////////////////////////////////////////////
  725. // CEndpointDlg message handlers
  726. LPCSTR CEndpointDlg::GetEndpointStr()
  727. {
  728. return Endpoint;
  729. }
  730. void CEndpointDlg::OnOK()
  731. {
  732. GetDlgItem(IDC_SERVER_IP_EDIT)->GetWindowText(Endpoint);
  733. if(Endpoint.GetLength() > 0)
  734. {
  735. CString port;
  736. GetDlgItem(IDC_SERVER_PORT_EDIT)->GetWindowText(port);
  737. if(port.GetLength() > 0 && atoi(port) > 0)
  738. {
  739. Endpoint += ":";
  740. Endpoint += port;
  741. CDialog::OnOK();
  742. }
  743. else
  744. MessageBox("A port must be specified", "Endpoint Error", MB_OK | MB_ICONEXCLAMATION);
  745. }
  746. else
  747. MessageBox("An IP must be specified", "Endpoint Error", MB_OK | MB_ICONEXCLAMATION);
  748. }
  749. void CEndpointDlg::OnCancel()
  750. {
  751. Endpoint.Empty();
  752. CDialog::OnCancel();
  753. }
  754. BOOL CEndpointDlg::OnInitDialog()
  755. {
  756. CDialog::OnInitDialog();
  757. GetDlgItem(IDC_SERVER_PORT_EDIT)->SetWindowText("7070");
  758. return TRUE;
  759. }