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"
34 bool GECheckInDlg_DoModal ( HWND parent, const char* filename, idStr* comment );
38 rvGEWorkspace::SaveFile
40 Writes the contents of the open gui file to disk
43 bool rvGEWorkspace::SaveFile ( const char* filename )
48 SetCursor ( LoadCursor ( NULL, MAKEINTRESOURCE(IDC_WAIT ) ) );
52 // Since quake can only write to its path we will write a temp file then copy it over
56 tempfile = "guis/temp.guied";
57 ospath = fileSystem->RelativePathToOSPath ( tempfile, "fs_basepath" );
59 // Open the output file for write
60 if ( !(file = fileSystem->OpenFileWrite ( tempfile ) ) )
62 int error = GetLastError ( );
63 SetCursor ( LoadCursor ( NULL, MAKEINTRESOURCE(IDC_ARROW ) ) );
67 window = mInterface->GetDesktop ( );
69 WriteWindow ( file, 1, window );
71 fileSystem->CloseFile ( file );
73 if ( !CopyFile ( ospath, filename, FALSE ) )
75 DeleteFile ( ospath );
76 SetCursor ( LoadCursor ( NULL, MAKEINTRESOURCE(IDC_ARROW ) ) );
80 DeleteFile ( ospath );
87 SetCursor ( LoadCursor ( NULL, MAKEINTRESOURCE(IDC_ARROW ) ) );
94 rvGEWorkspace::WriteTabs
96 Writes the given number of tabs to the given file
99 void rvGEWorkspace::WriteTabs ( idFile* file, int depth )
103 for ( i = 0; i < depth; i ++ )
105 file->Write ( "\t", 1 );
111 rvGEWorkspace::WriteWindow
113 Writes the contents of the given window to the file
116 bool rvGEWorkspace::WriteWindow ( idFile* file, int depth, idWindow* window )
119 rvGEWindowWrapper* wrapper;
122 wrapper = rvGEWindowWrapper::GetWrapper ( window );
128 if ( wrapper->IsDeleted ( ) )
134 WriteTabs ( file, depth - 1 );
136 out = wrapper->WindowTypeToString ( wrapper->GetWindowType ( ) );
138 file->Write ( out, out.Length() );
140 out = window->GetName ( );
141 file->Write ( out, out.Length() );
142 file->Write ( "\r\n", 2 );
144 WriteTabs ( file, depth - 1 );
147 file->Write ( out, out.Length() );
148 file->ForceFlush ( );
150 for ( i = 0; i < wrapper->GetStateDict().GetNumKeyVals(); i ++ )
152 const idKeyValue* key = wrapper->GetStateDict().GetKeyVal ( i );
154 // Dont write name to the files
155 if ( !key->GetKey().Icmp ( "name" ) )
160 WriteTabs ( file, depth );
164 file->Write ( out, out.Length() );
167 for ( p = key->GetValue().c_str(); *p; p ++ )
172 file->Write ( "\\n", 2 );
176 file->Write ( p, 1 );
181 file->Write ( "\r\n", 2 );
184 for ( i = 0; i < wrapper->GetVariableDict().GetNumKeyVals(); i ++ )
186 const idKeyValue* key = wrapper->GetVariableDict().GetKeyVal ( i );
188 WriteTabs ( file, depth );
192 out.Append ( key->GetValue() );
193 out.Append ( "\r\n" );
195 file->Write ( out, out.Length() );
198 if ( wrapper->GetScriptDict().GetNumKeyVals() )
200 file->Write ( "\r\n", 2 );
203 for ( i = 0; i < wrapper->GetScriptDict().GetNumKeyVals(); i ++ )
205 const idKeyValue* key = wrapper->GetScriptDict().GetKeyVal ( i );
207 WriteTabs ( file, depth );
209 file->Write ( key->GetKey(), key->GetKey().Length() );
210 file->Write ( " ", 1 );
212 idLexer src( key->GetValue(), key->GetValue().Length(), "", LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
213 src.ParseBracedSectionExact ( out, depth + 1);
215 file->Write ( out, out.Length() );
216 file->Write ( "\r\n", 2 );
217 file->Write ( "\r\n", 2 );
220 for ( i = 0; i < wrapper->GetChildCount(); i ++ )
222 idWindow* child = wrapper->GetChild ( i );
224 WriteWindow ( file, depth + 1, child );
228 WriteTabs ( file, depth - 1 );
231 file->Write ( out, out.Length() );
232 file->ForceFlush ( );
239 rvGEWorkspace::NewFile
241 Opens a new file for editing
244 bool rvGEWorkspace::NewFile ( void )
250 // Make a temporary file with nothing in it so we can just use
251 // load to do all the work
252 ospath = fileSystem->RelativePathToOSPath ( "guis/Untitled.guiednew", "fs_basepath" );
253 DeleteFile ( ospath );
255 file = fileSystem->OpenFileWrite ( "guis/Untitled.guiednew" );
261 empty = "windowDef Desktop { rect 0,0,640,480 }";
262 file->Write ( empty, empty.Length() );
263 fileSystem->CloseFile ( file );
265 // Load the temporary file
266 if ( !LoadFile ( ospath, NULL ) )
268 // Ensure the temp file doesnt hang around
269 DeleteFile ( ospath );
275 // Ensure the temp file doesnt hang around
276 DeleteFile ( ospath );
278 // Go back to using a .gui extensions
279 ospath.StripFileExtension ( );
280 ospath.Append ( ".gui" );
289 rvGEWorkspace::LoadFile
291 Loads the given gui file.
294 bool rvGEWorkspace::LoadFile ( const char* filename, idStr* error )
302 tempfile = "guis/temp.guied";
303 ospath = fileSystem->RelativePathToOSPath ( tempfile, "fs_basepath" );
305 // Make sure the gui directory exists
306 idStr createDir = ospath;
307 createDir.StripFilename ( );
308 CreateDirectory ( createDir, NULL );
310 SetFileAttributes ( ospath, FILE_ATTRIBUTE_NORMAL );
311 DeleteFile ( ospath );
312 if ( !CopyFile ( filename, ospath, FALSE ) )
316 *error = "File not found";
321 SetFileAttributes ( ospath, FILE_ATTRIBUTE_NORMAL );
323 mFilename = filename;
326 // Let the real window system parse it first
331 mInterface = reinterpret_cast< idUserInterfaceLocal* >( uiManager->FindGui( tempfile, true, true ) );
332 if ( !mInterface && error )
334 *error = "File not found";
337 catch ( idException& e )
349 rvGEWindowWrapper::GetWrapper ( mInterface->GetDesktop ( ) )->Expand ( );
353 DeleteFile ( ospath );
361 rvGEWorkspace::CheckIn
363 Checks in the current workspace file into source control
366 bool rvGEWorkspace::CheckIn ( void )
374 rvGEWorkspace::CheckOut
376 Checks out the current workspace file from source control
379 bool rvGEWorkspace::CheckOut ( void )
386 rvGEWorkspace::UndoCheckout
388 Undoes the checkout of the current file
391 bool rvGEWorkspace::UndoCheckout ( void )