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 // replace ".[ExecutableType]" with "[ExecutableExt]"
82 const char *pattern = ".[ExecutableType]";
83 for ( const char *i = m_string.c_str(); *i != '\0'; ++i )
85 if ( strncmp( pattern, i, sizeof( pattern ) ) == 0 )
87 output.push_string("[ExecutableExt]");
88 i += strlen( pattern ) - 1;
95 setString(output.c_str());
98 StringBuffer variable;
99 bool in_variable = false;
100 for ( const char* i = m_string.c_str(); *i != '\0'; ++i )
102 if ( !in_variable ) {
109 output.push_back( *i );
119 output.push_string( build_get_variable( variable.c_str() ) );
123 variable.push_back( *i );
129 void exportXML( XMLImporter& importer ){
134 class Conditional : public Evaluatable
136 VariableString* m_test;
138 Evaluatable* m_result;
139 Conditional( VariableString* test ) : m_test( test ){
145 void evaluate( StringBuffer& output ){
147 m_test->evaluate( buffer );
148 if ( !string_empty( buffer.c_str() ) ) {
149 m_result->evaluate( output );
152 void exportXML( XMLImporter& importer ){
153 StaticElement conditionElement( "cond" );
154 conditionElement.insertAttribute( "value", m_test->c_str() );
155 importer.pushElement( conditionElement );
156 m_result->exportXML( importer );
157 importer.popElement( conditionElement.name() );
161 typedef std::vector<Evaluatable*> Evaluatables;
163 class Tool : public Evaluatable
165 Evaluatables m_evaluatables;
168 for ( Evaluatables::iterator i = m_evaluatables.begin(); i != m_evaluatables.end(); ++i )
173 void push_back( Evaluatable* evaluatable ){
174 m_evaluatables.push_back( evaluatable );
176 void evaluate( StringBuffer& output ){
177 for ( Evaluatables::iterator i = m_evaluatables.begin(); i != m_evaluatables.end(); ++i )
179 ( *i )->evaluate( output );
182 void exportXML( XMLImporter& importer ){
183 for ( Evaluatables::iterator i = m_evaluatables.begin(); i != m_evaluatables.end(); ++i )
185 ( *i )->exportXML( importer );
190 #include "xml/ixml.h"
192 class XMLElementParser : public TextOutputStream
195 virtual ~XMLElementParser() = default;
196 virtual XMLElementParser& pushElement( const XMLElement& element ) = 0;
197 virtual void popElement( const char* name ) = 0;
200 class VariableStringXMLConstructor : public XMLElementParser
202 StringBuffer m_buffer;
203 VariableString& m_variableString;
205 VariableStringXMLConstructor( VariableString& variableString ) : m_variableString( variableString ){
207 ~VariableStringXMLConstructor(){
208 m_variableString.setString( m_buffer.c_str() );
210 std::size_t write( const char* buffer, std::size_t length ){
211 m_buffer.push_range( buffer, buffer + length );
214 XMLElementParser& pushElement( const XMLElement& element ){
215 ERROR_MESSAGE( "parse error: invalid element \"" << element.name() << "\"" );
218 void popElement( const char* name ){
222 class ConditionalXMLConstructor : public XMLElementParser
224 StringBuffer m_buffer;
225 Conditional& m_conditional;
227 ConditionalXMLConstructor( Conditional& conditional ) : m_conditional( conditional ){
229 ~ConditionalXMLConstructor(){
230 m_conditional.m_result = new VariableString( m_buffer.c_str() );
232 std::size_t write( const char* buffer, std::size_t length ){
233 m_buffer.push_range( buffer, buffer + length );
236 XMLElementParser& pushElement( const XMLElement& element ){
237 ERROR_MESSAGE( "parse error: invalid element \"" << element.name() << "\"" );
240 void popElement( const char* name ){
244 class ToolXMLConstructor : public XMLElementParser
246 StringBuffer m_buffer;
248 ConditionalXMLConstructor* m_conditional;
250 ToolXMLConstructor( Tool& tool ) : m_tool( tool ){
252 ~ToolXMLConstructor(){
255 std::size_t write( const char* buffer, std::size_t length ){
256 m_buffer.push_range( buffer, buffer + length );
259 XMLElementParser& pushElement( const XMLElement& element ){
260 if ( string_equal( element.name(), "cond" ) ) {
262 Conditional* conditional = new Conditional( new VariableString( element.attribute( "value" ) ) );
263 m_tool.push_back( conditional );
264 m_conditional = new ConditionalXMLConstructor( *conditional );
265 return *m_conditional;
269 ERROR_MESSAGE( "parse error: invalid element \"" << element.name() << "\"" );
273 void popElement( const char* name ){
274 if ( string_equal( name, "cond" ) ) {
275 delete m_conditional;
280 if ( !m_buffer.empty() ) {
281 m_tool.push_back( new VariableString( m_buffer.c_str() ) );
287 typedef VariableString BuildCommand;
288 typedef std::list<BuildCommand> Build;
290 class BuildXMLConstructor : public XMLElementParser
292 VariableStringXMLConstructor* m_variableString;
295 BuildXMLConstructor( Build& build ) : m_build( build ){
297 std::size_t write( const char* buffer, std::size_t length ){
300 XMLElementParser& pushElement( const XMLElement& element ){
301 if ( string_equal( element.name(), "command" ) ) {
302 m_build.push_back( BuildCommand() );
303 m_variableString = new VariableStringXMLConstructor( m_build.back() );
304 return *m_variableString;
308 ERROR_MESSAGE( "parse error: invalid element" );
312 void popElement( const char* name ){
313 delete m_variableString;
317 typedef std::pair<CopiedString, Build> BuildPair;
318 const char *SEPARATOR_STRING = "-";
319 static bool is_separator( const BuildPair &p ){
320 if ( !string_equal( p.first.c_str(), SEPARATOR_STRING ) ) {
323 for ( Build::const_iterator j = p.second.begin(); j != p.second.end(); ++j )
325 if ( !string_equal( ( *j ).c_str(), "" ) ) {
333 typedef std::list<BuildPair> Project;
335 Project::iterator Project_find( Project& project, const char* name ){
336 return std::find_if(project.begin(), project.end(), [&](const BuildPair &self) {
337 return string_equal(self.first.c_str(), name);
341 Project::iterator Project_find( Project& project, std::size_t index ){
342 Project::iterator i = project.begin();
343 while ( index-- != 0 && i != project.end() )
350 Build& project_find( Project& project, const char* build ){
351 Project::iterator i = Project_find( project, build );
352 ASSERT_MESSAGE( i != project.end(), "error finding build command" );
353 return ( *i ).second;
356 Build::iterator Build_find( Build& build, std::size_t index ){
357 Build::iterator i = build.begin();
358 while ( index-- != 0 && i != build.end() )
365 typedef std::map<CopiedString, Tool> Tools;
367 class ProjectXMLConstructor : public XMLElementParser
369 ToolXMLConstructor* m_tool;
370 BuildXMLConstructor* m_build;
374 ProjectXMLConstructor( Project& project, Tools& tools ) : m_project( project ), m_tools( tools ){
376 std::size_t write( const char* buffer, std::size_t length ){
379 XMLElementParser& pushElement( const XMLElement& element ){
380 if ( string_equal( element.name(), "var" ) ) {
381 Tools::iterator i = m_tools.insert( Tools::value_type( element.attribute( "name" ), Tool() ) ).first;
382 m_tool = new ToolXMLConstructor( ( *i ).second );
385 else if ( string_equal( element.name(), "build" ) ) {
386 m_project.push_back( Project::value_type( element.attribute( "name" ), Build() ) );
387 m_build = new BuildXMLConstructor( m_project.back().second );
390 else if ( string_equal( element.name(), "separator" ) ) {
391 m_project.push_back( Project::value_type( SEPARATOR_STRING, Build() ) );
396 ERROR_MESSAGE( "parse error: invalid element" );
400 void popElement( const char* name ){
401 if ( string_equal( name, "var" ) ) {
404 else if ( string_equal( name, "build" ) ) {
410 class SkipAllParser : public XMLElementParser
413 std::size_t write( const char* buffer, std::size_t length ){
416 XMLElementParser& pushElement( const XMLElement& element ){
419 void popElement( const char* name ){
423 class RootXMLConstructor : public XMLElementParser
425 CopiedString m_elementName;
426 XMLElementParser& m_parser;
427 SkipAllParser m_skip;
431 RootXMLConstructor( const char* elementName, XMLElementParser& parser, const char* version ) :
432 m_elementName( elementName ),
434 m_version( version_parse( version ) ),
435 m_compatible( false ){
437 std::size_t write( const char* buffer, std::size_t length ){
440 XMLElementParser& pushElement( const XMLElement& element ){
441 if ( string_equal( element.name(), m_elementName.c_str() ) ) {
442 Version dataVersion( version_parse( element.attribute( "version" ) ) );
443 if ( version_compatible( m_version, dataVersion ) ) {
454 //ERROR_MESSAGE("parse error: invalid element \"" << element.name() << "\"");
458 void popElement( const char* name ){
461 bool versionCompatible() const {
468 Project g_build_project;
470 bool g_build_changed = false;
473 void build_error_undefined_tool( const char* build, const char* tool ){
474 globalErrorStream() << "build " << makeQuoted( build ) << " refers to undefined tool " << makeQuoted( tool ) << '\n';
477 void project_verify( Project& project, Tools& tools ){
479 for ( Project::iterator i = project.begin(); i != project.end(); ++i )
481 Build& build = ( *i ).second;
482 for ( Build::iterator j = build.begin(); j != build.end(); ++j )
484 Tools::iterator k = tools.find( ( *j ).first );
485 if ( k == g_build_tools.end() ) {
486 build_error_undefined_tool( ( *i ).first.c_str(), ( *j ).first.c_str() );
493 void build_run( const char* name, CommandListener& listener ){
494 for ( Tools::iterator i = g_build_tools.begin(); i != g_build_tools.end(); ++i )
497 ( *i ).second.evaluate( output );
498 build_set_variable( ( *i ).first.c_str(), output.c_str() );
502 Project::iterator i = Project_find( g_build_project, name );
503 if ( i != g_build_project.end() ) {
504 Build& build = ( *i ).second;
505 for ( Build::iterator j = build.begin(); j != build.end(); ++j )
508 ( *j ).evaluate( output );
509 listener.execute( output.c_str() );
514 globalErrorStream() << "build " << makeQuoted( name ) << " not defined";
520 typedef std::vector<XMLElementParser*> XMLElementStack;
522 class XMLParser : public XMLImporter
524 XMLElementStack m_stack;
526 XMLParser( XMLElementParser& parser ){
527 m_stack.push_back( &parser );
529 std::size_t write( const char* buffer, std::size_t length ){
530 return m_stack.back()->write( buffer, length );
532 void pushElement( const XMLElement& element ){
533 m_stack.push_back( &m_stack.back()->pushElement( element ) );
535 void popElement( const char* name ){
537 m_stack.back()->popElement( name );
541 #include "stream/textfilestream.h"
542 #include "xml/xmlparser.h"
544 const char* const BUILDMENU_VERSION = "2.0";
546 bool build_commands_parse( const char* filename ){
547 TextFileInputStream projectFile( filename );
548 if ( !projectFile.failed() ) {
549 ProjectXMLConstructor projectConstructor( g_build_project, g_build_tools );
550 RootXMLConstructor rootConstructor( "project", projectConstructor, BUILDMENU_VERSION );
551 XMLParser importer( rootConstructor );
552 XMLStreamParser parser( projectFile );
553 parser.exportXML( importer );
555 if ( rootConstructor.versionCompatible() ) {
556 project_verify( g_build_project, g_build_tools );
560 globalErrorStream() << "failed to parse build menu: " << makeQuoted( filename ) << "\n";
565 void build_commands_clear(){
566 g_build_project.clear();
567 g_build_tools.clear();
570 class BuildXMLExporter
574 BuildXMLExporter( Build& build ) : m_build( build ){
576 void exportXML( XMLImporter& importer ){
578 for ( Build::iterator i = m_build.begin(); i != m_build.end(); ++i )
580 StaticElement commandElement( "command" );
581 importer.pushElement( commandElement );
582 ( *i ).exportXML( importer );
583 importer.popElement( commandElement.name() );
589 class ProjectXMLExporter
594 ProjectXMLExporter( Project& project, Tools& tools ) : m_project( project ), m_tools( tools ){
596 void exportXML( XMLImporter& importer ){
597 StaticElement projectElement( "project" );
598 projectElement.insertAttribute( "version", BUILDMENU_VERSION );
599 importer.pushElement( projectElement );
602 for ( Tools::iterator i = m_tools.begin(); i != m_tools.end(); ++i )
604 StaticElement toolElement( "var" );
605 toolElement.insertAttribute( "name", ( *i ).first.c_str() );
606 importer.pushElement( toolElement );
607 ( *i ).second.exportXML( importer );
608 importer.popElement( toolElement.name() );
611 for ( Project::iterator i = m_project.begin(); i != m_project.end(); ++i )
613 if ( is_separator( *i ) ) {
614 StaticElement buildElement( "separator" );
615 importer.pushElement( buildElement );
616 importer.popElement( buildElement.name() );
621 StaticElement buildElement( "build" );
622 buildElement.insertAttribute( "name", ( *i ).first.c_str() );
623 importer.pushElement( buildElement );
624 BuildXMLExporter buildExporter( ( *i ).second );
625 buildExporter.exportXML( importer );
626 importer.popElement( buildElement.name() );
630 importer.popElement( projectElement.name() );
634 #include "xml/xmlwriter.h"
636 void build_commands_write( const char* filename ){
637 TextFileOutputStream projectFile( filename );
638 if ( !projectFile.failed() ) {
639 XMLStreamWriter writer( projectFile );
640 ProjectXMLExporter projectExporter( g_build_project, g_build_tools );
642 projectExporter.exportXML( writer );
648 #include <gdk/gdkkeysyms.h>
650 #include "gtkutil/dialog.h"
651 #include "gtkutil/closure.h"
652 #include "gtkutil/window.h"
655 void Build_refreshMenu( ui::Menu menu );
658 void BSPCommandList_Construct( ui::ListStore store, Project& project ){
661 for ( Project::iterator i = project.begin(); i != project.end(); ++i )
663 store.append(0, (*i).first.c_str());
673 ui::ListStore m_store{ui::null};
675 ProjectList( Project& project ) : m_project( project ), m_changed( false ){
679 gboolean project_cell_edited(ui::CellRendererText cell, gchar* path_string, gchar* new_text, ProjectList* projectList ){
680 Project& project = projectList->m_project;
682 auto path = ui::TreePath( path_string );
684 ASSERT_MESSAGE( gtk_tree_path_get_depth( path ) == 1, "invalid path length" );
687 gtk_tree_model_get_iter(projectList->m_store, &iter, path );
689 Project::iterator i = Project_find( project, gtk_tree_path_get_indices( path )[0] );
690 if ( i != project.end() ) {
691 projectList->m_changed = true;
692 if ( string_empty( new_text ) ) {
694 gtk_list_store_remove( projectList->m_store, &iter );
698 ( *i ).first = new_text;
699 gtk_list_store_set( projectList->m_store, &iter, 0, new_text, -1 );
702 else if ( !string_empty( new_text ) ) {
703 projectList->m_changed = true;
704 project.push_back( Project::value_type( new_text, Build() ) );
706 gtk_list_store_set( projectList->m_store, &iter, 0, new_text, -1 );
707 projectList->m_store.append();
710 gtk_tree_path_free( path );
712 Build_refreshMenu( g_bsp_menu );
717 gboolean project_key_press( ui::TreeView widget, GdkEventKey* event, ProjectList* projectList ){
718 Project& project = projectList->m_project;
720 if ( event->keyval == GDK_KEY_Delete ) {
721 auto selection = ui::TreeSelection::from(gtk_tree_view_get_selection(widget));
724 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) ) {
725 auto path = gtk_tree_model_get_path( model, &iter );
726 Project::iterator x = Project_find( project, gtk_tree_path_get_indices( path )[0] );
727 gtk_tree_path_free( path );
729 if ( x != project.end() ) {
730 projectList->m_changed = true;
732 Build_refreshMenu( g_bsp_menu );
734 gtk_list_store_remove( projectList->m_store, &iter );
742 Build* g_current_build = 0;
744 gboolean project_selection_changed( ui::TreeSelection selection, ui::ListStore store ){
745 Project& project = g_build_project;
751 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) ) {
752 auto path = gtk_tree_model_get_path( model, &iter );
753 Project::iterator x = Project_find( project, gtk_tree_path_get_indices( path )[0] );
754 gtk_tree_path_free( path );
756 if ( x != project.end() ) {
757 Build& build = ( *x ).second;
758 g_current_build = &build;
760 for ( Build::iterator i = build.begin(); i != build.end(); ++i )
762 store.append(0, (*i).c_str());
779 gboolean commands_cell_edited(ui::CellRendererText cell, gchar* path_string, gchar* new_text, ui::ListStore store ){
780 if ( g_current_build == 0 ) {
783 Build& build = *g_current_build;
785 auto path = ui::TreePath( path_string );
787 ASSERT_MESSAGE( gtk_tree_path_get_depth( path ) == 1, "invalid path length" );
790 gtk_tree_model_get_iter(store, &iter, path );
792 Build::iterator i = Build_find( build, gtk_tree_path_get_indices( path )[0] );
793 if ( i != build.end() ) {
794 g_build_changed = true;
795 ( *i ).setString( new_text );
797 gtk_list_store_set( store, &iter, 0, new_text, -1 );
799 else if ( !string_empty( new_text ) ) {
800 g_build_changed = true;
801 build.push_back( Build::value_type( VariableString( new_text ) ) );
803 gtk_list_store_set( store, &iter, 0, new_text, -1 );
808 gtk_tree_path_free( path );
810 Build_refreshMenu( g_bsp_menu );
815 gboolean commands_key_press( ui::TreeView widget, GdkEventKey* event, ui::ListStore store ){
816 if ( g_current_build == 0 ) {
819 Build& build = *g_current_build;
821 if ( event->keyval == GDK_KEY_Delete ) {
822 auto selection = gtk_tree_view_get_selection(widget );
825 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) ) {
826 auto path = gtk_tree_model_get_path( model, &iter );
827 Build::iterator i = Build_find( build, gtk_tree_path_get_indices( path )[0] );
828 gtk_tree_path_free( path );
830 if ( i != build.end() ) {
831 g_build_changed = true;
834 gtk_list_store_remove( store, &iter );
842 ui::Window BuildMenuDialog_construct( ModalDialog& modal, ProjectList& projectList ){
843 ui::Window window = MainFrame_getWindow().create_dialog_window("Build Menu", G_CALLBACK(dialog_delete_callback ), &modal, -1, 400 );
846 auto table1 = create_dialog_table( 2, 2, 4, 4, 4 );
849 auto vbox = create_dialog_vbox( 4 );
850 table1.attach(vbox, {1, 2, 0, 1}, {GTK_FILL, GTK_FILL});
852 auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &modal );
853 vbox.pack_start( button, FALSE, FALSE, 0 );
856 auto button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &modal );
857 vbox.pack_start( button, FALSE, FALSE, 0 );
860 auto buildViewStore = ui::ListStore::from(gtk_list_store_new( 1, G_TYPE_STRING ));
861 auto buildView = ui::TreeView( ui::TreeModel::from( buildViewStore._handle ));
863 auto frame = create_dialog_frame( "Build menu" );
864 table1.attach(frame, {0, 1, 0, 1});
866 auto scr = create_scrolled_window( ui::Policy::NEVER, ui::Policy::AUTOMATIC, 4 );
870 auto view = buildView;
871 auto store = buildViewStore;
872 gtk_tree_view_set_headers_visible(view, FALSE );
874 auto renderer = ui::CellRendererText(ui::New);
875 object_set_boolean_property( G_OBJECT( renderer ), "editable", TRUE );
876 renderer.connect("edited", G_CALLBACK( project_cell_edited ), &projectList );
878 auto column = ui::TreeViewColumn( "", renderer, {{"text", 0}} );
879 gtk_tree_view_append_column(view, column );
881 auto selection = gtk_tree_view_get_selection(view );
882 gtk_tree_selection_set_mode( selection, GTK_SELECTION_BROWSE );
886 projectList.m_store = store;
889 view.connect( "key_press_event", G_CALLBACK( project_key_press ), &projectList );
896 auto frame = create_dialog_frame( "Commandline" );
897 table1.attach(frame, {0, 1, 1, 2});
899 auto scr = create_scrolled_window( ui::Policy::NEVER, ui::Policy::AUTOMATIC, 4 );
903 auto store = ui::ListStore::from(gtk_list_store_new( 1, G_TYPE_STRING ));
905 auto view = ui::TreeView(ui::TreeModel::from( store._handle ));
906 gtk_tree_view_set_headers_visible(view, FALSE );
908 auto renderer = ui::CellRendererText(ui::New);
909 object_set_boolean_property( G_OBJECT( renderer ), "editable", TRUE );
910 renderer.connect( "edited", G_CALLBACK( commands_cell_edited ), store );
912 auto column = ui::TreeViewColumn( "", renderer, {{"text", 0}} );
913 gtk_tree_view_append_column(view, column );
915 auto selection = gtk_tree_view_get_selection(view );
916 gtk_tree_selection_set_mode( selection, GTK_SELECTION_BROWSE );
924 view.connect( "key_press_event", G_CALLBACK( commands_key_press ), store );
926 auto sel = ui::TreeSelection::from(gtk_tree_view_get_selection(buildView ));
927 sel.connect( "changed", G_CALLBACK( project_selection_changed ), store );
933 BSPCommandList_Construct( projectList.m_store, g_build_project );
940 CopiedString g_buildMenu;
943 void LoadBuildMenu();
948 ProjectList projectList( g_build_project );
950 ui::Window window = BuildMenuDialog_construct( modal, projectList );
952 if ( modal_dialog_show( window, modal ) == eIDCANCEL ) {
953 build_commands_clear();
956 Build_refreshMenu( g_bsp_menu );
958 else if ( projectList.m_changed ) {
959 g_build_changed = true;
967 #include "gtkutil/menu.h"
968 #include "mainframe.h"
969 #include "preferences.h"
977 BuildMenuItem( const char* name, ui::MenuItem item )
978 : m_name( name ), m_item( item ){
983 typedef MemberCaller<BuildMenuItem, void(), &BuildMenuItem::run> RunCaller;
986 typedef std::list<BuildMenuItem> BuildMenuItems;
987 BuildMenuItems g_BuildMenuItems;
990 ui::Menu g_bsp_menu{ui::null};
992 void Build_constructMenu( ui::Menu menu ){
993 for ( Project::iterator i = g_build_project.begin(); i != g_build_project.end(); ++i )
995 g_BuildMenuItems.push_back( BuildMenuItem( ( *i ).first.c_str(), ui::MenuItem(ui::null) ) );
996 if ( is_separator( *i ) ) {
997 g_BuildMenuItems.back().m_item = menu_separator( menu );
1001 g_BuildMenuItems.back().m_item = create_menu_item_with_mnemonic( menu, ( *i ).first.c_str(), BuildMenuItem::RunCaller( g_BuildMenuItems.back() ) );
1007 void Build_refreshMenu( ui::Menu menu ){
1008 for (auto i = g_BuildMenuItems.begin(); i != g_BuildMenuItems.end(); ++i )
1010 menu.remove(ui::MenuItem(i->m_item));
1013 g_BuildMenuItems.clear();
1015 Build_constructMenu( menu );
1019 void LoadBuildMenu(){
1020 if ( string_empty( g_buildMenu.c_str() ) || !build_commands_parse( g_buildMenu.c_str() ) ) {
1022 StringOutputStream buffer( 256 );
1023 buffer << GameToolsPath_get() << "default_build_menu.xml";
1025 bool success = build_commands_parse( buffer.c_str() );
1026 ASSERT_MESSAGE( success, "failed to parse default build commands: " << buffer.c_str() );
1029 StringOutputStream buffer( 256 );
1030 buffer << SettingsPath_get() << g_pGameDescription->mGameFile.c_str() << "/build_menu.xml";
1032 g_buildMenu = buffer.c_str();
1037 void SaveBuildMenu(){
1038 if ( g_build_changed ) {
1039 g_build_changed = false;
1040 build_commands_write( g_buildMenu.c_str() );
1044 #include "preferencesystem.h"
1045 #include "stringio.h"
1047 void BuildMenu_Construct(){
1048 GlobalPreferenceSystem().registerPreference( "BuildMenu", make_property_string( g_buildMenu ) );
1051 void BuildMenu_Destroy(){