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.

1176 lines
33 KiB

  1. // ManifestDialog.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "hammer.h"
  5. #include "ManifestDialog.h"
  6. #include "MapDoc.h"
  7. #include "Manifest.h"
  8. #include "MapInstance.h"
  9. #include "ControlBarIDs.h"
  10. #include "p4lib/ip4.h"
  11. // CManifestMove dialog
  12. IMPLEMENT_DYNAMIC(CManifestMove, CDialog)
  13. //-----------------------------------------------------------------------------
  14. // Purpose: contructor
  15. // Input : pParent - the parent window of this dialog
  16. //-----------------------------------------------------------------------------
  17. CManifestMove::CManifestMove( bool bIsMove, CWnd* pParent /*=NULL*/ )
  18. : CDialog(CManifestMove::IDD, pParent)
  19. {
  20. m_bIsMove = bIsMove;
  21. }
  22. //-----------------------------------------------------------------------------
  23. // Purpose: the default destructor
  24. //-----------------------------------------------------------------------------
  25. CManifestMove::~CManifestMove()
  26. {
  27. }
  28. //-----------------------------------------------------------------------------
  29. // Purpose: MFC data exchange function
  30. // Input : pDX -
  31. //-----------------------------------------------------------------------------
  32. void CManifestMove::DoDataExchange(CDataExchange* pDX)
  33. {
  34. CDialog::DoDataExchange(pDX);
  35. DDX_Control(pDX, IDC_MANIFEST_FILENAME, m_FileNameControl);
  36. DDX_Control(pDX, IDC_MANIFEST_CENTER_AROUND_BRUSH, m_CenterContentsControl);
  37. DDX_Control(pDX, IDC_MANIFEST_NAME2, m_FriendlyNameControl);
  38. DDX_Control(pDX, IDC_FULL_PATH, m_FullPathNameControl);
  39. }
  40. BEGIN_MESSAGE_MAP(CManifestMove, CDialog)
  41. ON_EN_CHANGE(IDC_MANIFEST_FILENAME, &CManifestMove::OnEnChangeManifestFilename)
  42. END_MESSAGE_MAP()
  43. //-----------------------------------------------------------------------------
  44. // Purpose: the default dialog initialization routine
  45. // Output : returns true upon success
  46. //-----------------------------------------------------------------------------
  47. BOOL CManifestMove::OnInitDialog()
  48. {
  49. CDialog::OnInitDialog();
  50. m_FileNameControl.SetWindowText( "" );
  51. if ( m_bIsMove == false )
  52. {
  53. m_CenterContentsControl.ShowWindow( SW_HIDE );
  54. }
  55. return TRUE;
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Purpose: This function responds to the user hitting the OK button.
  59. //-----------------------------------------------------------------------------
  60. void CManifestMove::OnOK()
  61. {
  62. char FullFileName[ MAX_PATH ];
  63. CDialog::OnOK();
  64. m_FriendlyNameControl.GetWindowText( m_FriendlyName );
  65. m_FileNameControl.GetWindowText( m_FileName );
  66. strcpy( FullFileName, m_FileName );
  67. V_SetExtension( FullFileName, ".vmf", sizeof( FullFileName ) );
  68. m_FileName = FullFileName;
  69. m_CenterContents = ( m_CenterContentsControl.GetCheck() == BST_CHECKED );
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Purpose: this function is called when the file name edit box is updated. it sets the static text
  73. // field for the full file name.
  74. //-----------------------------------------------------------------------------
  75. void CManifestMove::OnEnChangeManifestFilename()
  76. {
  77. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  78. if ( activeDoc )
  79. {
  80. if ( activeDoc->GetManifest() )
  81. {
  82. CManifest *pManifest = activeDoc->GetManifest();
  83. char FullFileName[ MAX_PATH ];
  84. m_FileNameControl.GetWindowText( m_FileName );
  85. strcpy( FullFileName, m_FileName );
  86. GetDlgItem( IDOK )->EnableWindow( FullFileName[ 0 ] != 0 );
  87. V_SetExtension( FullFileName, ".vmf", sizeof( FullFileName ) );
  88. m_FileName = FullFileName;
  89. pManifest->GetFullMapPath( m_FileName, FullFileName );
  90. m_FullPathNameControl.SetWindowText( FullFileName );
  91. }
  92. }
  93. }
  94. //-----------------------------------------------------------------------------
  95. // Purpose: this is the default constructor for the manifest list box
  96. //-----------------------------------------------------------------------------
  97. CManifestListBox::CManifestListBox( void ) :
  98. CListBox()
  99. {
  100. m_Icons.Create( IDB_MANIFEST_ICONS, 16, 1, RGB( 0, 255, 255 ) );
  101. m_ManifestFilterMenu.LoadMenu( IDR_MANIFEST_FILTER );
  102. m_ManifestFilterSecondaryMenu.Attach( ::GetSubMenu( m_ManifestFilterMenu.m_hMenu, 0 ) );
  103. m_ManifestFilterPrimaryMenu.Attach( ::GetSubMenu( m_ManifestFilterMenu.m_hMenu, 1 ) );
  104. m_ManifestFilterBlankMenu.Attach( ::GetSubMenu( m_ManifestFilterMenu.m_hMenu, 2 ) );
  105. m_pTrackerManifestMap = NULL;
  106. }
  107. //-----------------------------------------------------------------------------
  108. // Purpose: this function handles the owner draw of the list box for each manifest sub map
  109. // Input : lpDrawItemStruct - the list box item being rendered
  110. //-----------------------------------------------------------------------------
  111. void CManifestListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  112. {
  113. CDC dc;
  114. RECT &r = lpDrawItemStruct->rcItem;
  115. RECT ItemRect;
  116. ItemRect = r;
  117. ItemRect.left += 36;
  118. dc.Attach( lpDrawItemStruct->hDC );
  119. dc.SetROP2( R2_COPYPEN );
  120. CPen m_hPen, *pOldPen;
  121. m_hPen.CreatePen( PS_SOLID, 1, ::GetSysColor( COLOR_3DSHADOW ) );
  122. pOldPen = dc.SelectObject( &m_hPen );
  123. int iBackIndex = COLOR_WINDOW;
  124. int iForeIndex = COLOR_WINDOWTEXT;
  125. CManifestMap *pManifestMap = NULL;
  126. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  127. if ( activeDoc && activeDoc->GetManifest() )
  128. {
  129. CManifest *pManifest = activeDoc->GetManifest();
  130. pManifestMap = pManifest->GetMap( ( int )lpDrawItemStruct->itemData );
  131. }
  132. dc.FillSolidRect( &lpDrawItemStruct->rcItem, ::GetSysColor( COLOR_3DFACE ) );
  133. if ( ( lpDrawItemStruct->itemState & ODS_SELECTED ) )
  134. {
  135. dc.FillSolidRect( &ItemRect, ::GetSysColor( COLOR_HIGHLIGHT ) );
  136. iForeIndex = COLOR_HIGHLIGHTTEXT;
  137. }
  138. else if ( m_pTrackerManifestMap == pManifestMap )
  139. {
  140. dc.FillSolidRect( &ItemRect, ::GetSysColor( COLOR_INACTIVECAPTION ) );
  141. }
  142. dc.MoveTo( r.left, r.top );
  143. dc.LineTo( r.right, r.top );
  144. dc.MoveTo( r.left, r.bottom );
  145. dc.LineTo( r.right, r.bottom );
  146. dc.MoveTo( r.left + 35, r.top );
  147. dc.LineTo( r.left + 35, r.bottom );
  148. if ( pManifestMap )
  149. {
  150. // draw the visible icon
  151. RECT VisibleRect;
  152. POINT p;
  153. VisibleRect.left = r.left + 1;
  154. VisibleRect.top = r.top + 2;
  155. VisibleRect.right = VisibleRect.left + 16;
  156. VisibleRect.bottom = VisibleRect.top + 16;
  157. p.x = VisibleRect.left;
  158. p.y = VisibleRect.top;
  159. dc.FillSolidRect( &VisibleRect, ::GetSysColor( COLOR_3DFACE ) );
  160. dc.Draw3dRect( &VisibleRect, ::GetSysColor( COLOR_3DSHADOW ), ::GetSysColor( COLOR_3DHILIGHT ) );
  161. if ( pManifestMap->m_bVisible )
  162. {
  163. m_Icons.Draw( &dc, 0, p, ILD_NORMAL );
  164. }
  165. VisibleRect.left = r.left + 1 + 17;
  166. VisibleRect.right = VisibleRect.left + 16;
  167. p.x = VisibleRect.left;
  168. p.y = VisibleRect.top;
  169. dc.FillSolidRect( &VisibleRect, ::GetSysColor( COLOR_3DFACE ) );
  170. dc.Draw3dRect( &VisibleRect, ::GetSysColor( COLOR_3DSHADOW ), ::GetSysColor( COLOR_3DHILIGHT ) );
  171. if ( pManifestMap->m_bProtected )
  172. {
  173. m_Icons.Draw( &dc, 1, p, ILD_NORMAL );
  174. }
  175. else if ( pManifestMap->m_bReadOnly )
  176. {
  177. m_Icons.Draw( &dc, 2, p, ILD_NORMAL );
  178. }
  179. else if ( pManifestMap->m_bCheckedOut )
  180. {
  181. m_Icons.Draw( &dc, 3, p, ILD_NORMAL );
  182. }
  183. VisibleRect.left = r.left + 1 + 17;
  184. VisibleRect.top = r.top + 2 + 17;
  185. VisibleRect.right = VisibleRect.left + 16;
  186. VisibleRect.bottom = VisibleRect.top + 16;
  187. p.x = VisibleRect.left;
  188. p.y = VisibleRect.top;
  189. dc.FillSolidRect( &VisibleRect, ::GetSysColor( COLOR_3DFACE ) );
  190. dc.Draw3dRect( &VisibleRect, ::GetSysColor( COLOR_3DSHADOW ), ::GetSysColor( COLOR_3DHILIGHT ) );
  191. if ( pManifestMap->m_Map->IsModified() )
  192. {
  193. m_Icons.Draw( &dc, 4, p, ILD_NORMAL );
  194. }
  195. dc.SetTextColor( GetSysColor( iForeIndex ) );
  196. dc.SetBkColor( GetSysColor( iBackIndex ) );
  197. dc.SetBkMode( TRANSPARENT );
  198. VisibleRect.left = r.left + 36;
  199. VisibleRect.top = r.top + 1;
  200. VisibleRect.right = r.right - 1;
  201. VisibleRect.bottom = r.bottom - 1;
  202. dc.DrawText( pManifestMap->m_FriendlyName, -1, &VisibleRect, DT_LEFT | DT_VCENTER );
  203. }
  204. if ( ( lpDrawItemStruct->itemState & ODS_FOCUS ) )
  205. {
  206. dc.DrawFocusRect( &ItemRect );
  207. }
  208. dc.SelectObject( pOldPen );
  209. dc.Detach();
  210. }
  211. //-----------------------------------------------------------------------------
  212. // Purpose: this function returns the height for the owner draw item
  213. // Output : sets the item height
  214. //-----------------------------------------------------------------------------
  215. void CManifestListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
  216. {
  217. lpMeasureItemStruct->itemHeight = 36;
  218. }
  219. //-----------------------------------------------------------------------------
  220. // Purpose: this function compares two items - it does nothing
  221. // Output : returns 0 indicating no sorting has happened
  222. //-----------------------------------------------------------------------------
  223. int CManifestListBox::CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct)
  224. {
  225. return 0;
  226. }
  227. //-----------------------------------------------------------------------------
  228. // Purpose: this function responds to the left mouse button being pressed. the left side of the manifest item
  229. // is the visibility toggle. the right side handles the selection to make it the primary map.
  230. // Input : nFlags - ignored
  231. // point - the location of the click
  232. //-----------------------------------------------------------------------------
  233. void CManifestListBox::OnLButtonDown(UINT nFlags, CPoint point)
  234. {
  235. BOOL bOutside;
  236. m_pTrackerManifestMap = NULL;
  237. int index = ItemFromPoint( point, bOutside );
  238. if ( bOutside == false )
  239. {
  240. int height = GetItemHeight( index );
  241. if ( point.x < 36 )
  242. {
  243. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  244. if ( activeDoc && activeDoc->GetManifest() )
  245. {
  246. CManifest *pManifest = activeDoc->GetManifest();
  247. CManifestMap *pManifestMap = pManifest->GetMap( ( int )GetItemData( index ) );
  248. if ( pManifestMap )
  249. {
  250. if ( point.x < 18 && ( point.y % height ) < 18 )
  251. {
  252. pManifest->SetVisibility( pManifestMap, !pManifestMap->m_bVisible );
  253. }
  254. }
  255. }
  256. }
  257. else
  258. {
  259. CListBox::OnLButtonDown( nFlags, point );
  260. }
  261. }
  262. }
  263. //-----------------------------------------------------------------------------
  264. // Purpose: passes along the double click message if it is on the right side of a list item
  265. // Input : nFlags - not used
  266. // point - the mouse coordinates
  267. //-----------------------------------------------------------------------------
  268. void CManifestListBox::OnLButtonDblClk(UINT nFlags, CPoint point)
  269. {
  270. BOOL bOutside;
  271. m_pTrackerManifestMap = NULL;
  272. // int index =
  273. ItemFromPoint( point, bOutside );
  274. if ( bOutside == false )
  275. {
  276. if ( point.x >= 36 )
  277. {
  278. CListBox::OnLButtonDblClk( nFlags, point );
  279. }
  280. }
  281. }
  282. //-----------------------------------------------------------------------------
  283. // Purpose: this handles bringing up the specific context menu based upon if you
  284. // are over the primary map, a different sub map, or an empty spot.
  285. // Input : nFlags - not used
  286. // point - the mouse coordinates
  287. //-----------------------------------------------------------------------------
  288. void CManifestListBox::OnRButtonUp(UINT nFlags, CPoint point)
  289. {
  290. BOOL bOutside;
  291. CMenu *pWhichMenu;
  292. const UINT nEnable = MF_BYCOMMAND | MF_ENABLED;
  293. const UINT nDisable = MF_BYCOMMAND | MF_DISABLED | MF_GRAYED;
  294. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  295. if ( !activeDoc || !activeDoc->GetManifest() )
  296. {
  297. return;
  298. }
  299. CManifest *pManifest = activeDoc->GetManifest();
  300. m_pTrackerManifestMap = NULL;
  301. CPoint ptScreen( point.x, point.y );
  302. ClientToScreen(& ptScreen );
  303. int index = ItemFromPoint( point, bOutside );
  304. if ( bOutside )
  305. {
  306. pWhichMenu = &m_ManifestFilterBlankMenu;
  307. }
  308. else
  309. {
  310. m_pTrackerManifestMap = pManifest->GetMap( ( int )GetItemData( index ) );
  311. if ( m_pTrackerManifestMap->m_bPrimaryMap )
  312. {
  313. pWhichMenu = &m_ManifestFilterPrimaryMenu;
  314. }
  315. else
  316. {
  317. pWhichMenu = &m_ManifestFilterSecondaryMenu;
  318. }
  319. }
  320. if ( activeDoc->GetSelection()->IsEmpty() == false )
  321. {
  322. pWhichMenu->EnableMenuItem( ID_MOVESELECTIONTO_SUBMAP, nEnable );
  323. pWhichMenu->EnableMenuItem( ID_MOVESELECTIONTO_NEWSUBMAP, nEnable );
  324. }
  325. else
  326. {
  327. pWhichMenu->EnableMenuItem( ID_MOVESELECTIONTO_SUBMAP, nDisable );
  328. pWhichMenu->EnableMenuItem( ID_MOVESELECTIONTO_NEWSUBMAP, nDisable );
  329. }
  330. if ( pManifest->GetNumMaps() > 1 )
  331. {
  332. pWhichMenu->EnableMenuItem( ID_MANIFEST_REMOVE, nEnable );
  333. }
  334. else
  335. {
  336. pWhichMenu->EnableMenuItem( ID_MANIFEST_REMOVE, nDisable );
  337. }
  338. pWhichMenu->EnableMenuItem( ID_VERSIONCONTROL_CHECKOUT, nDisable );
  339. pWhichMenu->EnableMenuItem( ID_VERSIONCONTROL_CHECKIN, nDisable );
  340. pWhichMenu->EnableMenuItem( ID_VERSIONCONTROL_ADD, nDisable );
  341. if ( p4 && m_pTrackerManifestMap )
  342. {
  343. if ( m_pTrackerManifestMap->m_bIsVersionControlled )
  344. {
  345. if ( m_pTrackerManifestMap->m_bCheckedOut )
  346. {
  347. pWhichMenu->EnableMenuItem( ID_VERSIONCONTROL_CHECKIN, nEnable );
  348. }
  349. else
  350. {
  351. pWhichMenu->EnableMenuItem( ID_VERSIONCONTROL_CHECKOUT, nEnable );
  352. }
  353. }
  354. else
  355. {
  356. pWhichMenu->EnableMenuItem( ID_VERSIONCONTROL_ADD, nEnable );
  357. }
  358. }
  359. Invalidate();
  360. pWhichMenu->TrackPopupMenu( TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_LEFTALIGN, ptScreen.x, ptScreen.y, this );
  361. CListBox::OnRButtonUp(nFlags, point);
  362. }
  363. //-----------------------------------------------------------------------------
  364. // Purpose: this function handles the menu command for moving the selection to an existing sub map
  365. //-----------------------------------------------------------------------------
  366. void CManifestListBox::OnMoveSelectionToSubMap()
  367. {
  368. if ( !m_pTrackerManifestMap )
  369. {
  370. return;
  371. }
  372. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  373. if ( !activeDoc || !activeDoc->GetManifest() )
  374. {
  375. return;
  376. }
  377. CManifest *pManifest = activeDoc->GetManifest();
  378. pManifest->MoveSelectionToSubmap( m_pTrackerManifestMap, false );
  379. m_pTrackerManifestMap = NULL;
  380. }
  381. //-----------------------------------------------------------------------------
  382. // Purpose: this function handles the menu command for moving the selection to a new sub map
  383. //-----------------------------------------------------------------------------
  384. void CManifestListBox::OnMoveSelectionToNewSubMap()
  385. {
  386. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  387. if ( !activeDoc || !activeDoc->GetManifest() )
  388. {
  389. return;
  390. }
  391. CManifestMove ManifestMove( true );
  392. if ( ManifestMove.DoModal() == IDOK )
  393. {
  394. CString FriendlyName, FileName;
  395. ManifestMove.GetFriendlyName( FriendlyName );
  396. ManifestMove.GetFileName( FileName );
  397. CManifest *pManifest = activeDoc->GetManifest();
  398. CManifestMap *pNewManifestMap = pManifest->MoveSelectionToNewSubmap( FriendlyName, FileName, ManifestMove.GetCenterContents() );
  399. if ( pNewManifestMap )
  400. {
  401. }
  402. }
  403. }
  404. //-----------------------------------------------------------------------------
  405. // Purpose:
  406. // Input :
  407. // Output :
  408. //-----------------------------------------------------------------------------
  409. void CManifestListBox::OnVersionControlCheckOut()
  410. {
  411. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  412. if ( !activeDoc || !activeDoc->GetManifest() )
  413. {
  414. return;
  415. }
  416. CManifest *pManifest = activeDoc->GetManifest();
  417. if ( !p4->OpenFileForEdit( m_pTrackerManifestMap->m_AbsoluteMapFileName ) )
  418. {
  419. char temp[ 2048 ];
  420. sprintf( temp, "Could not check out map: %s", p4->GetLastError() );
  421. AfxMessageBox( temp, MB_ICONHAND | MB_OK );
  422. }
  423. else
  424. {
  425. pManifest->CheckFileStatus();
  426. Invalidate();
  427. }
  428. }
  429. //-----------------------------------------------------------------------------
  430. // Purpose:
  431. // Input :
  432. // Output :
  433. //-----------------------------------------------------------------------------
  434. void CManifestListBox::OnVersionControlCheckIn()
  435. {
  436. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  437. if ( !activeDoc || !activeDoc->GetManifest() )
  438. {
  439. return;
  440. }
  441. CManifest *pManifest = activeDoc->GetManifest();
  442. pManifest->m_bDefaultCheckin = false;
  443. for( int i = 0; i < pManifest->GetNumMaps(); i++ )
  444. {
  445. CManifestMap *pManifestMap = pManifest->GetMap( i );
  446. pManifestMap->m_bDefaultCheckin = false;
  447. }
  448. if ( m_pTrackerManifestMap )
  449. {
  450. m_pTrackerManifestMap->m_bDefaultCheckin = true;
  451. }
  452. CManifestCheckin ManifestCheckin;
  453. if ( ManifestCheckin.DoModal() == IDOK )
  454. {
  455. pManifest->CheckFileStatus();
  456. Invalidate();
  457. }
  458. }
  459. //-----------------------------------------------------------------------------
  460. // Purpose:
  461. // Input :
  462. // Output :
  463. //-----------------------------------------------------------------------------
  464. void CManifestListBox::OnVersionControlAdd()
  465. {
  466. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  467. if ( !activeDoc || !activeDoc->GetManifest() )
  468. {
  469. return;
  470. }
  471. CManifest *pManifest = activeDoc->GetManifest();
  472. if ( !p4->OpenFileForAdd( m_pTrackerManifestMap->m_AbsoluteMapFileName ) )
  473. {
  474. char temp[ 2048 ];
  475. sprintf( temp, "Could not add map: %s", p4->GetLastError() );
  476. AfxMessageBox( temp, MB_ICONHAND | MB_OK );
  477. }
  478. else
  479. {
  480. pManifest->CheckFileStatus();
  481. Invalidate();
  482. }
  483. }
  484. //-----------------------------------------------------------------------------
  485. // Purpose: this function handles the menu command to insert a new empty sub map
  486. //-----------------------------------------------------------------------------
  487. void CManifestListBox::OnInsertEmptySubMap()
  488. {
  489. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  490. if ( !activeDoc || !activeDoc->GetManifest() )
  491. {
  492. return;
  493. }
  494. CManifestMove ManifestMove( false );
  495. if ( ManifestMove.DoModal() == IDOK )
  496. {
  497. CString FriendlyName, FileName;
  498. ManifestMove.GetFriendlyName( FriendlyName );
  499. ManifestMove.GetFileName( FileName );
  500. CManifest *pManifest = activeDoc->GetManifest();
  501. CManifestMap *pNewManifestMap = pManifest->AddNewSubmap( FriendlyName, FileName );
  502. if ( pNewManifestMap )
  503. {
  504. }
  505. }
  506. }
  507. //-----------------------------------------------------------------------------
  508. // Purpose: this function handles the menu command to insert an existing sub map
  509. //-----------------------------------------------------------------------------
  510. void CManifestListBox::OnInsertExistingSubMap()
  511. {
  512. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  513. if ( !activeDoc || !activeDoc->GetManifest() )
  514. {
  515. return;
  516. }
  517. CManifest *pManifest = activeDoc->GetManifest();
  518. pManifest->AddExistingMap();
  519. }
  520. //-----------------------------------------------------------------------------
  521. // Purpose: this function will handle bringing up the properties dialog of a sub map
  522. //-----------------------------------------------------------------------------
  523. void CManifestListBox::OnManifestProperties()
  524. {
  525. if ( !m_pTrackerManifestMap )
  526. {
  527. return;
  528. }
  529. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  530. if ( !activeDoc || !activeDoc->GetManifest() )
  531. {
  532. return;
  533. }
  534. CManifest *pManifest = activeDoc->GetManifest();
  535. CManifestMapDlg ManifestMapDlg( m_pTrackerManifestMap, this );
  536. if ( ManifestMapDlg.DoModal() == IDOK )
  537. {
  538. pManifest->SetManifestPrefsModifiedFlag( true );
  539. Invalidate();
  540. }
  541. }
  542. //-----------------------------------------------------------------------------
  543. // Purpose: this function will remove an existing sub map from the manifest, but will
  544. // not delete the file.
  545. //-----------------------------------------------------------------------------
  546. void CManifestListBox::OnManifestRemove()
  547. {
  548. if ( !m_pTrackerManifestMap )
  549. {
  550. return;
  551. }
  552. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  553. if ( !activeDoc || !activeDoc->GetManifest() )
  554. {
  555. return;
  556. }
  557. CManifest *pManifest = activeDoc->GetManifest();
  558. if ( AfxMessageBox( "Are you sure you want to remove this sub map from the manifest?", MB_YESNO | MB_ICONQUESTION ) == IDNO )
  559. {
  560. return;
  561. }
  562. pManifest->RemoveSubMap( m_pTrackerManifestMap );
  563. pManifest->SetPrimaryMap( pManifest->GetMap( 0 ) );
  564. m_pTrackerManifestMap = NULL;
  565. AfxMessageBox( "The sub map has been removed from the manifest, but the file has not been deleted.", MB_OK | MB_ICONASTERISK );
  566. }
  567. BEGIN_MESSAGE_MAP(CManifestListBox, CListBox)
  568. //{{AFX_MSG_MAP(CManifestListBox)
  569. ON_WM_LBUTTONDOWN()
  570. ON_WM_RBUTTONUP()
  571. //}}AFX_MSG_MAP
  572. ON_WM_LBUTTONDBLCLK()
  573. ON_COMMAND(ID_MOVESELECTIONTO_SUBMAP, OnMoveSelectionToSubMap)
  574. ON_COMMAND(ID_MOVESELECTIONTO_NEWSUBMAP, OnMoveSelectionToNewSubMap)
  575. ON_COMMAND(ID_VERSIONCONTROL_CHECKOUT, OnVersionControlCheckOut)
  576. ON_COMMAND(ID_VERSIONCONTROL_CHECKIN, OnVersionControlCheckIn)
  577. ON_COMMAND(ID_VERSIONCONTROL_ADD, OnVersionControlAdd)
  578. ON_COMMAND(ID_INSERT_EMPTYSUBMAP, OnInsertEmptySubMap)
  579. ON_COMMAND(ID_INSERT_EXISTINGSUBMAP, OnInsertExistingSubMap)
  580. ON_COMMAND(ID_MANIFEST_PROPERTIES, OnManifestProperties)
  581. ON_COMMAND(ID_MANIFEST_REMOVE, OnManifestRemove)
  582. END_MESSAGE_MAP()
  583. //-----------------------------------------------------------------------------
  584. // Purpose: this function will create the hammber bar window
  585. // Input : pParentWnd -
  586. // Output : Returns TRUE on success, FALSE on failure.
  587. //-----------------------------------------------------------------------------
  588. BOOL CManifestFilter::Create(CWnd *pParentWnd)
  589. {
  590. if (!CHammerBar::Create(pParentWnd, IDD_MANIFEST_CONTROL, CBRS_RIGHT | CBRS_SIZE_DYNAMIC, IDCB_MANIFEST_CONTROL, "Manifest Control"))
  591. {
  592. return FALSE;
  593. }
  594. m_ManifestList.SubclassDlgItem( IDC_MANIFEST_LIST, this );
  595. m_ManifestList.SetItemHeight( 0, 36 );
  596. AddControl( IDC_MANIFEST_LIST, GROUP_BOX );
  597. UpdateManifestList();
  598. m_pBkBrush = new CBrush( ::GetSysColor( COLOR_3DFACE ) );
  599. bInitialized = TRUE;
  600. return TRUE;
  601. }
  602. //-----------------------------------------------------------------------------
  603. // Purpose: default destructor
  604. //-----------------------------------------------------------------------------
  605. CManifestFilter::~CManifestFilter()
  606. {
  607. }
  608. //-----------------------------------------------------------------------------
  609. // Purpose: this function will update the manifest list ( for when sub maps are added / removed
  610. // or the primary map is changed.
  611. //-----------------------------------------------------------------------------
  612. void CManifestFilter::UpdateManifestList( void )
  613. {
  614. m_ManifestList.ResetContent();
  615. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  616. if ( activeDoc && activeDoc->GetManifest() )
  617. {
  618. CManifest *pManifest = activeDoc->GetManifest();
  619. for( int i = 0; i < pManifest->GetNumMaps(); i++ )
  620. {
  621. CManifestMap *pManifestMap = pManifest->GetMap( i );
  622. int index = m_ManifestList.AddString( "Manifest" );
  623. m_ManifestList.SetItemData( index, i );
  624. if ( pManifestMap->m_bPrimaryMap )
  625. {
  626. m_ManifestList.SetCurSel( index );
  627. }
  628. }
  629. }
  630. }
  631. //-----------------------------------------------------------------------------
  632. // Purpose: data exchange function for assigning variables to controls
  633. //-----------------------------------------------------------------------------
  634. void CManifestFilter::DoDataExchange(CDataExchange* pDX)
  635. {
  636. __super::DoDataExchange(pDX);
  637. }
  638. BEGIN_MESSAGE_MAP(CManifestFilter, CHammerBar)
  639. ON_LBN_SELCHANGE(IDC_MANIFEST_LIST, &CManifestFilter::OnLbnSelchangeManifestList)
  640. ON_LBN_DBLCLK(IDC_MANIFEST_LIST, &CManifestFilter::OnLbnDblClkManifestList)
  641. ON_WM_CTLCOLOR()
  642. ON_WM_DESTROY()
  643. ON_WM_SIZE()
  644. END_MESSAGE_MAP()
  645. //-----------------------------------------------------------------------------
  646. // Purpose: this function will handle the selection of a sub map to set it to the primary map
  647. //-----------------------------------------------------------------------------
  648. void CManifestFilter::OnLbnSelchangeManifestList()
  649. {
  650. int nIndex = m_ManifestList.GetCurSel();
  651. int nCount = m_ManifestList.GetCount();
  652. if ( ( nIndex != LB_ERR ) && ( nCount > 1 ) )
  653. {
  654. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  655. if ( activeDoc && activeDoc->GetManifest() )
  656. {
  657. CManifest *pManifest = activeDoc->GetManifest();
  658. CManifestMap *pManifestMap = pManifest->GetMap( ( int )m_ManifestList.GetItemData( nIndex ) );
  659. pManifest->SetPrimaryMap( pManifestMap );
  660. }
  661. }
  662. }
  663. //-----------------------------------------------------------------------------
  664. // Purpose: this function will bring up the properties dialog of a sub map
  665. //-----------------------------------------------------------------------------
  666. void CManifestFilter::OnLbnDblClkManifestList()
  667. {
  668. int nIndex = m_ManifestList.GetCurSel();
  669. // int nCount = m_ManifestList.GetCount();
  670. if ( ( nIndex != LB_ERR ) )
  671. {
  672. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  673. if ( activeDoc && activeDoc->GetManifest() )
  674. {
  675. CManifest *pManifest = activeDoc->GetManifest();
  676. CManifestMap *pManifestMap = pManifest->GetMap( ( int )m_ManifestList.GetItemData( nIndex ) );
  677. CManifestMapDlg ManifestMapDlg( pManifestMap, this );
  678. if ( ManifestMapDlg.DoModal() == IDOK )
  679. {
  680. pManifest->SetManifestPrefsModifiedFlag( true );
  681. m_ManifestList.Invalidate();
  682. }
  683. }
  684. }
  685. }
  686. //-----------------------------------------------------------------------------
  687. // Purpose: this function sets the text and background color of the custom list box
  688. // Input : pDC - the display context
  689. // pWnd - the owning window
  690. // nCtlColor - the color type to be set
  691. // Output : returns the brush for the control color
  692. //-----------------------------------------------------------------------------
  693. HBRUSH CManifestFilter::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  694. {
  695. switch (nCtlColor)
  696. {
  697. case CTLCOLOR_LISTBOX:
  698. pDC->SetTextColor( ::GetSysColor( COLOR_WINDOWTEXT ) );
  699. pDC->SetBkColor( ::GetSysColor( COLOR_3DFACE ) );
  700. return ( HBRUSH )( m_pBkBrush->GetSafeHandle() );
  701. default:
  702. return __super::OnCtlColor(pDC, pWnd, nCtlColor);
  703. }
  704. }
  705. //-----------------------------------------------------------------------------
  706. // Purpose: this function handles the destruction of the dialog to make sure the brush is destroyed
  707. //-----------------------------------------------------------------------------
  708. void CManifestFilter::OnDestroy()
  709. {
  710. __super::OnDestroy();
  711. delete m_pBkBrush;
  712. }
  713. //-----------------------------------------------------------------------------
  714. // Purpose:
  715. // Input : nType -
  716. // cx -
  717. // cy -
  718. //-----------------------------------------------------------------------------
  719. void CManifestFilter::OnSize(UINT nType, int cx, int cy)
  720. {
  721. // TODO: make larger / resizable when floating
  722. //if (IsFloating())
  723. //{
  724. // CWnd *pwnd = GetDlgItem(IDC_GROUPS);
  725. // if (pwnd && IsWindow(pwnd->GetSafeHwnd()))
  726. // {
  727. // pwnd->MoveWindow(2, 10, cx - 2, cy - 2, TRUE);
  728. // }
  729. //}
  730. CHammerBar::OnSize(nType, cx, cy);
  731. }
  732. IMPLEMENT_DYNAMIC(CManifestMapDlg, CDialog)
  733. //-----------------------------------------------------------------------------
  734. // Purpose: default constructor
  735. // Input : pManifestMap - the map for this dialog
  736. // pParent - the parent window
  737. //-----------------------------------------------------------------------------
  738. CManifestMapDlg::CManifestMapDlg( CManifestMap *pManifestMap, CWnd* pParent /*=NULL*/ )
  739. : CDialog(CManifestMapDlg::IDD, pParent)
  740. {
  741. m_pManifestMap = pManifestMap;
  742. }
  743. //-----------------------------------------------------------------------------
  744. // Purpose: default destructor
  745. //-----------------------------------------------------------------------------
  746. CManifestMapDlg::~CManifestMapDlg()
  747. {
  748. }
  749. //-----------------------------------------------------------------------------
  750. // Purpose: data exchange function for assigning variables to controls
  751. //-----------------------------------------------------------------------------
  752. void CManifestMapDlg::DoDataExchange(CDataExchange* pDX)
  753. {
  754. CDialog::DoDataExchange(pDX);
  755. DDX_Control(pDX, IDC_MANIFEST_FRIENDLY_NAME, m_FriendlyNameControl);
  756. DDX_Control(pDX, IDC_MANIFEST_FULL_FILENAME, m_FullFileNameCtrl);
  757. }
  758. BEGIN_MESSAGE_MAP(CManifestMapDlg, CDialog)
  759. END_MESSAGE_MAP()
  760. //-----------------------------------------------------------------------------
  761. // Purpose: routine to handle the initialization of the dialog
  762. //-----------------------------------------------------------------------------
  763. BOOL CManifestMapDlg::OnInitDialog()
  764. {
  765. CDialog::OnInitDialog();
  766. m_FriendlyNameControl.SetWindowText( m_pManifestMap->m_FriendlyName );
  767. m_FullFileNameCtrl.SetWindowText( m_pManifestMap->m_AbsoluteMapFileName );
  768. return TRUE;
  769. }
  770. //-----------------------------------------------------------------------------
  771. // Purpose: this function handles the user hitting ok
  772. //-----------------------------------------------------------------------------
  773. void CManifestMapDlg::OnOK()
  774. {
  775. m_FriendlyNameControl.GetWindowText( m_pManifestMap->m_FriendlyName );
  776. CDialog::OnOK();
  777. }
  778. // CManifestCheckin dialog
  779. IMPLEMENT_DYNAMIC(CManifestCheckin, CDialog)
  780. //-----------------------------------------------------------------------------
  781. // Purpose:
  782. // Input :
  783. // Output :
  784. //-----------------------------------------------------------------------------
  785. CManifestCheckin::CManifestCheckin(CWnd* pParent /*=NULL*/)
  786. : CDialog(CManifestCheckin::IDD, pParent)
  787. {
  788. }
  789. //-----------------------------------------------------------------------------
  790. // Purpose:
  791. // Input :
  792. // Output :
  793. //-----------------------------------------------------------------------------
  794. CManifestCheckin::~CManifestCheckin()
  795. {
  796. }
  797. //-----------------------------------------------------------------------------
  798. // Purpose:
  799. // Input :
  800. // Output :
  801. //-----------------------------------------------------------------------------
  802. void CManifestCheckin::DoDataExchange(CDataExchange* pDX)
  803. {
  804. CDialog::DoDataExchange(pDX);
  805. DDX_Control(pDX, IDC_CHECKIN_LIST, m_CheckinListCtrl);
  806. DDX_Control(pDX, IDC_CHECKIN_DESCRIPTION, m_DescriptionCtrl);
  807. }
  808. BEGIN_MESSAGE_MAP(CManifestCheckin, CDialog)
  809. ON_BN_CLICKED(IDOK, &CManifestCheckin::OnBnClickedOk)
  810. END_MESSAGE_MAP()
  811. //-----------------------------------------------------------------------------
  812. // Purpose:
  813. // Input :
  814. // Output :
  815. //-----------------------------------------------------------------------------
  816. BOOL CManifestCheckin::OnInitDialog()
  817. {
  818. P4File_t FileInfo;
  819. CDialog::OnInitDialog();
  820. m_CheckinListCtrl.SetExtendedStyle( m_CheckinListCtrl.GetExtendedStyle() | LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT );
  821. m_CheckinListCtrl.InsertColumn( 0, "", LVCFMT_LEFT, 30, -1 );
  822. m_CheckinListCtrl.InsertColumn( 1, "Status", LVCFMT_LEFT, 50, -1 );
  823. m_CheckinListCtrl.InsertColumn( 2, "Name", LVCFMT_LEFT, 100, -1 );
  824. m_CheckinListCtrl.InsertColumn( 3, "Folder", LVCFMT_LEFT, 350, -1 );
  825. if ( p4 == NULL )
  826. {
  827. return TRUE;
  828. }
  829. int nCount = 0;
  830. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  831. if ( activeDoc && activeDoc->GetManifest() )
  832. {
  833. CManifest *pManifest = activeDoc->GetManifest();
  834. if ( pManifest->m_bCheckedOut )
  835. {
  836. if ( p4->GetFileInfo( pManifest->GetPathName(), &FileInfo ) == true )
  837. {
  838. int nIndex = m_CheckinListCtrl.InsertItem( nCount, "" );
  839. nCount++;
  840. m_CheckinListCtrl.SetItemData( nIndex, ( DWORD_PTR )NULL );
  841. switch( FileInfo.m_eOpenState )
  842. {
  843. case P4FILE_OPENED_FOR_ADD:
  844. m_CheckinListCtrl.SetItemText( nIndex, 1, "Add" );
  845. break;
  846. case P4FILE_OPENED_FOR_EDIT:
  847. m_CheckinListCtrl.SetItemText( nIndex, 1, "Edit" );
  848. break;
  849. }
  850. m_CheckinListCtrl.SetItemText( nIndex, 2, p4->String( FileInfo.m_sName ) );
  851. m_CheckinListCtrl.SetItemText( nIndex, 3, p4->String( FileInfo.m_sPath ) );
  852. if ( pManifest->m_bDefaultCheckin )
  853. {
  854. ListView_SetItemState( m_CheckinListCtrl.m_hWnd, nIndex, INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ), LVIS_STATEIMAGEMASK );
  855. }
  856. }
  857. }
  858. for( int i = 0; i < pManifest->GetNumMaps(); i++ )
  859. {
  860. CManifestMap *pManifestMap = pManifest->GetMap( i );
  861. if ( pManifestMap->m_bCheckedOut )
  862. {
  863. if ( p4->GetFileInfo( pManifestMap->m_AbsoluteMapFileName, &FileInfo ) == true )
  864. {
  865. int nIndex = m_CheckinListCtrl.InsertItem( nCount, "" );
  866. nCount++;
  867. m_CheckinListCtrl.SetItemData( nIndex, ( DWORD_PTR )pManifestMap );
  868. switch( FileInfo.m_eOpenState )
  869. {
  870. case P4FILE_OPENED_FOR_ADD:
  871. m_CheckinListCtrl.SetItemText( nIndex, 1, "Add" );
  872. break;
  873. case P4FILE_OPENED_FOR_EDIT:
  874. m_CheckinListCtrl.SetItemText( nIndex, 1, "Edit" );
  875. break;
  876. }
  877. m_CheckinListCtrl.SetItemText( nIndex, 2, p4->String( FileInfo.m_sName ) );
  878. m_CheckinListCtrl.SetItemText( nIndex, 3, p4->String( FileInfo.m_sPath ) );
  879. if ( pManifestMap->m_bDefaultCheckin )
  880. {
  881. ListView_SetItemState( m_CheckinListCtrl.m_hWnd, nIndex, INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ), LVIS_STATEIMAGEMASK );
  882. }
  883. }
  884. }
  885. }
  886. }
  887. return TRUE;
  888. }
  889. //-----------------------------------------------------------------------------
  890. // Purpose:
  891. // Input :
  892. // Output :
  893. //-----------------------------------------------------------------------------
  894. void CManifestCheckin::OnBnClickedOk()
  895. {
  896. int nFileCount = 0;
  897. CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
  898. if ( !activeDoc || !activeDoc->GetManifest() )
  899. {
  900. OnOK();
  901. }
  902. CManifest *pManifest = activeDoc->GetManifest();
  903. for( int i = 0; i < m_CheckinListCtrl.GetItemCount(); i++ )
  904. {
  905. if ( m_CheckinListCtrl.GetItemState( i, LVIS_STATEIMAGEMASK ) == INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ) )
  906. {
  907. nFileCount++;
  908. }
  909. }
  910. if ( nFileCount > 0 )
  911. {
  912. CString Description;
  913. m_DescriptionCtrl.GetWindowText( Description );
  914. if ( Description.GetLength() < 2 )
  915. {
  916. 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 );
  917. return;
  918. }
  919. const char **ppFileNames = ( const char** )stackalloc( nFileCount * sizeof( char * ) );
  920. nFileCount = 0;
  921. for( int i = 0; i < m_CheckinListCtrl.GetItemCount(); i++ )
  922. {
  923. if ( m_CheckinListCtrl.GetItemState( i, LVIS_STATEIMAGEMASK ) == INDEXTOSTATEIMAGEMASK( LVIS_SELECTED ) )
  924. {
  925. CManifestMap *pManifestMap = ( CManifestMap * )m_CheckinListCtrl.GetItemData( i );
  926. if ( pManifestMap == NULL )
  927. {
  928. ppFileNames[ nFileCount ] = pManifest->GetPathName();
  929. pManifest->SaveVMFManifest( pManifest->GetPathName() );
  930. }
  931. else
  932. {
  933. ppFileNames[ nFileCount ] = pManifestMap->m_AbsoluteMapFileName;
  934. pManifestMap->m_Map->SaveVMF( pManifestMap->m_AbsoluteMapFileName, 0 );
  935. }
  936. nFileCount++;
  937. }
  938. }
  939. if ( p4->SubmitFiles( nFileCount, ppFileNames, Description ) == false )
  940. {
  941. char temp[ 2048 ];
  942. sprintf( temp, "Could not check in map(s): %s", p4->GetLastError() );
  943. AfxMessageBox( temp, MB_ICONHAND | MB_OK );
  944. return;
  945. }
  946. }
  947. OnOK();
  948. }