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.

1177 lines
33 KiB

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