Example #1
0
/*
================
DialogEntityDefEditor::OnBnClickedOk
================
*/
void DialogEntityDefEditor::OnBnClickedOk() {
	if ( decl ) {

		idStr declText;
		BuildDeclText(declText);

		if ( !TestDecl( declText ) ) {
			return;
		}

		if ( decl->SourceFileChanged() ) {
			if ( MessageBox( va( "Declaration file %s has been modified outside of the editor.\r\nReload declarations and save?", decl->GetFileName() ),
							va( "Warning saving: %s", decl->GetFileName() ), MB_OKCANCEL | MB_ICONERROR ) != IDOK ) {
				return;
			}
			declManager->Reload( false );
			DeclBrowserReloadDeclarations();
		}

		decl->SetText( declText );
		if ( !decl->ReplaceSourceFileText() ) {
			MessageBox( va( "Couldn't save: %s.\r\nMake sure the declaration file is not read-only.", decl->GetFileName() ),
						va( "Error saving: %s", decl->GetFileName() ), MB_OK | MB_ICONERROR );
			return;
		}
		decl->Invalidate();
	}

	okButton.EnableWindow( FALSE );
}
/*
================
DialogEntityDefEditor::OnBnClickedTest
================
*/
void DialogEntityDefEditor::OnBnClickedTest() {
	idStr declText, oldDeclText;
	if( decl ) {
		BuildDeclText( declText );
		if( !TestDecl( declText ) ) {
			return;
		}
		char *oldDeclText = ( char * )_alloca( ( decl->GetTextLength() + 1 ) * sizeof( char ) );
		decl->GetText( oldDeclText );
		decl->SetText( declText );
		decl->Invalidate();
		declManager->DeclByIndex( decl->GetType(), decl->Index(), true );
		decl->SetText( oldDeclText );
		decl->Invalidate();
		common->Printf( "tested %s\n", decl->GetName() );
		testButton.EnableWindow( FALSE );
	}
}