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"
27 #include "stream/stringstream.h"
28 #include "versionlib.h"
30 #include "mainframe.h"
32 typedef std::map<std::string, std::string> Variables;
33 Variables g_build_variables;
35 void build_clear_variables(){
36 g_build_variables.clear();
39 void build_set_variable( const char* name, const char* value ){
40 g_build_variables[name] = value;
43 const char* build_get_variable( const char* name ){
44 Variables::iterator i = g_build_variables.find( name );
45 if ( i != g_build_variables.end() ) {
46 return ( *i ).second.c_str();
48 globalErrorStream() << "undefined build variable: " << makeQuoted( name ) << "\n";
53 #include "xml/xmlelement.h"
58 virtual ~Evaluatable(){}
59 virtual void evaluate( StringBuffer& output ) = 0;
60 virtual void exportXML( XMLImporter& importer ) = 0;
63 class VariableString : public Evaluatable
67 VariableString() : m_string(){
69 VariableString( const char* string ) : m_string( string ){
71 const char* c_str() const {
72 return m_string.c_str();
74 void setString( const char* string ){
77 void evaluate( StringBuffer& output ){
78 StringBuffer variable;
79 bool in_variable = false;
80 for ( const char* i = m_string.c_str(); *i != '\0'; ++i )
89 output.push_back( *i );
99 output.push_string( build_get_variable( variable.c_str() ) );
103 variable.push_back( *i );
109 void exportXML( XMLImporter& importer ){
114 class Conditional : public Evaluatable
116 VariableString* m_test;
118 Evaluatable* m_result;
119 Conditional( VariableString* test ) : m_test( test ){
125 void evaluate( StringBuffer& output ){
127 m_test->evaluate( buffer );
128 if ( !string_empty( buffer.c_str() ) ) {
129 m_result->evaluate( output );
132 void exportXML( XMLImporter& importer ){
133 StaticElement conditionElement( "cond" );
134 conditionElement.insertAttribute( "value", m_test->c_str() );
135 importer.pushElement( conditionElement );
136 m_result->exportXML( importer );
137 importer.popElement( conditionElement.name() );
141 typedef std::vector<Evaluatable*> Evaluatables;
143 class Tool : public Evaluatable
145 Evaluatables m_evaluatables;
148 for ( Evaluatables::iterator i = m_evaluatables.begin(); i != m_evaluatables.end(); ++i )
153 void push_back( Evaluatable* evaluatable ){
154 m_evaluatables.push_back( evaluatable );
156 void evaluate( StringBuffer& output ){
157 for ( Evaluatables::iterator i = m_evaluatables.begin(); i != m_evaluatables.end(); ++i )
159 ( *i )->evaluate( output );
162 void exportXML( XMLImporter& importer ){
163 for ( Evaluatables::iterator i = m_evaluatables.begin(); i != m_evaluatables.end(); ++i )
165 ( *i )->exportXML( importer );
170 #include "xml/ixml.h"
172 class XMLElementParser : public TextOutputStream
175 virtual XMLElementParser& pushElement( const XMLElement& element ) = 0;
176 virtual void popElement( const char* name ) = 0;
179 class VariableStringXMLConstructor : public XMLElementParser
181 StringBuffer m_buffer;
182 VariableString& m_variableString;
184 VariableStringXMLConstructor( VariableString& variableString ) : m_variableString( variableString ){
186 ~VariableStringXMLConstructor(){
187 m_variableString.setString( m_buffer.c_str() );
189 std::size_t write( const char* buffer, std::size_t length ){
190 m_buffer.push_range( buffer, buffer + length );
193 XMLElementParser& pushElement( const XMLElement& element ){
194 ERROR_MESSAGE( "parse error: invalid element \"" << element.name() << "\"" );
197 void popElement( const char* name ){
201 class ConditionalXMLConstructor : public XMLElementParser
203 StringBuffer m_buffer;
204 Conditional& m_conditional;
206 ConditionalXMLConstructor( Conditional& conditional ) : m_conditional( conditional ){
208 ~ConditionalXMLConstructor(){
209 m_conditional.m_result = new VariableString( m_buffer.c_str() );
211 std::size_t write( const char* buffer, std::size_t length ){
212 m_buffer.push_range( buffer, buffer + length );
215 XMLElementParser& pushElement( const XMLElement& element ){
216 ERROR_MESSAGE( "parse error: invalid element \"" << element.name() << "\"" );
219 void popElement( const char* name ){
223 class ToolXMLConstructor : public XMLElementParser
225 StringBuffer m_buffer;
227 ConditionalXMLConstructor* m_conditional;
229 ToolXMLConstructor( Tool& tool ) : m_tool( tool ){
231 ~ToolXMLConstructor(){
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 if ( string_equal( element.name(), "cond" ) ) {
241 Conditional* conditional = new Conditional( new VariableString( element.attribute( "value" ) ) );
242 m_tool.push_back( conditional );
243 m_conditional = new ConditionalXMLConstructor( *conditional );
244 return *m_conditional;
248 ERROR_MESSAGE( "parse error: invalid element \"" << element.name() << "\"" );
252 void popElement( const char* name ){
253 if ( string_equal( name, "cond" ) ) {
254 delete m_conditional;
259 if ( !m_buffer.empty() ) {
260 m_tool.push_back( new VariableString( m_buffer.c_str() ) );
266 typedef VariableString BuildCommand;
267 typedef std::list<BuildCommand> Build;
269 class BuildXMLConstructor : public XMLElementParser
271 VariableStringXMLConstructor* m_variableString;
274 BuildXMLConstructor( Build& build ) : m_build( build ){
276 std::size_t write( const char* buffer, std::size_t length ){
279 XMLElementParser& pushElement( const XMLElement& element ){
280 if ( string_equal( element.name(), "command" ) ) {
281 m_build.push_back( BuildCommand() );
282 m_variableString = new VariableStringXMLConstructor( m_build.back() );
283 return *m_variableString;
287 ERROR_MESSAGE( "parse error: invalid element" );
291 void popElement( const char* name ){
292 delete m_variableString;
296 typedef std::pair<std::string, Build> BuildPair;
297 #define SEPARATOR_STRING "-"
298 static bool is_separator( const BuildPair &p ){
299 if ( !string_equal( p.first.c_str(), SEPARATOR_STRING ) ) {
302 for ( Build::const_iterator j = p.second.begin(); j != p.second.end(); ++j )
304 if ( !string_equal( ( *j ).c_str(), "" ) ) {
316 BuildPairEqual( const char* name ) : m_name( name ){
318 bool operator()( const BuildPair& self ) const {
319 return string_equal( self.first.c_str(), m_name );
323 typedef std::list<BuildPair> Project;
325 Project::iterator Project_find( Project& project, const char* name ){
326 return std::find_if( project.begin(), project.end(), BuildPairEqual( name ) );
329 Project::iterator Project_find( Project& project, std::size_t index ){
330 Project::iterator i = project.begin();
331 while ( index-- != 0 && i != project.end() )
338 Build& project_find( Project& project, const char* build ){
339 Project::iterator i = Project_find( project, build );
340 ASSERT_MESSAGE( i != project.end(), "error finding build command" );
341 return ( *i ).second;
344 Build::iterator Build_find( Build& build, std::size_t index ){
345 Build::iterator i = build.begin();
346 while ( index-- != 0 && i != build.end() )
353 typedef std::map<std::string, Tool> Tools;
355 class ProjectXMLConstructor : public XMLElementParser
357 ToolXMLConstructor* m_tool;
358 BuildXMLConstructor* m_build;
362 ProjectXMLConstructor( Project& project, Tools& tools ) : m_project( project ), m_tools( tools ){
364 std::size_t write( const char* buffer, std::size_t length ){
367 XMLElementParser& pushElement( const XMLElement& element ){
368 if ( string_equal( element.name(), "var" ) ) {
369 Tools::iterator i = m_tools.insert( Tools::value_type( element.attribute( "name" ), Tool() ) ).first;
370 m_tool = new ToolXMLConstructor( ( *i ).second );
373 else if ( string_equal( element.name(), "build" ) ) {
374 m_project.push_back( Project::value_type( element.attribute( "name" ), Build() ) );
375 m_build = new BuildXMLConstructor( m_project.back().second );
378 else if ( string_equal( element.name(), "separator" ) ) {
379 m_project.push_back( Project::value_type( SEPARATOR_STRING, Build() ) );
384 ERROR_MESSAGE( "parse error: invalid element" );
388 void popElement( const char* name ){
389 if ( string_equal( name, "var" ) ) {
392 else if ( string_equal( name, "build" ) ) {
398 class SkipAllParser : public XMLElementParser
401 std::size_t write( const char* buffer, std::size_t length ){
404 XMLElementParser& pushElement( const XMLElement& element ){
407 void popElement( const char* name ){
411 class RootXMLConstructor : public XMLElementParser
413 std::string m_elementName;
414 XMLElementParser& m_parser;
415 SkipAllParser m_skip;
419 RootXMLConstructor( const char* elementName, XMLElementParser& parser, const char* version ) :
420 m_elementName( elementName ),
422 m_version( version_parse( version ) ),
423 m_compatible( false ){
425 std::size_t write( const char* buffer, std::size_t length ){
428 XMLElementParser& pushElement( const XMLElement& element ){
429 if ( string_equal( element.name(), m_elementName.c_str() ) ) {
430 Version dataVersion( version_parse( element.attribute( "version" ) ) );
431 if ( version_compatible( m_version, dataVersion ) ) {
442 //ERROR_MESSAGE("parse error: invalid element \"" << element.name() << "\"");
446 void popElement( const char* name ){
449 bool versionCompatible() const {
456 Project g_build_project;
458 bool g_build_changed = false;
461 void build_error_undefined_tool( const char* build, const char* tool ){
462 globalErrorStream() << "build " << makeQuoted( build ) << " refers to undefined tool " << makeQuoted( tool ) << '\n';
465 void project_verify( Project& project, Tools& tools ){
467 for ( Project::iterator i = project.begin(); i != project.end(); ++i )
469 Build& build = ( *i ).second;
470 for ( Build::iterator j = build.begin(); j != build.end(); ++j )
472 Tools::iterator k = tools.find( ( *j ).first );
473 if ( k == g_build_tools.end() ) {
474 build_error_undefined_tool( ( *i ).first.c_str(), ( *j ).first.c_str() );
481 void build_run( const char* name, CommandListener& listener ){
482 for ( Tools::iterator i = g_build_tools.begin(); i != g_build_tools.end(); ++i )
485 ( *i ).second.evaluate( output );
486 build_set_variable( ( *i ).first.c_str(), output.c_str() );
490 Project::iterator i = Project_find( g_build_project, name );
491 if ( i != g_build_project.end() ) {
492 Build& build = ( *i ).second;
493 for ( Build::iterator j = build.begin(); j != build.end(); ++j )
496 ( *j ).evaluate( output );
497 listener.execute( output.c_str() );
502 globalErrorStream() << "build " << makeQuoted( name ) << " not defined";
508 typedef std::vector<XMLElementParser*> XMLElementStack;
510 class XMLParser : public XMLImporter
512 XMLElementStack m_stack;
514 XMLParser( XMLElementParser& parser ){
515 m_stack.push_back( &parser );
517 std::size_t write( const char* buffer, std::size_t length ){
518 return m_stack.back()->write( buffer, length );
520 void pushElement( const XMLElement& element ){
521 m_stack.push_back( &m_stack.back()->pushElement( element ) );
523 void popElement( const char* name ){
525 m_stack.back()->popElement( name );
529 #include "stream/textfilestream.h"
530 #include "xml/xmlparser.h"
532 const char* const BUILDMENU_VERSION = "2.0";
534 bool build_commands_parse( const char* filename ){
535 TextFileInputStream projectFile( filename );
536 if ( !projectFile.failed() ) {
537 ProjectXMLConstructor projectConstructor( g_build_project, g_build_tools );
538 RootXMLConstructor rootConstructor( "project", projectConstructor, BUILDMENU_VERSION );
539 XMLParser importer( rootConstructor );
540 XMLStreamParser parser( projectFile );
541 parser.exportXML( importer );
543 if ( rootConstructor.versionCompatible() ) {
544 project_verify( g_build_project, g_build_tools );
548 globalErrorStream() << "failed to parse build menu: " << makeQuoted( filename ) << "\n";
553 void build_commands_clear(){
554 g_build_project.clear();
555 g_build_tools.clear();
558 class BuildXMLExporter
562 BuildXMLExporter( Build& build ) : m_build( build ){
564 void exportXML( XMLImporter& importer ){
566 for ( Build::iterator i = m_build.begin(); i != m_build.end(); ++i )
568 StaticElement commandElement( "command" );
569 importer.pushElement( commandElement );
570 ( *i ).exportXML( importer );
571 importer.popElement( commandElement.name() );
577 class ProjectXMLExporter
582 ProjectXMLExporter( Project& project, Tools& tools ) : m_project( project ), m_tools( tools ){
584 void exportXML( XMLImporter& importer ){
585 StaticElement projectElement( "project" );
586 projectElement.insertAttribute( "version", BUILDMENU_VERSION );
587 importer.pushElement( projectElement );
590 for ( Tools::iterator i = m_tools.begin(); i != m_tools.end(); ++i )
592 StaticElement toolElement( "var" );
593 toolElement.insertAttribute( "name", ( *i ).first.c_str() );
594 importer.pushElement( toolElement );
595 ( *i ).second.exportXML( importer );
596 importer.popElement( toolElement.name() );
599 for ( Project::iterator i = m_project.begin(); i != m_project.end(); ++i )
601 if ( is_separator( *i ) ) {
602 StaticElement buildElement( "separator" );
603 importer.pushElement( buildElement );
604 importer.popElement( buildElement.name() );
609 StaticElement buildElement( "build" );
610 buildElement.insertAttribute( "name", ( *i ).first.c_str() );
611 importer.pushElement( buildElement );
612 BuildXMLExporter buildExporter( ( *i ).second );
613 buildExporter.exportXML( importer );
614 importer.popElement( buildElement.name() );
618 importer.popElement( projectElement.name() );
622 #include "xml/xmlwriter.h"
624 void build_commands_write( const char* filename ){
625 TextFileOutputStream projectFile( filename );
626 if ( !projectFile.failed() ) {
627 XMLStreamWriter writer( projectFile );
628 ProjectXMLExporter projectExporter( g_build_project, g_build_tools );
630 projectExporter.exportXML( writer );
636 #include <gdk/gdkkeysyms.h>
637 #include <gtk/gtkmain.h>
638 #include <gtk/gtkbox.h>
639 #include <gtk/gtktable.h>
640 #include <gtk/gtktreeview.h>
641 #include <gtk/gtkcellrenderertext.h>
642 #include <gtk/gtktreeselection.h>
643 #include <gtk/gtkliststore.h>
644 #include <gtk/gtkscrolledwindow.h>
646 #include "gtkutil/dialog.h"
647 #include "gtkutil/closure.h"
648 #include "gtkutil/window.h"
651 void Build_refreshMenu( GtkMenu* menu );
654 void BSPCommandList_Construct( GtkListStore* store, Project& project ){
655 gtk_list_store_clear( store );
657 for ( Project::iterator i = project.begin(); i != project.end(); ++i )
659 const char* buildName = ( *i ).first.c_str();
661 GtkTreeIter buildIter;
662 gtk_list_store_append( store, &buildIter );
663 gtk_list_store_set( store, &buildIter, 0, const_cast<char*>( buildName ), -1 );
666 GtkTreeIter lastIter;
667 gtk_list_store_append( store, &lastIter );
674 GtkListStore* m_store;
676 ProjectList( Project& project ) : m_project( project ), m_changed( false ){
680 gboolean project_cell_edited( GtkCellRendererText* cell, gchar* path_string, gchar* new_text, ProjectList* projectList ){
681 Project& project = projectList->m_project;
683 GtkTreePath* path = gtk_tree_path_new_from_string( path_string );
685 ASSERT_MESSAGE( gtk_tree_path_get_depth( path ) == 1, "invalid path length" );
688 gtk_tree_model_get_iter( GTK_TREE_MODEL( projectList->m_store ), &iter, path );
690 Project::iterator i = Project_find( project, gtk_tree_path_get_indices( path )[0] );
691 if ( i != project.end() ) {
692 projectList->m_changed = true;
693 if ( string_empty( new_text ) ) {
695 gtk_list_store_remove( projectList->m_store, &iter );
699 ( *i ).first = new_text;
700 gtk_list_store_set( projectList->m_store, &iter, 0, new_text, -1 );
703 else if ( !string_empty( new_text ) ) {
704 projectList->m_changed = true;
705 project.push_back( Project::value_type( new_text, Build() ) );
707 gtk_list_store_set( projectList->m_store, &iter, 0, new_text, -1 );
708 GtkTreeIter lastIter;
709 gtk_list_store_append( projectList->m_store, &lastIter );
712 gtk_tree_path_free( path );
714 Build_refreshMenu( g_bsp_menu );
719 gboolean project_key_press( ui::Widget widget, GdkEventKey* event, ProjectList* projectList ){
720 Project& project = projectList->m_project;
722 if ( event->keyval == GDK_Delete ) {
723 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( widget ) );
726 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) ) {
727 GtkTreePath* 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( GtkTreeSelection* selection, GtkListStore* store ){
747 Project& project = g_build_project;
749 gtk_list_store_clear( store );
753 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) ) {
754 GtkTreePath* 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 GtkTreeIter commandIter;
765 gtk_list_store_append( store, &commandIter );
766 gtk_list_store_set( store, &commandIter, 0, const_cast<char*>( ( *i ).c_str() ), -1 );
768 GtkTreeIter lastIter;
769 gtk_list_store_append( store, &lastIter );
784 gboolean commands_cell_edited( GtkCellRendererText* cell, gchar* path_string, gchar* new_text, GtkListStore* store ){
785 if ( g_current_build == 0 ) {
788 Build& build = *g_current_build;
790 GtkTreePath* path = gtk_tree_path_new_from_string( path_string );
792 ASSERT_MESSAGE( gtk_tree_path_get_depth( path ) == 1, "invalid path length" );
795 gtk_tree_model_get_iter( GTK_TREE_MODEL( store ), &iter, path );
797 Build::iterator i = Build_find( build, gtk_tree_path_get_indices( path )[0] );
798 if ( i != build.end() ) {
799 g_build_changed = true;
800 ( *i ).setString( new_text );
802 gtk_list_store_set( store, &iter, 0, new_text, -1 );
804 else if ( !string_empty( new_text ) ) {
805 g_build_changed = true;
806 build.push_back( Build::value_type( VariableString( new_text ) ) );
808 gtk_list_store_set( store, &iter, 0, new_text, -1 );
810 GtkTreeIter lastIter;
811 gtk_list_store_append( store, &lastIter );
814 gtk_tree_path_free( path );
816 Build_refreshMenu( g_bsp_menu );
821 gboolean commands_key_press( ui::Widget widget, GdkEventKey* event, GtkListStore* store ){
822 if ( g_current_build == 0 ) {
825 Build& build = *g_current_build;
827 if ( event->keyval == GDK_Delete ) {
828 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( widget ) );
831 if ( gtk_tree_selection_get_selected( selection, &model, &iter ) ) {
832 GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
833 Build::iterator i = Build_find( build, gtk_tree_path_get_indices( path )[0] );
834 gtk_tree_path_free( path );
836 if ( i != build.end() ) {
837 g_build_changed = true;
840 gtk_list_store_remove( store, &iter );
848 ui::Window BuildMenuDialog_construct( ModalDialog& modal, ProjectList& projectList ){
849 ui::Window window = MainFrame_getWindow().create_dialog_window("Build Menu", G_CALLBACK(dialog_delete_callback ), &modal, -1, 400 );
851 ui::Widget buildView;
854 GtkTable* table1 = create_dialog_table( 2, 2, 4, 4, 4 );
855 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( table1 ) );
857 GtkVBox* vbox = create_dialog_vbox( 4 );
858 gtk_table_attach( table1, GTK_WIDGET( vbox ), 1, 2, 0, 1,
859 (GtkAttachOptions) ( GTK_FILL ),
860 (GtkAttachOptions) ( GTK_FILL ), 0, 0 );
862 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &modal );
863 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
866 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &modal );
867 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
871 GtkFrame* frame = create_dialog_frame( "Build menu" );
872 gtk_table_attach( table1, GTK_WIDGET( frame ), 0, 1, 0, 1,
873 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
874 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), 0, 0 );
876 GtkScrolledWindow* scr = create_scrolled_window( GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC, 4 );
877 gtk_container_add( GTK_CONTAINER( frame ), GTK_WIDGET( scr ) );
880 GtkListStore* store = gtk_list_store_new( 1, G_TYPE_STRING );
882 ui::Widget view = ui::TreeView( ui::TreeModel(GTK_TREE_MODEL( store ) ));
883 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE );
885 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
886 object_set_boolean_property( G_OBJECT( renderer ), "editable", TRUE );
887 g_signal_connect( renderer, "edited", G_CALLBACK( project_cell_edited ), &projectList );
889 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "", renderer, "text", 0, 0 );
890 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
892 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
893 gtk_tree_selection_set_mode( selection, GTK_SELECTION_BROWSE );
895 gtk_widget_show( view );
898 projectList.m_store = store;
899 gtk_container_add( GTK_CONTAINER( scr ), view );
901 g_signal_connect( G_OBJECT( view ), "key_press_event", G_CALLBACK( project_key_press ), &projectList );
903 g_object_unref( G_OBJECT( store ) );
908 GtkFrame* frame = create_dialog_frame( "Commandline" );
909 gtk_table_attach( table1, GTK_WIDGET( frame ), 0, 1, 1, 2,
910 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
911 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), 0, 0 );
913 GtkScrolledWindow* scr = create_scrolled_window( GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC, 4 );
914 gtk_container_add( GTK_CONTAINER( frame ), GTK_WIDGET( scr ) );
917 GtkListStore* store = gtk_list_store_new( 1, G_TYPE_STRING );
919 ui::Widget view = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( store ) ));
920 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE );
922 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
923 object_set_boolean_property( G_OBJECT( renderer ), "editable", TRUE );
924 g_signal_connect( renderer, "edited", G_CALLBACK( commands_cell_edited ), store );
926 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "", renderer, "text", 0, 0 );
927 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
929 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
930 gtk_tree_selection_set_mode( selection, GTK_SELECTION_BROWSE );
932 gtk_widget_show( view );
934 gtk_container_add( GTK_CONTAINER( scr ), view );
936 g_object_unref( G_OBJECT( store ) );
938 g_signal_connect( G_OBJECT( view ), "key_press_event", G_CALLBACK( commands_key_press ), store );
940 g_signal_connect( G_OBJECT( gtk_tree_view_get_selection( GTK_TREE_VIEW( buildView ) ) ), "changed", G_CALLBACK( project_selection_changed ), store );
946 BSPCommandList_Construct( projectList.m_store, g_build_project );
953 std::string g_buildMenu;
956 void LoadBuildMenu();
961 ProjectList projectList( g_build_project );
963 ui::Window window = BuildMenuDialog_construct( modal, projectList );
965 if ( modal_dialog_show( window, modal ) == eIDCANCEL ) {
966 build_commands_clear();
969 Build_refreshMenu( g_bsp_menu );
971 else if ( projectList.m_changed ) {
972 g_build_changed = true;
975 gtk_widget_destroy( GTK_WIDGET( window ) );
980 #include "gtkutil/menu.h"
981 #include "mainframe.h"
982 #include "preferences.h"
985 typedef struct _GtkMenuItem GtkMenuItem;
992 BuildMenuItem( const char* name, GtkMenuItem* item )
993 : m_name( name ), m_item( item ){
998 typedef MemberCaller<BuildMenuItem, &BuildMenuItem::run> RunCaller;
1001 typedef std::list<BuildMenuItem> BuildMenuItems;
1002 BuildMenuItems g_BuildMenuItems;
1005 GtkMenu* g_bsp_menu;
1007 void Build_constructMenu( GtkMenu* menu ){
1008 for ( Project::iterator i = g_build_project.begin(); i != g_build_project.end(); ++i )
1010 g_BuildMenuItems.push_back( BuildMenuItem( ( *i ).first.c_str(), 0 ) );
1011 if ( is_separator( *i ) ) {
1012 g_BuildMenuItems.back().m_item = menu_separator( menu );
1016 g_BuildMenuItems.back().m_item = create_menu_item_with_mnemonic( menu, ( *i ).first.c_str(), BuildMenuItem::RunCaller( g_BuildMenuItems.back() ) );
1022 void Build_refreshMenu( GtkMenu* menu ){
1023 for ( BuildMenuItems::iterator i = g_BuildMenuItems.begin(); i != g_BuildMenuItems.end(); ++i )
1025 gtk_container_remove( GTK_CONTAINER( menu ), GTK_WIDGET( ( *i ).m_item ) );
1028 g_BuildMenuItems.clear();
1030 Build_constructMenu( menu );
1034 void LoadBuildMenu(){
1035 if ( string_empty( g_buildMenu.c_str() ) || !build_commands_parse( g_buildMenu.c_str() ) ) {
1037 StringOutputStream buffer( 256 );
1038 buffer << GameToolsPath_get() << "default_build_menu.xml";
1040 bool success = build_commands_parse( buffer.c_str() );
1041 ASSERT_MESSAGE( success, "failed to parse default build commands: " << buffer.c_str() );
1044 StringOutputStream buffer( 256 );
1045 buffer << SettingsPath_get() << g_pGameDescription->mGameFile.c_str() << "/build_menu.xml";
1047 g_buildMenu = buffer.c_str();
1052 void SaveBuildMenu(){
1053 if ( g_build_changed ) {
1054 g_build_changed = false;
1055 build_commands_write( g_buildMenu.c_str() );
1059 #include "preferencesystem.h"
1060 #include "stringio.h"
1062 void BuildMenu_Construct(){
1063 GlobalPreferenceSystem().registerPreference( "BuildMenu", CopiedStringImportStringCaller( g_buildMenu ), CopiedStringExportStringCaller( g_buildMenu ) );
1066 void BuildMenu_Destroy(){