]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
support for separators in build menu
authorRudolf Polzer <divverent@alientrap.org>
Fri, 13 Jan 2012 20:44:52 +0000 (21:44 +0100)
committerRudolf Polzer <divverent@alientrap.org>
Fri, 13 Jan 2012 20:44:52 +0000 (21:44 +0100)
radiant/build.cpp

index dcb23a28c0b6b1075f666b139908f3bffb4db48d..c7e910a58c15409dc27d4ef2596626bb61d0140a 100644 (file)
@@ -337,6 +337,19 @@ public:
 };
 
 typedef std::pair<CopiedString, Build> BuildPair;
+#define SEPARATOR_STRING "-"
+static bool is_separator(const BuildPair &p)
+{
+      if(!string_equal(p.first.c_str(), SEPARATOR_STRING))
+             return false;
+      for(Build::const_iterator j = p.second.begin(); j != p.second.end(); ++j)
+      {
+             if(!string_equal((*j).c_str(), ""))
+                     return false;
+      }
+      return true;
+}
+
 
 class BuildPairEqual
 {
@@ -415,6 +428,11 @@ public:
       m_build = new BuildXMLConstructor(m_project.back().second);
       return *m_build;
     }
+    else if(string_equal(element.name(), "separator"))
+    {
+      m_project.push_back(Project::value_type(SEPARATOR_STRING, Build()));
+      return *this;
+    }
     else
     {
       ERROR_MESSAGE("parse error: invalid element");
@@ -664,13 +682,23 @@ public:
     }
     for(Project::iterator i = m_project.begin(); i != m_project.end(); ++i)
     {
-      StaticElement buildElement("build");
-      buildElement.insertAttribute("name", (*i).first.c_str());
-      importer.pushElement(buildElement);
-      BuildXMLExporter buildExporter((*i).second);
-      buildExporter.exportXML(importer);
-      importer.popElement(buildElement.name());
-      importer << "\n";
+      if(is_separator(*i))
+      {
+        StaticElement buildElement("separator");
+        importer.pushElement(buildElement);
+        importer.popElement(buildElement.name());
+        importer << "\n";
+      }
+      else
+      {
+        StaticElement buildElement("build");
+        buildElement.insertAttribute("name", (*i).first.c_str());
+        importer.pushElement(buildElement);
+        BuildXMLExporter buildExporter((*i).second);
+        buildExporter.exportXML(importer);
+        importer.popElement(buildElement.name());
+        importer << "\n";
+      }
     }
     importer.popElement(projectElement.name());
   }
@@ -756,15 +784,11 @@ gboolean project_cell_edited(GtkCellRendererText* cell, gchar* path_string, gcha
     if(string_empty(new_text))
     {
       project.erase(i);
-      Build_refreshMenu(g_bsp_menu);
-
       gtk_list_store_remove(projectList->m_store, &iter);
     }
     else
     {
       (*i).first = new_text;
-      Build_refreshMenu(g_bsp_menu);
-
       gtk_list_store_set(projectList->m_store, &iter, 0, new_text, -1);
     }
   }
@@ -772,7 +796,6 @@ gboolean project_cell_edited(GtkCellRendererText* cell, gchar* path_string, gcha
   {
     projectList->m_changed = true;
     project.push_back(Project::value_type(new_text, Build()));
-    Build_refreshMenu(g_bsp_menu);
 
     gtk_list_store_set(projectList->m_store, &iter, 0, new_text, -1);
     GtkTreeIter lastIter;
@@ -781,6 +804,8 @@ gboolean project_cell_edited(GtkCellRendererText* cell, gchar* path_string, gcha
 
   gtk_tree_path_free(path);
 
+  Build_refreshMenu(g_bsp_menu);
+
   return FALSE;
 }
 
@@ -892,6 +917,8 @@ gboolean commands_cell_edited(GtkCellRendererText* cell, gchar* path_string, gch
 
   gtk_tree_path_free(path);
 
+  Build_refreshMenu(g_bsp_menu);
+
   return FALSE;
 }
 
@@ -1097,7 +1124,14 @@ void Build_constructMenu(GtkMenu* menu)
   for(Project::iterator i = g_build_project.begin(); i != g_build_project.end(); ++i)
   {
     g_BuildMenuItems.push_back(BuildMenuItem((*i).first.c_str(), 0));
-    g_BuildMenuItems.back().m_item = create_menu_item_with_mnemonic(menu, (*i).first.c_str(), BuildMenuItem::RunCaller(g_BuildMenuItems.back()));
+    if(is_separator(*i))
+    {
+      g_BuildMenuItems.back().m_item = menu_separator(menu);
+    }
+    else
+    {
+      g_BuildMenuItems.back().m_item = create_menu_item_with_mnemonic(menu, (*i).first.c_str(), BuildMenuItem::RunCaller(g_BuildMenuItems.back()));
+    }
   }
 }