static void edit_script_cb (GtkButton *button, DialogData *data) { GtkTreeSelection *selection; GtkTreeModel *model = GTK_TREE_MODEL (data->list_store); GtkTreeIter iter; GthScript *script; GtkWidget *dialog; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->list_view)); if (! gtk_tree_selection_get_selected (selection, &model, &iter)) return; gtk_tree_model_get (model, &iter, COLUMN_SCRIPT, &script, -1); if (script == NULL) return; dialog = gth_script_editor_dialog_new (_("Edit Command"), GTK_WINDOW (data->dialog)); gth_script_editor_dialog_set_script (GTH_SCRIPT_EDITOR_DIALOG (dialog), script); g_signal_connect (dialog, "response", G_CALLBACK (script_editor_dialog__response_cb), data); gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); gtk_window_present (GTK_WINDOW (dialog)); g_object_unref (script); }
static void gth_script_editor_dialog_finalize (GObject *object) { GthScriptEditorDialog *dialog; dialog = GTH_SCRIPT_EDITOR_DIALOG (object); if (dialog->priv != NULL) { g_object_unref (dialog->priv->builder); g_free (dialog->priv->script_id); g_free (dialog->priv); dialog->priv = NULL; } G_OBJECT_CLASS (gth_script_editor_dialog_parent_class)->finalize (object); }
static void script_editor_dialog__response_cb (GtkDialog *dialog, int response, gpointer user_data) { DialogData *data = user_data; GthScript *script; GError *error = NULL; GthScriptFile *script_file; gboolean new_script; GtkTreeIter iter; gboolean change_list = TRUE; if (response == GTK_RESPONSE_HELP) { /* FIXME: show help dialog */ return; } if (response != GTK_RESPONSE_OK) { gtk_widget_destroy (GTK_WIDGET (dialog)); return; } script = gth_script_editor_dialog_get_script (GTH_SCRIPT_EDITOR_DIALOG (dialog), &error); if (script == NULL) { _gtk_error_dialog_from_gerror_show (GTK_WINDOW (dialog), _("Could not save the script"), error); g_clear_error (&error); return; } /* update the script file */ script_file = gth_script_file_get (); new_script = ! gth_script_file_has_script (script_file, script); g_signal_handlers_block_by_func (script_file, scripts_changed_cb, data); gth_script_file_add (script_file, script); gth_script_file_save (script_file, NULL); /* FIXME: handle errors */ g_signal_handlers_unblock_by_func (script_file, scripts_changed_cb, data); /* update the script list */ if (new_script) { g_signal_handlers_block_by_func (data->list_store, row_inserted_cb, data); gtk_list_store_append (data->list_store, &iter); g_signal_handlers_unblock_by_func (data->list_store, row_inserted_cb, data); } else change_list = get_script_iter (data, script, &iter); if (change_list) { char *shortcut; shortcut = get_script_shortcut (script); gtk_list_store_set (data->list_store, &iter, COLUMN_SCRIPT, script, COLUMN_NAME, gth_script_get_display_name (script), COLUMN_SHORTCUT, shortcut, COLUMN_VISIBLE, gth_script_is_visible (script), -1); g_free (shortcut); } gtk_widget_destroy (GTK_WIDGET (dialog)); g_object_unref (script); }