1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 Copyright (C) 2003 Biswapesh Chattopadhyay
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * First tool configuratin dialog, presenting all tools in a list.
23 * In this dialog, you can enable, disable, add, remove and order tools.
25 *---------------------------------------------------------------------------*/
34 /*---------------------------------------------------------------------------*/
36 /* Widget and signal name found in gtk builder file
37 *---------------------------------------------------------------------------*/
39 #define TOOL_LIST "list_tools"
40 #define TOOL_TREEVIEW "tools_treeview"
41 #define TOOL_EDIT_BUTTON "edit_bt"
42 #define TOOL_DELETE_BUTTON "delete_bt"
43 #define TOOL_UP_BUTTON "up_bt"
44 #define TOOL_DOWN_BUTTON "down_bt"
46 /* Gtk builder callbacks */
47 void atp_on_tool_add (GtkButton
*button
, gpointer user_data
);
48 void atp_on_tool_activated (GtkTreeView
*treeview
, GtkTreePath
*path
, GtkTreeViewColumn
*col
, gpointer user_data
);
49 void atp_on_tool_edit (GtkButton
*button
, gpointer user_data
);
50 void atp_on_tool_delete (GtkButton
*button
, gpointer user_data
);
51 void atp_on_tool_up (GtkButton
*button
, gpointer user_data
);
52 void atp_on_tool_down (GtkButton
*button
, gpointer user_data
);
54 /* column of the list view */
56 ATP_TOOLS_ENABLED_COLUMN
,
57 ATP_TOOLS_NAME_COLUMN
,
58 ATP_TOOLS_DATA_COLUMN
,
62 /* Useful function used by GUI code
63 *---------------------------------------------------------------------------*/
66 get_current_tool (const ATPToolDialog
*this)
69 GtkTreeSelection
*sel
;
73 sel
= gtk_tree_view_get_selection (GTK_TREE_VIEW (this->view
));
74 if (gtk_tree_selection_get_selected (sel
, &model
, &iter
))
76 gtk_tree_model_get (model
, &iter
, ATP_TOOLS_DATA_COLUMN
, &tool
, -1);
85 update_sensitivity (const ATPToolDialog
*this)
88 gboolean tool_selected
;
91 gboolean tool_deletable
;
93 /* Get current selected tool */
94 tool
= get_current_tool (this);
95 tool_selected
= tool
!= NULL
;
96 tool_up
= tool_selected
&& (atp_user_tool_previous (tool
) != NULL
);
97 tool_down
= tool_selected
&& (atp_user_tool_next (tool
) != NULL
);
98 tool_deletable
= tool_selected
&& (atp_user_tool_get_storage (tool
) > ATP_TSTORE_GLOBAL
);
100 gtk_widget_set_sensitive(this->edit_bt
, tool_selected
);
101 gtk_widget_set_sensitive(this->delete_bt
, tool_deletable
);
102 gtk_widget_set_sensitive(this->up_bt
, tool_up
);
103 gtk_widget_set_sensitive(this->down_bt
, tool_down
);
107 get_current_writable_tool (ATPToolDialog
*this)
111 tool
= get_current_tool(this);
114 if (atp_user_tool_get_storage (tool
) <= ATP_TSTORE_GLOBAL
)
116 /* global tool are read only so create a writeable one */
117 tool
= atp_user_tool_clone_new (tool
, ATP_TSTORE_LOCAL
);
125 *---------------------------------------------------------------------------*/
128 atp_on_tool_add (GtkButton
*button
, gpointer user_data
)
130 ATPToolDialog
*this = (ATPToolDialog
*)user_data
;
134 tool
= get_current_tool (this);
138 /* Add the new tool at the end of the list */
139 tool
= atp_tool_list_append_new (atp_plugin_get_tool_list (this->plugin
), NULL
, ATP_TSTORE_LOCAL
);
143 /* Add tool after the current one */
144 tool
= atp_user_tool_append_new (tool
, NULL
, ATP_TSTORE_LOCAL
);
147 ted
= atp_tool_editor_new (tool
, &this->tedl
, this);
148 atp_tool_editor_show (ted
);
152 atp_on_tool_edit (GtkButton
*button
, gpointer user_data
)
154 ATPToolDialog
*this = (ATPToolDialog
*)user_data
;
158 /* Warning button could be NULL (called from on_row_activated) */
160 tool
= get_current_writable_tool (this);
163 ted
= atp_tool_editor_new (tool
, &this->tedl
, this);
164 atp_tool_editor_show (ted
);
169 atp_on_tool_delete (GtkButton
*button
, gpointer user_data
)
171 ATPToolDialog
*this = (ATPToolDialog
*)user_data
;
174 tool
= get_current_tool (this);
175 if ((tool
!= NULL
) && (atp_user_tool_get_storage (tool
) > ATP_TSTORE_GLOBAL
))
177 if (anjuta_util_dialog_boolean_question (GTK_WINDOW (this->dialog
), FALSE
,
178 _("Are you sure you want to delete the '%s' tool?"), atp_user_tool_get_name(tool
)))
180 atp_user_tool_free (tool
);
181 atp_tool_dialog_refresh (this, NULL
);
187 atp_on_tool_up (GtkButton
*button
, gpointer user_data
)
189 ATPToolDialog
*this = (ATPToolDialog
*)user_data
;
193 tool
= get_current_writable_tool (this);
196 prev
= atp_user_tool_previous (tool
);
199 if (atp_user_tool_get_storage (prev
) <= ATP_TSTORE_GLOBAL
)
201 /* global tool are read only so create a writeable one */
202 prev
= atp_user_tool_clone_new (prev
, ATP_TSTORE_LOCAL
);
204 atp_user_tool_move_after (prev
, tool
);
205 atp_tool_dialog_refresh (this, atp_user_tool_get_name (tool
));
211 atp_on_tool_down (GtkButton
*button
, gpointer user_data
)
213 ATPToolDialog
*this = (ATPToolDialog
*)user_data
;
217 tool
= get_current_writable_tool (this);
220 next
= atp_user_tool_next (tool
);
223 atp_user_tool_move_after (tool
, next
);
224 atp_tool_dialog_refresh (this, atp_user_tool_get_name (tool
));
230 atp_on_tool_activated (GtkTreeView
*treeview
, GtkTreePath
*path
, GtkTreeViewColumn
*col
, gpointer user_data
)
232 atp_on_tool_edit (NULL
, user_data
);
236 on_tool_enable (GtkCellRendererToggle
*cell_renderer
, const gchar
*path
, gpointer user_data
)
238 ATPToolDialog
*this = (ATPToolDialog
*)user_data
;
243 model
= gtk_tree_view_get_model (this->view
);
244 if (gtk_tree_model_get_iter_from_string (model
, &iter
, path
))
246 gtk_tree_model_get (model
, &iter
, ATP_TOOLS_DATA_COLUMN
, &tool
, -1);
247 atp_user_tool_set_flag (tool
, ATP_TOOL_ENABLE
| ATP_TOGGLE
);
249 gtk_list_store_set (GTK_LIST_STORE(model
), &iter
, ATP_TOOLS_ENABLED_COLUMN
,
250 atp_user_tool_get_flag (tool
, ATP_TOOL_ENABLE
), -1);
255 on_tool_selection_changed (GtkTreeSelection
*selection
, gpointer user_data
)
257 ATPToolDialog
*this = (ATPToolDialog
*)user_data
;
259 update_sensitivity (this);
263 *---------------------------------------------------------------------------*/
266 atp_tool_dialog_refresh (const ATPToolDialog
*this, const gchar
* select
)
270 GtkTreeSelection
*selection
;
272 /* Disable changed signal to avoid changing buttons sensitivity */
273 selection
= gtk_tree_view_get_selection (this->view
);
274 g_signal_handler_block (selection
, this->changed_sig
);
276 /* Regenerate the tool list */
277 model
= gtk_tree_view_get_model (this->view
);
278 gtk_list_store_clear (GTK_LIST_STORE(model
));
279 tool
= atp_tool_list_first (atp_plugin_get_tool_list (this->plugin
));
284 gtk_list_store_append (GTK_LIST_STORE(model
), &iter
);
285 gtk_list_store_set (GTK_LIST_STORE(model
), &iter
,
286 ATP_TOOLS_ENABLED_COLUMN
,
287 atp_user_tool_get_flag (tool
, ATP_TOOL_ENABLE
),
288 ATP_TOOLS_NAME_COLUMN
,
289 atp_user_tool_get_name (tool
),
290 ATP_TOOLS_DATA_COLUMN
, tool
,
292 if ((select
!= NULL
) && (strcmp(select
, atp_user_tool_get_name (tool
)) == 0))
294 gtk_tree_selection_select_iter (selection
, &iter
);
296 tool
= atp_user_tool_next (tool
);
300 /* Regenerate the tool menu */
301 atp_tool_list_activate (atp_plugin_get_tool_list (this->plugin
));
303 /* Restore changed signal */
304 g_signal_handler_unblock (selection
, this->changed_sig
);
305 update_sensitivity(this);
307 /* Just save tool list */
308 atp_anjuta_tools_save(this->plugin
);
311 /* Start the tool lister and editor */
314 atp_tool_dialog_show (ATPToolDialog
* this, GtkBuilder
*bxml
)
317 GtkCellRenderer
*renderer
;
318 GtkTreeViewColumn
*column
;
319 GtkTreeSelection
*selection
;
322 anjuta_util_builder_get_objects (bxml
,
323 TOOL_LIST
, &this->dialog
,
324 TOOL_TREEVIEW
, &this->view
,
325 TOOL_EDIT_BUTTON
, &this->edit_bt
,
326 TOOL_DELETE_BUTTON
, &this->delete_bt
,
327 TOOL_UP_BUTTON
, &this->up_bt
,
328 TOOL_DOWN_BUTTON
, & this->down_bt
,
330 gtk_window_set_transient_for (GTK_WINDOW (this->dialog
), atp_plugin_get_app_window (this->plugin
));
332 /* Create tree view */
333 model
= GTK_TREE_MODEL (gtk_list_store_new (ATP_N_TOOLS_COLUMNS
,
334 G_TYPE_BOOLEAN
, G_TYPE_STRING
, G_TYPE_POINTER
));
335 gtk_tree_view_set_model (this->view
, model
);
337 renderer
= gtk_cell_renderer_toggle_new ();
338 g_signal_connect (G_OBJECT (renderer
), "toggled", G_CALLBACK (on_tool_enable
), this);
339 column
= gtk_tree_view_column_new_with_attributes ("", renderer
,
340 "active", ATP_TOOLS_ENABLED_COLUMN
, NULL
);
341 gtk_tree_view_append_column (this->view
, column
);
343 renderer
= gtk_cell_renderer_text_new ();
344 column
= gtk_tree_view_column_new_with_attributes (_("Tool"), renderer
,
345 "text", ATP_TOOLS_NAME_COLUMN
, NULL
);
346 gtk_tree_view_append_column (this->view
, column
);
347 g_object_unref (model
);
349 /* Connect all signals */
350 gtk_builder_connect_signals (bxml
, this);
351 selection
= gtk_tree_view_get_selection (this->view
);
352 this->changed_sig
= g_signal_connect (G_OBJECT (selection
), "changed", G_CALLBACK (on_tool_selection_changed
), this);
354 atp_tool_dialog_refresh (this, NULL
);
358 atp_tool_dialog_close (ATPToolDialog
*this)
360 atp_tool_editor_list_destroy (&this->tedl
);
364 gtk_widget_destroy (GTK_WIDGET(this->dialog
));
370 *---------------------------------------------------------------------------*/
373 atp_tool_dialog_get_window (const ATPToolDialog
*this)
375 return GTK_WINDOW (this->dialog
);
379 atp_tool_dialog_get_variable (const ATPToolDialog
*this)
381 return atp_plugin_get_variable (this->plugin
);
384 /* Creation and Destruction
385 *---------------------------------------------------------------------------*/
388 atp_tool_dialog_construct (ATPToolDialog
*this, ATPPlugin
*plugin
)
390 this->plugin
= plugin
;
392 atp_tool_editor_list_construct (&this->tedl
);
396 atp_tool_dialog_destroy (ATPToolDialog
*this)
398 atp_tool_dialog_close (this);