2 * dialog-workbook-attr.c: Implements a dialog to set workbook attributes.
5 * JP Rosevear <jpr@arcavia.com>
7 * This program 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 * This program 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 this program; if not, see <https://www.gnu.org/licenses/>.
21 #include <gnumeric-config.h>
22 #include <glib/gi18n-lib.h>
28 #include <workbook-view.h>
31 #include <workbook-priv.h>
34 #define WORKBOOK_ATTRIBUTE_KEY "workbook-attribute-dialog"
48 GtkWidget
*apply_button
;
59 /*****************************************************************************/
60 /* Some utility routines shared by all pages */
62 /* Default to the 'View' page but remember which page we were on between
64 static int attr_dialog_page
= 0;
66 /*****************************************************************************/
69 cb_widget_changed (GtkWidget
*widget
, AttrState
*state
)
73 key
= g_object_get_data (G_OBJECT (widget
), "GNUMERIC:VIEWPROPERTY");
74 g_object_set (G_OBJECT (state
->wbv
),
75 key
, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget
)),
80 cb_attr_dialog_dialog_close (G_GNUC_UNUSED GtkWidget
*button
,
83 state
->destroying
= TRUE
;
84 gtk_widget_destroy (state
->dialog
);
88 cb_attr_dialog_dialog_destroy (AttrState
*state
)
90 if (state
->gui
!= NULL
) {
91 g_object_unref (state
->gui
);
99 /*****************************************************************************/
102 attr_dialog_init_toggle (AttrState
*state
, char const *name
, char const *key
)
104 GtkWidget
*w
= go_gtk_builder_get_widget (state
->gui
, name
);
105 gboolean val
= FALSE
;
107 g_object_get (G_OBJECT (state
->wbv
), key
, &val
, NULL
);
108 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w
), val
);
110 g_signal_connect (G_OBJECT (w
),
112 G_CALLBACK (cb_widget_changed
), state
);
113 g_object_set_data (G_OBJECT (w
), "GNUMERIC:VIEWPROPERTY", (gpointer
) key
);
118 attr_dialog_init_widget_page (AttrState
*state
)
120 attr_dialog_init_toggle
122 "WorkbookView::show_horizontal_scrollbar", "show_horizontal_scrollbar");
123 attr_dialog_init_toggle
125 "WorkbookView::show_vertical_scrollbar", "show_vertical_scrollbar");
126 attr_dialog_init_toggle
128 "WorkbookView::show_notebook_tabs", "show_notebook_tabs");
132 attr_dialog_init_autocompletion_page (AttrState
*state
)
134 attr_dialog_init_toggle
136 "WorkbookView::do_auto_completion", "do_auto_completion");
140 attr_dialog_init_cell_marker_page (AttrState
*state
)
142 attr_dialog_init_toggle
144 "WorkbookView::show_function_cell_markers",
145 "show_function_cell_markers");
146 attr_dialog_init_toggle
148 "WorkbookView::show_extension_markers",
149 "show_extension_markers");
153 attr_dialog_init_protection_page (AttrState
*state
)
155 attr_dialog_init_toggle
157 "WorkbookView::workbook_protected", "protected");
159 /*****************************************************************************/
163 attr_dialog_add_item (AttrState
*state
, char const *page_name
,
164 char const *icon_name
,
165 int page
, char const* parent_path
)
167 GtkTreeIter iter
, parent
;
168 GdkPixbuf
*icon
= icon_name
169 ? go_gtk_widget_render_icon_pixbuf (GTK_WIDGET (wbcg_toplevel (state
->wbcg
)), icon_name
, GTK_ICON_SIZE_MENU
)
172 if (parent_path
&& gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (state
->store
),
173 &parent
, parent_path
))
174 gtk_tree_store_append (state
->store
, &iter
, &parent
);
176 gtk_tree_store_append (state
->store
, &iter
, NULL
);
178 gtk_tree_store_set (state
->store
, &iter
,
180 ITEM_NAME
, _(page_name
),
184 g_object_unref (icon
);
188 char const *page_name
;
189 char const *icon_name
;
190 char const *parent_path
;
192 void (*page_initializer
) (AttrState
*state
);
195 static page_info_t
const page_info
[] = {
196 {N_("Widgets"), "gnumeric-object-scrollbar", NULL
, 0, &attr_dialog_init_widget_page
},
197 {N_("Protection"), GTK_STOCK_DIALOG_AUTHENTICATION
, NULL
, 1 ,&attr_dialog_init_protection_page
},
198 {N_("Auto Completion"), NULL
, NULL
, 2 ,&attr_dialog_init_autocompletion_page
},
199 {N_("Cell Markers"), NULL
, NULL
, 3 ,&attr_dialog_init_cell_marker_page
},
200 {NULL
, NULL
, NULL
, -1, NULL
},
209 attr_dialog_select_page_search (GtkTreeModel
*model
,
215 gtk_tree_model_get (model
, iter
, PAGE_NUMBER
, &page
, -1);
216 if (page
== pst
->page
) {
217 pst
->path
= gtk_tree_path_copy (path
);
224 attr_dialog_select_page (AttrState
*state
, int page
)
226 page_search_t pst
= {page
, NULL
};
229 gtk_tree_model_foreach (GTK_TREE_MODEL (state
->store
),
230 (GtkTreeModelForeachFunc
) attr_dialog_select_page_search
,
233 if (pst
.path
== NULL
)
234 pst
.path
= gtk_tree_path_new_from_string ("0");
236 if (pst
.path
!= NULL
) {
237 gtk_tree_view_set_cursor (state
->tview
, pst
.path
, NULL
, FALSE
);
238 gtk_tree_view_expand_row (state
->tview
, pst
.path
, TRUE
);
239 gtk_tree_path_free (pst
.path
);
244 cb_attr_dialog_selection_changed (GtkTreeSelection
*selection
,
249 if (gtk_tree_selection_get_selected (selection
, NULL
, &iter
)) {
250 gtk_tree_model_get (GTK_TREE_MODEL (state
->store
), &iter
,
251 PAGE_NUMBER
, &attr_dialog_page
,
253 gtk_notebook_set_current_page (GTK_NOTEBOOK (state
->notebook
), attr_dialog_page
);
255 attr_dialog_select_page (state
, attr_dialog_page
);
258 /*****************************************************************************/
261 attr_dialog_impl (AttrState
*state
)
263 GtkWidget
*dialog
= go_gtk_builder_get_widget (state
->gui
, "WorkbookAttr");
264 GtkTreeViewColumn
*column
;
265 GtkTreeSelection
*selection
;
268 g_return_if_fail (dialog
!= NULL
);
271 state
->dialog
= dialog
;
272 state
->notebook
= go_gtk_builder_get_widget (state
->gui
, "notebook");
273 state
->destroying
= FALSE
;
275 state
->tview
= GTK_TREE_VIEW(go_gtk_builder_get_widget (state
->gui
, "itemlist"));
276 state
->store
= gtk_tree_store_new (NUM_COLUMNS
,
280 gtk_tree_view_set_model (state
->tview
, GTK_TREE_MODEL(state
->store
));
281 g_object_unref (state
->store
);
282 selection
= gtk_tree_view_get_selection (state
->tview
);
283 gtk_tree_selection_set_mode (selection
, GTK_SELECTION_SINGLE
);
284 column
= gtk_tree_view_column_new_with_attributes ("",
285 gtk_cell_renderer_pixbuf_new (),
288 gtk_tree_view_append_column (state
->tview
, column
);
289 column
= gtk_tree_view_column_new_with_attributes ("",
290 gtk_cell_renderer_text_new (),
293 gtk_tree_view_append_column (state
->tview
, column
);
294 gtk_tree_view_set_expander_column (state
->tview
, column
);
296 g_signal_connect (selection
,
298 G_CALLBACK (cb_attr_dialog_selection_changed
), state
);
300 for (i
= 0; page_info
[i
].page
> -1; i
++) {
301 const page_info_t
*this_page
= &page_info
[i
];
302 this_page
->page_initializer (state
);
303 attr_dialog_add_item (state
, this_page
->page_name
, this_page
->icon_name
,
304 this_page
->page
, this_page
->parent_path
);
307 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (state
->store
), ITEM_NAME
, GTK_SORT_ASCENDING
);
309 g_signal_connect (G_OBJECT (go_gtk_builder_get_widget (state
->gui
, "close_button")),
311 G_CALLBACK (cb_attr_dialog_dialog_close
), state
);
313 gnm_init_help_button (
314 go_gtk_builder_get_widget (state
->gui
, "help_button"),
315 GNUMERIC_HELP_LINK_WORKBOOK_ATTRIBUTE
);
317 /* a candidate for merging into attach guru */
318 g_object_set_data_full (G_OBJECT (dialog
),
319 "state", state
, (GDestroyNotify
) cb_attr_dialog_dialog_destroy
);
320 wbc_gtk_attach_guru (state
->wbcg
, state
->dialog
);
321 gnm_keyed_dialog (state
->wbcg
, GTK_WINDOW (state
->dialog
),
322 WORKBOOK_ATTRIBUTE_KEY
);
323 gtk_widget_show (state
->dialog
);
327 dialog_workbook_attr (WBCGtk
*wbcg
)
332 g_return_if_fail (wbcg
!= NULL
);
334 if (gnm_dialog_raise_if_exists (wbcg
, WORKBOOK_ATTRIBUTE_KEY
))
337 gui
= gnm_gtk_builder_load ("res:ui/workbook-attr.ui", NULL
, GO_CMD_CONTEXT (wbcg
));
342 state
= g_new (AttrState
, 1);
345 state
->wbv
= wb_control_view (GNM_WBC (wbcg
));
346 state
->wb
= wb_control_get_workbook (GNM_WBC (wbcg
));
348 attr_dialog_impl (state
);
350 /* Select the same page the last invocation used */
351 attr_dialog_select_page (state
, attr_dialog_page
);