EditFilenameListDialog.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // EditFilenameListDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "editfilenamelistdialog.h"
  23. #include "utils.h"
  24. #include "filemgr.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. //
  32. // EditFilenameListDialogClass
  33. //
  34. /////////////////////////////////////////////////////////////////////////////
  35. EditFilenameListDialogClass::EditFilenameListDialogClass(CWnd* pParent /*=NULL*/)
  36. : CDialog(EditFilenameListDialogClass::IDD, pParent)
  37. {
  38. //{{AFX_DATA_INIT(EditFilenameListDialogClass)
  39. // NOTE: the ClassWizard will add member initialization here
  40. //}}AFX_DATA_INIT
  41. return ;
  42. }
  43. /////////////////////////////////////////////////////////////////////////////
  44. //
  45. // DoDataExchange
  46. //
  47. /////////////////////////////////////////////////////////////////////////////
  48. void
  49. EditFilenameListDialogClass::DoDataExchange (CDataExchange *pDX)
  50. {
  51. CDialog::DoDataExchange(pDX);
  52. //{{AFX_DATA_MAP(EditFilenameListDialogClass)
  53. DDX_Control(pDX, IDC_FILENAME_LIST_CTRL, m_ListCtrl);
  54. //}}AFX_DATA_MAP
  55. return ;
  56. }
  57. BEGIN_MESSAGE_MAP(EditFilenameListDialogClass, CDialog)
  58. //{{AFX_MSG_MAP(EditFilenameListDialogClass)
  59. ON_BN_CLICKED(IDC_ADD, OnAdd)
  60. ON_NOTIFY(LVN_KEYDOWN, IDC_FILENAME_LIST_CTRL, OnKeydownFilenameListCtrl)
  61. //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63. /////////////////////////////////////////////////////////////////////////////
  64. //
  65. // OnAdd
  66. //
  67. /////////////////////////////////////////////////////////////////////////////
  68. void
  69. EditFilenameListDialogClass::OnAdd (void)
  70. {
  71. CFileDialog dialog ( TRUE,
  72. ".w3d",
  73. NULL,
  74. OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_ALLOWMULTISELECT,
  75. "Westwood 3D Files (*.w3d)|*.w3d|Texture Files (*.tga)|*.tga|Sound Files (*.wav,*.mp3)|*.wav;*.mp3|All Files|*.*||",
  76. this);
  77. TCHAR filename_list[MAX_PATH*20] = { 0 };
  78. dialog.m_ofn.lpstrFile = filename_list;
  79. dialog.m_ofn.nMaxFile = sizeof (filename_list);
  80. //
  81. // Start the user off in the assets directory
  82. //
  83. dialog.m_ofn.lpstrInitialDir = ::Get_File_Mgr ()->Get_Base_Path ();
  84. //
  85. // Ask the user to select the files
  86. //
  87. if (dialog.DoModal () == IDOK) {
  88. //
  89. // Add all the new filenames to the list
  90. //
  91. POSITION pos = dialog.GetStartPosition ();
  92. while (pos != NULL) {
  93. CString full_path = (LPCTSTR)dialog.GetNextPathName (pos);
  94. if (::Get_File_Mgr ()->Is_Path_Valid (full_path)) {
  95. m_ListCtrl.InsertItem (0xFF, (LPCTSTR)::Get_File_Mgr ()->Make_Relative_Path (full_path));
  96. }
  97. }
  98. }
  99. return ;
  100. }
  101. /////////////////////////////////////////////////////////////////////////////
  102. //
  103. // OnKeydownFilenameListCtrl
  104. //
  105. /////////////////////////////////////////////////////////////////////////////
  106. void
  107. EditFilenameListDialogClass::OnKeydownFilenameListCtrl
  108. (
  109. NMHDR *pNMHDR,
  110. LRESULT *pResult
  111. )
  112. {
  113. LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
  114. (*pResult) = 0;
  115. if (pLVKeyDow->wVKey == VK_DELETE) {
  116. //
  117. // Delete all the selected items
  118. //
  119. int index = -1;
  120. while ((index = m_ListCtrl.GetNextItem (-1, LVNI_SELECTED | LVNI_ALL)) >= 0) {
  121. m_ListCtrl.DeleteItem (index);
  122. }
  123. }
  124. return ;
  125. }
  126. /////////////////////////////////////////////////////////////////////////////
  127. //
  128. // OnInitDialog
  129. //
  130. /////////////////////////////////////////////////////////////////////////////
  131. BOOL
  132. EditFilenameListDialogClass::OnInitDialog (void)
  133. {
  134. CDialog::OnInitDialog ();
  135. //
  136. // Add a single column to the list control
  137. //
  138. m_ListCtrl.InsertColumn (0, "Filename");
  139. //
  140. // Size the column
  141. //
  142. CRect rect;
  143. m_ListCtrl.GetClientRect (&rect);
  144. rect.right -= ::GetSystemMetrics (SM_CXVSCROLL);
  145. m_ListCtrl.SetColumnWidth(0, rect.Width ());
  146. //
  147. // Add all the initial filenames to the list control
  148. //
  149. for (int index = 0; index < m_List.Count (); index ++) {
  150. m_ListCtrl.InsertItem (0xFF, m_List[index]);
  151. }
  152. return TRUE;
  153. }
  154. /////////////////////////////////////////////////////////////////////////////
  155. //
  156. // OnOK
  157. //
  158. /////////////////////////////////////////////////////////////////////////////
  159. void
  160. EditFilenameListDialogClass::OnOK (void)
  161. {
  162. //
  163. // Start fresh
  164. //
  165. m_List.Delete_All ();
  166. //
  167. // Rebuild the list from the user's entries in the list control
  168. //
  169. for (int index = 0; index < m_ListCtrl.GetItemCount (); index ++) {
  170. StringClass filename = (LPCTSTR)m_ListCtrl.GetItemText (index, 0);
  171. m_List.Add (filename);
  172. }
  173. CDialog::OnOK ();
  174. return ;
  175. }