]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/findtexturedialog.cpp
* more translateable strings
[xonotic/netradiant.git] / radiant / findtexturedialog.cpp
1 /*
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
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.
11
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.
16
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
20 */
21
22 //
23 // Find/Replace textures dialogs
24 //
25 // Leonardo Zide (leo@lokigames.com)
26 //
27
28 #include "stdafx.h"
29 #include "findtexturedialog.h"
30 #include <glib/gi18n.h>
31
32 FindTextureDialog g_TexFindDlg;
33 FindTextureDialog& g_dlgFind = g_TexFindDlg;
34 static bool g_bFindActive = true;
35
36 static void OnApply(GtkWidget *widget, gpointer data)
37 {
38   g_dlgFind.UpdateData(TRUE);
39   FindReplaceTextures(g_dlgFind.m_strFind, g_dlgFind.m_strReplace,
40     g_dlgFind.m_bSelectedOnly, g_dlgFind.m_bForce, FALSE);
41 }
42
43 static void OnFind(GtkWidget *widget, gpointer data)
44 {
45   g_dlgFind.UpdateData(TRUE);
46   FindReplaceTextures(g_dlgFind.m_strFind, g_dlgFind.m_strReplace,
47     g_dlgFind.m_bSelectedOnly, FALSE, TRUE);
48 }
49
50 static void OnOK(GtkWidget *widget, gpointer data)
51 {
52   g_dlgFind.UpdateData(TRUE);
53   FindReplaceTextures(g_dlgFind.m_strFind, g_dlgFind.m_strReplace,
54     g_dlgFind.m_bSelectedOnly, g_dlgFind.m_bForce, FALSE);
55   g_dlgFind.HideDlg ();
56 }
57
58 static void OnClose(GtkWidget *widget, gpointer data)
59 {
60   g_dlgFind.HideDlg ();
61 }
62
63 static void popup_selected (GtkWidget *widget, gpointer data)
64 {
65   gchar *str;
66
67   gtk_label_get (GTK_LABEL (GTK_BIN (widget)->child), &str);
68   gtk_entry_set_text (GTK_ENTRY (data), str);
69 }
70
71 static void find_clicked (GtkWidget *widget, gpointer data)
72 {
73   GtkWidget *menu, *item;
74   menu = gtk_menu_new ();
75
76   for (int i = 0; i < QERApp_GetActiveShaderCount (); i++)
77   {
78     IShader *pShader = QERApp_ActiveShader_ForIndex (i);
79
80     item = gtk_menu_item_new_with_label (pShader->getName ());
81     gtk_signal_connect (GTK_OBJECT (item), "activate", GTK_SIGNAL_FUNC (popup_selected), data);
82     gtk_widget_show (item);
83     gtk_menu_append (GTK_MENU (menu), item);
84   }
85
86   gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 1, GDK_CURRENT_TIME);
87 }
88
89 static gint find_focus_in (GtkWidget *widget, GdkEventFocus *event, gpointer data)
90 {
91   g_bFindActive = true;
92   return FALSE;
93 }
94
95 static gint replace_focus_in (GtkWidget *widget, GdkEventFocus *event, gpointer data)
96 {
97   g_bFindActive = false;
98   return FALSE;
99 }
100
101 // =============================================================================
102 // FindTextureDialog class
103
104 FindTextureDialog::FindTextureDialog ()
105 {
106   m_bSelectedOnly = FALSE;
107   m_strFind = "";
108   m_strReplace = "";
109   m_bForce = FALSE;
110   m_bLive = TRUE;
111 }
112
113 FindTextureDialog::~FindTextureDialog ()
114 {
115 }
116
117 void FindTextureDialog::BuildDialog ()
118 {
119   GtkWidget *dlg, *vbox, *hbox, *table, *label;
120   GtkWidget *button, *check, *entry, *arrow;
121
122   dlg = m_pWidget;
123   gtk_window_set_title (GTK_WINDOW (dlg), "Find / Replace Texture(s)");
124   gtk_window_set_transient_for (GTK_WINDOW (dlg), GTK_WINDOW (g_pParentWnd->m_pWidget));
125
126   hbox = gtk_hbox_new (FALSE, 5);
127   gtk_widget_show (hbox);
128   gtk_container_add (GTK_CONTAINER (dlg), hbox);
129   gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
130
131   vbox = gtk_vbox_new (FALSE, 5);
132   gtk_widget_show (vbox);
133   gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
134
135   table = gtk_table_new (2, 3, FALSE);
136   gtk_widget_show (table);
137   gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
138   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
139   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
140
141   label = gtk_label_new ("Find:");
142   gtk_widget_show (label);
143   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
144                     (GtkAttachOptions) (GTK_FILL),
145                     (GtkAttachOptions) (0), 0, 0);
146   gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
147
148   label = gtk_label_new ("Replace:");
149   gtk_widget_show (label);
150   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
151                     (GtkAttachOptions) (GTK_FILL),
152                     (GtkAttachOptions) (0), 0, 0);
153   gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
154
155   entry = gtk_entry_new ();
156   gtk_widget_show (entry);
157   gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 0, 1,
158                     (GtkAttachOptions) (GTK_EXPAND|GTK_FILL),
159                     (GtkAttachOptions) (0), 0, 0);
160   gtk_signal_connect (GTK_OBJECT (entry), "focus_in_event",
161                       GTK_SIGNAL_FUNC (find_focus_in), NULL);
162   AddDialogData (entry, &m_strFind, DLG_ENTRY_TEXT);
163
164   button = gtk_button_new ();
165   gtk_widget_show (button);
166   gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1,
167                     (GtkAttachOptions) (GTK_FILL),
168                     (GtkAttachOptions) (GTK_FILL), 0, 0);
169   gtk_signal_connect (GTK_OBJECT (button), "clicked",
170                       GTK_SIGNAL_FUNC (find_clicked), entry);
171
172   arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
173   gtk_widget_show (arrow);
174   gtk_container_add (GTK_CONTAINER (button), arrow);
175
176   entry = gtk_entry_new ();
177   gtk_widget_show (entry);
178   gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 1, 2,
179                     (GtkAttachOptions) (GTK_EXPAND|GTK_FILL),
180                     (GtkAttachOptions) (0), 0, 0);
181   gtk_signal_connect (GTK_OBJECT (entry), "focus_in_event",
182                       GTK_SIGNAL_FUNC (replace_focus_in), NULL);
183   AddDialogData (entry, &m_strReplace, DLG_ENTRY_TEXT);
184
185   button = gtk_button_new ();
186   gtk_widget_show (button);
187   gtk_table_attach (GTK_TABLE (table), button, 2, 3, 1, 2,
188                     (GtkAttachOptions) (GTK_FILL),
189                     (GtkAttachOptions) (GTK_FILL), 0, 0);
190   gtk_signal_connect (GTK_OBJECT (button), "clicked",
191                       GTK_SIGNAL_FUNC (find_clicked), entry);
192
193   arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
194   gtk_widget_show (arrow);
195   gtk_container_add (GTK_CONTAINER (button), arrow);
196
197   check = gtk_check_button_new_with_label ("Use selected brushes only");
198   gtk_widget_show (check);
199   gtk_box_pack_start (GTK_BOX (vbox), check, TRUE, TRUE, 0);
200   AddDialogData (check, &m_bSelectedOnly, DLG_CHECK_BOOL);
201
202   check = gtk_check_button_new_with_label ("Replace everywhere (selected/active), don't test against Find");
203   gtk_widget_show (check);
204   gtk_box_pack_start (GTK_BOX (vbox), check, TRUE, TRUE, 0);
205   AddDialogData (check, &m_bForce, DLG_CHECK_BOOL);
206
207   check = gtk_check_button_new_with_label ("Live updates from Texture/Camera windows");
208   gtk_widget_show (check);
209   gtk_box_pack_start (GTK_BOX (vbox), check, TRUE, TRUE, 0);
210   AddDialogData (check, &m_bLive, DLG_CHECK_BOOL);
211
212   vbox = gtk_vbox_new (FALSE, 5);
213   gtk_widget_show (vbox);
214   gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
215
216   button = gtk_button_new_with_label( _("Find") );
217   gtk_widget_show( button );
218   gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
219   gtk_signal_connect( GTK_OBJECT( button ), "clicked",
220                       GTK_SIGNAL_FUNC( OnFind ), NULL );
221   gtk_widget_set_usize( button, 60, -2 );
222
223   button = gtk_button_new_with_label (_("OK"));
224   gtk_widget_show (button);
225   gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
226   gtk_signal_connect (GTK_OBJECT (button), "clicked",
227                       GTK_SIGNAL_FUNC (OnOK), NULL);
228   gtk_widget_set_usize (button, 60, -2);
229
230   button = gtk_button_new_with_label (_("Apply"));
231   gtk_widget_show (button);
232   gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
233   gtk_signal_connect (GTK_OBJECT (button), "clicked",
234                       GTK_SIGNAL_FUNC (OnApply), NULL);
235   gtk_widget_set_usize (button, 60, -2);
236
237   button = gtk_button_new_with_label (_("Close"));
238   gtk_widget_show (button);
239   gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
240   gtk_signal_connect (GTK_OBJECT (button), "clicked",
241                       GTK_SIGNAL_FUNC (OnClose), NULL);
242   gtk_widget_set_usize (button, 60, -2);
243
244   gtk_widget_show (dlg);
245 }
246
247 void FindTextureDialog::updateTextures(const char *p)
248 {
249   if (isOpen())
250   {
251     if (g_bFindActive)
252     {
253       setFindStr(p);
254     }
255     else
256     {
257       setReplaceStr(p);
258     }
259   }
260 }
261
262 bool FindTextureDialog::isOpen()
263 {
264   return (g_dlgFind.m_pWidget == NULL || GTK_WIDGET_VISIBLE (g_dlgFind.m_pWidget) == FALSE) ? false : true;
265 }
266
267 void FindTextureDialog::setFindStr(const char * p)
268 {
269   g_dlgFind.UpdateData(TRUE);
270   if (g_dlgFind.m_bLive)
271   {
272     g_dlgFind.m_strFind = p;
273     g_dlgFind.UpdateData(FALSE);
274   }
275 }
276
277 void FindTextureDialog::setReplaceStr(const char * p)
278 {
279   g_dlgFind.UpdateData(TRUE);
280   if (g_dlgFind.m_bLive)
281   {
282     g_dlgFind.m_strReplace = p;
283     g_dlgFind.UpdateData(FALSE);
284   }
285 }
286
287 void FindTextureDialog::show()
288 {
289   g_dlgFind.ShowDlg ();
290 }