- Brushplugin Version 2.0, supports multiple collapse modes and a materialignore...
[xonotic/netradiant.git] / contrib / brushexport / callbacks.cpp
1 #include <glib.h>\r
2 #include <gtk/gtk.h>\r
3 #include <set>\r
4 \r
5 #include "qerplugin.h"\r
6 #include "debugging/debugging.h"\r
7 #include "support.h"\r
8 #include "export.h"\r
9 \r
10 // stuff from interface.cpp\r
11 void DestroyWindow();\r
12 \r
13 \r
14 namespace callbacks {\r
15 \r
16 void OnDestroy(GtkWidget* w, gpointer data)\r
17 {\r
18         DestroyWindow();\r
19 }\r
20 \r
21 void OnExportClicked(GtkButton* button, gpointer user_data)\r
22 {\r
23         GtkWidget* window = lookup_widget(GTK_WIDGET(button), "w_plugplug2");\r
24         ASSERT_NOTNULL(window);\r
25         const char* path = GlobalRadiant().m_pfnFileDialog(window, false, "Save as Obj", 0, 0);\r
26         if(!path)\r
27                 return;\r
28   \r
29   // get ignore list from ui\r
30   std::set<std::string> ignore;\r
31   \r
32   GtkTreeView* view = GTK_TREE_VIEW(lookup_widget(GTK_WIDGET(button), "t_materialist"));\r
33   GtkListStore* list = GTK_LIST_STORE(gtk_tree_view_get_model(view));\r
34 \r
35   GtkTreeIter iter;\r
36   bool valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list), &iter);\r
37   while(valid)\r
38   {\r
39     gchar* data;\r
40         gtk_tree_model_get(GTK_TREE_MODEL(list), &iter, 0, &data, -1);\r
41         globalOutputStream() << data << "\n";\r
42         ignore.insert(std::string(data));\r
43         g_free(data);\r
44         valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(list), &iter);\r
45   }\r
46   \r
47   for(std::set<std::string>::iterator it(ignore.begin()); it != ignore.end(); ++it)\r
48     globalOutputStream() << it->c_str() << "\n";\r
49   \r
50   // collapse mode\r
51   collapsemode mode = COLLAPSE_NONE;\r
52   \r
53   GtkWidget* radio = lookup_widget(GTK_WIDGET(button), "r_collapse");\r
54   ASSERT_NOTNULL(radio);\r
55   \r
56   if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio)))\r
57     mode = COLLAPSE_ALL;\r
58   else\r
59   {\r
60     radio = lookup_widget(GTK_WIDGET(button), "r_collapsebymaterial");\r
61     ASSERT_NOTNULL(radio);\r
62     if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio)))\r
63       mode = COLLAPSE_BY_MATERIAL;\r
64         else\r
65         {\r
66           radio = lookup_widget(GTK_WIDGET(button), "r_nocollapse");\r
67           ASSERT_NOTNULL(radio);\r
68           ASSERT_NOTNULL(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio)));\r
69           mode = COLLAPSE_NONE;\r
70         }\r
71   }\r
72   \r
73   // export\r
74   ExportSelection(ignore, mode, path);\r
75 }\r
76 \r
77 void OnAddMaterial(GtkButton* button, gpointer user_data)\r
78 {\r
79   GtkEntry* edit = GTK_ENTRY(lookup_widget(GTK_WIDGET(button), "ed_materialname"));\r
80   ASSERT_NOTNULL(edit);\r
81   \r
82   const gchar* name = gtk_entry_get_text(edit);\r
83   if(g_utf8_strlen(name, -1) > 0)\r
84   {\r
85         GtkListStore* list = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(lookup_widget(GTK_WIDGET(button), "t_materialist"))));\r
86         GtkTreeIter iter;\r
87         gtk_list_store_append(list, &iter);\r
88         gtk_list_store_set(list, &iter, 0, name, -1);\r
89         gtk_entry_set_text(edit, "");\r
90   }\r
91 }\r
92 \r
93 void OnRemoveMaterial(GtkButton* button, gpointer user_data)\r
94 {\r
95         GtkTreeView* view = GTK_TREE_VIEW(lookup_widget(GTK_WIDGET(button), "t_materialist"));\r
96         GtkListStore* list = GTK_LIST_STORE(gtk_tree_view_get_model(view));\r
97         GtkTreeSelection* sel = gtk_tree_view_get_selection(view);\r
98         \r
99         GtkTreeIter iter;\r
100         if(gtk_tree_selection_get_selected(sel, 0, &iter))\r
101           gtk_list_store_remove(list, &iter);\r
102 }\r
103 \r
104 }// callbacks\r