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<CopiedString, CopiedString> Variables;
33 Variables g_build_variables;
35 void build_clear_variables()
37 g_build_variables.clear();
40 void build_set_variable(const char* name, const char* value)
42 g_build_variables[name] = value;
45 const char* build_get_variable(const char* name)
47 Variables::iterator i = g_build_variables.find(name);
48 if(i != g_build_variables.end())
50 return (*i).second.c_str();
52 globalErrorStream() << "undefined build variable: " << makeQuoted(name) << "\n";
57 #include "xml/xmlelement.h"
62 virtual void evaluate(StringBuffer& output) = 0;
63 virtual void exportXML(XMLImporter& importer) = 0;
66 class VariableString : public Evaluatable
68 CopiedString m_string;
70 VariableString() : m_string()
73 VariableString(const char* string) : m_string(string)
76 const char* c_str() const
78 return m_string.c_str();
80 void setString(const char* string)
84 void evaluate(StringBuffer& output)
86 StringBuffer variable;
87 bool in_variable = false;
88 for(const char* i = m_string.c_str(); *i != '\0'; ++i)
108 output.push_string(build_get_variable(variable.c_str()));
112 variable.push_back(*i);
118 void exportXML(XMLImporter& importer)
124 class Conditional : public Evaluatable
126 VariableString* m_test;
128 Evaluatable* m_result;
129 Conditional(VariableString* test) : m_test(test)
137 void evaluate(StringBuffer& output)
140 m_test->evaluate(buffer);
141 if(!string_empty(buffer.c_str()))
143 m_result->evaluate(output);
146 void exportXML(XMLImporter& importer)
148 StaticElement conditionElement("cond");
149 conditionElement.insertAttribute("value", m_test->c_str());
150 importer.pushElement(conditionElement);
151 m_result->exportXML(importer);
152 importer.popElement(conditionElement.name());
156 typedef std::vector<Evaluatable*> Evaluatables;
158 class Tool : public Evaluatable
160 Evaluatables m_evaluatables;
164 for(Evaluatables::iterator i = m_evaluatables.begin(); i != m_evaluatables.end(); ++i)
169 void push_back(Evaluatable* evaluatable)
171 m_evaluatables.push_back(evaluatable);
173 void evaluate(StringBuffer& output)
175 for(Evaluatables::iterator i = m_evaluatables.begin(); i != m_evaluatables.end(); ++i)
177 (*i)->evaluate(output);
180 void exportXML(XMLImporter& importer)
182 for(Evaluatables::iterator i = m_evaluatables.begin(); i != m_evaluatables.end(); ++i)
184 (*i)->exportXML(importer);
189 #include "xml/ixml.h"
191 class XMLElementParser : public TextOutputStream
194 virtual XMLElementParser& pushElement(const XMLElement& element) = 0;
195 virtual void popElement(const char* name) = 0;
198 class VariableStringXMLConstructor : public XMLElementParser
200 StringBuffer m_buffer;
201 VariableString& m_variableString;
203 VariableStringXMLConstructor(VariableString& variableString) : m_variableString(variableString)
206 ~VariableStringXMLConstructor()
208 m_variableString.setString(m_buffer.c_str());
210 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)
217 ERROR_MESSAGE("parse error: invalid element \"" << element.name() << "\"");
220 void popElement(const char* name)
225 class ConditionalXMLConstructor : public XMLElementParser
227 StringBuffer m_buffer;
228 Conditional& m_conditional;
230 ConditionalXMLConstructor(Conditional& conditional) : m_conditional(conditional)
233 ~ConditionalXMLConstructor()
235 m_conditional.m_result = new VariableString(m_buffer.c_str());
237 std::size_t write(const char* buffer, std::size_t length)
239 m_buffer.push_range(buffer, buffer + length);
242 XMLElementParser& pushElement(const XMLElement& element)
244 ERROR_MESSAGE("parse error: invalid element \"" << element.name() << "\"");
247 void popElement(const char* name)
252 class ToolXMLConstructor : public XMLElementParser
254 StringBuffer m_buffer;
256 ConditionalXMLConstructor* m_conditional;
258 ToolXMLConstructor(Tool& tool) : m_tool(tool)
261 ~ToolXMLConstructor()
265 std::size_t write(const char* buffer, std::size_t length)
267 m_buffer.push_range(buffer, buffer + length);
270 XMLElementParser& pushElement(const XMLElement& element)
272 if(string_equal(element.name(), "cond"))
275 Conditional* conditional = new Conditional(new VariableString(element.attribute("value")));
276 m_tool.push_back(conditional);
277 m_conditional = new ConditionalXMLConstructor(*conditional);
278 return *m_conditional;
282 ERROR_MESSAGE("parse error: invalid element \"" << element.name() << "\"");
286 void popElement(const char* name)
288 if(string_equal(name, "cond"))
290 delete m_conditional;
296 if(!m_buffer.empty())
298 m_tool.push_back(new VariableString(m_buffer.c_str()));
304 typedef VariableString BuildCommand;
305 typedef std::list<BuildCommand> Build;
307 class BuildXMLConstructor : public XMLElementParser
309 VariableStringXMLConstructor* m_variableString;
312 BuildXMLConstructor(Build& build) : m_build(build)
315 std::size_t write(const char* buffer, std::size_t length)
319 XMLElementParser& pushElement(const XMLElement& element)
321 if(string_equal(element.name(), "command"))
323 m_build.push_back(BuildCommand());
324 m_variableString = new VariableStringXMLConstructor(m_build.back());
325 return *m_variableString;
329 ERROR_MESSAGE("parse error: invalid element");
333 void popElement(const char* name)
335 delete m_variableString;
339 typedef std::pair<CopiedString, Build> BuildPair;
345 BuildPairEqual(const char* name) : m_name(name)
348 bool operator()(const BuildPair& self) const
350 return string_equal(self.first.c_str(), m_name);
354 typedef std::list<BuildPair> Project;
356 Project::iterator Project_find(Project& project, const char* name)
358 return std::find_if(project.begin(), project.end(), BuildPairEqual(name));
361 Project::iterator Project_find(Project& project, std::size_t index)
363 Project::iterator i = project.begin();
364 while(index-- != 0 && i != project.end())
371 Build& project_find(Project& project, const char* build)
373 Project::iterator i = Project_find(project, build);
374 ASSERT_MESSAGE(i != project.end(), "error finding build command");
378 Build::iterator Build_find(Build& build, std::size_t index)
380 Build::iterator i = build.begin();
381 while(index-- != 0 && i != build.end())
388 typedef std::map<CopiedString, Tool> Tools;
390 class ProjectXMLConstructor : public XMLElementParser
392 ToolXMLConstructor* m_tool;
393 BuildXMLConstructor* m_build;
397 ProjectXMLConstructor(Project& project, Tools& tools) : m_project(project), m_tools(tools)
400 std::size_t write(const char* buffer, std::size_t length)
404 XMLElementParser& pushElement(const XMLElement& element)
406 if(string_equal(element.name(), "var"))
408 Tools::iterator i = m_tools.insert(Tools::value_type(element.attribute("name"), Tool())).first;
409 m_tool = new ToolXMLConstructor((*i).second);
412 else if(string_equal(element.name(), "build"))
414 m_project.push_back(Project::value_type(element.attribute("name"), Build()));
415 m_build = new BuildXMLConstructor(m_project.back().second);
420 ERROR_MESSAGE("parse error: invalid element");
424 void popElement(const char* name)
426 if(string_equal(name, "var"))
430 else if(string_equal(name, "build"))
437 class SkipAllParser : public XMLElementParser
440 std::size_t write(const char* buffer, std::size_t length)
444 XMLElementParser& pushElement(const XMLElement& element)
448 void popElement(const char* name)
453 class RootXMLConstructor : public XMLElementParser
455 CopiedString m_elementName;
456 XMLElementParser& m_parser;
457 SkipAllParser m_skip;
461 RootXMLConstructor(const char* elementName, XMLElementParser& parser, const char* version) :
462 m_elementName(elementName),
464 m_version(version_parse(version)),
468 std::size_t write(const char* buffer, std::size_t length)
472 XMLElementParser& pushElement(const XMLElement& element)
474 if(string_equal(element.name(), m_elementName.c_str()))
476 Version dataVersion(version_parse(element.attribute("version")));
477 if(version_compatible(m_version, dataVersion))
489 //ERROR_MESSAGE("parse error: invalid element \"" << element.name() << "\"");
493 void popElement(const char* name)
497 bool versionCompatible() const
505 Project g_build_project;
507 bool g_build_changed = false;
510 void build_error_undefined_tool(const char* build, const char* tool)
512 globalErrorStream() << "build " << makeQuoted(build) << " refers to undefined tool " << makeQuoted(tool) << '\n';
515 void project_verify(Project& project, Tools& tools)
518 for(Project::iterator i = project.begin(); i != project.end(); ++i)
520 Build& build = (*i).second;
521 for(Build::iterator j = build.begin(); j != build.end(); ++j)
523 Tools::iterator k = tools.find((*j).first);
524 if(k == g_build_tools.end())
526 build_error_undefined_tool((*i).first.c_str(), (*j).first.c_str());
533 void build_run(const char* name, CommandListener& listener)
535 for(Tools::iterator i = g_build_tools.begin(); i != g_build_tools.end(); ++i)
538 (*i).second.evaluate(output);
539 build_set_variable((*i).first.c_str(), output.c_str());
543 Project::iterator i = Project_find(g_build_project, name);
544 if(i != g_build_project.end())
546 Build& build = (*i).second;
547 for(Build::iterator j = build.begin(); j != build.end(); ++j)
550 (*j).evaluate(output);
551 listener.execute(output.c_str());
556 globalErrorStream() << "build " << makeQuoted(name) << " not defined";
562 typedef std::vector<XMLElementParser*> XMLElementStack;
564 class XMLParser : public XMLImporter
566 XMLElementStack m_stack;
568 XMLParser(XMLElementParser& parser)
570 m_stack.push_back(&parser);
572 std::size_t write(const char* buffer, std::size_t length)
574 return m_stack.back()->write(buffer, length);
576 void pushElement(const XMLElement& element)
578 m_stack.push_back(&m_stack.back()->pushElement(element));
580 void popElement(const char* name)
583 m_stack.back()->popElement(name);
587 #include "stream/textfilestream.h"
588 #include "xml/xmlparser.h"
590 const char* const BUILDMENU_VERSION = "2.0";
592 bool build_commands_parse(const char* filename)
594 TextFileInputStream projectFile(filename);
595 if(!projectFile.failed())
597 ProjectXMLConstructor projectConstructor(g_build_project, g_build_tools);
598 RootXMLConstructor rootConstructor("project", projectConstructor, BUILDMENU_VERSION);
599 XMLParser importer(rootConstructor);
600 XMLStreamParser parser(projectFile);
601 parser.exportXML(importer);
603 if(rootConstructor.versionCompatible())
605 project_verify(g_build_project, g_build_tools);
609 globalErrorStream() << "failed to parse build menu: " << makeQuoted(filename) << "\n";
614 void build_commands_clear()
616 g_build_project.clear();
617 g_build_tools.clear();
620 class BuildXMLExporter
624 BuildXMLExporter(Build& build) : m_build(build)
627 void exportXML(XMLImporter& importer)
630 for(Build::iterator i = m_build.begin(); i != m_build.end(); ++i)
632 StaticElement commandElement("command");
633 importer.pushElement(commandElement);
634 (*i).exportXML(importer);
635 importer.popElement(commandElement.name());
641 class ProjectXMLExporter
646 ProjectXMLExporter(Project& project, Tools& tools) : m_project(project), m_tools(tools)
649 void exportXML(XMLImporter& importer)
651 StaticElement projectElement("project");
652 projectElement.insertAttribute("version", BUILDMENU_VERSION);
653 importer.pushElement(projectElement);
656 for(Tools::iterator i = m_tools.begin(); i != m_tools.end(); ++i)
658 StaticElement toolElement("var");
659 toolElement.insertAttribute("name", (*i).first.c_str());
660 importer.pushElement(toolElement);
661 (*i).second.exportXML(importer);
662 importer.popElement(toolElement.name());
665 for(Project::iterator i = m_project.begin(); i != m_project.end(); ++i)
667 StaticElement buildElement("build");
668 buildElement.insertAttribute("name", (*i).first.c_str());
669 importer.pushElement(buildElement);
670 BuildXMLExporter buildExporter((*i).second);
671 buildExporter.exportXML(importer);
672 importer.popElement(buildElement.name());
675 importer.popElement(projectElement.name());
679 #include "xml/xmlwriter.h"
681 void build_commands_write(const char* filename)
683 TextFileOutputStream projectFile(filename);
684 if(!projectFile.failed())
686 XMLStreamWriter writer(projectFile);
687 ProjectXMLExporter projectExporter(g_build_project, g_build_tools);
689 projectExporter.exportXML(writer);
695 #include <gdk/gdkkeysyms.h>
696 #include <gtk/gtkmain.h>
697 #include <gtk/gtkbox.h>
698 #include <gtk/gtktable.h>
699 #include <gtk/gtktreeview.h>
700 #include <gtk/gtkcellrenderertext.h>
701 #include <gtk/gtktreeselection.h>
702 #include <gtk/gtkliststore.h>
703 #include <gtk/gtkscrolledwindow.h>
705 #include "gtkutil/dialog.h"
706 #include "gtkutil/closure.h"
707 #include "gtkutil/window.h"
710 void Build_refreshMenu(GtkMenu* menu);
713 void BSPCommandList_Construct(GtkListStore* store, Project& project)
715 gtk_list_store_clear(store);
717 for(Project::iterator i = project.begin(); i != project.end(); ++i)
719 const char* buildName = (*i).first.c_str();
721 GtkTreeIter buildIter;
722 gtk_list_store_append(store, &buildIter);
723 gtk_list_store_set(store, &buildIter, 0, const_cast<char*>(buildName), -1);
726 GtkTreeIter lastIter;
727 gtk_list_store_append(store, &lastIter);
734 GtkListStore* m_store;
736 ProjectList(Project& project) : m_project(project), m_changed(false)
741 gboolean project_cell_edited(GtkCellRendererText* cell, gchar* path_string, gchar* new_text, ProjectList* projectList)
743 Project& project = projectList->m_project;
745 GtkTreePath* path = gtk_tree_path_new_from_string(path_string);
747 ASSERT_MESSAGE(gtk_tree_path_get_depth(path) == 1, "invalid path length");
750 gtk_tree_model_get_iter(GTK_TREE_MODEL(projectList->m_store), &iter, path);
752 Project::iterator i = Project_find(project, gtk_tree_path_get_indices(path)[0]);
753 if(i != project.end())
755 projectList->m_changed = true;
756 if(string_empty(new_text))
759 Build_refreshMenu(g_bsp_menu);
761 gtk_list_store_remove(projectList->m_store, &iter);
765 (*i).first = new_text;
766 Build_refreshMenu(g_bsp_menu);
768 gtk_list_store_set(projectList->m_store, &iter, 0, new_text, -1);
771 else if(!string_empty(new_text))
773 projectList->m_changed = true;
774 project.push_back(Project::value_type(new_text, Build()));
775 Build_refreshMenu(g_bsp_menu);
777 gtk_list_store_set(projectList->m_store, &iter, 0, new_text, -1);
778 GtkTreeIter lastIter;
779 gtk_list_store_append(projectList->m_store, &lastIter);
782 gtk_tree_path_free(path);
787 gboolean project_key_press(GtkWidget* widget, GdkEventKey* event, ProjectList* projectList)
789 Project& project = projectList->m_project;
791 if(event->keyval == GDK_Delete)
793 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
796 if(gtk_tree_selection_get_selected(selection, &model, &iter))
798 GtkTreePath* path = gtk_tree_model_get_path(model, &iter);
799 Project::iterator x = Project_find(project, gtk_tree_path_get_indices(path)[0]);
800 gtk_tree_path_free(path);
802 if(x != project.end())
804 projectList->m_changed = true;
806 Build_refreshMenu(g_bsp_menu);
808 gtk_list_store_remove(projectList->m_store, &iter);
816 Build* g_current_build = 0;
818 gboolean project_selection_changed(GtkTreeSelection* selection, GtkListStore* store)
820 Project& project = g_build_project;
822 gtk_list_store_clear(store);
826 if(gtk_tree_selection_get_selected(selection, &model, &iter))
828 GtkTreePath* path = gtk_tree_model_get_path(model, &iter);
829 Project::iterator x = Project_find(project, gtk_tree_path_get_indices(path)[0]);
830 gtk_tree_path_free(path);
832 if(x != project.end())
834 Build& build = (*x).second;
835 g_current_build = &build;
837 for(Build::iterator i = build.begin(); i != build.end(); ++i)
839 GtkTreeIter commandIter;
840 gtk_list_store_append(store, &commandIter);
841 gtk_list_store_set(store, &commandIter, 0, const_cast<char*>((*i).c_str()), -1);
843 GtkTreeIter lastIter;
844 gtk_list_store_append(store, &lastIter);
859 gboolean commands_cell_edited(GtkCellRendererText* cell, gchar* path_string, gchar* new_text, GtkListStore* store)
861 if(g_current_build == 0)
865 Build& build = *g_current_build;
867 GtkTreePath* path = gtk_tree_path_new_from_string(path_string);
869 ASSERT_MESSAGE(gtk_tree_path_get_depth(path) == 1, "invalid path length");
872 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
874 Build::iterator i = Build_find(build, gtk_tree_path_get_indices(path)[0]);
877 g_build_changed = true;
878 (*i).setString(new_text);
880 gtk_list_store_set(store, &iter, 0, new_text, -1);
882 else if(!string_empty(new_text))
884 g_build_changed = true;
885 build.push_back(Build::value_type(VariableString(new_text)));
887 gtk_list_store_set(store, &iter, 0, new_text, -1);
889 GtkTreeIter lastIter;
890 gtk_list_store_append(store, &lastIter);
893 gtk_tree_path_free(path);
898 gboolean commands_key_press(GtkWidget* widget, GdkEventKey* event, GtkListStore* store)
900 if(g_current_build == 0)
904 Build& build = *g_current_build;
906 if(event->keyval == GDK_Delete)
908 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
911 if(gtk_tree_selection_get_selected(selection, &model, &iter))
913 GtkTreePath* path = gtk_tree_model_get_path(model, &iter);
914 Build::iterator i = Build_find(build, gtk_tree_path_get_indices(path)[0]);
915 gtk_tree_path_free(path);
919 g_build_changed = true;
922 gtk_list_store_remove(store, &iter);
930 GtkWindow* BuildMenuDialog_construct(ModalDialog& modal, ProjectList& projectList)
932 GtkWindow* window = create_dialog_window(MainFrame_getWindow(), "Build Menu", G_CALLBACK(dialog_delete_callback), &modal, -1, 400);
934 GtkWidget* buildView = 0;
937 GtkTable* table1 = create_dialog_table(2, 2, 4, 4, 4);
938 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(table1));
940 GtkVBox* vbox = create_dialog_vbox(4);
941 gtk_table_attach(table1, GTK_WIDGET(vbox), 1, 2, 0, 1,
942 (GtkAttachOptions) (GTK_FILL),
943 (GtkAttachOptions) (GTK_FILL), 0, 0);
945 GtkButton* button = create_dialog_button("OK", G_CALLBACK(dialog_button_ok), &modal);
946 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
949 GtkButton* button = create_dialog_button("Cancel", G_CALLBACK(dialog_button_cancel), &modal);
950 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
954 GtkFrame* frame = create_dialog_frame("Build menu");
955 gtk_table_attach(table1, GTK_WIDGET(frame), 0, 1, 0, 1,
956 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
957 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
959 GtkScrolledWindow* scr = create_scrolled_window(GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC, 4);
960 gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(scr));
963 GtkListStore* store = gtk_list_store_new(1, G_TYPE_STRING);
965 GtkWidget* view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
966 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
968 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
969 object_set_boolean_property(G_OBJECT(renderer), "editable", TRUE);
970 g_signal_connect(renderer, "edited", G_CALLBACK(project_cell_edited), &projectList);
972 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("", renderer, "text", 0, 0);
973 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
975 GtkTreeSelection* selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
976 gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
978 gtk_widget_show(view);
981 projectList.m_store = store;
982 gtk_container_add(GTK_CONTAINER (scr), view);
984 g_signal_connect(G_OBJECT(view), "key_press_event", G_CALLBACK(project_key_press), &projectList);
986 g_object_unref(G_OBJECT(store));
991 GtkFrame* frame = create_dialog_frame("Commandline");
992 gtk_table_attach(table1, GTK_WIDGET(frame), 0, 1, 1, 2,
993 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
994 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
996 GtkScrolledWindow* scr = create_scrolled_window(GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC, 4);
997 gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(scr));
1000 GtkListStore* store = gtk_list_store_new(1, G_TYPE_STRING);
1002 GtkWidget* view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
1003 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
1005 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1006 object_set_boolean_property(G_OBJECT(renderer), "editable", TRUE);
1007 g_signal_connect(renderer, "edited", G_CALLBACK(commands_cell_edited), store);
1009 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("", renderer, "text", 0, 0);
1010 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
1012 GtkTreeSelection* selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
1013 gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
1015 gtk_widget_show(view);
1017 gtk_container_add(GTK_CONTAINER (scr), view);
1019 g_object_unref(G_OBJECT(store));
1021 g_signal_connect(G_OBJECT(view), "key_press_event", G_CALLBACK(commands_key_press), store);
1023 g_signal_connect(G_OBJECT(gtk_tree_view_get_selection(GTK_TREE_VIEW(buildView))), "changed", G_CALLBACK(project_selection_changed), store);
1029 BSPCommandList_Construct(projectList.m_store, g_build_project);
1036 CopiedString g_buildMenu;
1039 void LoadBuildMenu();
1045 ProjectList projectList(g_build_project);
1047 GtkWindow* window = BuildMenuDialog_construct(modal, projectList);
1049 if(modal_dialog_show(window, modal) == eIDCANCEL)
1051 build_commands_clear();
1054 Build_refreshMenu(g_bsp_menu);
1056 else if(projectList.m_changed)
1058 g_build_changed = true;
1061 gtk_widget_destroy(GTK_WIDGET(window));
1066 #include "gtkutil/menu.h"
1067 #include "mainframe.h"
1068 #include "preferences.h"
1071 typedef struct _GtkMenuItem GtkMenuItem;
1077 GtkMenuItem* m_item;
1078 BuildMenuItem(const char* name, GtkMenuItem* item)
1079 : m_name(name), m_item(item)
1086 typedef MemberCaller<BuildMenuItem, &BuildMenuItem::run> RunCaller;
1089 typedef std::list<BuildMenuItem> BuildMenuItems;
1090 BuildMenuItems g_BuildMenuItems;
1093 GtkMenu* g_bsp_menu;
1095 void Build_constructMenu(GtkMenu* menu)
1097 for(Project::iterator i = g_build_project.begin(); i != g_build_project.end(); ++i)
1099 g_BuildMenuItems.push_back(BuildMenuItem((*i).first.c_str(), 0));
1100 g_BuildMenuItems.back().m_item = create_menu_item_with_mnemonic(menu, (*i).first.c_str(), BuildMenuItem::RunCaller(g_BuildMenuItems.back()));
1105 void Build_refreshMenu(GtkMenu* menu)
1107 for(BuildMenuItems::iterator i = g_BuildMenuItems.begin(); i != g_BuildMenuItems.end(); ++i)
1109 gtk_container_remove(GTK_CONTAINER(menu), GTK_WIDGET((*i).m_item));
1112 g_BuildMenuItems.clear();
1114 Build_constructMenu(menu);
1118 void LoadBuildMenu()
1120 if(string_empty(g_buildMenu.c_str()) || !build_commands_parse(g_buildMenu.c_str()))
1123 StringOutputStream buffer(256);
1124 buffer << GameToolsPath_get() << "default_build_menu.xml";
1126 bool success = build_commands_parse(buffer.c_str());
1127 ASSERT_MESSAGE(success, "failed to parse default build commands: " << buffer.c_str());
1130 StringOutputStream buffer(256);
1131 buffer << SettingsPath_get() << g_pGameDescription->mGameFile.c_str() << "/build_menu.xml";
1133 g_buildMenu = buffer.c_str();
1138 void SaveBuildMenu()
1142 g_build_changed = false;
1143 build_commands_write(g_buildMenu.c_str());
1147 #include "preferencesystem.h"
1148 #include "stringio.h"
1150 void BuildMenu_Construct()
1152 GlobalPreferenceSystem().registerPreference("BuildMenu", CopiedStringImportStringCaller(g_buildMenu), CopiedStringExportStringCaller(g_buildMenu));
1155 void BuildMenu_Destroy()