Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

618 lines
18 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "dme_controls/filelistmanager.h"
  9. #include "vgui_controls/FileOpenDialog.h"
  10. #include "vgui_controls/menu.h"
  11. #include "vgui_controls/messagebox.h"
  12. #include "datamodel/idatamodel.h"
  13. #include "datamodel/dmelement.h"
  14. #include "datamodel/dmattribute.h"
  15. #include "datamodel/dmattributevar.h"
  16. #include "vgui/ISurface.h"
  17. #include <vgui/IInput.h>
  18. #include "vgui/mousecode.h"
  19. #include "tier1/strtools.h"
  20. #include "tier1/KeyValues.h"
  21. #include "tier2/tier2.h"
  22. #include "p4lib/ip4.h"
  23. #include "filesystem.h"
  24. #include "dme_controls/INotifyUI.h"
  25. // memdbgon must be the last include file in a .cpp file!!!
  26. #include "tier0/memdbgon.h"
  27. template < int C >
  28. int ListPanelStringSortFunc( vgui::ListPanel *pPanel, const vgui::ListPanelItem &item1, const vgui::ListPanelItem &item2 );
  29. struct ColumnInfo_t
  30. {
  31. char const *columnName;
  32. char const *columnText;
  33. int startingWidth;
  34. int flags;
  35. vgui::SortFunc *pfnSort;
  36. vgui::Label::Alignment alignment;
  37. };
  38. enum ColumnIndex_t
  39. {
  40. CI_FILENAME,
  41. CI_PATH,
  42. CI_LOADED,
  43. CI_NUMELEMENTS,
  44. CI_CHANGED,
  45. CI_INPERFORCE,
  46. CI_OPENFOREDIT,
  47. };
  48. const int baseflags = vgui::ListPanel::COLUMN_UNHIDABLE;
  49. const int fixedflags = vgui::ListPanel::COLUMN_UNHIDABLE | vgui::ListPanel::COLUMN_FIXEDSIZE;
  50. static ColumnInfo_t g_ColInfo[] =
  51. {
  52. { "filename", "#BxFileManager_Filename", 150, baseflags, ListPanelStringSortFunc< CI_FILENAME >, vgui::Label::a_west },
  53. { "path", "#BxFileManager_Path", 240, baseflags, ListPanelStringSortFunc< CI_PATH >, vgui::Label::a_west },
  54. { "loaded", "#BxFileManager_Loaded", 40, fixedflags, ListPanelStringSortFunc< CI_LOADED >, vgui::Label::a_center },
  55. { "numelements", "#BxFileManager_NumElements", 60, fixedflags, ListPanelStringSortFunc< CI_NUMELEMENTS >, vgui::Label::a_east },
  56. { "changed", "#BxFileManager_Changed", 50, fixedflags, ListPanelStringSortFunc< CI_CHANGED >, vgui::Label::a_center },
  57. { "in_perforce", "#BxFileManager_P4Exists", 35, fixedflags, ListPanelStringSortFunc< CI_INPERFORCE >, vgui::Label::a_center },
  58. { "open_for_edit", "#BxFileManager_P4Edit", 40, fixedflags, ListPanelStringSortFunc< CI_OPENFOREDIT >, vgui::Label::a_center },
  59. };
  60. const char *GetKey( ColumnIndex_t ci )
  61. {
  62. return g_ColInfo[ ci ].columnName;
  63. }
  64. template < int C >
  65. int ListPanelStringSortFunc( vgui::ListPanel *pPanel, const vgui::ListPanelItem &item1, const vgui::ListPanelItem &item2 )
  66. {
  67. NOTE_UNUSED( pPanel );
  68. const char *pKey = GetKey( ( ColumnIndex_t )C );
  69. const char *string1 = item1.kv->GetString( pKey );
  70. const char *string2 = item2.kv->GetString( pKey );
  71. return Q_stricmp( string1, string2 );
  72. }
  73. void AddColumn( CFileListManager *pFileManager, ColumnIndex_t ci )
  74. {
  75. pFileManager->AddColumnHeader( ci, g_ColInfo[ ci ].columnName, g_ColInfo[ ci ].columnText, g_ColInfo[ ci ].startingWidth, g_ColInfo[ ci ].flags );
  76. pFileManager->SetSortFunc( ci, g_ColInfo[ ci ].pfnSort );
  77. pFileManager->SetColumnTextAlignment( ci, g_ColInfo[ ci ].alignment );
  78. }
  79. CFileListManager::CFileListManager( vgui::Panel *parent ) : BaseClass( parent, "FileListManager" )
  80. {
  81. SetMultiselectEnabled( true );
  82. SetVisible( true );
  83. m_bRefreshRequired = false;
  84. SetSize( 800, 200 );
  85. SetPos( 100, 100 );
  86. AddColumn( this, CI_FILENAME );
  87. AddColumn( this, CI_PATH );
  88. AddColumn( this, CI_LOADED );
  89. AddColumn( this, CI_NUMELEMENTS );
  90. AddColumn( this, CI_CHANGED );
  91. AddColumn( this, CI_INPERFORCE );
  92. AddColumn( this, CI_OPENFOREDIT );
  93. SetSortColumn( 0 );
  94. Refresh();
  95. SetScheme( vgui::scheme()->LoadSchemeFromFile( "Resource/BoxRocket.res", "BoxRocket" ) );
  96. // LoadControlSettings( "resource/BxFileListManager.res" );
  97. }
  98. int CFileListManager::AddItem( DmFileId_t fileid, const char *pFilename, const char *pPath, bool bLoaded, int nElements, bool bChanged, bool bInPerforce, bool bOpenForEdit )
  99. {
  100. KeyValues *kv = new KeyValues( "", GetKey( CI_FILENAME ), pFilename, GetKey( CI_PATH ), pPath );
  101. kv->SetInt ( GetKey( CI_NUMELEMENTS ), nElements );
  102. kv->SetString( GetKey( CI_LOADED ), bLoaded ? "Y" : "N" );
  103. kv->SetString( GetKey( CI_CHANGED ), bChanged ? "Y" : "N" );
  104. kv->SetString( GetKey( CI_INPERFORCE ), bInPerforce ? "Y" : "N" );
  105. kv->SetString( GetKey( CI_OPENFOREDIT ), bOpenForEdit ? "Y" : "N" );
  106. int itemID = BaseClass::AddItem( kv, fileid, false, false );
  107. kv->deleteThis();
  108. return itemID;
  109. }
  110. void CFileListManager::SetLoaded( DmFileId_t fileid, bool bLoaded )
  111. {
  112. CNotifyScopeGuard notify( "CFileListManager::SetLoaded", NOTIFY_SOURCE_FILE_LIST_MANAGER, NOTIFY_SETDIRTYFLAG );
  113. if ( bLoaded )
  114. {
  115. const char *pFilename = g_pDataModel->GetFileName( fileid );
  116. Assert( pFilename );
  117. if ( !pFilename )
  118. return;
  119. CDisableUndoScopeGuard guard;
  120. CDmElement *pRoot = NULL;
  121. g_pDataModel->RestoreFromFile( pFilename, NULL, NULL, &pRoot, CR_DELETE_NEW );
  122. }
  123. else
  124. {
  125. CDisableUndoScopeGuard guard;
  126. g_pDataModel->UnloadFile( fileid );
  127. }
  128. }
  129. void CFileListManager::OnMousePressed( vgui::MouseCode code )
  130. {
  131. // determine where we were pressed
  132. int x, y, row, column;
  133. vgui::input()->GetCursorPos( x, y );
  134. GetCellAtPos( x, y, row, column );
  135. if ( code == MOUSE_LEFT )
  136. {
  137. bool bIsFakeToggleButton = column == CI_LOADED;
  138. if ( bIsFakeToggleButton && row >= 0 && row < GetItemCount() )
  139. {
  140. int itemID = GetItemIDFromRow( row );
  141. KeyValues *kv = GetItem( itemID );
  142. const char *pStr = kv->GetString( GetKey( ( ColumnIndex_t )column ), "" );
  143. Assert( *pStr == 'Y' || *pStr == 'N' );
  144. bool bSet = *pStr == 'N'; // bSet is the NEW state, not the old one
  145. kv->SetString( GetKey( ( ColumnIndex_t )column ), bSet ? "Y" : "N" );
  146. SetLoaded( ( DmFileId_t )GetItemUserData( itemID ), bSet );
  147. // get the key focus
  148. RequestFocus();
  149. return;
  150. }
  151. }
  152. else if ( code == MOUSE_RIGHT )
  153. {
  154. int itemID = -1;
  155. if ( row >= 0 && row < GetItemCount() )
  156. {
  157. itemID = GetItemIDFromRow( row );
  158. if ( !IsItemSelected( itemID ) )
  159. {
  160. SetSingleSelectedItem( itemID );
  161. }
  162. }
  163. KeyValues *kv = new KeyValues( "OpenContextMenu", "itemID", itemID );
  164. OnOpenContextMenu( kv );
  165. kv->deleteThis();
  166. return;
  167. }
  168. BaseClass::OnMousePressed( code );
  169. }
  170. int AddMenuItemHelper( vgui::Menu *pMenu, const char *pItemName, const char *pKVName, vgui::Panel *pTarget, bool bEnabled )
  171. {
  172. int id = pMenu->AddMenuItem( pItemName, new KeyValues( pKVName ), pTarget );
  173. pMenu->SetItemEnabled( id, bEnabled );
  174. return id;
  175. }
  176. void CFileListManager::OnOpenContextMenu( KeyValues *pParams )
  177. {
  178. if ( m_hContextMenu.Get() )
  179. {
  180. delete m_hContextMenu.Get();
  181. m_hContextMenu = NULL;
  182. }
  183. m_hContextMenu = new vgui::Menu( this, "ContextMenu" );
  184. int itemID = pParams->GetInt( "itemID", -1 );
  185. if ( itemID < 0 )
  186. {
  187. AddMenuItemHelper( m_hContextMenu, "Open File...", "open", this, true ); // Is this how we should load other files???
  188. }
  189. else
  190. {
  191. bool bP4Connected = p4->IsConnectedToServer();
  192. int nSelected = GetSelectedItemsCount();
  193. int nLoaded = 0;
  194. int nChanged = 0;
  195. int nOnDisk = 0;
  196. int nInPerforce = 0;
  197. int nOpenForEdit = 0;
  198. for ( int i = 0; i < nSelected; ++i )
  199. {
  200. int itemId = GetSelectedItem( i );
  201. DmFileId_t fileid = ( DmFileId_t )GetItemUserData( itemId );
  202. if ( g_pDataModel->IsFileLoaded( fileid ) )
  203. {
  204. ++nLoaded;
  205. ++nChanged; // TODO - find out for real
  206. }
  207. const char *pFilename = g_pDataModel->GetFileName( fileid );
  208. if ( g_pFullFileSystem->FileExists( pFilename ) )
  209. {
  210. ++nOnDisk;
  211. }
  212. if ( bP4Connected )
  213. {
  214. if ( p4->IsFileInPerforce( pFilename ) )
  215. {
  216. ++nInPerforce;
  217. if ( p4->GetFileState( pFilename ) != P4FILE_UNOPENED )
  218. {
  219. ++nOpenForEdit;
  220. }
  221. }
  222. }
  223. }
  224. AddMenuItemHelper( m_hContextMenu, "Load", "load", this, nLoaded < nSelected && nOnDisk > 0 );
  225. AddMenuItemHelper( m_hContextMenu, "Unload", "unload", this, nLoaded > 0 );
  226. AddMenuItemHelper( m_hContextMenu, "Save", "save", this, nChanged > 0 && nOnDisk == nSelected );
  227. AddMenuItemHelper( m_hContextMenu, "Save As...", "saveas", this, nLoaded == 1 && nSelected == 1 );
  228. AddMenuItemHelper( m_hContextMenu, "Add To Perforce", "p4add", this, nInPerforce < nSelected && nOnDisk > 0 );
  229. AddMenuItemHelper( m_hContextMenu, "Open For Edit", "p4edit", this, nOpenForEdit < nSelected && nOnDisk > 0 );
  230. }
  231. vgui::Menu::PlaceContextMenu( this, m_hContextMenu.Get() );
  232. }
  233. void CFileListManager::OnLoadFiles( KeyValues *pParams )
  234. {
  235. CNotifyScopeGuard notify( "CFileListManager::OnLoadFiles", NOTIFY_SOURCE_FILE_LIST_MANAGER, NOTIFY_SETDIRTYFLAG );
  236. int nSelected = GetSelectedItemsCount();
  237. for ( int i = 0; i < nSelected; ++i )
  238. {
  239. int itemId = GetSelectedItem( i );
  240. DmFileId_t fileid = ( DmFileId_t )GetItemUserData( itemId );
  241. if ( !g_pDataModel->IsFileLoaded( fileid ) )
  242. {
  243. SetLoaded( fileid, true );
  244. }
  245. }
  246. Refresh();
  247. }
  248. void CFileListManager::OnUnloadFiles( KeyValues *pParams )
  249. {
  250. CNotifyScopeGuard notify( "CFileListManager::OnUnloadFiles", NOTIFY_SOURCE_FILE_LIST_MANAGER, NOTIFY_SETDIRTYFLAG );
  251. int nSelected = GetSelectedItemsCount();
  252. for ( int i = 0; i < nSelected; ++i )
  253. {
  254. int itemId = GetSelectedItem( i );
  255. DmFileId_t fileid = ( DmFileId_t )GetItemUserData( itemId );
  256. if ( g_pDataModel->IsFileLoaded( fileid ) )
  257. {
  258. SetLoaded( fileid, false );
  259. }
  260. }
  261. Refresh();
  262. }
  263. void CFileListManager::OnSaveFiles( KeyValues *pParams )
  264. {
  265. int nSelected = GetSelectedItemsCount();
  266. for ( int i = 0; i < nSelected; ++i )
  267. {
  268. int itemId = GetSelectedItem( i );
  269. DmFileId_t fileid = ( DmFileId_t )GetItemUserData( itemId );
  270. if ( !g_pDataModel->IsFileLoaded( fileid ) )
  271. continue;
  272. const char *pFilename = g_pDataModel->GetFileName( fileid );
  273. Assert( pFilename );
  274. if ( !pFilename )
  275. continue;
  276. CDmElement *pRoot = GetElement< CDmElement >( g_pDataModel->GetFileRoot( fileid ) );
  277. Assert( pRoot );
  278. if ( !pRoot )
  279. continue;
  280. const char *pFileFormat = g_pDataModel->GetFileFormat( fileid );
  281. const char *pEncoding = g_pDataModel->GetDefaultEncoding( pFileFormat );
  282. g_pDataModel->SaveToFile( pFilename, NULL, pEncoding, pFileFormat, pRoot );
  283. }
  284. Refresh();
  285. }
  286. void CFileListManager::OnOpenFile( KeyValues *pParams )
  287. {
  288. KeyValues *pContextKeyValues = new KeyValues( "OnOpen" );
  289. vgui::FileOpenDialog *pFileOpenDialog = new vgui::FileOpenDialog( this, "Save .dmx File As", false, pContextKeyValues );
  290. pFileOpenDialog->AddFilter( "*.dmx", "DmElements File (*.dmx)", true );
  291. pFileOpenDialog->AddActionSignalTarget( this );
  292. pFileOpenDialog->SetDeleteSelfOnClose( true );
  293. pFileOpenDialog->DoModal( false );
  294. }
  295. void CFileListManager::OnSaveFileAs( KeyValues *pParams )
  296. {
  297. int nSelected = GetSelectedItemsCount();
  298. Assert( nSelected == 1 );
  299. if ( nSelected != 1 )
  300. return;
  301. KeyValues *pContextKeyValues = new KeyValues( "OnSaveAs" );
  302. pContextKeyValues->SetInt( "itemId", GetSelectedItem( 0 ) );
  303. DmFileId_t fileid = ( DmFileId_t )GetItemUserData( GetSelectedItem( 0 ) );
  304. const char *pFileFormat = g_pDataModel->GetFileFormat( fileid );
  305. vgui::FileOpenDialog *pFileOpenDialog = new vgui::FileOpenDialog( this, "Save .dmx File As", false, pContextKeyValues );
  306. // if this control is moved to vgui_controls, change the default format to "dmx", the generic dmx format
  307. pFileOpenDialog->AddFilter( "*.dmx", "Generic MovieObjects File (*.dmx)", false, "movieobjects" );
  308. if ( V_strcmp( pFileFormat, "movieobjects" ) != 0 )
  309. {
  310. char description[ 256 ];
  311. V_snprintf( description, sizeof( description ), "%s (*.dmx)", g_pDataModel->GetFormatDescription( pFileFormat ) );
  312. pFileOpenDialog->AddFilter( "*.dmx", description, true, pFileFormat );
  313. }
  314. pFileOpenDialog->AddActionSignalTarget( this );
  315. pFileOpenDialog->SetDeleteSelfOnClose( true );
  316. pFileOpenDialog->DoModal( false );
  317. }
  318. void CFileListManager::OnFileSelected( KeyValues *pParams )
  319. {
  320. const char *pFullPath = pParams->GetString( "fullpath" );
  321. if ( !pFullPath || !pFullPath[ 0 ] )
  322. return;
  323. KeyValues *pSaveAsKey = pParams->FindKey( "OnSaveAs" );
  324. if ( pSaveAsKey )
  325. {
  326. int itemId = pSaveAsKey->GetInt( "itemId", -1 );
  327. Assert( itemId != -1 );
  328. if ( itemId == -1 )
  329. return;
  330. DmFileId_t fileid = ( DmFileId_t )GetItemUserData( itemId );
  331. Assert( fileid != DMFILEID_INVALID );
  332. if ( fileid == DMFILEID_INVALID )
  333. return;
  334. CDmElement *pRoot = GetElement< CDmElement >( g_pDataModel->GetFileRoot( fileid ) );
  335. Assert( pRoot );
  336. if ( !pRoot )
  337. return;
  338. const char *pFormat = pParams->GetString( "filterinfo" );
  339. Assert( pFormat );
  340. if ( !pFormat )
  341. return;
  342. g_pDataModel->SetFileName( fileid, pFullPath );
  343. g_pDataModel->SaveToFile( pFullPath, NULL, g_pDataModel->GetDefaultEncoding( pFormat ), pFormat, pRoot );
  344. Refresh();
  345. return;
  346. }
  347. KeyValues *pOpenKey = pParams->FindKey( "OnOpen" );
  348. if ( pOpenKey )
  349. {
  350. CDmElement *pRoot = NULL;
  351. g_pDataModel->RestoreFromFile( pFullPath, NULL, NULL, &pRoot );
  352. Refresh();
  353. return;
  354. }
  355. }
  356. void CFileListManager::OnAddToPerforce( KeyValues *pParams )
  357. {
  358. int nFileCount = 0;
  359. int nSelected = GetSelectedItemsCount();
  360. const char **ppFileNames = ( const char** )_alloca( nSelected * sizeof( char* ) );
  361. for ( int i = 0; i < nSelected; ++i )
  362. {
  363. int itemId = GetSelectedItem( i );
  364. DmFileId_t fileid = ( DmFileId_t )GetItemUserData( itemId );
  365. const char *pFilename = g_pDataModel->GetFileName( fileid );
  366. Assert( pFilename );
  367. if ( !pFilename )
  368. continue;
  369. ++nFileCount;
  370. ppFileNames[ i ] = pFilename;
  371. }
  372. bool bSuccess = p4->OpenFilesForAdd( nFileCount, ppFileNames );
  373. if ( !bSuccess )
  374. {
  375. vgui::MessageBox *pError = new vgui::MessageBox( "Perforce Error!", p4->GetLastError(), GetParent() );
  376. pError->SetSmallCaption( true );
  377. pError->DoModal();
  378. }
  379. Refresh();
  380. }
  381. void CFileListManager::OnOpenForEdit( KeyValues *pParams )
  382. {
  383. int nFileCount = 0;
  384. int nSelected = GetSelectedItemsCount();
  385. const char **ppFileNames = ( const char** )_alloca( nSelected * sizeof( char* ) );
  386. for ( int i = 0; i < nSelected; ++i )
  387. {
  388. int itemId = GetSelectedItem( i );
  389. DmFileId_t fileid = ( DmFileId_t )GetItemUserData( itemId );
  390. const char *pFilename = g_pDataModel->GetFileName( fileid );
  391. Assert( pFilename );
  392. if ( !pFilename )
  393. continue;
  394. ++nFileCount;
  395. ppFileNames[ i ] = pFilename;
  396. }
  397. bool bSuccess = p4->OpenFilesForEdit( nFileCount, ppFileNames );
  398. if ( !bSuccess )
  399. {
  400. vgui::MessageBox *pError = new vgui::MessageBox( "Perforce Error!", p4->GetLastError(), GetParent() );
  401. pError->SetSmallCaption( true );
  402. pError->DoModal();
  403. }
  404. Refresh();
  405. }
  406. void CFileListManager::OnDataChanged( KeyValues *pParams )
  407. {
  408. int nNotifyFlags = pParams->GetInt( "notifyFlags" );
  409. if ( ( nNotifyFlags & NOTIFY_CHANGE_TOPOLOGICAL ) == 0 )
  410. return;
  411. int nNotifySource = pParams->GetInt( "source" );
  412. if ( nNotifySource == NOTIFY_SOURCE_FILE_LIST_MANAGER )
  413. return;
  414. if ( !IsVisible() )
  415. {
  416. m_bRefreshRequired = true;
  417. return;
  418. }
  419. int nCount = GetItemCount();
  420. int nFiles = g_pDataModel->NumFileIds();
  421. bool bPerformFullRefresh = ( nCount != nFiles );
  422. if ( !bPerformFullRefresh )
  423. {
  424. const char *pNameKey = GetKey( CI_FILENAME );
  425. for ( int i = 0; i < nCount; ++i )
  426. {
  427. DmFileId_t fileid = g_pDataModel->GetFileId( i );
  428. const char *pFileName = g_pDataModel->GetFileName( fileid );
  429. if ( !pFileName || !*pFileName )
  430. {
  431. bPerformFullRefresh = true;
  432. break;
  433. }
  434. pFileName = V_UnqualifiedFileName( pFileName );
  435. KeyValues *pKeyValues = GetItem( i );
  436. bPerformFullRefresh = ( fileid != (DmFileId_t)GetItemUserData(i) ) || Q_stricmp( pFileName, pKeyValues->GetString( pNameKey ) );
  437. if ( bPerformFullRefresh )
  438. break;
  439. pKeyValues->SetInt ( GetKey( CI_NUMELEMENTS ), g_pDataModel->NumElementsInFile( fileid ) );
  440. pKeyValues->SetString( GetKey( CI_LOADED ), g_pDataModel->IsFileLoaded( fileid ) ? "Y" : "N" );
  441. pKeyValues->SetString( GetKey( CI_CHANGED ), false ? "Y" : "N" );
  442. ApplyItemChanges( i );
  443. }
  444. }
  445. if ( bPerformFullRefresh )
  446. {
  447. Refresh();
  448. return;
  449. }
  450. }
  451. void CFileListManager::Refresh()
  452. {
  453. m_bRefreshRequired = false;
  454. RemoveAll();
  455. const bool bP4Connected = p4 ? p4->IsConnectedToServer() : false;
  456. int nFiles = g_pDataModel->NumFileIds();
  457. for ( int i = 0; i < nFiles; ++i )
  458. {
  459. DmFileId_t fileid = g_pDataModel->GetFileId( i );
  460. const char *pFileName = g_pDataModel->GetFileName( fileid );
  461. if ( !pFileName || !*pFileName )
  462. continue; // skip DMFILEID_INVALID and the default fileid ""
  463. bool bLoaded = g_pDataModel->IsFileLoaded( fileid );
  464. int nElements = g_pDataModel->NumElementsInFile( fileid );
  465. bool bChanged = false; // TODO - find out for real
  466. bool bInPerforce = bP4Connected && p4->IsFileInPerforce( pFileName );
  467. bool bOpenForEdit = bInPerforce && p4->GetFileState( pFileName ) != P4FILE_UNOPENED;
  468. char path[ 256 ];
  469. V_ExtractFilePath( pFileName, path, sizeof( path ) );
  470. AddItem( fileid, V_UnqualifiedFileName( pFileName ), path, bLoaded, nElements, bChanged, bInPerforce, bOpenForEdit );
  471. }
  472. }
  473. void CFileListManager::OnThink( )
  474. {
  475. BaseClass::OnThink();
  476. if ( m_bRefreshRequired && IsVisible() )
  477. {
  478. Refresh();
  479. }
  480. }
  481. void CFileListManager::OnCommand( const char *cmd )
  482. {
  483. // if ( !Q_stricmp( cmd, "foo" ) ) ...
  484. BaseClass::OnCommand( cmd );
  485. }
  486. //-----------------------------------------------------------------------------
  487. //
  488. // CFileManagerFrame methods
  489. //
  490. //-----------------------------------------------------------------------------
  491. CFileManagerFrame::CFileManagerFrame( vgui::Panel *parent ) : BaseClass( parent, "FileManagerFrame" )
  492. {
  493. SetTitle( "#BxFileManagerFrame", true );
  494. SetSizeable( true );
  495. SetCloseButtonVisible( false );
  496. SetMinimumSize( 200, 200 );
  497. SetVisible( true );
  498. SetSize( 800, 200 );
  499. SetPos( 100, 100 );
  500. m_pFileListManager = new CFileListManager( this );
  501. Refresh();
  502. SetScheme( vgui::scheme()->LoadSchemeFromFile( "Resource/BoxRocket.res", "BoxRocket" ) );
  503. }
  504. void CFileManagerFrame::Refresh()
  505. {
  506. m_pFileListManager->Refresh();
  507. }
  508. void CFileManagerFrame::OnCommand( const char *cmd )
  509. {
  510. BaseClass::OnCommand( cmd );
  511. m_pFileListManager->OnCommand( cmd );
  512. }
  513. void CFileManagerFrame::PerformLayout()
  514. {
  515. BaseClass::PerformLayout();
  516. int iWidth, iHeight;
  517. GetSize( iWidth, iHeight );
  518. m_pFileListManager->SetPos( 0, GetCaptionHeight() );
  519. m_pFileListManager->SetSize( iWidth, iHeight - GetCaptionHeight() );
  520. }