Counter Strike : Global Offensive Source Code
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.

760 lines
20 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. // TransformDlg.cpp : implementation file
  9. //
  10. #include "stdafx.h"
  11. #include "hammer.h"
  12. #include "versioncontroldialog.h"
  13. #include "mapdoc.h"
  14. #include "p4lib/ip4.h"
  15. #include "options.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include <tier0/memdbgon.h>
  18. // CMapDocCheckin dialog
  19. IMPLEMENT_DYNAMIC(CMapDocCheckin, CDialog)
  20. //-----------------------------------------------------------------------------
  21. // Purpose:
  22. // Input :
  23. // Output :
  24. //-----------------------------------------------------------------------------
  25. CMapDocCheckin::CMapDocCheckin(CWnd* pParent /*=NULL*/)
  26. : CDialog(CMapDocCheckin::IDD, pParent)
  27. {
  28. }
  29. //-----------------------------------------------------------------------------
  30. // Purpose:
  31. // Input :
  32. // Output :
  33. //-----------------------------------------------------------------------------
  34. CMapDocCheckin::~CMapDocCheckin()
  35. {
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Purpose:
  39. // Input :
  40. // Output :
  41. //-----------------------------------------------------------------------------
  42. void CMapDocCheckin::DoDataExchange(CDataExchange* pDX)
  43. {
  44. CDialog::DoDataExchange(pDX);
  45. DDX_Control(pDX, IDC_CHECKIN_LIST, m_CheckinListCtrl);
  46. DDX_Control(pDX, IDC_CHECKIN_DESCRIPTION, m_DescriptionCtrl);
  47. DDX_Control(pDX, IDC_CHECKIN_STATUS, m_CheckInStatusControl);
  48. DDX_Control(pDX, ID_SUBMIT, m_SubmitButtonControl);
  49. }
  50. BEGIN_MESSAGE_MAP(CMapDocCheckin, CDialog)
  51. ON_BN_CLICKED(ID_SUBMIT, &CMapDocCheckin::OnBnClickedSubmit)
  52. ON_NOTIFY(NM_RCLICK, IDC_CHECKIN_LIST, &CMapDocCheckin::OnNMRclickCheckinList)
  53. ON_WM_SHOWWINDOW()
  54. END_MESSAGE_MAP()
  55. //-----------------------------------------------------------------------------
  56. // Purpose:
  57. // Input :
  58. // Output :
  59. //-----------------------------------------------------------------------------
  60. void CMapDocCheckin::AddFileToList( CMapDoc *pMapDoc, P4File_t *FileInfo )
  61. {
  62. int nIndex = m_CheckinListCtrl.InsertItem( m_CheckinListCtrl.GetItemCount(), "" );
  63. // nCount++;
  64. m_CheckinListCtrl.SetItemData( nIndex, ( DWORD_PTR )pMapDoc );
  65. switch( FileInfo->m_eOpenState )
  66. {
  67. case P4FILE_OPENED_FOR_ADD:
  68. m_CheckinListCtrl.SetItemText( nIndex, 1, "Add" );
  69. break;
  70. case P4FILE_OPENED_FOR_EDIT:
  71. m_CheckinListCtrl.SetItemText( nIndex, 1, "Edit" );
  72. break;
  73. }
  74. m_CheckinListCtrl.SetItemText( nIndex, 2, p4->String( FileInfo->m_sName ) );
  75. m_CheckinListCtrl.SetItemText( nIndex, 3, p4->String( FileInfo->m_sPath ) );
  76. m_FileList.AddToTail( FileInfo->m_sLocalFile );
  77. if ( pMapDoc != NULL && pMapDoc->IsDefaultCheckIn() )
  78. {
  79. ListView_SetItemState( m_CheckinListCtrl.m_hWnd, nIndex, INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ), LVIS_STATEIMAGEMASK );
  80. pMapDoc->ClearDefaultCheckIn();
  81. }
  82. }
  83. //-----------------------------------------------------------------------------
  84. // Purpose:
  85. // Input :
  86. // Output :
  87. //-----------------------------------------------------------------------------
  88. BOOL CMapDocCheckin::OnInitDialog()
  89. {
  90. CDialog::OnInitDialog();
  91. m_CheckinListCtrl.SetExtendedStyle( m_CheckinListCtrl.GetExtendedStyle() | LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT );
  92. m_CheckinListCtrl.InsertColumn( 0, "", LVCFMT_LEFT, 30, -1 );
  93. m_CheckinListCtrl.InsertColumn( 1, "Status", LVCFMT_LEFT, 50, -1 );
  94. m_CheckinListCtrl.InsertColumn( 2, "Name", LVCFMT_LEFT, 180, -1 );
  95. m_CheckinListCtrl.InsertColumn( 3, "Folder", LVCFMT_LEFT, 360, -1 );
  96. if ( p4 == NULL )
  97. {
  98. return TRUE;
  99. }
  100. P4File_t FileInfo;
  101. CUtlVector< P4File_t > FileList;
  102. p4->GetOpenedFileList( FileList, true );
  103. POSITION pos = APP()->pMapDocTemplate->GetFirstDocPosition();
  104. while( pos != NULL )
  105. {
  106. CDocument *pDoc = APP()->pMapDocTemplate->GetNextDoc( pos );
  107. CMapDoc *pMapDoc = dynamic_cast< CMapDoc * >( pDoc );
  108. if ( pMapDoc )
  109. {
  110. if ( pMapDoc->IsCheckedOut() )
  111. {
  112. if ( p4->GetFileInfo( pMapDoc->GetPathName(), &FileInfo ) == true )
  113. {
  114. for( int i = 0; i < FileList.Count(); i++ )
  115. {
  116. if ( FileList[ i ].m_sClientFile == FileInfo.m_sClientFile )
  117. {
  118. FileList.Remove( i );
  119. break;
  120. }
  121. }
  122. AddFileToList( pMapDoc, &FileInfo );
  123. }
  124. }
  125. }
  126. }
  127. for( int i = 0; i < FileList.Count(); i++ )
  128. {
  129. AddFileToList( NULL, &FileList[ i ] );
  130. }
  131. return TRUE;
  132. }
  133. //-----------------------------------------------------------------------------
  134. // Purpose:
  135. // Input :
  136. // Output :
  137. //-----------------------------------------------------------------------------
  138. void CMapDocCheckin::OnOK()
  139. {
  140. }
  141. //-----------------------------------------------------------------------------
  142. // Purpose:
  143. // Input :
  144. // Output :
  145. //-----------------------------------------------------------------------------
  146. void CMapDocCheckin::OnBnClickedSubmit()
  147. {
  148. int nFileCount = 0;
  149. char temp[ 2048 ];
  150. for( int i = 0; i < m_CheckinListCtrl.GetItemCount(); i++ )
  151. {
  152. if ( m_CheckinListCtrl.GetItemState( i, LVIS_STATEIMAGEMASK ) == INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ) )
  153. {
  154. nFileCount++;
  155. }
  156. }
  157. if ( nFileCount > 0 )
  158. {
  159. CString Description;
  160. m_DescriptionCtrl.GetWindowText( Description );
  161. if ( Description.GetLength() < 2 )
  162. {
  163. m_CheckInStatusControl.SetWindowText( "Checkin FAILED!" );
  164. AfxMessageBox( "Please put in something descriptive for the description. I took the time to type this dialog, the least you could do is type something!", MB_ICONHAND | MB_OK );
  165. return;
  166. }
  167. if ( Description.GetLength() >= P4_MAX_INPUT_BUFFER_SIZE )
  168. {
  169. m_CheckInStatusControl.SetWindowText( "Checkin FAILED!" );
  170. sprintf( temp, "Your description is too long. Please shorten it down by %d characters.", Description.GetLength() - P4_MAX_INPUT_BUFFER_SIZE + 1 );
  171. AfxMessageBox( temp, MB_ICONHAND | MB_OK );
  172. return;
  173. }
  174. m_SubmitButtonControl.EnableWindow( FALSE );
  175. sprintf( temp, "Checking in %d file(s). Please wait...", nFileCount );
  176. m_CheckInStatusControl.SetWindowText( temp );
  177. const char **ppFileNames = ( const char** )stackalloc( nFileCount * sizeof( char * ) );
  178. nFileCount = 0;
  179. for( int i = 0; i < m_CheckinListCtrl.GetItemCount(); i++ )
  180. {
  181. if ( m_CheckinListCtrl.GetItemState( i, LVIS_STATEIMAGEMASK ) == INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ) )
  182. {
  183. CMapDoc *pMapDoc = ( CMapDoc * )m_CheckinListCtrl.GetItemData( i );
  184. const char *pszFileName = p4->String( m_FileList[ i ] );
  185. if ( pMapDoc != NULL )
  186. {
  187. ppFileNames[ nFileCount ] = pMapDoc->GetPathName();
  188. pMapDoc->OnSaveDocument( pMapDoc->GetPathName() );
  189. }
  190. else
  191. {
  192. ppFileNames[ nFileCount ] = pszFileName;
  193. }
  194. nFileCount++;
  195. }
  196. }
  197. // we need to replace \r\n with \t\n to make multi-line p4 changelist descriptions happy
  198. Description.Replace( '\n', '\t' );
  199. Description.Replace( '\r', '\n' );
  200. if ( p4->SubmitFiles( nFileCount, ppFileNames, Description ) == false )
  201. {
  202. m_CheckInStatusControl.SetWindowText( "Checkin FAILED!" );
  203. m_SubmitButtonControl.EnableWindow( TRUE );
  204. sprintf( temp, "Could not check in map(s): %s", p4->GetLastError() );
  205. AfxMessageBox( temp, MB_ICONHAND | MB_OK );
  206. return;
  207. }
  208. for( int i = 0; i < m_CheckinListCtrl.GetItemCount(); i++ )
  209. {
  210. if ( m_CheckinListCtrl.GetItemState( i, LVIS_STATEIMAGEMASK ) == INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ) )
  211. {
  212. CMapDoc *pMapDoc = ( CMapDoc * )m_CheckinListCtrl.GetItemData( i );
  213. if ( pMapDoc != NULL )
  214. {
  215. pMapDoc->CheckFileStatus();
  216. }
  217. }
  218. }
  219. m_SubmitButtonControl.EnableWindow( TRUE );
  220. m_CheckInStatusControl.SetWindowText( "" );
  221. }
  222. EndDialog( IDOK );
  223. }
  224. void CMapDocCheckin::OnNMRclickCheckinList(NMHDR *pNMHDR, LRESULT *pResult)
  225. {
  226. *pResult = 0;
  227. for( int i = 0; i < m_CheckinListCtrl.GetItemCount(); i++ )
  228. {
  229. if ( m_bSelectAll == true )
  230. {
  231. m_CheckinListCtrl.SetItemState( i, ( unsigned int )INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ), LVIS_STATEIMAGEMASK );
  232. }
  233. else
  234. {
  235. m_CheckinListCtrl.SetItemState( i, ( unsigned int )INDEXTOSTATEIMAGEMASK( LVIS_FOCUSED ), LVIS_STATEIMAGEMASK );
  236. }
  237. }
  238. m_bSelectAll = !m_bSelectAll;
  239. }
  240. void CMapDocCheckin::OnShowWindow(BOOL bShow, UINT nStatus)
  241. {
  242. CDialog::OnShowWindow(bShow, nStatus);
  243. m_bSelectAll = true;
  244. }
  245. // CMapDocStatus dialog
  246. IMPLEMENT_DYNAMIC(CMapDocStatus, CDialog)
  247. //-----------------------------------------------------------------------------
  248. // Purpose:
  249. // Input :
  250. // Output :
  251. //-----------------------------------------------------------------------------
  252. CMapDocStatus::CMapDocStatus(CWnd* pParent /*=NULL*/)
  253. : CDialog(CMapDocStatus::IDD, pParent)
  254. {
  255. }
  256. //-----------------------------------------------------------------------------
  257. // Purpose:
  258. // Input :
  259. // Output :
  260. //-----------------------------------------------------------------------------
  261. CMapDocStatus::~CMapDocStatus()
  262. {
  263. }
  264. //-----------------------------------------------------------------------------
  265. // Purpose:
  266. // Input :
  267. // Output :
  268. //-----------------------------------------------------------------------------
  269. void CMapDocStatus::DoDataExchange(CDataExchange* pDX)
  270. {
  271. CDialog::DoDataExchange(pDX);
  272. DDX_Control(pDX, IDC_FILE_LIST, m_FileListCtrl);
  273. DDX_Control(pDX, IDC_STATUS_TEXT, m_StatusTextControl);
  274. DDX_Control(pDX, IDSYNC, m_SyncControl);
  275. DDX_Control(pDX, IDADD, m_AddControl);
  276. DDX_Control(pDX, IDCHECKOUT, m_CheckOutControl);
  277. DDX_Control(pDX, IDCANCEL, m_DoneControl);
  278. DDX_Control(pDX, IDREVERT, m_RevertControl);
  279. }
  280. BEGIN_MESSAGE_MAP(CMapDocStatus, CDialog)
  281. ON_BN_CLICKED(IDCHECKOUT, &CMapDocStatus::OnBnClickedCheckout)
  282. ON_BN_CLICKED(IDADD, &CMapDocStatus::OnBnClickedAdd)
  283. ON_BN_CLICKED(IDSYNC, &CMapDocStatus::OnBnClickedSync)
  284. ON_BN_CLICKED(IDREVERT, &CMapDocStatus::OnBnClickedRevert)
  285. ON_NOTIFY(NM_RCLICK, IDC_FILE_LIST, &CMapDocStatus::OnNMRclickFileList)
  286. ON_WM_SHOWWINDOW()
  287. END_MESSAGE_MAP()
  288. //-----------------------------------------------------------------------------
  289. // Purpose:
  290. // Input :
  291. // Output :
  292. //-----------------------------------------------------------------------------
  293. BOOL CMapDocStatus::OnInitDialog()
  294. {
  295. CDialog::OnInitDialog();
  296. m_FileListCtrl.SetExtendedStyle( m_FileListCtrl.GetExtendedStyle() | LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT );
  297. m_FileListCtrl.InsertColumn( 0, "", LVCFMT_LEFT, 30, -1 );
  298. m_FileListCtrl.InsertColumn( 1, "Status", LVCFMT_LEFT, 80, -1 );
  299. m_FileListCtrl.InsertColumn( 2, "Revision", LVCFMT_LEFT, 70, -1 );
  300. m_FileListCtrl.InsertColumn( 3, "Name", LVCFMT_LEFT, 150, -1 );
  301. m_FileListCtrl.InsertColumn( 4, "Folder", LVCFMT_LEFT, 300, -1 );
  302. SetControls( false, "" );
  303. UpdateMapList();
  304. if ( Options.general.bEnablePerforceIntegration == FALSE )
  305. {
  306. GetDlgItem( IDCHECKOUT )->EnableWindow( false );
  307. GetDlgItem( IDADD )->EnableWindow( false );
  308. }
  309. return TRUE;
  310. }
  311. //-----------------------------------------------------------------------------
  312. // Purpose:
  313. // Input :
  314. // Output :
  315. //-----------------------------------------------------------------------------
  316. void CMapDocStatus::UpdateMapList( bool RedoList )
  317. {
  318. P4File_t FileInfo;
  319. m_FileListCtrl.DeleteAllItems();
  320. int nCount = 0;
  321. POSITION pos = APP()->pMapDocTemplate->GetFirstDocPosition();
  322. while( pos != NULL )
  323. {
  324. CDocument *pDoc = APP()->pMapDocTemplate->GetNextDoc( pos );
  325. CMapDoc *pMapDoc = dynamic_cast< CMapDoc * >( pDoc );
  326. pMapDoc->CheckFileStatus();
  327. int nIndex = m_FileListCtrl.InsertItem( nCount, "" );
  328. nCount++;
  329. m_FileListCtrl.SetItemData( nIndex, ( DWORD_PTR )pMapDoc );
  330. if ( p4 && Options.general.bEnablePerforceIntegration == TRUE && p4->GetFileInfo( pMapDoc->GetPathName(), &FileInfo ) == true )
  331. {
  332. switch( FileInfo.m_eOpenState )
  333. {
  334. case P4FILE_UNOPENED:
  335. if ( pMapDoc->IsReadOnly() )
  336. {
  337. m_FileListCtrl.SetItemText( nIndex, 1, "Read Only" );
  338. }
  339. else
  340. {
  341. m_FileListCtrl.SetItemText( nIndex, 1, "Writeable" );
  342. }
  343. break;
  344. case P4FILE_OPENED_FOR_ADD:
  345. m_FileListCtrl.SetItemText( nIndex, 1, "Add" );
  346. break;
  347. case P4FILE_OPENED_FOR_EDIT:
  348. m_FileListCtrl.SetItemText( nIndex, 1, "Edit" );
  349. break;
  350. }
  351. if ( FileInfo.m_iHaveRevision == FileInfo.m_iHeadRevision )
  352. {
  353. char temp[ 128 ];
  354. sprintf( temp, "%d", FileInfo.m_iHaveRevision );
  355. m_FileListCtrl.SetItemText( nIndex, 2, temp );
  356. }
  357. else
  358. {
  359. char temp[ 128 ];
  360. sprintf( temp, "%d / %d", FileInfo.m_iHaveRevision, FileInfo.m_iHeadRevision );
  361. m_FileListCtrl.SetItemText( nIndex, 2, temp );
  362. }
  363. m_FileListCtrl.SetItemText( nIndex, 3, p4->String( FileInfo.m_sName ) );
  364. m_FileListCtrl.SetItemText( nIndex, 4, p4->String( FileInfo.m_sPath ) );
  365. }
  366. else
  367. {
  368. if ( pMapDoc->IsReadOnly() )
  369. {
  370. m_FileListCtrl.SetItemText( nIndex, 1, "Read Only" );
  371. }
  372. else
  373. {
  374. m_FileListCtrl.SetItemText( nIndex, 1, "Writeable" );
  375. }
  376. CString strMapFilename = pMapDoc->GetPathName();
  377. if ( strMapFilename.IsEmpty() )
  378. {
  379. m_FileListCtrl.SetItemText( nIndex, 3, "not saved" );
  380. m_FileListCtrl.SetItemText( nIndex, 4, "" );
  381. }
  382. // the map already has a filename
  383. else
  384. {
  385. int nFilenameBeginOffset = strMapFilename.ReverseFind( '\\' ) + 1;
  386. int nFilenameEndOffset = strMapFilename.Find( '.' );
  387. m_FileListCtrl.SetItemText( nIndex, 3, strMapFilename.Mid( nFilenameBeginOffset, nFilenameEndOffset - nFilenameBeginOffset ) );
  388. m_FileListCtrl.SetItemText( nIndex, 4, strMapFilename.Mid( 0, nFilenameBeginOffset - 1 ) );
  389. }
  390. }
  391. }
  392. }
  393. //-----------------------------------------------------------------------------
  394. // Purpose:
  395. // Input :
  396. // Output :
  397. //-----------------------------------------------------------------------------
  398. void CMapDocStatus::OnBnClickedCheckout()
  399. {
  400. if ( !p4 || Options.general.bEnablePerforceIntegration == FALSE )
  401. {
  402. return;
  403. }
  404. char temp[ 2048 ];
  405. int nFileCount = 0;
  406. for( int i = 0; i < m_FileListCtrl.GetItemCount(); i++ )
  407. {
  408. if ( m_FileListCtrl.GetItemState( i, LVIS_STATEIMAGEMASK ) == INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ) )
  409. {
  410. nFileCount++;
  411. }
  412. }
  413. if ( nFileCount > 0 )
  414. {
  415. sprintf( temp, "Checking out %d file(s). Please wait...", nFileCount );
  416. SetControls( true, temp );
  417. const char **ppFileNames = ( const char** )stackalloc( nFileCount * sizeof( char * ) );
  418. nFileCount = 0;
  419. for( int i = 0; i < m_FileListCtrl.GetItemCount(); i++ )
  420. {
  421. if ( m_FileListCtrl.GetItemState( i, LVIS_STATEIMAGEMASK ) == INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ) )
  422. {
  423. CMapDoc *pMapDoc = ( CMapDoc * )m_FileListCtrl.GetItemData( i );
  424. ppFileNames[ nFileCount ] = pMapDoc->GetPathName();
  425. nFileCount++;
  426. }
  427. }
  428. if ( p4->OpenFilesForEdit( nFileCount, ppFileNames ) == false )
  429. {
  430. SetControls( false, "Checkout FAILED." );
  431. sprintf( temp, "Could not check out map(s): %s", p4->GetLastError() );
  432. AfxMessageBox( temp, MB_ICONHAND | MB_OK );
  433. return;
  434. }
  435. UpdateMapList();
  436. sprintf( temp, "Checked out %d file(s).", nFileCount );
  437. SetControls( false, temp );
  438. }
  439. }
  440. //-----------------------------------------------------------------------------
  441. // Purpose:
  442. // Input :
  443. // Output :
  444. //-----------------------------------------------------------------------------
  445. void CMapDocStatus::OnBnClickedAdd()
  446. {
  447. if ( !p4 || Options.general.bEnablePerforceIntegration == FALSE )
  448. {
  449. return;
  450. }
  451. int nFileCount = 0;
  452. char temp[ 2048 ];
  453. for( int i = 0; i < m_FileListCtrl.GetItemCount(); i++ )
  454. {
  455. if ( m_FileListCtrl.GetItemState( i, LVIS_STATEIMAGEMASK ) == INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ) )
  456. {
  457. nFileCount++;
  458. }
  459. }
  460. if ( nFileCount > 0 )
  461. {
  462. sprintf( temp, "Adding %d file(s). Please wait...", nFileCount );
  463. SetControls( true, temp );
  464. const char **ppFileNames = ( const char** )stackalloc( nFileCount * sizeof( char * ) );
  465. nFileCount = 0;
  466. for( int i = 0; i < m_FileListCtrl.GetItemCount(); i++ )
  467. {
  468. if ( m_FileListCtrl.GetItemState( i, LVIS_STATEIMAGEMASK ) == INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ) )
  469. {
  470. CMapDoc *pMapDoc = ( CMapDoc * )m_FileListCtrl.GetItemData( i );
  471. ppFileNames[ nFileCount ] = pMapDoc->GetPathName();
  472. nFileCount++;
  473. }
  474. }
  475. if ( p4->OpenFilesForAdd( nFileCount, ppFileNames ) == false )
  476. {
  477. SetControls( false, "Adding FAILED." );
  478. sprintf( temp, "Could not add map(s): %s", p4->GetLastError() );
  479. AfxMessageBox( temp, MB_ICONHAND | MB_OK );
  480. return;
  481. }
  482. UpdateMapList();
  483. sprintf( temp, "Added %d file(s).", nFileCount );
  484. SetControls( false, temp );
  485. }
  486. }
  487. void CMapDocStatus::OnBnClickedSync()
  488. {
  489. if ( !p4 || Options.general.bEnablePerforceIntegration == FALSE )
  490. {
  491. return;
  492. }
  493. int nFileCount = 0;
  494. char temp[ 2048 ];
  495. for( int i = 0; i < m_FileListCtrl.GetItemCount(); i++ )
  496. {
  497. if ( m_FileListCtrl.GetItemState( i, LVIS_STATEIMAGEMASK ) == INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ) )
  498. {
  499. nFileCount++;
  500. }
  501. }
  502. if ( nFileCount > 0 )
  503. {
  504. sprintf( temp, "Syncing %d file(s). Please wait...", nFileCount );
  505. SetControls( true, temp );
  506. int nSyncFileCount = 0;
  507. for( int i = 0; i < m_FileListCtrl.GetItemCount(); i++ )
  508. {
  509. if ( m_FileListCtrl.GetItemState( i, LVIS_STATEIMAGEMASK ) == INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ) )
  510. {
  511. CMapDoc *pMapDoc = ( CMapDoc * )m_FileListCtrl.GetItemData( i );
  512. if ( pMapDoc->SyncToHeadRevision() == true )
  513. {
  514. nSyncFileCount++;
  515. }
  516. }
  517. }
  518. UpdateMapList();
  519. if ( CMapDoc::GetActiveMapDoc() != NULL )
  520. {
  521. CMapDoc::GetActiveMapDoc()->UpdateAllViews( MAPVIEW_UPDATE_SELECTION | MAPVIEW_UPDATE_TOOL | MAPVIEW_RENDER_NOW );
  522. }
  523. if ( nSyncFileCount == nFileCount )
  524. {
  525. sprintf( temp, "Synced %d file(s).", nSyncFileCount );
  526. }
  527. else
  528. {
  529. sprintf( temp, "Synced %d file(s). %d file(s) were not synced!", nSyncFileCount, nFileCount - nSyncFileCount );
  530. }
  531. SetControls( false, temp );
  532. }
  533. }
  534. void CMapDocStatus::SetControls( bool bDisable, char *pszMessage )
  535. {
  536. BOOL bEnable = ( bDisable ? FALSE : TRUE );
  537. m_StatusTextControl.SetWindowText( pszMessage );
  538. m_SyncControl.EnableWindow( bEnable );
  539. m_AddControl.EnableWindow( bEnable );
  540. m_CheckOutControl.EnableWindow( bEnable );
  541. m_RevertControl.EnableWindow( bEnable );
  542. m_DoneControl.EnableWindow( bEnable );
  543. }
  544. void CMapDocStatus::OnBnClickedRevert()
  545. {
  546. if ( !p4 || Options.general.bEnablePerforceIntegration == FALSE )
  547. {
  548. return;
  549. }
  550. int nFileCount = 0;
  551. char temp[ 2048 ];
  552. for( int i = 0; i < m_FileListCtrl.GetItemCount(); i++ )
  553. {
  554. if ( m_FileListCtrl.GetItemState( i, LVIS_STATEIMAGEMASK ) == INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ) )
  555. {
  556. nFileCount++;
  557. }
  558. }
  559. if ( nFileCount > 0 )
  560. {
  561. if ( AfxMessageBox( "Are you sure you want to revert these file(s)?", MB_ICONQUESTION | MB_YESNO ) == IDNO )
  562. {
  563. return;
  564. }
  565. sprintf( temp, "Reverting %d file(s). Please wait...", nFileCount );
  566. SetControls( true, temp );
  567. int nRevertFileCount = 0;
  568. for( int i = 0; i < m_FileListCtrl.GetItemCount(); i++ )
  569. {
  570. if ( m_FileListCtrl.GetItemState( i, LVIS_STATEIMAGEMASK ) == INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ) )
  571. {
  572. CMapDoc *pMapDoc = ( CMapDoc * )m_FileListCtrl.GetItemData( i );
  573. if ( pMapDoc->Revert() == true )
  574. {
  575. nRevertFileCount++;
  576. }
  577. }
  578. }
  579. UpdateMapList();
  580. if ( CMapDoc::GetActiveMapDoc() != NULL )
  581. {
  582. CMapDoc::GetActiveMapDoc()->UpdateAllViews( MAPVIEW_UPDATE_SELECTION | MAPVIEW_UPDATE_TOOL | MAPVIEW_RENDER_NOW );
  583. }
  584. if ( nRevertFileCount == nFileCount )
  585. {
  586. sprintf( temp, "Reverted %d file(s).", nRevertFileCount );
  587. }
  588. else
  589. {
  590. sprintf( temp, "Reverted %d file(s). %d file(s) were not reverted!", nRevertFileCount, nFileCount - nRevertFileCount );
  591. }
  592. SetControls( false, temp );
  593. }
  594. }
  595. void CMapDocStatus::OnNMRclickFileList(NMHDR *pNMHDR, LRESULT *pResult)
  596. {
  597. *pResult = 0;
  598. for( int i = 0; i < m_FileListCtrl.GetItemCount(); i++ )
  599. {
  600. if ( m_bSelectAll == true )
  601. {
  602. m_FileListCtrl.SetItemState( i, ( unsigned int )INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ), LVIS_STATEIMAGEMASK );
  603. }
  604. else
  605. {
  606. m_FileListCtrl.SetItemState( i, ( unsigned int )INDEXTOSTATEIMAGEMASK( LVIS_FOCUSED ), LVIS_STATEIMAGEMASK );
  607. }
  608. }
  609. m_bSelectAll = !m_bSelectAll;
  610. }
  611. void CMapDocStatus::OnShowWindow(BOOL bShow, UINT nStatus)
  612. {
  613. CDialog::OnShowWindow(bShow, nStatus);
  614. m_bSelectAll = true;
  615. }