PropertyList.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. /*=========================================================================
  2. Program: WXDialog - wxWidgets X-platform GUI Front-End for CMake
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Author: Jorgen Bodde
  8. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  9. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  10. This software is distributed WITHOUT ANY WARRANTY; without even
  11. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12. PURPOSE. See the above copyright notices for more information.
  13. =========================================================================*/
  14. /* for compilers that support precompilation
  15. includes "wx/wx.h" */
  16. #include "wx/wxprec.h"
  17. #ifdef __BORLANDC__
  18. #pragma hdrstop
  19. #endif
  20. #include "PropertyList.h"
  21. #include "app_resources.h"
  22. #include "../cmCacheManager.h"
  23. #include "../cmSystemTools.h"
  24. #include "../cmake.h"
  25. BEGIN_EVENT_TABLE( wxPropertyList, wxGrid )
  26. EVT_GRID_CELL_LEFT_CLICK( wxPropertyList::OnSelectCell )
  27. EVT_GRID_CELL_CHANGE( wxPropertyList::OnCellChange )
  28. EVT_GRID_CMD_CELL_RIGHT_CLICK( wxID_ANY, wxPropertyList::OnCellPopup )
  29. EVT_MENU ( ID_CACHE_DELETE, wxPropertyList::OnDeleteCache )
  30. EVT_MENU ( ID_CACHE_IGNORE, wxPropertyList::OnIgnoreCache )
  31. EVT_MENU ( ID_CACHE_BROWSE, wxPropertyList::OnBrowseItem )
  32. EVT_SIZE ( wxPropertyList::OnSizeGrid )
  33. EVT_CHAR ( wxPropertyList::OnKeyPressed )
  34. END_EVENT_TABLE()
  35. #if 0
  36. // ----------------------------------------------------------------------------
  37. // wxGridCellPathEditor
  38. // ----------------------------------------------------------------------------
  39. wxGridCellPathEditor::wxGridCellPathEditor()
  40. {
  41. m_maxChars = 0;
  42. }
  43. void wxGridCellPathEditor::Create(wxWindow* parent,
  44. wxWindowID id,
  45. wxEvtHandler* evtHandler)
  46. {
  47. m_control = new wxTextCtrl(parent, id, wxEmptyString,
  48. wxDefaultPosition, wxDefaultSize
  49. #if defined(__WXMSW__)
  50. , wxTE_PROCESS_TAB | wxTE_AUTO_SCROLL
  51. #endif
  52. );
  53. //
  54. // m_button = new wxButton(parent, id+1, _("..."),
  55. // wxDefaultPosition, wxDefaultSize);
  56. //
  57. // set max length allowed in the textctrl, if the parameter was set
  58. if (m_maxChars != 0)
  59. {
  60. ((wxTextCtrl*)m_control)->SetMaxLength(m_maxChars);
  61. }
  62. wxGridCellEditor::Create(parent, id, evtHandler);
  63. }
  64. void wxGridCellPathEditor::PaintBackground(const wxRect& WXUNUSED(rectCell),
  65. wxGridCellAttr * WXUNUSED(attr))
  66. {
  67. // as we fill the entire client area, don't do anything here to minimize
  68. // flicker
  69. }
  70. void wxGridCellPathEditor::SetSize(const wxRect& rectOrig)
  71. {
  72. wxRect rect(rectOrig);
  73. // Make the edit control large enough to allow for internal
  74. // margins
  75. //
  76. // TODO: remove this if the text ctrl sizing is improved esp. for
  77. // unix
  78. //
  79. #if defined(__WXGTK__)
  80. if (rect.x != 0)
  81. {
  82. rect.x += 1;
  83. rect.y += 1;
  84. rect.width -= 1;
  85. rect.height -= 1;
  86. }
  87. #else // !GTK
  88. int extra_x = ( rect.x > 2 )? 2 : 1;
  89. // MB: treat MSW separately here otherwise the caret doesn't show
  90. // when the editor is in the first row.
  91. #if defined(__WXMSW__)
  92. int extra_y = 2;
  93. #else
  94. int extra_y = ( rect.y > 2 )? 2 : 1;
  95. #endif // MSW
  96. #if defined(__WXMOTIF__)
  97. extra_x *= 2;
  98. extra_y *= 2;
  99. #endif
  100. rect.SetLeft( wxMax(0, rect.x - extra_x) );
  101. rect.SetTop( wxMax(0, rect.y - extra_y) );
  102. rect.SetRight( rect.GetRight() + 2*extra_x );
  103. rect.SetBottom( rect.GetBottom() + 2*extra_y );
  104. #endif // GTK/!GTK
  105. wxGridCellEditor::SetSize(rect);
  106. }
  107. void wxGridCellPathEditor::BeginEdit(int row, int col, wxGrid* grid)
  108. {
  109. wxASSERT_MSG(m_control,
  110. wxT("The wxGridCellEditor must be Created first!"));
  111. m_startValue = grid->GetTable()->GetValue(row, col);
  112. DoBeginEdit(m_startValue);
  113. }
  114. void wxGridCellPathEditor::DoBeginEdit(const wxString& startValue)
  115. {
  116. Text()->SetValue(startValue);
  117. Text()->SetInsertionPointEnd();
  118. Text()->SetSelection(-1,-1);
  119. Text()->SetFocus();
  120. }
  121. bool wxGridCellPathEditor::EndEdit(int row, int col,
  122. wxGrid* grid)
  123. {
  124. wxASSERT_MSG(m_control,
  125. wxT("The wxGridCellEditor must be Created first!"));
  126. bool changed = false;
  127. wxString value = Text()->GetValue();
  128. if (value != m_startValue)
  129. changed = true;
  130. if (changed)
  131. grid->GetTable()->SetValue(row, col, value);
  132. m_startValue = wxEmptyString;
  133. // No point in setting the text of the hidden control
  134. //Text()->SetValue(m_startValue);
  135. return changed;
  136. }
  137. void wxGridCellPathEditor::Reset()
  138. {
  139. wxASSERT_MSG(m_control,
  140. wxT("The wxGridCellEditor must be Created first!"));
  141. DoReset(m_startValue);
  142. }
  143. void wxGridCellPathEditor::DoReset(const wxString& startValue)
  144. {
  145. Text()->SetValue(startValue);
  146. Text()->SetInsertionPointEnd();
  147. }
  148. bool wxGridCellPathEditor::IsAcceptedKey(wxKeyEvent& event)
  149. {
  150. return wxGridCellEditor::IsAcceptedKey(event);
  151. }
  152. void wxGridCellPathEditor::StartingKey(wxKeyEvent& event)
  153. {
  154. // Since this is now happening in the EVT_CHAR event EmulateKeyPress is no
  155. // longer an appropriate way to get the character into the text control.
  156. // Do it ourselves instead. We know that if we get this far that we have
  157. // a valid character, so not a whole lot of testing needs to be done.
  158. wxTextCtrl* tc = Text();
  159. wxChar ch;
  160. long pos;
  161. #if wxUSE_UNICODE
  162. ch = event.GetUnicodeKey();
  163. if (ch <= 127)
  164. ch = (wxChar)event.GetKeyCode();
  165. #else
  166. ch = (wxChar)event.GetKeyCode();
  167. #endif
  168. switch (ch)
  169. {
  170. case WXK_DELETE:
  171. // delete the character at the cursor
  172. pos = tc->GetInsertionPoint();
  173. if (pos < tc->GetLastPosition())
  174. tc->Remove(pos, pos+1);
  175. break;
  176. case WXK_BACK:
  177. // delete the character before the cursor
  178. pos = tc->GetInsertionPoint();
  179. if (pos > 0)
  180. tc->Remove(pos-1, pos);
  181. break;
  182. default:
  183. tc->WriteText(ch);
  184. break;
  185. }
  186. }
  187. void wxGridCellPathEditor::HandleReturn( wxKeyEvent &event )
  188. {
  189. #if defined(__WXMOTIF__) || defined(__WXGTK__)
  190. // wxMotif needs a little extra help...
  191. size_t pos = (size_t)( Text()->GetInsertionPoint() );
  192. wxString s( Text()->GetValue() );
  193. s = s.Left(pos) + wxT("\n") + s.Mid(pos);
  194. Text()->SetValue(s);
  195. Text()->SetInsertionPoint( pos );
  196. #else
  197. // the other ports can handle a Return key press
  198. //
  199. event.Skip();
  200. #endif
  201. }
  202. void wxGridCellPathEditor::SetParameters(const wxString& params)
  203. {
  204. if ( !params )
  205. {
  206. // reset to default
  207. m_maxChars = 0;
  208. }
  209. else
  210. {
  211. long tmp;
  212. if ( !params.ToLong(&tmp) )
  213. {
  214. wxLogDebug(_T("Invalid wxGridCellPathEditor parameter string '%s' ignored"), params.c_str());
  215. }
  216. else
  217. {
  218. m_maxChars = (size_t)tmp;
  219. }
  220. }
  221. }
  222. // return the value in the text control
  223. wxString wxGridCellPathEditor::GetValue() const
  224. {
  225. return Text()->GetValue();
  226. }
  227. #endif
  228. /////////////////////////////////////////////////////////////////////////////
  229. // wxPropertyItem
  230. // returns true when this property item is a filepath
  231. bool wxPropertyItem::IsFilePath()
  232. {
  233. return m_nItemType == wxPropertyList::FILE;
  234. }
  235. // returns true when this property item is a dir path
  236. bool wxPropertyItem::IsDirPath()
  237. {
  238. return m_nItemType == wxPropertyList::PATH;
  239. }
  240. /////////////////////////////////////////////////////////////////////////////
  241. // wxPropertyList
  242. wxPropertyList::~wxPropertyList()
  243. {
  244. WX_CLEAR_ARRAY(m_PropertyItems);
  245. }
  246. int wxPropertyList::AddItem(const wxString &txt)
  247. {
  248. // TODO: Add the item to the grid!
  249. //int nIndex = AddString(txt);
  250. //return nIndex;
  251. return 0;
  252. }
  253. // order = 0 sorted (not supported yet)
  254. // order = 1 add to top
  255. // order = 2 add to bottom
  256. int wxPropertyList::AddPropItem(wxPropertyItem* pItem, int order)
  257. {
  258. m_PropertyItems.Add(pItem);
  259. if(pItem->GetAdvanced() && ! m_ShowAdvanced)
  260. return 0;
  261. // disable in progress editing
  262. HideControls();
  263. return AddPropertyToGrid(pItem, order);
  264. }
  265. int wxPropertyList::AddPropertyToGrid(wxPropertyItem *pItem, int order)
  266. {
  267. int row = 0;
  268. if(order == 1)
  269. InsertRows(0,1);
  270. else
  271. {
  272. AppendRows(1);
  273. row = GetNumberRows() - 1;
  274. }
  275. // initialise the type of renderer
  276. if(pItem->GetItemType() == wxPropertyList::CHECKBOX)
  277. {
  278. SetCellRenderer(row, 1, new wxGridCellBoolRenderer);
  279. SetCellEditor(row, 1, new wxGridCellBoolEditor);
  280. }
  281. #ifdef __LINUX__
  282. // fix to make sure scrollbars are drawn properly
  283. wxGrid::AdjustScrollbars();
  284. #endif
  285. // the property display is read only
  286. UpdatePropertyItem(pItem, row);
  287. return row;
  288. }
  289. void wxPropertyList::AddProperty(const char* name, const char* value, const char* helpString,
  290. int type, const char* comboItems, bool reverseOrder, bool advanced)
  291. {
  292. wxPropertyItem* pItem = 0;
  293. // add or update the property item
  294. for(size_t i = 0; i < m_PropertyItems.Count(); i++)
  295. {
  296. if(m_PropertyItems[i]->GetPropName().IsSameAs(name))
  297. {
  298. pItem = m_PropertyItems[i];
  299. if(!pItem->GetCurValue().IsSameAs(value))
  300. {
  301. pItem->SetCurValue(value);
  302. pItem->SetHelpString(helpString);
  303. pItem->SetAdvanced(advanced);
  304. // update the property item
  305. int row = FindProperty(pItem);
  306. if(row != -1)
  307. UpdatePropertyItem(pItem, row);
  308. }
  309. return;
  310. }
  311. }
  312. // if it is not found, then create a new one
  313. if(!pItem)
  314. {
  315. pItem = new wxPropertyItem(name, value, helpString, type, comboItems);
  316. pItem->SetAdvanced(advanced);
  317. AddPropItem(pItem, 1);
  318. }
  319. }
  320. void wxPropertyList::UpdateGridView()
  321. {
  322. // make sure all items are shown, remove items that should not be shown
  323. bool keepItem;
  324. int row;
  325. for(size_t i = 0; i < m_PropertyItems.Count(); i++)
  326. {
  327. // to begin with, does this item fit the query?
  328. keepItem = m_strQuery.IsEmpty() || (m_PropertyItems[i]->GetPropName().Find(m_strQuery) != -1);
  329. if(keepItem)
  330. {
  331. // when advanced items are allowed to be shown, keep when ok
  332. if(!m_ShowAdvanced)
  333. keepItem = !m_PropertyItems[i]->GetAdvanced();
  334. }
  335. // find the item, if not present but keep is true, add, if
  336. // present but keep is false, remove
  337. row = -1;
  338. for(size_t j = 0; j < (size_t)GetNumberRows(); j++)
  339. {
  340. if(m_PropertyItems[i]->GetPropName().IsSameAs(GetCellValue(j, 0)))
  341. {
  342. row = j;
  343. break;
  344. }
  345. }
  346. if(row == -1 && keepItem)
  347. AddPropertyToGrid(m_PropertyItems[i], (m_ShowAdvanced ? 2 : 0));
  348. else if(row != -1 && !keepItem)
  349. DeleteRows(row, 1);
  350. }
  351. #ifdef __LINUX__
  352. // fix to make sure scrollbars are drawn properly
  353. wxGrid::AdjustScrollbars();
  354. #endif
  355. }
  356. void wxPropertyList::HideControls()
  357. {
  358. DisableCellEditControl();
  359. }
  360. void wxPropertyList::RemoveProperty(wxPropertyItem *pItem)
  361. {
  362. HideControls();
  363. // look for property in grid, delete it when present
  364. for(size_t j = 0; j < (size_t)GetNumberRows(); j++)
  365. {
  366. if(pItem->GetPropName().IsSameAs(GetCellValue(j, 0), false))
  367. {
  368. DeleteRows(j, 1);
  369. #ifdef __LINUX__
  370. // fix to make sure scrollbars are drawn properly
  371. wxGrid::AdjustScrollbars();
  372. #endif
  373. break;
  374. }
  375. }
  376. // delete the item from the list
  377. m_PropertyItems.Remove(pItem);
  378. delete pItem;
  379. }
  380. wxPropertyItem *wxPropertyList::FindPropertyByName(const wxString &name)
  381. {
  382. for(size_t i = 0; i < m_PropertyItems.Count(); i++)
  383. {
  384. // we have an advanced item, go through table and if not present, show it
  385. if(m_PropertyItems[i]->GetPropName().IsSameAs(name, true))
  386. return m_PropertyItems[i];
  387. }
  388. return 0;
  389. }
  390. /**
  391. void wxPropertyList::OnIgnore()
  392. {
  393. if(m_curSel == -1 || this->GetCount() <= 0)
  394. {
  395. return;
  396. }
  397. wxPropertyItem* pItem = (wxPropertyItem*) GetItemDataPtr(m_curSel);
  398. pItem->m_curValue = "IGNORE";
  399. InvalidateList();
  400. }
  401. */
  402. /**
  403. void wxPropertyList::OnDelete()
  404. {
  405. if(m_curSel == -1 || this->GetCount() <= 0)
  406. {
  407. return;
  408. }
  409. wxPropertyItem* pItem = (wxPropertyItem*) GetItemDataPtr(m_curSel);
  410. m_CMakeSetupDialog->GetCMakeInstance()->GetCacheManager()->RemoveCacheEntry(pItem->m_propName);
  411. m_PropertyItems.erase(pItem);
  412. delete pItem;
  413. this->DeleteString(m_curSel);
  414. this->HideControls();
  415. this->SetTopIndex(0);
  416. InvalidateList();
  417. }
  418. */
  419. /**
  420. void wxPropertyList::OnHelp()
  421. {
  422. if(m_curSel == -1 || this->GetCount() <= 0)
  423. {
  424. return;
  425. }
  426. wxPropertyItem* pItem = (wxPropertyItem*) GetItemDataPtr(m_curSel);
  427. MessageBox(pItem->m_HelpString, pItem->m_propName, MB_OK|MB_ICONINFORMATION);
  428. }
  429. */
  430. void wxPropertyList::RemoveAll()
  431. {
  432. WX_CLEAR_ARRAY(m_PropertyItems);
  433. m_generatedProjects = false;
  434. if(GetNumberRows() > 0)
  435. DeleteRows(0, GetNumberRows());
  436. m_strQuery.Empty();
  437. #ifdef __LINUX__
  438. // fix to make sure scrollbars are drawn properly
  439. wxGrid::AdjustScrollbars();
  440. #endif
  441. }
  442. void wxPropertyList::ShowAdvanced()
  443. {
  444. // set flag in the control
  445. m_ShowAdvanced = true;
  446. UpdateGridView();
  447. }
  448. void wxPropertyList::HideAdvanced()
  449. {
  450. // set flag in the control
  451. m_ShowAdvanced = false;
  452. UpdateGridView();
  453. }
  454. int wxPropertyList::FindProperty(wxPropertyItem *pItem)
  455. {
  456. if(GetNumberRows() > 0 && pItem != 0)
  457. {
  458. // find the property the traditional way
  459. for(size_t j = 0; j < (size_t)GetNumberRows(); j++)
  460. {
  461. if(pItem->GetPropName().IsSameAs(GetCellValue(j, 0)))
  462. return j;
  463. }
  464. }
  465. return -1;
  466. }
  467. wxPropertyItem *wxPropertyList::GetPropertyItemFromRow(int row)
  468. {
  469. if(row < GetNumberRows() && row >= 0)
  470. {
  471. wxString str = GetCellValue(row, 0);
  472. // find the property the traditional way
  473. for(size_t i = 0; i < (size_t)m_PropertyItems.Count(); i++)
  474. {
  475. if(m_PropertyItems[i]->GetPropName().IsSameAs(str))
  476. return m_PropertyItems[i];
  477. }
  478. }
  479. return 0;
  480. }
  481. bool wxPropertyList::UpdatePropertyItem(wxPropertyItem *pItem, int row)
  482. {
  483. wxCHECK(row < GetNumberRows(), false);
  484. // reflect the property's state to match the grid row
  485. SetReadOnly(row, 0);
  486. // TODO: Make this a UpdatePropItem where ADVANCED, and new edit values are reflected
  487. SetCellValue(row,0, pItem->GetPropName());
  488. // boolean renderer
  489. if(pItem->GetItemType() == wxPropertyList::CHECKBOX)
  490. {
  491. // translate ON or TRUE (case insensitive to a checkbox)
  492. if(pItem->GetCurValue().IsSameAs(wxT("ON"), false) ||
  493. pItem->GetCurValue().IsSameAs(wxT("TRUE"), false))
  494. SetCellValue(row, 1, wxT("1"));
  495. else
  496. SetCellValue(row, 1, wxT("0"));
  497. }
  498. else
  499. {
  500. // for normal path values, give bold in cell when
  501. // the NOTFOUND is present, for emphasis
  502. wxString str = pItem->GetPropName() + wxT("-NOTFOUND");
  503. if(pItem->GetCurValue().IsSameAs(str))
  504. {
  505. wxFont fnt = GetCellFont(row, 0);
  506. fnt.SetWeight(wxFONTWEIGHT_BOLD);
  507. SetCellFont(row, 1, fnt);
  508. }
  509. else
  510. SetCellFont(row, 1, GetCellFont(row, 0));
  511. SetCellValue(row,1, pItem->GetCurValue());
  512. }
  513. if(pItem->GetCurValue().IsSameAs("IGNORE"))
  514. {
  515. // ignored cell is completely dimmed
  516. wxColour col(192,192,192);
  517. SetCellTextColour(row, 1, col);
  518. }
  519. else
  520. {
  521. // we colour paths blue, filenames green, all else black
  522. wxColour col;
  523. if(pItem->IsDirPath())
  524. col.Set(0,0,255);
  525. else if(pItem->IsFilePath())
  526. col.Set(0,128,0);
  527. else
  528. col = GetCellTextColour(row, 0);
  529. SetCellTextColour(row, 1, col);
  530. }
  531. if(pItem->GetNewValue())
  532. {
  533. // new cell is red
  534. wxColour col(255,100,100);
  535. SetCellBackgroundColour(row, 0, col);
  536. }
  537. else
  538. {
  539. // old cell is grey
  540. wxColour col(192, 192, 192);
  541. SetCellBackgroundColour(row, 0, col);
  542. }
  543. return true;
  544. }
  545. void wxPropertyList::OnSelectCell( wxGridEvent& event )
  546. {
  547. this->SetFocus();
  548. event.Skip();
  549. }
  550. void wxPropertyList::OnCellChange( wxGridEvent& event )
  551. {
  552. int row = event.GetRow();
  553. wxPropertyItem *pItem = GetPropertyItemFromRow(row);
  554. if(pItem && row != wxNOT_FOUND)
  555. {
  556. // write propery back, and set as new
  557. pItem->SetNewValue(true);
  558. // write back bool
  559. if(pItem->GetItemType() == CHECKBOX)
  560. {
  561. if(GetCellValue(row, 1).IsSameAs("1"))
  562. pItem->SetCurValue("ON");
  563. else
  564. pItem->SetCurValue("OFF");
  565. }
  566. else
  567. pItem->SetCurValue(GetCellValue(row, 1));
  568. UpdatePropertyItem(pItem, row);
  569. event.Skip();
  570. }
  571. }
  572. void wxPropertyList::OnCellPopup( wxGridEvent& event )
  573. {
  574. wxPoint pt;
  575. int row = event.GetRow();
  576. //pt = ::wxGetMousePosition();
  577. //ScreenToClient(pt);
  578. //row = YToRow(pt.y);
  579. if(row != wxNOT_FOUND)
  580. {
  581. wxPropertyItem *pItem = GetPropertyItemFromRow(row);
  582. if(pItem)
  583. {
  584. // select the row first if already in selection, don't
  585. // this will clear the previous selection
  586. if(!IsInSelection(row, 0))
  587. SelectRow(row);
  588. // show popup menu
  589. wxMenu *menu = AppResources::CreatePopupMenu();
  590. // enable when it is browsable, and selected one only
  591. wxMenuItem *item = menu->FindItem(ID_CACHE_BROWSE);
  592. if(item)
  593. item->Enable(IsSelectedItemBrowsable());
  594. PopupMenu(menu);
  595. delete menu;
  596. }
  597. }
  598. }
  599. void wxPropertyList::OnIgnoreCache( wxCommandEvent& event )
  600. {
  601. HideControls();
  602. // ignore all selected items
  603. for(size_t i = 0; i < (size_t)GetNumberRows(); i++)
  604. {
  605. if(IsInSelection(i, 0))
  606. {
  607. wxPropertyItem *pItem = GetPropertyItemFromRow(i);
  608. if(pItem)
  609. {
  610. pItem->SetCurValue("IGNORE");
  611. UpdatePropertyItem(pItem, i);
  612. }
  613. }
  614. }
  615. }
  616. void wxPropertyList::OnDeleteCache( wxCommandEvent& event )
  617. {
  618. HideControls();
  619. // convert selections to prop items
  620. wxArrayPtrVoid items;
  621. for(size_t i = 0; i < (size_t)GetNumberRows(); i++)
  622. {
  623. // if selected, query for removal
  624. if(IsInSelection(i, 0))
  625. {
  626. wxPropertyItem *pItem = GetPropertyItemFromRow(i);
  627. if(pItem)
  628. items.Add((void *)pItem);
  629. }
  630. }
  631. // now delete all prop items in cells
  632. for(size_t i = 0; i < items.Count(); i++)
  633. RemoveProperty((wxPropertyItem *)items[i]);
  634. }
  635. void wxPropertyList::OnBrowseItem( wxCommandEvent& event )
  636. {
  637. BrowseSelectedItem();
  638. }
  639. bool wxPropertyList::IsSelectedItemBrowsable(int row)
  640. {
  641. // when there is only one selection, and our current item
  642. // is browsable, make sure it can be selected.
  643. wxPropertyItem *pItem = 0;
  644. size_t count = 0;
  645. for(size_t i = 0; i < (size_t)GetNumberRows() && (count < 2); i++)
  646. {
  647. if(IsInSelection(i, 0))
  648. {
  649. if(!pItem)
  650. pItem = GetPropertyItemFromRow(i);
  651. count ++;
  652. }
  653. }
  654. // if we found nothing, take row (because the event EVT_GRID_CELL_SELECTED
  655. // deselects the cells first before selecting the new one again
  656. if(row != -1 && !pItem)
  657. {
  658. pItem = GetPropertyItemFromRow(row);
  659. count ++; // needed because of next loop
  660. }
  661. // only one item allowed to select
  662. if(pItem && count == 1)
  663. {
  664. if(pItem)
  665. return pItem->IsDirPath() || pItem->IsFilePath();
  666. }
  667. return false;
  668. }
  669. void wxPropertyList::BrowseSelectedItem()
  670. {
  671. HideControls();
  672. for(size_t i = 0; i < (size_t)GetNumberRows(); i++)
  673. {
  674. if(IsInSelection(i, 0))
  675. {
  676. // browse for file or directory
  677. wxPropertyItem *pItem = GetPropertyItemFromRow(i);
  678. if(pItem)
  679. {
  680. wxString title;
  681. wxString str = pItem->GetPropName() + _("-NOTFOUND");
  682. if(pItem->GetCurValue().IsSameAs(str, true))
  683. str.Empty();
  684. else
  685. str = pItem->GetCurValue();
  686. // browse the directory path
  687. if(pItem->IsDirPath())
  688. {
  689. title = _("Select path for ") + pItem->GetPropName();
  690. str = ::wxDirSelector(title, str, 0, wxDefaultPosition, this);
  691. }
  692. else if(pItem->IsFilePath())
  693. {
  694. title = _("Select file for ") + pItem->GetPropName();
  695. str = ::wxFileSelector(title, str, _(""), _(""), _(MC_DEFAULT_WILDCARD), wxFILE_MUST_EXIST, this);
  696. }
  697. else
  698. str.Empty();
  699. if(!str.IsEmpty())
  700. {
  701. pItem->SetCurValue(str.c_str());
  702. UpdatePropertyItem(pItem, i);
  703. }
  704. }
  705. // only allow one item to browse
  706. break;
  707. }
  708. }
  709. }
  710. void wxPropertyList::OnSizeGrid( wxSizeEvent &event )
  711. {
  712. int width, height;
  713. // make sure the grid's cells are equally adjusted
  714. GetClientSize(&width, &height);
  715. SetDefaultColSize(width / 2, true);
  716. wxGrid::AdjustScrollbars();
  717. }
  718. void wxPropertyList::OnKeyPressed( wxKeyEvent &event )
  719. {
  720. event.Skip();
  721. }