2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "debugging/debugging.h"
28 #include "stream/stringstream.h"
29 #include "versionlib.h"
31 #include "mainframe.h"
33 typedef std::map<CopiedString, CopiedString> Variables;
34 Variables g_build_variables;
36 void build_clear_variables(){
37 g_build_variables.clear();
40 void build_set_variable( const char* name, const char* value ){
41 g_build_variables[name] = value;
44 const char* build_get_variable( const char* name ){
45 Variables::iterator i = g_build_variables.find( name );
46 if ( i != g_build_variables.end() ) {
47 return ( *i ).second.c_str();
49 globalErrorStream() << "undefined build variable: " << makeQuoted( name ) << "\n";
54 #include "xml/xmlelement.h"
59 virtual ~Evaluatable() = default;
60 virtual void evaluate( StringBuffer& output ) = 0;
61 virtual void exportXML( XMLImporter& importer ) = 0;
64 class VariableString : public Evaluatable
66 CopiedString m_string;
68 VariableString() : m_string(){
70 VariableString( const char* string ) : m_string( string ){
72 const char* c_str() const {
73 return m_string.c_str();
75 void setString( const char* string ){
78 void evaluate( StringBuffer& output ){
79 #if !(GDEF_OS_WINDOWS)
80 // strip .[ExecutableType] entirely (including preceding dot) on Mac and Linux
83 const char *pattern = ".[ExecutableType]";
84 for ( const char *i = m_string.c_str(); *i != '\0'; ++i )
86 if ( strcmp( pattern, i ) == 0 )
88 output.push_string("");
89 i += strlen( pattern );
96 setString(output.c_str());
98 #endif // !(GDEF_OS_WINDOWS)
100 StringBuffer variable;
101 bool in_variable = false;
102 for ( const char* i = m_string.c_str(); *i != '\0'; ++i )
104 if ( !in_variable ) {
111 output.push_back( *i );
121 output.push_string( build_get_variable( variable.c_str() ) );
125 variable.push_back( *i );
131 void exportXML( XMLImporter& importer ){
136 class Conditional : public Evaluatable
138 VariableString* m_test;
140 Evaluatable* m_result;
141 Conditional( VariableString* test ) : m_test( test ){
147 void evaluate( StringBuffer& output ){
149 m_test->evaluate( buffer );
150 if ( !string_empty( buffer.c_str() ) ) {
151 m_result->evaluate( output );
154 void exportXML( XMLImporter& importer ){
155 StaticElement conditionElement( "cond" );
156 conditionElement.insertAttribute( "value", m_test->c_str() );
157 importer.pushElement( conditionElement );
158 m_result->exportXML( importer );
159 importer.popElement( conditionElement.name() );
163 typedef std::vector<Evaluatable*> Evaluatables;
165 class Tool : public Evaluatable
167 Evaluatables m_evaluatables;
170 for ( Evaluatables::iterator i = m_evaluatables.begin(); i != m_evaluatables.end(); ++i )
175 void push_back( Evaluatable* evaluatable ){
176 m_evaluatables.push_back( evaluatable );
178 void evaluate( StringBuffer& output ){
179 for ( Evaluatables::iterator i = m_evaluatables.begin(); i != m_evaluatables.end(); ++i )
181 ( *i )->evaluate( output );
184 void exportXML( XMLImporter& importer ){
185 for ( Evaluatables::iterator i = m_evaluatables.begin(); i != m_evaluatables.end(); ++i )
187 ( *i )->exportXML( importer );
192 #include "xml/ixml.h"
194 class XMLElementParser : public TextOutputStream
197 virtual ~XMLElementParser() = default;
198 virtual XMLElementParser& pushElement( const XMLElement& element ) = 0;
199 virtual void popElement( const char* name ) = 0;
202 class VariableStringXMLConstructor : public XMLElementParser
204 StringBuffer m_buffer;
205 VariableString& m_variableString;
207 VariableStringXMLConstructor( VariableString& variableString ) : m_variableString( variableString ){
209 ~VariableStringXMLConstructor(){
210 m_variableString.setString( m_buffer.c_str() );
212 std::size_t write( const char* buffer, std::size_t length ){
213 m_buffer.push_range( buffer, buffer + length );
216 XMLElementParser& pushElement( const XMLElement& element ){
217 ERROR_MESSAGE( "parse error: invalid element \"" << element.name() << "\"" );
220 void popElement( const char* name ){
224 class ConditionalXMLConstructor : public XMLElementParser
226 StringBuffer m_buffer;
227 Conditional& m_conditional;
229 ConditionalXMLConstructor( Conditional& conditional ) : m_conditional( conditional ){
231 ~ConditionalXMLConstructor(){
232 m_conditional.m_result = new VariableString( m_buffer.c_str() );
234 std::size_t write( const char* buffer, std::size_t length ){
235 m_buffer.push_range( buffer, buffer + length );
238 XMLElementParser& pushElement( const XMLElement& element ){
239 ERROR_MESSAGE( "parse error: invalid element \"" << element.name() << "\"" );
242 void popElement( const char* name ){
246 class ToolXMLConstructor : public XMLElementParser
248 StringBuffer m_buffer;
250 ConditionalXMLConstructor* m_conditional;
252 ToolXMLConstructor( Tool& tool ) : m_tool( tool ){
254 ~ToolXMLConstructor(){
257 std::size_t write( const char* buffer, std::size_t length ){
258 m_buffer.push_range( buffer, buffer + length );
261 XMLElementParser& pushElement( const XMLElement& element ){
262 if ( string_equal( element.name(), "cond" ) ) {
264 Conditional* conditional = new Conditional( new VariableString( element.attribute( "value" ) ) );
265 m_tool.push_back( conditional );
266 m_conditional = new ConditionalXMLConstructor( *conditional );
267 return *m_conditional;
271 ERROR_MESSAGE( "parse error: invalid element \"" << element.name() << "\"" );
275 void popElement( const char* name ){
276 if ( string_equal( name, "cond" ) ) {
277 delete m_conditional;
282 if ( !m_buffer.empty() ) {
283 m_tool.push_back( new VariableString( m_buffer.c_str() ) );
289 typedef VariableString BuildCommand;
290 typedef std::list<BuildCommand> Build;
292 class BuildXMLConstructor : public XMLElementParser
294 VariableStringXMLConstructor* m_variableString;
297 BuildXMLConstructor( Build& build ) : m_build( build ){
299 std::size_t write( const char* buffer, std::size_t length ){
302 XMLElementParser& pushElement( const XMLElement& element ){
303 if ( string_equal( element.name(), "command" ) ) {
304 m_build.push_back( BuildCommand() );
305 m_variableString = new VariableStringXMLConstructor( m_build.back() );
306 return *m_variableString;
310 ERROR_MESSAGE( "parse error: invalid element" );
314 void popElement( const char* name ){
315 delete m_variableString;
319 typedef std::pair<CopiedString, Build> BuildPair;
320 const char *SEPARATOR_STRING = "-";
321 static bool is_separator( const BuildPair &p ){
322 if ( !string_equal( p.first.c_str(), SEPARATOR_STRING ) ) {
325 for ( Build::const_iterator j = p.second.begin(); j != p.second.end(); ++j )
327 if ( !string_equal( ( *j ).c_str(), "" ) ) {
335 typedef std::list<BuildPair> Project;
337 Project::iterator Project_find( Project& project, const char* name ){
338 return std::find_if(project.begin(), project.end(), [&](const BuildPair &self) {
339 return string_equal(self.first.c_str(), name);
343 Project::iterator Project_find( Project& project, std::size_t index ){
344 Project::iterator i = project.begin();
345 while ( index-- != 0 && i != project.end() )
352 Build& project_find( Project& project, const char* build ){
353 Project::iterator i = Project_find( project, build );
354 ASSERT_MESSAGE( i != project.end(), "error finding build command" );
355 return ( *i ).second;
358 Build::iterator Build_find( Build& build, std::size_t index ){
359 Build::iterator i = build.begin();
360 while ( index-- != 0 && i != build.end() )
367 typedef std::map<CopiedString, Tool> Tools;
369 class ProjectXMLConstructor : public XMLElementParser
371 ToolXMLConstructor* m_tool;
372 BuildXMLConstructor* m_build;
376 ProjectXMLConstructor( Project& project, Tools& tools ) : m_project( project ), m_tools( tools ){
378 std::size_t write( const char* buffer, std::size_t length ){
381 XMLElementParser& pushElement( const XMLElement& element ){
382 if ( string_equal( element.name(), "var" ) ) {
383 Tools::iterator i = m_tools.insert( Tools::value_type( element.attribute( "name" ), Tool() ) ).first;
384 m_tool = new ToolXMLConstructor( ( *i ).second );
387 else if ( string_equal( element.name(), "build" ) ) {
388 m_project.push_back( Project::value_type( element.attribute( "name" ), Build() ) );
389 m_build = new BuildXMLConstructor( m_project.back().second );
392 else if ( string_equal( element.name(), "separator" ) ) {
393 m_project.push_back( Project::value_type( SEPARATOR_STRING, Build() ) );
398 ERROR_MESSAGE( "parse error: invalid element" );
402 void popElement( const char* name ){
403 if ( string_equal( name, "var" ) ) {
406 else if ( string_equal( name, "build" ) ) {
412 class SkipAllParser : public XMLElementParser
415 std::size_t write( const char* buffer, std::size_t length ){
418 XMLElementParser& pushElement( const XMLElement& element ){
421 void popElement( const char* name ){
425 class RootXMLConstructor : public XMLElementParser
427 CopiedString m_elementName;
428 XMLElementParser& m_parser;
429 SkipAllParser m_skip;
433 RootXMLConstructor( const char* elementName, XMLElementParser& parser, const char* version ) :
434 m_elementName( elementName ),
436 m_version( version_parse( version ) ),
437 m_compatible( false ){
439 std::size_t write( const char* buffer, std::size_t length ){
442 XMLElementParser& pushElement( const XMLElement& element ){
443 if ( string_equal( element.name(), m_elementName.c_str() ) ) {
444 Version dataVersion( version_parse( element.attribute( "version" ) ) );
445 if ( version_compatible( m_version, dataVersion ) ) {
456 //ERROR_MESSAGE("parse error: invalid element \"" << element.name() << "\"");
460 void popElement( const char* name ){
463 bool versionCompatible() const {
470 Project g_build_project;
472 bool g_build_changed = false;
475 void build_error_undefined_tool( const char* build, const char* tool ){
476 globalErrorStream() << "build " << makeQuoted( build ) << " refers to undefined tool " << makeQuoted( tool ) << '\n';
479 void project_verify( Project& project, Tools& tools ){
481 for ( Project::iterator i = project.begin(); i != project.end(); ++i )
483 Build& build = ( *i ).second;
484 for ( Build::iterator j = build.begin(); j != build.end(); ++j )
486 Tools::iterator k = tools.find( ( *j ).first );
487 if ( k == g_build_tools.end() ) {
488 build_error_undefined_tool( ( *i ).first.c_str(), ( *j ).first.c_str() );
495 void build_run( const char* name, CommandListener& listener ){
496 for ( Tools::iterator i = g_build_tools.begin(); i != g_build_tools.end(); ++i )
499 ( *i ).second.evaluate( output );
500 build_set_variable( ( *i ).first.c_str(), output.c_str() );
504 Project::iterator i = Project_find( g_build_project, name );
505 if ( i != g_build_project.end() ) {
506 Build& build = ( *i ).second;
507 for ( Build::iterator j = build.begin(); j != build.end(); ++j )
510 ( *j ).evaluate( output );
511 listener.execute( output.c_str() );
516 globalErrorStream() << "build " << makeQuoted( name ) << " not defined";
522 typedef std::vector<XMLElementParser*> XMLElementStack;
524 class XMLParser : public XMLImporter
526 XMLElementStack m_stack;
528 XMLParser( XMLElementParser& parser ){
529 m_stack.push_back( &parser );
531 std::size_t write( const char* buffer, std::size_t length ){
532 return m_stack.back()->write( buffer, length );
534 void pushElement( const XMLElement& element ){
535 m_stack.push_back( &m_stack.back()->pushElement( element ) );
537 void popElement( const char* name ){
539 m_stack.back()->popElement( name );
543 #include "stream/textfilestream.h"
544 #include "xml/xmlparser.h"
546 const char* const BUILDMENU_VERSION = "2.0";
548 bool build_commands_parse( const char* filename ){
549 TextFileInputStream projectFile( filename );
550 if ( !projectFile.failed() ) {
551 ProjectXMLConstructor projectConstructor( g_build_project, g_build_tools );
552 RootXMLConstructor rootConstructor( "project", projectConstructor, BUILDMENU_VERSION );
553 XMLParser importer( rootConstructor );
554 XMLStreamParser parser( projectFile );
555 parser.exportXML( importer );
557 if ( rootConstructor.versionCompatible() ) {
558 project_verify( g_build_project, g_build_tools );
562 globalErrorStream() << "failed to parse build menu: " << makeQuoted( filename ) << "\n";
567 void build_commands_clear(){
568 g_build_project.clear();
569 g_build_tools.clear();
572 class BuildXMLExporter
576 BuildXMLExporter( Build& build ) : m_build( build ){
578 void exportXML( XMLImporter& importer ){
580 for ( Build::iterator i = m_build.begin(); i != m_build.end(); ++i )
582 StaticElement commandElement( "command" );
583 importer.pushElement( commandElement );
584 ( *i ).exportXML( importer );
585 importer.popElement( commandElement.name() );
591 class ProjectXMLExporter
596 ProjectXMLExporter( Project& project, Tools& tools ) : m_project( project ), m_tools( tools ){
598 void exportXML( XMLImporter& importer ){
599 StaticElement projectElement( "project" );
600 projectElement.insertAttribute( "version", BUILDMENU_VERSION );
601 importer.pushElement( projectElement );
604 for ( Tools::iterator i = m_tools.begin(); i != m_tools.end(); ++i )
606 StaticElement toolElement( "var" );
607 toolElement.insertAttribute( "name", ( *i ).first.c_str() );
608 importer.pushElement( toolElement );
609 ( *i ).second.exportXML( importer );
610 importer.popElement( toolElement.name() );
613 for ( Project::iterator i = m_project.begin(); i != m_project.end(); ++i )
615 if ( is_separator( *i ) ) {
616 StaticElement buildElement( "separator" );
617 importer.pushElement( buildElement );
618 importer.popElement( buildElement.name() );
623 StaticElement buildElement( "build" );
624 buildElement.insertAttribute( "name", ( *i ).first.c_str() );
625 importer.pushElement( buildElement );
626 BuildXMLExporter buildExporter( ( *i ).second );
627 buildExporter.exportXML( importer );
628 importer.popElement( buildElement.name() );
632 importer.popElement( projectElement.name() );
636 #include "xml/xmlwriter.h"
638 void build_commands_write( const char* filename ){
639 TextFileOutputStream projectFile( filename );
640 if ( !projectFile.failed() ) {
641 XMLStreamWriter writer( projectFile );
642 ProjectXMLExporter projectExporter( g_build_project, g_build_tools );
644 projectExporter.exportXML( writer );
650 #include <gdk/gdkkeysyms.h>
652 #include "gtkutil/dialog.h"
653 #include "gtkutil/closure.h"
654 #include "gtkutil/window.h"
657 void Build_refreshMenu( ui::Menu menu );
660 void BSPCommandList_Construct( ui::ListStore store, Project& project ){
663 for ( Project::iterator i = project.begin(); i != project.end(); ++i )
665 store.append(0, (*i).first.c_str());
675 ui::ListStore m_store{ui::null};
677 ProjectList( Project& project ) : m_project( project ), m_changed( false ){
681 gboolean project_cell_edited(ui::CellRendererText cell, gchar* path_string, gchar* new_text, ProjectList* projectList ){
682 Project& project = projectList->m_project;
684 auto path = ui::TreePath( path_string );
686 ASSERT_MESSAGE( gtk_tree_path_get_depth( path ) == 1, "invalid path length" );
689 gtk_tree_model_get_iter(projectList->m_store, &iter, path );
691 Project::iterator i = Project_find( project, gtk_tree_path_get_indices( path )[0] );
692 if ( i != project.end() ) {
693 projectList->m_changed = true;
694 if ( string_empty( new_text ) ) {
696 gtk_list_store_remove( projectList->m_store, &iter );
700 ( *i ).first = new_text;
701 gtk_list_store_set( projectList->m_store, &iter, 0, new_text, -1 );
704 else if ( !string_empty( new_text ) ) {
705 projectList->m_changed = true;
706 project.push_back( Project::value_type( new_text, Build() ) );
708 gtk_list_store_set( projectList->m_store, &iter, 0, new_text, -1 );
709 projectList->m_store.append();
712 gtk_tree_path_free( path );
714 Build_refreshMenu( g_bsp_menu );
719 gboolean project_key_press( ui::TreeView widget, GdkEventKey* event, ProjectList* projectList ){
720 Project& project = projectList->m_project;
722 if ( event->keyval == GDK_KEY_Delete ) {
723 auto selection = ui::TreeSelection::from(gtk_tree_view_get_selection(widget));
726 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) ) {
727 auto path = gtk_tree_model_get_path( model, &iter );
728 Project::iterator x = Project_find( project, gtk_tree_path_get_indices( path )[0] );
729 gtk_tree_path_free( path );
731 if ( x != project.end() ) {
732 projectList->m_changed = true;
734 Build_refreshMenu( g_bsp_menu );
736 gtk_list_store_remove( projectList->m_store, &iter );
744 Build* g_current_build = 0;
746 gboolean project_selection_changed( ui::TreeSelection selection, ui::ListStore store ){
747 Project& project = g_build_project;
753 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) ) {
754 auto path = gtk_tree_model_get_path( model, &iter );
755 Project::iterator x = Project_find( project, gtk_tree_path_get_indices( path )[0] );
756 gtk_tree_path_free( path );
758 if ( x != project.end() ) {
759 Build& build = ( *x ).second;
760 g_current_build = &build;
762 for ( Build::iterator i = build.begin(); i != build.end(); ++i )
764 store.append(0, (*i).c_str());
781 gboolean commands_cell_edited(ui::CellRendererText cell, gchar* path_string, gchar* new_text, ui::ListStore store ){
782 if ( g_current_build == 0 ) {
785 Build& build = *g_current_build;
787 auto path = ui::TreePath( path_string );
789 ASSERT_MESSAGE( gtk_tree_path_get_depth( path ) == 1, "invalid path length" );
792 gtk_tree_model_get_iter(store, &iter, path );
794 Build::iterator i = Build_find( build, gtk_tree_path_get_indices( path )[0] );
795 if ( i != build.end() ) {
796 g_build_changed = true;
797 ( *i ).setString( new_text );
799 gtk_list_store_set( store, &iter, 0, new_text, -1 );
801 else if ( !string_empty( new_text ) ) {
802 g_build_changed = true;
803 build.push_back( Build::value_type( VariableString( new_text ) ) );
805 gtk_list_store_set( store, &iter, 0, new_text, -1 );
810 gtk_tree_path_free( path );
812 Build_refreshMenu( g_bsp_menu );
817 gboolean commands_key_press( ui::TreeView widget, GdkEventKey* event, ui::ListStore store ){
818 if ( g_current_build == 0 ) {
821 Build& build = *g_current_build;
823 if ( event->keyval == GDK_KEY_Delete ) {
824 auto selection = gtk_tree_view_get_selection(widget );
827 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) ) {
828 auto path = gtk_tree_model_get_path( model, &iter );
829 Build::iterator i = Build_find( build, gtk_tree_path_get_indices( path )[0] );
830 gtk_tree_path_free( path );
832 if ( i != build.end() ) {
833 g_build_changed = true;
836 gtk_list_store_remove( store, &iter );
844 ui::Window BuildMenuDialog_construct( ModalDialog& modal, ProjectList& projectList ){
845 ui::Window window = MainFrame_getWindow().create_dialog_window("Build Menu", G_CALLBACK(dialog_delete_callback ), &modal, -1, 400 );
848 auto table1 = create_dialog_table( 2, 2, 4, 4, 4 );
851 auto vbox = create_dialog_vbox( 4 );
852 table1.attach(vbox, {1, 2, 0, 1}, {GTK_FILL, GTK_FILL});
854 auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &modal );
855 vbox.pack_start( button, FALSE, FALSE, 0 );
858 auto button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &modal );
859 vbox.pack_start( button, FALSE, FALSE, 0 );
862 auto buildViewStore = ui::ListStore::from(gtk_list_store_new( 1, G_TYPE_STRING ));
863 auto buildView = ui::TreeView( ui::TreeModel::from( buildViewStore._handle ));
865 auto frame = create_dialog_frame( "Build menu" );
866 table1.attach(frame, {0, 1, 0, 1});
868 auto scr = create_scrolled_window( ui::Policy::NEVER, ui::Policy::AUTOMATIC, 4 );
872 auto view = buildView;
873 auto store = buildViewStore;
874 gtk_tree_view_set_headers_visible(view, FALSE );
876 auto renderer = ui::CellRendererText(ui::New);
877 object_set_boolean_property( G_OBJECT( renderer ), "editable", TRUE );
878 renderer.connect("edited", G_CALLBACK( project_cell_edited ), &projectList );
880 auto column = ui::TreeViewColumn( "", renderer, {{"text", 0}} );
881 gtk_tree_view_append_column(view, column );
883 auto selection = gtk_tree_view_get_selection(view );
884 gtk_tree_selection_set_mode( selection, GTK_SELECTION_BROWSE );
888 projectList.m_store = store;
891 view.connect( "key_press_event", G_CALLBACK( project_key_press ), &projectList );
898 auto frame = create_dialog_frame( "Commandline" );
899 table1.attach(frame, {0, 1, 1, 2});
901 auto scr = create_scrolled_window( ui::Policy::NEVER, ui::Policy::AUTOMATIC, 4 );
905 auto store = ui::ListStore::from(gtk_list_store_new( 1, G_TYPE_STRING ));
907 auto view = ui::TreeView(ui::TreeModel::from( store._handle ));
908 gtk_tree_view_set_headers_visible(view, FALSE );
910 auto renderer = ui::CellRendererText(ui::New);
911 object_set_boolean_property( G_OBJECT( renderer ), "editable", TRUE );
912 renderer.connect( "edited", G_CALLBACK( commands_cell_edited ), store );
914 auto column = ui::TreeViewColumn( "", renderer, {{"text", 0}} );
915 gtk_tree_view_append_column(view, column );
917 auto selection = gtk_tree_view_get_selection(view );
918 gtk_tree_selection_set_mode( selection, GTK_SELECTION_BROWSE );
926 view.connect( "key_press_event", G_CALLBACK( commands_key_press ), store );
928 auto sel = ui::TreeSelection::from(gtk_tree_view_get_selection(buildView ));
929 sel.connect( "changed", G_CALLBACK( project_selection_changed ), store );
935 BSPCommandList_Construct( projectList.m_store, g_build_project );
942 CopiedString g_buildMenu;
945 void LoadBuildMenu();
950 ProjectList projectList( g_build_project );
952 ui::Window window = BuildMenuDialog_construct( modal, projectList );
954 if ( modal_dialog_show( window, modal ) == eIDCANCEL ) {
955 build_commands_clear();
958 Build_refreshMenu( g_bsp_menu );
960 else if ( projectList.m_changed ) {
961 g_build_changed = true;
969 #include "gtkutil/menu.h"
970 #include "mainframe.h"
971 #include "preferences.h"
979 BuildMenuItem( const char* name, ui::MenuItem item )
980 : m_name( name ), m_item( item ){
985 typedef MemberCaller<BuildMenuItem, void(), &BuildMenuItem::run> RunCaller;
988 typedef std::list<BuildMenuItem> BuildMenuItems;
989 BuildMenuItems g_BuildMenuItems;
992 ui::Menu g_bsp_menu{ui::null};
994 void Build_constructMenu( ui::Menu menu ){
995 for ( Project::iterator i = g_build_project.begin(); i != g_build_project.end(); ++i )
997 g_BuildMenuItems.push_back( BuildMenuItem( ( *i ).first.c_str(), ui::MenuItem(ui::null) ) );
998 if ( is_separator( *i ) ) {
999 g_BuildMenuItems.back().m_item = menu_separator( menu );
1003 g_BuildMenuItems.back().m_item = create_menu_item_with_mnemonic( menu, ( *i ).first.c_str(), BuildMenuItem::RunCaller( g_BuildMenuItems.back() ) );
1009 void Build_refreshMenu( ui::Menu menu ){
1010 for (auto i = g_BuildMenuItems.begin(); i != g_BuildMenuItems.end(); ++i )
1012 menu.remove(ui::MenuItem(i->m_item));
1015 g_BuildMenuItems.clear();
1017 Build_constructMenu( menu );
1021 void LoadBuildMenu(){
1022 if ( string_empty( g_buildMenu.c_str() ) || !build_commands_parse( g_buildMenu.c_str() ) ) {
1024 StringOutputStream buffer( 256 );
1025 buffer << GameToolsPath_get() << "default_build_menu.xml";
1027 bool success = build_commands_parse( buffer.c_str() );
1028 ASSERT_MESSAGE( success, "failed to parse default build commands: " << buffer.c_str() );
1031 StringOutputStream buffer( 256 );
1032 buffer << SettingsPath_get() << g_pGameDescription->mGameFile.c_str() << "/build_menu.xml";
1034 g_buildMenu = buffer.c_str();
1039 void SaveBuildMenu(){
1040 if ( g_build_changed ) {
1041 g_build_changed = false;
1042 build_commands_write( g_buildMenu.c_str() );
1046 #include "preferencesystem.h"
1047 #include "stringio.h"
1049 void BuildMenu_Construct(){
1050 GlobalPreferenceSystem().registerPreference( "BuildMenu", make_property_string( g_buildMenu ) );
1053 void BuildMenu_Destroy(){