2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
29 #include "../../idlib/precompiled.h"
32 #include "../../sys/win32/rc/DeclEditor_resource.h"
34 #include "../comafx/CPathTreeCtrl.h"
35 #include "DialogDeclBrowser.h"
36 #include "DialogDeclNew.h"
38 #ifdef ID_DEBUG_MEMORY
45 toolTip_t DialogDeclNew::toolTips[] = {
46 { IDC_DECLNEW_COMBO_NEW_TYPE, "select the declaration type to create" },
47 { IDC_DECLNEW_EDIT_NEW_NAME, "enter a name for the new declaration" },
48 { IDC_DECLNEW_EDIT_NEW_FILE, "enter the name of the file to add the declaration to" },
49 { IDC_DECLNEW_BUTTON_NEW_FILE, "select existing file to add the declaration to" },
50 { IDOK, "create new declaration" },
51 { IDCANCEL, "cancel" },
56 IMPLEMENT_DYNAMIC(DialogDeclNew, CDialog)
60 DialogDeclNew::DialogDeclNew
63 DialogDeclNew::DialogDeclNew( CWnd* pParent /*=NULL*/ )
64 : CDialog(DialogDeclNew::IDD, pParent)
72 DialogDeclNew::~DialogDeclNew
75 DialogDeclNew::~DialogDeclNew() {
80 DialogDeclNew::DoDataExchange
83 void DialogDeclNew::DoDataExchange(CDataExchange* pDX) {
84 CDialog::DoDataExchange(pDX);
85 //{{AFX_DATA_MAP(DialogDeclNew)
86 DDX_Control(pDX, IDC_DECLNEW_COMBO_NEW_TYPE, typeList);
87 DDX_Control(pDX, IDC_DECLNEW_EDIT_NEW_NAME, nameEdit);
88 DDX_Control(pDX, IDC_DECLNEW_EDIT_NEW_FILE, fileEdit);
89 DDX_Control(pDX, IDC_DECLNEW_BUTTON_NEW_FILE, fileButton);
90 DDX_Control(pDX, IDOK, okButton);
91 DDX_Control(pDX, IDCANCEL, cancelButton);
97 DialogDeclNew::InitTypeList
100 void DialogDeclNew::InitTypeList( void ) {
103 typeList.ResetContent();
104 for ( i = 0; i < declManager->GetNumDeclTypes(); i++ ) {
105 typeList.AddString( declManager->GetDeclNameFromType( (declType_t)i ) );
111 DialogDeclNew::OnInitDialog
114 BOOL DialogDeclNew::OnInitDialog() {
116 CDialog::OnInitDialog();
120 SetSafeComboBoxSelection( &typeList, defaultType.c_str(), -1 );
121 nameEdit.SetWindowText( defaultName.c_str() );
122 fileEdit.SetWindowText( defaultFile.c_str() );
124 EnableToolTips( TRUE );
126 return TRUE; // return TRUE unless you set the focus to a control
127 // EXCEPTION: OCX Property Pages should return FALSE
131 BEGIN_MESSAGE_MAP(DialogDeclNew, CDialog)
132 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify)
133 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify)
137 ON_BN_CLICKED(IDC_DECLNEW_BUTTON_NEW_FILE, OnBnClickedFile)
138 ON_BN_CLICKED(IDOK, OnBnClickedOk)
139 ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
143 // DialogDeclNew message handlers
147 DialogDeclNew::OnActivate
150 void DialogDeclNew::OnActivate( UINT nState, CWnd *pWndOther, BOOL bMinimized ) {
151 CDialog::OnActivate( nState, pWndOther, bMinimized );
156 DialogDeclNew::OnToolTipNotify
159 BOOL DialogDeclNew::OnToolTipNotify( UINT id, NMHDR *pNMHDR, LRESULT *pResult ) {
160 return DefaultOnToolTipNotify( toolTips, id, pNMHDR, pResult );
165 DialogDeclNew::OnSetFocus
168 void DialogDeclNew::OnSetFocus( CWnd *pOldWnd ) {
169 CDialog::OnSetFocus( pOldWnd );
174 DialogDeclNew::OnDestroy
177 void DialogDeclNew::OnDestroy() {
178 return CDialog::OnDestroy();
183 DialogDeclNew::OnBnClickedFile
186 void DialogDeclNew::OnBnClickedFile() {
187 CString typeName, folder, ext;
189 const char *errorTitle = "Error selecting file.";
191 if ( GetSafeComboBoxSelection( &typeList, typeName, -1 ) == -1 ) {
192 MessageBox( "Select a declaration type first.", errorTitle, MB_OK );
196 declType_t type = declManager->GetDeclTypeFromName( typeName );
197 if ( type >= declManager->GetNumDeclTypes() ) {
198 MessageBox( "Unknown declaration type.", errorTitle, MB_OK | MB_ICONERROR );
203 case DECL_TABLE: folder = "materials"; ext = "(*.mtr)|*.mtr|(*.*)|*.*||"; break;
204 case DECL_MATERIAL: folder = "materials"; ext = "(*.mtr)|*.mtr|(*.*)|*.*||"; break;
205 case DECL_SKIN: folder = "skins"; ext = "(*.skin)|*.skin|(*.*)|*.*||"; break;
206 case DECL_SOUND: folder = "sound"; ext = "(*.sndshd|*.sndshd|(*.*)|*.*||"; break;
207 case DECL_ENTITYDEF: folder = "def"; ext = "(*.def)|*.def|(*.decl)|*.decl|(*.*)|*.*||"; break;
208 case DECL_MODELDEF: folder = "def"; ext = "(*.def)|*.def|(*.*)|*.*||"; break;
209 case DECL_FX: folder = "fx"; ext = "(*.fx)|*.fx|(*.*)|*.*||"; break;
210 case DECL_PARTICLE: folder = "particles"; ext = "(*.prt)|*.prt|(*.*)|*.*||"; break;
211 case DECL_AF: folder = "af"; ext = "(*.af)|*.af|(*.*)|*.*||"; break;
212 default: folder = "def"; ext = "(*.decl)|*.decl|(*.*)|*.*||"; break;
215 path = fileSystem->RelativePathToOSPath( folder );
218 CFileDialog dlgFile( TRUE, "decl", path, 0, ext, this );
219 if ( dlgFile.DoModal() == IDOK ) {
220 path = fileSystem->OSPathToRelativePath( dlgFile.m_ofn.lpstrFile );
221 fileEdit.SetWindowText( path );
227 DialogDeclNew::OnBnClickedOk
230 void DialogDeclNew::OnBnClickedOk() {
231 CString typeName, declName, fileName;
232 const char *errorTitle = "Error creating declaration.";
235 MessageBox( "No declaration tree available.", errorTitle, MB_OK | MB_ICONERROR );
239 if ( GetSafeComboBoxSelection( &typeList, typeName, -1 ) == -1 ) {
240 MessageBox( "No declaration type selected.", errorTitle, MB_OK | MB_ICONERROR );
244 nameEdit.GetWindowText( declName );
245 if ( declName.GetLength() == 0 ) {
246 MessageBox( "No declaration name specified.", errorTitle, MB_OK | MB_ICONERROR );
250 fileEdit.GetWindowText( fileName );
251 if ( fileName.GetLength() == 0 ) {
252 MessageBox( "No file name specified.", errorTitle, MB_OK | MB_ICONERROR );
256 if ( declTree->FindItem( idStr( typeName + "/" + declName ) ) ) {
257 MessageBox( "Declaration already exists.", errorTitle, MB_OK | MB_ICONERROR );
261 declType_t type = declManager->GetDeclTypeFromName( typeName );
262 if ( type >= declManager->GetNumDeclTypes() ) {
263 MessageBox( "Unknown declaration type.", errorTitle, MB_OK | MB_ICONERROR );
267 newDecl = declManager->CreateNewDecl( type, declName, fileName );
274 DialogDeclNew::OnBnClickedCancel
277 void DialogDeclNew::OnBnClickedCancel() {