From 2ab142b0947aa5aa1b8f448bec37a9e55ba16809 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 11 Dec 2016 18:20:46 -0800 Subject: [PATCH 001/132] close-confirmation-dialog: Clean up code styling --- xed/dialogs/xed-close-confirmation-dialog.c | 975 ++++++++++---------- 1 file changed, 466 insertions(+), 509 deletions(-) diff --git a/xed/dialogs/xed-close-confirmation-dialog.c b/xed/dialogs/xed-close-confirmation-dialog.c index 7219f47..0e4dbfa 100755 --- a/xed/dialogs/xed-close-confirmation-dialog.c +++ b/xed/dialogs/xed-close-confirmation-dialog.c @@ -16,13 +16,13 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ /* - * Modified by the xed Team, 2004-2005. See the AUTHORS file for a - * list of people on the xed Team. + * Modified by the xed Team, 2004-2005. See the AUTHORS file for a + * list of people on the xed Team. * See the ChangeLog files for a list of changes. * * $Id$ @@ -41,716 +41,673 @@ /* Properties */ -enum +enum { - PROP_0, - PROP_UNSAVED_DOCUMENTS, - PROP_LOGOUT_MODE + PROP_0, + PROP_UNSAVED_DOCUMENTS, + PROP_LOGOUT_MODE }; /* Mode */ enum { - SINGLE_DOC_MODE, - MULTIPLE_DOCS_MODE + SINGLE_DOC_MODE, + MULTIPLE_DOCS_MODE }; /* Columns */ enum { - SAVE_COLUMN, - NAME_COLUMN, - DOC_COLUMN, /* a handy pointer to the document */ - N_COLUMNS + SAVE_COLUMN, + NAME_COLUMN, + DOC_COLUMN, /* a handy pointer to the document */ + N_COLUMNS }; -struct _XedCloseConfirmationDialogPrivate +struct _XedCloseConfirmationDialogPrivate { - gboolean logout_mode; - - GList *unsaved_documents; - - GList *selected_documents; - - GtkTreeModel *list_store; - + gboolean logout_mode; + GList *unsaved_documents; + GList *selected_documents; + GtkTreeModel *list_store; }; #define XED_CLOSE_CONFIRMATION_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ - XED_TYPE_CLOSE_CONFIRMATION_DIALOG, \ - XedCloseConfirmationDialogPrivate)) + XED_TYPE_CLOSE_CONFIRMATION_DIALOG, \ + XedCloseConfirmationDialogPrivate)) #define GET_MODE(priv) (((priv->unsaved_documents != NULL) && \ - (priv->unsaved_documents->next == NULL)) ? \ - SINGLE_DOC_MODE : MULTIPLE_DOCS_MODE) + (priv->unsaved_documents->next == NULL)) ? \ + SINGLE_DOC_MODE : MULTIPLE_DOCS_MODE) G_DEFINE_TYPE(XedCloseConfirmationDialog, xed_close_confirmation_dialog, GTK_TYPE_DIALOG) -static void set_unsaved_document (XedCloseConfirmationDialog *dlg, - const GList *list); +static void set_unsaved_document (XedCloseConfirmationDialog *dlg, + const GList *list); +static GList *get_selected_docs (GtkTreeModel *store); -static GList *get_selected_docs (GtkTreeModel *store); - -/* Since we connect in the costructor we are sure this handler will be called +/* Since we connect in the costructor we are sure this handler will be called * before the user ones */ static void response_cb (XedCloseConfirmationDialog *dlg, - gint response_id, - gpointer data) + gint response_id, + gpointer data) { - XedCloseConfirmationDialogPrivate *priv; + XedCloseConfirmationDialogPrivate *priv; - g_return_if_fail (XED_IS_CLOSE_CONFIRMATION_DIALOG (dlg)); + g_return_if_fail (XED_IS_CLOSE_CONFIRMATION_DIALOG (dlg)); - priv = dlg->priv; - - if (priv->selected_documents != NULL) - g_list_free (priv->selected_documents); + priv = dlg->priv; - if (response_id == GTK_RESPONSE_YES) - { - if (GET_MODE (priv) == SINGLE_DOC_MODE) - { - priv->selected_documents = - g_list_copy (priv->unsaved_documents); - } - else - { - g_return_if_fail (priv->list_store); + if (priv->selected_documents != NULL) + { + g_list_free (priv->selected_documents); + } - priv->selected_documents = - get_selected_docs (priv->list_store); - } - } - else - priv->selected_documents = NULL; + if (response_id == GTK_RESPONSE_YES) + { + if (GET_MODE (priv) == SINGLE_DOC_MODE) + { + priv->selected_documents = g_list_copy (priv->unsaved_documents); + } + else + { + g_return_if_fail (priv->list_store); + + priv->selected_documents = get_selected_docs (priv->list_store); + } + } + else + priv->selected_documents = NULL; } static void set_logout_mode (XedCloseConfirmationDialog *dlg, - gboolean logout_mode) + gboolean logout_mode) { - dlg->priv->logout_mode = logout_mode; - - if (logout_mode) - { - gtk_dialog_add_button (GTK_DIALOG (dlg), - _("Log Out _without Saving"), - GTK_RESPONSE_NO); + dlg->priv->logout_mode = logout_mode; - xed_dialog_add_button (GTK_DIALOG (dlg), - _("_Cancel Logout"), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); - } - else - { - gtk_dialog_add_button (GTK_DIALOG (dlg), - _("Close _without Saving"), - GTK_RESPONSE_NO); + if (logout_mode) + { + gtk_dialog_add_button (GTK_DIALOG (dlg), _("Log Out _without Saving"), GTK_RESPONSE_NO); + xed_dialog_add_button (GTK_DIALOG (dlg), _("_Cancel Logout"), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + } + else + { + gtk_dialog_add_button (GTK_DIALOG (dlg), _("Close _without Saving"), GTK_RESPONSE_NO); + gtk_dialog_add_button (GTK_DIALOG (dlg), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + } - gtk_dialog_add_button (GTK_DIALOG (dlg), - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - } - - - const gchar *stock_id = GTK_STOCK_SAVE; - - if (GET_MODE (dlg->priv) == SINGLE_DOC_MODE) - { - XedDocument *doc; - - doc = XED_DOCUMENT (dlg->priv->unsaved_documents->data); - - if (xed_document_get_readonly (doc) || - xed_document_is_untitled (doc)) - stock_id = GTK_STOCK_SAVE_AS; - } - gtk_dialog_add_button (GTK_DIALOG (dlg), - stock_id, - GTK_RESPONSE_YES); + const gchar *stock_id = GTK_STOCK_SAVE; - gtk_dialog_set_default_response (GTK_DIALOG (dlg), - GTK_RESPONSE_YES); + if (GET_MODE (dlg->priv) == SINGLE_DOC_MODE) + { + XedDocument *doc; + + doc = XED_DOCUMENT (dlg->priv->unsaved_documents->data); + + if (xed_document_get_readonly (doc) || xed_document_is_untitled (doc)) + { + stock_id = GTK_STOCK_SAVE_AS; + } + } + + gtk_dialog_add_button (GTK_DIALOG (dlg), stock_id, GTK_RESPONSE_YES); + gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_RESPONSE_YES); } -static void +static void xed_close_confirmation_dialog_init (XedCloseConfirmationDialog *dlg) { - AtkObject *atk_obj; + AtkObject *atk_obj; - dlg->priv = XED_CLOSE_CONFIRMATION_DIALOG_GET_PRIVATE (dlg); + dlg->priv = XED_CLOSE_CONFIRMATION_DIALOG_GET_PRIVATE (dlg); - gtk_container_set_border_width (GTK_CONTAINER (dlg), 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), - 14); - gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE); - gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dlg), TRUE); - - gtk_window_set_title (GTK_WINDOW (dlg), ""); + gtk_container_set_border_width (GTK_CONTAINER (dlg), 5); + gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), 14); + gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE); + gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dlg), TRUE); - gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); - gtk_window_set_destroy_with_parent (GTK_WINDOW (dlg), TRUE); + gtk_window_set_title (GTK_WINDOW (dlg), ""); - atk_obj = gtk_widget_get_accessible (GTK_WIDGET (dlg)); - atk_object_set_role (atk_obj, ATK_ROLE_ALERT); - atk_object_set_name (atk_obj, _("Question")); - - g_signal_connect (dlg, - "response", - G_CALLBACK (response_cb), - NULL); + gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); + gtk_window_set_destroy_with_parent (GTK_WINDOW (dlg), TRUE); + + atk_obj = gtk_widget_get_accessible (GTK_WIDGET (dlg)); + atk_object_set_role (atk_obj, ATK_ROLE_ALERT); + atk_object_set_name (atk_obj, _("Question")); + + g_signal_connect (dlg, "response", G_CALLBACK (response_cb), NULL); } -static void +static void xed_close_confirmation_dialog_finalize (GObject *object) { - XedCloseConfirmationDialogPrivate *priv; + XedCloseConfirmationDialogPrivate *priv; - priv = XED_CLOSE_CONFIRMATION_DIALOG (object)->priv; + priv = XED_CLOSE_CONFIRMATION_DIALOG (object)->priv; - if (priv->unsaved_documents != NULL) - g_list_free (priv->unsaved_documents); + if (priv->unsaved_documents != NULL) + { + g_list_free (priv->unsaved_documents); + } - if (priv->selected_documents != NULL) - g_list_free (priv->selected_documents); + if (priv->selected_documents != NULL) + { + g_list_free (priv->selected_documents); + } - /* Call the parent's destructor */ - G_OBJECT_CLASS (xed_close_confirmation_dialog_parent_class)->finalize (object); + /* Call the parent's destructor */ + G_OBJECT_CLASS (xed_close_confirmation_dialog_parent_class)->finalize (object); } static void -xed_close_confirmation_dialog_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) +xed_close_confirmation_dialog_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - XedCloseConfirmationDialog *dlg; + XedCloseConfirmationDialog *dlg; - dlg = XED_CLOSE_CONFIRMATION_DIALOG (object); + dlg = XED_CLOSE_CONFIRMATION_DIALOG (object); - switch (prop_id) - { - case PROP_UNSAVED_DOCUMENTS: - set_unsaved_document (dlg, g_value_get_pointer (value)); - break; - - case PROP_LOGOUT_MODE: - set_logout_mode (dlg, g_value_get_boolean (value)); - break; + switch (prop_id) + { + case PROP_UNSAVED_DOCUMENTS: + set_unsaved_document (dlg, g_value_get_pointer (value)); + break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + case PROP_LOGOUT_MODE: + set_logout_mode (dlg, g_value_get_boolean (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -xed_close_confirmation_dialog_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) +xed_close_confirmation_dialog_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { - XedCloseConfirmationDialogPrivate *priv; + XedCloseConfirmationDialogPrivate *priv; - priv = XED_CLOSE_CONFIRMATION_DIALOG (object)->priv; + priv = XED_CLOSE_CONFIRMATION_DIALOG (object)->priv; - switch( prop_id ) - { - case PROP_UNSAVED_DOCUMENTS: - g_value_set_pointer (value, priv->unsaved_documents); - break; + switch( prop_id ) + { + case PROP_UNSAVED_DOCUMENTS: + g_value_set_pointer (value, priv->unsaved_documents); + break; - case PROP_LOGOUT_MODE: - g_value_set_boolean (value, priv->logout_mode); - break; + case PROP_LOGOUT_MODE: + g_value_set_boolean (value, priv->logout_mode); + break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } -static void +static void xed_close_confirmation_dialog_class_init (XedCloseConfirmationDialogClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - gobject_class->set_property = xed_close_confirmation_dialog_set_property; - gobject_class->get_property = xed_close_confirmation_dialog_get_property; - gobject_class->finalize = xed_close_confirmation_dialog_finalize; + gobject_class->set_property = xed_close_confirmation_dialog_set_property; + gobject_class->get_property = xed_close_confirmation_dialog_get_property; + gobject_class->finalize = xed_close_confirmation_dialog_finalize; - g_type_class_add_private (klass, sizeof (XedCloseConfirmationDialogPrivate)); + g_type_class_add_private (klass, sizeof (XedCloseConfirmationDialogPrivate)); - g_object_class_install_property (gobject_class, - PROP_UNSAVED_DOCUMENTS, - g_param_spec_pointer ("unsaved_documents", - "Unsaved Documents", - "List of Unsaved Documents", - (G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY))); + g_object_class_install_property (gobject_class, + PROP_UNSAVED_DOCUMENTS, + g_param_spec_pointer ("unsaved_documents", + "Unsaved Documents", + "List of Unsaved Documents", + (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); - g_object_class_install_property (gobject_class, - PROP_LOGOUT_MODE, - g_param_spec_boolean ("logout_mode", - "Logout Mode", - "Whether the dialog is in logout mode", - FALSE, - (G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY))); + g_object_class_install_property (gobject_class, + PROP_LOGOUT_MODE, + g_param_spec_boolean ("logout_mode", + "Logout Mode", + "Whether the dialog is in logout mode", + FALSE, + (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); } static GList * get_selected_docs (GtkTreeModel *store) { - GList *list; - gboolean valid; - GtkTreeIter iter; + GList *list; + gboolean valid; + GtkTreeIter iter; - list = NULL; - valid = gtk_tree_model_get_iter_first (store, &iter); + list = NULL; + valid = gtk_tree_model_get_iter_first (store, &iter); - while (valid) - { - gboolean to_save; - XedDocument *doc; + while (valid) + { + gboolean to_save; + XedDocument *doc; - gtk_tree_model_get (store, &iter, - SAVE_COLUMN, &to_save, - DOC_COLUMN, &doc, - -1); - if (to_save) - list = g_list_prepend (list, doc); + gtk_tree_model_get (store, &iter, SAVE_COLUMN, &to_save, DOC_COLUMN, &doc, -1); + if (to_save) + { + list = g_list_prepend (list, doc); + } - valid = gtk_tree_model_iter_next (store, &iter); - } + valid = gtk_tree_model_iter_next (store, &iter); + } - list = g_list_reverse (list); + list = g_list_reverse (list); - return list; + return list; } GList * xed_close_confirmation_dialog_get_selected_documents (XedCloseConfirmationDialog *dlg) { - g_return_val_if_fail (XED_IS_CLOSE_CONFIRMATION_DIALOG (dlg), NULL); + g_return_val_if_fail (XED_IS_CLOSE_CONFIRMATION_DIALOG (dlg), NULL); - return g_list_copy (dlg->priv->selected_documents); + return g_list_copy (dlg->priv->selected_documents); } GtkWidget * -xed_close_confirmation_dialog_new (GtkWindow *parent, - GList *unsaved_documents, - gboolean logout_mode) +xed_close_confirmation_dialog_new (GtkWindow *parent, + GList *unsaved_documents, + gboolean logout_mode) { - GtkWidget *dlg; - g_return_val_if_fail (unsaved_documents != NULL, NULL); + GtkWidget *dlg; + g_return_val_if_fail (unsaved_documents != NULL, NULL); - dlg = GTK_WIDGET (g_object_new (XED_TYPE_CLOSE_CONFIRMATION_DIALOG, - "unsaved_documents", unsaved_documents, - "logout_mode", logout_mode, - NULL)); - g_return_val_if_fail (dlg != NULL, NULL); + dlg = GTK_WIDGET (g_object_new (XED_TYPE_CLOSE_CONFIRMATION_DIALOG, + "unsaved_documents", unsaved_documents, + "logout_mode", logout_mode, + NULL)); + g_return_val_if_fail (dlg != NULL, NULL); - if (parent != NULL) - { - gtk_window_group_add_window (xed_window_get_group (XED_WINDOW (parent)), - GTK_WINDOW (dlg)); - - gtk_window_set_transient_for (GTK_WINDOW (dlg), parent); - } + if (parent != NULL) + { + gtk_window_group_add_window (xed_window_get_group (XED_WINDOW (parent)), GTK_WINDOW (dlg)); + gtk_window_set_transient_for (GTK_WINDOW (dlg), parent); + } - return dlg; + return dlg; } GtkWidget * -xed_close_confirmation_dialog_new_single (GtkWindow *parent, - XedDocument *doc, - gboolean logout_mode) +xed_close_confirmation_dialog_new_single (GtkWindow *parent, + XedDocument *doc, + gboolean logout_mode) { - GtkWidget *dlg; - GList *unsaved_documents; - g_return_val_if_fail (doc != NULL, NULL); - - unsaved_documents = g_list_prepend (NULL, doc); + GtkWidget *dlg; + GList *unsaved_documents; + g_return_val_if_fail (doc != NULL, NULL); - dlg = xed_close_confirmation_dialog_new (parent, - unsaved_documents, - logout_mode); - - g_list_free (unsaved_documents); + unsaved_documents = g_list_prepend (NULL, doc); - return dlg; + dlg = xed_close_confirmation_dialog_new (parent, unsaved_documents, logout_mode); + + g_list_free (unsaved_documents); + + return dlg; } static gchar * get_text_secondary_label (XedDocument *doc) { - glong seconds; - gchar *secondary_msg; - - seconds = MAX (1, _xed_document_get_seconds_since_last_save_or_load (doc)); + glong seconds; + gchar *secondary_msg; - if (seconds < 55) - { - secondary_msg = g_strdup_printf ( - ngettext ("If you don't save, changes from the last %ld second " - "will be permanently lost.", - "If you don't save, changes from the last %ld seconds " - "will be permanently lost.", - seconds), - seconds); - } - else if (seconds < 75) /* 55 <= seconds < 75 */ - { - secondary_msg = g_strdup (_("If you don't save, changes from the last minute " - "will be permanently lost.")); - } - else if (seconds < 110) /* 75 <= seconds < 110 */ - { - secondary_msg = g_strdup_printf ( - ngettext ("If you don't save, changes from the last minute and %ld " - "second will be permanently lost.", - "If you don't save, changes from the last minute and %ld " - "seconds will be permanently lost.", - seconds - 60 ), - seconds - 60); - } - else if (seconds < 3600) - { - secondary_msg = g_strdup_printf ( - ngettext ("If you don't save, changes from the last %ld minute " - "will be permanently lost.", - "If you don't save, changes from the last %ld minutes " - "will be permanently lost.", - seconds / 60), - seconds / 60); - } - else if (seconds < 7200) - { - gint minutes; - seconds -= 3600; + seconds = MAX (1, _xed_document_get_seconds_since_last_save_or_load (doc)); - minutes = seconds / 60; - if (minutes < 5) - { - secondary_msg = g_strdup (_("If you don't save, changes from the last hour " - "will be permanently lost.")); - } - else - { - secondary_msg = g_strdup_printf ( - ngettext ("If you don't save, changes from the last hour and %d " - "minute will be permanently lost.", - "If you don't save, changes from the last hour and %d " - "minutes will be permanently lost.", - minutes), - minutes); - } - } - else - { - gint hours; + if (seconds < 55) + { + secondary_msg = g_strdup_printf (ngettext ("If you don't save, changes from the last %ld second " + "will be permanently lost.", + "If you don't save, changes from the last %ld seconds " + "will be permanently lost.", + seconds), + seconds); + } + else if (seconds < 75) /* 55 <= seconds < 75 */ + { + secondary_msg = g_strdup (_("If you don't save, changes from the last minute " + "will be permanently lost.")); + } + else if (seconds < 110) /* 75 <= seconds < 110 */ + { + secondary_msg = g_strdup_printf (ngettext ("If you don't save, changes from the last minute and %ld " + "second will be permanently lost.", + "If you don't save, changes from the last minute and %ld " + "seconds will be permanently lost.", + seconds - 60 ), + seconds - 60); + } + else if (seconds < 3600) + { + secondary_msg = g_strdup_printf (ngettext ("If you don't save, changes from the last %ld minute " + "will be permanently lost.", + "If you don't save, changes from the last %ld minutes " + "will be permanently lost.", + seconds / 60), + seconds / 60); + } + else if (seconds < 7200) + { + gint minutes; + seconds -= 3600; - hours = seconds / 3600; + minutes = seconds / 60; + if (minutes < 5) + { + secondary_msg = g_strdup (_("If you don't save, changes from the last hour " + "will be permanently lost.")); + } + else + { + secondary_msg = g_strdup_printf (ngettext ("If you don't save, changes from the last hour and %d " + "minute will be permanently lost.", + "If you don't save, changes from the last hour and %d " + "minutes will be permanently lost.", + minutes), + minutes); + } + } + else + { + gint hours; - secondary_msg = g_strdup_printf ( - ngettext ("If you don't save, changes from the last %d hour " - "will be permanently lost.", - "If you don't save, changes from the last %d hours " - "will be permanently lost.", - hours), - hours); - } + hours = seconds / 3600; - return secondary_msg; + secondary_msg = g_strdup_printf (ngettext ("If you don't save, changes from the last %d hour " + "will be permanently lost.", + "If you don't save, changes from the last %d hours " + "will be permanently lost.", + hours), + hours); + } + + return secondary_msg; } static void build_single_doc_dialog (XedCloseConfirmationDialog *dlg) { - GtkWidget *hbox; - GtkWidget *vbox; - GtkWidget *primary_label; - GtkWidget *secondary_label; - GtkWidget *image; - XedDocument *doc; - gchar *doc_name; - gchar *str; - gchar *markup_str; + GtkWidget *hbox; + GtkWidget *vbox; + GtkWidget *primary_label; + GtkWidget *secondary_label; + GtkWidget *image; + XedDocument *doc; + gchar *doc_name; + gchar *str; + gchar *markup_str; - g_return_if_fail (dlg->priv->unsaved_documents->data != NULL); - doc = XED_DOCUMENT (dlg->priv->unsaved_documents->data); + g_return_if_fail (dlg->priv->unsaved_documents->data != NULL); + doc = XED_DOCUMENT (dlg->priv->unsaved_documents->data); - /* Image */ - image = gtk_image_new_from_icon_name ("dialog-warning", - GTK_ICON_SIZE_DIALOG); - gtk_widget_set_halign (image, GTK_ALIGN_START); - gtk_widget_set_valign (image, GTK_ALIGN_END); + /* Image */ + image = gtk_image_new_from_icon_name ("dialog-warning", GTK_ICON_SIZE_DIALOG); + gtk_widget_set_halign (image, GTK_ALIGN_START); + gtk_widget_set_valign (image, GTK_ALIGN_END); - /* Primary label */ - primary_label = gtk_label_new (NULL); - gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); - gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); - gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); - gtk_widget_set_can_focus (GTK_WIDGET (primary_label), FALSE); + /* Primary label */ + primary_label = gtk_label_new (NULL); + gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); + gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); + gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); + gtk_widget_set_can_focus (GTK_WIDGET (primary_label), FALSE); - doc_name = xed_document_get_short_name_for_display (doc); + doc_name = xed_document_get_short_name_for_display (doc); - str = g_markup_printf_escaped (_("Save changes to document \"%s\" before closing?"), doc_name); + str = g_markup_printf_escaped (_("Save changes to document \"%s\" before closing?"), doc_name); - g_free (doc_name); + g_free (doc_name); - markup_str = g_strconcat ("", str, "", NULL); - g_free (str); + markup_str = g_strconcat ("", str, "", NULL); + g_free (str); - gtk_label_set_markup (GTK_LABEL (primary_label), markup_str); - g_free (markup_str); + gtk_label_set_markup (GTK_LABEL (primary_label), markup_str); + g_free (markup_str); - /* Secondary label */ - str = get_text_secondary_label (doc); - secondary_label = gtk_label_new (str); - g_free (str); - gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); - gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); - gtk_widget_set_can_focus (GTK_WIDGET (secondary_label), FALSE); + /* Secondary label */ + str = get_text_secondary_label (doc); + secondary_label = gtk_label_new (str); + g_free (str); + gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); + gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); + gtk_widget_set_can_focus (GTK_WIDGET (secondary_label), FALSE); - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); - gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); - - gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0); + vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); - gtk_box_pack_start (GTK_BOX (vbox), primary_label, FALSE, FALSE, 0); - - gtk_box_pack_start (GTK_BOX (vbox), secondary_label, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox), primary_label, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox), secondary_label, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), hbox, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), - hbox, - FALSE, - FALSE, - 0); - - gtk_widget_show_all (hbox); + gtk_widget_show_all (hbox); } static void -populate_model (GtkTreeModel *store, GList *docs) +populate_model (GtkTreeModel *store, + GList *docs) { - GtkTreeIter iter; + GtkTreeIter iter; - while (docs != NULL) - { - XedDocument *doc; - gchar *name; + while (docs != NULL) + { + XedDocument *doc; + gchar *name; - doc = XED_DOCUMENT (docs->data); + doc = XED_DOCUMENT (docs->data); - name = xed_document_get_short_name_for_display (doc); + name = xed_document_get_short_name_for_display (doc); - gtk_list_store_append (GTK_LIST_STORE (store), &iter); - gtk_list_store_set (GTK_LIST_STORE (store), &iter, - SAVE_COLUMN, TRUE, - NAME_COLUMN, name, - DOC_COLUMN, doc, - -1); + gtk_list_store_append (GTK_LIST_STORE (store), &iter); + gtk_list_store_set (GTK_LIST_STORE (store), &iter, + SAVE_COLUMN, TRUE, + NAME_COLUMN, name, + DOC_COLUMN, doc, + -1); - g_free (name); + g_free (name); - docs = g_list_next (docs); - } + docs = g_list_next (docs); + } } static void -save_toggled (GtkCellRendererToggle *renderer, gchar *path_str, GtkTreeModel *store) +save_toggled (GtkCellRendererToggle *renderer, + gchar *path_str, + GtkTreeModel *store) { - GtkTreePath *path = gtk_tree_path_new_from_string (path_str); - GtkTreeIter iter; - gboolean active; + GtkTreePath *path = gtk_tree_path_new_from_string (path_str); + GtkTreeIter iter; + gboolean active; - gtk_tree_model_get_iter (store, &iter, path); - gtk_tree_model_get (store, &iter, SAVE_COLUMN, &active, -1); + gtk_tree_model_get_iter (store, &iter, path); + gtk_tree_model_get (store, &iter, SAVE_COLUMN, &active, -1); - active ^= 1; + active ^= 1; - gtk_list_store_set (GTK_LIST_STORE (store), &iter, - SAVE_COLUMN, active, -1); + gtk_list_store_set (GTK_LIST_STORE (store), &iter, SAVE_COLUMN, active, -1); - gtk_tree_path_free (path); + gtk_tree_path_free (path); } static GtkWidget * create_treeview (XedCloseConfirmationDialogPrivate *priv) { - GtkListStore *store; - GtkWidget *treeview; - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; + GtkListStore *store; + GtkWidget *treeview; + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; - treeview = gtk_tree_view_new (); - gtk_widget_set_size_request (treeview, 260, 120); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE); - gtk_tree_view_set_enable_search (GTK_TREE_VIEW (treeview), FALSE); + treeview = gtk_tree_view_new (); + gtk_widget_set_size_request (treeview, 260, 120); + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE); + gtk_tree_view_set_enable_search (GTK_TREE_VIEW (treeview), FALSE); - /* Create and populate the model */ - store = gtk_list_store_new (N_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_POINTER); - populate_model (GTK_TREE_MODEL (store), priv->unsaved_documents); + /* Create and populate the model */ + store = gtk_list_store_new (N_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_POINTER); + populate_model (GTK_TREE_MODEL (store), priv->unsaved_documents); - /* Set model to the treeview */ - gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (store)); - g_object_unref (store); + /* Set model to the treeview */ + gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (store)); + g_object_unref (store); - priv->list_store = GTK_TREE_MODEL (store); + priv->list_store = GTK_TREE_MODEL (store); - /* Add columns */ + /* Add columns */ - renderer = gtk_cell_renderer_toggle_new (); - g_signal_connect (renderer, "toggled", - G_CALLBACK (save_toggled), store); + renderer = gtk_cell_renderer_toggle_new (); + g_signal_connect (renderer, "toggled", G_CALLBACK (save_toggled), store); - column = gtk_tree_view_column_new_with_attributes ("Save?", - renderer, - "active", - SAVE_COLUMN, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); + column = gtk_tree_view_column_new_with_attributes ("Save?", + renderer, + "active", + SAVE_COLUMN, + NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Name", - renderer, - "text", - NAME_COLUMN, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); + renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes ("Name", + renderer, + "text", + NAME_COLUMN, + NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); - return treeview; + return treeview; } static void build_multiple_docs_dialog (XedCloseConfirmationDialog *dlg) { - XedCloseConfirmationDialogPrivate *priv; - GtkWidget *hbox; - GtkWidget *image; - GtkWidget *vbox; - GtkWidget *primary_label; - GtkWidget *vbox2; - GtkWidget *select_label; - GtkWidget *scrolledwindow; - GtkWidget *treeview; - GtkWidget *secondary_label; - gchar *str; - gchar *markup_str; + XedCloseConfirmationDialogPrivate *priv; + GtkWidget *hbox; + GtkWidget *image; + GtkWidget *vbox; + GtkWidget *primary_label; + GtkWidget *vbox2; + GtkWidget *select_label; + GtkWidget *scrolledwindow; + GtkWidget *treeview; + GtkWidget *secondary_label; + gchar *str; + gchar *markup_str; - priv = dlg->priv; + priv = dlg->priv; - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), - hbox, TRUE, TRUE, 0); + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), hbox, TRUE, TRUE, 0); - /* Image */ - image = gtk_image_new_from_icon_name ("dialog-warning", - GTK_ICON_SIZE_DIALOG); - gtk_widget_set_halign (image, GTK_ALIGN_CENTER); - gtk_widget_set_valign (image, GTK_ALIGN_START); - gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); + /* Image */ + image = gtk_image_new_from_icon_name ("dialog-warning", GTK_ICON_SIZE_DIALOG); + gtk_widget_set_halign (image, GTK_ALIGN_CENTER); + gtk_widget_set_valign (image, GTK_ALIGN_START); + gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); - gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); + vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); + gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); - /* Primary label */ - primary_label = gtk_label_new (NULL); - gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); - gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); - gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); + /* Primary label */ + primary_label = gtk_label_new (NULL); + gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); + gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); + gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); - str = g_strdup_printf ( - ngettext ("There is %d document with unsaved changes. " - "Save changes before closing?", - "There are %d documents with unsaved changes. " - "Save changes before closing?", - g_list_length (priv->unsaved_documents)), - g_list_length (priv->unsaved_documents)); + str = g_strdup_printf (ngettext ("There is %d document with unsaved changes. " + "Save changes before closing?", + "There are %d documents with unsaved changes. " + "Save changes before closing?", + g_list_length (priv->unsaved_documents)), + g_list_length (priv->unsaved_documents)); - markup_str = g_strconcat ("", str, "", NULL); - g_free (str); - - gtk_label_set_markup (GTK_LABEL (primary_label), markup_str); - g_free (markup_str); - gtk_box_pack_start (GTK_BOX (vbox), primary_label, FALSE, FALSE, 0); - - vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8); - gtk_box_pack_start (GTK_BOX (vbox), vbox2, FALSE, FALSE, 0); + markup_str = g_strconcat ("", str, "", NULL); + g_free (str); - select_label = gtk_label_new_with_mnemonic (_("S_elect the documents you want to save:")); + gtk_label_set_markup (GTK_LABEL (primary_label), markup_str); + g_free (markup_str); + gtk_box_pack_start (GTK_BOX (vbox), primary_label, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox2), select_label, FALSE, FALSE, 0); - gtk_label_set_line_wrap (GTK_LABEL (select_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (select_label), 0.0, 0.5); + vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8); + gtk_box_pack_start (GTK_BOX (vbox), vbox2, FALSE, FALSE, 0); - scrolledwindow = gtk_scrolled_window_new (NULL, NULL); - gtk_box_pack_start (GTK_BOX (vbox2), scrolledwindow, TRUE, TRUE, 0); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow), - GTK_SHADOW_IN); - gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (scrolledwindow), 60); + select_label = gtk_label_new_with_mnemonic (_("S_elect the documents you want to save:")); - treeview = create_treeview (priv); - gtk_container_add (GTK_CONTAINER (scrolledwindow), treeview); + gtk_box_pack_start (GTK_BOX (vbox2), select_label, FALSE, FALSE, 0); + gtk_label_set_line_wrap (GTK_LABEL (select_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (select_label), 0.0, 0.5); - /* Secondary label */ - secondary_label = gtk_label_new (_("If you don't save, " - "all your changes will be permanently lost.")); + scrolledwindow = gtk_scrolled_window_new (NULL, NULL); + gtk_box_pack_start (GTK_BOX (vbox2), scrolledwindow, TRUE, TRUE, 0); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_SHADOW_IN); + gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (scrolledwindow), 60); - gtk_box_pack_start (GTK_BOX (vbox2), secondary_label, FALSE, FALSE, 0); - gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); - gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); + treeview = create_treeview (priv); + gtk_container_add (GTK_CONTAINER (scrolledwindow), treeview); - gtk_label_set_mnemonic_widget (GTK_LABEL (select_label), treeview); + /* Secondary label */ + secondary_label = gtk_label_new (_("If you don't save, " + "all your changes will be permanently lost.")); - gtk_widget_show_all (hbox); + gtk_box_pack_start (GTK_BOX (vbox2), secondary_label, FALSE, FALSE, 0); + gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); + gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); + + gtk_label_set_mnemonic_widget (GTK_LABEL (select_label), treeview); + + gtk_widget_show_all (hbox); } static void set_unsaved_document (XedCloseConfirmationDialog *dlg, - const GList *list) + const GList *list) { - XedCloseConfirmationDialogPrivate *priv; + XedCloseConfirmationDialogPrivate *priv; - g_return_if_fail (list != NULL); + g_return_if_fail (list != NULL); - priv = dlg->priv; - g_return_if_fail (priv->unsaved_documents == NULL); + priv = dlg->priv; + g_return_if_fail (priv->unsaved_documents == NULL); - priv->unsaved_documents = g_list_copy ((GList *)list); + priv->unsaved_documents = g_list_copy ((GList *)list); - if (GET_MODE (priv) == SINGLE_DOC_MODE) - { - build_single_doc_dialog (dlg); - } - else - { - build_multiple_docs_dialog (dlg); - } + if (GET_MODE (priv) == SINGLE_DOC_MODE) + { + build_single_doc_dialog (dlg); + } + else + { + build_multiple_docs_dialog (dlg); + } } const GList * xed_close_confirmation_dialog_get_unsaved_documents (XedCloseConfirmationDialog *dlg) { - g_return_val_if_fail (XED_IS_CLOSE_CONFIRMATION_DIALOG (dlg), NULL); + g_return_val_if_fail (XED_IS_CLOSE_CONFIRMATION_DIALOG (dlg), NULL); - return dlg->priv->unsaved_documents; + return dlg->priv->unsaved_documents; } From 41162911b21ee82d1cc91abef2938b9900d43da1 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 11 Dec 2016 19:33:07 -0800 Subject: [PATCH 002/132] close-confirmation-dialog: Clean up some deprecations We're stuck with a couple uses of gtk_misc_* for now until we can move to a newer minimum version of gtk3. --- xed/dialogs/xed-close-confirmation-dialog.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/xed/dialogs/xed-close-confirmation-dialog.c b/xed/dialogs/xed-close-confirmation-dialog.c index 0e4dbfa..6de1101 100755 --- a/xed/dialogs/xed-close-confirmation-dialog.c +++ b/xed/dialogs/xed-close-confirmation-dialog.c @@ -131,16 +131,16 @@ set_logout_mode (XedCloseConfirmationDialog *dlg, if (logout_mode) { gtk_dialog_add_button (GTK_DIALOG (dlg), _("Log Out _without Saving"), GTK_RESPONSE_NO); - xed_dialog_add_button (GTK_DIALOG (dlg), _("_Cancel Logout"), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + gtk_dialog_add_button (GTK_DIALOG (dlg), _("_Cancel Logout"), GTK_RESPONSE_CANCEL); } else { gtk_dialog_add_button (GTK_DIALOG (dlg), _("Close _without Saving"), GTK_RESPONSE_NO); - gtk_dialog_add_button (GTK_DIALOG (dlg), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + gtk_dialog_add_button (GTK_DIALOG (dlg), _("_Cancel"), GTK_RESPONSE_CANCEL); } - const gchar *stock_id = GTK_STOCK_SAVE; + gboolean save_as = FALSE; if (GET_MODE (dlg->priv) == SINGLE_DOC_MODE) { @@ -150,11 +150,19 @@ set_logout_mode (XedCloseConfirmationDialog *dlg, if (xed_document_get_readonly (doc) || xed_document_is_untitled (doc)) { - stock_id = GTK_STOCK_SAVE_AS; + save_as = TRUE; } } - gtk_dialog_add_button (GTK_DIALOG (dlg), stock_id, GTK_RESPONSE_YES); + if (save_as) + { + gtk_dialog_add_button (GTK_DIALOG (dlg), _("_Save As..."), GTK_RESPONSE_YES); + } + else + { + gtk_dialog_add_button (GTK_DIALOG (dlg), _("_Save"), GTK_RESPONSE_YES); + } + gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_RESPONSE_YES); } @@ -484,7 +492,6 @@ build_single_doc_dialog (XedCloseConfirmationDialog *dlg) secondary_label = gtk_label_new (str); g_free (str); gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); gtk_widget_set_can_focus (GTK_WIDGET (secondary_label), FALSE); @@ -631,6 +638,7 @@ build_multiple_docs_dialog (XedCloseConfirmationDialog *dlg) primary_label = gtk_label_new (NULL); gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); + gtk_widget_set_halign (GTK_WIDGET (primary_label), GTK_ALIGN_START); gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); @@ -672,7 +680,6 @@ build_multiple_docs_dialog (XedCloseConfirmationDialog *dlg) gtk_box_pack_start (GTK_BOX (vbox2), secondary_label, FALSE, FALSE, 0); gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); gtk_label_set_mnemonic_widget (GTK_LABEL (select_label), treeview); From c801604a2c23ef2a716956a679285f85c24cfcca Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 11 Dec 2016 19:52:18 -0800 Subject: [PATCH 003/132] xed-encodings-dialog: Clean up code styling --- xed/dialogs/xed-encodings-dialog.c | 577 +++++++++++++---------------- 1 file changed, 260 insertions(+), 317 deletions(-) diff --git a/xed/dialogs/xed-encodings-dialog.c b/xed/dialogs/xed-encodings-dialog.c index a92c11e..e4d505a 100755 --- a/xed/dialogs/xed-encodings-dialog.c +++ b/xed/dialogs/xed-encodings-dialog.c @@ -2,7 +2,7 @@ * xed-encodings-dialog.c * This file is part of xed * - * Copyright (C) 2002-2005 Paolo Maggi + * Copyright (C) 2002-2005 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ /* - * Modified by the xed Team, 2002-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2002-2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -47,19 +47,19 @@ #include "xed-dirs.h" #define XED_ENCODINGS_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ - XED_TYPE_ENCODINGS_DIALOG, \ - XedEncodingsDialogPrivate)) + XED_TYPE_ENCODINGS_DIALOG, \ + XedEncodingsDialogPrivate)) struct _XedEncodingsDialogPrivate { - GtkListStore *available_liststore; - GtkListStore *displayed_liststore; - GtkWidget *available_treeview; - GtkWidget *displayed_treeview; - GtkWidget *add_button; - GtkWidget *remove_button; + GtkListStore *available_liststore; + GtkListStore *displayed_liststore; + GtkWidget *available_treeview; + GtkWidget *displayed_treeview; + GtkWidget *add_button; + GtkWidget *remove_button; - GSList *show_in_menu_list; + GSList *show_in_menu_list; }; G_DEFINE_TYPE(XedEncodingsDialog, xed_encodings_dialog, GTK_TYPE_DIALOG) @@ -67,432 +67,375 @@ G_DEFINE_TYPE(XedEncodingsDialog, xed_encodings_dialog, GTK_TYPE_DIALOG) static void xed_encodings_dialog_finalize (GObject *object) { - XedEncodingsDialogPrivate *priv = XED_ENCODINGS_DIALOG (object)->priv; + XedEncodingsDialogPrivate *priv = XED_ENCODINGS_DIALOG (object)->priv; - g_slist_free (priv->show_in_menu_list); + g_slist_free (priv->show_in_menu_list); - G_OBJECT_CLASS (xed_encodings_dialog_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_encodings_dialog_parent_class)->finalize (object); } static void xed_encodings_dialog_class_init (XedEncodingsDialogClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = xed_encodings_dialog_finalize; + object_class->finalize = xed_encodings_dialog_finalize; - g_type_class_add_private (object_class, sizeof (XedEncodingsDialogPrivate)); + g_type_class_add_private (object_class, sizeof (XedEncodingsDialogPrivate)); } -enum { - COLUMN_NAME, - COLUMN_CHARSET, - N_COLUMNS +enum +{ + COLUMN_NAME, + COLUMN_CHARSET, + N_COLUMNS }; static void count_selected_items_func (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer data) + GtkTreePath *path, + GtkTreeIter *iter, + gpointer data) { - int *count = data; + int *count = data; - *count += 1; + *count += 1; } static void -available_selection_changed_callback (GtkTreeSelection *selection, - XedEncodingsDialog *dialogs) +available_selection_changed_callback (GtkTreeSelection *selection, + XedEncodingsDialog *dialogs) { - int count; + int count; - count = 0; - gtk_tree_selection_selected_foreach (selection, - count_selected_items_func, - &count); + count = 0; + gtk_tree_selection_selected_foreach (selection, count_selected_items_func, &count); - gtk_widget_set_sensitive (dialogs->priv->add_button, count > 0); + gtk_widget_set_sensitive (dialogs->priv->add_button, count > 0); } static void -displayed_selection_changed_callback (GtkTreeSelection *selection, - XedEncodingsDialog *dialogs) +displayed_selection_changed_callback (GtkTreeSelection *selection, + XedEncodingsDialog *dialogs) { - int count; + int count; - count = 0; - gtk_tree_selection_selected_foreach (selection, - count_selected_items_func, - &count); + count = 0; + gtk_tree_selection_selected_foreach (selection, count_selected_items_func, &count); - gtk_widget_set_sensitive (dialogs->priv->remove_button, count > 0); + gtk_widget_set_sensitive (dialogs->priv->remove_button, count > 0); } static void get_selected_encodings_func (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer data) + GtkTreePath *path, + GtkTreeIter *iter, + gpointer data) { - GSList **list = data; - gchar *charset; - const XedEncoding *enc; + GSList **list = data; + gchar *charset; + const XedEncoding *enc; - charset = NULL; - gtk_tree_model_get (model, iter, COLUMN_CHARSET, &charset, -1); + charset = NULL; + gtk_tree_model_get (model, iter, COLUMN_CHARSET, &charset, -1); - enc = xed_encoding_get_from_charset (charset); - g_free (charset); + enc = xed_encoding_get_from_charset (charset); + g_free (charset); - *list = g_slist_prepend (*list, (gpointer)enc); + *list = g_slist_prepend (*list, (gpointer)enc); } static void update_shown_in_menu_tree_model (GtkListStore *store, - GSList *list) + GSList *list) { - GtkTreeIter iter; + GtkTreeIter iter; - gtk_list_store_clear (store); + gtk_list_store_clear (store); - while (list != NULL) - { - const XedEncoding *enc; + while (list != NULL) + { + const XedEncoding *enc; - enc = (const XedEncoding*) list->data; + enc = (const XedEncoding*) list->data; - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - COLUMN_CHARSET, - xed_encoding_get_charset (enc), - COLUMN_NAME, - xed_encoding_get_name (enc), -1); + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + COLUMN_CHARSET, xed_encoding_get_charset (enc), + COLUMN_NAME, xed_encoding_get_name (enc), + -1); - list = g_slist_next (list); - } + list = g_slist_next (list); + } } static void -add_button_clicked_callback (GtkWidget *button, - XedEncodingsDialog *dialog) +add_button_clicked_callback (GtkWidget *button, + XedEncodingsDialog *dialog) { - GtkTreeSelection *selection; - GSList *encodings; - GSList *tmp; + GtkTreeSelection *selection; + GSList *encodings; + GSList *tmp; - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->available_treeview)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->available_treeview)); - encodings = NULL; - gtk_tree_selection_selected_foreach (selection, - get_selected_encodings_func, - &encodings); + encodings = NULL; + gtk_tree_selection_selected_foreach (selection, get_selected_encodings_func, &encodings); - tmp = encodings; - while (tmp != NULL) - { - if (g_slist_find (dialog->priv->show_in_menu_list, tmp->data) == NULL) - dialog->priv->show_in_menu_list = g_slist_prepend (dialog->priv->show_in_menu_list, - tmp->data); + tmp = encodings; + while (tmp != NULL) + { + if (g_slist_find (dialog->priv->show_in_menu_list, tmp->data) == NULL) + dialog->priv->show_in_menu_list = g_slist_prepend (dialog->priv->show_in_menu_list, tmp->data); - tmp = g_slist_next (tmp); - } + tmp = g_slist_next (tmp); + } - g_slist_free (encodings); + g_slist_free (encodings); - update_shown_in_menu_tree_model (GTK_LIST_STORE (dialog->priv->displayed_liststore), - dialog->priv->show_in_menu_list); + update_shown_in_menu_tree_model (GTK_LIST_STORE (dialog->priv->displayed_liststore), + dialog->priv->show_in_menu_list); } static void -remove_button_clicked_callback (GtkWidget *button, - XedEncodingsDialog *dialog) +remove_button_clicked_callback (GtkWidget *button, + XedEncodingsDialog *dialog) { - GtkTreeSelection *selection; - GSList *encodings; - GSList *tmp; + GtkTreeSelection *selection; + GSList *encodings; + GSList *tmp; - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->displayed_treeview)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->displayed_treeview)); - encodings = NULL; - gtk_tree_selection_selected_foreach (selection, - get_selected_encodings_func, - &encodings); + encodings = NULL; + gtk_tree_selection_selected_foreach (selection, get_selected_encodings_func, &encodings); - tmp = encodings; - while (tmp != NULL) - { - dialog->priv->show_in_menu_list = g_slist_remove (dialog->priv->show_in_menu_list, - tmp->data); + tmp = encodings; + while (tmp != NULL) + { + dialog->priv->show_in_menu_list = g_slist_remove (dialog->priv->show_in_menu_list, tmp->data); - tmp = g_slist_next (tmp); - } + tmp = g_slist_next (tmp); + } - g_slist_free (encodings); + g_slist_free (encodings); - update_shown_in_menu_tree_model (GTK_LIST_STORE (dialog->priv->displayed_liststore), - dialog->priv->show_in_menu_list); + update_shown_in_menu_tree_model (GTK_LIST_STORE (dialog->priv->displayed_liststore), + dialog->priv->show_in_menu_list); } static void init_shown_in_menu_tree_model (XedEncodingsDialog *dialog) { - GtkTreeIter iter; - GSList *list, *tmp; + GtkTreeIter iter; + GSList *list, *tmp; - /* add data to the list store */ - list = xed_prefs_manager_get_shown_in_menu_encodings (); + /* add data to the list store */ + list = xed_prefs_manager_get_shown_in_menu_encodings (); - tmp = list; + tmp = list; - while (tmp != NULL) - { - const XedEncoding *enc; + while (tmp != NULL) + { + const XedEncoding *enc; - enc = (const XedEncoding *) tmp->data; + enc = (const XedEncoding *) tmp->data; - dialog->priv->show_in_menu_list = g_slist_prepend (dialog->priv->show_in_menu_list, - tmp->data); + dialog->priv->show_in_menu_list = g_slist_prepend (dialog->priv->show_in_menu_list, tmp->data); - gtk_list_store_append (dialog->priv->displayed_liststore, - &iter); - gtk_list_store_set (dialog->priv->displayed_liststore, - &iter, - COLUMN_CHARSET, - xed_encoding_get_charset (enc), - COLUMN_NAME, - xed_encoding_get_name (enc), -1); + gtk_list_store_append (dialog->priv->displayed_liststore, &iter); + gtk_list_store_set (dialog->priv->displayed_liststore, &iter, + COLUMN_CHARSET, xed_encoding_get_charset (enc), + COLUMN_NAME, xed_encoding_get_name (enc), + -1); - tmp = g_slist_next (tmp); - } + tmp = g_slist_next (tmp); + } - g_slist_free (list); + g_slist_free (list); } -static void -response_handler (GtkDialog *dialog, - gint response_id, +static void +response_handler (GtkDialog *dialog, + gint response_id, XedEncodingsDialog *dlg) { - if (response_id == GTK_RESPONSE_HELP) - { - xed_help_display (GTK_WINDOW (dialog), "xed", NULL); - g_signal_stop_emission_by_name (dialog, "response"); - return; - } + if (response_id == GTK_RESPONSE_HELP) + { + xed_help_display (GTK_WINDOW (dialog), "xed", NULL); + g_signal_stop_emission_by_name (dialog, "response"); + return; + } - if (response_id == GTK_RESPONSE_OK) - { - g_return_if_fail (xed_prefs_manager_shown_in_menu_encodings_can_set ()); - xed_prefs_manager_set_shown_in_menu_encodings (dlg->priv->show_in_menu_list); - } + if (response_id == GTK_RESPONSE_OK) + { + g_return_if_fail (xed_prefs_manager_shown_in_menu_encodings_can_set ()); + xed_prefs_manager_set_shown_in_menu_encodings (dlg->priv->show_in_menu_list); + } } static void xed_encodings_dialog_init (XedEncodingsDialog *dlg) { - GtkWidget *content; - GtkCellRenderer *cell_renderer; - GtkTreeModel *sort_model; - GtkTreeViewColumn *column; - GtkTreeIter parent_iter; - GtkTreeSelection *selection; - const XedEncoding *enc; - GtkWidget *error_widget; - int i; - gboolean ret; - gchar *file; - gchar *root_objects[] = { - "encodings-dialog-contents", - NULL - }; + GtkWidget *content; + GtkCellRenderer *cell_renderer; + GtkTreeModel *sort_model; + GtkTreeViewColumn *column; + GtkTreeIter parent_iter; + GtkTreeSelection *selection; + const XedEncoding *enc; + GtkWidget *error_widget; + int i; + gboolean ret; + gchar *file; + gchar *root_objects[] = { + "encodings-dialog-contents", + NULL + }; - dlg->priv = XED_ENCODINGS_DIALOG_GET_PRIVATE (dlg); - - gtk_dialog_add_buttons (GTK_DIALOG (dlg), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, - GTK_RESPONSE_OK, - GTK_STOCK_HELP, - GTK_RESPONSE_HELP, - NULL); + dlg->priv = XED_ENCODINGS_DIALOG_GET_PRIVATE (dlg); - gtk_window_set_title (GTK_WINDOW (dlg), _("Character Encodings")); - gtk_window_set_default_size (GTK_WINDOW (dlg), 650, 400); - - /* HIG defaults */ - gtk_container_set_border_width (GTK_CONTAINER (dlg), 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), - 2); /* 2 * 5 + 2 = 12 */ - gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), - 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 6); + gtk_dialog_add_buttons (GTK_DIALOG (dlg), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, + GTK_STOCK_HELP, GTK_RESPONSE_HELP, + NULL); - gtk_dialog_set_default_response (GTK_DIALOG (dlg), - GTK_RESPONSE_OK); + gtk_window_set_title (GTK_WINDOW (dlg), _("Character Encodings")); + gtk_window_set_default_size (GTK_WINDOW (dlg), 650, 400); - g_signal_connect (dlg, - "response", - G_CALLBACK (response_handler), - dlg); + /* HIG defaults */ + gtk_container_set_border_width (GTK_CONTAINER (dlg), 5); + gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), 2); /* 2 * 5 + 2 = 12 */ + gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 5); + gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 6); - file = xed_dirs_get_ui_file ("xed-encodings-dialog.ui"); - ret = xed_utils_get_ui_objects (file, - root_objects, - &error_widget, - "encodings-dialog-contents", &content, - "add-button", &dlg->priv->add_button, - "remove-button", &dlg->priv->remove_button, - "available-treeview", &dlg->priv->available_treeview, - "displayed-treeview", &dlg->priv->displayed_treeview, - NULL); - g_free (file); + gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_RESPONSE_OK); - if (!ret) - { - gtk_widget_show (error_widget); + g_signal_connect (dlg, "response", G_CALLBACK (response_handler), dlg); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), - error_widget, - TRUE, TRUE, 0); - gtk_container_set_border_width (GTK_CONTAINER (error_widget), 5); + file = xed_dirs_get_ui_file ("xed-encodings-dialog.ui"); + ret = xed_utils_get_ui_objects (file, + root_objects, + &error_widget, + "encodings-dialog-contents", &content, + "add-button", &dlg->priv->add_button, + "remove-button", &dlg->priv->remove_button, + "available-treeview", &dlg->priv->available_treeview, + "displayed-treeview", &dlg->priv->displayed_treeview, + NULL); + g_free (file); - return; - } + if (!ret) + { + gtk_widget_show (error_widget); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), - content, TRUE, TRUE, 0); - g_object_unref (content); - gtk_container_set_border_width (GTK_CONTAINER (content), 5); + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), error_widget, TRUE, TRUE, 0); + gtk_container_set_border_width (GTK_CONTAINER (error_widget), 5); - g_signal_connect (dlg->priv->add_button, - "clicked", - G_CALLBACK (add_button_clicked_callback), - dlg); - g_signal_connect (dlg->priv->remove_button, - "clicked", - G_CALLBACK (remove_button_clicked_callback), - dlg); + return; + } - /* Tree view of available encodings */ - dlg->priv->available_liststore = gtk_list_store_new (N_COLUMNS, - G_TYPE_STRING, - G_TYPE_STRING); + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), content, TRUE, TRUE, 0); + g_object_unref (content); + gtk_container_set_border_width (GTK_CONTAINER (content), 5); - cell_renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes (_("_Description"), - cell_renderer, - "text", COLUMN_NAME, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->available_treeview), - column); - gtk_tree_view_column_set_sort_column_id (column, COLUMN_NAME); + g_signal_connect (dlg->priv->add_button, "clicked", G_CALLBACK (add_button_clicked_callback), dlg); + g_signal_connect (dlg->priv->remove_button, "clicked", G_CALLBACK (remove_button_clicked_callback), dlg); - cell_renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes (_("_Encoding"), - cell_renderer, - "text", - COLUMN_CHARSET, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->available_treeview), - column); - gtk_tree_view_column_set_sort_column_id (column, COLUMN_CHARSET); + /* Tree view of available encodings */ + dlg->priv->available_liststore = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING); - /* Add the data */ - i = 0; - while ((enc = xed_encoding_get_from_index (i)) != NULL) - { - gtk_list_store_append (dlg->priv->available_liststore, - &parent_iter); - gtk_list_store_set (dlg->priv->available_liststore, - &parent_iter, - COLUMN_CHARSET, - xed_encoding_get_charset (enc), - COLUMN_NAME, - xed_encoding_get_name (enc), -1); + cell_renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes (_("_Description"), + cell_renderer, + "text", COLUMN_NAME, + NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->available_treeview), column); + gtk_tree_view_column_set_sort_column_id (column, COLUMN_NAME); - ++i; - } + cell_renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes (_("_Encoding"), + cell_renderer, + "text", + COLUMN_CHARSET, + NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->available_treeview), column); + gtk_tree_view_column_set_sort_column_id (column, COLUMN_CHARSET); - /* Sort model */ - sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (dlg->priv->available_liststore)); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model), - COLUMN_NAME, - GTK_SORT_ASCENDING); + /* Add the data */ + i = 0; + while ((enc = xed_encoding_get_from_index (i)) != NULL) + { + gtk_list_store_append (dlg->priv->available_liststore, &parent_iter); + gtk_list_store_set (dlg->priv->available_liststore, &parent_iter, + COLUMN_CHARSET, xed_encoding_get_charset (enc), + COLUMN_NAME, xed_encoding_get_name (enc), + -1); - gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->priv->available_treeview), - sort_model); - g_object_unref (G_OBJECT (dlg->priv->available_liststore)); - g_object_unref (G_OBJECT (sort_model)); + ++i; + } - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->available_treeview)); - gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection), - GTK_SELECTION_MULTIPLE); + /* Sort model */ + sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (dlg->priv->available_liststore)); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model), COLUMN_NAME, GTK_SORT_ASCENDING); - available_selection_changed_callback (selection, dlg); - g_signal_connect (selection, - "changed", - G_CALLBACK (available_selection_changed_callback), - dlg); + gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->priv->available_treeview), sort_model); + g_object_unref (G_OBJECT (dlg->priv->available_liststore)); + g_object_unref (G_OBJECT (sort_model)); - /* Tree view of selected encodings */ - dlg->priv->displayed_liststore = gtk_list_store_new (N_COLUMNS, - G_TYPE_STRING, - G_TYPE_STRING); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->available_treeview)); + gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection), GTK_SELECTION_MULTIPLE); - cell_renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes (_("_Description"), - cell_renderer, - "text", COLUMN_NAME, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->displayed_treeview), - column); - gtk_tree_view_column_set_sort_column_id (column, COLUMN_NAME); + available_selection_changed_callback (selection, dlg); + g_signal_connect (selection, "changed", G_CALLBACK (available_selection_changed_callback), dlg); - cell_renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes (_("_Encoding"), - cell_renderer, - "text", - COLUMN_CHARSET, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->displayed_treeview), - column); - gtk_tree_view_column_set_sort_column_id (column, COLUMN_CHARSET); + /* Tree view of selected encodings */ + dlg->priv->displayed_liststore = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING); - /* Add the data */ - init_shown_in_menu_tree_model (dlg); + cell_renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes (_("_Description"), + cell_renderer, + "text", COLUMN_NAME, + NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->displayed_treeview), column); + gtk_tree_view_column_set_sort_column_id (column, COLUMN_NAME); - /* Sort model */ - sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (dlg->priv->displayed_liststore)); + cell_renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes (_("_Encoding"), + cell_renderer, + "text", + COLUMN_CHARSET, + NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->displayed_treeview), column); + gtk_tree_view_column_set_sort_column_id (column, COLUMN_CHARSET); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE - (sort_model), COLUMN_NAME, - GTK_SORT_ASCENDING); + /* Add the data */ + init_shown_in_menu_tree_model (dlg); - gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->priv->displayed_treeview), - sort_model); - g_object_unref (G_OBJECT (sort_model)); - g_object_unref (G_OBJECT (dlg->priv->displayed_liststore)); + /* Sort model */ + sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (dlg->priv->displayed_liststore)); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->displayed_treeview)); - gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection), - GTK_SELECTION_MULTIPLE); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model), COLUMN_NAME, GTK_SORT_ASCENDING); - displayed_selection_changed_callback (selection, dlg); - g_signal_connect (selection, - "changed", - G_CALLBACK (displayed_selection_changed_callback), - dlg); + gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->priv->displayed_treeview), sort_model); + g_object_unref (G_OBJECT (sort_model)); + g_object_unref (G_OBJECT (dlg->priv->displayed_liststore)); + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->displayed_treeview)); + gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection), GTK_SELECTION_MULTIPLE); + + displayed_selection_changed_callback (selection, dlg); + g_signal_connect (selection, "changed", G_CALLBACK (displayed_selection_changed_callback), dlg); } GtkWidget * xed_encodings_dialog_new (void) { - GtkWidget *dlg; + GtkWidget *dlg; - dlg = GTK_WIDGET (g_object_new (XED_TYPE_ENCODINGS_DIALOG, NULL)); + dlg = GTK_WIDGET (g_object_new (XED_TYPE_ENCODINGS_DIALOG, NULL)); - return dlg; + return dlg; } From f1c1e6c689639eca30f30c2b0ead17c1b85e4651 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 11 Dec 2016 20:29:37 -0800 Subject: [PATCH 004/132] xed-encodings-dialog: Clean up some deprecations --- xed/dialogs/xed-encodings-dialog.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/xed/dialogs/xed-encodings-dialog.c b/xed/dialogs/xed-encodings-dialog.c index e4d505a..f94d16a 100755 --- a/xed/dialogs/xed-encodings-dialog.c +++ b/xed/dialogs/xed-encodings-dialog.c @@ -296,9 +296,9 @@ xed_encodings_dialog_init (XedEncodingsDialog *dlg) dlg->priv = XED_ENCODINGS_DIALOG_GET_PRIVATE (dlg); gtk_dialog_add_buttons (GTK_DIALOG (dlg), - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - GTK_STOCK_HELP, GTK_RESPONSE_HELP, + _("_Cancel"), GTK_RESPONSE_CANCEL, + _("_OK"), GTK_RESPONSE_OK, + _("_Help"), GTK_RESPONSE_HELP, NULL); gtk_window_set_title (GTK_WINDOW (dlg), _("Character Encodings")); @@ -307,8 +307,6 @@ xed_encodings_dialog_init (XedEncodingsDialog *dlg) /* HIG defaults */ gtk_container_set_border_width (GTK_CONTAINER (dlg), 5); gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), 2); /* 2 * 5 + 2 = 12 */ - gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 6); gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_RESPONSE_OK); From 71306fa224a9647e0ecf96e36417b053ff7461ca Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 11 Dec 2016 20:43:00 -0800 Subject: [PATCH 005/132] xed-encodings-combo-box: Clean up code styling --- xed/xed-encodings-combo-box.c | 543 ++++++++++++++++------------------ 1 file changed, 261 insertions(+), 282 deletions(-) diff --git a/xed/xed-encodings-combo-box.c b/xed/xed-encodings-combo-box.c index 08637f3..f9cf161 100644 --- a/xed/xed-encodings-combo-box.c +++ b/xed/xed-encodings-combo-box.c @@ -17,14 +17,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2003-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2003-2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id: xed-encodings-combo-box.c 6112 2008-01-23 08:26:24Z sfre $ */ @@ -42,392 +42,374 @@ #define ENCODING_KEY "Enconding" -#define XED_ENCODINGS_COMBO_BOX_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ - XED_TYPE_ENCODINGS_COMBO_BOX, \ - XedEncodingsComboBoxPrivate)) +#define XED_ENCODINGS_COMBO_BOX_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ + XED_TYPE_ENCODINGS_COMBO_BOX, \ + XedEncodingsComboBoxPrivate)) struct _XedEncodingsComboBoxPrivate { - GtkListStore *store; - glong changed_id; + GtkListStore *store; + glong changed_id; - guint activated_item; + guint activated_item; - guint save_mode : 1; + guint save_mode : 1; }; enum { - NAME_COLUMN, - ENCODING_COLUMN, - ADD_COLUMN, - N_COLUMNS + NAME_COLUMN, + ENCODING_COLUMN, + ADD_COLUMN, + N_COLUMNS }; /* Properties */ enum { - PROP_0, - PROP_SAVE_MODE + PROP_0, + PROP_SAVE_MODE }; G_DEFINE_TYPE(XedEncodingsComboBox, xed_encodings_combo_box, GTK_TYPE_COMBO_BOX) -static void update_menu (XedEncodingsComboBox *combo_box); +static void update_menu (XedEncodingsComboBox *combo_box); static void xed_encodings_combo_box_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - XedEncodingsComboBox *combo; + XedEncodingsComboBox *combo; - combo = XED_ENCODINGS_COMBO_BOX (object); + combo = XED_ENCODINGS_COMBO_BOX (object); - switch (prop_id) - { - case PROP_SAVE_MODE: - combo->priv->save_mode = g_value_get_boolean (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_SAVE_MODE: + combo->priv->save_mode = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_encodings_combo_box_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - XedEncodingsComboBox *combo; + XedEncodingsComboBox *combo; - combo = XED_ENCODINGS_COMBO_BOX (object); + combo = XED_ENCODINGS_COMBO_BOX (object); - switch (prop_id) - { - case PROP_SAVE_MODE: - g_value_set_boolean (value, combo->priv->save_mode); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_SAVE_MODE: + g_value_set_boolean (value, combo->priv->save_mode); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_encodings_combo_box_dispose (GObject *object) { - XedEncodingsComboBox *combo = XED_ENCODINGS_COMBO_BOX (object); + XedEncodingsComboBox *combo = XED_ENCODINGS_COMBO_BOX (object); - if (combo->priv->store != NULL) - { - g_object_unref (combo->priv->store); - combo->priv->store = NULL; - } + if (combo->priv->store != NULL) + { + g_object_unref (combo->priv->store); + combo->priv->store = NULL; + } - G_OBJECT_CLASS (xed_encodings_combo_box_parent_class)->dispose (object); + G_OBJECT_CLASS (xed_encodings_combo_box_parent_class)->dispose (object); } static void xed_encodings_combo_box_class_init (XedEncodingsComboBoxClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->set_property = xed_encodings_combo_box_set_property; - object_class->get_property = xed_encodings_combo_box_get_property; - object_class->dispose = xed_encodings_combo_box_dispose; + object_class->set_property = xed_encodings_combo_box_set_property; + object_class->get_property = xed_encodings_combo_box_get_property; + object_class->dispose = xed_encodings_combo_box_dispose; - g_object_class_install_property (object_class, - PROP_SAVE_MODE, - g_param_spec_boolean ("save-mode", - "Save Mode", - "Save Mode", - FALSE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT | - G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, + PROP_SAVE_MODE, + g_param_spec_boolean ("save-mode", + "Save Mode", + "Save Mode", + FALSE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS)); - g_type_class_add_private (object_class, sizeof (XedEncodingsComboBoxPrivate)); + g_type_class_add_private (object_class, sizeof (XedEncodingsComboBoxPrivate)); } static void -dialog_response_cb (GtkDialog *dialog, - gint response_id, +dialog_response_cb (GtkDialog *dialog, + gint response_id, XedEncodingsComboBox *menu) { - if (response_id == GTK_RESPONSE_OK) - { - update_menu (menu); - } + if (response_id == GTK_RESPONSE_OK) + { + update_menu (menu); + } - gtk_widget_destroy (GTK_WIDGET (dialog)); + gtk_widget_destroy (GTK_WIDGET (dialog)); } static void add_or_remove (XedEncodingsComboBox *menu, - GtkTreeModel *model) + GtkTreeModel *model) { - GtkTreeIter iter; - gboolean add_item = FALSE; + GtkTreeIter iter; + gboolean add_item = FALSE; - if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (menu), &iter)) - { - gtk_tree_model_get (model, &iter, - ADD_COLUMN, &add_item, - -1); - } + if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (menu), &iter)) + { + gtk_tree_model_get (model, &iter, ADD_COLUMN, &add_item, -1); + } - if (!add_item) - { - menu->priv->activated_item = gtk_combo_box_get_active (GTK_COMBO_BOX (menu)); - } - else - { - GtkWidget *dialog; + if (!add_item) + { + menu->priv->activated_item = gtk_combo_box_get_active (GTK_COMBO_BOX (menu)); + } + else + { + GtkWidget *dialog; - GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menu)); + GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menu)); - if (!gtk_widget_is_toplevel (toplevel)) - toplevel = NULL; + if (!gtk_widget_is_toplevel (toplevel)) + { + toplevel = NULL; + } - g_signal_handler_block (menu, menu->priv->changed_id); - gtk_combo_box_set_active (GTK_COMBO_BOX (menu), - menu->priv->activated_item); - g_signal_handler_unblock (menu, menu->priv->changed_id); + g_signal_handler_block (menu, menu->priv->changed_id); + gtk_combo_box_set_active (GTK_COMBO_BOX (menu), menu->priv->activated_item); + g_signal_handler_unblock (menu, menu->priv->changed_id); - dialog = xed_encodings_dialog_new(); + dialog = xed_encodings_dialog_new(); - if (toplevel != NULL) - { - GtkWindowGroup *wg; + if (toplevel != NULL) + { + GtkWindowGroup *wg; - gtk_window_set_transient_for (GTK_WINDOW (dialog), - GTK_WINDOW (toplevel)); + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel)); - wg = gtk_window_get_group (GTK_WINDOW (toplevel)); - if (wg == NULL) - { - wg = gtk_window_group_new (); - gtk_window_group_add_window (wg, - GTK_WINDOW (toplevel)); - } + wg = gtk_window_get_group (GTK_WINDOW (toplevel)); + if (wg == NULL) + { + wg = gtk_window_group_new (); + gtk_window_group_add_window (wg, GTK_WINDOW (toplevel)); + } - gtk_window_group_add_window (wg, - GTK_WINDOW (dialog)); - } + gtk_window_group_add_window (wg, GTK_WINDOW (dialog)); + } - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - g_signal_connect (dialog, - "response", - G_CALLBACK (dialog_response_cb), - menu); + g_signal_connect (dialog, "response", G_CALLBACK (dialog_response_cb), menu); - gtk_widget_show (dialog); - } + gtk_widget_show (dialog); + } } static gboolean -separator_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data) +separator_func (GtkTreeModel *model, + GtkTreeIter *iter, + gpointer data) { - gchar *str; - gboolean ret; + gchar *str; + gboolean ret; - gtk_tree_model_get (model, iter, NAME_COLUMN, &str, -1); - ret = (str == NULL || *str == '\0'); - g_free (str); + gtk_tree_model_get (model, iter, NAME_COLUMN, &str, -1); + ret = (str == NULL || *str == '\0'); + g_free (str); - return ret; + return ret; } static void update_menu (XedEncodingsComboBox *menu) { - GtkListStore *store; - GtkTreeIter iter; - GSList *encodings, *l; - gchar *str; - const XedEncoding *utf8_encoding; - const XedEncoding *current_encoding; + GtkListStore *store; + GtkTreeIter iter; + GSList *encodings, *l; + gchar *str; + const XedEncoding *utf8_encoding; + const XedEncoding *current_encoding; - store = menu->priv->store; + store = menu->priv->store; - /* Unset the previous model */ - g_signal_handler_block (menu, menu->priv->changed_id); - gtk_list_store_clear (store); - gtk_combo_box_set_model (GTK_COMBO_BOX (menu), - NULL); + /* Unset the previous model */ + g_signal_handler_block (menu, menu->priv->changed_id); + gtk_list_store_clear (store); + gtk_combo_box_set_model (GTK_COMBO_BOX (menu), NULL); - utf8_encoding = xed_encoding_get_utf8 (); - current_encoding = xed_encoding_get_current (); + utf8_encoding = xed_encoding_get_utf8 (); + current_encoding = xed_encoding_get_current (); - if (!menu->priv->save_mode) - { - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - NAME_COLUMN, _("Automatically Detected"), - ENCODING_COLUMN, NULL, - ADD_COLUMN, FALSE, - -1); + if (!menu->priv->save_mode) + { + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + NAME_COLUMN, _("Automatically Detected"), + ENCODING_COLUMN, NULL, + ADD_COLUMN, FALSE, + -1); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - NAME_COLUMN, "", - ENCODING_COLUMN, NULL, - ADD_COLUMN, FALSE, - -1); - } + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + NAME_COLUMN, "", + ENCODING_COLUMN, NULL, + ADD_COLUMN, FALSE, + -1); + } - if (current_encoding != utf8_encoding) - str = xed_encoding_to_string (utf8_encoding); - else - str = g_strdup_printf (_("Current Locale (%s)"), - xed_encoding_get_charset (utf8_encoding)); + if (current_encoding != utf8_encoding) + { + str = xed_encoding_to_string (utf8_encoding); + } + else + { + str = g_strdup_printf (_("Current Locale (%s)"), xed_encoding_get_charset (utf8_encoding)); + } - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - NAME_COLUMN, str, - ENCODING_COLUMN, utf8_encoding, - ADD_COLUMN, FALSE, - -1); + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + NAME_COLUMN, str, + ENCODING_COLUMN, utf8_encoding, + ADD_COLUMN, FALSE, + -1); - g_free (str); + g_free (str); - if ((utf8_encoding != current_encoding) && - (current_encoding != NULL)) - { - str = g_strdup_printf (_("Current Locale (%s)"), - xed_encoding_get_charset (current_encoding)); + if ((utf8_encoding != current_encoding) && (current_encoding != NULL)) + { + str = g_strdup_printf (_("Current Locale (%s)"), xed_encoding_get_charset (current_encoding)); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - NAME_COLUMN, str, - ENCODING_COLUMN, current_encoding, - ADD_COLUMN, FALSE, - -1); + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + NAME_COLUMN, str, + ENCODING_COLUMN, current_encoding, + ADD_COLUMN, FALSE, + -1); - g_free (str); - } + g_free (str); + } - encodings = xed_prefs_manager_get_shown_in_menu_encodings (); + encodings = xed_prefs_manager_get_shown_in_menu_encodings (); - for (l = encodings; l != NULL; l = g_slist_next (l)) - { - const XedEncoding *enc = (const XedEncoding *)l->data; + for (l = encodings; l != NULL; l = g_slist_next (l)) + { + const XedEncoding *enc = (const XedEncoding *)l->data; - if ((enc != current_encoding) && - (enc != utf8_encoding) && - (enc != NULL)) - { - str = xed_encoding_to_string (enc); + if ((enc != current_encoding) && (enc != utf8_encoding) && (enc != NULL)) + { + str = xed_encoding_to_string (enc); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - NAME_COLUMN, str, - ENCODING_COLUMN, enc, - ADD_COLUMN, FALSE, - -1); + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + NAME_COLUMN, str, + ENCODING_COLUMN, enc, + ADD_COLUMN, FALSE, + -1); - g_free (str); - } - } + g_free (str); + } + } - g_slist_free (encodings); + g_slist_free (encodings); - if (xed_prefs_manager_shown_in_menu_encodings_can_set ()) - { - gtk_list_store_append (store, &iter); - /* separator */ - gtk_list_store_set (store, &iter, - NAME_COLUMN, "", - ENCODING_COLUMN, NULL, - ADD_COLUMN, FALSE, - -1); + if (xed_prefs_manager_shown_in_menu_encodings_can_set ()) + { + gtk_list_store_append (store, &iter); + /* separator */ + gtk_list_store_set (store, &iter, + NAME_COLUMN, "", + ENCODING_COLUMN, NULL, + ADD_COLUMN, FALSE, + -1); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - NAME_COLUMN, _("Add or Remove..."), - ENCODING_COLUMN, NULL, - ADD_COLUMN, TRUE, - -1); - } + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + NAME_COLUMN, _("Add or Remove..."), + ENCODING_COLUMN, NULL, + ADD_COLUMN, TRUE, + -1); + } - /* set the model back */ - gtk_combo_box_set_model (GTK_COMBO_BOX (menu), - GTK_TREE_MODEL (menu->priv->store)); - gtk_combo_box_set_active (GTK_COMBO_BOX (menu), 0); + /* set the model back */ + gtk_combo_box_set_model (GTK_COMBO_BOX (menu), GTK_TREE_MODEL (menu->priv->store)); + gtk_combo_box_set_active (GTK_COMBO_BOX (menu), 0); - g_signal_handler_unblock (menu, menu->priv->changed_id); + g_signal_handler_unblock (menu, menu->priv->changed_id); } static void xed_encodings_combo_box_init (XedEncodingsComboBox *menu) { - GtkCellRenderer *text_renderer; + GtkCellRenderer *text_renderer; - menu->priv = XED_ENCODINGS_COMBO_BOX_GET_PRIVATE (menu); + menu->priv = XED_ENCODINGS_COMBO_BOX_GET_PRIVATE (menu); - menu->priv->store = gtk_list_store_new (N_COLUMNS, - G_TYPE_STRING, - G_TYPE_POINTER, - G_TYPE_BOOLEAN); + menu->priv->store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN); - /* Setup up the cells */ - text_renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (menu), - text_renderer, TRUE); + /* Setup up the cells */ + text_renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (menu), text_renderer, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (menu), - text_renderer, - "text", - NAME_COLUMN, - NULL); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (menu), + text_renderer, + "text", + NAME_COLUMN, + NULL); - gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (menu), - separator_func, NULL, - NULL); + gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (menu), separator_func, NULL, NULL); - menu->priv->changed_id = g_signal_connect (menu, "changed", - G_CALLBACK (add_or_remove), - menu->priv->store); + menu->priv->changed_id = g_signal_connect (menu, "changed", G_CALLBACK (add_or_remove), menu->priv->store); - update_menu (menu); + update_menu (menu); } GtkWidget * xed_encodings_combo_box_new (gboolean save_mode) { - return g_object_new (XED_TYPE_ENCODINGS_COMBO_BOX, - "save_mode", save_mode, - NULL); + return g_object_new (XED_TYPE_ENCODINGS_COMBO_BOX, + "save_mode", save_mode, + NULL); } const XedEncoding * xed_encodings_combo_box_get_selected_encoding (XedEncodingsComboBox *menu) { - GtkTreeIter iter; + GtkTreeIter iter; - g_return_val_if_fail (XED_IS_ENCODINGS_COMBO_BOX (menu), NULL); + g_return_val_if_fail (XED_IS_ENCODINGS_COMBO_BOX (menu), NULL); - if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (menu), &iter)) - { - const XedEncoding *ret; - GtkTreeModel *model; + if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (menu), &iter)) + { + const XedEncoding *ret; + GtkTreeModel *model; - model = gtk_combo_box_get_model (GTK_COMBO_BOX (menu)); + model = gtk_combo_box_get_model (GTK_COMBO_BOX (menu)); - gtk_tree_model_get (model, &iter, - ENCODING_COLUMN, &ret, - -1); + gtk_tree_model_get (model, &iter, ENCODING_COLUMN, &ret, -1); - return ret; - } + return ret; + } - return NULL; + return NULL; } /** @@ -437,33 +419,30 @@ xed_encodings_combo_box_get_selected_encoding (XedEncodingsComboBox *menu) **/ void xed_encodings_combo_box_set_selected_encoding (XedEncodingsComboBox *menu, - const XedEncoding *encoding) + const XedEncoding *encoding) { - GtkTreeIter iter; - GtkTreeModel *model; - gboolean b; - g_return_if_fail (XED_IS_ENCODINGS_COMBO_BOX (menu)); - g_return_if_fail (GTK_IS_COMBO_BOX (menu)); + GtkTreeIter iter; + GtkTreeModel *model; + gboolean b; + g_return_if_fail (XED_IS_ENCODINGS_COMBO_BOX (menu)); + g_return_if_fail (GTK_IS_COMBO_BOX (menu)); - model = gtk_combo_box_get_model (GTK_COMBO_BOX (menu)); - b = gtk_tree_model_get_iter_first (model, &iter); + model = gtk_combo_box_get_model (GTK_COMBO_BOX (menu)); + b = gtk_tree_model_get_iter_first (model, &iter); - while (b) - { - const XedEncoding *enc; + while (b) + { + const XedEncoding *enc; - gtk_tree_model_get (model, &iter, - ENCODING_COLUMN, &enc, - -1); + gtk_tree_model_get (model, &iter, ENCODING_COLUMN, &enc, -1); - if (enc == encoding) - { - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (menu), - &iter); + if (enc == encoding) + { + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (menu), &iter); - return; - } + return; + } - b = gtk_tree_model_iter_next (model, &iter); - } + b = gtk_tree_model_iter_next (model, &iter); + } } From c50299ec32b3b30c6e77551f3c67d519f13dfe68 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 11 Dec 2016 22:33:32 -0800 Subject: [PATCH 006/132] xed-commands-file: Clean up code styling --- xed/xed-commands-file.c | 2302 +++++++++++++++++++-------------------- 1 file changed, 1101 insertions(+), 1201 deletions(-) diff --git a/xed/xed-commands-file.c b/xed/xed-commands-file.c index f239261..ee0af0f 100644 --- a/xed/xed-commands-file.c +++ b/xed/xed-commands-file.c @@ -51,221 +51,217 @@ /* Defined constants */ -#define XED_OPEN_DIALOG_KEY "xed-open-dialog-key" -#define XED_TAB_TO_SAVE_AS "xed-tab-to-save-as" +#define XED_OPEN_DIALOG_KEY "xed-open-dialog-key" +#define XED_TAB_TO_SAVE_AS "xed-tab-to-save-as" #define XED_LIST_OF_TABS_TO_SAVE_AS "xed-list-of-tabs-to-save-as" #define XED_IS_CLOSING_ALL "xed-is-closing-all" -#define XED_IS_QUITTING "xed-is-quitting" -#define XED_IS_CLOSING_TAB "xed-is-closing-tab" -#define XED_IS_QUITTING_ALL "xed-is-quitting-all" +#define XED_IS_QUITTING "xed-is-quitting" +#define XED_IS_CLOSING_TAB "xed-is-closing-tab" +#define XED_IS_QUITTING_ALL "xed-is-quitting-all" static void tab_state_changed_while_saving (XedTab *tab, - GParamSpec *pspec, - XedWindow *window); + GParamSpec *pspec, + XedWindow *window); void _xed_cmd_file_new (GtkAction *action, - XedWindow *window) + XedWindow *window) { - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - xed_window_create_tab (window, TRUE); + xed_window_create_tab (window, TRUE); } static XedTab * -get_tab_from_file (GList *docs, GFile *file) +get_tab_from_file (GList *docs, + GFile *file) { - XedTab *tab = NULL; + XedTab *tab = NULL; - while (docs != NULL) - { - XedDocument *d; - GFile *l; + while (docs != NULL) + { + XedDocument *d; + GFile *l; - d = XED_DOCUMENT (docs->data); + d = XED_DOCUMENT (docs->data); - l = xed_document_get_location (d); - if (l != NULL) - { - if (g_file_equal (l, file)) - { - tab = xed_tab_get_from_document (d); - g_object_unref (l); - break; - } + l = xed_document_get_location (d); + if (l != NULL) + { + if (g_file_equal (l, file)) + { + tab = xed_tab_get_from_document (d); + g_object_unref (l); + break; + } - g_object_unref (l); - } + g_object_unref (l); + } - docs = g_list_next (docs); - } + docs = g_list_next (docs); + } - return tab; + return tab; } static gboolean -is_duplicated_file (GSList *files, GFile *file) +is_duplicated_file (GSList *files, + GFile *file) { - while (files != NULL) - { - if (g_file_equal (files->data, file)) - return TRUE; + while (files != NULL) + { + if (g_file_equal (files->data, file)) + { + return TRUE; + } - files = g_slist_next (files); - } + files = g_slist_next (files); + } - return FALSE; + return FALSE; } /* File loading */ static gint load_file_list (XedWindow *window, - GSList *files, - const XedEncoding *encoding, - gint line_pos, - gboolean create) + GSList *files, + const XedEncoding *encoding, + gint line_pos, + gboolean create) { - XedTab *tab; - gint loaded_files = 0; /* Number of files to load */ - gboolean jump_to = TRUE; /* Whether to jump to the new tab */ - GList *win_docs; - GSList *files_to_load = NULL; - GSList *l; + XedTab *tab; + gint loaded_files = 0; /* Number of files to load */ + gboolean jump_to = TRUE; /* Whether to jump to the new tab */ + GList *win_docs; + GSList *files_to_load = NULL; + GSList *l; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - win_docs = xed_window_get_documents (window); + win_docs = xed_window_get_documents (window); - /* Remove the uris corresponding to documents already open - * in "window" and remove duplicates from "uris" list */ - for (l = files; l != NULL; l = l->next) - { - if (!is_duplicated_file (files_to_load, l->data)) - { - tab = get_tab_from_file (win_docs, l->data); - if (tab != NULL) - { - if (l == files) - { - xed_window_set_active_tab (window, tab); - jump_to = FALSE; + /* Remove the uris corresponding to documents already open + * in "window" and remove duplicates from "uris" list */ + for (l = files; l != NULL; l = l->next) + { + if (!is_duplicated_file (files_to_load, l->data)) + { + tab = get_tab_from_file (win_docs, l->data); + if (tab != NULL) + { + if (l == files) + { + xed_window_set_active_tab (window, tab); + jump_to = FALSE; - if (line_pos > 0) - { - XedDocument *doc; - XedView *view; + if (line_pos > 0) + { + XedDocument *doc; + XedView *view; - doc = xed_tab_get_document (tab); - view = xed_tab_get_view (tab); + doc = xed_tab_get_document (tab); + view = xed_tab_get_view (tab); - /* document counts lines starting from 0 */ - xed_document_goto_line (doc, line_pos - 1); - xed_view_scroll_to_cursor (view); - } - } + /* document counts lines starting from 0 */ + xed_document_goto_line (doc, line_pos - 1); + xed_view_scroll_to_cursor (view); + } + } - ++loaded_files; - } - else - { - files_to_load = g_slist_prepend (files_to_load, - l->data); - } - } - } + ++loaded_files; + } + else + { + files_to_load = g_slist_prepend (files_to_load, + l->data); + } + } + } - g_list_free (win_docs); + g_list_free (win_docs); - if (files_to_load == NULL) - return loaded_files; - - files_to_load = g_slist_reverse (files_to_load); - l = files_to_load; + if (files_to_load == NULL) + { + return loaded_files; + } - tab = xed_window_get_active_tab (window); - if (tab != NULL) - { - XedDocument *doc; + files_to_load = g_slist_reverse (files_to_load); + l = files_to_load; - doc = xed_tab_get_document (tab); + tab = xed_window_get_active_tab (window); + if (tab != NULL) + { + XedDocument *doc; - if (xed_document_is_untouched (doc) && - (xed_tab_get_state (tab) == XED_TAB_STATE_NORMAL)) - { - gchar *uri; + doc = xed_tab_get_document (tab); - // FIXME: pass the GFile to tab when api is there - uri = g_file_get_uri (l->data); - _xed_tab_load (tab, - uri, - encoding, - line_pos, - create); - g_free (uri); + if (xed_document_is_untouched (doc) && (xed_tab_get_state (tab) == XED_TAB_STATE_NORMAL)) + { + gchar *uri; - l = g_slist_next (l); - jump_to = FALSE; + // FIXME: pass the GFile to tab when api is there + uri = g_file_get_uri (l->data); + _xed_tab_load (tab, uri, encoding, line_pos, create); + g_free (uri); - ++loaded_files; - } - } + l = g_slist_next (l); + jump_to = FALSE; - while (l != NULL) - { - gchar *uri; + ++loaded_files; + } + } - g_return_val_if_fail (l->data != NULL, 0); + while (l != NULL) + { + gchar *uri; - // FIXME: pass the GFile to tab when api is there - uri = g_file_get_uri (l->data); - tab = xed_window_create_tab_from_uri (window, - uri, - encoding, - line_pos, - create, - jump_to); - g_free (uri); + g_return_val_if_fail (l->data != NULL, 0); - if (tab != NULL) - { - jump_to = FALSE; - ++loaded_files; - } + // FIXME: pass the GFile to tab when api is there + uri = g_file_get_uri (l->data); + tab = xed_window_create_tab_from_uri (window, uri, encoding, line_pos, create, jump_to); + g_free (uri); - l = g_slist_next (l); - } + if (tab != NULL) + { + jump_to = FALSE; + ++loaded_files; + } - if (loaded_files == 1) - { - XedDocument *doc; - gchar *uri_for_display; + l = g_slist_next (l); + } - g_return_val_if_fail (tab != NULL, loaded_files); + if (loaded_files == 1) + { + XedDocument *doc; + gchar *uri_for_display; - doc = xed_tab_get_document (tab); - uri_for_display = xed_document_get_uri_for_display (doc); + g_return_val_if_fail (tab != NULL, loaded_files); - xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar), - window->priv->generic_message_cid, - _("Loading file '%s'\342\200\246"), - uri_for_display); + doc = xed_tab_get_document (tab); + uri_for_display = xed_document_get_uri_for_display (doc); - g_free (uri_for_display); - } - else - { - xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar), - window->priv->generic_message_cid, - ngettext("Loading %d file\342\200\246", - "Loading %d files\342\200\246", - loaded_files), - loaded_files); - } + xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar), + window->priv->generic_message_cid, + _("Loading file '%s'\342\200\246"), + uri_for_display); - /* Free uris_to_load. Note that l points to the first element of uris_to_load */ - g_slist_free (files_to_load); + g_free (uri_for_display); + } + else + { + xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar), + window->priv->generic_message_cid, + ngettext("Loading %d file\342\200\246", + "Loading %d files\342\200\246", + loaded_files), + loaded_files); + } - return loaded_files; + /* Free uris_to_load. Note that l points to the first element of uris_to_load */ + g_slist_free (files_to_load); + + return loaded_files; } @@ -274,32 +270,36 @@ load_file_list (XedWindow *window, static gint load_uri_list (XedWindow *window, - const GSList *uris, - const XedEncoding *encoding, - gint line_pos, - gboolean create) + const GSList *uris, + const XedEncoding *encoding, + gint line_pos, + gboolean create) { - GSList *files = NULL; - const GSList *u; - gint ret; + GSList *files = NULL; + const GSList *u; + gint ret; - for (u = uris; u != NULL; u = u->next) - { - gchar *uri = u->data; + for (u = uris; u != NULL; u = u->next) + { + gchar *uri = u->data; - if (xed_utils_is_valid_uri (uri)) - files = g_slist_prepend (files, g_file_new_for_uri (uri)); - else - g_warning ("invalid uri: %s", uri); - } - files = g_slist_reverse (files); + if (xed_utils_is_valid_uri (uri)) + { + files = g_slist_prepend (files, g_file_new_for_uri (uri)); + } + else + { + g_warning ("invalid uri: %s", uri); + } + } + files = g_slist_reverse (files); - ret = load_file_list (window, files, encoding, line_pos, create); + ret = load_file_list (window, files, encoding, line_pos, create); - g_slist_foreach (files, (GFunc) g_object_unref, NULL); - g_slist_free (files); + g_slist_foreach (files, (GFunc) g_object_unref, NULL); + g_slist_free (files); - return ret; + return ret; } /** @@ -315,23 +315,23 @@ load_uri_list (XedWindow *window, */ void xed_commands_load_uri (XedWindow *window, - const gchar *uri, - const XedEncoding *encoding, - gint line_pos) + const gchar *uri, + const XedEncoding *encoding, + gint line_pos) { - GSList *uris = NULL; + GSList *uris = NULL; - g_return_if_fail (XED_IS_WINDOW (window)); - g_return_if_fail (uri != NULL); - g_return_if_fail (xed_utils_is_valid_uri (uri)); + g_return_if_fail (XED_IS_WINDOW (window)); + g_return_if_fail (uri != NULL); + g_return_if_fail (xed_utils_is_valid_uri (uri)); - xed_debug_message (DEBUG_COMMANDS, "Loading URI '%s'", uri); + xed_debug_message (DEBUG_COMMANDS, "Loading URI '%s'", uri); - uris = g_slist_prepend (uris, (gchar *)uri); + uris = g_slist_prepend (uris, (gchar *)uri); - load_uri_list (window, uris, encoding, line_pos, FALSE); + load_uri_list (window, uris, encoding, line_pos, FALSE); - g_slist_free (uris); + g_slist_free (uris); } /** @@ -347,16 +347,16 @@ xed_commands_load_uri (XedWindow *window, */ gint xed_commands_load_uris (XedWindow *window, - const GSList *uris, - const XedEncoding *encoding, - gint line_pos) + const GSList *uris, + const XedEncoding *encoding, + gint line_pos) { - g_return_val_if_fail (XED_IS_WINDOW (window), 0); - g_return_val_if_fail ((uris != NULL) && (uris->data != NULL), 0); + g_return_val_if_fail (XED_IS_WINDOW (window), 0); + g_return_val_if_fail ((uris != NULL) && (uris->data != NULL), 0); - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - return load_uri_list (window, uris, encoding, line_pos, FALSE); + return load_uri_list (window, uris, encoding, line_pos, FALSE); } /* @@ -364,16 +364,16 @@ xed_commands_load_uris (XedWindow *window, */ static gint xed_commands_load_files (XedWindow *window, - GSList *files, - const XedEncoding *encoding, - gint line_pos) + GSList *files, + const XedEncoding *encoding, + gint line_pos) { - g_return_val_if_fail (XED_IS_WINDOW (window), 0); - g_return_val_if_fail ((files != NULL) && (files->data != NULL), 0); + g_return_val_if_fail (XED_IS_WINDOW (window), 0); + g_return_val_if_fail ((files != NULL) && (files->data != NULL), 0); - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - return load_file_list (window, files, encoding, line_pos, FALSE); + return load_file_list (window, files, encoding, line_pos, FALSE); } /* @@ -383,137 +383,126 @@ xed_commands_load_files (XedWindow *window, */ gint _xed_cmd_load_files_from_prompt (XedWindow *window, - GSList *files, - const XedEncoding *encoding, - gint line_pos) + GSList *files, + const XedEncoding *encoding, + gint line_pos) { - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - return load_file_list (window, files, encoding, line_pos, TRUE); + return load_file_list (window, files, encoding, line_pos, TRUE); } static void open_dialog_destroyed (XedWindow *window, - XedFileChooserDialog *dialog) + XedFileChooserDialog *dialog) { - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - g_object_set_data (G_OBJECT (window), - XED_OPEN_DIALOG_KEY, - NULL); + g_object_set_data (G_OBJECT (window), XED_OPEN_DIALOG_KEY, NULL); } static void open_dialog_response_cb (XedFileChooserDialog *dialog, - gint response_id, + gint response_id, XedWindow *window) { - GSList *files; - const XedEncoding *encoding; + GSList *files; + const XedEncoding *encoding; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - if (response_id != GTK_RESPONSE_OK) - { - gtk_widget_destroy (GTK_WIDGET (dialog)); + if (response_id != GTK_RESPONSE_OK) + { + gtk_widget_destroy (GTK_WIDGET (dialog)); - return; - } + return; + } - files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog)); - g_return_if_fail (files != NULL); + files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog)); + g_return_if_fail (files != NULL); - encoding = xed_file_chooser_dialog_get_encoding (dialog); + encoding = xed_file_chooser_dialog_get_encoding (dialog); - gtk_widget_destroy (GTK_WIDGET (dialog)); + gtk_widget_destroy (GTK_WIDGET (dialog)); - /* Remember the folder we navigated to */ - _xed_window_set_default_location (window, files->data); + /* Remember the folder we navigated to */ + _xed_window_set_default_location (window, files->data); - xed_commands_load_files (window, - files, - encoding, - 0); + xed_commands_load_files (window, files, encoding, 0); - g_slist_foreach (files, (GFunc) g_object_unref, NULL); - g_slist_free (files); + g_slist_foreach (files, (GFunc) g_object_unref, NULL); + g_slist_free (files); } void -_xed_cmd_file_open (GtkAction *action, - XedWindow *window) +_xed_cmd_file_open (GtkAction *action, + XedWindow *window) { - GtkWidget *open_dialog; - gpointer data; - XedDocument *doc; - GFile *default_path = NULL; + GtkWidget *open_dialog; + gpointer data; + XedDocument *doc; + GFile *default_path = NULL; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - data = g_object_get_data (G_OBJECT (window), XED_OPEN_DIALOG_KEY); + data = g_object_get_data (G_OBJECT (window), XED_OPEN_DIALOG_KEY); - if (data != NULL) - { - g_return_if_fail (XED_IS_FILE_CHOOSER_DIALOG (data)); + if (data != NULL) + { + g_return_if_fail (XED_IS_FILE_CHOOSER_DIALOG (data)); - gtk_window_present (GTK_WINDOW (data)); + gtk_window_present (GTK_WINDOW (data)); - return; - } + return; + } - /* Translators: "Open Files" is the title of the file chooser window */ - open_dialog = xed_file_chooser_dialog_new (_("Open Files"), - GTK_WINDOW (window), - GTK_FILE_CHOOSER_ACTION_OPEN, - NULL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_OK, - NULL); + /* Translators: "Open Files" is the title of the file chooser window */ + open_dialog = xed_file_chooser_dialog_new (_("Open Files"), + GTK_WINDOW (window), + GTK_FILE_CHOOSER_ACTION_OPEN, + NULL, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_OK, + NULL); - g_object_set_data (G_OBJECT (window), - XED_OPEN_DIALOG_KEY, - open_dialog); + g_object_set_data (G_OBJECT (window), XED_OPEN_DIALOG_KEY, open_dialog); - g_object_weak_ref (G_OBJECT (open_dialog), - (GWeakNotify) open_dialog_destroyed, - window); + g_object_weak_ref (G_OBJECT (open_dialog), (GWeakNotify) open_dialog_destroyed, window); - /* Set the curret folder uri */ - doc = xed_window_get_active_document (window); - if (doc != NULL) - { - GFile *file; + /* Set the curret folder uri */ + doc = xed_window_get_active_document (window); + if (doc != NULL) + { + GFile *file; - file = xed_document_get_location (doc); + file = xed_document_get_location (doc); - if (file != NULL) - { - default_path = g_file_get_parent (file); - g_object_unref (file); - } - } + if (file != NULL) + { + default_path = g_file_get_parent (file); + g_object_unref (file); + } + } - if (default_path == NULL) - default_path = _xed_window_get_default_location (window); + if (default_path == NULL) + { + default_path = _xed_window_get_default_location (window); + } - if (default_path != NULL) - { - gchar *uri; + if (default_path != NULL) + { + gchar *uri; - uri = g_file_get_uri (default_path); - gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (open_dialog), - uri); + uri = g_file_get_uri (default_path); + gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (open_dialog), uri); - g_free (uri); - g_object_unref (default_path); - } + g_free (uri); + g_object_unref (default_path); + } - g_signal_connect (open_dialog, - "response", - G_CALLBACK (open_dialog_response_cb), - window); + g_signal_connect (open_dialog, "response", G_CALLBACK (open_dialog_response_cb), window); - gtk_widget_show (open_dialog); + gtk_widget_show (open_dialog); } /* File saving */ @@ -522,404 +511,384 @@ static void file_save_as (XedTab *tab, XedWindow *window); static gboolean is_read_only (GFile *location) { - gboolean ret = TRUE; /* default to read only */ - GFileInfo *info; + gboolean ret = TRUE; /* default to read only */ + GFileInfo *info; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - info = g_file_query_info (location, - G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, - G_FILE_QUERY_INFO_NONE, - NULL, - NULL); + info = g_file_query_info (location, + G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, + G_FILE_QUERY_INFO_NONE, + NULL, + NULL); - if (info != NULL) - { - if (g_file_info_has_attribute (info, - G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) - { - ret = !g_file_info_get_attribute_boolean (info, - G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); - } + if (info != NULL) + { + if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) + { + ret = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); + } - g_object_unref (info); - } + g_object_unref (info); + } - return ret; + return ret; } /* FIXME: modify this dialog to be similar to the one provided by gtk+ for * already existing files - Paolo (Oct. 11, 2005) */ static gboolean -replace_read_only_file (GtkWindow *parent, GFile *file) +replace_read_only_file (GtkWindow *parent, + GFile *file) { - GtkWidget *dialog; - gint ret; - gchar *parse_name; - gchar *name_for_display; + GtkWidget *dialog; + gint ret; + gchar *parse_name; + gchar *name_for_display; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - parse_name = g_file_get_parse_name (file); + parse_name = g_file_get_parse_name (file); - /* Truncate the name so it doesn't get insanely wide. Note that even - * though the dialog uses wrapped text, if the name doesn't contain - * white space then the text-wrapping code is too stupid to wrap it. - */ - name_for_display = xed_utils_str_middle_truncate (parse_name, 50); - g_free (parse_name); + /* Truncate the name so it doesn't get insanely wide. Note that even + * though the dialog uses wrapped text, if the name doesn't contain + * white space then the text-wrapping code is too stupid to wrap it. + */ + name_for_display = xed_utils_str_middle_truncate (parse_name, 50); + g_free (parse_name); - dialog = gtk_message_dialog_new (parent, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_NONE, - _("The file \"%s\" is read-only."), - name_for_display); - g_free (name_for_display); + dialog = gtk_message_dialog_new (parent, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + _("The file \"%s\" is read-only."), + name_for_display); + g_free (name_for_display); - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), - _("Do you want to try to replace it " - "with the one you are saving?")); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), + _("Do you want to try to replace it " + "with the one you are saving?")); - gtk_dialog_add_button (GTK_DIALOG (dialog), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); + gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - xed_dialog_add_button (GTK_DIALOG (dialog), - _("_Replace"), - GTK_STOCK_SAVE_AS, - GTK_RESPONSE_YES); + xed_dialog_add_button (GTK_DIALOG (dialog), _("_Replace"), GTK_STOCK_SAVE_AS, GTK_RESPONSE_YES); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), - GTK_RESPONSE_CANCEL); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL); - gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); - ret = gtk_dialog_run (GTK_DIALOG (dialog)); + ret = gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); + gtk_widget_destroy (dialog); - return (ret == GTK_RESPONSE_YES); + return (ret == GTK_RESPONSE_YES); } static void save_dialog_response_cb (XedFileChooserDialog *dialog, - gint response_id, + gint response_id, XedWindow *window) { - GFile *file; - const XedEncoding *encoding; - XedTab *tab; - gpointer data; - GSList *tabs_to_save_as; - XedDocumentNewlineType newline_type; + GFile *file; + const XedEncoding *encoding; + XedTab *tab; + gpointer data; + GSList *tabs_to_save_as; + XedDocumentNewlineType newline_type; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - tab = XED_TAB (g_object_get_data (G_OBJECT (dialog), - XED_TAB_TO_SAVE_AS)); + tab = XED_TAB (g_object_get_data (G_OBJECT (dialog), XED_TAB_TO_SAVE_AS)); - if (response_id != GTK_RESPONSE_OK) - { - gtk_widget_destroy (GTK_WIDGET (dialog)); + if (response_id != GTK_RESPONSE_OK) + { + gtk_widget_destroy (GTK_WIDGET (dialog)); - goto save_next_tab; - } + goto save_next_tab; + } - file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog)); - g_return_if_fail (file != NULL); + file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog)); + g_return_if_fail (file != NULL); - encoding = xed_file_chooser_dialog_get_encoding (dialog); - newline_type = xed_file_chooser_dialog_get_newline_type (dialog); + encoding = xed_file_chooser_dialog_get_encoding (dialog); + newline_type = xed_file_chooser_dialog_get_newline_type (dialog); - gtk_widget_destroy (GTK_WIDGET (dialog)); + gtk_widget_destroy (GTK_WIDGET (dialog)); - if (tab != NULL) - { - XedDocument *doc; - gchar *parse_name; - gchar *uri; + if (tab != NULL) + { + XedDocument *doc; + gchar *parse_name; + gchar *uri; - doc = xed_tab_get_document (tab); - g_return_if_fail (XED_IS_DOCUMENT (doc)); + doc = xed_tab_get_document (tab); + g_return_if_fail (XED_IS_DOCUMENT (doc)); - parse_name = g_file_get_parse_name (file); + parse_name = g_file_get_parse_name (file); - xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar), - window->priv->generic_message_cid, - _("Saving file '%s'\342\200\246"), - parse_name); + xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar), + window->priv->generic_message_cid, + _("Saving file '%s'\342\200\246"), + parse_name); - g_free (parse_name); + g_free (parse_name); - /* let's remember the dir we navigated too, - * even if the saving fails... */ - _xed_window_set_default_location (window, file); + /* let's remember the dir we navigated too, + * even if the saving fails... */ + _xed_window_set_default_location (window, file); - // FIXME: pass the GFile to tab when api is there - uri = g_file_get_uri (file); - _xed_tab_save_as (tab, uri, encoding, newline_type); - g_free (uri); - } + // FIXME: pass the GFile to tab when api is there + uri = g_file_get_uri (file); + _xed_tab_save_as (tab, uri, encoding, newline_type); + g_free (uri); + } - g_object_unref (file); + g_object_unref (file); save_next_tab: - data = g_object_get_data (G_OBJECT (window), - XED_LIST_OF_TABS_TO_SAVE_AS); - if (data == NULL) - return; + data = g_object_get_data (G_OBJECT (window), XED_LIST_OF_TABS_TO_SAVE_AS); + if (data == NULL) + { + return; + } - /* Save As the next tab of the list (we are Saving All files) */ - tabs_to_save_as = (GSList *)data; - g_return_if_fail (tab == XED_TAB (tabs_to_save_as->data)); + /* Save As the next tab of the list (we are Saving All files) */ + tabs_to_save_as = (GSList *)data; + g_return_if_fail (tab == XED_TAB (tabs_to_save_as->data)); - /* Remove the first item of the list */ - tabs_to_save_as = g_slist_delete_link (tabs_to_save_as, - tabs_to_save_as); + /* Remove the first item of the list */ + tabs_to_save_as = g_slist_delete_link (tabs_to_save_as, tabs_to_save_as); - g_object_set_data (G_OBJECT (window), - XED_LIST_OF_TABS_TO_SAVE_AS, - tabs_to_save_as); + g_object_set_data (G_OBJECT (window), XED_LIST_OF_TABS_TO_SAVE_AS, tabs_to_save_as); - if (tabs_to_save_as != NULL) - { - tab = XED_TAB (tabs_to_save_as->data); + if (tabs_to_save_as != NULL) + { + tab = XED_TAB (tabs_to_save_as->data); - if (GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (tab), - XED_IS_CLOSING_TAB)) == TRUE) - { - g_object_set_data (G_OBJECT (tab), - XED_IS_CLOSING_TAB, - NULL); + if (GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (tab), XED_IS_CLOSING_TAB)) == TRUE) + { + g_object_set_data (G_OBJECT (tab), XED_IS_CLOSING_TAB, NULL); - /* Trace tab state changes */ - g_signal_connect (tab, - "notify::state", - G_CALLBACK (tab_state_changed_while_saving), - window); - } + /* Trace tab state changes */ + g_signal_connect (tab, "notify::state", G_CALLBACK (tab_state_changed_while_saving), window); + } - xed_window_set_active_tab (window, tab); - file_save_as (tab, window); - } + xed_window_set_active_tab (window, tab); + file_save_as (tab, window); + } } static GtkFileChooserConfirmation confirm_overwrite_callback (GtkFileChooser *dialog, - gpointer data) + gpointer data) { - gchar *uri; - GFile *file; - GtkFileChooserConfirmation res; + gchar *uri; + GFile *file; + GtkFileChooserConfirmation res; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - uri = gtk_file_chooser_get_uri (dialog); - file = g_file_new_for_uri (uri); - g_free (uri); + uri = gtk_file_chooser_get_uri (dialog); + file = g_file_new_for_uri (uri); + g_free (uri); - if (is_read_only (file)) - { - if (replace_read_only_file (GTK_WINDOW (dialog), file)) - res = GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME; - else - res = GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN; - } - else - { - /* fall back to the default confirmation dialog */ - res = GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM; - } + if (is_read_only (file)) + { + if (replace_read_only_file (GTK_WINDOW (dialog), file)) + { + res = GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME; + } + else + { + res = GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN; + } + } + else + { + /* fall back to the default confirmation dialog */ + res = GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM; + } - g_object_unref (file); + g_object_unref (file); - return res; + return res; } static void file_save_as (XedTab *tab, - XedWindow *window) + XedWindow *window) { - GtkWidget *save_dialog; - GtkWindowGroup *wg; - XedDocument *doc; - GFile *file; - gboolean uri_set = FALSE; - const XedEncoding *encoding; - XedDocumentNewlineType newline_type; + GtkWidget *save_dialog; + GtkWindowGroup *wg; + XedDocument *doc; + GFile *file; + gboolean uri_set = FALSE; + const XedEncoding *encoding; + XedDocumentNewlineType newline_type; - g_return_if_fail (XED_IS_TAB (tab)); - g_return_if_fail (XED_IS_WINDOW (window)); + g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail (XED_IS_WINDOW (window)); - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - save_dialog = xed_file_chooser_dialog_new (_("Save As\342\200\246"), - GTK_WINDOW (window), - GTK_FILE_CHOOSER_ACTION_SAVE, - NULL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_OK, - NULL); + save_dialog = xed_file_chooser_dialog_new (_("Save As\342\200\246"), + GTK_WINDOW (window), + GTK_FILE_CHOOSER_ACTION_SAVE, + NULL, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_OK, + NULL); - gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (save_dialog), - TRUE); - g_signal_connect (save_dialog, - "confirm-overwrite", - G_CALLBACK (confirm_overwrite_callback), - NULL); + gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (save_dialog), TRUE); + g_signal_connect (save_dialog, "confirm-overwrite", G_CALLBACK (confirm_overwrite_callback), NULL); - wg = xed_window_get_group (window); + wg = xed_window_get_group (window); - gtk_window_group_add_window (wg, - GTK_WINDOW (save_dialog)); + gtk_window_group_add_window (wg, GTK_WINDOW (save_dialog)); - /* Save As dialog is modal to its main window */ - gtk_window_set_modal (GTK_WINDOW (save_dialog), TRUE); + /* Save As dialog is modal to its main window */ + gtk_window_set_modal (GTK_WINDOW (save_dialog), TRUE); - /* Set the suggested file name */ - doc = xed_tab_get_document (tab); - file = xed_document_get_location (doc); + /* Set the suggested file name */ + doc = xed_tab_get_document (tab); + file = xed_document_get_location (doc); - if (file != NULL) - { - uri_set = gtk_file_chooser_set_file (GTK_FILE_CHOOSER (save_dialog), - file, - NULL); + if (file != NULL) + { + uri_set = gtk_file_chooser_set_file (GTK_FILE_CHOOSER (save_dialog), file, NULL); - g_object_unref (file); - } + g_object_unref (file); + } - if (!uri_set) - { - GFile *default_path; - gchar *docname; + if (!uri_set) + { + GFile *default_path; + gchar *docname; - default_path = _xed_window_get_default_location (window); - docname = xed_document_get_short_name_for_display (doc); + default_path = _xed_window_get_default_location (window); + docname = xed_document_get_short_name_for_display (doc); - if (default_path != NULL) - { - gchar *uri; + if (default_path != NULL) + { + gchar *uri; - uri = g_file_get_uri (default_path); - gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (save_dialog), - uri); + uri = g_file_get_uri (default_path); + gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (save_dialog), uri); - g_free (uri); - g_object_unref (default_path); - } + g_free (uri); + g_object_unref (default_path); + } - gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (save_dialog), - docname); + gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (save_dialog), docname); - g_free (docname); - } + g_free (docname); + } - /* Set suggested encoding */ - encoding = xed_document_get_encoding (doc); - g_return_if_fail (encoding != NULL); + /* Set suggested encoding */ + encoding = xed_document_get_encoding (doc); + g_return_if_fail (encoding != NULL); - newline_type = xed_document_get_newline_type (doc); + newline_type = xed_document_get_newline_type (doc); - xed_file_chooser_dialog_set_encoding (XED_FILE_CHOOSER_DIALOG (save_dialog), - encoding); + xed_file_chooser_dialog_set_encoding (XED_FILE_CHOOSER_DIALOG (save_dialog), encoding); - xed_file_chooser_dialog_set_newline_type (XED_FILE_CHOOSER_DIALOG (save_dialog), - newline_type); + xed_file_chooser_dialog_set_newline_type (XED_FILE_CHOOSER_DIALOG (save_dialog), newline_type); - g_object_set_data (G_OBJECT (save_dialog), - XED_TAB_TO_SAVE_AS, - tab); + g_object_set_data (G_OBJECT (save_dialog), XED_TAB_TO_SAVE_AS, tab); - g_signal_connect (save_dialog, - "response", - G_CALLBACK (save_dialog_response_cb), - window); + g_signal_connect (save_dialog, "response", G_CALLBACK (save_dialog_response_cb), window); - gtk_widget_show (save_dialog); + gtk_widget_show (save_dialog); } static void file_save (XedTab *tab, - XedWindow *window) + XedWindow *window) { - XedDocument *doc; - gchar *uri_for_display; + XedDocument *doc; + gchar *uri_for_display; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - g_return_if_fail (XED_IS_TAB (tab)); - g_return_if_fail (XED_IS_WINDOW (window)); + g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail (XED_IS_WINDOW (window)); - doc = xed_tab_get_document (tab); - g_return_if_fail (XED_IS_DOCUMENT (doc)); + doc = xed_tab_get_document (tab); + g_return_if_fail (XED_IS_DOCUMENT (doc)); - if (xed_document_is_untitled (doc) || - xed_document_get_readonly (doc)) - { - xed_debug_message (DEBUG_COMMANDS, "Untitled or Readonly"); + if (xed_document_is_untitled (doc) || + xed_document_get_readonly (doc)) + { + xed_debug_message (DEBUG_COMMANDS, "Untitled or Readonly"); - file_save_as (tab, window); - - return; - } + file_save_as (tab, window); - uri_for_display = xed_document_get_uri_for_display (doc); - xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar), - window->priv->generic_message_cid, - _("Saving file '%s'\342\200\246"), - uri_for_display); + return; + } - g_free (uri_for_display); + uri_for_display = xed_document_get_uri_for_display (doc); + xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar), + window->priv->generic_message_cid, + _("Saving file '%s'\342\200\246"), + uri_for_display); - _xed_tab_save (tab); + g_free (uri_for_display); + + _xed_tab_save (tab); } void -_xed_cmd_file_save (GtkAction *action, - XedWindow *window) +_xed_cmd_file_save (GtkAction *action, + XedWindow *window) { - XedTab *tab; + XedTab *tab; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - tab = xed_window_get_active_tab (window); - if (tab == NULL) - return; + tab = xed_window_get_active_tab (window); + if (tab == NULL) + { + return; + } - file_save (tab, window); + file_save (tab, window); } void -_xed_cmd_file_save_as (GtkAction *action, - XedWindow *window) +_xed_cmd_file_save_as (GtkAction *action, + XedWindow *window) { - XedTab *tab; + XedTab *tab; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - tab = xed_window_get_active_tab (window); - if (tab == NULL) - return; + tab = xed_window_get_active_tab (window); + if (tab == NULL) + { + return; + } - file_save_as (tab, window); + file_save_as (tab, window); } static gboolean document_needs_saving (XedDocument *doc) { - if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc))) - return TRUE; + if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc))) + { + return TRUE; + } - /* we check if it was deleted only for local files - * since for remote files it may hang */ - if (xed_document_is_local (doc) && xed_document_get_deleted (doc)) - return TRUE; + /* we check if it was deleted only for local files + * since for remote files it may hang */ + if (xed_document_is_local (doc) && xed_document_get_deleted (doc)) + { + return TRUE; + } - return FALSE; + return FALSE; } /* @@ -927,775 +896,722 @@ document_needs_saving (XedDocument *doc) */ void _xed_cmd_file_save_documents_list (XedWindow *window, - GList *docs) + GList *docs) { - GList *l; - GSList *tabs_to_save_as = NULL; + GList *l; + GSList *tabs_to_save_as = NULL; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - g_return_if_fail (!(xed_window_get_state (window) & - (XED_WINDOW_STATE_PRINTING | - XED_WINDOW_STATE_SAVING_SESSION))); + g_return_if_fail (!(xed_window_get_state (window) & (XED_WINDOW_STATE_PRINTING | XED_WINDOW_STATE_SAVING_SESSION))); - l = docs; - while (l != NULL) - { - XedDocument *doc; - XedTab *t; - XedTabState state; + l = docs; + while (l != NULL) + { + XedDocument *doc; + XedTab *t; + XedTabState state; - g_return_if_fail (XED_IS_DOCUMENT (l->data)); - - doc = XED_DOCUMENT (l->data); - t = xed_tab_get_from_document (doc); - state = xed_tab_get_state (t); + g_return_if_fail (XED_IS_DOCUMENT (l->data)); - g_return_if_fail (state != XED_TAB_STATE_PRINTING); - g_return_if_fail (state != XED_TAB_STATE_PRINT_PREVIEWING); - g_return_if_fail (state != XED_TAB_STATE_CLOSING); + doc = XED_DOCUMENT (l->data); + t = xed_tab_get_from_document (doc); + state = xed_tab_get_state (t); - if ((state == XED_TAB_STATE_NORMAL) || - (state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW) || - (state == XED_TAB_STATE_GENERIC_NOT_EDITABLE)) - { - /* FIXME: manage the case of local readonly files owned by the - user is running xed - Paolo (Dec. 8, 2005) */ - if (xed_document_is_untitled (doc) || - xed_document_get_readonly (doc)) - { - if (document_needs_saving (doc)) - { - tabs_to_save_as = g_slist_prepend (tabs_to_save_as, - t); - } - } - else - { - file_save (t, window); - } - } - else - { - /* If the state is: - - XED_TAB_STATE_LOADING: we do not save since we are sure the file is unmodified - - XED_TAB_STATE_REVERTING: we do not save since the user wants - to return back to the version of the file she previously saved - - XED_TAB_STATE_SAVING: well, we are already saving (no need to save again) - - XED_TAB_STATE_PRINTING, XED_TAB_STATE_PRINT_PREVIEWING: there is not a - real reason for not saving in this case, we do not save to avoid to run - two operations using the message area at the same time (may be we can remove - this limitation in the future). Note that SaveAll, ClosAll - and Quit are unsensitive if the window state is PRINTING. - - XED_TAB_STATE_GENERIC_ERROR: we do not save since the document contains - errors (I don't think this is a very frequent case, we should probably remove - this state) - - XED_TAB_STATE_LOADING_ERROR: there is nothing to save - - XED_TAB_STATE_REVERTING_ERROR: there is nothing to save and saving the current - document will overwrite the copy of the file the user wants to go back to - - XED_TAB_STATE_SAVING_ERROR: we do not save since we just failed to save, so there is - no reason to automatically retry... we wait for user intervention - - XED_TAB_STATE_CLOSING: this state is invalid in this case - */ + g_return_if_fail (state != XED_TAB_STATE_PRINTING); + g_return_if_fail (state != XED_TAB_STATE_PRINT_PREVIEWING); + g_return_if_fail (state != XED_TAB_STATE_CLOSING); - gchar *uri_for_display; + if ((state == XED_TAB_STATE_NORMAL) || + (state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW) || + (state == XED_TAB_STATE_GENERIC_NOT_EDITABLE)) + { + /* FIXME: manage the case of local readonly files owned by the + user is running xed - Paolo (Dec. 8, 2005) */ + if (xed_document_is_untitled (doc) || xed_document_get_readonly (doc)) + { + if (document_needs_saving (doc)) + { + tabs_to_save_as = g_slist_prepend (tabs_to_save_as, t); + } + } + else + { + file_save (t, window); + } + } + else + { + /* If the state is: + - XED_TAB_STATE_LOADING: we do not save since we are sure the file is unmodified + - XED_TAB_STATE_REVERTING: we do not save since the user wants + to return back to the version of the file she previously saved + - XED_TAB_STATE_SAVING: well, we are already saving (no need to save again) + - XED_TAB_STATE_PRINTING, XED_TAB_STATE_PRINT_PREVIEWING: there is not a + real reason for not saving in this case, we do not save to avoid to run + two operations using the message area at the same time (may be we can remove + this limitation in the future). Note that SaveAll, ClosAll + and Quit are unsensitive if the window state is PRINTING. + - XED_TAB_STATE_GENERIC_ERROR: we do not save since the document contains + errors (I don't think this is a very frequent case, we should probably remove + this state) + - XED_TAB_STATE_LOADING_ERROR: there is nothing to save + - XED_TAB_STATE_REVERTING_ERROR: there is nothing to save and saving the current + document will overwrite the copy of the file the user wants to go back to + - XED_TAB_STATE_SAVING_ERROR: we do not save since we just failed to save, so there is + no reason to automatically retry... we wait for user intervention + - XED_TAB_STATE_CLOSING: this state is invalid in this case + */ - uri_for_display = xed_document_get_uri_for_display (doc); - xed_debug_message (DEBUG_COMMANDS, - "File '%s' not saved. State: %d", - uri_for_display, - state); - g_free (uri_for_display); - } + gchar *uri_for_display; - l = g_list_next (l); - } + uri_for_display = xed_document_get_uri_for_display (doc); + xed_debug_message (DEBUG_COMMANDS, + "File '%s' not saved. State: %d", + uri_for_display, + state); + g_free (uri_for_display); + } - if (tabs_to_save_as != NULL) - { - XedTab *tab; + l = g_list_next (l); + } - tabs_to_save_as = g_slist_reverse (tabs_to_save_as ); + if (tabs_to_save_as != NULL) + { + XedTab *tab; - g_return_if_fail (g_object_get_data (G_OBJECT (window), - XED_LIST_OF_TABS_TO_SAVE_AS) == NULL); + tabs_to_save_as = g_slist_reverse (tabs_to_save_as ); - g_object_set_data (G_OBJECT (window), - XED_LIST_OF_TABS_TO_SAVE_AS, - tabs_to_save_as); + g_return_if_fail (g_object_get_data (G_OBJECT (window), XED_LIST_OF_TABS_TO_SAVE_AS) == NULL); - tab = XED_TAB (tabs_to_save_as->data); + g_object_set_data (G_OBJECT (window), XED_LIST_OF_TABS_TO_SAVE_AS, tabs_to_save_as); - xed_window_set_active_tab (window, tab); - file_save_as (tab, window); - } + tab = XED_TAB (tabs_to_save_as->data); + + xed_window_set_active_tab (window, tab); + file_save_as (tab, window); + } } void xed_commands_save_all_documents (XedWindow *window) { - GList *docs; - - g_return_if_fail (XED_IS_WINDOW (window)); + GList *docs; - xed_debug (DEBUG_COMMANDS); + g_return_if_fail (XED_IS_WINDOW (window)); - docs = xed_window_get_documents (window); + xed_debug (DEBUG_COMMANDS); - _xed_cmd_file_save_documents_list (window, docs); + docs = xed_window_get_documents (window); - g_list_free (docs); + _xed_cmd_file_save_documents_list (window, docs); + + g_list_free (docs); } void -_xed_cmd_file_save_all (GtkAction *action, - XedWindow *window) +_xed_cmd_file_save_all (GtkAction *action, + XedWindow *window) { - xed_commands_save_all_documents (window); + xed_commands_save_all_documents (window); } void xed_commands_save_document (XedWindow *window, - XedDocument *document) + XedDocument *document) { - XedTab *tab; + XedTab *tab; - g_return_if_fail (XED_IS_WINDOW (window)); - g_return_if_fail (XED_IS_DOCUMENT (document)); - - xed_debug (DEBUG_COMMANDS); - - tab = xed_tab_get_from_document (document); - file_save (tab, window); + g_return_if_fail (XED_IS_WINDOW (window)); + g_return_if_fail (XED_IS_DOCUMENT (document)); + + xed_debug (DEBUG_COMMANDS); + + tab = xed_tab_get_from_document (document); + file_save (tab, window); } /* File revert */ static void do_revert (XedWindow *window, - XedTab *tab) + XedTab *tab) { - XedDocument *doc; - gchar *docname; + XedDocument *doc; + gchar *docname; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - doc = xed_tab_get_document (tab); - docname = xed_document_get_short_name_for_display (doc); + doc = xed_tab_get_document (tab); + docname = xed_document_get_short_name_for_display (doc); - xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar), - window->priv->generic_message_cid, - _("Reverting the document '%s'\342\200\246"), - docname); + xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar), + window->priv->generic_message_cid, + _("Reverting the document '%s'\342\200\246"), + docname); - g_free (docname); + g_free (docname); - _xed_tab_revert (tab); + _xed_tab_revert (tab); } static void -revert_dialog_response_cb (GtkDialog *dialog, - gint response_id, - XedWindow *window) +revert_dialog_response_cb (GtkDialog *dialog, + gint response_id, + XedWindow *window) { - XedTab *tab; + XedTab *tab; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - /* FIXME: we are relying on the fact that the dialog is - modal so the active tab can't be changed... - not very nice - Paolo (Oct 11, 2005) */ - tab = xed_window_get_active_tab (window); - if (tab == NULL) - return; + /* FIXME: we are relying on the fact that the dialog is + modal so the active tab can't be changed... + not very nice - Paolo (Oct 11, 2005) */ + tab = xed_window_get_active_tab (window); + if (tab == NULL) + { + return; + } - gtk_widget_destroy (GTK_WIDGET (dialog)); + gtk_widget_destroy (GTK_WIDGET (dialog)); - if (response_id == GTK_RESPONSE_OK) - { - do_revert (window, tab); - } + if (response_id == GTK_RESPONSE_OK) + { + do_revert (window, tab); + } } static GtkWidget * revert_dialog (XedWindow *window, - XedDocument *doc) + XedDocument *doc) { - GtkWidget *dialog; - gchar *docname; - gchar *primary_msg; - gchar *secondary_msg; - glong seconds; + GtkWidget *dialog; + gchar *docname; + gchar *primary_msg; + gchar *secondary_msg; + glong seconds; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - docname = xed_document_get_short_name_for_display (doc); - primary_msg = g_strdup_printf (_("Revert unsaved changes to document '%s'?"), - docname); - g_free (docname); + docname = xed_document_get_short_name_for_display (doc); + primary_msg = g_strdup_printf (_("Revert unsaved changes to document '%s'?"), docname); + g_free (docname); - seconds = MAX (1, _xed_document_get_seconds_since_last_save_or_load (doc)); + seconds = MAX (1, _xed_document_get_seconds_since_last_save_or_load (doc)); - if (seconds < 55) - { - secondary_msg = g_strdup_printf ( - ngettext ("Changes made to the document in the last %ld second " - "will be permanently lost.", - "Changes made to the document in the last %ld seconds " - "will be permanently lost.", - seconds), - seconds); - } - else if (seconds < 75) /* 55 <= seconds < 75 */ - { - secondary_msg = g_strdup (_("Changes made to the document in the last minute " - "will be permanently lost.")); - } - else if (seconds < 110) /* 75 <= seconds < 110 */ - { - secondary_msg = g_strdup_printf ( - ngettext ("Changes made to the document in the last minute and " - "%ld second will be permanently lost.", - "Changes made to the document in the last minute and " - "%ld seconds will be permanently lost.", - seconds - 60 ), - seconds - 60); - } - else if (seconds < 3600) - { - secondary_msg = g_strdup_printf ( - ngettext ("Changes made to the document in the last %ld minute " - "will be permanently lost.", - "Changes made to the document in the last %ld minutes " - "will be permanently lost.", - seconds / 60), - seconds / 60); - } - else if (seconds < 7200) - { - gint minutes; - seconds -= 3600; + if (seconds < 55) + { + secondary_msg = g_strdup_printf (ngettext ("Changes made to the document in the last %ld second " + "will be permanently lost.", + "Changes made to the document in the last %ld seconds " + "will be permanently lost.", + seconds), + seconds); + } + else if (seconds < 75) /* 55 <= seconds < 75 */ + { + secondary_msg = g_strdup (_("Changes made to the document in the last minute " + "will be permanently lost.")); + } + else if (seconds < 110) /* 75 <= seconds < 110 */ + { + secondary_msg = g_strdup_printf (ngettext ("Changes made to the document in the last minute and " + "%ld second will be permanently lost.", + "Changes made to the document in the last minute and " + "%ld seconds will be permanently lost.", + seconds - 60 ), + seconds - 60); + } + else if (seconds < 3600) + { + secondary_msg = g_strdup_printf (ngettext ("Changes made to the document in the last %ld minute " + "will be permanently lost.", + "Changes made to the document in the last %ld minutes " + "will be permanently lost.", + seconds / 60), + seconds / 60); + } + else if (seconds < 7200) + { + gint minutes; + seconds -= 3600; - minutes = seconds / 60; - if (minutes < 5) - { - secondary_msg = g_strdup (_("Changes made to the document in the last hour " - "will be permanently lost.")); - } - else - { - secondary_msg = g_strdup_printf ( - ngettext ("Changes made to the document in the last hour and " - "%d minute will be permanently lost.", - "Changes made to the document in the last hour and " - "%d minutes will be permanently lost.", - minutes), - minutes); - } - } - else - { - gint hours; + minutes = seconds / 60; + if (minutes < 5) + { + secondary_msg = g_strdup (_("Changes made to the document in the last hour " + "will be permanently lost.")); + } + else + { + secondary_msg = g_strdup_printf (ngettext ("Changes made to the document in the last hour and " + "%d minute will be permanently lost.", + "Changes made to the document in the last hour and " + "%d minutes will be permanently lost.", + minutes), + minutes); + } + } + else + { + gint hours; - hours = seconds / 3600; + hours = seconds / 3600; - secondary_msg = g_strdup_printf ( - ngettext ("Changes made to the document in the last %d hour " - "will be permanently lost.", - "Changes made to the document in the last %d hours " - "will be permanently lost.", - hours), - hours); - } + secondary_msg = g_strdup_printf (ngettext ("Changes made to the document in the last %d hour " + "will be permanently lost.", + "Changes made to the document in the last %d hours " + "will be permanently lost.", + hours), + hours); + } - dialog = gtk_message_dialog_new (GTK_WINDOW (window), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_NONE, - "%s", primary_msg); + dialog = gtk_message_dialog_new (GTK_WINDOW (window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + "%s", primary_msg); - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), - "%s", secondary_msg); - g_free (primary_msg); - g_free (secondary_msg); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", secondary_msg); + g_free (primary_msg); + g_free (secondary_msg); - gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); - gtk_dialog_add_button (GTK_DIALOG (dialog), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); + gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - xed_dialog_add_button (GTK_DIALOG (dialog), - _("_Revert"), - GTK_STOCK_REVERT_TO_SAVED, - GTK_RESPONSE_OK); + xed_dialog_add_button (GTK_DIALOG (dialog), _("_Revert"), GTK_STOCK_REVERT_TO_SAVED, GTK_RESPONSE_OK); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), - GTK_RESPONSE_CANCEL); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL); - return dialog; + return dialog; } void _xed_cmd_file_revert (GtkAction *action, - XedWindow *window) + XedWindow *window) { - XedTab *tab; - XedDocument *doc; - GtkWidget *dialog; - GtkWindowGroup *wg; + XedTab *tab; + XedDocument *doc; + GtkWidget *dialog; + GtkWindowGroup *wg; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - tab = xed_window_get_active_tab (window); - g_return_if_fail (tab != NULL); + tab = xed_window_get_active_tab (window); + g_return_if_fail (tab != NULL); - /* If we are already displaying a notification - * reverting will drop local modifications, do - * not bug the user further */ - if (xed_tab_get_state (tab) == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) - { - do_revert (window, tab); - return; - } + /* If we are already displaying a notification + * reverting will drop local modifications, do + * not bug the user further */ + if (xed_tab_get_state (tab) == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) + { + do_revert (window, tab); + return; + } - doc = xed_tab_get_document (tab); - g_return_if_fail (doc != NULL); - g_return_if_fail (!xed_document_is_untitled (doc)); + doc = xed_tab_get_document (tab); + g_return_if_fail (doc != NULL); + g_return_if_fail (!xed_document_is_untitled (doc)); - dialog = revert_dialog (window, doc); + dialog = revert_dialog (window, doc); - wg = xed_window_get_group (window); + wg = xed_window_get_group (window); - gtk_window_group_add_window (wg, GTK_WINDOW (dialog)); + gtk_window_group_add_window (wg, GTK_WINDOW (dialog)); - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - g_signal_connect (dialog, - "response", - G_CALLBACK (revert_dialog_response_cb), - window); + g_signal_connect (dialog, "response", G_CALLBACK (revert_dialog_response_cb), window); - gtk_widget_show (dialog); + gtk_widget_show (dialog); } /* Close tab */ static gboolean really_close_tab (XedTab *tab) { - GtkWidget *toplevel; - XedWindow *window; + GtkWidget *toplevel; + XedWindow *window; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - g_return_val_if_fail (xed_tab_get_state (tab) == XED_TAB_STATE_CLOSING, - FALSE); + g_return_val_if_fail (xed_tab_get_state (tab) == XED_TAB_STATE_CLOSING, FALSE); - toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tab)); - g_return_val_if_fail (XED_IS_WINDOW (toplevel), FALSE); + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tab)); + g_return_val_if_fail (XED_IS_WINDOW (toplevel), FALSE); - window = XED_WINDOW (toplevel); + window = XED_WINDOW (toplevel); - xed_window_close_tab (window, tab); + xed_window_close_tab (window, tab); - if (xed_window_get_active_tab (window) == NULL) - { - gboolean is_quitting; + if (xed_window_get_active_tab (window) == NULL) + { + gboolean is_quitting; - is_quitting = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window), - XED_IS_QUITTING)); + is_quitting = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window), XED_IS_QUITTING)); - if (is_quitting) - gtk_widget_destroy (GTK_WIDGET (window)); - } + if (is_quitting) + { + gtk_widget_destroy (GTK_WIDGET (window)); + } + } - return FALSE; + return FALSE; } static void -tab_state_changed_while_saving (XedTab *tab, - GParamSpec *pspec, - XedWindow *window) +tab_state_changed_while_saving (XedTab *tab, + GParamSpec *pspec, + XedWindow *window) { - XedTabState ts; + XedTabState ts; - ts = xed_tab_get_state (tab); + ts = xed_tab_get_state (tab); - xed_debug_message (DEBUG_COMMANDS, "State while saving: %d\n", ts); + xed_debug_message (DEBUG_COMMANDS, "State while saving: %d\n", ts); - /* When the state become NORMAL, it means the saving operation is - finished */ - if (ts == XED_TAB_STATE_NORMAL) - { - XedDocument *doc; + /* When the state become NORMAL, it means the saving operation is + finished */ + if (ts == XED_TAB_STATE_NORMAL) + { + XedDocument *doc; - g_signal_handlers_disconnect_by_func (tab, - G_CALLBACK (tab_state_changed_while_saving), - window); + g_signal_handlers_disconnect_by_func (tab, G_CALLBACK (tab_state_changed_while_saving), window); - doc = xed_tab_get_document (tab); - g_return_if_fail (doc != NULL); + doc = xed_tab_get_document (tab); + g_return_if_fail (doc != NULL); - /* If the saving operation failed or was interrupted, then the - document is still "modified" -> do not close the tab */ - if (document_needs_saving (doc)) - return; + /* If the saving operation failed or was interrupted, then the + document is still "modified" -> do not close the tab */ + if (document_needs_saving (doc)) + { + return; + } - /* Close the document only if it has been succesfully saved. - Tab state is set to CLOSING (it is a state without exiting - transitions) and the tab is closed in a idle handler */ - _xed_tab_mark_for_closing (tab); + /* Close the document only if it has been succesfully saved. + Tab state is set to CLOSING (it is a state without exiting + transitions) and the tab is closed in a idle handler */ + _xed_tab_mark_for_closing (tab); - g_idle_add_full (G_PRIORITY_HIGH_IDLE, - (GSourceFunc)really_close_tab, - tab, - NULL); - } + g_idle_add_full (G_PRIORITY_HIGH_IDLE, (GSourceFunc)really_close_tab, tab, NULL); + } } static void save_and_close (XedTab *tab, - XedWindow *window) + XedWindow *window) { - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - /* Trace tab state changes */ - g_signal_connect (tab, - "notify::state", - G_CALLBACK (tab_state_changed_while_saving), - window); + /* Trace tab state changes */ + g_signal_connect (tab, "notify::state", G_CALLBACK (tab_state_changed_while_saving), window); - file_save (tab, window); + file_save (tab, window); } static void save_as_and_close (XedTab *tab, - XedWindow *window) + XedWindow *window) { - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - g_object_set_data (G_OBJECT (tab), - XED_IS_CLOSING_TAB, - NULL); + g_object_set_data (G_OBJECT (tab), XED_IS_CLOSING_TAB, NULL); - /* Trace tab state changes */ - g_signal_connect (tab, - "notify::state", - G_CALLBACK (tab_state_changed_while_saving), - window); + /* Trace tab state changes */ + g_signal_connect (tab, "notify::state", G_CALLBACK (tab_state_changed_while_saving), window); - xed_window_set_active_tab (window, tab); - file_save_as (tab, window); + xed_window_set_active_tab (window, tab); + file_save_as (tab, window); } static void -save_and_close_all_documents (const GList *docs, - XedWindow *window) +save_and_close_all_documents (const GList *docs, + XedWindow *window) { - GList *tabs; - GList *l; - GSList *sl; - GSList *tabs_to_save_as; - GSList *tabs_to_save_and_close; - GList *tabs_to_close; + GList *tabs; + GList *l; + GSList *sl; + GSList *tabs_to_save_as; + GSList *tabs_to_save_and_close; + GList *tabs_to_close; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - g_return_if_fail (!(xed_window_get_state (window) & XED_WINDOW_STATE_PRINTING)); + g_return_if_fail (!(xed_window_get_state (window) & XED_WINDOW_STATE_PRINTING)); - tabs = gtk_container_get_children ( - GTK_CONTAINER (_xed_window_get_notebook (window))); + tabs = gtk_container_get_children (GTK_CONTAINER (_xed_window_get_notebook (window))); - tabs_to_save_as = NULL; - tabs_to_save_and_close = NULL; - tabs_to_close = NULL; + tabs_to_save_as = NULL; + tabs_to_save_and_close = NULL; + tabs_to_close = NULL; - l = tabs; - while (l != NULL) - { - XedTab *t; - XedTabState state; - XedDocument *doc; + l = tabs; + while (l != NULL) + { + XedTab *t; + XedTabState state; + XedDocument *doc; - t = XED_TAB (l->data); + t = XED_TAB (l->data); - state = xed_tab_get_state (t); - doc = xed_tab_get_document (t); + state = xed_tab_get_state (t); + doc = xed_tab_get_document (t); - /* If the state is: ([*] invalid states) - - XED_TAB_STATE_NORMAL: close (and if needed save) - - XED_TAB_STATE_LOADING: close, we are sure the file is unmodified - - XED_TAB_STATE_REVERTING: since the user wants - to return back to the version of the file she previously saved, we can close - without saving (CHECK: are we sure this is the right behavior, suppose the case - the original file has been deleted) - - [*] XED_TAB_STATE_SAVING: invalid, ClosAll - and Quit are unsensitive if the window state is SAVING. - - [*] XED_TAB_STATE_PRINTING, XED_TAB_STATE_PRINT_PREVIEWING: there is not a - real reason for not closing in this case, we do not save to avoid to run - two operations using the message area at the same time (may be we can remove - this limitation in the future). Note that ClosAll - and Quit are unsensitive if the window state is PRINTING. - - XED_TAB_STATE_SHOWING_PRINT_PREVIEW: close (and if needed save) - - XED_TAB_STATE_LOADING_ERROR: close without saving (if the state is LOADING_ERROR then the - document is not modified) - - XED_TAB_STATE_REVERTING_ERROR: we do not close since the document contains errors - - XED_TAB_STATE_SAVING_ERROR: we do not close since the document contains errors - - XED_TAB_STATE_GENERIC_ERROR: we do not close since the document contains - errors (CHECK: we should problably remove this state) - - [*] XED_TAB_STATE_CLOSING: this state is invalid in this case - */ + /* If the state is: ([*] invalid states) + - XED_TAB_STATE_NORMAL: close (and if needed save) + - XED_TAB_STATE_LOADING: close, we are sure the file is unmodified + - XED_TAB_STATE_REVERTING: since the user wants + to return back to the version of the file she previously saved, we can close + without saving (CHECK: are we sure this is the right behavior, suppose the case + the original file has been deleted) + - [*] XED_TAB_STATE_SAVING: invalid, ClosAll + and Quit are unsensitive if the window state is SAVING. + - [*] XED_TAB_STATE_PRINTING, XED_TAB_STATE_PRINT_PREVIEWING: there is not a + real reason for not closing in this case, we do not save to avoid to run + two operations using the message area at the same time (may be we can remove + this limitation in the future). Note that ClosAll + and Quit are unsensitive if the window state is PRINTING. + - XED_TAB_STATE_SHOWING_PRINT_PREVIEW: close (and if needed save) + - XED_TAB_STATE_LOADING_ERROR: close without saving (if the state is LOADING_ERROR then the + document is not modified) + - XED_TAB_STATE_REVERTING_ERROR: we do not close since the document contains errors + - XED_TAB_STATE_SAVING_ERROR: we do not close since the document contains errors + - XED_TAB_STATE_GENERIC_ERROR: we do not close since the document contains + errors (CHECK: we should problably remove this state) + - [*] XED_TAB_STATE_CLOSING: this state is invalid in this case + */ - g_return_if_fail (state != XED_TAB_STATE_PRINTING); - g_return_if_fail (state != XED_TAB_STATE_PRINT_PREVIEWING); - g_return_if_fail (state != XED_TAB_STATE_CLOSING); - g_return_if_fail (state != XED_TAB_STATE_SAVING); + g_return_if_fail (state != XED_TAB_STATE_PRINTING); + g_return_if_fail (state != XED_TAB_STATE_PRINT_PREVIEWING); + g_return_if_fail (state != XED_TAB_STATE_CLOSING); + g_return_if_fail (state != XED_TAB_STATE_SAVING); - if ((state != XED_TAB_STATE_SAVING_ERROR) && - (state != XED_TAB_STATE_GENERIC_ERROR) && - (state != XED_TAB_STATE_REVERTING_ERROR)) - { - if ((g_list_index ((GList *)docs, doc) >= 0) && - (state != XED_TAB_STATE_LOADING) && - (state != XED_TAB_STATE_LOADING_ERROR) && - (state != XED_TAB_STATE_REVERTING)) /* CHECK: is this the right behavior with REVERTING ?*/ - { - /* The document must be saved before closing */ - g_return_if_fail (document_needs_saving (doc)); - - /* FIXME: manage the case of local readonly files owned by the - user is running xed - Paolo (Dec. 8, 2005) */ - if (xed_document_is_untitled (doc) || - xed_document_get_readonly (doc)) - { - g_object_set_data (G_OBJECT (t), - XED_IS_CLOSING_TAB, - GBOOLEAN_TO_POINTER (TRUE)); + if ((state != XED_TAB_STATE_SAVING_ERROR) && + (state != XED_TAB_STATE_GENERIC_ERROR) && + (state != XED_TAB_STATE_REVERTING_ERROR)) + { + if ((g_list_index ((GList *)docs, doc) >= 0) && + (state != XED_TAB_STATE_LOADING) && + (state != XED_TAB_STATE_LOADING_ERROR) && + (state != XED_TAB_STATE_REVERTING)) /* CHECK: is this the right behavior with REVERTING ?*/ + { + /* The document must be saved before closing */ + g_return_if_fail (document_needs_saving (doc)); - tabs_to_save_as = g_slist_prepend (tabs_to_save_as, - t); - } - else - { - tabs_to_save_and_close = g_slist_prepend (tabs_to_save_and_close, - t); - } - } - else - { - /* The document must be closed without saving */ - tabs_to_close = g_list_prepend (tabs_to_close, - t); - } - } + /* FIXME: manage the case of local readonly files owned by the + user is running xed - Paolo (Dec. 8, 2005) */ + if (xed_document_is_untitled (doc) || xed_document_get_readonly (doc)) + { + g_object_set_data (G_OBJECT (t), XED_IS_CLOSING_TAB, GBOOLEAN_TO_POINTER (TRUE)); - l = g_list_next (l); - } + tabs_to_save_as = g_slist_prepend (tabs_to_save_as, t); + } + else + { + tabs_to_save_and_close = g_slist_prepend (tabs_to_save_and_close, t); + } + } + else + { + /* The document must be closed without saving */ + tabs_to_close = g_list_prepend (tabs_to_close, t); + } + } - g_list_free (tabs); + l = g_list_next (l); + } - /* Close all tabs to close (in a sync way) */ - xed_window_close_tabs (window, tabs_to_close); - g_list_free (tabs_to_close); + g_list_free (tabs); - /* Save and close all the files in tabs_to_save_and_close */ - sl = tabs_to_save_and_close; - while (sl != NULL) - { - save_and_close (XED_TAB (sl->data), - window); - sl = g_slist_next (sl); - } - g_slist_free (tabs_to_save_and_close); + /* Close all tabs to close (in a sync way) */ + xed_window_close_tabs (window, tabs_to_close); + g_list_free (tabs_to_close); - /* Save As and close all the files in tabs_to_save_as */ - if (tabs_to_save_as != NULL) - { - XedTab *tab; + /* Save and close all the files in tabs_to_save_and_close */ + sl = tabs_to_save_and_close; + while (sl != NULL) + { + save_and_close (XED_TAB (sl->data), window); + sl = g_slist_next (sl); + } + g_slist_free (tabs_to_save_and_close); - tabs_to_save_as = g_slist_reverse (tabs_to_save_as ); + /* Save As and close all the files in tabs_to_save_as */ + if (tabs_to_save_as != NULL) + { + XedTab *tab; - g_return_if_fail (g_object_get_data (G_OBJECT (window), - XED_LIST_OF_TABS_TO_SAVE_AS) == NULL); + tabs_to_save_as = g_slist_reverse (tabs_to_save_as ); - g_object_set_data (G_OBJECT (window), - XED_LIST_OF_TABS_TO_SAVE_AS, - tabs_to_save_as); + g_return_if_fail (g_object_get_data (G_OBJECT (window), XED_LIST_OF_TABS_TO_SAVE_AS) == NULL); - tab = XED_TAB (tabs_to_save_as->data); + g_object_set_data (G_OBJECT (window), XED_LIST_OF_TABS_TO_SAVE_AS, tabs_to_save_as); - save_as_and_close (tab, window); - } + tab = XED_TAB (tabs_to_save_as->data); + + save_as_and_close (tab, window); + } } static void -save_and_close_document (const GList *docs, - XedWindow *window) +save_and_close_document (const GList *docs, + XedWindow *window) { - XedTab *tab; + XedTab *tab; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - g_return_if_fail (docs->next == NULL); + g_return_if_fail (docs->next == NULL); - tab = xed_tab_get_from_document (XED_DOCUMENT (docs->data)); - g_return_if_fail (tab != NULL); + tab = xed_tab_get_from_document (XED_DOCUMENT (docs->data)); + g_return_if_fail (tab != NULL); - save_and_close (tab, window); + save_and_close (tab, window); } static void close_all_tabs (XedWindow *window) { - gboolean is_quitting; + gboolean is_quitting; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - /* There is no document to save -> close all tabs */ - xed_window_close_all_tabs (window); + /* There is no document to save -> close all tabs */ + xed_window_close_all_tabs (window); - is_quitting = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window), - XED_IS_QUITTING)); + is_quitting = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window), XED_IS_QUITTING)); - if (is_quitting) - gtk_widget_destroy (GTK_WIDGET (window)); + if (is_quitting) + { + gtk_widget_destroy (GTK_WIDGET (window)); + } - return; + return; } static void close_document (XedWindow *window, - XedDocument *doc) + XedDocument *doc) { - XedTab *tab; + XedTab *tab; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - tab = xed_tab_get_from_document (doc); - g_return_if_fail (tab != NULL); + tab = xed_tab_get_from_document (doc); + g_return_if_fail (tab != NULL); - xed_window_close_tab (window, tab); + xed_window_close_tab (window, tab); } static void close_confirmation_dialog_response_handler (XedCloseConfirmationDialog *dlg, - gint response_id, - XedWindow *window) + gint response_id, + XedWindow *window) { - GList *selected_documents; - gboolean is_closing_all; + GList *selected_documents; + gboolean is_closing_all; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - is_closing_all = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window), - XED_IS_CLOSING_ALL)); + is_closing_all = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window), XED_IS_CLOSING_ALL)); - gtk_widget_hide (GTK_WIDGET (dlg)); + gtk_widget_hide (GTK_WIDGET (dlg)); - switch (response_id) - { - case GTK_RESPONSE_YES: /* Save and Close */ - selected_documents = xed_close_confirmation_dialog_get_selected_documents (dlg); - if (selected_documents == NULL) - { - if (is_closing_all) - { - /* There is no document to save -> close all tabs */ - /* We call gtk_widget_destroy before close_all_tabs - * because close_all_tabs could destroy the xed window */ - gtk_widget_destroy (GTK_WIDGET (dlg)); + switch (response_id) + { + case GTK_RESPONSE_YES: /* Save and Close */ + selected_documents = xed_close_confirmation_dialog_get_selected_documents (dlg); + if (selected_documents == NULL) + { + if (is_closing_all) + { + /* There is no document to save -> close all tabs */ + /* We call gtk_widget_destroy before close_all_tabs + * because close_all_tabs could destroy the xed window */ + gtk_widget_destroy (GTK_WIDGET (dlg)); - close_all_tabs (window); + close_all_tabs (window); - return; - } - else - g_return_if_reached (); - } - else - { - if (is_closing_all) - { - save_and_close_all_documents (selected_documents, - window); - } - else - { - save_and_close_document (selected_documents, - window); - } - } + return; + } + else + g_return_if_reached (); + } + else + { + if (is_closing_all) + { + save_and_close_all_documents (selected_documents, window); + } + else + { + save_and_close_document (selected_documents, window); + } + } - g_list_free (selected_documents); + g_list_free (selected_documents); - break; + break; - case GTK_RESPONSE_NO: /* Close without Saving */ - if (is_closing_all) - { - /* We call gtk_widget_destroy before close_all_tabs - * because close_all_tabs could destroy the xed window */ - gtk_widget_destroy (GTK_WIDGET (dlg)); + case GTK_RESPONSE_NO: /* Close without Saving */ + if (is_closing_all) + { + /* We call gtk_widget_destroy before close_all_tabs + * because close_all_tabs could destroy the xed window */ + gtk_widget_destroy (GTK_WIDGET (dlg)); - close_all_tabs (window); + close_all_tabs (window); - return; - } - else - { - const GList *unsaved_documents; + return; + } + else + { + const GList *unsaved_documents; - unsaved_documents = xed_close_confirmation_dialog_get_unsaved_documents (dlg); - g_return_if_fail (unsaved_documents->next == NULL); + unsaved_documents = xed_close_confirmation_dialog_get_unsaved_documents (dlg); + g_return_if_fail (unsaved_documents->next == NULL); - close_document (window, - XED_DOCUMENT (unsaved_documents->data)); - } + close_document (window, XED_DOCUMENT (unsaved_documents->data)); + } - break; - default: /* Do not close */ + break; + default: /* Do not close */ - /* Reset is_quitting flag */ - g_object_set_data (G_OBJECT (window), - XED_IS_QUITTING, - GBOOLEAN_TO_POINTER (FALSE)); + /* Reset is_quitting flag */ + g_object_set_data (G_OBJECT (window), XED_IS_QUITTING, GBOOLEAN_TO_POINTER (FALSE)); - break; - } + break; + } - gtk_widget_destroy (GTK_WIDGET (dlg)); + gtk_widget_destroy (GTK_WIDGET (dlg)); } /* Returns TRUE if the tab can be immediately closed */ static gboolean tab_can_close (XedTab *tab, - GtkWindow *window) + GtkWindow *window) { - XedDocument *doc; + XedDocument *doc; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - doc = xed_tab_get_document (tab); + doc = xed_tab_get_document (tab); - if (!_xed_tab_can_close (tab)) - { - GtkWidget *dlg; + if (!_xed_tab_can_close (tab)) + { + GtkWidget *dlg; - dlg = xed_close_confirmation_dialog_new_single ( - window, - doc, - FALSE); + dlg = xed_close_confirmation_dialog_new_single (window, doc, FALSE); - g_signal_connect (dlg, - "response", - G_CALLBACK (close_confirmation_dialog_response_handler), - window); + g_signal_connect (dlg, "response", + G_CALLBACK (close_confirmation_dialog_response_handler), window); - gtk_widget_show (dlg); + gtk_widget_show (dlg); - return FALSE; - } + return FALSE; + } - return TRUE; + return TRUE; } /* CHECK: we probably need this one public for plugins... @@ -1706,142 +1622,126 @@ tab_can_close (XedTab *tab, */ void _xed_cmd_file_close_tab (XedTab *tab, - XedWindow *window) + XedWindow *window) { - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - g_return_if_fail (GTK_WIDGET (window) == gtk_widget_get_toplevel (GTK_WIDGET (tab))); + g_return_if_fail (GTK_WIDGET (window) == gtk_widget_get_toplevel (GTK_WIDGET (tab))); - g_object_set_data (G_OBJECT (window), - XED_IS_CLOSING_ALL, - GBOOLEAN_TO_POINTER (FALSE)); - - g_object_set_data (G_OBJECT (window), - XED_IS_QUITTING, - GBOOLEAN_TO_POINTER (FALSE)); - - g_object_set_data (G_OBJECT (window), - XED_IS_QUITTING_ALL, - GINT_TO_POINTER (FALSE)); + g_object_set_data (G_OBJECT (window), XED_IS_CLOSING_ALL, GBOOLEAN_TO_POINTER (FALSE)); + g_object_set_data (G_OBJECT (window), XED_IS_QUITTING, GBOOLEAN_TO_POINTER (FALSE)); + g_object_set_data (G_OBJECT (window), XED_IS_QUITTING_ALL, GINT_TO_POINTER (FALSE)); - if (tab_can_close (tab, GTK_WINDOW (window))) - xed_window_close_tab (window, tab); + if (tab_can_close (tab, GTK_WINDOW (window))) + { + xed_window_close_tab (window, tab); + } } void _xed_cmd_file_close (GtkAction *action, - XedWindow *window) + XedWindow *window) { - XedTab *active_tab; + XedTab *active_tab; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - active_tab = xed_window_get_active_tab (window); + active_tab = xed_window_get_active_tab (window); - if (active_tab == NULL) - { - return; - } + if (active_tab == NULL) + { + return; + } - _xed_cmd_file_close_tab (active_tab, window); + _xed_cmd_file_close_tab (active_tab, window); } /* Close all tabs */ static void file_close_all (XedWindow *window, - gboolean is_quitting) + gboolean is_quitting) { - GList *unsaved_docs; - GtkWidget *dlg; + GList *unsaved_docs; + GtkWidget *dlg; - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - g_return_if_fail (!(xed_window_get_state (window) & - (XED_WINDOW_STATE_SAVING | - XED_WINDOW_STATE_PRINTING | - XED_WINDOW_STATE_SAVING_SESSION))); + g_return_if_fail (!(xed_window_get_state (window) & + (XED_WINDOW_STATE_SAVING | + XED_WINDOW_STATE_PRINTING | + XED_WINDOW_STATE_SAVING_SESSION))); - g_object_set_data (G_OBJECT (window), - XED_IS_CLOSING_ALL, - GBOOLEAN_TO_POINTER (TRUE)); + g_object_set_data (G_OBJECT (window), XED_IS_CLOSING_ALL, GBOOLEAN_TO_POINTER (TRUE)); + g_object_set_data (G_OBJECT (window), XED_IS_QUITTING, GBOOLEAN_TO_POINTER (is_quitting)); - g_object_set_data (G_OBJECT (window), - XED_IS_QUITTING, - GBOOLEAN_TO_POINTER (is_quitting)); - - unsaved_docs = xed_window_get_unsaved_documents (window); + unsaved_docs = xed_window_get_unsaved_documents (window); - if (unsaved_docs == NULL) - { - /* There is no document to save -> close all tabs */ - xed_window_close_all_tabs (window); + if (unsaved_docs == NULL) + { + /* There is no document to save -> close all tabs */ + xed_window_close_all_tabs (window); - if (is_quitting) - gtk_widget_destroy (GTK_WIDGET (window)); + if (is_quitting) + { + gtk_widget_destroy (GTK_WIDGET (window)); + } - return; - } + return; + } - if (unsaved_docs->next == NULL) - { - /* There is only one unsaved document */ - XedTab *tab; - XedDocument *doc; + if (unsaved_docs->next == NULL) + { + /* There is only one unsaved document */ + XedTab *tab; + XedDocument *doc; - doc = XED_DOCUMENT (unsaved_docs->data); + doc = XED_DOCUMENT (unsaved_docs->data); - tab = xed_tab_get_from_document (doc); - g_return_if_fail (tab != NULL); + tab = xed_tab_get_from_document (doc); + g_return_if_fail (tab != NULL); - xed_window_set_active_tab (window, tab); + xed_window_set_active_tab (window, tab); - dlg = xed_close_confirmation_dialog_new_single ( - GTK_WINDOW (window), - doc, - FALSE); - } - else - { - dlg = xed_close_confirmation_dialog_new (GTK_WINDOW (window), - unsaved_docs, - FALSE); - } + dlg = xed_close_confirmation_dialog_new_single (GTK_WINDOW (window), doc, FALSE); + } + else + { + dlg = xed_close_confirmation_dialog_new (GTK_WINDOW (window), unsaved_docs, FALSE); + } - g_list_free (unsaved_docs); + g_list_free (unsaved_docs); - g_signal_connect (dlg, - "response", - G_CALLBACK (close_confirmation_dialog_response_handler), - window); + g_signal_connect (dlg, "response", + G_CALLBACK (close_confirmation_dialog_response_handler), window); - gtk_widget_show (dlg); + gtk_widget_show (dlg); } void _xed_cmd_file_close_all (GtkAction *action, - XedWindow *window) + XedWindow *window) { - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - g_return_if_fail (!(xed_window_get_state (window) & - (XED_WINDOW_STATE_SAVING | - XED_WINDOW_STATE_PRINTING | - XED_WINDOW_STATE_SAVING_SESSION))); + g_return_if_fail (!(xed_window_get_state (window) & + (XED_WINDOW_STATE_SAVING | + XED_WINDOW_STATE_PRINTING | + XED_WINDOW_STATE_SAVING_SESSION))); - file_close_all (window, FALSE); + file_close_all (window, FALSE); } void -_xed_cmd_file_quit (GtkAction *action, - XedWindow *window) +_xed_cmd_file_quit (GtkAction *action, + XedWindow *window) { - xed_debug (DEBUG_COMMANDS); + xed_debug (DEBUG_COMMANDS); - g_return_if_fail (!(xed_window_get_state (window) & - (XED_WINDOW_STATE_SAVING | - XED_WINDOW_STATE_PRINTING | - XED_WINDOW_STATE_SAVING_SESSION))); + g_return_if_fail (!(xed_window_get_state (window) & + (XED_WINDOW_STATE_SAVING | + XED_WINDOW_STATE_PRINTING | + XED_WINDOW_STATE_SAVING_SESSION))); - file_close_all (window, TRUE); + file_close_all (window, TRUE); } From 7417c54a94f3b8a192c6d15bdf31b39d94aa41c1 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 11 Dec 2016 23:01:51 -0800 Subject: [PATCH 007/132] xed-commands-file: Clean up deprecations --- xed/xed-commands-file.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/xed/xed-commands-file.c b/xed/xed-commands-file.c index ee0af0f..8fb1d69 100644 --- a/xed/xed-commands-file.c +++ b/xed/xed-commands-file.c @@ -461,8 +461,8 @@ _xed_cmd_file_open (GtkAction *action, GTK_WINDOW (window), GTK_FILE_CHOOSER_ACTION_OPEN, NULL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_OK, + _("_Cancel"), GTK_RESPONSE_CANCEL, + _("_Open"), GTK_RESPONSE_OK, NULL); g_object_set_data (G_OBJECT (window), XED_OPEN_DIALOG_KEY, open_dialog); @@ -569,9 +569,8 @@ replace_read_only_file (GtkWindow *parent, _("Do you want to try to replace it " "with the one you are saving?")); - gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - - xed_dialog_add_button (GTK_DIALOG (dialog), _("_Replace"), GTK_STOCK_SAVE_AS, GTK_RESPONSE_YES); + gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Cancel"), GTK_RESPONSE_CANCEL); + gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Replace"), GTK_RESPONSE_YES); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL); @@ -736,8 +735,8 @@ file_save_as (XedTab *tab, GTK_WINDOW (window), GTK_FILE_CHOOSER_ACTION_SAVE, NULL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_OK, + _("_Cancel"), GTK_RESPONSE_CANCEL, + _("_Save"), GTK_RESPONSE_OK, NULL); gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (save_dialog), TRUE); @@ -1177,10 +1176,8 @@ revert_dialog (XedWindow *window, gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); - gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - - xed_dialog_add_button (GTK_DIALOG (dialog), _("_Revert"), GTK_STOCK_REVERT_TO_SAVED, GTK_RESPONSE_OK); - + gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Cancel"), GTK_RESPONSE_CANCEL); + gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Revert"), GTK_RESPONSE_OK); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL); return dialog; From fb84d4bfc7431eff6cdab31fb1de89d1ce99b221 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 11 Dec 2016 23:16:13 -0800 Subject: [PATCH 008/132] xed-app: Clean up code styling --- xed/xed-app.c | 848 +++++++++++++++++++++++++------------------------- 1 file changed, 429 insertions(+), 419 deletions(-) diff --git a/xed/xed-app.c b/xed/xed-app.c index 25d4673..9393036 100644 --- a/xed/xed-app.c +++ b/xed/xed-app.c @@ -46,23 +46,23 @@ #include "xed-enum-types.h" #include "xed-dirs.h" -#define XED_PAGE_SETUP_FILE "xed-page-setup" -#define XED_PRINT_SETTINGS_FILE "xed-print-settings" +#define XED_PAGE_SETUP_FILE "xed-page-setup" +#define XED_PRINT_SETTINGS_FILE "xed-print-settings" #define XED_APP_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_APP, XedAppPrivate)) /* Properties */ enum { - PROP_0, + PROP_0, }; struct _XedAppPrivate { - GList *windows; - XedWindow *active_window; - GtkPageSetup *page_setup; - GtkPrintSettings *print_settings; + GList *windows; + XedWindow *active_window; + GtkPageSetup *page_setup; + GtkPrintSettings *print_settings; }; G_DEFINE_TYPE(XedApp, xed_app, G_TYPE_OBJECT) @@ -70,258 +70,259 @@ G_DEFINE_TYPE(XedApp, xed_app, G_TYPE_OBJECT) static void xed_app_finalize (GObject *object) { - XedApp *app = XED_APP (object); + XedApp *app = XED_APP (object); - g_list_free (app->priv->windows); + g_list_free (app->priv->windows); - if (app->priv->page_setup) - g_object_unref (app->priv->page_setup); - if (app->priv->print_settings) - g_object_unref (app->priv->print_settings); + if (app->priv->page_setup) + { + g_object_unref (app->priv->page_setup); + } - G_OBJECT_CLASS (xed_app_parent_class)->finalize (object); + if (app->priv->print_settings) + { + g_object_unref (app->priv->print_settings); + } + + G_OBJECT_CLASS (xed_app_parent_class)->finalize (object); } static void xed_app_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - XedApp *app = XED_APP (object); + XedApp *app = XED_APP (object); - switch (prop_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_app_class_init (XedAppClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = xed_app_finalize; - object_class->get_property = xed_app_get_property; + object_class->finalize = xed_app_finalize; + object_class->get_property = xed_app_get_property; - g_type_class_add_private (object_class, sizeof(XedAppPrivate)); + g_type_class_add_private (object_class, sizeof(XedAppPrivate)); } static gboolean ensure_user_config_dir (void) { - gchar *config_dir; - gboolean ret = TRUE; - gint res; + gchar *config_dir; + gboolean ret = TRUE; + gint res; - config_dir = xed_dirs_get_user_config_dir (); - if (config_dir == NULL) - { - g_warning ("Could not get config directory\n"); - return FALSE; - } + config_dir = xed_dirs_get_user_config_dir (); + if (config_dir == NULL) + { + g_warning ("Could not get config directory\n"); + return FALSE; + } - res = g_mkdir_with_parents (config_dir, 0755); - if (res < 0) - { - g_warning ("Could not create config directory\n"); - ret = FALSE; - } + res = g_mkdir_with_parents (config_dir, 0755); + if (res < 0) + { + g_warning ("Could not create config directory\n"); + ret = FALSE; + } - g_free (config_dir); + g_free (config_dir); - return ret; + return ret; } static void load_accels (void) { - gchar *filename; + gchar *filename; - filename = xed_dirs_get_user_accels_file (); - if (filename != NULL) - { - xed_debug_message (DEBUG_APP, "Loading keybindings from %s\n", filename); - gtk_accel_map_load (filename); - g_free (filename); - } + filename = xed_dirs_get_user_accels_file (); + if (filename != NULL) + { + xed_debug_message (DEBUG_APP, "Loading keybindings from %s\n", filename); + gtk_accel_map_load (filename); + g_free (filename); + } } static void save_accels (void) { - gchar *filename; + gchar *filename; - filename = xed_dirs_get_user_accels_file (); - if (filename != NULL) - { - xed_debug_message (DEBUG_APP, "Saving keybindings in %s\n", filename); - gtk_accel_map_save (filename); - g_free (filename); - } + filename = xed_dirs_get_user_accels_file (); + if (filename != NULL) + { + xed_debug_message (DEBUG_APP, "Saving keybindings in %s\n", filename); + gtk_accel_map_save (filename); + g_free (filename); + } } static gchar * get_page_setup_file (void) { - gchar *config_dir; - gchar *setup = NULL; + gchar *config_dir; + gchar *setup = NULL; - config_dir = xed_dirs_get_user_config_dir (); + config_dir = xed_dirs_get_user_config_dir (); - if (config_dir != NULL) - { - setup = g_build_filename (config_dir, - XED_PAGE_SETUP_FILE, - NULL); - g_free (config_dir); - } + if (config_dir != NULL) + { + setup = g_build_filename (config_dir, XED_PAGE_SETUP_FILE, NULL); + g_free (config_dir); + } - return setup; + return setup; } static void load_page_setup (XedApp *app) { - gchar *filename; - GError *error = NULL; + gchar *filename; + GError *error = NULL; - g_return_if_fail (app->priv->page_setup == NULL); + g_return_if_fail (app->priv->page_setup == NULL); - filename = get_page_setup_file (); + filename = get_page_setup_file (); - app->priv->page_setup = gtk_page_setup_new_from_file (filename, - &error); - if (error) - { - /* Ignore file not found error */ - if (error->domain != G_FILE_ERROR || - error->code != G_FILE_ERROR_NOENT) - { - g_warning ("%s", error->message); - } + app->priv->page_setup = gtk_page_setup_new_from_file (filename, &error); + if (error) + { + /* Ignore file not found error */ + if (error->domain != G_FILE_ERROR || error->code != G_FILE_ERROR_NOENT) + { + g_warning ("%s", error->message); + } - g_error_free (error); - } + g_error_free (error); + } - g_free (filename); + g_free (filename); - /* fall back to default settings */ - if (app->priv->page_setup == NULL) - app->priv->page_setup = gtk_page_setup_new (); + /* fall back to default settings */ + if (app->priv->page_setup == NULL) + { + app->priv->page_setup = gtk_page_setup_new (); + } } static void save_page_setup (XedApp *app) { - gchar *filename; - GError *error = NULL; + gchar *filename; + GError *error = NULL; - if (app->priv->page_setup == NULL) - return; + if (app->priv->page_setup == NULL) + { + return; + } - filename = get_page_setup_file (); + filename = get_page_setup_file (); - gtk_page_setup_to_file (app->priv->page_setup, - filename, - &error); - if (error) - { - g_warning ("%s", error->message); - g_error_free (error); - } + gtk_page_setup_to_file (app->priv->page_setup, filename, &error); + if (error) + { + g_warning ("%s", error->message); + g_error_free (error); + } - g_free (filename); + g_free (filename); } static gchar * get_print_settings_file (void) { - gchar *config_dir; - gchar *settings = NULL; + gchar *config_dir; + gchar *settings = NULL; - config_dir = xed_dirs_get_user_config_dir (); + config_dir = xed_dirs_get_user_config_dir (); - if (config_dir != NULL) - { - settings = g_build_filename (config_dir, - XED_PRINT_SETTINGS_FILE, - NULL); - g_free (config_dir); - } + if (config_dir != NULL) + { + settings = g_build_filename (config_dir, XED_PRINT_SETTINGS_FILE, NULL); + g_free (config_dir); + } - return settings; + return settings; } static void load_print_settings (XedApp *app) { - gchar *filename; - GError *error = NULL; + gchar *filename; + GError *error = NULL; - g_return_if_fail (app->priv->print_settings == NULL); + g_return_if_fail (app->priv->print_settings == NULL); - filename = get_print_settings_file (); + filename = get_print_settings_file (); - app->priv->print_settings = gtk_print_settings_new_from_file (filename, - &error); - if (error) - { - /* Ignore file not found error */ - if (error->domain != G_FILE_ERROR || - error->code != G_FILE_ERROR_NOENT) - { - g_warning ("%s", error->message); - } + app->priv->print_settings = gtk_print_settings_new_from_file (filename, &error); + if (error) + { + /* Ignore file not found error */ + if (error->domain != G_FILE_ERROR || error->code != G_FILE_ERROR_NOENT) + { + g_warning ("%s", error->message); + } - g_error_free (error); - } + g_error_free (error); + } - g_free (filename); + g_free (filename); - /* fall back to default settings */ - if (app->priv->print_settings == NULL) - app->priv->print_settings = gtk_print_settings_new (); + /* fall back to default settings */ + if (app->priv->print_settings == NULL) + { + app->priv->print_settings = gtk_print_settings_new (); + } } static void save_print_settings (XedApp *app) { - gchar *filename; - GError *error = NULL; + gchar *filename; + GError *error = NULL; - if (app->priv->print_settings == NULL) - return; + if (app->priv->print_settings == NULL) + { + return; + } - filename = get_print_settings_file (); + filename = get_print_settings_file (); - gtk_print_settings_to_file (app->priv->print_settings, - filename, - &error); - if (error) - { - g_warning ("%s", error->message); - g_error_free (error); - } + gtk_print_settings_to_file (app->priv->print_settings, filename, &error); + if (error) + { + g_warning ("%s", error->message); + g_error_free (error); + } - g_free (filename); + g_free (filename); } static void xed_app_init (XedApp *app) { - app->priv = XED_APP_GET_PRIVATE (app); + app->priv = XED_APP_GET_PRIVATE (app); - load_accels (); + load_accels (); } static void app_weak_notify (gpointer data, - GObject *where_the_app_was) + GObject *where_the_app_was) { - gtk_main_quit (); + gtk_main_quit (); } /** @@ -335,197 +336,190 @@ app_weak_notify (gpointer data, XedApp * xed_app_get_default (void) { - static XedApp *app = NULL; + static XedApp *app = NULL; - if (app != NULL) - return app; + if (app != NULL) + return app; - app = XED_APP (g_object_new (XED_TYPE_APP, NULL)); + app = XED_APP (g_object_new (XED_TYPE_APP, NULL)); - g_object_add_weak_pointer (G_OBJECT (app), - (gpointer) &app); - g_object_weak_ref (G_OBJECT (app), - app_weak_notify, - NULL); + g_object_add_weak_pointer (G_OBJECT (app), (gpointer) &app); + g_object_weak_ref (G_OBJECT (app), app_weak_notify, NULL); - return app; + return app; } static void set_active_window (XedApp *app, XedWindow *window) { - app->priv->active_window = window; + app->priv->active_window = window; } static gboolean -window_focus_in_event (XedWindow *window, - GdkEventFocus *event, - XedApp *app) +window_focus_in_event (XedWindow *window, + GdkEventFocus *event, + XedApp *app) { - /* updates active_view and active_child when a new toplevel receives focus */ - g_return_val_if_fail (XED_IS_WINDOW (window), FALSE); + /* updates active_view and active_child when a new toplevel receives focus */ + g_return_val_if_fail (XED_IS_WINDOW (window), FALSE); - set_active_window (app, window); + set_active_window (app, window); - return FALSE; + return FALSE; } static gboolean window_delete_event (XedWindow *window, - GdkEvent *event, + GdkEvent *event, XedApp *app) { - XedWindowState ws; + XedWindowState ws; - ws = xed_window_get_state (window); + ws = xed_window_get_state (window); - if (ws & - (XED_WINDOW_STATE_SAVING | - XED_WINDOW_STATE_PRINTING | - XED_WINDOW_STATE_SAVING_SESSION)) - return TRUE; + if (ws & + (XED_WINDOW_STATE_SAVING | + XED_WINDOW_STATE_PRINTING | + XED_WINDOW_STATE_SAVING_SESSION)) + { + return TRUE; + } - _xed_cmd_file_quit (NULL, window); + _xed_cmd_file_quit (NULL, window); - /* Do not destroy the window */ - return TRUE; + /* Do not destroy the window */ + return TRUE; } static void window_destroy (XedWindow *window, - XedApp *app) + XedApp *app) { - app->priv->windows = g_list_remove (app->priv->windows, - window); + app->priv->windows = g_list_remove (app->priv->windows, + window); - if (window == app->priv->active_window) - { - set_active_window (app, app->priv->windows != NULL ? app->priv->windows->data : NULL); - } + if (window == app->priv->active_window) + { + set_active_window (app, app->priv->windows != NULL ? app->priv->windows->data : NULL); + } /* CHECK: I don't think we have to disconnect this function, since windows is being destroyed */ /* - g_signal_handlers_disconnect_by_func (window, - G_CALLBACK (window_focus_in_event), - app); - g_signal_handlers_disconnect_by_func (window, - G_CALLBACK (window_destroy), - app); + g_signal_handlers_disconnect_by_func (window, + G_CALLBACK (window_focus_in_event), + app); + g_signal_handlers_disconnect_by_func (window, + G_CALLBACK (window_destroy), + app); */ - if (app->priv->windows == NULL) - { - /* Last window is gone... save some settings and exit */ - ensure_user_config_dir (); + if (app->priv->windows == NULL) + { + /* Last window is gone... save some settings and exit */ + ensure_user_config_dir (); - save_accels (); - save_page_setup (app); - save_print_settings (app); + save_accels (); + save_page_setup (app); + save_print_settings (app); - g_object_unref (app); - } + g_object_unref (app); + } } /* Generates a unique string for a window role */ static gchar * gen_role (void) { - GTimeVal result; - static gint serial; + GTimeVal result; + static gint serial; - g_get_current_time (&result); + g_get_current_time (&result); - return g_strdup_printf ("xed-window-%ld-%ld-%d-%s", - result.tv_sec, - result.tv_usec, - serial++, - g_get_host_name ()); + return g_strdup_printf ("xed-window-%ld-%ld-%d-%s", + result.tv_sec, + result.tv_usec, + serial++, + g_get_host_name ()); } static XedWindow * -xed_app_create_window_real (XedApp *app, - gboolean set_geometry, - const gchar *role) +xed_app_create_window_real (XedApp *app, + gboolean set_geometry, + const gchar *role) { - XedWindow *window; + XedWindow *window; - xed_debug (DEBUG_APP); + xed_debug (DEBUG_APP); - /* - * We need to be careful here, there is a race condition: - * when another xed is launched it checks active_window, - * so we must do our best to ensure that active_window - * is never NULL when at least a window exists. - */ - if (app->priv->windows == NULL) - { - window = g_object_new (XED_TYPE_WINDOW, NULL); - set_active_window (app, window); - } - else - { - window = g_object_new (XED_TYPE_WINDOW, NULL); - } + /* + * We need to be careful here, there is a race condition: + * when another xed is launched it checks active_window, + * so we must do our best to ensure that active_window + * is never NULL when at least a window exists. + */ + if (app->priv->windows == NULL) + { + window = g_object_new (XED_TYPE_WINDOW, NULL); + set_active_window (app, window); + } + else + { + window = g_object_new (XED_TYPE_WINDOW, NULL); + } - app->priv->windows = g_list_prepend (app->priv->windows, - window); + app->priv->windows = g_list_prepend (app->priv->windows, window); - xed_debug_message (DEBUG_APP, "Window created"); + xed_debug_message (DEBUG_APP, "Window created"); - if (role != NULL) - { - gtk_window_set_role (GTK_WINDOW (window), role); - } - else - { - gchar *newrole; + if (role != NULL) + { + gtk_window_set_role (GTK_WINDOW (window), role); + } + else + { + gchar *newrole; - newrole = gen_role (); - gtk_window_set_role (GTK_WINDOW (window), newrole); - g_free (newrole); - } + newrole = gen_role (); + gtk_window_set_role (GTK_WINDOW (window), newrole); + g_free (newrole); + } - if (set_geometry) - { - GdkWindowState state; - gint w, h; + if (set_geometry) + { + GdkWindowState state; + gint w, h; - state = xed_prefs_manager_get_window_state (); + state = xed_prefs_manager_get_window_state (); - if ((state & GDK_WINDOW_STATE_MAXIMIZED) != 0) - { - xed_prefs_manager_get_default_window_size (&w, &h); - gtk_window_set_default_size (GTK_WINDOW (window), w, h); - gtk_window_maximize (GTK_WINDOW (window)); - } - else - { - xed_prefs_manager_get_window_size (&w, &h); - gtk_window_set_default_size (GTK_WINDOW (window), w, h); - gtk_window_unmaximize (GTK_WINDOW (window)); - } + if ((state & GDK_WINDOW_STATE_MAXIMIZED) != 0) + { + xed_prefs_manager_get_default_window_size (&w, &h); + gtk_window_set_default_size (GTK_WINDOW (window), w, h); + gtk_window_maximize (GTK_WINDOW (window)); + } + else + { + xed_prefs_manager_get_window_size (&w, &h); + gtk_window_set_default_size (GTK_WINDOW (window), w, h); + gtk_window_unmaximize (GTK_WINDOW (window)); + } - if ((state & GDK_WINDOW_STATE_STICKY ) != 0) - gtk_window_stick (GTK_WINDOW (window)); - else - gtk_window_unstick (GTK_WINDOW (window)); - } + if ((state & GDK_WINDOW_STATE_STICKY ) != 0) + { + gtk_window_stick (GTK_WINDOW (window)); + } + else + { + gtk_window_unstick (GTK_WINDOW (window)); + } + } - g_signal_connect (window, - "focus_in_event", - G_CALLBACK (window_focus_in_event), - app); - g_signal_connect (window, - "delete_event", - G_CALLBACK (window_delete_event), - app); - g_signal_connect (window, - "destroy", - G_CALLBACK (window_destroy), - app); + g_signal_connect (window, "focus_in_event", G_CALLBACK (window_focus_in_event), app); + g_signal_connect (window, "delete_event", G_CALLBACK (window_delete_event), app); + g_signal_connect (window, "destroy", G_CALLBACK (window_destroy), app); - return window; + return window; } /** @@ -538,17 +532,19 @@ xed_app_create_window_real (XedApp *app, * Return value: the new #XedWindow */ XedWindow * -xed_app_create_window (XedApp *app, - GdkScreen *screen) +xed_app_create_window (XedApp *app, + GdkScreen *screen) { - XedWindow *window; + XedWindow *window; - window = xed_app_create_window_real (app, TRUE, NULL); + window = xed_app_create_window_real (app, TRUE, NULL); - if (screen != NULL) - gtk_window_set_screen (GTK_WINDOW (window), screen); + if (screen != NULL) + { + gtk_window_set_screen (GTK_WINDOW (window), screen); + } - return window; + return window; } /* @@ -556,14 +552,14 @@ xed_app_create_window (XedApp *app, * The session manager takes care of it. Used in mate-session. */ XedWindow * -_xed_app_restore_window (XedApp *app, - const gchar *role) +_xed_app_restore_window (XedApp *app, + const gchar *role) { - XedWindow *window; + XedWindow *window; - window = xed_app_create_window_real (app, FALSE, role); + window = xed_app_create_window_real (app, FALSE, role); - return window; + return window; } /** @@ -578,9 +574,9 @@ _xed_app_restore_window (XedApp *app, const GList * xed_app_get_windows (XedApp *app) { - g_return_val_if_fail (XED_IS_APP (app), NULL); + g_return_val_if_fail (XED_IS_APP (app), NULL); - return app->priv->windows; + return app->priv->windows; } /** @@ -594,74 +590,80 @@ xed_app_get_windows (XedApp *app) XedWindow * xed_app_get_active_window (XedApp *app) { - g_return_val_if_fail (XED_IS_APP (app), NULL); + g_return_val_if_fail (XED_IS_APP (app), NULL); - /* make sure our active window is always realized: - * this is needed on startup if we launch two xed fast - * enough that the second instance comes up before the - * first one shows its window. - */ - if (!gtk_widget_get_realized (GTK_WIDGET (app->priv->active_window))) - gtk_widget_realize (GTK_WIDGET (app->priv->active_window)); + /* make sure our active window is always realized: + * this is needed on startup if we launch two xed fast + * enough that the second instance comes up before the + * first one shows its window. + */ + if (!gtk_widget_get_realized (GTK_WIDGET (app->priv->active_window))) + { + gtk_widget_realize (GTK_WIDGET (app->priv->active_window)); + } - return app->priv->active_window; + return app->priv->active_window; } static gboolean -is_in_viewport (XedWindow *window, - GdkScreen *screen, - gint workspace, - gint viewport_x, - gint viewport_y) +is_in_viewport (XedWindow *window, + GdkScreen *screen, + gint workspace, + gint viewport_x, + gint viewport_y) { - GdkScreen *s; - GdkDisplay *display; - GdkWindow *gdkwindow; - const gchar *cur_name; - const gchar *name; - gint cur_n; - gint n; - gint ws; - gint sc_width, sc_height; - gint x, y, width, height; - gint vp_x, vp_y; + GdkScreen *s; + GdkDisplay *display; + GdkWindow *gdkwindow; + const gchar *cur_name; + const gchar *name; + gint cur_n; + gint n; + gint ws; + gint sc_width, sc_height; + gint x, y, width, height; + gint vp_x, vp_y; - /* Check for screen and display match */ - display = gdk_screen_get_display (screen); - cur_name = gdk_display_get_name (display); - cur_n = gdk_screen_get_number (screen); + /* Check for screen and display match */ + display = gdk_screen_get_display (screen); + cur_name = gdk_display_get_name (display); + cur_n = gdk_screen_get_number (screen); - s = gtk_window_get_screen (GTK_WINDOW (window)); - display = gdk_screen_get_display (s); - name = gdk_display_get_name (display); - n = gdk_screen_get_number (s); + s = gtk_window_get_screen (GTK_WINDOW (window)); + display = gdk_screen_get_display (s); + name = gdk_display_get_name (display); + n = gdk_screen_get_number (s); - if (strcmp (cur_name, name) != 0 || cur_n != n) - return FALSE; + if (strcmp (cur_name, name) != 0 || cur_n != n) + { + return FALSE; + } - /* Check for workspace match */ - ws = xed_utils_get_window_workspace (GTK_WINDOW (window)); - if (ws != workspace && ws != XED_ALL_WORKSPACES) - return FALSE; + /* Check for workspace match */ + ws = xed_utils_get_window_workspace (GTK_WINDOW (window)); + if (ws != workspace && ws != XED_ALL_WORKSPACES) + { + return FALSE; + } - /* Check for viewport match */ - gdkwindow = gtk_widget_get_window (GTK_WIDGET (window)); - gdk_window_get_position (gdkwindow, &x, &y); + /* Check for viewport match */ + gdkwindow = gtk_widget_get_window (GTK_WIDGET (window)); + gdk_window_get_position (gdkwindow, &x, &y); - width = gdk_window_get_width(gdkwindow); - height = gdk_window_get_height(gdkwindow); + width = gdk_window_get_width (gdkwindow); + height = gdk_window_get_height (gdkwindow); - xed_utils_get_current_viewport (screen, &vp_x, &vp_y); - x += vp_x; - y += vp_y; + xed_utils_get_current_viewport (screen, &vp_x, &vp_y); + x += vp_x; + y += vp_y; - sc_width = gdk_screen_get_width (screen); - sc_height = gdk_screen_get_height (screen); + sc_width = gdk_screen_get_width (screen); + sc_height = gdk_screen_get_height (screen); - return x + width * .25 >= viewport_x && - x + width * .75 <= viewport_x + sc_width && - y >= viewport_y && - y + height <= viewport_y + sc_height; + return x + width * .25 >= viewport_x && + x + width * .75 <= viewport_x + sc_width && + y >= viewport_y && + y + height <= viewport_y + sc_height; } /** @@ -679,37 +681,41 @@ is_in_viewport (XedWindow *window, * Return value: the #XedWindow in the given viewport of the given workspace. */ XedWindow * -_xed_app_get_window_in_viewport (XedApp *app, - GdkScreen *screen, - gint workspace, - gint viewport_x, - gint viewport_y) +_xed_app_get_window_in_viewport (XedApp *app, + GdkScreen *screen, + gint workspace, + gint viewport_x, + gint viewport_y) { - XedWindow *window; + XedWindow *window; - GList *l; + GList *l; - g_return_val_if_fail (XED_IS_APP (app), NULL); + g_return_val_if_fail (XED_IS_APP (app), NULL); - /* first try if the active window */ - window = app->priv->active_window; + /* first try if the active window */ + window = app->priv->active_window; - g_return_val_if_fail (XED_IS_WINDOW (window), NULL); + g_return_val_if_fail (XED_IS_WINDOW (window), NULL); - if (is_in_viewport (window, screen, workspace, viewport_x, viewport_y)) - return window; + if (is_in_viewport (window, screen, workspace, viewport_x, viewport_y)) + { + return window; + } - /* otherwise try to see if there is a window on this workspace */ - for (l = app->priv->windows; l != NULL; l = l->next) - { - window = l->data; + /* otherwise try to see if there is a window on this workspace */ + for (l = app->priv->windows; l != NULL; l = l->next) + { + window = l->data; - if (is_in_viewport (window, screen, workspace, viewport_x, viewport_y)) - return window; - } + if (is_in_viewport (window, screen, workspace, viewport_x, viewport_y)) + { + return window; + } + } - /* no window on this workspace... create a new one */ - return xed_app_create_window (app, screen); + /* no window on this workspace... create a new one */ + return xed_app_create_window (app, screen); } /** @@ -722,24 +728,22 @@ _xed_app_get_window_in_viewport (XedApp *app, * a newly allocated list of #XedDocument objects */ GList * -xed_app_get_documents (XedApp *app) +xed_app_get_documents (XedApp *app) { - GList *res = NULL; - GList *windows; + GList *res = NULL; + GList *windows; - g_return_val_if_fail (XED_IS_APP (app), NULL); + g_return_val_if_fail (XED_IS_APP (app), NULL); - windows = app->priv->windows; + windows = app->priv->windows; - while (windows != NULL) - { - res = g_list_concat (res, - xed_window_get_documents (XED_WINDOW (windows->data))); + while (windows != NULL) + { + res = g_list_concat (res, xed_window_get_documents (XED_WINDOW (windows->data))); + windows = g_list_next (windows); + } - windows = g_list_next (windows); - } - - return res; + return res; } /** @@ -754,71 +758,77 @@ xed_app_get_documents (XedApp *app) GList * xed_app_get_views (XedApp *app) { - GList *res = NULL; - GList *windows; + GList *res = NULL; + GList *windows; - g_return_val_if_fail (XED_IS_APP (app), NULL); + g_return_val_if_fail (XED_IS_APP (app), NULL); - windows = app->priv->windows; + windows = app->priv->windows; - while (windows != NULL) - { - res = g_list_concat (res, - xed_window_get_views (XED_WINDOW (windows->data))); + while (windows != NULL) + { + res = g_list_concat (res, xed_window_get_views (XED_WINDOW (windows->data))); + windows = g_list_next (windows); + } - windows = g_list_next (windows); - } - - return res; + return res; } /* Returns a copy */ GtkPageSetup * _xed_app_get_default_page_setup (XedApp *app) { - g_return_val_if_fail (XED_IS_APP (app), NULL); + g_return_val_if_fail (XED_IS_APP (app), NULL); - if (app->priv->page_setup == NULL) - load_page_setup (app); + if (app->priv->page_setup == NULL) + { + load_page_setup (app); + } - return gtk_page_setup_copy (app->priv->page_setup); + return gtk_page_setup_copy (app->priv->page_setup); } void -_xed_app_set_default_page_setup (XedApp *app, - GtkPageSetup *page_setup) +_xed_app_set_default_page_setup (XedApp *app, + GtkPageSetup *page_setup) { - g_return_if_fail (XED_IS_APP (app)); - g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup)); + g_return_if_fail (XED_IS_APP (app)); + g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup)); - if (app->priv->page_setup != NULL) - g_object_unref (app->priv->page_setup); + if (app->priv->page_setup != NULL) + { + g_object_unref (app->priv->page_setup); + } - app->priv->page_setup = g_object_ref (page_setup); + app->priv->page_setup = g_object_ref (page_setup); } /* Returns a copy */ GtkPrintSettings * _xed_app_get_default_print_settings (XedApp *app) { - g_return_val_if_fail (XED_IS_APP (app), NULL); + g_return_val_if_fail (XED_IS_APP (app), NULL); - if (app->priv->print_settings == NULL) - load_print_settings (app); + if (app->priv->print_settings == NULL) + { + load_print_settings (app); + } - return gtk_print_settings_copy (app->priv->print_settings); + return gtk_print_settings_copy (app->priv->print_settings); } void -_xed_app_set_default_print_settings (XedApp *app, - GtkPrintSettings *settings) +_xed_app_set_default_print_settings (XedApp *app, + GtkPrintSettings *settings) { - g_return_if_fail (XED_IS_APP (app)); - g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings)); + g_return_if_fail (XED_IS_APP (app)); + g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings)); - if (app->priv->print_settings != NULL) - g_object_unref (app->priv->print_settings); + if (app->priv->print_settings != NULL) + { + g_object_unref (app->priv->print_settings); + } - app->priv->print_settings = g_object_ref (settings); + app->priv->print_settings = g_object_ref (settings); } From 2a93bcbb6d25743399b9d1dfb33a14da58d9de02 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 11 Dec 2016 23:19:19 -0800 Subject: [PATCH 009/132] xed-app: Remove an unused variable --- xed/xed-app.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/xed/xed-app.c b/xed/xed-app.c index 9393036..867ea89 100644 --- a/xed/xed-app.c +++ b/xed/xed-app.c @@ -93,8 +93,6 @@ xed_app_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - XedApp *app = XED_APP (object); - switch (prop_id) { default: From ee841c10156d2a488f128c2336d3e630d7c2ea6e Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 11 Dec 2016 23:43:52 -0800 Subject: [PATCH 010/132] xed-commands-search: Fix some missing casts --- xed/xed-commands-search.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xed/xed-commands-search.c b/xed/xed-commands-search.c index 6435389..9050525 100644 --- a/xed/xed-commands-search.c +++ b/xed/xed-commands-search.c @@ -17,14 +17,14 @@ void _xed_cmd_search_find (GtkAction *action, XedWindow *window) { - xed_searchbar_show (xed_window_get_searchbar (window), FALSE); + xed_searchbar_show (XED_SEARCHBAR (xed_window_get_searchbar (window)), FALSE); } void _xed_cmd_search_replace (GtkAction *action, XedWindow *window) { - xed_searchbar_show (xed_window_get_searchbar (window), TRUE); + xed_searchbar_show (XED_SEARCHBAR (xed_window_get_searchbar (window)), TRUE); } void @@ -32,7 +32,7 @@ _xed_cmd_search_find_next (GtkAction *action, XedWindow *window) { xed_debug (DEBUG_COMMANDS); - xed_searchbar_find_again (xed_window_get_searchbar (window), FALSE); + xed_searchbar_find_again (XED_SEARCHBAR (xed_window_get_searchbar (window)), FALSE); } void @@ -40,7 +40,7 @@ _xed_cmd_search_find_prev (GtkAction *action, XedWindow *window) { xed_debug (DEBUG_COMMANDS); - xed_searchbar_find_again (xed_window_get_searchbar (window), TRUE); + xed_searchbar_find_again (XED_SEARCHBAR (xed_window_get_searchbar (window)), TRUE); } void From 3aa6f847d9071504204a5424ce8095f9cd05775e Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 12 Dec 2016 01:30:18 -0800 Subject: [PATCH 011/132] xed-document: Clean up code style --- xed/xed-document.c | 3641 ++++++++++++++++++++++---------------------- 1 file changed, 1791 insertions(+), 1850 deletions(-) diff --git a/xed/xed-document.c b/xed/xed-document.c index d559e79..05c2da6 100644 --- a/xed/xed-document.c +++ b/xed/xed-document.c @@ -3,8 +3,8 @@ * This file is part of xed * * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence - * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi - * Copyright (C) 2002-2005 Paolo Maggi + * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi + * Copyright (C) 2002-2005 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,14 +18,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 1998-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 1998-2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -59,7 +59,7 @@ #define METADATA_QUERY "metadata::*" #endif -#undef ENABLE_PROFILE +#undef ENABLE_PROFILE #ifdef ENABLE_PROFILE #define PROFILE(x) x @@ -79,97 +79,99 @@ PROFILE (static GTimer *timer = NULL) #define XED_DOCUMENT_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_DOCUMENT, XedDocumentPrivate)) -static void xed_document_load_real (XedDocument *doc, - const gchar *uri, - const XedEncoding *encoding, - gint line_pos, - gboolean create); -static void xed_document_save_real (XedDocument *doc, - const gchar *uri, - const XedEncoding *encoding, - XedDocumentSaveFlags flags); -static void to_search_region_range (XedDocument *doc, - GtkTextIter *start, - GtkTextIter *end); -static void insert_text_cb (XedDocument *doc, - GtkTextIter *pos, - const gchar *text, - gint length); - -static void delete_range_cb (XedDocument *doc, - GtkTextIter *start, - GtkTextIter *end); - +static void xed_document_load_real (XedDocument *doc, + const gchar *uri, + const XedEncoding *encoding, + gint line_pos, + gboolean create); +static void xed_document_save_real (XedDocument *doc, + const gchar *uri, + const XedEncoding *encoding, + XedDocumentSaveFlags flags); +static void to_search_region_range (XedDocument *doc, + GtkTextIter *start, + GtkTextIter *end); +static void insert_text_cb (XedDocument *doc, + GtkTextIter *pos, + const gchar *text, + gint length); + +static void delete_range_cb (XedDocument *doc, + GtkTextIter *start, + GtkTextIter *end); + struct _XedDocumentPrivate { - gchar *uri; - gint untitled_number; - gchar *short_name; + gchar *uri; + gint untitled_number; + gchar *short_name; - GFileInfo *metadata_info; + GFileInfo *metadata_info; - const XedEncoding *encoding; + const XedEncoding *encoding; - gchar *content_type; + gchar *content_type; - GTimeVal mtime; - GTimeVal time_of_last_save_or_load; + GTimeVal mtime; + GTimeVal time_of_last_save_or_load; - guint search_flags; - gchar *search_text; - gint num_of_lines_search_text; + guint search_flags; + gchar *search_text; + gint num_of_lines_search_text; - XedDocumentNewlineType newline_type; + XedDocumentNewlineType newline_type; - /* Temp data while loading */ - XedDocumentLoader *loader; - gboolean create; /* Create file if uri points - * to a non existing file */ - const XedEncoding *requested_encoding; - gint requested_line_pos; + /* Temp data while loading */ + XedDocumentLoader *loader; + gboolean create; /* Create file if uri points + * to a non existing file */ + const XedEncoding *requested_encoding; + gint requested_line_pos; - /* Saving stuff */ - XedDocumentSaver *saver; + /* Saving stuff */ + XedDocumentSaver *saver; - /* Search highlighting support variables */ - XedTextRegion *to_search_region; - GtkTextTag *found_tag; + /* Search highlighting support variables */ + XedTextRegion *to_search_region; + GtkTextTag *found_tag; - /* Mount operation factory */ - XedMountOperationFactory mount_operation_factory; - gpointer mount_operation_userdata; + /* Mount operation factory */ + XedMountOperationFactory mount_operation_factory; + gpointer mount_operation_userdata; - gint readonly : 1; - gint last_save_was_manually : 1; - gint language_set_by_user : 1; - gint stop_cursor_moved_emission : 1; - gint dispose_has_run : 1; + gint readonly : 1; + gint last_save_was_manually : 1; + gint language_set_by_user : 1; + gint stop_cursor_moved_emission : 1; + gint dispose_has_run : 1; }; -enum { - PROP_0, +enum +{ + PROP_0, - PROP_URI, - PROP_SHORTNAME, - PROP_CONTENT_TYPE, - PROP_MIME_TYPE, - PROP_READ_ONLY, - PROP_ENCODING, - PROP_CAN_SEARCH_AGAIN, - PROP_ENABLE_SEARCH_HIGHLIGHTING, - PROP_NEWLINE_TYPE + PROP_URI, + PROP_SHORTNAME, + PROP_CONTENT_TYPE, + PROP_MIME_TYPE, + PROP_READ_ONLY, + PROP_ENCODING, + PROP_CAN_SEARCH_AGAIN, + PROP_ENABLE_SEARCH_HIGHLIGHTING, + PROP_NEWLINE_TYPE }; -enum { - CURSOR_MOVED, - LOAD, - LOADING, - LOADED, - SAVE, - SAVING, - SAVED, - SEARCH_HIGHLIGHT_UPDATED, - LAST_SIGNAL +enum +{ + CURSOR_MOVED, + LOAD, + LOADING, + LOADED, + SAVE, + SAVING, + SAVED, + SEARCH_HIGHLIGHT_UPDATED, + LAST_SIGNAL }; static guint document_signals[LAST_SIGNAL] = { 0 }; @@ -179,12 +181,14 @@ G_DEFINE_TYPE(XedDocument, xed_document, GTK_SOURCE_TYPE_BUFFER) GQuark xed_document_error_quark (void) { - static GQuark quark = 0; + static GQuark quark = 0; - if (G_UNLIKELY (quark == 0)) - quark = g_quark_from_static_string ("xed_io_load_error"); + if (G_UNLIKELY (quark == 0)) + { + quark = g_quark_from_static_string ("xed_io_load_error"); + } - return quark; + return quark; } static GHashTable *allocated_untitled_numbers = NULL; @@ -192,807 +196,797 @@ static GHashTable *allocated_untitled_numbers = NULL; static gint get_untitled_number (void) { - gint i = 1; + gint i = 1; - if (allocated_untitled_numbers == NULL) - allocated_untitled_numbers = g_hash_table_new (NULL, NULL); + if (allocated_untitled_numbers == NULL) + { + allocated_untitled_numbers = g_hash_table_new (NULL, NULL); + } - g_return_val_if_fail (allocated_untitled_numbers != NULL, -1); + g_return_val_if_fail (allocated_untitled_numbers != NULL, -1); - while (TRUE) - { - if (g_hash_table_lookup (allocated_untitled_numbers, GINT_TO_POINTER (i)) == NULL) - { - g_hash_table_insert (allocated_untitled_numbers, - GINT_TO_POINTER (i), - GINT_TO_POINTER (i)); + while (TRUE) + { + if (g_hash_table_lookup (allocated_untitled_numbers, GINT_TO_POINTER (i)) == NULL) + { + g_hash_table_insert (allocated_untitled_numbers, GINT_TO_POINTER (i), GINT_TO_POINTER (i)); - return i; - } + return i; + } - ++i; - } + ++i; + } } static void release_untitled_number (gint n) { - g_return_if_fail (allocated_untitled_numbers != NULL); + g_return_if_fail (allocated_untitled_numbers != NULL); - g_hash_table_remove (allocated_untitled_numbers, GINT_TO_POINTER (n)); + g_hash_table_remove (allocated_untitled_numbers, GINT_TO_POINTER (n)); } static void xed_document_dispose (GObject *object) { - XedDocument *doc = XED_DOCUMENT (object); + XedDocument *doc = XED_DOCUMENT (object); - xed_debug (DEBUG_DOCUMENT); + xed_debug (DEBUG_DOCUMENT); - /* Metadata must be saved here and not in finalize - * because the language is gone by the time finalize runs. - * beside if some plugin prevents proper finalization by - * holding a ref to the doc, we still save the metadata */ - if ((!doc->priv->dispose_has_run) && (doc->priv->uri != NULL)) - { - GtkTextIter iter; - gchar *position; - const gchar *language = NULL; + /* Metadata must be saved here and not in finalize + * because the language is gone by the time finalize runs. + * beside if some plugin prevents proper finalization by + * holding a ref to the doc, we still save the metadata */ + if ((!doc->priv->dispose_has_run) && (doc->priv->uri != NULL)) + { + GtkTextIter iter; + gchar *position; + const gchar *language = NULL; - if (doc->priv->language_set_by_user) - { - GtkSourceLanguage *lang; + if (doc->priv->language_set_by_user) + { + GtkSourceLanguage *lang; - lang = xed_document_get_language (doc); + lang = xed_document_get_language (doc); - if (lang == NULL) - language = "_NORMAL_"; - else - language = gtk_source_language_get_id (lang); - } + if (lang == NULL) + { + language = "_NORMAL_"; + } + else + { + language = gtk_source_language_get_id (lang); + } + } - gtk_text_buffer_get_iter_at_mark ( - GTK_TEXT_BUFFER (doc), - &iter, - gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (doc))); + gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), + &iter, + gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (doc))); - position = g_strdup_printf ("%d", - gtk_text_iter_get_offset (&iter)); + position = g_strdup_printf ("%d", gtk_text_iter_get_offset (&iter)); - if (language == NULL) - xed_document_set_metadata (doc, XED_METADATA_ATTRIBUTE_POSITION, - position, NULL); - else - xed_document_set_metadata (doc, XED_METADATA_ATTRIBUTE_POSITION, - position, XED_METADATA_ATTRIBUTE_LANGUAGE, - language, NULL); - g_free (position); - } + if (language == NULL) + { + xed_document_set_metadata (doc, XED_METADATA_ATTRIBUTE_POSITION, position, NULL); + } + else + { + xed_document_set_metadata (doc, XED_METADATA_ATTRIBUTE_POSITION, + position, XED_METADATA_ATTRIBUTE_LANGUAGE, + language, NULL); + } + g_free (position); + } - if (doc->priv->loader) - { - g_object_unref (doc->priv->loader); - doc->priv->loader = NULL; - } + if (doc->priv->loader) + { + g_object_unref (doc->priv->loader); + doc->priv->loader = NULL; + } - if (doc->priv->metadata_info != NULL) - { - g_object_unref (doc->priv->metadata_info); - doc->priv->metadata_info = NULL; - } + if (doc->priv->metadata_info != NULL) + { + g_object_unref (doc->priv->metadata_info); + doc->priv->metadata_info = NULL; + } - doc->priv->dispose_has_run = TRUE; + doc->priv->dispose_has_run = TRUE; - G_OBJECT_CLASS (xed_document_parent_class)->dispose (object); + G_OBJECT_CLASS (xed_document_parent_class)->dispose (object); } static void xed_document_finalize (GObject *object) { - XedDocument *doc = XED_DOCUMENT (object); + XedDocument *doc = XED_DOCUMENT (object); - xed_debug (DEBUG_DOCUMENT); + xed_debug (DEBUG_DOCUMENT); - if (doc->priv->untitled_number > 0) - { - g_return_if_fail (doc->priv->uri == NULL); - release_untitled_number (doc->priv->untitled_number); - } + if (doc->priv->untitled_number > 0) + { + g_return_if_fail (doc->priv->uri == NULL); + release_untitled_number (doc->priv->untitled_number); + } - g_free (doc->priv->uri); - g_free (doc->priv->content_type); - g_free (doc->priv->search_text); + g_free (doc->priv->uri); + g_free (doc->priv->content_type); + g_free (doc->priv->search_text); - if (doc->priv->to_search_region != NULL) - { - /* we can't delete marks if we're finalizing the buffer */ - xed_text_region_destroy (doc->priv->to_search_region, FALSE); - } + if (doc->priv->to_search_region != NULL) + { + /* we can't delete marks if we're finalizing the buffer */ + xed_text_region_destroy (doc->priv->to_search_region, FALSE); + } - G_OBJECT_CLASS (xed_document_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_document_parent_class)->finalize (object); } static void xed_document_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - XedDocument *doc = XED_DOCUMENT (object); + XedDocument *doc = XED_DOCUMENT (object); - switch (prop_id) - { - case PROP_URI: - g_value_set_string (value, doc->priv->uri); - break; - case PROP_SHORTNAME: - g_value_take_string (value, xed_document_get_short_name_for_display (doc)); - break; - case PROP_CONTENT_TYPE: - g_value_take_string (value, xed_document_get_content_type (doc)); - break; - case PROP_MIME_TYPE: - g_value_take_string (value, xed_document_get_mime_type (doc)); - break; - case PROP_READ_ONLY: - g_value_set_boolean (value, doc->priv->readonly); - break; - case PROP_ENCODING: - g_value_set_boxed (value, doc->priv->encoding); - break; - case PROP_CAN_SEARCH_AGAIN: - g_value_set_boolean (value, xed_document_get_can_search_again (doc)); - break; - case PROP_ENABLE_SEARCH_HIGHLIGHTING: - g_value_set_boolean (value, xed_document_get_enable_search_highlighting (doc)); - break; - case PROP_NEWLINE_TYPE: - g_value_set_enum (value, doc->priv->newline_type); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_URI: + g_value_set_string (value, doc->priv->uri); + break; + case PROP_SHORTNAME: + g_value_take_string (value, xed_document_get_short_name_for_display (doc)); + break; + case PROP_CONTENT_TYPE: + g_value_take_string (value, xed_document_get_content_type (doc)); + break; + case PROP_MIME_TYPE: + g_value_take_string (value, xed_document_get_mime_type (doc)); + break; + case PROP_READ_ONLY: + g_value_set_boolean (value, doc->priv->readonly); + break; + case PROP_ENCODING: + g_value_set_boxed (value, doc->priv->encoding); + break; + case PROP_CAN_SEARCH_AGAIN: + g_value_set_boolean (value, xed_document_get_can_search_again (doc)); + break; + case PROP_ENABLE_SEARCH_HIGHLIGHTING: + g_value_set_boolean (value, xed_document_get_enable_search_highlighting (doc)); + break; + case PROP_NEWLINE_TYPE: + g_value_set_enum (value, doc->priv->newline_type); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_document_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - XedDocument *doc = XED_DOCUMENT (object); + XedDocument *doc = XED_DOCUMENT (object); - switch (prop_id) - { - case PROP_ENABLE_SEARCH_HIGHLIGHTING: - xed_document_set_enable_search_highlighting (doc, - g_value_get_boolean (value)); - break; - case PROP_NEWLINE_TYPE: - xed_document_set_newline_type (doc, - g_value_get_enum (value)); - break; - case PROP_SHORTNAME: - xed_document_set_short_name_for_display (doc, - g_value_get_string (value)); - break; - case PROP_CONTENT_TYPE: - xed_document_set_content_type (doc, - g_value_get_string (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_ENABLE_SEARCH_HIGHLIGHTING: + xed_document_set_enable_search_highlighting (doc, g_value_get_boolean (value)); + break; + case PROP_NEWLINE_TYPE: + xed_document_set_newline_type (doc, g_value_get_enum (value)); + break; + case PROP_SHORTNAME: + xed_document_set_short_name_for_display (doc, g_value_get_string (value)); + break; + case PROP_CONTENT_TYPE: + xed_document_set_content_type (doc, g_value_get_string (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void emit_cursor_moved (XedDocument *doc) { - if (!doc->priv->stop_cursor_moved_emission) - { - g_signal_emit (doc, - document_signals[CURSOR_MOVED], - 0); - } + if (!doc->priv->stop_cursor_moved_emission) + { + g_signal_emit (doc, document_signals[CURSOR_MOVED], 0); + } } static void xed_document_mark_set (GtkTextBuffer *buffer, - const GtkTextIter *iter, - GtkTextMark *mark) + const GtkTextIter *iter, + GtkTextMark *mark) { - XedDocument *doc = XED_DOCUMENT (buffer); + XedDocument *doc = XED_DOCUMENT (buffer); - if (GTK_TEXT_BUFFER_CLASS (xed_document_parent_class)->mark_set) - GTK_TEXT_BUFFER_CLASS (xed_document_parent_class)->mark_set (buffer, - iter, - mark); + if (GTK_TEXT_BUFFER_CLASS (xed_document_parent_class)->mark_set) + { + GTK_TEXT_BUFFER_CLASS (xed_document_parent_class)->mark_set (buffer, iter, mark); + } - if (mark == gtk_text_buffer_get_insert (buffer)) - { - emit_cursor_moved (doc); - } + if (mark == gtk_text_buffer_get_insert (buffer)) + { + emit_cursor_moved (doc); + } } static void xed_document_changed (GtkTextBuffer *buffer) { - emit_cursor_moved (XED_DOCUMENT (buffer)); + emit_cursor_moved (XED_DOCUMENT (buffer)); - GTK_TEXT_BUFFER_CLASS (xed_document_parent_class)->changed (buffer); -} - -static void -xed_document_class_init (XedDocumentClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkTextBufferClass *buf_class = GTK_TEXT_BUFFER_CLASS (klass); - - object_class->dispose = xed_document_dispose; - object_class->finalize = xed_document_finalize; - object_class->get_property = xed_document_get_property; - object_class->set_property = xed_document_set_property; - - buf_class->mark_set = xed_document_mark_set; - buf_class->changed = xed_document_changed; - - klass->load = xed_document_load_real; - klass->save = xed_document_save_real; - - g_object_class_install_property (object_class, PROP_URI, - g_param_spec_string ("uri", - "URI", - "The document's URI", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property (object_class, PROP_SHORTNAME, - g_param_spec_string ("shortname", - "Short Name", - "The document's short name", - NULL, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property (object_class, PROP_CONTENT_TYPE, - g_param_spec_string ("content-type", - "Content Type", - "The document's Content Type", - NULL, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property (object_class, PROP_MIME_TYPE, - g_param_spec_string ("mime-type", - "MIME Type", - "The document's MIME Type", - "text/plain", - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property (object_class, PROP_READ_ONLY, - g_param_spec_boolean ("read-only", - "Read Only", - "Whether the document is read only or not", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property (object_class, PROP_ENCODING, - g_param_spec_boxed ("encoding", - "Encoding", - "The XedEncoding used for the document", - XED_TYPE_ENCODING, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property (object_class, PROP_CAN_SEARCH_AGAIN, - g_param_spec_boolean ("can-search-again", - "Can search again", - "Whether it's possible to search again in the document", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property (object_class, PROP_ENABLE_SEARCH_HIGHLIGHTING, - g_param_spec_boolean ("enable-search-highlighting", - "Enable Search Highlighting", - "Whether all the occurrences of the searched string must be highlighted", - FALSE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); - - /** - * XedDocument:newline-type: - * - * The :newline-type property determines what is considered - * as a line ending when saving the document - */ - g_object_class_install_property (object_class, PROP_NEWLINE_TYPE, - g_param_spec_enum ("newline-type", - "Newline type", - "The accepted types of line ending", - XED_TYPE_DOCUMENT_NEWLINE_TYPE, - XED_DOCUMENT_NEWLINE_TYPE_LF, - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_BLURB)); - - /* This signal is used to update the cursor position is the statusbar, - * it's emitted either when the insert mark is moved explicitely or - * when the buffer changes (insert/delete). - * We prevent the emission of the signal during replace_all to - * improve performance. - */ - document_signals[CURSOR_MOVED] = - g_signal_new ("cursor-moved", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedDocumentClass, cursor_moved), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - /** - * XedDocument::load: - * @document: the #XedDocument. - * @uri: the uri where to load the document from. - * @encoding: the #XedEncoding to encode the document. - * @line_pos: the line to show. - * @create: whether the document should be created if it doesn't exist. - * - * The "load" signal is emitted when a document is loaded. - * - * Since: 2.22 - */ - document_signals[LOAD] = - g_signal_new ("load", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedDocumentClass, load), - NULL, NULL, - xed_marshal_VOID__STRING_BOXED_INT_BOOLEAN, - G_TYPE_NONE, - 4, - G_TYPE_STRING, - /* we rely on the fact that the XedEncoding pointer stays - * the same forever */ - XED_TYPE_ENCODING | G_SIGNAL_TYPE_STATIC_SCOPE, - G_TYPE_INT, - G_TYPE_BOOLEAN); - - - document_signals[LOADING] = - g_signal_new ("loading", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedDocumentClass, loading), - NULL, NULL, - xed_marshal_VOID__UINT64_UINT64, - G_TYPE_NONE, - 2, - G_TYPE_UINT64, - G_TYPE_UINT64); - - document_signals[LOADED] = - g_signal_new ("loaded", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedDocumentClass, loaded), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, - 1, - G_TYPE_POINTER); - - /** - * XedDocument::save: - * @document: the #XedDocument. - * @uri: the uri where the document is about to be saved. - * @encoding: the #XedEncoding used to save the document. - * @flags: the #XedDocumentSaveFlags for the save operation. - * - * The "save" signal is emitted when the document is saved. - * - * Since: 2.20 - */ - document_signals[SAVE] = - g_signal_new ("save", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedDocumentClass, save), - NULL, NULL, - xed_marshal_VOID__STRING_BOXED_FLAGS, - G_TYPE_NONE, - 3, - G_TYPE_STRING, - /* we rely on the fact that the XedEncoding pointer stays - * the same forever */ - XED_TYPE_ENCODING | G_SIGNAL_TYPE_STATIC_SCOPE, - XED_TYPE_DOCUMENT_SAVE_FLAGS); - - document_signals[SAVING] = - g_signal_new ("saving", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedDocumentClass, saving), - NULL, NULL, - xed_marshal_VOID__UINT64_UINT64, - G_TYPE_NONE, - 2, - G_TYPE_UINT64, - G_TYPE_UINT64); - - document_signals[SAVED] = - g_signal_new ("saved", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedDocumentClass, saved), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, - 1, - G_TYPE_POINTER); - - document_signals[SEARCH_HIGHLIGHT_UPDATED] = - g_signal_new ("search_highlight_updated", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedDocumentClass, search_highlight_updated), - NULL, NULL, - xed_marshal_VOID__BOXED_BOXED, - G_TYPE_NONE, - 2, - GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE, - GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE); - - g_type_class_add_private (object_class, sizeof(XedDocumentPrivate)); + GTK_TEXT_BUFFER_CLASS (xed_document_parent_class)->changed (buffer); } static void -set_language (XedDocument *doc, +xed_document_class_init (XedDocumentClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkTextBufferClass *buf_class = GTK_TEXT_BUFFER_CLASS (klass); + + object_class->dispose = xed_document_dispose; + object_class->finalize = xed_document_finalize; + object_class->get_property = xed_document_get_property; + object_class->set_property = xed_document_set_property; + + buf_class->mark_set = xed_document_mark_set; + buf_class->changed = xed_document_changed; + + klass->load = xed_document_load_real; + klass->save = xed_document_save_real; + + g_object_class_install_property (object_class, PROP_URI, + g_param_spec_string ("uri", + "URI", + "The document's URI", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (object_class, PROP_SHORTNAME, + g_param_spec_string ("shortname", + "Short Name", + "The document's short name", + NULL, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (object_class, PROP_CONTENT_TYPE, + g_param_spec_string ("content-type", + "Content Type", + "The document's Content Type", + NULL, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (object_class, PROP_MIME_TYPE, + g_param_spec_string ("mime-type", + "MIME Type", + "The document's MIME Type", + "text/plain", + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (object_class, PROP_READ_ONLY, + g_param_spec_boolean ("read-only", + "Read Only", + "Whether the document is read only or not", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (object_class, PROP_ENCODING, + g_param_spec_boxed ("encoding", + "Encoding", + "The XedEncoding used for the document", + XED_TYPE_ENCODING, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (object_class, PROP_CAN_SEARCH_AGAIN, + g_param_spec_boolean ("can-search-again", + "Can search again", + "Whether it's possible to search again in the document", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (object_class, PROP_ENABLE_SEARCH_HIGHLIGHTING, + g_param_spec_boolean ("enable-search-highlighting", + "Enable Search Highlighting", + "Whether all the occurrences of the searched string must be highlighted", + FALSE, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); + + /** + * XedDocument:newline-type: + * + * The :newline-type property determines what is considered + * as a line ending when saving the document + */ + g_object_class_install_property (object_class, PROP_NEWLINE_TYPE, + g_param_spec_enum ("newline-type", + "Newline type", + "The accepted types of line ending", + XED_TYPE_DOCUMENT_NEWLINE_TYPE, + XED_DOCUMENT_NEWLINE_TYPE_LF, + G_PARAM_READWRITE | + G_PARAM_STATIC_NAME | + G_PARAM_STATIC_BLURB)); + + /* This signal is used to update the cursor position is the statusbar, + * it's emitted either when the insert mark is moved explicitely or + * when the buffer changes (insert/delete). + * We prevent the emission of the signal during replace_all to + * improve performance. + */ + document_signals[CURSOR_MOVED] = + g_signal_new ("cursor-moved", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedDocumentClass, cursor_moved), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + + /** + * XedDocument::load: + * @document: the #XedDocument. + * @uri: the uri where to load the document from. + * @encoding: the #XedEncoding to encode the document. + * @line_pos: the line to show. + * @create: whether the document should be created if it doesn't exist. + * + * The "load" signal is emitted when a document is loaded. + * + * Since: 2.22 + */ + document_signals[LOAD] = + g_signal_new ("load", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedDocumentClass, load), + NULL, NULL, + xed_marshal_VOID__STRING_BOXED_INT_BOOLEAN, + G_TYPE_NONE, + 4, + G_TYPE_STRING, + /* we rely on the fact that the XedEncoding pointer stays + * the same forever */ + XED_TYPE_ENCODING | G_SIGNAL_TYPE_STATIC_SCOPE, + G_TYPE_INT, + G_TYPE_BOOLEAN); + + + document_signals[LOADING] = + g_signal_new ("loading", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedDocumentClass, loading), + NULL, NULL, + xed_marshal_VOID__UINT64_UINT64, + G_TYPE_NONE, + 2, + G_TYPE_UINT64, + G_TYPE_UINT64); + + document_signals[LOADED] = + g_signal_new ("loaded", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedDocumentClass, loaded), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, + 1, + G_TYPE_POINTER); + + /** + * XedDocument::save: + * @document: the #XedDocument. + * @uri: the uri where the document is about to be saved. + * @encoding: the #XedEncoding used to save the document. + * @flags: the #XedDocumentSaveFlags for the save operation. + * + * The "save" signal is emitted when the document is saved. + * + * Since: 2.20 + */ + document_signals[SAVE] = + g_signal_new ("save", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedDocumentClass, save), + NULL, NULL, + xed_marshal_VOID__STRING_BOXED_FLAGS, + G_TYPE_NONE, + 3, + G_TYPE_STRING, + /* we rely on the fact that the XedEncoding pointer stays + * the same forever */ + XED_TYPE_ENCODING | G_SIGNAL_TYPE_STATIC_SCOPE, + XED_TYPE_DOCUMENT_SAVE_FLAGS); + + document_signals[SAVING] = + g_signal_new ("saving", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedDocumentClass, saving), + NULL, NULL, + xed_marshal_VOID__UINT64_UINT64, + G_TYPE_NONE, + 2, + G_TYPE_UINT64, + G_TYPE_UINT64); + + document_signals[SAVED] = + g_signal_new ("saved", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedDocumentClass, saved), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, + 1, + G_TYPE_POINTER); + + document_signals[SEARCH_HIGHLIGHT_UPDATED] = + g_signal_new ("search_highlight_updated", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedDocumentClass, search_highlight_updated), + NULL, NULL, + xed_marshal_VOID__BOXED_BOXED, + G_TYPE_NONE, + 2, + GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE, + GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE); + + g_type_class_add_private (object_class, sizeof(XedDocumentPrivate)); +} + +static void +set_language (XedDocument *doc, GtkSourceLanguage *lang, gboolean set_by_user) { - GtkSourceLanguage *old_lang; + GtkSourceLanguage *old_lang; - xed_debug (DEBUG_DOCUMENT); - - old_lang = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (doc)); - - if (old_lang == lang) - return; + xed_debug (DEBUG_DOCUMENT); - gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (doc), lang); + old_lang = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (doc)); - if (lang != NULL) - gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (doc), - xed_prefs_manager_get_enable_syntax_highlighting ()); - else - gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (doc), - FALSE); + if (old_lang == lang) + { + return; + } - if (set_by_user && (doc->priv->uri != NULL)) - { - xed_document_set_metadata (doc, XED_METADATA_ATTRIBUTE_LANGUAGE, - (lang == NULL) ? "_NORMAL_" : gtk_source_language_get_id (lang), - NULL); - } + gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (doc), lang); - doc->priv->language_set_by_user = set_by_user; + if (lang != NULL) + { + gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (doc), + xed_prefs_manager_get_enable_syntax_highlighting ()); + } + else + { + gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (doc), FALSE); + } + + if (set_by_user && (doc->priv->uri != NULL)) + { + xed_document_set_metadata (doc, XED_METADATA_ATTRIBUTE_LANGUAGE, + (lang == NULL) ? "_NORMAL_" : gtk_source_language_get_id (lang), + NULL); + } + + doc->priv->language_set_by_user = set_by_user; } static void -set_encoding (XedDocument *doc, - const XedEncoding *encoding, - gboolean set_by_user) +set_encoding (XedDocument *doc, + const XedEncoding *encoding, + gboolean set_by_user) { - g_return_if_fail (encoding != NULL); + g_return_if_fail (encoding != NULL); - xed_debug (DEBUG_DOCUMENT); + xed_debug (DEBUG_DOCUMENT); - if (doc->priv->encoding == encoding) - return; + if (doc->priv->encoding == encoding) + { + return; + } - doc->priv->encoding = encoding; + doc->priv->encoding = encoding; - if (set_by_user) - { - const gchar *charset; + if (set_by_user) + { + const gchar *charset; - charset = xed_encoding_get_charset (encoding); + charset = xed_encoding_get_charset (encoding); - xed_document_set_metadata (doc, XED_METADATA_ATTRIBUTE_ENCODING, - charset, NULL); - } + xed_document_set_metadata (doc, XED_METADATA_ATTRIBUTE_ENCODING, charset, NULL); + } - g_object_notify (G_OBJECT (doc), "encoding"); + g_object_notify (G_OBJECT (doc), "encoding"); } static GtkSourceStyleScheme * get_default_style_scheme (void) { - gchar *scheme_id; - GtkSourceStyleScheme *def_style; - GtkSourceStyleSchemeManager *manager; + gchar *scheme_id; + GtkSourceStyleScheme *def_style; + GtkSourceStyleSchemeManager *manager; - manager = xed_get_style_scheme_manager (); - scheme_id = xed_prefs_manager_get_source_style_scheme (); - def_style = gtk_source_style_scheme_manager_get_scheme (manager, - scheme_id); + manager = xed_get_style_scheme_manager (); + scheme_id = xed_prefs_manager_get_source_style_scheme (); + def_style = gtk_source_style_scheme_manager_get_scheme (manager, + scheme_id); - if (def_style == NULL) - { - g_warning ("Default style scheme '%s' cannot be found, falling back to 'classic' style scheme ", scheme_id); + if (def_style == NULL) + { + g_warning ("Default style scheme '%s' cannot be found, falling back to 'classic' style scheme ", scheme_id); - def_style = gtk_source_style_scheme_manager_get_scheme (manager, "classic"); - if (def_style == NULL) - { - g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation."); - } - } + def_style = gtk_source_style_scheme_manager_get_scheme (manager, "classic"); + if (def_style == NULL) + { + g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation."); + } + } - g_free (scheme_id); + g_free (scheme_id); - return def_style; + return def_style; } static void on_uri_changed (XedDocument *doc, - GParamSpec *pspec, - gpointer useless) + GParamSpec *pspec, + gpointer useless) { #ifdef ENABLE_GVFS_METADATA - GFile *location; + GFile *location; - location = xed_document_get_location (doc); + location = xed_document_get_location (doc); - /* load metadata for this uri: we load sync since metadata is - * always local so it should be fast and we need the information - * right after the uri was set. - */ - if (location != NULL) - { - GError *error = NULL; + /* load metadata for this uri: we load sync since metadata is + * always local so it should be fast and we need the information + * right after the uri was set. + */ + if (location != NULL) + { + GError *error = NULL; - if (doc->priv->metadata_info != NULL) - g_object_unref (doc->priv->metadata_info); + if (doc->priv->metadata_info != NULL) + { + g_object_unref (doc->priv->metadata_info); + } - doc->priv->metadata_info = g_file_query_info (location, - METADATA_QUERY, - G_FILE_QUERY_INFO_NONE, - NULL, - &error); + doc->priv->metadata_info = g_file_query_info (location, + METADATA_QUERY, + G_FILE_QUERY_INFO_NONE, + NULL, + &error); - if (error != NULL) - { - if (error->code != G_FILE_ERROR_ISDIR && - error->code != G_FILE_ERROR_NOTDIR && - error->code != G_FILE_ERROR_NOENT) - { - g_warning ("%s", error->message); - } + if (error != NULL) + { + if (error->code != G_FILE_ERROR_ISDIR && + error->code != G_FILE_ERROR_NOTDIR && + error->code != G_FILE_ERROR_NOENT) + { + g_warning ("%s", error->message); + } - g_error_free (error); - } + g_error_free (error); + } - g_object_unref (location); - } + g_object_unref (location); + } #endif } static GtkSourceLanguage * guess_language (XedDocument *doc, - const gchar *content_type) + const gchar *content_type) { - gchar *data; - GtkSourceLanguage *language = NULL; + gchar *data; + GtkSourceLanguage *language = NULL; - data = xed_document_get_metadata (doc, XED_METADATA_ATTRIBUTE_LANGUAGE); + data = xed_document_get_metadata (doc, XED_METADATA_ATTRIBUTE_LANGUAGE); - if (data != NULL) - { - xed_debug_message (DEBUG_DOCUMENT, "Language from metadata: %s", data); + if (data != NULL) + { + xed_debug_message (DEBUG_DOCUMENT, "Language from metadata: %s", data); - if (strcmp (data, "_NORMAL_") != 0) - { - language = gtk_source_language_manager_get_language ( - xed_get_language_manager (), - data); - } + if (strcmp (data, "_NORMAL_") != 0) + { + language = gtk_source_language_manager_get_language (xed_get_language_manager (), data); + } - g_free (data); - } - else - { - GFile *file; - gchar *basename = NULL; + g_free (data); + } + else + { + GFile *file; + gchar *basename = NULL; - file = xed_document_get_location (doc); - xed_debug_message (DEBUG_DOCUMENT, "Sniffing Language"); + file = xed_document_get_location (doc); + xed_debug_message (DEBUG_DOCUMENT, "Sniffing Language"); - if (file) - { - basename = g_file_get_basename (file); - } - else if (doc->priv->short_name != NULL) - { - basename = g_strdup (doc->priv->short_name); - } + if (file) + { + basename = g_file_get_basename (file); + } + else if (doc->priv->short_name != NULL) + { + basename = g_strdup (doc->priv->short_name); + } - language = gtk_source_language_manager_guess_language ( - xed_get_language_manager (), - basename, - content_type); + language = gtk_source_language_manager_guess_language (xed_get_language_manager (), basename, content_type); - g_free (basename); + g_free (basename); - if (file != NULL) - { - g_object_unref (file); - } - } + if (file != NULL) + { + g_object_unref (file); + } + } - return language; + return language; } static void on_content_type_changed (XedDocument *doc, - GParamSpec *pspec, - gpointer useless) + GParamSpec *pspec, + gpointer useless) { - if (!doc->priv->language_set_by_user) - { - GtkSourceLanguage *language; + if (!doc->priv->language_set_by_user) + { + GtkSourceLanguage *language; - language = guess_language (doc, doc->priv->content_type); + language = guess_language (doc, doc->priv->content_type); - xed_debug_message (DEBUG_DOCUMENT, "Language: %s", - language != NULL ? gtk_source_language_get_name (language) : "None"); + xed_debug_message (DEBUG_DOCUMENT, "Language: %s", + language != NULL ? gtk_source_language_get_name (language) : "None"); - set_language (doc, language, FALSE); - } + set_language (doc, language, FALSE); + } } static gchar * get_default_content_type (void) { - return g_content_type_from_mime_type ("text/plain"); + return g_content_type_from_mime_type ("text/plain"); } static void xed_document_init (XedDocument *doc) { - GtkSourceStyleScheme *style_scheme; + GtkSourceStyleScheme *style_scheme; - xed_debug (DEBUG_DOCUMENT); + xed_debug (DEBUG_DOCUMENT); - doc->priv = XED_DOCUMENT_GET_PRIVATE (doc); + doc->priv = XED_DOCUMENT_GET_PRIVATE (doc); - doc->priv->uri = NULL; - doc->priv->untitled_number = get_untitled_number (); + doc->priv->uri = NULL; + doc->priv->untitled_number = get_untitled_number (); - doc->priv->metadata_info = NULL; + doc->priv->metadata_info = NULL; - doc->priv->content_type = get_default_content_type (); + doc->priv->content_type = get_default_content_type (); - doc->priv->readonly = FALSE; + doc->priv->readonly = FALSE; - doc->priv->stop_cursor_moved_emission = FALSE; + doc->priv->stop_cursor_moved_emission = FALSE; - doc->priv->last_save_was_manually = TRUE; - doc->priv->language_set_by_user = FALSE; + doc->priv->last_save_was_manually = TRUE; + doc->priv->language_set_by_user = FALSE; - doc->priv->dispose_has_run = FALSE; + doc->priv->dispose_has_run = FALSE; - doc->priv->mtime.tv_sec = 0; - doc->priv->mtime.tv_usec = 0; + doc->priv->mtime.tv_sec = 0; + doc->priv->mtime.tv_usec = 0; - g_get_current_time (&doc->priv->time_of_last_save_or_load); + g_get_current_time (&doc->priv->time_of_last_save_or_load); - doc->priv->encoding = xed_encoding_get_utf8 (); + doc->priv->encoding = xed_encoding_get_utf8 (); - doc->priv->newline_type = XED_DOCUMENT_NEWLINE_TYPE_DEFAULT; + doc->priv->newline_type = XED_DOCUMENT_NEWLINE_TYPE_DEFAULT; - gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (doc), - xed_prefs_manager_get_undo_actions_limit ()); + gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (doc), xed_prefs_manager_get_undo_actions_limit ()); + gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (doc), + xed_prefs_manager_get_bracket_matching ()); + xed_document_set_enable_search_highlighting (doc, xed_prefs_manager_get_enable_search_highlighting ()); - gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (doc), - xed_prefs_manager_get_bracket_matching ()); + style_scheme = get_default_style_scheme (); + if (style_scheme != NULL) + { + gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (doc), style_scheme); + } - xed_document_set_enable_search_highlighting (doc, - xed_prefs_manager_get_enable_search_highlighting ()); - - style_scheme = get_default_style_scheme (); - if (style_scheme != NULL) - gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (doc), - style_scheme); - - g_signal_connect_after (doc, - "insert-text", - G_CALLBACK (insert_text_cb), - NULL); - - g_signal_connect_after (doc, - "delete-range", - G_CALLBACK (delete_range_cb), - NULL); - - g_signal_connect (doc, - "notify::content-type", - G_CALLBACK (on_content_type_changed), - NULL); - - g_signal_connect (doc, - "notify::uri", - G_CALLBACK (on_uri_changed), - NULL); + g_signal_connect_after (doc, "insert-text", G_CALLBACK (insert_text_cb), NULL); + g_signal_connect_after (doc, "delete-range", G_CALLBACK (delete_range_cb), NULL); + g_signal_connect (doc, "notify::content-type", G_CALLBACK (on_content_type_changed), NULL); + g_signal_connect (doc, "notify::uri", G_CALLBACK (on_uri_changed), NULL); } XedDocument * xed_document_new (void) { - xed_debug (DEBUG_DOCUMENT); + xed_debug (DEBUG_DOCUMENT); - return XED_DOCUMENT (g_object_new (XED_TYPE_DOCUMENT, NULL)); + return XED_DOCUMENT (g_object_new (XED_TYPE_DOCUMENT, NULL)); } static void set_content_type_no_guess (XedDocument *doc, - const gchar *content_type) + const gchar *content_type) { - xed_debug (DEBUG_DOCUMENT); + xed_debug (DEBUG_DOCUMENT); - if (doc->priv->content_type != NULL && content_type != NULL && - (0 == strcmp (doc->priv->content_type, content_type))) - return; + if (doc->priv->content_type != NULL && content_type != NULL && + (0 == strcmp (doc->priv->content_type, content_type))) + { + return; + } - g_free (doc->priv->content_type); + g_free (doc->priv->content_type); - if (content_type == NULL || g_content_type_is_unknown (content_type)) - doc->priv->content_type = get_default_content_type (); - else - doc->priv->content_type = g_strdup (content_type); + if (content_type == NULL || g_content_type_is_unknown (content_type)) + { + doc->priv->content_type = get_default_content_type (); + } + else + { + doc->priv->content_type = g_strdup (content_type); + } - g_object_notify (G_OBJECT (doc), "content-type"); + g_object_notify (G_OBJECT (doc), "content-type"); } static void set_content_type (XedDocument *doc, - const gchar *content_type) + const gchar *content_type) { - xed_debug (DEBUG_DOCUMENT); + xed_debug (DEBUG_DOCUMENT); - if (content_type == NULL) - { - GFile *file; - gchar *guessed_type = NULL; + if (content_type == NULL) + { + GFile *file; + gchar *guessed_type = NULL; - /* If content type is null, we guess from the filename */ - file = xed_document_get_location (doc); - if (file != NULL) - { - gchar *basename; + /* If content type is null, we guess from the filename */ + file = xed_document_get_location (doc); + if (file != NULL) + { + gchar *basename; - basename = g_file_get_basename (file); - guessed_type = g_content_type_guess (basename, NULL, 0, NULL); + basename = g_file_get_basename (file); + guessed_type = g_content_type_guess (basename, NULL, 0, NULL); - g_free (basename); - g_object_unref (file); - } + g_free (basename); + g_object_unref (file); + } - set_content_type_no_guess (doc, guessed_type); + set_content_type_no_guess (doc, guessed_type); - g_free (guessed_type); - } - else - { - set_content_type_no_guess (doc, content_type); - } + g_free (guessed_type); + } + else + { + set_content_type_no_guess (doc, content_type); + } } /** @@ -1002,69 +996,71 @@ set_content_type (XedDocument *doc, */ void xed_document_set_content_type (XedDocument *doc, - const gchar *content_type) + const gchar *content_type) { - g_return_if_fail (XED_IS_DOCUMENT (doc)); + g_return_if_fail (XED_IS_DOCUMENT (doc)); - set_content_type (doc, content_type); + set_content_type (doc, content_type); } static void set_uri (XedDocument *doc, - const gchar *uri) + const gchar *uri) { - xed_debug (DEBUG_DOCUMENT); + xed_debug (DEBUG_DOCUMENT); - g_return_if_fail ((uri == NULL) || xed_utils_is_valid_uri (uri)); + g_return_if_fail ((uri == NULL) || xed_utils_is_valid_uri (uri)); - if (uri != NULL) - { - if (doc->priv->uri == uri) - return; + if (uri != NULL) + { + if (doc->priv->uri == uri) + { + return; + } - g_free (doc->priv->uri); - doc->priv->uri = g_strdup (uri); + g_free (doc->priv->uri); + doc->priv->uri = g_strdup (uri); - if (doc->priv->untitled_number > 0) - { - release_untitled_number (doc->priv->untitled_number); - doc->priv->untitled_number = 0; - } - } + if (doc->priv->untitled_number > 0) + { + release_untitled_number (doc->priv->untitled_number); + doc->priv->untitled_number = 0; + } + } - g_object_notify (G_OBJECT (doc), "uri"); + g_object_notify (G_OBJECT (doc), "uri"); - if (doc->priv->short_name == NULL) - { - g_object_notify (G_OBJECT (doc), "shortname"); - } + if (doc->priv->short_name == NULL) + { + g_object_notify (G_OBJECT (doc), "shortname"); + } } GFile * xed_document_get_location (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - return doc->priv->uri == NULL ? NULL : g_file_new_for_uri (doc->priv->uri); + return doc->priv->uri == NULL ? NULL : g_file_new_for_uri (doc->priv->uri); } gchar * xed_document_get_uri (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - return g_strdup (doc->priv->uri); + return g_strdup (doc->priv->uri); } void xed_document_set_uri (XedDocument *doc, - const gchar *uri) + const gchar *uri) { - g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail (uri != NULL); + g_return_if_fail (XED_IS_DOCUMENT (doc)); + g_return_if_fail (uri != NULL); - set_uri (doc, uri); - set_content_type (doc, NULL); + set_uri (doc, uri); + set_content_type (doc, NULL); } /** @@ -1076,13 +1072,16 @@ xed_document_set_uri (XedDocument *doc, gchar * xed_document_get_uri_for_display (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), g_strdup ("")); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), g_strdup ("")); - if (doc->priv->uri == NULL) - return g_strdup_printf (_("Unsaved Document %d"), - doc->priv->untitled_number); - else - return xed_utils_uri_for_display (doc->priv->uri); + if (doc->priv->uri == NULL) + { + return g_strdup_printf (_("Unsaved Document %d"), doc->priv->untitled_number); + } + else + { + return xed_utils_uri_for_display (doc->priv->uri); + } } /** @@ -1094,15 +1093,20 @@ xed_document_get_uri_for_display (XedDocument *doc) gchar * xed_document_get_short_name_for_display (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), g_strdup ("")); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), g_strdup ("")); - if (doc->priv->short_name != NULL) - return g_strdup (doc->priv->short_name); - else if (doc->priv->uri == NULL) - return g_strdup_printf (_("Unsaved Document %d"), - doc->priv->untitled_number); - else - return xed_utils_basename_for_display (doc->priv->uri); + if (doc->priv->short_name != NULL) + { + return g_strdup (doc->priv->short_name); + } + else if (doc->priv->uri == NULL) + { + return g_strdup_printf (_("Unsaved Document %d"), doc->priv->untitled_number); + } + else + { + return xed_utils_basename_for_display (doc->priv->uri); + } } /** @@ -1112,22 +1116,22 @@ xed_document_get_short_name_for_display (XedDocument *doc) */ void xed_document_set_short_name_for_display (XedDocument *doc, - const gchar *short_name) + const gchar *short_name) { - g_return_if_fail (XED_IS_DOCUMENT (doc)); + g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_free (doc->priv->short_name); - doc->priv->short_name = g_strdup (short_name); + g_free (doc->priv->short_name); + doc->priv->short_name = g_strdup (short_name); - g_object_notify (G_OBJECT (doc), "shortname"); + g_object_notify (G_OBJECT (doc), "shortname"); } gchar * xed_document_get_content_type (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - return g_strdup (doc->priv->content_type); + return g_strdup (doc->priv->content_type); } /** @@ -1139,34 +1143,36 @@ xed_document_get_content_type (XedDocument *doc) gchar * xed_document_get_mime_type (XedDocument *doc) { - gchar *mime_type = NULL; + gchar *mime_type = NULL; - g_return_val_if_fail (XED_IS_DOCUMENT (doc), g_strdup ("text/plain")); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), g_strdup ("text/plain")); - if ((doc->priv->content_type != NULL) && - (!g_content_type_is_unknown (doc->priv->content_type))) - { - mime_type = g_content_type_get_mime_type (doc->priv->content_type); - } + if ((doc->priv->content_type != NULL) && + (!g_content_type_is_unknown (doc->priv->content_type))) + { + mime_type = g_content_type_get_mime_type (doc->priv->content_type); + } - return mime_type != NULL ? mime_type : g_strdup ("text/plain"); + return mime_type != NULL ? mime_type : g_strdup ("text/plain"); } /* Note: do not emit the notify::read-only signal */ static gboolean set_readonly (XedDocument *doc, - gboolean readonly) + gboolean readonly) { - xed_debug (DEBUG_DOCUMENT); + xed_debug (DEBUG_DOCUMENT); - readonly = (readonly != FALSE); + readonly = (readonly != FALSE); - if (doc->priv->readonly == readonly) - return FALSE; + if (doc->priv->readonly == readonly) + { + return FALSE; + } - doc->priv->readonly = readonly; + doc->priv->readonly = readonly; - return TRUE; + return TRUE; } /** @@ -1178,258 +1184,240 @@ set_readonly (XedDocument *doc, */ void _xed_document_set_readonly (XedDocument *doc, - gboolean readonly) + gboolean readonly) { - xed_debug (DEBUG_DOCUMENT); + xed_debug (DEBUG_DOCUMENT); - g_return_if_fail (XED_IS_DOCUMENT (doc)); + g_return_if_fail (XED_IS_DOCUMENT (doc)); - if (set_readonly (doc, readonly)) - { - g_object_notify (G_OBJECT (doc), "read-only"); - } + if (set_readonly (doc, readonly)) + { + g_object_notify (G_OBJECT (doc), "read-only"); + } } gboolean xed_document_get_readonly (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), TRUE); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), TRUE); - return doc->priv->readonly; + return doc->priv->readonly; } gboolean _xed_document_check_externally_modified (XedDocument *doc) { - GFile *gfile; - GFileInfo *info; + GFile *gfile; + GFileInfo *info; - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - if (doc->priv->uri == NULL) - { - return FALSE; - } + if (doc->priv->uri == NULL) + { + return FALSE; + } - gfile = g_file_new_for_uri (doc->priv->uri); - info = g_file_query_info (gfile, - G_FILE_ATTRIBUTE_TIME_MODIFIED "," \ - G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, - G_FILE_QUERY_INFO_NONE, - NULL, NULL); - g_object_unref (gfile); + gfile = g_file_new_for_uri (doc->priv->uri); + info = g_file_query_info (gfile, + G_FILE_ATTRIBUTE_TIME_MODIFIED "," \ + G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, + G_FILE_QUERY_INFO_NONE, + NULL, NULL); + g_object_unref (gfile); - if (info != NULL) - { - /* While at it also check if permissions changed */ - if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) - { - gboolean read_only; + if (info != NULL) + { + /* While at it also check if permissions changed */ + if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) + { + gboolean read_only; - read_only = !g_file_info_get_attribute_boolean (info, - G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); + read_only = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); - _xed_document_set_readonly (doc, read_only); - } + _xed_document_set_readonly (doc, read_only); + } - if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) - { - GTimeVal timeval; + if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) + { + GTimeVal timeval; - g_file_info_get_modification_time (info, &timeval); - g_object_unref (info); - - return (timeval.tv_sec > doc->priv->mtime.tv_sec) || - (timeval.tv_sec == doc->priv->mtime.tv_sec && - timeval.tv_usec > doc->priv->mtime.tv_usec); - } - } + g_file_info_get_modification_time (info, &timeval); + g_object_unref (info); - return FALSE; + return (timeval.tv_sec > doc->priv->mtime.tv_sec) || + (timeval.tv_sec == doc->priv->mtime.tv_sec && + timeval.tv_usec > doc->priv->mtime.tv_usec); + } + } + + return FALSE; } static void reset_temp_loading_data (XedDocument *doc) { - /* the loader has been used, throw it away */ - g_object_unref (doc->priv->loader); - doc->priv->loader = NULL; + /* the loader has been used, throw it away */ + g_object_unref (doc->priv->loader); + doc->priv->loader = NULL; - doc->priv->requested_encoding = NULL; - doc->priv->requested_line_pos = 0; + doc->priv->requested_encoding = NULL; + doc->priv->requested_line_pos = 0; } static void document_loader_loaded (XedDocumentLoader *loader, - const GError *error, - XedDocument *doc) + const GError *error, + XedDocument *doc) { - /* load was successful */ - if (error == NULL || - (error->domain == XED_DOCUMENT_ERROR && - error->code == XED_DOCUMENT_ERROR_CONVERSION_FALLBACK)) - { - GtkTextIter iter; - GFileInfo *info; - const gchar *content_type = NULL; - gboolean read_only = FALSE; - GTimeVal mtime = {0, 0}; + /* load was successful */ + if (error == NULL || + (error->domain == XED_DOCUMENT_ERROR && + error->code == XED_DOCUMENT_ERROR_CONVERSION_FALLBACK)) + { + GtkTextIter iter; + GFileInfo *info; + const gchar *content_type = NULL; + gboolean read_only = FALSE; + GTimeVal mtime = {0, 0}; - info = xed_document_loader_get_info (loader); + info = xed_document_loader_get_info (loader); - if (info) - { - if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)) - content_type = g_file_info_get_attribute_string (info, - G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); + if (info) + { + if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)) + { + content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); + } + if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) + { + g_file_info_get_modification_time (info, &mtime); + } + if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) + { + read_only = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); + } + } - if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) - g_file_info_get_modification_time (info, &mtime); + doc->priv->mtime = mtime; - if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) - read_only = !g_file_info_get_attribute_boolean (info, - G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); - } + set_readonly (doc, read_only); - doc->priv->mtime = mtime; + g_get_current_time (&doc->priv->time_of_last_save_or_load); - set_readonly (doc, read_only); + set_encoding (doc, xed_document_loader_get_encoding (loader), (doc->priv->requested_encoding != NULL)); - g_get_current_time (&doc->priv->time_of_last_save_or_load); + set_content_type (doc, content_type); - set_encoding (doc, - xed_document_loader_get_encoding (loader), - (doc->priv->requested_encoding != NULL)); + xed_document_set_newline_type (doc, xed_document_loader_get_newline_type (loader)); - set_content_type (doc, content_type); + /* move the cursor at the requested line if any */ + if (doc->priv->requested_line_pos > 0) + { + /* line_pos - 1 because get_iter_at_line counts from 0 */ + gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (doc), + &iter, + doc->priv->requested_line_pos - 1); + } + /* else, if enabled, to the position stored in the metadata */ + else if (xed_prefs_manager_get_restore_cursor_position ()) + { + gchar *pos; + gint offset; - xed_document_set_newline_type (doc, - xed_document_loader_get_newline_type (loader)); + pos = xed_document_get_metadata (doc, XED_METADATA_ATTRIBUTE_POSITION); - /* move the cursor at the requested line if any */ - if (doc->priv->requested_line_pos > 0) - { - /* line_pos - 1 because get_iter_at_line counts from 0 */ - gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (doc), - &iter, - doc->priv->requested_line_pos - 1); - } - /* else, if enabled, to the position stored in the metadata */ - else if (xed_prefs_manager_get_restore_cursor_position ()) - { - gchar *pos; - gint offset; + offset = pos ? atoi (pos) : 0; + g_free (pos); - pos = xed_document_get_metadata (doc, XED_METADATA_ATTRIBUTE_POSITION); + gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &iter, MAX (offset, 0)); - offset = pos ? atoi (pos) : 0; - g_free (pos); + /* make sure it's a valid position, if the file + * changed we may have ended up in the middle of + * a utf8 character cluster */ + if (!gtk_text_iter_is_cursor_position (&iter)) + { + gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (doc), &iter); + } + } + /* otherwise to the top */ + else + { + gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (doc), &iter); + } - gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), - &iter, - MAX (offset, 0)); + gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter); + } - /* make sure it's a valid position, if the file - * changed we may have ended up in the middle of - * a utf8 character cluster */ - if (!gtk_text_iter_is_cursor_position (&iter)) - { - gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (doc), - &iter); - } - } - /* otherwise to the top */ - else - { - gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (doc), - &iter); - } + /* special case creating a named new doc */ + else if (doc->priv->create && + (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_FOUND) && + (xed_utils_uri_has_file_scheme (doc->priv->uri))) + { + reset_temp_loading_data (doc); - gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter); - } + g_signal_emit (doc, document_signals[LOADED], 0, NULL); - /* special case creating a named new doc */ - else if (doc->priv->create && - (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_FOUND) && - (xed_utils_uri_has_file_scheme (doc->priv->uri))) - { - reset_temp_loading_data (doc); + return; + } - g_signal_emit (doc, - document_signals[LOADED], - 0, - NULL); + g_signal_emit (doc, document_signals[LOADED], 0, error); - return; - } - - g_signal_emit (doc, - document_signals[LOADED], - 0, - error); - - reset_temp_loading_data (doc); + reset_temp_loading_data (doc); } static void document_loader_loading (XedDocumentLoader *loader, - gboolean completed, - const GError *error, - XedDocument *doc) + gboolean completed, + const GError *error, + XedDocument *doc) { - if (completed) - { - document_loader_loaded (loader, error, doc); - } - else - { - goffset size = 0; - goffset read; - GFileInfo *info; + if (completed) + { + document_loader_loaded (loader, error, doc); + } + else + { + goffset size = 0; + goffset read; + GFileInfo *info; - info = xed_document_loader_get_info (loader); + info = xed_document_loader_get_info (loader); - if (info && g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE)) - size = g_file_info_get_attribute_uint64 (info, - G_FILE_ATTRIBUTE_STANDARD_SIZE); + if (info && g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE)) + { + size = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_STANDARD_SIZE); + } - read = xed_document_loader_get_bytes_read (loader); + read = xed_document_loader_get_bytes_read (loader); - g_signal_emit (doc, - document_signals[LOADING], - 0, - read, - size); - } + g_signal_emit (doc, document_signals[LOADING], 0, read, size); + } } static void xed_document_load_real (XedDocument *doc, - const gchar *uri, - const XedEncoding *encoding, - gint line_pos, - gboolean create) + const gchar *uri, + const XedEncoding *encoding, + gint line_pos, + gboolean create) { - g_return_if_fail (doc->priv->loader == NULL); + g_return_if_fail (doc->priv->loader == NULL); - xed_debug_message (DEBUG_DOCUMENT, "load_real: uri = %s", uri); + xed_debug_message (DEBUG_DOCUMENT, "load_real: uri = %s", uri); - /* create a loader. It will be destroyed when loading is completed */ - doc->priv->loader = xed_document_loader_new (doc, uri, encoding); + /* create a loader. It will be destroyed when loading is completed */ + doc->priv->loader = xed_document_loader_new (doc, uri, encoding); - g_signal_connect (doc->priv->loader, - "loading", - G_CALLBACK (document_loader_loading), - doc); + g_signal_connect (doc->priv->loader, "loading", G_CALLBACK (document_loader_loading), doc); - doc->priv->create = create; - doc->priv->requested_encoding = encoding; - doc->priv->requested_line_pos = line_pos; + doc->priv->create = create; + doc->priv->requested_encoding = encoding; + doc->priv->requested_line_pos = line_pos; - set_uri (doc, uri); - set_content_type (doc, NULL); + set_uri (doc, uri); + set_content_type (doc, NULL); - xed_document_loader_load (doc->priv->loader); + xed_document_loader_load (doc->priv->loader); } /** @@ -1444,16 +1432,16 @@ xed_document_load_real (XedDocument *doc, */ void xed_document_load (XedDocument *doc, - const gchar *uri, - const XedEncoding *encoding, - gint line_pos, - gboolean create) + const gchar *uri, + const XedEncoding *encoding, + gint line_pos, + gboolean create) { - g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail (uri != NULL); - g_return_if_fail (xed_utils_is_valid_uri (uri)); + g_return_if_fail (XED_IS_DOCUMENT (doc)); + g_return_if_fail (uri != NULL); + g_return_if_fail (xed_utils_is_valid_uri (uri)); - g_signal_emit (doc, document_signals[LOAD], 0, uri, encoding, line_pos, create); + g_signal_emit (doc, document_signals[LOAD], 0, uri, encoding, line_pos, create); } /** @@ -1465,111 +1453,98 @@ xed_document_load (XedDocument *doc, gboolean xed_document_load_cancel (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - if (doc->priv->loader == NULL) - return FALSE; + if (doc->priv->loader == NULL) + { + return FALSE; + } - return xed_document_loader_cancel (doc->priv->loader); + return xed_document_loader_cancel (doc->priv->loader); } static void document_saver_saving (XedDocumentSaver *saver, - gboolean completed, - const GError *error, - XedDocument *doc) + gboolean completed, + const GError *error, + XedDocument *doc) { - xed_debug (DEBUG_DOCUMENT); + xed_debug (DEBUG_DOCUMENT); - if (completed) - { - /* save was successful */ - if (error == NULL) - { - const gchar *uri; - const gchar *content_type = NULL; - GTimeVal mtime = {0, 0}; - GFileInfo *info; + if (completed) + { + /* save was successful */ + if (error == NULL) + { + const gchar *uri; + const gchar *content_type = NULL; + GTimeVal mtime = {0, 0}; + GFileInfo *info; - uri = xed_document_saver_get_uri (saver); - set_uri (doc, uri); + uri = xed_document_saver_get_uri (saver); + set_uri (doc, uri); - info = xed_document_saver_get_info (saver); + info = xed_document_saver_get_info (saver); - if (info != NULL) - { - if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)) - content_type = g_file_info_get_attribute_string (info, - G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); + if (info != NULL) + { + if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)) + { + content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); + } + if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) + { + g_file_info_get_modification_time (info, &mtime); + } + } - if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) - g_file_info_get_modification_time (info, &mtime); - } + set_content_type (doc, content_type); + doc->priv->mtime = mtime; - set_content_type (doc, content_type); - doc->priv->mtime = mtime; + g_get_current_time (&doc->priv->time_of_last_save_or_load); - g_get_current_time (&doc->priv->time_of_last_save_or_load); + _xed_document_set_readonly (doc, FALSE); - _xed_document_set_readonly (doc, FALSE); + gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc), FALSE); + set_encoding (doc, doc->priv->requested_encoding, TRUE); + } - gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc), - FALSE); + g_signal_emit (doc, document_signals[SAVED], 0, error); - set_encoding (doc, - doc->priv->requested_encoding, - TRUE); - } + /* the saver has been used, throw it away */ + g_object_unref (doc->priv->saver); + doc->priv->saver = NULL; + } + else + { + goffset size = 0; + goffset written = 0; - g_signal_emit (doc, - document_signals[SAVED], - 0, - error); + size = xed_document_saver_get_file_size (saver); + written = xed_document_saver_get_bytes_written (saver); - /* the saver has been used, throw it away */ - g_object_unref (doc->priv->saver); - doc->priv->saver = NULL; - } - else - { - goffset size = 0; - goffset written = 0; + xed_debug_message (DEBUG_DOCUMENT, "save progress: %" G_GINT64_FORMAT " of %" G_GINT64_FORMAT, written, size); - size = xed_document_saver_get_file_size (saver); - written = xed_document_saver_get_bytes_written (saver); - - xed_debug_message (DEBUG_DOCUMENT, "save progress: %" G_GINT64_FORMAT " of %" G_GINT64_FORMAT, written, size); - - g_signal_emit (doc, - document_signals[SAVING], - 0, - written, - size); - } + g_signal_emit (doc, document_signals[SAVING], 0, written, size); + } } static void xed_document_save_real (XedDocument *doc, - const gchar *uri, - const XedEncoding *encoding, - XedDocumentSaveFlags flags) + const gchar *uri, + const XedEncoding *encoding, + XedDocumentSaveFlags flags) { - g_return_if_fail (doc->priv->saver == NULL); + g_return_if_fail (doc->priv->saver == NULL); - /* create a saver, it will be destroyed once saving is complete */ - doc->priv->saver = xed_document_saver_new (doc, uri, encoding, - doc->priv->newline_type, - flags); + /* create a saver, it will be destroyed once saving is complete */ + doc->priv->saver = xed_document_saver_new (doc, uri, encoding, doc->priv->newline_type, flags); - g_signal_connect (doc->priv->saver, - "saving", - G_CALLBACK (document_saver_saving), - doc); + g_signal_connect (doc->priv->saver, "saving", G_CALLBACK (document_saver_saving), doc); - doc->priv->requested_encoding = encoding; + doc->priv->requested_encoding = encoding; - xed_document_saver_save (doc->priv->saver, - &doc->priv->mtime); + xed_document_saver_save (doc->priv->saver, &doc->priv->mtime); } /** @@ -1582,17 +1557,12 @@ xed_document_save_real (XedDocument *doc, */ void xed_document_save (XedDocument *doc, - XedDocumentSaveFlags flags) + XedDocumentSaveFlags flags) { - g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail (doc->priv->uri != NULL); + g_return_if_fail (XED_IS_DOCUMENT (doc)); + g_return_if_fail (doc->priv->uri != NULL); - g_signal_emit (doc, - document_signals[SAVE], - 0, - doc->priv->uri, - doc->priv->encoding, - flags); + g_signal_emit (doc, document_signals[SAVE], 0, doc->priv->uri, doc->priv->encoding, flags); } /** @@ -1607,76 +1577,69 @@ xed_document_save (XedDocument *doc, */ void xed_document_save_as (XedDocument *doc, - const gchar *uri, - const XedEncoding *encoding, - XedDocumentSaveFlags flags) + const gchar *uri, + const XedEncoding *encoding, + XedDocumentSaveFlags flags) { - g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail (uri != NULL); - g_return_if_fail (encoding != NULL); + g_return_if_fail (XED_IS_DOCUMENT (doc)); + g_return_if_fail (uri != NULL); + g_return_if_fail (encoding != NULL); - /* priv->mtime refers to the the old uri (if any). Thus, it should be - * ignored when saving as. */ - g_signal_emit (doc, - document_signals[SAVE], - 0, - uri, - encoding, - flags | XED_DOCUMENT_SAVE_IGNORE_MTIME); + /* priv->mtime refers to the the old uri (if any). Thus, it should be + * ignored when saving as. */ + g_signal_emit (doc, document_signals[SAVE], 0, uri, encoding, flags | XED_DOCUMENT_SAVE_IGNORE_MTIME); } gboolean xed_document_insert_file (XedDocument *doc, - GtkTextIter *iter, - const gchar *uri, - const XedEncoding *encoding) + GtkTextIter *iter, + const gchar *uri, + const XedEncoding *encoding) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - g_return_val_if_fail (iter != NULL, FALSE); - g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == - GTK_TEXT_BUFFER (doc), FALSE); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); + g_return_val_if_fail (iter != NULL, FALSE); + g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == GTK_TEXT_BUFFER (doc), FALSE); - /* TODO */ + /* TODO */ - return FALSE; + return FALSE; } -gboolean +gboolean xed_document_is_untouched (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), TRUE); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), TRUE); - return (doc->priv->uri == NULL) && - (!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc))); + return (doc->priv->uri == NULL) && (!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc))); } -gboolean +gboolean xed_document_is_untitled (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), TRUE); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), TRUE); - return (doc->priv->uri == NULL); + return (doc->priv->uri == NULL); } gboolean xed_document_is_local (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - if (doc->priv->uri == NULL) - { - return FALSE; - } + if (doc->priv->uri == NULL) + { + return FALSE; + } - return xed_utils_uri_has_file_scheme (doc->priv->uri); + return xed_utils_uri_has_file_scheme (doc->priv->uri); } gboolean xed_document_get_deleted (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - return doc->priv->uri && !xed_utils_uri_exists (doc->priv->uri); + return doc->priv->uri && !xed_utils_uri_exists (doc->priv->uri); } /* @@ -1684,97 +1647,92 @@ xed_document_get_deleted (XedDocument *doc) * to the last line and FALSE is returned. */ gboolean -xed_document_goto_line (XedDocument *doc, - gint line) +xed_document_goto_line (XedDocument *doc, + gint line) { - gboolean ret = TRUE; - guint line_count; - GtkTextIter iter; + gboolean ret = TRUE; + guint line_count; + GtkTextIter iter; - xed_debug (DEBUG_DOCUMENT); + xed_debug (DEBUG_DOCUMENT); - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - g_return_val_if_fail (line >= -1, FALSE); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); + g_return_val_if_fail (line >= -1, FALSE); - line_count = gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (doc)); + line_count = gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (doc)); - if (line >= line_count) - { - ret = FALSE; - gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), - &iter); - } - else - { - gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (doc), - &iter, - line); - } + if (line >= line_count) + { + ret = FALSE; + gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &iter); + } + else + { + gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (doc), &iter, line); + } - gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter); + gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter); - return ret; + return ret; } gboolean xed_document_goto_line_offset (XedDocument *doc, - gint line, - gint line_offset) + gint line, + gint line_offset) { - gboolean ret = TRUE; - guint offset_count; - GtkTextIter iter; - - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - g_return_val_if_fail (line >= -1, FALSE); - g_return_val_if_fail (line_offset >= -1, FALSE); - - gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (doc), - &iter, - line); + gboolean ret = TRUE; + guint offset_count; + GtkTextIter iter; - offset_count = gtk_text_iter_get_chars_in_line (&iter); - if (line_offset > offset_count) - { - ret = FALSE; - } - else - { - gtk_text_iter_set_line_offset (&iter, line_offset); - } - - gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); + g_return_val_if_fail (line >= -1, FALSE); + g_return_val_if_fail (line_offset >= -1, FALSE); - return ret; + gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (doc), &iter, line); + + offset_count = gtk_text_iter_get_chars_in_line (&iter); + if (line_offset > offset_count) + { + ret = FALSE; + } + else + { + gtk_text_iter_set_line_offset (&iter, line_offset); + } + + gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter); + + return ret; } static gint compute_num_of_lines (const gchar *text) { - const gchar *p; - gint len; - gint n = 1; + const gchar *p; + gint len; + gint n = 1; - g_return_val_if_fail (text != NULL, 0); + g_return_val_if_fail (text != NULL, 0); - len = strlen (text); - p = text; + len = strlen (text); + p = text; - while (len > 0) - { - gint del, par; + while (len > 0) + { + gint del, par; - pango_find_paragraph_boundary (p, len, &del, &par); + pango_find_paragraph_boundary (p, len, &del, &par); - if (del == par) /* not found */ - break; + if (del == par) /* not found */ + break; - p += par; - len -= par; - ++n; - } + p += par; + len -= par; + ++n; + } - return n; + return n; } /** @@ -1785,64 +1743,63 @@ compute_num_of_lines (const gchar *text) **/ void xed_document_set_search_text (XedDocument *doc, - const gchar *text, - guint flags) + const gchar *text, + guint flags) { - gchar *converted_text; - gboolean notify = FALSE; - gboolean update_to_search_region = FALSE; - - g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail ((text == NULL) || (doc->priv->search_text != text)); - g_return_if_fail ((text == NULL) || g_utf8_validate (text, -1, NULL)); + gchar *converted_text; + gboolean notify = FALSE; + gboolean update_to_search_region = FALSE; - xed_debug_message (DEBUG_DOCUMENT, "text = %s", text); + g_return_if_fail (XED_IS_DOCUMENT (doc)); + g_return_if_fail ((text == NULL) || (doc->priv->search_text != text)); + g_return_if_fail ((text == NULL) || g_utf8_validate (text, -1, NULL)); - if (text != NULL) - { - if (*text != '\0') - { - converted_text = xed_utils_unescape_search_text (text); - notify = !xed_document_get_can_search_again (doc); - } - else - { - converted_text = g_strdup(""); - notify = xed_document_get_can_search_again (doc); - } - - g_free (doc->priv->search_text); - - doc->priv->search_text = converted_text; - doc->priv->num_of_lines_search_text = compute_num_of_lines (doc->priv->search_text); - update_to_search_region = TRUE; - } - - if (!XED_SEARCH_IS_DONT_SET_FLAGS (flags)) - { - if (doc->priv->search_flags != flags) - update_to_search_region = TRUE; - - doc->priv->search_flags = flags; + xed_debug_message (DEBUG_DOCUMENT, "text = %s", text); - } + if (text != NULL) + { + if (*text != '\0') + { + converted_text = xed_utils_unescape_search_text (text); + notify = !xed_document_get_can_search_again (doc); + } + else + { + converted_text = g_strdup(""); + notify = xed_document_get_can_search_again (doc); + } - if (update_to_search_region) - { - GtkTextIter begin; - GtkTextIter end; - - gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), - &begin, - &end); - - to_search_region_range (doc, - &begin, - &end); - } - - if (notify) - g_object_notify (G_OBJECT (doc), "can-search-again"); + g_free (doc->priv->search_text); + + doc->priv->search_text = converted_text; + doc->priv->num_of_lines_search_text = compute_num_of_lines (doc->priv->search_text); + update_to_search_region = TRUE; + } + + if (!XED_SEARCH_IS_DONT_SET_FLAGS (flags)) + { + if (doc->priv->search_flags != flags) + { + update_to_search_region = TRUE; + } + + doc->priv->search_flags = flags; + + } + + if (update_to_search_region) + { + GtkTextIter begin; + GtkTextIter end; + + gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &begin, &end); + to_search_region_range (doc, &begin, &end); + } + + if (notify) + { + g_object_notify (G_OBJECT (doc), "can-search-again"); + } } /** @@ -1852,23 +1809,24 @@ xed_document_set_search_text (XedDocument *doc, */ gchar * xed_document_get_search_text (XedDocument *doc, - guint *flags) + guint *flags) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - if (flags != NULL) - *flags = doc->priv->search_flags; + if (flags != NULL) + { + *flags = doc->priv->search_flags; + } - return xed_utils_escape_search_text (doc->priv->search_text); + return xed_utils_escape_search_text (doc->priv->search_text); } gboolean xed_document_get_can_search_again (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - return ((doc->priv->search_text != NULL) && - (*doc->priv->search_text != '\0')); + return ((doc->priv->search_text != NULL) && (*doc->priv->search_text != '\0')); } /** @@ -1880,72 +1838,80 @@ xed_document_get_can_search_again (XedDocument *doc) * @match_end: (allow=none): **/ gboolean -xed_document_search_forward (XedDocument *doc, - const GtkTextIter *start, - const GtkTextIter *end, - GtkTextIter *match_start, - GtkTextIter *match_end) +xed_document_search_forward (XedDocument *doc, + const GtkTextIter *start, + const GtkTextIter *end, + GtkTextIter *match_start, + GtkTextIter *match_end) { - GtkTextIter iter; - GtkTextSearchFlags search_flags; - gboolean found = FALSE; - GtkTextIter m_start; - GtkTextIter m_end; - - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - g_return_val_if_fail ((start == NULL) || - (gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc)), FALSE); - g_return_val_if_fail ((end == NULL) || - (gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc)), FALSE); - - if (doc->priv->search_text == NULL) - { - xed_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == NULL\n"); - return FALSE; - } - else - xed_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == \"%s\"\n", doc->priv->search_text); - - if (start == NULL) - gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (doc), &iter); - else - iter = *start; + GtkTextIter iter; + GtkTextSearchFlags search_flags; + gboolean found = FALSE; + GtkTextIter m_start; + GtkTextIter m_end; - search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY; + g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); + g_return_val_if_fail ((start == NULL) || (gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc)), FALSE); + g_return_val_if_fail ((end == NULL) || (gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc)), FALSE); - if (!XED_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags)) - { - search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE; - } - - while (!found) - { - found = gtk_text_iter_forward_search (&iter, - doc->priv->search_text, - search_flags, - &m_start, - &m_end, - end); - - if (found && XED_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags)) - { - found = gtk_text_iter_starts_word (&m_start) && - gtk_text_iter_ends_word (&m_end); + if (doc->priv->search_text == NULL) + { + xed_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == NULL\n"); + return FALSE; + } + else + xed_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == \"%s\"\n", doc->priv->search_text); - if (!found) - iter = m_end; - } - else - break; - } - - if (found && (match_start != NULL)) - *match_start = m_start; - - if (found && (match_end != NULL)) - *match_end = m_end; - - return found; + if (start == NULL) + { + gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (doc), &iter); + } + else + { + iter = *start; + } + + search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY; + + if (!XED_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags)) + { + search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE; + } + + while (!found) + { + found = gtk_text_iter_forward_search (&iter, + doc->priv->search_text, + search_flags, + &m_start, + &m_end, + end); + + if (found && XED_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags)) + { + found = gtk_text_iter_starts_word (&m_start) && gtk_text_iter_ends_word (&m_end); + + if (!found) + { + iter = m_end; + } + } + else + { + break; + } + } + + if (found && (match_start != NULL)) + { + *match_start = m_start; + } + if (found && (match_end != NULL)) + { + *match_end = m_end; + } + + return found; } /** @@ -1957,190 +1923,197 @@ xed_document_search_forward (XedDocument *doc, * @match_end: (allow=none): **/ gboolean -xed_document_search_backward (XedDocument *doc, - const GtkTextIter *start, - const GtkTextIter *end, - GtkTextIter *match_start, - GtkTextIter *match_end) +xed_document_search_backward (XedDocument *doc, + const GtkTextIter *start, + const GtkTextIter *end, + GtkTextIter *match_start, + GtkTextIter *match_end) { - GtkTextIter iter; - GtkTextSearchFlags search_flags; - gboolean found = FALSE; - GtkTextIter m_start; - GtkTextIter m_end; - - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - g_return_val_if_fail ((start == NULL) || - (gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc)), FALSE); - g_return_val_if_fail ((end == NULL) || - (gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc)), FALSE); - - if (doc->priv->search_text == NULL) - { - xed_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == NULL\n"); - return FALSE; - } - else - xed_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == \"%s\"\n", doc->priv->search_text); - - if (end == NULL) - gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &iter); - else - iter = *end; + GtkTextIter iter; + GtkTextSearchFlags search_flags; + gboolean found = FALSE; + GtkTextIter m_start; + GtkTextIter m_end; - search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY; + g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); + g_return_val_if_fail ((start == NULL) || (gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc)), FALSE); + g_return_val_if_fail ((end == NULL) || (gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc)), FALSE); - if (!XED_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags)) - { - search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE; - } + if (doc->priv->search_text == NULL) + { + xed_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == NULL\n"); + return FALSE; + } + else + { + xed_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == \"%s\"\n", doc->priv->search_text); + } - while (!found) - { - found = gtk_text_iter_backward_search (&iter, - doc->priv->search_text, - search_flags, - &m_start, - &m_end, - start); - - if (found && XED_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags)) - { - found = gtk_text_iter_starts_word (&m_start) && - gtk_text_iter_ends_word (&m_end); + if (end == NULL) + { + gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &iter); + } + else + { + iter = *end; + } - if (!found) - iter = m_start; - } - else - break; - } - - if (found && (match_start != NULL)) - *match_start = m_start; - - if (found && (match_end != NULL)) - *match_end = m_end; - - return found; + search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY; + + if (!XED_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags)) + { + search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE; + } + + while (!found) + { + found = gtk_text_iter_backward_search (&iter, + doc->priv->search_text, + search_flags, + &m_start, + &m_end, + start); + + if (found && XED_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags)) + { + found = gtk_text_iter_starts_word (&m_start) && gtk_text_iter_ends_word (&m_end); + + if (!found) + { + iter = m_start; + } + } + else + { + break; + } + } + + if (found && (match_start != NULL)) + { + *match_start = m_start; + } + if (found && (match_end != NULL)) + { + *match_end = m_end; + } + + return found; } /* FIXME this is an issue for introspection regardning @find */ -gint -xed_document_replace_all (XedDocument *doc, - const gchar *find, - const gchar *replace, - guint flags) +gint +xed_document_replace_all (XedDocument *doc, + const gchar *find, + const gchar *replace, + guint flags) { - GtkTextIter iter; - GtkTextIter m_start; - GtkTextIter m_end; - GtkTextSearchFlags search_flags = 0; - gboolean found = TRUE; - gint cont = 0; - gchar *search_text; - gchar *replace_text; - gint replace_text_len; - GtkTextBuffer *buffer; - gboolean brackets_highlighting; - gboolean search_highliting; + GtkTextIter iter; + GtkTextIter m_start; + GtkTextIter m_end; + GtkTextSearchFlags search_flags = 0; + gboolean found = TRUE; + gint cont = 0; + gchar *search_text; + gchar *replace_text; + gint replace_text_len; + GtkTextBuffer *buffer; + gboolean brackets_highlighting; + gboolean search_highliting; - g_return_val_if_fail (XED_IS_DOCUMENT (doc), 0); - g_return_val_if_fail (replace != NULL, 0); - g_return_val_if_fail ((find != NULL) || (doc->priv->search_text != NULL), 0); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), 0); + g_return_val_if_fail (replace != NULL, 0); + g_return_val_if_fail ((find != NULL) || (doc->priv->search_text != NULL), 0); - buffer = GTK_TEXT_BUFFER (doc); + buffer = GTK_TEXT_BUFFER (doc); - if (find == NULL) - search_text = g_strdup (doc->priv->search_text); - else - search_text = xed_utils_unescape_search_text (find); + if (find == NULL) + { + search_text = g_strdup (doc->priv->search_text); + } + else + { + search_text = xed_utils_unescape_search_text (find); + } - replace_text = xed_utils_unescape_search_text (replace); + replace_text = xed_utils_unescape_search_text (replace); - gtk_text_buffer_get_start_iter (buffer, &iter); + gtk_text_buffer_get_start_iter (buffer, &iter); - search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY; + search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY; - if (!XED_SEARCH_IS_CASE_SENSITIVE (flags)) - { - search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE; - } + if (!XED_SEARCH_IS_CASE_SENSITIVE (flags)) + { + search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE; + } - replace_text_len = strlen (replace_text); + replace_text_len = strlen (replace_text); - /* disable cursor_moved emission until the end of the - * replace_all so that we don't spend all the time - * updating the position in the statusbar - */ - doc->priv->stop_cursor_moved_emission = TRUE; + /* disable cursor_moved emission until the end of the + * replace_all so that we don't spend all the time + * updating the position in the statusbar + */ + doc->priv->stop_cursor_moved_emission = TRUE; - /* also avoid spending time matching brackets */ - brackets_highlighting = gtk_source_buffer_get_highlight_matching_brackets (GTK_SOURCE_BUFFER (buffer)); - gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (buffer), FALSE); + /* also avoid spending time matching brackets */ + brackets_highlighting = gtk_source_buffer_get_highlight_matching_brackets (GTK_SOURCE_BUFFER (buffer)); + gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (buffer), FALSE); - /* and do search highliting later */ - search_highliting = xed_document_get_enable_search_highlighting (doc); - xed_document_set_enable_search_highlighting (doc, FALSE); + /* and do search highliting later */ + search_highliting = xed_document_get_enable_search_highlighting (doc); + xed_document_set_enable_search_highlighting (doc, FALSE); - gtk_text_buffer_begin_user_action (buffer); + gtk_text_buffer_begin_user_action (buffer); - do - { - found = gtk_text_iter_forward_search (&iter, - search_text, - search_flags, - &m_start, - &m_end, - NULL); + do + { + found = gtk_text_iter_forward_search (&iter, + search_text, + search_flags, + &m_start, + &m_end, + NULL); - if (found && XED_SEARCH_IS_ENTIRE_WORD (flags)) - { - gboolean word; + if (found && XED_SEARCH_IS_ENTIRE_WORD (flags)) + { + gboolean word; - word = gtk_text_iter_starts_word (&m_start) && - gtk_text_iter_ends_word (&m_end); + word = gtk_text_iter_starts_word (&m_start) && gtk_text_iter_ends_word (&m_end); - if (!word) - { - iter = m_end; - continue; - } - } + if (!word) + { + iter = m_end; + continue; + } + } - if (found) - { - ++cont; + if (found) + { + ++cont; - gtk_text_buffer_delete (buffer, - &m_start, - &m_end); - gtk_text_buffer_insert (buffer, - &m_start, - replace_text, - replace_text_len); + gtk_text_buffer_delete (buffer, &m_start, &m_end); + gtk_text_buffer_insert (buffer, &m_start, replace_text, replace_text_len); - iter = m_start; - } + iter = m_start; + } - } while (found); + } while (found); - gtk_text_buffer_end_user_action (buffer); + gtk_text_buffer_end_user_action (buffer); - /* re-enable cursor_moved emission and notify - * the current position - */ - doc->priv->stop_cursor_moved_emission = FALSE; - emit_cursor_moved (doc); + /* re-enable cursor_moved emission and notify + * the current position + */ + doc->priv->stop_cursor_moved_emission = FALSE; + emit_cursor_moved (doc); - gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (buffer), - brackets_highlighting); - xed_document_set_enable_search_highlighting (doc, search_highliting); + gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (buffer), brackets_highlighting); + xed_document_set_enable_search_highlighting (doc, search_highliting); - g_free (search_text); - g_free (replace_text); + g_free (search_text); + g_free (replace_text); - return cont; + return cont; } /** @@ -2149,535 +2122,509 @@ xed_document_replace_all (XedDocument *doc, * @lang: (allow-none): **/ void -xed_document_set_language (XedDocument *doc, - GtkSourceLanguage *lang) +xed_document_set_language (XedDocument *doc, + GtkSourceLanguage *lang) { - g_return_if_fail (XED_IS_DOCUMENT (doc)); + g_return_if_fail (XED_IS_DOCUMENT (doc)); - set_language (doc, lang, TRUE); + set_language (doc, lang, TRUE); } GtkSourceLanguage * xed_document_get_language (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - return gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (doc)); + return gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (doc)); } const XedEncoding * xed_document_get_encoding (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - return doc->priv->encoding; + return doc->priv->encoding; } glong _xed_document_get_seconds_since_last_save_or_load (XedDocument *doc) { - GTimeVal current_time; + GTimeVal current_time; - xed_debug (DEBUG_DOCUMENT); - - g_return_val_if_fail (XED_IS_DOCUMENT (doc), -1); + xed_debug (DEBUG_DOCUMENT); - g_get_current_time (¤t_time); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), -1); - return (current_time.tv_sec - doc->priv->time_of_last_save_or_load.tv_sec); + g_get_current_time (¤t_time); + + return (current_time.tv_sec - doc->priv->time_of_last_save_or_load.tv_sec); } static void get_search_match_colors (XedDocument *doc, - gboolean *foreground_set, - GdkColor *foreground, - gboolean *background_set, - GdkColor *background) + gboolean *foreground_set, + GdkColor *foreground, + gboolean *background_set, + GdkColor *background) { - GtkSourceStyleScheme *style_scheme; - GtkSourceStyle *style; - gchar *bg; - gchar *fg; + GtkSourceStyleScheme *style_scheme; + GtkSourceStyle *style; + gchar *bg; + gchar *fg; - style_scheme = gtk_source_buffer_get_style_scheme (GTK_SOURCE_BUFFER (doc)); - if (style_scheme == NULL) - goto fallback; + style_scheme = gtk_source_buffer_get_style_scheme (GTK_SOURCE_BUFFER (doc)); + if (style_scheme == NULL) + { + goto fallback; + } - style = gtk_source_style_scheme_get_style (style_scheme, - "search-match"); - if (style == NULL) - goto fallback; + style = gtk_source_style_scheme_get_style (style_scheme, "search-match"); + if (style == NULL) + { + goto fallback; + } - g_object_get (style, - "foreground-set", foreground_set, - "foreground", &fg, - "background-set", background_set, - "background", &bg, - NULL); + g_object_get (style, + "foreground-set", foreground_set, + "foreground", &fg, + "background-set", background_set, + "background", &bg, + NULL); - if (*foreground_set) - { - if (fg == NULL || - !gdk_color_parse (fg, foreground)) - { - *foreground_set = FALSE; - } - } + if (*foreground_set) + { + if (fg == NULL || !gdk_color_parse (fg, foreground)) + { + *foreground_set = FALSE; + } + } - if (*background_set) - { - if (bg == NULL || - !gdk_color_parse (bg, background)) - { - *background_set = FALSE; - } - } + if (*background_set) + { + if (bg == NULL || !gdk_color_parse (bg, background)) + { + *background_set = FALSE; + } + } - g_free (fg); - g_free (bg); + g_free (fg); + g_free (bg); - return; + return; fallback: - xed_debug_message (DEBUG_DOCUMENT, - "Falling back to hard-coded colors " - "for the \"found\" text tag."); + xed_debug_message (DEBUG_DOCUMENT, + "Falling back to hard-coded colors " + "for the \"found\" text tag."); - gdk_color_parse ("#FFFF78", background); - *background_set = TRUE; - *foreground_set = FALSE; + gdk_color_parse ("#FFFF78", background); + *background_set = TRUE; + *foreground_set = FALSE; - return; + return; } static void sync_found_tag (XedDocument *doc, - GParamSpec *pspec, - gpointer data) + GParamSpec *pspec, + gpointer data) { - GdkColor fg; - GdkColor bg; - gboolean fg_set; - gboolean bg_set; + GdkColor fg; + GdkColor bg; + gboolean fg_set; + gboolean bg_set; - xed_debug (DEBUG_DOCUMENT); + xed_debug (DEBUG_DOCUMENT); - g_return_if_fail (GTK_TEXT_TAG (doc->priv->found_tag)); + g_return_if_fail (GTK_TEXT_TAG (doc->priv->found_tag)); - get_search_match_colors (doc, - &fg_set, &fg, - &bg_set, &bg); + get_search_match_colors (doc, &fg_set, &fg, &bg_set, &bg); - g_object_set (doc->priv->found_tag, - "foreground-gdk", fg_set ? &fg : NULL, - NULL); - g_object_set (doc->priv->found_tag, - "background-gdk", bg_set ? &bg : NULL, - NULL); + g_object_set (doc->priv->found_tag, "foreground-gdk", fg_set ? &fg : NULL, NULL); + g_object_set (doc->priv->found_tag, "background-gdk", bg_set ? &bg : NULL, NULL); } static void text_tag_set_highest_priority (GtkTextTag *tag, - GtkTextBuffer *buffer) + GtkTextBuffer *buffer) { - GtkTextTagTable *table; - gint n; + GtkTextTagTable *table; + gint n; - table = gtk_text_buffer_get_tag_table (buffer); - n = gtk_text_tag_table_get_size (table); - gtk_text_tag_set_priority (tag, n - 1); + table = gtk_text_buffer_get_tag_table (buffer); + n = gtk_text_tag_table_get_size (table); + gtk_text_tag_set_priority (tag, n - 1); } static void search_region (XedDocument *doc, - GtkTextIter *start, - GtkTextIter *end) + GtkTextIter *start, + GtkTextIter *end) { - GtkTextIter iter; - GtkTextIter m_start; - GtkTextIter m_end; - GtkTextSearchFlags search_flags = 0; - gboolean found = TRUE; + GtkTextIter iter; + GtkTextIter m_start; + GtkTextIter m_end; + GtkTextSearchFlags search_flags = 0; + gboolean found = TRUE; - GtkTextBuffer *buffer; + GtkTextBuffer *buffer; - xed_debug (DEBUG_DOCUMENT); - - buffer = GTK_TEXT_BUFFER (doc); - - if (doc->priv->found_tag == NULL) - { - doc->priv->found_tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (doc), - "found", - NULL); + xed_debug (DEBUG_DOCUMENT); - sync_found_tag (doc, NULL, NULL); + buffer = GTK_TEXT_BUFFER (doc); - g_signal_connect (doc, - "notify::style-scheme", - G_CALLBACK (sync_found_tag), - NULL); - } + if (doc->priv->found_tag == NULL) + { + doc->priv->found_tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (doc), "found", NULL); - /* make sure the 'found' tag has the priority over - * syntax highlighting tags */ - text_tag_set_highest_priority (doc->priv->found_tag, - GTK_TEXT_BUFFER (doc)); - + sync_found_tag (doc, NULL, NULL); - if (doc->priv->search_text == NULL) - return; + g_signal_connect (doc, "notify::style-scheme", G_CALLBACK (sync_found_tag), NULL); + } - g_return_if_fail (doc->priv->num_of_lines_search_text > 0); + /* make sure the 'found' tag has the priority over + * syntax highlighting tags */ + text_tag_set_highest_priority (doc->priv->found_tag, GTK_TEXT_BUFFER (doc)); - gtk_text_iter_backward_lines (start, doc->priv->num_of_lines_search_text); - gtk_text_iter_forward_lines (end, doc->priv->num_of_lines_search_text); - if (gtk_text_iter_has_tag (start, doc->priv->found_tag) && - !gtk_text_iter_begins_tag (start, doc->priv->found_tag)) - gtk_text_iter_backward_to_tag_toggle (start, doc->priv->found_tag); + if (doc->priv->search_text == NULL) + { + return; + } - if (gtk_text_iter_has_tag (end, doc->priv->found_tag) && - !gtk_text_iter_ends_tag (end, doc->priv->found_tag)) - gtk_text_iter_forward_to_tag_toggle (end, doc->priv->found_tag); + g_return_if_fail (doc->priv->num_of_lines_search_text > 0); - /* - g_print ("[%u (%u), %u (%u)]\n", gtk_text_iter_get_line (start), gtk_text_iter_get_offset (start), - gtk_text_iter_get_line (end), gtk_text_iter_get_offset (end)); - */ + gtk_text_iter_backward_lines (start, doc->priv->num_of_lines_search_text); + gtk_text_iter_forward_lines (end, doc->priv->num_of_lines_search_text); - gtk_text_buffer_remove_tag (buffer, - doc->priv->found_tag, - start, - end); + if (gtk_text_iter_has_tag (start, doc->priv->found_tag) && + !gtk_text_iter_begins_tag (start, doc->priv->found_tag)) + { + gtk_text_iter_backward_to_tag_toggle (start, doc->priv->found_tag); + } + if (gtk_text_iter_has_tag (end, doc->priv->found_tag) && + !gtk_text_iter_ends_tag (end, doc->priv->found_tag)) + { + gtk_text_iter_forward_to_tag_toggle (end, doc->priv->found_tag); + } + /* + g_print ("[%u (%u), %u (%u)]\n", gtk_text_iter_get_line (start), gtk_text_iter_get_offset (start), + gtk_text_iter_get_line (end), gtk_text_iter_get_offset (end)); + */ - if (*doc->priv->search_text == '\0') - return; + gtk_text_buffer_remove_tag (buffer, doc->priv->found_tag, start, end); - iter = *start; + if (*doc->priv->search_text == '\0') + { + return; + } - search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY; + iter = *start; - if (!XED_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags)) - { - search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE; - } - - do - { - if ((end != NULL) && gtk_text_iter_is_end (end)) - end = NULL; - - found = gtk_text_iter_forward_search (&iter, - doc->priv->search_text, - search_flags, - &m_start, - &m_end, - end); - - iter = m_end; - - if (found && XED_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags)) - { - gboolean word; - - word = gtk_text_iter_starts_word (&m_start) && - gtk_text_iter_ends_word (&m_end); - - if (!word) - continue; - } + search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY; - if (found) - { - gtk_text_buffer_apply_tag (buffer, - doc->priv->found_tag, - &m_start, - &m_end); - } + if (!XED_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags)) + { + search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE; + } - } while (found); + do + { + if ((end != NULL) && gtk_text_iter_is_end (end)) + { + end = NULL; + } + + found = gtk_text_iter_forward_search (&iter, + doc->priv->search_text, + search_flags, + &m_start, + &m_end, + end); + + iter = m_end; + + if (found && XED_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags)) + { + gboolean word; + + word = gtk_text_iter_starts_word (&m_start) && gtk_text_iter_ends_word (&m_end); + + if (!word) + { + continue; + } + } + + if (found) + { + gtk_text_buffer_apply_tag (buffer, doc->priv->found_tag, &m_start, &m_end); + } + + } while (found); } static void to_search_region_range (XedDocument *doc, - GtkTextIter *start, - GtkTextIter *end) + GtkTextIter *start, + GtkTextIter *end) { - xed_debug (DEBUG_DOCUMENT); - - if (doc->priv->to_search_region == NULL) - return; - - gtk_text_iter_set_line_offset (start, 0); - gtk_text_iter_forward_to_line_end (end); - - /* - g_print ("+ [%u (%u), %u (%u)]\n", gtk_text_iter_get_line (start), gtk_text_iter_get_offset (start), - gtk_text_iter_get_line (end), gtk_text_iter_get_offset (end)); - */ + xed_debug (DEBUG_DOCUMENT); - /* Add the region to the refresh region */ - xed_text_region_add (doc->priv->to_search_region, start, end); + if (doc->priv->to_search_region == NULL) + { + return; + } - /* Notify views of the updated highlight region */ - gtk_text_iter_backward_lines (start, doc->priv->num_of_lines_search_text); - gtk_text_iter_forward_lines (end, doc->priv->num_of_lines_search_text); - - g_signal_emit (doc, document_signals [SEARCH_HIGHLIGHT_UPDATED], 0, start, end); + gtk_text_iter_set_line_offset (start, 0); + gtk_text_iter_forward_to_line_end (end); + + /* + g_print ("+ [%u (%u), %u (%u)]\n", gtk_text_iter_get_line (start), gtk_text_iter_get_offset (start), + gtk_text_iter_get_line (end), gtk_text_iter_get_offset (end)); + */ + + /* Add the region to the refresh region */ + xed_text_region_add (doc->priv->to_search_region, start, end); + + /* Notify views of the updated highlight region */ + gtk_text_iter_backward_lines (start, doc->priv->num_of_lines_search_text); + gtk_text_iter_forward_lines (end, doc->priv->num_of_lines_search_text); + + g_signal_emit (doc, document_signals [SEARCH_HIGHLIGHT_UPDATED], 0, start, end); } void -_xed_document_search_region (XedDocument *doc, - const GtkTextIter *start, - const GtkTextIter *end) +_xed_document_search_region (XedDocument *doc, + const GtkTextIter *start, + const GtkTextIter *end) { - XedTextRegion *region; + XedTextRegion *region; - xed_debug (DEBUG_DOCUMENT); - - g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail (start != NULL); - g_return_if_fail (end != NULL); - - if (doc->priv->to_search_region == NULL) - return; + xed_debug (DEBUG_DOCUMENT); - /* - g_print ("U [%u (%u), %u (%u)]\n", gtk_text_iter_get_line (start), gtk_text_iter_get_offset (start), - gtk_text_iter_get_line (end), gtk_text_iter_get_offset (end)); - */ - - /* get the subregions not yet highlighted */ - region = xed_text_region_intersect (doc->priv->to_search_region, - start, - end); - if (region) - { - gint i; - GtkTextIter start_search; - GtkTextIter end_search; + g_return_if_fail (XED_IS_DOCUMENT (doc)); + g_return_if_fail (start != NULL); + g_return_if_fail (end != NULL); - i = xed_text_region_subregions (region); - xed_text_region_nth_subregion (region, - 0, - &start_search, - NULL); + if (doc->priv->to_search_region == NULL) + { + return; + } - xed_text_region_nth_subregion (region, - i - 1, - NULL, - &end_search); + /* + g_print ("U [%u (%u), %u (%u)]\n", gtk_text_iter_get_line (start), gtk_text_iter_get_offset (start), + gtk_text_iter_get_line (end), gtk_text_iter_get_offset (end)); + */ - xed_text_region_destroy (region, TRUE); + /* get the subregions not yet highlighted */ + region = xed_text_region_intersect (doc->priv->to_search_region, start, end); + if (region) + { + gint i; + GtkTextIter start_search; + GtkTextIter end_search; - gtk_text_iter_order (&start_search, &end_search); + i = xed_text_region_subregions (region); + xed_text_region_nth_subregion (region, 0, &start_search, NULL); + xed_text_region_nth_subregion (region, i - 1, NULL, &end_search); - search_region (doc, &start_search, &end_search); + xed_text_region_destroy (region, TRUE); - /* remove the just highlighted region */ - xed_text_region_subtract (doc->priv->to_search_region, - start, - end); - } + gtk_text_iter_order (&start_search, &end_search); + + search_region (doc, &start_search, &end_search); + + /* remove the just highlighted region */ + xed_text_region_subtract (doc->priv->to_search_region, start, end); + } } static void -insert_text_cb (XedDocument *doc, - GtkTextIter *pos, - const gchar *text, - gint length) +insert_text_cb (XedDocument *doc, + GtkTextIter *pos, + const gchar *text, + gint length) { - GtkTextIter start; - GtkTextIter end; + GtkTextIter start; + GtkTextIter end; - xed_debug (DEBUG_DOCUMENT); - - start = end = *pos; + xed_debug (DEBUG_DOCUMENT); - /* - * pos is invalidated when - * insertion occurs (because the buffer contents change), but the - * default signal handler revalidates it to point to the end of the - * inserted text - */ - gtk_text_iter_backward_chars (&start, - g_utf8_strlen (text, length)); - - to_search_region_range (doc, &start, &end); + start = end = *pos; + + /* + * pos is invalidated when + * insertion occurs (because the buffer contents change), but the + * default signal handler revalidates it to point to the end of the + * inserted text + */ + gtk_text_iter_backward_chars (&start, g_utf8_strlen (text, length)); + + to_search_region_range (doc, &start, &end); } - -static void -delete_range_cb (XedDocument *doc, - GtkTextIter *start, - GtkTextIter *end) -{ - GtkTextIter d_start; - GtkTextIter d_end; - xed_debug (DEBUG_DOCUMENT); - - d_start = *start; - d_end = *end; - - to_search_region_range (doc, &d_start, &d_end); +static void +delete_range_cb (XedDocument *doc, + GtkTextIter *start, + GtkTextIter *end) +{ + GtkTextIter d_start; + GtkTextIter d_end; + + xed_debug (DEBUG_DOCUMENT); + + d_start = *start; + d_end = *end; + + to_search_region_range (doc, &d_start, &d_end); } void xed_document_set_enable_search_highlighting (XedDocument *doc, - gboolean enable) + gboolean enable) { - g_return_if_fail (XED_IS_DOCUMENT (doc)); - - enable = enable != FALSE; - - if ((doc->priv->to_search_region != NULL) == enable) - return; - - if (doc->priv->to_search_region != NULL) - { - /* Disable search highlighting */ - if (doc->priv->found_tag != NULL) - { - /* If needed remove the found_tag */ - GtkTextIter begin; - GtkTextIter end; - - gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), - &begin, - &end); + g_return_if_fail (XED_IS_DOCUMENT (doc)); - gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (doc), - doc->priv->found_tag, - &begin, - &end); - } - - xed_text_region_destroy (doc->priv->to_search_region, - TRUE); - doc->priv->to_search_region = NULL; - } - else - { - doc->priv->to_search_region = xed_text_region_new (GTK_TEXT_BUFFER (doc)); - if (xed_document_get_can_search_again (doc)) - { - /* If search_text is not empty, highligth all its occurrences */ - GtkTextIter begin; - GtkTextIter end; - - gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), - &begin, - &end); - - to_search_region_range (doc, - &begin, - &end); - } - } + enable = enable != FALSE; + + if ((doc->priv->to_search_region != NULL) == enable) + { + return; + } + + if (doc->priv->to_search_region != NULL) + { + /* Disable search highlighting */ + if (doc->priv->found_tag != NULL) + { + /* If needed remove the found_tag */ + GtkTextIter begin; + GtkTextIter end; + + gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &begin, &end); + gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (doc), doc->priv->found_tag, &begin, &end); + } + + xed_text_region_destroy (doc->priv->to_search_region, TRUE); + doc->priv->to_search_region = NULL; + } + else + { + doc->priv->to_search_region = xed_text_region_new (GTK_TEXT_BUFFER (doc)); + if (xed_document_get_can_search_again (doc)) + { + /* If search_text is not empty, highligth all its occurrences */ + GtkTextIter begin; + GtkTextIter end; + + gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &begin, &end); + to_search_region_range (doc, &begin, &end); + } + } } gboolean xed_document_get_enable_search_highlighting (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - - return (doc->priv->to_search_region != NULL); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); + + return (doc->priv->to_search_region != NULL); } void xed_document_set_newline_type (XedDocument *doc, - XedDocumentNewlineType newline_type) + XedDocumentNewlineType newline_type) { - g_return_if_fail (XED_IS_DOCUMENT (doc)); + g_return_if_fail (XED_IS_DOCUMENT (doc)); - if (doc->priv->newline_type != newline_type) - { - doc->priv->newline_type = newline_type; - - g_object_notify (G_OBJECT (doc), "newline-type"); - } + if (doc->priv->newline_type != newline_type) + { + doc->priv->newline_type = newline_type; + g_object_notify (G_OBJECT (doc), "newline-type"); + } } XedDocumentNewlineType xed_document_get_newline_type (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), 0); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), 0); - return doc->priv->newline_type; + return doc->priv->newline_type; } void -_xed_document_set_mount_operation_factory (XedDocument *doc, - XedMountOperationFactory callback, - gpointer userdata) +_xed_document_set_mount_operation_factory (XedDocument *doc, + XedMountOperationFactory callback, + gpointer userdata) { - g_return_if_fail (XED_IS_DOCUMENT (doc)); - - doc->priv->mount_operation_factory = callback; - doc->priv->mount_operation_userdata = userdata; + g_return_if_fail (XED_IS_DOCUMENT (doc)); + + doc->priv->mount_operation_factory = callback; + doc->priv->mount_operation_userdata = userdata; } GMountOperation * _xed_document_create_mount_operation (XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - - if (doc->priv->mount_operation_factory == NULL) - return g_mount_operation_new (); - else - return doc->priv->mount_operation_factory (doc, - doc->priv->mount_operation_userdata); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + + if (doc->priv->mount_operation_factory == NULL) + { + return g_mount_operation_new (); + } + else + { + return doc->priv->mount_operation_factory (doc, doc->priv->mount_operation_userdata); + } } #ifndef ENABLE_GVFS_METADATA gchar * xed_document_get_metadata (XedDocument *doc, - const gchar *key) + const gchar *key) { - gchar *value = NULL; + gchar *value = NULL; - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - g_return_val_if_fail (key != NULL, NULL); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + g_return_val_if_fail (key != NULL, NULL); - if (!xed_document_is_untitled (doc)) - { - value = xed_metadata_manager_get (doc->priv->uri, key); - } + if (!xed_document_is_untitled (doc)) + { + value = xed_metadata_manager_get (doc->priv->uri, key); + } - return value; + return value; } void xed_document_set_metadata (XedDocument *doc, - const gchar *first_key, - ...) + const gchar *first_key, + ...) { - const gchar *key; - const gchar *value; - va_list var_args; + const gchar *key; + const gchar *value; + va_list var_args; - g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail (first_key != NULL); + g_return_if_fail (XED_IS_DOCUMENT (doc)); + g_return_if_fail (first_key != NULL); - if (xed_document_is_untitled (doc)) - { - /* Can't set metadata for untitled documents */ - return; - } + if (xed_document_is_untitled (doc)) + { + /* Can't set metadata for untitled documents */ + return; + } - va_start (var_args, first_key); + va_start (var_args, first_key); - for (key = first_key; key; key = va_arg (var_args, const gchar *)) - { - value = va_arg (var_args, const gchar *); - - xed_metadata_manager_set (doc->priv->uri, - key, - value); - } + for (key = first_key; key; key = va_arg (var_args, const gchar *)) + { + value = va_arg (var_args, const gchar *); - va_end (var_args); + xed_metadata_manager_set (doc->priv->uri, key, value); + } + + va_end (var_args); } #else @@ -2693,32 +2640,27 @@ xed_document_set_metadata (XedDocument *doc, */ gchar * xed_document_get_metadata (XedDocument *doc, - const gchar *key) + const gchar *key) { - gchar *value = NULL; + gchar *value = NULL; - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - g_return_val_if_fail (key != NULL, NULL); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + g_return_val_if_fail (key != NULL, NULL); - if (doc->priv->metadata_info && g_file_info_has_attribute (doc->priv->metadata_info, - key)) - { - value = g_strdup (g_file_info_get_attribute_string (doc->priv->metadata_info, - key)); - } + if (doc->priv->metadata_info && g_file_info_has_attribute (doc->priv->metadata_info, key)) + { + value = g_strdup (g_file_info_get_attribute_string (doc->priv->metadata_info, key)); + } - return value; + return value; } static void set_attributes_cb (GObject *source, - GAsyncResult *res, - gpointer useless) + GAsyncResult *res, + gpointer useless) { - g_file_set_attributes_finish (G_FILE (source), - res, - NULL, - NULL); + g_file_set_attributes_finish (G_FILE (source), res, NULL, NULL); } /** @@ -2732,60 +2674,59 @@ set_attributes_cb (GObject *source, */ void xed_document_set_metadata (XedDocument *doc, - const gchar *first_key, - ...) + const gchar *first_key, + ...) { - const gchar *key; - const gchar *value; - va_list var_args; - GFileInfo *info; - GFile *location; + const gchar *key; + const gchar *value; + va_list var_args; + GFileInfo *info; + GFile *location; - g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail (first_key != NULL); + g_return_if_fail (XED_IS_DOCUMENT (doc)); + g_return_if_fail (first_key != NULL); - info = g_file_info_new (); + info = g_file_info_new (); - va_start (var_args, first_key); + va_start (var_args, first_key); - for (key = first_key; key; key = va_arg (var_args, const gchar *)) - { - value = va_arg (var_args, const gchar *); - - if (value != NULL) - { - g_file_info_set_attribute_string (info, - key, value); - } - else - { - /* Unset the key */ - g_file_info_set_attribute (info, key, - G_FILE_ATTRIBUTE_TYPE_INVALID, - NULL); - } - } + for (key = first_key; key; key = va_arg (var_args, const gchar *)) + { + value = va_arg (var_args, const gchar *); - va_end (var_args); + if (value != NULL) + { + g_file_info_set_attribute_string (info, key, value); + } + else + { + /* Unset the key */ + g_file_info_set_attribute (info, key, G_FILE_ATTRIBUTE_TYPE_INVALID, NULL); + } + } - if (doc->priv->metadata_info != NULL) - g_file_info_copy_into (info, doc->priv->metadata_info); + va_end (var_args); - location = xed_document_get_location (doc); + if (doc->priv->metadata_info != NULL) + { + g_file_info_copy_into (info, doc->priv->metadata_info); + } - if (location != NULL) - { - g_file_set_attributes_async (location, - info, - G_FILE_QUERY_INFO_NONE, - G_PRIORITY_DEFAULT, - NULL, - set_attributes_cb, - NULL); + location = xed_document_get_location (doc); - g_object_unref (location); - } - - g_object_unref (info); + if (location != NULL) + { + g_file_set_attributes_async (location, + info, + G_FILE_QUERY_INFO_NONE, + G_PRIORITY_DEFAULT, + NULL, + set_attributes_cb, + NULL); + + g_object_unref (location); + } + + g_object_unref (info); } #endif From 21f524a7b364f50c052a0c32d439ff7ed161c2bd Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 12 Dec 2016 01:40:18 -0800 Subject: [PATCH 012/132] xed-document: Remove use of deprecated gdk_color_parse --- xed/xed-document.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/xed/xed-document.c b/xed/xed-document.c index 05c2da6..502631c 100644 --- a/xed/xed-document.c +++ b/xed/xed-document.c @@ -2163,9 +2163,9 @@ _xed_document_get_seconds_since_last_save_or_load (XedDocument *doc) static void get_search_match_colors (XedDocument *doc, gboolean *foreground_set, - GdkColor *foreground, + GdkRGBA *foreground, gboolean *background_set, - GdkColor *background) + GdkRGBA *background) { GtkSourceStyleScheme *style_scheme; GtkSourceStyle *style; @@ -2193,7 +2193,7 @@ get_search_match_colors (XedDocument *doc, if (*foreground_set) { - if (fg == NULL || !gdk_color_parse (fg, foreground)) + if (fg == NULL || !gdk_rgba_parse (foreground, fg)) { *foreground_set = FALSE; } @@ -2201,7 +2201,7 @@ get_search_match_colors (XedDocument *doc, if (*background_set) { - if (bg == NULL || !gdk_color_parse (bg, background)) + if (bg == NULL || !gdk_rgba_parse (background, bg)) { *background_set = FALSE; } @@ -2217,7 +2217,7 @@ get_search_match_colors (XedDocument *doc, "Falling back to hard-coded colors " "for the \"found\" text tag."); - gdk_color_parse ("#FFFF78", background); + gdk_rgba_parse (background, "#FFFF78"); *background_set = TRUE; *foreground_set = FALSE; @@ -2229,8 +2229,8 @@ sync_found_tag (XedDocument *doc, GParamSpec *pspec, gpointer data) { - GdkColor fg; - GdkColor bg; + GdkRGBA fg; + GdkRGBA bg; gboolean fg_set; gboolean bg_set; @@ -2240,8 +2240,8 @@ sync_found_tag (XedDocument *doc, get_search_match_colors (doc, &fg_set, &fg, &bg_set, &bg); - g_object_set (doc->priv->found_tag, "foreground-gdk", fg_set ? &fg : NULL, NULL); - g_object_set (doc->priv->found_tag, "background-gdk", bg_set ? &bg : NULL, NULL); + g_object_set (doc->priv->found_tag, "foreground-rgba", fg_set ? &fg : NULL, NULL); + g_object_set (doc->priv->found_tag, "background-rgba", bg_set ? &bg : NULL, NULL); } static void From 76ce469bfabbc867eb82bff770b7440d17b08cf6 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 12 Dec 2016 02:12:16 -0800 Subject: [PATCH 013/132] xed-documents-panel: Cleanup code styling --- xed/xed-documents-panel.c | 1053 +++++++++++++++++-------------------- 1 file changed, 488 insertions(+), 565 deletions(-) diff --git a/xed/xed-documents-panel.c b/xed/xed-documents-panel.c index c448f24..98aaa08 100644 --- a/xed/xed-documents-panel.c +++ b/xed/xed-documents-panel.c @@ -2,7 +2,7 @@ * xed-documents-panel.c * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -39,34 +39,34 @@ #include #define XED_DOCUMENTS_PANEL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ - XED_TYPE_DOCUMENTS_PANEL, \ - XedDocumentsPanelPrivate)) + XED_TYPE_DOCUMENTS_PANEL, \ + XedDocumentsPanelPrivate)) struct _XedDocumentsPanelPrivate { - XedWindow *window; + XedWindow *window; - GtkWidget *treeview; - GtkTreeModel *model; + GtkWidget *treeview; + GtkTreeModel *model; - guint adding_tab : 1; - guint is_reodering : 1; + guint adding_tab : 1; + guint is_reodering : 1; }; -G_DEFINE_TYPE(XedDocumentsPanel, xed_documents_panel, GTK_TYPE_BOX) +G_DEFINE_TYPE (XedDocumentsPanel, xed_documents_panel, GTK_TYPE_BOX) enum { - PROP_0, - PROP_WINDOW + PROP_0, + PROP_WINDOW }; enum { - PIXBUF_COLUMN, - NAME_COLUMN, - TAB_COLUMN, - N_COLUMNS + PIXBUF_COLUMN, + NAME_COLUMN, + TAB_COLUMN, + N_COLUMNS }; #define MAX_DOC_NAME_LENGTH 60 @@ -74,759 +74,682 @@ enum static gchar * tab_get_name (XedTab *tab) { - XedDocument *doc; - gchar *name; - gchar *docname; - gchar *tab_name; + XedDocument *doc; + gchar *name; + gchar *docname; + gchar *tab_name; - g_return_val_if_fail (XED_IS_TAB (tab), NULL); + g_return_val_if_fail (XED_IS_TAB (tab), NULL); - doc = xed_tab_get_document (tab); + doc = xed_tab_get_document (tab); - name = xed_document_get_short_name_for_display (doc); + name = xed_document_get_short_name_for_display (doc); - /* Truncate the name so it doesn't get insanely wide. */ - docname = xed_utils_str_middle_truncate (name, MAX_DOC_NAME_LENGTH); + /* Truncate the name so it doesn't get insanely wide. */ + docname = xed_utils_str_middle_truncate (name, MAX_DOC_NAME_LENGTH); - if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc))) - { - if (xed_document_get_readonly (doc)) - { - tab_name = g_markup_printf_escaped ("%s [%s]", - docname, - _("Read-Only")); - } - else - { - tab_name = g_markup_printf_escaped ("%s", - docname); - } - } - else - { - if (xed_document_get_readonly (doc)) - { - tab_name = g_markup_printf_escaped ("%s [%s]", - docname, - _("Read-Only")); - } - else - { - tab_name = g_markup_escape_text (docname, -1); - } - } + if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc))) + { + if (xed_document_get_readonly (doc)) + { + tab_name = g_markup_printf_escaped ("%s [%s]", docname, _("Read-Only")); + } + else + { + tab_name = g_markup_printf_escaped ("%s", docname); + } + } + else + { + if (xed_document_get_readonly (doc)) + { + tab_name = g_markup_printf_escaped ("%s [%s]", docname, _("Read-Only")); + } + else + { + tab_name = g_markup_escape_text (docname, -1); + } + } - g_free (docname); - g_free (name); + g_free (docname); + g_free (name); - return tab_name; + return tab_name; } static void -get_iter_from_tab (XedDocumentsPanel *panel, XedTab *tab, GtkTreeIter *iter) +get_iter_from_tab (XedDocumentsPanel *panel, + XedTab *tab, + GtkTreeIter *iter) { - gint num; - GtkWidget *nb; - GtkTreePath *path; + gint num; + GtkWidget *nb; + GtkTreePath *path; - nb = _xed_window_get_notebook (panel->priv->window); - num = gtk_notebook_page_num (GTK_NOTEBOOK (nb), - GTK_WIDGET (tab)); + nb = _xed_window_get_notebook (panel->priv->window); + num = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (tab)); - path = gtk_tree_path_new_from_indices (num, -1); - gtk_tree_model_get_iter (panel->priv->model, - iter, - path); - gtk_tree_path_free (path); + path = gtk_tree_path_new_from_indices (num, -1); + gtk_tree_model_get_iter (panel->priv->model, iter, path); + gtk_tree_path_free (path); } static void window_active_tab_changed (XedWindow *window, - XedTab *tab, - XedDocumentsPanel *panel) -{ - g_return_if_fail (tab != NULL); + XedTab *tab, + XedDocumentsPanel *panel) +{ + g_return_if_fail (tab != NULL); - if (!_xed_window_is_removing_tabs (window)) - { - GtkTreeIter iter; - GtkTreeSelection *selection; + if (!_xed_window_is_removing_tabs (window)) + { + GtkTreeIter iter; + GtkTreeSelection *selection; - get_iter_from_tab (panel, tab, &iter); + get_iter_from_tab (panel, tab, &iter); - if (gtk_list_store_iter_is_valid (GTK_LIST_STORE (panel->priv->model), - &iter)) - { - selection = gtk_tree_view_get_selection ( - GTK_TREE_VIEW (panel->priv->treeview)); + if (gtk_list_store_iter_is_valid (GTK_LIST_STORE (panel->priv->model), &iter)) + { + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (panel->priv->treeview)); - gtk_tree_selection_select_iter (selection, &iter); - } - } + gtk_tree_selection_select_iter (selection, &iter); + } + } } static void refresh_list (XedDocumentsPanel *panel) { - /* TODO: refresh the list only if the panel is visible */ + /* TODO: refresh the list only if the panel is visible */ - GList *tabs; - GList *l; - GtkWidget *nb; - GtkListStore *list_store; - XedTab *active_tab; + GList *tabs; + GList *l; + GtkWidget *nb; + GtkListStore *list_store; + XedTab *active_tab; - /* g_debug ("refresh_list"); */ - - list_store = GTK_LIST_STORE (panel->priv->model); + /* g_debug ("refresh_list"); */ - gtk_list_store_clear (list_store); + list_store = GTK_LIST_STORE (panel->priv->model); - active_tab = xed_window_get_active_tab (panel->priv->window); + gtk_list_store_clear (list_store); - nb = _xed_window_get_notebook (panel->priv->window); + active_tab = xed_window_get_active_tab (panel->priv->window); - tabs = gtk_container_get_children (GTK_CONTAINER (nb)); - l = tabs; + nb = _xed_window_get_notebook (panel->priv->window); - panel->priv->adding_tab = TRUE; - - while (l != NULL) - { - GdkPixbuf *pixbuf; - gchar *name; - GtkTreeIter iter; + tabs = gtk_container_get_children (GTK_CONTAINER (nb)); + l = tabs; - name = tab_get_name (XED_TAB (l->data)); - pixbuf = _xed_tab_get_icon (XED_TAB (l->data)); + panel->priv->adding_tab = TRUE; - /* Add a new row to the model */ - gtk_list_store_append (list_store, &iter); - gtk_list_store_set (list_store, - &iter, - PIXBUF_COLUMN, pixbuf, - NAME_COLUMN, name, - TAB_COLUMN, l->data, - -1); + while (l != NULL) + { + GdkPixbuf *pixbuf; + gchar *name; + GtkTreeIter iter; - g_free (name); - if (pixbuf != NULL) - g_object_unref (pixbuf); + name = tab_get_name (XED_TAB (l->data)); + pixbuf = _xed_tab_get_icon (XED_TAB (l->data)); - if (l->data == active_tab) - { - GtkTreeSelection *selection; + /* Add a new row to the model */ + gtk_list_store_append (list_store, &iter); + gtk_list_store_set (list_store, &iter, + PIXBUF_COLUMN, pixbuf, + NAME_COLUMN, name, + TAB_COLUMN, l->data, + -1); - selection = gtk_tree_view_get_selection ( - GTK_TREE_VIEW (panel->priv->treeview)); + g_free (name); + if (pixbuf != NULL) + { + g_object_unref (pixbuf); + } - gtk_tree_selection_select_iter (selection, &iter); - } + if (l->data == active_tab) + { + GtkTreeSelection *selection; - l = g_list_next (l); - } - - panel->priv->adding_tab = FALSE; + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (panel->priv->treeview)); - g_list_free (tabs); + gtk_tree_selection_select_iter (selection, &iter); + } + + l = g_list_next (l); + } + + panel->priv->adding_tab = FALSE; + + g_list_free (tabs); } static void sync_name_and_icon (XedTab *tab, - GParamSpec *pspec, - XedDocumentsPanel *panel) + GParamSpec *pspec, + XedDocumentsPanel *panel) { - GdkPixbuf *pixbuf; - gchar *name; - GtkTreeIter iter; + GdkPixbuf *pixbuf; + gchar *name; + GtkTreeIter iter; - get_iter_from_tab (panel, tab, &iter); + get_iter_from_tab (panel, tab, &iter); - name = tab_get_name (tab); - pixbuf = _xed_tab_get_icon (tab); + name = tab_get_name (tab); + pixbuf = _xed_tab_get_icon (tab); - gtk_list_store_set (GTK_LIST_STORE (panel->priv->model), - &iter, - PIXBUF_COLUMN, pixbuf, - NAME_COLUMN, name, - TAB_COLUMN, tab, - -1); + gtk_list_store_set (GTK_LIST_STORE (panel->priv->model), &iter, + PIXBUF_COLUMN, pixbuf, + NAME_COLUMN, name, + TAB_COLUMN, tab, + -1); - g_free (name); - if (pixbuf != NULL) - g_object_unref (pixbuf); + g_free (name); + if (pixbuf != NULL) + { + g_object_unref (pixbuf); + } } static void window_tab_removed (XedWindow *window, - XedTab *tab, - XedDocumentsPanel *panel) + XedTab *tab, + XedDocumentsPanel *panel) { - g_signal_handlers_disconnect_by_func (tab, - G_CALLBACK (sync_name_and_icon), - panel); + g_signal_handlers_disconnect_by_func (tab, G_CALLBACK (sync_name_and_icon), panel); - if (_xed_window_is_removing_tabs (window)) - gtk_list_store_clear (GTK_LIST_STORE (panel->priv->model)); - else - refresh_list (panel); + if (_xed_window_is_removing_tabs (window)) + { + gtk_list_store_clear (GTK_LIST_STORE (panel->priv->model)); + } + else + { + refresh_list (panel); + } } static void window_tab_added (XedWindow *window, - XedTab *tab, - XedDocumentsPanel *panel) + XedTab *tab, + XedDocumentsPanel *panel) { - GtkTreeIter iter; - GtkTreeIter sibling; - GdkPixbuf *pixbuf; - gchar *name; + GtkTreeIter iter; + GtkTreeIter sibling; + GdkPixbuf *pixbuf; + gchar *name; - g_signal_connect (tab, - "notify::name", - G_CALLBACK (sync_name_and_icon), - panel); + g_signal_connect (tab, "notify::name", G_CALLBACK (sync_name_and_icon), panel); + g_signal_connect (tab, "notify::state", G_CALLBACK (sync_name_and_icon), panel); - g_signal_connect (tab, - "notify::state", - G_CALLBACK (sync_name_and_icon), - panel); + get_iter_from_tab (panel, tab, &sibling); - get_iter_from_tab (panel, tab, &sibling); + panel->priv->adding_tab = TRUE; - panel->priv->adding_tab = TRUE; - - if (gtk_list_store_iter_is_valid (GTK_LIST_STORE (panel->priv->model), - &sibling)) - { - gtk_list_store_insert_after (GTK_LIST_STORE (panel->priv->model), - &iter, - &sibling); - } - else - { - XedTab *active_tab; + if (gtk_list_store_iter_is_valid (GTK_LIST_STORE (panel->priv->model), &sibling)) + { + gtk_list_store_insert_after (GTK_LIST_STORE (panel->priv->model), &iter, &sibling); + } + else + { + XedTab *active_tab; - gtk_list_store_append (GTK_LIST_STORE (panel->priv->model), - &iter); + gtk_list_store_append (GTK_LIST_STORE (panel->priv->model), &iter); - active_tab = xed_window_get_active_tab (panel->priv->window); + active_tab = xed_window_get_active_tab (panel->priv->window); - if (tab == active_tab) - { - GtkTreeSelection *selection; + if (tab == active_tab) + { + GtkTreeSelection *selection; - selection = gtk_tree_view_get_selection ( - GTK_TREE_VIEW (panel->priv->treeview)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (panel->priv->treeview)); + gtk_tree_selection_select_iter (selection, &iter); + } + } - gtk_tree_selection_select_iter (selection, &iter); - } - } + name = tab_get_name (tab); + pixbuf = _xed_tab_get_icon (tab); - name = tab_get_name (tab); - pixbuf = _xed_tab_get_icon (tab); + gtk_list_store_set (GTK_LIST_STORE (panel->priv->model), &iter, + PIXBUF_COLUMN, pixbuf, + NAME_COLUMN, name, + TAB_COLUMN, tab, + -1); - gtk_list_store_set (GTK_LIST_STORE (panel->priv->model), - &iter, - PIXBUF_COLUMN, pixbuf, - NAME_COLUMN, name, - TAB_COLUMN, tab, - -1); + g_free (name); + if (pixbuf != NULL) + { + g_object_unref (pixbuf); + } - g_free (name); - if (pixbuf != NULL) - g_object_unref (pixbuf); - - panel->priv->adding_tab = FALSE; + panel->priv->adding_tab = FALSE; } static void window_tabs_reordered (XedWindow *window, - XedDocumentsPanel *panel) + XedDocumentsPanel *panel) { - if (panel->priv->is_reodering) - return; + if (panel->priv->is_reodering) + { + return; + } - refresh_list (panel); + refresh_list (panel); } static void set_window (XedDocumentsPanel *panel, - XedWindow *window) + XedWindow *window) { - g_return_if_fail (panel->priv->window == NULL); - g_return_if_fail (XED_IS_WINDOW (window)); + g_return_if_fail (panel->priv->window == NULL); + g_return_if_fail (XED_IS_WINDOW (window)); - panel->priv->window = g_object_ref (window); + panel->priv->window = g_object_ref (window); - g_signal_connect (window, - "tab_added", - G_CALLBACK (window_tab_added), - panel); - g_signal_connect (window, - "tab_removed", - G_CALLBACK (window_tab_removed), - panel); - g_signal_connect (window, - "tabs_reordered", - G_CALLBACK (window_tabs_reordered), - panel); - g_signal_connect (window, - "active_tab_changed", - G_CALLBACK (window_active_tab_changed), - panel); + g_signal_connect (window, "tab_added", G_CALLBACK (window_tab_added), panel); + g_signal_connect (window, "tab_removed", G_CALLBACK (window_tab_removed), panel); + g_signal_connect (window, "tabs_reordered", G_CALLBACK (window_tabs_reordered), panel); + g_signal_connect (window, "active_tab_changed", G_CALLBACK (window_active_tab_changed), panel); } static void -treeview_cursor_changed (GtkTreeView *view, - XedDocumentsPanel *panel) +treeview_cursor_changed (GtkTreeView *view, + XedDocumentsPanel *panel) { - GtkTreeIter iter; - GtkTreeSelection *selection; - gpointer tab; + GtkTreeIter iter; + GtkTreeSelection *selection; + gpointer tab; - selection = gtk_tree_view_get_selection ( - GTK_TREE_VIEW (panel->priv->treeview)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (panel->priv->treeview)); - if (gtk_tree_selection_get_selected (selection, NULL, &iter)) - { - gtk_tree_model_get (panel->priv->model, - &iter, - TAB_COLUMN, - &tab, - -1); + if (gtk_tree_selection_get_selected (selection, NULL, &iter)) + { + gtk_tree_model_get (panel->priv->model, &iter, + TAB_COLUMN, &tab, + -1); - if (xed_window_get_active_tab (panel->priv->window) != tab) - { - xed_window_set_active_tab (panel->priv->window, - XED_TAB (tab)); - } - } + if (xed_window_get_active_tab (panel->priv->window) != tab) + { + xed_window_set_active_tab (panel->priv->window, XED_TAB (tab)); + } + } } static void xed_documents_panel_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - XedDocumentsPanel *panel = XED_DOCUMENTS_PANEL (object); + XedDocumentsPanel *panel = XED_DOCUMENTS_PANEL (object); - switch (prop_id) - { - case PROP_WINDOW: - set_window (panel, g_value_get_object (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_WINDOW: + set_window (panel, g_value_get_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_documents_panel_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - XedDocumentsPanel *panel = XED_DOCUMENTS_PANEL (object); + XedDocumentsPanel *panel = XED_DOCUMENTS_PANEL (object); - switch (prop_id) - { - case PROP_WINDOW: - g_value_set_object (value, - XED_DOCUMENTS_PANEL_GET_PRIVATE (panel)->window); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_WINDOW: + g_value_set_object (value, XED_DOCUMENTS_PANEL_GET_PRIVATE (panel)->window); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_documents_panel_finalize (GObject *object) { - /* XedDocumentsPanel *tab = XED_DOCUMENTS_PANEL (object); */ - - /* TODO: disconnect signal with window */ + /* XedDocumentsPanel *tab = XED_DOCUMENTS_PANEL (object); */ - G_OBJECT_CLASS (xed_documents_panel_parent_class)->finalize (object); + /* TODO: disconnect signal with window */ + + G_OBJECT_CLASS (xed_documents_panel_parent_class)->finalize (object); } static void xed_documents_panel_dispose (GObject *object) { - XedDocumentsPanel *panel = XED_DOCUMENTS_PANEL (object); + XedDocumentsPanel *panel = XED_DOCUMENTS_PANEL (object); - if (panel->priv->window != NULL) - { - g_object_unref (panel->priv->window); - panel->priv->window = NULL; - } + if (panel->priv->window != NULL) + { + g_object_unref (panel->priv->window); + panel->priv->window = NULL; + } - G_OBJECT_CLASS (xed_documents_panel_parent_class)->dispose (object); + G_OBJECT_CLASS (xed_documents_panel_parent_class)->dispose (object); } -static void +static void xed_documents_panel_class_init (XedDocumentsPanelClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = xed_documents_panel_finalize; - object_class->dispose = xed_documents_panel_dispose; - object_class->get_property = xed_documents_panel_get_property; - object_class->set_property = xed_documents_panel_set_property; + object_class->finalize = xed_documents_panel_finalize; + object_class->dispose = xed_documents_panel_dispose; + object_class->get_property = xed_documents_panel_get_property; + object_class->set_property = xed_documents_panel_set_property; - g_object_class_install_property (object_class, - PROP_WINDOW, - g_param_spec_object ("window", - "Window", - "The XedWindow this XedDocumentsPanel is associated with", - XED_TYPE_WINDOW, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, + PROP_WINDOW, + g_param_spec_object ("window", + "Window", + "The XedWindow this XedDocumentsPanel is associated with", + XED_TYPE_WINDOW, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); - g_type_class_add_private (object_class, sizeof (XedDocumentsPanelPrivate)); + g_type_class_add_private (object_class, sizeof (XedDocumentsPanelPrivate)); } static GtkTreePath * get_current_path (XedDocumentsPanel *panel) { - gint num; - GtkWidget *nb; - GtkTreePath *path; + gint num; + GtkWidget *nb; + GtkTreePath *path; - nb = _xed_window_get_notebook (panel->priv->window); - num = gtk_notebook_get_current_page (GTK_NOTEBOOK (nb)); + nb = _xed_window_get_notebook (panel->priv->window); + num = gtk_notebook_get_current_page (GTK_NOTEBOOK (nb)); - path = gtk_tree_path_new_from_indices (num, -1); + path = gtk_tree_path_new_from_indices (num, -1); - return path; + return path; } static void -menu_position (GtkMenu *menu, - gint *x, - gint *y, - gboolean *push_in, - XedDocumentsPanel *panel) +menu_position (GtkMenu *menu, + gint *x, + gint *y, + gboolean *push_in, + XedDocumentsPanel *panel) { - GtkTreePath *path; - GdkRectangle rect; - gint wx, wy; - GtkAllocation allocation; - GtkRequisition requisition; - GtkWidget *w; + GtkTreePath *path; + GdkRectangle rect; + gint wx, wy; + GtkAllocation allocation; + GtkRequisition requisition; + GtkWidget *w; - w = panel->priv->treeview; + w = panel->priv->treeview; - gtk_widget_get_allocation(w, &allocation); + gtk_widget_get_allocation(w, &allocation); - path = get_current_path (panel); + path = get_current_path (panel); - gtk_tree_view_get_cell_area (GTK_TREE_VIEW (w), - path, - NULL, - &rect); + gtk_tree_view_get_cell_area (GTK_TREE_VIEW (w), path, NULL, &rect); - wx = rect.x; - wy = rect.y; + wx = rect.x; + wy = rect.y; - gdk_window_get_origin (gtk_widget_get_window (w), x, y); + gdk_window_get_origin (gtk_widget_get_window (w), x, y); - gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &requisition); + gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &requisition); - if (gtk_widget_get_direction (w) == GTK_TEXT_DIR_RTL) - { - *x += allocation.x + allocation.width - requisition.width - 10; - } - else - { - *x += allocation.x + 10; - } + if (gtk_widget_get_direction (w) == GTK_TEXT_DIR_RTL) + { + *x += allocation.x + allocation.width - requisition.width - 10; + } + else + { + *x += allocation.x + 10; + } - wy = MAX (*y + 5, *y + wy + 5); - wy = MIN (wy, *y + allocation.height - requisition.height - 5); - - *y = wy; + wy = MAX (*y + 5, *y + wy + 5); + wy = MIN (wy, *y + allocation.height - requisition.height - 5); - *push_in = TRUE; + *y = wy; + + *push_in = TRUE; } static gboolean show_popup_menu (XedDocumentsPanel *panel, - GdkEventButton *event) + GdkEventButton *event) { - GtkWidget *menu; + GtkWidget *menu; - menu = gtk_ui_manager_get_widget (xed_window_get_ui_manager (panel->priv->window), - "/NotebookPopup"); - g_return_val_if_fail (menu != NULL, FALSE); + menu = gtk_ui_manager_get_widget (xed_window_get_ui_manager (panel->priv->window), "/NotebookPopup"); + g_return_val_if_fail (menu != NULL, FALSE); - if (event != NULL) - { - gtk_menu_popup (GTK_MENU (menu), - NULL, - NULL, - NULL, - NULL, - event->button, - event->time); - } - else - { - gtk_menu_popup (GTK_MENU (menu), - NULL, - NULL, - (GtkMenuPositionFunc) menu_position, - panel, - 0, - gtk_get_current_event_time ()); + if (event != NULL) + { + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, + NULL, NULL, + event->button, event->time); + } + else + { + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, + (GtkMenuPositionFunc) menu_position, panel, + 0, gtk_get_current_event_time ()); - gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE); - } + gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE); + } - return TRUE; + return TRUE; } static gboolean -panel_button_press_event (GtkTreeView *treeview, - GdkEventButton *event, - XedDocumentsPanel *panel) +panel_button_press_event (GtkTreeView *treeview, + GdkEventButton *event, + XedDocumentsPanel *panel) { - if ((GDK_BUTTON_PRESS == event->type) && (3 == event->button)) - { - GtkTreePath* path = NULL; + if ((GDK_BUTTON_PRESS == event->type) && (3 == event->button)) + { + GtkTreePath* path = NULL; - if (event->window == gtk_tree_view_get_bin_window (treeview)) - { - /* Change the cursor position */ - if (gtk_tree_view_get_path_at_pos (treeview, - event->x, - event->y, - &path, - NULL, - NULL, - NULL)) - { + if (event->window == gtk_tree_view_get_bin_window (treeview)) + { + /* Change the cursor position */ + if (gtk_tree_view_get_path_at_pos (treeview, + event->x, event->y, + &path, NULL, + NULL, NULL)) + { - gtk_tree_view_set_cursor (treeview, - path, - NULL, - FALSE); + gtk_tree_view_set_cursor (treeview, path, NULL, FALSE); - gtk_tree_path_free (path); + gtk_tree_path_free (path); - /* A row exists at mouse position */ - return show_popup_menu (panel, event); - } - } - } + /* A row exists at mouse position */ + return show_popup_menu (panel, event); + } + } + } - return FALSE; + return FALSE; } static gboolean -panel_popup_menu (GtkWidget *treeview, - XedDocumentsPanel *panel) +panel_popup_menu (GtkWidget *treeview, + XedDocumentsPanel *panel) { - /* Only respond if the treeview is the actual focus */ - if (gtk_window_get_focus (GTK_WINDOW (panel->priv->window)) == treeview) - { - return show_popup_menu (panel, NULL); - } + /* Only respond if the treeview is the actual focus */ + if (gtk_window_get_focus (GTK_WINDOW (panel->priv->window)) == treeview) + { + return show_popup_menu (panel, NULL); + } - return FALSE; + return FALSE; } static gboolean treeview_query_tooltip (GtkWidget *widget, - gint x, - gint y, - gboolean keyboard_tip, - GtkTooltip *tooltip, - gpointer data) + gint x, + gint y, + gboolean keyboard_tip, + GtkTooltip *tooltip, + gpointer data) { - GtkTreeIter iter; - GtkTreeView *tree_view = GTK_TREE_VIEW (widget); - GtkTreeModel *model = gtk_tree_view_get_model (tree_view); - GtkTreePath *path = NULL; - gpointer *tab; - gchar *tip; + GtkTreeIter iter; + GtkTreeView *tree_view = GTK_TREE_VIEW (widget); + GtkTreeModel *model = gtk_tree_view_get_model (tree_view); + GtkTreePath *path = NULL; + gpointer *tab; + gchar *tip; - if (keyboard_tip) - { - gtk_tree_view_get_cursor (tree_view, &path, NULL); + if (keyboard_tip) + { + gtk_tree_view_get_cursor (tree_view, &path, NULL); - if (path == NULL) - { - return FALSE; - } - } - else - { - gint bin_x, bin_y; + if (path == NULL) + { + return FALSE; + } + } + else + { + gint bin_x, bin_y; - gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, - x, y, - &bin_x, &bin_y); + gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y, &bin_x, &bin_y); - if (!gtk_tree_view_get_path_at_pos (tree_view, - bin_x, bin_y, - &path, - NULL, NULL, NULL)) - { - return FALSE; - } - } + if (!gtk_tree_view_get_path_at_pos (tree_view, + bin_x, bin_y, + &path, NULL, + NULL, NULL)) + { + return FALSE; + } + } - gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, - &iter, - TAB_COLUMN, - &tab, - -1); + gtk_tree_model_get_iter (model, &iter, path); + gtk_tree_model_get (model, &iter, TAB_COLUMN, &tab, -1); - tip = _xed_tab_get_tooltips (XED_TAB (tab)); - gtk_tooltip_set_markup (tooltip, tip); + tip = _xed_tab_get_tooltips (XED_TAB (tab)); + gtk_tooltip_set_markup (tooltip, tip); - g_free (tip); - gtk_tree_path_free (path); + g_free (tip); + gtk_tree_path_free (path); - return TRUE; + return TRUE; } static void -treeview_row_inserted (GtkTreeModel *tree_model, - GtkTreePath *path, - GtkTreeIter *iter, - XedDocumentsPanel *panel) +treeview_row_inserted (GtkTreeModel *tree_model, + GtkTreePath *path, + GtkTreeIter *iter, + XedDocumentsPanel *panel) { - XedTab *tab; - gint *indeces; - GtkWidget *nb; - gint old_position; - gint new_position; - - if (panel->priv->adding_tab) - return; - - tab = xed_window_get_active_tab (panel->priv->window); - g_return_if_fail (tab != NULL); + XedTab *tab; + gint *indeces; + GtkWidget *nb; + gint old_position; + gint new_position; - panel->priv->is_reodering = TRUE; - - indeces = gtk_tree_path_get_indices (path); - - /* g_debug ("New Index: %d (path: %s)", indeces[0], gtk_tree_path_to_string (path));*/ - - nb = _xed_window_get_notebook (panel->priv->window); + if (panel->priv->adding_tab) + { + return; + } - new_position = indeces[0]; - old_position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), - GTK_WIDGET (tab)); - if (new_position > old_position) - new_position = MAX (0, new_position - 1); - - xed_notebook_reorder_tab (XED_NOTEBOOK (nb), - tab, - new_position); + tab = xed_window_get_active_tab (panel->priv->window); + g_return_if_fail (tab != NULL); - panel->priv->is_reodering = FALSE; + panel->priv->is_reodering = TRUE; + + indeces = gtk_tree_path_get_indices (path); + + /* g_debug ("New Index: %d (path: %s)", indeces[0], gtk_tree_path_to_string (path));*/ + + nb = _xed_window_get_notebook (panel->priv->window); + + new_position = indeces[0]; + old_position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (tab)); + if (new_position > old_position) + { + new_position = MAX (0, new_position - 1); + } + + xed_notebook_reorder_tab (XED_NOTEBOOK (nb), tab, new_position); + + panel->priv->is_reodering = FALSE; } static void xed_documents_panel_init (XedDocumentsPanel *panel) { - GtkWidget *sw; - GtkTreeViewColumn *column; - GtkCellRenderer *cell; - GtkTreeSelection *selection; + GtkWidget *sw; + GtkTreeViewColumn *column; + GtkCellRenderer *cell; + GtkTreeSelection *selection; - panel->priv = XED_DOCUMENTS_PANEL_GET_PRIVATE (panel); - - panel->priv->adding_tab = FALSE; - panel->priv->is_reodering = FALSE; + panel->priv = XED_DOCUMENTS_PANEL_GET_PRIVATE (panel); - gtk_orientable_set_orientation (GTK_ORIENTABLE (panel), - GTK_ORIENTATION_VERTICAL); - - /* Create the scrolled window */ - sw = gtk_scrolled_window_new (NULL, NULL); - g_return_if_fail (sw != NULL); - - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_widget_show (sw); - gtk_box_pack_start (GTK_BOX (panel), sw, TRUE, TRUE, 0); - - /* Create the empty model */ - panel->priv->model = GTK_TREE_MODEL (gtk_list_store_new (N_COLUMNS, - GDK_TYPE_PIXBUF, - G_TYPE_STRING, - G_TYPE_POINTER)); + panel->priv->adding_tab = FALSE; + panel->priv->is_reodering = FALSE; - /* Create the treeview */ - panel->priv->treeview = gtk_tree_view_new_with_model (panel->priv->model); - g_object_unref (G_OBJECT (panel->priv->model)); - gtk_container_add (GTK_CONTAINER (sw), panel->priv->treeview); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (panel->priv->treeview), FALSE); - gtk_tree_view_set_reorderable (GTK_TREE_VIEW (panel->priv->treeview), TRUE); + gtk_orientable_set_orientation (GTK_ORIENTABLE (panel), GTK_ORIENTATION_VERTICAL); - g_object_set (panel->priv->treeview, "has-tooltip", TRUE, NULL); + /* Create the scrolled window */ + sw = gtk_scrolled_window_new (NULL, NULL); + g_return_if_fail (sw != NULL); - gtk_widget_show (panel->priv->treeview); - - column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_title (column, _("Documents")); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_widget_show (sw); + gtk_box_pack_start (GTK_BOX (panel), sw, TRUE, TRUE, 0); - cell = gtk_cell_renderer_pixbuf_new (); - gtk_tree_view_column_pack_start (column, cell, FALSE); - gtk_tree_view_column_add_attribute (column, cell, "pixbuf", PIXBUF_COLUMN); - cell = gtk_cell_renderer_text_new (); - gtk_tree_view_column_pack_start (column, cell, TRUE); - gtk_tree_view_column_add_attribute (column, cell, "markup", NAME_COLUMN); + /* Create the empty model */ + panel->priv->model = GTK_TREE_MODEL (gtk_list_store_new (N_COLUMNS, + GDK_TYPE_PIXBUF, + G_TYPE_STRING, + G_TYPE_POINTER)); - gtk_tree_view_append_column (GTK_TREE_VIEW (panel->priv->treeview), - column); - - selection = gtk_tree_view_get_selection ( - GTK_TREE_VIEW (panel->priv->treeview)); + /* Create the treeview */ + panel->priv->treeview = gtk_tree_view_new_with_model (panel->priv->model); + g_object_unref (G_OBJECT (panel->priv->model)); + gtk_container_add (GTK_CONTAINER (sw), panel->priv->treeview); + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (panel->priv->treeview), FALSE); + gtk_tree_view_set_reorderable (GTK_TREE_VIEW (panel->priv->treeview), TRUE); - gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); - - g_signal_connect (panel->priv->treeview, - "cursor_changed", - G_CALLBACK (treeview_cursor_changed), - panel); - g_signal_connect (panel->priv->treeview, - "button-press-event", - G_CALLBACK (panel_button_press_event), - panel); - g_signal_connect (panel->priv->treeview, - "popup-menu", - G_CALLBACK (panel_popup_menu), - panel); - g_signal_connect (panel->priv->treeview, - "query-tooltip", - G_CALLBACK (treeview_query_tooltip), - NULL); + g_object_set (panel->priv->treeview, "has-tooltip", TRUE, NULL); - g_signal_connect (panel->priv->model, - "row-inserted", - G_CALLBACK (treeview_row_inserted), - panel); + gtk_widget_show (panel->priv->treeview); + + column = gtk_tree_view_column_new (); + gtk_tree_view_column_set_title (column, _("Documents")); + + cell = gtk_cell_renderer_pixbuf_new (); + gtk_tree_view_column_pack_start (column, cell, FALSE); + gtk_tree_view_column_add_attribute (column, cell, "pixbuf", PIXBUF_COLUMN); + cell = gtk_cell_renderer_text_new (); + gtk_tree_view_column_pack_start (column, cell, TRUE); + gtk_tree_view_column_add_attribute (column, cell, "markup", NAME_COLUMN); + + gtk_tree_view_append_column (GTK_TREE_VIEW (panel->priv->treeview), column); + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (panel->priv->treeview)); + + gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); + + g_signal_connect (panel->priv->treeview, "cursor_changed", G_CALLBACK (treeview_cursor_changed), panel); + g_signal_connect (panel->priv->treeview, "button-press-event", G_CALLBACK (panel_button_press_event), panel); + g_signal_connect (panel->priv->treeview, "popup-menu", G_CALLBACK (panel_popup_menu), panel); + g_signal_connect (panel->priv->treeview, "query-tooltip", G_CALLBACK (treeview_query_tooltip), NULL); + g_signal_connect (panel->priv->model, "row-inserted", G_CALLBACK (treeview_row_inserted), panel); } GtkWidget * xed_documents_panel_new (XedWindow *window) { - g_return_val_if_fail (XED_IS_WINDOW (window), NULL); + g_return_val_if_fail (XED_IS_WINDOW (window), NULL); - return GTK_WIDGET (g_object_new (XED_TYPE_DOCUMENTS_PANEL, - "window", window, - NULL)); + return GTK_WIDGET (g_object_new (XED_TYPE_DOCUMENTS_PANEL, + "window", window, + NULL)); } From 909ea55a7ca059c03c531e3d7816b67ce28d1a85 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 12 Dec 2016 02:14:40 -0800 Subject: [PATCH 014/132] xed-documents-panel: Remove an unused variable --- xed/xed-documents-panel.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xed/xed-documents-panel.c b/xed/xed-documents-panel.c index 98aaa08..8f3aff4 100644 --- a/xed/xed-documents-panel.c +++ b/xed/xed-documents-panel.c @@ -482,7 +482,7 @@ menu_position (GtkMenu *menu, { GtkTreePath *path; GdkRectangle rect; - gint wx, wy; + gint wy; GtkAllocation allocation; GtkRequisition requisition; GtkWidget *w; @@ -495,7 +495,6 @@ menu_position (GtkMenu *menu, gtk_tree_view_get_cell_area (GTK_TREE_VIEW (w), path, NULL, &rect); - wx = rect.x; wy = rect.y; gdk_window_get_origin (gtk_widget_get_window (w), x, y); From 2bf076e7c540b40b664466ba39a965492a061bba Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 12 Dec 2016 02:48:58 -0800 Subject: [PATCH 015/132] xed-message-bus: Clean up code styling --- xed/xed-message-bus.c | 1169 +++++++++++++++++++++-------------------- 1 file changed, 587 insertions(+), 582 deletions(-) diff --git a/xed/xed-message-bus.c b/xed/xed-message-bus.c index aa35631..1978705 100644 --- a/xed/xed-message-bus.c +++ b/xed/xed-message-bus.c @@ -46,8 +46,8 @@ * * // Register 'method' at '/plugins/example' with one required * // string argument 'arg1' - * XedMessageType *message_type = xed_message_bus_register ("/plugins/example", "method", - * 0, + * XedMessageType *message_type = xed_message_bus_register ("/plugins/example", "method", + * 0, * "arg1", G_TYPE_STRING, * NULL); * @@ -60,21 +60,21 @@ * XedMessage *message, * gpointer userdata) * { - * gchar *arg1 = NULL; - * - * xed_message_get (message, "arg1", &arg1, NULL); - * g_message ("Evoked /plugins/example.method with: %s", arg1); - * g_free (arg1); + * gchar *arg1 = NULL; + * + * xed_message_get (message, "arg1", &arg1, NULL); + * g_message ("Evoked /plugins/example.method with: %s", arg1); + * g_free (arg1); * } * * XedMessageBus *bus = xed_message_bus_get_default (); - * - * guint id = xed_message_bus_connect (bus, + * + * guint id = xed_message_bus_connect (bus, * "/plugins/example", "method", * example_method_cb, * NULL, * NULL); - * + * * * * @@ -82,9 +82,9 @@ * * XedMessageBus *bus = xed_message_bus_get_default (); * - * xed_message_bus_send (bus, - * "/plugins/example", "method", - * "arg1", "Hello World", + * xed_message_bus_send (bus, + * "/plugins/example", "method", + * "arg1", "Hello World", * NULL); * * @@ -92,430 +92,439 @@ * Since: 2.25.3 * */ - + #define XED_MESSAGE_BUS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), XED_TYPE_MESSAGE_BUS, XedMessageBusPrivate)) typedef struct { - gchar *object_path; - gchar *method; + gchar *object_path; + gchar *method; - GList *listeners; + GList *listeners; } Message; typedef struct { - guint id; - gboolean blocked; + guint id; + gboolean blocked; - GDestroyNotify destroy_data; - XedMessageCallback callback; - gpointer userdata; + GDestroyNotify destroy_data; + XedMessageCallback callback; + gpointer userdata; } Listener; typedef struct { - Message *message; - GList *listener; + Message *message; + GList *listener; } IdMap; struct _XedMessageBusPrivate { - GHashTable *messages; - GHashTable *idmap; + GHashTable *messages; + GHashTable *idmap; - GList *message_queue; - guint idle_id; + GList *message_queue; + guint idle_id; - guint next_id; - - GHashTable *types; /* mapping from identifier to XedMessageType */ + guint next_id; + + GHashTable *types; /* mapping from identifier to XedMessageType */ }; /* signals */ enum { - DISPATCH, - REGISTERED, - UNREGISTERED, - LAST_SIGNAL + DISPATCH, + REGISTERED, + UNREGISTERED, + LAST_SIGNAL }; static guint message_bus_signals[LAST_SIGNAL] = { 0 }; static void xed_message_bus_dispatch_real (XedMessageBus *bus, - XedMessage *message); + XedMessage *message); -G_DEFINE_TYPE(XedMessageBus, xed_message_bus, G_TYPE_OBJECT) +G_DEFINE_TYPE (XedMessageBus, xed_message_bus, G_TYPE_OBJECT) static void listener_free (Listener *listener) { - if (listener->destroy_data) - listener->destroy_data (listener->userdata); + if (listener->destroy_data) + { + listener->destroy_data (listener->userdata); + } - g_free (listener); + g_free (listener); } static void message_free (Message *message) { - g_free (message->method); - g_free (message->object_path); - - g_list_foreach (message->listeners, (GFunc)listener_free, NULL); - g_list_free (message->listeners); - - g_free (message); + g_free (message->method); + g_free (message->object_path); + + g_list_foreach (message->listeners, (GFunc)listener_free, NULL); + g_list_free (message->listeners); + + g_free (message); } static void message_queue_free (GList *queue) { - g_list_foreach (queue, (GFunc)g_object_unref, NULL); - g_list_free (queue); + g_list_foreach (queue, (GFunc)g_object_unref, NULL); + g_list_free (queue); } static void xed_message_bus_finalize (GObject *object) { - XedMessageBus *bus = XED_MESSAGE_BUS (object); - - if (bus->priv->idle_id != 0) - g_source_remove (bus->priv->idle_id); - - message_queue_free (bus->priv->message_queue); + XedMessageBus *bus = XED_MESSAGE_BUS (object); - g_hash_table_destroy (bus->priv->messages); - g_hash_table_destroy (bus->priv->idmap); - g_hash_table_destroy (bus->priv->types); - - G_OBJECT_CLASS (xed_message_bus_parent_class)->finalize (object); + if (bus->priv->idle_id != 0) + { + g_source_remove (bus->priv->idle_id); + } + + message_queue_free (bus->priv->message_queue); + + g_hash_table_destroy (bus->priv->messages); + g_hash_table_destroy (bus->priv->idmap); + g_hash_table_destroy (bus->priv->types); + + G_OBJECT_CLASS (xed_message_bus_parent_class)->finalize (object); } static void xed_message_bus_class_init (XedMessageBusClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = xed_message_bus_finalize; - - klass->dispatch = xed_message_bus_dispatch_real; + GObjectClass *object_class = G_OBJECT_CLASS (klass); - /** - * XedMessageBus::dispatch: - * @bus: a #XedMessageBus - * @message: the #XedMessage to dispatch - * - * The "dispatch" signal is emitted when a message is to be dispatched. - * The message is dispatched in the default handler of this signal. - * Primary use of this signal is to customize the dispatch of a message - * (for instance to automatically dispatch all messages over DBus). - *2 - */ - message_bus_signals[DISPATCH] = - g_signal_new ("dispatch", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedMessageBusClass, dispatch), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - XED_TYPE_MESSAGE); + object_class->finalize = xed_message_bus_finalize; - /** - * XedMessageBus::registered: - * @bus: a #XedMessageBus - * @message_type: the registered #XedMessageType - * - * The "registered" signal is emitted when a message has been registered - * on the bus. - * - */ - message_bus_signals[REGISTERED] = - g_signal_new ("registered", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedMessageBusClass, registered), - NULL, NULL, - g_cclosure_marshal_VOID__BOXED, - G_TYPE_NONE, - 1, - XED_TYPE_MESSAGE_TYPE); + klass->dispatch = xed_message_bus_dispatch_real; - /** - * XedMessageBus::unregistered: - * @bus: a #XedMessageBus - * @message_type: the unregistered #XedMessageType - * - * The "unregistered" signal is emitted when a message has been - * unregistered from the bus. - * - */ - message_bus_signals[UNREGISTERED] = - g_signal_new ("unregistered", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedMessageBusClass, unregistered), - NULL, NULL, - g_cclosure_marshal_VOID__BOXED, - G_TYPE_NONE, - 1, - XED_TYPE_MESSAGE_TYPE); + /** + * XedMessageBus::dispatch: + * @bus: a #XedMessageBus + * @message: the #XedMessage to dispatch + * + * The "dispatch" signal is emitted when a message is to be dispatched. + * The message is dispatched in the default handler of this signal. + * Primary use of this signal is to customize the dispatch of a message + * (for instance to automatically dispatch all messages over DBus). + *2 + */ + message_bus_signals[DISPATCH] = + g_signal_new ("dispatch", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedMessageBusClass, dispatch), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, + XED_TYPE_MESSAGE); - g_type_class_add_private (object_class, sizeof(XedMessageBusPrivate)); + /** + * XedMessageBus::registered: + * @bus: a #XedMessageBus + * @message_type: the registered #XedMessageType + * + * The "registered" signal is emitted when a message has been registered + * on the bus. + * + */ + message_bus_signals[REGISTERED] = + g_signal_new ("registered", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedMessageBusClass, registered), + NULL, NULL, + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, + 1, + XED_TYPE_MESSAGE_TYPE); + + /** + * XedMessageBus::unregistered: + * @bus: a #XedMessageBus + * @message_type: the unregistered #XedMessageType + * + * The "unregistered" signal is emitted when a message has been + * unregistered from the bus. + * + */ + message_bus_signals[UNREGISTERED] = + g_signal_new ("unregistered", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedMessageBusClass, unregistered), + NULL, NULL, + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, + 1, + XED_TYPE_MESSAGE_TYPE); + + g_type_class_add_private (object_class, sizeof(XedMessageBusPrivate)); } static Message * message_new (XedMessageBus *bus, - const gchar *object_path, - const gchar *method) + const gchar *object_path, + const gchar *method) { - Message *message = g_new (Message, 1); - - message->object_path = g_strdup (object_path); - message->method = g_strdup (method); - message->listeners = NULL; + Message *message = g_new (Message, 1); - g_hash_table_insert (bus->priv->messages, - xed_message_type_identifier (object_path, method), - message); - return message; + message->object_path = g_strdup (object_path); + message->method = g_strdup (method); + message->listeners = NULL; + + g_hash_table_insert (bus->priv->messages, xed_message_type_identifier (object_path, method), message); + return message; } static Message * lookup_message (XedMessageBus *bus, - const gchar *object_path, - const gchar *method, - gboolean create) + const gchar *object_path, + const gchar *method, + gboolean create) { - gchar *identifier; - Message *message; - - identifier = xed_message_type_identifier (object_path, method); - message = (Message *)g_hash_table_lookup (bus->priv->messages, identifier); - g_free (identifier); + gchar *identifier; + Message *message; - if (!message && !create) - return NULL; - - if (!message) - message = message_new (bus, object_path, method); - - return message; + identifier = xed_message_type_identifier (object_path, method); + message = (Message *)g_hash_table_lookup (bus->priv->messages, identifier); + g_free (identifier); + + if (!message && !create) + { + return NULL; + } + + if (!message) + { + message = message_new (bus, object_path, method); + } + + return message; } static guint add_listener (XedMessageBus *bus, - Message *message, - XedMessageCallback callback, - gpointer userdata, - GDestroyNotify destroy_data) + Message *message, + XedMessageCallback callback, + gpointer userdata, + GDestroyNotify destroy_data) { - Listener *listener; - IdMap *idmap; - - listener = g_new (Listener, 1); - listener->id = ++bus->priv->next_id; - listener->callback = callback; - listener->userdata = userdata; - listener->blocked = FALSE; - listener->destroy_data = destroy_data; + Listener *listener; + IdMap *idmap; - message->listeners = g_list_append (message->listeners, listener); - - idmap = g_new (IdMap, 1); - idmap->message = message; - idmap->listener = g_list_last (message->listeners); + listener = g_new (Listener, 1); + listener->id = ++bus->priv->next_id; + listener->callback = callback; + listener->userdata = userdata; + listener->blocked = FALSE; + listener->destroy_data = destroy_data; - g_hash_table_insert (bus->priv->idmap, GINT_TO_POINTER (listener->id), idmap); - return listener->id; + message->listeners = g_list_append (message->listeners, listener); + + idmap = g_new (IdMap, 1); + idmap->message = message; + idmap->listener = g_list_last (message->listeners); + + g_hash_table_insert (bus->priv->idmap, GINT_TO_POINTER (listener->id), idmap); + return listener->id; } static void remove_listener (XedMessageBus *bus, - Message *message, - GList *listener) + Message *message, + GList *listener) { - Listener *lst; - - lst = (Listener *)listener->data; - - /* remove from idmap */ - g_hash_table_remove (bus->priv->idmap, GINT_TO_POINTER (lst->id)); - listener_free (lst); + Listener *lst; - /* remove from list of listeners */ - message->listeners = g_list_delete_link (message->listeners, listener); - - if (!message->listeners) - { - /* remove message because it does not have any listeners */ - g_hash_table_remove (bus->priv->messages, message); - } + lst = (Listener *)listener->data; + + /* remove from idmap */ + g_hash_table_remove (bus->priv->idmap, GINT_TO_POINTER (lst->id)); + listener_free (lst); + + /* remove from list of listeners */ + message->listeners = g_list_delete_link (message->listeners, listener); + + if (!message->listeners) + { + /* remove message because it does not have any listeners */ + g_hash_table_remove (bus->priv->messages, message); + } } static void block_listener (XedMessageBus *bus, - Message *message, - GList *listener) + Message *message, + GList *listener) { - Listener *lst; - - lst = (Listener *)listener->data; - lst->blocked = TRUE; + Listener *lst; + + lst = (Listener *)listener->data; + lst->blocked = TRUE; } static void unblock_listener (XedMessageBus *bus, - Message *message, - GList *listener) + Message *message, + GList *listener) { - Listener *lst; - - lst = (Listener *)listener->data; - lst->blocked = FALSE; + Listener *lst; + + lst = (Listener *)listener->data; + lst->blocked = FALSE; } static void dispatch_message_real (XedMessageBus *bus, - Message *msg, - XedMessage *message) + Message *msg, + XedMessage *message) { - GList *item; - - for (item = msg->listeners; item; item = item->next) - { - Listener *listener = (Listener *)item->data; - - if (!listener->blocked) - listener->callback (bus, message, listener->userdata); - } + GList *item; + + for (item = msg->listeners; item; item = item->next) + { + Listener *listener = (Listener *)item->data; + + if (!listener->blocked) + { + listener->callback (bus, message, listener->userdata); + } + } } static void xed_message_bus_dispatch_real (XedMessageBus *bus, - XedMessage *message) + XedMessage *message) { - const gchar *object_path; - const gchar *method; - Message *msg; - - object_path = xed_message_get_object_path (message); - method = xed_message_get_method (message); + const gchar *object_path; + const gchar *method; + Message *msg; - msg = lookup_message (bus, object_path, method, FALSE); - - if (msg) - dispatch_message_real (bus, msg, message); + object_path = xed_message_get_object_path (message); + method = xed_message_get_method (message); + + msg = lookup_message (bus, object_path, method, FALSE); + + if (msg) + { + dispatch_message_real (bus, msg, message); + } } static void dispatch_message (XedMessageBus *bus, - XedMessage *message) + XedMessage *message) { - g_signal_emit (bus, message_bus_signals[DISPATCH], 0, message); + g_signal_emit (bus, message_bus_signals[DISPATCH], 0, message); } static gboolean idle_dispatch (XedMessageBus *bus) { - GList *list; - GList *item; - - /* make sure to set idle_id to 0 first so that any new async messages - will be queued properly */ - bus->priv->idle_id = 0; + GList *list; + GList *item; - /* reverse queue to get correct delivery order */ - list = g_list_reverse (bus->priv->message_queue); - bus->priv->message_queue = NULL; - - for (item = list; item; item = item->next) - { - XedMessage *msg = XED_MESSAGE (item->data); - - dispatch_message (bus, msg); - } - - message_queue_free (list); - return FALSE; + /* make sure to set idle_id to 0 first so that any new async messages + will be queued properly */ + bus->priv->idle_id = 0; + + /* reverse queue to get correct delivery order */ + list = g_list_reverse (bus->priv->message_queue); + bus->priv->message_queue = NULL; + + for (item = list; item; item = item->next) + { + XedMessage *msg = XED_MESSAGE (item->data); + + dispatch_message (bus, msg); + } + + message_queue_free (list); + return FALSE; } typedef void (*MatchCallback) (XedMessageBus *, Message *, GList *); static void -process_by_id (XedMessageBus *bus, - guint id, - MatchCallback processor) +process_by_id (XedMessageBus *bus, + guint id, + MatchCallback processor) { - IdMap *idmap; - - idmap = (IdMap *)g_hash_table_lookup (bus->priv->idmap, GINT_TO_POINTER (id)); - - if (idmap == NULL) - { - g_warning ("No handler registered with id `%d'", id); - return; - } - - processor (bus, idmap->message, idmap->listener); + IdMap *idmap; + + idmap = (IdMap *)g_hash_table_lookup (bus->priv->idmap, GINT_TO_POINTER (id)); + + if (idmap == NULL) + { + g_warning ("No handler registered with id `%d'", id); + return; + } + + processor (bus, idmap->message, idmap->listener); } static void process_by_match (XedMessageBus *bus, - const gchar *object_path, - const gchar *method, - XedMessageCallback callback, - gpointer userdata, - MatchCallback processor) + const gchar *object_path, + const gchar *method, + XedMessageCallback callback, + gpointer userdata, + MatchCallback processor) { - Message *message; - GList *item; - - message = lookup_message (bus, object_path, method, FALSE); - - if (!message) - { - g_warning ("No such handler registered for %s.%s", object_path, method); - return; - } - - for (item = message->listeners; item; item = item->next) - { - Listener *listener = (Listener *)item->data; - - if (listener->callback == callback && - listener->userdata == userdata) - { - processor (bus, message, item); - return; - } - } - - g_warning ("No such handler registered for %s.%s", object_path, method); + Message *message; + GList *item; + + message = lookup_message (bus, object_path, method, FALSE); + + if (!message) + { + g_warning ("No such handler registered for %s.%s", object_path, method); + return; + } + + for (item = message->listeners; item; item = item->next) + { + Listener *listener = (Listener *)item->data; + + if (listener->callback == callback && listener->userdata == userdata) + { + processor (bus, message, item); + return; + } + } + + g_warning ("No such handler registered for %s.%s", object_path, method); } static void xed_message_bus_init (XedMessageBus *self) { - self->priv = XED_MESSAGE_BUS_GET_PRIVATE (self); - - self->priv->messages = g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify)g_free, - (GDestroyNotify)message_free); + self->priv = XED_MESSAGE_BUS_GET_PRIVATE (self); - self->priv->idmap = g_hash_table_new_full (g_direct_hash, - g_direct_equal, - NULL, - (GDestroyNotify)g_free); - - self->priv->types = g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify)g_free, - (GDestroyNotify)xed_message_type_unref); + self->priv->messages = g_hash_table_new_full (g_str_hash, + g_str_equal, + (GDestroyNotify)g_free, + (GDestroyNotify)message_free); + + self->priv->idmap = g_hash_table_new_full (g_direct_hash, + g_direct_equal, + NULL, + (GDestroyNotify)g_free); + + self->priv->types = g_hash_table_new_full (g_str_hash, + g_str_equal, + (GDestroyNotify)g_free, + (GDestroyNotify)xed_message_type_unref); } /** @@ -529,21 +538,20 @@ xed_message_bus_init (XedMessageBus *self) XedMessageBus * xed_message_bus_get_default (void) { - static XedMessageBus *default_bus = NULL; - - if (G_UNLIKELY (default_bus == NULL)) - { - default_bus = g_object_new (XED_TYPE_MESSAGE_BUS, NULL); - g_object_add_weak_pointer (G_OBJECT (default_bus), - (gpointer) &default_bus); - } - - return default_bus; + static XedMessageBus *default_bus = NULL; + + if (G_UNLIKELY (default_bus == NULL)) + { + default_bus = g_object_new (XED_TYPE_MESSAGE_BUS, NULL); + g_object_add_weak_pointer (G_OBJECT (default_bus), (gpointer) &default_bus); + } + + return default_bus; } /** * xed_message_bus_new: - * + * * Create a new message bus. Use xed_message_bus_get_default() to get the * default, application wide, message bus. Creating a new bus is useful for * associating a specific bus with for instance a #XedWindow. @@ -554,7 +562,7 @@ xed_message_bus_get_default (void) XedMessageBus * xed_message_bus_new (void) { - return XED_MESSAGE_BUS (g_object_new (XED_TYPE_MESSAGE_BUS, NULL)); + return XED_MESSAGE_BUS (g_object_new (XED_TYPE_MESSAGE_BUS, NULL)); } /** @@ -563,7 +571,7 @@ xed_message_bus_new (void) * @object_path: the object path * @method: the method * - * Get the registered #XedMessageType for @method at @object_path. The + * Get the registered #XedMessageType for @method at @object_path. The * returned #XedMessageType is owned by the bus and should not be unreffed. * * Return value: the registered #XedMessageType or %NULL if no message type @@ -572,21 +580,21 @@ xed_message_bus_new (void) */ XedMessageType * xed_message_bus_lookup (XedMessageBus *bus, - const gchar *object_path, - const gchar *method) + const gchar *object_path, + const gchar *method) { - gchar *identifier; - XedMessageType *message_type; - - g_return_val_if_fail (XED_IS_MESSAGE_BUS (bus), NULL); - g_return_val_if_fail (object_path != NULL, NULL); - g_return_val_if_fail (method != NULL, NULL); + gchar *identifier; + XedMessageType *message_type; - identifier = xed_message_type_identifier (object_path, method); - message_type = XED_MESSAGE_TYPE (g_hash_table_lookup (bus->priv->types, identifier)); - - g_free (identifier); - return message_type; + g_return_val_if_fail (XED_IS_MESSAGE_BUS (bus), NULL); + g_return_val_if_fail (object_path != NULL, NULL); + g_return_val_if_fail (method != NULL, NULL); + + identifier = xed_message_type_identifier (object_path, method); + message_type = XED_MESSAGE_TYPE (g_hash_table_lookup (bus->priv->types, identifier)); + + g_free (identifier); + return message_type; } /** @@ -598,9 +606,9 @@ xed_message_bus_lookup (XedMessageBus *bus, * @...: NULL terminated list of key/gtype method argument pairs * * Register a message on the bus. A message must be registered on the bus before - * it can be send. This function registers the type arguments for @method at - * @object_path. The arguments are specified with the variable arguments which - * should contain pairs of const gchar *key and GType terminated by %NULL. The + * it can be send. This function registers the type arguments for @method at + * @object_path. The arguments are specified with the variable arguments which + * should contain pairs of const gchar *key and GType terminated by %NULL. The * last @num_optional arguments are registered as optional (and are thus not * required when sending a message). * @@ -613,68 +621,67 @@ xed_message_bus_lookup (XedMessageBus *bus, */ XedMessageType * xed_message_bus_register (XedMessageBus *bus, - const gchar *object_path, - const gchar *method, - guint num_optional, - ...) + const gchar *object_path, + const gchar *method, + guint num_optional, + ...) { - gchar *identifier; - gpointer data; - va_list var_args; - XedMessageType *message_type; + gchar *identifier; + gpointer data; + va_list var_args; + XedMessageType *message_type; - g_return_val_if_fail (XED_IS_MESSAGE_BUS (bus), NULL); - g_return_val_if_fail (xed_message_type_is_valid_object_path (object_path), NULL); - - if (xed_message_bus_is_registered (bus, object_path, method)) - { - g_warning ("Message type for '%s.%s' is already registered", object_path, method); - return NULL; - } + g_return_val_if_fail (XED_IS_MESSAGE_BUS (bus), NULL); + g_return_val_if_fail (xed_message_type_is_valid_object_path (object_path), NULL); - identifier = xed_message_type_identifier (object_path, method); - data = g_hash_table_lookup (bus->priv->types, identifier); - - va_start (var_args, num_optional); - message_type = xed_message_type_new_valist (object_path, - method, - num_optional, - var_args); - va_end (var_args); - - if (message_type) - { - g_hash_table_insert (bus->priv->types, identifier, message_type); - g_signal_emit (bus, message_bus_signals[REGISTERED], 0, message_type); - } - else - { - g_free (identifier); - } - - return message_type; + if (xed_message_bus_is_registered (bus, object_path, method)) + { + g_warning ("Message type for '%s.%s' is already registered", object_path, method); + return NULL; + } + + identifier = xed_message_type_identifier (object_path, method); + data = g_hash_table_lookup (bus->priv->types, identifier); + + va_start (var_args, num_optional); + message_type = xed_message_type_new_valist (object_path, method, num_optional, var_args); + va_end (var_args); + + if (message_type) + { + g_hash_table_insert (bus->priv->types, identifier, message_type); + g_signal_emit (bus, message_bus_signals[REGISTERED], 0, message_type); + } + else + { + g_free (identifier); + } + + return message_type; } static void xed_message_bus_unregister_real (XedMessageBus *bus, - XedMessageType *message_type, - gboolean remove_from_store) + XedMessageType *message_type, + gboolean remove_from_store) { - gchar *identifier; - - g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); + gchar *identifier; - identifier = xed_message_type_identifier (xed_message_type_get_object_path (message_type), - xed_message_type_get_method (message_type)); - - /* Keep message type alive for signal emission */ - xed_message_type_ref (message_type); + g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); - if (!remove_from_store || g_hash_table_remove (bus->priv->types, identifier)) - g_signal_emit (bus, message_bus_signals[UNREGISTERED], 0, message_type); - - xed_message_type_unref (message_type); - g_free (identifier); + identifier = xed_message_type_identifier (xed_message_type_get_object_path (message_type), + xed_message_type_get_method (message_type)); + + /* Keep message type alive for signal emission */ + xed_message_type_ref (message_type); + + if (!remove_from_store || g_hash_table_remove (bus->priv->types, identifier)) + { + g_signal_emit (bus, message_bus_signals[UNREGISTERED], 0, message_type); + } + + xed_message_type_unref (message_type); + g_free (identifier); } /** @@ -682,7 +689,7 @@ xed_message_bus_unregister_real (XedMessageBus *bus, * @bus: a #XedMessageBus * @message_type: the #XedMessageType to unregister * - * Unregisters a previously registered message type. This is especially useful + * Unregisters a previously registered message type. This is especially useful * for plugins which should unregister message types when they are deactivated. * * This function emits the #XedMessageBus::unregistered signal. @@ -690,31 +697,31 @@ xed_message_bus_unregister_real (XedMessageBus *bus, */ void xed_message_bus_unregister (XedMessageBus *bus, - XedMessageType *message_type) + XedMessageType *message_type) { - g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); - xed_message_bus_unregister_real (bus, message_type, TRUE); + g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); + xed_message_bus_unregister_real (bus, message_type, TRUE); } -typedef struct +typedef struct { - XedMessageBus *bus; - const gchar *object_path; + XedMessageBus *bus; + const gchar *object_path; } UnregisterInfo; static gboolean -unregister_each (const gchar *identifier, - XedMessageType *message_type, - UnregisterInfo *info) +unregister_each (const gchar *identifier, + XedMessageType *message_type, + UnregisterInfo *info) { - if (strcmp (xed_message_type_get_object_path (message_type), - info->object_path) == 0) - { - xed_message_bus_unregister_real (info->bus, message_type, FALSE); - return TRUE; - } - - return FALSE; + if (strcmp (xed_message_type_get_object_path (message_type), + info->object_path) == 0) + { + xed_message_bus_unregister_real (info->bus, message_type, FALSE); + return TRUE; + } + + return FALSE; } /** @@ -731,16 +738,14 @@ unregister_each (const gchar *identifier, */ void xed_message_bus_unregister_all (XedMessageBus *bus, - const gchar *object_path) + const gchar *object_path) { - UnregisterInfo info = {bus, object_path}; + UnregisterInfo info = {bus, object_path}; - g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); - g_return_if_fail (object_path != NULL); + g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); + g_return_if_fail (object_path != NULL); - g_hash_table_foreach_remove (bus->priv->types, - (GHRFunc)unregister_each, - &info); + g_hash_table_foreach_remove (bus->priv->types, (GHRFunc)unregister_each, &info); } /** @@ -749,46 +754,46 @@ xed_message_bus_unregister_all (XedMessageBus *bus, * @object_path: the object path * @method: the method * - * Check whether a message type @method at @object_path is registered on the + * Check whether a message type @method at @object_path is registered on the * bus. * - * Return value: %TRUE if the @method at @object_path is a registered message + * Return value: %TRUE if the @method at @object_path is a registered message * type on the bus * */ gboolean -xed_message_bus_is_registered (XedMessageBus *bus, - const gchar *object_path, - const gchar *method) +xed_message_bus_is_registered (XedMessageBus *bus, + const gchar *object_path, + const gchar *method) { - gchar *identifier; - gboolean ret; - - g_return_val_if_fail (XED_IS_MESSAGE_BUS (bus), FALSE); - g_return_val_if_fail (object_path != NULL, FALSE); - g_return_val_if_fail (method != NULL, FALSE); + gchar *identifier; + gboolean ret; - identifier = xed_message_type_identifier (object_path, method); - ret = g_hash_table_lookup (bus->priv->types, identifier) != NULL; - - g_free(identifier); - return ret; + g_return_val_if_fail (XED_IS_MESSAGE_BUS (bus), FALSE); + g_return_val_if_fail (object_path != NULL, FALSE); + g_return_val_if_fail (method != NULL, FALSE); + + identifier = xed_message_type_identifier (object_path, method); + ret = g_hash_table_lookup (bus->priv->types, identifier) != NULL; + + g_free(identifier); + return ret; } typedef struct { - XedMessageBusForeach func; - gpointer userdata; + XedMessageBusForeach func; + gpointer userdata; } ForeachInfo; static void -foreach_type (const gchar *key, - XedMessageType *message_type, - ForeachInfo *info) +foreach_type (const gchar *key, + XedMessageType *message_type, + ForeachInfo *info) { - xed_message_type_ref (message_type); - info->func (message_type, info->userdata); - xed_message_type_unref (message_type); + xed_message_type_ref (message_type); + info->func (message_type, info->userdata); + xed_message_type_unref (message_type); } /** @@ -800,17 +805,17 @@ foreach_type (const gchar *key, * Calls @func for each message type registered on the bus * */ -void +void xed_message_bus_foreach (XedMessageBus *bus, - XedMessageBusForeach func, - gpointer userdata) + XedMessageBusForeach func, + gpointer userdata) { - ForeachInfo info = {func, userdata}; - - g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); - g_return_if_fail (func != NULL); + ForeachInfo info = {func, userdata}; - g_hash_table_foreach (bus->priv->types, (GHFunc)foreach_type, &info); + g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); + g_return_if_fail (func != NULL); + + g_hash_table_foreach (bus->priv->types, (GHFunc)foreach_type, &info); } /** @@ -830,24 +835,24 @@ xed_message_bus_foreach (XedMessageBus *bus, * */ guint -xed_message_bus_connect (XedMessageBus *bus, - const gchar *object_path, - const gchar *method, - XedMessageCallback callback, - gpointer userdata, - GDestroyNotify destroy_data) +xed_message_bus_connect (XedMessageBus *bus, + const gchar *object_path, + const gchar *method, + XedMessageCallback callback, + gpointer userdata, + GDestroyNotify destroy_data) { - Message *message; + Message *message; - g_return_val_if_fail (XED_IS_MESSAGE_BUS (bus), 0); - g_return_val_if_fail (object_path != NULL, 0); - g_return_val_if_fail (method != NULL, 0); - g_return_val_if_fail (callback != NULL, 0); - - /* lookup the message and create if it does not exist yet */ - message = lookup_message (bus, object_path, method, TRUE); - - return add_listener (bus, message, callback, userdata, destroy_data); + g_return_val_if_fail (XED_IS_MESSAGE_BUS (bus), 0); + g_return_val_if_fail (object_path != NULL, 0); + g_return_val_if_fail (method != NULL, 0); + g_return_val_if_fail (callback != NULL, 0); + + /* lookup the message and create if it does not exist yet */ + message = lookup_message (bus, object_path, method, TRUE); + + return add_listener (bus, message, callback, userdata, destroy_data); } /** @@ -860,11 +865,11 @@ xed_message_bus_connect (XedMessageBus *bus, */ void xed_message_bus_disconnect (XedMessageBus *bus, - guint id) + guint id) { - g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); - - process_by_id (bus, id, remove_listener); + g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); + + process_by_id (bus, id, remove_listener); } /** @@ -875,21 +880,21 @@ xed_message_bus_disconnect (XedMessageBus *bus, * @callback: the connected callback * @userdata: the userdata with which the callback was connected * - * Disconnects a previously connected message callback by matching the - * provided callback function and userdata. See also + * Disconnects a previously connected message callback by matching the + * provided callback function and userdata. See also * xed_message_bus_disconnect(). * */ void xed_message_bus_disconnect_by_func (XedMessageBus *bus, - const gchar *object_path, - const gchar *method, - XedMessageCallback callback, - gpointer userdata) + const gchar *object_path, + const gchar *method, + XedMessageCallback callback, + gpointer userdata) { - g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); - - process_by_match (bus, object_path, method, callback, userdata, remove_listener); + g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); + + process_by_match (bus, object_path, method, callback, userdata, remove_listener); } /** @@ -903,11 +908,11 @@ xed_message_bus_disconnect_by_func (XedMessageBus *bus, */ void xed_message_bus_block (XedMessageBus *bus, - guint id) + guint id) { - g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); - - process_by_id (bus, id, block_listener); + g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); + + process_by_id (bus, id, block_listener); } /** @@ -924,14 +929,14 @@ xed_message_bus_block (XedMessageBus *bus, */ void xed_message_bus_block_by_func (XedMessageBus *bus, - const gchar *object_path, - const gchar *method, - XedMessageCallback callback, - gpointer userdata) + const gchar *object_path, + const gchar *method, + XedMessageCallback callback, + gpointer userdata) { - g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); - - process_by_match (bus, object_path, method, callback, userdata, block_listener); + g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); + + process_by_match (bus, object_path, method, callback, userdata, block_listener); } /** @@ -944,11 +949,11 @@ xed_message_bus_block_by_func (XedMessageBus *bus, */ void xed_message_bus_unblock (XedMessageBus *bus, - guint id) + guint id) { - g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); - - process_by_id (bus, id, unblock_listener); + g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); + + process_by_id (bus, id, unblock_listener); } /** @@ -964,46 +969,47 @@ xed_message_bus_unblock (XedMessageBus *bus, */ void xed_message_bus_unblock_by_func (XedMessageBus *bus, - const gchar *object_path, - const gchar *method, - XedMessageCallback callback, - gpointer userdata) + const gchar *object_path, + const gchar *method, + XedMessageCallback callback, + gpointer userdata) { - g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); - - process_by_match (bus, object_path, method, callback, userdata, unblock_listener); + g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); + + process_by_match (bus, object_path, method, callback, userdata, unblock_listener); } static gboolean validate_message (XedMessage *message) { - if (!xed_message_validate (message)) - { - g_warning ("Message '%s.%s' is invalid", xed_message_get_object_path (message), - xed_message_get_method (message)); - return FALSE; - } - - return TRUE; + if (!xed_message_validate (message)) + { + g_warning ("Message '%s.%s' is invalid", xed_message_get_object_path (message), + xed_message_get_method (message)); + return FALSE; + } + + return TRUE; } static void send_message_real (XedMessageBus *bus, - XedMessage *message) + XedMessage *message) { - if (!validate_message (message)) - { - return; - } - - bus->priv->message_queue = g_list_prepend (bus->priv->message_queue, - g_object_ref (message)); + if (!validate_message (message)) + { + return; + } - if (bus->priv->idle_id == 0) - bus->priv->idle_id = g_idle_add_full (G_PRIORITY_HIGH, - (GSourceFunc)idle_dispatch, - bus, - NULL); + bus->priv->message_queue = g_list_prepend (bus->priv->message_queue, g_object_ref (message)); + + if (bus->priv->idle_id == 0) + { + bus->priv->idle_id = g_idle_add_full (G_PRIORITY_HIGH, + (GSourceFunc)idle_dispatch, + bus, + NULL); + } } /** @@ -1012,31 +1018,31 @@ send_message_real (XedMessageBus *bus, * @message: the message to send * * This sends the provided @message asynchronously over the bus. To send - * a message synchronously, use xed_message_bus_send_message_sync(). The + * a message synchronously, use xed_message_bus_send_message_sync(). The * convenience function xed_message_bus_send() can be used to easily send * a message without constructing the message object explicitly first. * */ void xed_message_bus_send_message (XedMessageBus *bus, - XedMessage *message) + XedMessage *message) { - g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); - g_return_if_fail (XED_IS_MESSAGE (message)); - - send_message_real (bus, message); + g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); + g_return_if_fail (XED_IS_MESSAGE (message)); + + send_message_real (bus, message); } static void send_message_sync_real (XedMessageBus *bus, XedMessage *message) { - if (!validate_message (message)) - { - return; - } - - dispatch_message (bus, message); + if (!validate_message (message)) + { + return; + } + + dispatch_message (bus, message); } /** @@ -1045,39 +1051,38 @@ send_message_sync_real (XedMessageBus *bus, * @message: the message to send * * This sends the provided @message synchronously over the bus. To send - * a message asynchronously, use xed_message_bus_send_message(). The + * a message asynchronously, use xed_message_bus_send_message(). The * convenience function xed_message_bus_send_sync() can be used to easily send * a message without constructing the message object explicitly first. * */ void xed_message_bus_send_message_sync (XedMessageBus *bus, - XedMessage *message) + XedMessage *message) { - g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); - g_return_if_fail (XED_IS_MESSAGE (message)); + g_return_if_fail (XED_IS_MESSAGE_BUS (bus)); + g_return_if_fail (XED_IS_MESSAGE (message)); - send_message_sync_real (bus, message); + send_message_sync_real (bus, message); } static XedMessage * create_message (XedMessageBus *bus, - const gchar *object_path, - const gchar *method, - va_list var_args) + const gchar *object_path, + const gchar *method, + va_list var_args) { - XedMessageType *message_type; - - message_type = xed_message_bus_lookup (bus, object_path, method); - - if (!message_type) - { - g_warning ("Could not find message type for '%s.%s'", object_path, method); - return NULL; - } + XedMessageType *message_type; - return xed_message_type_instantiate_valist (message_type, - var_args); + message_type = xed_message_bus_lookup (bus, object_path, method); + + if (!message_type) + { + g_warning ("Could not find message type for '%s.%s'", object_path, method); + return NULL; + } + + return xed_message_type_instantiate_valist (message_type, var_args); } /** @@ -1087,36 +1092,36 @@ create_message (XedMessageBus *bus, * @method: the method * @...: NULL terminated list of key/value pairs * - * This provides a convenient way to quickly send a message @method at - * @object_path asynchronously over the bus. The variable argument list - * specifies key (string) value pairs used to construct the message arguments. + * This provides a convenient way to quickly send a message @method at + * @object_path asynchronously over the bus. The variable argument list + * specifies key (string) value pairs used to construct the message arguments. * To send a message synchronously use xed_message_bus_send_sync(). * */ void xed_message_bus_send (XedMessageBus *bus, - const gchar *object_path, - const gchar *method, - ...) + const gchar *object_path, + const gchar *method, + ...) { - va_list var_args; - XedMessage *message; - - va_start (var_args, method); + va_list var_args; + XedMessage *message; - message = create_message (bus, object_path, method, var_args); - - if (message) - { - send_message_real (bus, message); - g_object_unref (message); - } - else - { - g_warning ("Could not instantiate message"); - } + va_start (var_args, method); - va_end (var_args); + message = create_message (bus, object_path, method, var_args); + + if (message) + { + send_message_real (bus, message); + g_object_unref (message); + } + else + { + g_warning ("Could not instantiate message"); + } + + va_end (var_args); } /** @@ -1126,9 +1131,9 @@ xed_message_bus_send (XedMessageBus *bus, * @method: the method * @...: NULL terminated list of key/value pairs * - * This provides a convenient way to quickly send a message @method at - * @object_path synchronously over the bus. The variable argument list - * specifies key (string) value pairs used to construct the message + * This provides a convenient way to quickly send a message @method at + * @object_path synchronously over the bus. The variable argument list + * specifies key (string) value pairs used to construct the message * arguments. To send a message asynchronously use xed_message_bus_send(). * * Return value: the constructed #XedMessage. The caller owns a reference @@ -1137,22 +1142,22 @@ xed_message_bus_send (XedMessageBus *bus, */ XedMessage * xed_message_bus_send_sync (XedMessageBus *bus, - const gchar *object_path, - const gchar *method, - ...) + const gchar *object_path, + const gchar *method, + ...) { - va_list var_args; - XedMessage *message; - - va_start (var_args, method); - message = create_message (bus, object_path, method, var_args); - - if (message) - send_message_sync_real (bus, message); + va_list var_args; + XedMessage *message; - va_end (var_args); - - return message; + va_start (var_args, method); + message = create_message (bus, object_path, method, var_args); + + if (message) + send_message_sync_real (bus, message); + + va_end (var_args); + + return message; } // ex:ts=8:noet: From e9834c088361324877e883f65813eaa3d8b14332 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 12 Dec 2016 02:50:04 -0800 Subject: [PATCH 016/132] xed-message-bus: Clean up an unused variables --- xed/xed-message-bus.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/xed/xed-message-bus.c b/xed/xed-message-bus.c index 1978705..5972ee7 100644 --- a/xed/xed-message-bus.c +++ b/xed/xed-message-bus.c @@ -627,7 +627,6 @@ xed_message_bus_register (XedMessageBus *bus, ...) { gchar *identifier; - gpointer data; va_list var_args; XedMessageType *message_type; @@ -641,7 +640,6 @@ xed_message_bus_register (XedMessageBus *bus, } identifier = xed_message_type_identifier (object_path, method); - data = g_hash_table_lookup (bus->priv->types, identifier); va_start (var_args, num_optional); message_type = xed_message_type_new_valist (object_path, method, num_optional, var_args); From a5c62d2380f5c687f9380833d270133a90a83f5d Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 12 Dec 2016 03:43:54 -0800 Subject: [PATCH 017/132] xed-io-error-message-area: Clean up code styling --- xed/xed-io-error-message-area.c | 1773 +++++++++++++++---------------- 1 file changed, 837 insertions(+), 936 deletions(-) diff --git a/xed/xed-io-error-message-area.c b/xed/xed-io-error-message-area.c index bfa7500..3677faf 100644 --- a/xed/xed-io-error-message-area.c +++ b/xed/xed-io-error-message-area.c @@ -2,7 +2,7 @@ * xed-io-error-message-area.c * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,18 +16,18 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ - + /* * Verbose error reporting for file I/O operations (load, save, revert, create) */ @@ -53,1143 +53,1044 @@ static gboolean is_recoverable_error (const GError *error) { - gboolean is_recoverable = FALSE; + gboolean is_recoverable = FALSE; - if (error->domain == G_IO_ERROR) - { - switch (error->code) { - case G_IO_ERROR_PERMISSION_DENIED: - case G_IO_ERROR_NOT_FOUND: - case G_IO_ERROR_HOST_NOT_FOUND: - case G_IO_ERROR_TIMED_OUT: - case G_IO_ERROR_NOT_MOUNTABLE_FILE: - case G_IO_ERROR_NOT_MOUNTED: - case G_IO_ERROR_BUSY: - is_recoverable = TRUE; - } - } + if (error->domain == G_IO_ERROR) + { + switch (error->code) + { + case G_IO_ERROR_PERMISSION_DENIED: + case G_IO_ERROR_NOT_FOUND: + case G_IO_ERROR_HOST_NOT_FOUND: + case G_IO_ERROR_TIMED_OUT: + case G_IO_ERROR_NOT_MOUNTABLE_FILE: + case G_IO_ERROR_NOT_MOUNTED: + case G_IO_ERROR_BUSY: + is_recoverable = TRUE; + } + } - return is_recoverable; + return is_recoverable; } static gboolean is_gio_error (const GError *error, - gint code) + gint code) { - return error->domain == G_IO_ERROR && error->code == code; + return error->domain == G_IO_ERROR && error->code == code; } static void set_contents (GtkWidget *area, - GtkWidget *contents) + GtkWidget *contents) { - GtkWidget *content_area; - - content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (area)); - gtk_container_add (GTK_CONTAINER (content_area), contents); + GtkWidget *content_area; + + content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (area)); + gtk_container_add (GTK_CONTAINER (content_area), contents); } static void info_bar_add_stock_button_with_text (GtkInfoBar *infobar, - const gchar *text, - const gchar *stock_id, - gint response_id) + const gchar *text, + const gchar *stock_id, + gint response_id) { - GtkWidget *button; - GtkWidget *image; + GtkWidget *button; + GtkWidget *image; - button = gtk_info_bar_add_button (infobar, text, response_id); - image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON); - gtk_button_set_image (GTK_BUTTON (button), image); + button = gtk_info_bar_add_button (infobar, text, response_id); + image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON); + gtk_button_set_image (GTK_BUTTON (button), image); } static void set_message_area_text_and_icon (GtkWidget *message_area, - const gchar *icon_stock_id, - const gchar *primary_text, - const gchar *secondary_text) + const gchar *icon_stock_id, + const gchar *primary_text, + const gchar *secondary_text) { - GtkWidget *hbox_content; - GtkWidget *image; - GtkWidget *vbox; - gchar *primary_markup; - gchar *secondary_markup; - GtkWidget *primary_label; - GtkWidget *secondary_label; + GtkWidget *hbox_content; + GtkWidget *image; + GtkWidget *vbox; + gchar *primary_markup; + gchar *secondary_markup; + GtkWidget *primary_label; + GtkWidget *secondary_label; - hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); + hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); - image = gtk_image_new_from_stock (icon_stock_id, GTK_ICON_SIZE_DIALOG); - gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0); - gtk_widget_set_halign (image, GTK_ALIGN_CENTER); - gtk_widget_set_valign (image, GTK_ALIGN_START); + image = gtk_image_new_from_stock (icon_stock_id, GTK_ICON_SIZE_DIALOG); + gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0); + gtk_widget_set_halign (image, GTK_ALIGN_CENTER); + gtk_widget_set_valign (image, GTK_ALIGN_START); - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0); + vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0); - primary_markup = g_strdup_printf ("%s", primary_text); - primary_label = gtk_label_new (primary_markup); - g_free (primary_markup); - gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0); - gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); - gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); - gtk_widget_set_can_focus (primary_label, TRUE); - gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); + primary_markup = g_strdup_printf ("%s", primary_text); + primary_label = gtk_label_new (primary_markup); + g_free (primary_markup); + gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0); + gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); + gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); + gtk_widget_set_can_focus (primary_label, TRUE); + gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); - if (secondary_text != NULL) - { - secondary_markup = g_strdup_printf ("%s", - secondary_text); - secondary_label = gtk_label_new (secondary_markup); - g_free (secondary_markup); - gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0); - gtk_widget_set_can_focus (secondary_label, TRUE); - gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); - gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); - gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); - } + if (secondary_text != NULL) + { + secondary_markup = g_strdup_printf ("%s", secondary_text); + secondary_label = gtk_label_new (secondary_markup); + g_free (secondary_markup); + gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0); + gtk_widget_set_can_focus (secondary_label, TRUE); + gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); + gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); + gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); + } - gtk_widget_show_all (hbox_content); - set_contents (message_area, hbox_content); + gtk_widget_show_all (hbox_content); + set_contents (message_area, hbox_content); } static GtkWidget * create_io_loading_error_message_area (const gchar *primary_text, - const gchar *secondary_text, - gboolean recoverable_error) + const gchar *secondary_text, + gboolean recoverable_error) { - GtkWidget *message_area; + GtkWidget *message_area; - message_area = gtk_info_bar_new_with_buttons ( - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - NULL); - gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), - GTK_MESSAGE_ERROR); + message_area = gtk_info_bar_new_with_buttons (GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); + gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), GTK_MESSAGE_ERROR); - set_message_area_text_and_icon (message_area, - "gtk-dialog-error", - primary_text, - secondary_text); + set_message_area_text_and_icon (message_area, "gtk-dialog-error", primary_text, secondary_text); - if (recoverable_error) - { - info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area), - _("_Retry"), - GTK_STOCK_REFRESH, - GTK_RESPONSE_OK); - } + if (recoverable_error) + { + info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area), _("_Retry"), + GTK_STOCK_REFRESH, GTK_RESPONSE_OK); + } - return message_area; + return message_area; } static gboolean parse_gio_error (gint code, - gchar **error_message, - gchar **message_details, - const gchar *uri, - const gchar *uri_for_display) + gchar **error_message, + gchar **message_details, + const gchar *uri, + const gchar *uri_for_display) { - gboolean ret = TRUE; + gboolean ret = TRUE; - switch (code) - { - case G_IO_ERROR_NOT_FOUND: - case G_IO_ERROR_NOT_DIRECTORY: - *error_message = g_strdup_printf (_("Could not find the file %s."), - uri_for_display); - *message_details = g_strdup (_("Please check that you typed the " - "location correctly and try again.")); - break; - case G_IO_ERROR_NOT_SUPPORTED: - { - gchar *scheme_string; - gchar *scheme_markup; - - scheme_string = g_uri_parse_scheme (uri); + switch (code) + { + case G_IO_ERROR_NOT_FOUND: + case G_IO_ERROR_NOT_DIRECTORY: + *error_message = g_strdup_printf (_("Could not find the file %s."), uri_for_display); + *message_details = g_strdup (_("Please check that you typed the " + "location correctly and try again.")); + break; + case G_IO_ERROR_NOT_SUPPORTED: + { + gchar *scheme_string; + gchar *scheme_markup; - if ((scheme_string != NULL) && g_utf8_validate (scheme_string, -1, NULL)) - { - scheme_markup = g_markup_printf_escaped ("%s:", scheme_string); + scheme_string = g_uri_parse_scheme (uri); - /* Translators: %s is a URI scheme (like for example http:, ftp:, etc.) */ - *message_details = g_strdup_printf (_("xed cannot handle %s locations."), - scheme_markup); - g_free (scheme_markup); - } - else - { - *message_details = g_strdup (_("xed cannot handle this location.")); - } + if ((scheme_string != NULL) && g_utf8_validate (scheme_string, -1, NULL)) + { + scheme_markup = g_markup_printf_escaped ("%s:", scheme_string); - g_free (scheme_string); - } - break; + /* Translators: %s is a URI scheme (like for example http:, ftp:, etc.) */ + *message_details = g_strdup_printf (_("xed cannot handle %s locations."), scheme_markup); + g_free (scheme_markup); + } + else + { + *message_details = g_strdup (_("xed cannot handle this location.")); + } - case G_IO_ERROR_NOT_MOUNTABLE_FILE: - *message_details = g_strdup (_("The location of the file cannot be mounted.")); - break; - - case G_IO_ERROR_NOT_MOUNTED: - *message_details = g_strdup( _("The location of the file cannot be accessed because it is not mounted.")); + g_free (scheme_string); + } + break; + case G_IO_ERROR_NOT_MOUNTABLE_FILE: + *message_details = g_strdup (_("The location of the file cannot be mounted.")); + break; + case G_IO_ERROR_NOT_MOUNTED: + *message_details = g_strdup( _("The location of the file cannot be accessed because it is not mounted.")); + break; + case G_IO_ERROR_IS_DIRECTORY: + *error_message = g_strdup_printf (_("%s is a directory."), uri_for_display); + *message_details = g_strdup (_("Please check that you typed the " + "location correctly and try again.")); + break; + case G_IO_ERROR_INVALID_FILENAME: + *error_message = g_strdup_printf (_("%s is not a valid location."), uri_for_display); + *message_details = g_strdup (_("Please check that you typed the " + "location correctly and try again.")); + break; + case G_IO_ERROR_HOST_NOT_FOUND: + /* This case can be hit for user-typed strings like "foo" due to + * the code that guesses web addresses when there's no initial "/". + * But this case is also hit for legitimate web addresses when + * the proxy is set up wrong. + */ + { + gchar *hn = NULL; - break; - case G_IO_ERROR_IS_DIRECTORY: - *error_message = g_strdup_printf (_("%s is a directory."), - uri_for_display); - *message_details = g_strdup (_("Please check that you typed the " - "location correctly and try again.")); - break; - - case G_IO_ERROR_INVALID_FILENAME: - *error_message = g_strdup_printf (_("%s is not a valid location."), - uri_for_display); - *message_details = g_strdup (_("Please check that you typed the " - "location correctly and try again.")); - break; - - case G_IO_ERROR_HOST_NOT_FOUND: - /* This case can be hit for user-typed strings like "foo" due to - * the code that guesses web addresses when there's no initial "/". - * But this case is also hit for legitimate web addresses when - * the proxy is set up wrong. - */ - { - gchar *hn = NULL; + if (xed_utils_decode_uri (uri, NULL, NULL, &hn, NULL, NULL)) + { + if (hn != NULL) + { + gchar *host_markup; + gchar *host_name; - if (xed_utils_decode_uri (uri, NULL, NULL, &hn, NULL, NULL)) - { - if (hn != NULL) - { - gchar *host_markup; - gchar *host_name; + host_name = xed_utils_make_valid_utf8 (hn); + g_free (hn); - host_name = xed_utils_make_valid_utf8 (hn); - g_free (hn); + host_markup = g_markup_printf_escaped ("%s", host_name); + g_free (host_name); - host_markup = g_markup_printf_escaped ("%s", host_name); - g_free (host_name); + /* Translators: %s is a host name */ + *message_details = g_strdup_printf (_("Host %s could not be found. " + "Please check that your proxy settings " + "are correct and try again."), + host_markup); - /* Translators: %s is a host name */ - *message_details = g_strdup_printf ( - _("Host %s could not be found. " - "Please check that your proxy settings " - "are correct and try again."), - host_markup); + g_free (host_markup); + } + } - g_free (host_markup); - } - } - - if (!*message_details) - { - /* use the same string as INVALID_HOST */ - *message_details = g_strdup_printf ( - _("Hostname was invalid. " - "Please check that you typed the location " - "correctly and try again.")); - } - } - break; + if (!*message_details) + { + /* use the same string as INVALID_HOST */ + *message_details = g_strdup_printf (_("Hostname was invalid. " + "Please check that you typed the location " + "correctly and try again.")); + } + } + break; + case G_IO_ERROR_NOT_REGULAR_FILE: + *message_details = g_strdup_printf (_("%s is not a regular file."), uri_for_display); + break; + case G_IO_ERROR_TIMED_OUT: + *message_details = g_strdup (_("Connection timed out. Please try again.")); + break; + default: + ret = FALSE; + break; + } - case G_IO_ERROR_NOT_REGULAR_FILE: - *message_details = g_strdup_printf (_("%s is not a regular file."), - uri_for_display); - break; - - case G_IO_ERROR_TIMED_OUT: - *message_details = g_strdup (_("Connection timed out. Please try again.")); - break; - - default: - ret = FALSE; - break; - } - - return ret; + return ret; } static gboolean parse_xed_error (gint code, - gchar **error_message, - gchar **message_details, - const gchar *uri, - const gchar *uri_for_display) + gchar **error_message, + gchar **message_details, + const gchar *uri, + const gchar *uri_for_display) { - gboolean ret = TRUE; + gboolean ret = TRUE; - switch (code) - { - case XED_DOCUMENT_ERROR_TOO_BIG: - *message_details = g_strdup (_("The file is too big.")); - break; + switch (code) + { + case XED_DOCUMENT_ERROR_TOO_BIG: + *message_details = g_strdup (_("The file is too big.")); + break; + default: + ret = FALSE; + break; + } - default: - ret = FALSE; - break; - } - - return ret; + return ret; } static void -parse_error (const GError *error, - gchar **error_message, - gchar **message_details, - const gchar *uri, - const gchar *uri_for_display) +parse_error (const GError *error, + gchar **error_message, + gchar **message_details, + const gchar *uri, + const gchar *uri_for_display) { - gboolean ret = FALSE; + gboolean ret = FALSE; - if (error->domain == G_IO_ERROR) - { - ret = parse_gio_error (error->code, - error_message, - message_details, - uri, - uri_for_display); - } - else if (error->domain == XED_DOCUMENT_ERROR) - { - ret = parse_xed_error (error->code, - error_message, - message_details, - uri, - uri_for_display); - } - - if (!ret) - { - g_warning ("Hit unhandled case %d (%s) in %s.", - error->code, error->message, G_STRFUNC); - *message_details = g_strdup_printf (_("Unexpected error: %s"), - error->message); - } + if (error->domain == G_IO_ERROR) + { + ret = parse_gio_error (error->code, error_message, message_details, uri, uri_for_display); + } + else if (error->domain == XED_DOCUMENT_ERROR) + { + ret = parse_xed_error (error->code, error_message, message_details, uri, uri_for_display); + } + + if (!ret) + { + g_warning ("Hit unhandled case %d (%s) in %s.", error->code, error->message, G_STRFUNC); + *message_details = g_strdup_printf (_("Unexpected error: %s"), error->message); + } } GtkWidget * xed_unrecoverable_reverting_error_message_area_new (const gchar *uri, - const GError *error) + const GError *error) { - gchar *error_message = NULL; - gchar *message_details = NULL; - gchar *full_formatted_uri; - gchar *uri_for_display; - gchar *temp_uri_for_display; - GtkWidget *message_area; + gchar *error_message = NULL; + gchar *message_details = NULL; + gchar *full_formatted_uri; + gchar *uri_for_display; + gchar *temp_uri_for_display; + GtkWidget *message_area; - g_return_val_if_fail (uri != NULL, NULL); - g_return_val_if_fail (error != NULL, NULL); - g_return_val_if_fail ((error->domain == XED_DOCUMENT_ERROR) || - (error->domain == G_IO_ERROR), NULL); + g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (error != NULL, NULL); + g_return_val_if_fail ((error->domain == XED_DOCUMENT_ERROR) || (error->domain == G_IO_ERROR), NULL); - full_formatted_uri = xed_utils_uri_for_display (uri); + full_formatted_uri = xed_utils_uri_for_display (uri); - /* Truncate the URI so it doesn't get insanely wide. Note that even - * though the dialog uses wrapped text, if the URI doesn't contain - * white space then the text-wrapping code is too stupid to wrap it. - */ - temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, - MAX_URI_IN_DIALOG_LENGTH); - g_free (full_formatted_uri); + /* Truncate the URI so it doesn't get insanely wide. Note that even + * though the dialog uses wrapped text, if the URI doesn't contain + * white space then the text-wrapping code is too stupid to wrap it. + */ + temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, MAX_URI_IN_DIALOG_LENGTH); + g_free (full_formatted_uri); - uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); - g_free (temp_uri_for_display); + uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); + g_free (temp_uri_for_display); - if (is_gio_error (error, G_IO_ERROR_NOT_FOUND)) - { - message_details = g_strdup (_("xed cannot find the file. " - "Perhaps it has recently been deleted.")); - } - else - { - parse_error (error, &error_message, &message_details, uri, uri_for_display); - } + if (is_gio_error (error, G_IO_ERROR_NOT_FOUND)) + { + message_details = g_strdup (_("xed cannot find the file. " + "Perhaps it has recently been deleted.")); + } + else + { + parse_error (error, &error_message, &message_details, uri, uri_for_display); + } - if (error_message == NULL) - { - error_message = g_strdup_printf (_("Could not revert the file %s."), - uri_for_display); - } + if (error_message == NULL) + { + error_message = g_strdup_printf (_("Could not revert the file %s."), uri_for_display); + } - message_area = create_io_loading_error_message_area (error_message, - message_details, - FALSE); + message_area = create_io_loading_error_message_area (error_message, message_details, FALSE); - g_free (uri_for_display); - g_free (error_message); - g_free (message_details); + g_free (uri_for_display); + g_free (error_message); + g_free (message_details); - return message_area; + return message_area; } static void -create_combo_box (GtkWidget *message_area, GtkWidget *vbox) +create_combo_box (GtkWidget *message_area, + GtkWidget *vbox) { - GtkWidget *hbox; - GtkWidget *label; - GtkWidget *menu; - gchar *label_markup; + GtkWidget *hbox; + GtkWidget *label; + GtkWidget *menu; + gchar *label_markup; - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - label_markup = g_strdup_printf ("%s", - _("Ch_aracter Encoding:")); - label = gtk_label_new_with_mnemonic (label_markup); - g_free (label_markup); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - menu = xed_encodings_combo_box_new (TRUE); - g_object_set_data (G_OBJECT (message_area), - "xed-message-area-encoding-menu", - menu); + label_markup = g_strdup_printf ("%s", _("Ch_aracter Encoding:")); + label = gtk_label_new_with_mnemonic (label_markup); + g_free (label_markup); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + menu = xed_encodings_combo_box_new (TRUE); + g_object_set_data (G_OBJECT (message_area), "xed-message-area-encoding-menu", menu); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), menu); - gtk_box_pack_start (GTK_BOX (hbox), - label, - FALSE, - FALSE, - 0); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), menu); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), menu, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), - menu, - FALSE, - FALSE, - 0); - - gtk_widget_show_all (hbox); - gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0); + gtk_widget_show_all (hbox); + gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0); } static GtkWidget * create_conversion_error_message_area (const gchar *primary_text, - const gchar *secondary_text, - gboolean edit_anyway) + const gchar *secondary_text, + gboolean edit_anyway) { - GtkWidget *message_area; - GtkWidget *hbox_content; - GtkWidget *image; - GtkWidget *vbox; - gchar *primary_markup; - gchar *secondary_markup; - GtkWidget *primary_label; - GtkWidget *secondary_label; + GtkWidget *message_area; + GtkWidget *hbox_content; + GtkWidget *image; + GtkWidget *vbox; + gchar *primary_markup; + gchar *secondary_markup; + GtkWidget *primary_label; + GtkWidget *secondary_label; - message_area = gtk_info_bar_new (); + message_area = gtk_info_bar_new (); - info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area), - _("_Retry"), - GTK_STOCK_REDO, - GTK_RESPONSE_OK); + info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area), _("_Retry"), + GTK_STOCK_REDO, GTK_RESPONSE_OK); - if (edit_anyway) - { - gtk_info_bar_add_button (GTK_INFO_BAR (message_area), - /* Translators: the access key chosen for this string should be - different from other main menu access keys (Open, Edit, View...) */ - _("Edit Any_way"), - GTK_RESPONSE_YES); - gtk_info_bar_add_button (GTK_INFO_BAR (message_area), - /* Translators: the access key chosen for this string should be - different from other main menu access keys (Open, Edit, View...) */ - _("D_on't Edit"), - GTK_RESPONSE_NO); - gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), - GTK_MESSAGE_WARNING); - } - else - { - gtk_info_bar_add_button (GTK_INFO_BAR (message_area), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); - gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), - GTK_MESSAGE_ERROR); - } + if (edit_anyway) + { + gtk_info_bar_add_button (GTK_INFO_BAR (message_area), + /* Translators: the access key chosen for this string should be + different from other main menu access keys (Open, Edit, View...) */ + _("Edit Any_way"), + GTK_RESPONSE_YES); + gtk_info_bar_add_button (GTK_INFO_BAR (message_area), + /* Translators: the access key chosen for this string should be + different from other main menu access keys (Open, Edit, View...) */ + _("D_on't Edit"), + GTK_RESPONSE_NO); + gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), GTK_MESSAGE_WARNING); + } + else + { + gtk_info_bar_add_button (GTK_INFO_BAR (message_area), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), GTK_MESSAGE_ERROR); + } - hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); + hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); - image = gtk_image_new_from_stock ("gtk-dialog-error", GTK_ICON_SIZE_DIALOG); - gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0); - gtk_widget_set_halign (image, GTK_ALIGN_CENTER); - gtk_widget_set_valign (image, GTK_ALIGN_START); + image = gtk_image_new_from_stock ("gtk-dialog-error", GTK_ICON_SIZE_DIALOG); + gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0); + gtk_widget_set_halign (image, GTK_ALIGN_CENTER); + gtk_widget_set_valign (image, GTK_ALIGN_START); - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0); - - primary_markup = g_strdup_printf ("%s", primary_text); - primary_label = gtk_label_new (primary_markup); - g_free (primary_markup); - gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0); - gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); - gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); - gtk_widget_set_can_focus (primary_label, TRUE); - gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); + vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0); - if (secondary_text != NULL) - { - secondary_markup = g_strdup_printf ("%s", - secondary_text); - secondary_label = gtk_label_new (secondary_markup); - g_free (secondary_markup); - gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0); - gtk_widget_set_can_focus (secondary_label, TRUE); - gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); - gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); - gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); - } + primary_markup = g_strdup_printf ("%s", primary_text); + primary_label = gtk_label_new (primary_markup); + g_free (primary_markup); + gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0); + gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); + gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); + gtk_widget_set_can_focus (primary_label, TRUE); + gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); - create_combo_box (message_area, vbox); - gtk_widget_show_all (hbox_content); - set_contents (message_area, hbox_content); + if (secondary_text != NULL) + { + secondary_markup = g_strdup_printf ("%s", secondary_text); + secondary_label = gtk_label_new (secondary_markup); + g_free (secondary_markup); + gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0); + gtk_widget_set_can_focus (secondary_label, TRUE); + gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); + gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); + gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); + } - return message_area; + create_combo_box (message_area, vbox); + gtk_widget_show_all (hbox_content); + set_contents (message_area, hbox_content); + + return message_area; } GtkWidget * -xed_io_loading_error_message_area_new (const gchar *uri, - const XedEncoding *encoding, - const GError *error) +xed_io_loading_error_message_area_new (const gchar *uri, + const XedEncoding *encoding, + const GError *error) { - gchar *error_message = NULL; - gchar *message_details = NULL; - gchar *full_formatted_uri; - gchar *encoding_name; - gchar *uri_for_display; - gchar *temp_uri_for_display; - GtkWidget *message_area; - gboolean edit_anyway = FALSE; - gboolean convert_error = FALSE; - - g_return_val_if_fail (uri != NULL, NULL); - g_return_val_if_fail (error != NULL, NULL); - g_return_val_if_fail ((error->domain == G_CONVERT_ERROR) || - (error->domain == XED_DOCUMENT_ERROR) || - (error->domain == G_IO_ERROR), NULL); - - full_formatted_uri = xed_utils_uri_for_display (uri); + gchar *error_message = NULL; + gchar *message_details = NULL; + gchar *full_formatted_uri; + gchar *encoding_name; + gchar *uri_for_display; + gchar *temp_uri_for_display; + GtkWidget *message_area; + gboolean edit_anyway = FALSE; + gboolean convert_error = FALSE; - /* Truncate the URI so it doesn't get insanely wide. Note that even - * though the dialog uses wrapped text, if the URI doesn't contain - * white space then the text-wrapping code is too stupid to wrap it. - */ - temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, - MAX_URI_IN_DIALOG_LENGTH); - g_free (full_formatted_uri); - - uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); - g_free (temp_uri_for_display); + g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (error != NULL, NULL); + g_return_val_if_fail ((error->domain == G_CONVERT_ERROR) || + (error->domain == XED_DOCUMENT_ERROR) || + (error->domain == G_IO_ERROR), NULL); - if (encoding != NULL) - encoding_name = xed_encoding_to_string (encoding); - else - encoding_name = g_strdup ("UTF-8"); + full_formatted_uri = xed_utils_uri_for_display (uri); - if (is_gio_error (error, G_IO_ERROR_TOO_MANY_LINKS)) - { - message_details = g_strdup (_("The number of followed links is limited and the actual file could not be found within this limit.")); - } - else if (is_gio_error (error, G_IO_ERROR_PERMISSION_DENIED)) - { - message_details = g_strdup (_("You do not have the permissions necessary to open the file.")); - } - else if ((is_gio_error (error, G_IO_ERROR_INVALID_DATA) && encoding == NULL) || - (error->domain == XED_DOCUMENT_ERROR && - error->code == XED_DOCUMENT_ERROR_ENCODING_AUTO_DETECTION_FAILED)) - { - message_details = g_strconcat (_("xed has not been able to detect " - "the character encoding."), "\n", - _("Please check that you are not trying to open a binary file."), "\n", - _("Select a character encoding from the menu and try again."), NULL); - convert_error = TRUE; - } - else if (error->domain == XED_DOCUMENT_ERROR && - error->code == XED_DOCUMENT_ERROR_CONVERSION_FALLBACK) - { - error_message = g_strdup_printf (_("There was a problem opening the file %s."), - uri_for_display); - message_details = g_strconcat (_("The file you opened has some invalid characters. " - "If you continue editing this file you could make this " - "document useless."), "\n", - _("You can also choose another character encoding and try again."), - NULL); - edit_anyway = TRUE; - convert_error = TRUE; - } - else if (is_gio_error (error, G_IO_ERROR_INVALID_DATA) && encoding != NULL) - { - error_message = g_strdup_printf (_("Could not open the file %s using the %s character encoding."), - uri_for_display, - encoding_name); - message_details = g_strconcat (_("Please check that you are not trying to open a binary file."), "\n", - _("Select a different character encoding from the menu and try again."), NULL); - convert_error = TRUE; - } - else - { - parse_error (error, &error_message, &message_details, uri, uri_for_display); - } + /* Truncate the URI so it doesn't get insanely wide. Note that even + * though the dialog uses wrapped text, if the URI doesn't contain + * white space then the text-wrapping code is too stupid to wrap it. + */ + temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, MAX_URI_IN_DIALOG_LENGTH); + g_free (full_formatted_uri); - if (error_message == NULL) - { - error_message = g_strdup_printf (_("Could not open the file %s."), - uri_for_display); - } + uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); + g_free (temp_uri_for_display); - if (convert_error) - { - message_area = create_conversion_error_message_area (error_message, - message_details, - edit_anyway); - } - else - { - message_area = create_io_loading_error_message_area (error_message, - message_details, - is_recoverable_error (error)); - } + if (encoding != NULL) + { + encoding_name = xed_encoding_to_string (encoding); + } + else + { + encoding_name = g_strdup ("UTF-8"); + } - g_free (uri_for_display); - g_free (encoding_name); - g_free (error_message); - g_free (message_details); - - return message_area; + if (is_gio_error (error, G_IO_ERROR_TOO_MANY_LINKS)) + { + message_details = g_strdup (_("The number of followed links is limited and the actual file could not be found within this limit.")); + } + else if (is_gio_error (error, G_IO_ERROR_PERMISSION_DENIED)) + { + message_details = g_strdup (_("You do not have the permissions necessary to open the file.")); + } + else if ((is_gio_error (error, G_IO_ERROR_INVALID_DATA) && encoding == NULL) || + (error->domain == XED_DOCUMENT_ERROR && + error->code == XED_DOCUMENT_ERROR_ENCODING_AUTO_DETECTION_FAILED)) + { + message_details = g_strconcat (_("xed has not been able to detect " + "the character encoding."), "\n", + _("Please check that you are not trying to open a binary file."), "\n", + _("Select a character encoding from the menu and try again."), NULL); + convert_error = TRUE; + } + else if (error->domain == XED_DOCUMENT_ERROR && error->code == XED_DOCUMENT_ERROR_CONVERSION_FALLBACK) + { + error_message = g_strdup_printf (_("There was a problem opening the file %s."), uri_for_display); + message_details = g_strconcat (_("The file you opened has some invalid characters. " + "If you continue editing this file you could make this " + "document useless."), "\n", + _("You can also choose another character encoding and try again."), + NULL); + edit_anyway = TRUE; + convert_error = TRUE; + } + else if (is_gio_error (error, G_IO_ERROR_INVALID_DATA) && encoding != NULL) + { + error_message = g_strdup_printf (_("Could not open the file %s using the %s character encoding."), + uri_for_display, + encoding_name); + message_details = g_strconcat (_("Please check that you are not trying to open a binary file."), "\n", + _("Select a different character encoding from the menu and try again."), NULL); + convert_error = TRUE; + } + else + { + parse_error (error, &error_message, &message_details, uri, uri_for_display); + } + + if (error_message == NULL) + { + error_message = g_strdup_printf (_("Could not open the file %s."), uri_for_display); + } + + if (convert_error) + { + message_area = create_conversion_error_message_area (error_message, message_details, edit_anyway); + } + else + { + message_area = create_io_loading_error_message_area (error_message, + message_details, + is_recoverable_error (error)); + } + + g_free (uri_for_display); + g_free (encoding_name); + g_free (error_message); + g_free (message_details); + + return message_area; } GtkWidget * -xed_conversion_error_while_saving_message_area_new ( - const gchar *uri, - const XedEncoding *encoding, - const GError *error) +xed_conversion_error_while_saving_message_area_new (const gchar *uri, + const XedEncoding *encoding, + const GError *error) { - gchar *error_message = NULL; - gchar *message_details = NULL; - gchar *full_formatted_uri; - gchar *encoding_name; - gchar *uri_for_display; - gchar *temp_uri_for_display; - GtkWidget *message_area; - - g_return_val_if_fail (uri != NULL, NULL); - g_return_val_if_fail (error != NULL, NULL); - g_return_val_if_fail (error->domain == G_CONVERT_ERROR || - error->domain == G_IO_ERROR, NULL); - g_return_val_if_fail (encoding != NULL, NULL); - - full_formatted_uri = xed_utils_uri_for_display (uri); + gchar *error_message = NULL; + gchar *message_details = NULL; + gchar *full_formatted_uri; + gchar *encoding_name; + gchar *uri_for_display; + gchar *temp_uri_for_display; + GtkWidget *message_area; - /* Truncate the URI so it doesn't get insanely wide. Note that even - * though the dialog uses wrapped text, if the URI doesn't contain - * white space then the text-wrapping code is too stupid to wrap it. - */ - temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, - MAX_URI_IN_DIALOG_LENGTH); - g_free (full_formatted_uri); - - uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); - g_free (temp_uri_for_display); + g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (error != NULL, NULL); + g_return_val_if_fail (error->domain == G_CONVERT_ERROR || + error->domain == G_IO_ERROR, NULL); + g_return_val_if_fail (encoding != NULL, NULL); - encoding_name = xed_encoding_to_string (encoding); - - error_message = g_strdup_printf (_("Could not save the file %s using the %s character encoding."), - uri_for_display, - encoding_name); - message_details = g_strconcat (_("The document contains one or more characters that cannot be encoded " - "using the specified character encoding."), "\n", - _("Select a different character encoding from the menu and try again."), NULL); - - message_area = create_conversion_error_message_area ( - error_message, - message_details, - FALSE); + full_formatted_uri = xed_utils_uri_for_display (uri); - g_free (uri_for_display); - g_free (encoding_name); - g_free (error_message); - g_free (message_details); - - return message_area; + /* Truncate the URI so it doesn't get insanely wide. Note that even + * though the dialog uses wrapped text, if the URI doesn't contain + * white space then the text-wrapping code is too stupid to wrap it. + */ + temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, MAX_URI_IN_DIALOG_LENGTH); + g_free (full_formatted_uri); + + uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); + g_free (temp_uri_for_display); + + encoding_name = xed_encoding_to_string (encoding); + + error_message = g_strdup_printf (_("Could not save the file %s using the %s character encoding."), + uri_for_display, + encoding_name); + message_details = g_strconcat (_("The document contains one or more characters that cannot be encoded " + "using the specified character encoding."), "\n", + _("Select a different character encoding from the menu and try again."), NULL); + + message_area = create_conversion_error_message_area (error_message, message_details, FALSE); + + g_free (uri_for_display); + g_free (encoding_name); + g_free (error_message); + g_free (message_details); + + return message_area; } const XedEncoding * xed_conversion_error_message_area_get_encoding (GtkWidget *message_area) { - gpointer menu; + gpointer menu; - g_return_val_if_fail (GTK_IS_INFO_BAR (message_area), NULL); + g_return_val_if_fail (GTK_IS_INFO_BAR (message_area), NULL); - menu = g_object_get_data (G_OBJECT (message_area), - "xed-message-area-encoding-menu"); - g_return_val_if_fail (menu, NULL); - - return xed_encodings_combo_box_get_selected_encoding - (XED_ENCODINGS_COMBO_BOX (menu)); + menu = g_object_get_data (G_OBJECT (message_area), "xed-message-area-encoding-menu"); + g_return_val_if_fail (menu, NULL); + + return xed_encodings_combo_box_get_selected_encoding (XED_ENCODINGS_COMBO_BOX (menu)); } GtkWidget * xed_file_already_open_warning_message_area_new (const gchar *uri) { - GtkWidget *message_area; - GtkWidget *hbox_content; - GtkWidget *image; - GtkWidget *vbox; - gchar *primary_markup; - gchar *secondary_markup; - GtkWidget *primary_label; - GtkWidget *secondary_label; - gchar *primary_text; - const gchar *secondary_text; - gchar *full_formatted_uri; - gchar *uri_for_display; - gchar *temp_uri_for_display; - - full_formatted_uri = xed_utils_uri_for_display (uri); + GtkWidget *message_area; + GtkWidget *hbox_content; + GtkWidget *image; + GtkWidget *vbox; + gchar *primary_markup; + gchar *secondary_markup; + GtkWidget *primary_label; + GtkWidget *secondary_label; + gchar *primary_text; + const gchar *secondary_text; + gchar *full_formatted_uri; + gchar *uri_for_display; + gchar *temp_uri_for_display; - /* Truncate the URI so it doesn't get insanely wide. Note that even - * though the dialog uses wrapped text, if the URI doesn't contain - * white space then the text-wrapping code is too stupid to wrap it. - */ - temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, - MAX_URI_IN_DIALOG_LENGTH); - g_free (full_formatted_uri); - - uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); - g_free (temp_uri_for_display); + full_formatted_uri = xed_utils_uri_for_display (uri); - message_area = gtk_info_bar_new (); - gtk_info_bar_add_button (GTK_INFO_BAR (message_area), - /* Translators: the access key chosen for this string should be - different from other main menu access keys (Open, Edit, View...) */ - _("Edit Any_way"), - GTK_RESPONSE_YES); - gtk_info_bar_add_button (GTK_INFO_BAR (message_area), - /* Translators: the access key chosen for this string should be - different from other main menu access keys (Open, Edit, View...) */ - _("D_on't Edit"), - GTK_RESPONSE_CANCEL); - gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), - GTK_MESSAGE_WARNING); + /* Truncate the URI so it doesn't get insanely wide. Note that even + * though the dialog uses wrapped text, if the URI doesn't contain + * white space then the text-wrapping code is too stupid to wrap it. + */ + temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, MAX_URI_IN_DIALOG_LENGTH); + g_free (full_formatted_uri); - hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); + uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); + g_free (temp_uri_for_display); - image = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_DIALOG); - gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0); - gtk_widget_set_halign (image, GTK_ALIGN_CENTER); - gtk_widget_set_valign (image, GTK_ALIGN_START); + message_area = gtk_info_bar_new (); + gtk_info_bar_add_button (GTK_INFO_BAR (message_area), + /* Translators: the access key chosen for this string should be + different from other main menu access keys (Open, Edit, View...) */ + _("Edit Any_way"), + GTK_RESPONSE_YES); + gtk_info_bar_add_button (GTK_INFO_BAR (message_area), + /* Translators: the access key chosen for this string should be + different from other main menu access keys (Open, Edit, View...) */ + _("D_on't Edit"), + GTK_RESPONSE_CANCEL); + gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), GTK_MESSAGE_WARNING); - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0); + hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); - primary_text = g_strdup_printf (_("This file (%s) is already open in another xed window."), uri_for_display); - g_free (uri_for_display); - - primary_markup = g_strdup_printf ("%s", primary_text); - g_free (primary_text); - primary_label = gtk_label_new (primary_markup); - g_free (primary_markup); - gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0); - gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); - gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); - gtk_widget_set_can_focus (primary_label, TRUE); - gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); + image = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_DIALOG); + gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0); + gtk_widget_set_halign (image, GTK_ALIGN_CENTER); + gtk_widget_set_valign (image, GTK_ALIGN_START); - secondary_text = _("xed opened this instance of the file in a non-editable way. " - "Do you want to edit it anyway?"); - secondary_markup = g_strdup_printf ("%s", - secondary_text); - secondary_label = gtk_label_new (secondary_markup); - g_free (secondary_markup); - gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0); - gtk_widget_set_can_focus (secondary_label, TRUE); - gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); - gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); - gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); + vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0); - gtk_widget_show_all (hbox_content); - set_contents (message_area, hbox_content); + primary_text = g_strdup_printf (_("This file (%s) is already open in another xed window."), uri_for_display); + g_free (uri_for_display); - return message_area; + primary_markup = g_strdup_printf ("%s", primary_text); + g_free (primary_text); + primary_label = gtk_label_new (primary_markup); + g_free (primary_markup); + gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0); + gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); + gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); + gtk_widget_set_can_focus (primary_label, TRUE); + gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); + + secondary_text = _("xed opened this instance of the file in a non-editable way. " + "Do you want to edit it anyway?"); + secondary_markup = g_strdup_printf ("%s", secondary_text); + secondary_label = gtk_label_new (secondary_markup); + g_free (secondary_markup); + gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0); + gtk_widget_set_can_focus (secondary_label, TRUE); + gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); + gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); + gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); + + gtk_widget_show_all (hbox_content); + set_contents (message_area, hbox_content); + + return message_area; } GtkWidget * -xed_externally_modified_saving_error_message_area_new ( - const gchar *uri, - const GError *error) +xed_externally_modified_saving_error_message_area_new (const gchar *uri, + const GError *error) { - GtkWidget *message_area; - GtkWidget *hbox_content; - GtkWidget *image; - GtkWidget *vbox; - gchar *primary_markup; - gchar *secondary_markup; - GtkWidget *primary_label; - GtkWidget *secondary_label; - gchar *primary_text; - const gchar *secondary_text; - gchar *full_formatted_uri; - gchar *uri_for_display; - gchar *temp_uri_for_display; + GtkWidget *message_area; + GtkWidget *hbox_content; + GtkWidget *image; + GtkWidget *vbox; + gchar *primary_markup; + gchar *secondary_markup; + GtkWidget *primary_label; + GtkWidget *secondary_label; + gchar *primary_text; + const gchar *secondary_text; + gchar *full_formatted_uri; + gchar *uri_for_display; + gchar *temp_uri_for_display; - g_return_val_if_fail (uri != NULL, NULL); - g_return_val_if_fail (error != NULL, NULL); - g_return_val_if_fail (error->domain == XED_DOCUMENT_ERROR, NULL); - g_return_val_if_fail (error->code == XED_DOCUMENT_ERROR_EXTERNALLY_MODIFIED, NULL); + g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (error != NULL, NULL); + g_return_val_if_fail (error->domain == XED_DOCUMENT_ERROR, NULL); + g_return_val_if_fail (error->code == XED_DOCUMENT_ERROR_EXTERNALLY_MODIFIED, NULL); - full_formatted_uri = xed_utils_uri_for_display (uri); + full_formatted_uri = xed_utils_uri_for_display (uri); - /* Truncate the URI so it doesn't get insanely wide. Note that even - * though the dialog uses wrapped text, if the URI doesn't contain - * white space then the text-wrapping code is too stupid to wrap it. - */ - temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, - MAX_URI_IN_DIALOG_LENGTH); - g_free (full_formatted_uri); + /* Truncate the URI so it doesn't get insanely wide. Note that even + * though the dialog uses wrapped text, if the URI doesn't contain + * white space then the text-wrapping code is too stupid to wrap it. + */ + temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, MAX_URI_IN_DIALOG_LENGTH); + g_free (full_formatted_uri); - uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); - g_free (temp_uri_for_display); + uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); + g_free (temp_uri_for_display); - message_area = gtk_info_bar_new (); - - info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area), - _("S_ave Anyway"), - GTK_STOCK_SAVE, - GTK_RESPONSE_YES); - gtk_info_bar_add_button (GTK_INFO_BAR (message_area), - _("D_on't Save"), - GTK_RESPONSE_CANCEL); - gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), - GTK_MESSAGE_WARNING); + message_area = gtk_info_bar_new (); - hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); + info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area), _("S_ave Anyway"), + GTK_STOCK_SAVE, GTK_RESPONSE_YES); + gtk_info_bar_add_button (GTK_INFO_BAR (message_area), _("D_on't Save"), GTK_RESPONSE_CANCEL); + gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), GTK_MESSAGE_WARNING); - image = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_DIALOG); - gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0); - gtk_widget_set_halign (image, GTK_ALIGN_CENTER); - gtk_widget_set_valign (image, GTK_ALIGN_START); + hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0); + image = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_DIALOG); + gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0); + gtk_widget_set_halign (image, GTK_ALIGN_CENTER); + gtk_widget_set_valign (image, GTK_ALIGN_START); - // FIXME: review this message, it's not clear since for the user the "modification" - // could be interpreted as the changes he made in the document. beside "reading" is - // not accurate (since last load/save) - primary_text = g_strdup_printf (_("The file %s has been modified since reading it."), - uri_for_display); - g_free (uri_for_display); + vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0); - primary_markup = g_strdup_printf ("%s", primary_text); - g_free (primary_text); - primary_label = gtk_label_new (primary_markup); - g_free (primary_markup); - gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0); - gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); - gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); - gtk_widget_set_can_focus (primary_label, TRUE); - gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); + // FIXME: review this message, it's not clear since for the user the "modification" + // could be interpreted as the changes he made in the document. beside "reading" is + // not accurate (since last load/save) + primary_text = g_strdup_printf (_("The file %s has been modified since reading it."), uri_for_display); + g_free (uri_for_display); - secondary_text = _("If you save it, all the external changes could be lost. Save it anyway?"); - secondary_markup = g_strdup_printf ("%s", - secondary_text); - secondary_label = gtk_label_new (secondary_markup); - g_free (secondary_markup); - gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0); - gtk_widget_set_can_focus (secondary_label, TRUE); - gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); - gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); - gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); + primary_markup = g_strdup_printf ("%s", primary_text); + g_free (primary_text); + primary_label = gtk_label_new (primary_markup); + g_free (primary_markup); + gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0); + gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); + gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); + gtk_widget_set_can_focus (primary_label, TRUE); + gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); - gtk_widget_show_all (hbox_content); - set_contents (message_area, hbox_content); + secondary_text = _("If you save it, all the external changes could be lost. Save it anyway?"); + secondary_markup = g_strdup_printf ("%s", secondary_text); + secondary_label = gtk_label_new (secondary_markup); + g_free (secondary_markup); + gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0); + gtk_widget_set_can_focus (secondary_label, TRUE); + gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); + gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); + gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); - return message_area; + gtk_widget_show_all (hbox_content); + set_contents (message_area, hbox_content); + + return message_area; } GtkWidget * xed_no_backup_saving_error_message_area_new (const gchar *uri, - const GError *error) + const GError *error) { - GtkWidget *message_area; - GtkWidget *hbox_content; - GtkWidget *image; - GtkWidget *vbox; - gchar *primary_markup; - gchar *secondary_markup; - GtkWidget *primary_label; - GtkWidget *secondary_label; - gchar *primary_text; - const gchar *secondary_text; - gchar *full_formatted_uri; - gchar *uri_for_display; - gchar *temp_uri_for_display; + GtkWidget *message_area; + GtkWidget *hbox_content; + GtkWidget *image; + GtkWidget *vbox; + gchar *primary_markup; + gchar *secondary_markup; + GtkWidget *primary_label; + GtkWidget *secondary_label; + gchar *primary_text; + const gchar *secondary_text; + gchar *full_formatted_uri; + gchar *uri_for_display; + gchar *temp_uri_for_display; - g_return_val_if_fail (uri != NULL, NULL); - g_return_val_if_fail (error != NULL, NULL); - g_return_val_if_fail (((error->domain == XED_DOCUMENT_ERROR && - error->code == XED_DOCUMENT_ERROR_CANT_CREATE_BACKUP) || - (error->domain == G_IO_ERROR && - error->code == G_IO_ERROR_CANT_CREATE_BACKUP)), NULL); + g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (error != NULL, NULL); + g_return_val_if_fail (((error->domain == XED_DOCUMENT_ERROR && + error->code == XED_DOCUMENT_ERROR_CANT_CREATE_BACKUP) || + (error->domain == G_IO_ERROR && + error->code == G_IO_ERROR_CANT_CREATE_BACKUP)), NULL); - full_formatted_uri = xed_utils_uri_for_display (uri); + full_formatted_uri = xed_utils_uri_for_display (uri); - /* Truncate the URI so it doesn't get insanely wide. Note that even - * though the dialog uses wrapped text, if the URI doesn't contain - * white space then the text-wrapping code is too stupid to wrap it. - */ - temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, - MAX_URI_IN_DIALOG_LENGTH); - g_free (full_formatted_uri); + /* Truncate the URI so it doesn't get insanely wide. Note that even + * though the dialog uses wrapped text, if the URI doesn't contain + * white space then the text-wrapping code is too stupid to wrap it. + */ + temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, MAX_URI_IN_DIALOG_LENGTH); + g_free (full_formatted_uri); - uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); - g_free (temp_uri_for_display); + uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); + g_free (temp_uri_for_display); - message_area = gtk_info_bar_new (); - - info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area), - _("S_ave Anyway"), - GTK_STOCK_SAVE, - GTK_RESPONSE_YES); - gtk_info_bar_add_button (GTK_INFO_BAR (message_area), - _("D_on't Save"), - GTK_RESPONSE_CANCEL); - gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), - GTK_MESSAGE_WARNING); + message_area = gtk_info_bar_new (); - hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); + info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area), _("S_ave Anyway"), + GTK_STOCK_SAVE, GTK_RESPONSE_YES); + gtk_info_bar_add_button (GTK_INFO_BAR (message_area), _("D_on't Save"), GTK_RESPONSE_CANCEL); + gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), GTK_MESSAGE_WARNING); - image = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_DIALOG); - gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0); - gtk_widget_set_halign (image, GTK_ALIGN_CENTER); - gtk_widget_set_valign (image, GTK_ALIGN_START); + hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0); + image = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_DIALOG); + gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0); + gtk_widget_set_halign (image, GTK_ALIGN_CENTER); + gtk_widget_set_valign (image, GTK_ALIGN_START); - // FIXME: review this messages + vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0); - if (xed_prefs_manager_get_create_backup_copy ()) - primary_text = g_strdup_printf (_("Could not create a backup file while saving %s"), - uri_for_display); - else - primary_text = g_strdup_printf (_("Could not create a temporary backup file while saving %s"), - uri_for_display); + // FIXME: review this messages - g_free (uri_for_display); + if (xed_prefs_manager_get_create_backup_copy ()) + { + primary_text = g_strdup_printf (_("Could not create a backup file while saving %s"), uri_for_display); + } + else + { + primary_text = g_strdup_printf (_("Could not create a temporary backup file while saving %s"), uri_for_display); + } - primary_markup = g_strdup_printf ("%s", primary_text); - g_free (primary_text); - primary_label = gtk_label_new (primary_markup); - g_free (primary_markup); - gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0); - gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); - gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); - gtk_widget_set_can_focus (primary_label, TRUE); - gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); + g_free (uri_for_display); - secondary_text = _("xed could not back up the old copy of the file before saving the new one. " - "You can ignore this warning and save the file anyway, but if an error " - "occurs while saving, you could lose the old copy of the file. Save anyway?"); - secondary_markup = g_strdup_printf ("%s", - secondary_text); - secondary_label = gtk_label_new (secondary_markup); - g_free (secondary_markup); - gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0); - gtk_widget_set_can_focus (secondary_label, TRUE); - gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); - gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); - gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); + primary_markup = g_strdup_printf ("%s", primary_text); + g_free (primary_text); + primary_label = gtk_label_new (primary_markup); + g_free (primary_markup); + gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0); + gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); + gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); + gtk_widget_set_can_focus (primary_label, TRUE); + gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); - gtk_widget_show_all (hbox_content); - set_contents (message_area, hbox_content); + secondary_text = _("xed could not back up the old copy of the file before saving the new one. " + "You can ignore this warning and save the file anyway, but if an error " + "occurs while saving, you could lose the old copy of the file. Save anyway?"); + secondary_markup = g_strdup_printf ("%s", secondary_text); + secondary_label = gtk_label_new (secondary_markup); + g_free (secondary_markup); + gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0); + gtk_widget_set_can_focus (secondary_label, TRUE); + gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); + gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); + gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); - return message_area; + gtk_widget_show_all (hbox_content); + set_contents (message_area, hbox_content); + + return message_area; } GtkWidget * xed_unrecoverable_saving_error_message_area_new (const gchar *uri, - const GError *error) + const GError *error) { - gchar *error_message = NULL; - gchar *message_details = NULL; - gchar *full_formatted_uri; - gchar *scheme_string; - gchar *scheme_markup; - gchar *uri_for_display; - gchar *temp_uri_for_display; - GtkWidget *message_area; + gchar *error_message = NULL; + gchar *message_details = NULL; + gchar *full_formatted_uri; + gchar *scheme_string; + gchar *scheme_markup; + gchar *uri_for_display; + gchar *temp_uri_for_display; + GtkWidget *message_area; - g_return_val_if_fail (uri != NULL, NULL); - g_return_val_if_fail (error != NULL, NULL); - g_return_val_if_fail ((error->domain == XED_DOCUMENT_ERROR) || - (error->domain == G_IO_ERROR), NULL); + g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (error != NULL, NULL); + g_return_val_if_fail ((error->domain == XED_DOCUMENT_ERROR) || (error->domain == G_IO_ERROR), NULL); - full_formatted_uri = xed_utils_uri_for_display (uri); + full_formatted_uri = xed_utils_uri_for_display (uri); - /* Truncate the URI so it doesn't get insanely wide. Note that even - * though the dialog uses wrapped text, if the URI doesn't contain - * white space then the text-wrapping code is too stupid to wrap it. - */ - temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, - MAX_URI_IN_DIALOG_LENGTH); - g_free (full_formatted_uri); + /* Truncate the URI so it doesn't get insanely wide. Note that even + * though the dialog uses wrapped text, if the URI doesn't contain + * white space then the text-wrapping code is too stupid to wrap it. + */ + temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, MAX_URI_IN_DIALOG_LENGTH); + g_free (full_formatted_uri); - uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); - g_free (temp_uri_for_display); + uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); + g_free (temp_uri_for_display); - if (is_gio_error (error, G_IO_ERROR_NOT_SUPPORTED)) - { - scheme_string = g_uri_parse_scheme (uri); + if (is_gio_error (error, G_IO_ERROR_NOT_SUPPORTED)) + { + scheme_string = g_uri_parse_scheme (uri); - if ((scheme_string != NULL) && g_utf8_validate (scheme_string, -1, NULL)) - { - scheme_markup = g_markup_printf_escaped ("%s:", scheme_string); + if ((scheme_string != NULL) && g_utf8_validate (scheme_string, -1, NULL)) + { + scheme_markup = g_markup_printf_escaped ("%s:", scheme_string); - /* Translators: %s is a URI scheme (like for example http:, ftp:, etc.) */ - message_details = g_strdup_printf (_("xed cannot handle %s locations in write mode. " - "Please check that you typed the " - "location correctly and try again."), - scheme_markup); - g_free (scheme_markup); - } - else - { - message_details = g_strdup (_("xed cannot handle this location in write mode. " - "Please check that you typed the " - "location correctly and try again.")); - } + /* Translators: %s is a URI scheme (like for example http:, ftp:, etc.) */ + message_details = g_strdup_printf (_("xed cannot handle %s locations in write mode. " + "Please check that you typed the " + "location correctly and try again."), + scheme_markup); + g_free (scheme_markup); + } + else + { + message_details = g_strdup (_("xed cannot handle this location in write mode. " + "Please check that you typed the " + "location correctly and try again.")); + } - g_free (scheme_string); - } - else if (is_gio_error (error, G_IO_ERROR_INVALID_FILENAME)) - { - message_details = g_strdup (_("%s is not a valid location. " - "Please check that you typed the " - "location correctly and try again.")); - } - else if (is_gio_error (error, G_IO_ERROR_PERMISSION_DENIED)) - { - message_details = g_strdup (_("You do not have the permissions necessary to save the file. " - "Please check that you typed the " - "location correctly and try again.")); - } - else if (is_gio_error (error, G_IO_ERROR_NO_SPACE)) - { - message_details = g_strdup (_("There is not enough disk space to save the file. " - "Please free some disk space and try again.")); - } - else if (is_gio_error (error, G_IO_ERROR_READ_ONLY)) - { - message_details = g_strdup (_("You are trying to save the file on a read-only disk. " - "Please check that you typed the location " - "correctly and try again.")); - } - else if (is_gio_error (error, G_IO_ERROR_EXISTS)) - { - message_details = g_strdup (_("A file with the same name already exists. " - "Please use a different name.")); - } - else if (is_gio_error (error, G_IO_ERROR_FILENAME_TOO_LONG)) - { - message_details = g_strdup (_("The disk where you are trying to save the file has " - "a limitation on length of the file names. " - "Please use a shorter name.")); - } - else if (error->domain == XED_DOCUMENT_ERROR && - error->code == XED_DOCUMENT_ERROR_TOO_BIG) - { - message_details = g_strdup (_("The disk where you are trying to save the file has " - "a limitation on file sizes. Please try saving " - "a smaller file or saving it to a disk that does not " - "have this limitation.")); - } - else - { - parse_error (error, - &error_message, - &message_details, - uri, - uri_for_display); - } + g_free (scheme_string); + } + else if (is_gio_error (error, G_IO_ERROR_INVALID_FILENAME)) + { + message_details = g_strdup (_("%s is not a valid location. " + "Please check that you typed the " + "location correctly and try again.")); + } + else if (is_gio_error (error, G_IO_ERROR_PERMISSION_DENIED)) + { + message_details = g_strdup (_("You do not have the permissions necessary to save the file. " + "Please check that you typed the " + "location correctly and try again.")); + } + else if (is_gio_error (error, G_IO_ERROR_NO_SPACE)) + { + message_details = g_strdup (_("There is not enough disk space to save the file. " + "Please free some disk space and try again.")); + } + else if (is_gio_error (error, G_IO_ERROR_READ_ONLY)) + { + message_details = g_strdup (_("You are trying to save the file on a read-only disk. " + "Please check that you typed the location " + "correctly and try again.")); + } + else if (is_gio_error (error, G_IO_ERROR_EXISTS)) + { + message_details = g_strdup (_("A file with the same name already exists. " + "Please use a different name.")); + } + else if (is_gio_error (error, G_IO_ERROR_FILENAME_TOO_LONG)) + { + message_details = g_strdup (_("The disk where you are trying to save the file has " + "a limitation on length of the file names. " + "Please use a shorter name.")); + } + else if (error->domain == XED_DOCUMENT_ERROR && error->code == XED_DOCUMENT_ERROR_TOO_BIG) + { + message_details = g_strdup (_("The disk where you are trying to save the file has " + "a limitation on file sizes. Please try saving " + "a smaller file or saving it to a disk that does not " + "have this limitation.")); + } + else + { + parse_error (error, &error_message, &message_details, uri, uri_for_display); + } - if (error_message == NULL) - { - error_message = g_strdup_printf (_("Could not save the file %s."), - uri_for_display); - } + if (error_message == NULL) + { + error_message = g_strdup_printf (_("Could not save the file %s."), uri_for_display); + } - message_area = create_io_loading_error_message_area (error_message, - message_details, - FALSE); + message_area = create_io_loading_error_message_area (error_message, message_details, FALSE); - g_free (uri_for_display); - g_free (error_message); - g_free (message_details); + g_free (uri_for_display); + g_free (error_message); + g_free (message_details); - return message_area; + return message_area; } GtkWidget * xed_externally_modified_message_area_new (const gchar *uri, - gboolean document_modified) + gboolean document_modified) { - gchar *full_formatted_uri; - gchar *uri_for_display; - gchar *temp_uri_for_display; - const gchar *primary_text; - const gchar *secondary_text; - GtkWidget *message_area; + gchar *full_formatted_uri; + gchar *uri_for_display; + gchar *temp_uri_for_display; + const gchar *primary_text; + const gchar *secondary_text; + GtkWidget *message_area; - g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (uri != NULL, NULL); - full_formatted_uri = xed_utils_uri_for_display (uri); + full_formatted_uri = xed_utils_uri_for_display (uri); - /* Truncate the URI so it doesn't get insanely wide. Note that even - * though the dialog uses wrapped text, if the URI doesn't contain - * white space then the text-wrapping code is too stupid to wrap it. - */ - temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, - MAX_URI_IN_DIALOG_LENGTH); - g_free (full_formatted_uri); + /* Truncate the URI so it doesn't get insanely wide. Note that even + * though the dialog uses wrapped text, if the URI doesn't contain + * white space then the text-wrapping code is too stupid to wrap it. + */ + temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, MAX_URI_IN_DIALOG_LENGTH); + g_free (full_formatted_uri); - uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); - g_free (temp_uri_for_display); + uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); + g_free (temp_uri_for_display); - // FIXME: review this message, it's not clear since for the user the "modification" - // could be interpreted as the changes he made in the document. beside "reading" is - // not accurate (since last load/save) - primary_text = g_strdup_printf (_("The file %s changed on disk."), - uri_for_display); - g_free (uri_for_display); + // FIXME: review this message, it's not clear since for the user the "modification" + // could be interpreted as the changes he made in the document. beside "reading" is + // not accurate (since last load/save) + primary_text = g_strdup_printf (_("The file %s changed on disk."), uri_for_display); + g_free (uri_for_display); - if (document_modified) - secondary_text = _("Do you want to drop your changes and reload the file?"); - else - secondary_text = _("Do you want to reload the file?"); + if (document_modified) + { + secondary_text = _("Do you want to drop your changes and reload the file?"); + } + else + { + secondary_text = _("Do you want to reload the file?"); + } - message_area = gtk_info_bar_new (); - - info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area), - _("_Reload"), - GTK_STOCK_REFRESH, - GTK_RESPONSE_OK); - gtk_info_bar_add_button (GTK_INFO_BAR (message_area), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); - gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), - GTK_MESSAGE_WARNING); + message_area = gtk_info_bar_new (); - set_message_area_text_and_icon (message_area, - "gtk-dialog-warning", - primary_text, - secondary_text); + info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area), _("_Reload"), + GTK_STOCK_REFRESH, GTK_RESPONSE_OK); + gtk_info_bar_add_button (GTK_INFO_BAR (message_area), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), GTK_MESSAGE_WARNING); - return message_area; + set_message_area_text_and_icon (message_area, "gtk-dialog-warning", primary_text, secondary_text); + + return message_area; } From d091965175fab3510d57d177a18840b87fff5dd8 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 12 Dec 2016 13:34:56 -0800 Subject: [PATCH 018/132] xed-io-error-message-area: Fix up some deprecations --- xed/xed-io-error-message-area.c | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/xed/xed-io-error-message-area.c b/xed/xed-io-error-message-area.c index 3677faf..f11f17a 100644 --- a/xed/xed-io-error-message-area.c +++ b/xed/xed-io-error-message-area.c @@ -91,22 +91,22 @@ set_contents (GtkWidget *area, } static void -info_bar_add_stock_button_with_text (GtkInfoBar *infobar, - const gchar *text, - const gchar *stock_id, - gint response_id) +info_bar_add_button_with_text (GtkInfoBar *infobar, + const gchar *text, + const gchar *icon_name, + gint response_id) { GtkWidget *button; GtkWidget *image; button = gtk_info_bar_add_button (infobar, text, response_id); - image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON); + image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON); gtk_button_set_image (GTK_BUTTON (button), image); } static void set_message_area_text_and_icon (GtkWidget *message_area, - const gchar *icon_stock_id, + const gchar *icon_name, const gchar *primary_text, const gchar *secondary_text) { @@ -120,7 +120,7 @@ set_message_area_text_and_icon (GtkWidget *message_area, hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); - image = gtk_image_new_from_stock (icon_stock_id, GTK_ICON_SIZE_DIALOG); + image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_DIALOG); gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0); gtk_widget_set_halign (image, GTK_ALIGN_CENTER); gtk_widget_set_valign (image, GTK_ALIGN_START); @@ -162,15 +162,15 @@ create_io_loading_error_message_area (const gchar *primary_text, { GtkWidget *message_area; - message_area = gtk_info_bar_new_with_buttons (GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); + message_area = gtk_info_bar_new_with_buttons (_("_Cancel"), GTK_RESPONSE_CANCEL, NULL); gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), GTK_MESSAGE_ERROR); - set_message_area_text_and_icon (message_area, "gtk-dialog-error", primary_text, secondary_text); + set_message_area_text_and_icon (message_area, "dialog-error-symbolic", primary_text, secondary_text); if (recoverable_error) { - info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area), _("_Retry"), - GTK_STOCK_REFRESH, GTK_RESPONSE_OK); + info_bar_add_button_with_text (GTK_INFO_BAR (message_area), _("_Retry"), + "view-refresh-symbolic", GTK_RESPONSE_OK); } return message_area; @@ -427,8 +427,8 @@ create_conversion_error_message_area (const gchar *primary_text, message_area = gtk_info_bar_new (); - info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area), _("_Retry"), - GTK_STOCK_REDO, GTK_RESPONSE_OK); + info_bar_add_button_with_text (GTK_INFO_BAR (message_area), _("_Retry"), + "edit-redo-symbolic", GTK_RESPONSE_OK); if (edit_anyway) { @@ -446,13 +446,13 @@ create_conversion_error_message_area (const gchar *primary_text, } else { - gtk_info_bar_add_button (GTK_INFO_BAR (message_area), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + gtk_info_bar_add_button (GTK_INFO_BAR (message_area), _("_Cancel"), GTK_RESPONSE_CANCEL); gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), GTK_MESSAGE_ERROR); } hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); - image = gtk_image_new_from_stock ("gtk-dialog-error", GTK_ICON_SIZE_DIALOG); + image = gtk_image_new_from_icon_name ("dialog-error-symbolic", GTK_ICON_SIZE_DIALOG); gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0); gtk_widget_set_halign (image, GTK_ALIGN_CENTER); gtk_widget_set_valign (image, GTK_ALIGN_START); @@ -706,7 +706,7 @@ xed_file_already_open_warning_message_area_new (const gchar *uri) hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); - image = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_DIALOG); + image = gtk_image_new_from_icon_name ("dialog-warning-symbolic", GTK_ICON_SIZE_DIALOG); gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0); gtk_widget_set_halign (image, GTK_ALIGN_CENTER); gtk_widget_set_valign (image, GTK_ALIGN_START); @@ -783,14 +783,14 @@ xed_externally_modified_saving_error_message_area_new (const gchar *uri, message_area = gtk_info_bar_new (); - info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area), _("S_ave Anyway"), - GTK_STOCK_SAVE, GTK_RESPONSE_YES); + info_bar_add_button_with_text (GTK_INFO_BAR (message_area), _("S_ave Anyway"), + "document-save-symbolic", GTK_RESPONSE_YES); gtk_info_bar_add_button (GTK_INFO_BAR (message_area), _("D_on't Save"), GTK_RESPONSE_CANCEL); gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), GTK_MESSAGE_WARNING); hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); - image = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_DIALOG); + image = gtk_image_new_from_icon_name ("dialog-warning-symbolic", GTK_ICON_SIZE_DIALOG); gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0); gtk_widget_set_halign (image, GTK_ALIGN_CENTER); gtk_widget_set_valign (image, GTK_ALIGN_START); @@ -871,14 +871,14 @@ xed_no_backup_saving_error_message_area_new (const gchar *uri, message_area = gtk_info_bar_new (); - info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area), _("S_ave Anyway"), - GTK_STOCK_SAVE, GTK_RESPONSE_YES); + info_bar_add_button_with_text (GTK_INFO_BAR (message_area), _("S_ave Anyway"), + "document-save-symbolic", GTK_RESPONSE_YES); gtk_info_bar_add_button (GTK_INFO_BAR (message_area), _("D_on't Save"), GTK_RESPONSE_CANCEL); gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), GTK_MESSAGE_WARNING); hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); - image = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_DIALOG); + image = gtk_image_new_from_icon_name ("dialog-warning-symbolic", GTK_ICON_SIZE_DIALOG); gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0); gtk_widget_set_halign (image, GTK_ALIGN_CENTER); gtk_widget_set_valign (image, GTK_ALIGN_START); @@ -1084,12 +1084,12 @@ xed_externally_modified_message_area_new (const gchar *uri, message_area = gtk_info_bar_new (); - info_bar_add_stock_button_with_text (GTK_INFO_BAR (message_area), _("_Reload"), - GTK_STOCK_REFRESH, GTK_RESPONSE_OK); - gtk_info_bar_add_button (GTK_INFO_BAR (message_area), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + info_bar_add_button_with_text (GTK_INFO_BAR (message_area), _("_Reload"), + "view-refresh-symbolic", GTK_RESPONSE_OK); + gtk_info_bar_add_button (GTK_INFO_BAR (message_area), _("_Cancel"), GTK_RESPONSE_CANCEL); gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), GTK_MESSAGE_WARNING); - set_message_area_text_and_icon (message_area, "gtk-dialog-warning", primary_text, secondary_text); + set_message_area_text_and_icon (message_area, "dialog-warning-symbolic", primary_text, secondary_text); return message_area; } From 6893642b16b0102399d6f4740e9dacb3da5fbfc3 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 12 Dec 2016 14:59:49 -0800 Subject: [PATCH 019/132] xed-panel: Clean up code formatting --- xed/xed-panel.c | 1050 ++++++++++++++++++++++------------------------- 1 file changed, 492 insertions(+), 558 deletions(-) diff --git a/xed/xed-panel.c b/xed/xed-panel.c index 7ee88e0..13d7357 100644 --- a/xed/xed-panel.c +++ b/xed/xed-panel.c @@ -2,7 +2,7 @@ * xed-panel.c * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,13 +16,13 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. * See the ChangeLog files for a list of changes. * * $Id$ @@ -43,214 +43,221 @@ #define XED_PANEL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_PANEL, XedPanelPrivate)) -struct _XedPanelPrivate +struct _XedPanelPrivate { - GtkOrientation orientation; - - /* Title bar (vertical panel only) */ - GtkWidget *title_image; - GtkWidget *title_label; + GtkOrientation orientation; - /* Notebook */ - GtkWidget *notebook; + /* Title bar (vertical panel only) */ + GtkWidget *title_image; + GtkWidget *title_label; + + /* Notebook */ + GtkWidget *notebook; }; typedef struct _XedPanelItem XedPanelItem; -struct _XedPanelItem +struct _XedPanelItem { - gchar *name; - GtkWidget *icon; + gchar *name; + GtkWidget *icon; }; /* Properties */ -enum { - PROP_0, - PROP_ORIENTATION +enum +{ + PROP_0, + PROP_ORIENTATION }; /* Signals */ -enum { - ITEM_ADDED, - ITEM_REMOVED, - CLOSE, - FOCUS_DOCUMENT, - LAST_SIGNAL +enum +{ + ITEM_ADDED, + ITEM_REMOVED, + CLOSE, + FOCUS_DOCUMENT, + LAST_SIGNAL }; static guint signals[LAST_SIGNAL] = { 0 }; -static GObject *xed_panel_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties); +static GObject *xed_panel_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties); -G_DEFINE_TYPE(XedPanel, xed_panel, GTK_TYPE_BOX) +G_DEFINE_TYPE (XedPanel, xed_panel, GTK_TYPE_BOX) static void xed_panel_finalize (GObject *obj) { - if (G_OBJECT_CLASS (xed_panel_parent_class)->finalize) - (*G_OBJECT_CLASS (xed_panel_parent_class)->finalize) (obj); + if (G_OBJECT_CLASS (xed_panel_parent_class)->finalize) + { + (*G_OBJECT_CLASS (xed_panel_parent_class)->finalize) (obj); + } } static void xed_panel_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - XedPanel *panel = XED_PANEL (object); - - switch (prop_id) - { - case PROP_ORIENTATION: - g_value_set_enum(value, panel->priv->orientation); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + XedPanel *panel = XED_PANEL (object); + + switch (prop_id) + { + case PROP_ORIENTATION: + g_value_set_enum(value, panel->priv->orientation); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_panel_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - XedPanel *panel = XED_PANEL (object); + XedPanel *panel = XED_PANEL (object); - switch (prop_id) - { - case PROP_ORIENTATION: - panel->priv->orientation = g_value_get_enum (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_ORIENTATION: + panel->priv->orientation = g_value_get_enum (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_panel_close (XedPanel *panel) { - gtk_widget_hide (GTK_WIDGET (panel)); + gtk_widget_hide (GTK_WIDGET (panel)); } static void xed_panel_focus_document (XedPanel *panel) { - GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (panel)); - if (gtk_widget_is_toplevel (toplevel) && XED_IS_WINDOW (toplevel)) - { - XedView *view; + GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (panel)); + if (gtk_widget_is_toplevel (toplevel) && XED_IS_WINDOW (toplevel)) + { + XedView *view; - view = xed_window_get_active_view (XED_WINDOW (toplevel)); - if (view != NULL) - gtk_widget_grab_focus (GTK_WIDGET (view)); - } + view = xed_window_get_active_view (XED_WINDOW (toplevel)); + if (view != NULL) + { + gtk_widget_grab_focus (GTK_WIDGET (view)); + } + } } static void xed_panel_grab_focus (GtkWidget *w) { - gint n; - GtkWidget *tab; - XedPanel *panel = XED_PANEL (w); + gint n; + GtkWidget *tab; + XedPanel *panel = XED_PANEL (w); - n = gtk_notebook_get_current_page (GTK_NOTEBOOK (panel->priv->notebook)); - if (n == -1) - return; + n = gtk_notebook_get_current_page (GTK_NOTEBOOK (panel->priv->notebook)); + if (n == -1) + { + return; + } - tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (panel->priv->notebook), - n); - g_return_if_fail (tab != NULL); + tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (panel->priv->notebook), n); + g_return_if_fail (tab != NULL); - gtk_widget_grab_focus (tab); + gtk_widget_grab_focus (tab); } static void xed_panel_class_init (XedPanelClass *klass) { - GtkBindingSet *binding_set; - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GtkBindingSet *binding_set; + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - g_type_class_add_private (klass, sizeof (XedPanelPrivate)); + g_type_class_add_private (klass, sizeof (XedPanelPrivate)); - object_class->constructor = xed_panel_constructor; - object_class->finalize = xed_panel_finalize; - object_class->get_property = xed_panel_get_property; - object_class->set_property = xed_panel_set_property; + object_class->constructor = xed_panel_constructor; + object_class->finalize = xed_panel_finalize; + object_class->get_property = xed_panel_get_property; + object_class->set_property = xed_panel_set_property; - g_object_class_install_property (object_class, - PROP_ORIENTATION, - g_param_spec_enum ("panel-orientation", - "Panel Orientation", - "The panel's orientation", - GTK_TYPE_ORIENTATION, - GTK_ORIENTATION_VERTICAL, - G_PARAM_WRITABLE | - G_PARAM_READABLE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, + PROP_ORIENTATION, + g_param_spec_enum ("panel-orientation", + "Panel Orientation", + "The panel's orientation", + GTK_TYPE_ORIENTATION, + GTK_ORIENTATION_VERTICAL, + G_PARAM_WRITABLE | + G_PARAM_READABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); - widget_class->grab_focus = xed_panel_grab_focus; + widget_class->grab_focus = xed_panel_grab_focus; - klass->close = xed_panel_close; - klass->focus_document = xed_panel_focus_document; + klass->close = xed_panel_close; + klass->focus_document = xed_panel_focus_document; - signals[ITEM_ADDED] = - g_signal_new ("item_added", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (XedPanelClass, item_added), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - GTK_TYPE_WIDGET); - signals[ITEM_REMOVED] = - g_signal_new ("item_removed", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (XedPanelClass, item_removed), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - GTK_TYPE_WIDGET); + signals[ITEM_ADDED] = + g_signal_new ("item_added", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (XedPanelClass, item_added), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, + GTK_TYPE_WIDGET); + signals[ITEM_REMOVED] = + g_signal_new ("item_removed", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (XedPanelClass, item_removed), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, + GTK_TYPE_WIDGET); - /* Keybinding signals */ - signals[CLOSE] = - g_signal_new ("close", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (XedPanelClass, close), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - signals[FOCUS_DOCUMENT] = - g_signal_new ("focus_document", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (XedPanelClass, focus_document), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - binding_set = gtk_binding_set_by_class (klass); + /* Keybinding signals */ + signals[CLOSE] = + g_signal_new ("close", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (XedPanelClass, close), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + signals[FOCUS_DOCUMENT] = + g_signal_new ("focus_document", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (XedPanelClass, focus_document), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + binding_set = gtk_binding_set_by_class (klass); - gtk_binding_entry_add_signal (binding_set, - GDK_KEY_Escape, - 0, - "close", - 0); - gtk_binding_entry_add_signal (binding_set, - GDK_KEY_Return, - GDK_CONTROL_MASK, - "focus_document", - 0); + gtk_binding_entry_add_signal (binding_set, + GDK_KEY_Escape, + 0, + "close", + 0); + gtk_binding_entry_add_signal (binding_set, + GDK_KEY_Return, + GDK_CONTROL_MASK, + "focus_document", + 0); } /* This is ugly, since it supports only known @@ -260,313 +267,246 @@ xed_panel_class_init (XedPanelClass *klass) */ static void set_gtk_image_from_gtk_image (GtkImage *image, - GtkImage *source) + GtkImage *source) { - switch (gtk_image_get_storage_type (source)) - { - case GTK_IMAGE_EMPTY: - gtk_image_clear (image); - break; - case GTK_IMAGE_PIXBUF: - { - GdkPixbuf *pb; + switch (gtk_image_get_storage_type (source)) + { + case GTK_IMAGE_EMPTY: + gtk_image_clear (image); + break; + case GTK_IMAGE_PIXBUF: + { + GdkPixbuf *pb; - pb = gtk_image_get_pixbuf (source); - gtk_image_set_from_pixbuf (image, pb); - } - break; - case GTK_IMAGE_STOCK: - { - gchar *s_id; - GtkIconSize s; + pb = gtk_image_get_pixbuf (source); + gtk_image_set_from_pixbuf (image, pb); + } + break; + case GTK_IMAGE_STOCK: + { + gchar *s_id; + GtkIconSize s; - gtk_image_get_stock (source, &s_id, &s); - gtk_image_set_from_stock (image, s_id, s); - } - break; - case GTK_IMAGE_ICON_SET: - { - GtkIconSet *is; - GtkIconSize s; + gtk_image_get_stock (source, &s_id, &s); + gtk_image_set_from_stock (image, s_id, s); + } + break; + case GTK_IMAGE_ICON_SET: + { + GtkIconSet *is; + GtkIconSize s; - gtk_image_get_icon_set (source, &is, &s); - gtk_image_set_from_icon_set (image, is, s); - } - break; - case GTK_IMAGE_ANIMATION: - { - GdkPixbufAnimation *a; + gtk_image_get_icon_set (source, &is, &s); + gtk_image_set_from_icon_set (image, is, s); + } + break; + case GTK_IMAGE_ANIMATION: + { + GdkPixbufAnimation *a; - a = gtk_image_get_animation (source); - gtk_image_set_from_animation (image, a); - } - break; - case GTK_IMAGE_ICON_NAME: - { - const gchar *n; - GtkIconSize s; + a = gtk_image_get_animation (source); + gtk_image_set_from_animation (image, a); + } + break; + case GTK_IMAGE_ICON_NAME: + { + const gchar *n; + GtkIconSize s; - gtk_image_get_icon_name (source, &n, &s); - gtk_image_set_from_icon_name (image, n, s); - } - break; - default: - gtk_image_set_from_stock (image, - GTK_STOCK_FILE, - GTK_ICON_SIZE_MENU); - } + gtk_image_get_icon_name (source, &n, &s); + gtk_image_set_from_icon_name (image, n, s); + } + break; + default: + gtk_image_set_from_stock (image, GTK_STOCK_FILE, GTK_ICON_SIZE_MENU); + } } static void sync_title (XedPanel *panel, - XedPanelItem *item) + XedPanelItem *item) { - if (panel->priv->orientation != GTK_ORIENTATION_VERTICAL) - return; + if (panel->priv->orientation != GTK_ORIENTATION_VERTICAL) + { + return; + } - if (item != NULL) - { - gtk_label_set_text (GTK_LABEL (panel->priv->title_label), - item->name); + if (item != NULL) + { + gtk_label_set_text (GTK_LABEL (panel->priv->title_label), item->name); - set_gtk_image_from_gtk_image (GTK_IMAGE (panel->priv->title_image), - GTK_IMAGE (item->icon)); - } - else - { - gtk_label_set_text (GTK_LABEL (panel->priv->title_label), - _("Empty")); - - gtk_image_set_from_stock (GTK_IMAGE (panel->priv->title_image), - GTK_STOCK_FILE, - GTK_ICON_SIZE_MENU); - } + set_gtk_image_from_gtk_image (GTK_IMAGE (panel->priv->title_image), GTK_IMAGE (item->icon)); + } + else + { + gtk_label_set_text (GTK_LABEL (panel->priv->title_label), _("Empty")); + gtk_image_set_from_stock (GTK_IMAGE (panel->priv->title_image), GTK_STOCK_FILE, GTK_ICON_SIZE_MENU); + } } static void -notebook_page_changed (GtkNotebook *notebook, - GtkWidget *page, - guint page_num, - XedPanel *panel) +notebook_page_changed (GtkNotebook *notebook, + GtkWidget *page, + guint page_num, + XedPanel *panel) { - GtkWidget *item; - XedPanelItem *data; + GtkWidget *item; + XedPanelItem *data; - item = gtk_notebook_get_nth_page (notebook, page_num); - g_return_if_fail (item != NULL); + item = gtk_notebook_get_nth_page (notebook, page_num); + g_return_if_fail (item != NULL); - data = (XedPanelItem *)g_object_get_data (G_OBJECT (item), - PANEL_ITEM_KEY); - g_return_if_fail (data != NULL); + data = (XedPanelItem *)g_object_get_data (G_OBJECT (item), PANEL_ITEM_KEY); + g_return_if_fail (data != NULL); - sync_title (panel, data); + sync_title (panel, data); } static void panel_show (XedPanel *panel, - gpointer user_data) + gpointer user_data) { - gint page; - GtkNotebook *nb; + gint page; + GtkNotebook *nb; - nb = GTK_NOTEBOOK (panel->priv->notebook); + nb = GTK_NOTEBOOK (panel->priv->notebook); - page = gtk_notebook_get_current_page (nb); + page = gtk_notebook_get_current_page (nb); - if (page != -1) - notebook_page_changed (nb, NULL, page, panel); + if (page != -1) + { + notebook_page_changed (nb, NULL, page, panel); + } } static void xed_panel_init (XedPanel *panel) { - panel->priv = XED_PANEL_GET_PRIVATE (panel); + panel->priv = XED_PANEL_GET_PRIVATE (panel); - gtk_orientable_set_orientation (GTK_ORIENTABLE (panel), - GTK_ORIENTATION_VERTICAL); + gtk_orientable_set_orientation (GTK_ORIENTABLE (panel), GTK_ORIENTATION_VERTICAL); } static void close_button_clicked_cb (GtkWidget *widget, - GtkWidget *panel) + GtkWidget *panel) { - gtk_widget_hide (panel); + gtk_widget_hide (panel); } static GtkWidget * create_close_button (XedPanel *panel) { - GtkWidget *button; + GtkWidget *button; - button = xed_close_button_new (); + button = xed_close_button_new (); + gtk_widget_set_tooltip_text (button, _("Hide panel")); + g_signal_connect (button, "clicked", G_CALLBACK (close_button_clicked_cb), panel); - gtk_widget_set_tooltip_text (button, _("Hide panel")); - - g_signal_connect (button, - "clicked", - G_CALLBACK (close_button_clicked_cb), - panel); - - return button; + return button; } static void build_notebook_for_panel (XedPanel *panel) { - /* Create the panel notebook */ - panel->priv->notebook = gtk_notebook_new (); + /* Create the panel notebook */ + panel->priv->notebook = gtk_notebook_new (); - gtk_notebook_set_tab_pos (GTK_NOTEBOOK (panel->priv->notebook), - GTK_POS_BOTTOM); - gtk_notebook_set_scrollable (GTK_NOTEBOOK (panel->priv->notebook), - TRUE); - gtk_notebook_popup_enable (GTK_NOTEBOOK (panel->priv->notebook)); + gtk_notebook_set_tab_pos (GTK_NOTEBOOK (panel->priv->notebook), GTK_POS_BOTTOM); + gtk_notebook_set_scrollable (GTK_NOTEBOOK (panel->priv->notebook), TRUE); + gtk_notebook_popup_enable (GTK_NOTEBOOK (panel->priv->notebook)); - gtk_widget_show (GTK_WIDGET (panel->priv->notebook)); + gtk_widget_show (GTK_WIDGET (panel->priv->notebook)); - g_signal_connect (panel->priv->notebook, - "switch-page", - G_CALLBACK (notebook_page_changed), - panel); + g_signal_connect (panel->priv->notebook, "switch-page", G_CALLBACK (notebook_page_changed), panel); } static void build_horizontal_panel (XedPanel *panel) { - GtkWidget *box; - GtkWidget *sidebar; - GtkWidget *close_button; + GtkWidget *box; + GtkWidget *sidebar; + GtkWidget *close_button; - box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_pack_start (GTK_BOX (box), panel->priv->notebook, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (box), - panel->priv->notebook, - TRUE, - TRUE, - 0); + /* Toolbar, close button and first separator */ + sidebar = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6); + gtk_container_set_border_width (GTK_CONTAINER (sidebar), 4); + gtk_box_pack_start (GTK_BOX (box), sidebar, FALSE, FALSE, 0); - /* Toolbar, close button and first separator */ - sidebar = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6); - gtk_container_set_border_width (GTK_CONTAINER (sidebar), 4); + close_button = create_close_button (panel); + gtk_box_pack_start (GTK_BOX (sidebar), close_button, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (box), - sidebar, - FALSE, - FALSE, - 0); + gtk_widget_show_all (box); - close_button = create_close_button (panel); - - gtk_box_pack_start (GTK_BOX (sidebar), - close_button, - FALSE, - FALSE, - 0); - - gtk_widget_show_all (box); - - gtk_box_pack_start (GTK_BOX (panel), - box, - TRUE, - TRUE, - 0); + gtk_box_pack_start (GTK_BOX (panel), box, TRUE, TRUE, 0); } static void build_vertical_panel (XedPanel *panel) { - GtkWidget *close_button; - GtkWidget *title_hbox; - GtkWidget *icon_name_hbox; - GtkWidget *dummy_label; + GtkWidget *close_button; + GtkWidget *title_hbox; + GtkWidget *icon_name_hbox; + GtkWidget *dummy_label; - /* Create title hbox */ - title_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_container_set_border_width (GTK_CONTAINER (title_hbox), 5); - - gtk_box_pack_start (GTK_BOX (panel), title_hbox, FALSE, FALSE, 0); - - icon_name_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_start (GTK_BOX (title_hbox), - icon_name_hbox, - TRUE, - TRUE, - 0); - - panel->priv->title_image = - gtk_image_new_from_stock (GTK_STOCK_FILE, - GTK_ICON_SIZE_MENU); - gtk_box_pack_start (GTK_BOX (icon_name_hbox), - panel->priv->title_image, - FALSE, - TRUE, - 0); + /* Create title hbox */ + title_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + gtk_container_set_border_width (GTK_CONTAINER (title_hbox), 5); - dummy_label = gtk_label_new (" "); + gtk_box_pack_start (GTK_BOX (panel), title_hbox, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (icon_name_hbox), - dummy_label, - FALSE, - FALSE, - 0); + icon_name_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_pack_start (GTK_BOX (title_hbox), icon_name_hbox, TRUE, TRUE, 0); - panel->priv->title_label = gtk_label_new (_("Empty")); + panel->priv->title_image = gtk_image_new_from_stock (GTK_STOCK_FILE, GTK_ICON_SIZE_MENU); + gtk_box_pack_start (GTK_BOX (icon_name_hbox), panel->priv->title_image, FALSE, TRUE, 0); - gtk_misc_set_alignment (GTK_MISC (panel->priv->title_label), 0, 0.5); - gtk_label_set_ellipsize(GTK_LABEL (panel->priv->title_label), PANGO_ELLIPSIZE_END); + dummy_label = gtk_label_new (" "); + gtk_box_pack_start (GTK_BOX (icon_name_hbox), dummy_label, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (icon_name_hbox), - panel->priv->title_label, - TRUE, - TRUE, - 0); + panel->priv->title_label = gtk_label_new (_("Empty")); + gtk_misc_set_alignment (GTK_MISC (panel->priv->title_label), 0, 0.5); + gtk_label_set_ellipsize(GTK_LABEL (panel->priv->title_label), PANGO_ELLIPSIZE_END); + gtk_box_pack_start (GTK_BOX (icon_name_hbox), panel->priv->title_label, TRUE, TRUE, 0); - close_button = create_close_button (panel); + close_button = create_close_button (panel); + gtk_box_pack_start (GTK_BOX (title_hbox), close_button, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (title_hbox), - close_button, - FALSE, - FALSE, - 0); + gtk_widget_show_all (title_hbox); - gtk_widget_show_all (title_hbox); - - gtk_box_pack_start (GTK_BOX (panel), - panel->priv->notebook, - TRUE, - TRUE, - 0); + gtk_box_pack_start (GTK_BOX (panel), panel->priv->notebook, TRUE, TRUE, 0); } static GObject * -xed_panel_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) +xed_panel_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) { - - /* Invoke parent constructor. */ - XedPanelClass *klass = XED_PANEL_CLASS (g_type_class_peek (XED_TYPE_PANEL)); - GObjectClass *parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass)); - GObject *obj = parent_class->constructor (type, - n_construct_properties, - construct_properties); - /* Build the panel, now that we know the orientation - (_init has been called previously) */ - XedPanel *panel = XED_PANEL (obj); + /* Invoke parent constructor. */ + XedPanelClass *klass = XED_PANEL_CLASS (g_type_class_peek (XED_TYPE_PANEL)); + GObjectClass *parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass)); + GObject *obj = parent_class->constructor (type, n_construct_properties, construct_properties); - build_notebook_for_panel (panel); - if (panel->priv->orientation == GTK_ORIENTATION_HORIZONTAL) - build_horizontal_panel (panel); - else - build_vertical_panel (panel); + /* Build the panel, now that we know the orientation (_init has been called previously) */ + XedPanel *panel = XED_PANEL (obj); - g_signal_connect (panel, - "show", - G_CALLBACK (panel_show), - NULL); + build_notebook_for_panel (panel); + if (panel->priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + build_horizontal_panel (panel); + } + else + { + build_vertical_panel (panel); + } - return obj; + g_signal_connect (panel, "show", G_CALLBACK (panel_show), NULL); + + return obj; } /** @@ -582,54 +522,58 @@ xed_panel_constructor (GType type, GtkWidget * xed_panel_new (GtkOrientation orientation) { - return GTK_WIDGET (g_object_new (XED_TYPE_PANEL, "orientation", orientation, NULL)); + return GTK_WIDGET (g_object_new (XED_TYPE_PANEL, "orientation", orientation, NULL)); } static GtkWidget * -build_tab_label (XedPanel *panel, - GtkWidget *item, - const gchar *name, - GtkWidget *icon) +build_tab_label (XedPanel *panel, + GtkWidget *item, + const gchar *name, + GtkWidget *icon) { - GtkWidget *hbox, *label_hbox, *label_ebox; - GtkWidget *label; + GtkWidget *hbox; + GtkWidget *label_hbox; + GtkWidget *label_ebox; + GtkWidget *label; - /* set hbox spacing and label padding (see below) so that there's an - * equal amount of space around the label */ - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); + /* set hbox spacing and label padding (see below) so that there's an + * equal amount of space around the label */ + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); - label_ebox = gtk_event_box_new (); - gtk_event_box_set_visible_window (GTK_EVENT_BOX (label_ebox), FALSE); - gtk_box_pack_start (GTK_BOX (hbox), label_ebox, TRUE, TRUE, 0); + label_ebox = gtk_event_box_new (); + gtk_event_box_set_visible_window (GTK_EVENT_BOX (label_ebox), FALSE); + gtk_box_pack_start (GTK_BOX (hbox), label_ebox, TRUE, TRUE, 0); - label_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); - gtk_container_add (GTK_CONTAINER (label_ebox), label_hbox); + label_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); + gtk_container_add (GTK_CONTAINER (label_ebox), label_hbox); - /* setup icon */ - gtk_box_pack_start (GTK_BOX (label_hbox), icon, FALSE, FALSE, 0); + /* setup icon */ + gtk_box_pack_start (GTK_BOX (label_hbox), icon, FALSE, FALSE, 0); - /* setup label */ + /* setup label */ label = gtk_label_new (name); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_widget_set_margin_left (label, 0); - gtk_widget_set_margin_right (label, 0); - gtk_widget_set_margin_top (label, 0); - gtk_widget_set_margin_bottom (label, 0); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_widget_set_margin_left (label, 0); + gtk_widget_set_margin_right (label, 0); + gtk_widget_set_margin_top (label, 0); + gtk_widget_set_margin_bottom (label, 0); - gtk_box_pack_start (GTK_BOX (label_hbox), label, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (label_hbox), label, TRUE, TRUE, 0); - gtk_widget_set_tooltip_text (label_ebox, name); + gtk_widget_set_tooltip_text (label_ebox, name); - gtk_widget_show_all (hbox); + gtk_widget_show_all (hbox); - if (panel->priv->orientation == GTK_ORIENTATION_VERTICAL) - gtk_widget_hide(label); + if (panel->priv->orientation == GTK_ORIENTATION_VERTICAL) + { + gtk_widget_hide(label); + } - g_object_set_data (G_OBJECT (item), "label", label); - g_object_set_data (G_OBJECT (item), "hbox", hbox); + g_object_set_data (G_OBJECT (item), "label", label); + g_object_set_data (G_OBJECT (item), "hbox", hbox); - return hbox; + return hbox; } /** @@ -642,58 +586,54 @@ build_tab_label (XedPanel *panel, * Adds a new item to the @panel. */ void -xed_panel_add_item (XedPanel *panel, - GtkWidget *item, - const gchar *name, - GtkWidget *image) +xed_panel_add_item (XedPanel *panel, + GtkWidget *item, + const gchar *name, + GtkWidget *image) { - XedPanelItem *data; - GtkWidget *tab_label; - GtkWidget *menu_label; - gint w, h; - - g_return_if_fail (XED_IS_PANEL (panel)); - g_return_if_fail (GTK_IS_WIDGET (item)); - g_return_if_fail (name != NULL); - g_return_if_fail (image == NULL || GTK_IS_IMAGE (image)); + XedPanelItem *data; + GtkWidget *tab_label; + GtkWidget *menu_label; + gint w, h; - data = g_new (XedPanelItem, 1); + g_return_if_fail (XED_IS_PANEL (panel)); + g_return_if_fail (GTK_IS_WIDGET (item)); + g_return_if_fail (name != NULL); + g_return_if_fail (image == NULL || GTK_IS_IMAGE (image)); - data->name = g_strdup (name); + data = g_new (XedPanelItem, 1); - if (image == NULL) - { - /* default to empty */ - data->icon = gtk_image_new_from_stock (GTK_STOCK_FILE, - GTK_ICON_SIZE_MENU); - } - else - { - data->icon = image; - } + data->name = g_strdup (name); - gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &w, &h); - gtk_widget_set_size_request (data->icon, w, h); - - g_object_set_data (G_OBJECT (item), - PANEL_ITEM_KEY, - data); + if (image == NULL) + { + /* default to empty */ + data->icon = gtk_image_new_from_stock (GTK_STOCK_FILE, GTK_ICON_SIZE_MENU); + } + else + { + data->icon = image; + } - tab_label = build_tab_label (panel, item, data->name, data->icon); + gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &w, &h); + gtk_widget_set_size_request (data->icon, w, h); - menu_label = gtk_label_new (name); + g_object_set_data (G_OBJECT (item), PANEL_ITEM_KEY, data); - gtk_misc_set_alignment (GTK_MISC (menu_label), 0.0, 0.5); + tab_label = build_tab_label (panel, item, data->name, data->icon); - if (!gtk_widget_get_visible (item)) - gtk_widget_show (item); + menu_label = gtk_label_new (name); - gtk_notebook_append_page_menu (GTK_NOTEBOOK (panel->priv->notebook), - item, - tab_label, - menu_label); + gtk_misc_set_alignment (GTK_MISC (menu_label), 0.0, 0.5); - g_signal_emit (G_OBJECT (panel), signals[ITEM_ADDED], 0, item); + if (!gtk_widget_get_visible (item)) + { + gtk_widget_show (item); + } + + gtk_notebook_append_page_menu (GTK_NOTEBOOK (panel->priv->notebook), item, tab_label, menu_label); + + g_signal_emit (G_OBJECT (panel), signals[ITEM_ADDED], 0, item); } /** @@ -706,20 +646,19 @@ xed_panel_add_item (XedPanel *panel, * Same as xed_panel_add_item() but using an image from stock. */ void -xed_panel_add_item_with_stock_icon (XedPanel *panel, - GtkWidget *item, - const gchar *name, - const gchar *stock_id) +xed_panel_add_item_with_stock_icon (XedPanel *panel, + GtkWidget *item, + const gchar *name, + const gchar *stock_id) { - GtkWidget *icon = NULL; + GtkWidget *icon = NULL; - if (stock_id != NULL) - { - icon = gtk_image_new_from_stock (stock_id, - GTK_ICON_SIZE_MENU); - } + if (stock_id != NULL) + { + icon = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU); + } - xed_panel_add_item (panel, item, name, icon); + xed_panel_add_item (panel, item, name, icon); } /** @@ -733,47 +672,46 @@ xed_panel_add_item_with_stock_icon (XedPanel *panel, * Returns: %TRUE if it was well removed. */ gboolean -xed_panel_remove_item (XedPanel *panel, - GtkWidget *item) +xed_panel_remove_item (XedPanel *panel, + GtkWidget *item) { - XedPanelItem *data; - gint page_num; - - g_return_val_if_fail (XED_IS_PANEL (panel), FALSE); - g_return_val_if_fail (GTK_IS_WIDGET (item), FALSE); + XedPanelItem *data; + gint page_num; - page_num = gtk_notebook_page_num (GTK_NOTEBOOK (panel->priv->notebook), - item); - - if (page_num == -1) - return FALSE; - - data = (XedPanelItem *)g_object_get_data (G_OBJECT (item), - PANEL_ITEM_KEY); - g_return_val_if_fail (data != NULL, FALSE); - - g_free (data->name); - g_free (data); + g_return_val_if_fail (XED_IS_PANEL (panel), FALSE); + g_return_val_if_fail (GTK_IS_WIDGET (item), FALSE); - g_object_set_data (G_OBJECT (item), - PANEL_ITEM_KEY, - NULL); + page_num = gtk_notebook_page_num (GTK_NOTEBOOK (panel->priv->notebook), item); - /* ref the item to keep it alive during signal emission */ - g_object_ref (G_OBJECT (item)); + if (page_num == -1) + { + return FALSE; + } - gtk_notebook_remove_page (GTK_NOTEBOOK (panel->priv->notebook), - page_num); + data = (XedPanelItem *)g_object_get_data (G_OBJECT (item), PANEL_ITEM_KEY); + g_return_val_if_fail (data != NULL, FALSE); - /* if we removed all the pages, reset the title */ - if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (panel->priv->notebook)) == 0) - sync_title (panel, NULL); + g_free (data->name); + g_free (data); - g_signal_emit (G_OBJECT (panel), signals[ITEM_REMOVED], 0, item); + g_object_set_data (G_OBJECT (item), PANEL_ITEM_KEY, NULL); - g_object_unref (G_OBJECT (item)); + /* ref the item to keep it alive during signal emission */ + g_object_ref (G_OBJECT (item)); - return TRUE; + gtk_notebook_remove_page (GTK_NOTEBOOK (panel->priv->notebook), page_num); + + /* if we removed all the pages, reset the title */ + if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (panel->priv->notebook)) == 0) + { + sync_title (panel, NULL); + } + + g_signal_emit (G_OBJECT (panel), signals[ITEM_REMOVED], 0, item); + + g_object_unref (G_OBJECT (item)); + + return TRUE; } /** @@ -786,24 +724,24 @@ xed_panel_remove_item (XedPanel *panel, * Returns: %TRUE if it was activated */ gboolean -xed_panel_activate_item (XedPanel *panel, - GtkWidget *item) +xed_panel_activate_item (XedPanel *panel, + GtkWidget *item) { - gint page_num; + gint page_num; - g_return_val_if_fail (XED_IS_PANEL (panel), FALSE); - g_return_val_if_fail (GTK_IS_WIDGET (item), FALSE); + g_return_val_if_fail (XED_IS_PANEL (panel), FALSE); + g_return_val_if_fail (GTK_IS_WIDGET (item), FALSE); - page_num = gtk_notebook_page_num (GTK_NOTEBOOK (panel->priv->notebook), - item); + page_num = gtk_notebook_page_num (GTK_NOTEBOOK (panel->priv->notebook), item); - if (page_num == -1) - return FALSE; + if (page_num == -1) + { + return FALSE; + } - gtk_notebook_set_current_page (GTK_NOTEBOOK (panel->priv->notebook), - page_num); + gtk_notebook_set_current_page (GTK_NOTEBOOK (panel->priv->notebook), page_num); - return TRUE; + return TRUE; } /** @@ -816,41 +754,41 @@ xed_panel_activate_item (XedPanel *panel, * Returns: %TRUE if @item is the active widget */ gboolean -xed_panel_item_is_active (XedPanel *panel, - GtkWidget *item) +xed_panel_item_is_active (XedPanel *panel, + GtkWidget *item) { - gint cur_page; - gint page_num; + gint cur_page; + gint page_num; - g_return_val_if_fail (XED_IS_PANEL (panel), FALSE); - g_return_val_if_fail (GTK_IS_WIDGET (item), FALSE); + g_return_val_if_fail (XED_IS_PANEL (panel), FALSE); + g_return_val_if_fail (GTK_IS_WIDGET (item), FALSE); - page_num = gtk_notebook_page_num (GTK_NOTEBOOK (panel->priv->notebook), - item); + page_num = gtk_notebook_page_num (GTK_NOTEBOOK (panel->priv->notebook), item); - if (page_num == -1) - return FALSE; + if (page_num == -1) + { + return FALSE; + } - cur_page = gtk_notebook_get_current_page ( - GTK_NOTEBOOK (panel->priv->notebook)); + cur_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (panel->priv->notebook)); - return (page_num == cur_page); + return (page_num == cur_page); } /** * xed_panel_get_orientation: * @panel: a #XedPanel * - * Gets the orientation of the @panel. + * Gets the orientation of the @panel. * * Returns: the #GtkOrientation of #XedPanel */ GtkOrientation xed_panel_get_orientation (XedPanel *panel) { - g_return_val_if_fail (XED_IS_PANEL (panel), GTK_ORIENTATION_VERTICAL); + g_return_val_if_fail (XED_IS_PANEL (panel), GTK_ORIENTATION_VERTICAL); - return panel->priv->orientation; + return panel->priv->orientation; } /** @@ -858,81 +796,77 @@ xed_panel_get_orientation (XedPanel *panel) * @panel: a #XedPanel * * Gets the number of items in a @panel. - * + * * Returns: the number of items contained in #XedPanel */ gint xed_panel_get_n_items (XedPanel *panel) { - g_return_val_if_fail (XED_IS_PANEL (panel), -1); + g_return_val_if_fail (XED_IS_PANEL (panel), -1); - return gtk_notebook_get_n_pages (GTK_NOTEBOOK (panel->priv->notebook)); + return gtk_notebook_get_n_pages (GTK_NOTEBOOK (panel->priv->notebook)); } gint _xed_panel_get_active_item_id (XedPanel *panel) { - gint cur_page; - GtkWidget *item; - XedPanelItem *data; + gint cur_page; + GtkWidget *item; + XedPanelItem *data; - g_return_val_if_fail (XED_IS_PANEL (panel), 0); + g_return_val_if_fail (XED_IS_PANEL (panel), 0); - cur_page = gtk_notebook_get_current_page ( - GTK_NOTEBOOK (panel->priv->notebook)); - if (cur_page == -1) - return 0; + cur_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (panel->priv->notebook)); + if (cur_page == -1) + { + return 0; + } - item = gtk_notebook_get_nth_page ( - GTK_NOTEBOOK (panel->priv->notebook), - cur_page); + item = gtk_notebook_get_nth_page (GTK_NOTEBOOK (panel->priv->notebook), cur_page); - /* FIXME: for now we use as the hash of the name as id. - * However the name is not guaranteed to be unique and - * it is a translated string, so it's subotimal, but should - * be good enough for now since we don't want to add an - * ad hoc id argument. - */ + /* FIXME: for now we use as the hash of the name as id. + * However the name is not guaranteed to be unique and + * it is a translated string, so it's subotimal, but should + * be good enough for now since we don't want to add an + * ad hoc id argument. + */ - data = (XedPanelItem *)g_object_get_data (G_OBJECT (item), - PANEL_ITEM_KEY); - g_return_val_if_fail (data != NULL, 0); + data = (XedPanelItem *)g_object_get_data (G_OBJECT (item), PANEL_ITEM_KEY); + g_return_val_if_fail (data != NULL, 0); - return g_str_hash (data->name); + return g_str_hash (data->name); } void _xed_panel_set_active_item_by_id (XedPanel *panel, - gint id) + gint id) { - gint n, i; + gint n, i; - g_return_if_fail (XED_IS_PANEL (panel)); + g_return_if_fail (XED_IS_PANEL (panel)); - if (id == 0) - return; + if (id == 0) + { + return; + } - n = gtk_notebook_get_n_pages ( - GTK_NOTEBOOK (panel->priv->notebook)); + n = gtk_notebook_get_n_pages (GTK_NOTEBOOK (panel->priv->notebook)); - for (i = 0; i < n; i++) - { - GtkWidget *item; - XedPanelItem *data; + for (i = 0; i < n; i++) + { + GtkWidget *item; + XedPanelItem *data; - item = gtk_notebook_get_nth_page ( - GTK_NOTEBOOK (panel->priv->notebook), i); + item = gtk_notebook_get_nth_page (GTK_NOTEBOOK (panel->priv->notebook), i); - data = (XedPanelItem *)g_object_get_data (G_OBJECT (item), - PANEL_ITEM_KEY); - g_return_if_fail (data != NULL); + data = (XedPanelItem *)g_object_get_data (G_OBJECT (item), PANEL_ITEM_KEY); + g_return_if_fail (data != NULL); - if (g_str_hash (data->name) == id) - { - gtk_notebook_set_current_page ( - GTK_NOTEBOOK (panel->priv->notebook), i); + if (g_str_hash (data->name) == id) + { + gtk_notebook_set_current_page (GTK_NOTEBOOK (panel->priv->notebook), i); - return; - } - } + return; + } + } } From cab79801ca64e72d947c24e09c5132134cfa73f6 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 25 Dec 2016 14:24:00 -0800 Subject: [PATCH 020/132] plugins: Drop support for old style python plugins All the the old python plugins have already been removed. Remove a bunch of the other related cruft since we want to port the plugin system to libpeas Taken from https://github.com/mate-desktop/pluma/commit/65371f53dbb06180b750dad7c19e7bcf0f8651d6#diff-2bbd410468516599f21e84fecb500348 --- autogen.sh | 1 - configure.ac | 124 +- data/xed-bugreport.sh.in | 23 +- docs/reference/Makefile.am | 12 +- m4/python.m4 | 62 - plugin-loaders/Makefile.am | 4 - plugin-loaders/python/Makefile.am | 36 - plugin-loaders/python/bindings/Makefile.am | 115 -- plugin-loaders/python/bindings/xed.defs | 1442 ----------------- plugin-loaders/python/bindings/xed.override | 461 ------ .../python/bindings/xedcommands.defs | 45 - .../python/bindings/xedcommands.override | 122 -- .../python/bindings/xedmessage.override | 556 ------- .../python/bindings/xedplugin.override | 193 --- plugin-loaders/python/bindings/xedutils.defs | 67 - .../python/bindings/xedutils.override | 85 - .../python/xed-plugin-loader-python.c | 719 -------- .../python/xed-plugin-loader-python.h | 61 - plugin-loaders/python/xed-plugin-python.c | 281 ---- plugin-loaders/python/xed-plugin-python.h | 88 - tools/plugin_template/xed-plugin.desktop.in | 3 - xed/xed-plugin-info-priv.h | 11 +- 22 files changed, 9 insertions(+), 4502 deletions(-) delete mode 100644 m4/python.m4 delete mode 100644 plugin-loaders/python/Makefile.am delete mode 100644 plugin-loaders/python/bindings/Makefile.am delete mode 100644 plugin-loaders/python/bindings/xed.defs delete mode 100644 plugin-loaders/python/bindings/xed.override delete mode 100644 plugin-loaders/python/bindings/xedcommands.defs delete mode 100644 plugin-loaders/python/bindings/xedcommands.override delete mode 100644 plugin-loaders/python/bindings/xedmessage.override delete mode 100644 plugin-loaders/python/bindings/xedplugin.override delete mode 100644 plugin-loaders/python/bindings/xedutils.defs delete mode 100644 plugin-loaders/python/bindings/xedutils.override delete mode 100644 plugin-loaders/python/xed-plugin-loader-python.c delete mode 100644 plugin-loaders/python/xed-plugin-loader-python.h delete mode 100644 plugin-loaders/python/xed-plugin-python.c delete mode 100644 plugin-loaders/python/xed-plugin-python.h diff --git a/autogen.sh b/autogen.sh index 6769318..56ea79f 100755 --- a/autogen.sh +++ b/autogen.sh @@ -24,7 +24,6 @@ which yelp-build || { } REQUIRED_AUTOMAKE_VERSION=1.9 -REQUIRED_MACROS=python.m4 GNOME_DATADIR="$gnome_datadir" USE_COMMON_DOC_BUILD=yes diff --git a/configure.ac b/configure.ac index e37126a..3d6e7e2 100644 --- a/configure.ac +++ b/configure.ac @@ -178,123 +178,6 @@ dnl ================================================================ GLIB_GSETTINGS -dnl ================================================================ -dnl Python -dnl ================================================================ - -AC_MSG_CHECKING([whether Python support is requested]) -AC_ARG_ENABLE([python], - AS_HELP_STRING([--enable-python],[Enable python support]), - [enable_python=$enableval have_python=$enableval], - [enable_python=autodetect have_python=yes]) -AC_MSG_RESULT([$enable_python]) - -if test "x$have_python" != "xno"; then - AM_PATH_PYTHON([2.5],[],[no]) - if test "x$PYTHON" = "x:"; then - have_python=no - fi -fi - -if test "x$have_python" != "xno"; then - AM_CHECK_PYTHON_HEADERS([],[have_python=no]) -fi - -if test "x$have_python" != "xno"; then - PY_EXEC_PREFIX=`$PYTHON -c 'import sys ; print sys.exec_prefix'` - PYTHON_LIBS="-lpython$PYTHON_VERSION" - - PY_PREFIX=`$PYTHON -c 'import sys ; print sys.prefix'` - PYTHON_LIB_LOC="-L$libdir/python$PYTHON_VERSION/config" - PYTHON_CFLAGS="-I$PY_PREFIX/include/python$PYTHON_VERSION" - PYTHON_MAKEFILE="$libdir/python$PYTHON_VERSION/config/Makefile" - PYTHON_BASEMODLIBS=`sed -n -e 's/^BASEMODLIBS=\(.*\)/\1/p' $PYTHON_MAKEFILE` - PYTHON_OTHER_LIBS=`sed -n -e 's/^LIBS=\(.*\)/\1/p' $PYTHON_MAKEFILE` - PYTHON_EXTRA_LIBS="$PYTHON_BASEMODLIBS $PYTHON_OTHER_LIBS" - - AC_SUBST([PYTHON_LIBS]) - AC_SUBST([PYTHON_LIB_LOC]) - AC_SUBST([PYTHON_CFLAGS]) - AC_SUBST([PYTHON_EXTRA_LIBS]) -fi - -if test "x$have_python" != "xyes"; then - if test "x$enable_python" = "xyes"; then - AC_MSG_ERROR([Python not found]) - elif test "x$enable_python" = "xautodetect"; then - enable_python=no - AC_MSG_WARN([Python not found, disabling python support]) - fi -fi - -if test "x$have_python" != "xno"; then - PYGOBJECT_REQUIRED=2.15.4 - PYGTK_REQUIRED=2.12.0 - PYGTKSOURCEVIEW_REQUIRED=2.9.2 - - PKG_CHECK_MODULES([PYGTK], [ - pygobject-2.0 >= $PYGOBJECT_REQUIRED - pygtk-2.0 >= $PYGTK_REQUIRED - pygtksourceview-2.0 >= $PYGTKSOURCEVIEW_REQUIRED], - [], - [ - have_python=no - if test "x$enable_python" = "xyes"; then - AC_MSG_ERROR([$PYGTK_PKG_ERRORS]) - elif test "x$enable_python" = "xautodetect"; then - enable_python=no - AC_MSG_WARN([$PYGTK_PKG_ERRORS]) - AC_MSG_WARN([Disabling python support]) - fi - ]) -fi - -if test "x$have_python" != "xno"; then - AC_MSG_CHECKING([for pygtk defs]) - PYGTK_DEFSDIR=`$PKG_CONFIG --variable=defsdir pygtk-2.0` - AC_MSG_RESULT([$PYGTK_DEFSDIR]) - - AC_MSG_CHECKING([for pygobject defs]) - PYGOBJECT_DEFSDIR=`$PKG_CONFIG --variable=defsdir pygobject-2.0` - AC_MSG_RESULT([$PYGOBJECT_DEFSDIR]) - - AC_MSG_CHECKING([for pygtk codegen]) - PYGTK_CODEGEN="$PYTHON `$PKG_CONFIG --variable=codegendir pygtk-2.0`/codegen.py" - AC_MSG_RESULT([$PYGTK_CODEGEN]) - - AC_MSG_CHECKING([for pygtk h2def]) - PYGTK_H2DEF="$PYTHON `$PKG_CONFIG --variable=codegendir pygtk-2.0`/h2def.py" - AC_MSG_RESULT([$PYGTK_H2DEF]) - - AC_SUBST([PYGTK_DEFSDIR]) - AC_SUBST([PYGOBJECT_DEFSDIR]) - AC_SUBST([PYGTK_CODEGEN]) - AC_SUBST([PYGTK_H2DEF]) - - dnl Check for -fno-strict-aliasing - FLAGS="-fno-strict-aliasing" - save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $FLAGS" - AC_MSG_CHECKING([whether [$]CC understands $FLAGS]) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[compiler_has_option=yes],[compiler_has_option=no]) - CFLAGS="$save_CFLAGS" - AC_MSG_RESULT($compiler_has_option) - if test $compiler_has_option = yes; then - NO_STRICT_ALIASING_CFLAGS="$FLAGS" - fi - AC_SUBST([NO_STRICT_ALIASING_CFLAGS]) -fi - -if test "x$have_python" != "xno" -a "x$enable_python" != "xno"; then - enable_python=yes - AC_DEFINE([ENABLE_PYTHON],[1],[Define to compile with python support]) -fi - -AM_CONDITIONAL([ENABLE_PYTHON],[test "x$enable_python" = "xyes"]) - -dnl This allows the bug-report script to know whether python has been enabled -AC_SUBST(enable_python) - dnl ================================================================ dnl Misc dnl ================================================================ @@ -355,8 +238,6 @@ help/Makefile pixmaps/Makefile plugin-loaders/Makefile plugin-loaders/c/Makefile -plugin-loaders/python/Makefile -plugin-loaders/python/bindings/Makefile plugins/Makefile plugins/changecase/Makefile plugins/docinfo/Makefile @@ -381,9 +262,8 @@ echo " Configuration: Source code location: ${srcdir} - Compiler: ${CC} - Python Plugins Support: $enable_python + Compiler: ${CC} Spell Plugin enabled: $enable_enchant Gvfs metadata enabled: $enable_gvfs_metadata - Tests enabled: $enable_tests + Tests enabled: $enable_tests " diff --git a/data/xed-bugreport.sh.in b/data/xed-bugreport.sh.in index fcaed9f..01ae2cc 100644 --- a/data/xed-bugreport.sh.in +++ b/data/xed-bugreport.sh.in @@ -1,10 +1,7 @@ #!/bin/sh -ENABLE_PYTHON=@enable_python@ - PKG_CONFIG_MODULES="glib-2.0 gtk+-2.0 gtksourceview-2.0 \ - pygobject-2.0 pygtk-2.0 \ - pygtksourceview-2.0 enchant iso-codes" + enchant iso-codes" echo_padded () { @@ -53,21 +50,3 @@ else echo " pkg-config unavailable" fi echo - -echo "Python module versions:" -if test "$ENABLE_PYTHON" = "yes" -then - echo_padded "python" - python -V 2>&1 | cut -c8- - - echo_padded "pygtk" - python -c "import gtk, sys; \ - sys.stdout.write('%d.%d.%d ' % gtk.pygtk_version); \ - sys.stdout.write('(GTK+ %d.%d.%d)' % gtk.gtk_version)" \ - 2>/dev/null - echo -else - echo " Python support was not enabled at compile time." -fi -echo - diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am index e153873..a890721 100644 --- a/docs/reference/Makefile.am +++ b/docs/reference/Makefile.am @@ -20,7 +20,7 @@ DOC_SOURCE_DIR=../../xed SCANGOBJ_OPTIONS= # Extra options to supply to gtkdoc-scan. -# e.g. SCAN_OPTIONS=--deprecated-guards="GTK_DISABLE_DEPRECATED" +# e.g. SCAN_OPTIONS=--deprecated-guards="GTK_DISABLE_DEPRECATED" SCAN_OPTIONS= # Extra options to supply to gtkdoc-mkdb. @@ -96,16 +96,6 @@ GTKDOC_LIBS= \ $(top_builddir)/xed/libxed.la \ $(XED_LIBS) -if ENABLE_PYTHON -GTKDOC_CFLAGS += \ - $(NO_STRICT_ALIASING_CFLAGS) \ - $(PYGTK_CFLAGS) \ - $(PYTHON_CFLAGS) \ - $(AM_CFLAGS) -GTKDOC_LIBS += \ - $(top_builddir)/plugin-loaders/python/bindings/xed.la -endif - # This includes the standard gtk-doc make rules, copied by gtkdocize. include $(top_srcdir)/gtk-doc.make diff --git a/m4/python.m4 b/m4/python.m4 deleted file mode 100644 index e1c5266..0000000 --- a/m4/python.m4 +++ /dev/null @@ -1,62 +0,0 @@ -## this one is commonly used with AM_PATH_PYTHONDIR ... -dnl AM_CHECK_PYMOD(MODNAME [,SYMBOL [,ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]]]) -dnl Check if a module containing a given symbol is visible to python. -AC_DEFUN([AM_CHECK_PYMOD], -[AC_REQUIRE([AM_PATH_PYTHON]) -py_mod_var=`echo $1['_']$2 | sed 'y%./+-%__p_%'` -AC_MSG_CHECKING(for ifelse([$2],[],,[$2 in ])python module $1) -AC_CACHE_VAL(py_cv_mod_$py_mod_var, [ -ifelse([$2],[], [prog=" -import sys -try: - import $1 -except ImportError: - sys.exit(1) -except: - sys.exit(0) -sys.exit(0)"], [prog=" -import $1 -$1.$2"]) -if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC - then - eval "py_cv_mod_$py_mod_var=yes" - else - eval "py_cv_mod_$py_mod_var=no" - fi -]) -py_val=`eval "echo \`echo '$py_cv_mod_'$py_mod_var\`"` -if test "x$py_val" != xno; then - AC_MSG_RESULT(yes) - ifelse([$3], [],, [$3 -])dnl -else - AC_MSG_RESULT(no) - ifelse([$4], [],, [$4 -])dnl -fi -]) - -dnl a macro to check for ability to create python extensions -dnl AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE]) -dnl function also defines PYTHON_INCLUDES -AC_DEFUN([AM_CHECK_PYTHON_HEADERS], -[AC_REQUIRE([AM_PATH_PYTHON]) -AC_MSG_CHECKING(for headers required to compile python extensions) -dnl deduce PYTHON_INCLUDES -py_prefix=`$PYTHON -c "import sys; print sys.prefix"` -py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"` -PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}" -if test "$py_prefix" != "$py_exec_prefix"; then - PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}" -fi -AC_SUBST(PYTHON_INCLUDES) -dnl check if the headers exist: -save_CPPFLAGS="$CPPFLAGS" -CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES" -AC_TRY_CPP([#include ],dnl -[AC_MSG_RESULT(found) -$1],dnl -[AC_MSG_RESULT(not found) -$2]) -CPPFLAGS="$save_CPPFLAGS" -]) diff --git a/plugin-loaders/Makefile.am b/plugin-loaders/Makefile.am index bf1e964..2573ec3 100644 --- a/plugin-loaders/Makefile.am +++ b/plugin-loaders/Makefile.am @@ -1,7 +1,3 @@ SUBDIRS = c -if ENABLE_PYTHON -SUBDIRS += python -endif - -include $(top_srcdir)/git.mk diff --git a/plugin-loaders/python/Makefile.am b/plugin-loaders/python/Makefile.am deleted file mode 100644 index ef9acc2..0000000 --- a/plugin-loaders/python/Makefile.am +++ /dev/null @@ -1,36 +0,0 @@ -# C plugin loader - -SUBDIRS = bindings -loaderdir = $(libdir)/xed/plugin-loaders - -AM_CPPFLAGS = \ - -I$(top_srcdir) \ - -I$(top_builddir) \ - -I$(top_srcdir)/xed \ - -I$(top_builddir)/xed \ - $(XED_CFLAGS) \ - $(WARN_CFLAGS) \ - $(DISABLE_DEPRECATED_CFLAGS) \ - $(PYGTK_CFLAGS) \ - $(PYTHON_CFLAGS) \ - -DXED_PLUGINS_LIBS_DIR=\"$(XED_PLUGINS_LIBS_DIR)\" \ - -DXED_LOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\" - -loader_LTLIBRARIES = libpythonloader.la - - -NOINST_H_FILES = \ - xed-plugin-loader-python.h \ - xed-plugin-python.h - -libpythonloader_la_SOURCES = \ - xed-plugin-loader-python.c \ - xed-plugin-python.c \ - $(NOINST_H_FILES) - -libpythonloader_la_LDFLAGS = $(LOADER_LIBTOOL_FLAGS) -libpythonloader_la_LIBADD = \ - $(XED_LIBS) \ - bindings/xed.la - --include $(top_srcdir)/git.mk diff --git a/plugin-loaders/python/bindings/Makefile.am b/plugin-loaders/python/bindings/Makefile.am deleted file mode 100644 index efcbf17..0000000 --- a/plugin-loaders/python/bindings/Makefile.am +++ /dev/null @@ -1,115 +0,0 @@ -## Process this file with automake to produce Makefile.in - -noinst_LTLIBRARIES = \ - xed.la - -nodist_xed_la_SOURCES = \ - xed.c \ - xedutils.c \ - xedcommands.c - -xed_la_LDFLAGS = \ - -module -avoid-version - -xed_la_LIBADD = \ - $(PYTHON_LIB_LOC) \ - $(PYTHON_LIBS) \ - $(PYTHON_EXTRA_LIBS) \ - $(PYGTK_LIBS) - -xed_la_CFLAGS = \ - -I$(top_srcdir) \ - -I$(top_builddir) \ - -I$(top_srcdir)/xed \ - -I$(top_builddir)/xed \ - -I$(top_srcdir)/plugin-loaders/python \ - -I$(top_builddir)/plugin-loaders/python \ - $(XED_CFLAGS) \ - $(NO_STRICT_ALIASING_CFLAGS) \ - $(PYGTK_CFLAGS) \ - $(PYTHON_CFLAGS) \ - $(AM_CFLAGS) - -$(top_builddir)/xed/xed-enum-types.h: - cd $(top_builddir)/xed && $(MAKE) xed-enum-types.h - -xed.c: xed.defs xed.override xedplugin.override xedmessage.override $(top_builddir)/xed/xed-enum-types.h - ( cd $(srcdir) && $(PYGTK_CODEGEN) \ - --register $(PYGTK_DEFSDIR)/pango-types.defs \ - --register $(PYGTK_DEFSDIR)/gdk-types.defs \ - --register $(PYGTK_DEFSDIR)/gtk-types.defs \ - --register $(PYGTK_DEFSDIR)/gtksourceview2.defs \ - --register $(PYGOBJECT_DEFSDIR)/gio-types.defs \ - --override $*.override \ - --prefix py$* $( $@ - -xedutils.c: xedutils.defs xedutils.override - ( cd $(srcdir) && $(PYGTK_CODEGEN) \ - --override $*.override \ - --prefix py$* $( $@ - -xedcommands.c: xedcommands.defs xedcommands.override xed.defs - ( cd $(srcdir) && $(PYGTK_CODEGEN) \ - --register xed.defs \ - --register $(PYGTK_DEFSDIR)/gtk-types.defs \ - --override $*.override \ - --prefix py$* $( $@ - -BINDING_XED_HEADERS_SRCDIR_IN = \ - xed/xed-app.h \ - xed/xed-document.h \ - xed/xed-encodings.h \ - xed/xed-plugin.h \ - plugin-loaders/python/xed-plugin-python.h \ - xed/xed-view.h \ - xed/xed-statusbar.h \ - xed/xed-tab.h \ - xed/xed-panel.h \ - xed/xed-window.h \ - xed/xed-help.h \ - xed/xed-debug.h \ - xed/xed-message-type.h \ - xed/xed-message.h \ - xed/xed-message-bus.h \ - xed/xed-language-manager.h - -BINDING_UTILS_HEADERS_SRCDIR_IN = \ - xed/xed-utils.h - -BINDING_COMMANDS_HEADERS_SRCDIR_IN = \ - xed/xed-commands.h - -BINDING_HEADERS_BUILDDIR_IN = - -BINDING_XED_HEADERS_SRCDIR := $(addprefix $(top_srcdir)/,$(BINDING_XED_HEADERS_SRCDIR_IN)) -BINDING_UTILS_HEADERS_SRCDIR := $(addprefix $(top_srcdir)/,$(BINDING_UTILS_HEADERS_SRCDIR_IN)) -BINDING_COMMANDS_HEADERS_SRCDIR := $(addprefix $(top_srcdir)/,$(BINDING_COMMANDS_HEADERS_SRCDIR_IN)) - -BINDING_HEADERS_BUILDDIR := $(addprefix $(top_builddir)/,$(BINDING_HEADERS_BUILDDIR_IN)) - -regenerate-python-binding: - $(PYGTK_H2DEF) $(sort $(BINDING_XED_HEADERS_SRCDIR) $(BINDING_HEADERS_BUILDDIR)) > xed.defs.new - $(PYGTK_H2DEF) $(sort $(BINDING_UTILS_HEADERS_SRCDIR) $(BINDING_HEADERS_BUILDDIR)) > xedutils.defs.new - $(PYGTK_H2DEF) $(sort $(BINDING_COMMANDS_HEADERS_SRCDIR) $(BINDING_HEADERS_BUILDDIR)) > xedcommands.defs.new - -BUILT_SOURCES = \ - xed.c \ - xedutils.c \ - xedcommands.c - -EXTRA_DIST = \ - xed.override \ - xed.defs \ - xedutils.override \ - xedutils.defs \ - xedcommands.override \ - xedcommands.defs \ - xedmessage.override \ - xedplugin.override - -CLEANFILES = $(BUILT_SOURCES) - -dist-hook: - cd $(distdir); rm -f $(BUILT_SOURCES) - --include $(top_srcdir)/git.mk diff --git a/plugin-loaders/python/bindings/xed.defs b/plugin-loaders/python/bindings/xed.defs deleted file mode 100644 index 75af263..0000000 --- a/plugin-loaders/python/bindings/xed.defs +++ /dev/null @@ -1,1442 +0,0 @@ -;; -*- scheme -*- -; object definitions ... -(define-object App - (in-module "Xed") - (parent "GObject") - (c-name "XedApp") - (gtype-id "XED_TYPE_APP") -) - -(define-object Document - (in-module "Xed") - (parent "GtkSourceBuffer") - (c-name "XedDocument") - (gtype-id "XED_TYPE_DOCUMENT") -) - -(define-object Message - (in-module "Xed") - (parent "GObject") - (c-name "XedMessage") - (gtype-id "XED_TYPE_MESSAGE") -) - -(define-object MessageBus - (in-module "Xed") - (parent "GObject") - (c-name "XedMessageBus") - (gtype-id "XED_TYPE_MESSAGE_BUS") -) - -(define-object Panel - (in-module "Xed") - (parent "GtkVBox") - (c-name "XedPanel") - (gtype-id "XED_TYPE_PANEL") -) - -(define-object __Plugin - (in-module "Xed") - (parent "GObject") - (c-name "XedPlugin") - (gtype-id "XED_TYPE_PLUGIN") -) - -(define-object Plugin - (in-module "Xed") - (parent "XedPlugin") - (c-name "XedPluginPython") - (gtype-id "XED_TYPE_PLUGIN_PYTHON") -) - -(define-object Statusbar - (in-module "Xed") - (parent "GtkStatusbar") - (c-name "XedStatusbar") - (gtype-id "XED_TYPE_STATUSBAR") -) - -(define-object Tab - (in-module "Xed") - (parent "GtkVBox") - (c-name "XedTab") - (gtype-id "XED_TYPE_TAB") -) - -(define-object View - (in-module "Xed") - (parent "GtkSourceView") - (c-name "XedView") - (gtype-id "XED_TYPE_VIEW") -) - -(define-object Window - (in-module "Xed") - (parent "GtkWindow") - (c-name "XedWindow") - (gtype-id "XED_TYPE_WINDOW") -) - -;; Enumerations and flags ... - -(define-flags SearchFlags - (in-module "Xed") - (c-name "XedSearchFlags") - (gtype-id "XED_TYPE_SEARCH_FLAGS") - (values - '("dont-set-flags" "XED_SEARCH_DONT_SET_FLAGS") - '("entire-word" "XED_SEARCH_ENTIRE_WORD") - '("case-sensitive" "XED_SEARCH_CASE_SENSITIVE") - ) -) - -(define-flags DocumentSaveFlags - (in-module "Xed") - (c-name "XedDocumentSaveFlags") - (gtype-id "XED_TYPE_DOCUMENT_SAVE_FLAGS") - (values - '("ignore-mtime" "XED_DOCUMENT_SAVE_IGNORE_MTIME") - '("ignore-backup" "XED_DOCUMENT_SAVE_IGNORE_BACKUP") - '("preserve-backup" "XED_DOCUMENT_SAVE_PRESERVE_BACKUP") - ) -) - -(define-enum TabState - (in-module "Xed") - (c-name "XedTabState") - (gtype-id "XED_TYPE_TAB_STATE") - (values - '("normal" "XED_TAB_STATE_NORMAL") - '("loading" "XED_TAB_STATE_LOADING") - '("reverting" "XED_TAB_STATE_REVERTING") - '("saving" "XED_TAB_STATE_SAVING") - '("printing" "XED_TAB_STATE_PRINTING") - '("print-previewing" "XED_TAB_STATE_PRINT_PREVIEWING") - '("showing-print-preview" "XED_TAB_STATE_SHOWING_PRINT_PREVIEW") - '("generic-not-editable" "XED_TAB_STATE_GENERIC_NOT_EDITABLE") - '("loading-error" "XED_TAB_STATE_LOADING_ERROR") - '("reverting-error" "XED_TAB_STATE_REVERTING_ERROR") - '("saving-error" "XED_TAB_STATE_SAVING_ERROR") - '("generic-error" "XED_TAB_STATE_GENERIC_ERROR") - '("closing" "XED_TAB_STATE_CLOSING") - ) -) - -(define-flags WindowState - (in-module "Xed") - (c-name "XedWindowState") - (gtype-id "XED_TYPE_WINDOW_STATE") - (values - '("normal" "XED_WINDOW_STATE_NORMAL") - '("saving" "XED_WINDOW_STATE_SAVING") - '("printing" "XED_WINDOW_STATE_PRINTING") - '("loading" "XED_WINDOW_STATE_LOADING") - '("error" "XED_WINDOW_STATE_ERROR") - '("saving-session" "XED_WINDOW_STATE_SAVING_SESSION") - ) -) - -;; Boxed types -(define-boxed Encoding - (in-module "Xed") - (c-name "XedEncoding") - (gtype-id "XED_TYPE_ENCODING") - (copy-func "xed_encoding_copy") - (release-func "xed_encoding_free") -;; (fields -;; '("gint" "index") -;; '("gchar*" "charset") -;; '("gchar*" "name") -;; ) -) - -(define-boxed MessageType - (in-module "Xed") - (c-name "XedMessageType") - (gtype-id "XED_TYPE_MESSAGE_TYPE") - (copy-func "xed_message_type_ref") - (release-func "xed_message_type_unref") -) - - -;; From ../../xed/xed-app.h - -(define-function xed_app_get_type - (c-name "xed_app_get_type") - (return-type "GType") -) - -(define-function app_get_default - (c-name "xed_app_get_default") - (return-type "XedApp*") -) - -; deprecated version ! -(define-function xed_app_get_default - (c-name "xed_app_get_default_deprecated") - (return-type "XedApp*") -) - -(define-method create_window - (of-object "XedApp") - (c-name "xed_app_create_window") - (return-type "XedWindow*") - (parameters - '("GdkScreen*" "screen") - ) -) - -(define-method get_windows - (of-object "XedApp") - (c-name "xed_app_get_windows") - (return-type "const-GList*") -) - -(define-method get_active_window - (of-object "XedApp") - (c-name "xed_app_get_active_window") - (return-type "XedWindow*") -) - -(define-method get_documents - (of-object "XedApp") - (c-name "xed_app_get_documents") - (return-type "GList*") -) - -(define-method get_views - (of-object "XedApp") - (c-name "xed_app_get_views") - (return-type "GList*") -) - - -;; From ../../xed/xed-document.h - -(define-function document_error_quark - (c-name "xed_document_error_quark") - (return-type "GQuark") -) - -(define-function xed_document_get_type - (c-name "xed_document_get_type") - (return-type "GType") -) - -(define-function xed_document_new - (c-name "xed_document_new") - (is-constructor-of "XedDocument") - (return-type "XedDocument*") -) - -(define-method get_location - (of-object "XedDocument") - (c-name "xed_document_get_location") - (return-type "GFile*") -) - -(define-method get_uri - (of-object "XedDocument") - (c-name "xed_document_get_uri") - (return-type "gchar*") -) - -(define-method set_uri - (of-object "XedDocument") - (c-name "xed_document_set_uri") - (return-type "none") - (parameters - '("const-gchar*" "uri") - ) -) - -(define-method get_uri_for_display - (of-object "XedDocument") - (c-name "xed_document_get_uri_for_display") - (return-type "gchar*") -) - -(define-method get_short_name_for_display - (of-object "XedDocument") - (c-name "xed_document_get_short_name_for_display") - (return-type "gchar*") -) - -(define-method get_content_type - (of-object "XedDocument") - (c-name "xed_document_get_content_type") - (return-type "gchar*") -) - -(define-method get_mime_type - (of-object "XedDocument") - (c-name "xed_document_get_mime_type") - (return-type "gchar*") -) - -(define-method get_readonly - (of-object "XedDocument") - (c-name "xed_document_get_readonly") - (return-type "gboolean") -) - -(define-method load - (of-object "XedDocument") - (c-name "xed_document_load") - (return-type "none") - (parameters - '("const-gchar*" "uri") - '("const-XedEncoding*" "encoding") - '("gint" "line_pos") - '("gboolean" "create") - ) -) - -(define-method insert_file - (of-object "XedDocument") - (c-name "xed_document_insert_file") - (return-type "gboolean") - (parameters - '("GtkTextIter*" "iter") - '("const-gchar*" "uri") - '("const-XedEncoding*" "encoding") - ) -) - -(define-method load_cancel - (of-object "XedDocument") - (c-name "xed_document_load_cancel") - (return-type "gboolean") -) - -(define-method save - (of-object "XedDocument") - (c-name "xed_document_save") - (parameters - '("XedDocumentSaveFlags" "flags") - ) - (return-type "none") -) - -(define-method save_as - (of-object "XedDocument") - (c-name "xed_document_save_as") - (return-type "none") - (parameters - '("const-gchar*" "uri") - '("const-XedEncoding*" "encoding") - '("XedDocumentSaveFlags" "flags") - ) -) - -(define-method is_untouched - (of-object "XedDocument") - (c-name "xed_document_is_untouched") - (return-type "gboolean") -) - -(define-method is_untitled - (of-object "XedDocument") - (c-name "xed_document_is_untitled") - (return-type "gboolean") -) - -(define-method is_local - (of-object "XedDocument") - (c-name "xed_document_is_local") - (return-type "gboolean") -) - -(define-method get_deleted - (of-object "XedDocument") - (c-name "xed_document_get_deleted") - (return-type "gboolean") -) - -(define-method goto_line - (of-object "XedDocument") - (c-name "xed_document_goto_line") - (return-type "gboolean") - (parameters - '("gint" "line") - ) -) - -(define-method set_search_text - (of-object "XedDocument") - (c-name "xed_document_set_search_text") - (return-type "none") - (parameters - '("const-gchar*" "text") - '("guint" "flags") - ) -) - -(define-method get_search_text - (of-object "XedDocument") - (c-name "xed_document_get_search_text") - (return-type "gchar*") - (parameters - '("guint*" "flags") - ) -) - -(define-method get_can_search_again - (of-object "XedDocument") - (c-name "xed_document_get_can_search_again") - (return-type "gboolean") -) - -(define-method search_forward - (of-object "XedDocument") - (c-name "xed_document_search_forward") - (return-type "gboolean") - (parameters - '("const-GtkTextIter*" "start") - '("const-GtkTextIter*" "end") - '("GtkTextIter*" "match_start") - '("GtkTextIter*" "match_end") - ) -) - -(define-method replace_all - (of-object "XedDocument") - (c-name "xed_document_replace_all") - (return-type "gint") - (parameters - '("const-gchar*" "find") - '("const-gchar*" "replace") - '("guint" "flags") - ) -) - -(define-method search_backward - (of-object "XedDocument") - (c-name "xed_document_search_backward") - (return-type "gboolean") - (parameters - '("const-GtkTextIter*" "start") - '("const-GtkTextIter*" "end") - '("GtkTextIter*" "match_start") - '("GtkTextIter*" "match_end") - ) -) - -(define-method set_language - (of-object "XedDocument") - (c-name "xed_document_set_language") - (return-type "none") - (parameters - '("GtkSourceLanguage*" "lang" (null-ok)) - ) -) - -(define-method get_language - (of-object "XedDocument") - (c-name "xed_document_get_language") - (return-type "GtkSourceLanguage*") -) - -(define-method get_encoding - (of-object "XedDocument") - (c-name "xed_document_get_encoding") - (return-type "const-XedEncoding*") -) - -(define-method set_enable_search_highlighting - (of-object "XedDocument") - (c-name "xed_document_set_enable_search_highlighting") - (return-type "none") - (parameters - '("gboolean" "enable") - ) -) - -(define-method get_enable_search_highlighting - (of-object "XedDocument") - (c-name "xed_document_get_enable_search_highlighting") - (return-type "gboolean") -) - -;; From ../../xed/xed-encodings.h - -(define-function xed_encoding_get_type - (c-name "xed_encoding_get_type") - (return-type "GType") -) - -(define-method copy - (of-object "XedEncoding") - (c-name "xed_encoding_copy") - (return-type "XedEncoding*") -) - -(define-method free - (of-object "XedEncoding") - (c-name "xed_encoding_free") - (return-type "none") -) - -(define-function encoding_get_from_charset - (c-name "xed_encoding_get_from_charset") - (return-type "const-XedEncoding*") - (parameters - '("const-gchar*" "charset") - ) -) - -; Deprecated version ! -(define-function xed_encoding_get_from_charset - (c-name "xed_encoding_get_from_charset_deprecated") - (return-type "const-XedEncoding*") - (parameters - '("const-gchar*" "charset") - ) -) - -(define-function encoding_get_from_index - (c-name "xed_encoding_get_from_index") - (return-type "const-XedEncoding*") - (parameters - '("gint" "index") - ) -) - -; Deprecated version ! -(define-function xed_encoding_get_from_index - (c-name "xed_encoding_get_from_index_deprecated") - (return-type "const-XedEncoding*") - (parameters - '("gint" "index") - ) -) - -(define-method to_string - (of-object "XedEncoding") - (c-name "xed_encoding_to_string") - (return-type "gchar*") -) - -(define-method get_name - (of-object "XedEncoding") - (c-name "xed_encoding_get_name") - (return-type "const-gchar*") -) - -(define-method get_charset - (of-object "XedEncoding") - (c-name "xed_encoding_get_charset") - (return-type "const-gchar*") -) - -(define-function encoding_get_utf8 - (c-name "xed_encoding_get_utf8") - (return-type "const-XedEncoding*") -) - -; Deprecated version ! -(define-function xed_encoding_get_utf8 - (c-name "xed_encoding_get_utf8_deprecated") - (return-type "const-XedEncoding*") -) - -(define-function encoding_get_current - (c-name "xed_encoding_get_current") - (return-type "const-XedEncoding*") -) - -; Deprecated version ! -(define-function xed_encoding_get_current - (c-name "xed_encoding_get_current_deprecated") - (return-type "const-XedEncoding*") -) - -;; From ../../xed/xed-help.h - -(define-function help_display - (c-name "xed_help_display") - (return-type "gboolean") - (parameters - '("GtkWindow*" "parent") - '("const-gchar*" "name") - '("const-gchar*" "link_id") - ) -) - - - -;; From ../../xed/xed-panel.h - -(define-function xed_panel_get_type - (c-name "xed_panel_get_type") - (return-type "GType") -) - -(define-function xed_panel_new - (c-name "xed_panel_new") - (is-constructor-of "XedPanel") - (return-type "GtkWidget*") -) - -(define-method add_item - (of-object "XedPanel") - (c-name "xed_panel_add_item") - (return-type "none") - (parameters - '("GtkWidget*" "item") - '("const-gchar*" "name") - '("GtkWidget*" "image") - ) -) - -(define-method add_item_with_stock_icon - (of-object "XedPanel") - (c-name "xed_panel_add_item_with_stock_icon") - (return-type "none") - (parameters - '("GtkWidget*" "item") - '("const-gchar*" "name") - '("const-gchar*" "stock_id") - ) -) - -(define-method remove_item - (of-object "XedPanel") - (c-name "xed_panel_remove_item") - (return-type "gboolean") - (parameters - '("GtkWidget*" "item") - ) -) - -(define-method activate_item - (of-object "XedPanel") - (c-name "xed_panel_activate_item") - (return-type "gboolean") - (parameters - '("GtkWidget*" "item") - ) -) - -(define-method item_is_active - (of-object "XedPanel") - (c-name "xed_panel_item_is_active") - (return-type "gboolean") - (parameters - '("GtkWidget*" "item") - ) -) - -(define-method get_orientation - (of-object "XedPanel") - (c-name "xed_panel_get_orientation") - (return-type "GtkOrientation") -) - -(define-method get_n_items - (of-object "XedPanel") - (c-name "xed_panel_get_n_items") - (return-type "gint") -) - - -;; From ../../xed/xed-plugin.h - -(define-function xed_plugin_get_type - (c-name "xed_plugin_get_type") - (return-type "GType") -) - -(define-method get_install_dir - (of-object "XedPlugin") - (c-name "xed_plugin_get_install_dir") - (return-type "gchar*") -) - -(define-method get_data_dir - (of-object "XedPlugin") - (c-name "xed_plugin_get_data_dir") - (return-type "gchar*") -) - -(define-method activate - (of-object "XedPlugin") - (c-name "xed_plugin_activate") - (return-type "none") - (parameters - '("XedWindow*" "window") - ) -) - -(define-method deactivate - (of-object "XedPlugin") - (c-name "xed_plugin_deactivate") - (return-type "none") - (parameters - '("XedWindow*" "window") - ) -) - -(define-method update_ui - (of-object "XedPlugin") - (c-name "xed_plugin_update_ui") - (return-type "none") - (parameters - '("XedWindow*" "window") - ) -) - -(define-method is_configurable - (of-object "XedPlugin") - (c-name "xed_plugin_is_configurable") - (return-type "gboolean") -) - -(define-method create_configure_dialog - (of-object "XedPlugin") - (c-name "xed_plugin_create_configure_dialog") - (return-type "GtkWidget*") -) - -;; From ../xed/xed-plugin-python.h - -(define-function xed_plugin_python_get_type - (c-name "xed_plugin_python_get_type") - (return-type "GType") -) - -(define-function xed_plugin_python_new - (c-name "xed_plugin_python_new") - (is-constructor-of "XedPluginPython") - (return-type "XedPluginPython*") -) - -;; From ../../xed/xed-status-bar.h - -(define-method flash_message - (of-object "XedStatusbar") - (c-name "xed_statusbar_flash_message") - (return-type "none") - (parameters - '("int" "context_id") - '("const-gchar*" "message") - ) - ) - -;; From ../../xed/xed-tab.h - -(define-function xed_tab_get_type - (c-name "xed_tab_get_type") - (return-type "GType") -) - -(define-method get_view - (of-object "XedTab") - (c-name "xed_tab_get_view") - (return-type "XedView*") -) - -(define-method get_document - (of-object "XedTab") - (c-name "xed_tab_get_document") - (return-type "XedDocument*") -) - -(define-function tab_get_from_document - (c-name "xed_tab_get_from_document") - (return-type "XedTab*") - (parameters - '("XedDocument*" "doc") - ) -) - -; Deprecated version ! -(define-function xed_tab_get_from_document - (c-name "xed_tab_get_from_document_deprecated") - (return-type "XedTab*") - (parameters - '("XedDocument*" "doc") - ) -) - -(define-method get_state - (of-object "XedTab") - (c-name "xed_tab_get_state") - (return-type "XedTabState") -) - -(define-method set_auto_save_enabled - (of-object "XedTab") - (c-name "xed_tab_set_auto_save_enabled") - (return-type "none") - (parameters - '("gboolean" "enable") - ) -) - -(define-method get_auto_save_enabled - (of-object "XedTab") - (c-name "xed_tab_get_auto_save_enabled") - (return-type "gboolean") -) - -(define-method set_auto_save_interval - (of-object "XedTab") - (c-name "xed_tab_set_auto_save_interval") - (return-type "none") - (parameters - '("gint" "interval") - ) -) - -(define-method get_auto_save_interval - (of-object "XedTab") - (c-name "xed_tab_get_auto_save_interval") - (return-type "gint") -) - -;; From ../../xed/xed-view.h - -(define-function xed_view_get_type - (c-name "xed_view_get_type") - (return-type "GtkType") -) - -(define-function xed_view_new - (c-name "xed_view_new") - (is-constructor-of "XedView") - (return-type "GtkWidget*") - (parameters - '("XedDocument*" "doc") - ) -) - -(define-method cut_clipboard - (of-object "XedView") - (c-name "xed_view_cut_clipboard") - (return-type "none") -) - -(define-method copy_clipboard - (of-object "XedView") - (c-name "xed_view_copy_clipboard") - (return-type "none") -) - -(define-method paste_clipboard - (of-object "XedView") - (c-name "xed_view_paste_clipboard") - (return-type "none") -) - -(define-method delete_selection - (of-object "XedView") - (c-name "xed_view_delete_selection") - (return-type "none") -) - -(define-method select_all - (of-object "XedView") - (c-name "xed_view_select_all") - (return-type "none") -) - -(define-method scroll_to_cursor - (of-object "XedView") - (c-name "xed_view_scroll_to_cursor") - (return-type "none") -) - -(define-method set_font - (of-object "XedView") - (c-name "xed_view_set_font") - (return-type "none") - (parameters - '("gboolean" "def") - '("const-gchar*" "font_name") - ) -) - - - -;; From ../../xed/xed-window.h - -(define-function xed_window_get_type - (c-name "xed_window_get_type") - (return-type "GType") -) - -(define-method create_tab - (of-object "XedWindow") - (c-name "xed_window_create_tab") - (return-type "XedTab*") - (parameters - '("gboolean" "jump_to") - ) -) - -(define-method create_tab_from_uri - (of-object "XedWindow") - (c-name "xed_window_create_tab_from_uri") - (return-type "XedTab*") - (parameters - '("const-gchar*" "uri") - '("const-XedEncoding*" "encoding" (null-ok)) - '("gint" "line_pos") - '("gboolean" "create") - '("gboolean" "jump_to") - ) -) - -(define-method close_tab - (of-object "XedWindow") - (c-name "xed_window_close_tab") - (return-type "none") - (parameters - '("XedTab*" "tab") - ) -) - -(define-method close_tabs - (of-object "XedWindow") - (c-name "xed_window_close_tabs") - (return-type "none") - (parameters - '("const-GList*" "tabs") - ) -) - -(define-method close_all_tabs - (of-object "XedWindow") - (c-name "xed_window_close_all_tabs") - (return-type "none") -) - -(define-method get_active_tab - (of-object "XedWindow") - (c-name "xed_window_get_active_tab") - (return-type "XedTab*") -) - -(define-method set_active_tab - (of-object "XedWindow") - (c-name "xed_window_set_active_tab") - (return-type "none") - (parameters - '("XedTab*" "tab") - ) -) - -(define-method get_active_view - (of-object "XedWindow") - (c-name "xed_window_get_active_view") - (return-type "XedView*") -) - -(define-method get_active_document - (of-object "XedWindow") - (c-name "xed_window_get_active_document") - (return-type "XedDocument*") -) - -(define-method get_documents - (of-object "XedWindow") - (c-name "xed_window_get_documents") - (return-type "GList*") -) - -(define-method get_unsaved_documents - (of-object "XedWindow") - (c-name "xed_window_get_unsaved_documents") - (return-type "GList*") -) - -(define-method get_views - (of-object "XedWindow") - (c-name "xed_window_get_views") - (return-type "GList*") -) - -(define-method get_group - (of-object "XedWindow") - (c-name "xed_window_get_group") - (return-type "GtkWindowGroup*") -) - -(define-method get_side_panel - (of-object "XedWindow") - (c-name "xed_window_get_side_panel") - (return-type "XedPanel*") -) - -(define-method get_bottom_panel - (of-object "XedWindow") - (c-name "xed_window_get_bottom_panel") - (return-type "XedPanel*") -) - -(define-method get_statusbar - (of-object "XedWindow") - (c-name "xed_window_get_statusbar") - (return-type "GtkWidget*") -) - -(define-method get_ui_manager - (of-object "XedWindow") - (c-name "xed_window_get_ui_manager") - (return-type "GtkUIManager*") -) - -(define-method get_state - (of-object "XedWindow") - (c-name "xed_window_get_state") - (return-type "XedWindowState") -) - -(define-method get_message_bus - (of-object "XedWindow") - (c-name "xed_window_get_message_bus") - (return-type "XedMessageBus*") -) - -(define-method get_tab_from_uri - (of-object "XedWindow") - (c-name "xed_window_get_tab_from_uri") - (return-type "XedTab*") - (parameters - '("const-gchar*" "uri") - ) -) - -;; From xed-language-manager.h - -(define-function get_language_manager - (c-name "xed_get_language_manager") - (return-type "GtkSourceLanguageManager*") -) - -(define-function language_manager_list_languages_sorted - (c-name "xed_language_manager_list_languages_sorted") - (return-type "GSList*") - (parameters - '("GtkSourceLanguageManager*" "lm") - '("gboolean" "include_hidden") - ) -) - - -;; From xed-message-bus.h - -(define-function xed_message_bus_get_type - (c-name "xed_message_bus_get_type") - (return-type "GType") -) - -(define-function message_bus_get_default - (c-name "xed_message_bus_get_default") - (return-type "XedMessageBus*") -) - -(define-function xed_message_bus_new - (c-name "xed_message_bus_new") - (is-constructor-of "XedMessageBus") - (return-type "XedMessageBus*") -) - -(define-method lookup - (of-object "XedMessageBus") - (c-name "xed_message_bus_lookup") - (return-type "XedMessageType*") - (parameters - '("const-gchar*" "object_path") - '("const-gchar*" "method") - ) -) - -(define-method register - (of-object "XedMessageBus") - (c-name "xed_message_bus_register") - (return-type "XedMessageType*") - (parameters - '("const-gchar*" "object_path") - '("const-gchar*" "method") - '("guint" "num_optional") - ) - (varargs #t) -) - -(define-method unregister - (of-object "XedMessageBus") - (c-name "xed_message_bus_unregister") - (return-type "none") - (parameters - '("XedMessageType*" "message_type") - ) -) - -(define-method unregister_all - (of-object "XedMessageBus") - (c-name "xed_message_bus_unregister_all") - (return-type "none") - (parameters - '("const-gchar*" "object_path") - ) -) - -(define-method is_registered - (of-object "XedMessageBus") - (c-name "xed_message_bus_is_registered") - (return-type "gboolean") - (parameters - '("const-gchar*" "object_path") - '("const-gchar*" "method") - ) -) - -(define-method connect - (of-object "XedMessageBus") - (c-name "xed_message_bus_connect") - (return-type "guint") - (parameters - '("const-gchar*" "object_path") - '("const-gchar*" "method") - '("XedMessageCallback" "callback") - '("gpointer" "userdata") - '("GDestroyNotify" "destroy_data") - ) -) - -(define-method disconnect - (of-object "XedMessageBus") - (c-name "xed_message_bus_disconnect") - (return-type "none") - (parameters - '("guint" "id") - ) -) - -(define-method disconnect_by_func - (of-object "XedMessageBus") - (c-name "xed_message_bus_disconnect_by_func") - (return-type "none") - (parameters - '("const-gchar*" "object_path") - '("const-gchar*" "method") - '("XedMessageCallback" "callback") - '("gpointer" "userdata") - ) -) - -(define-method block - (of-object "XedMessageBus") - (c-name "xed_message_bus_block") - (return-type "none") - (parameters - '("guint" "id") - ) -) - -(define-method block_by_func - (of-object "XedMessageBus") - (c-name "xed_message_bus_block_by_func") - (return-type "none") - (parameters - '("const-gchar*" "object_path") - '("const-gchar*" "method") - '("XedMessageCallback" "callback") - '("gpointer" "userdata") - ) -) - -(define-method unblock - (of-object "XedMessageBus") - (c-name "xed_message_bus_unblock") - (return-type "none") - (parameters - '("guint" "id") - ) -) - -(define-method unblock_by_func - (of-object "XedMessageBus") - (c-name "xed_message_bus_unblock_by_func") - (return-type "none") - (parameters - '("const-gchar*" "object_path") - '("const-gchar*" "method") - '("XedMessageCallback" "callback") - '("gpointer" "userdata") - ) -) - -(define-method send_message - (of-object "XedMessageBus") - (c-name "xed_message_bus_send_message") - (return-type "none") - (parameters - '("XedMessage*" "message") - ) -) - -(define-method send_message_sync - (of-object "XedMessageBus") - (c-name "xed_message_bus_send_message_sync") - (return-type "none") - (parameters - '("XedMessage*" "message") - ) -) - -(define-method send - (of-object "XedMessageBus") - (c-name "xed_message_bus_send") - (return-type "none") - (parameters - '("const-gchar*" "object_path") - '("const-gchar*" "method") - ) - (varargs #t) -) - -(define-method send_sync - (of-object "XedMessageBus") - (c-name "xed_message_bus_send_sync") - (return-type "XedMessage*") - (parameters - '("const-gchar*" "object_path") - '("const-gchar*" "method") - ) - (varargs #t) -) - - -;; From xed-message-type.h - -(define-function xed_message_type_get_type - (c-name "xed_message_type_get_type") - (return-type "GType") -) - -(define-function xed_message_type_is_supported - (c-name "xed_message_type_is_supported") - (return-type "gboolean") - (parameters - '("GType" "type") - ) -) - -(define-function xed_message_type_identifier - (c-name "xed_message_type_identifier") - (return-type "gchar*") - (parameters - '("const-gchar*" "object_path") - '("const-gchar*" "method") - ) -) - -(define-function xed_message_type_new - (c-name "xed_message_type_new") - (is-constructor-of "XedMessageType") - (return-type "XedMessageType*") - (parameters - '("const-gchar*" "object_path") - '("const-gchar*" "method") - '("guint" "num_optional") - ) - (varargs #t) -) - -(define-function xed_message_type_new_valist - (c-name "xed_message_type_new_valist") - (return-type "XedMessageType*") - (parameters - '("const-gchar*" "object_path") - '("const-gchar*" "method") - '("guint" "num_optional") - '("va_list" "va_args") - ) -) - -(define-method ref - (of-object "XedMessageType") - (c-name "xed_message_type_ref") - (return-type "XedMessageType*") -) - -(define-method unref - (of-object "XedMessageType") - (c-name "xed_message_type_unref") - (return-type "none") -) - -(define-method instantiate_valist - (of-object "XedMessageType") - (c-name "xed_message_type_instantiate_valist") - (return-type "XedMessage*") - (parameters - '("va_list" "va_args") - ) -) - -(define-method instantiate - (of-object "XedMessageType") - (c-name "xed_message_type_instantiate") - (return-type "XedMessage*") - (parameters - ) - (varargs #t) -) - -(define-method get_object_path - (of-object "XedMessageType") - (c-name "xed_message_type_get_object_path") - (return-type "const-gchar*") -) - -(define-method get_method - (of-object "XedMessageType") - (c-name "xed_message_type_get_method") - (return-type "const-gchar*") -) - -(define-method lookup - (of-object "XedMessageType") - (c-name "xed_message_type_lookup") - (return-type "GType") - (parameters - '("const-gchar*" "key") - ) -) - -(define-method foreach - (of-object "XedMessageType") - (c-name "xed_message_type_foreach") - (return-type "none") - (parameters - '("XedMessageTypeForeach" "func") - '("gpointer" "user_data") - ) -) - - -;; From xed-message.h - -(define-function xed_message_get_type - (c-name "xed_message_get_type") - (return-type "GType") -) - -(define-method get - (of-object "XedMessage") - (c-name "xed_message_get") - (return-type "none") - (parameters - ) - (varargs #t) -) - -(define-method get_valist - (of-object "XedMessage") - (c-name "xed_message_get_valist") - (return-type "none") - (parameters - '("va_list" "var_args") - ) -) - -(define-method get_value - (of-object "XedMessage") - (c-name "xed_message_get_value") - (return-type "none") - (parameters - '("const-gchar*" "key") - '("GValue*" "value") - ) -) - -(define-method set - (of-object "XedMessage") - (c-name "xed_message_set") - (return-type "none") - (parameters - ) - (varargs #t) -) - -(define-method set_valist - (of-object "XedMessage") - (c-name "xed_message_set_valist") - (return-type "none") - (parameters - '("va_list" "var_args") - ) -) - -(define-method set_value - (of-object "XedMessage") - (c-name "xed_message_set_value") - (return-type "none") - (parameters - '("const-gchar*" "key") - '("GValue*" "value") - ) -) - -(define-method set_valuesv - (of-object "XedMessage") - (c-name "xed_message_set_valuesv") - (return-type "none") - (parameters - '("const-gchar**" "keys") - '("GValue*" "values") - '("gint" "n_values") - ) -) - -(define-method get_object_path - (of-object "XedMessage") - (c-name "xed_message_get_object_path") - (return-type "const-gchar*") -) - -(define-method get_method - (of-object "XedMessage") - (c-name "xed_message_get_method") - (return-type "const-gchar*") -) - -(define-method has_key - (of-object "XedMessage") - (c-name "xed_message_has_key") - (return-type "gboolean") - (parameters - '("const-gchar*" "key") - ) -) - -(define-method get_key_type - (of-object "XedMessage") - (c-name "xed_message_get_key_type") - (return-type "GType") - (parameters - '("const-gchar*" "key") - ) -) - -(define-method validate - (of-object "XedMessage") - (c-name "xed_message_validate") - (return-type "gboolean") -) - - -;; From ../../xed/xed-debug.h - -(define-function debug - (c-name "xed_debug") - (parameters - '("const-gchar*" "message") - ) - (return-type "none") -) - diff --git a/plugin-loaders/python/bindings/xed.override b/plugin-loaders/python/bindings/xed.override deleted file mode 100644 index 93f37e3..0000000 --- a/plugin-loaders/python/bindings/xed.override +++ /dev/null @@ -1,461 +0,0 @@ -%% -headers -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "xed-plugin-python.h" - -void pyxed_register_classes (PyObject *d); -void pyxed_add_constants (PyObject *module, const gchar *strip_prefix); - -static PyObject * -_helper_wrap_gobject_glist (const GList *list) -{ - PyObject *py_list; - const GList *tmp; - - if ((py_list = PyList_New(0)) == NULL) { - return NULL; - } - for (tmp = list; tmp != NULL; tmp = tmp->next) { - PyObject *py_obj = pygobject_new(G_OBJECT(tmp->data)); - - if (py_obj == NULL) { - Py_DECREF(py_list); - return NULL; - } - PyList_Append(py_list, py_obj); - Py_DECREF(py_obj); - } - return py_list; -} - -static PyObject * -_helper_wrap_gobject_gslist (const GSList *list) -{ - PyObject *py_list; - const GSList *tmp; - - if ((py_list = PyList_New(0)) == NULL) { - return NULL; - } - for (tmp = list; tmp != NULL; tmp = tmp->next) { - PyObject *py_obj = pygobject_new(G_OBJECT(tmp->data)); - - if (py_obj == NULL) { - Py_DECREF(py_list); - return NULL; - } - PyList_Append(py_list, py_obj); - Py_DECREF(py_obj); - } - return py_list; -} -%% -include - xedplugin.override - xedmessage.override -%% -modulename xed -%% -import gtk.Widget as PyGtkWidget_Type -import gobject.GObject as PyGObject_Type -import gtk.gdk.Screen as PyGdkScreen_Type -import gtk.VBox as PyGtkVBox_Type -import gtk.Window as PyGtkWindow_Type -import gtk.Image as PyGtkImage_Type -import gtk.Statusbar as PyGtkStatusbar_Type -import gtksourceview2.Buffer as PyGtkSourceBuffer_Type -import gtksourceview2.View as PyGtkSourceView_Type -import gtksourceview2.Language as PyGtkSourceLanguage_Type -import gtksourceview2.LanguageManager as PyGtkSourceLanguageManager_Type -%% -ignore-glob - *_get_type - xed_document_error_quark - xed_panel_add_item_with_stock_icon -%% -override xed_app_create_window kwargs -static PyObject * -_wrap_xed_app_create_window(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "screen", NULL}; - PyGObject *screen = NULL; - XedWindow *ret; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|O!", kwlist, - &PyGdkScreen_Type, &screen)) - return NULL; - - ret = xed_app_create_window(XED_APP(self->obj), - screen ? GDK_SCREEN(screen->obj) : NULL); - - /* pygobject_new handles NULL checking */ - return pygobject_new((GObject *)ret); -} -%% -override xed_app_get_windows -static PyObject * -_wrap_xed_app_get_windows(PyGObject *self) -{ - const GList *list; - PyObject *py_list; - - list = xed_app_get_windows (XED_APP (self->obj)); - - py_list = _helper_wrap_gobject_glist (list); - - return py_list; -} -%% -override xed_app_get_views -static PyObject * -_wrap_xed_app_get_views(PyGObject *self) -{ - GList *list; - PyObject *py_list; - - list = xed_app_get_views (XED_APP (self->obj)); - - py_list = _helper_wrap_gobject_glist (list); - - g_list_free (list); - - return py_list; -} -%% -override xed_app_get_documents -static PyObject * -_wrap_xed_app_get_documents(PyGObject *self) -{ - GList *list; - PyObject *py_list; - - list = xed_app_get_documents (XED_APP (self->obj)); - - py_list = _helper_wrap_gobject_glist (list); - - g_list_free (list); - - return py_list; -} -%% -override xed_window_get_documents -static PyObject * -_wrap_xed_window_get_documents(PyGObject *self) -{ - GList *list; - PyObject *py_list; - - list = xed_window_get_documents (XED_WINDOW (self->obj)); - - py_list = _helper_wrap_gobject_glist (list); - - g_list_free(list); - - return py_list; -} -%% -override xed_window_get_unsaved_documents -static PyObject * -_wrap_xed_window_get_unsaved_documents(PyGObject *self) -{ - GList *list; - PyObject *py_list; - - list = xed_window_get_unsaved_documents (XED_WINDOW (self->obj)); - - py_list = _helper_wrap_gobject_glist (list); - - g_list_free(list); - - return py_list; -} -%% -override xed_window_get_views -static PyObject * -_wrap_xed_window_get_views(PyGObject *self) -{ - GList *list; - PyObject *py_list; - - list = xed_window_get_views (XED_WINDOW (self->obj)); - - py_list = _helper_wrap_gobject_glist (list); - - g_list_free(list); - - return py_list; -} -%% -override xed_window_close_tabs kwargs -static PyObject * -_wrap_xed_window_close_tabs (PyGObject *self, - PyObject *args, - PyObject *kwargs) -{ - static char *kwlist[] = { "tabs", NULL }; - PyObject *list, *item; - GList *glist = NULL; - int len, i; - - if (!PyArg_ParseTupleAndKeywords (args, kwargs, - "O:XedWindow.close_tabs", kwlist, - &list)) - return NULL; - - if (!PySequence_Check (list)) - { - PyErr_SetString (PyExc_TypeError, - "first argument must be a sequence"); - return NULL; - } - - len = PySequence_Length (list); - - for (i = 0; i < len; i++) - { - item = PySequence_GetItem (list, i); - Py_DECREF(item); - - if (!pygobject_check (item, &PyXedTab_Type)) - { - PyErr_SetString (PyExc_TypeError, - "sequence item not a Gtkwidget object"); - g_list_free (glist); - return NULL; - } - - glist = g_list_append (glist, pygobject_get (item)); - } - - xed_window_close_tabs (XED_WINDOW (self->obj), glist); - - g_list_free (glist); - Py_INCREF (Py_None); - return Py_None; -} -%% -override xed_document_get_search_text -static PyObject * -_wrap_xed_document_get_search_text(PyGObject *self) -{ - PyObject *tuple, *string; - guint flags; - gchar *ret; - - ret = xed_document_get_search_text (XED_DOCUMENT (self->obj), &flags); - - tuple = PyTuple_New(2); - if (ret) { - string = PyString_FromString(ret); - PyTuple_SetItem(tuple, 0, string); - } else { - Py_INCREF(Py_None); - PyTuple_SetItem(tuple, 0, Py_None); - } - PyTuple_SetItem(tuple, 1, PyInt_FromLong(flags)); - - g_free(ret); - - return tuple; -} -%% -override xed_panel_add_item kwargs -static PyObject * -_wrap_xed_panel_add_item(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist1[] = { "item", "name", "image", NULL }; - static char *kwlist2[] = { "item", "name", "stock_id", NULL }; - PyGObject *item, *image; - char *name = NULL; - char *stock_id = NULL; - - if (PyArg_ParseTupleAndKeywords(args, kwargs, "O!sO!:XedPanel.add_item", kwlist1, &PyGtkWidget_Type, &item, &name, &PyGtkImage_Type, &image)) { - xed_panel_add_item(XED_PANEL(self->obj), GTK_WIDGET(item->obj), name, GTK_WIDGET(image->obj)); - Py_INCREF(Py_None); - return Py_None; - } - - PyErr_Clear(); - - if (PyArg_ParseTupleAndKeywords(args, kwargs, "O!ss:XedPanel.add_item", kwlist2, &PyGtkWidget_Type, &item, &name, &stock_id)) { - xed_panel_add_item_with_stock_icon(XED_PANEL(self->obj), GTK_WIDGET(item->obj), name, stock_id); - Py_INCREF(Py_None); - return Py_None; - } - - PyErr_Clear(); - PyErr_SetString(PyExc_TypeError, "the last arg should be either a gtk.Image or a stock_id string"); - return NULL; -} -%% -override xed_app_get_default_deprecated -/* deprecated wrappers */ -static PyObject * -_wrap_xed_app_get_default_deprecated(PyObject *self) -{ - if (PyErr_Warn(PyExc_DeprecationWarning, "use xed.app_get_default instead") < 0) - return NULL; - return _wrap_xed_app_get_default(self); -} -%% -override xed_encoding_get_from_charset_deprecated kwargs -static PyObject * -_wrap_xed_encoding_get_from_charset_deprecated(PyObject *self, PyObject *args, PyObject *kwargs) -{ - if (PyErr_Warn(PyExc_DeprecationWarning, "use xed.encoding_get_from_charset instead") < 0) - return NULL; - return _wrap_xed_encoding_get_from_charset(self, args, kwargs); -} -%% -override xed_encoding_get_from_index_deprecated kwargs -static PyObject * -_wrap_xed_encoding_get_from_index_deprecated(PyObject *self, PyObject *args, PyObject *kwargs) -{ - if (PyErr_Warn(PyExc_DeprecationWarning, "use xed.encoding_get_from_index instead") < 0) - return NULL; - return _wrap_xed_encoding_get_from_index(self, args, kwargs); -} -%% -override xed_encoding_get_utf8_deprecated -static PyObject * -_wrap_xed_encoding_get_utf8_deprecated(PyObject *self) -{ - if (PyErr_Warn(PyExc_DeprecationWarning, "use xed.encoding_get_utf8 instead") < 0) - return NULL; - return _wrap_xed_encoding_get_utf8(self); -} -%% -override xed_encoding_get_current_deprecated -static PyObject * -_wrap_xed_encoding_get_current_deprecated(PyObject *self) -{ - if (PyErr_Warn(PyExc_DeprecationWarning, "use xed.encoding_get_current instead") < 0) - return NULL; - return _wrap_xed_encoding_get_current(self); -} -%% -override xed_tab_get_from_document_deprecated kwargs -static PyObject * -_wrap_xed_tab_get_from_document_deprecated(PyObject *self, PyObject *args, PyObject *kwargs) -{ - if (PyErr_Warn(PyExc_DeprecationWarning, "use xed.tab_get_from_document instead") < 0) - return NULL; - return _wrap_xed_tab_get_from_document(self, args, kwargs); -} -%% -override xed_language_manager_list_languages_sorted kwargs -static PyObject * -_wrap_xed_language_manager_list_languages_sorted(PyObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "lm", "include_hidden", NULL }; - PyGObject *lm; - int include_hidden; - PyObject *py_list; - GSList *list; - - if (!PyArg_ParseTupleAndKeywords (args, kwargs, - "O!i:language_manager_list_languages_sorted", - kwlist, &PyGtkSourceLanguageManager_Type, &lm, - &include_hidden)) - return NULL; - - list = xed_language_manager_list_languages_sorted (GTK_SOURCE_LANGUAGE_MANAGER (lm->obj), - include_hidden); - - py_list = _helper_wrap_gobject_gslist (list); - - g_slist_free (list); - - return py_list; -} -%% -override xed_debug kwargs -static PyObject * -_wrap_xed_debug(PyObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "message", NULL }; - PyObject *traceback_module, *mdict, *func, *traceback, *tuple; - PyObject *filename, *lineno, *funcname; - char *message = NULL; - - if (g_getenv ("XED_DEBUG_PLUGINS") == NULL) - { - Py_INCREF (Py_None); - return Py_None; - } - - if (!PyArg_ParseTupleAndKeywords (args, kwargs, "|s", kwlist, &message)) - return NULL; - - traceback_module = PyImport_ImportModule ("traceback"); - if (traceback_module == NULL) - { - g_warning ("traceback module cannot be imported"); - Py_INCREF (Py_None); - return Py_None; - } - - mdict = PyModule_GetDict (traceback_module); - func = PyDict_GetItemString (mdict, "extract_stack"); - traceback = PyObject_CallFunction (func, "zi", NULL, 1); - tuple = PyList_GetItem (traceback, 0); - - if (tuple == NULL || !PyTuple_Check (tuple)) - { - g_warning ("traceback tuple is null!"); - } - else - { - filename = PyTuple_GetItem (tuple, 0); - lineno = PyTuple_GetItem (tuple, 1); - funcname = PyTuple_GetItem (tuple, 2); - - if (message == NULL) - xed_debug (XED_DEBUG_PLUGINS, - PyString_AsString (filename), - PyInt_AsLong (lineno), - PyString_AsString (funcname)); - else - xed_debug_message (XED_DEBUG_PLUGINS, - PyString_AsString (filename), - PyInt_AsLong (lineno), - PyString_AsString (funcname), - "%s", - message); - } - Py_DECREF (traceback); - Py_DECREF (traceback_module); - - Py_INCREF (Py_None); - return Py_None; -} -%% -override xed_statusbar_flash_message kwargs -static PyObject * -_wrap_xed_statusbar_flash_message(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "context_id", "message", NULL }; - int context_id; - char *message; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs,"is:XedStatusbar.flash_message", kwlist, &context_id, &message)) - return NULL; - - xed_statusbar_flash_message(XED_STATUSBAR(self->obj), context_id, "%s", message); - - Py_INCREF(Py_None); - return Py_None; -} -%% diff --git a/plugin-loaders/python/bindings/xedcommands.defs b/plugin-loaders/python/bindings/xedcommands.defs deleted file mode 100644 index 31aa7e3..0000000 --- a/plugin-loaders/python/bindings/xedcommands.defs +++ /dev/null @@ -1,45 +0,0 @@ -;; -*- scheme -*- -; object definitions ... -;; Enumerations and flags ... - - -;; From ../../xed/xed-commands.h - -(define-function load_uri - (c-name "xed_commands_load_uri") - (return-type "none") - (parameters - '("XedWindow*" "window") - '("const-gchar*" "uri") - '("const-XedEncoding*" "encoding") - '("gint" "line_pos") - ) -) - -(define-function load_uris - (c-name "xed_commands_load_uris") - (return-type "gint") - (parameters - '("XedWindow*" "window") - '("const-GSList*" "uris") - '("const-XedEncoding*" "encoding") - '("gint" "line_pos") - ) -) - -(define-function save_document - (c-name "xed_commands_save_document") - (return-type "none") - (parameters - '("XedWindow*" "window") - '("XedDocument*" "document") - ) -) - -(define-function save_all_documents - (c-name "xed_commands_save_all_documents") - (return-type "none") - (parameters - '("XedWindow*" "window") - ) -) diff --git a/plugin-loaders/python/bindings/xedcommands.override b/plugin-loaders/python/bindings/xedcommands.override deleted file mode 100644 index 603b0c5..0000000 --- a/plugin-loaders/python/bindings/xedcommands.override +++ /dev/null @@ -1,122 +0,0 @@ -%% -headers -#define NO_IMPORT_PYGOBJECT -#define NO_IMPORT_PYGTK -#include -#include - -#include "xed-commands.h" -#include "xed-window.h" - -void pyxedcommands_register_classes (PyObject *d); -void pyxedcommands_add_constants (PyObject *module, const gchar *strip_prefix); - -%% -modulename xed.commands -%% -import xed.Window as PyXedWindow_Type -import xed.Document as PyXedDocument_Type -%% -ignore-glob - _* -%% -override xed_commands_load_uri kwargs -static PyObject * -_wrap_xed_commands_load_uri (PyObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "window", "uri", "encoding", "line_pos", NULL }; - PyGObject *window; - char *uri; - int line_pos = 0; - PyObject *py_encoding = NULL; - XedEncoding *encoding = NULL; - - if (!PyArg_ParseTupleAndKeywords (args, kwargs, "O!s|Oi:load_uri", - kwlist, &PyXedWindow_Type, - &window, &uri, &py_encoding, - &line_pos)) - return NULL; - - if (py_encoding != NULL && py_encoding != Py_None) - { - if (pyg_boxed_check (py_encoding, XED_TYPE_ENCODING)) - encoding = pyg_boxed_get (py_encoding, XedEncoding); - else - { - PyErr_SetString (PyExc_TypeError, - "encoding should be a XedEncoding"); - return NULL; - } - } - - xed_commands_load_uri (XED_WINDOW (window->obj), uri, encoding, - line_pos); - Py_INCREF (Py_None); - return Py_None; -} -%% -override xed_commands_load_uris kwargs -static PyObject * -_wrap_xed_commands_load_uris (PyObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "window", "uris", "encoding", "line_pos", NULL }; - PyGObject *window; - GSList *uris = NULL; - int line_pos = 0; - PyObject *py_encoding = NULL; - PyObject *list; - PyObject *item; - XedEncoding *encoding = NULL; - int len; - int i; - - if (!PyArg_ParseTupleAndKeywords (args, kwargs, "O!O|Oi:load_uri", - kwlist, &PyXedWindow_Type, - &window, &list, &py_encoding, - &line_pos)) - return NULL; - - if (py_encoding != NULL && py_encoding != Py_None) - { - if (pyg_boxed_check (py_encoding, XED_TYPE_ENCODING)) - encoding = pyg_boxed_get (py_encoding, XedEncoding); - else { - PyErr_SetString (PyExc_TypeError, - "encoding should be a XedEncoding"); - return NULL; - } - } - - if (!PySequence_Check (list)) - { - PyErr_SetString (PyExc_TypeError, - "second argument must be a sequence"); - return NULL; - } - - len = PySequence_Length (list); - - for (i = 0; i < len; i++) - { - item = PySequence_GetItem (list, i); - Py_DECREF (item); - - if (!PyString_Check (item)) - { - PyErr_SetString (PyExc_TypeError, - "sequence item not a string"); - g_slist_free (uris); - return NULL; - } - - uris = g_slist_prepend (uris, PyString_AsString (item)); - } - - uris = g_slist_reverse (uris); - xed_commands_load_uris (XED_WINDOW (window->obj), uris, - encoding, line_pos); - g_slist_free (uris); - - Py_INCREF (Py_None); - return Py_None; -} diff --git a/plugin-loaders/python/bindings/xedmessage.override b/plugin-loaders/python/bindings/xedmessage.override deleted file mode 100644 index c1af552..0000000 --- a/plugin-loaders/python/bindings/xedmessage.override +++ /dev/null @@ -1,556 +0,0 @@ -%% -headers - -#include -#include - -static GType -_helper_wrap_get_gtype_from_pytype (PyObject *pytype) -{ - PyTypeObject *type = (PyTypeObject *)pytype; - - if (type == &PyList_Type || type == &PyTuple_Type) - return G_TYPE_STRV; - - return pyg_type_from_object (pytype); -} - -static gchar * -_helper_wrap_get_string (PyObject *obj) -{ - PyObject *str; - gchar *result; - - str = PyObject_Str (obj); - - if (!str) - return NULL; - - result = g_strdup (PyString_AsString (str)); - Py_DECREF (str); - - return result; -} - -static int -_helper_wrap_list_to_gvalue (GValue *gvalue, PyObject *pyvalue) -{ - int num; - gchar **lst; - gint i; - - num = PySequence_Size (pyvalue); - lst = g_new0 (gchar *, num + 1); - - for (i = 0; i < num; i++) - { - lst[i] = _helper_wrap_get_string (PySequence_GetItem (pyvalue, i)); - - if (lst[i] == NULL) - { - g_strfreev (lst); - return 1; - } - } - - g_value_set_boxed (gvalue, lst); - g_strfreev (lst); - - return 0; -} - -static int -_helper_wrap_get_gvalue_from_pyobject (GValue *gvalue, PyObject *pyvalue) -{ - if (pyvalue->ob_type == &PyList_Type || pyvalue->ob_type == &PyTuple_Type) - return _helper_wrap_list_to_gvalue (gvalue, pyvalue); - - return pyg_value_from_pyobject(gvalue, pyvalue); -} - -static int -_helper_wrap_message_set_value(XedMessage *message, PyObject *pykey, PyObject *pyvalue) -{ - gchar *key; - GType gtype; - GValue value = {0,}; - - key = _helper_wrap_get_string(pykey); - - if (key == NULL) - return 0; - - gtype = xed_message_get_key_type(message, key); - - if (gtype == 0) { - PyErr_SetString(PyExc_TypeError, "invalid key"); - g_free (key); - return 0; - } - - g_value_init(&value, gtype); - - if (_helper_wrap_get_gvalue_from_pyobject (&value, pyvalue)) { - PyErr_SetString(PyExc_TypeError, - "value is of the wrong type for this key"); - g_free (key); - return 0; - } - - xed_message_set_value(message, key, &value); - g_value_unset(&value); - g_free (key); - - return 1; -} - -typedef void (*ParsePairFunc)(PyObject *key, PyObject *value, gpointer user_data); - -static void -_helper_parse_pairs_dict (PyObject *dict, ParsePairFunc func, gpointer user_data) -{ - if (!dict) - return; - - PyObject *key, *value; - Py_ssize_t i = 0; - - while (PyDict_Next(dict, &i, &key, &value)) - { - func(key, value, user_data); - } -} - -static void -_helper_parse_pairs(PyObject *args, PyObject *kwargs, ParsePairFunc func, gpointer user_data) -{ - guint len; - guint i; - - len = PyTuple_Size(args); - - for (i = 0; i < len; ++i) - { - PyObject *d = PyTuple_GetItem(args, i); - - if (PyDict_Check(d)) - _helper_parse_pairs_dict(d, func, user_data); - } - - _helper_parse_pairs_dict(kwargs, func, user_data); -} - -static void -_helper_message_set(PyObject *key, PyObject *value, XedMessage *message) -{ - _helper_wrap_message_set_value(message, key, value); -} - -static void -_helper_message_set_values(XedMessage *message, PyObject *args, PyObject *kwargs) -{ - _helper_parse_pairs(args, kwargs, (ParsePairFunc)_helper_message_set, message); -} - -static XedMessage * -_helper_wrap_create_message(XedMessageBus *bus, PyObject *args, PyObject *kwargs) -{ - PyObject *pypath, *pymethod, *pydict; - - if (!PyArg_ParseTuple(args, "OO|O:XedMessage.create", &pypath, &pymethod, &pydict)) - return NULL; - - gchar *object_path = _helper_wrap_get_string(pypath); - gchar *method = _helper_wrap_get_string(pymethod); - - XedMessageType *message_type = xed_message_bus_lookup (bus, object_path, method); - XedMessage *message; - - if (message_type) - { - message = xed_message_type_instantiate(message_type, NULL); - _helper_message_set_values(message, args, kwargs); - } - else - { - PyErr_SetString(PyExc_StandardError, "Message type does not exist"); - message = NULL; - } - - g_free(object_path); - g_free(method); - - return message; -} - -typedef struct { - PyObject *func; - PyObject *data; -} PyXedCustomNotify; - -static void -pyxed_custom_destroy_notify(gpointer user_data) -{ - PyXedCustomNotify *cunote = user_data; - PyGILState_STATE state; - - g_return_if_fail(user_data); - state = pyg_gil_state_ensure(); - Py_XDECREF(cunote->func); - Py_XDECREF(cunote->data); - pyg_gil_state_release(state); - - g_free(cunote); -} -%% -ignore-glob - *_get_type - xed_message_type_foreach - xed_message_type_instantiate_valist - xed_message_type_new_valist - xed_message_get_valist - xed_message_set_valist - xed_message_set_valuesv - xed_message_bus_disconnect_by_func - xed_message_bus_block_by_func - xed_message_bus_unblock_by_func -%% -override xed_message_type_new kwargs - -typedef struct -{ - XedMessageType *message_type; - PyObject *optional; -} MessageTypeSetInfo; - -static void -_message_type_set(PyObject *key, PyObject *value, MessageTypeSetInfo *info) -{ - GType gtype; - - gchar *k = _helper_wrap_get_string(key); - - if (!k) - return; - - gtype = _helper_wrap_get_gtype_from_pytype(value); - - gboolean optional = info->optional && PySequence_Contains(info->optional, key); - - xed_message_type_set(info->message_type, optional, k, gtype, NULL); - g_free(k); -} - -static int -_wrap_xed_message_type_new(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - PyObject *pypath, *pymethod, *optional = NULL, *pydict; - - if (!PyArg_ParseTuple(args, "OO|OO:XedMessageType.new", &pypath, &pymethod, &optional, &pydict)) - return -1; - - XedMessageType *message_type = XED_MESSAGE_TYPE(g_object_new(pyg_type_from_object((PyObject *) self), NULL)); - - MessageTypeSetInfo info = {message_type, optional && PySequence_Check(optional) ? optional : NULL}; - _helper_parse_pairs (args, kwargs, (ParsePairFunc)_message_type_set, &info); - - self->obj = (GObject *)message_type; - pygobject_register_wrapper((PyObject *) self); - - return 0; -} -%% -override xed_message_type_instantiate kwargs -static PyObject * -_wrap_xed_message_type_instantiate(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - XedMessageType *message_type = XED_MESSAGE_TYPE (self->obj); - XedMessage *message = xed_message_type_instantiate(message_type, NULL); - - _helper_message_set_values(message, args, kwargs); - - return pygobject_new((GObject *)message); -} -%% -override xed_message_get args -static PyObject * -_wrap_xed_message_get(PyGObject *self, PyObject *args) -{ - guint len, i; - PyObject *ret; - - len = PyTuple_Size(args); - - ret = PyTuple_New(len); - - for (i = 0; i < len; i++) { - GValue value = { 0, }; - PyObject *py_key = PyTuple_GetItem(args, i); - gchar *key = _helper_wrap_get_string(py_key); - - if (!key) { - PyErr_SetString(PyExc_TypeError, "keys must be strings"); - Py_DECREF(ret); - return NULL; - } - - xed_message_get_value (XED_MESSAGE (self->obj), key, &value); - g_free (key); - - PyTuple_SetItem(ret, i, pyg_value_as_pyobject(&value, TRUE)); - g_value_unset(&value); - } - - return ret; -} -%% -override xed_message_get_value kwargs -static PyObject * -_wrap_xed_message_get_value(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "key", NULL }; - const gchar *key; - PyObject *ret; - GValue value = { 0, }; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:XedMessage.get_value", kwlist, &key)) - return NULL; - - xed_message_get_value(XED_MESSAGE(self->obj), key, &value); - ret = pyg_value_as_pyobject(&value, TRUE); - g_value_unset(&value); - - return ret; -} -%% -override xed_message_set_value kwargs -static PyObject * -_wrap_xed_message_set_value(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "key", "value", NULL }; - PyObject *pykey, *pyvalue; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO:XedMessage.set_value", kwlist, &pykey, &pyvalue)) - return NULL; - - if (!_helper_wrap_message_set_value(XED_MESSAGE(self->obj), pykey, pyvalue)) - return NULL; - - Py_INCREF(Py_None); - return Py_None; -} -%% -override xed_message_set kwargs -static PyObject * -_wrap_xed_message_set (PyGObject *self, PyObject *args, PyObject *kwargs) { - _helper_message_set_values(XED_MESSAGE(self->obj), args, kwargs); - - Py_INCREF(Py_None); - return Py_None; -} -%% -override xed_message_bus_new -static int -_wrap_xed_message_bus_new(PyGObject *self) -{ - pygobject_construct (self, NULL); - - if (!self->obj) { - PyErr_SetString (PyExc_RuntimeError, "could not create xed.MessageBus object"); - return -1; - } - - return 0; -} -%% -new-constructor XED_TYPE_MESSAGE_BUS -%% -override xed_message_bus_register kwargs -static PyObject * -_wrap_xed_message_bus_register(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - PyObject *pypath, *pymethod, *optional = NULL, *pydict; - XedMessageBus *bus = XED_MESSAGE_BUS(self->obj); - - if (!PyArg_ParseTuple(args, "OO|OO:XedMessageBus.register", &pypath, &pymethod, &optional, &pydict)) - return NULL; - - gchar *object_path = _helper_wrap_get_string(pypath); - gchar *method = _helper_wrap_get_string(pymethod); - - XedMessageType *message_type = xed_message_bus_register(bus, object_path, method, 0, NULL); - - g_free(object_path); - g_free(method); - - if (!message_type) - { - PyErr_SetString(PyExc_StandardError, "Message type already exists"); - return NULL; - } - - MessageTypeSetInfo info = {message_type, optional && PySequence_Check(optional) ? optional : NULL}; - _helper_parse_pairs (args, kwargs, (ParsePairFunc)_message_type_set, &info); - - return pyg_boxed_new(XED_TYPE_MESSAGE_TYPE, message_type, TRUE, TRUE); -} -%% -override xed_message_bus_connect kwargs -static void -pyxed_message_bus_connect_cb(XedMessageBus *bus, XedMessage *message, gpointer data) -{ - PyGILState_STATE state; - PyXedCustomNotify *cunote = data; - PyObject *pybus, *pymessage, *retobj; - - g_assert(cunote->func); - - state = pyg_gil_state_ensure(); - - pybus = pygobject_new((GObject *)bus); - pymessage = pygobject_new((GObject *)message); - - if (cunote->data) { - retobj = PyEval_CallFunction(cunote->func, "(NNO)", pybus, pymessage, cunote->data); - } else { - retobj = PyEval_CallFunction(cunote->func, "(NN)", pybus, pymessage); - } - - if (PyErr_Occurred()) { - PyErr_Print(); - } - - Py_XDECREF(retobj); - - pyg_gil_state_release(state); -} - -static PyObject * -_wrap_xed_message_bus_connect(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "domain", "name", "func", "data", NULL }; - PyObject *pyfunc, *pyarg = NULL; - const gchar *domain; - const gchar *name; - PyXedCustomNotify *cunote; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "ssO|O:XedMessageBus.connect", - kwlist, &domain, &name, &pyfunc, &pyarg)) - return NULL; - - if (!PyCallable_Check(pyfunc)) { - PyErr_SetString(PyExc_TypeError, "func must be a callable object"); - return NULL; - } - cunote = g_new(PyXedCustomNotify, 1); - Py_INCREF(pyfunc); - cunote->func = pyfunc; - Py_XINCREF(pyarg); - cunote->data = pyarg; - - guint id = xed_message_bus_connect(XED_MESSAGE_BUS(self->obj), - domain, - name, - pyxed_message_bus_connect_cb, - (gpointer)cunote, - pyxed_custom_destroy_notify); - return PyLong_FromUnsignedLong(id); -} -%% -override xed_message_bus_send kwargs -static PyObject * -_wrap_xed_message_bus_send(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - /* create a new message object */ - XedMessage *message; - XedMessageBus *bus = XED_MESSAGE_BUS(self->obj); - message = _helper_wrap_create_message(bus, args, kwargs); - - if (!message) - return NULL; - - xed_message_bus_send_message(bus, message); - g_object_unref (message); - - Py_INCREF(Py_None); - return Py_None; -} -%% -override xed_message_bus_send_sync kwargs -static PyObject * -_wrap_xed_message_bus_send_sync(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - /* create a new message object */ - XedMessage *message; - XedMessageBus *bus = XED_MESSAGE_BUS(self->obj); - - message = _helper_wrap_create_message(bus, args, kwargs); - - if (!message) - return NULL; - - xed_message_bus_send_message_sync(bus, message); - return pygobject_new((GObject *)message); -} -%% -override-slot XedMessage.tp_getattro -static PyObject * -_wrap_xed_message_tp_getattro(PyObject *self, PyObject *attrname) -{ - XedMessage *message = XED_MESSAGE(((PyGObject *)self)->obj); - XedMessageType *type; - - gchar *name = _helper_wrap_get_string (attrname); - gboolean exists; - gboolean intype; - PyObject *ret; - - if (name == NULL) - { - PyErr_SetString(PyExc_TypeError, "attr name somehow not a string"); - return NULL; - } - - g_object_get (message, "type", &type, NULL); - intype = xed_message_type_lookup (type, name) != G_TYPE_INVALID; - xed_message_type_unref (type); - - exists = xed_message_has_key (message, name); - - if (!intype) - { - ret = PyObject_GenericGetAttr(self, attrname); - } - else if (exists) - { - GValue value = { 0, }; - xed_message_get_value (message, name, &value); - ret = pyg_value_as_pyobject(&value, TRUE); - g_value_unset (&value); - } - else - { - Py_INCREF(Py_None); - ret = Py_None; - } - - g_free (name); - return ret; -} -%% -override-slot XedMessage.tp_setattro -static int -_wrap_xed_message_tp_setattro(PyObject *self, PyObject *attrname, PyObject *value) -{ - XedMessage *message = XED_MESSAGE(((PyGObject *)self)->obj); - - if (!_helper_wrap_message_set_value(message, attrname, value)) - { - return PyObject_GenericSetAttr(self, attrname, value); - } - else - { - return 1; - } -} diff --git a/plugin-loaders/python/bindings/xedplugin.override b/plugin-loaders/python/bindings/xedplugin.override deleted file mode 100644 index 05d549a..0000000 --- a/plugin-loaders/python/bindings/xedplugin.override +++ /dev/null @@ -1,193 +0,0 @@ -%% -headers -#include -#include -%% -override xed_plugin_activate kwargs -static PyObject * -_wrap_xed_plugin_activate(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - gpointer klass, klass2; - static char *kwlist[] = { "window", NULL }; - PyGObject *window; - PyObject *cls = (PyObject *)(((PyObject *)self)->ob_type); - - if (!PyArg_ParseTupleAndKeywords (args, - kwargs, - "O!:XedPlugin.activate", - kwlist, - &PyXedWindow_Type, - &window)) - return NULL; - - klass = g_type_class_ref (pyg_type_from_object (cls)); - - if (XED_IS_PLUGIN_PYTHON_CLASS (klass)) - { - klass2 = g_type_class_peek_parent (klass); - g_type_class_unref (klass); - klass = g_type_class_ref (G_TYPE_FROM_CLASS (klass2)); - } - - if (XED_PLUGIN_CLASS (klass)->activate) - XED_PLUGIN_CLASS (klass)->activate (XED_PLUGIN (self->obj), - XED_WINDOW (window->obj)); - else { - PyErr_SetString (PyExc_NotImplementedError, - "virtual method XedPlugin.activate not implemented"); - g_type_class_unref (klass); - return NULL; - } - - g_type_class_unref (klass); - Py_INCREF(Py_None); - return Py_None; -} - -%% -override xed_plugin_deactivate kwargs -static PyObject * -_wrap_xed_plugin_deactivate(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - gpointer klass, klass2; - static char *kwlist[] = {"window", NULL}; - PyGObject *window; - PyObject *cls = (PyObject *)(((PyObject *)self)->ob_type); - - if (!PyArg_ParseTupleAndKeywords (args, - kwargs, - "O!:XedPlugin.deactivate", - kwlist, - &PyXedWindow_Type, - &window)) - return NULL; - - klass = g_type_class_ref (pyg_type_from_object (cls)); - - if (XED_IS_PLUGIN_PYTHON_CLASS (klass)) - { - klass2 = g_type_class_peek_parent (klass); - g_type_class_unref (klass); - klass = g_type_class_ref (G_TYPE_FROM_CLASS (klass2)); - } - - if (XED_PLUGIN_CLASS (klass)->deactivate) - XED_PLUGIN_CLASS (klass)->deactivate (XED_PLUGIN (self->obj), - XED_WINDOW (window->obj)); - else { - PyErr_SetString (PyExc_NotImplementedError, - "virtual method XedPlugin.deactivate not implemented"); - g_type_class_unref (klass); - return NULL; - } - - g_type_class_unref (klass); - Py_INCREF(Py_None); - return Py_None; -} - -%% -override xed_plugin_update_ui kwargs -static PyObject * -_wrap_xed_plugin_update_ui (PyGObject *self, PyObject *args, PyObject *kwargs) -{ - gpointer klass, klass2; - static char *kwlist[] = {"window", NULL}; - PyGObject *window; - PyObject *cls = (PyObject *)(((PyObject *)self)->ob_type); - - if (!PyArg_ParseTupleAndKeywords (args, - kwargs, - "O!:XedPlugin.update_ui", - kwlist, - &PyXedWindow_Type, - &window)) - return NULL; - - klass = g_type_class_ref (pyg_type_from_object (cls)); - - if (XED_IS_PLUGIN_PYTHON_CLASS (klass)) - { - klass2 = g_type_class_peek_parent (klass); - g_type_class_unref (klass); - klass = g_type_class_ref (G_TYPE_FROM_CLASS (klass2)); - } - - if (XED_PLUGIN_CLASS (klass)->update_ui) - XED_PLUGIN_CLASS (klass)->update_ui (XED_PLUGIN (self->obj), - XED_WINDOW (window->obj)); - else { - PyErr_SetString (PyExc_NotImplementedError, - "virtual method XedPlugin.update_ui not implemented"); - g_type_class_unref (klass); - return NULL; - } - - g_type_class_unref (klass); - Py_INCREF(Py_None); - return Py_None; -} - -%% -override xed_plugin_is_configurable -static PyObject * -_wrap_xed_plugin_is_configurable (PyGObject *self) -{ - int ret; - gpointer klass, klass2; - PyObject *cls = (PyObject *)(((PyObject *)self)->ob_type); - - klass = g_type_class_ref (pyg_type_from_object (cls)); - - if (XED_IS_PLUGIN_PYTHON_CLASS (klass)) - { - klass2 = g_type_class_peek_parent (klass); - g_type_class_unref (klass); - klass = g_type_class_ref (G_TYPE_FROM_CLASS (klass2)); - } - - if (XED_PLUGIN_CLASS (klass)->is_configurable) - ret = XED_PLUGIN_CLASS (klass)->is_configurable (XED_PLUGIN (self->obj)); - else { - PyErr_SetString (PyExc_NotImplementedError, - "virtual method XedPlugin.is_configurable not implemented"); - g_type_class_unref (klass); - return NULL; - } - - g_type_class_unref (klass); - return PyBool_FromLong (ret); -} - -%% -override xed_plugin_configure_dialog -static PyObject * -_wrap_xed_plugin_create_configure_dialog (PyGObject *self) -{ - GtkWidget *ret; - gpointer klass, klass2; - PyObject *cls = (PyObject *)(((PyObject *)self)->ob_type); - - klass = g_type_class_ref(pyg_type_from_object (cls)); - - if (XED_IS_PLUGIN_PYTHON_CLASS (klass)) - { - klass2 = g_type_class_peek_parent (klass); - g_type_class_unref (klass); - klass = g_type_class_ref (G_TYPE_FROM_CLASS (klass2)); - } - - if (XED_PLUGIN_CLASS (klass)->create_configure_dialog) - ret = XED_PLUGIN_CLASS (klass)->create_configure_dialog (XED_PLUGIN (self->obj)); - else { - PyErr_SetString (PyExc_NotImplementedError, - "virtual method XedPlugin.create_configure_dialog not implemented"); - g_type_class_unref (klass); - return NULL; - } - - g_type_class_unref (klass); - - /* pygobject_new handles NULL checking */ - return pygobject_new ((GObject *)ret); -} diff --git a/plugin-loaders/python/bindings/xedutils.defs b/plugin-loaders/python/bindings/xedutils.defs deleted file mode 100644 index ecb38db..0000000 --- a/plugin-loaders/python/bindings/xedutils.defs +++ /dev/null @@ -1,67 +0,0 @@ -;; -*- scheme -*- - -;; From ../../xed/xed-utils.h - -(define-function uri_has_writable_scheme - (c-name "xed_utils_uri_has_writable_scheme") - (return-type "gboolean") - (parameters - '("const-gchar*" "uri") - ) -) - -(define-function uri_has_file_scheme - (c-name "xed_utils_uri_has_file_scheme") - (return-type "gboolean") - (parameters - '("const-gchar*" "uri") - ) -) - -(define-function uri_exists - (c-name "xed_utils_uri_exists") - (return-type "gboolean") - (parameters - '("const-gchar*" "text_uri") - ) -) - -(define-function uri_is_valid - (c-name "xed_utils_is_valid_uri") - (return-type "gboolean") - (parameters - '("const-gchar*" "uri") - ) -) - -(define-function uri_get_dirname - (c-name "xed_utils_uri_get_dirname") - (return-type "gchar*") - (parameters - '("const-char*" "uri") - ) -) - -(define-function menu_position_under_widget - (c-name "xed_utils_menu_position_under_widget") - (return-type "none") - (parameters - '("GtkMenu*" "menu") - '("gint*" "x") - '("gint*" "y") - '("gboolean*" "push_in") - '("gpointer" "user_data") - ) -) - -(define-function menu_position_under_tree_view - (c-name "xed_utils_menu_position_under_tree_view") - (return-type "none") - (parameters - '("GtkMenu*" "menu") - '("gint*" "x") - '("gint*" "y") - '("gboolean*" "push_in") - '("gpointer" "user_data") - ) -) diff --git a/plugin-loaders/python/bindings/xedutils.override b/plugin-loaders/python/bindings/xedutils.override deleted file mode 100644 index f177494..0000000 --- a/plugin-loaders/python/bindings/xedutils.override +++ /dev/null @@ -1,85 +0,0 @@ -%% -headers -#define NO_IMPORT_PYGOBJECT -#define NO_IMPORT_PYGTK -#include -#include - -#include "xed-utils.h" - -void pyxedutils_register_classes (PyObject *d); -void pyxedutils_add_constants (PyObject *module, const gchar *strip_prefix); - -%% -modulename xed.utils -%% -import gtk.Widget as PyGtkWidget_Type -import gtk.TreeView as PyGtkTreeView_Type -import gtk.Menu as PyGtkMenu_Type -%% -ignore-glob - _* -%% -override xed_utils_menu_position_under_widget kwargs -static PyObject * -_wrap_xed_utils_menu_position_under_widget (PyObject *self, - PyObject *args, - PyObject *kwargs) -{ - static char *kwlist[] = { "menu", "widget", NULL }; - PyObject *py_menu, *py_widget; - GtkMenu *menu; - GtkWidget *widget; - gint x, y; - gboolean push_in; - PyObject *tuple; - - if (!PyArg_ParseTupleAndKeywords (args, kwargs, - "O!O!", kwlist, - &PyGtkMenu_Type, &py_menu, - &PyGtkWidget_Type, &py_widget)) - return NULL; - - menu = GTK_MENU (pygobject_get (py_menu)); - widget = GTK_WIDGET (pygobject_get (py_widget)); - - xed_utils_menu_position_under_widget (menu, &x, &y, &push_in, widget); - - tuple = PyTuple_New (3); - PyTuple_SetItem (tuple, 0, PyInt_FromLong (x)); - PyTuple_SetItem (tuple, 1, PyInt_FromLong (y)); - PyTuple_SetItem (tuple, 2, PyBool_FromLong (push_in)); - return tuple; -} -%% -override xed_utils_menu_position_under_tree_view kwargs -static PyObject * -_wrap_xed_utils_menu_position_under_tree_view (PyObject *self, - PyObject *args, - PyObject *kwargs) -{ - static char *kwlist[] = { "menu", "tree_view", NULL }; - PyObject *py_menu, *py_view; - GtkMenu *menu; - GtkTreeView *view; - gint x, y; - gboolean push_in; - PyObject *tuple; - - if (!PyArg_ParseTupleAndKeywords (args, kwargs, - "O!O!", kwlist, - &PyGtkMenu_Type, &py_menu, - &PyGtkTreeView_Type, &py_view)) - return NULL; - - menu = GTK_MENU (pygobject_get (py_menu)); - view = GTK_TREE_VIEW (pygobject_get (py_view)); - - xed_utils_menu_position_under_widget (menu, &x, &y, &push_in, view); - - tuple = PyTuple_New (3); - PyTuple_SetItem (tuple, 0, PyInt_FromLong (x)); - PyTuple_SetItem (tuple, 1, PyInt_FromLong (y)); - PyTuple_SetItem (tuple, 2, PyBool_FromLong (push_in)); - return tuple; -} diff --git a/plugin-loaders/python/xed-plugin-loader-python.c b/plugin-loaders/python/xed-plugin-loader-python.c deleted file mode 100644 index 3b14715..0000000 --- a/plugin-loaders/python/xed-plugin-loader-python.c +++ /dev/null @@ -1,719 +0,0 @@ -/* - * xed-plugin-loader-python.c - * This file is part of xed - * - * Copyright (C) 2008 - Jesse van den Kieboom - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "xed-plugin-loader-python.h" -#include "xed-plugin-python.h" -#include - -#define NO_IMPORT_PYGOBJECT -#define NO_IMPORT_PYGTK - -#include -#include -#include -#include -#include "config.h" - -#if PY_VERSION_HEX < 0x02050000 -typedef int Py_ssize_t; -#define PY_SSIZE_T_MAX INT_MAX -#define PY_SSIZE_T_MIN INT_MIN -#endif - -#define XED_PLUGIN_LOADER_PYTHON_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), XED_TYPE_PLUGIN_LOADER_PYTHON, XedPluginLoaderPythonPrivate)) - -struct _XedPluginLoaderPythonPrivate -{ - GHashTable *loaded_plugins; - guint idle_gc; - gboolean init_failed; -}; - -typedef struct -{ - PyObject *type; - PyObject *instance; - gchar *path; -} PythonInfo; - -static void xed_plugin_loader_iface_init (gpointer g_iface, gpointer iface_data); - -/* Exported by pyxed module */ -void pyxed_register_classes (PyObject *d); -void pyxed_add_constants (PyObject *module, const gchar *strip_prefix); -extern PyMethodDef pyxed_functions[]; - -/* Exported by pyxedutils module */ -void pyxedutils_register_classes (PyObject *d); -extern PyMethodDef pyxedutils_functions[]; - -/* Exported by pyxedcommands module */ -void pyxedcommands_register_classes (PyObject *d); -extern PyMethodDef pyxedcommands_functions[]; - -/* We retreive this to check for correct class hierarchy */ -static PyTypeObject *PyXedPlugin_Type; - -XED_PLUGIN_LOADER_REGISTER_TYPE (XedPluginLoaderPython, xed_plugin_loader_python, G_TYPE_OBJECT, xed_plugin_loader_iface_init); - - -static PyObject * -find_python_plugin_type (XedPluginInfo *info, - PyObject *pymodule) -{ - PyObject *locals, *key, *value; - Py_ssize_t pos = 0; - - locals = PyModule_GetDict (pymodule); - - while (PyDict_Next (locals, &pos, &key, &value)) - { - if (!PyType_Check(value)) - continue; - - if (PyObject_IsSubclass (value, (PyObject*) PyXedPlugin_Type)) - return value; - } - - g_warning ("No XedPlugin derivative found in Python plugin '%s'", - xed_plugin_info_get_name (info)); - return NULL; -} - -static XedPlugin * -new_plugin_from_info (XedPluginLoaderPython *loader, - XedPluginInfo *info) -{ - PythonInfo *pyinfo; - PyTypeObject *pytype; - PyObject *pyobject; - PyGObject *pygobject; - XedPlugin *instance; - PyObject *emptyarg; - - pyinfo = (PythonInfo *)g_hash_table_lookup (loader->priv->loaded_plugins, info); - - if (pyinfo == NULL) - return NULL; - - pytype = (PyTypeObject *)pyinfo->type; - - if (pytype->tp_new == NULL) - return NULL; - - emptyarg = PyTuple_New(0); - pyobject = pytype->tp_new (pytype, emptyarg, NULL); - Py_DECREF (emptyarg); - - if (pyobject == NULL) - { - g_error ("Could not create instance for %s.", xed_plugin_info_get_name (info)); - return NULL; - } - - pygobject = (PyGObject *)pyobject; - - if (pygobject->obj != NULL) - { - Py_DECREF (pyobject); - g_error ("Could not create instance for %s (GObject already initialized).", xed_plugin_info_get_name (info)); - return NULL; - } - - pygobject_construct (pygobject, - "install-dir", pyinfo->path, - "data-dir-name", xed_plugin_info_get_module_name (info), - NULL); - - if (pygobject->obj == NULL) - { - g_error ("Could not create instance for %s (GObject not constructed).", xed_plugin_info_get_name (info)); - Py_DECREF (pyobject); - - return NULL; - } - - /* now call tp_init manually */ - if (PyType_IsSubtype (pyobject->ob_type, pytype) && - pyobject->ob_type->tp_init != NULL) - { - emptyarg = PyTuple_New(0); - pyobject->ob_type->tp_init (pyobject, emptyarg, NULL); - Py_DECREF (emptyarg); - } - - instance = XED_PLUGIN (pygobject->obj); - pyinfo->instance = (PyObject *)pygobject; - - /* make sure to register the python instance for the XedPluginPython - object to it can wrap the virtual xed plugin funcs back to python */ - _xed_plugin_python_set_instance (XED_PLUGIN_PYTHON (instance), (PyObject *)pygobject); - - /* we return a reference here because the other is owned by python */ - return XED_PLUGIN (g_object_ref (instance)); -} - -static XedPlugin * -add_python_info (XedPluginLoaderPython *loader, - XedPluginInfo *info, - PyObject *module, - const gchar *path, - PyObject *type) -{ - PythonInfo *pyinfo; - - pyinfo = g_new (PythonInfo, 1); - pyinfo->path = g_strdup (path); - pyinfo->type = type; - - Py_INCREF (pyinfo->type); - - g_hash_table_insert (loader->priv->loaded_plugins, info, pyinfo); - - return new_plugin_from_info (loader, info); -} - -static const gchar * -xed_plugin_loader_iface_get_id (void) -{ - return "Python"; -} - -static XedPlugin * -xed_plugin_loader_iface_load (XedPluginLoader *loader, - XedPluginInfo *info, - const gchar *path) -{ - XedPluginLoaderPython *pyloader = XED_PLUGIN_LOADER_PYTHON (loader); - PyObject *main_module, *main_locals, *pytype; - PyObject *pymodule, *fromlist; - gchar *module_name; - XedPlugin *result; - - if (pyloader->priv->init_failed) - { - g_warning ("Cannot load python plugin Python '%s' since xed was" - "not able to initialize the Python interpreter.", - xed_plugin_info_get_name (info)); - return NULL; - } - - /* see if py definition for the plugin is already loaded */ - result = new_plugin_from_info (pyloader, info); - - if (result != NULL) - return result; - - main_module = PyImport_AddModule ("xed.plugins"); - if (main_module == NULL) - { - g_warning ("Could not get xed.plugins."); - return NULL; - } - - /* If we have a special path, we register it */ - if (path != NULL) - { - PyObject *sys_path = PySys_GetObject ("path"); - PyObject *pypath = PyString_FromString (path); - - if (PySequence_Contains (sys_path, pypath) == 0) - PyList_Insert (sys_path, 0, pypath); - - Py_DECREF (pypath); - } - - main_locals = PyModule_GetDict (main_module); - - /* we need a fromlist to be able to import modules with a '.' in the - name. */ - fromlist = PyTuple_New(0); - module_name = g_strdup (xed_plugin_info_get_module_name (info)); - - pymodule = PyImport_ImportModuleEx (module_name, - main_locals, - main_locals, - fromlist); - - Py_DECREF(fromlist); - - if (!pymodule) - { - g_free (module_name); - PyErr_Print (); - return NULL; - } - - PyDict_SetItemString (main_locals, module_name, pymodule); - g_free (module_name); - - pytype = find_python_plugin_type (info, pymodule); - - if (pytype) - return add_python_info (pyloader, info, pymodule, path, pytype); - - return NULL; -} - -static void -xed_plugin_loader_iface_unload (XedPluginLoader *loader, - XedPluginInfo *info) -{ - XedPluginLoaderPython *pyloader = XED_PLUGIN_LOADER_PYTHON (loader); - PythonInfo *pyinfo; - PyGILState_STATE state; - - pyinfo = (PythonInfo *)g_hash_table_lookup (pyloader->priv->loaded_plugins, info); - - if (!pyinfo) - return; - - state = pyg_gil_state_ensure (); - Py_XDECREF (pyinfo->instance); - pyg_gil_state_release (state); - - pyinfo->instance = NULL; -} - -static gboolean -run_gc (XedPluginLoaderPython *loader) -{ - while (PyGC_Collect ()) - ; - - loader->priv->idle_gc = 0; - return FALSE; -} - -static void -xed_plugin_loader_iface_garbage_collect (XedPluginLoader *loader) -{ - XedPluginLoaderPython *pyloader; - - if (!Py_IsInitialized()) - return; - - pyloader = XED_PLUGIN_LOADER_PYTHON (loader); - - /* - * We both run the GC right now and we schedule - * a further collection in the main loop. - */ - - while (PyGC_Collect ()) - ; - - if (pyloader->priv->idle_gc == 0) - pyloader->priv->idle_gc = g_idle_add ((GSourceFunc)run_gc, pyloader); -} - -static void -xed_plugin_loader_iface_init (gpointer g_iface, - gpointer iface_data) -{ - XedPluginLoaderInterface *iface = (XedPluginLoaderInterface *)g_iface; - - iface->get_id = xed_plugin_loader_iface_get_id; - iface->load = xed_plugin_loader_iface_load; - iface->unload = xed_plugin_loader_iface_unload; - iface->garbage_collect = xed_plugin_loader_iface_garbage_collect; -} - -static void -xed_python_shutdown (XedPluginLoaderPython *loader) -{ - if (!Py_IsInitialized ()) - return; - - if (loader->priv->idle_gc != 0) - { - g_source_remove (loader->priv->idle_gc); - loader->priv->idle_gc = 0; - } - - while (PyGC_Collect ()) - ; - - Py_Finalize (); -} - - -/* C equivalent of - * import pygtk - * pygtk.require ("2.0") - */ -static gboolean -xed_check_pygtk2 (void) -{ - PyObject *pygtk, *mdict, *require; - - /* pygtk.require("2.0") */ - pygtk = PyImport_ImportModule ("pygtk"); - if (pygtk == NULL) - { - g_warning ("Error initializing Python interpreter: could not import pygtk."); - return FALSE; - } - - mdict = PyModule_GetDict (pygtk); - require = PyDict_GetItemString (mdict, "require"); - PyObject_CallObject (require, - Py_BuildValue ("(S)", PyString_FromString ("2.0"))); - if (PyErr_Occurred()) - { - g_warning ("Error initializing Python interpreter: pygtk 2 is required."); - return FALSE; - } - - return TRUE; -} - -/* Note: the following two functions are needed because - * init_pyobject and init_pygtk which are *macros* which in case - * case of error set the PyErr and then make the calling - * function return behind our back. - * It's up to the caller to check the result with PyErr_Occurred() - */ -static void -xed_init_pygobject (void) -{ - init_pygobject_check (2, 11, 5); /* FIXME: get from config */ -} - -static void -xed_init_pygtk (void) -{ - PyObject *gtk, *mdict, *version, *required_version; - - init_pygtk (); - - /* there isn't init_pygtk_check(), do the version - * check ourselves */ - gtk = PyImport_ImportModule("gtk"); - mdict = PyModule_GetDict(gtk); - version = PyDict_GetItemString (mdict, "pygtk_version"); - if (!version) - { - PyErr_SetString (PyExc_ImportError, - "PyGObject version too old"); - return; - } - - required_version = Py_BuildValue ("(iii)", 2, 4, 0); /* FIXME */ - - if (PyObject_Compare (version, required_version) == -1) - { - PyErr_SetString (PyExc_ImportError, - "PyGObject version too old"); - Py_DECREF (required_version); - return; - } - - Py_DECREF (required_version); -} - -static void -old_gtksourceview_init (void) -{ - PyErr_SetString(PyExc_ImportError, - "gtksourceview module not allowed, use gtksourceview2"); -} - -static void -xed_init_pygtksourceview (void) -{ - PyObject *gtksourceview, *mdict, *version, *required_version; - - gtksourceview = PyImport_ImportModule("gtksourceview2"); - if (gtksourceview == NULL) - { - PyErr_SetString (PyExc_ImportError, - "could not import gtksourceview"); - return; - } - - mdict = PyModule_GetDict (gtksourceview); - version = PyDict_GetItemString (mdict, "pygtksourceview2_version"); - if (!version) - { - PyErr_SetString (PyExc_ImportError, - "PyGtkSourceView version too old"); - return; - } - - required_version = Py_BuildValue ("(iii)", 0, 8, 0); /* FIXME */ - - if (PyObject_Compare (version, required_version) == -1) - { - PyErr_SetString (PyExc_ImportError, - "PyGtkSourceView version too old"); - Py_DECREF (required_version); - return; - } - - Py_DECREF (required_version); - - /* Create a dummy 'gtksourceview' module to prevent - * loading of the old 'gtksourceview' modules that - * has conflicting symbols with the gtksourceview2 module. - * Raise an exception when trying to import it. - */ - PyImport_AppendInittab ("gtksourceview", old_gtksourceview_init); -} - -static gboolean -xed_python_init (XedPluginLoaderPython *loader) -{ - PyObject *mdict, *tuple; - PyObject *xed, *xedutils, *xedcommands, *xedplugins; - PyObject *gettext, *install, *gettext_args; - //char *argv[] = { "xed", NULL }; - char *argv[] = { XED_PLUGINS_LIBS_DIR, NULL }; -#ifdef HAVE_SIGACTION - gint res; - struct sigaction old_sigint; -#endif - - if (loader->priv->init_failed) - { - /* We already failed to initialized Python, don't need to - * retry again */ - return FALSE; - } - - if (Py_IsInitialized ()) - { - /* Python has already been successfully initialized */ - return TRUE; - } - - /* We are trying to initialize Python for the first time, - set init_failed to FALSE only if the entire initialization process - ends with success */ - loader->priv->init_failed = TRUE; - - /* Hack to make python not overwrite SIGINT: this is needed to avoid - * the crash reported on bug #326191 */ - - /* CHECK: can't we use Py_InitializeEx instead of Py_Initialize in order - to avoid to manage signal handlers ? - Paolo (Dec. 31, 2006) */ - -#ifdef HAVE_SIGACTION - /* Save old handler */ - res = sigaction (SIGINT, NULL, &old_sigint); - if (res != 0) - { - g_warning ("Error initializing Python interpreter: cannot get " - "handler to SIGINT signal (%s)", - g_strerror (errno)); - - return FALSE; - } -#endif - - /* Python initialization */ - Py_Initialize (); - -#ifdef HAVE_SIGACTION - /* Restore old handler */ - res = sigaction (SIGINT, &old_sigint, NULL); - if (res != 0) - { - g_warning ("Error initializing Python interpreter: cannot restore " - "handler to SIGINT signal (%s).", - g_strerror (errno)); - - goto python_init_error; - } -#endif - - PySys_SetArgv (1, argv); - - if (!xed_check_pygtk2 ()) - { - /* Warning message already printed in check_pygtk2 */ - goto python_init_error; - } - - /* import gobject */ - xed_init_pygobject (); - if (PyErr_Occurred ()) - { - g_warning ("Error initializing Python interpreter: could not import pygobject."); - - goto python_init_error; - } - - /* import gtk */ - xed_init_pygtk (); - if (PyErr_Occurred ()) - { - g_warning ("Error initializing Python interpreter: could not import pygtk."); - - goto python_init_error; - } - - /* import gtksourceview */ - xed_init_pygtksourceview (); - if (PyErr_Occurred ()) - { - PyErr_Print (); - - g_warning ("Error initializing Python interpreter: could not import pygtksourceview."); - - goto python_init_error; - } - - /* import xed */ - xed = Py_InitModule ("xed", pyxed_functions); - mdict = PyModule_GetDict (xed); - - pyxed_register_classes (mdict); - pyxed_add_constants (xed, "XED_"); - - /* xed version */ - tuple = Py_BuildValue("(iii)", - XED_MAJOR_VERSION, - XED_MINOR_VERSION, - XED_MICRO_VERSION); - PyDict_SetItemString(mdict, "version", tuple); - Py_DECREF(tuple); - - /* Retrieve the Python type for xed.Plugin */ - PyXedPlugin_Type = (PyTypeObject *) PyDict_GetItemString (mdict, "Plugin"); - if (PyXedPlugin_Type == NULL) - { - PyErr_Print (); - - goto python_init_error; - } - - /* import xed.utils */ - xedutils = Py_InitModule ("xed.utils", pyxedutils_functions); - PyDict_SetItemString (mdict, "utils", xedutils); - - /* import xed.commands */ - xedcommands = Py_InitModule ("xed.commands", pyxedcommands_functions); - PyDict_SetItemString (mdict, "commands", xedcommands); - - /* initialize empty xed.plugins module */ - xedplugins = Py_InitModule ("xed.plugins", NULL); - PyDict_SetItemString (mdict, "plugins", xedplugins); - - mdict = PyModule_GetDict (xedutils); - pyxedutils_register_classes (mdict); - - mdict = PyModule_GetDict (xedcommands); - pyxedcommands_register_classes (mdict); - - /* i18n support */ - gettext = PyImport_ImportModule ("gettext"); - if (gettext == NULL) - { - g_warning ("Error initializing Python interpreter: could not import gettext."); - - goto python_init_error; - } - - mdict = PyModule_GetDict (gettext); - install = PyDict_GetItemString (mdict, "install"); - gettext_args = Py_BuildValue ("ss", GETTEXT_PACKAGE, XED_LOCALEDIR); - PyObject_CallObject (install, gettext_args); - Py_DECREF (gettext_args); - - /* Python has been successfully initialized */ - loader->priv->init_failed = FALSE; - - return TRUE; - -python_init_error: - - g_warning ("Please check the installation of all the Python related packages required " - "by xed and try again."); - - PyErr_Clear (); - - xed_python_shutdown (loader); - - return FALSE; -} - -static void -xed_plugin_loader_python_finalize (GObject *object) -{ - XedPluginLoaderPython *pyloader = XED_PLUGIN_LOADER_PYTHON (object); - - g_hash_table_destroy (pyloader->priv->loaded_plugins); - xed_python_shutdown (pyloader); - - G_OBJECT_CLASS (xed_plugin_loader_python_parent_class)->finalize (object); -} - -static void -xed_plugin_loader_python_class_init (XedPluginLoaderPythonClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = xed_plugin_loader_python_finalize; - - g_type_class_add_private (object_class, sizeof (XedPluginLoaderPythonPrivate)); -} - -static void -xed_plugin_loader_python_class_finalize (XedPluginLoaderPythonClass *klass) -{ -} - -static void -destroy_python_info (PythonInfo *info) -{ - PyGILState_STATE state = pyg_gil_state_ensure (); - Py_XDECREF (info->type); - pyg_gil_state_release (state); - - g_free (info->path); - g_free (info); -} - -static void -xed_plugin_loader_python_init (XedPluginLoaderPython *self) -{ - self->priv = XED_PLUGIN_LOADER_PYTHON_GET_PRIVATE (self); - - /* initialize python interpreter */ - xed_python_init (self); - - /* loaded_plugins maps XedPluginInfo to a PythonInfo */ - self->priv->loaded_plugins = g_hash_table_new_full (g_direct_hash, - g_direct_equal, - NULL, - (GDestroyNotify)destroy_python_info); -} - -XedPluginLoaderPython * -xed_plugin_loader_python_new () -{ - GObject *loader = g_object_new (XED_TYPE_PLUGIN_LOADER_PYTHON, NULL); - - return XED_PLUGIN_LOADER_PYTHON (loader); -} - diff --git a/plugin-loaders/python/xed-plugin-loader-python.h b/plugin-loaders/python/xed-plugin-loader-python.h deleted file mode 100644 index b6c3afe..0000000 --- a/plugin-loaders/python/xed-plugin-loader-python.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * xed-plugin-loader-python.h - * This file is part of xed - * - * Copyright (C) 2008 - Jesse van den Kieboom - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __XED_PLUGIN_LOADER_PYTHON_H__ -#define __XED_PLUGIN_LOADER_PYTHON_H__ - -#include - -G_BEGIN_DECLS - -#define XED_TYPE_PLUGIN_LOADER_PYTHON (xed_plugin_loader_python_get_type ()) -#define XED_PLUGIN_LOADER_PYTHON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_PLUGIN_LOADER_PYTHON, XedPluginLoaderPython)) -#define XED_PLUGIN_LOADER_PYTHON_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_PLUGIN_LOADER_PYTHON, XedPluginLoaderPython const)) -#define XED_PLUGIN_LOADER_PYTHON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_PLUGIN_LOADER_PYTHON, XedPluginLoaderPythonClass)) -#define XED_IS_PLUGIN_LOADER_PYTHON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_PLUGIN_LOADER_PYTHON)) -#define XED_IS_PLUGIN_LOADER_PYTHON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_PLUGIN_LOADER_PYTHON)) -#define XED_PLUGIN_LOADER_PYTHON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_PLUGIN_LOADER_PYTHON, XedPluginLoaderPythonClass)) - -typedef struct _XedPluginLoaderPython XedPluginLoaderPython; -typedef struct _XedPluginLoaderPythonClass XedPluginLoaderPythonClass; -typedef struct _XedPluginLoaderPythonPrivate XedPluginLoaderPythonPrivate; - -struct _XedPluginLoaderPython { - GObject parent; - - XedPluginLoaderPythonPrivate *priv; -}; - -struct _XedPluginLoaderPythonClass { - GObjectClass parent_class; -}; - -GType xed_plugin_loader_python_get_type (void) G_GNUC_CONST; -XedPluginLoaderPython *xed_plugin_loader_python_new(void); - -/* All the loaders must implement this function */ -G_MODULE_EXPORT GType register_xed_plugin_loader (GTypeModule * module); - -G_END_DECLS - -#endif /* __XED_PLUGIN_LOADER_PYTHON_H__ */ - diff --git a/plugin-loaders/python/xed-plugin-python.c b/plugin-loaders/python/xed-plugin-python.c deleted file mode 100644 index 2700d83..0000000 --- a/plugin-loaders/python/xed-plugin-python.c +++ /dev/null @@ -1,281 +0,0 @@ -/* - * xed-plugin-python.c - * This file is part of xed - * - * Copyright (C) 2005 Raphael Slinckx - * Copyright (C) 2008 Jesse van den Kieboom - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include - -#include "xed-plugin-python.h" - -#include -#include -#include -#include - -#define XED_PLUGIN_PYTHON_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_PLUGIN_PYTHON, XedPluginPythonPrivate)) - -static GObjectClass *parent_class; - -struct _XedPluginPythonPrivate -{ - PyObject *instance; -}; - -static void xed_plugin_python_class_init (XedPluginPythonClass *klass); -static void xed_plugin_python_init (XedPluginPython *plugin); - -G_DEFINE_TYPE (XedPluginPython, xed_plugin_python, XED_TYPE_PLUGIN) - -static PyObject * -call_python_method (XedPluginPythonPrivate *priv, - XedWindow *window, - gchar *method) -{ - PyObject *py_ret = NULL; - - g_return_val_if_fail (PyObject_HasAttrString (priv->instance, method), NULL); - - if (window == NULL) - { - py_ret = PyObject_CallMethod (priv->instance, - method, - NULL); - } - else - { - py_ret = PyObject_CallMethod (priv->instance, - method, - "(N)", - pygobject_new (G_OBJECT (window))); - } - - if (!py_ret) - PyErr_Print (); - - return py_ret; -} - -static gboolean -check_py_object_is_gtk_widget (PyObject *py_obj) -{ - static PyTypeObject *_PyGtkWidget_Type = NULL; - - if (_PyGtkWidget_Type == NULL) - { - PyObject *module; - - if ((module = PyImport_ImportModule ("gtk"))) - { - PyObject *moddict = PyModule_GetDict (module); - _PyGtkWidget_Type = (PyTypeObject *) PyDict_GetItemString (moddict, "Widget"); - } - - if (_PyGtkWidget_Type == NULL) - { - PyErr_SetString(PyExc_TypeError, "could not find Python gtk widget type"); - PyErr_Print(); - - return FALSE; - } - } - - return PyObject_TypeCheck (py_obj, _PyGtkWidget_Type) ? TRUE : FALSE; -} - -static void -impl_update_ui (XedPlugin *plugin, - XedWindow *window) -{ - PyGILState_STATE state = pyg_gil_state_ensure (); - XedPluginPythonPrivate *priv = XED_PLUGIN_PYTHON(plugin)->priv; - - if (PyObject_HasAttrString (priv->instance, "update_ui")) - { - PyObject *py_ret = call_python_method (priv, window, "update_ui"); - - if (py_ret) - { - Py_XDECREF (py_ret); - } - } - else - XED_PLUGIN_CLASS (parent_class)->update_ui (plugin, window); - - pyg_gil_state_release (state); -} - -static void -impl_deactivate (XedPlugin *plugin, - XedWindow *window) -{ - PyGILState_STATE state = pyg_gil_state_ensure (); - XedPluginPythonPrivate *priv = XED_PLUGIN_PYTHON(plugin)->priv; - - if (PyObject_HasAttrString (priv->instance, "deactivate")) - { - PyObject *py_ret = call_python_method (priv, window, "deactivate"); - - if (py_ret) - { - Py_XDECREF (py_ret); - } - } - else - XED_PLUGIN_CLASS (parent_class)->deactivate (plugin, window); - - pyg_gil_state_release (state); -} - -static void -impl_activate (XedPlugin *plugin, - XedWindow *window) -{ - PyGILState_STATE state = pyg_gil_state_ensure (); - XedPluginPythonPrivate *priv = XED_PLUGIN_PYTHON(plugin)->priv; - - if (PyObject_HasAttrString (priv->instance, "activate")) - { - PyObject *py_ret = call_python_method (priv, window, "activate"); - - if (py_ret) - { - Py_XDECREF (py_ret); - } - } - else - XED_PLUGIN_CLASS (parent_class)->activate (plugin, window); - - pyg_gil_state_release (state); -} - -static GtkWidget * -impl_create_configure_dialog (XedPlugin *plugin) -{ - PyGILState_STATE state = pyg_gil_state_ensure (); - XedPluginPythonPrivate *priv = XED_PLUGIN_PYTHON(plugin)->priv; - GtkWidget *ret = NULL; - - if (PyObject_HasAttrString (priv->instance, "create_configure_dialog")) - { - PyObject *py_ret = call_python_method (priv, NULL, "create_configure_dialog"); - - if (py_ret) - { - if (check_py_object_is_gtk_widget (py_ret)) - { - ret = GTK_WIDGET (pygobject_get (py_ret)); - g_object_ref (ret); - } - else - { - PyErr_SetString(PyExc_TypeError, "return value for create_configure_dialog is not a GtkWidget"); - PyErr_Print(); - } - - Py_DECREF (py_ret); - } - } - else - ret = XED_PLUGIN_CLASS (parent_class)->create_configure_dialog (plugin); - - pyg_gil_state_release (state); - - return ret; -} - -static gboolean -impl_is_configurable (XedPlugin *plugin) -{ - PyGILState_STATE state = pyg_gil_state_ensure (); - XedPluginPythonPrivate *priv = XED_PLUGIN_PYTHON(plugin)->priv; - PyObject *dict = priv->instance->ob_type->tp_dict; - gboolean result; - - if (dict == NULL) - result = FALSE; - else if (!PyDict_Check(dict)) - result = FALSE; - else - result = PyDict_GetItemString(dict, "create_configure_dialog") != NULL; - - pyg_gil_state_release (state); - - return result; -} - -void -_xed_plugin_python_set_instance (XedPluginPython *plugin, - PyObject *instance) -{ - PyGILState_STATE state = pyg_gil_state_ensure (); - - /* we don't increment the instance here because we are the instance, - when it dies, we also die */ - plugin->priv->instance = instance; - pyg_gil_state_release (state); -} - -PyObject * -_xed_plugin_python_get_instance (XedPluginPython *plugin) -{ - return plugin->priv->instance; -} - -static void -xed_plugin_python_init (XedPluginPython *plugin) -{ - plugin->priv = XED_PLUGIN_PYTHON_GET_PRIVATE(plugin); - - xed_debug_message (DEBUG_PLUGINS, "Creating Python plugin instance"); - plugin->priv->instance = 0; -} - -static void -xed_plugin_python_finalize (GObject *object) -{ - PyGILState_STATE state; - - xed_debug_message (DEBUG_PLUGINS, "Finalizing Python plugin instance"); - - state = pyg_gil_state_ensure (); - Py_XDECREF (XED_PLUGIN_PYTHON(object)->priv->instance); - pyg_gil_state_release (state); - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static void -xed_plugin_python_class_init (XedPluginPythonClass *klass) -{ - XedPluginClass *plugin_class = XED_PLUGIN_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - g_type_class_add_private (klass, sizeof (XedPluginPythonPrivate)); - G_OBJECT_CLASS (klass)->finalize = xed_plugin_python_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_update_ui; - plugin_class->create_configure_dialog = impl_create_configure_dialog; - plugin_class->is_configurable = impl_is_configurable; -} - diff --git a/plugin-loaders/python/xed-plugin-python.h b/plugin-loaders/python/xed-plugin-python.h deleted file mode 100644 index 96a9eec..0000000 --- a/plugin-loaders/python/xed-plugin-python.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * xed-plugin-python.h - * This file is part of xed - * - * Copyright (C) 2005 - Raphael Slinckx - * Copyright (C) 2008 - Jesse van den Kieboom - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __XED_PLUGIN_PYTHON_H__ -#define __XED_PLUGIN_PYTHON_H__ - -#define NO_IMPORT_PYGOBJECT - -#include -#include - -#include - -G_BEGIN_DECLS - -/* - * Type checking and casting macros - */ -#define XED_TYPE_PLUGIN_PYTHON (xed_plugin_python_get_type()) -#define XED_PLUGIN_PYTHON(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_PLUGIN_PYTHON, XedPluginPython)) -#define XED_PLUGIN_PYTHON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_PLUGIN_PYTHON, XedPluginPythonClass)) -#define XED_IS_PLUGIN_PYTHON(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_PLUGIN_PYTHON)) -#define XED_IS_PLUGIN_PYTHON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_PLUGIN_PYTHON)) -#define XED_PLUGIN_PYTHON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_PLUGIN_PYTHON, XedPluginPythonClass)) - -/* Private structure type */ -typedef struct _XedPluginPythonPrivate XedPluginPythonPrivate; - -/* - * Main object structure - */ -typedef struct _XedPluginPython XedPluginPython; - -struct _XedPluginPython -{ - XedPlugin parent; - - /*< private > */ - XedPluginPythonPrivate *priv; -}; - -/* - * Class definition - */ -typedef struct _XedPluginPythonClass XedPluginPythonClass; - -struct _XedPluginPythonClass -{ - XedPluginClass parent_class; -}; - -/* - * Public methods - */ -GType xed_plugin_python_get_type (void) G_GNUC_CONST; - - -/* - * Private methods - */ -void _xed_plugin_python_set_instance (XedPluginPython *plugin, - PyObject *instance); -PyObject *_xed_plugin_python_get_instance (XedPluginPython *plugin); - -G_END_DECLS - -#endif /* __XED_PLUGIN_PYTHON_H__ */ - diff --git a/tools/plugin_template/xed-plugin.desktop.in b/tools/plugin_template/xed-plugin.desktop.in index df3a5cd..7b54a27 100644 --- a/tools/plugin_template/xed-plugin.desktop.in +++ b/tools/plugin_template/xed-plugin.desktop.in @@ -1,7 +1,4 @@ [Xed Plugin] -##ifdef WITH_PYTHON -Loader=python -##endif Module=##(PLUGIN_MODULE) IAge=2 _Name=##(PLUGIN_NAME) diff --git a/xed/xed-plugin-info-priv.h b/xed/xed-plugin-info-priv.h index 23f799f..79d8742 100644 --- a/xed/xed-plugin-info-priv.h +++ b/xed/xed-plugin-info-priv.h @@ -2,7 +2,7 @@ * xed-plugin-info-priv.h * This file is part of xed * - * Copyright (C) 2002-2005 - Paolo Maggi + * Copyright (C) 2002-2005 - Paolo Maggi * Copyright (C) 2007 - Paolo Maggi, Steve Frécinaux * * This program is free software; you can redistribute it and/or modify @@ -17,10 +17,10 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ - + /* * Modified by the xed Team, 2002-2007. See the AUTHORS file for a * list of people on the xed Team. @@ -55,8 +55,7 @@ struct _XedPluginInfo gchar *version; /* A plugin is unavailable if it is not possible to activate it - due to an error loading the plugin module (e.g. for Python plugins - when the interpreter has not been correctly initializated) */ + due to an error loading the plugin module */ gint available : 1; }; From 2ddd92171c4f7b379a355b6d026961441c6f6a8a Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 10:08:11 -0800 Subject: [PATCH 021/132] build: Clean up a bit more of the gtk2 and --enable-python leftovers --- data/xed-bugreport.sh.in | 3 +-- data/xed.pc.in | 2 +- debian/rules | 4 +--- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/data/xed-bugreport.sh.in b/data/xed-bugreport.sh.in index 01ae2cc..6d6bf0c 100644 --- a/data/xed-bugreport.sh.in +++ b/data/xed-bugreport.sh.in @@ -1,7 +1,6 @@ #!/bin/sh -PKG_CONFIG_MODULES="glib-2.0 gtk+-2.0 gtksourceview-2.0 \ - enchant iso-codes" +PKG_CONFIG_MODULES="glib-2.0 gtk+-3.0 gtksourceview-3.0 enchant iso-codes" echo_padded () { diff --git a/data/xed.pc.in b/data/xed.pc.in index 80ab0a3..24593ca 100644 --- a/data/xed.pc.in +++ b/data/xed.pc.in @@ -6,7 +6,7 @@ pluginsdir=@libdir@/xed/plugins Name: xed Description: xed -Requires: gtksourceview-@GTK_API_VERSION@ +Requires: gtksourceview-3.0 Version: @VERSION@ Cflags: -I${includedir}/xed Libs: -L${libdir} diff --git a/debian/rules b/debian/rules index 6052977..9088701 100755 --- a/debian/rules +++ b/debian/rules @@ -16,9 +16,7 @@ override_dh_auto_configure: dh_auto_configure $(DHFLAGS) -- \ --disable-silent-rules \ --libexecdir=/usr/lib/ \ - --disable-python \ - --enable-gtk-doc \ - --with-gtk=3.0 + --enable-gtk-doc override_dh_installchangelogs: dh_installchangelogs NEWS From c6f5fd5e1d9eef8b6799bd23e465fb27eb7e8a64 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 10:56:42 -0800 Subject: [PATCH 022/132] build GObject introspection data Adapted from: https://github.com/mate-desktop/pluma/commit/a4dcd9177a32626929783b3920d660782d89bf01 https://github.com/mate-desktop/debian-packages/commit/0488ffe5d2c698a33294e13ae06338b8f250caa3 --- configure.ac | 11 +++++ debian/control | 28 ++++++++++++ debian/gir1.2-xed.install | 2 + xed/Makefile.am | 89 +++++++++++++++++++++++++-------------- xed/xed.c | 8 ++++ 5 files changed, 106 insertions(+), 32 deletions(-) create mode 100644 debian/gir1.2-xed.install diff --git a/configure.ac b/configure.ac index 3d6e7e2..ceadc41 100644 --- a/configure.ac +++ b/configure.ac @@ -172,6 +172,16 @@ PKG_CHECK_MODULES(EGG_SMCLIENT, [sm >= 1.0.0]) AC_SUBST(EGG_SMCLIENT_CFLAGS) AC_SUBST(EGG_SMCLIENT_LIBS) +# Introspection +GOBJECT_INTROSPECTION_CHECK([0.9.3]) + +if test "$found_introspection" = "yes"; then + have_introspection=yes + AC_DEFINE([HAVE_INTROSPECTION], [1], [Define to enable GObject Introspection]) +else + have_introspection=no +fi + dnl ================================================================ dnl GSettings related settings dnl ================================================================ @@ -265,5 +275,6 @@ Configuration: Compiler: ${CC} Spell Plugin enabled: $enable_enchant Gvfs metadata enabled: $enable_gvfs_metadata + GObject Introspection: ${have_introspection} Tests enabled: $enable_tests " diff --git a/debian/control b/debian/control index 7ebdb41..7dfecfe 100644 --- a/debian/control +++ b/debian/control @@ -4,10 +4,12 @@ Priority: optional Maintainer: Linux Mint Build-Depends: autotools-dev, debhelper (>= 9), + gobject-introspection, gtk-doc-tools, intltool, iso-codes, libenchant-dev, + libgirepository1.0-dev, libglib2.0-dev, libgtk-3-dev, libgtksourceview-3.0-dev, @@ -137,3 +139,29 @@ Description: generic text editor (documentation files) ChangeLogs, and adjusting indentation levels. . This package contains the documentation files. + +Package: gir1.2-xed +Architecture: any +Depends: ${gir:Depends}, + ${misc:Depends}, + ${shlibs:Depends}, +Description: GObject introspection data for Xed + Xed is a text editor which supports most standard editor features, + extending this basic functionality with other features not usually + found in simple text editors. Xed is a graphical application which + supports editing multiple text files in one window (known sometimes as + tabs or MDI). + . + Xed fully supports international text through its use of the + Unicode UTF-8 encoding in edited files. Its core feature set includes syntax + highlighting of source code, auto indentation and printing and print preview + support. + . + Xed is also extensible through its plugin system, which currently + includes support for spell checking, comparing files, viewing CVS + ChangeLogs, and adjusting indentation levels. + . + This package contains introspection data for Xed. + . + It can be used by packages using the GIRepository format to generate + dynamic bindings. \ No newline at end of file diff --git a/debian/gir1.2-xed.install b/debian/gir1.2-xed.install new file mode 100644 index 0000000..d8bd766 --- /dev/null +++ b/debian/gir1.2-xed.install @@ -0,0 +1,2 @@ +usr/lib/*/girepository-1.0 +usr/share/gir-1.0 \ No newline at end of file diff --git a/xed/Makefile.am b/xed/Makefile.am index c5018fe..1505e33 100644 --- a/xed/Makefile.am +++ b/xed/Makefile.am @@ -5,20 +5,21 @@ bin_PROGRAMS = xed noinst_LTLIBRARIES = libxed.la -AM_CPPFLAGS = \ - -I$(top_srcdir) \ +AM_CPPFLAGS = \ + -I$(top_srcdir) \ -I$(srcdir) \ - -I$(srcdir)/smclient \ - $(XED_CFLAGS) \ - $(WARN_CFLAGS) \ - $(DISABLE_DEPRECATED_CFLAGS) \ - -DDATADIR=\""$(datadir)"\" \ + -I$(srcdir)/smclient \ + $(XED_CFLAGS) \ + $(WARN_CFLAGS) \ + $(INTROSPECTION_CFLAGS) \ + $(DISABLE_DEPRECATED_CFLAGS) \ + -DDATADIR=\""$(datadir)"\" \ -DLIBDIR=\""$(libdir)"\" xed_SOURCES = \ xed.c -xed_LDADD = libxed.la $(XED_LIBS) $(EGG_SMCLIENT_LIBS) +xed_LDADD = libxed.la $(XED_LIBS) $(EGG_SMCLIENT_LIBS) $(INTROSPECTION_LIBS) xed_LDFLAGS = -export-dynamic -no-undefined -export-symbols-regex "^[[^_]].*" @@ -104,22 +105,19 @@ header_DATA = \ $(INST_H_FILES) -libxed_la_SOURCES = \ - $(BUILT_SOURCES) \ - $(BACON_FILES) \ - $(POSIXIO_FILES) \ - xed-app.c \ - xed-close-button.c \ +libxed_c_files = \ + xed-app.c \ + xed-close-button.c \ xed-commands-documents.c \ - xed-commands-edit.c \ - xed-commands-file.c \ + xed-commands-edit.c \ + xed-commands-file.c \ xed-commands-file-print.c \ - xed-commands-help.c \ + xed-commands-help.c \ xed-commands-search.c \ - xed-commands-view.c \ - xed-debug.c \ - xed-dirs.c \ - xed-document.c \ + xed-commands-view.c \ + xed-debug.c \ + xed-dirs.c \ + xed-document.c \ xed-document-input-stream.c \ xed-document-loader.c \ xed-document-output-stream.c \ @@ -127,19 +125,19 @@ libxed_la_SOURCES = \ xed-document-saver.c \ xed-gio-document-saver.c \ xed-documents-panel.c \ - xed-encodings.c \ + xed-encodings.c \ xed-encodings-combo-box.c \ xed-file-chooser-dialog.c \ - xed-help.c \ - xed-history-entry.c \ + xed-help.c \ + xed-history-entry.c \ xed-io-error-message-area.c \ - xed-language-manager.c \ - xed-message-bus.c \ - xed-message-type.c \ - xed-message.c \ - xed-object-module.c \ - xed-notebook.c \ - xed-panel.c \ + xed-language-manager.c \ + xed-message-bus.c \ + xed-message-type.c \ + xed-message.c \ + xed-object-module.c \ + xed-notebook.c \ + xed-panel.c \ xed-plugin-info.c \ xed-plugin.c \ xed-plugin-loader.c \ @@ -162,7 +160,13 @@ libxed_la_SOURCES = \ xed-utils.c \ xed-view.c \ xed-window.c \ - xedtextregion.c \ + xedtextregion.c + +libxed_la_SOURCES = \ + $(libxed_c_files) \ + $(BUILT_SOURCES) \ + $(BACON_FILES) \ + $(POSIXIO_FILES) \ $(NOINST_H_FILES) \ $(INST_H_FILES) @@ -198,6 +202,27 @@ EXTRA_DIST = \ CLEANFILES = $(BUILT_SOURCES) +if HAVE_INTROSPECTION +-include $(INTROSPECTION_MAKEFILE) +INTROSPECTION_GIRS = Xed-1.0.gir +INTROSPECTION_SCANNER_ARGS = -I$(top_srcdir) --warn-all + +Xed-1.0.gir: xed +Xed_1_0_gir_INCLUDES = Gtk-3.0 GtkSource-3.0 +Xed_1_0_gir_FILES = $(INST_H_FILES) $(libxed_c_files) $(BUILT_SOURCES) +Xed_1_0_gir_VERSION = 1.0 +Xed_1_0_gir_PROGRAM = $(builddir)/xed +Xed_1_0_gir_NAMESPACE = Xed + +girdir = $(datadir)/gir-1.0 +gir_DATA = $(INTROSPECTION_GIRS) + +typelibdir = $(libdir)/girepository-1.0 +typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib) + +CLEANFILES += $(gir_DATA) $(typelib_DATA) +endif + dist-hook: cd $(distdir); rm -f $(BUILT_SOURCES) diff --git a/xed/xed.c b/xed/xed.c index dc99eac..b2eb973 100644 --- a/xed/xed.c +++ b/xed/xed.c @@ -42,6 +42,10 @@ #include #include +#ifdef HAVE_INTROSPECTION +#include +#endif + #include "xed-app.h" #include "xed-commands.h" #include "xed-debug.h" @@ -522,6 +526,10 @@ main (int argc, char *argv[]) g_option_context_add_group (context, gtk_get_option_group (FALSE)); g_option_context_add_group (context, egg_sm_client_get_option_group ()); +#ifdef HAVE_INTROSPECTION + g_option_context_add_group (context, g_irepository_get_option_group ()); +#endif + gtk_init (&argc, &argv); if (!g_option_context_parse (context, &argc, &argv, &error)) From 7a6db1f8c5ad57aa525706008bffbcd42ea50341 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 11:41:29 -0800 Subject: [PATCH 023/132] Fix some introspection warnings Adapted from: https://github.com/mate-desktop/pluma/commit/b9a3360ee86441189c8091836dae6d1e97544db8 --- xed/xed-app.c | 8 +- xed/xed-document.c | 18 +- xed/xed-file-chooser-dialog.c | 2 +- xed/xed-message-bus.c | 12 +- xed/xed-message-type.c | 84 +++---- xed/xed-message.c | 108 ++++----- xed/xed-status-combo-box.c | 69 +++--- xed/xed-tab.c | 400 +++++++++++++++++----------------- xed/xed-utils.c | 208 ++++++++++-------- xed/xed-window.c | 26 +-- 10 files changed, 485 insertions(+), 450 deletions(-) diff --git a/xed/xed-app.c b/xed/xed-app.c index 867ea89..5ca4f3c 100644 --- a/xed/xed-app.c +++ b/xed/xed-app.c @@ -329,7 +329,7 @@ app_weak_notify (gpointer data, * Returns the #XedApp object. This object is a singleton and * represents the running xed instance. * - * Return value: the #XedApp pointer + * Return value: (transfer none): the #XedApp pointer */ XedApp * xed_app_get_default (void) @@ -527,7 +527,7 @@ xed_app_create_window_real (XedApp *app, * * Create a new #XedWindow part of @app. * - * Return value: the new #XedWindow + * Return value: (transfer none): the new #XedWindow */ XedWindow * xed_app_create_window (XedApp *app, @@ -566,7 +566,7 @@ _xed_app_restore_window (XedApp *app, * * Returns all the windows currently present in #XedApp. * - * Return value: (transfer none): the list of #XedWindows objects. + * Return value: (element-type Xed.Window) (transfer none): the list of #XedWindows objects. * The list should not be freed */ const GList * @@ -583,7 +583,7 @@ xed_app_get_windows (XedApp *app) * * Retrives the #XedWindow currently active. * - * Return value: the active #XedWindow + * Return value: (transfer none): the active #XedWindow */ XedWindow * xed_app_get_active_window (XedApp *app) diff --git a/xed/xed-document.c b/xed/xed-document.c index 502631c..36bd176 100644 --- a/xed/xed-document.c +++ b/xed/xed-document.c @@ -1036,6 +1036,12 @@ set_uri (XedDocument *doc, } } +/** + * xed_document_get_location: + * @doc: a #XedDocument + * + * Returns: (allow-none) (transfer full): a new #GFile + */ GFile * xed_document_get_location (XedDocument *doc) { @@ -1736,7 +1742,7 @@ compute_num_of_lines (const gchar *text) } /** - * xed_document_set_search_text" + * xed_document_set_search_text: * @doc: * @text: (allow-none): * @flags: @@ -1835,7 +1841,7 @@ xed_document_get_can_search_again (XedDocument *doc) * @start: (allow-none): * @end: (allow-none): * @match_start: (allow-none): - * @match_end: (allow=none): + * @match_end: (allow-none): **/ gboolean xed_document_search_forward (XedDocument *doc, @@ -1920,7 +1926,7 @@ xed_document_search_forward (XedDocument *doc, * @start: (allow-none): * @end: (allow-none): * @match_start: (allow-none): - * @match_end: (allow=none): + * @match_end: (allow-none): **/ gboolean xed_document_search_backward (XedDocument *doc, @@ -2130,6 +2136,12 @@ xed_document_set_language (XedDocument *doc, set_language (doc, lang, TRUE); } +/** + * xed_document_get_language: + * @doc: + * + * Return value: (transfer none): + */ GtkSourceLanguage * xed_document_get_language (XedDocument *doc) { diff --git a/xed/xed-file-chooser-dialog.c b/xed/xed-file-chooser-dialog.c index abffce8..8c906f4 100644 --- a/xed/xed-file-chooser-dialog.c +++ b/xed/xed-file-chooser-dialog.c @@ -455,7 +455,7 @@ xed_file_chooser_dialog_new_valist (const gchar *title, * @action: Open or save mode for the dialog * @first_button_text: (allow-none): stock ID or text to go in * the first button, or %NULL - * @Varargs: (allow-none): response ID for the first button, then + * @...: (allow-none): response ID for the first button, then * additional (button, id) pairs, ending with %NULL * * Creates a new #XedFileChooserDialog. This function is analogous to diff --git a/xed/xed-message-bus.c b/xed/xed-message-bus.c index 5972ee7..6a51955 100644 --- a/xed/xed-message-bus.c +++ b/xed/xed-message-bus.c @@ -532,7 +532,7 @@ xed_message_bus_init (XedMessageBus *self) * * Get the default application #XedMessageBus. * - * Return value: the default #XedMessageBus + * Return value: (transfer none): the default #XedMessageBus * */ XedMessageBus * @@ -797,7 +797,7 @@ foreach_type (const gchar *key, /** * xed_message_bus_foreach: * @bus: the #XedMessagebus - * @func: the callback function + * @func: (scope call): the callback function * @userdata: the user data to supply to the callback function * * Calls @func for each message type registered on the bus @@ -875,7 +875,7 @@ xed_message_bus_disconnect (XedMessageBus *bus, * @bus: a #XedMessageBus * @object_path: the object path * @method: the method - * @callback: the connected callback + * @callback: (scope call): the connected callback * @userdata: the userdata with which the callback was connected * * Disconnects a previously connected message callback by matching the @@ -918,7 +918,7 @@ xed_message_bus_block (XedMessageBus *bus, * @bus: a #XedMessageBus * @object_path: the object path * @method: the method - * @callback: the callback to block + * @callback: (scope call): the callback to block * @userdata: the userdata with which the callback was connected * * Blocks evoking the callback that matches provided @callback and @userdata. @@ -959,7 +959,7 @@ xed_message_bus_unblock (XedMessageBus *bus, * @bus: a #XedMessageBus * @object_path: the object path * @method: the method - * @callback: the callback to block + * @callback: (scope call): the callback to block * @userdata: the userdata with which the callback was connected * * Unblocks the callback that matches provided @callback and @userdata. @@ -1134,7 +1134,7 @@ xed_message_bus_send (XedMessageBus *bus, * specifies key (string) value pairs used to construct the message * arguments. To send a message asynchronously use xed_message_bus_send(). * - * Return value: the constructed #XedMessage. The caller owns a reference + * Return value: (transfer full): the constructed #XedMessage. The caller owns a reference * to the #XedMessage and should call g_object_unref() when * it is no longer needed */ diff --git a/xed/xed-message-type.c b/xed/xed-message-type.c index 1ab1aa5..0211c22 100644 --- a/xed/xed-message-type.c +++ b/xed/xed-message-type.c @@ -10,12 +10,12 @@ * the Object Path, Method and Arguments of the message. * * A message type can contain any number of required and optional arguments. - * To instantiate a #XedMessage from a #XedMessageType, use + * To instantiate a #XedMessage from a #XedMessageType, use * xed_message_type_instantiate(). * * Registering a new message type on a #XedMessageBus with * xed_message_bus_register() internally creates a new #XedMessageType. When - * then using xed_message_bus_send(), an actual instantiation of the + * then using xed_message_bus_send(), an actual instantiation of the * registered type is internally created and send over the bus. * * @@ -50,10 +50,10 @@ struct _XedMessageType gchar *object_path; gchar *method; - + guint num_arguments; guint num_required; - + GHashTable *arguments; // mapping of key -> ArgumentInfo }; @@ -71,7 +71,7 @@ xed_message_type_ref (XedMessageType *message_type) { g_return_val_if_fail (message_type != NULL, NULL); g_atomic_int_inc (&message_type->ref_count); - + return message_type; } @@ -83,30 +83,30 @@ xed_message_type_ref (XedMessageType *message_type) * drops to 0, @message_type is destroyed. * */ -void +void xed_message_type_unref (XedMessageType *message_type) { g_return_if_fail (message_type != NULL); if (!g_atomic_int_dec_and_test (&message_type->ref_count)) return; - + g_free (message_type->object_path); g_free (message_type->method); - + g_hash_table_destroy (message_type->arguments); g_free (message_type); } /** * xed_message_type_get_type: - * + * * Retrieves the GType object which is associated with the * #XedMessageType class. - * + * * Return value: the GType associated with #XedMessageType. **/ -GType +GType xed_message_type_get_type (void) { static GType our_type = 0; @@ -151,17 +151,17 @@ xed_message_type_is_valid_object_path (const gchar *object_path) { if (!object_path) return FALSE; - + /* needs to start with / */ if (*object_path != '/') return FALSE; - + while (*object_path) { if (*object_path == '/') { ++object_path; - + if (!*object_path || !(g_ascii_isalpha (*object_path) || *object_path == '_')) return FALSE; } @@ -169,10 +169,10 @@ xed_message_type_is_valid_object_path (const gchar *object_path) { return FALSE; } - + ++object_path; } - + return TRUE; } @@ -189,7 +189,7 @@ gboolean xed_message_type_is_supported (GType type) { gint i = 0; - + static const GType type_list[] = { G_TYPE_BOOLEAN, @@ -252,7 +252,7 @@ xed_message_type_new_valist (const gchar *object_path, g_return_val_if_fail (xed_message_type_is_valid_object_path (object_path), NULL); message_type = g_new0(XedMessageType, 1); - + message_type->ref_count = 1; message_type->object_path = g_strdup(object_path); message_type->method = g_strdup(method); @@ -288,11 +288,11 @@ xed_message_type_new (const gchar *object_path, { XedMessageType *message_type; va_list var_args; - + va_start(var_args, num_optional); message_type = xed_message_type_new_valist (object_path, method, num_optional, var_args); va_end(var_args); - + return message_type; } @@ -313,7 +313,7 @@ xed_message_type_set (XedMessageType *message_type, ...) { va_list va_args; - + va_start (va_args, num_optional); xed_message_type_set_valist (message_type, num_optional, va_args); va_end (va_args); @@ -326,11 +326,11 @@ xed_message_type_set (XedMessageType *message_type, * @var_args: key/gtype pair variable argument list * * Sets argument names/types supplied by the NULL terminated variable - * argument list @var_args. The last @num_optional provided arguments are + * argument list @var_args. The last @num_optional provided arguments are * considered optional. * */ -void +void xed_message_type_set_valist (XedMessageType *message_type, guint num_optional, va_list var_args) @@ -346,35 +346,35 @@ xed_message_type_set_valist (XedMessageType *message_type, // get corresponding GType GType gtype = va_arg (var_args, GType); ArgumentInfo *info; - + if (!xed_message_type_is_supported (gtype)) { g_error ("Message type '%s' is not supported", g_type_name (gtype)); xed_message_type_unref (message_type); g_free (optional); - + return; } - + info = g_new(ArgumentInfo, 1); info->type = gtype; info->required = TRUE; g_hash_table_insert (message_type->arguments, g_strdup (key), info); - + ++message_type->num_arguments; ++added; - + if (num_optional > 0) { for (i = num_optional - 1; i > 0; --i) optional[i] = optional[i - 1]; - + *optional = info; } } - + message_type->num_required += added; // set required for last num_optional arguments @@ -386,7 +386,7 @@ xed_message_type_set_valist (XedMessageType *message_type, --message_type->num_required; } } - + g_free (optional); } @@ -398,7 +398,7 @@ xed_message_type_set_valist (XedMessageType *message_type, * Instantiate a new message from the message type with specific values * for the message arguments. * - * Return value: the newly created message + * Return value: (transfer full): the newly created message * */ XedMessage * @@ -406,12 +406,12 @@ xed_message_type_instantiate_valist (XedMessageType *message_type, va_list va_args) { XedMessage *message; - + g_return_val_if_fail (message_type != NULL, NULL); - + message = XED_MESSAGE (g_object_new (XED_TYPE_MESSAGE, "type", message_type, NULL)); xed_message_set_valist (message, va_args); - + return message; } @@ -423,7 +423,7 @@ xed_message_type_instantiate_valist (XedMessageType *message_type, * Instantiate a new message from the message type with specific values * for the message arguments. * - * Return value: the newly created message + * Return value: (transfer full): the newly created message * */ XedMessage * @@ -432,11 +432,11 @@ xed_message_type_instantiate (XedMessageType *message_type, { XedMessage *message; va_list va_args; - + va_start (va_args, message_type); message = xed_message_type_instantiate_valist (message_type, va_args); va_end (va_args); - + return message; } @@ -485,10 +485,10 @@ xed_message_type_lookup (XedMessageType *message_type, const gchar *key) { ArgumentInfo *info = g_hash_table_lookup (message_type->arguments, key); - + if (!info) return G_TYPE_INVALID; - + return info->type; } @@ -509,13 +509,13 @@ foreach_gtype (const gchar *key, /** * xed_message_type_foreach: * @message_type: the #XedMessageType - * @func: the callback function + * @func: (scope call): the callback function * @user_data: user data supplied to the callback function * * Calls @func for each argument in the message type. * */ -void +void xed_message_type_foreach (XedMessageType *message_type, XedMessageTypeForeach func, gpointer user_data) diff --git a/xed/xed-message.c b/xed/xed-message.c index 13dd947..24a2979 100644 --- a/xed/xed-message.c +++ b/xed/xed-message.c @@ -45,7 +45,7 @@ static void xed_message_finalize (GObject *object) { XedMessage *message = XED_MESSAGE (object); - + xed_message_type_unref (message->priv->type); g_hash_table_destroy (message->priv->values); @@ -102,16 +102,16 @@ add_value (XedMessage *message, { GValue *value; GType type = xed_message_type_lookup (message->priv->type, key); - + if (type == G_TYPE_INVALID) return NULL; - + value = g_new0 (GValue, 1); g_value_init (value, type); g_value_reset (value); g_hash_table_insert (message->priv->values, g_strdup (key), value); - + return value; } @@ -119,11 +119,11 @@ static void xed_message_class_init (XedMessageClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); - + object_class->finalize = xed_message_finalize; object_class->get_property = xed_message_get_property; object_class->set_property = xed_message_set_property; - + /** * XedMessage:object_path: * @@ -151,7 +151,7 @@ xed_message_class_init (XedMessageClass *klass) NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - + /** * XedMEssage:type: * @@ -189,17 +189,17 @@ xed_message_init (XedMessage *self) } static gboolean -set_value_real (GValue *to, +set_value_real (GValue *to, const GValue *from) { GType from_type; GType to_type; - + from_type = G_VALUE_TYPE (from); to_type = G_VALUE_TYPE (to); if (!g_type_is_a (from_type, to_type)) - { + { if (!g_value_transform (from, to)) { g_warning ("%s: Unable to make conversion from %s to %s", @@ -208,10 +208,10 @@ set_value_real (GValue *to, g_type_name (to_type)); return FALSE; } - + return TRUE; } - + g_value_copy (from, to); return TRUE; } @@ -222,10 +222,10 @@ value_lookup (XedMessage *message, gboolean create) { GValue *ret = (GValue *)g_hash_table_lookup (message->priv->values, key); - + if (!ret && create) ret = add_value (message, key); - + return ret; } @@ -242,7 +242,7 @@ const gchar * xed_message_get_method (XedMessage *message) { g_return_val_if_fail (XED_IS_MESSAGE (message), NULL); - + return xed_message_type_get_method (message->priv->type); } @@ -259,7 +259,7 @@ const gchar * xed_message_get_object_path (XedMessage *message) { g_return_val_if_fail (XED_IS_MESSAGE (message), NULL); - + return xed_message_type_get_object_path (message->priv->type); } @@ -308,21 +308,21 @@ xed_message_set_valist (XedMessage *message, GValue *container = value_lookup (message, key, TRUE); GValue value = {0,}; gchar *error = NULL; - + if (!container) { - g_warning ("%s: Cannot set value for %s, does not exist", + g_warning ("%s: Cannot set value for %s, does not exist", G_STRLOC, key); - + /* skip value */ va_arg (var_args, gpointer); continue; } - + g_value_init (&value, G_VALUE_TYPE (container)); G_VALUE_COLLECT (&value, var_args, 0, &error); - + if (error) { g_warning ("%s: %s", G_STRLOC, error); @@ -350,25 +350,25 @@ xed_message_set_value (XedMessage *message, { GValue *container; g_return_if_fail (XED_IS_MESSAGE (message)); - + container = value_lookup (message, key, TRUE); - + if (!container) { - g_warning ("%s: Cannot set value for %s, does not exist", - G_STRLOC, + g_warning ("%s: Cannot set value for %s, does not exist", + G_STRLOC, key); return; } - + set_value_real (container, value); } /** * xed_message_set_valuesv: * @message: the #XedMessage - * @keys: (array-length=n_values): keys to set values for - * @values: (array-length=n_values): values to set + * @keys: (array length=n_values): keys to set values for + * @values: (array length=n_values): values to set * @n_values: number of arguments to set values for * * Set message argument values. @@ -381,9 +381,9 @@ xed_message_set_valuesv (XedMessage *message, gint n_values) { gint i; - + g_return_if_fail (XED_IS_MESSAGE (message)); - + for (i = 0; i < n_values; i++) { xed_message_set_value (message, keys[i], &values[i]); @@ -401,14 +401,14 @@ xed_message_set_valuesv (XedMessage *message, * value for the specified key. * */ -void +void xed_message_get (XedMessage *message, ...) { va_list ap; g_return_if_fail (XED_IS_MESSAGE (message)); - + va_start (ap, message); xed_message_get_valist (message, ap); va_end (ap); @@ -431,7 +431,7 @@ xed_message_get_valist (XedMessage *message, const gchar *key; g_return_if_fail (XED_IS_MESSAGE (message)); - + while ((key = va_arg (var_args, const gchar *)) != NULL) { GValue *container; @@ -439,30 +439,30 @@ xed_message_get_valist (XedMessage *message, gchar *error = NULL; container = value_lookup (message, key, FALSE); - + if (!container) - { + { /* skip value */ va_arg (var_args, gpointer); continue; } - + /* copy the value here, to be sure it isn't tainted */ g_value_init (©, G_VALUE_TYPE (container)); g_value_copy (container, ©); - + G_VALUE_LCOPY (©, var_args, 0, &error); - + if (error) { g_warning ("%s: %s", G_STRLOC, error); g_free (error); - + /* purposely leak the value here, because it might be in a bad state */ continue; } - + g_value_unset (©); } } @@ -477,17 +477,17 @@ xed_message_get_valist (XedMessage *message, * with the correct type. * */ -void +void xed_message_get_value (XedMessage *message, const gchar *key, GValue *value) { GValue *container; - + g_return_if_fail (XED_IS_MESSAGE (message)); - + container = value_lookup (message, key, FALSE); - + if (!container) { g_warning ("%s: Invalid key `%s'", @@ -495,7 +495,7 @@ xed_message_get_value (XedMessage *message, key); return; } - + g_value_init (value, G_VALUE_TYPE (container)); set_value_real (value, container); } @@ -510,7 +510,7 @@ xed_message_get_value (XedMessage *message, * Return value: the type of @key * */ -GType +GType xed_message_get_key_type (XedMessage *message, const gchar *key) { @@ -535,14 +535,14 @@ xed_message_has_key (XedMessage *message, const gchar *key) { g_return_val_if_fail (XED_IS_MESSAGE (message), FALSE); - + return value_lookup (message, key, FALSE) != NULL; } typedef struct { XedMessage *message; - gboolean valid; + gboolean valid; } ValidateInfo; static void @@ -552,12 +552,12 @@ validate_key (const gchar *key, ValidateInfo *info) { GValue *value; - + if (!info->valid || !required) return; - + value = value_lookup (info->message, key, FALSE); - + if (!value) info->valid = FALSE; } @@ -578,16 +578,16 @@ xed_message_validate (XedMessage *message) g_return_val_if_fail (XED_IS_MESSAGE (message), FALSE); g_return_val_if_fail (message->priv->type != NULL, FALSE); - + if (!message->priv->valid) { - xed_message_type_foreach (message->priv->type, + xed_message_type_foreach (message->priv->type, (XedMessageTypeForeach)validate_key, &info); message->priv->valid = info.valid; } - + return message->priv->valid; } diff --git a/xed/xed-status-combo-box.c b/xed/xed-status-combo-box.c index b2b5bf3..bad9537 100644 --- a/xed/xed-status-combo-box.c +++ b/xed/xed-status-combo-box.c @@ -36,7 +36,7 @@ struct _XedStatusComboBoxPrivate GtkWidget *label; GtkWidget *item; GtkWidget *arrow; - + GtkWidget *menu; GtkWidget *current_item; }; @@ -54,10 +54,10 @@ enum }; /* Properties */ -enum +enum { PROP_0, - + PROP_LABEL }; @@ -131,7 +131,7 @@ xed_status_combo_box_changed (XedStatusComboBox *combo, GtkMenuItem *item) { const gchar *text; - + text = g_object_get_data (G_OBJECT (item), COMBO_BOX_TEXT_DATA); if (text != NULL) @@ -155,13 +155,13 @@ xed_status_combo_box_class_init (XedStatusComboBoxClass *klass) "-GtkWidget-focus-padding : 0;\n" "padding: 0;\n" "}"; - + object_class->finalize = xed_status_combo_box_finalize; object_class->get_property = xed_status_combo_box_get_property; object_class->set_property = xed_status_combo_box_set_property; widget_class->destroy = xed_status_combo_box_destroy; - + klass->changed = xed_status_combo_box_changed; signals[CHANGED] = @@ -172,7 +172,7 @@ xed_status_combo_box_class_init (XedStatusComboBoxClass *klass) changed), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GTK_TYPE_MENU_ITEM); - + g_object_class_install_property (object_class, PROP_LABEL, g_param_spec_string ("label", "LABEL", @@ -204,7 +204,7 @@ menu_position_func (GtkMenu *menu, { GtkRequisition request; GtkAllocation allocation; - + *push_in = FALSE; gtk_widget_get_preferred_size (gtk_widget_get_toplevel (GTK_WIDGET (menu)), &request, NULL); @@ -212,13 +212,13 @@ menu_position_func (GtkMenu *menu, /* get the origin... */ gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (combo)), x, y); gtk_widget_get_allocation (GTK_WIDGET (combo), &allocation); - + /* make the menu as wide as the widget */ if (request.width < allocation.width) { gtk_widget_set_size_request (GTK_WIDGET (menu), allocation.width, -1); } - + /* position it above the widget */ *y -= request.height; } @@ -310,12 +310,12 @@ xed_status_combo_box_init (XedStatusComboBox *self) GtkStyleContext *context; self->priv = XED_STATUS_COMBO_BOX_GET_PRIVATE (self); - + gtk_event_box_set_visible_window (GTK_EVENT_BOX (self), TRUE); self->priv->frame = gtk_frame_new (NULL); gtk_widget_show (self->priv->frame); - + self->priv->button = gtk_toggle_button_new (); gtk_button_set_relief (GTK_BUTTON (self->priv->button), GTK_RELIEF_NONE); gtk_widget_show (self->priv->button); @@ -324,27 +324,27 @@ xed_status_combo_box_init (XedStatusComboBox *self) self->priv->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3); gtk_widget_show (self->priv->hbox); - + gtk_container_add (GTK_CONTAINER (self), self->priv->frame); gtk_container_add (GTK_CONTAINER (self->priv->frame), self->priv->button); gtk_container_add (GTK_CONTAINER (self->priv->button), self->priv->hbox); - + self->priv->label = gtk_label_new (""); gtk_widget_show (self->priv->label); - + gtk_label_set_single_line_mode (GTK_LABEL (self->priv->label), TRUE); gtk_widget_set_halign (GTK_WIDGET (self->priv->label), GTK_ALIGN_START); gtk_box_pack_start (GTK_BOX (self->priv->hbox), self->priv->label, FALSE, TRUE, 0); - + self->priv->item = gtk_label_new (""); gtk_widget_show (self->priv->item); - + gtk_label_set_single_line_mode (GTK_LABEL (self->priv->item), TRUE); gtk_widget_set_halign (self->priv->item, GTK_ALIGN_START); gtk_box_pack_start (GTK_BOX (self->priv->hbox), self->priv->item, TRUE, TRUE, 0); - + self->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); gtk_widget_show (self->priv->arrow); @@ -352,15 +352,15 @@ xed_status_combo_box_init (XedStatusComboBox *self) gtk_widget_set_valign (self->priv->arrow, GTK_ALIGN_CENTER); gtk_box_pack_start (GTK_BOX (self->priv->hbox), self->priv->arrow, FALSE, TRUE, 0); - + self->priv->menu = gtk_menu_new (); gtk_menu_attach_to_widget (GTK_MENU (self->priv->menu), GTK_WIDGET (self), menu_detached); - g_signal_connect (self->priv->button, - "button-press-event", - G_CALLBACK (button_press_event), + g_signal_connect (self->priv->button, + "button-press-event", + G_CALLBACK (button_press_event), self); g_signal_connect (self->priv->menu, "deactivate", @@ -395,13 +395,13 @@ xed_status_combo_box_new (const gchar *label) * @label: (allow-none): */ void -xed_status_combo_box_set_label (XedStatusComboBox *combo, +xed_status_combo_box_set_label (XedStatusComboBox *combo, const gchar *label) { gchar *text; g_return_if_fail (XED_IS_STATUS_COMBO_BOX (combo)); - + text = g_strconcat (" ", label, ": ", NULL); gtk_label_set_markup (GTK_LABEL (combo->priv->label), text); g_free (text); @@ -437,7 +437,7 @@ xed_status_combo_box_add_item (XedStatusComboBox *combo, g_return_if_fail (GTK_IS_MENU_ITEM (item)); gtk_menu_shell_append (GTK_MENU_SHELL (combo->priv->menu), GTK_WIDGET (item)); - + xed_status_combo_box_set_item_text (combo, item, text); g_signal_connect (item, "activate", G_CALLBACK (item_activated), combo); } @@ -453,6 +453,13 @@ xed_status_combo_box_remove_item (XedStatusComboBox *combo, GTK_WIDGET (item)); } + +/** + * xed_status_combo_box_get_items: + * @combo: + * + * Returns: (element-type Gtk.Widget) (transfer container): + */ GList * xed_status_combo_box_get_items (XedStatusComboBox *combo) { @@ -466,12 +473,12 @@ xed_status_combo_box_get_item_text (XedStatusComboBox *combo, GtkMenuItem *item) { const gchar *ret = NULL; - + g_return_val_if_fail (XED_IS_STATUS_COMBO_BOX (combo), NULL); g_return_val_if_fail (GTK_IS_MENU_ITEM (item), NULL); - + ret = g_object_get_data (G_OBJECT (item), COMBO_BOX_TEXT_DATA); - + return ret; } @@ -481,7 +488,7 @@ xed_status_combo_box_get_item_text (XedStatusComboBox *combo, * @item: * @text: (allow-none): */ -void +void xed_status_combo_box_set_item_text (XedStatusComboBox *combo, GtkMenuItem *item, const gchar *text) @@ -489,7 +496,7 @@ xed_status_combo_box_set_item_text (XedStatusComboBox *combo, g_return_if_fail (XED_IS_STATUS_COMBO_BOX (combo)); g_return_if_fail (GTK_IS_MENU_ITEM (item)); - g_object_set_data_full (G_OBJECT (item), + g_object_set_data_full (G_OBJECT (item), COMBO_BOX_TEXT_DATA, g_strdup (text), (GDestroyNotify)g_free); @@ -509,7 +516,7 @@ GtkLabel * xed_status_combo_box_get_item_label (XedStatusComboBox *combo) { g_return_val_if_fail (XED_IS_STATUS_COMBO_BOX (combo), NULL); - + return GTK_LABEL (combo->priv->item); } diff --git a/xed/xed-tab.c b/xed/xed-tab.c index ddf6c7a..3a09ff4 100644 --- a/xed/xed-tab.c +++ b/xed/xed-tab.c @@ -2,7 +2,7 @@ * xed-tab.c * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. */ #ifdef HAVE_CONFIG_H @@ -52,7 +52,7 @@ struct _XedTabPrivate { XedTabState state; - + GtkWidget *view; GtkWidget *view_scrolled_window; @@ -67,7 +67,7 @@ struct _XedTabPrivate /* tmp data for loading */ gint tmp_line_pos; const XedEncoding *tmp_encoding; - + GTimer *timer; guint times_called; @@ -75,7 +75,7 @@ struct _XedTabPrivate gint auto_save_interval; guint auto_save_timeout; - + gint not_editable : 1; gint auto_save : 1; @@ -105,7 +105,7 @@ install_auto_save_timeout (XedTab *tab) g_return_if_fail (tab->priv->auto_save_timeout <= 0); g_return_if_fail (tab->priv->auto_save); g_return_if_fail (tab->priv->auto_save_interval > 0); - + g_return_if_fail (tab->priv->state != XED_TAB_STATE_LOADING); g_return_if_fail (tab->priv->state != XED_TAB_STATE_SAVING); g_return_if_fail (tab->priv->state != XED_TAB_STATE_REVERTING); @@ -128,7 +128,7 @@ install_auto_save_timeout_if_needed (XedTab *tab) XedDocument *doc; xed_debug (DEBUG_TAB); - + g_return_val_if_fail (tab->priv->auto_save_timeout <= 0, FALSE); g_return_val_if_fail ((tab->priv->state == XED_TAB_STATE_NORMAL) || (tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW) || @@ -139,15 +139,15 @@ install_auto_save_timeout_if_needed (XedTab *tab) doc = xed_tab_get_document (tab); - if (tab->priv->auto_save && + if (tab->priv->auto_save && !xed_document_is_untitled (doc) && !xed_document_get_readonly (doc)) - { + { install_auto_save_timeout (tab); - + return TRUE; } - + return FALSE; } @@ -157,9 +157,9 @@ remove_auto_save_timeout (XedTab *tab) xed_debug (DEBUG_TAB); /* FIXME: check sugli stati */ - + g_return_if_fail (tab->priv->auto_save_timeout > 0); - + g_source_remove (tab->priv->auto_save_timeout); tab->priv->auto_save_timeout = 0; } @@ -181,7 +181,7 @@ xed_tab_get_property (GObject *object, case PROP_STATE: g_value_set_enum (value, xed_tab_get_state (tab)); - break; + break; case PROP_AUTO_SAVE: g_value_set_boolean (value, xed_tab_get_auto_save_enabled (tab)); @@ -192,7 +192,7 @@ xed_tab_get_property (GObject *object, break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; + break; } } @@ -216,7 +216,7 @@ xed_tab_set_property (GObject *object, break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; + break; } } @@ -236,7 +236,7 @@ xed_tab_finalize (GObject *object) G_OBJECT_CLASS (xed_tab_parent_class)->finalize (object); } -static void +static void xed_tab_class_init (XedTabClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -244,7 +244,7 @@ xed_tab_class_init (XedTabClass *klass) object_class->finalize = xed_tab_finalize; object_class->get_property = xed_tab_get_property; object_class->set_property = xed_tab_set_property; - + g_object_class_install_property (object_class, PROP_NAME, g_param_spec_string ("name", @@ -299,7 +299,7 @@ XedTabState xed_tab_get_state (XedTab *tab) { g_return_val_if_fail (XED_IS_TAB (tab), XED_TAB_STATE_NORMAL); - + return tab->priv->state; } @@ -403,27 +403,27 @@ xed_tab_set_state (XedTab *tab, set_cursor_according_to_state (GTK_TEXT_VIEW (tab->priv->view), state); - g_object_notify (G_OBJECT (tab), "state"); + g_object_notify (G_OBJECT (tab), "state"); } -static void +static void document_uri_notify_handler (XedDocument *document, GParamSpec *pspec, XedTab *tab) { xed_debug (DEBUG_TAB); - + /* Notify the change in the URI */ g_object_notify (G_OBJECT (tab), "name"); } -static void +static void document_shortname_notify_handler (XedDocument *document, GParamSpec *pspec, XedTab *tab) { xed_debug (DEBUG_TAB); - + /* Notify the change in the shortname */ g_object_notify (G_OBJECT (tab), "name"); } @@ -454,9 +454,9 @@ set_message_area (XedTab *tab, tab->priv->message_area, FALSE, FALSE, - 0); + 0); - g_object_add_weak_pointer (G_OBJECT (tab->priv->message_area), + g_object_add_weak_pointer (G_OBJECT (tab->priv->message_area), (gpointer *)&tab->priv->message_area); } @@ -470,7 +470,7 @@ remove_tab (XedTab *tab) xed_notebook_remove_tab (notebook, tab); } -static void +static void io_loading_error_message_area_response (GtkWidget *message_area, gint response_id, XedTab *tab) @@ -530,26 +530,26 @@ io_loading_error_message_area_response (GtkWidget *message_area, g_free (uri); } -static void +static void file_already_open_warning_message_area_response (GtkWidget *message_area, gint response_id, XedTab *tab) { XedView *view; - + view = xed_tab_get_view (tab); - + if (response_id == GTK_RESPONSE_YES) { tab->priv->not_editable = FALSE; - + gtk_text_view_set_editable (GTK_TEXT_VIEW (view), TRUE); } gtk_widget_destroy (message_area); - gtk_widget_grab_focus (GTK_WIDGET (view)); + gtk_widget_grab_focus (GTK_WIDGET (view)); } static void @@ -558,19 +558,19 @@ load_cancelled (GtkWidget *area, XedTab *tab) { g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); - + g_object_ref (tab); xed_document_load_cancel (xed_tab_get_document (tab)); - g_object_unref (tab); + g_object_unref (tab); } -static void +static void unrecoverable_reverting_error_message_area_response (GtkWidget *message_area, gint response_id, XedTab *tab) { XedView *view; - + xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); @@ -579,8 +579,8 @@ unrecoverable_reverting_error_message_area_response (GtkWidget *message_a view = xed_tab_get_view (tab); gtk_widget_grab_focus (GTK_WIDGET (view)); - - install_auto_save_timeout_if_needed (tab); + + install_auto_save_timeout_if_needed (tab); } #define MAX_MSG_LENGTH 100 @@ -601,7 +601,7 @@ show_loading_message_area (XedTab *tab) return; xed_debug (DEBUG_TAB); - + doc = xed_tab_get_document (tab); g_return_if_fail (doc != NULL); @@ -637,7 +637,7 @@ show_loading_message_area (XedTab *tab) * we have a title long 99 + 20, but I think it's a rare enough * case to be acceptable. It's justa darn title afterall :) */ - dirname = xed_utils_str_middle_truncate (str, + dirname = xed_utils_str_middle_truncate (str, MAX (20, MAX_MSG_LENGTH - len)); g_free (str); } @@ -660,10 +660,10 @@ show_loading_message_area (XedTab *tab) } else { - msg = g_strdup_printf (_("Reverting %s"), + msg = g_strdup_printf (_("Reverting %s"), name_markup); } - + area = xed_progress_message_area_new (GTK_STOCK_REVERT_TO_SAVED, msg, TRUE); @@ -683,7 +683,7 @@ show_loading_message_area (XedTab *tab) } else { - msg = g_strdup_printf (_("Loading %s"), + msg = g_strdup_printf (_("Loading %s"), name_markup); } @@ -696,7 +696,7 @@ show_loading_message_area (XedTab *tab) "response", G_CALLBACK (load_cancelled), tab); - + gtk_widget_show (area); set_message_area (tab, area); @@ -721,12 +721,12 @@ show_saving_message_area (XedTab *tab) gint len; g_return_if_fail (tab->priv->tmp_save_uri != NULL); - + if (tab->priv->message_area != NULL) return; - + xed_debug (DEBUG_TAB); - + doc = xed_tab_get_document (tab); g_return_if_fail (doc != NULL); @@ -739,7 +739,7 @@ show_saving_message_area (XedTab *tab) */ if (len > MAX_MSG_LENGTH) { - from = xed_utils_str_middle_truncate (short_name, + from = xed_utils_str_middle_truncate (short_name, MAX_MSG_LENGTH); g_free (short_name); } @@ -751,10 +751,10 @@ show_saving_message_area (XedTab *tab) to = xed_utils_uri_for_display (tab->priv->tmp_save_uri); - str = xed_utils_str_middle_truncate (to, + str = xed_utils_str_middle_truncate (to, MAX (20, MAX_MSG_LENGTH - len)); g_free (to); - + to = str; } @@ -801,12 +801,12 @@ message_area_set_progress (XedTab *tab, xed_debug_message (DEBUG_TAB, "%" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, size, total_size); g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); - + if (total_size == 0) { if (size != 0) xed_progress_message_area_pulse ( - XED_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); + XED_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); else xed_progress_message_area_set_fraction ( XED_PROGRESS_MESSAGE_AREA (tab->priv->message_area), @@ -820,7 +820,7 @@ message_area_set_progress (XedTab *tab, xed_progress_message_area_set_fraction ( XED_PROGRESS_MESSAGE_AREA (tab->priv->message_area), - frac); + frac); } } @@ -906,7 +906,7 @@ document_loaded (XedDocument *document, error->code == G_IO_ERROR_CANCELLED) { /* remove the tab, but in an idle handler, since - * we are in the handler of doc loaded and we + * we are in the handler of doc loaded and we * don't want doc and tab to be finalized now. */ g_idle_add ((GSourceFunc) remove_tab_idle, tab); @@ -930,7 +930,7 @@ document_loaded (XedDocument *document, else { g_return_if_fail (tab->priv->state == XED_TAB_STATE_REVERTING_ERROR); - + emsg = xed_unrecoverable_reverting_error_message_area_new (uri, error); @@ -1000,7 +1000,7 @@ document_loaded (XedDocument *document, for (l = all_documents; l != NULL; l = g_list_next (l)) { XedDocument *d = XED_DOCUMENT (l->data); - + if (d != document) { GFile *loc; @@ -1034,7 +1034,7 @@ document_loaded (XedDocument *document, g_object_unref (loc); break; } - + if (loc != NULL) g_object_unref (loc); } @@ -1043,7 +1043,7 @@ document_loaded (XedDocument *document, g_list_free (all_documents); xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); - + install_auto_save_timeout_if_needed (tab); tab->priv->ask_if_externally_modified = TRUE; @@ -1099,32 +1099,32 @@ end_saving (XedTab *tab) g_free (tab->priv->tmp_save_uri); tab->priv->tmp_save_uri = NULL; tab->priv->tmp_encoding = NULL; - + install_auto_save_timeout_if_needed (tab); } -static void +static void unrecoverable_saving_error_message_area_response (GtkWidget *message_area, gint response_id, XedTab *tab) { XedView *view; - + if (tab->priv->print_preview != NULL) xed_tab_set_state (tab, XED_TAB_STATE_SHOWING_PRINT_PREVIEW); else xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); end_saving (tab); - + set_message_area (tab, NULL); view = xed_tab_get_view (tab); - gtk_widget_grab_focus (GTK_WIDGET (view)); + gtk_widget_grab_focus (GTK_WIDGET (view)); } -static void +static void no_backup_error_message_area_response (GtkWidget *message_area, gint response_id, XedTab *tab) @@ -1147,7 +1147,7 @@ no_backup_error_message_area_response (GtkWidget *message_area, tab->priv->save_flags |= XED_DOCUMENT_SAVE_IGNORE_BACKUP; g_return_if_fail (tab->priv->auto_save_timeout <= 0); - + /* Force saving */ xed_document_save (doc, tab->priv->save_flags); } @@ -1170,7 +1170,7 @@ externally_modified_error_message_area_response (GtkWidget *message_area, doc = xed_tab_get_document (tab); g_return_if_fail (XED_IS_DOCUMENT (doc)); - + set_message_area (tab, NULL); g_return_if_fail (tab->priv->tmp_save_uri != NULL); @@ -1179,21 +1179,21 @@ externally_modified_error_message_area_response (GtkWidget *message_area, xed_tab_set_state (tab, XED_TAB_STATE_SAVING); g_return_if_fail (tab->priv->auto_save_timeout <= 0); - + /* ignore mtime should not be persisted in save flags across saves */ /* Force saving */ xed_document_save (doc, tab->priv->save_flags | XED_DOCUMENT_SAVE_IGNORE_MTIME); } else - { + { unrecoverable_saving_error_message_area_response (message_area, response_id, tab); } } -static void +static void recoverable_saving_error_message_area_response (GtkWidget *message_area, gint response_id, XedTab *tab) @@ -1202,11 +1202,11 @@ recoverable_saving_error_message_area_response (GtkWidget *message_area, doc = xed_tab_get_document (tab); g_return_if_fail (XED_IS_DOCUMENT (doc)); - + if (response_id == GTK_RESPONSE_OK) { const XedEncoding *encoding; - + encoding = xed_conversion_error_message_area_get_encoding ( GTK_WIDGET (message_area)); @@ -1215,22 +1215,22 @@ recoverable_saving_error_message_area_response (GtkWidget *message_area, set_message_area (tab, NULL); g_return_if_fail (tab->priv->tmp_save_uri != NULL); - + xed_tab_set_state (tab, XED_TAB_STATE_SAVING); - + tab->priv->tmp_encoding = encoding; xed_debug_message (DEBUG_TAB, "Force saving with URI '%s'", tab->priv->tmp_save_uri); - + g_return_if_fail (tab->priv->auto_save_timeout <= 0); - + xed_document_save_as (doc, tab->priv->tmp_save_uri, tab->priv->tmp_encoding, tab->priv->save_flags); } else - { + { unrecoverable_saving_error_message_area_response (message_area, response_id, tab); @@ -1247,25 +1247,25 @@ document_saved (XedDocument *document, g_return_if_fail (tab->priv->state == XED_TAB_STATE_SAVING); g_return_if_fail (tab->priv->tmp_save_uri != NULL); - g_return_if_fail (tab->priv->tmp_encoding != NULL); + g_return_if_fail (tab->priv->tmp_encoding != NULL); g_return_if_fail (tab->priv->auto_save_timeout <= 0); - + g_timer_destroy (tab->priv->timer); tab->priv->timer = NULL; tab->priv->times_called = 0; - + set_message_area (tab, NULL); - + if (error != NULL) { xed_tab_set_state (tab, XED_TAB_STATE_SAVING_ERROR); - + if (error->domain == XED_DOCUMENT_ERROR && error->code == XED_DOCUMENT_ERROR_EXTERNALLY_MODIFIED) { /* This error is recoverable */ emsg = xed_externally_modified_saving_error_message_area_new ( - tab->priv->tmp_save_uri, + tab->priv->tmp_save_uri, error); g_return_if_fail (emsg != NULL); @@ -1283,7 +1283,7 @@ document_saved (XedDocument *document, { /* This error is recoverable */ emsg = xed_no_backup_saving_error_message_area_new ( - tab->priv->tmp_save_uri, + tab->priv->tmp_save_uri, error); g_return_if_fail (emsg != NULL); @@ -1303,10 +1303,10 @@ document_saved (XedDocument *document, _xed_recent_remove (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), tab->priv->tmp_save_uri); - emsg = xed_unrecoverable_saving_error_message_area_new (tab->priv->tmp_save_uri, + emsg = xed_unrecoverable_saving_error_message_area_new (tab->priv->tmp_save_uri, error); g_return_if_fail (emsg != NULL); - + set_message_area (tab, emsg); g_signal_connect (emsg, @@ -1353,12 +1353,12 @@ document_saved (XedDocument *document, xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); tab->priv->ask_if_externally_modified = TRUE; - + end_saving (tab); } } -static void +static void externally_modified_notification_message_area_response (GtkWidget *message_area, gint response_id, XedTab *tab) @@ -1483,7 +1483,7 @@ xed_tab_init (XedTab *tab) gtk_orientable_set_orientation (GTK_ORIENTABLE (tab), GTK_ORIENTATION_VERTICAL); - + /* Create the scrolled window */ sw = gtk_scrolled_window_new (NULL, NULL); tab->priv->view_scrolled_window = sw; @@ -1563,12 +1563,12 @@ _xed_tab_new (void) return GTK_WIDGET (g_object_new (XED_TYPE_TAB, NULL)); } -/* Whether create is TRUE, creates a new empty document if location does +/* Whether create is TRUE, creates a new empty document if location does not refer to an existing file */ GtkWidget * _xed_tab_new_from_uri (const gchar *uri, const XedEncoding *encoding, - gint line_pos, + gint line_pos, gboolean create) { XedTab *tab; @@ -1584,7 +1584,7 @@ _xed_tab_new_from_uri (const gchar *uri, create); return GTK_WIDGET (tab); -} +} /** * xed_tab_get_view: @@ -1592,7 +1592,7 @@ _xed_tab_new_from_uri (const gchar *uri, * * Gets the #XedView inside @tab. * - * Returns: the #XedView inside @tab + * Returns: (transfer none): the #XedView inside @tab */ XedView * xed_tab_get_view (XedTab *tab) @@ -1606,7 +1606,7 @@ xed_tab_get_view (XedTab *tab) * * Gets the #XedDocument associated to @tab. * - * Returns: the #XedDocument associated to @tab + * Returns: (transfer none): the #XedDocument associated to @tab */ XedDocument * xed_tab_get_document (XedTab *tab) @@ -1637,23 +1637,23 @@ _xed_tab_get_name (XedTab *tab) if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc))) { tab_name = g_strdup_printf ("*%s", docname); - } - else + } + else { - #if 0 - if (xed_document_get_readonly (doc)) + #if 0 + if (xed_document_get_readonly (doc)) { - tab_name = g_strdup_printf ("%s [%s]", docname, + tab_name = g_strdup_printf ("%s [%s]", docname, /*Read only*/ _("RO")); - } - else + } + else { tab_name = g_strdup_printf ("%s", docname); } #endif tab_name = g_strdup (docname); } - + g_free (docname); g_free (name); @@ -1686,7 +1686,7 @@ _xed_tab_get_tooltips (XedTab *tab) gchar *content_type; gchar *mime_type; gchar *content_description; - gchar *content_full_description; + gchar *content_full_description; gchar *encoding; const XedEncoding *enc; @@ -1698,12 +1698,12 @@ _xed_tab_get_tooltips (XedTab *tab) case XED_TAB_STATE_REVERTING_ERROR: tip = g_strdup_printf (_("Error reverting file %s"), ruri_markup); - break; + break; case XED_TAB_STATE_SAVING_ERROR: tip = g_strdup_printf (_("Error saving file %s"), ruri_markup); - break; + break; default: content_type = xed_document_get_content_type (doc); mime_type = xed_document_get_mime_type (doc); @@ -1712,7 +1712,7 @@ _xed_tab_get_tooltips (XedTab *tab) if (content_description == NULL) content_full_description = g_strdup (mime_type); else - content_full_description = g_strdup_printf ("%s (%s)", + content_full_description = g_strdup_printf ("%s (%s)", content_description, mime_type); g_free (content_type); @@ -1739,9 +1739,9 @@ _xed_tab_get_tooltips (XedTab *tab) break; } - g_free (ruri); + g_free (ruri); g_free (ruri_markup); - + return tip; } @@ -1751,28 +1751,28 @@ resize_icon (GdkPixbuf *pixbuf, { gint width, height; - width = gdk_pixbuf_get_width (pixbuf); + width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); /* if the icon is larger than the nominal size, scale down */ - if (MAX (width, height) > size) + if (MAX (width, height) > size) { GdkPixbuf *scaled_pixbuf; - - if (width > height) + + if (width > height) { height = height * size / width; width = size; - } - else + } + else { width = width * size / height; height = size; } - - scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf, - width, - height, + + scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf, + width, + height, GDK_INTERP_BILINEAR); g_object_unref (pixbuf); pixbuf = scaled_pixbuf; @@ -1782,21 +1782,21 @@ resize_icon (GdkPixbuf *pixbuf, } static GdkPixbuf * -get_stock_icon (GtkIconTheme *theme, +get_stock_icon (GtkIconTheme *theme, const gchar *stock, gint size) { GdkPixbuf *pixbuf; - + pixbuf = gtk_icon_theme_load_icon (theme, stock, size, 0, NULL); if (pixbuf == NULL) return NULL; - + return resize_icon (pixbuf, size); } static GdkPixbuf * -get_icon (GtkIconTheme *theme, +get_icon (GtkIconTheme *theme, GFile *location, gint size) { @@ -1809,10 +1809,10 @@ get_icon (GtkIconTheme *theme, return get_stock_icon (theme, GTK_STOCK_FILE, size); /* FIXME: Doing a sync stat is bad, this should be fixed */ - info = g_file_query_info (location, - G_FILE_ATTRIBUTE_STANDARD_ICON, - G_FILE_QUERY_INFO_NONE, - NULL, + info = g_file_query_info (location, + G_FILE_ATTRIBUTE_STANDARD_ICON, + G_FILE_QUERY_INFO_NONE, + NULL, NULL); if (info == NULL) return get_stock_icon (theme, GTK_STOCK_FILE, size); @@ -1826,17 +1826,17 @@ get_icon (GtkIconTheme *theme, } icon_info = gtk_icon_theme_lookup_by_gicon (theme, gicon, size, 0); - g_object_unref (info); - + g_object_unref (info); + if (icon_info == NULL) return get_stock_icon (theme, GTK_STOCK_FILE, size); - + pixbuf = gtk_icon_info_load_icon (icon_info, NULL); gtk_icon_info_free (icon_info); - + if (pixbuf == NULL) return get_stock_icon (theme, GTK_STOCK_FILE, size); - + return resize_icon (pixbuf, size); } @@ -1862,33 +1862,33 @@ _xed_tab_get_icon (XedTab *tab) switch (tab->priv->state) { case XED_TAB_STATE_LOADING: - pixbuf = get_stock_icon (theme, - GTK_STOCK_OPEN, + pixbuf = get_stock_icon (theme, + GTK_STOCK_OPEN, icon_size); break; case XED_TAB_STATE_REVERTING: - pixbuf = get_stock_icon (theme, - GTK_STOCK_REVERT_TO_SAVED, - icon_size); + pixbuf = get_stock_icon (theme, + GTK_STOCK_REVERT_TO_SAVED, + icon_size); break; case XED_TAB_STATE_SAVING: - pixbuf = get_stock_icon (theme, - GTK_STOCK_SAVE, + pixbuf = get_stock_icon (theme, + GTK_STOCK_SAVE, icon_size); break; case XED_TAB_STATE_PRINTING: - pixbuf = get_stock_icon (theme, - GTK_STOCK_PRINT, + pixbuf = get_stock_icon (theme, + GTK_STOCK_PRINT, icon_size); break; case XED_TAB_STATE_PRINT_PREVIEWING: - case XED_TAB_STATE_SHOWING_PRINT_PREVIEW: - pixbuf = get_stock_icon (theme, - GTK_STOCK_PRINT_PREVIEW, + case XED_TAB_STATE_SHOWING_PRINT_PREVIEW: + pixbuf = get_stock_icon (theme, + GTK_STOCK_PRINT_PREVIEW, icon_size); break; @@ -1896,8 +1896,8 @@ _xed_tab_get_icon (XedTab *tab) case XED_TAB_STATE_REVERTING_ERROR: case XED_TAB_STATE_SAVING_ERROR: case XED_TAB_STATE_GENERIC_ERROR: - pixbuf = get_stock_icon (theme, - GTK_STOCK_DIALOG_ERROR, + pixbuf = get_stock_icon (theme, + GTK_STOCK_DIALOG_ERROR, icon_size); break; @@ -1931,17 +1931,17 @@ _xed_tab_get_icon (XedTab *tab) * * Gets the #XedTab associated with @doc. * - * Returns: the #XedTab associated with @doc + * Returns: (transfer none): the #XedTab associated with @doc */ XedTab * xed_tab_get_from_document (XedDocument *doc) { gpointer res; - + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - + res = g_object_get_data (G_OBJECT (doc), XED_TAB_KEY); - + return (res != NULL) ? XED_TAB (res) : NULL; } @@ -2049,11 +2049,11 @@ _xed_tab_save (XedTab *tab) /* uri used in error messages, will be freed in document_saved */ tab->priv->tmp_save_uri = xed_document_get_uri (doc); - tab->priv->tmp_encoding = xed_document_get_encoding (doc); + tab->priv->tmp_encoding = xed_document_get_encoding (doc); if (tab->priv->auto_save_timeout > 0) remove_auto_save_timeout (tab); - + xed_document_save (doc, save_flags); } @@ -2063,12 +2063,12 @@ xed_tab_auto_save (XedTab *tab) XedDocument *doc; xed_debug (DEBUG_TAB); - + g_return_val_if_fail (tab->priv->tmp_save_uri == NULL, FALSE); g_return_val_if_fail (tab->priv->tmp_encoding == NULL, FALSE); - + doc = xed_tab_get_document (tab); - + g_return_val_if_fail (!xed_document_is_untitled (doc), FALSE); g_return_val_if_fail (!xed_document_get_readonly (doc), FALSE); @@ -2082,7 +2082,7 @@ xed_tab_auto_save (XedTab *tab) return TRUE; } - + if ((tab->priv->state != XED_TAB_STATE_NORMAL) && (tab->priv->state != XED_TAB_STATE_SHOWING_PRINT_PREVIEW)) { @@ -2101,12 +2101,12 @@ xed_tab_auto_save (XedTab *tab) /* Returns FALSE so the old timeout is "destroyed" */ return FALSE; } - + xed_tab_set_state (tab, XED_TAB_STATE_SAVING); /* uri used in error messages, will be freed in document_saved */ tab->priv->tmp_save_uri = xed_document_get_uri (doc); - tab->priv->tmp_encoding = xed_document_get_encoding (doc); + tab->priv->tmp_encoding = xed_document_get_encoding (doc); /* Set auto_save_timeout to 0 since the timeout is going to be destroyed */ tab->priv->auto_save_timeout = 0; @@ -2116,9 +2116,9 @@ xed_tab_auto_save (XedTab *tab) error happens while saving, the last backup is not preserved since the user expressed his willing of saving the file */ xed_document_save (doc, tab->priv->save_flags | XED_DOCUMENT_SAVE_PRESERVE_BACKUP); - + xed_debug_message (DEBUG_TAB, "Done"); - + /* Returns FALSE so the old timeout is "destroyed" */ return FALSE; } @@ -2245,7 +2245,7 @@ printing_cb (XedPrintJob *job, XedPrintJobStatus status, XedTab *tab) { - g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); + g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); gtk_widget_show (tab->priv->message_area); @@ -2368,9 +2368,9 @@ print_preview_destroyed (GtkWidget *preview, * preview. In this case let us continue whithout changing * the state and show the document. See bug #352658 */ gtk_widget_show (tab->priv->view_scrolled_window); - + g_return_if_fail (tab->priv->state == XED_TAB_STATE_PRINTING); - } + } } #endif @@ -2397,7 +2397,7 @@ show_preview_cb (XedPrintJob *job, g_signal_connect (tab->priv->print_preview, "destroy", G_CALLBACK (print_preview_destroyed), - tab); + tab); */ xed_tab_set_state (tab, XED_TAB_STATE_SHOWING_PRINT_PREVIEW); } @@ -2410,7 +2410,7 @@ set_print_preview (XedTab *tab, { if (tab->priv->print_preview == print_preview) return; - + if (tab->priv->print_preview != NULL) gtk_widget_destroy (tab->priv->print_preview); @@ -2420,7 +2420,7 @@ set_print_preview (XedTab *tab, tab->priv->print_preview, TRUE, TRUE, - 0); + 0); gtk_widget_grab_focus (tab->priv->print_preview); @@ -2438,17 +2438,17 @@ preview_finished_cb (GtkSourcePrintJob *pjob, XedTab *tab) g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); set_message_area (tab, NULL); /* destroy the message area */ - + gjob = gtk_source_print_job_get_print_job (pjob); - preview = xed_print_job_preview_new (gjob); + preview = xed_print_job_preview_new (gjob); g_object_unref (gjob); - + set_print_preview (tab, preview); - + gtk_widget_show (preview); g_object_unref (pjob); - + xed_tab_set_state (tab, XED_TAB_STATE_SHOWING_PRINT_PREVIEW); } @@ -2485,7 +2485,7 @@ show_printing_message_area (XedTab *tab, gboolean preview) "response", G_CALLBACK (print_cancelled), tab); - + set_message_area (tab, area); } @@ -2508,7 +2508,7 @@ xed_tab_print_or_print_preview (XedTab *tab, is_preview = (print_action == GTK_PRINT_OPERATION_ACTION_PREVIEW); tab->priv->print_job = xed_print_job_new (view); - g_object_add_weak_pointer (G_OBJECT (tab->priv->print_job), + g_object_add_weak_pointer (G_OBJECT (tab->priv->print_job), (gpointer *) &tab->priv->print_job); show_printing_message_area (tab, is_preview); @@ -2552,7 +2552,7 @@ xed_tab_print_or_print_preview (XedTab *tab, } } -void +void _xed_tab_print (XedTab *tab) { g_return_if_fail (XED_IS_TAB (tab)); @@ -2578,12 +2578,12 @@ _xed_tab_print_preview (XedTab *tab) GTK_PRINT_OPERATION_ACTION_PREVIEW); } -void +void _xed_tab_mark_for_closing (XedTab *tab) { g_return_if_fail (XED_IS_TAB (tab)); g_return_if_fail (tab->priv->state == XED_TAB_STATE_NORMAL); - + xed_tab_set_state (tab, XED_TAB_STATE_CLOSING); } @@ -2607,7 +2607,7 @@ _xed_tab_can_close (XedTab *tab) /* Do not close tab with saving errors */ if (ts == XED_TAB_STATE_SAVING_ERROR) return FALSE; - + doc = xed_tab_get_document (tab); /* TODO: we need to save the file also if it has been externally @@ -2620,9 +2620,9 @@ _xed_tab_can_close (XedTab *tab) /** * xed_tab_get_auto_save_enabled: * @tab: a #XedTab - * + * * Gets the current state for the autosave feature - * + * * Return value: %TRUE if the autosave is enabled, else %FALSE **/ gboolean @@ -2639,12 +2639,12 @@ xed_tab_get_auto_save_enabled (XedTab *tab) * xed_tab_set_auto_save_enabled: * @tab: a #XedTab * @enable: enable (%TRUE) or disable (%FALSE) auto save - * + * * Enables or disables the autosave feature. It does not install an * autosave timeout if the document is new or is read-only **/ void -xed_tab_set_auto_save_enabled (XedTab *tab, +xed_tab_set_auto_save_enabled (XedTab *tab, gboolean enable) { XedDocument *doc = NULL; @@ -2659,7 +2659,7 @@ xed_tab_set_auto_save_enabled (XedTab *tab, tab->priv->auto_save = enable; - if (enable && + if (enable && (tab->priv->auto_save_timeout <=0) && !xed_document_is_untitled (doc) && !xed_document_get_readonly (doc)) @@ -2675,30 +2675,30 @@ xed_tab_set_auto_save_enabled (XedTab *tab, } /* else: the timeout will be installed when loading/saving/reverting will terminate */ - + return; } - + if (!enable && (tab->priv->auto_save_timeout > 0)) { remove_auto_save_timeout (tab); - - return; - } - g_return_if_fail ((!enable && (tab->priv->auto_save_timeout <= 0)) || - xed_document_is_untitled (doc) || xed_document_get_readonly (doc)); + return; + } + + g_return_if_fail ((!enable && (tab->priv->auto_save_timeout <= 0)) || + xed_document_is_untitled (doc) || xed_document_get_readonly (doc)); } /** * xed_tab_get_auto_save_interval: * @tab: a #XedTab - * + * * Gets the current interval for the autosaves - * + * * Return value: the value of the autosave **/ -gint +gint xed_tab_get_auto_save_interval (XedTab *tab) { xed_debug (DEBUG_TAB); @@ -2712,20 +2712,20 @@ xed_tab_get_auto_save_interval (XedTab *tab) * xed_tab_set_auto_save_interval: * @tab: a #XedTab * @interval: the new interval - * + * * Sets the interval for the autosave feature. It does nothing if the * interval is the same as the one already present. It removes the old * interval timeout and adds a new one with the autosave passed as * argument. **/ -void -xed_tab_set_auto_save_interval (XedTab *tab, +void +xed_tab_set_auto_save_interval (XedTab *tab, gint interval) { XedDocument *doc = NULL; - + xed_debug (DEBUG_TAB); - + g_return_if_fail (XED_IS_TAB (tab)); doc = xed_tab_get_document(tab); @@ -2737,7 +2737,7 @@ xed_tab_set_auto_save_interval (XedTab *tab, return; tab->priv->auto_save_interval = interval; - + if (!tab->priv->auto_save) return; diff --git a/xed/xed-utils.c b/xed/xed-utils.c index 600ff50..5fb81c1 100644 --- a/xed/xed-utils.c +++ b/xed/xed-utils.c @@ -3,8 +3,8 @@ * This file is part of xed * * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence - * Copyright (C) 2000, 2002 Chema Celorio, Paolo Maggi - * Copyright (C) 2003-2005 Paolo Maggi + * Copyright (C) 2000, 2002 Chema Celorio, Paolo Maggi + * Copyright (C) 2003-2005 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,14 +18,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 1998-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 1998-2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -74,7 +74,7 @@ xed_utils_uri_has_file_scheme (const gchar *uri) gfile = g_file_new_for_uri (uri); res = g_file_has_uri_scheme (gfile, "file"); - + g_object_unref (gfile); return res; } @@ -163,7 +163,7 @@ xed_utils_menu_position_under_tree_view (GtkMenu *menu, GtkTreeModel *model; GtkTreeSelection *selection; GtkTreeIter iter; - + model = gtk_tree_view_get_model (tree); g_return_if_fail (model != NULL); @@ -176,16 +176,16 @@ xed_utils_menu_position_under_tree_view (GtkMenu *menu, GdkRectangle rect; widget_get_origin (GTK_WIDGET (tree), x, y); - + path = gtk_tree_model_get_path (model, &iter); gtk_tree_view_get_cell_area (tree, path, gtk_tree_view_get_column (tree, 0), /* FIXME 0 for RTL ? */ &rect); gtk_tree_path_free (path); - + *x += rect.x; *y += rect.y + rect.height; - + if (gtk_widget_get_direction (GTK_WIDGET (tree)) == GTK_TEXT_DIR_RTL) { GtkRequisition requisition; @@ -204,15 +204,22 @@ xed_utils_menu_position_under_tree_view (GtkMenu *menu, } /* FIXME: remove this with gtk 2.12, it has gdk_color_to_string */ -gchar * +gchar * xed_gdk_color_to_string (GdkColor color) { return g_strdup_printf ("#%04x%04x%04x", - color.red, + color.red, color.green, color.blue); } +/** + * xed_gtk_button_new_with_stock_icon: + * @label: + * @stock_id: + * + * Returns: (transfer full): + */ GtkWidget * xed_gtk_button_new_with_stock_icon (const gchar *label, const gchar *stock_id) @@ -227,6 +234,15 @@ xed_gtk_button_new_with_stock_icon (const gchar *label, return button; } +/** + * xed_dialog_add_button: + * @dialog: + * @text: + * @stock_id: + * @response_id: + * + * Returns: (transfer none): + */ GtkWidget * xed_dialog_add_button (GtkDialog *dialog, const gchar *text, @@ -246,7 +262,7 @@ xed_dialog_add_button (GtkDialog *dialog, gtk_widget_show (button); - gtk_dialog_add_action_widget (dialog, button, response_id); + gtk_dialog_add_action_widget (dialog, button, response_id); return button; } @@ -254,7 +270,7 @@ xed_dialog_add_button (GtkDialog *dialog, /* * n: len of the string in bytes */ -gboolean +gboolean g_utf8_caselessnmatch (const char *s1, const char *s2, gssize n1, gssize n2) { gchar *casefold; @@ -284,10 +300,10 @@ g_utf8_caselessnmatch (const char *s1, const char *s2, gssize n1, gssize n2) goto finally_2; ret = (strncmp (normalized_s1, normalized_s2, len_s2) == 0); - + finally_2: g_free (normalized_s1); - g_free (normalized_s2); + g_free (normalized_s2); return ret; } @@ -302,7 +318,7 @@ finally_2: * for a specified gtk widget. */ void -xed_utils_set_atk_name_description (GtkWidget *widget, +xed_utils_set_atk_name_description (GtkWidget *widget, const gchar *name, const gchar *description) { @@ -330,8 +346,8 @@ xed_utils_set_atk_name_description (GtkWidget *widget, * between 2 specified widgets. */ void -xed_utils_set_atk_relation (GtkWidget *obj1, - GtkWidget *obj2, +xed_utils_set_atk_relation (GtkWidget *obj1, + GtkWidget *obj2, AtkRelationType rel_type ) { AtkObject *atk_obj1, *atk_obj2; @@ -359,9 +375,9 @@ xed_utils_uri_exists (const gchar* text_uri) { GFile *gfile; gboolean res; - + g_return_val_if_fail (text_uri != NULL, FALSE); - + xed_debug_message (DEBUG_UTILS, "text_uri: %s", text_uri); gfile = g_file_new_for_uri (text_uri); @@ -439,7 +455,7 @@ xed_utils_unescape_search_text (const gchar *text) const gchar *cur; const gchar *end; const gchar *prev; - + if (text == NULL) return NULL; @@ -450,15 +466,15 @@ xed_utils_unescape_search_text (const gchar *text) cur = text; end = text + length; prev = NULL; - - while (cur != end) + + while (cur != end) { const gchar *next; next = g_utf8_next_char (cur); - if (prev && (*prev == '\\')) + if (prev && (*prev == '\\')) { - switch (*cur) + switch (*cur) { case 'n': str = g_string_append (str, "\n"); @@ -478,21 +494,21 @@ xed_utils_unescape_search_text (const gchar *text) str = g_string_append_len (str, cur, next - cur); break; } - } - else if (*cur != '\\') + } + else if (*cur != '\\') { str = g_string_append_len (str, cur, next - cur); - } - else if ((next == end) && (*cur == '\\')) + } + else if ((next == end) && (*cur == '\\')) { str = g_string_append (str, "\\"); } - + if (!drop_prev) { prev = cur; } - else + else { prev = NULL; drop_prev = FALSE; @@ -504,19 +520,19 @@ xed_utils_unescape_search_text (const gchar *text) return g_string_free (str, FALSE); } -void +void xed_warning (GtkWindow *parent, const gchar *format, ...) { va_list args; gchar *str; GtkWidget *dialog; GtkWindowGroup *wg = NULL; - + g_return_if_fail (format != NULL); if (parent != NULL) wg = gtk_window_get_group (parent); - + va_start (args, format); str = g_strdup_vprintf (format, args); va_end (args); @@ -532,7 +548,7 @@ xed_warning (GtkWindow *parent, const gchar *format, ...) if (wg != NULL) gtk_window_group_add_window (wg, GTK_WINDOW (dialog)); - + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); @@ -541,14 +557,14 @@ xed_warning (GtkWindow *parent, const gchar *format, ...) "response", G_CALLBACK (gtk_widget_destroy), NULL); - + gtk_widget_show (dialog); } /* * Doubles underscore to avoid spurious menu accels. */ -gchar * +gchar * xed_utils_escape_underscores (const gchar* text, gssize length) { @@ -642,7 +658,7 @@ xed_utils_str_truncate (const gchar *string, g_utf8_offset_to_pointer (string, num_left_chars) - string); g_string_append (truncated, delimiter); } - + return g_string_free (truncated, FALSE); } @@ -695,7 +711,7 @@ xed_utils_make_valid_utf8 (const char *name) } g_string_append (string, remainder); - + g_assert (g_utf8_validate (string->str, -1, NULL)); return g_string_free (string, FALSE); @@ -721,14 +737,14 @@ xed_utils_uri_get_dirname (const gchar *uri) if ((strlen (str) == 1) && (*str == '.')) { g_free (str); - + return NULL; } res = xed_utils_replace_home_dir_with_tilde (str); g_free (str); - + return res; } @@ -827,7 +843,7 @@ xed_utils_replace_home_dir_with_tilde (const gchar *uri) if (strcmp (uri, home) == 0) { g_free (home); - + return g_strdup ("~"); } @@ -842,8 +858,8 @@ xed_utils_replace_home_dir_with_tilde (const gchar *uri) res = g_strdup_printf ("~/%s", uri + strlen (home)); g_free (home); - - return res; + + return res; } g_free (home); @@ -1059,7 +1075,7 @@ xed_utils_is_valid_uri (const gchar *uri) if (!g_ascii_isxdigit (*p)) return FALSE; - ++p; + ++p; if (!g_ascii_isxdigit (*p)) return FALSE; } @@ -1146,12 +1162,12 @@ xed_utils_get_ui_objects (const gchar *filename, *error_widget = NULL; builder = gtk_builder_new (); - + if (root_objects != NULL) { - gtk_builder_add_objects_from_file (builder, - filename, - root_objects, + gtk_builder_add_objects_from_file (builder, + filename, + root_objects, &error); } else @@ -1183,8 +1199,8 @@ xed_utils_get_ui_objects (const gchar *filename, if (!*gobj) { - *error_widget = handle_builder_error (_("Unable to find the object '%s' inside file %s."), - name, + *error_widget = handle_builder_error (_("Unable to find the object '%s' inside file %s."), + name, filename_markup), ret = FALSE; break; @@ -1215,25 +1231,25 @@ xed_utils_get_ui_objects (const gchar *filename, gchar * xed_utils_make_canonical_uri_from_shell_arg (const gchar *str) -{ +{ GFile *gfile; gchar *uri; g_return_val_if_fail (str != NULL, NULL); g_return_val_if_fail (*str != '\0', NULL); - - /* Note for the future: + + /* Note for the future: * FIXME: is still still relevant? * - * paolo: and flame whoever tells - * you that file:///mate/test_files/hëllò + * paolo: and flame whoever tells + * you that file:///mate/test_files/hëllò * doesn't work --- that's not a valid URI * - * federico: well, another solution that - * does not requires patch to _from_shell_args - * is to check that the string returned by it + * federico: well, another solution that + * does not requires patch to _from_shell_args + * is to check that the string returned by it * contains only ASCII chars - * paolo: hmmmm, isn't there + * paolo: hmmmm, isn't there * mate_vfs_is_uri_valid() or something? * : I will use xed_utils_is_valid_uri () * @@ -1245,7 +1261,7 @@ xed_utils_make_canonical_uri_from_shell_arg (const gchar *str) if (xed_utils_is_valid_uri (uri)) return uri; - + g_free (uri); return NULL; } @@ -1262,13 +1278,13 @@ xed_utils_file_has_parent (GFile *gfile) { GFile *parent; gboolean ret; - + parent = g_file_get_parent (gfile); ret = parent != NULL; - + if (parent) g_object_unref (parent); - + return ret; } @@ -1294,9 +1310,9 @@ xed_utils_basename_for_display (gchar const *uri) { GFileInfo *info; info = g_file_query_info (gfile, - G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, - G_FILE_QUERY_INFO_NONE, - NULL, + G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, + G_FILE_QUERY_INFO_NONE, + NULL, NULL); if (info) @@ -1310,7 +1326,7 @@ xed_utils_basename_for_display (gchar const *uri) /* This is a local file, and therefore we will use * g_filename_display_basename on the local path */ gchar *local_path; - + local_path = g_file_get_path (gfile); name = g_filename_display_basename (local_path); g_free (local_path); @@ -1327,8 +1343,8 @@ xed_utils_basename_for_display (gchar const *uri) parse_name = g_file_get_parse_name (gfile); base = g_filename_display_basename (parse_name); name = g_uri_unescape_string (base, NULL); - - g_free (base); + + g_free (base); g_free (parse_name); } else @@ -1360,7 +1376,7 @@ xed_utils_basename_for_display (gchar const *uri) * * Filter, modify, unescape and change @uri to make it appropriate * for display to users. - * + * * This function is a convenient wrapper for g_file_get_parse_name * * Return value: a string which represents @uri and can be displayed. @@ -1383,9 +1399,9 @@ xed_utils_uri_for_display (const gchar *uri) * @selection_data: the #GtkSelectionData from drag_data_received * * Create a list of valid uri's from a uri-list drop. - * - * Return value: a string array which will hold the uris or %NULL if there - * were no valid uris. g_strfreev should be used when the + * + * Return value: (transfer full): a string array which will hold the uris or %NULL if there + * were no valid uris. g_strfreev should be used when the * string array is no longer used */ gchar ** @@ -1402,9 +1418,9 @@ xed_utils_drop_get_uris (GtkSelectionData *selection_data) for (i = 0; uris[i] != NULL; i++) { gchar *uri; - + uri = xed_utils_make_canonical_uri_from_shell_arg (uris[i]); - + /* Silently ignore malformed URI/filename */ if (uri != NULL) uri_list[p++] = uri; @@ -1442,7 +1458,7 @@ null_ptr (gchar **ptr) * scheme, user info, port, host and path. The return value pointer can be * %NULL to ignore certain parts of the uri. If the function returns %TRUE, then * all return value pointers should be freed using g_free - * + * * Return value: %TRUE if the uri could be properly decoded, %FALSE otherwise. */ gboolean @@ -1454,7 +1470,7 @@ xed_utils_decode_uri (const gchar *uri, gchar **path ) { - /* Largely copied from glib/gio/gdummyfile.c:_g_decode_uri. This + /* Largely copied from glib/gio/gdummyfile.c:_g_decode_uri. This * functionality should be in glib/gio, but for now we implement it * ourselves (see bug #546182) */ @@ -1464,10 +1480,10 @@ xed_utils_decode_uri (const gchar *uri, /* From RFC 3986 Decodes: * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] - */ + */ p = uri; - + null_ptr (scheme); null_ptr (user); null_ptr (port); @@ -1494,32 +1510,32 @@ xed_utils_decode_uri (const gchar *uri, c == '.')) return FALSE; } - + if (scheme) { *scheme = g_malloc (p - uri); out = *scheme; - + for (in = uri; in < p - 1; in++) *out++ = g_ascii_tolower (*in); - + *out = '\0'; } - + hier_part_start = p; hier_part_end = p + strlen (p); - + if (hier_part_start[0] == '/' && hier_part_start[1] == '/') { const char *authority_start, *authority_end; const char *userinfo_start, *userinfo_end; const char *host_start, *host_end; const char *port_start; - + authority_start = hier_part_start + 2; /* authority is always followed by / or nothing */ authority_end = memchr (authority_start, '/', hier_part_end - authority_start); - + if (authority_end == NULL) authority_end = hier_part_end; @@ -1528,14 +1544,14 @@ xed_utils_decode_uri (const gchar *uri, */ userinfo_end = memchr (authority_start, '@', authority_end - authority_start); - + if (userinfo_end) { userinfo_start = authority_start; - + if (user) *user = g_uri_unescape_segment (userinfo_start, userinfo_end, NULL); - + if (user && *user == NULL) { if (scheme) @@ -1543,7 +1559,7 @@ xed_utils_decode_uri (const gchar *uri, return FALSE; } - + host_start = userinfo_end + 1; } else @@ -1569,6 +1585,6 @@ xed_utils_decode_uri (const gchar *uri, if (path) *path = g_uri_unescape_segment (hier_part_start, hier_part_end, "/"); - + return TRUE; } diff --git a/xed/xed-window.c b/xed/xed-window.c index 1b50c99..545b4b1 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -3395,7 +3395,7 @@ xed_window_init (XedWindow *window) * * Gets the active #XedView. * - * Returns: the active #XedView + * Returns: (transfer none): the active #XedView */ XedView * xed_window_get_active_view (XedWindow *window) @@ -3423,7 +3423,7 @@ xed_window_get_active_view (XedWindow *window) * * Gets the active #XedDocument. * - * Returns: the active #XedDocument + * Returns: (transfer none): the active #XedDocument */ XedDocument * xed_window_get_active_document (XedWindow *window) @@ -3460,7 +3460,7 @@ _xed_window_get_notebook (XedWindow *window) * Creates a new #XedTab and adds the new tab to the #XedNotebook. * In case @jump_to is %TRUE the #XedNotebook switches to that new #XedTab. * - * Returns: a new #XedTab + * Returns: (transfer none): a new #XedTab */ XedTab * xed_window_create_tab (XedWindow *window, @@ -3497,7 +3497,7 @@ xed_window_create_tab (XedWindow *window, * Whether @create is %TRUE, creates a new empty document if location does * not refer to an existing file * - * Returns: a new #XedTab + * Returns: (transfer none): a new #XedTab */ XedTab * xed_window_create_tab_from_uri (XedWindow *window, @@ -3536,7 +3536,7 @@ xed_window_create_tab_from_uri (XedWindow *window, * * Gets the active #XedTab in the @window. * - * Returns: the active #XedTab in the @window. + * Returns: (transfer none): the active #XedTab in the @window. */ XedTab * xed_window_get_active_tab (XedWindow *window) @@ -3729,7 +3729,7 @@ xed_window_set_active_tab (XedWindow *window, * * Gets the #GtkWindowGroup in which @window resides. * - * Returns: the #GtkWindowGroup + * Returns: (transfer none): the #GtkWindowGroup */ GtkWindowGroup * xed_window_get_group (XedWindow *window) @@ -3751,7 +3751,7 @@ _xed_window_is_removing_tabs (XedWindow *window) * * Gets the #GtkUIManager associated with the @window. * - * Returns: the #GtkUIManager of the @window. + * Returns: (transfer none): the #GtkUIManager of the @window. */ GtkUIManager * xed_window_get_ui_manager (XedWindow *window) @@ -3766,7 +3766,7 @@ xed_window_get_ui_manager (XedWindow *window) * * Gets the side #XedPanel of the @window. * - * Returns: the side #XedPanel. + * Returns: (transfer none): the side #XedPanel. */ XedPanel * xed_window_get_side_panel (XedWindow *window) @@ -3781,7 +3781,7 @@ xed_window_get_side_panel (XedWindow *window) * * Gets the bottom #XedPanel of the @window. * - * Returns: the bottom #XedPanel. + * Returns: (transfer none): the bottom #XedPanel. */ XedPanel * xed_window_get_bottom_panel (XedWindow *window) @@ -3796,7 +3796,7 @@ xed_window_get_bottom_panel (XedWindow *window) * * Gets the #XedStatusbar of the @window. * - * Returns: the #XedStatusbar of the @window. + * Returns: (transfer none): the #XedStatusbar of the @window. */ GtkWidget * xed_window_get_statusbar (XedWindow *window) @@ -3809,9 +3809,9 @@ xed_window_get_statusbar (XedWindow *window) * xed_window_get_searchbar: * @window: a #XedWindow * - * Gets the #XedSearchDialog of the @window. + * Gets the #XedSearchbar of the @window. * - * Returns: the #XedSearchDialog of the @window. + * Returns: (transfer none): the #XedSearchbar of the @window. */ GtkWidget * xed_window_get_searchbar (XedWindow *window) @@ -4084,7 +4084,7 @@ xed_window_get_message_bus (XedWindow *window) * * Gets the #XedTab that matches @uri. * - * Returns: the #XedTab associated with @uri. + * Returns: (transfer none): the #XedTab associated with @uri. * * Deprecated: 2.24: Use xed_window_get_tab_from_location() instead. */ From 8cb1a6dad83312d059d7cbcc45035001ad3df65a Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 11:44:21 -0800 Subject: [PATCH 024/132] Remove a couple of invalid annotations --- xed/xed-commands-file.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/xed/xed-commands-file.c b/xed/xed-commands-file.c index 8fb1d69..68d3bc8 100644 --- a/xed/xed-commands-file.c +++ b/xed/xed-commands-file.c @@ -310,8 +310,6 @@ load_uri_list (XedWindow *window, * @line_pos: * * Do nothing if uri does not exist - * - * Returns: (transfer container): */ void xed_commands_load_uri (XedWindow *window, @@ -343,7 +341,7 @@ xed_commands_load_uri (XedWindow *window, * * Ignore non-existing URIs * - * Returns: (transfer container): + * Returns: */ gint xed_commands_load_uris (XedWindow *window, From ae4b648a7902e4cf69569640b1757d34a4aa195e Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 11:49:28 -0800 Subject: [PATCH 025/132] xed-window: Remove an unused function --- docs/reference/xed-sections.txt | 1 - xed/xed-window.c | 28 ---------------------------- xed/xed-window.h | 1 - 3 files changed, 30 deletions(-) diff --git a/docs/reference/xed-sections.txt b/docs/reference/xed-sections.txt index 5b60e1f..dac318e 100644 --- a/docs/reference/xed-sections.txt +++ b/docs/reference/xed-sections.txt @@ -409,7 +409,6 @@ xed_window_get_statusbar xed_window_get_ui_manager xed_window_get_state xed_window_get_tab_from_location -xed_window_get_tab_from_uri xed_window_get_message_bus XED_WINDOW diff --git a/xed/xed-window.c b/xed/xed-window.c index 545b4b1..1647476 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -4076,31 +4076,3 @@ xed_window_get_message_bus (XedWindow *window) g_return_val_if_fail(XED_IS_WINDOW (window), NULL); return window->priv->message_bus; } - -/** - * xed_window_get_tab_from_uri: - * @window: a #XedWindow - * @uri: the uri to get the #XedTab - * - * Gets the #XedTab that matches @uri. - * - * Returns: (transfer none): the #XedTab associated with @uri. - * - * Deprecated: 2.24: Use xed_window_get_tab_from_location() instead. - */ -XedTab * -xed_window_get_tab_from_uri (XedWindow *window, - const gchar *uri) -{ - GFile *f; - XedTab *tab; - - g_return_val_if_fail(XED_IS_WINDOW (window), NULL); - g_return_val_if_fail(uri != NULL, NULL); - - f = g_file_new_for_uri (uri); - tab = xed_window_get_tab_from_location (window, f); - g_object_unref (f); - - return tab; -} diff --git a/xed/xed-window.h b/xed/xed-window.h index 5909d2f..19d52a8 100644 --- a/xed/xed-window.h +++ b/xed/xed-window.h @@ -97,7 +97,6 @@ GtkWidget *xed_window_get_searchbar (XedWindow *window); GtkUIManager *xed_window_get_ui_manager (XedWindow *window); XedWindowState xed_window_get_state (XedWindow *window); XedTab *xed_window_get_tab_from_location (XedWindow *window, GFile *location); -XedTab *xed_window_get_tab_from_uri (XedWindow *window, const gchar *uri); /* Message bus */ XedMessageBus *xed_window_get_message_bus (XedWindow *window); From 29f0acc0d67da02071ecfbace9250206b7d2c360 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 11:53:22 -0800 Subject: [PATCH 026/132] Drop some leftover 2.xx comments from gnome/pluma --- xed/xed-document.c | 4 ---- xed/xed-message-bus.c | 3 --- xed/xed-message-type.c | 3 --- xed/xed-message.c | 3 --- 4 files changed, 13 deletions(-) diff --git a/xed/xed-document.c b/xed/xed-document.c index 36bd176..0f6a0be 100644 --- a/xed/xed-document.c +++ b/xed/xed-document.c @@ -549,8 +549,6 @@ xed_document_class_init (XedDocumentClass *klass) * @create: whether the document should be created if it doesn't exist. * * The "load" signal is emitted when a document is loaded. - * - * Since: 2.22 */ document_signals[LOAD] = g_signal_new ("load", @@ -600,8 +598,6 @@ xed_document_class_init (XedDocumentClass *klass) * @flags: the #XedDocumentSaveFlags for the save operation. * * The "save" signal is emitted when the document is saved. - * - * Since: 2.20 */ document_signals[SAVE] = g_signal_new ("save", diff --git a/xed/xed-message-bus.c b/xed/xed-message-bus.c index 6a51955..9a5be47 100644 --- a/xed/xed-message-bus.c +++ b/xed/xed-message-bus.c @@ -88,9 +88,6 @@ * NULL); * * - * - * Since: 2.25.3 - * */ #define XED_MESSAGE_BUS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), XED_TYPE_MESSAGE_BUS, XedMessageBusPrivate)) diff --git a/xed/xed-message-type.c b/xed/xed-message-type.c index 0211c22..236f5b8 100644 --- a/xed/xed-message-type.c +++ b/xed/xed-message-type.c @@ -33,9 +33,6 @@ * NULL); * * - * - * Since: 2.25.3 - * */ typedef struct { diff --git a/xed/xed-message.c b/xed/xed-message.c index 24a2979..ed7c7c5 100644 --- a/xed/xed-message.c +++ b/xed/xed-message.c @@ -17,9 +17,6 @@ * A message can be seen as a method call, or signal emission depending on * who is the sender and who is the receiver. There is no explicit distinction * between methods and signals. - * - * Since: 2.25.3 - * */ #define XED_MESSAGE_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), XED_TYPE_MESSAGE, XedMessagePrivate)) From b52cc3f03720d65173082ae674c3b2f949ef40fc Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 12:53:23 -0800 Subject: [PATCH 027/132] Port plugin system to libpeas Adapted from: https://github.com/mate-desktop/pluma/commit/52fd78ddfcbe35507aee9122fed0f18c99407c89 --- configure.ac | 2 + data/xed.pc.in | 2 +- xed/Makefile.am | 11 - xed/dialogs/xed-preferences-dialog.c | 222 +++---- xed/xed-dirs.c | 14 +- xed/xed-dirs.h | 7 +- xed/xed-plugins-engine.c | 846 ++------------------------- xed/xed-plugins-engine.h | 71 +-- xed/xed-prefs-manager-app.c | 29 +- xed/xed-window-private.h | 27 +- xed/xed-window.c | 61 +- 11 files changed, 267 insertions(+), 1025 deletions(-) diff --git a/configure.ac b/configure.ac index ceadc41..9b900d0 100644 --- a/configure.ac +++ b/configure.ac @@ -157,6 +157,8 @@ PKG_CHECK_MODULES(XED, [ gio-2.0 >= 2.26.0 gtk+-3.0 >= 3.10.0 gtksourceview-3.0 >= 2.9.7 + libpeas-1.0 >= 1.12.0 + libpeas-gtk-1.0 >= 1.12.0 ]) PKG_CHECK_MODULES(X11, [x11]) diff --git a/data/xed.pc.in b/data/xed.pc.in index 24593ca..68685d0 100644 --- a/data/xed.pc.in +++ b/data/xed.pc.in @@ -6,7 +6,7 @@ pluginsdir=@libdir@/xed/plugins Name: xed Description: xed -Requires: gtksourceview-3.0 +Requires: gtksourceview-3.0 libpeas-1.0 libpeas-gtk-1.0 Version: @VERSION@ Cflags: -I${includedir}/xed Libs: -L${libdir} diff --git a/xed/Makefile.am b/xed/Makefile.am index 1505e33..e7d6d36 100644 --- a/xed/Makefile.am +++ b/xed/Makefile.am @@ -52,11 +52,6 @@ NOINST_H_FILES = \ xed-history-entry.h \ xed-io-error-message-area.h \ xed-language-manager.h \ - xed-object-module.h \ - xed-plugin-info.h \ - xed-plugin-info-priv.h \ - xed-plugin-loader.h \ - xed-plugin-manager.h \ xed-plugins-engine.h \ xed-prefs-manager-private.h \ xed-print-job.h \ @@ -83,7 +78,6 @@ INST_H_FILES = \ xed-message.h \ xed-notebook.h \ xed-panel.h \ - xed-plugin.h \ xed-prefs-manager-app.h \ xed-prefs-manager.h \ xed-progress-message-area.h \ @@ -135,13 +129,8 @@ libxed_c_files = \ xed-message-bus.c \ xed-message-type.c \ xed-message.c \ - xed-object-module.c \ xed-notebook.c \ xed-panel.c \ - xed-plugin-info.c \ - xed-plugin.c \ - xed-plugin-loader.c \ - xed-plugin-manager.c \ xed-plugins-engine.c \ xed-prefs-manager-app.c \ xed-prefs-manager.c \ diff --git a/xed/dialogs/xed-preferences-dialog.c b/xed/dialogs/xed-preferences-dialog.c index faf930c..8d383ec 100755 --- a/xed/dialogs/xed-preferences-dialog.c +++ b/xed/dialogs/xed-preferences-dialog.c @@ -3,7 +3,7 @@ * xed-preferences-dialog.c * This file is part of xed * - * Copyright (C) 2001-2005 Paolo Maggi + * Copyright (C) 2001-2005 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,14 +17,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ /* - * Modified by the xed Team, 2001-2003. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2001-2003. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -47,7 +48,6 @@ #include "xed-debug.h" #include "xed-document.h" #include "xed-style-scheme-manager.h" -#include "xed-plugin-manager.h" #include "xed-help.h" #include "xed-dirs.h" @@ -90,7 +90,7 @@ struct _XedPreferencesDialogPrivate GtkWidget *schemes_treeview; GtkWidget *install_scheme_button; GtkWidget *uninstall_scheme_button; - + GtkWidget *install_scheme_file_schooser; /* Tabs */ @@ -110,16 +110,16 @@ struct _XedPreferencesDialogPrivate GtkWidget *auto_save_checkbutton; GtkWidget *auto_save_spinbutton; GtkWidget *autosave_hbox; - + /* Line numbers */ GtkWidget *display_line_numbers_checkbutton; /* Highlight current line */ GtkWidget *highlight_current_line_checkbutton; - + /* Highlight matching bracket */ GtkWidget *bracket_matching_checkbutton; - + /* Right margin */ GtkWidget *right_margin_checkbutton; GtkWidget *right_margin_position_spinbutton; @@ -136,7 +136,7 @@ struct _XedPreferencesDialogPrivate G_DEFINE_TYPE(XedPreferencesDialog, xed_preferences_dialog, GTK_TYPE_DIALOG) -static void +static void xed_preferences_dialog_class_init (XedPreferencesDialogClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -145,7 +145,7 @@ xed_preferences_dialog_class_init (XedPreferencesDialogClass *klass) } static void -dialog_response_handler (GtkDialog *dlg, +dialog_response_handler (GtkDialog *dlg, gint res_id) { xed_debug (DEBUG_PREFS); @@ -176,7 +176,7 @@ tabs_width_spinbutton_value_changed (GtkSpinButton *spin_button, xed_prefs_manager_set_tabs_size (gtk_spin_button_get_value_as_int (spin_button)); } - + static void insert_spaces_checkbutton_toggled (GtkToggleButton *button, XedPreferencesDialog *dlg) @@ -209,12 +209,12 @@ auto_save_checkbutton_toggled (GtkToggleButton *button, if (gtk_toggle_button_get_active (button)) { - gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, + gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, xed_prefs_manager_auto_save_interval_can_set()); xed_prefs_manager_set_auto_save (TRUE); } - else + else { gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, FALSE); xed_prefs_manager_set_auto_save (FALSE); @@ -228,7 +228,7 @@ backup_copy_checkbutton_toggled (GtkToggleButton *button, xed_debug (DEBUG_PREFS); g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton)); - + xed_prefs_manager_set_create_backup_copy (gtk_toggle_button_get_active (button)); } @@ -253,9 +253,9 @@ setup_editor_page (XedPreferencesDialog *dlg) /* Set initial state */ gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->tabs_width_spinbutton), (guint) xed_prefs_manager_get_tabs_size ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->insert_spaces_checkbutton), + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->insert_spaces_checkbutton), xed_prefs_manager_get_insert_spaces ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_indent_checkbutton), + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_indent_checkbutton), xed_prefs_manager_get_auto_indent ()); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton), xed_prefs_manager_get_create_backup_copy ()); @@ -272,7 +272,7 @@ setup_editor_page (XedPreferencesDialog *dlg) auto_save_interval); /* Set widget sensitivity */ - gtk_widget_set_sensitive (dlg->priv->tabs_width_hbox, + gtk_widget_set_sensitive (dlg->priv->tabs_width_hbox, xed_prefs_manager_tabs_size_can_set ()); gtk_widget_set_sensitive (dlg->priv->insert_spaces_checkbutton, xed_prefs_manager_insert_spaces_can_set ()); @@ -280,9 +280,9 @@ setup_editor_page (XedPreferencesDialog *dlg) xed_prefs_manager_auto_indent_can_set ()); gtk_widget_set_sensitive (dlg->priv->backup_copy_checkbutton, xed_prefs_manager_create_backup_copy_can_set ()); - gtk_widget_set_sensitive (dlg->priv->autosave_hbox, - xed_prefs_manager_auto_save_can_set ()); - gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, + gtk_widget_set_sensitive (dlg->priv->autosave_hbox, + xed_prefs_manager_auto_save_can_set ()); + gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, auto_save && xed_prefs_manager_auto_save_interval_can_set ()); @@ -317,7 +317,7 @@ static void display_line_numbers_checkbutton_toggled (GtkToggleButton *button, XedPreferencesDialog *dlg) { - g_return_if_fail (button == + g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton)); xed_prefs_manager_set_display_line_numbers (gtk_toggle_button_get_active (button)); @@ -327,7 +327,7 @@ static void highlight_current_line_checkbutton_toggled (GtkToggleButton *button, XedPreferencesDialog *dlg) { - g_return_if_fail (button == + g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton)); xed_prefs_manager_set_highlight_current_line (gtk_toggle_button_get_active (button)); @@ -337,7 +337,7 @@ static void bracket_matching_checkbutton_toggled (GtkToggleButton *button, XedPreferencesDialog *dlg) { - g_return_if_fail (button == + g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton)); xed_prefs_manager_set_bracket_matching ( @@ -347,21 +347,21 @@ bracket_matching_checkbutton_toggled (GtkToggleButton *button, static gboolean split_button_state = TRUE; static void -wrap_mode_checkbutton_toggled (GtkToggleButton *button, +wrap_mode_checkbutton_toggled (GtkToggleButton *button, XedPreferencesDialog *dlg) { if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton))) { xed_prefs_manager_set_wrap_mode (GTK_WRAP_NONE); - - gtk_widget_set_sensitive (dlg->priv->split_checkbutton, + + gtk_widget_set_sensitive (dlg->priv->split_checkbutton, FALSE); gtk_toggle_button_set_inconsistent ( GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE); } else { - gtk_widget_set_sensitive (dlg->priv->split_checkbutton, + gtk_widget_set_sensitive (dlg->priv->split_checkbutton, TRUE); gtk_toggle_button_set_inconsistent ( @@ -371,13 +371,13 @@ wrap_mode_checkbutton_toggled (GtkToggleButton *button, if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton))) { split_button_state = TRUE; - + xed_prefs_manager_set_wrap_mode (GTK_WRAP_WORD); } else { split_button_state = FALSE; - + xed_prefs_manager_set_wrap_mode (GTK_WRAP_CHAR); } } @@ -388,24 +388,24 @@ right_margin_checkbutton_toggled (GtkToggleButton *button, XedPreferencesDialog *dlg) { gboolean active; - + g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->right_margin_checkbutton)); active = gtk_toggle_button_get_active (button); - + xed_prefs_manager_set_display_right_margin (active); gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, - active && + active && xed_prefs_manager_right_margin_position_can_set ()); } static void -right_margin_position_spinbutton_value_changed (GtkSpinButton *spin_button, +right_margin_position_spinbutton_value_changed (GtkSpinButton *spin_button, XedPreferencesDialog *dlg) { gint value; - + g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton)); value = CLAMP (gtk_spin_button_get_value_as_int (spin_button), 1, 160); @@ -421,14 +421,14 @@ setup_view_page (XedPreferencesDialog *dlg) gboolean wrap_mode_can_set; xed_debug (DEBUG_PREFS); - + /* Set initial state */ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton), xed_prefs_manager_get_display_line_numbers ()); - + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton), xed_prefs_manager_get_highlight_current_line ()); - + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton), xed_prefs_manager_get_bracket_matching ()); @@ -458,15 +458,15 @@ setup_view_page (XedPreferencesDialog *dlg) } display_right_margin = xed_prefs_manager_get_display_right_margin (); - + gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (dlg->priv->right_margin_checkbutton), + GTK_TOGGLE_BUTTON (dlg->priv->right_margin_checkbutton), display_right_margin); - + gtk_spin_button_set_value ( GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton), (guint)CLAMP (xed_prefs_manager_get_right_margin_position (), 1, 160)); - + /* Set widgets sensitivity */ gtk_widget_set_sensitive (dlg->priv->display_line_numbers_checkbutton, xed_prefs_manager_display_line_numbers_can_set ()); @@ -475,45 +475,45 @@ setup_view_page (XedPreferencesDialog *dlg) gtk_widget_set_sensitive (dlg->priv->bracket_matching_checkbutton, xed_prefs_manager_bracket_matching_can_set ()); wrap_mode_can_set = xed_prefs_manager_wrap_mode_can_set (); - gtk_widget_set_sensitive (dlg->priv->wrap_text_checkbutton, + gtk_widget_set_sensitive (dlg->priv->wrap_text_checkbutton, wrap_mode_can_set); - gtk_widget_set_sensitive (dlg->priv->split_checkbutton, - wrap_mode_can_set && + gtk_widget_set_sensitive (dlg->priv->split_checkbutton, + wrap_mode_can_set && (wrap_mode != GTK_WRAP_NONE)); gtk_widget_set_sensitive (dlg->priv->right_margin_checkbutton, xed_prefs_manager_display_right_margin_can_set ()); gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, - display_right_margin && + display_right_margin && xed_prefs_manager_right_margin_position_can_set ()); - + /* Connect signals */ g_signal_connect (dlg->priv->display_line_numbers_checkbutton, "toggled", - G_CALLBACK (display_line_numbers_checkbutton_toggled), + G_CALLBACK (display_line_numbers_checkbutton_toggled), dlg); g_signal_connect (dlg->priv->highlight_current_line_checkbutton, - "toggled", - G_CALLBACK (highlight_current_line_checkbutton_toggled), + "toggled", + G_CALLBACK (highlight_current_line_checkbutton_toggled), dlg); g_signal_connect (dlg->priv->bracket_matching_checkbutton, - "toggled", - G_CALLBACK (bracket_matching_checkbutton_toggled), + "toggled", + G_CALLBACK (bracket_matching_checkbutton_toggled), dlg); g_signal_connect (dlg->priv->wrap_text_checkbutton, - "toggled", - G_CALLBACK (wrap_mode_checkbutton_toggled), + "toggled", + G_CALLBACK (wrap_mode_checkbutton_toggled), dlg); g_signal_connect (dlg->priv->split_checkbutton, - "toggled", - G_CALLBACK (wrap_mode_checkbutton_toggled), + "toggled", + G_CALLBACK (wrap_mode_checkbutton_toggled), dlg); g_signal_connect (dlg->priv->right_margin_checkbutton, - "toggled", - G_CALLBACK (right_margin_checkbutton_toggled), + "toggled", + G_CALLBACK (right_margin_checkbutton_toggled), dlg); g_signal_connect (dlg->priv->right_margin_position_spinbutton, "value_changed", - G_CALLBACK (right_margin_position_spinbutton_value_changed), + G_CALLBACK (right_margin_position_spinbutton_value_changed), dlg); } @@ -532,7 +532,7 @@ default_font_font_checkbutton_toggled (GtkToggleButton *button, } else { - gtk_widget_set_sensitive (dlg->priv->font_hbox, + gtk_widget_set_sensitive (dlg->priv->font_hbox, xed_prefs_manager_editor_font_can_set ()); xed_prefs_manager_set_use_default_font (FALSE); } @@ -575,8 +575,8 @@ setup_font_colors_page_font_section (XedPreferencesDialog *dlg) dlg->priv->default_font_checkbutton, ATK_RELATION_CONTROLLED_BY); xed_utils_set_atk_relation (dlg->priv->default_font_checkbutton, - dlg->priv->font_button, - ATK_RELATION_CONTROLLER_FOR); + dlg->priv->font_button, + ATK_RELATION_CONTROLLER_FOR); editor_font = xed_prefs_manager_get_system_font (); label = g_strdup_printf(_("_Use the system fixed width font (%s)"), @@ -610,13 +610,13 @@ setup_font_colors_page_font_section (XedPreferencesDialog *dlg) dlg); /* Set initial widget sensitivity */ - gtk_widget_set_sensitive (dlg->priv->default_font_checkbutton, + gtk_widget_set_sensitive (dlg->priv->default_font_checkbutton, xed_prefs_manager_use_default_font_can_set ()); if (use_default_font) gtk_widget_set_sensitive (dlg->priv->font_hbox, FALSE); else - gtk_widget_set_sensitive (dlg->priv->font_hbox, + gtk_widget_set_sensitive (dlg->priv->font_hbox, xed_prefs_manager_editor_font_can_set ()); } @@ -625,8 +625,8 @@ set_buttons_sensisitivity_according_to_scheme (XedPreferencesDialog *dlg, const gchar *scheme_id) { gboolean editable; - - editable = (scheme_id != NULL) && + + editable = (scheme_id != NULL) && _xed_style_scheme_manager_scheme_is_xed_user_scheme ( xed_get_style_scheme_manager (), scheme_id); @@ -694,7 +694,7 @@ ensure_color_scheme_id (const gchar *id) return gtk_source_style_scheme_get_id (scheme); } -/* If def_id is NULL, use the default scheme as returned by +/* If def_id is NULL, use the default scheme as returned by * xed_style_scheme_manager_get_default_scheme. If this one returns NULL * use the first available scheme as default */ static const gchar * @@ -702,17 +702,17 @@ populate_color_scheme_list (XedPreferencesDialog *dlg, const gchar *def_id) { GSList *schemes; GSList *l; - + gtk_list_store_clear (dlg->priv->schemes_treeview_model); - + def_id = ensure_color_scheme_id (def_id); - if (def_id == NULL) + if (def_id == NULL) { g_warning ("Cannot build the list of available color schemes.\n" "Please check your GtkSourceView installation."); return NULL; } - + schemes = xed_style_scheme_manager_list_schemes_sorted (xed_get_style_scheme_manager ()); l = schemes; while (l != NULL) @@ -724,7 +724,7 @@ populate_color_scheme_list (XedPreferencesDialog *dlg, const gchar *def_id) GtkTreeIter iter; scheme = GTK_SOURCE_STYLE_SCHEME (l->data); - + id = gtk_source_style_scheme_get_id (scheme); name = gtk_source_style_scheme_get_name (scheme); description = gtk_source_style_scheme_get_description (scheme); @@ -741,39 +741,39 @@ populate_color_scheme_list (XedPreferencesDialog *dlg, const gchar *def_id) if (strcmp (id, def_id) == 0) { GtkTreeSelection *selection; - + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->schemes_treeview)); gtk_tree_selection_select_iter (selection, &iter); } - + l = g_slist_next (l); } - + g_slist_free (schemes); - + return def_id; } static void -add_scheme_chooser_response_cb (GtkDialog *chooser, +add_scheme_chooser_response_cb (GtkDialog *chooser, gint res_id, XedPreferencesDialog *dlg) { - gchar* filename; + gchar* filename; const gchar *scheme_id; - + if (res_id != GTK_RESPONSE_ACCEPT) { gtk_widget_hide (GTK_WIDGET (chooser)); return; } - + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser)); if (filename == NULL) return; - + gtk_widget_hide (GTK_WIDGET (chooser)); - + scheme_id = _xed_style_scheme_manager_install_scheme ( xed_get_style_scheme_manager (), filename); @@ -793,14 +793,14 @@ add_scheme_chooser_response_cb (GtkDialog *chooser, set_buttons_sensisitivity_according_to_scheme (dlg, scheme_id); } - + static void install_scheme_clicked (GtkButton *button, XedPreferencesDialog *dlg) { GtkWidget *chooser; GtkFileFilter *filter; - + if (dlg->priv->install_scheme_file_schooser != NULL) { gtk_window_present (GTK_WINDOW (dlg->priv->install_scheme_file_schooser)); gtk_widget_grab_focus (dlg->priv->install_scheme_file_schooser); @@ -813,13 +813,13 @@ install_scheme_clicked (GtkButton *button, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); - xed_dialog_add_button (GTK_DIALOG (chooser), + xed_dialog_add_button (GTK_DIALOG (chooser), _("A_dd Scheme"), GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT); gtk_window_set_destroy_with_parent (GTK_WINDOW (chooser), TRUE); - + /* Filters */ filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("Color Scheme Files")); @@ -827,25 +827,25 @@ install_scheme_clicked (GtkButton *button, gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), filter); - + filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("All Files")); gtk_file_filter_add_pattern (filter, "*"); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); gtk_dialog_set_default_response (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT); - + g_signal_connect (chooser, "response", G_CALLBACK (add_scheme_chooser_response_cb), dlg); dlg->priv->install_scheme_file_schooser = chooser; - + g_object_add_weak_pointer (G_OBJECT (chooser), (gpointer) &dlg->priv->install_scheme_file_schooser); - - gtk_widget_show (chooser); + + gtk_widget_show (chooser); } static void @@ -870,7 +870,7 @@ uninstall_scheme_clicked (GtkButton *button, ID_COLUMN, &id, NAME_COLUMN, &name, -1); - + if (!_xed_style_scheme_manager_uninstall_scheme (xed_get_style_scheme_manager (), id)) { xed_warning (GTK_WINDOW (dlg), @@ -878,7 +878,7 @@ uninstall_scheme_clicked (GtkButton *button, name); } else - { + { const gchar *real_new_id; gchar *new_id = NULL; GtkTreePath *path; @@ -899,13 +899,13 @@ uninstall_scheme_clicked (GtkButton *button, gtk_tree_path_next (path); if (!gtk_tree_model_get_iter (model, &new_iter, path)) { - /* It seems the removed style scheme was the - * last of the list. Try to move to the + /* It seems the removed style scheme was the + * last of the list. Try to move to the * previous one */ gtk_tree_path_free (path); path = gtk_tree_model_get_path (model, &iter); - + gtk_tree_path_prev (path); if (gtk_tree_model_get_iter (model, &new_iter, path)) new_iter_set = TRUE; @@ -914,17 +914,17 @@ uninstall_scheme_clicked (GtkButton *button, new_iter_set = TRUE; gtk_tree_path_free (path); - + if (new_iter_set) gtk_tree_model_get (model, &new_iter, ID_COLUMN, &new_id, -1); - + real_new_id = populate_color_scheme_list (dlg, new_id); g_free (new_id); - + set_buttons_sensisitivity_according_to_scheme (dlg, real_new_id); - + if (real_new_id != NULL) xed_prefs_manager_set_source_style_scheme (real_new_id); } @@ -980,9 +980,9 @@ setup_font_colors_page_style_scheme_section (XedPreferencesDialog *dlg) GtkTreeViewColumn *column; GtkTreeSelection *selection; const gchar *def_id; - + xed_debug (DEBUG_PREFS); - + /* Create GtkListStore for styles & setup treeview. */ dlg->priv->schemes_treeview_model = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, @@ -1014,7 +1014,7 @@ setup_font_colors_page_style_scheme_section (XedPreferencesDialog *dlg) gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); def_id = populate_color_scheme_list (dlg, NULL); - + /* Connect signals */ g_signal_connect (dlg->priv->schemes_treeview, "cursor-changed", @@ -1028,7 +1028,7 @@ setup_font_colors_page_style_scheme_section (XedPreferencesDialog *dlg) "clicked", G_CALLBACK (uninstall_scheme_clicked), dlg); - + /* Set initial widget sensitivity */ set_buttons_sensisitivity_according_to_scheme (dlg, def_id); } @@ -1047,7 +1047,7 @@ setup_plugins_page (XedPreferencesDialog *dlg) xed_debug (DEBUG_PREFS); - page_content = xed_plugin_manager_new (); + page_content = peas_gtk_plugin_manager_new (NULL); g_return_if_fail (page_content != NULL); gtk_box_pack_start (GTK_BOX (dlg->priv->plugin_manager_place_holder), @@ -1094,12 +1094,12 @@ xed_preferences_dialog_init (XedPreferencesDialog *dlg) gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), 2); /* 2 * 5 + 2 = 12 */ gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 5); gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 6); - + g_signal_connect (dlg, "response", G_CALLBACK (dialog_response_handler), NULL); - + file = xed_dirs_get_ui_file ("xed-preferences-dialog.ui"); ret = xed_utils_get_ui_objects (file, root_objects, @@ -1144,11 +1144,11 @@ xed_preferences_dialog_init (XedPreferencesDialog *dlg) if (!ret) { gtk_widget_show (error_widget); - + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), error_widget, TRUE, TRUE, 0); - + return; } diff --git a/xed/xed-dirs.c b/xed/xed-dirs.c index c40a88f..e125d5e 100644 --- a/xed/xed-dirs.c +++ b/xed/xed-dirs.c @@ -95,17 +95,17 @@ gchar* xed_dirs_get_xed_plugins_dir(void) return plugin_dir; } -gchar* xed_dirs_get_xed_plugin_loaders_dir(void) +gchar* xed_dirs_get_xed_plugins_data_dir (void) { - gchar* lib_dir; - gchar* loader_dir; + gchar* data_dir; + gchar* plugin_data_dir; - lib_dir = xed_dirs_get_xed_lib_dir(); + data_dir = xed_dirs_get_xed_data_dir (); - loader_dir = g_build_filename(lib_dir, "plugin-loaders", NULL); - g_free(lib_dir); + plugin_data_dir = g_build_filename (data_dir, "plugins", NULL); + g_free (data_dir); - return loader_dir; + return plugin_data_dir; } gchar* xed_dirs_get_ui_file(const gchar* file) diff --git a/xed/xed-dirs.h b/xed/xed-dirs.h index 3e571b9..eb2d09f 100644 --- a/xed/xed-dirs.h +++ b/xed/xed-dirs.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ @@ -44,8 +44,7 @@ gchar *xed_dirs_get_xed_lib_dir (void); gchar *xed_dirs_get_xed_plugins_dir (void); -gchar *xed_dirs_get_xed_plugin_loaders_dir - (void); +gchar *xed_dirs_get_xed_plugins_data_dir (void); gchar *xed_dirs_get_ui_file (const gchar *file); diff --git a/xed/xed-plugins-engine.c b/xed/xed-plugins-engine.c index 0fcb992..c3160ab 100644 --- a/xed/xed-plugins-engine.c +++ b/xed/xed-plugins-engine.c @@ -35,827 +35,109 @@ #include #include +#include #include "xed-plugins-engine.h" -#include "xed-plugin-info-priv.h" -#include "xed-plugin.h" #include "xed-debug.h" #include "xed-app.h" #include "xed-prefs-manager.h" -#include "xed-plugin-loader.h" -#include "xed-object-module.h" #include "xed-dirs.h" -#define XED_PLUGINS_ENGINE_BASE_KEY "/apps/xed/plugins" -#define XED_PLUGINS_ENGINE_KEY XED_PLUGINS_ENGINE_BASE_KEY "/active-plugins" - -#define PLUGIN_EXT ".xed-plugin" -#define LOADER_EXT G_MODULE_SUFFIX - -typedef struct -{ - XedPluginLoader *loader; - XedObjectModule *module; -} LoaderInfo; - -/* Signals */ -enum -{ - ACTIVATE_PLUGIN, - DEACTIVATE_PLUGIN, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -G_DEFINE_TYPE(XedPluginsEngine, xed_plugins_engine, G_TYPE_OBJECT) +G_DEFINE_TYPE (XedPluginsEngine, xed_plugins_engine, PEAS_TYPE_ENGINE) struct _XedPluginsEnginePrivate { - GList *plugin_list; - GHashTable *loaders; - - gboolean activate_from_prefs; + GSettings *plugin_settings; }; XedPluginsEngine *default_engine = NULL; -static void xed_plugins_engine_activate_plugin_real (XedPluginsEngine *engine, - XedPluginInfo *info); -static void xed_plugins_engine_deactivate_plugin_real (XedPluginsEngine *engine, - XedPluginInfo *info); - -typedef gboolean (*LoadDirCallback)(XedPluginsEngine *engine, const gchar *filename, gpointer userdata); - -static gboolean -load_dir_real (XedPluginsEngine *engine, - const gchar *dir, - const gchar *suffix, - LoadDirCallback callback, - gpointer userdata) -{ - GError *error = NULL; - GDir *d; - const gchar *dirent; - gboolean ret = TRUE; - - g_return_val_if_fail (dir != NULL, TRUE); - - xed_debug_message (DEBUG_PLUGINS, "DIR: %s", dir); - - d = g_dir_open (dir, 0, &error); - if (!d) - { - g_warning ("%s", error->message); - g_error_free (error); - return TRUE; - } - - while ((dirent = g_dir_read_name (d))) - { - gchar *filename; - - if (!g_str_has_suffix (dirent, suffix)) - continue; - - filename = g_build_filename (dir, dirent, NULL); - - ret = callback (engine, filename, userdata); - - g_free (filename); - - if (!ret) - break; - } - - g_dir_close (d); - return ret; -} - -static gboolean -load_plugin_info (XedPluginsEngine *engine, - const gchar *filename, - gpointer userdata) -{ - XedPluginInfo *info; - - info = _xed_plugin_info_new (filename); - - if (info == NULL) - return TRUE; - - /* If a plugin with this name has already been loaded - * drop this one (user plugins override system plugins) */ - if (xed_plugins_engine_get_plugin_info (engine, xed_plugin_info_get_module_name (info)) != NULL) - { - xed_debug_message (DEBUG_PLUGINS, "Two or more plugins named '%s'. " - "Only the first will be considered.\n", - xed_plugin_info_get_module_name (info)); - - _xed_plugin_info_unref (info); - - return TRUE; - } - - engine->priv->plugin_list = g_list_prepend (engine->priv->plugin_list, info); - - xed_debug_message (DEBUG_PLUGINS, "Plugin %s loaded", info->name); - return TRUE; -} - -static void -load_all_plugins (XedPluginsEngine *engine) -{ - gchar *plugin_dir; - const gchar *pdirs_env = NULL; - - /* load user plugins */ - plugin_dir = xed_dirs_get_user_plugins_dir (); - if (g_file_test (plugin_dir, G_FILE_TEST_IS_DIR)) - { - load_dir_real (engine, - plugin_dir, - PLUGIN_EXT, - load_plugin_info, - NULL); - - } - g_free (plugin_dir); - - /* load system plugins */ - pdirs_env = g_getenv ("XED_PLUGINS_PATH"); - - xed_debug_message (DEBUG_PLUGINS, "XED_PLUGINS_PATH=%s", pdirs_env); - - if (pdirs_env != NULL) - { - gchar **pdirs; - gint i; - - pdirs = g_strsplit (pdirs_env, G_SEARCHPATH_SEPARATOR_S, 0); - - for (i = 0; pdirs[i] != NULL; i++) - { - if (!load_dir_real (engine, - pdirs[i], - PLUGIN_EXT, - load_plugin_info, - NULL)) - { - break; - } - } - - g_strfreev (pdirs); - } - else - { - plugin_dir = xed_dirs_get_xed_plugins_dir (); - - load_dir_real (engine, - plugin_dir, - PLUGIN_EXT, - load_plugin_info, - NULL); - - g_free (plugin_dir); - } -} - -static guint -hash_lowercase (gconstpointer data) -{ - gchar *lowercase; - guint ret; - - lowercase = g_ascii_strdown ((const gchar *)data, -1); - ret = g_str_hash (lowercase); - g_free (lowercase); - - return ret; -} - -static gboolean -equal_lowercase (gconstpointer a, gconstpointer b) -{ - return g_ascii_strcasecmp ((const gchar *)a, (const gchar *)b) == 0; -} - -static void -loader_destroy (LoaderInfo *info) -{ - if (!info) - return; - - if (info->loader) - g_object_unref (info->loader); - - g_free (info); -} - -static void -add_loader (XedPluginsEngine *engine, - const gchar *loader_id, - XedObjectModule *module) -{ - LoaderInfo *info; - - info = g_new (LoaderInfo, 1); - info->loader = NULL; - info->module = module; - - g_hash_table_insert (engine->priv->loaders, g_strdup (loader_id), info); -} - static void xed_plugins_engine_init (XedPluginsEngine *engine) { - xed_debug (DEBUG_PLUGINS); + gchar *private_path; + GError *error = NULL; - if (!g_module_supported ()) - { - g_warning ("xed is not able to initialize the plugins engine."); - return; - } + xed_debug (DEBUG_PLUGINS); - engine->priv = G_TYPE_INSTANCE_GET_PRIVATE (engine, - XED_TYPE_PLUGINS_ENGINE, - XedPluginsEnginePrivate); + engine->priv = G_TYPE_INSTANCE_GET_PRIVATE (engine, XED_TYPE_PLUGINS_ENGINE, XedPluginsEnginePrivate); - load_all_plugins (engine); + engine->priv->plugin_settings = g_settings_new (XED_SCHEMA); - /* make sure that the first reactivation will read active plugins - from the prefs */ - engine->priv->activate_from_prefs = TRUE; + peas_engine_enable_loader (PEAS_ENGINE (engine), "python3"); - /* mapping from loadername -> loader object */ - engine->priv->loaders = g_hash_table_new_full (hash_lowercase, - equal_lowercase, - (GDestroyNotify)g_free, - (GDestroyNotify)loader_destroy); + /* This should be moved to libpeas */ + if (!g_irepository_require (g_irepository_get_default (), "Peas", "1.0", 0, &error)) + { + g_warning ("Could not load Peas repository: %s", error->message); + g_error_free (error); + error = NULL; + } + + if (!g_irepository_require (g_irepository_get_default (), "PeasGtk", "1.0", 0, &error)) + { + g_warning ("Could not load PeasGtk repository: %s", error->message); + g_error_free (error); + error = NULL; + } + + private_path = g_build_filename (LIBDIR, "girepository-1.0", NULL); + + if (!g_irepository_require_private (g_irepository_get_default (), private_path, "Xed", "1.0", 0, &error)) + { + g_warning ("Could not load Xed repository: %s", error->message); + g_error_free (error); + error = NULL; + } + + g_free (private_path); + + peas_engine_add_search_path (PEAS_ENGINE (engine), + xed_dirs_get_user_plugins_dir (), + xed_dirs_get_user_plugins_dir ()); + + peas_engine_add_search_path (PEAS_ENGINE (engine), + xed_dirs_get_xed_plugins_dir(), + xed_dirs_get_xed_plugins_data_dir()); + + g_settings_bind (engine->priv->plugin_settings, GPM_ACTIVE_PLUGINS, + engine, "loaded-plugins", G_SETTINGS_BIND_DEFAULT); } static void -loader_garbage_collect (const char *id, LoaderInfo *info) +xed_plugins_engine_dispose (GObject *object) { - if (info->loader) - xed_plugin_loader_garbage_collect (info->loader); -} + XedPluginsEngine *engine = XED_PLUGINS_ENGINE (object); -void -xed_plugins_engine_garbage_collect (XedPluginsEngine *engine) -{ - g_hash_table_foreach (engine->priv->loaders, - (GHFunc) loader_garbage_collect, - NULL); -} + if (engine->priv->plugin_settings != NULL) + { + g_object_unref (engine->priv->plugin_settings); + engine->priv->plugin_settings = NULL; + } -static void -xed_plugins_engine_finalize (GObject *object) -{ - XedPluginsEngine *engine = XED_PLUGINS_ENGINE (object); - GList *item; - - xed_debug (DEBUG_PLUGINS); - - /* Firs deactivate all plugins */ - for (item = engine->priv->plugin_list; item; item = item->next) - { - XedPluginInfo *info = XED_PLUGIN_INFO (item->data); - - if (xed_plugin_info_is_active (info)) - xed_plugins_engine_deactivate_plugin_real (engine, info); - } - - /* unref the loaders */ - g_hash_table_destroy (engine->priv->loaders); - - /* and finally free the infos */ - for (item = engine->priv->plugin_list; item; item = item->next) - { - XedPluginInfo *info = XED_PLUGIN_INFO (item->data); - - _xed_plugin_info_unref (info); - } - - g_list_free (engine->priv->plugin_list); - - G_OBJECT_CLASS (xed_plugins_engine_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_plugins_engine_parent_class)->dispose (object); } static void xed_plugins_engine_class_init (XedPluginsEngineClass *klass) { - GType the_type = G_TYPE_FROM_CLASS (klass); - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = xed_plugins_engine_finalize; - klass->activate_plugin = xed_plugins_engine_activate_plugin_real; - klass->deactivate_plugin = xed_plugins_engine_deactivate_plugin_real; + object_class->dispose = xed_plugins_engine_dispose; - signals[ACTIVATE_PLUGIN] = - g_signal_new ("activate-plugin", - the_type, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedPluginsEngineClass, activate_plugin), - NULL, NULL, - g_cclosure_marshal_VOID__BOXED, - G_TYPE_NONE, - 1, - XED_TYPE_PLUGIN_INFO | G_SIGNAL_TYPE_STATIC_SCOPE); - - signals[DEACTIVATE_PLUGIN] = - g_signal_new ("deactivate-plugin", - the_type, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedPluginsEngineClass, deactivate_plugin), - NULL, NULL, - g_cclosure_marshal_VOID__BOXED, - G_TYPE_NONE, - 1, - XED_TYPE_PLUGIN_INFO | G_SIGNAL_TYPE_STATIC_SCOPE); - - g_type_class_add_private (klass, sizeof (XedPluginsEnginePrivate)); -} - -static gboolean -load_loader (XedPluginsEngine *engine, - const gchar *filename, - gpointer data) -{ - XedObjectModule *module; - gchar *base; - gchar *path; - const gchar *id; - GType type; - - /* try to load in the module */ - path = g_path_get_dirname (filename); - base = g_path_get_basename (filename); - - /* for now they are all resident */ - module = xed_object_module_new (base, - path, - "register_xed_plugin_loader", - TRUE); - - g_free (base); - g_free (path); - - /* make sure to load the type definition */ - if (!g_type_module_use (G_TYPE_MODULE (module))) - { - g_object_unref (module); - g_warning ("Plugin loader module `%s' could not be loaded", filename); - - return TRUE; - } - - /* get the exported type and check the name as exported by the - * loader interface */ - type = xed_object_module_get_object_type (module); - id = xed_plugin_loader_type_get_id (type); - - add_loader (engine, id, module); - g_type_module_unuse (G_TYPE_MODULE (module)); - - return TRUE; -} - -static void -ensure_loader (LoaderInfo *info) -{ - if (info->loader == NULL && info->module != NULL) - { - /* create a new loader object */ - XedPluginLoader *loader; - loader = (XedPluginLoader *)xed_object_module_new_object (info->module, NULL); - - if (loader == NULL || !XED_IS_PLUGIN_LOADER (loader)) - { - g_warning ("Loader object is not a valid XedPluginLoader instance"); - - if (loader != NULL && G_IS_OBJECT (loader)) - g_object_unref (loader); - } - else - { - info->loader = loader; - } - } -} - -static XedPluginLoader * -get_plugin_loader (XedPluginsEngine *engine, XedPluginInfo *info) -{ - const gchar *loader_id; - LoaderInfo *loader_info; - - loader_id = info->loader; - - loader_info = (LoaderInfo *)g_hash_table_lookup ( - engine->priv->loaders, - loader_id); - - if (loader_info == NULL) - { - gchar *loader_dir; - - loader_dir = xed_dirs_get_xed_plugin_loaders_dir (); - - /* loader could not be found in the hash, try to find it by - scanning */ - load_dir_real (engine, - loader_dir, - LOADER_EXT, - (LoadDirCallback)load_loader, - NULL); - g_free (loader_dir); - - loader_info = (LoaderInfo *)g_hash_table_lookup ( - engine->priv->loaders, - loader_id); - } - - if (loader_info == NULL) - { - /* cache non-existent so we don't scan again */ - add_loader (engine, loader_id, NULL); - return NULL; - } - - ensure_loader (loader_info); - return loader_info->loader; + g_type_class_add_private (klass, sizeof (XedPluginsEnginePrivate)); } XedPluginsEngine * xed_plugins_engine_get_default (void) { - if (default_engine != NULL) - return default_engine; + if (default_engine != NULL) + { + return default_engine; + } - default_engine = XED_PLUGINS_ENGINE (g_object_new (XED_TYPE_PLUGINS_ENGINE, NULL)); - g_object_add_weak_pointer (G_OBJECT (default_engine), - (gpointer) &default_engine); - return default_engine; -} - -const GList * -xed_plugins_engine_get_plugin_list (XedPluginsEngine *engine) -{ - xed_debug (DEBUG_PLUGINS); - - return engine->priv->plugin_list; -} - -static gint -compare_plugin_info_and_name (XedPluginInfo *info, - const gchar *module_name) -{ - return strcmp (xed_plugin_info_get_module_name (info), module_name); -} - -XedPluginInfo * -xed_plugins_engine_get_plugin_info (XedPluginsEngine *engine, - const gchar *name) -{ - GList *l = g_list_find_custom (engine->priv->plugin_list, - name, - (GCompareFunc) compare_plugin_info_and_name); - - return l == NULL ? NULL : (XedPluginInfo *) l->data; -} - -static void -save_active_plugin_list (XedPluginsEngine *engine) -{ - GSList *active_plugins = NULL; - GList *l; - - for (l = engine->priv->plugin_list; l != NULL; l = l->next) - { - XedPluginInfo *info = (XedPluginInfo *) l->data; - - if (xed_plugin_info_is_active (info)) - { - active_plugins = g_slist_prepend (active_plugins, - (gpointer)xed_plugin_info_get_module_name (info)); - } - } - - xed_prefs_manager_set_active_plugins (active_plugins); - - g_slist_free (active_plugins); -} - -static gboolean -load_plugin (XedPluginsEngine *engine, - XedPluginInfo *info) -{ - XedPluginLoader *loader; - gchar *path; - - if (xed_plugin_info_is_active (info)) - return TRUE; - - if (!xed_plugin_info_is_available (info)) - return FALSE; - - loader = get_plugin_loader (engine, info); - - if (loader == NULL) - { - g_warning ("Could not find loader `%s' for plugin `%s'", info->loader, info->name); - info->available = FALSE; - return FALSE; - } - - path = g_path_get_dirname (info->file); - g_return_val_if_fail (path != NULL, FALSE); - - info->plugin = xed_plugin_loader_load (loader, info, path); - - g_free (path); - - if (info->plugin == NULL) - { - g_warning ("Error loading plugin '%s'", info->name); - info->available = FALSE; - return FALSE; - } - - return TRUE; -} - -static void -xed_plugins_engine_activate_plugin_real (XedPluginsEngine *engine, - XedPluginInfo *info) -{ - const GList *wins; - - if (!load_plugin (engine, info)) - return; - - for (wins = xed_app_get_windows (xed_app_get_default ()); - wins != NULL; - wins = wins->next) - { - xed_plugin_activate (info->plugin, XED_WINDOW (wins->data)); - } -} - -gboolean -xed_plugins_engine_activate_plugin (XedPluginsEngine *engine, - XedPluginInfo *info) -{ - xed_debug (DEBUG_PLUGINS); - - g_return_val_if_fail (info != NULL, FALSE); - - if (!xed_plugin_info_is_available (info)) - return FALSE; - - if (xed_plugin_info_is_active (info)) - return TRUE; - - g_signal_emit (engine, signals[ACTIVATE_PLUGIN], 0, info); - - if (xed_plugin_info_is_active (info)) - save_active_plugin_list (engine); - - return xed_plugin_info_is_active (info); -} - -static void -call_plugin_deactivate (XedPlugin *plugin, - XedWindow *window) -{ - xed_plugin_deactivate (plugin, window); - - /* ensure update of ui manager, because we suspect it does something - with expected static strings in the type module (when unloaded the - strings don't exist anymore, and ui manager updates in an idle - func) */ - gtk_ui_manager_ensure_update (xed_window_get_ui_manager (window)); -} - -static void -xed_plugins_engine_deactivate_plugin_real (XedPluginsEngine *engine, - XedPluginInfo *info) -{ - const GList *wins; - XedPluginLoader *loader; - - if (!xed_plugin_info_is_active (info) || - !xed_plugin_info_is_available (info)) - return; - - for (wins = xed_app_get_windows (xed_app_get_default ()); - wins != NULL; - wins = wins->next) - { - call_plugin_deactivate (info->plugin, XED_WINDOW (wins->data)); - } - - /* first unref the plugin (the loader still has one) */ - g_object_unref (info->plugin); - - /* find the loader and tell it to gc and unload the plugin */ - loader = get_plugin_loader (engine, info); - - xed_plugin_loader_garbage_collect (loader); - xed_plugin_loader_unload (loader, info); - - info->plugin = NULL; -} - -gboolean -xed_plugins_engine_deactivate_plugin (XedPluginsEngine *engine, - XedPluginInfo *info) -{ - xed_debug (DEBUG_PLUGINS); - - g_return_val_if_fail (info != NULL, FALSE); - - if (!xed_plugin_info_is_active (info)) - return TRUE; - - g_signal_emit (engine, signals[DEACTIVATE_PLUGIN], 0, info); - if (!xed_plugin_info_is_active (info)) - save_active_plugin_list (engine); - - return !xed_plugin_info_is_active (info); -} - -void -xed_plugins_engine_activate_plugins (XedPluginsEngine *engine, - XedWindow *window) -{ - GSList *active_plugins = NULL; - GList *pl; - - xed_debug (DEBUG_PLUGINS); - - g_return_if_fail (XED_IS_PLUGINS_ENGINE (engine)); - g_return_if_fail (XED_IS_WINDOW (window)); - - /* the first time, we get the 'active' plugins from GSettings */ - if (engine->priv->activate_from_prefs) - { - active_plugins = xed_prefs_manager_get_active_plugins (); - } - - for (pl = engine->priv->plugin_list; pl; pl = pl->next) - { - XedPluginInfo *info = (XedPluginInfo*)pl->data; - - if (engine->priv->activate_from_prefs && - g_slist_find_custom (active_plugins, - xed_plugin_info_get_module_name (info), - (GCompareFunc)strcmp) == NULL) - continue; - - /* If plugin is not active, don't try to activate/load it */ - if (!engine->priv->activate_from_prefs && - !xed_plugin_info_is_active (info)) - continue; - - if (load_plugin (engine, info)) - xed_plugin_activate (info->plugin, - window); - } - - if (engine->priv->activate_from_prefs) - { - g_slist_foreach (active_plugins, (GFunc) g_free, NULL); - g_slist_free (active_plugins); - engine->priv->activate_from_prefs = FALSE; - } - - xed_debug_message (DEBUG_PLUGINS, "End"); - - /* also call update_ui after activation */ - xed_plugins_engine_update_plugins_ui (engine, window); -} - -void -xed_plugins_engine_deactivate_plugins (XedPluginsEngine *engine, - XedWindow *window) -{ - GList *pl; - - xed_debug (DEBUG_PLUGINS); - - g_return_if_fail (XED_IS_PLUGINS_ENGINE (engine)); - g_return_if_fail (XED_IS_WINDOW (window)); - - for (pl = engine->priv->plugin_list; pl; pl = pl->next) - { - XedPluginInfo *info = (XedPluginInfo*)pl->data; - - /* check if the plugin is actually active */ - if (!xed_plugin_info_is_active (info)) - continue; - - /* call deactivate for the plugin for this window */ - xed_plugin_deactivate (info->plugin, window); - } - - xed_debug_message (DEBUG_PLUGINS, "End"); -} - -void -xed_plugins_engine_update_plugins_ui (XedPluginsEngine *engine, - XedWindow *window) -{ - GList *pl; - - xed_debug (DEBUG_PLUGINS); - - g_return_if_fail (XED_IS_PLUGINS_ENGINE (engine)); - g_return_if_fail (XED_IS_WINDOW (window)); - - /* call update_ui for all active plugins */ - for (pl = engine->priv->plugin_list; pl; pl = pl->next) - { - XedPluginInfo *info = (XedPluginInfo*)pl->data; - - if (!xed_plugin_info_is_active (info)) - continue; - - xed_debug_message (DEBUG_PLUGINS, "Updating UI of %s", info->name); - xed_plugin_update_ui (info->plugin, window); - } -} - -void -xed_plugins_engine_configure_plugin (XedPluginsEngine *engine, - XedPluginInfo *info, - GtkWindow *parent) -{ - GtkWidget *conf_dlg; - - GtkWindowGroup *wg; - - xed_debug (DEBUG_PLUGINS); - - g_return_if_fail (info != NULL); - - conf_dlg = xed_plugin_create_configure_dialog (info->plugin); - g_return_if_fail (conf_dlg != NULL); - gtk_window_set_transient_for (GTK_WINDOW (conf_dlg), - parent); - - wg = gtk_window_get_group (parent); - if (wg == NULL) - { - wg = gtk_window_group_new (); - gtk_window_group_add_window (wg, parent); - } - - gtk_window_group_add_window (wg, - GTK_WINDOW (conf_dlg)); - - gtk_window_set_modal (GTK_WINDOW (conf_dlg), TRUE); - gtk_widget_show (conf_dlg); -} - -void -xed_plugins_engine_active_plugins_changed (XedPluginsEngine *engine) -{ - gboolean to_activate; - GSList *active_plugins; - GList *pl; - - xed_debug (DEBUG_PLUGINS); - - active_plugins = xed_prefs_manager_get_active_plugins (); - - for (pl = engine->priv->plugin_list; pl; pl = pl->next) - { - XedPluginInfo *info = (XedPluginInfo*)pl->data; - - if (!xed_plugin_info_is_available (info)) - continue; - - to_activate = (g_slist_find_custom (active_plugins, - xed_plugin_info_get_module_name (info), - (GCompareFunc)strcmp) != NULL); - - if (!xed_plugin_info_is_active (info) && to_activate) - g_signal_emit (engine, signals[ACTIVATE_PLUGIN], 0, info); - else if (xed_plugin_info_is_active (info) && !to_activate) - g_signal_emit (engine, signals[DEACTIVATE_PLUGIN], 0, info); - } - - g_slist_foreach (active_plugins, (GFunc) g_free, NULL); - g_slist_free (active_plugins); -} - -void -xed_plugins_engine_rescan_plugins (XedPluginsEngine *engine) -{ - xed_debug (DEBUG_PLUGINS); - - load_all_plugins (engine); + default_engine = XED_PLUGINS_ENGINE (g_object_new (XED_TYPE_PLUGINS_ENGINE, NULL)); + g_object_add_weak_pointer (G_OBJECT (default_engine), (gpointer) &default_engine); + + return default_engine; } diff --git a/xed/xed-plugins-engine.h b/xed/xed-plugins-engine.h index 1c567d6..f2a0c9a 100644 --- a/xed/xed-plugins-engine.h +++ b/xed/xed-plugins-engine.h @@ -2,7 +2,7 @@ * xed-plugins-engine.h * This file is part of xed * - * Copyright (C) 2002-2005 - Paolo Maggi + * Copyright (C) 2002-2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2002-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2002-2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -32,9 +32,7 @@ #define __XED_PLUGINS_ENGINE_H__ #include -#include "xed-window.h" -#include "xed-plugin-info.h" -#include "xed-plugin.h" +#include G_BEGIN_DECLS @@ -45,62 +43,25 @@ G_BEGIN_DECLS #define XED_IS_PLUGINS_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_PLUGINS_ENGINE)) #define XED_PLUGINS_ENGINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_PLUGINS_ENGINE, XedPluginsEngineClass)) -typedef struct _XedPluginsEngine XedPluginsEngine; -typedef struct _XedPluginsEnginePrivate XedPluginsEnginePrivate; +typedef struct _XedPluginsEngine XedPluginsEngine; +typedef struct _XedPluginsEnginePrivate XedPluginsEnginePrivate; struct _XedPluginsEngine { - GObject parent; - XedPluginsEnginePrivate *priv; + PeasEngine parent; + XedPluginsEnginePrivate *priv; }; -typedef struct _XedPluginsEngineClass XedPluginsEngineClass; +typedef struct _XedPluginsEngineClass XedPluginsEngineClass; struct _XedPluginsEngineClass { - GObjectClass parent_class; - - void (* activate_plugin) (XedPluginsEngine *engine, - XedPluginInfo *info); - - void (* deactivate_plugin) (XedPluginsEngine *engine, - XedPluginInfo *info); + PeasEngineClass parent_class; }; -GType xed_plugins_engine_get_type (void) G_GNUC_CONST; +GType xed_plugins_engine_get_type (void) G_GNUC_CONST; -XedPluginsEngine *xed_plugins_engine_get_default (void); - -void xed_plugins_engine_garbage_collect (XedPluginsEngine *engine); - -const GList *xed_plugins_engine_get_plugin_list (XedPluginsEngine *engine); - -XedPluginInfo *xed_plugins_engine_get_plugin_info (XedPluginsEngine *engine, - const gchar *name); - -/* plugin load and unloading (overall, for all windows) */ -gboolean xed_plugins_engine_activate_plugin (XedPluginsEngine *engine, - XedPluginInfo *info); -gboolean xed_plugins_engine_deactivate_plugin (XedPluginsEngine *engine, - XedPluginInfo *info); - -void xed_plugins_engine_configure_plugin (XedPluginsEngine *engine, - XedPluginInfo *info, - GtkWindow *parent); - -/* plugin activation/deactivation per window, private to XedWindow */ -void xed_plugins_engine_activate_plugins (XedPluginsEngine *engine, - XedWindow *window); -void xed_plugins_engine_deactivate_plugins (XedPluginsEngine *engine, - XedWindow *window); -void xed_plugins_engine_update_plugins_ui (XedPluginsEngine *engine, - XedWindow *window); - -/* private for GSettings notification */ -void xed_plugins_engine_active_plugins_changed - (XedPluginsEngine *engine); - -void xed_plugins_engine_rescan_plugins (XedPluginsEngine *engine); +XedPluginsEngine *xed_plugins_engine_get_default (void); G_END_DECLS diff --git a/xed/xed-prefs-manager-app.c b/xed/xed-prefs-manager-app.c index bdeddb6..56c4c0d 100644 --- a/xed/xed-prefs-manager-app.c +++ b/xed/xed-prefs-manager-app.c @@ -112,10 +112,6 @@ static void xed_prefs_manager_auto_save_changed (GSettings *settings, gchar *key, gpointer user_data); -static void xed_prefs_manager_active_plugins_changed (GSettings *settings, - gchar *key, - gpointer user_data); - /* GUI state is serialized to a .desktop file, not in GSettings */ #define XED_STATE_DEFAULT_WINDOW_STATE 0 @@ -708,11 +704,6 @@ xed_prefs_manager_app_init (void) "changed::" GPM_WRITABLE_VFS_SCHEMES, G_CALLBACK (xed_prefs_manager_auto_save_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_ACTIVE_PLUGINS, - G_CALLBACK (xed_prefs_manager_active_plugins_changed), - NULL); } return xed_prefs_manager != NULL; @@ -1305,7 +1296,7 @@ xed_prefs_manager_source_style_scheme_changed (GSettings *settings, for (l = docs; l != NULL; l = l->next) { g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); - + gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (l->data), style); } @@ -1394,21 +1385,3 @@ xed_prefs_manager_auto_save_changed (GSettings *settings, g_list_free (docs); } } - -static void -xed_prefs_manager_active_plugins_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_ACTIVE_PLUGINS) == 0) - { - XedPluginsEngine *engine; - - engine = xed_plugins_engine_get_default (); - - xed_plugins_engine_active_plugins_changed (engine); - } -} - diff --git a/xed/xed-window-private.h b/xed/xed-window-private.h index 0be7945..84a4b99 100644 --- a/xed/xed-window-private.h +++ b/xed/xed-window-private.h @@ -2,7 +2,7 @@ * xed-window-private.h * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -31,6 +31,8 @@ #ifndef __XED_WINDOW_PRIVATE_H__ #define __XED_WINDOW_PRIVATE_H__ +#include + #include "xed/xed-window.h" #include "xed-prefs-manager.h" #include "xed-message-bus.h" @@ -48,11 +50,12 @@ struct _XedWindowPrivate GtkWidget *hpaned; GtkWidget *vpaned; - + GtkWidget *tab_width_combo; GtkWidget *language_combo; - - XedMessageBus *message_bus; + + XedMessageBus *message_bus; + PeasExtensionSet *extensions; /* Widgets for fullscreen mode */ GtkWidget *fullscreen_controls; @@ -61,8 +64,8 @@ struct _XedWindowPrivate gboolean fullscreen_animation_enter; /* statusbar and context ids for statusbar messages */ - GtkWidget *statusbar; - GtkWidget *searchbar; + GtkWidget *statusbar; + GtkWidget *searchbar; guint generic_message_cid; guint tip_message_cid; guint tab_width_id; @@ -93,7 +96,7 @@ struct _XedWindowPrivate gint num_tabs_with_error; gint width; - gint height; + gint height; GdkWindowState window_state; gint side_panel_size; diff --git a/xed/xed-window.c b/xed/xed-window.c index 1647476..2967974 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include "xed-ui.h" #include "xed-window.h" @@ -154,14 +156,18 @@ xed_window_dispose (GObject *object) /* First of all, force collection so that plugins * really drop some of the references. */ - xed_plugins_engine_garbage_collect (xed_plugins_engine_get_default ()); + peas_engine_garbage_collect (PEAS_ENGINE (xed_plugins_engine_get_default())); /* save the panes position and make sure to deactivate plugins * for this window, but only once */ if (!window->priv->dispose_has_run) { save_panes_state (window); - xed_plugins_engine_deactivate_plugins (xed_plugins_engine_get_default (), window); + /* Note that unreffing the extension will automatically remove + all extensions which in turn will deactivate the extension */ + g_object_unref (window->priv->extensions); + + peas_engine_garbage_collect (PEAS_ENGINE (xed_plugins_engine_get_default ())); window->priv->dispose_has_run = TRUE; } @@ -203,9 +209,8 @@ xed_window_dispose (GObject *object) window->priv->window_group = NULL; } - /* Now that there have broken some reference loops, force collection again. - */ - xed_plugins_engine_garbage_collect (xed_plugins_engine_get_default ()); + /* Now that there have broken some reference loops, force collection again. */ + peas_engine_garbage_collect (PEAS_ENGINE (xed_plugins_engine_get_default ())); G_OBJECT_CLASS (xed_window_parent_class)->dispose (object); } @@ -293,7 +298,7 @@ static void xed_window_tab_removed (XedWindow *window, XedTab *tab) { - xed_plugins_engine_garbage_collect (xed_plugins_engine_get_default ()); + peas_engine_garbage_collect (PEAS_ENGINE (xed_plugins_engine_get_default ())); } static void @@ -641,7 +646,7 @@ set_sensitivity_according_to_tab (XedWindow *window, update_next_prev_doc_sensitivity (window, tab); - xed_plugins_engine_update_plugins_ui (xed_plugins_engine_get_default (), window); + peas_extension_set_call (window->priv->extensions, "update_state", window); } static void @@ -2289,7 +2294,7 @@ sync_name (XedTab *tab, g_free (escaped_name); g_free (tip); - xed_plugins_engine_update_plugins_ui (xed_plugins_engine_get_default (), window); + peas_extension_set_call (window->priv->extensions, "update_state", window); } static XedWindow * @@ -2702,7 +2707,7 @@ selection_changed (XedDocument *doc, gtk_action_set_sensitive (action, state_normal && editable && gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER(doc))); - xed_plugins_engine_update_plugins_ui (xed_plugins_engine_get_default (), window); + peas_extension_set_call (window->priv->extensions, "update_state", window); } static void @@ -2711,7 +2716,7 @@ sync_languages_menu (XedDocument *doc, XedWindow *window) { update_languages_menu (window); - xed_plugins_engine_update_plugins_ui (xed_plugins_engine_get_default (), window); + peas_extension_set_call (window->priv->extensions, "update_state", window); } static void @@ -2721,7 +2726,7 @@ readonly_changed (XedDocument *doc, { set_sensitivity_according_to_tab (window, window->priv->active_tab); sync_name (window->priv->active_tab, NULL, window); - xed_plugins_engine_update_plugins_ui (xed_plugins_engine_get_default (), window); + peas_extension_set_call (window->priv->extensions, "update_state", window); } static void @@ -2729,7 +2734,7 @@ editable_changed (XedView *view, GParamSpec *arg1, XedWindow *window) { - xed_plugins_engine_update_plugins_ui (xed_plugins_engine_get_default (), window); + peas_extension_set_call (window->priv->extensions, "update_state", window); } static void @@ -2871,7 +2876,7 @@ notebook_tab_removed (XedNotebook *notebook, if (window->priv->num_tabs == 0) { - xed_plugins_engine_update_plugins_ui (xed_plugins_engine_get_default (), window); + peas_extension_set_call (window->priv->extensions, "update_state", window); } update_window_state (window); @@ -3272,6 +3277,28 @@ add_notebook (XedWindow *window, connect_notebook_signals (window, notebook); } + static void +on_extension_added (PeasExtensionSet *extensions, + PeasPluginInfo *info, + PeasExtension *exten, + XedWindow *window) +{ + peas_extension_call (exten, "activate", window); +} + +static void +on_extension_removed (PeasExtensionSet *extensions, + PeasPluginInfo *info, + PeasExtension *exten, + XedWindow *window) +{ + peas_extension_call (exten, "deactivate", window); + + /* Ensure update of the ui manager, because we suspect it does something with expected static strings in the + * type module (when unloaded the strings don't exist anymore, and the ui manager update in a idle func) */ + gtk_ui_manager_ensure_update (window->priv->manager); +} + static void xed_window_init (XedWindow *window) { @@ -3378,7 +3405,13 @@ xed_window_init (XedWindow *window) xed_debug_message (DEBUG_WINDOW, "Update plugins ui"); - xed_plugins_engine_activate_plugins (xed_plugins_engine_get_default (), window); + window->priv->extensions = peas_extension_set_new (PEAS_ENGINE (xed_plugins_engine_get_default ()), + PEAS_TYPE_ACTIVATABLE, "object", window, NULL); + + peas_extension_set_call (window->priv->extensions, "activate"); + + g_signal_connect (window->priv->extensions, "extension-added", G_CALLBACK (on_extension_added), window); + g_signal_connect (window->priv->extensions, "extension-removed", G_CALLBACK (on_extension_removed), window); /* set visibility of panes. * This needs to be done after plugins activatation */ From 7220312ac6000e8450e397777224e48da78b7e01 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 13:08:36 -0800 Subject: [PATCH 028/132] changecase-plugin: Port to libpeas Adapted from: https://github.com/mate-desktop/pluma/commit/c475e25a50537301f95606a4b09f4951ccd592a7 --- plugins/changecase/xed-changecase-plugin.c | 501 ++++++++++++--------- plugins/changecase/xed-changecase-plugin.h | 34 +- 2 files changed, 306 insertions(+), 229 deletions(-) diff --git a/plugins/changecase/xed-changecase-plugin.c b/plugins/changecase/xed-changecase-plugin.c index cf6da80..52b9e4e 100644 --- a/plugins/changecase/xed-changecase-plugin.c +++ b/plugins/changecase/xed-changecase-plugin.c @@ -1,13 +1,13 @@ /* * xed-changecase-plugin.c - * + * * Copyright (C) 2004-2005 - Paolo Borelli * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -28,18 +28,42 @@ #include #include +#include +#include #include -#define WINDOW_DATA_KEY "XedChangecasePluginWindowData" +#define XED_CHANGECASE_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ + XED_TYPE_CHANGECASE_PLUGIN, \ + XedChangecasePluginPrivate)) -XED_PLUGIN_REGISTER_TYPE(XedChangecasePlugin, xed_changecase_plugin) +static void peas_activatable_iface_init (PeasActivatableInterface *iface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedChangecasePlugin, + xed_changecase_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init)) + +struct _XedChangecasePluginPrivate +{ + GtkWidget *window; + GtkActionGroup *action_group; + guint ui_id; +}; + +enum +{ + PROP_0, + PROP_OBJECT +}; typedef enum { - TO_UPPER_CASE, - TO_LOWER_CASE, - INVERT_CASE, - TO_TITLE_CASE, + TO_UPPER_CASE, + TO_LOWER_CASE, + INVERT_CASE, + TO_TITLE_CASE, } ChangeCaseChoice; static void @@ -47,24 +71,23 @@ do_upper_case (GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end) { - GString *s = g_string_new (NULL); + GString *s = g_string_new (NULL); - while (!gtk_text_iter_is_end (start) && - !gtk_text_iter_equal (start, end)) - { - gunichar c, nc; + while (!gtk_text_iter_is_end (start) && !gtk_text_iter_equal (start, end)) + { + gunichar c, nc; - c = gtk_text_iter_get_char (start); - nc = g_unichar_toupper (c); - g_string_append_unichar (s, nc); + c = gtk_text_iter_get_char (start); + nc = g_unichar_toupper (c); + g_string_append_unichar (s, nc); - gtk_text_iter_forward_char (start); - } + gtk_text_iter_forward_char (start); + } - gtk_text_buffer_delete_selection (buffer, TRUE, TRUE); - gtk_text_buffer_insert_at_cursor (buffer, s->str, s->len); + gtk_text_buffer_delete_selection (buffer, TRUE, TRUE); + gtk_text_buffer_insert_at_cursor (buffer, s->str, s->len); - g_string_free (s, TRUE); + g_string_free (s, TRUE); } static void @@ -72,24 +95,23 @@ do_lower_case (GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end) { - GString *s = g_string_new (NULL); + GString *s = g_string_new (NULL); - while (!gtk_text_iter_is_end (start) && - !gtk_text_iter_equal (start, end)) - { - gunichar c, nc; + while (!gtk_text_iter_is_end (start) && !gtk_text_iter_equal (start, end)) + { + gunichar c, nc; - c = gtk_text_iter_get_char (start); - nc = g_unichar_tolower (c); - g_string_append_unichar (s, nc); + c = gtk_text_iter_get_char (start); + nc = g_unichar_tolower (c); + g_string_append_unichar (s, nc); - gtk_text_iter_forward_char (start); - } + gtk_text_iter_forward_char (start); + } - gtk_text_buffer_delete_selection (buffer, TRUE, TRUE); - gtk_text_buffer_insert_at_cursor (buffer, s->str, s->len); + gtk_text_buffer_delete_selection (buffer, TRUE, TRUE); + gtk_text_buffer_insert_at_cursor (buffer, s->str, s->len); - g_string_free (s, TRUE); + g_string_free (s, TRUE); } static void @@ -97,27 +119,30 @@ do_invert_case (GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end) { - GString *s = g_string_new (NULL); + GString *s = g_string_new (NULL); - while (!gtk_text_iter_is_end (start) && - !gtk_text_iter_equal (start, end)) - { - gunichar c, nc; + while (!gtk_text_iter_is_end (start) && !gtk_text_iter_equal (start, end)) + { + gunichar c, nc; - c = gtk_text_iter_get_char (start); - if (g_unichar_islower (c)) - nc = g_unichar_toupper (c); - else - nc = g_unichar_tolower (c); - g_string_append_unichar (s, nc); + c = gtk_text_iter_get_char (start); + if (g_unichar_islower (c)) + { + nc = g_unichar_toupper (c); + } + else + { + nc = g_unichar_tolower (c); + } + g_string_append_unichar (s, nc); - gtk_text_iter_forward_char (start); - } + gtk_text_iter_forward_char (start); + } - gtk_text_buffer_delete_selection (buffer, TRUE, TRUE); - gtk_text_buffer_insert_at_cursor (buffer, s->str, s->len); + gtk_text_buffer_delete_selection (buffer, TRUE, TRUE); + gtk_text_buffer_insert_at_cursor (buffer, s->str, s->len); - g_string_free (s, TRUE); + g_string_free (s, TRUE); } static void @@ -125,113 +150,115 @@ do_title_case (GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end) { - GString *s = g_string_new (NULL); + GString *s = g_string_new (NULL); - while (!gtk_text_iter_is_end (start) && - !gtk_text_iter_equal (start, end)) - { - gunichar c, nc; + while (!gtk_text_iter_is_end (start) && !gtk_text_iter_equal (start, end)) + { + gunichar c, nc; - c = gtk_text_iter_get_char (start); - if (gtk_text_iter_starts_word (start)) - nc = g_unichar_totitle (c); - else - nc = g_unichar_tolower (c); - g_string_append_unichar (s, nc); + c = gtk_text_iter_get_char (start); + if (gtk_text_iter_starts_word (start)) + { + nc = g_unichar_totitle (c); + } + else + { + nc = g_unichar_tolower (c); + } + g_string_append_unichar (s, nc); - gtk_text_iter_forward_char (start); - } + gtk_text_iter_forward_char (start); + } - gtk_text_buffer_delete_selection (buffer, TRUE, TRUE); - gtk_text_buffer_insert_at_cursor (buffer, s->str, s->len); + gtk_text_buffer_delete_selection (buffer, TRUE, TRUE); + gtk_text_buffer_insert_at_cursor (buffer, s->str, s->len); - g_string_free (s, TRUE); + g_string_free (s, TRUE); } static void -change_case (XedWindow *window, +change_case (XedWindow *window, ChangeCaseChoice choice) { - XedDocument *doc; - GtkTextIter start, end; + XedDocument *doc; + GtkTextIter start, end; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - doc = xed_window_get_active_document (window); - g_return_if_fail (doc != NULL); + doc = xed_window_get_active_document (window); + g_return_if_fail (doc != NULL); - if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), - &start, &end)) - { - return; - } + if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &start, &end)) + { + return; + } - gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (doc)); + gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (doc)); - switch (choice) - { - case TO_UPPER_CASE: - do_upper_case (GTK_TEXT_BUFFER (doc), &start, &end); - break; - case TO_LOWER_CASE: - do_lower_case (GTK_TEXT_BUFFER (doc), &start, &end); - break; - case INVERT_CASE: - do_invert_case (GTK_TEXT_BUFFER (doc), &start, &end); - break; - case TO_TITLE_CASE: - do_title_case (GTK_TEXT_BUFFER (doc), &start, &end); - break; - default: - g_return_if_reached (); - } + switch (choice) + { + case TO_UPPER_CASE: + do_upper_case (GTK_TEXT_BUFFER (doc), &start, &end); + break; + case TO_LOWER_CASE: + do_lower_case (GTK_TEXT_BUFFER (doc), &start, &end); + break; + case INVERT_CASE: + do_invert_case (GTK_TEXT_BUFFER (doc), &start, &end); + break; + case TO_TITLE_CASE: + do_title_case (GTK_TEXT_BUFFER (doc), &start, &end); + break; + default: + g_return_if_reached (); + } - gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (doc)); + gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (doc)); } static void -upper_case_cb (GtkAction *action, +upper_case_cb (GtkAction *action, XedWindow *window) { - change_case (window, TO_UPPER_CASE); + change_case (window, TO_UPPER_CASE); } static void -lower_case_cb (GtkAction *action, +lower_case_cb (GtkAction *action, XedWindow *window) { - change_case (window, TO_LOWER_CASE); + change_case (window, TO_LOWER_CASE); } static void -invert_case_cb (GtkAction *action, +invert_case_cb (GtkAction *action, XedWindow *window) { - change_case (window, INVERT_CASE); + change_case (window, INVERT_CASE); } static void -title_case_cb (GtkAction *action, +title_case_cb (GtkAction *action, XedWindow *window) { - change_case (window, TO_TITLE_CASE); + change_case (window, TO_TITLE_CASE); } static const GtkActionEntry action_entries[] = { - { "ChangeCase", NULL, N_("C_hange Case") }, - { "UpperCase", NULL, N_("All _Upper Case"), NULL, - N_("Change selected text to upper case"), - G_CALLBACK (upper_case_cb) }, - { "LowerCase", NULL, N_("All _Lower Case"), NULL, - N_("Change selected text to lower case"), - G_CALLBACK (lower_case_cb) }, - { "InvertCase", NULL, N_("_Invert Case"), NULL, - N_("Invert the case of selected text"), - G_CALLBACK (invert_case_cb) }, - { "TitleCase", NULL, N_("_Title Case"), NULL, - N_("Capitalize the first letter of each selected word"), - G_CALLBACK (title_case_cb) } + { "ChangeCase", NULL, N_("C_hange Case") }, + { "UpperCase", NULL, N_("All _Upper Case"), NULL, + N_("Change selected text to upper case"), + G_CALLBACK (upper_case_cb) }, + { "LowerCase", NULL, N_("All _Lower Case"), NULL, + N_("Change selected text to lower case"), + G_CALLBACK (lower_case_cb) }, + { "InvertCase", NULL, N_("_Invert Case"), NULL, + N_("Invert the case of selected text"), + G_CALLBACK (invert_case_cb) }, + { "TitleCase", NULL, N_("_Title Case"), NULL, + N_("Capitalize the first letter of each selected word"), + G_CALLBACK (title_case_cb) } }; const gchar submenu[] = @@ -253,143 +280,187 @@ const gchar submenu[] = static void xed_changecase_plugin_init (XedChangecasePlugin *plugin) { - xed_debug_message (DEBUG_PLUGINS, "XedChangecasePlugin initializing"); + xed_debug_message (DEBUG_PLUGINS, "XedChangecasePlugin initializing"); + + plugin->priv = XED_CHANGECASE_PLUGIN_GET_PRIVATE (plugin); } static void -xed_changecase_plugin_finalize (GObject *object) +xed_changecase_plugin_dispose (GObject *object) { - G_OBJECT_CLASS (xed_changecase_plugin_parent_class)->finalize (object); + XedChangecasePlugin *plugin = XED_CHANGECASE_PLUGIN (object); - xed_debug_message (DEBUG_PLUGINS, "XedChangecasePlugin finalizing"); -} + xed_debug_message (DEBUG_PLUGINS, "XedChangecasePlugin disposing"); -typedef struct -{ - GtkActionGroup *action_group; - guint ui_id; -} WindowData; + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } -static void -free_window_data (WindowData *data) -{ - g_return_if_fail (data != NULL); + if (plugin->priv->action_group != NULL) + { + g_object_unref (plugin->priv->action_group); + plugin->priv->action_group = NULL; + } - g_slice_free (WindowData, data); + G_OBJECT_CLASS (xed_changecase_plugin_parent_class)->dispose (object); } static void -update_ui_real (XedWindow *window, - WindowData *data) +xed_changecase_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - GtkTextView *view; - GtkAction *action; - gboolean sensitive = FALSE; + XedChangecasePlugin *plugin = XED_CHANGECASE_PLUGIN (object); - xed_debug (DEBUG_PLUGINS); - - view = GTK_TEXT_VIEW (xed_window_get_active_view (window)); - - if (view != NULL) - { - GtkTextBuffer *buffer; - - buffer = gtk_text_view_get_buffer (view); - sensitive = (gtk_text_view_get_editable (view) && - gtk_text_buffer_get_has_selection (buffer)); - } - - action = gtk_action_group_get_action (data->action_group, - "ChangeCase"); - gtk_action_set_sensitive (action, sensitive); + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -impl_activate (XedPlugin *plugin, - XedWindow *window) +xed_changecase_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { - GtkUIManager *manager; - WindowData *data; - GError *error = NULL; + XedChangecasePlugin *plugin = XED_CHANGECASE_PLUGIN (object); - xed_debug (DEBUG_PLUGINS); - - data = g_slice_new (WindowData); - - manager = xed_window_get_ui_manager (window); - - data->action_group = gtk_action_group_new ("XedChangecasePluginActions"); - gtk_action_group_set_translation_domain (data->action_group, - GETTEXT_PACKAGE); - gtk_action_group_add_actions (data->action_group, - action_entries, - G_N_ELEMENTS (action_entries), - window); - - gtk_ui_manager_insert_action_group (manager, data->action_group, -1); - - data->ui_id = gtk_ui_manager_add_ui_from_string (manager, - submenu, - -1, - &error); - if (data->ui_id == 0) - { - g_warning ("%s", error->message); - free_window_data (data); - return; - } - - g_object_set_data_full (G_OBJECT (window), - WINDOW_DATA_KEY, - data, - (GDestroyNotify) free_window_data); - - update_ui_real (window, data); + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -impl_deactivate (XedPlugin *plugin, - XedWindow *window) +update_ui (XedChangecasePluginPrivate *data) { - GtkUIManager *manager; - WindowData *data; + XedWindow *window; + GtkTextView *view; + GtkAction *action; + gboolean sensitive = FALSE; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - manager = xed_window_get_ui_manager (window); + window = XED_WINDOW (data->window); + view = GTK_TEXT_VIEW (xed_window_get_active_view (window)); - data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); + if (view != NULL) + { + GtkTextBuffer *buffer; - gtk_ui_manager_remove_ui (manager, data->ui_id); - gtk_ui_manager_remove_action_group (manager, data->action_group); + buffer = gtk_text_view_get_buffer (view); + sensitive = (gtk_text_view_get_editable (view) && gtk_text_buffer_get_has_selection (buffer)); + } - g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL); + action = gtk_action_group_get_action (data->action_group, "ChangeCase"); + gtk_action_set_sensitive (action, sensitive); } static void -impl_update_ui (XedPlugin *plugin, - XedWindow *window) +xed_changecase_plugin_activate (PeasActivatable *activatable) { - WindowData *data; + XedChangecasePluginPrivate *data; + XedWindow *window; + GtkUIManager *manager; + GError *error = NULL; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); + data = XED_CHANGECASE_PLUGIN (activatable)->priv; + window = XED_WINDOW (data->window); - update_ui_real (window, data); + manager = xed_window_get_ui_manager (window); + + data->action_group = gtk_action_group_new ("XedChangecasePluginActions"); + gtk_action_group_set_translation_domain (data->action_group, GETTEXT_PACKAGE); + gtk_action_group_add_actions (data->action_group, action_entries, G_N_ELEMENTS (action_entries), window); + + gtk_ui_manager_insert_action_group (manager, data->action_group, -1); + + data->ui_id = gtk_ui_manager_add_ui_from_string (manager, submenu, -1, &error); + if (data->ui_id == 0) + { + g_warning ("%s", error->message); + return; + } + + update_ui (data); +} + +static void +xed_changecase_plugin_deactivate (PeasActivatable *activatable) +{ + XedChangecasePluginPrivate *data; + XedWindow *window; + GtkUIManager *manager; + + xed_debug (DEBUG_PLUGINS); + + data = XED_CHANGECASE_PLUGIN (activatable)->priv; + window = XED_WINDOW (data->window); + + manager = xed_window_get_ui_manager (window); + + gtk_ui_manager_remove_ui (manager, data->ui_id); + gtk_ui_manager_remove_action_group (manager, data->action_group); +} + +static void +xed_changecase_plugin_update_state (PeasActivatable *activatable) +{ + xed_debug (DEBUG_PLUGINS); + + update_ui (XED_CHANGECASE_PLUGIN (activatable)->priv); } static void xed_changecase_plugin_class_init (XedChangecasePluginClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - XedPluginClass *plugin_class = XED_PLUGIN_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = xed_changecase_plugin_finalize; + object_class->dispose = xed_changecase_plugin_dispose; + object_class->set_property = xed_changecase_plugin_set_property; + object_class->get_property = xed_changecase_plugin_get_property; - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_update_ui; + g_object_class_override_property (object_class, PROP_OBJECT, "object"); + + g_type_class_add_private (klass, sizeof (XedChangecasePluginPrivate)); +} + +static void +xed_changecase_plugin_class_finalize (XedChangecasePluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = xed_changecase_plugin_activate; + iface->deactivate = xed_changecase_plugin_deactivate; + iface->update_state = xed_changecase_plugin_update_state; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + xed_changecase_plugin_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + XED_TYPE_CHANGECASE_PLUGIN); } diff --git a/plugins/changecase/xed-changecase-plugin.h b/plugins/changecase/xed-changecase-plugin.h index 7363247..6053c4c 100644 --- a/plugins/changecase/xed-changecase-plugin.h +++ b/plugins/changecase/xed-changecase-plugin.h @@ -1,6 +1,6 @@ /* * xed-changecase-plugin.h - * + * * Copyright (C) 2004-2005 - Paolo Borelli * * This program is free software; you can redistribute it and/or modify @@ -25,47 +25,53 @@ #include #include -#include +#include +#include G_BEGIN_DECLS /* * Type checking and casting macros */ -#define XED_TYPE_CHANGECASE_PLUGIN (xed_changecase_plugin_get_type ()) -#define XED_CHANGECASE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePlugin)) -#define XED_CHANGECASE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePluginClass)) -#define XED_IS_CHANGECASE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_CHANGECASE_PLUGIN)) -#define XED_IS_CHANGECASE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_CHANGECASE_PLUGIN)) -#define XED_CHANGECASE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePluginClass)) +#define XED_TYPE_CHANGECASE_PLUGIN (xed_changecase_plugin_get_type ()) +#define XED_CHANGECASE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePlugin)) +#define XED_CHANGECASE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePluginClass)) +#define XED_IS_CHANGECASE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_CHANGECASE_PLUGIN)) +#define XED_IS_CHANGECASE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_CHANGECASE_PLUGIN)) +#define XED_CHANGECASE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePluginClass)) + +typedef struct _XedChangecasePluginPrivate XedChangecasePluginPrivate; /* * Main object structure */ -typedef struct _XedChangecasePlugin XedChangecasePlugin; +typedef struct _XedChangecasePlugin XedChangecasePlugin; struct _XedChangecasePlugin { - XedPlugin parent_instance; + PeasExtensionBase parent_instance; + + /*< private > */ + XedChangecasePluginPrivate *priv; }; /* * Class definition */ -typedef struct _XedChangecasePluginClass XedChangecasePluginClass; +typedef struct _XedChangecasePluginClass XedChangecasePluginClass; struct _XedChangecasePluginClass { - XedPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* * Public methods */ -GType xed_changecase_plugin_get_type (void) G_GNUC_CONST; +GType xed_changecase_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_xed_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS From fdc2da63a90308b6d6f07c603d61c06edba61051 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 13:13:01 -0800 Subject: [PATCH 029/132] docinfo-plugin: Port to libpeas Adapted from: https://github.com/mate-desktop/pluma/commit/9ca3dda49113bcc40b726ebf51db7f07d69e96ad --- plugins/docinfo/xed-docinfo-plugin.c | 846 ++++++++++++++------------- plugins/docinfo/xed-docinfo-plugin.h | 36 +- 2 files changed, 460 insertions(+), 422 deletions(-) diff --git a/plugins/docinfo/xed-docinfo-plugin.c b/plugins/docinfo/xed-docinfo-plugin.c index fc7b8df..a8337bd 100644 --- a/plugins/docinfo/xed-docinfo-plugin.c +++ b/plugins/docinfo/xed-docinfo-plugin.c @@ -1,13 +1,13 @@ /* * xed-docinfo-plugin.c - * - * Copyright (C) 2002-2005 Paolo Maggi + * + * Copyright (C) 2002-2005 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -31,551 +31,585 @@ #include #include #include +#include +#include #include #include -#define WINDOW_DATA_KEY "XedDocInfoWindowData" #define MENU_PATH "/MenuBar/ToolsMenu/ToolsOps_2" -XED_PLUGIN_REGISTER_TYPE(XedDocInfoPlugin, xed_docinfo_plugin) +#define XED_DOCINFO_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ + XED_TYPE_DOCINFO_PLUGIN, \ + XedDocInfoPluginPrivate)) + +static void peas_activatable_iface_init (PeasActivatableInterface *iface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedDocInfoPlugin, + xed_docinfo_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init)) typedef struct { - GtkWidget *dialog; - GtkWidget *file_name_label; - GtkWidget *lines_label; - GtkWidget *words_label; - GtkWidget *chars_label; - GtkWidget *chars_ns_label; - GtkWidget *bytes_label; - GtkWidget *selection_vbox; - GtkWidget *selected_lines_label; - GtkWidget *selected_words_label; - GtkWidget *selected_chars_label; - GtkWidget *selected_chars_ns_label; - GtkWidget *selected_bytes_label; + GtkWidget *dialog; + GtkWidget *file_name_label; + GtkWidget *lines_label; + GtkWidget *words_label; + GtkWidget *chars_label; + GtkWidget *chars_ns_label; + GtkWidget *bytes_label; + GtkWidget *selection_vbox; + GtkWidget *selected_lines_label; + GtkWidget *selected_words_label; + GtkWidget *selected_chars_label; + GtkWidget *selected_chars_ns_label; + GtkWidget *selected_bytes_label; } DocInfoDialog; -typedef struct +struct _XedDocInfoPluginPrivate { - XedPlugin *plugin; + GtkWidget *window; - GtkActionGroup *ui_action_group; - guint ui_id; + GtkActionGroup *ui_action_group; + guint ui_id; - DocInfoDialog *dialog; -} WindowData; + DocInfoDialog *dialog; +}; -static void docinfo_dialog_response_cb (GtkDialog *widget, - gint res_id, - XedWindow *window); +enum +{ + PROP_0, + PROP_OBJECT +}; + +static void docinfo_dialog_response_cb (GtkDialog *widget, + gint res_id, + XedDocInfoPluginPrivate *data); static void -docinfo_dialog_destroy_cb (GObject *obj, - WindowData *data) +docinfo_dialog_destroy_cb (GObject *obj, + XedDocInfoPluginPrivate *data) { - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - if (data != NULL) - { - g_free (data->dialog); - data->dialog = NULL; - } + if (data != NULL) + { + g_free (data->dialog); + data->dialog = NULL; + } } static DocInfoDialog * -get_docinfo_dialog (XedWindow *window, - WindowData *data) +get_docinfo_dialog (XedDocInfoPlugin *plugin) { - DocInfoDialog *dialog; - gchar *data_dir; - gchar *ui_file; - GtkWidget *content; - GtkWidget *error_widget; - gboolean ret; + XedDocInfoPluginPrivate *data; + XedWindow *window; + DocInfoDialog *dialog; + gchar *data_dir; + gchar *ui_file; + GtkWidget *content; + GtkWidget *error_widget; + gboolean ret; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - dialog = g_new (DocInfoDialog, 1); + data = plugin->priv; + window = XED_WINDOW (data->window); - data_dir = xed_plugin_get_data_dir (data->plugin); - ui_file = g_build_filename (data_dir, "docinfo.ui", NULL); - ret = xed_utils_get_ui_objects (ui_file, - NULL, - &error_widget, - "dialog", &dialog->dialog, - "docinfo_dialog_content", &content, - "file_name_label", &dialog->file_name_label, - "words_label", &dialog->words_label, - "bytes_label", &dialog->bytes_label, - "lines_label", &dialog->lines_label, - "chars_label", &dialog->chars_label, - "chars_ns_label", &dialog->chars_ns_label, - "selection_vbox", &dialog->selection_vbox, - "selected_words_label", &dialog->selected_words_label, - "selected_bytes_label", &dialog->selected_bytes_label, - "selected_lines_label", &dialog->selected_lines_label, - "selected_chars_label", &dialog->selected_chars_label, - "selected_chars_ns_label", &dialog->selected_chars_ns_label, - NULL); + dialog = g_new (DocInfoDialog, 1); - g_free (data_dir); - g_free (ui_file); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); + ui_file = g_build_filename (data_dir, "docinfo.ui", NULL); + ret = xed_utils_get_ui_objects (ui_file, + NULL, + &error_widget, + "dialog", &dialog->dialog, + "docinfo_dialog_content", &content, + "file_name_label", &dialog->file_name_label, + "words_label", &dialog->words_label, + "bytes_label", &dialog->bytes_label, + "lines_label", &dialog->lines_label, + "chars_label", &dialog->chars_label, + "chars_ns_label", &dialog->chars_ns_label, + "selection_vbox", &dialog->selection_vbox, + "selected_words_label", &dialog->selected_words_label, + "selected_bytes_label", &dialog->selected_bytes_label, + "selected_lines_label", &dialog->selected_lines_label, + "selected_chars_label", &dialog->selected_chars_label, + "selected_chars_ns_label", &dialog->selected_chars_ns_label, + NULL); - if (!ret) - { - const gchar *err_message; + g_free (data_dir); + g_free (ui_file); - err_message = gtk_label_get_label (GTK_LABEL (error_widget)); - xed_warning (GTK_WINDOW (window), "%s", err_message); + if (!ret) + { + const gchar *err_message; - g_free (dialog); - gtk_widget_destroy (error_widget); + err_message = gtk_label_get_label (GTK_LABEL (error_widget)); + xed_warning (GTK_WINDOW (window), "%s", err_message); - return NULL; - } + g_free (dialog); + gtk_widget_destroy (error_widget); - gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), - GTK_RESPONSE_OK); - gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), - GTK_WINDOW (window)); - - g_signal_connect (dialog->dialog, - "destroy", - G_CALLBACK (docinfo_dialog_destroy_cb), - data); + return NULL; + } - g_signal_connect (dialog->dialog, - "response", - G_CALLBACK (docinfo_dialog_response_cb), - window); + gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), GTK_RESPONSE_OK); + gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), GTK_WINDOW (window)); - return dialog; + g_signal_connect (dialog->dialog, "destroy", G_CALLBACK (docinfo_dialog_destroy_cb), data); + g_signal_connect (dialog->dialog, "response", G_CALLBACK (docinfo_dialog_response_cb), data); + + return dialog; } -static void +static void calculate_info (XedDocument *doc, - GtkTextIter *start, - GtkTextIter *end, - gint *chars, - gint *words, - gint *white_chars, - gint *bytes) -{ - gchar *text; + GtkTextIter *start, + GtkTextIter *end, + gint *chars, + gint *words, + gint *white_chars, + gint *bytes) +{ + gchar *text; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - text = gtk_text_buffer_get_slice (GTK_TEXT_BUFFER (doc), - start, - end, - TRUE); + text = gtk_text_buffer_get_slice (GTK_TEXT_BUFFER (doc), start, end, TRUE); - *chars = g_utf8_strlen (text, -1); - *bytes = strlen (text); + *chars = g_utf8_strlen (text, -1); + *bytes = strlen (text); - if (*chars > 0) - { - PangoLogAttr *attrs; - gint i; + if (*chars > 0) + { + PangoLogAttr *attrs; + gint i; - attrs = g_new0 (PangoLogAttr, *chars + 1); + attrs = g_new0 (PangoLogAttr, *chars + 1); - pango_get_log_attrs (text, - -1, - 0, - pango_language_from_string ("C"), - attrs, - *chars + 1); + pango_get_log_attrs (text, -1, 0, pango_language_from_string ("C"), attrs, *chars + 1); - for (i = 0; i < (*chars); i++) - { - if (attrs[i].is_white) - ++(*white_chars); + for (i = 0; i < (*chars); i++) + { + if (attrs[i].is_white) + { + ++(*white_chars); + } - if (attrs[i].is_word_start) - ++(*words); - } + if (attrs[i].is_word_start) + { + ++(*words); + } + } - g_free (attrs); - } - else - { - *white_chars = 0; - *words = 0; - } + g_free (attrs); + } + else + { + *white_chars = 0; + *words = 0; + } - g_free (text); + g_free (text); } static void -docinfo_real (XedDocument *doc, - DocInfoDialog *dialog) +docinfo_real (XedDocument *doc, + DocInfoDialog *dialog) { - GtkTextIter start, end; - gint words = 0; - gint chars = 0; - gint white_chars = 0; - gint lines = 0; - gint bytes = 0; - gchar *tmp_str; - gchar *doc_name; + GtkTextIter start, end; + gint words = 0; + gint chars = 0; + gint white_chars = 0; + gint lines = 0; + gint bytes = 0; + gchar *tmp_str; + gchar *doc_name; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), - &start, - &end); + gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &start, &end); - lines = gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (doc)); + lines = gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (doc)); - calculate_info (doc, - &start, &end, - &chars, &words, &white_chars, &bytes); + calculate_info (doc, &start, &end, &chars, &words, &white_chars, &bytes); - if (chars == 0) - lines = 0; + if (chars == 0) + { + lines = 0; + } - xed_debug_message (DEBUG_PLUGINS, "Chars: %d", chars); - xed_debug_message (DEBUG_PLUGINS, "Lines: %d", lines); - xed_debug_message (DEBUG_PLUGINS, "Words: %d", words); - xed_debug_message (DEBUG_PLUGINS, "Chars non-space: %d", chars - white_chars); - xed_debug_message (DEBUG_PLUGINS, "Bytes: %d", bytes); + xed_debug_message (DEBUG_PLUGINS, "Chars: %d", chars); + xed_debug_message (DEBUG_PLUGINS, "Lines: %d", lines); + xed_debug_message (DEBUG_PLUGINS, "Words: %d", words); + xed_debug_message (DEBUG_PLUGINS, "Chars non-space: %d", chars - white_chars); + xed_debug_message (DEBUG_PLUGINS, "Bytes: %d", bytes); - doc_name = xed_document_get_short_name_for_display (doc); - tmp_str = g_strdup_printf ("%s", doc_name); - gtk_label_set_markup (GTK_LABEL (dialog->file_name_label), tmp_str); - g_free (doc_name); - g_free (tmp_str); + doc_name = xed_document_get_short_name_for_display (doc); + tmp_str = g_strdup_printf ("%s", doc_name); + gtk_label_set_markup (GTK_LABEL (dialog->file_name_label), tmp_str); + g_free (doc_name); + g_free (tmp_str); - tmp_str = g_strdup_printf("%d", lines); - gtk_label_set_text (GTK_LABEL (dialog->lines_label), tmp_str); - g_free (tmp_str); + tmp_str = g_strdup_printf("%d", lines); + gtk_label_set_text (GTK_LABEL (dialog->lines_label), tmp_str); + g_free (tmp_str); - tmp_str = g_strdup_printf("%d", words); - gtk_label_set_text (GTK_LABEL (dialog->words_label), tmp_str); - g_free (tmp_str); + tmp_str = g_strdup_printf("%d", words); + gtk_label_set_text (GTK_LABEL (dialog->words_label), tmp_str); + g_free (tmp_str); - tmp_str = g_strdup_printf("%d", chars); - gtk_label_set_text (GTK_LABEL (dialog->chars_label), tmp_str); - g_free (tmp_str); + tmp_str = g_strdup_printf("%d", chars); + gtk_label_set_text (GTK_LABEL (dialog->chars_label), tmp_str); + g_free (tmp_str); - tmp_str = g_strdup_printf("%d", chars - white_chars); - gtk_label_set_text (GTK_LABEL (dialog->chars_ns_label), tmp_str); - g_free (tmp_str); + tmp_str = g_strdup_printf("%d", chars - white_chars); + gtk_label_set_text (GTK_LABEL (dialog->chars_ns_label), tmp_str); + g_free (tmp_str); - tmp_str = g_strdup_printf("%d", bytes); - gtk_label_set_text (GTK_LABEL (dialog->bytes_label), tmp_str); - g_free (tmp_str); + tmp_str = g_strdup_printf("%d", bytes); + gtk_label_set_text (GTK_LABEL (dialog->bytes_label), tmp_str); + g_free (tmp_str); } static void -selectioninfo_real (XedDocument *doc, - DocInfoDialog *dialog) +selectioninfo_real (XedDocument *doc, + DocInfoDialog *dialog) { - gboolean sel; - GtkTextIter start, end; - gint words = 0; - gint chars = 0; - gint white_chars = 0; - gint lines = 0; - gint bytes = 0; - gchar *tmp_str; + gboolean sel; + GtkTextIter start, end; + gint words = 0; + gint chars = 0; + gint white_chars = 0; + gint lines = 0; + gint bytes = 0; + gchar *tmp_str; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - sel = gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), - &start, - &end); + sel = gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &start, &end); - if (sel) - { - lines = gtk_text_iter_get_line (&end) - gtk_text_iter_get_line (&start) + 1; - - calculate_info (doc, - &start, &end, - &chars, &words, &white_chars, &bytes); + if (sel) + { + lines = gtk_text_iter_get_line (&end) - gtk_text_iter_get_line (&start) + 1; - xed_debug_message (DEBUG_PLUGINS, "Selected chars: %d", chars); - xed_debug_message (DEBUG_PLUGINS, "Selected lines: %d", lines); - xed_debug_message (DEBUG_PLUGINS, "Selected words: %d", words); - xed_debug_message (DEBUG_PLUGINS, "Selected chars non-space: %d", chars - white_chars); - xed_debug_message (DEBUG_PLUGINS, "Selected bytes: %d", bytes); + calculate_info (doc, &start, &end, &chars, &words, &white_chars, &bytes); - gtk_widget_set_sensitive (dialog->selection_vbox, TRUE); - } - else - { - gtk_widget_set_sensitive (dialog->selection_vbox, FALSE); + xed_debug_message (DEBUG_PLUGINS, "Selected chars: %d", chars); + xed_debug_message (DEBUG_PLUGINS, "Selected lines: %d", lines); + xed_debug_message (DEBUG_PLUGINS, "Selected words: %d", words); + xed_debug_message (DEBUG_PLUGINS, "Selected chars non-space: %d", chars - white_chars); + xed_debug_message (DEBUG_PLUGINS, "Selected bytes: %d", bytes); - xed_debug_message (DEBUG_PLUGINS, "Selection empty"); - } + gtk_widget_set_sensitive (dialog->selection_vbox, TRUE); + } + else + { + gtk_widget_set_sensitive (dialog->selection_vbox, FALSE); - if (chars == 0) - lines = 0; + xed_debug_message (DEBUG_PLUGINS, "Selection empty"); + } - tmp_str = g_strdup_printf("%d", lines); - gtk_label_set_text (GTK_LABEL (dialog->selected_lines_label), tmp_str); - g_free (tmp_str); + if (chars == 0) + { + lines = 0; + } - tmp_str = g_strdup_printf("%d", words); - gtk_label_set_text (GTK_LABEL (dialog->selected_words_label), tmp_str); - g_free (tmp_str); + tmp_str = g_strdup_printf("%d", lines); + gtk_label_set_text (GTK_LABEL (dialog->selected_lines_label), tmp_str); + g_free (tmp_str); - tmp_str = g_strdup_printf("%d", chars); - gtk_label_set_text (GTK_LABEL (dialog->selected_chars_label), tmp_str); - g_free (tmp_str); + tmp_str = g_strdup_printf("%d", words); + gtk_label_set_text (GTK_LABEL (dialog->selected_words_label), tmp_str); + g_free (tmp_str); - tmp_str = g_strdup_printf("%d", chars - white_chars); - gtk_label_set_text (GTK_LABEL (dialog->selected_chars_ns_label), tmp_str); - g_free (tmp_str); + tmp_str = g_strdup_printf("%d", chars); + gtk_label_set_text (GTK_LABEL (dialog->selected_chars_label), tmp_str); + g_free (tmp_str); - tmp_str = g_strdup_printf("%d", bytes); - gtk_label_set_text (GTK_LABEL (dialog->selected_bytes_label), tmp_str); - g_free (tmp_str); + tmp_str = g_strdup_printf("%d", chars - white_chars); + gtk_label_set_text (GTK_LABEL (dialog->selected_chars_ns_label), tmp_str); + g_free (tmp_str); + + tmp_str = g_strdup_printf("%d", bytes); + gtk_label_set_text (GTK_LABEL (dialog->selected_bytes_label), tmp_str); + g_free (tmp_str); } static void -docinfo_cb (GtkAction *action, - XedWindow *window) +docinfo_cb (GtkAction *action, + XedDocInfoPlugin *plugin) { - XedDocument *doc; - WindowData *data; + XedDocInfoPluginPrivate *data; + XedWindow *window; + XedDocument *doc; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - data = (WindowData *) g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); + data = plugin->priv; + window = XED_WINDOW (data->window); + doc = xed_window_get_active_document (window); + g_return_if_fail (doc != NULL); - doc = xed_window_get_active_document (window); - g_return_if_fail (doc != NULL); + if (data->dialog != NULL) + { + gtk_window_present (GTK_WINDOW (data->dialog->dialog)); + gtk_widget_grab_focus (GTK_WIDGET (data->dialog->dialog)); + } + else + { + DocInfoDialog *dialog; - if (data->dialog != NULL) - { - gtk_window_present (GTK_WINDOW (data->dialog->dialog)); - gtk_widget_grab_focus (GTK_WIDGET (data->dialog->dialog)); - } - else - { - DocInfoDialog *dialog; + dialog = get_docinfo_dialog (plugin); + g_return_if_fail (dialog != NULL); - dialog = get_docinfo_dialog (window, data); - g_return_if_fail (dialog != NULL); - - data->dialog = dialog; + data->dialog = dialog; - gtk_widget_show (GTK_WIDGET (dialog->dialog)); - } - - docinfo_real (doc, - data->dialog); - selectioninfo_real (doc, - data->dialog); + gtk_widget_show (GTK_WIDGET (dialog->dialog)); + } + + docinfo_real (doc, + data->dialog); + selectioninfo_real (doc, + data->dialog); } static void -docinfo_dialog_response_cb (GtkDialog *widget, - gint res_id, - XedWindow *window) +docinfo_dialog_response_cb (GtkDialog *widget, + gint res_id, + XedDocInfoPluginPrivate *data) { - WindowData *data; + XedWindow *window; - xed_debug (DEBUG_PLUGINS); - - data = (WindowData *) g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); + xed_debug (DEBUG_PLUGINS); - switch (res_id) - { - case GTK_RESPONSE_CLOSE: - { - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CLOSE"); - gtk_widget_destroy (data->dialog->dialog); + window = XED_WINDOW (data->window); - break; - } + switch (res_id) + { + case GTK_RESPONSE_CLOSE: + { + xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CLOSE"); + gtk_widget_destroy (data->dialog->dialog); - case GTK_RESPONSE_OK: - { - XedDocument *doc; - - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK"); - - doc = xed_window_get_active_document (window); - g_return_if_fail (doc != NULL); - - docinfo_real (doc, - data->dialog); + break; + } - selectioninfo_real (doc, - data->dialog); - - break; - } - } + case GTK_RESPONSE_OK: + { + XedDocument *doc; + + xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK"); + + doc = xed_window_get_active_document (window); + g_return_if_fail (doc != NULL); + + docinfo_real (doc, data->dialog); + selectioninfo_real (doc, data->dialog); + + break; + } + } } static const GtkActionEntry action_entries[] = { - { "DocumentStatistics", - NULL, - N_("_Document Statistics"), - NULL, - N_("Get statistical information on the current document"), - G_CALLBACK (docinfo_cb) } + { "DocumentStatistics", + NULL, + N_("_Document Statistics"), + NULL, + N_("Get statistical information on the current document"), + G_CALLBACK (docinfo_cb) } }; static void -free_window_data (WindowData *data) +update_ui (XedDocInfoPluginPrivate *data) { - g_return_if_fail (data != NULL); - - xed_debug (DEBUG_PLUGINS); + XedWindow *window; + XedView *view; - g_object_unref (data->plugin); + xed_debug (DEBUG_PLUGINS); - g_object_unref (data->ui_action_group); - - if (data->dialog != NULL) - { - gtk_widget_destroy (data->dialog->dialog); - } - - g_free (data); -} + window = XED_WINDOW (data->window); + view = xed_window_get_active_view (window); -static void -update_ui_real (XedWindow *window, - WindowData *data) -{ - XedView *view; + gtk_action_group_set_sensitive (data->ui_action_group, (view != NULL)); - xed_debug (DEBUG_PLUGINS); - - view = xed_window_get_active_view (window); - - gtk_action_group_set_sensitive (data->ui_action_group, - (view != NULL)); - - if (data->dialog != NULL) - { - gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog->dialog), - GTK_RESPONSE_OK, - (view != NULL)); - } + if (data->dialog != NULL) + { + gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog->dialog), GTK_RESPONSE_OK, (view != NULL)); + } } static void xed_docinfo_plugin_init (XedDocInfoPlugin *plugin) { - xed_debug_message (DEBUG_PLUGINS, "XedDocInfoPlugin initializing"); + xed_debug_message (DEBUG_PLUGINS, "XedDocInfoPlugin initializing"); + plugin->priv = XED_DOCINFO_PLUGIN_GET_PRIVATE (plugin); } static void -xed_docinfo_plugin_finalize (GObject *object) +xed_docinfo_plugin_dispose (GObject *object) { - xed_debug_message (DEBUG_PLUGINS, "XedDocInfoPlugin finalizing"); + XedDocInfoPlugin *plugin = XED_DOCINFO_PLUGIN (object); - G_OBJECT_CLASS (xed_docinfo_plugin_parent_class)->finalize (object); + xed_debug_message (DEBUG_PLUGINS, "XedDocInfoPlugin disposing"); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + if (plugin->priv->ui_action_group != NULL) + { + g_object_unref (plugin->priv->ui_action_group); + plugin->priv->ui_action_group = NULL; + } + + G_OBJECT_CLASS (xed_docinfo_plugin_parent_class)->dispose (object); } static void -impl_activate (XedPlugin *plugin, - XedWindow *window) +xed_docinfo_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - GtkUIManager *manager; - WindowData *data; - - xed_debug (DEBUG_PLUGINS); + XedDocInfoPlugin *plugin = XED_DOCINFO_PLUGIN (object); - data = g_new (WindowData, 1); - - data->plugin = g_object_ref (plugin); - data->dialog = NULL; - data->ui_action_group = gtk_action_group_new ("XedDocInfoPluginActions"); - - gtk_action_group_set_translation_domain (data->ui_action_group, - GETTEXT_PACKAGE); - gtk_action_group_add_actions (data->ui_action_group, - action_entries, - G_N_ELEMENTS (action_entries), - window); - - manager = xed_window_get_ui_manager (window); - gtk_ui_manager_insert_action_group (manager, - data->ui_action_group, - -1); - - data->ui_id = gtk_ui_manager_new_merge_id (manager); - - g_object_set_data_full (G_OBJECT (window), - WINDOW_DATA_KEY, - data, - (GDestroyNotify) free_window_data); - - gtk_ui_manager_add_ui (manager, - data->ui_id, - MENU_PATH, - "DocumentStatistics", - "DocumentStatistics", - GTK_UI_MANAGER_MENUITEM, - FALSE); - - update_ui_real (window, - data); + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -impl_deactivate (XedPlugin *plugin, - XedWindow *window) +xed_docinfo_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { - GtkUIManager *manager; - WindowData *data; + XedDocInfoPlugin *plugin = XED_DOCINFO_PLUGIN (object); - xed_debug (DEBUG_PLUGINS); - - manager = xed_window_get_ui_manager (window); - - data = (WindowData *) g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - - gtk_ui_manager_remove_ui (manager, - data->ui_id); - gtk_ui_manager_remove_action_group (manager, - data->ui_action_group); - - g_object_set_data (G_OBJECT (window), - WINDOW_DATA_KEY, - NULL); + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -impl_update_ui (XedPlugin *plugin, - XedWindow *window) +xed_docinfo_plugin_activate (PeasActivatable *activatable) { - WindowData *data; + XedDocInfoPlugin *plugin; + XedDocInfoPluginPrivate *data; + XedWindow *window; + GtkUIManager *manager; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - data = (WindowData *) g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); + plugin = XED_DOCINFO_PLUGIN (activatable); + data = plugin->priv; + window = XED_WINDOW (data->window); - update_ui_real (window, - data); + data->dialog = NULL; + data->ui_action_group = gtk_action_group_new ("XedDocInfoPluginActions"); + + gtk_action_group_set_translation_domain (data->ui_action_group, GETTEXT_PACKAGE); + gtk_action_group_add_actions (data->ui_action_group, action_entries, + G_N_ELEMENTS (action_entries), plugin); + + manager = xed_window_get_ui_manager (window); + gtk_ui_manager_insert_action_group (manager, data->ui_action_group, -1); + + data->ui_id = gtk_ui_manager_new_merge_id (manager); + + gtk_ui_manager_add_ui (manager, + data->ui_id, + MENU_PATH, + "DocumentStatistics", + "DocumentStatistics", + GTK_UI_MANAGER_MENUITEM, + FALSE); + + update_ui (data); +} + +static void +xed_docinfo_plugin_deactivate (PeasActivatable *activatable) +{ + XedDocInfoPluginPrivate *data; + XedWindow *window; + GtkUIManager *manager; + + xed_debug (DEBUG_PLUGINS); + + data = XED_DOCINFO_PLUGIN (activatable)->priv; + window = XED_WINDOW (data->window); + + manager = xed_window_get_ui_manager (window); + + gtk_ui_manager_remove_ui (manager, data->ui_id); + gtk_ui_manager_remove_action_group (manager, data->ui_action_group); +} + +static void +xed_docinfo_plugin_update_state (PeasActivatable *activatable) +{ + xed_debug (DEBUG_PLUGINS); + + update_ui (XED_DOCINFO_PLUGIN (activatable)->priv); } static void xed_docinfo_plugin_class_init (XedDocInfoPluginClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - XedPluginClass *plugin_class = XED_PLUGIN_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = xed_docinfo_plugin_finalize; + object_class->dispose = xed_docinfo_plugin_dispose; + object_class->set_property = xed_docinfo_plugin_set_property; + object_class->get_property = xed_docinfo_plugin_get_property; - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_update_ui; + g_object_class_override_property (object_class, PROP_OBJECT, "object"); + + g_type_class_add_private (klass, sizeof (XedDocInfoPluginPrivate)); +} + +static void +xed_docinfo_plugin_class_finalize (XedDocInfoPluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = xed_docinfo_plugin_activate; + iface->deactivate = xed_docinfo_plugin_deactivate; + iface->update_state = xed_docinfo_plugin_update_state; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + xed_docinfo_plugin_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + XED_TYPE_DOCINFO_PLUGIN); } diff --git a/plugins/docinfo/xed-docinfo-plugin.h b/plugins/docinfo/xed-docinfo-plugin.h index dcb3856..b6c5cd8 100644 --- a/plugins/docinfo/xed-docinfo-plugin.h +++ b/plugins/docinfo/xed-docinfo-plugin.h @@ -1,7 +1,7 @@ /* * xed-docinfo-plugin.h - * - * Copyright (C) 2002-2005 Paolo Maggi + * + * Copyright (C) 2002-2005 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,50 +25,54 @@ #include #include -#include +#include +#include G_BEGIN_DECLS /* * Type checking and casting macros */ -#define XED_TYPE_DOCINFO_PLUGIN (xed_docinfo_plugin_get_type ()) -#define XED_DOCINFO_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_DOCINFO_PLUGIN, XedDocInfoPlugin)) -#define XED_DOCINFO_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_DOCINFO_PLUGIN, XedDocInfoPluginClass)) -#define XED_IS_DOCINFO_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_DOCINFO_PLUGIN)) -#define XED_IS_DOCINFO_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_DOCINFO_PLUGIN)) -#define XED_DOCINFO_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_DOCINFO_PLUGIN, XedDocInfoPluginClass)) +#define XED_TYPE_DOCINFO_PLUGIN (xed_docinfo_plugin_get_type ()) +#define XED_DOCINFO_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_DOCINFO_PLUGIN, XedDocInfoPlugin)) +#define XED_DOCINFO_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_DOCINFO_PLUGIN, XedDocInfoPluginClass)) +#define XED_IS_DOCINFO_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_DOCINFO_PLUGIN)) +#define XED_IS_DOCINFO_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_DOCINFO_PLUGIN)) +#define XED_DOCINFO_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_DOCINFO_PLUGIN, XedDocInfoPluginClass)) /* Private structure type */ -typedef struct _XedDocInfoPluginPrivate XedDocInfoPluginPrivate; +typedef struct _XedDocInfoPluginPrivate XedDocInfoPluginPrivate; /* * Main object structure */ -typedef struct _XedDocInfoPlugin XedDocInfoPlugin; +typedef struct _XedDocInfoPlugin XedDocInfoPlugin; struct _XedDocInfoPlugin { - XedPlugin parent_instance; + PeasExtensionBase parent_instance; + + /*< private >*/ + XedDocInfoPluginPrivate *priv; }; /* * Class definition */ -typedef struct _XedDocInfoPluginClass XedDocInfoPluginClass; +typedef struct _XedDocInfoPluginClass XedDocInfoPluginClass; struct _XedDocInfoPluginClass { - XedPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* * Public methods */ -GType xed_docinfo_plugin_get_type (void) G_GNUC_CONST; +GType xed_docinfo_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_xed_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS From 4cad8ffa7f027c7d93f9f71bd141fc82df5fa96b Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 13:25:50 -0800 Subject: [PATCH 030/132] filebrowser-plugin: Port to libpeas Adapted from: https://github.com/mate-desktop/pluma/commit/3e00f9094c06fa43d768bd3268cb503d8e6a738b --- .../filebrowser/xed-file-bookmarks-store.c | 1283 +++++++++-------- .../filebrowser/xed-file-bookmarks-store.h | 74 +- plugins/filebrowser/xed-file-browser-plugin.c | 260 ++-- plugins/filebrowser/xed-file-browser-plugin.h | 34 +- plugins/filebrowser/xed-file-browser-store.c | 312 ++-- plugins/filebrowser/xed-file-browser-store.h | 162 +-- plugins/filebrowser/xed-file-browser-view.c | 225 +-- plugins/filebrowser/xed-file-browser-view.h | 14 +- plugins/filebrowser/xed-file-browser-widget.c | 15 +- plugins/filebrowser/xed-file-browser-widget.h | 76 +- 10 files changed, 1304 insertions(+), 1151 deletions(-) diff --git a/plugins/filebrowser/xed-file-bookmarks-store.c b/plugins/filebrowser/xed-file-bookmarks-store.c index f5fce51..ad1904e 100644 --- a/plugins/filebrowser/xed-file-bookmarks-store.c +++ b/plugins/filebrowser/xed-file-bookmarks-store.c @@ -1,5 +1,5 @@ /* - * xed-file-bookmarks-store.c - Xed plugin providing easy file access + * xed-file-bookmarks-store.c - Xed plugin providing easy file access * from the sidepanel * * Copyright (C) 2006 - Jesse van den Kieboom @@ -23,857 +23,928 @@ #include #include #include -#include #include "xed-file-bookmarks-store.h" #include "xed-file-browser-utils.h" #define XED_FILE_BOOKMARKS_STORE_GET_PRIVATE(object)( \ - G_TYPE_INSTANCE_GET_PRIVATE((object), XED_TYPE_FILE_BOOKMARKS_STORE, \ - XedFileBookmarksStorePrivate)) + G_TYPE_INSTANCE_GET_PRIVATE((object), XED_TYPE_FILE_BOOKMARKS_STORE, \ + XedFileBookmarksStorePrivate)) -struct _XedFileBookmarksStorePrivate +struct _XedFileBookmarksStorePrivate { - GVolumeMonitor * volume_monitor; - GFileMonitor * bookmarks_monitor; + GVolumeMonitor * volume_monitor; + GFileMonitor * bookmarks_monitor; }; -static void remove_node (GtkTreeModel * model, +static void remove_node (GtkTreeModel * model, GtkTreeIter * iter); -static void on_fs_changed (GVolumeMonitor *monitor, - GObject *object, - XedFileBookmarksStore *model); - +static void on_fs_changed (GVolumeMonitor *monitor, + GObject *object, + XedFileBookmarksStore *model); + static void on_bookmarks_file_changed (GFileMonitor * monitor, - GFile * file, - GFile * other_file, - GFileMonitorEvent event_type, - XedFileBookmarksStore * model); -static gboolean find_with_flags (GtkTreeModel * model, + GFile * file, + GFile * other_file, + GFileMonitorEvent event_type, + XedFileBookmarksStore * model); +static gboolean find_with_flags (GtkTreeModel * model, GtkTreeIter * iter, - gpointer obj, + gpointer obj, guint flags, guint notflags); -XED_PLUGIN_DEFINE_TYPE(XedFileBookmarksStore, xed_file_bookmarks_store, GTK_TYPE_TREE_STORE) +G_DEFINE_DYNAMIC_TYPE (XedFileBookmarksStore, xed_file_bookmarks_store, GTK_TYPE_TREE_STORE) static void xed_file_bookmarks_store_dispose (GObject * object) { - XedFileBookmarksStore *obj = XED_FILE_BOOKMARKS_STORE (object); + XedFileBookmarksStore *obj = XED_FILE_BOOKMARKS_STORE (object); - if (obj->priv->volume_monitor != NULL) { - g_signal_handlers_disconnect_by_func (obj->priv->volume_monitor, - on_fs_changed, - obj); + if (obj->priv->volume_monitor != NULL) + { + g_signal_handlers_disconnect_by_func (obj->priv->volume_monitor, on_fs_changed, obj); - g_object_unref (obj->priv->volume_monitor); - obj->priv->volume_monitor = NULL; - } + g_object_unref (obj->priv->volume_monitor); + obj->priv->volume_monitor = NULL; + } - if (obj->priv->bookmarks_monitor != NULL) { - g_object_unref (obj->priv->bookmarks_monitor); - obj->priv->bookmarks_monitor = NULL; - } + if (obj->priv->bookmarks_monitor != NULL) + { + g_object_unref (obj->priv->bookmarks_monitor); + obj->priv->bookmarks_monitor = NULL; + } - G_OBJECT_CLASS (xed_file_bookmarks_store_parent_class)->dispose (object); + G_OBJECT_CLASS (xed_file_bookmarks_store_parent_class)->dispose (object); } static void xed_file_bookmarks_store_finalize (GObject * object) { - G_OBJECT_CLASS (xed_file_bookmarks_store_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_file_bookmarks_store_parent_class)->finalize (object); } static void xed_file_bookmarks_store_class_init (XedFileBookmarksStoreClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->dispose = xed_file_bookmarks_store_dispose; - object_class->finalize = xed_file_bookmarks_store_finalize; + object_class->dispose = xed_file_bookmarks_store_dispose; + object_class->finalize = xed_file_bookmarks_store_finalize; - g_type_class_add_private (object_class, sizeof (XedFileBookmarksStorePrivate)); + g_type_class_add_private (object_class, sizeof (XedFileBookmarksStorePrivate)); +} + +static void +xed_file_bookmarks_store_class_finalize (XedFileBookmarksStoreClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE */ } static void xed_file_bookmarks_store_init (XedFileBookmarksStore * obj) { - obj->priv = XED_FILE_BOOKMARKS_STORE_GET_PRIVATE (obj); + obj->priv = XED_FILE_BOOKMARKS_STORE_GET_PRIVATE (obj); } /* Private */ static void -add_node (XedFileBookmarksStore *model, - GdkPixbuf *pixbuf, - const gchar *name, - GObject *obj, - guint flags, - GtkTreeIter *iter) +add_node (XedFileBookmarksStore *model, + GdkPixbuf *pixbuf, + const gchar *name, + GObject *obj, + guint flags, + GtkTreeIter *iter) { - GtkTreeIter newiter; + GtkTreeIter newiter; - gtk_tree_store_append (GTK_TREE_STORE (model), &newiter, NULL); + gtk_tree_store_append (GTK_TREE_STORE (model), &newiter, NULL); - gtk_tree_store_set (GTK_TREE_STORE (model), &newiter, - XED_FILE_BOOKMARKS_STORE_COLUMN_ICON, pixbuf, - XED_FILE_BOOKMARKS_STORE_COLUMN_NAME, name, - XED_FILE_BOOKMARKS_STORE_COLUMN_OBJECT, obj, - XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, flags, - -1); + gtk_tree_store_set (GTK_TREE_STORE (model), &newiter, + XED_FILE_BOOKMARKS_STORE_COLUMN_ICON, pixbuf, + XED_FILE_BOOKMARKS_STORE_COLUMN_NAME, name, + XED_FILE_BOOKMARKS_STORE_COLUMN_OBJECT, obj, + XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, flags, + -1); - if (iter != NULL) - *iter = newiter; + if (iter != NULL) + { + *iter = newiter; + } } static gboolean -add_file (XedFileBookmarksStore *model, - GFile *file, - const gchar *name, - guint flags, - GtkTreeIter *iter) +add_file (XedFileBookmarksStore *model, + GFile *file, + const gchar *name, + guint flags, + GtkTreeIter *iter) { - GdkPixbuf *pixbuf = NULL; - gboolean native; - gchar *newname; + GdkPixbuf *pixbuf = NULL; + gboolean native; + gchar *newname; - native = g_file_is_native (file); + native = g_file_is_native (file); - if (native && !g_file_query_exists (file, NULL)) { - return FALSE; - } + if (native && !g_file_query_exists (file, NULL)) + { + return FALSE; + } - if (flags & XED_FILE_BOOKMARKS_STORE_IS_HOME) - pixbuf = xed_file_browser_utils_pixbuf_from_theme ("user-home", GTK_ICON_SIZE_MENU); - else if (flags & XED_FILE_BOOKMARKS_STORE_IS_DESKTOP) - pixbuf = xed_file_browser_utils_pixbuf_from_theme ("user-desktop", GTK_ICON_SIZE_MENU); - else if (flags & XED_FILE_BOOKMARKS_STORE_IS_ROOT) - pixbuf = xed_file_browser_utils_pixbuf_from_theme ("drive-harddisk", GTK_ICON_SIZE_MENU); + if (flags & XED_FILE_BOOKMARKS_STORE_IS_HOME) + { + pixbuf = xed_file_browser_utils_pixbuf_from_theme ("user-home", GTK_ICON_SIZE_MENU); + } + else if (flags & XED_FILE_BOOKMARKS_STORE_IS_DESKTOP) + { + pixbuf = xed_file_browser_utils_pixbuf_from_theme ("user-desktop", GTK_ICON_SIZE_MENU); + } + else if (flags & XED_FILE_BOOKMARKS_STORE_IS_ROOT) + { + pixbuf = xed_file_browser_utils_pixbuf_from_theme ("drive-harddisk", GTK_ICON_SIZE_MENU); + } - if (pixbuf == NULL) { - /* getting the icon is a sync get_info call, so we just do it for local files */ - if (native) { - pixbuf = xed_file_browser_utils_pixbuf_from_file (file, GTK_ICON_SIZE_MENU); - } else { - pixbuf = xed_file_browser_utils_pixbuf_from_theme ("folder", GTK_ICON_SIZE_MENU); - } - } + if (pixbuf == NULL) + { + /* getting the icon is a sync get_info call, so we just do it for local files */ + if (native) + { + pixbuf = xed_file_browser_utils_pixbuf_from_file (file, GTK_ICON_SIZE_MENU); + } + else + { + pixbuf = xed_file_browser_utils_pixbuf_from_theme ("folder", GTK_ICON_SIZE_MENU); + } + } - if (name == NULL) { - newname = xed_file_browser_utils_file_basename (file); - } else { - newname = g_strdup (name); - } + if (name == NULL) + { + newname = xed_file_browser_utils_file_basename (file); + } + else + { + newname = g_strdup (name); + } - add_node (model, pixbuf, newname, G_OBJECT (file), flags, iter); + add_node (model, pixbuf, newname, G_OBJECT (file), flags, iter); - if (pixbuf) - g_object_unref (pixbuf); + if (pixbuf) + { + g_object_unref (pixbuf); + } - g_free (newname); + g_free (newname); - return TRUE; + return TRUE; } static void check_mount_separator (XedFileBookmarksStore * model, guint flags, - gboolean added) + gboolean added) { - GtkTreeIter iter; - gboolean found; + GtkTreeIter iter; + gboolean found; - found = - find_with_flags (GTK_TREE_MODEL (model), &iter, NULL, - flags | - XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR, 0); + found = find_with_flags (GTK_TREE_MODEL (model), &iter, NULL, + flags | XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR, 0); - if (added && !found) { - /* Add the separator */ - add_node (model, NULL, NULL, NULL, - flags | XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR, - NULL); - } else if (!added && found) { - remove_node (GTK_TREE_MODEL (model), &iter); - } + if (added && !found) + { + /* Add the separator */ + add_node (model, NULL, NULL, NULL, flags | XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR, NULL); + } + else if (!added && found) + { + remove_node (GTK_TREE_MODEL (model), &iter); + } } static void init_special_directories (XedFileBookmarksStore * model) { - gchar const *path; - GFile * file; + gchar const *path; + GFile * file; - path = g_get_home_dir (); - if (path != NULL) - { - file = g_file_new_for_path (path); - add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_HOME | - XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL); - g_object_unref (file); - } + path = g_get_home_dir (); + if (path != NULL) + { + file = g_file_new_for_path (path); + add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_HOME | XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL); + g_object_unref (file); + } - path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP); - if (path != NULL) - { - file = g_file_new_for_path (path); - add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_DESKTOP | - XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL); - g_object_unref (file); - } + path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP); + if (path != NULL) + { + file = g_file_new_for_path (path); + add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_DESKTOP | + XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL); + g_object_unref (file); + } - path = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS); - if (path != NULL) - { - file = g_file_new_for_path (path); - add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_DOCUMENTS | - XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL); - g_object_unref (file); - } - - file = g_file_new_for_uri ("file:///"); - add_file (model, file, _("File System"), XED_FILE_BOOKMARKS_STORE_IS_ROOT, NULL); - g_object_unref (file); - - check_mount_separator (model, XED_FILE_BOOKMARKS_STORE_IS_ROOT, TRUE); + path = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS); + if (path != NULL) + { + file = g_file_new_for_path (path); + add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_DOCUMENTS | + XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL); + g_object_unref (file); + } + + file = g_file_new_for_uri ("file:///"); + add_file (model, file, _("File System"), XED_FILE_BOOKMARKS_STORE_IS_ROOT, NULL); + g_object_unref (file); + + check_mount_separator (model, XED_FILE_BOOKMARKS_STORE_IS_ROOT, TRUE); } static void get_fs_properties (gpointer fs, - gchar **name, - GdkPixbuf **pixbuf, - guint *flags) + gchar **name, + GdkPixbuf **pixbuf, + guint *flags) { - GIcon *icon = NULL; + GIcon *icon = NULL; - *flags = XED_FILE_BOOKMARKS_STORE_IS_FS; - *name = NULL; - *pixbuf = NULL; - - if (G_IS_DRIVE (fs)) - { - icon = g_drive_get_icon (G_DRIVE (fs)); - *name = g_drive_get_name (G_DRIVE (fs)); - - *flags |= XED_FILE_BOOKMARKS_STORE_IS_DRIVE; - } - else if (G_IS_VOLUME (fs)) - { - icon = g_volume_get_icon (G_VOLUME (fs)); - *name = g_volume_get_name (G_VOLUME (fs)); - - *flags |= XED_FILE_BOOKMARKS_STORE_IS_VOLUME; - } - else if (G_IS_MOUNT (fs)) - { - icon = g_mount_get_icon (G_MOUNT (fs)); - *name = g_mount_get_name (G_MOUNT (fs)); - - *flags |= XED_FILE_BOOKMARKS_STORE_IS_MOUNT; - } - - if (icon) - { - *pixbuf = xed_file_browser_utils_pixbuf_from_icon (icon, GTK_ICON_SIZE_MENU); - g_object_unref (icon); - } + *flags = XED_FILE_BOOKMARKS_STORE_IS_FS; + *name = NULL; + *pixbuf = NULL; + + if (G_IS_DRIVE (fs)) + { + icon = g_drive_get_icon (G_DRIVE (fs)); + *name = g_drive_get_name (G_DRIVE (fs)); + + *flags |= XED_FILE_BOOKMARKS_STORE_IS_DRIVE; + } + else if (G_IS_VOLUME (fs)) + { + icon = g_volume_get_icon (G_VOLUME (fs)); + *name = g_volume_get_name (G_VOLUME (fs)); + + *flags |= XED_FILE_BOOKMARKS_STORE_IS_VOLUME; + } + else if (G_IS_MOUNT (fs)) + { + icon = g_mount_get_icon (G_MOUNT (fs)); + *name = g_mount_get_name (G_MOUNT (fs)); + + *flags |= XED_FILE_BOOKMARKS_STORE_IS_MOUNT; + } + + if (icon) + { + *pixbuf = xed_file_browser_utils_pixbuf_from_icon (icon, GTK_ICON_SIZE_MENU); + g_object_unref (icon); + } } - + static void add_fs (XedFileBookmarksStore *model, - gpointer fs, - guint flags, - GtkTreeIter *iter) + gpointer fs, + guint flags, + GtkTreeIter *iter) { - gchar *name; - GdkPixbuf *pixbuf; - guint fsflags; - - get_fs_properties (fs, &name, &pixbuf, &fsflags); - add_node (model, pixbuf, name, fs, flags | fsflags, iter); - - if (pixbuf) - g_object_unref (pixbuf); + gchar *name; + GdkPixbuf *pixbuf; + guint fsflags; - g_free (name); - check_mount_separator (model, XED_FILE_BOOKMARKS_STORE_IS_FS, TRUE); + get_fs_properties (fs, &name, &pixbuf, &fsflags); + add_node (model, pixbuf, name, fs, flags | fsflags, iter); + + if (pixbuf) + { + g_object_unref (pixbuf); + } + + g_free (name); + check_mount_separator (model, XED_FILE_BOOKMARKS_STORE_IS_FS, TRUE); } static void -process_volume_cb (GVolume *volume, - XedFileBookmarksStore *model) +process_volume_cb (GVolume *volume, + XedFileBookmarksStore *model) { - GMount *mount; - guint flags = XED_FILE_BOOKMARKS_STORE_NONE; - mount = g_volume_get_mount (volume); - - /* CHECK: should we use the LOCAL/REMOTE thing still? */ - if (mount) - { - /* Show mounted volume */ - add_fs (model, mount, flags, NULL); - g_object_unref (mount); - } - else if (g_volume_can_mount (volume)) - { - /* We also show the unmounted volume here so users can - mount it if they want to access it */ - add_fs (model, volume, flags, NULL); - } + GMount *mount; + guint flags = XED_FILE_BOOKMARKS_STORE_NONE; + mount = g_volume_get_mount (volume); + + /* CHECK: should we use the LOCAL/REMOTE thing still? */ + if (mount) + { + /* Show mounted volume */ + add_fs (model, mount, flags, NULL); + g_object_unref (mount); + } + else if (g_volume_can_mount (volume)) + { + /* We also show the unmounted volume here so users can + mount it if they want to access it */ + add_fs (model, volume, flags, NULL); + } } static void process_drive_novolumes (XedFileBookmarksStore *model, - GDrive *drive) + GDrive *drive) { - if (g_drive_is_media_removable (drive) && - !g_drive_is_media_check_automatic (drive) && - g_drive_can_poll_for_media (drive)) - { - /* This can be the case for floppy drives or other - drives where media detection fails. We show the - drive and poll for media when the user activates - it */ - add_fs (model, drive, XED_FILE_BOOKMARKS_STORE_NONE, NULL); - } + if (g_drive_is_media_removable (drive) && + !g_drive_is_media_check_automatic (drive) && + g_drive_can_poll_for_media (drive)) + { + /* This can be the case for floppy drives or other + drives where media detection fails. We show the + drive and poll for media when the user activates + it */ + add_fs (model, drive, XED_FILE_BOOKMARKS_STORE_NONE, NULL); + } } static void -process_drive_cb (GDrive *drive, - XedFileBookmarksStore *model) +process_drive_cb (GDrive *drive, + XedFileBookmarksStore *model) { - GList *volumes; + GList *volumes; - volumes = g_drive_get_volumes (drive); + volumes = g_drive_get_volumes (drive); - if (volumes) - { - /* Add all volumes for the drive */ - g_list_foreach (volumes, (GFunc)process_volume_cb, model); - g_list_free (volumes); - } - else - { - process_drive_novolumes (model, drive); - } + if (volumes) + { + /* Add all volumes for the drive */ + g_list_foreach (volumes, (GFunc)process_volume_cb, model); + g_list_free (volumes); + } + else + { + process_drive_novolumes (model, drive); + } } static void init_drives (XedFileBookmarksStore *model) { - GList *drives; - - drives = g_volume_monitor_get_connected_drives (model->priv->volume_monitor); + GList *drives; - g_list_foreach (drives, (GFunc)process_drive_cb, model); - g_list_foreach (drives, (GFunc)g_object_unref, NULL); - g_list_free (drives); + drives = g_volume_monitor_get_connected_drives (model->priv->volume_monitor); + + g_list_foreach (drives, (GFunc)process_drive_cb, model); + g_list_foreach (drives, (GFunc)g_object_unref, NULL); + g_list_free (drives); } static void -process_volume_nodrive_cb (GVolume *volume, - XedFileBookmarksStore *model) +process_volume_nodrive_cb (GVolume *volume, + XedFileBookmarksStore *model) { - GDrive *drive; - - drive = g_volume_get_drive (volume); - - if (drive) - { - g_object_unref (drive); - return; - } - - process_volume_cb (volume, model); + GDrive *drive; + + drive = g_volume_get_drive (volume); + + if (drive) + { + g_object_unref (drive); + return; + } + + process_volume_cb (volume, model); } static void init_volumes (XedFileBookmarksStore *model) { - GList *volumes; - - volumes = g_volume_monitor_get_volumes (model->priv->volume_monitor); - - g_list_foreach (volumes, (GFunc)process_volume_nodrive_cb, model); - g_list_foreach (volumes, (GFunc)g_object_unref, NULL); - g_list_free (volumes); + GList *volumes; + + volumes = g_volume_monitor_get_volumes (model->priv->volume_monitor); + + g_list_foreach (volumes, (GFunc)process_volume_nodrive_cb, model); + g_list_foreach (volumes, (GFunc)g_object_unref, NULL); + g_list_free (volumes); } static void -process_mount_novolume_cb (GMount *mount, - XedFileBookmarksStore *model) +process_mount_novolume_cb (GMount *mount, + XedFileBookmarksStore *model) { - GVolume *volume; - - volume = g_mount_get_volume (mount); - - if (volume) - { - g_object_unref (volume); - } - else if (!g_mount_is_shadowed (mount)) - { - /* Add the mount */ - add_fs (model, mount, XED_FILE_BOOKMARKS_STORE_NONE, NULL); - } + GVolume *volume; + + volume = g_mount_get_volume (mount); + + if (volume) + { + g_object_unref (volume); + } + else if (!g_mount_is_shadowed (mount)) + { + /* Add the mount */ + add_fs (model, mount, XED_FILE_BOOKMARKS_STORE_NONE, NULL); + } } static void init_mounts (XedFileBookmarksStore *model) { - GList *mounts; - - mounts = g_volume_monitor_get_mounts (model->priv->volume_monitor); - - g_list_foreach (mounts, (GFunc)process_mount_novolume_cb, model); - g_list_foreach (mounts, (GFunc)g_object_unref, NULL); - g_list_free (mounts); + GList *mounts; + + mounts = g_volume_monitor_get_mounts (model->priv->volume_monitor); + + g_list_foreach (mounts, (GFunc)process_mount_novolume_cb, model); + g_list_foreach (mounts, (GFunc)g_object_unref, NULL); + g_list_free (mounts); } static void init_fs (XedFileBookmarksStore * model) { - if (model->priv->volume_monitor == NULL) { - const gchar **ptr; - const gchar *signals[] = { - "drive-connected", "drive-changed", "drive-disconnected", - "volume-added", "volume-removed", "volume-changed", - "mount-added", "mount-removed", "mount-changed", - NULL - }; - - model->priv->volume_monitor = g_volume_monitor_get (); + if (model->priv->volume_monitor == NULL) + { + const gchar **ptr; + const gchar *signals[] = { + "drive-connected", "drive-changed", "drive-disconnected", + "volume-added", "volume-removed", "volume-changed", + "mount-added", "mount-removed", "mount-changed", + NULL + }; - /* Connect signals */ - for (ptr = signals; *ptr; ptr++) - { - g_signal_connect (model->priv->volume_monitor, - *ptr, - G_CALLBACK (on_fs_changed), model); - } - } + model->priv->volume_monitor = g_volume_monitor_get (); - /* First go through all the connected drives */ - init_drives (model); - - /* Then add all volumes, not associated with a drive */ - init_volumes (model); - - /* Then finally add all mounts that have no volume */ - init_mounts (model); + /* Connect signals */ + for (ptr = signals; *ptr; ptr++) + { + g_signal_connect (model->priv->volume_monitor, *ptr, G_CALLBACK (on_fs_changed), model); + } + } + + /* First go through all the connected drives */ + init_drives (model); + + /* Then add all volumes, not associated with a drive */ + init_volumes (model); + + /* Then finally add all mounts that have no volume */ + init_mounts (model); } static gboolean -add_bookmark (XedFileBookmarksStore * model, - gchar const * name, - gchar const * uri) +add_bookmark (XedFileBookmarksStore * model, + gchar const * name, + gchar const * uri) { - GFile * file; - gboolean ret; - guint flags = XED_FILE_BOOKMARKS_STORE_IS_BOOKMARK; - GtkTreeIter iter; - - file = g_file_new_for_uri (uri); - - if (g_file_is_native (file)) { - flags |= XED_FILE_BOOKMARKS_STORE_IS_LOCAL_BOOKMARK; - } else { - flags |= XED_FILE_BOOKMARKS_STORE_IS_REMOTE_BOOKMARK; - } + GFile * file; + gboolean ret; + guint flags = XED_FILE_BOOKMARKS_STORE_IS_BOOKMARK; + GtkTreeIter iter; - ret = add_file (model, file, name, flags, &iter); + file = g_file_new_for_uri (uri); - g_object_unref (file); - - return ret; + if (g_file_is_native (file)) + { + flags |= XED_FILE_BOOKMARKS_STORE_IS_LOCAL_BOOKMARK; + } + else + { + flags |= XED_FILE_BOOKMARKS_STORE_IS_REMOTE_BOOKMARK; + } + + ret = add_file (model, file, name, flags, &iter); + + g_object_unref (file); + + return ret; } static void init_bookmarks (XedFileBookmarksStore * model) { - gchar *bookmarks; - GError *error = NULL; - gchar *contents; - gchar **lines; - gchar **line; - gboolean added = FALSE; + gchar *bookmarks; + GError *error = NULL; + gchar *contents; + gchar **lines; + gchar **line; + gboolean added = FALSE; - /* Read the bookmarks file */ - bookmarks = g_build_filename (g_get_home_dir (), - ".gtk-bookmarks", - NULL); + /* Read the bookmarks file */ + bookmarks = g_build_filename (g_get_home_dir (), ".gtk-bookmarks", NULL); - if (g_file_get_contents (bookmarks, &contents, NULL, &error)) { - lines = g_strsplit (contents, "\n", 0); + if (g_file_get_contents (bookmarks, &contents, NULL, &error)) + { + lines = g_strsplit (contents, "\n", 0); - for (line = lines; *line; ++line) { - if (**line) { - gchar *pos; - gchar *name; + for (line = lines; *line; ++line) + { + if (**line) + { + gchar *pos; + gchar *name; - /* CHECK: is this really utf8? */ - pos = g_utf8_strchr (*line, -1, ' '); + /* CHECK: is this really utf8? */ + pos = g_utf8_strchr (*line, -1, ' '); - if (pos != NULL) { - *pos = '\0'; - name = pos + 1; - } else { - name = NULL; - } + if (pos != NULL) + { + *pos = '\0'; + name = pos + 1; + } + else + { + name = NULL; + } - /* the bookmarks file should contain valid - * URIs, but paranoia is good */ - if (xed_utils_is_valid_uri (*line)) { - added |= add_bookmark (model, name, *line); - } - } - } + /* the bookmarks file should contain valid + * URIs, but paranoia is good */ + if (xed_utils_is_valid_uri (*line)) + { + added |= add_bookmark (model, name, *line); + } + } + } - g_strfreev (lines); - g_free (contents); + g_strfreev (lines); + g_free (contents); - /* Add a watch */ - if (model->priv->bookmarks_monitor == NULL) { - GFile * file; + /* Add a watch */ + if (model->priv->bookmarks_monitor == NULL) + { + GFile * file; - file = g_file_new_for_path (bookmarks); - model->priv->bookmarks_monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL); - g_object_unref (file); + file = g_file_new_for_path (bookmarks); + model->priv->bookmarks_monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL); + g_object_unref (file); - g_signal_connect (model->priv->bookmarks_monitor, - "changed", - (GCallback)on_bookmarks_file_changed, - model); - } - } else { - /* The bookmarks file doesn't exist (which is perfectly fine) */ - g_error_free (error); - } + g_signal_connect (model->priv->bookmarks_monitor, "changed", + (GCallback)on_bookmarks_file_changed, model); + } + } + else + { + /* The bookmarks file doesn't exist (which is perfectly fine) */ + g_error_free (error); + } - if (added) { - /* Bookmarks separator */ - add_node (model, NULL, NULL, NULL, - XED_FILE_BOOKMARKS_STORE_IS_BOOKMARK | - XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR, NULL); - } + if (added) + { + /* Bookmarks separator */ + add_node (model, NULL, NULL, NULL, + XED_FILE_BOOKMARKS_STORE_IS_BOOKMARK | + XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR, NULL); + } - g_free (bookmarks); + g_free (bookmarks); } static gint flags_order[] = { - XED_FILE_BOOKMARKS_STORE_IS_HOME, - XED_FILE_BOOKMARKS_STORE_IS_DESKTOP, - XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, - XED_FILE_BOOKMARKS_STORE_IS_ROOT, - XED_FILE_BOOKMARKS_STORE_IS_FS, - XED_FILE_BOOKMARKS_STORE_IS_BOOKMARK, - -1 + XED_FILE_BOOKMARKS_STORE_IS_HOME, + XED_FILE_BOOKMARKS_STORE_IS_DESKTOP, + XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, + XED_FILE_BOOKMARKS_STORE_IS_ROOT, + XED_FILE_BOOKMARKS_STORE_IS_FS, + XED_FILE_BOOKMARKS_STORE_IS_BOOKMARK, + -1 }; static gint utf8_casecmp (gchar const *s1, const gchar * s2) { - gchar *n1; - gchar *n2; - gint result; + gchar *n1; + gchar *n2; + gint result; - n1 = g_utf8_casefold (s1, -1); - n2 = g_utf8_casefold (s2, -1); + n1 = g_utf8_casefold (s1, -1); + n2 = g_utf8_casefold (s2, -1); - result = g_utf8_collate (n1, n2); + result = g_utf8_collate (n1, n2); - g_free (n1); - g_free (n2); + g_free (n1); + g_free (n2); - return result; + return result; } static gint -bookmarks_compare_names (GtkTreeModel * model, GtkTreeIter * a, - GtkTreeIter * b) +bookmarks_compare_names (GtkTreeModel * model, + GtkTreeIter * a, + GtkTreeIter * b) { - gchar *n1; - gchar *n2; - gint result; - guint f1; - guint f2; + gchar *n1; + gchar *n2; + gint result; + guint f1; + guint f2; - gtk_tree_model_get (model, a, - XED_FILE_BOOKMARKS_STORE_COLUMN_NAME, &n1, - XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, &f1, - -1); - gtk_tree_model_get (model, b, - XED_FILE_BOOKMARKS_STORE_COLUMN_NAME, &n2, - XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, &f2, - -1); + gtk_tree_model_get (model, a, + XED_FILE_BOOKMARKS_STORE_COLUMN_NAME, &n1, + XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, &f1, + -1); + gtk_tree_model_get (model, b, + XED_FILE_BOOKMARKS_STORE_COLUMN_NAME, &n2, + XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, &f2, + -1); - /* do not sort actual bookmarks to keep same order as in caja */ - if ((f1 & XED_FILE_BOOKMARKS_STORE_IS_BOOKMARK) && - (f2 & XED_FILE_BOOKMARKS_STORE_IS_BOOKMARK)) - result = 0; - else if (n1 == NULL && n2 == NULL) - result = 0; - else if (n1 == NULL) - result = -1; - else if (n2 == NULL) - result = 1; - else - result = utf8_casecmp (n1, n2); + /* do not sort actual bookmarks to keep same order as in caja */ + if ((f1 & XED_FILE_BOOKMARKS_STORE_IS_BOOKMARK) && (f2 & XED_FILE_BOOKMARKS_STORE_IS_BOOKMARK)) + { + result = 0; + } + else if (n1 == NULL && n2 == NULL) + { + result = 0; + } + else if (n1 == NULL) + { + result = -1; + } + else if (n2 == NULL) + { + result = 1; + } + else + { + result = utf8_casecmp (n1, n2); + } - g_free (n1); - g_free (n2); + g_free (n1); + g_free (n2); - return result; + return result; } static gint -bookmarks_compare_flags (GtkTreeModel * model, GtkTreeIter * a, - GtkTreeIter * b) +bookmarks_compare_flags (GtkTreeModel * model, + GtkTreeIter * a, + GtkTreeIter * b) { - guint f1; - guint f2; - gint *flags; - guint sep; + guint f1; + guint f2; + gint *flags; + guint sep; - sep = XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR; + sep = XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR; - gtk_tree_model_get (model, a, - XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, &f1, - -1); - gtk_tree_model_get (model, b, - XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, &f2, - -1); + gtk_tree_model_get (model, a, XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, &f1, -1); + gtk_tree_model_get (model, b, XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, &f2, -1); - for (flags = flags_order; *flags != -1; ++flags) { - if ((f1 & *flags) != (f2 & *flags)) { - if (f1 & *flags) { - return -1; - } else { - return 1; - } - } else if ((f1 & *flags) && (f1 & sep) != (f2 & sep)) { - if (f1 & sep) - return -1; - else - return 1; - } - } + for (flags = flags_order; *flags != -1; ++flags) + { + if ((f1 & *flags) != (f2 & *flags)) + { + if (f1 & *flags) + { + return -1; + } + else + { + return 1; + } + } + else if ((f1 & *flags) && (f1 & sep) != (f2 & sep)) + { + if (f1 & sep) + { + return -1; + } + else + { + return 1; + } + } + } - return 0; + return 0; } static gint -bookmarks_compare_func (GtkTreeModel * model, GtkTreeIter * a, - GtkTreeIter * b, gpointer user_data) +bookmarks_compare_func (GtkTreeModel *model, + GtkTreeIter *a, + GtkTreeIter *b, + gpointer user_data) { - gint result; + gint result; - result = bookmarks_compare_flags (model, a, b); + result = bookmarks_compare_flags (model, a, b); - if (result == 0) - result = bookmarks_compare_names (model, a, b); + if (result == 0) + { + result = bookmarks_compare_names (model, a, b); + } - return result; + return result; } static gboolean -find_with_flags (GtkTreeModel * model, GtkTreeIter * iter, gpointer obj, - guint flags, guint notflags) +find_with_flags (GtkTreeModel *model, + GtkTreeIter *iter, + gpointer obj, + guint flags, + guint notflags) { - GtkTreeIter child; - guint childflags = 0; - GObject * childobj; - gboolean fequal; - - if (!gtk_tree_model_get_iter_first (model, &child)) - return FALSE; + GtkTreeIter child; + guint childflags = 0; + GObject * childobj; + gboolean fequal; - do { - gtk_tree_model_get (model, &child, - XED_FILE_BOOKMARKS_STORE_COLUMN_OBJECT, - &childobj, - XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, - &childflags, -1); - - fequal = (obj == childobj); - - if (childobj) - g_object_unref (childobj); - - if ((obj == NULL || fequal) && - (childflags & flags) == flags - && !(childflags & notflags)) { - *iter = child; - return TRUE; - } - } while (gtk_tree_model_iter_next (model, &child)); + if (!gtk_tree_model_get_iter_first (model, &child)) + { + return FALSE; + } - return FALSE; + do { + gtk_tree_model_get (model, &child, + XED_FILE_BOOKMARKS_STORE_COLUMN_OBJECT, + &childobj, + XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, + &childflags, -1); + + fequal = (obj == childobj); + + if (childobj) + { + g_object_unref (childobj); + } + + if ((obj == NULL || fequal) && + (childflags & flags) == flags + && !(childflags & notflags)) + { + *iter = child; + return TRUE; + } + } while (gtk_tree_model_iter_next (model, &child)); + + return FALSE; } static void -remove_node (GtkTreeModel * model, GtkTreeIter * iter) +remove_node (GtkTreeModel *model, + GtkTreeIter *iter) { - guint flags; + guint flags; - gtk_tree_model_get (model, iter, - XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, &flags, - -1); + gtk_tree_model_get (model, iter, XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, &flags, -1); - if (!(flags & XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR)) { - if (flags & XED_FILE_BOOKMARKS_STORE_IS_FS) { - check_mount_separator (XED_FILE_BOOKMARKS_STORE (model), - flags & XED_FILE_BOOKMARKS_STORE_IS_FS, - FALSE); - } - } + if (!(flags & XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR)) + { + if (flags & XED_FILE_BOOKMARKS_STORE_IS_FS) + { + check_mount_separator (XED_FILE_BOOKMARKS_STORE (model), + flags & XED_FILE_BOOKMARKS_STORE_IS_FS, + FALSE); + } + } - gtk_tree_store_remove (GTK_TREE_STORE (model), iter); + gtk_tree_store_remove (GTK_TREE_STORE (model), iter); } static void -remove_bookmarks (XedFileBookmarksStore * model) +remove_bookmarks (XedFileBookmarksStore *model) { - GtkTreeIter iter; + GtkTreeIter iter; - while (find_with_flags (GTK_TREE_MODEL (model), &iter, NULL, - XED_FILE_BOOKMARKS_STORE_IS_BOOKMARK, - 0)) { - remove_node (GTK_TREE_MODEL (model), &iter); - } + while (find_with_flags (GTK_TREE_MODEL (model), &iter, NULL, + XED_FILE_BOOKMARKS_STORE_IS_BOOKMARK, 0)) + { + remove_node (GTK_TREE_MODEL (model), &iter); + } } static void -initialize_fill (XedFileBookmarksStore * model) +initialize_fill (XedFileBookmarksStore *model) { - init_special_directories (model); - init_fs (model); - init_bookmarks (model); + init_special_directories (model); + init_fs (model); + init_bookmarks (model); } /* Public */ XedFileBookmarksStore * xed_file_bookmarks_store_new (void) { - XedFileBookmarksStore *model; - GType column_types[] = { - GDK_TYPE_PIXBUF, - G_TYPE_STRING, - G_TYPE_OBJECT, - G_TYPE_UINT - }; + XedFileBookmarksStore *model; + GType column_types[] = { + GDK_TYPE_PIXBUF, + G_TYPE_STRING, + G_TYPE_OBJECT, + G_TYPE_UINT + }; - model = g_object_new (XED_TYPE_FILE_BOOKMARKS_STORE, NULL); - gtk_tree_store_set_column_types (GTK_TREE_STORE (model), - XED_FILE_BOOKMARKS_STORE_N_COLUMNS, - column_types); + model = g_object_new (XED_TYPE_FILE_BOOKMARKS_STORE, NULL); + gtk_tree_store_set_column_types (GTK_TREE_STORE (model), + XED_FILE_BOOKMARKS_STORE_N_COLUMNS, + column_types); - gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (model), - bookmarks_compare_func, - NULL, NULL); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model), - GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, - GTK_SORT_ASCENDING); + gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (model), + bookmarks_compare_func, + NULL, NULL); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model), + GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, + GTK_SORT_ASCENDING); - initialize_fill (model); + initialize_fill (model); - return model; + return model; } gchar * -xed_file_bookmarks_store_get_uri (XedFileBookmarksStore * model, - GtkTreeIter * iter) +xed_file_bookmarks_store_get_uri (XedFileBookmarksStore *model, + GtkTreeIter *iter) { - GObject * obj; - GFile * file = NULL; - guint flags; - gchar * ret = NULL; - gboolean isfs; - - g_return_val_if_fail (XED_IS_FILE_BOOKMARKS_STORE (model), NULL); - g_return_val_if_fail (iter != NULL, NULL); + GObject * obj; + GFile * file = NULL; + guint flags; + gchar * ret = NULL; + gboolean isfs; - gtk_tree_model_get (GTK_TREE_MODEL (model), iter, - XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, - &flags, - XED_FILE_BOOKMARKS_STORE_COLUMN_OBJECT, - &obj, - -1); + g_return_val_if_fail (XED_IS_FILE_BOOKMARKS_STORE (model), NULL); + g_return_val_if_fail (iter != NULL, NULL); - if (obj == NULL) - return NULL; + gtk_tree_model_get (GTK_TREE_MODEL (model), iter, + XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, + &flags, + XED_FILE_BOOKMARKS_STORE_COLUMN_OBJECT, + &obj, + -1); - isfs = (flags & XED_FILE_BOOKMARKS_STORE_IS_FS); - - if (isfs && (flags & XED_FILE_BOOKMARKS_STORE_IS_MOUNT)) - { - file = g_mount_get_root (G_MOUNT (obj)); - } - else if (!isfs) - { - file = g_object_ref (obj); - } - - g_object_unref (obj); - - if (file) - { - ret = g_file_get_uri (file); - g_object_unref (file); - } - - return ret; + if (obj == NULL) + { + return NULL; + } + + isfs = (flags & XED_FILE_BOOKMARKS_STORE_IS_FS); + + if (isfs && (flags & XED_FILE_BOOKMARKS_STORE_IS_MOUNT)) + { + file = g_mount_get_root (G_MOUNT (obj)); + } + else if (!isfs) + { + file = g_object_ref (obj); + } + + g_object_unref (obj); + + if (file) + { + ret = g_file_get_uri (file); + g_object_unref (file); + } + + return ret; } void -xed_file_bookmarks_store_refresh (XedFileBookmarksStore * model) +xed_file_bookmarks_store_refresh (XedFileBookmarksStore *model) { - gtk_tree_store_clear (GTK_TREE_STORE (model)); - initialize_fill (model); + gtk_tree_store_clear (GTK_TREE_STORE (model)); + initialize_fill (model); } static void -on_fs_changed (GVolumeMonitor *monitor, - GObject *object, - XedFileBookmarksStore *model) +on_fs_changed (GVolumeMonitor *monitor, + GObject *object, + XedFileBookmarksStore *model) { - GtkTreeModel *tree_model = GTK_TREE_MODEL (model); - guint flags = XED_FILE_BOOKMARKS_STORE_IS_FS; - guint noflags = XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR; - GtkTreeIter iter; + GtkTreeModel *tree_model = GTK_TREE_MODEL (model); + guint flags = XED_FILE_BOOKMARKS_STORE_IS_FS; + guint noflags = XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR; + GtkTreeIter iter; - /* clear all fs items */ - while (find_with_flags (tree_model, &iter, NULL, flags, noflags)) - remove_node (tree_model, &iter); - - /* then reinitialize */ - init_fs (model); + /* clear all fs items */ + while (find_with_flags (tree_model, &iter, NULL, flags, noflags)) + remove_node (tree_model, &iter); + + /* then reinitialize */ + init_fs (model); } static void on_bookmarks_file_changed (GFileMonitor * monitor, - GFile * file, - GFile * other_file, - GFileMonitorEvent event_type, - XedFileBookmarksStore * model) + GFile * file, + GFile * other_file, + GFileMonitorEvent event_type, + XedFileBookmarksStore * model) { - switch (event_type) { - case G_FILE_MONITOR_EVENT_CHANGED: - case G_FILE_MONITOR_EVENT_CREATED: - /* Re-initialize bookmarks */ - remove_bookmarks (model); - init_bookmarks (model); - break; - case G_FILE_MONITOR_EVENT_DELETED: // FIXME: shouldn't we also monitor the directory? - /* Remove bookmarks */ - remove_bookmarks (model); - g_object_unref (monitor); - model->priv->bookmarks_monitor = NULL; - break; - default: - break; - } + switch (event_type) { + case G_FILE_MONITOR_EVENT_CHANGED: + case G_FILE_MONITOR_EVENT_CREATED: + /* Re-initialize bookmarks */ + remove_bookmarks (model); + init_bookmarks (model); + break; + case G_FILE_MONITOR_EVENT_DELETED: // FIXME: shouldn't we also monitor the directory? + /* Remove bookmarks */ + remove_bookmarks (model); + g_object_unref (monitor); + model->priv->bookmarks_monitor = NULL; + break; + default: + break; + } +} + +void +_xed_file_bookmarks_store_register_type (GTypeModule *type_module) +{ + xed_file_bookmarks_store_register_type (type_module); } // ex:ts=8:noet: diff --git a/plugins/filebrowser/xed-file-bookmarks-store.h b/plugins/filebrowser/xed-file-bookmarks-store.h index 8560812..57fe961 100644 --- a/plugins/filebrowser/xed-file-bookmarks-store.h +++ b/plugins/filebrowser/xed-file-bookmarks-store.h @@ -1,5 +1,5 @@ /* - * xed-file-bookmarks-store.h - Xed plugin providing easy file access + * xed-file-bookmarks-store.h - Xed plugin providing easy file access * from the sidepanel * * Copyright (C) 2006 - Jesse van den Kieboom @@ -25,66 +25,66 @@ #include G_BEGIN_DECLS -#define XED_TYPE_FILE_BOOKMARKS_STORE (xed_file_bookmarks_store_get_type ()) -#define XED_FILE_BOOKMARKS_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStore)) -#define XED_FILE_BOOKMARKS_STORE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStore const)) -#define XED_FILE_BOOKMARKS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStoreClass)) -#define XED_IS_FILE_BOOKMARKS_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_FILE_BOOKMARKS_STORE)) -#define XED_IS_FILE_BOOKMARKS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_BOOKMARKS_STORE)) -#define XED_FILE_BOOKMARKS_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStoreClass)) +#define XED_TYPE_FILE_BOOKMARKS_STORE (xed_file_bookmarks_store_get_type ()) +#define XED_FILE_BOOKMARKS_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStore)) +#define XED_FILE_BOOKMARKS_STORE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStore const)) +#define XED_FILE_BOOKMARKS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStoreClass)) +#define XED_IS_FILE_BOOKMARKS_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_FILE_BOOKMARKS_STORE)) +#define XED_IS_FILE_BOOKMARKS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_BOOKMARKS_STORE)) +#define XED_FILE_BOOKMARKS_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStoreClass)) typedef struct _XedFileBookmarksStore XedFileBookmarksStore; typedef struct _XedFileBookmarksStoreClass XedFileBookmarksStoreClass; typedef struct _XedFileBookmarksStorePrivate XedFileBookmarksStorePrivate; -enum +enum { - XED_FILE_BOOKMARKS_STORE_COLUMN_ICON = 0, - XED_FILE_BOOKMARKS_STORE_COLUMN_NAME, - XED_FILE_BOOKMARKS_STORE_COLUMN_OBJECT, - XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, - XED_FILE_BOOKMARKS_STORE_N_COLUMNS + XED_FILE_BOOKMARKS_STORE_COLUMN_ICON = 0, + XED_FILE_BOOKMARKS_STORE_COLUMN_NAME, + XED_FILE_BOOKMARKS_STORE_COLUMN_OBJECT, + XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, + XED_FILE_BOOKMARKS_STORE_N_COLUMNS }; -enum +enum { - XED_FILE_BOOKMARKS_STORE_NONE = 0, - XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR = 1 << 0, /* Separator item */ - XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR = 1 << 1, /* Special user dir */ - XED_FILE_BOOKMARKS_STORE_IS_HOME = 1 << 2, /* The special Home user directory */ - XED_FILE_BOOKMARKS_STORE_IS_DESKTOP = 1 << 3, /* The special Desktop user directory */ - XED_FILE_BOOKMARKS_STORE_IS_DOCUMENTS = 1 << 4, /* The special Documents user directory */ - XED_FILE_BOOKMARKS_STORE_IS_FS = 1 << 5, /* A mount object */ - XED_FILE_BOOKMARKS_STORE_IS_MOUNT = 1 << 6, /* A mount object */ - XED_FILE_BOOKMARKS_STORE_IS_VOLUME = 1 << 7, /* A volume object */ - XED_FILE_BOOKMARKS_STORE_IS_DRIVE = 1 << 8, /* A drive object */ - XED_FILE_BOOKMARKS_STORE_IS_ROOT = 1 << 9, /* The root file system (file:///) */ - XED_FILE_BOOKMARKS_STORE_IS_BOOKMARK = 1 << 10, /* A gtk bookmark */ - XED_FILE_BOOKMARKS_STORE_IS_REMOTE_BOOKMARK = 1 << 11, /* A remote gtk bookmark */ - XED_FILE_BOOKMARKS_STORE_IS_LOCAL_BOOKMARK = 1 << 12 /* A local gtk bookmark */ + XED_FILE_BOOKMARKS_STORE_NONE = 0, + XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR = 1 << 0, /* Separator item */ + XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR = 1 << 1, /* Special user dir */ + XED_FILE_BOOKMARKS_STORE_IS_HOME = 1 << 2, /* The special Home user directory */ + XED_FILE_BOOKMARKS_STORE_IS_DESKTOP = 1 << 3, /* The special Desktop user directory */ + XED_FILE_BOOKMARKS_STORE_IS_DOCUMENTS = 1 << 4, /* The special Documents user directory */ + XED_FILE_BOOKMARKS_STORE_IS_FS = 1 << 5, /* A mount object */ + XED_FILE_BOOKMARKS_STORE_IS_MOUNT = 1 << 6, /* A mount object */ + XED_FILE_BOOKMARKS_STORE_IS_VOLUME = 1 << 7, /* A volume object */ + XED_FILE_BOOKMARKS_STORE_IS_DRIVE = 1 << 8, /* A drive object */ + XED_FILE_BOOKMARKS_STORE_IS_ROOT = 1 << 9, /* The root file system (file:///) */ + XED_FILE_BOOKMARKS_STORE_IS_BOOKMARK = 1 << 10, /* A gtk bookmark */ + XED_FILE_BOOKMARKS_STORE_IS_REMOTE_BOOKMARK = 1 << 11, /* A remote gtk bookmark */ + XED_FILE_BOOKMARKS_STORE_IS_LOCAL_BOOKMARK = 1 << 12 /* A local gtk bookmark */ }; -struct _XedFileBookmarksStore +struct _XedFileBookmarksStore { - GtkTreeStore parent; + GtkTreeStore parent; - XedFileBookmarksStorePrivate *priv; + XedFileBookmarksStorePrivate *priv; }; -struct _XedFileBookmarksStoreClass +struct _XedFileBookmarksStoreClass { - GtkTreeStoreClass parent_class; + GtkTreeStoreClass parent_class; }; GType xed_file_bookmarks_store_get_type (void) G_GNUC_CONST; -GType xed_file_bookmarks_store_register_type (GTypeModule * module); +void _xed_file_bookmarks_store_register_type (GTypeModule * module); XedFileBookmarksStore *xed_file_bookmarks_store_new (void); gchar *xed_file_bookmarks_store_get_uri (XedFileBookmarksStore * model, - GtkTreeIter * iter); + GtkTreeIter * iter); void xed_file_bookmarks_store_refresh (XedFileBookmarksStore * model); G_END_DECLS -#endif /* __XED_FILE_BOOKMARKS_STORE_H__ */ +#endif /* __XED_FILE_BOOKMARKS_STORE_H__ */ // ex:ts=8:noet: diff --git a/plugins/filebrowser/xed-file-browser-plugin.c b/plugins/filebrowser/xed-file-browser-plugin.c index 762c4b6..2e360f7 100644 --- a/plugins/filebrowser/xed-file-browser-plugin.c +++ b/plugins/filebrowser/xed-file-browser-plugin.c @@ -28,9 +28,11 @@ #include #include #include +#include #include #include #include +#include #include "xed-file-browser-enum-types.h" #include "xed-file-browser-plugin.h" @@ -39,8 +41,6 @@ #include "xed-file-browser-widget.h" #include "xed-file-browser-messages.h" -#define WINDOW_DATA_KEY "XedFileBrowserPluginWindowData" - #define FILE_BROWSER_SCHEMA "org.x.editor.plugins.filebrowser" #define FILE_BROWSER_ONLOAD_SCHEMA "org.x.editor.plugins.filebrowser.on-load" @@ -48,11 +48,8 @@ struct _XedFileBrowserPluginPrivate { - gpointer *dummy; -}; + GtkWidget *window; -typedef struct _XedFileBrowserPluginData -{ XedFileBrowserWidget * tree_widget; gulong merge_id; GtkActionGroup * action_group; @@ -62,7 +59,13 @@ typedef struct _XedFileBrowserPluginData GSettings *settings; GSettings *onload_settings; -} XedFileBrowserPluginData; +}; + +enum +{ + PROP_0, + PROP_OBJECT +}; static void on_uri_activated_cb (XedFileBrowserWidget * widget, gchar const *uri, @@ -70,67 +73,113 @@ static void on_uri_activated_cb (XedFileBrowserWidget * widget, static void on_error_cb (XedFileBrowserWidget * widget, guint code, gchar const *message, - XedWindow * window); + XedFileBrowserPluginPrivate * data); static void on_model_set_cb (XedFileBrowserView * widget, GParamSpec *arg1, - XedWindow * window); + XedFileBrowserPluginPrivate * data); static void on_virtual_root_changed_cb (XedFileBrowserStore * model, GParamSpec * param, - XedWindow * window); + XedFileBrowserPluginPrivate * data); static void on_filter_mode_changed_cb (XedFileBrowserStore * model, GParamSpec * param, - XedWindow * window); + XedFileBrowserPluginPrivate * data); static void on_rename_cb (XedFileBrowserStore * model, const gchar * olduri, const gchar * newuri, XedWindow * window); static void on_filter_pattern_changed_cb (XedFileBrowserWidget * widget, GParamSpec * param, - XedWindow * window); + XedFileBrowserPluginPrivate * data); static void on_tab_added_cb (XedWindow * window, XedTab * tab, - XedFileBrowserPluginData * data); + XedFileBrowserPluginPrivate * data); static gboolean on_confirm_delete_cb (XedFileBrowserWidget * widget, XedFileBrowserStore * store, GList * rows, - XedWindow * window); + XedFileBrowserPluginPrivate * data); static gboolean on_confirm_no_trash_cb (XedFileBrowserWidget * widget, GList * files, XedWindow * window); -XED_PLUGIN_REGISTER_TYPE_WITH_CODE (XedFileBrowserPlugin, filetree_plugin, \ - xed_file_browser_enum_and_flag_register_type (type_module); \ - xed_file_browser_store_register_type (type_module); \ - xed_file_bookmarks_store_register_type (type_module); \ - xed_file_browser_view_register_type (type_module); \ - xed_file_browser_widget_register_type (type_module); \ +static void peas_activatable_iface_init (PeasActivatableInterface *iface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedFileBrowserPlugin, + xed_file_browser_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init) \ + \ + xed_file_browser_enum_and_flag_register_type (type_module); \ + _xed_file_browser_store_register_type (type_module); \ + _xed_file_bookmarks_store_register_type (type_module); \ + _xed_file_browser_view_register_type (type_module); \ + _xed_file_browser_widget_register_type (type_module); ) static void -filetree_plugin_init (XedFileBrowserPlugin * plugin) +xed_file_browser_plugin_init (XedFileBrowserPlugin * plugin) { plugin->priv = XED_FILE_BROWSER_PLUGIN_GET_PRIVATE (plugin); } static void -filetree_plugin_finalize (GObject * object) +xed_file_browser_plugin_dispose (GObject * object) { - //XedFileBrowserPlugin * plugin = XED_FILE_BROWSER_PLUGIN (object); + XedFileBrowserPlugin *plugin = XED_FILE_BROWSER_PLUGIN (object); - G_OBJECT_CLASS (filetree_plugin_parent_class)->finalize (object); + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + G_OBJECT_CLASS (xed_file_browser_plugin_parent_class)->dispose (object); } -static XedFileBrowserPluginData * -get_plugin_data (XedWindow * window) +static void +xed_file_browser_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - return (XedFileBrowserPluginData *) (g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY)); + XedFileBrowserPlugin *plugin = XED_FILE_BROWSER_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +xed_file_browser_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + XedFileBrowserPlugin *plugin = XED_FILE_BROWSER_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void on_end_loading_cb (XedFileBrowserStore * store, GtkTreeIter * iter, - XedFileBrowserPluginData * data) + XedFileBrowserPluginPrivate * data) { /* Disconnect the signal */ g_signal_handler_disconnect (store, data->end_loading_handle); @@ -139,7 +188,7 @@ on_end_loading_cb (XedFileBrowserStore * store, } static void -prepare_auto_root (XedFileBrowserPluginData *data) +prepare_auto_root (XedFileBrowserPluginPrivate *data) { XedFileBrowserStore *store; @@ -159,7 +208,7 @@ prepare_auto_root (XedFileBrowserPluginData *data) } static void -restore_default_location (XedFileBrowserPluginData *data) +restore_default_location (XedFileBrowserPluginPrivate *data) { gchar * root; gchar * virtual_root; @@ -205,7 +254,7 @@ restore_default_location (XedFileBrowserPluginData *data) } static void -restore_filter (XedFileBrowserPluginData * data) +restore_filter (XedFileBrowserPluginPrivate *data) { gchar *filter_mode; XedFileBrowserStoreFilterMode mode; @@ -247,7 +296,7 @@ restore_filter (XedFileBrowserPluginData * data) } static void -set_root_from_doc (XedFileBrowserPluginData * data, +set_root_from_doc (XedFileBrowserPluginPrivate * data, XedDocument * doc) { GFile *file; @@ -280,17 +329,13 @@ set_root_from_doc (XedFileBrowserPluginData * data, static void on_action_set_active_root (GtkAction * action, - XedWindow * window) + XedFileBrowserPluginPrivate * data) { - XedFileBrowserPluginData *data; - - data = get_plugin_data (window); - set_root_from_doc (data, - xed_window_get_active_document (window)); + set_root_from_doc (data, xed_window_get_active_document (XED_WINDOW (data->window))); } static gchar * -get_terminal (XedFileBrowserPluginData * data) +get_terminal (XedFileBrowserPluginPrivate * data) { // TODO : Identify the DE, find the preferred terminal application (xterminal shouldn't be hardcoded here, it should be set as default in the DE prefs) return g_strdup ("xterminal"); @@ -298,9 +343,8 @@ get_terminal (XedFileBrowserPluginData * data) static void on_action_open_terminal (GtkAction * action, - XedWindow * window) + XedFileBrowserPluginPrivate * data) { - XedFileBrowserPluginData * data; gchar * terminal; gchar * wd = NULL; gchar * local; @@ -310,8 +354,6 @@ on_action_open_terminal (GtkAction * action, GtkTreeIter iter; XedFileBrowserStore * store; - data = get_plugin_data (window); - /* Get the current directory */ if (!xed_file_browser_widget_get_selected_directory (data->tree_widget, &iter)) return; @@ -351,17 +393,14 @@ on_action_open_terminal (GtkAction * action, static void on_selection_changed_cb (GtkTreeSelection *selection, - XedWindow *window) + XedFileBrowserPluginPrivate *data) { - XedFileBrowserPluginData * data; GtkTreeView * tree_view; GtkTreeModel * model; GtkTreeIter iter; gboolean sensitive; gchar * uri; - data = get_plugin_data (window); - tree_view = GTK_TREE_VIEW (xed_file_browser_widget_get_browser_view (data->tree_widget)); model = gtk_tree_view_get_model (tree_view); @@ -418,14 +457,12 @@ static GtkActionEntry extra_single_selection_actions[] = { }; static void -add_popup_ui (XedWindow * window) +add_popup_ui (XedFileBrowserPluginPrivate *data) { - XedFileBrowserPluginData * data; GtkUIManager * manager; GtkActionGroup * action_group; GError * error = NULL; - data = get_plugin_data (window); manager = xed_file_browser_widget_get_ui_manager (data->tree_widget); action_group = gtk_action_group_new ("FileBrowserPluginExtra"); @@ -433,7 +470,7 @@ add_popup_ui (XedWindow * window) gtk_action_group_add_actions (action_group, extra_actions, G_N_ELEMENTS (extra_actions), - window); + data); gtk_ui_manager_insert_action_group (manager, action_group, 0); data->action_group = action_group; @@ -442,7 +479,7 @@ add_popup_ui (XedWindow * window) gtk_action_group_add_actions (action_group, extra_single_selection_actions, G_N_ELEMENTS (extra_single_selection_actions), - window); + data); gtk_ui_manager_insert_action_group (manager, action_group, 0); data->single_selection_action_group = action_group; @@ -458,12 +495,10 @@ add_popup_ui (XedWindow * window) } static void -remove_popup_ui (XedWindow * window) +remove_popup_ui (XedFileBrowserPluginPrivate *data) { - XedFileBrowserPluginData * data; GtkUIManager * manager; - data = get_plugin_data (window); manager = xed_file_browser_widget_get_ui_manager (data->tree_widget); gtk_ui_manager_remove_ui (manager, data->merge_id); @@ -475,14 +510,14 @@ remove_popup_ui (XedWindow * window) } static void -impl_updateui (XedPlugin * plugin, XedWindow * window) +xed_file_browser_plugin_update_state (PeasActivatable *activatable) { - XedFileBrowserPluginData * data; + XedFileBrowserPluginPrivate *data; XedDocument * doc; - data = get_plugin_data (window); + data = XED_FILE_BROWSER_PLUGIN (activatable)->priv; - doc = xed_window_get_active_document (window); + doc = xed_window_get_active_document (XED_WINDOW (data->window)); gtk_action_set_sensitive (gtk_action_group_get_action (data->action_group, "SetActiveRoot"), @@ -491,10 +526,11 @@ impl_updateui (XedPlugin * plugin, XedWindow * window) } static void -impl_activate (XedPlugin * plugin, XedWindow * window) +xed_file_browser_plugin_activate (PeasActivatable *activatable) { + XedFileBrowserPluginPrivate *data; + XedWindow *window; XedPanel * panel; - XedFileBrowserPluginData * data; GtkWidget * image; GdkPixbuf * pixbuf; XedFileBrowserStore * store; @@ -502,9 +538,10 @@ impl_activate (XedPlugin * plugin, XedWindow * window) GSettingsSchemaSource *schema_source; GSettingsSchema *schema; - data = g_new0 (XedFileBrowserPluginData, 1); + data = XED_FILE_BROWSER_PLUGIN (activatable)->priv; + window = XED_WINDOW (data->window); - data_dir = xed_plugin_get_data_dir (plugin); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (activatable)); data->tree_widget = XED_FILE_BROWSER_WIDGET (xed_file_browser_widget_new (data_dir)); g_free (data_dir); @@ -516,17 +553,17 @@ impl_activate (XedPlugin * plugin, XedWindow * window) G_CALLBACK (on_uri_activated_cb), window); g_signal_connect (data->tree_widget, - "error", G_CALLBACK (on_error_cb), window); + "error", G_CALLBACK (on_error_cb), data); g_signal_connect (data->tree_widget, "notify::filter-pattern", G_CALLBACK (on_filter_pattern_changed_cb), - window); + data); g_signal_connect (data->tree_widget, "confirm-delete", G_CALLBACK (on_confirm_delete_cb), - window); + data); g_signal_connect (data->tree_widget, "confirm-no-trash", @@ -538,7 +575,7 @@ impl_activate (XedPlugin * plugin, XedWindow * window) (data->tree_widget))), "changed", G_CALLBACK (on_selection_changed_cb), - window); + data); panel = xed_window_get_side_panel (window); pixbuf = xed_file_browser_utils_pixbuf_from_theme("system-file-manager", @@ -557,9 +594,8 @@ impl_activate (XedPlugin * plugin, XedWindow * window) _("File Browser"), image); gtk_widget_show (GTK_WIDGET (data->tree_widget)); - g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, data); - add_popup_ui (window); + add_popup_ui (data); /* Restore filter options */ restore_filter (data); @@ -568,18 +604,18 @@ impl_activate (XedPlugin * plugin, XedWindow * window) g_signal_connect (xed_file_browser_widget_get_browser_view (data->tree_widget), "notify::model", G_CALLBACK (on_model_set_cb), - window); + data); store = xed_file_browser_widget_get_browser_store (data->tree_widget); g_signal_connect (store, "notify::virtual-root", G_CALLBACK (on_virtual_root_changed_cb), - window); + data); g_signal_connect (store, "notify::filter-mode", G_CALLBACK (on_filter_mode_changed_cb), - window); + data); g_signal_connect (store, "rename", @@ -594,16 +630,18 @@ impl_activate (XedPlugin * plugin, XedWindow * window) /* Register messages on the bus */ xed_file_browser_messages_register (window, data->tree_widget); - impl_updateui (plugin, window); + xed_file_browser_plugin_update_state (activatable); } static void -impl_deactivate (XedPlugin * plugin, XedWindow * window) +xed_file_browser_plugin_deactivate (PeasActivatable *activatable) { - XedFileBrowserPluginData * data; + XedFileBrowserPluginPrivate *data; + XedWindow *window; XedPanel * panel; - data = get_plugin_data (window); + data = XED_FILE_BROWSER_PLUGIN (activatable)->priv; + window = XED_WINDOW (data->window); /* Unregister messages from the bus */ xed_file_browser_messages_unregister (window); @@ -616,31 +654,51 @@ impl_deactivate (XedPlugin * plugin, XedWindow * window) g_object_unref (data->settings); g_object_unref (data->onload_settings); - remove_popup_ui (window); + remove_popup_ui (data); panel = xed_window_get_side_panel (window); xed_panel_remove_item (panel, GTK_WIDGET (data->tree_widget)); - - g_free (data); - g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL); } static void -filetree_plugin_class_init (XedFileBrowserPluginClass * klass) +xed_file_browser_plugin_class_init (XedFileBrowserPluginClass * klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - XedPluginClass * plugin_class = XED_PLUGIN_CLASS (klass); - object_class->finalize = filetree_plugin_finalize; + object_class->dispose = xed_file_browser_plugin_dispose; + object_class->set_property = xed_file_browser_plugin_set_property; + object_class->get_property = xed_file_browser_plugin_get_property; - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_updateui; + g_object_class_override_property (object_class, PROP_OBJECT, "object"); g_type_class_add_private (object_class, sizeof (XedFileBrowserPluginPrivate)); } +static void +xed_file_browser_plugin_class_finalize (XedFileBrowserPluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = xed_file_browser_plugin_activate; + iface->deactivate = xed_file_browser_plugin_deactivate; + iface->update_state = xed_file_browser_plugin_update_state; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + xed_file_browser_plugin_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + XED_TYPE_FILE_BROWSER_PLUGIN); +} + /* Callbacks */ static void on_uri_activated_cb (XedFileBrowserWidget * tree_widget, @@ -651,13 +709,10 @@ on_uri_activated_cb (XedFileBrowserWidget * tree_widget, static void on_error_cb (XedFileBrowserWidget * tree_widget, - guint code, gchar const *message, XedWindow * window) + guint code, gchar const *message, XedFileBrowserPluginPrivate * data) { gchar * title; GtkWidget * dlg; - XedFileBrowserPluginData * data; - - data = get_plugin_data (window); /* Do not show the error when the root has been set automatically */ if (data->auto_root && (code == XED_FILE_BROWSER_ERROR_SET_ROOT || @@ -704,7 +759,7 @@ on_error_cb (XedFileBrowserWidget * tree_widget, break; } - dlg = gtk_message_dialog_new (GTK_WINDOW (window), + dlg = gtk_message_dialog_new (GTK_WINDOW (data->window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, @@ -719,9 +774,8 @@ on_error_cb (XedFileBrowserWidget * tree_widget, static void on_model_set_cb (XedFileBrowserView * widget, GParamSpec *arg1, - XedWindow * window) + XedFileBrowserPluginPrivate * data) { - XedFileBrowserPluginData * data = get_plugin_data (window); GtkTreeModel * model; model = gtk_tree_view_get_model (GTK_TREE_VIEW (xed_file_browser_widget_get_browser_view (data->tree_widget))); @@ -737,9 +791,8 @@ on_model_set_cb (XedFileBrowserView * widget, static void on_filter_mode_changed_cb (XedFileBrowserStore * model, GParamSpec * param, - XedWindow * window) + XedFileBrowserPluginPrivate * data) { - XedFileBrowserPluginData * data = get_plugin_data (window); XedFileBrowserStoreFilterMode mode; mode = xed_file_browser_store_get_filter_mode (model); @@ -823,9 +876,8 @@ on_rename_cb (XedFileBrowserStore * store, static void on_filter_pattern_changed_cb (XedFileBrowserWidget * widget, GParamSpec * param, - XedWindow * window) + XedFileBrowserPluginPrivate * data) { - XedFileBrowserPluginData * data = get_plugin_data (window); gchar * pattern; g_object_get (G_OBJECT (widget), "filter-pattern", &pattern, NULL); @@ -841,9 +893,8 @@ on_filter_pattern_changed_cb (XedFileBrowserWidget * widget, static void on_virtual_root_changed_cb (XedFileBrowserStore * store, GParamSpec * param, - XedWindow * window) + XedFileBrowserPluginPrivate * data) { - XedFileBrowserPluginData * data = get_plugin_data (window); gchar * root; gchar * virtual_root; @@ -863,7 +914,7 @@ on_virtual_root_changed_cb (XedFileBrowserStore * store, g_settings_set_string (data->onload_settings, "virtual-root", virtual_root); } - g_signal_handlers_disconnect_by_func (window, + g_signal_handlers_disconnect_by_func (XED_WINDOW (data->window), G_CALLBACK (on_tab_added_cb), data); @@ -874,7 +925,7 @@ on_virtual_root_changed_cb (XedFileBrowserStore * store, static void on_tab_added_cb (XedWindow * window, XedTab * tab, - XedFileBrowserPluginData * data) + XedFileBrowserPluginPrivate *data) { gboolean open; gboolean load_default = TRUE; @@ -956,15 +1007,12 @@ static gboolean on_confirm_delete_cb (XedFileBrowserWidget *widget, XedFileBrowserStore *store, GList *paths, - XedWindow *window) + XedFileBrowserPluginPrivate *data) { gchar *normal; gchar *message; gchar *secondary; gboolean result; - XedFileBrowserPluginData *data; - - data = get_plugin_data (window); if (paths->next == NULL) { normal = get_filename_from_path (GTK_TREE_MODEL (store), (GtkTreePath *)(paths->data)); @@ -976,7 +1024,7 @@ on_confirm_delete_cb (XedFileBrowserWidget *widget, secondary = _("If you delete an item, it is permanently lost."); - result = xed_file_browser_utils_confirmation_dialog (window, + result = xed_file_browser_utils_confirmation_dialog (XED_WINDOW (data->window), GTK_MESSAGE_QUESTION, message, secondary, diff --git a/plugins/filebrowser/xed-file-browser-plugin.h b/plugins/filebrowser/xed-file-browser-plugin.h index e7188e1..b6fed71 100644 --- a/plugins/filebrowser/xed-file-browser-plugin.h +++ b/plugins/filebrowser/xed-file-browser-plugin.h @@ -1,5 +1,5 @@ /* - * xed-file-browser-plugin.h - Xed plugin providing easy file access + * xed-file-browser-plugin.h - Xed plugin providing easy file access * from the sidepanel * * Copyright (C) 2006 - Jesse van den Kieboom @@ -24,46 +24,48 @@ #include #include -#include +#include +#include G_BEGIN_DECLS + /* * Type checking and casting macros */ -#define XED_TYPE_FILE_BROWSER_PLUGIN (filetree_plugin_get_type ()) -#define XED_FILE_BROWSER_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPlugin)) -#define XED_FILE_BROWSER_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPluginClass)) -#define XED_IS_FILE_BROWSER_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_FILE_BROWSER_PLUGIN)) -#define XED_IS_FILE_BROWSER_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_FILE_BROWSER_PLUGIN)) -#define XED_FILE_BROWSER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPluginClass)) +#define XED_TYPE_FILE_BROWSER_PLUGIN (xed_file_browser_plugin_get_type ()) +#define XED_FILE_BROWSER_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPlugin)) +#define XED_FILE_BROWSER_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPluginClass)) +#define XED_IS_FILE_BROWSER_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_FILE_BROWSER_PLUGIN)) +#define XED_IS_FILE_BROWSER_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_FILE_BROWSER_PLUGIN)) +#define XED_FILE_BROWSER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPluginClass)) /* Private structure type */ typedef struct _XedFileBrowserPluginPrivate XedFileBrowserPluginPrivate; typedef struct _XedFileBrowserPlugin XedFileBrowserPlugin; typedef struct _XedFileBrowserPluginClass XedFileBrowserPluginClass; -struct _XedFileBrowserPlugin +struct _XedFileBrowserPlugin { - XedPlugin parent_instance; + PeasExtensionBase parent_instance; - /*< private > */ - XedFileBrowserPluginPrivate *priv; + /*< private > */ + XedFileBrowserPluginPrivate *priv; }; -struct _XedFileBrowserPluginClass +struct _XedFileBrowserPluginClass { - XedPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* * Public methods */ -GType filetree_plugin_get_type (void) G_GNUC_CONST; +GType xed_file_browser_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_xed_plugin (GTypeModule * module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule * module); G_END_DECLS #endif /* __XED_FILE_BROWSER_PLUGIN_H__ */ diff --git a/plugins/filebrowser/xed-file-browser-store.c b/plugins/filebrowser/xed-file-browser-store.c index c29adc6..f8965ab 100644 --- a/plugins/filebrowser/xed-file-browser-store.c +++ b/plugins/filebrowser/xed-file-browser-store.c @@ -1,5 +1,5 @@ /* - * xed-file-browser-store.c - Xed plugin providing easy file access + * xed-file-browser-store.c - Xed plugin providing easy file access * from the sidepanel * * Copyright (C) 2006 - Jesse van den Kieboom @@ -26,7 +26,6 @@ #include #include #include -#include #include #include "xed-file-browser-store.h" @@ -88,7 +87,7 @@ typedef struct { GCancellable * cancellable; } MountInfo; -struct _FileBrowserNode +struct _FileBrowserNode { GFile *file; guint flags; @@ -102,7 +101,7 @@ struct _FileBrowserNode gboolean inserted; }; -struct _FileBrowserNodeDir +struct _FileBrowserNodeDir { FileBrowserNode node; GSList *children; @@ -113,7 +112,7 @@ struct _FileBrowserNodeDir XedFileBrowserStore *model; }; -struct _XedFileBrowserStorePrivate +struct _XedFileBrowserStorePrivate { FileBrowserNode *root; FileBrowserNode *virtual_root; @@ -133,7 +132,7 @@ static FileBrowserNode *model_find_node (XedFileBrowserStore *model, FileBrowserNode *node, GFile *uri); static void model_remove_node (XedFileBrowserStore * model, - FileBrowserNode * node, + FileBrowserNode * node, GtkTreePath * path, gboolean free_nodes); @@ -165,7 +164,7 @@ static gint xed_file_browser_store_iter_n_children (GtkTreeModel * tree_m GtkTreeIter * iter); static gboolean xed_file_browser_store_iter_nth_child (GtkTreeModel * tree_model, GtkTreeIter * iter, - GtkTreeIter * parent, + GtkTreeIter * parent, gint n); static gboolean xed_file_browser_store_iter_parent (GtkTreeModel * tree_model, GtkTreeIter * iter, @@ -197,13 +196,12 @@ static void model_check_dummy (XedFileBrowserStore static void next_files_async (GFileEnumerator * enumerator, AsyncNode * async); -XED_PLUGIN_DEFINE_TYPE_WITH_CODE (XedFileBrowserStore, xed_file_browser_store, +G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedFileBrowserStore, xed_file_browser_store, G_TYPE_OBJECT, - XED_PLUGIN_IMPLEMENT_INTERFACE (xed_file_browser_store_tree_model, - GTK_TYPE_TREE_MODEL, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (GTK_TYPE_TREE_MODEL, xed_file_browser_store_iface_init) - XED_PLUGIN_IMPLEMENT_INTERFACE (xed_file_browser_store_drag_source, - GTK_TYPE_TREE_DRAG_SOURCE, + G_IMPLEMENT_INTERFACE_DYNAMIC (GTK_TYPE_TREE_DRAG_SOURCE, xed_file_browser_store_drag_source_init)) /* Properties */ @@ -216,7 +214,7 @@ enum { }; /* Signals */ -enum +enum { BEGIN_LOADING, END_LOADING, @@ -256,10 +254,10 @@ xed_file_browser_store_finalize (GObject * object) { AsyncData *data = (AsyncData *) (item->data); g_cancellable_cancel (data->cancellable); - + data->removed = TRUE; } - + cancel_mount_operation (obj); g_slist_free (obj->priv->async_handles); @@ -295,7 +293,7 @@ xed_file_browser_store_get_property (GObject *object, break; case PROP_VIRTUAL_ROOT: set_gvalue_from_node (value, obj->priv->virtual_root); - break; + break; case PROP_FILTER_MODE: g_value_set_flags (value, obj->priv->filter_mode); break; @@ -393,7 +391,7 @@ xed_file_browser_store_class_init (XedFileBrowserStoreClass * klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (XedFileBrowserStoreClass, rename), NULL, NULL, - xed_file_browser_marshal_VOID__STRING_STRING, + xed_file_browser_marshal_VOID__STRING_STRING, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); @@ -427,6 +425,12 @@ xed_file_browser_store_class_init (XedFileBrowserStoreClass * klass) sizeof (XedFileBrowserStorePrivate)); } +static void +xed_file_browser_store_class_finalize (XedFileBrowserStoreClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + static void xed_file_browser_store_iface_init (GtkTreeModelIface * iface) { @@ -659,13 +663,13 @@ xed_file_browser_store_get_path (GtkTreeModel * tree_model, g_return_val_if_fail (iter != NULL, NULL); g_return_val_if_fail (iter->user_data != NULL, NULL); - return xed_file_browser_store_get_path_real (XED_FILE_BROWSER_STORE (tree_model), + return xed_file_browser_store_get_path_real (XED_FILE_BROWSER_STORE (tree_model), (FileBrowserNode *) (iter->user_data)); } static void xed_file_browser_store_get_value (GtkTreeModel * tree_model, - GtkTreeIter * iter, + GtkTreeIter * iter, gint column, GValue * value) { @@ -774,7 +778,7 @@ filter_tree_model_iter_has_child_real (XedFileBrowserStore * model, FileBrowserNode * node) { GSList *item; - + if (!NODE_IS_DIR (node)) return FALSE; @@ -910,7 +914,7 @@ xed_file_browser_store_row_inserted (GtkTreeModel * tree_model, GtkTreeIter * iter) { FileBrowserNode * node = (FileBrowserNode *)(iter->user_data); - + node->inserted = TRUE; } @@ -1143,7 +1147,7 @@ row_changed (XedFileBrowserStore * model, signal may alter the path */ gtk_tree_model_row_changed (GTK_TREE_MODEL(model), *path, iter); gtk_tree_path_free (*path); - + *path = gtk_tree_row_reference_get_path (ref); gtk_tree_row_reference_free (ref); } @@ -1155,7 +1159,7 @@ row_inserted (XedFileBrowserStore * model, { /* This function creates a row reference for the path because it's uncertain what might change the actual model/view when we insert - a node, maybe another directory load is triggered for example. + a node, maybe another directory load is triggered for example. Because functions that use this function rely on the notion that the path remains pointed towards the inserted node, we use the reference to keep track. */ @@ -1164,7 +1168,7 @@ row_inserted (XedFileBrowserStore * model, gtk_tree_model_row_inserted (GTK_TREE_MODEL(model), copy, iter); gtk_tree_path_free (copy); - + if (ref) { gtk_tree_path_free (*path); @@ -1184,7 +1188,7 @@ row_deleted (XedFileBrowserStore * model, const GtkTreePath * path) { GtkTreePath *copy = gtk_tree_path_copy (path); - + /* Delete a copy of the actual path here because the row-deleted signal may alter the path */ gtk_tree_model_row_deleted (GTK_TREE_MODEL(model), copy); @@ -1255,7 +1259,7 @@ model_refilter_node (XedFileBrowserStore * model, gtk_tree_path_next (*path); } } - + model_check_dummy (model, node); if (tmppath) @@ -1373,7 +1377,7 @@ file_browser_node_free (XedFileBrowserStore * model, if (dir->hidden_file_hash) g_hash_table_destroy (dir->hidden_file_hash); } - + if (node->file) { uri = g_file_get_uri (node->file); @@ -1390,7 +1394,7 @@ file_browser_node_free (XedFileBrowserStore * model, g_object_unref (node->emblem); g_free (node->name); - + if (NODE_IS_DIR (node)) g_slice_free (FileBrowserNodeDir, (FileBrowserNodeDir *)node); else @@ -1432,10 +1436,10 @@ model_remove_node_children (XedFileBrowserStore * model, // be freed if (free_nodes) file_browser_node_free_children (model, node); - + return; } - + if (path == NULL) path_child = xed_file_browser_store_get_path_real (model, node); @@ -1459,10 +1463,10 @@ model_remove_node_children (XedFileBrowserStore * model, * model_remove_node: * @model: the #XedFileBrowserStore * @node: the FileBrowserNode to remove - * @path: the path to use to remove this node, or NULL to use the path + * @path: the path to use to remove this node, or NULL to use the path * calculated from the node itself * @free_nodes: whether to also remove the nodes from memory - * + * * Removes this node and all its children from the model. This function is used * to remove the node from the _model_. Don't use it to just free * a node. @@ -1505,7 +1509,7 @@ model_remove_node (XedFileBrowserStore * model, (node->parent)->children, node); } - + /* If this is the virtual root, than set the parent as the virtual root */ if (node == model->priv->virtual_root) set_virtual_root_from_node (model, parent); @@ -1548,7 +1552,7 @@ model_clear (XedFileBrowserStore * model, gboolean free_nodes) if (NODE_IS_DUMMY (dummy) && model_node_visibility (model, dummy)) { path = gtk_tree_path_new_first (); - + dummy->inserted = FALSE; row_deleted (model, path); gtk_tree_path_free (path); @@ -1562,7 +1566,7 @@ file_browser_node_unload (XedFileBrowserStore * model, FileBrowserNode * node, gboolean remove_children) { FileBrowserNodeDir *dir; - + if (node == NULL) return; @@ -1585,7 +1589,7 @@ file_browser_node_unload (XedFileBrowserStore * model, if (dir->monitor) { g_file_monitor_cancel (dir->monitor); g_object_unref (dir->monitor); - + dir->monitor = NULL; } @@ -1734,7 +1738,7 @@ model_check_dummy (XedFileBrowserStore * model, FileBrowserNode * node) path = xed_file_browser_store_get_path_real (model, dummy); - + row_inserted (model, &path, &iter); gtk_tree_path_free (path); } @@ -1750,7 +1754,7 @@ model_check_dummy (XedFileBrowserStore * model, FileBrowserNode * node) (model, dummy); dummy->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; - + dummy->inserted = FALSE; row_deleted (model, path); gtk_tree_path_free (path); @@ -1892,15 +1896,15 @@ static gchar const * backup_content_type (GFileInfo * info) { gchar const * content; - + if (!g_file_info_get_is_backup (info)) return NULL; - + content = g_file_info_get_content_type (info); - + if (!content || g_content_type_equals (content, "application/x-trash")) return "text/plain"; - + return content; } @@ -1919,12 +1923,12 @@ file_browser_node_set_from_info (XedFileBrowserStore * model, GError * error = NULL; if (info == NULL) { - info = g_file_query_info (node->file, + info = g_file_query_info (node->file, STANDARD_ATTRIBUTE_TYPES, G_FILE_QUERY_INFO_NONE, NULL, &error); - + if (!info) { if (!(error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_FOUND)) { uri = g_file_get_uri (node->file); @@ -1935,7 +1939,7 @@ file_browser_node_set_from_info (XedFileBrowserStore * model, return; } - + free_info = TRUE; } @@ -1953,13 +1957,13 @@ file_browser_node_set_from_info (XedFileBrowserStore * model, else { if (!(content = backup_content_type (info))) content = g_file_info_get_content_type (info); - - if (!content || + + if (!content || g_content_type_is_unknown (content) || g_content_type_is_a (content, "text/plain")) - node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_TEXT; + node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_TEXT; } - + model_recomposite_icon_real (model, node, info); if (free_info) @@ -1969,7 +1973,7 @@ file_browser_node_set_from_info (XedFileBrowserStore * model, path = xed_file_browser_store_get_path_real (model, node); model_refilter_node (model, node, &path); gtk_tree_path_free (path); - + model_check_dummy (model, node->parent); } else { model_node_update_visibility (model, node); @@ -2013,11 +2017,11 @@ model_add_node_from_file (XedFileBrowserStore * model, &error); free_info = TRUE; } - + if (!info) { g_warning ("Error querying file info: %s", error->message); g_error_free (error); - + /* FIXME: What to do now then... */ node = file_browser_node_new (file, parent); } else if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { @@ -2028,7 +2032,7 @@ model_add_node_from_file (XedFileBrowserStore * model, file_browser_node_set_from_info (model, node, info, FALSE); model_add_node (model, node, parent); - + if (info && free_info) g_object_unref (info); } @@ -2063,7 +2067,7 @@ model_add_nodes_from_files (XedFileBrowserStore * model, type != G_FILE_TYPE_SYMBOLIC_LINK) { g_object_unref (info); continue; - } + } name = g_file_info_get_name (info); @@ -2105,7 +2109,7 @@ model_add_node_from_dir (XedFileBrowserStore * model, FileBrowserNode *node; /* Check if it already exists */ - if ((node = node_list_contains_file (FILE_BROWSER_NODE_DIR (parent)->children, file)) == NULL) { + if ((node = node_list_contains_file (FILE_BROWSER_NODE_DIR (parent)->children, file)) == NULL) { node = file_browser_node_dir_new (model, file, parent); file_browser_node_set_from_info (model, node, NULL, FALSE); @@ -2142,15 +2146,15 @@ parse_dot_hidden_file (FileBrowserNode *directory) if (directory->file == NULL || !g_file_is_native (directory->file)) { return; } - + child = g_file_get_child (directory->file, ".hidden"); info = g_file_query_info (child, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); type = info ? g_file_info_get_file_type (info) : G_FILE_TYPE_UNKNOWN; - + if (info) g_object_unref (info); - + if (type != G_FILE_TYPE_REGULAR) { g_object_unref (child); @@ -2168,7 +2172,7 @@ parse_dot_hidden_file (FileBrowserNode *directory) dir->hidden_file_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); } - + /* Now parse the data */ i = 0; while (i < file_size) { @@ -2181,14 +2185,14 @@ parse_dot_hidden_file (FileBrowserNode *directory) if (i > start) { char *hidden_filename; - + hidden_filename = g_strndup (file_contents + start, i - start); g_hash_table_insert (dir->hidden_file_hash, hidden_filename, hidden_filename); } i++; - + } g_free (file_contents); @@ -2216,7 +2220,7 @@ on_directory_monitor_event (GFileMonitor * monitor, if (g_file_query_exists (file, NULL)) { model_add_node_from_file (dir->model, parent, file, NULL); } - + break; default: break; @@ -2232,33 +2236,33 @@ async_node_free (AsyncNode *async) } static void -model_iterate_next_files_cb (GFileEnumerator * enumerator, - GAsyncResult * result, +model_iterate_next_files_cb (GFileEnumerator * enumerator, + GAsyncResult * result, AsyncNode * async) { GList * files; GError * error = NULL; FileBrowserNodeDir * dir = async->dir; FileBrowserNode * parent = (FileBrowserNode *)dir; - + files = g_file_enumerator_next_files_finish (enumerator, result, &error); if (files == NULL) { g_file_enumerator_close (enumerator, NULL, NULL); async_node_free (async); - + if (!error) { /* We're done loading */ g_object_unref (dir->cancellable); dir->cancellable = NULL; - + /* * FIXME: This is temporarly, it is a bug in gio: * http://bugzilla.gnome.org/show_bug.cgi?id=565924 */ if (g_file_is_native (parent->file) && dir->monitor == NULL) { - dir->monitor = g_file_monitor_directory (parent->file, + dir->monitor = g_file_monitor_directory (parent->file, G_FILE_MONITOR_NONE, NULL, NULL); @@ -2277,7 +2281,7 @@ model_iterate_next_files_cb (GFileEnumerator * enumerator, /* Simply return if we were cancelled */ if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED) return; - + /* Otherwise handle the error appropriately */ g_signal_emit (dir->model, model_signals[ERROR], @@ -2294,7 +2298,7 @@ model_iterate_next_files_cb (GFileEnumerator * enumerator, async_node_free (async); } else { model_add_nodes_from_files (dir->model, parent, async->original_children, files); - + g_list_free (files); next_files_async (enumerator, async); } @@ -2313,7 +2317,7 @@ next_files_async (GFileEnumerator * enumerator, } static void -model_iterate_children_cb (GFile * file, +model_iterate_children_cb (GFile * file, GAsyncResult * result, AsyncNode * async) { @@ -2325,13 +2329,13 @@ model_iterate_children_cb (GFile * file, async_node_free (async); return; } - + enumerator = g_file_enumerate_children_finish (file, result, &error); if (enumerator == NULL) { /* Simply return if we were cancelled or if the dir is not there */ FileBrowserNodeDir *dir = async->dir; - + /* Otherwise handle the error appropriately */ g_signal_emit (dir->model, model_signals[ERROR], @@ -2368,9 +2372,9 @@ model_load_directory (XedFileBrowserStore * model, /* Read the '.hidden' file first (if any) */ parse_dot_hidden_file (node); - + dir->cancellable = g_cancellable_new (); - + async = g_new (AsyncNode, 1); async->dir = dir; async->cancellable = g_object_ref (dir->cancellable); @@ -2390,7 +2394,7 @@ static GList * get_parent_files (XedFileBrowserStore * model, GFile * file) { GList * result = NULL; - + result = g_list_prepend (result, g_object_ref (file)); while ((file = g_file_get_parent (file))) { @@ -2436,7 +2440,7 @@ model_fill (XedFileBrowserStore * model, FileBrowserNode * node, if (node != model->priv->virtual_root) { /* Insert node */ iter.user_data = node; - + row_inserted(model, path, &iter); } @@ -2459,7 +2463,7 @@ model_fill (XedFileBrowserStore * model, FileBrowserNode * node, /* Move back up to node path */ gtk_tree_path_up (*path); } - + model_check_dummy (model, node); if (free_path) @@ -2520,8 +2524,8 @@ set_virtual_root_from_node (XedFileBrowserStore * model, for (item = FILE_BROWSER_NODE_DIR (node)->children; item; item = item->next) { check = (FileBrowserNode *) (item->data); - - if (NODE_IS_DIR (check)) { + + if (NODE_IS_DIR (check)) { for (copy = FILE_BROWSER_NODE_DIR (check)->children; copy; copy = copy->next) { @@ -2572,7 +2576,7 @@ set_virtual_root_from_file (XedFileBrowserStore * model, for (item = files; item; item = item->next) { check = G_FILE (item->data); - + parent = model_add_node_from_dir (model, parent, check); g_object_unref (check); } @@ -2590,21 +2594,21 @@ model_find_node_children (XedFileBrowserStore * model, FileBrowserNode *child; FileBrowserNode *result; GSList *children; - + if (!NODE_IS_DIR (parent)) return NULL; - + dir = FILE_BROWSER_NODE_DIR (parent); - + for (children = dir->children; children; children = children->next) { child = (FileBrowserNode *)(children->data); - + result = model_find_node (model, child, file); - + if (result) return result; } - + return NULL; } @@ -2621,7 +2625,7 @@ model_find_node (XedFileBrowserStore * model, if (NODE_IS_DIR (node) && g_file_has_prefix (file, node->file)) return model_find_node_children (model, node, file); - + return NULL; } @@ -2684,40 +2688,40 @@ handle_root_error (XedFileBrowserStore * model, GError *error) { FileBrowserNode * root; - g_signal_emit (model, - model_signals[ERROR], - 0, + g_signal_emit (model, + model_signals[ERROR], + 0, XED_FILE_BROWSER_ERROR_SET_ROOT, error->message); - + /* Set the virtual root to the root */ root = model->priv->root; model->priv->virtual_root = root; - + /* Set the root to be loaded */ root->flags |= XED_FILE_BROWSER_STORE_FLAG_LOADED; - + /* Check the dummy */ model_check_dummy (model, root); - + g_object_notify (G_OBJECT (model), "root"); g_object_notify (G_OBJECT (model), "virtual-root"); } static void -mount_cb (GFile * file, - GAsyncResult * res, +mount_cb (GFile * file, + GAsyncResult * res, MountInfo * mount_info) { gboolean mounted; GError * error = NULL; XedFileBrowserStore * model = mount_info->model; - + mounted = g_file_mount_enclosing_volume_finish (file, res, &error); if (mount_info->model) { - model->priv->mount_info = NULL; + model->priv->mount_info = NULL; model_end_loading (model, model->priv->root); } @@ -2734,7 +2738,7 @@ mount_cb (GFile * file, { handle_root_error (model, error); } - + if (error) g_error_free (error); @@ -2751,9 +2755,9 @@ model_mount_root (XedFileBrowserStore * model, gchar const * virtual_root) GFileInfo * info; GError * error = NULL; MountInfo * mount_info; - - info = g_file_query_info (model->priv->root->file, - G_FILE_ATTRIBUTE_STANDARD_TYPE, + + info = g_file_query_info (model->priv->root->file, + G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, &error); @@ -2762,23 +2766,23 @@ model_mount_root (XedFileBrowserStore * model, gchar const * virtual_root) if (error->code == G_IO_ERROR_NOT_MOUNTED) { /* Try to mount it */ FILE_BROWSER_NODE_DIR (model->priv->root)->cancellable = g_cancellable_new (); - + mount_info = g_new(MountInfo, 1); mount_info->model = model; mount_info->virtual_root = g_strdup (virtual_root); - + /* FIXME: we should be setting the correct window */ mount_info->operation = gtk_mount_operation_new (NULL); mount_info->cancellable = g_object_ref (FILE_BROWSER_NODE_DIR (model->priv->root)->cancellable); - + model_begin_loading (model, model->priv->root); - g_file_mount_enclosing_volume (model->priv->root->file, + g_file_mount_enclosing_volume (model->priv->root->file, G_MOUNT_MOUNT_NONE, mount_info->operation, mount_info->cancellable, (GAsyncReadyCallback)mount_cb, mount_info); - + model->priv->mount_info = mount_info; return XED_FILE_BROWSER_STORE_RESULT_MOUNTING; } @@ -2786,14 +2790,14 @@ model_mount_root (XedFileBrowserStore * model, gchar const * virtual_root) { handle_root_error (model, error); } - + g_error_free (error); } else { g_object_unref (info); - + return model_root_mounted (model, virtual_root); } - + return XED_FILE_BROWSER_STORE_RESULT_OK; } @@ -2844,7 +2848,7 @@ xed_file_browser_store_set_value (XedFileBrowserStore * tree_model, model_recomposite_icon (tree_model, iter); if (model_node_visibility (tree_model, node)) { - path = xed_file_browser_store_get_path (GTK_TREE_MODEL (tree_model), + path = xed_file_browser_store_get_path (GTK_TREE_MODEL (tree_model), iter); row_changed (tree_model, &path, iter); gtk_tree_path_free (path); @@ -3002,7 +3006,7 @@ void xed_file_browser_store_cancel_mount_operation (XedFileBrowserStore *store) { g_return_if_fail (XED_IS_FILE_BROWSER_STORE (store)); - + cancel_mount_operation (store); } @@ -3049,7 +3053,7 @@ xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore * g_object_unref (vfile); } - + /* make sure to cancel any previous mount operations */ cancel_mount_operation (model); @@ -3063,7 +3067,7 @@ xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore * if (file != NULL) { /* Create the root node */ node = file_browser_node_dir_new (model, file, NULL); - + g_object_unref (file); model->priv->root = node; @@ -3091,18 +3095,18 @@ gchar * xed_file_browser_store_get_root (XedFileBrowserStore * model) { g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), NULL); - + if (model->priv->root == NULL || model->priv->root->file == NULL) return NULL; else return g_file_get_uri (model->priv->root->file); } -gchar * +gchar * xed_file_browser_store_get_virtual_root (XedFileBrowserStore * model) { g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), NULL); - + if (model->priv->virtual_root == NULL || model->priv->virtual_root->file == NULL) return NULL; else @@ -3228,7 +3232,7 @@ reparent_node (FileBrowserNode * node, gboolean reparent) if (!node->file) { return; } - + if (reparent) { parent = node->parent->file; base = g_file_get_basename (node->file); @@ -3237,10 +3241,10 @@ reparent_node (FileBrowserNode * node, gboolean reparent) node->file = g_file_get_child (parent, base); g_free (base); } - + if (NODE_IS_DIR (node)) { dir = FILE_BROWSER_NODE_DIR (node); - + for (child = dir->children; child; child = child->next) { reparent_node ((FileBrowserNode *)child->data, TRUE); } @@ -3286,7 +3290,7 @@ xed_file_browser_store_rename (XedFileBrowserStore * model, /* This makes sure the actual info for the node is requeried */ file_browser_node_set_name (node); file_browser_node_set_from_info (model, node, NULL, TRUE); - + reparent_node (node, FALSE); if (model_node_visibility (model, node)) { @@ -3298,7 +3302,7 @@ xed_file_browser_store_rename (XedFileBrowserStore * model, model_resort_node (model, node); } else { g_object_unref (previous); - + if (error != NULL) *error = g_error_new_literal (xed_file_browser_store_error_quark (), XED_FILE_BROWSER_ERROR_RENAME, @@ -3327,7 +3331,7 @@ xed_file_browser_store_rename (XedFileBrowserStore * model, XED_FILE_BROWSER_ERROR_RENAME, err->message); } - + g_error_free (err); } @@ -3339,13 +3343,13 @@ static void async_data_free (AsyncData * data) { g_object_unref (data->cancellable); - + g_list_foreach (data->files, (GFunc)g_object_unref, NULL); g_list_free (data->files); - + if (!data->removed) data->model->priv->async_handles = g_slist_remove (data->model->priv->async_handles, data); - + g_free (data); } @@ -3372,7 +3376,7 @@ file_deleted (IdleDelete * data) if (node != NULL) model_remove_node (data->model, node, NULL, TRUE); - + return FALSE; } @@ -3386,14 +3390,14 @@ delete_files (GIOSchedulerJob * job, gboolean ret; gint code; IdleDelete delete; - + /* Check if our job is done */ if (!data->iter) return FALSE; - + /* Move a file to the trash */ file = G_FILE (data->iter->data); - + if (data->trash) ret = g_file_trash (file, cancellable, &error); else @@ -3419,7 +3423,7 @@ delete_files (GIOSchedulerJob * job, return TRUE; } - + /* End the job */ return FALSE; } else if (code == G_IO_ERROR_CANCELLED) { @@ -3427,7 +3431,7 @@ delete_files (GIOSchedulerJob * job, return FALSE; } } - + /* Process the next item */ data->iter = data->iter->next; return TRUE; @@ -3446,7 +3450,7 @@ xed_file_browser_store_delete_all (XedFileBrowserStore *model, GtkTreePath * path; g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); - + if (rows == NULL) return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; @@ -3460,17 +3464,17 @@ xed_file_browser_store_delete_all (XedFileBrowserStore *model, if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path)) continue; - + /* Skip if the current path is actually a descendant of the previous path */ if (prev != NULL && gtk_tree_path_is_descendant (path, prev)) continue; - + prev = path; node = (FileBrowserNode *)(iter.user_data); files = g_list_prepend (files, g_object_ref (node->file)); } - + data = g_new (AsyncData, 1); data->model = model; @@ -3479,17 +3483,17 @@ xed_file_browser_store_delete_all (XedFileBrowserStore *model, data->trash = trash; data->iter = files; data->removed = FALSE; - + model->priv->async_handles = g_slist_prepend (model->priv->async_handles, data); - g_io_scheduler_push_job ((GIOSchedulerJobFunc)delete_files, + g_io_scheduler_push_job ((GIOSchedulerJobFunc)delete_files, data, - (GDestroyNotify)async_data_free, - G_PRIORITY_DEFAULT, + (GDestroyNotify)async_data_free, + G_PRIORITY_DEFAULT, data->cancellable); g_list_free (rows); - + return XED_FILE_BROWSER_STORE_RESULT_OK; } @@ -3512,10 +3516,10 @@ xed_file_browser_store_delete (XedFileBrowserStore * model, rows = g_list_append(NULL, xed_file_browser_store_get_path_real (model, node)); result = xed_file_browser_store_delete_all (model, rows, trash); - + g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL); g_list_free (rows); - + return result; } @@ -3544,7 +3548,7 @@ xed_file_browser_store_new_file (XedFileBrowserStore * model, file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("file")); stream = g_file_create (file, G_FILE_CREATE_NONE, NULL, &error); - + if (!stream) { g_signal_emit (model, model_signals[ERROR], 0, @@ -3553,9 +3557,9 @@ xed_file_browser_store_new_file (XedFileBrowserStore * model, g_error_free (error); } else { g_object_unref (stream); - node = model_add_node_from_file (model, - (FileBrowserNode *)parent_node, - file, + node = model_add_node_from_file (model, + (FileBrowserNode *)parent_node, + file, NULL); if (model_node_visibility (model, node)) { @@ -3602,9 +3606,9 @@ xed_file_browser_store_new_directory (XedFileBrowserStore * model, error->message); g_error_free (error); } else { - node = model_add_node_from_file (model, - (FileBrowserNode *)parent_node, - file, + node = model_add_node_from_file (model, + (FileBrowserNode *)parent_node, + file, NULL); if (model_node_visibility (model, node)) { @@ -3622,4 +3626,10 @@ xed_file_browser_store_new_directory (XedFileBrowserStore * model, return result; } +void +_xed_file_browser_store_register_type (GTypeModule *type_module) +{ + xed_file_browser_store_register_type (type_module); +} + // ex:ts=8:noet: diff --git a/plugins/filebrowser/xed-file-browser-store.h b/plugins/filebrowser/xed-file-browser-store.h index 6185069..28c3e5c 100644 --- a/plugins/filebrowser/xed-file-browser-store.h +++ b/plugins/filebrowser/xed-file-browser-store.h @@ -1,5 +1,5 @@ /* - * xed-file-browser-store.h - Xed plugin providing easy file access + * xed-file-browser-store.h - Xed plugin providing easy file access * from the sidepanel * * Copyright (C) 2006 - Jesse van den Kieboom @@ -25,113 +25,113 @@ #include G_BEGIN_DECLS -#define XED_TYPE_FILE_BROWSER_STORE (xed_file_browser_store_get_type ()) -#define XED_FILE_BROWSER_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_STORE, XedFileBrowserStore)) -#define XED_FILE_BROWSER_STORE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_STORE, XedFileBrowserStore const)) -#define XED_FILE_BROWSER_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_FILE_BROWSER_STORE, XedFileBrowserStoreClass)) -#define XED_IS_FILE_BROWSER_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_FILE_BROWSER_STORE)) -#define XED_IS_FILE_BROWSER_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_BROWSER_STORE)) -#define XED_FILE_BROWSER_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_BROWSER_STORE, XedFileBrowserStoreClass)) +#define XED_TYPE_FILE_BROWSER_STORE (xed_file_browser_store_get_type ()) +#define XED_FILE_BROWSER_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_STORE, XedFileBrowserStore)) +#define XED_FILE_BROWSER_STORE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_STORE, XedFileBrowserStore const)) +#define XED_FILE_BROWSER_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_FILE_BROWSER_STORE, XedFileBrowserStoreClass)) +#define XED_IS_FILE_BROWSER_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_FILE_BROWSER_STORE)) +#define XED_IS_FILE_BROWSER_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_BROWSER_STORE)) +#define XED_FILE_BROWSER_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_BROWSER_STORE, XedFileBrowserStoreClass)) -typedef enum +typedef enum { - XED_FILE_BROWSER_STORE_COLUMN_ICON = 0, - XED_FILE_BROWSER_STORE_COLUMN_NAME, - XED_FILE_BROWSER_STORE_COLUMN_URI, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, - XED_FILE_BROWSER_STORE_COLUMN_EMBLEM, - XED_FILE_BROWSER_STORE_COLUMN_NUM + XED_FILE_BROWSER_STORE_COLUMN_ICON = 0, + XED_FILE_BROWSER_STORE_COLUMN_NAME, + XED_FILE_BROWSER_STORE_COLUMN_URI, + XED_FILE_BROWSER_STORE_COLUMN_FLAGS, + XED_FILE_BROWSER_STORE_COLUMN_EMBLEM, + XED_FILE_BROWSER_STORE_COLUMN_NUM } XedFileBrowserStoreColumn; -typedef enum +typedef enum { - XED_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY = 1 << 0, - XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN = 1 << 1, - XED_FILE_BROWSER_STORE_FLAG_IS_TEXT = 1 << 2, - XED_FILE_BROWSER_STORE_FLAG_LOADED = 1 << 3, - XED_FILE_BROWSER_STORE_FLAG_IS_FILTERED = 1 << 4, - XED_FILE_BROWSER_STORE_FLAG_IS_DUMMY = 1 << 5 + XED_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY = 1 << 0, + XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN = 1 << 1, + XED_FILE_BROWSER_STORE_FLAG_IS_TEXT = 1 << 2, + XED_FILE_BROWSER_STORE_FLAG_LOADED = 1 << 3, + XED_FILE_BROWSER_STORE_FLAG_IS_FILTERED = 1 << 4, + XED_FILE_BROWSER_STORE_FLAG_IS_DUMMY = 1 << 5 } XedFileBrowserStoreFlag; -typedef enum +typedef enum { - XED_FILE_BROWSER_STORE_RESULT_OK, - XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE, - XED_FILE_BROWSER_STORE_RESULT_ERROR, - XED_FILE_BROWSER_STORE_RESULT_NO_TRASH, - XED_FILE_BROWSER_STORE_RESULT_MOUNTING, - XED_FILE_BROWSER_STORE_RESULT_NUM + XED_FILE_BROWSER_STORE_RESULT_OK, + XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE, + XED_FILE_BROWSER_STORE_RESULT_ERROR, + XED_FILE_BROWSER_STORE_RESULT_NO_TRASH, + XED_FILE_BROWSER_STORE_RESULT_MOUNTING, + XED_FILE_BROWSER_STORE_RESULT_NUM } XedFileBrowserStoreResult; -typedef enum +typedef enum { - XED_FILE_BROWSER_STORE_FILTER_MODE_NONE = 0, - XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN = 1 << 0, - XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY = 1 << 1 + XED_FILE_BROWSER_STORE_FILTER_MODE_NONE = 0, + XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN = 1 << 0, + XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY = 1 << 1 } XedFileBrowserStoreFilterMode; -#define FILE_IS_DIR(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY) -#define FILE_IS_HIDDEN(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN) -#define FILE_IS_TEXT(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_TEXT) -#define FILE_LOADED(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_LOADED) -#define FILE_IS_FILTERED(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_FILTERED) -#define FILE_IS_DUMMY(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_DUMMY) +#define FILE_IS_DIR(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY) +#define FILE_IS_HIDDEN(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN) +#define FILE_IS_TEXT(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_TEXT) +#define FILE_LOADED(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_LOADED) +#define FILE_IS_FILTERED(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_FILTERED) +#define FILE_IS_DUMMY(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_DUMMY) typedef struct _XedFileBrowserStore XedFileBrowserStore; typedef struct _XedFileBrowserStoreClass XedFileBrowserStoreClass; typedef struct _XedFileBrowserStorePrivate XedFileBrowserStorePrivate; typedef gboolean (*XedFileBrowserStoreFilterFunc) (XedFileBrowserStore - * model, - GtkTreeIter * iter, - gpointer user_data); + * model, + GtkTreeIter * iter, + gpointer user_data); -struct _XedFileBrowserStore +struct _XedFileBrowserStore { - GObject parent; + GObject parent; - XedFileBrowserStorePrivate *priv; + XedFileBrowserStorePrivate *priv; }; struct _XedFileBrowserStoreClass { - GObjectClass parent_class; + GObjectClass parent_class; - /* Signals */ - void (*begin_loading) (XedFileBrowserStore * model, - GtkTreeIter * iter); - void (*end_loading) (XedFileBrowserStore * model, - GtkTreeIter * iter); - void (*error) (XedFileBrowserStore * model, - guint code, - gchar * message); - gboolean (*no_trash) (XedFileBrowserStore * model, - GList * files); - void (*rename) (XedFileBrowserStore * model, - const gchar * olduri, - const gchar * newuri); - void (*begin_refresh) (XedFileBrowserStore * model); - void (*end_refresh) (XedFileBrowserStore * model); - void (*unload) (XedFileBrowserStore * model, - const gchar * uri); + /* Signals */ + void (*begin_loading) (XedFileBrowserStore * model, + GtkTreeIter * iter); + void (*end_loading) (XedFileBrowserStore * model, + GtkTreeIter * iter); + void (*error) (XedFileBrowserStore * model, + guint code, + gchar * message); + gboolean (*no_trash) (XedFileBrowserStore * model, + GList * files); + void (*rename) (XedFileBrowserStore * model, + const gchar * olduri, + const gchar * newuri); + void (*begin_refresh) (XedFileBrowserStore * model); + void (*end_refresh) (XedFileBrowserStore * model); + void (*unload) (XedFileBrowserStore * model, + const gchar * uri); }; GType xed_file_browser_store_get_type (void) G_GNUC_CONST; -GType xed_file_browser_store_register_type (GTypeModule * module); +void _xed_file_browser_store_register_type (GTypeModule * module); XedFileBrowserStore *xed_file_browser_store_new (gchar const *root); XedFileBrowserStoreResult xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore * model, - gchar const *root, - gchar const *virtual_root); + gchar const *root, + gchar const *virtual_root); XedFileBrowserStoreResult xed_file_browser_store_set_root (XedFileBrowserStore * model, - gchar const *root); + gchar const *root); XedFileBrowserStoreResult xed_file_browser_store_set_virtual_root (XedFileBrowserStore * model, - GtkTreeIter * iter); + GtkTreeIter * iter); XedFileBrowserStoreResult -xed_file_browser_store_set_virtual_root_from_string (XedFileBrowserStore * model, +xed_file_browser_store_set_virtual_root_from_string (XedFileBrowserStore * model, gchar const *root); XedFileBrowserStoreResult xed_file_browser_store_set_virtual_root_up (XedFileBrowserStore * model); @@ -139,25 +139,25 @@ XedFileBrowserStoreResult xed_file_browser_store_set_virtual_root_top (XedFileBrowserStore * model); gboolean -xed_file_browser_store_get_iter_virtual_root (XedFileBrowserStore * model, +xed_file_browser_store_get_iter_virtual_root (XedFileBrowserStore * model, GtkTreeIter * iter); gboolean xed_file_browser_store_get_iter_root (XedFileBrowserStore * model, - GtkTreeIter * iter); + GtkTreeIter * iter); gchar * xed_file_browser_store_get_root (XedFileBrowserStore * model); gchar * xed_file_browser_store_get_virtual_root (XedFileBrowserStore * model); -gboolean xed_file_browser_store_iter_equal (XedFileBrowserStore * model, +gboolean xed_file_browser_store_iter_equal (XedFileBrowserStore * model, GtkTreeIter * iter1, - GtkTreeIter * iter2); + GtkTreeIter * iter2); -void xed_file_browser_store_set_value (XedFileBrowserStore * tree_model, +void xed_file_browser_store_set_value (XedFileBrowserStore * tree_model, GtkTreeIter * iter, - gint column, + gint column, GValue * value); -void _xed_file_browser_store_iter_expanded (XedFileBrowserStore * model, +void _xed_file_browser_store_iter_expanded (XedFileBrowserStore * model, GtkTreeIter * iter); -void _xed_file_browser_store_iter_collapsed (XedFileBrowserStore * model, +void _xed_file_browser_store_iter_collapsed (XedFileBrowserStore * model, GtkTreeIter * iter); XedFileBrowserStoreFilterMode @@ -165,7 +165,7 @@ xed_file_browser_store_get_filter_mode (XedFileBrowserStore * model void xed_file_browser_store_set_filter_mode (XedFileBrowserStore * model, XedFileBrowserStoreFilterMode mode); void xed_file_browser_store_set_filter_func (XedFileBrowserStore * model, - XedFileBrowserStoreFilterFunc func, + XedFileBrowserStoreFilterFunc func, gpointer user_data); void xed_file_browser_store_refilter (XedFileBrowserStore * model); XedFileBrowserStoreFilterMode @@ -178,11 +178,11 @@ gboolean xed_file_browser_store_rename (XedFileBrowserStore * model GError ** error); XedFileBrowserStoreResult xed_file_browser_store_delete (XedFileBrowserStore * model, - GtkTreeIter * iter, + GtkTreeIter * iter, gboolean trash); XedFileBrowserStoreResult xed_file_browser_store_delete_all (XedFileBrowserStore * model, - GList *rows, + GList *rows, gboolean trash); gboolean xed_file_browser_store_new_file (XedFileBrowserStore * model, @@ -195,6 +195,6 @@ gboolean xed_file_browser_store_new_directory (XedFileBrowserStore * model void xed_file_browser_store_cancel_mount_operation (XedFileBrowserStore *store); G_END_DECLS -#endif /* __XED_FILE_BROWSER_STORE_H__ */ +#endif /* __XED_FILE_BROWSER_STORE_H__ */ // ex:ts=8:noet: diff --git a/plugins/filebrowser/xed-file-browser-view.c b/plugins/filebrowser/xed-file-browser-view.c index 5e26bac..80f3798 100644 --- a/plugins/filebrowser/xed-file-browser-view.c +++ b/plugins/filebrowser/xed-file-browser-view.c @@ -1,5 +1,5 @@ /* - * xed-file-browser-view.c - Xed plugin providing easy file access + * xed-file-browser-view.c - Xed plugin providing easy file access * from the sidepanel * * Copyright (C) 2006 - Jesse van den Kieboom @@ -21,7 +21,6 @@ #include #include -#include #include #include @@ -35,7 +34,7 @@ G_TYPE_INSTANCE_GET_PRIVATE((object), \ XED_TYPE_FILE_BROWSER_VIEW, XedFileBrowserViewPrivate)) -struct _XedFileBrowserViewPrivate +struct _XedFileBrowserViewPrivate { GtkTreeViewColumn *column; GtkCellRenderer *pixbuf_renderer; @@ -55,7 +54,7 @@ struct _XedFileBrowserViewPrivate gboolean selected_on_button_down; gint drag_button; gboolean drag_started; - + gboolean restore_expand_state; gboolean is_refresh; GHashTable * expand_state; @@ -65,7 +64,7 @@ struct _XedFileBrowserViewPrivate enum { PROP_0, - + PROP_CLICK_POLICY, PROP_RESTORE_EXPAND_STATE }; @@ -86,33 +85,33 @@ static const GtkTargetEntry drag_source_targets[] = { { "text/uri-list", 0, 0 } }; -XED_PLUGIN_DEFINE_TYPE (XedFileBrowserView, xed_file_browser_view, +G_DEFINE_DYNAMIC_TYPE (XedFileBrowserView, xed_file_browser_view, GTK_TYPE_TREE_VIEW) -static void on_cell_edited (GtkCellRendererText * cell, +static void on_cell_edited (GtkCellRendererText * cell, gchar * path, gchar * new_text, XedFileBrowserView * tree_view); -static void on_begin_refresh (XedFileBrowserStore * model, +static void on_begin_refresh (XedFileBrowserStore * model, XedFileBrowserView * view); -static void on_end_refresh (XedFileBrowserStore * model, +static void on_end_refresh (XedFileBrowserStore * model, XedFileBrowserView * view); -static void on_unload (XedFileBrowserStore * model, +static void on_unload (XedFileBrowserStore * model, gchar const * uri, XedFileBrowserView * view); -static void on_row_inserted (XedFileBrowserStore * model, +static void on_row_inserted (XedFileBrowserStore * model, GtkTreePath * path, GtkTreeIter * iter, XedFileBrowserView * view); - + static void xed_file_browser_view_finalize (GObject * object) { XedFileBrowserView *obj = XED_FILE_BROWSER_VIEW(object); - + if (obj->priv->hand_cursor) g_object_unref (obj->priv->hand_cursor); @@ -136,12 +135,12 @@ add_expand_state (XedFileBrowserView * view, gchar const * uri) { GFile * file; - + if (!uri) return; file = g_file_new_for_uri (uri); - + if (view->priv->expand_state) g_hash_table_insert (view->priv->expand_state, file, file); else @@ -153,12 +152,12 @@ remove_expand_state (XedFileBrowserView * view, gchar const * uri) { GFile * file; - + if (!uri) return; file = g_file_new_for_uri (uri); - + if (view->priv->expand_state) g_hash_table_remove (view->priv->expand_state, file); @@ -182,7 +181,7 @@ row_expanded (GtkTreeView * tree_view, if (view->priv->restore_expand_state) { gtk_tree_model_get (view->priv->model, - iter, + iter, XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, -1); @@ -208,11 +207,11 @@ row_collapsed (GtkTreeView * tree_view, if (!XED_IS_FILE_BROWSER_STORE (view->priv->model)) return; - + if (view->priv->restore_expand_state) { - gtk_tree_model_get (view->priv->model, - iter, + gtk_tree_model_get (view->priv->model, + iter, XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, -1); @@ -291,7 +290,7 @@ motion_notify_event (GtkWidget * widget, if (old_hover_path != NULL) gtk_tree_path_free (old_hover_path); } - + // Chainup return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->motion_notify_event (widget, event); } @@ -323,7 +322,7 @@ set_click_policy_property (XedFileBrowserView *obj, if (gtk_widget_get_realized (GTK_WIDGET (obj))) { win = gtk_widget_get_window (GTK_WIDGET (obj)); gdk_window_set_cursor (win, NULL); - + display = gtk_widget_get_display (GTK_WIDGET (obj)); if (display != NULL) @@ -338,7 +337,7 @@ set_click_policy_property (XedFileBrowserView *obj, } static void -directory_activated (XedFileBrowserView *view, +directory_activated (XedFileBrowserView *view, GtkTreeIter *iter) { xed_file_browser_store_set_virtual_root (XED_FILE_BROWSER_STORE (view->priv->model), iter); @@ -355,30 +354,30 @@ activate_selected_files (XedFileBrowserView *view) { XedFileBrowserStoreFlag flags; rows = gtk_tree_selection_get_selected_rows (selection, &view->priv->model); - + for (row = rows; row; row = row->next) { path = (GtkTreePath *)(row->data); - + /* Get iter from path */ if (!gtk_tree_model_get_iter (view->priv->model, &iter, path)) continue; - + gtk_tree_model_get (view->priv->model, &iter, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, -1); if (FILE_IS_DIR (flags)) { if (directory == NULL) directory = path; - + } else if (!FILE_IS_DUMMY (flags)) { g_signal_emit (view, signals[FILE_ACTIVATED], 0, &iter); } } - + if (directory != NULL) { if (gtk_tree_model_get_iter (view->priv->model, &iter, directory)) g_signal_emit (view, signals[DIRECTORY_ACTIVATED], 0, &iter); } - + g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL); g_list_free (rows); } @@ -428,10 +427,10 @@ drag_begin (GtkWidget *widget, GdkDragContext *context) { XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget); - + view->priv->drag_button = 0; view->priv->drag_started = TRUE; - + /* Chain up */ GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->drag_begin (widget, context); } @@ -443,14 +442,14 @@ did_not_drag (XedFileBrowserView *view, GtkTreeView *tree_view; GtkTreeSelection *selection; GtkTreePath *path; - + tree_view = GTK_TREE_VIEW (view); selection = gtk_tree_view_get_selection (tree_view); if (gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y, &path, NULL, NULL, NULL)) { if ((view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) - && !button_event_modifies_selection(event) + && !button_event_modifies_selection(event) && (event->button == 1 || event->button == 2)) { /* Activate all selected items, and leave them selected */ activate_selected_items (view); @@ -483,9 +482,9 @@ button_release_event (GtkWidget *widget, !view->priv->ignore_release) did_not_drag (view, event); } - + /* Chain up */ - return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->button_release_event (widget, event); + return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->button_release_event (widget, event); } static gboolean @@ -511,7 +510,7 @@ button_press_event (GtkWidget *widget, selection = gtk_tree_view_get_selection (tree_view); /* Get double click time */ - g_object_get (G_OBJECT (gtk_widget_get_settings (widget)), + g_object_get (G_OBJECT (gtk_widget_get_settings (widget)), "gtk-double-click-time", &double_click_time, NULL); @@ -520,11 +519,11 @@ button_press_event (GtkWidget *widget, click_count++; else click_count = 0; - + last_click_time = event->time; /* Ignore double click if we are in single click mode */ - if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE && + if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE && click_count >= 2) { return TRUE; } @@ -536,7 +535,7 @@ button_press_event (GtkWidget *widget, &path, NULL, NULL, NULL)) { /* Keep track of path of last click so double clicks only happen * on the same item */ - if ((event->button == 1 || event->button == 2) && + if ((event->button == 1 || event->button == 2) && event->type == GDK_BUTTON_PRESS) { if (view->priv->double_click_path[1]) gtk_tree_path_free (view->priv->double_click_path[1]); @@ -549,7 +548,7 @@ button_press_event (GtkWidget *widget, if (view->priv->double_click_path[1] && gtk_tree_path_compare (view->priv->double_click_path[0], view->priv->double_click_path[1]) == 0) activate_selected_items (view); - + /* Chain up */ widget_parent->button_press_event (widget, event); } else { @@ -585,14 +584,14 @@ button_press_event (GtkWidget *widget, view->priv->ignore_release = on_expander; } } - + if (call_parent) { /* Chain up */ widget_parent->button_press_event (widget, event); } else if (selected) { gtk_widget_grab_focus (widget); } - + if ((event->button == 1 || event->button == 2) && event->type == GDK_BUTTON_PRESS) { view->priv->drag_started = FALSE; @@ -602,7 +601,7 @@ button_press_event (GtkWidget *widget, gtk_tree_path_free (path); } else { - if ((event->button == 1 || event->button == 2) && + if ((event->button == 1 || event->button == 2) && event->type == GDK_BUTTON_PRESS) { if (view->priv->double_click_path[1]) gtk_tree_path_free (view->priv->double_click_path[1]); @@ -668,7 +667,7 @@ key_press_event (GtkWidget *widget, /* Chain up */ if (!handled) return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->key_press_event (widget, event); - + return TRUE; } @@ -678,31 +677,31 @@ fill_expand_state (XedFileBrowserView * view, GtkTreeIter * iter) GtkTreePath * path; GtkTreeIter child; gchar * uri; - + if (!gtk_tree_model_iter_has_child (view->priv->model, iter)) return; - + path = gtk_tree_model_get_path (view->priv->model, iter); - + if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (view), path)) { - gtk_tree_model_get (view->priv->model, - iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, - &uri, + gtk_tree_model_get (view->priv->model, + iter, + XED_FILE_BROWSER_STORE_COLUMN_URI, + &uri, -1); add_expand_state (view, uri); g_free (uri); } - + if (gtk_tree_model_iter_children (view->priv->model, &child, iter)) { do { fill_expand_state (view, &child); } while (gtk_tree_model_iter_next (view->priv->model, &child)); } - + gtk_tree_path_free (path); } @@ -710,20 +709,20 @@ static void uninstall_restore_signals (XedFileBrowserView * tree_view, GtkTreeModel * model) { - g_signal_handlers_disconnect_by_func (model, - on_begin_refresh, - tree_view); - - g_signal_handlers_disconnect_by_func (model, - on_end_refresh, - tree_view); - - g_signal_handlers_disconnect_by_func (model, - on_unload, + g_signal_handlers_disconnect_by_func (model, + on_begin_refresh, tree_view); - g_signal_handlers_disconnect_by_func (model, - on_row_inserted, + g_signal_handlers_disconnect_by_func (model, + on_end_refresh, + tree_view); + + g_signal_handlers_disconnect_by_func (model, + on_unload, + tree_view); + + g_signal_handlers_disconnect_by_func (model, + on_row_inserted, tree_view); } @@ -731,24 +730,24 @@ static void install_restore_signals (XedFileBrowserView * tree_view, GtkTreeModel * model) { - g_signal_connect (model, + g_signal_connect (model, "begin-refresh", - G_CALLBACK (on_begin_refresh), + G_CALLBACK (on_begin_refresh), tree_view); - g_signal_connect (model, + g_signal_connect (model, "end-refresh", - G_CALLBACK (on_end_refresh), + G_CALLBACK (on_end_refresh), tree_view); - g_signal_connect (model, + g_signal_connect (model, "unload", - G_CALLBACK (on_unload), + G_CALLBACK (on_unload), tree_view); - g_signal_connect_after (model, + g_signal_connect_after (model, "row-inserted", - G_CALLBACK (on_row_inserted), + G_CALLBACK (on_row_inserted), tree_view); } @@ -771,7 +770,7 @@ set_restore_expand_state (XedFileBrowserView * view, (GEqualFunc)g_file_equal, g_object_unref, NULL); - + if (view->priv->model && XED_IS_FILE_BROWSER_STORE (view->priv->model)) { fill_expand_state (view, NULL); @@ -837,11 +836,11 @@ xed_file_browser_view_class_init (XedFileBrowserViewClass * klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkTreeViewClass *tree_view_class = GTK_TREE_VIEW_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - + object_class->finalize = xed_file_browser_view_finalize; object_class->get_property = get_property; object_class->set_property = set_property; - + /* Event handlers */ widget_class->motion_notify_event = motion_notify_event; widget_class->enter_notify_event = enter_notify_event; @@ -854,7 +853,7 @@ xed_file_browser_view_class_init (XedFileBrowserViewClass * klass) /* Tree view handlers */ tree_view_class->row_expanded = row_expanded; tree_view_class->row_collapsed = row_collapsed; - + /* Default handlers */ klass->directory_activated = directory_activated; @@ -910,6 +909,12 @@ xed_file_browser_view_class_init (XedFileBrowserViewClass * klass) sizeof (XedFileBrowserViewPrivate)); } +static void +xed_file_browser_view_class_finalize (XedFileBrowserViewClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE */ +} + static void cell_data_cb (GtkTreeViewColumn * tree_column, GtkCellRenderer * cell, GtkTreeModel * tree_model, GtkTreeIter * iter, @@ -922,18 +927,18 @@ cell_data_cb (GtkTreeViewColumn * tree_column, GtkCellRenderer * cell, path = gtk_tree_model_get_path (tree_model, iter); if (obj->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) { - if (obj->priv->hover_path != NULL && + if (obj->priv->hover_path != NULL && gtk_tree_path_compare (path, obj->priv->hover_path) == 0) - underline = PANGO_UNDERLINE_SINGLE; + underline = PANGO_UNDERLINE_SINGLE; } if (XED_IS_FILE_BROWSER_STORE (tree_model)) { - if (obj->priv->editable != NULL && + if (obj->priv->editable != NULL && gtk_tree_row_reference_valid (obj->priv->editable)) { GtkTreePath *edpath = gtk_tree_row_reference_get_path (obj->priv->editable); - + editable = edpath && gtk_tree_path_compare (path, edpath) == 0; } } @@ -1018,7 +1023,7 @@ xed_file_browser_view_set_model (XedFileBrowserView * tree_view, selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); if (XED_IS_FILE_BOOKMARKS_STORE (model)) { - gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); + gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (tree_view), bookmarks_separator_func, @@ -1045,7 +1050,7 @@ xed_file_browser_view_set_model (XedFileBrowserView * tree_view, if (tree_view->priv->restore_expand_state) install_restore_signals (tree_view, model); - + } if (tree_view->priv->hover_path != NULL) { @@ -1055,7 +1060,7 @@ xed_file_browser_view_set_model (XedFileBrowserView * tree_view, if (XED_IS_FILE_BROWSER_STORE (tree_view->priv->model)) { if (tree_view->priv->restore_expand_state) - uninstall_restore_signals (tree_view, + uninstall_restore_signals (tree_view, tree_view->priv->model); } @@ -1088,18 +1093,18 @@ xed_file_browser_view_start_rename (XedFileBrowserView * tree_view, /* Start editing */ gtk_widget_grab_focus (GTK_WIDGET (tree_view)); - + if (gtk_tree_path_up (path)) gtk_tree_view_expand_to_path (GTK_TREE_VIEW (tree_view), path); - + gtk_tree_path_free (path); tree_view->priv->editable = rowref; gtk_tree_view_set_cursor (GTK_TREE_VIEW (tree_view), gtk_tree_row_reference_get_path (tree_view->priv->editable), tree_view->priv->column, TRUE); - + gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), gtk_tree_row_reference_get_path (tree_view->priv->editable), tree_view->priv->column, @@ -1111,9 +1116,9 @@ xed_file_browser_view_set_click_policy (XedFileBrowserView *tree_view, XedFileBrowserViewClickPolicy policy) { g_return_if_fail (XED_IS_FILE_BROWSER_VIEW (tree_view)); - + set_click_policy_property (tree_view, policy); - + g_object_notify (G_OBJECT (tree_view), "click-policy"); } @@ -1136,13 +1141,13 @@ on_cell_edited (GtkCellRendererText * cell, gchar * path, gchar * new_text, GtkTreeIter iter; gboolean ret; GError * error = NULL; - + gtk_tree_row_reference_free (tree_view->priv->editable); tree_view->priv->editable = NULL; if (new_text == NULL || *new_text == '\0') return; - + treepath = gtk_tree_path_new_from_string (path); ret = gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_view->priv->model), &iter, treepath); gtk_tree_path_free (treepath); @@ -1166,8 +1171,8 @@ on_cell_edited (GtkCellRendererText * cell, gchar * path, gchar * new_text, } } -static void -on_begin_refresh (XedFileBrowserStore * model, +static void +on_begin_refresh (XedFileBrowserStore * model, XedFileBrowserView * view) { /* Store the refresh state, so we can handle unloading of nodes while @@ -1175,8 +1180,8 @@ on_begin_refresh (XedFileBrowserStore * model, view->priv->is_refresh = TRUE; } -static void -on_end_refresh (XedFileBrowserStore * model, +static void +on_end_refresh (XedFileBrowserStore * model, XedFileBrowserView * view) { /* Store the refresh state, so we can handle unloading of nodes while @@ -1185,14 +1190,14 @@ on_end_refresh (XedFileBrowserStore * model, } static void -on_unload (XedFileBrowserStore * model, +on_unload (XedFileBrowserStore * model, gchar const * uri, XedFileBrowserView * view) { /* Don't remove the expand state if we are refreshing */ if (!view->priv->restore_expand_state || view->priv->is_refresh) return; - + remove_expand_state (view, uri); } @@ -1205,10 +1210,10 @@ restore_expand_state (XedFileBrowserView * view, GFile * file; GtkTreePath * path; - gtk_tree_model_get (GTK_TREE_MODEL (model), - iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, - &uri, + gtk_tree_model_get (GTK_TREE_MODEL (model), + iter, + XED_FILE_BROWSER_STORE_COLUMN_URI, + &uri, -1); if (!uri) @@ -1223,15 +1228,15 @@ restore_expand_state (XedFileBrowserView * view, path, FALSE); } - + gtk_tree_path_free (path); - g_object_unref (file); + g_object_unref (file); g_free (uri); } -static void -on_row_inserted (XedFileBrowserStore * model, +static void +on_row_inserted (XedFileBrowserStore * model, GtkTreePath * path, GtkTreeIter * iter, XedFileBrowserView * view) @@ -1253,5 +1258,11 @@ on_row_inserted (XedFileBrowserStore * model, gtk_tree_path_free (copy); } - + +void +_xed_file_browser_view_register_type (GTypeModule *type_module) +{ + xed_file_browser_view_register_type (type_module); +} + // ex:ts=8:noet: diff --git a/plugins/filebrowser/xed-file-browser-view.h b/plugins/filebrowser/xed-file-browser-view.h index 3806b16..353c6c4 100644 --- a/plugins/filebrowser/xed-file-browser-view.h +++ b/plugins/filebrowser/xed-file-browser-view.h @@ -1,5 +1,5 @@ /* - * xed-file-browser-view.h - Xed plugin providing easy file access + * xed-file-browser-view.h - Xed plugin providing easy file access * from the sidepanel * * Copyright (C) 2006 - Jesse van den Kieboom @@ -39,22 +39,22 @@ typedef struct _XedFileBrowserViewPrivate XedFileBrowserViewPrivate; typedef enum { XED_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE, - XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE + XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE } XedFileBrowserViewClickPolicy; -struct _XedFileBrowserView +struct _XedFileBrowserView { GtkTreeView parent; XedFileBrowserViewPrivate *priv; }; -struct _XedFileBrowserViewClass +struct _XedFileBrowserViewClass { GtkTreeViewClass parent_class; /* Signals */ - void (*error) (XedFileBrowserView * filetree, + void (*error) (XedFileBrowserView * filetree, guint code, gchar const *message); void (*file_activated) (XedFileBrowserView * filetree, @@ -66,12 +66,12 @@ struct _XedFileBrowserViewClass }; GType xed_file_browser_view_get_type (void) G_GNUC_CONST; -GType xed_file_browser_view_register_type (GTypeModule * module); +void _xed_file_browser_view_register_type (GTypeModule * module); GtkWidget *xed_file_browser_view_new (void); void xed_file_browser_view_set_model (XedFileBrowserView * tree_view, GtkTreeModel * model); -void xed_file_browser_view_start_rename (XedFileBrowserView * tree_view, +void xed_file_browser_view_start_rename (XedFileBrowserView * tree_view, GtkTreeIter * iter); void xed_file_browser_view_set_click_policy (XedFileBrowserView * tree_view, XedFileBrowserViewClickPolicy policy); diff --git a/plugins/filebrowser/xed-file-browser-widget.c b/plugins/filebrowser/xed-file-browser-widget.c index 4f39762..0d95c9c 100644 --- a/plugins/filebrowser/xed-file-browser-widget.c +++ b/plugins/filebrowser/xed-file-browser-widget.c @@ -32,7 +32,6 @@ #include #include -#include #include "xed-file-browser-utils.h" #include "xed-file-browser-error.h" @@ -236,7 +235,7 @@ static void on_action_filter_binary (GtkAction * action, static void on_action_bookmark_open (GtkAction * action, XedFileBrowserWidget * obj); -XED_PLUGIN_DEFINE_TYPE (XedFileBrowserWidget, xed_file_browser_widget, +G_DEFINE_DYNAMIC_TYPE (XedFileBrowserWidget, xed_file_browser_widget, GTK_TYPE_BOX) static void @@ -479,6 +478,12 @@ xed_file_browser_widget_class_init (XedFileBrowserWidgetClass * klass) sizeof (XedFileBrowserWidgetPrivate)); } +static void +xed_file_browser_widget_class_finalize (XedFileBrowserWidgetClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE */ +} + static void add_signal (XedFileBrowserWidget * obj, gpointer object, gulong id) { @@ -3146,4 +3151,10 @@ on_action_bookmark_open (GtkAction * action, XedFileBrowserWidget * obj) bookmark_open (obj, model, &iter); } +void +_xed_file_browser_widget_register_type (GTypeModule *type_module) +{ + xed_file_browser_widget_register_type (type_module); +} + // ex:ts=8:noet: diff --git a/plugins/filebrowser/xed-file-browser-widget.h b/plugins/filebrowser/xed-file-browser-widget.h index 486fbe4..65f7b49 100644 --- a/plugins/filebrowser/xed-file-browser-widget.h +++ b/plugins/filebrowser/xed-file-browser-widget.h @@ -1,5 +1,5 @@ /* - * xed-file-browser-widget.h - Xed plugin providing easy file access + * xed-file-browser-widget.h - Xed plugin providing easy file access * from the sidepanel * * Copyright (C) 2006 - Jesse van den Kieboom @@ -28,13 +28,13 @@ #include "xed-file-browser-view.h" G_BEGIN_DECLS -#define XED_TYPE_FILE_BROWSER_WIDGET (xed_file_browser_widget_get_type ()) -#define XED_FILE_BROWSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_WIDGET, XedFileBrowserWidget)) -#define XED_FILE_BROWSER_WIDGET_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_WIDGET, XedFileBrowserWidget const)) -#define XED_FILE_BROWSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_FILE_BROWSER_WIDGET, XedFileBrowserWidgetClass)) -#define XED_IS_FILE_BROWSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_FILE_BROWSER_WIDGET)) -#define XED_IS_FILE_BROWSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_BROWSER_WIDGET)) -#define XED_FILE_BROWSER_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_BROWSER_WIDGET, XedFileBrowserWidgetClass)) +#define XED_TYPE_FILE_BROWSER_WIDGET (xed_file_browser_widget_get_type ()) +#define XED_FILE_BROWSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_WIDGET, XedFileBrowserWidget)) +#define XED_FILE_BROWSER_WIDGET_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_WIDGET, XedFileBrowserWidget const)) +#define XED_FILE_BROWSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_FILE_BROWSER_WIDGET, XedFileBrowserWidgetClass)) +#define XED_IS_FILE_BROWSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_FILE_BROWSER_WIDGET)) +#define XED_IS_FILE_BROWSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_BROWSER_WIDGET)) +#define XED_FILE_BROWSER_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_BROWSER_WIDGET, XedFileBrowserWidgetClass)) typedef struct _XedFileBrowserWidget XedFileBrowserWidget; typedef struct _XedFileBrowserWidgetClass XedFileBrowserWidgetClass; @@ -42,36 +42,36 @@ typedef struct _XedFileBrowserWidgetPrivate XedFileBrowserWidgetPrivate; typedef gboolean (*XedFileBrowserWidgetFilterFunc) (XedFileBrowserWidget * obj, - XedFileBrowserStore * - model, GtkTreeIter * iter, - gpointer user_data); + XedFileBrowserStore * + model, GtkTreeIter * iter, + gpointer user_data); -struct _XedFileBrowserWidget +struct _XedFileBrowserWidget { - GtkBox parent; + GtkBox parent; - XedFileBrowserWidgetPrivate *priv; + XedFileBrowserWidgetPrivate *priv; }; -struct _XedFileBrowserWidgetClass +struct _XedFileBrowserWidgetClass { - GtkBoxClass parent_class; + GtkBoxClass parent_class; - /* Signals */ - void (*uri_activated) (XedFileBrowserWidget * widget, - gchar const *uri); - void (*error) (XedFileBrowserWidget * widget, - guint code, - gchar const *message); - gboolean (*confirm_delete) (XedFileBrowserWidget * widget, - XedFileBrowserStore * model, - GList *list); - gboolean (*confirm_no_trash) (XedFileBrowserWidget * widget, - GList *list); + /* Signals */ + void (*uri_activated) (XedFileBrowserWidget * widget, + gchar const *uri); + void (*error) (XedFileBrowserWidget * widget, + guint code, + gchar const *message); + gboolean (*confirm_delete) (XedFileBrowserWidget * widget, + XedFileBrowserStore * model, + GList *list); + gboolean (*confirm_no_trash) (XedFileBrowserWidget * widget, + GList *list); }; GType xed_file_browser_widget_get_type (void) G_GNUC_CONST; -GType xed_file_browser_widget_register_type (GTypeModule * module); +void _xed_file_browser_widget_register_type (GTypeModule * module); GtkWidget *xed_file_browser_widget_new (const gchar *data_dir); @@ -83,27 +83,27 @@ void xed_file_browser_widget_set_root (XedFileBrowserWidget * obj, gboolean virtual_root); void xed_file_browser_widget_set_root_and_virtual_root (XedFileBrowserWidget * obj, - gchar const *root, - gchar const *virtual_root); + gchar const *root, + gchar const *virtual_root); gboolean -xed_file_browser_widget_get_selected_directory (XedFileBrowserWidget * obj, +xed_file_browser_widget_get_selected_directory (XedFileBrowserWidget * obj, GtkTreeIter * iter); -XedFileBrowserStore * +XedFileBrowserStore * xed_file_browser_widget_get_browser_store (XedFileBrowserWidget * obj); -XedFileBookmarksStore * +XedFileBookmarksStore * xed_file_browser_widget_get_bookmarks_store (XedFileBrowserWidget * obj); XedFileBrowserView * xed_file_browser_widget_get_browser_view (XedFileBrowserWidget * obj); GtkWidget * xed_file_browser_widget_get_filter_entry (XedFileBrowserWidget * obj); -GtkUIManager * +GtkUIManager * xed_file_browser_widget_get_ui_manager (XedFileBrowserWidget * obj); gulong xed_file_browser_widget_add_filter (XedFileBrowserWidget * obj, - XedFileBrowserWidgetFilterFunc func, + XedFileBrowserWidgetFilterFunc func, gpointer user_data, GDestroyNotify notify); void xed_file_browser_widget_remove_filter (XedFileBrowserWidget * obj, @@ -111,9 +111,9 @@ void xed_file_browser_widget_remove_filter (XedFileBrowserWidget * obj, void xed_file_browser_widget_set_filter_pattern (XedFileBrowserWidget * obj, gchar const *pattern); -void xed_file_browser_widget_refresh (XedFileBrowserWidget * obj); -void xed_file_browser_widget_history_back (XedFileBrowserWidget * obj); -void xed_file_browser_widget_history_forward (XedFileBrowserWidget * obj); +void xed_file_browser_widget_refresh (XedFileBrowserWidget * obj); +void xed_file_browser_widget_history_back (XedFileBrowserWidget * obj); +void xed_file_browser_widget_history_forward (XedFileBrowserWidget * obj); G_END_DECLS #endif /* __XED_FILE_BROWSER_WIDGET_H__ */ From decfeff88864d605e5459f1877cfafd1bb47b903 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 13:29:33 -0800 Subject: [PATCH 031/132] modelines-plugin: Port to libpeas Adapted from: https://github.com/mate-desktop/pluma/commit/b43579beda637b155aab3bb4fa257f27cb88d75e --- plugins/modelines/xed-modeline-plugin.c | 198 +++++++++++++++++------- plugins/modelines/xed-modeline-plugin.h | 40 +++-- 2 files changed, 166 insertions(+), 72 deletions(-) diff --git a/plugins/modelines/xed-modeline-plugin.c b/plugins/modelines/xed-modeline-plugin.c index b8921bb..47f9d3c 100644 --- a/plugins/modelines/xed-modeline-plugin.c +++ b/plugins/modelines/xed-modeline-plugin.c @@ -1,14 +1,14 @@ /* * xed-modeline-plugin.c * Emacs, Kate and Vim-style modelines support for xed. - * + * * Copyright (C) 2005-2007 - Steve Frécinaux * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -18,27 +18,30 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ - + #ifdef HAVE_CONFIG_H # include #endif #include #include +#include #include "xed-modeline-plugin.h" #include "modeline-parser.h" +#include #include #include -#define WINDOW_DATA_KEY "XedModelinePluginWindowData" #define DOCUMENT_DATA_KEY "XedModelinePluginDocumentData" -typedef struct +struct _XedModelinePluginPrivate { + GtkWidget *window; + gulong tab_added_handler_id; gulong tab_removed_handler_id; -} WindowData; +}; typedef struct { @@ -46,18 +49,20 @@ typedef struct gulong document_saved_handler_id; } DocumentData; -static void xed_modeline_plugin_activate (XedPlugin *plugin, XedWindow *window); -static void xed_modeline_plugin_deactivate (XedPlugin *plugin, XedWindow *window); -static GObject *xed_modeline_plugin_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_param); -static void xed_modeline_plugin_finalize (GObject *object); - -XED_PLUGIN_REGISTER_TYPE(XedModelinePlugin, xed_modeline_plugin) - -static void -window_data_free (WindowData *wdata) +enum { - g_slice_free (WindowData, wdata); -} + PROP_0, + PROP_OBJECT +}; + +static void peas_activatable_iface_init (PeasActivatableInterface *iface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedModelinePlugin, + xed_modeline_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init)) static void document_data_free (DocumentData *ddata) @@ -66,43 +71,27 @@ document_data_free (DocumentData *ddata) } static void -xed_modeline_plugin_class_init (XedModelinePluginClass *klass) +xed_modeline_plugin_constructed (GObject *object) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - XedPluginClass *plugin_class = XED_PLUGIN_CLASS (klass); - - object_class->constructor = xed_modeline_plugin_constructor; - object_class->finalize = xed_modeline_plugin_finalize; - - plugin_class->activate = xed_modeline_plugin_activate; - plugin_class->deactivate = xed_modeline_plugin_deactivate; -} - -static GObject * -xed_modeline_plugin_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_param) -{ - GObject *object; gchar *data_dir; - object = G_OBJECT_CLASS (xed_modeline_plugin_parent_class)->constructor (type, - n_construct_properties, - construct_param); - - data_dir = xed_plugin_get_data_dir (XED_PLUGIN (object)); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (object)); modeline_parser_init (data_dir); g_free (data_dir); - return object; + G_OBJECT_CLASS (xed_modeline_plugin_parent_class)->constructed (object); } static void xed_modeline_plugin_init (XedModelinePlugin *plugin) { xed_debug_message (DEBUG_PLUGINS, "XedModelinePlugin initializing"); + + plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin, + XED_TYPE_MODELINE_PLUGIN, + XedModelinePluginPrivate); } static void @@ -115,6 +104,60 @@ xed_modeline_plugin_finalize (GObject *object) G_OBJECT_CLASS (xed_modeline_plugin_parent_class)->finalize (object); } +static void +xed_modeline_plugin_dispose (GObject *object) +{ + XedModelinePlugin *plugin = XED_MODELINE_PLUGIN (object); + + xed_debug_message (DEBUG_PLUGINS, "XedModelinePlugin disposing"); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + G_OBJECT_CLASS (xed_modeline_plugin_parent_class)->dispose (object); +} + +static void +xed_modeline_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + XedModelinePlugin *plugin = XED_MODELINE_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +xed_modeline_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + XedModelinePlugin *plugin = XED_MODELINE_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + static void on_document_loaded_or_saved (XedDocument *document, const GError *error, @@ -186,15 +229,18 @@ on_window_tab_removed (XedWindow *window, } static void -xed_modeline_plugin_activate (XedPlugin *plugin, - XedWindow *window) +xed_modeline_plugin_activate (PeasActivatable *activatable) { - WindowData *wdata; + XedModelinePluginPrivate *data; + XedWindow *window; GList *views; GList *l; xed_debug (DEBUG_PLUGINS); + data = XED_MODELINE_PLUGIN (activatable)->priv; + window = XED_WINDOW (data->window); + views = xed_window_get_views (window); for (l = views; l != NULL; l = l->next) { @@ -203,46 +249,78 @@ xed_modeline_plugin_activate (XedPlugin *plugin, } g_list_free (views); - wdata = g_slice_new (WindowData); - - wdata->tab_added_handler_id = + data->tab_added_handler_id = g_signal_connect (window, "tab-added", G_CALLBACK (on_window_tab_added), NULL); - wdata->tab_removed_handler_id = + data->tab_removed_handler_id = g_signal_connect (window, "tab-removed", G_CALLBACK (on_window_tab_removed), NULL); - - g_object_set_data_full (G_OBJECT (window), WINDOW_DATA_KEY, - wdata, (GDestroyNotify) window_data_free); } static void -xed_modeline_plugin_deactivate (XedPlugin *plugin, - XedWindow *window) +xed_modeline_plugin_deactivate (PeasActivatable *activatable) { - WindowData *wdata; + XedModelinePluginPrivate *data; + XedWindow *window; GList *views; GList *l; xed_debug (DEBUG_PLUGINS); - wdata = g_object_steal_data (G_OBJECT (window), WINDOW_DATA_KEY); + data = XED_MODELINE_PLUGIN (activatable)->priv; + window = XED_WINDOW (data->window); - g_signal_handler_disconnect (window, wdata->tab_added_handler_id); - g_signal_handler_disconnect (window, wdata->tab_removed_handler_id); - - window_data_free (wdata); + g_signal_handler_disconnect (window, data->tab_added_handler_id); + g_signal_handler_disconnect (window, data->tab_removed_handler_id); views = xed_window_get_views (window); for (l = views; l != NULL; l = l->next) { disconnect_handlers (XED_VIEW (l->data)); - + modeline_parser_deactivate (GTK_SOURCE_VIEW (l->data)); } - + g_list_free (views); } +static void +xed_modeline_plugin_class_init (XedModelinePluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructed = xed_modeline_plugin_constructed; + object_class->finalize = xed_modeline_plugin_finalize; + object_class->dispose = xed_modeline_plugin_dispose; + object_class->set_property = xed_modeline_plugin_set_property; + object_class->get_property = xed_modeline_plugin_get_property; + + g_object_class_override_property (object_class, PROP_OBJECT, "object"); + + g_type_class_add_private (klass, sizeof (XedModelinePluginPrivate)); +} + +static void +xed_modeline_plugin_class_finalize (XedModelinePluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = xed_modeline_plugin_activate; + iface->deactivate = xed_modeline_plugin_deactivate; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + xed_modeline_plugin_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + XED_TYPE_MODELINE_PLUGIN); +} diff --git a/plugins/modelines/xed-modeline-plugin.h b/plugins/modelines/xed-modeline-plugin.h index 726ce8a..59e8240 100644 --- a/plugins/modelines/xed-modeline-plugin.h +++ b/plugins/modelines/xed-modeline-plugin.h @@ -1,7 +1,7 @@ /* * xed-modeline-plugin.h * Emacs, Kate and Vim-style modelines support for xed. - * + * * Copyright (C) 2005-2007 - Steve Frécinaux * * This program is free software; you can redistribute it and/or modify @@ -24,24 +24,40 @@ #include #include -#include +#include +#include G_BEGIN_DECLS -#define XED_TYPE_MODELINE_PLUGIN (xed_modeline_plugin_get_type ()) -#define XED_MODELINE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_MODELINE_PLUGIN, XedModelinePlugin)) -#define XED_MODELINE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_MODELINE_PLUGIN, XedModelinePluginClass)) -#define XED_IS_MODELINE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_MODELINE_PLUGIN)) -#define XED_IS_MODELINE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_MODELINE_PLUGIN)) -#define XED_MODELINE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_MODELINE_PLUGIN, XedModelinePluginClass)) +#define XED_TYPE_MODELINE_PLUGIN (xed_modeline_plugin_get_type ()) +#define XED_MODELINE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_MODELINE_PLUGIN, XedModelinePlugin)) +#define XED_MODELINE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_MODELINE_PLUGIN, XedModelinePluginClass)) +#define XED_IS_MODELINE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_MODELINE_PLUGIN)) +#define XED_IS_MODELINE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_MODELINE_PLUGIN)) +#define XED_MODELINE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_MODELINE_PLUGIN, XedModelinePluginClass)) /* Private structure type */ -typedef XedPluginClass XedModelinePluginClass; -typedef XedPlugin XedModelinePlugin; +typedef struct _XedModelinePlugin XedModelinePlugin; +typedef struct _XedModelinePluginPrivate XedModelinePluginPrivate; -GType xed_modeline_plugin_get_type (void) G_GNUC_CONST; +struct _XedModelinePlugin +{ + PeasExtensionBase parent_instance; -G_MODULE_EXPORT GType register_xed_plugin (GTypeModule *module); + /*< private >*/ + XedModelinePluginPrivate *priv; +}; + +typedef struct _XedModelinePluginClass XedModelinePluginClass; + +struct _XedModelinePluginClass +{ + PeasExtensionBaseClass parent_class; +}; + +GType xed_modeline_plugin_get_type (void) G_GNUC_CONST; + +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS From 7e6b54b760f6f0b10874bddf549261091e506387 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 13:39:52 -0800 Subject: [PATCH 032/132] sort-plugin: Port to libpeas Adapted from: https://github.com/mate-desktop/pluma/commit/55dfd7836e390c45891b590e8f4bf720100ad063 --- plugins/sort/xed-sort-plugin.c | 219 +++++++++++++++++++++------------ plugins/sort/xed-sort-plugin.h | 34 ++--- 2 files changed, 156 insertions(+), 97 deletions(-) diff --git a/plugins/sort/xed-sort-plugin.c b/plugins/sort/xed-sort-plugin.c index b64bd98..1027f31 100644 --- a/plugins/sort/xed-sort-plugin.c +++ b/plugins/sort/xed-sort-plugin.c @@ -30,20 +30,31 @@ #include #include #include +#include +#include #include #include #include #define XED_SORT_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_SORT_PLUGIN, XedSortPluginPrivate)) -/* Key in case the plugin ever needs any settings. */ -#define SORT_BASE_KEY "/apps/xed/plugins/sort" - -#define WINDOW_DATA_KEY "XedSortPluginWindowData" #define MENU_PATH "/MenuBar/EditMenu/EditOps_6" -XED_PLUGIN_REGISTER_TYPE(XedSortPlugin, xed_sort_plugin) +static void peas_activatable_iface_init (PeasActivatableInterface *iface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedSortPlugin, + xed_sort_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init)) + +enum +{ + PROP_0, + PROP_OBJECT +}; typedef struct { @@ -58,17 +69,13 @@ typedef struct GtkTextIter start, end; /* selection */ } SortDialog; -typedef struct +struct _XedSortPluginPrivate { + GtkWidget *window; + GtkActionGroup *ui_action_group; guint ui_id; -} WindowData; - -typedef struct -{ - XedPlugin *plugin; - XedWindow *window; -} ActionData; +}; typedef struct { @@ -78,7 +85,7 @@ typedef struct gint starting_column; } SortInfo; -static void sort_cb (GtkAction *action, ActionData *action_data); +static void sort_cb (GtkAction *action, XedSortPlugin *plugin); static void sort_real (SortDialog *dialog); static const GtkActionEntry action_entries[] = @@ -92,7 +99,7 @@ static const GtkActionEntry action_entries[] = }; static void -sort_dialog_dispose (GObject *obj, +sort_dialog_destroy (GObject *obj, gpointer dialog_pointer) { xed_debug (DEBUG_PLUGINS); @@ -150,8 +157,9 @@ get_current_selection (XedWindow *window, SortDialog *dialog) } static SortDialog * -get_sort_dialog (ActionData *action_data) +get_sort_dialog (XedSortPlugin *plugin) { + XedWindow *window; SortDialog *dialog; GtkWidget *error_widget; gboolean ret; @@ -160,9 +168,11 @@ get_sort_dialog (ActionData *action_data) xed_debug (DEBUG_PLUGINS); + window = XED_WINDOW (plugin->priv->window); + dialog = g_slice_new (SortDialog); - data_dir = xed_plugin_get_data_dir (action_data->plugin); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); ui_file = g_build_filename (data_dir, "sort.ui", NULL); g_free (data_dir); ret = xed_utils_get_ui_objects (ui_file, @@ -181,7 +191,7 @@ get_sort_dialog (ActionData *action_data) const gchar *err_message; err_message = gtk_label_get_label (GTK_LABEL (error_widget)); - xed_warning (GTK_WINDOW (action_data->window), + xed_warning (GTK_WINDOW (window), "%s", err_message); g_slice_free (SortDialog, dialog); @@ -194,8 +204,8 @@ get_sort_dialog (ActionData *action_data) GTK_RESPONSE_OK); g_signal_connect (dialog->dialog, - "dispose", - G_CALLBACK (sort_dialog_dispose), + "destroy", + G_CALLBACK (sort_dialog_destroy), dialog); g_signal_connect (dialog->dialog, @@ -203,35 +213,38 @@ get_sort_dialog (ActionData *action_data) G_CALLBACK (sort_dialog_response_handler), dialog); - get_current_selection (action_data->window, dialog); + get_current_selection (window, dialog); return dialog; } static void sort_cb (GtkAction *action, - ActionData *action_data) + XedSortPlugin *plugin) { + XedWindow *window; XedDocument *doc; GtkWindowGroup *wg; SortDialog *dialog; xed_debug (DEBUG_PLUGINS); - doc = xed_window_get_active_document (action_data->window); + window = XED_WINDOW (plugin->priv->window); + + doc = xed_window_get_active_document (window); g_return_if_fail (doc != NULL); - dialog = get_sort_dialog (action_data); + dialog = get_sort_dialog (plugin); g_return_if_fail (dialog != NULL); - wg = xed_window_get_group (action_data->window); + wg = xed_window_get_group (window); gtk_window_group_add_window (wg, GTK_WINDOW (dialog->dialog)); dialog->doc = doc; gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), - GTK_WINDOW (action_data->window)); + GTK_WINDOW (window)); gtk_window_set_modal (GTK_WINDOW (dialog->dialog), TRUE); @@ -439,30 +452,52 @@ sort_real (SortDialog *dialog) } static void -free_window_data (WindowData *data) +xed_sort_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - g_return_if_fail (data != NULL); + XedSortPlugin *plugin = XED_SORT_PLUGIN (object); - g_object_unref (data->ui_action_group); - g_slice_free (WindowData, data); + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -free_action_data (ActionData *data) +xed_sort_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { - g_return_if_fail (data != NULL); + XedSortPlugin *plugin = XED_SORT_PLUGIN (object); - g_slice_free (ActionData, data); + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -update_ui_real (XedWindow *window, - WindowData *data) +update_ui (XedSortPluginPrivate *data) { + XedWindow *window; XedView *view; xed_debug (DEBUG_PLUGINS); + window = XED_WINDOW (data->window); view = xed_window_get_active_view (window); gtk_action_group_set_sensitive (data->ui_action_group, @@ -471,30 +506,28 @@ update_ui_real (XedWindow *window, } static void -impl_activate (XedPlugin *plugin, - XedWindow *window) +xed_sort_plugin_activate (PeasActivatable *activatable) { + XedSortPlugin *plugin; + XedSortPluginPrivate *data; + XedWindow *window; GtkUIManager *manager; - WindowData *data; - ActionData *action_data; xed_debug (DEBUG_PLUGINS); - data = g_slice_new (WindowData); - action_data = g_slice_new (ActionData); - action_data->window = window; - action_data->plugin = plugin; + plugin = XED_SORT_PLUGIN (activatable); + data = plugin->priv; + window = XED_WINDOW (data->window); manager = xed_window_get_ui_manager (window); data->ui_action_group = gtk_action_group_new ("XedSortPluginActions"); gtk_action_group_set_translation_domain (data->ui_action_group, GETTEXT_PACKAGE); - gtk_action_group_add_actions_full (data->ui_action_group, + gtk_action_group_add_actions (data->ui_action_group, action_entries, G_N_ELEMENTS (action_entries), - action_data, - (GDestroyNotify) free_action_data); + plugin); gtk_ui_manager_insert_action_group (manager, data->ui_action_group, @@ -502,11 +535,6 @@ impl_activate (XedPlugin *plugin, data->ui_id = gtk_ui_manager_new_merge_id (manager); - g_object_set_data_full (G_OBJECT (window), - WINDOW_DATA_KEY, - data, - (GDestroyNotify) free_window_data); - gtk_ui_manager_add_ui (manager, data->ui_id, MENU_PATH, @@ -515,74 +543,101 @@ impl_activate (XedPlugin *plugin, GTK_UI_MANAGER_MENUITEM, FALSE); - update_ui_real (window, - data); + update_ui (data); } static void -impl_deactivate (XedPlugin *plugin, - XedWindow *window) +xed_sort_plugin_deactivate (PeasActivatable *activatable) { + XedSortPluginPrivate *data; + XedWindow *window; GtkUIManager *manager; - WindowData *data; xed_debug (DEBUG_PLUGINS); - manager = xed_window_get_ui_manager (window); + data = XED_SORT_PLUGIN (activatable)->priv; + window = XED_WINDOW (data->window); - data = (WindowData *) g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); + manager = xed_window_get_ui_manager (window); gtk_ui_manager_remove_ui (manager, data->ui_id); gtk_ui_manager_remove_action_group (manager, data->ui_action_group); - - g_object_set_data (G_OBJECT (window), - WINDOW_DATA_KEY, - NULL); } static void -impl_update_ui (XedPlugin *plugin, - XedWindow *window) +xed_sort_plugin_update_state (PeasActivatable *activatable) { - WindowData *data; - xed_debug (DEBUG_PLUGINS); - data = (WindowData *) g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - - update_ui_real (window, - data); + update_ui (XED_SORT_PLUGIN (activatable)->priv); } static void xed_sort_plugin_init (XedSortPlugin *plugin) { xed_debug_message (DEBUG_PLUGINS, "XedSortPlugin initializing"); + + plugin->priv = XED_SORT_PLUGIN_GET_PRIVATE (plugin); } static void -xed_sort_plugin_finalize (GObject *object) +xed_sort_plugin_dispose (GObject *object) { - xed_debug_message (DEBUG_PLUGINS, "XedSortPlugin finalizing"); + XedSortPlugin *plugin = XED_SORT_PLUGIN (object); - G_OBJECT_CLASS (xed_sort_plugin_parent_class)->finalize (object); + xed_debug_message (DEBUG_PLUGINS, "XedSortPlugin disposing"); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + if (plugin->priv->ui_action_group) + { + g_object_unref (plugin->priv->ui_action_group); + plugin->priv->ui_action_group = NULL; + } + + G_OBJECT_CLASS (xed_sort_plugin_parent_class)->dispose (object); } static void xed_sort_plugin_class_init (XedSortPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - XedPluginClass *plugin_class = XED_PLUGIN_CLASS (klass); - object_class->finalize = xed_sort_plugin_finalize; + object_class->dispose = xed_sort_plugin_dispose; + object_class->set_property = xed_sort_plugin_set_property; + object_class->get_property = xed_sort_plugin_get_property; - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_update_ui; + g_object_class_override_property (object_class, PROP_OBJECT, "object"); + + g_type_class_add_private (klass, sizeof (XedSortPluginPrivate)); +} + +static void +xed_sort_plugin_class_finalize (XedSortPluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = xed_sort_plugin_activate; + iface->deactivate = xed_sort_plugin_deactivate; + iface->update_state = xed_sort_plugin_update_state; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + xed_sort_plugin_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + XED_TYPE_SORT_PLUGIN); } diff --git a/plugins/sort/xed-sort-plugin.h b/plugins/sort/xed-sort-plugin.h index d35c2c8..02b97ee 100644 --- a/plugins/sort/xed-sort-plugin.h +++ b/plugins/sort/xed-sort-plugin.h @@ -1,6 +1,6 @@ /* * xed-sort-plugin.h - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) @@ -23,50 +23,54 @@ #include #include -#include +#include +#include G_BEGIN_DECLS /* * Type checking and casting macros */ -#define XED_TYPE_SORT_PLUGIN (xed_sort_plugin_get_type ()) -#define XED_SORT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_SORT_PLUGIN, XedSortPlugin)) -#define XED_SORT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_SORT_PLUGIN, XedSortPluginClass)) -#define XED_IS_SORT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_SORT_PLUGIN)) -#define XED_IS_SORT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_SORT_PLUGIN)) -#define XED_SORT_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_SORT_PLUGIN, XedSortPluginClass)) +#define XED_TYPE_SORT_PLUGIN (xed_sort_plugin_get_type ()) +#define XED_SORT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_SORT_PLUGIN, XedSortPlugin)) +#define XED_SORT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_SORT_PLUGIN, XedSortPluginClass)) +#define XED_IS_SORT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_SORT_PLUGIN)) +#define XED_IS_SORT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_SORT_PLUGIN)) +#define XED_SORT_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_SORT_PLUGIN, XedSortPluginClass)) /* Private structure type */ -typedef struct _XedSortPluginPrivate XedSortPluginPrivate; +typedef struct _XedSortPluginPrivate XedSortPluginPrivate; /* * Main object structure */ -typedef struct _XedSortPlugin XedSortPlugin; +typedef struct _XedSortPlugin XedSortPlugin; struct _XedSortPlugin { - XedPlugin parent_instance; + PeasExtensionBase parent_instance; + + /*< private >*/ + XedSortPluginPrivate *priv; }; /* * Class definition */ -typedef struct _XedSortPluginClass XedSortPluginClass; +typedef struct _XedSortPluginClass XedSortPluginClass; struct _XedSortPluginClass { - XedPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* * Public methods */ -GType xed_sort_plugin_get_type (void) G_GNUC_CONST; +GType xed_sort_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_xed_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS From e389368a910e4663c5c0247cf3be15068d508310 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 13:44:07 -0800 Subject: [PATCH 033/132] spell-plugin: Port to libpeas Adapted from: https://github.com/mate-desktop/pluma/commit/67a0f36183ed2fe4dd66a044566e523b4b256fe4 --- plugins/spell/xed-spell-plugin.c | 520 +++++++++++++++---------------- plugins/spell/xed-spell-plugin.h | 35 ++- 2 files changed, 268 insertions(+), 287 deletions(-) diff --git a/plugins/spell/xed-spell-plugin.c b/plugins/spell/xed-spell-plugin.c index 32ac6eb..88e2114 100644 --- a/plugins/spell/xed-spell-plugin.c +++ b/plugins/spell/xed-spell-plugin.c @@ -1,13 +1,13 @@ /* * xed-spell-plugin.c - * - * Copyright (C) 2002-2005 Paolo Maggi + * + * Copyright (C) 2002-2005 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -31,9 +31,11 @@ #include #include +#include +#include +#include #include -#include #include #include #include @@ -46,7 +48,6 @@ #define XED_METADATA_ATTRIBUTE_SPELL_LANGUAGE "metadata::xed-spell-language" #define XED_METADATA_ATTRIBUTE_SPELL_ENABLED "metadata::xed-spell-enabled" -#define WINDOW_DATA_KEY "XedSpellPluginWindowData" #define MENU_PATH "/MenuBar/ToolsMenu/ToolsOps_1" #define XED_SPELL_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ @@ -57,32 +58,40 @@ #define SPELL_SCHEMA "org.x.editor.plugins.spell" #define AUTOCHECK_TYPE_KEY "autocheck-type" -XED_PLUGIN_REGISTER_TYPE(XedSpellPlugin, xed_spell_plugin) +static void peas_activatable_iface_init (PeasActivatableInterface *iface); +static void peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface); -typedef struct +G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedSpellPlugin, + xed_spell_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init) + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_GTK_TYPE_CONFIGURABLE, + peas_gtk_configurable_iface_init)) + +enum { + PROP_0, + PROP_OBJECT +}; + +struct _XedSpellPluginPrivate +{ + GtkWidget *window; + GtkActionGroup *action_group; guint ui_id; guint message_cid; gulong tab_added_id; gulong tab_removed_id; - XedSpellPlugin *plugin; -} WindowData; -typedef struct -{ - XedPlugin *plugin; - XedWindow *window; -} ActionData; - -struct _XedSpellPluginPrivate -{ GSettings *settings; }; -static void spell_cb (GtkAction *action, ActionData *action_data); -static void set_language_cb (GtkAction *action, ActionData *action_data); -static void auto_spell_cb (GtkAction *action, XedWindow *window); +static void spell_cb (GtkAction *action, XedSpellPlugin *plugin); +static void set_language_cb (GtkAction *action, XedSpellPlugin *plugin); +static void auto_spell_cb (GtkAction *action, XedSpellPlugin *plugin); /* UI actions. */ static const GtkActionEntry action_entries[] = @@ -120,13 +129,13 @@ typedef struct _SpellConfigureDialog SpellConfigureDialog; struct _SpellConfigureDialog { - GtkWidget *dialog; + GtkWidget *content; GtkWidget *never; GtkWidget *always; GtkWidget *document; - XedSpellPlugin *plugin; + GSettings *settings; }; typedef enum @@ -163,18 +172,30 @@ xed_spell_plugin_init (XedSpellPlugin *plugin) } static void -xed_spell_plugin_finalize (GObject *object) +xed_spell_plugin_dispose (GObject *object) { XedSpellPlugin *plugin = XED_SPELL_PLUGIN (object); - xed_debug_message (DEBUG_PLUGINS, "XedSpellPlugin finalizing"); + xed_debug_message (DEBUG_PLUGINS, "XedSpellPlugin disposing"); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + if (plugin->priv->action_group) + { + g_object_unref (plugin->priv->action_group); + plugin->priv->action_group = NULL; + } g_object_unref (G_OBJECT (plugin->priv->settings)); - G_OBJECT_CLASS (xed_spell_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_spell_plugin_parent_class)->dispose (object); } -static void +static void set_spell_language_cb (XedSpellChecker *spell, const XedSpellCheckerLanguage *lang, XedDocument *doc) @@ -226,16 +247,16 @@ get_autocheck_type (XedSpellPlugin *plugin) } static void -set_autocheck_type (XedSpellPlugin *plugin, +set_autocheck_type (GSettings *settings, XedSpellPluginAutocheckType autocheck_type) { - if (!g_settings_is_writable (plugin->priv->settings, + if (!g_settings_is_writable (settings, AUTOCHECK_TYPE_KEY)) { return; } - g_settings_set_enum (plugin->priv->settings, + g_settings_set_enum (settings, AUTOCHECK_TYPE_KEY, autocheck_type); } @@ -258,9 +279,9 @@ get_spell_checker_from_document (XedDocument *doc) set_language_from_metadata (spell, doc); - g_object_set_qdata_full (G_OBJECT (doc), - spell_checker_id, - spell, + g_object_set_qdata_full (G_OBJECT (doc), + spell_checker_id, + spell, (GDestroyNotify) g_object_unref); g_signal_connect (spell, @@ -307,24 +328,24 @@ update_current (XedDocument *doc, range = get_check_range (doc); g_return_if_fail (range != NULL); - gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), + gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &iter, current); if (!gtk_text_iter_inside_word (&iter)) - { + { /* if we're not inside a word, * we must be in some spaces. * skip forward to the beginning of the next word. */ if (!gtk_text_iter_is_end (&iter)) { gtk_text_iter_forward_word_end (&iter); - gtk_text_iter_backward_word_start (&iter); + gtk_text_iter_backward_word_start (&iter); } } else { if (!gtk_text_iter_starts_word (&iter)) - gtk_text_iter_backward_word_start (&iter); + gtk_text_iter_backward_word_start (&iter); } gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), @@ -332,7 +353,7 @@ update_current (XedDocument *doc, range->end_mark); if (gtk_text_iter_compare (&end_iter, &iter) < 0) - { + { gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), range->current_mark, &end_iter); @@ -374,9 +395,9 @@ set_check_range (XedDocument *doc, range->current_mark = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), "check_range_current_mark", &iter, TRUE); - g_object_set_qdata_full (G_OBJECT (doc), - check_range_id, - range, + g_object_set_qdata_full (G_OBJECT (doc), + check_range_id, + range, (GDestroyNotify)g_free); } @@ -435,12 +456,12 @@ get_current_word (XedDocument *doc, gint *start, gint *end) range = get_check_range (doc); g_return_val_if_fail (range != NULL, NULL); - gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), + gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), &end_iter, range->end_mark); range_end = gtk_text_iter_get_offset (&end_iter); - gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), + gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), ¤t_iter, range->current_mark); end_iter = current_iter; @@ -481,7 +502,7 @@ goto_next_word (XedDocument *doc) range = get_check_range (doc); g_return_val_if_fail (range != NULL, FALSE); - gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), + gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), ¤t_iter, range->current_mark); gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &end_iter); @@ -587,7 +608,7 @@ ignore_cb (XedSpellCheckerDialog *dlg, if (word == NULL) { xed_spell_checker_dialog_set_completed (dlg); - + return; } @@ -739,7 +760,6 @@ get_configure_dialog (XedSpellPlugin *plugin) SpellConfigureDialog *dialog = NULL; gchar *data_dir; gchar *ui_file; - GtkWidget *content; XedSpellPluginAutocheckType autocheck_type; GtkWidget *error_widget; gboolean ret; @@ -750,37 +770,15 @@ get_configure_dialog (XedSpellPlugin *plugin) xed_debug (DEBUG_PLUGINS); - GtkWidget *dlg = gtk_dialog_new_with_buttons (_("Configure Spell Checker plugin..."), - NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, - GTK_RESPONSE_OK, - GTK_STOCK_HELP, - GTK_RESPONSE_HELP, - NULL); + dialog = g_slice_new (SpellConfigureDialog); + dialog->settings = g_object_ref (plugin->priv->settings); - g_return_val_if_fail (dlg != NULL, NULL); - - dialog = g_new0 (SpellConfigureDialog, 1); - dialog->dialog = dlg; - - - /* HIG defaults */ - gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog->dialog)), 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - 2); /* 2 * 5 + 2 = 12 */ - gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dialog->dialog))), - 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog->dialog))), 6); - - data_dir = xed_plugin_get_data_dir (XED_PLUGIN (plugin)); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); ui_file = g_build_filename (data_dir, "xed-spell-setup-dialog.ui", NULL); ret = xed_utils_get_ui_objects (ui_file, root_objects, &error_widget, - "spell_dialog_content", &content, + "spell_dialog_content", &dialog->content, "autocheck_never", &dialog->never, "autocheck_document", &dialog->document, "autocheck_always", &dialog->always, @@ -791,18 +789,9 @@ get_configure_dialog (XedSpellPlugin *plugin) if (!ret) { - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - error_widget, TRUE, TRUE, 0); - - gtk_container_set_border_width (GTK_CONTAINER (error_widget), 5); - - gtk_widget_show (error_widget); - - return dialog; + return NULL; } - gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE); - autocheck_type = get_autocheck_type (plugin); if (autocheck_type == AUTOCHECK_ALWAYS) @@ -818,75 +807,46 @@ get_configure_dialog (XedSpellPlugin *plugin) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->never), TRUE); } - gtk_window_set_default_size (GTK_WIDGET (content), 15, 120); - - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - content, FALSE, FALSE, 0); - g_object_unref (content); - gtk_container_set_border_width (GTK_CONTAINER (content), 5); - - gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), - GTK_RESPONSE_OK); - return dialog; } static void -ok_button_pressed (SpellConfigureDialog *dialog) +configure_dialog_button_toggled (GtkToggleButton *button, + SpellConfigureDialog *dialog) { xed_debug (DEBUG_PLUGINS); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->always))) { - set_autocheck_type (dialog->plugin, AUTOCHECK_ALWAYS); + set_autocheck_type (dialog->settings, AUTOCHECK_ALWAYS); } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->document))) { - set_autocheck_type (dialog->plugin, AUTOCHECK_DOCUMENT); + set_autocheck_type (dialog->settings, AUTOCHECK_DOCUMENT); } else { - set_autocheck_type (dialog->plugin, AUTOCHECK_NEVER); + set_autocheck_type (dialog->settings, AUTOCHECK_NEVER); } } static void -configure_dialog_response_cb (GtkWidget *widget, - gint response, - SpellConfigureDialog *dialog) +configure_dialog_destroyed (GtkWidget *widget, + gpointer data) { - switch (response) - { - case GTK_RESPONSE_HELP: - { - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_HELP"); + SpellConfigureDialog *dialog = (SpellConfigureDialog *) data; - xed_help_display (GTK_WINDOW (widget), - NULL, - "xed-spell-checker-plugin"); - break; - } - case GTK_RESPONSE_OK: - { - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK"); + xed_debug (DEBUG_PLUGINS); - ok_button_pressed (dialog); - - gtk_widget_destroy (dialog->dialog); - break; - } - case GTK_RESPONSE_CANCEL: - { - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CANCEL"); - gtk_widget_destroy (dialog->dialog); - } - } + g_object_unref (dialog->settings); + g_slice_free (SpellConfigureDialog, data); } static void set_language_cb (GtkAction *action, - ActionData *action_data) + XedSpellPlugin *plugin) { + XedWindow *window; XedDocument *doc; XedSpellChecker *spell; const XedSpellCheckerLanguage *lang; @@ -896,7 +856,8 @@ set_language_cb (GtkAction *action, xed_debug (DEBUG_PLUGINS); - doc = xed_window_get_active_document (action_data->window); + window = XED_WINDOW (plugin->priv->window); + doc = xed_window_get_active_document (window); g_return_if_fail (doc != NULL); spell = get_spell_checker_from_document (doc); @@ -904,13 +865,13 @@ set_language_cb (GtkAction *action, lang = xed_spell_checker_get_language (spell); - data_dir = xed_plugin_get_data_dir (action_data->plugin); - dlg = xed_spell_language_dialog_new (GTK_WINDOW (action_data->window), + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); + dlg = xed_spell_language_dialog_new (GTK_WINDOW (window), lang, data_dir); g_free (data_dir); - wg = xed_window_get_group (action_data->window); + wg = xed_window_get_group (window); gtk_window_group_add_window (wg, GTK_WINDOW (dlg)); @@ -926,8 +887,10 @@ set_language_cb (GtkAction *action, static void spell_cb (GtkAction *action, - ActionData *action_data) + XedSpellPlugin *plugin) { + XedSpellPluginPrivate *data; + XedWindow *window; XedView *view; XedDocument *doc; XedSpellChecker *spell; @@ -938,7 +901,9 @@ spell_cb (GtkAction *action, xed_debug (DEBUG_PLUGINS); - view = xed_window_get_active_view (action_data->window); + data = plugin->priv; + window = XED_WINDOW (data->window); + view = xed_window_get_active_view (window); g_return_if_fail (view != NULL); doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); @@ -949,14 +914,9 @@ spell_cb (GtkAction *action, if (gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc)) <= 0) { - WindowData *data; GtkWidget *statusbar; - data = (WindowData *) g_object_get_data (G_OBJECT (action_data->window), - WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - - statusbar = xed_window_get_statusbar (action_data->window); + statusbar = xed_window_get_statusbar (window); xed_statusbar_flash_message (XED_STATUSBAR (statusbar), data->message_cid, _("The document is empty.")); @@ -979,14 +939,9 @@ spell_cb (GtkAction *action, word = get_next_misspelled_word (view); if (word == NULL) { - WindowData *data; GtkWidget *statusbar; - data = (WindowData *) g_object_get_data (G_OBJECT (action_data->window), - WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - - statusbar = xed_window_get_statusbar (action_data->window); + statusbar = xed_window_get_statusbar (window); xed_statusbar_flash_message (XED_STATUSBAR (statusbar), data->message_cid, _("No misspelled words")); @@ -994,12 +949,13 @@ spell_cb (GtkAction *action, return; } - data_dir = xed_plugin_get_data_dir (action_data->plugin); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); dlg = xed_spell_checker_dialog_new_from_spell_checker (spell, data_dir); g_free (data_dir); + gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); gtk_window_set_transient_for (GTK_WINDOW (dlg), - GTK_WINDOW (action_data->window)); + GTK_WINDOW (window)); g_signal_connect (dlg, "ignore", G_CALLBACK (ignore_cb), view); g_signal_connect (dlg, "ignore_all", G_CALLBACK (ignore_cb), view); @@ -1054,15 +1010,16 @@ set_auto_spell (XedWindow *window, static void auto_spell_cb (GtkAction *action, - XedWindow *window) + XedSpellPlugin *plugin) { - + XedWindow *window; XedDocument *doc; gboolean active; - WindowData *data; xed_debug (DEBUG_PLUGINS); + window = XED_WINDOW (plugin->priv->window); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); xed_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated"); @@ -1071,12 +1028,8 @@ auto_spell_cb (GtkAction *action, if (doc == NULL) return; - data = g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - - if (get_autocheck_type(data->plugin) == AUTOCHECK_DOCUMENT) + if (get_autocheck_type (plugin) == AUTOCHECK_DOCUMENT) { - xed_document_set_metadata (doc, XED_METADATA_ATTRIBUTE_SPELL_ENABLED, active ? "1" : NULL, NULL); @@ -1086,26 +1039,10 @@ auto_spell_cb (GtkAction *action, } static void -free_window_data (WindowData *data) -{ - g_return_if_fail (data != NULL); - - g_object_unref (data->action_group); - g_slice_free (WindowData, data); -} - -static void -free_action_data (gpointer data) -{ - g_return_if_fail (data != NULL); - - g_slice_free (ActionData, data); -} - -static void -update_ui_real (XedWindow *window, - WindowData *data) +update_ui (XedSpellPlugin *plugin) { + XedSpellPluginPrivate *data; + XedWindow *window; XedDocument *doc; XedView *view; gboolean autospell; @@ -1113,6 +1050,8 @@ update_ui_real (XedWindow *window, xed_debug (DEBUG_PLUGINS); + data = plugin->priv; + window = XED_WINDOW (data->window); doc = xed_window_get_active_document (window); view = xed_window_get_active_view (window); @@ -1133,14 +1072,14 @@ update_ui_real (XedWindow *window, { action = gtk_action_group_get_action (data->action_group, "AutoSpell"); - + g_signal_handlers_block_by_func (action, auto_spell_cb, - window); + plugin); set_auto_spell (window, doc, autospell); gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), autospell); g_signal_handlers_unblock_by_func (action, auto_spell_cb, - window); + plugin); } } @@ -1150,20 +1089,16 @@ update_ui_real (XedWindow *window, } static void -set_auto_spell_from_metadata (XedWindow *window, +set_auto_spell_from_metadata (XedSpellPlugin *plugin, XedDocument *doc, GtkActionGroup *action_group) { gboolean active = FALSE; gchar *active_str = NULL; + XedWindow *window; XedDocument *active_doc; XedSpellPluginAutocheckType autocheck_type; - WindowData *data; - - data = g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - - autocheck_type = get_autocheck_type(data->plugin); + autocheck_type = get_autocheck_type (plugin); switch (autocheck_type) { @@ -1187,10 +1122,12 @@ set_auto_spell_from_metadata (XedWindow *window, if (active_str) { active = *active_str == '1'; - + g_free (active_str); } + window = XED_WINDOW (plugin->priv->window); + set_auto_spell (window, doc, active); /* In case that the doc is the active one we mark the spell action */ @@ -1199,27 +1136,26 @@ set_auto_spell_from_metadata (XedWindow *window, if (active_doc == doc && action_group != NULL) { GtkAction *action; - + action = gtk_action_group_get_action (action_group, "AutoSpell"); g_signal_handlers_block_by_func (action, auto_spell_cb, - window); + plugin); gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active); g_signal_handlers_unblock_by_func (action, auto_spell_cb, - window); + plugin); } } static void on_document_loaded (XedDocument *doc, const GError *error, - XedWindow *window) + XedSpellPlugin *plugin) { if (error == NULL) { - WindowData *data; XedSpellChecker *spell; spell = XED_SPELL_CHECKER (g_object_get_qdata (G_OBJECT (doc), @@ -1229,22 +1165,18 @@ on_document_loaded (XedDocument *doc, set_language_from_metadata (spell, doc); } - data = g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - - set_auto_spell_from_metadata (window, doc, data->action_group); + set_auto_spell_from_metadata (plugin, doc, plugin->priv->action_group); } } static void on_document_saved (XedDocument *doc, const GError *error, - XedWindow *window) + XedSpellPlugin *plugin) { XedAutomaticSpellChecker *autospell; XedSpellChecker *spell; const gchar *key; - WindowData *data; if (error != NULL) { @@ -1264,10 +1196,7 @@ on_document_saved (XedDocument *doc, key = NULL; } - data = g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - - if (get_autocheck_type(data->plugin) == AUTOCHECK_DOCUMENT) + if (get_autocheck_type (plugin) == AUTOCHECK_DOCUMENT) { xed_document_set_metadata (doc, @@ -1289,7 +1218,7 @@ on_document_saved (XedDocument *doc, static void tab_added_cb (XedWindow *window, XedTab *tab, - gpointer useless) + XedSpellPlugin *plugin) { XedDocument *doc; @@ -1297,189 +1226,206 @@ tab_added_cb (XedWindow *window, g_signal_connect (doc, "loaded", G_CALLBACK (on_document_loaded), - window); + plugin); g_signal_connect (doc, "saved", G_CALLBACK (on_document_saved), - window); + plugin); } static void tab_removed_cb (XedWindow *window, XedTab *tab, - gpointer useless) + XedSpellPlugin *plugin) { XedDocument *doc; doc = xed_tab_get_document (tab); - - g_signal_handlers_disconnect_by_func (doc, on_document_loaded, window); - g_signal_handlers_disconnect_by_func (doc, on_document_saved, window); + + g_signal_handlers_disconnect_by_func (doc, on_document_loaded, plugin); + g_signal_handlers_disconnect_by_func (doc, on_document_saved, plugin); } static void -impl_activate (XedPlugin *plugin, - XedWindow *window) +xed_spell_plugin_activate (PeasActivatable *activatable) { + XedSpellPlugin *plugin; + XedSpellPluginPrivate *data; + XedWindow *window; GtkUIManager *manager; - WindowData *data; - ActionData *action_data; GList *docs, *l; xed_debug (DEBUG_PLUGINS); - data = g_slice_new (WindowData); - data->plugin = XED_SPELL_PLUGIN (plugin); - action_data = g_slice_new (ActionData); - action_data->plugin = plugin; - action_data->window = window; + plugin = XED_SPELL_PLUGIN (activatable); + data = plugin->priv; + window = XED_WINDOW (data->window); manager = xed_window_get_ui_manager (window); data->action_group = gtk_action_group_new ("XedSpellPluginActions"); - gtk_action_group_set_translation_domain (data->action_group, + gtk_action_group_set_translation_domain (data->action_group, GETTEXT_PACKAGE); - gtk_action_group_add_actions_full (data->action_group, + gtk_action_group_add_actions (data->action_group, action_entries, G_N_ELEMENTS (action_entries), - action_data, - (GDestroyNotify) free_action_data); - gtk_action_group_add_toggle_actions (data->action_group, + plugin); + gtk_action_group_add_toggle_actions (data->action_group, toggle_action_entries, G_N_ELEMENTS (toggle_action_entries), - window); + plugin); gtk_ui_manager_insert_action_group (manager, data->action_group, -1); data->ui_id = gtk_ui_manager_new_merge_id (manager); data->message_cid = gtk_statusbar_get_context_id - (GTK_STATUSBAR (xed_window_get_statusbar (window)), + (GTK_STATUSBAR (xed_window_get_statusbar (window)), "spell_plugin_message"); - g_object_set_data_full (G_OBJECT (window), - WINDOW_DATA_KEY, - data, - (GDestroyNotify) free_window_data); - gtk_ui_manager_add_ui (manager, data->ui_id, MENU_PATH, "CheckSpell", "CheckSpell", - GTK_UI_MANAGER_MENUITEM, + GTK_UI_MANAGER_MENUITEM, FALSE); - gtk_ui_manager_add_ui (manager, - data->ui_id, + gtk_ui_manager_add_ui (manager, + data->ui_id, MENU_PATH, - "AutoSpell", "AutoSpell", - GTK_UI_MANAGER_MENUITEM, + "AutoSpell", + GTK_UI_MANAGER_MENUITEM, FALSE); - gtk_ui_manager_add_ui (manager, - data->ui_id, + gtk_ui_manager_add_ui (manager, + data->ui_id, MENU_PATH, - "ConfigSpell", "ConfigSpell", - GTK_UI_MANAGER_MENUITEM, + "ConfigSpell", + GTK_UI_MANAGER_MENUITEM, FALSE); - update_ui_real (window, data); + update_ui (plugin); docs = xed_window_get_documents (window); for (l = docs; l != NULL; l = g_list_next (l)) { XedDocument *doc = XED_DOCUMENT (l->data); - set_auto_spell_from_metadata (window, doc, + set_auto_spell_from_metadata (plugin, doc, data->action_group); g_signal_handlers_disconnect_by_func (doc, on_document_loaded, - window); + plugin); g_signal_handlers_disconnect_by_func (doc, on_document_saved, - window); + plugin); } data->tab_added_id = g_signal_connect (window, "tab-added", - G_CALLBACK (tab_added_cb), NULL); + G_CALLBACK (tab_added_cb), plugin); data->tab_removed_id = g_signal_connect (window, "tab-removed", - G_CALLBACK (tab_removed_cb), NULL); + G_CALLBACK (tab_removed_cb), plugin); } static void -impl_deactivate (XedPlugin *plugin, - XedWindow *window) +xed_spell_plugin_deactivate (PeasActivatable *activatable) { + XedSpellPluginPrivate *data; + XedWindow *window; GtkUIManager *manager; - WindowData *data; xed_debug (DEBUG_PLUGINS); - manager = xed_window_get_ui_manager (window); + data = XED_SPELL_PLUGIN (activatable)->priv; + window = XED_WINDOW (data->window); - data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); + manager = xed_window_get_ui_manager (window); gtk_ui_manager_remove_ui (manager, data->ui_id); gtk_ui_manager_remove_action_group (manager, data->action_group); g_signal_handler_disconnect (window, data->tab_added_id); g_signal_handler_disconnect (window, data->tab_removed_id); - - g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL); } static void -impl_update_ui (XedPlugin *plugin, - XedWindow *window) +xed_spell_plugin_update_state (PeasActivatable *activatable) { - WindowData *data; + xed_debug (DEBUG_PLUGINS); - xed_debug (DEBUG_PLUGINS); + update_ui (XED_SPELL_PLUGIN (activatable)); +} - data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); +static void +xed_spell_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + XedSpellPlugin *plugin = XED_SPELL_PLUGIN (object); - update_ui_real (window, data); + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +xed_spell_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + XedSpellPlugin *plugin = XED_SPELL_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static GtkWidget * -impl_create_configure_dialog (XedPlugin *plugin) +xed_spell_plugin_create_configure_widget (PeasGtkConfigurable *configurable) { SpellConfigureDialog *dialog; - dialog = get_configure_dialog(XED_SPELL_PLUGIN (plugin)); + dialog = get_configure_dialog (XED_SPELL_PLUGIN (configurable)); - dialog->plugin = XED_SPELL_PLUGIN (plugin); + g_signal_connect (dialog->always, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); + g_signal_connect (dialog->document, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); + g_signal_connect (dialog->never, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); + g_signal_connect (dialog->content, "destroy", G_CALLBACK (configure_dialog_destroyed), dialog); - g_signal_connect (dialog->dialog, - "response", - G_CALLBACK (configure_dialog_response_cb), - dialog); - - return GTK_WIDGET (dialog->dialog); + return dialog->content; } static void xed_spell_plugin_class_init (XedSpellPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - XedPluginClass *plugin_class = XED_PLUGIN_CLASS (klass); - object_class->finalize = xed_spell_plugin_finalize; + object_class->dispose = xed_spell_plugin_dispose; + object_class->set_property = xed_spell_plugin_set_property; + object_class->get_property = xed_spell_plugin_get_property; - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_update_ui; - - plugin_class->create_configure_dialog = impl_create_configure_dialog; + g_object_class_override_property (object_class, PROP_OBJECT, "object"); if (spell_checker_id == 0) spell_checker_id = g_quark_from_string ("XedSpellCheckerID"); @@ -1489,3 +1435,37 @@ xed_spell_plugin_class_init (XedSpellPluginClass *klass) g_type_class_add_private (object_class, sizeof (XedSpellPluginPrivate)); } + +static void +xed_spell_plugin_class_finalize (XedSpellPluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = xed_spell_plugin_activate; + iface->deactivate = xed_spell_plugin_deactivate; + iface->update_state = xed_spell_plugin_update_state; +} + +static void +peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface) +{ + iface->create_configure_widget = xed_spell_plugin_create_configure_widget; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + xed_spell_plugin_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + XED_TYPE_SPELL_PLUGIN); + + peas_object_module_register_extension_type (module, + PEAS_GTK_TYPE_CONFIGURABLE, + XED_TYPE_SPELL_PLUGIN); +} diff --git a/plugins/spell/xed-spell-plugin.h b/plugins/spell/xed-spell-plugin.h index 998ef40..be2982c 100644 --- a/plugins/spell/xed-spell-plugin.h +++ b/plugins/spell/xed-spell-plugin.h @@ -1,7 +1,7 @@ /* * xed-spell-plugin.h - * - * Copyright (C) 2002-2005 Paolo Maggi + * + * Copyright (C) 2002-2005 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,52 +25,53 @@ #include #include -#include +#include +#include G_BEGIN_DECLS /* * Type checking and casting macros */ -#define XED_TYPE_SPELL_PLUGIN (xed_spell_plugin_get_type ()) -#define XED_SPELL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_SPELL_PLUGIN, XedSpellPlugin)) -#define XED_SPELL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_SPELL_PLUGIN, XedSpellPluginClass)) -#define XED_IS_SPELL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_SPELL_PLUGIN)) -#define XED_IS_SPELL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_SPELL_PLUGIN)) -#define XED_SPELL_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_SPELL_PLUGIN, XedSpellPluginClass)) +#define XED_TYPE_SPELL_PLUGIN (xed_spell_plugin_get_type ()) +#define XED_SPELL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_SPELL_PLUGIN, XedSpellPlugin)) +#define XED_SPELL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_SPELL_PLUGIN, XedSpellPluginClass)) +#define XED_IS_SPELL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_SPELL_PLUGIN)) +#define XED_IS_SPELL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_SPELL_PLUGIN)) +#define XED_SPELL_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_SPELL_PLUGIN, XedSpellPluginClass)) /* Private structure type */ -typedef struct _XedSpellPluginPrivate XedSpellPluginPrivate; +typedef struct _XedSpellPluginPrivate XedSpellPluginPrivate; /* * Main object structure */ -typedef struct _XedSpellPlugin XedSpellPlugin; +typedef struct _XedSpellPlugin XedSpellPlugin; struct _XedSpellPlugin { - XedPlugin parent_instance; + PeasExtensionBase parent_instance; - XedSpellPluginPrivate *priv; + XedSpellPluginPrivate *priv; }; /* * Class definition */ -typedef struct _XedSpellPluginClass XedSpellPluginClass; +typedef struct _XedSpellPluginClass XedSpellPluginClass; struct _XedSpellPluginClass { - XedPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* * Public methods */ -GType xed_spell_plugin_get_type (void) G_GNUC_CONST; +GType xed_spell_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_xed_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS From 804259fe1f973e837120ede46a5e2b5145ac5c71 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 13:50:48 -0800 Subject: [PATCH 034/132] taglist-plugin: Port to libpeas Adapted from: https://github.com/mate-desktop/pluma/commit/2aafaabdaa4854b3941bd9f3319b89c807abf306 --- plugins/taglist/xed-taglist-plugin-panel.c | 25 ++- plugins/taglist/xed-taglist-plugin-panel.h | 34 ++-- plugins/taglist/xed-taglist-plugin.c | 201 ++++++++++++++------- plugins/taglist/xed-taglist-plugin.h | 43 ++--- 4 files changed, 197 insertions(+), 106 deletions(-) diff --git a/plugins/taglist/xed-taglist-plugin-panel.c b/plugins/taglist/xed-taglist-plugin-panel.c index a5a95d5..a1b0622 100644 --- a/plugins/taglist/xed-taglist-plugin-panel.c +++ b/plugins/taglist/xed-taglist-plugin-panel.c @@ -39,7 +39,6 @@ #include #include -#include #include #include @@ -65,11 +64,11 @@ struct _XedTaglistPluginPanelPrivate GtkWidget *preview; TagGroup *selected_tag_group; - + gchar *data_dir; }; -XED_PLUGIN_DEFINE_TYPE (XedTaglistPluginPanel, xed_taglist_plugin_panel, GTK_TYPE_BOX) +G_DEFINE_DYNAMIC_TYPE (XedTaglistPluginPanel, xed_taglist_plugin_panel, GTK_TYPE_BOX) enum { @@ -133,7 +132,7 @@ static void xed_taglist_plugin_panel_finalize (GObject *object) { XedTaglistPluginPanel *panel = XED_TAGLIST_PLUGIN_PANEL (object); - + g_free (panel->priv->data_dir); G_OBJECT_CLASS (xed_taglist_plugin_panel_parent_class)->finalize (object); @@ -160,6 +159,12 @@ xed_taglist_plugin_panel_class_init (XedTaglistPluginPanelClass *klass) g_type_class_add_private (object_class, sizeof(XedTaglistPluginPanelPrivate)); } +static void +xed_taglist_plugin_panel_class_finalize (XedTaglistPluginPanelClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE */ +} + static void insert_tag (XedTaglistPluginPanel *panel, Tag *tag, @@ -431,7 +436,7 @@ selected_group_changed (GtkComboBox *combo, populate_tags_list (panel); } - + /* Clean up preview */ gtk_label_set_text (GTK_LABEL (panel->priv->preview), ""); @@ -781,8 +786,14 @@ xed_taglist_plugin_panel_new (XedWindow *window, panel = g_object_new (XED_TYPE_TAGLIST_PLUGIN_PANEL, "window", window, NULL); - + panel->priv->data_dir = g_strdup (data_dir); - + return GTK_WIDGET (panel); } + +void +_xed_taglist_plugin_panel_register_type (GTypeModule *type_module) +{ + xed_taglist_plugin_panel_register_type (type_module); +} diff --git a/plugins/taglist/xed-taglist-plugin-panel.h b/plugins/taglist/xed-taglist-plugin-panel.h index 72d1ec1..9583b8a 100644 --- a/plugins/taglist/xed-taglist-plugin-panel.h +++ b/plugins/taglist/xed-taglist-plugin-panel.h @@ -2,7 +2,7 @@ * xed-taglist-plugin-panel.h * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -56,12 +56,12 @@ typedef struct _XedTaglistPluginPanelPrivate XedTaglistPluginPanelPrivate; */ typedef struct _XedTaglistPluginPanel XedTaglistPluginPanel; -struct _XedTaglistPluginPanel +struct _XedTaglistPluginPanel { - GtkBox vbox; + GtkBox vbox; - /*< private > */ - XedTaglistPluginPanelPrivate *priv; + /*< private > */ + XedTaglistPluginPanelPrivate *priv; }; /* @@ -69,20 +69,20 @@ struct _XedTaglistPluginPanel */ typedef struct _XedTaglistPluginPanelClass XedTaglistPluginPanelClass; -struct _XedTaglistPluginPanelClass +struct _XedTaglistPluginPanelClass { - GtkBoxClass parent_class; + GtkBoxClass parent_class; }; /* * Public methods */ -GType xed_taglist_plugin_panel_register_type (GTypeModule *module); - -GType xed_taglist_plugin_panel_get_type (void) G_GNUC_CONST; +void _xed_taglist_plugin_panel_register_type (GTypeModule *module); -GtkWidget *xed_taglist_plugin_panel_new (XedWindow *window, - const gchar *data_dir); +GType xed_taglist_plugin_panel_get_type (void) G_GNUC_CONST; + +GtkWidget *xed_taglist_plugin_panel_new (XedWindow *window, + const gchar *data_dir); G_END_DECLS diff --git a/plugins/taglist/xed-taglist-plugin.c b/plugins/taglist/xed-taglist-plugin.c index 8cfa239..0f5076f 100644 --- a/plugins/taglist/xed-taglist-plugin.c +++ b/plugins/taglist/xed-taglist-plugin.c @@ -1,6 +1,6 @@ /* * xed-taglist-plugin.h - * + * * Copyright (C) 2002-2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify @@ -20,9 +20,9 @@ */ /* - * Modified by the xed Team, 2002-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2002-2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -37,23 +37,38 @@ #include #include +#include -#include +#include #include -#define WINDOW_DATA_KEY "XedTaglistPluginWindowData" - #define XED_TAGLIST_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginPrivate)) struct _XedTaglistPluginPrivate { - gpointer dummy; + GtkWidget *window; + + GtkWidget *taglist_panel; }; -XED_PLUGIN_REGISTER_TYPE_WITH_CODE (XedTaglistPlugin, xed_taglist_plugin, - xed_taglist_plugin_panel_register_type (module); +static void peas_activatable_iface_init (PeasActivatableInterface *iface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedTaglistPlugin, + xed_taglist_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init) \ + \ + _xed_taglist_plugin_panel_register_type (type_module); \ ) +enum +{ + PROP_0, + PROP_OBJECT +}; + static void xed_taglist_plugin_init (XedTaglistPlugin *plugin) { @@ -62,99 +77,163 @@ xed_taglist_plugin_init (XedTaglistPlugin *plugin) xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin initializing"); } +static void +xed_taglist_plugin_dispose (GObject *object) +{ + XedTaglistPlugin *plugin = XED_TAGLIST_PLUGIN (object); + + xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin disposing"); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + G_OBJECT_CLASS (xed_taglist_plugin_parent_class)->dispose (object); +} + static void xed_taglist_plugin_finalize (GObject *object) { -/* - XedTaglistPlugin *plugin = XED_TAGLIST_PLUGIN (object); -*/ - xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin finalizing"); + xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin finalizing"); free_taglist (); - + G_OBJECT_CLASS (xed_taglist_plugin_parent_class)->finalize (object); } static void -impl_activate (XedPlugin *plugin, - XedWindow *window) +xed_taglist_plugin_activate (PeasActivatable *activatable) { + XedTaglistPluginPrivate *priv; + XedWindow *window; XedPanel *side_panel; - GtkWidget *taglist_panel; gchar *data_dir; - + xed_debug (DEBUG_PLUGINS); - - g_return_if_fail (g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY) == NULL); - + + priv = XED_TAGLIST_PLUGIN (activatable)->priv; + window = XED_WINDOW (priv->window); side_panel = xed_window_get_side_panel (window); - - data_dir = xed_plugin_get_data_dir (plugin); - taglist_panel = xed_taglist_plugin_panel_new (window, data_dir); + + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (activatable)); + priv->taglist_panel = xed_taglist_plugin_panel_new (window, data_dir); g_free (data_dir); - - xed_panel_add_item_with_stock_icon (side_panel, - taglist_panel, - _("Tags"), - GTK_STOCK_ADD); - g_object_set_data (G_OBJECT (window), - WINDOW_DATA_KEY, - taglist_panel); + xed_panel_add_item_with_stock_icon (side_panel, + priv->taglist_panel, + _("Tags"), + GTK_STOCK_ADD); } static void -impl_deactivate (XedPlugin *plugin, - XedWindow *window) +xed_taglist_plugin_deactivate (PeasActivatable *activatable) { + XedTaglistPluginPrivate *priv; + XedWindow *window; XedPanel *side_panel; - gpointer data; - + xed_debug (DEBUG_PLUGINS); - - data = g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - + + priv = XED_TAGLIST_PLUGIN (activatable)->priv; + window = XED_WINDOW (priv->window); side_panel = xed_window_get_side_panel (window); - xed_panel_remove_item (side_panel, - GTK_WIDGET (data)); - - g_object_set_data (G_OBJECT (window), - WINDOW_DATA_KEY, - NULL); + xed_panel_remove_item (side_panel, priv->taglist_panel); } static void -impl_update_ui (XedPlugin *plugin, - XedWindow *window) +xed_taglist_plugin_update_state (PeasActivatable *activatable) { - gpointer data; + XedTaglistPluginPrivate *priv; + XedWindow *window; XedView *view; - + xed_debug (DEBUG_PLUGINS); - - data = g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - + + priv = XED_TAGLIST_PLUGIN (activatable)->priv; + window = XED_WINDOW (priv->window); view = xed_window_get_active_view (window); - - gtk_widget_set_sensitive (GTK_WIDGET (data), + + gtk_widget_set_sensitive (priv->taglist_panel, (view != NULL) && gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); } +static void +xed_taglist_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + XedTaglistPlugin *plugin = XED_TAGLIST_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +xed_taglist_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + XedTaglistPlugin *plugin = XED_TAGLIST_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + static void xed_taglist_plugin_class_init (XedTaglistPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - XedPluginClass *plugin_class = XED_PLUGIN_CLASS (klass); object_class->finalize = xed_taglist_plugin_finalize; + object_class->dispose = xed_taglist_plugin_dispose; + object_class->set_property = xed_taglist_plugin_set_property; + object_class->get_property = xed_taglist_plugin_get_property; - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_update_ui; + g_object_class_override_property (object_class, PROP_OBJECT, "object"); g_type_class_add_private (object_class, sizeof (XedTaglistPluginPrivate)); } + +static void +xed_taglist_plugin_class_finalize (XedTaglistPluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = xed_taglist_plugin_activate; + iface->deactivate = xed_taglist_plugin_deactivate; + iface->update_state = xed_taglist_plugin_update_state; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + xed_taglist_plugin_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + XED_TYPE_TAGLIST_PLUGIN); +} diff --git a/plugins/taglist/xed-taglist-plugin.h b/plugins/taglist/xed-taglist-plugin.h index a71083e..aa40462 100644 --- a/plugins/taglist/xed-taglist-plugin.h +++ b/plugins/taglist/xed-taglist-plugin.h @@ -1,6 +1,6 @@ /* * xed-taglist-plugin.h - * + * * Copyright (C) 2002-2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify @@ -20,65 +20,66 @@ */ /* - * Modified by the xed Team, 2002-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2002-2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ - + #ifndef __XED_TAGLIST_PLUGIN_H__ #define __XED_TAGLIST_PLUGIN_H__ #include #include -#include +#include +#include G_BEGIN_DECLS /* * Type checking and casting macros */ -#define XED_TYPE_TAGLIST_PLUGIN (xed_taglist_plugin_get_type ()) -#define XED_TAGLIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPlugin)) -#define XED_TAGLIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginClass)) -#define XED_IS_TAGLIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TAGLIST_PLUGIN)) -#define XED_IS_TAGLIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TAGLIST_PLUGIN)) -#define XED_TAGLIST_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginClass)) +#define XED_TYPE_TAGLIST_PLUGIN (xed_taglist_plugin_get_type ()) +#define XED_TAGLIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPlugin)) +#define XED_TAGLIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginClass)) +#define XED_IS_TAGLIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TAGLIST_PLUGIN)) +#define XED_IS_TAGLIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TAGLIST_PLUGIN)) +#define XED_TAGLIST_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginClass)) /* Private structure type */ -typedef struct _XedTaglistPluginPrivate XedTaglistPluginPrivate; +typedef struct _XedTaglistPluginPrivate XedTaglistPluginPrivate; /* * Main object structure */ -typedef struct _XedTaglistPlugin XedTaglistPlugin; +typedef struct _XedTaglistPlugin XedTaglistPlugin; struct _XedTaglistPlugin { - XedPlugin parent_instance; + PeasExtensionBase parent_instance; - /*< private >*/ - XedTaglistPluginPrivate *priv; + /*< private >*/ + XedTaglistPluginPrivate *priv; }; /* * Class definition */ -typedef struct _XedTaglistPluginClass XedTaglistPluginClass; +typedef struct _XedTaglistPluginClass XedTaglistPluginClass; struct _XedTaglistPluginClass { - XedPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* * Public methods */ -GType xed_taglist_plugin_get_type (void) G_GNUC_CONST; +GType xed_taglist_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_xed_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS From b7ecc43dfc7005448aea7fe6b589a5e95b0e2b2f Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 13:54:48 -0800 Subject: [PATCH 035/132] time-plugin: Port to libpeas Adapted from: https://github.com/mate-desktop/pluma/commit/564ca51a2544db1be35fd1493110b6db8ecdc4a6 --- plugins/time/xed-time-plugin.c | 453 ++++++++++++++++----------------- plugins/time/xed-time-plugin.h | 35 +-- 2 files changed, 237 insertions(+), 251 deletions(-) diff --git a/plugins/time/xed-time-plugin.c b/plugins/time/xed-time-plugin.c index da3a890..f308c31 100644 --- a/plugins/time/xed-time-plugin.c +++ b/plugins/time/xed-time-plugin.c @@ -40,7 +40,10 @@ #include #include #include +#include +#include +#include #include #include @@ -48,7 +51,6 @@ XED_TYPE_TIME_PLUGIN, \ XedTimePluginPrivate)) -#define WINDOW_DATA_KEY "XedTimePluginWindowData" #define MENU_PATH "/MenuBar/EditMenu/EditOps_4" /* GSettings keys */ @@ -106,7 +108,7 @@ typedef struct _TimeConfigureDialog TimeConfigureDialog; struct _TimeConfigureDialog { - GtkWidget *dialog; + GtkWidget *content; GtkWidget *list; @@ -118,8 +120,7 @@ struct _TimeConfigureDialog GtkWidget *custom_entry; GtkWidget *custom_format_example; - /* Info needed for the response handler */ - XedTimePlugin *plugin; + GSettings *settings; }; typedef struct _ChooseFormatDialog ChooseFormatDialog; @@ -139,7 +140,8 @@ struct _ChooseFormatDialog /* Info needed for the response handler */ GtkTextBuffer *buffer; - XedTimePlugin *plugin; + + GSettings *settings; }; typedef enum @@ -152,24 +154,33 @@ typedef enum struct _XedTimePluginPrivate { - GSettings *settings; -}; + GtkWidget *window; -XED_PLUGIN_REGISTER_TYPE(XedTimePlugin, xed_time_plugin) + GSettings *settings; -typedef struct -{ GtkActionGroup *action_group; guint ui_id; -} WindowData; +}; -typedef struct +enum { - XedWindow *window; - XedTimePlugin *plugin; -} ActionData; + PROP_0, + PROP_OBJECT +}; -static void time_cb (GtkAction *action, ActionData *data); +static void peas_activatable_iface_init (PeasActivatableInterface *iface); +static void peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedTimePlugin, + xed_time_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init) + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_GTK_TYPE_CONFIGURABLE, + peas_gtk_configurable_iface_init)) + +static void time_cb (GtkAction *action, XedTimePlugin *plugin); static const GtkActionEntry action_entries[] = { @@ -206,23 +217,37 @@ xed_time_plugin_finalize (GObject *object) } static void -free_window_data (WindowData *data) +xed_time_plugin_dispose (GObject *object) { - g_return_if_fail (data != NULL); + XedTimePlugin *plugin = XED_TIME_PLUGIN (object); - g_object_unref (data->action_group); - g_free (data); + xed_debug_message (DEBUG_PLUGINS, "XedTimePlugin disposing"); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + if (plugin->priv->action_group) + { + g_object_unref (plugin->priv->action_group); + plugin->priv->action_group = NULL; + } + + G_OBJECT_CLASS (xed_time_plugin_parent_class)->dispose (object); } static void -update_ui_real (XedWindow *window, - WindowData *data) +update_ui (XedTimePluginPrivate *data) { + XedWindow *window; XedView *view; GtkAction *action; xed_debug (DEBUG_PLUGINS); + window = XED_WINDOW (data->window); view = xed_window_get_active_view (window); xed_debug_message (DEBUG_PLUGINS, "View: %p", view); @@ -235,41 +260,33 @@ update_ui_real (XedWindow *window, } static void -impl_activate (XedPlugin *plugin, - XedWindow *window) +xed_time_plugin_activate (PeasActivatable *activatable) { + XedTimePlugin *plugin; + XedTimePluginPrivate *data; + XedWindow *window; GtkUIManager *manager; - WindowData *data; - ActionData *action_data; xed_debug (DEBUG_PLUGINS); - data = g_new (WindowData, 1); - action_data = g_new (ActionData, 1); - - action_data->plugin = XED_TIME_PLUGIN (plugin); - action_data->window = window; + plugin = XED_TIME_PLUGIN (activatable); + data = plugin->priv; + window = XED_WINDOW (data->window); manager = xed_window_get_ui_manager (window); data->action_group = gtk_action_group_new ("XedTimePluginActions"); gtk_action_group_set_translation_domain (data->action_group, GETTEXT_PACKAGE); - gtk_action_group_add_actions_full (data->action_group, + gtk_action_group_add_actions (data->action_group, action_entries, G_N_ELEMENTS (action_entries), - action_data, - (GDestroyNotify) g_free); + plugin); gtk_ui_manager_insert_action_group (manager, data->action_group, -1); data->ui_id = gtk_ui_manager_new_merge_id (manager); - g_object_set_data_full (G_OBJECT (window), - WINDOW_DATA_KEY, - data, - (GDestroyNotify) free_window_data); - gtk_ui_manager_add_ui (manager, data->ui_id, MENU_PATH, @@ -278,41 +295,33 @@ impl_activate (XedPlugin *plugin, GTK_UI_MANAGER_MENUITEM, FALSE); - update_ui_real (window, data); + update_ui (data); } static void -impl_deactivate (XedPlugin *plugin, - XedWindow *window) +xed_time_plugin_deactivate (PeasActivatable *activatable) { + XedTimePluginPrivate *data; + XedWindow *window; GtkUIManager *manager; - WindowData *data; xed_debug (DEBUG_PLUGINS); + data = XED_TIME_PLUGIN (activatable)->priv; + window = XED_WINDOW (data->window); + manager = xed_window_get_ui_manager (window); - data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - gtk_ui_manager_remove_ui (manager, data->ui_id); gtk_ui_manager_remove_action_group (manager, data->action_group); - - g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL); } static void -impl_update_ui (XedPlugin *plugin, - XedWindow *window) +xed_time_plugin_update_state (PeasActivatable *activatable) { - WindowData *data; - xed_debug (DEBUG_PLUGINS); - data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - - update_ui_real (window, data); + update_ui (XED_TIME_PLUGIN (activatable)->priv); } /* whether we should prompt the user or use the specified format */ @@ -328,16 +337,16 @@ get_prompt_type (XedTimePlugin *plugin) } static void -set_prompt_type (XedTimePlugin *plugin, +set_prompt_type (GSettings *settings, XedTimePluginPromptType prompt_type) { - if (!g_settings_is_writable (plugin->priv->settings, + if (!g_settings_is_writable (settings, PROMPT_TYPE_KEY)) { return; } - g_settings_set_enum (plugin->priv->settings, + g_settings_set_enum (settings, PROMPT_TYPE_KEY, prompt_type); } @@ -355,18 +364,18 @@ get_selected_format (XedTimePlugin *plugin) } static void -set_selected_format (XedTimePlugin *plugin, +set_selected_format (GSettings *settings, const gchar *format) { g_return_if_fail (format != NULL); - if (!g_settings_is_writable (plugin->priv->settings, + if (!g_settings_is_writable (settings, SELECTED_FORMAT_KEY)) { return; } - g_settings_set_string (plugin->priv->settings, + g_settings_set_string (settings, SELECTED_FORMAT_KEY, format); } @@ -384,16 +393,16 @@ get_custom_format (XedTimePlugin *plugin) } static void -set_custom_format (XedTimePlugin *plugin, +set_custom_format (GSettings *settings, const gchar *format) { g_return_if_fail (format != NULL); - if (!g_settings_is_writable (plugin->priv->settings, + if (!g_settings_is_writable (settings, CUSTOM_FORMAT_KEY)) return; - g_settings_set_string (plugin->priv->settings, + g_settings_set_string (settings, CUSTOM_FORMAT_KEY, format); } @@ -448,13 +457,24 @@ get_time (const gchar* format) } static void -dialog_disposed (GObject *obj, gpointer dialog_pointer) +configure_dialog_destroyed (GtkWidget *widget, + gpointer data) { + TimeConfigureDialog *dialog = (TimeConfigureDialog *) data; + xed_debug (DEBUG_PLUGINS); - g_free (dialog_pointer); + g_object_unref (dialog->settings); + g_slice_free (TimeConfigureDialog, data); +} - xed_debug_message (DEBUG_PLUGINS, "END"); +static void +choose_format_dialog_destroyed (GtkWidget *widget, + gpointer data) +{ + xed_debug (DEBUG_PLUGINS); + + g_slice_free (ChooseFormatDialog, data); } static GtkTreeModel * @@ -640,7 +660,8 @@ configure_dialog_button_toggled (GtkToggleButton *button, TimeConfigureDialog *d gtk_widget_set_sensitive (dialog->custom_entry, TRUE); gtk_widget_set_sensitive (dialog->custom_format_example, TRUE); - return; + set_prompt_type (dialog->settings, USE_CUSTOM_FORMAT); + return; } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list))) @@ -649,7 +670,8 @@ configure_dialog_button_toggled (GtkToggleButton *button, TimeConfigureDialog *d gtk_widget_set_sensitive (dialog->custom_entry, FALSE); gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); - return; + set_prompt_type (dialog->settings, USE_SELECTED_FORMAT); + return; } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->prompt))) @@ -658,7 +680,8 @@ configure_dialog_button_toggled (GtkToggleButton *button, TimeConfigureDialog *d gtk_widget_set_sensitive (dialog->custom_entry, FALSE); gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); - return; + set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT); + return; } } @@ -691,10 +714,21 @@ get_format_from_list (GtkWidget *listview) g_return_val_if_reached (0); } +static void +configure_dialog_selection_changed (GtkTreeSelection *selection, + TimeConfigureDialog *dialog) +{ + gint sel_format; + + sel_format = get_format_from_list (dialog->list); + set_selected_format (dialog->settings, formats[sel_format]); +} + static TimeConfigureDialog * get_configure_dialog (XedTimePlugin *plugin) { TimeConfigureDialog *dialog = NULL; + GtkTreeSelection *selection; gchar *data_dir; gchar *ui_file; GtkWidget *content; @@ -710,37 +744,15 @@ get_configure_dialog (XedTimePlugin *plugin) xed_debug (DEBUG_PLUGINS); - GtkWidget *dlg = gtk_dialog_new_with_buttons (_("Configure insert date/time plugin..."), - NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, - GTK_RESPONSE_OK, - GTK_STOCK_HELP, - GTK_RESPONSE_HELP, - NULL); + dialog = g_slice_new (TimeConfigureDialog); + dialog->settings = g_object_ref (plugin->priv->settings); - g_return_val_if_fail (dlg != NULL, NULL); - - dialog = g_new0 (TimeConfigureDialog, 1); - dialog->dialog = dlg; - - /* HIG defaults */ - gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog->dialog)), 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - 2); /* 2 * 5 + 2 = 12 */ - gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dialog->dialog))), - 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog->dialog))), 6); - - - data_dir = xed_plugin_get_data_dir (XED_PLUGIN (plugin)); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); ui_file = g_build_filename (data_dir, "xed-time-setup-dialog.ui", NULL); ret = xed_utils_get_ui_objects (ui_file, root_objects, &error_widget, - "time_dialog_content", &content, + "time_dialog_content", &dialog->content, "formats_viewport", &viewport, "formats_tree", &dialog->list, "always_prompt", &dialog->prompt, @@ -755,27 +767,18 @@ get_configure_dialog (XedTimePlugin *plugin) if (!ret) { - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - error_widget, - TRUE, TRUE, 0); - gtk_container_set_border_width (GTK_CONTAINER (error_widget), 5); - - gtk_widget_show (error_widget); - - return dialog; + return NULL; } - gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE); - sf = get_selected_format (plugin); create_formats_list (dialog->list, sf, plugin); g_free (sf); prompt_type = get_prompt_type (plugin); - cf = get_custom_format (plugin); - gtk_entry_set_text (GTK_ENTRY(dialog->custom_entry), cf); - g_free (cf); + g_settings_bind (dialog->settings, CUSTOM_FORMAT_KEY, + dialog->custom_entry, "text", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); if (prompt_type == USE_CUSTOM_FORMAT) { @@ -808,34 +811,14 @@ get_configure_dialog (XedTimePlugin *plugin) /* setup a window of a sane size. */ gtk_widget_set_size_request (GTK_WIDGET (viewport), 10, 200); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - content, FALSE, FALSE, 0); - g_object_unref (content); - gtk_container_set_border_width (GTK_CONTAINER (content), 5); + g_signal_connect (dialog->custom, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); + g_signal_connect (dialog->prompt, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); + g_signal_connect (dialog->use_list, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); + g_signal_connect (dialog->content, "destroy", G_CALLBACK (configure_dialog_destroyed), dialog); + g_signal_connect (dialog->custom_entry, "changed", G_CALLBACK (updated_custom_format_example), dialog->custom_format_example); - gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), - GTK_RESPONSE_OK); - - g_signal_connect (dialog->custom, - "toggled", - G_CALLBACK (configure_dialog_button_toggled), - dialog); - g_signal_connect (dialog->prompt, - "toggled", - G_CALLBACK (configure_dialog_button_toggled), - dialog); - g_signal_connect (dialog->use_list, - "toggled", - G_CALLBACK (configure_dialog_button_toggled), - dialog); - g_signal_connect (dialog->dialog, - "dispose", - G_CALLBACK (dialog_disposed), - dialog); - g_signal_connect (dialog->custom_entry, - "changed", - G_CALLBACK (updated_custom_format_example), - dialog->custom_format_example); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->list)); + g_signal_connect (selection, "changed", G_CALLBACK (configure_dialog_selection_changed), dialog); return dialog; } @@ -866,8 +849,8 @@ choose_format_dialog_row_activated (GtkTreeView *list, sel_format = get_format_from_list (dialog->list); the_time = get_time (formats[sel_format]); - set_prompt_type (dialog->plugin, PROMPT_SELECTED_FORMAT); - set_selected_format (dialog->plugin, formats[sel_format]); + set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT); + set_selected_format (dialog->settings, formats[sel_format]); g_return_if_fail (the_time != NULL); @@ -892,9 +875,10 @@ get_choose_format_dialog (GtkWindow *parent, if (parent != NULL) wg = gtk_window_get_group (parent); - dialog = g_new0 (ChooseFormatDialog, 1); + dialog = g_slice_new (ChooseFormatDialog); + dialog->settings = plugin->priv->settings; - data_dir = xed_plugin_get_data_dir (XED_PLUGIN (plugin)); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); ui_file = g_build_filename (data_dir, "xed-time-dialog.ui", NULL); ret = xed_utils_get_ui_objects (ui_file, NULL, @@ -991,8 +975,8 @@ get_choose_format_dialog (GtkWindow *parent, G_CALLBACK (choose_format_dialog_button_toggled), dialog); g_signal_connect (dialog->dialog, - "dispose", - G_CALLBACK (dialog_disposed), + "destroy", + G_CALLBACK (choose_format_dialog_destroyed), dialog); g_signal_connect (dialog->custom_entry, "changed", @@ -1037,8 +1021,8 @@ choose_format_dialog_response_cb (GtkWidget *widget, sel_format = get_format_from_list (dialog->list); the_time = get_time (formats[sel_format]); - set_prompt_type (dialog->plugin, PROMPT_SELECTED_FORMAT); - set_selected_format (dialog->plugin, formats[sel_format]); + set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT); + set_selected_format (dialog->settings, formats[sel_format]); } else { @@ -1047,8 +1031,8 @@ choose_format_dialog_response_cb (GtkWidget *widget, format = gtk_entry_get_text (GTK_ENTRY (dialog->custom_entry)); the_time = get_time (format); - set_prompt_type (dialog->plugin, PROMPT_CUSTOM_FORMAT); - set_custom_format (dialog->plugin, format); + set_prompt_type (dialog->settings, PROMPT_CUSTOM_FORMAT); + set_custom_format (dialog->settings, format); } g_return_if_fail (the_time != NULL); @@ -1066,29 +1050,31 @@ choose_format_dialog_response_cb (GtkWidget *widget, } static void -time_cb (GtkAction *action, - ActionData *data) +time_cb (GtkAction *action, + XedTimePlugin *plugin) { + XedWindow *window; GtkTextBuffer *buffer; gchar *the_time = NULL; XedTimePluginPromptType prompt_type; xed_debug (DEBUG_PLUGINS); - buffer = GTK_TEXT_BUFFER (xed_window_get_active_document (data->window)); + window = XED_WINDOW (plugin->priv->window); + buffer = GTK_TEXT_BUFFER (xed_window_get_active_document (window)); g_return_if_fail (buffer != NULL); - prompt_type = get_prompt_type (data->plugin); + prompt_type = get_prompt_type (plugin); if (prompt_type == USE_CUSTOM_FORMAT) { - gchar *cf = get_custom_format (data->plugin); + gchar *cf = get_custom_format (plugin); the_time = get_time (cf); g_free (cf); } else if (prompt_type == USE_SELECTED_FORMAT) { - gchar *sf = get_selected_format (data->plugin); + gchar *sf = get_selected_format (plugin); the_time = get_time (sf); g_free (sf); } @@ -1096,13 +1082,13 @@ time_cb (GtkAction *action, { ChooseFormatDialog *dialog; - dialog = get_choose_format_dialog (GTK_WINDOW (data->window), + dialog = get_choose_format_dialog (GTK_WINDOW (window), prompt_type, - data->plugin); + plugin); if (dialog != NULL) { dialog->buffer = buffer; - dialog->plugin = data->plugin; + dialog->settings = plugin->priv->settings; g_signal_connect (dialog->dialog, "response", @@ -1122,100 +1108,99 @@ time_cb (GtkAction *action, g_free (the_time); } -static void -ok_button_pressed (TimeConfigureDialog *dialog) -{ - gint sel_format; - const gchar *custom_format; - - xed_debug (DEBUG_PLUGINS); - - sel_format = get_format_from_list (dialog->list); - - custom_format = gtk_entry_get_text (GTK_ENTRY (dialog->custom_entry)); - - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->custom))) - { - set_prompt_type (dialog->plugin, USE_CUSTOM_FORMAT); - set_custom_format (dialog->plugin, custom_format); - } - else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list))) - { - set_prompt_type (dialog->plugin, USE_SELECTED_FORMAT); - set_selected_format (dialog->plugin, formats [sel_format]); - } - else - { - /* Default to prompt the user with the list selected */ - set_prompt_type (dialog->plugin, PROMPT_SELECTED_FORMAT); - } - - xed_debug_message (DEBUG_PLUGINS, "Sel: %d", sel_format); -} - -static void -configure_dialog_response_cb (GtkWidget *widget, - gint response, - TimeConfigureDialog *dialog) -{ - switch (response) - { - case GTK_RESPONSE_HELP: - { - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_HELP"); - - xed_help_display (GTK_WINDOW (widget), - NULL, - "xed-insert-date-time-plugin#xed-date-time-configure"); - break; - } - case GTK_RESPONSE_OK: - { - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK"); - - ok_button_pressed (dialog); - - gtk_widget_destroy (dialog->dialog); - break; - } - case GTK_RESPONSE_CANCEL: - { - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CANCEL"); - gtk_widget_destroy (dialog->dialog); - } - } -} - static GtkWidget * -impl_create_configure_dialog (XedPlugin *plugin) +xed_time_plugin_create_configure_widget (PeasGtkConfigurable *configurable) { TimeConfigureDialog *dialog; - dialog = get_configure_dialog (XED_TIME_PLUGIN (plugin)); + dialog = get_configure_dialog (XED_TIME_PLUGIN (configurable)); - dialog->plugin = XED_TIME_PLUGIN (plugin); + return dialog->content; +} - g_signal_connect (dialog->dialog, - "response", - G_CALLBACK (configure_dialog_response_cb), - dialog); +static void +xed_time_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + XedTimePlugin *plugin = XED_TIME_PLUGIN (object); - return GTK_WIDGET (dialog->dialog); + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +xed_time_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + XedTimePlugin *plugin = XED_TIME_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_time_plugin_class_init (XedTimePluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - XedPluginClass *plugin_class = XED_PLUGIN_CLASS (klass); object_class->finalize = xed_time_plugin_finalize; + object_class->dispose = xed_time_plugin_dispose; + object_class->set_property = xed_time_plugin_set_property; + object_class->get_property = xed_time_plugin_get_property; - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_update_ui; - - plugin_class->create_configure_dialog = impl_create_configure_dialog; + g_object_class_override_property (object_class, PROP_OBJECT, "object"); g_type_class_add_private (object_class, sizeof (XedTimePluginPrivate)); } + +static void +xed_time_plugin_class_finalize (XedTimePluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = xed_time_plugin_activate; + iface->deactivate = xed_time_plugin_deactivate; + iface->update_state = xed_time_plugin_update_state; +} + +static void +peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface) +{ + iface->create_configure_widget = xed_time_plugin_create_configure_widget; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + xed_time_plugin_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + XED_TYPE_TIME_PLUGIN); + + peas_object_module_register_extension_type (module, + PEAS_GTK_TYPE_CONFIGURABLE, + XED_TYPE_TIME_PLUGIN); +} diff --git a/plugins/time/xed-time-plugin.h b/plugins/time/xed-time-plugin.h index 41bf687..436ed05 100644 --- a/plugins/time/xed-time-plugin.h +++ b/plugins/time/xed-time-plugin.h @@ -1,6 +1,6 @@ /* * xed-time-plugin.h - * + * * Copyright (C) 2002-2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify @@ -25,53 +25,54 @@ #include #include -#include +#include +#include G_BEGIN_DECLS /* * Type checking and casting macros */ -#define XED_TYPE_TIME_PLUGIN (xed_time_plugin_get_type ()) -#define XED_TIME_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TIME_PLUGIN, XedTimePlugin)) -#define XED_TIME_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TIME_PLUGIN, XedTimePluginClass)) -#define XED_IS_TIME_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TIME_PLUGIN)) -#define XED_IS_TIME_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TIME_PLUGIN)) -#define XED_TIME_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_TIME_PLUGIN, XedTimePluginClass)) +#define XED_TYPE_TIME_PLUGIN (xed_time_plugin_get_type ()) +#define XED_TIME_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TIME_PLUGIN, XedTimePlugin)) +#define XED_TIME_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TIME_PLUGIN, XedTimePluginClass)) +#define XED_IS_TIME_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TIME_PLUGIN)) +#define XED_IS_TIME_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TIME_PLUGIN)) +#define XED_TIME_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_TIME_PLUGIN, XedTimePluginClass)) /* Private structure type */ -typedef struct _XedTimePluginPrivate XedTimePluginPrivate; +typedef struct _XedTimePluginPrivate XedTimePluginPrivate; /* * Main object structure */ -typedef struct _XedTimePlugin XedTimePlugin; +typedef struct _XedTimePlugin XedTimePlugin; struct _XedTimePlugin { - XedPlugin parent_instance; + PeasExtensionBase parent_instance; - /*< private >*/ - XedTimePluginPrivate *priv; + /*< private >*/ + XedTimePluginPrivate *priv; }; /* * Class definition */ -typedef struct _XedTimePluginClass XedTimePluginClass; +typedef struct _XedTimePluginClass XedTimePluginClass; struct _XedTimePluginClass { - XedPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* * Public methods */ -GType xed_time_plugin_get_type (void) G_GNUC_CONST; +GType xed_time_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_xed_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS From 9b3313efa7295ca1112f0266262d3e6f548e3ea1 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 13:58:16 -0800 Subject: [PATCH 036/132] trailsave-plugin: Port to libpeas Adapted from: https://github.com/mate-desktop/pluma/commit/ce25be232024458af2a28f4cf145d8cd22f2db29 --- plugins/trailsave/xed-trail-save-plugin.c | 138 +++++++++++++++++++--- plugins/trailsave/xed-trail-save-plugin.h | 33 ++++-- 2 files changed, 143 insertions(+), 28 deletions(-) diff --git a/plugins/trailsave/xed-trail-save-plugin.c b/plugins/trailsave/xed-trail-save-plugin.c index b237d5d..86f5914 100644 --- a/plugins/trailsave/xed-trail-save-plugin.c +++ b/plugins/trailsave/xed-trail-save-plugin.c @@ -22,9 +22,36 @@ #include #endif +#include + +#include +#include + #include "xed-trail-save-plugin.h" -XED_PLUGIN_REGISTER_TYPE(XedTrailSavePlugin, xed_trail_save_plugin) +#define XED_TRAIL_SAVE_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ + XED_TYPE_TRAIL_SAVE_PLUGIN, \ + XedTrailSavePluginPrivate)) + +static void peas_activatable_iface_init (PeasActivatableInterface *iface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedTrailSavePlugin, + xed_trail_save_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init)) + +struct _XedTrailSavePluginPrivate +{ + GtkWidget *window; +}; + +enum +{ + PROP_0, + PROP_OBJECT +}; static void strip_trailing_spaces (GtkTextBuffer *text_buffer) @@ -107,7 +134,7 @@ on_save (XedDocument *document, const gchar *uri, XedEncoding *encoding, XedDocumentSaveFlags save_flags, - XedPlugin *plugin) + XedTrailSavePlugin *plugin) { GtkTextBuffer *text_buffer = GTK_TEXT_BUFFER (document); @@ -117,7 +144,7 @@ on_save (XedDocument *document, static void on_tab_added (XedWindow *window, XedTab *tab, - XedPlugin *plugin) + XedTrailSavePlugin *plugin) { XedDocument *document; @@ -128,7 +155,7 @@ on_tab_added (XedWindow *window, static void on_tab_removed (XedWindow *window, XedTab *tab, - XedPlugin *plugin) + XedTrailSavePlugin *plugin) { XedDocument *document; @@ -137,15 +164,19 @@ on_tab_removed (XedWindow *window, } static void -impl_activate (XedPlugin *plugin, - XedWindow *window) +xed_trail_save_plugin_activate (PeasActivatable *activatable) { + XedTrailSavePlugin *plugin; + XedWindow *window; GList *documents; GList *documents_iter; XedDocument *document; xed_debug (DEBUG_PLUGINS); + plugin = XED_TRAIL_SAVE_PLUGIN (activatable); + window = XED_WINDOW (plugin->priv->window); + g_signal_connect (window, "tab_added", G_CALLBACK (on_tab_added), plugin); g_signal_connect (window, "tab_removed", G_CALLBACK (on_tab_removed), plugin); @@ -163,15 +194,19 @@ impl_activate (XedPlugin *plugin, } static void -impl_deactivate (XedPlugin *plugin, - XedWindow *window) +xed_trail_save_plugin_deactivate (PeasActivatable *activatable) { + XedTrailSavePlugin *plugin; + XedWindow *window; GList *documents; GList *documents_iter; XedDocument *document; xed_debug (DEBUG_PLUGINS); + plugin = XED_TRAIL_SAVE_PLUGIN (activatable); + window = XED_WINDOW (plugin->priv->window); + g_signal_handlers_disconnect_by_data (window, plugin); documents = xed_window_get_documents (window); @@ -191,24 +226,97 @@ static void xed_trail_save_plugin_init (XedTrailSavePlugin *plugin) { xed_debug_message (DEBUG_PLUGINS, "XedTrailSavePlugin initializing"); + + plugin->priv = XED_TRAIL_SAVE_PLUGIN_GET_PRIVATE (plugin); } static void -xed_trail_save_plugin_finalize (GObject *object) +xed_trail_save_plugin_dispose (GObject *object) { - xed_debug_message (DEBUG_PLUGINS, "XedTrailSavePlugin finalizing"); + XedTrailSavePlugin *plugin = XED_TRAIL_SAVE_PLUGIN (object); - G_OBJECT_CLASS (xed_trail_save_plugin_parent_class)->finalize (object); + xed_debug_message (DEBUG_PLUGINS, "XedTrailSavePlugin disposing"); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + G_OBJECT_CLASS (xed_trail_save_plugin_parent_class)->dispose (object); +} + +static void +xed_trail_save_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + XedTrailSavePlugin *plugin = XED_TRAIL_SAVE_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +xed_trail_save_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + XedTrailSavePlugin *plugin = XED_TRAIL_SAVE_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_trail_save_plugin_class_init (XedTrailSavePluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - XedPluginClass *plugin_class = XED_PLUGIN_CLASS (klass); - object_class->finalize = xed_trail_save_plugin_finalize; + object_class->dispose = xed_trail_save_plugin_dispose; + object_class->set_property = xed_trail_save_plugin_set_property; + object_class->get_property = xed_trail_save_plugin_get_property; - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; + g_object_class_override_property (object_class, PROP_OBJECT, "object"); + + g_type_class_add_private (object_class, sizeof (XedTrailSavePluginPrivate)); +} + +static void +xed_trail_save_plugin_class_finalize (XedTrailSavePluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = xed_trail_save_plugin_activate; + iface->deactivate = xed_trail_save_plugin_deactivate; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + xed_trail_save_plugin_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + XED_TYPE_TRAIL_SAVE_PLUGIN); } diff --git a/plugins/trailsave/xed-trail-save-plugin.h b/plugins/trailsave/xed-trail-save-plugin.h index d0ff1f3..8454fac 100644 --- a/plugins/trailsave/xed-trail-save-plugin.h +++ b/plugins/trailsave/xed-trail-save-plugin.h @@ -23,47 +23,54 @@ #include #include -#include +#include +#include G_BEGIN_DECLS /* * Type checking and casting macros */ -#define XED_TYPE_TRAIL_SAVE_PLUGIN (xed_trail_save_plugin_get_type ()) -#define XED_TRAIL_SAVE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TRAIL_SAVE_PLUGIN, XedTrailSavePlugin)) -#define XED_TRAIL_SAVE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TRAIL_SAVE_PLUGIN, XedTrailSavePluginClass)) -#define XED_IS_TRAIL_SAVE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TRAIL_SAVE_PLUGIN)) -#define XED_IS_TRAIL_SAVE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TRAIL_SAVE_PLUGIN)) -#define XED_TRAIL_SAVE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_TRAIL_SAVE_PLUGIN, XedTrailSavePluginClass)) +#define XED_TYPE_TRAIL_SAVE_PLUGIN (xed_trail_save_plugin_get_type ()) +#define XED_TRAIL_SAVE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TRAIL_SAVE_PLUGIN, XedTrailSavePlugin)) +#define XED_TRAIL_SAVE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TRAIL_SAVE_PLUGIN, XedTrailSavePluginClass)) +#define XED_IS_TRAIL_SAVE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TRAIL_SAVE_PLUGIN)) +#define XED_IS_TRAIL_SAVE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TRAIL_SAVE_PLUGIN)) +#define XED_TRAIL_SAVE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_TRAIL_SAVE_PLUGIN, XedTrailSavePluginClass)) + +/* Private structure type */ +typedef struct _XedTrailSavePluginPrivate XedTrailSavePluginPrivate; /* * Main object structure */ -typedef struct _XedTrailSavePlugin XedTrailSavePlugin; +typedef struct _XedTrailSavePlugin XedTrailSavePlugin; struct _XedTrailSavePlugin { - XedPlugin parent_instance; + PeasExtensionBase parent_instance; + + /*< private >*/ + XedTrailSavePluginPrivate *priv; }; /* * Class definition */ -typedef struct _XedTrailSavePluginClass XedTrailSavePluginClass; +typedef struct _XedTrailSavePluginClass XedTrailSavePluginClass; struct _XedTrailSavePluginClass { - XedPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* * Public methods */ -GType xed_trail_save_plugin_get_type (void) G_GNUC_CONST; +GType xed_trail_save_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_xed_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS From 89758101ccd0f88ff7c9df09535548cee216575e Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 16:12:05 -0800 Subject: [PATCH 037/132] plugins: Make them actually recognized and loaded by Xed Adapted from: https://github.com/mate-desktop/pluma/commit/e1fbe56adf49a5f4d3a3bb493933d9ae5a5c081f --- plugins/changecase/Makefile.am | 6 +++--- ...desktop.in => changecase.plugin.desktop.in} | 2 +- plugins/docinfo/Makefile.am | 6 +++--- ...in.desktop.in => docinfo.plugin.desktop.in} | 2 +- plugins/filebrowser/Makefile.am | 6 +++--- ...esktop.in => filebrowser.plugin.desktop.in} | 2 +- plugins/modelines/Makefile.am | 6 +++--- ....desktop.in => modelines.plugin.desktop.in} | 2 +- plugins/sort/Makefile.am | 8 ++++---- ...lugin.desktop.in => sort.plugin.desktop.in} | 2 +- plugins/spell/Makefile.am | 12 ++++++------ ...ugin.desktop.in => spell.plugin.desktop.in} | 2 +- plugins/taglist/Makefile.am | 8 ++++---- ...in.desktop.in => taglist.plugin.desktop.in} | 2 +- plugins/time/Makefile.am | 8 ++++---- ...lugin.desktop.in => time.plugin.desktop.in} | 2 +- plugins/trailsave/Makefile.am | 6 +++--- ....desktop.in => trailsave.plugin.desktop.in} | 2 +- po/POTFILES.in | 18 +++++++++--------- 19 files changed, 51 insertions(+), 51 deletions(-) rename plugins/changecase/{changecase.xed-plugin.desktop.in => changecase.plugin.desktop.in} (94%) rename plugins/docinfo/{docinfo.xed-plugin.desktop.in => docinfo.plugin.desktop.in} (95%) rename plugins/filebrowser/{filebrowser.xed-plugin.desktop.in => filebrowser.plugin.desktop.in} (95%) rename plugins/modelines/{modelines.xed-plugin.desktop.in => modelines.plugin.desktop.in} (94%) rename plugins/sort/{sort.xed-plugin.desktop.in => sort.plugin.desktop.in} (97%) rename plugins/spell/{spell.xed-plugin.desktop.in => spell.plugin.desktop.in} (94%) rename plugins/taglist/{taglist.xed-plugin.desktop.in => taglist.plugin.desktop.in} (95%) rename plugins/time/{time.xed-plugin.desktop.in => time.plugin.desktop.in} (95%) rename plugins/trailsave/{trailsave.xed-plugin.desktop.in => trailsave.plugin.desktop.in} (95%) diff --git a/plugins/changecase/Makefile.am b/plugins/changecase/Makefile.am index d4ad1a0..03ccaba 100644 --- a/plugins/changecase/Makefile.am +++ b/plugins/changecase/Makefile.am @@ -19,11 +19,11 @@ libchangecase_la_LIBADD = $(XED_LIBS) uidir = $(XED_PLUGINS_DATA_DIR)/changecase ui_DATA = -plugin_in_files = changecase.xed-plugin.desktop.in +plugin_in_files = changecase.plugin.desktop.in -%.xed-plugin: %.xed-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache -plugin_DATA = $(plugin_in_files:.xed-plugin.desktop.in=.xed-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) EXTRA_DIST = $(ui_DATA) $(plugin_in_files) diff --git a/plugins/changecase/changecase.xed-plugin.desktop.in b/plugins/changecase/changecase.plugin.desktop.in similarity index 94% rename from plugins/changecase/changecase.xed-plugin.desktop.in rename to plugins/changecase/changecase.plugin.desktop.in index 079ec7d..d1539d9 100644 --- a/plugins/changecase/changecase.xed-plugin.desktop.in +++ b/plugins/changecase/changecase.plugin.desktop.in @@ -1,4 +1,4 @@ -[Xed Plugin] +[Plugin] Module=changecase IAge=2 _Name=Change Case diff --git a/plugins/docinfo/Makefile.am b/plugins/docinfo/Makefile.am index 1fa6fbb..015cece 100644 --- a/plugins/docinfo/Makefile.am +++ b/plugins/docinfo/Makefile.am @@ -19,11 +19,11 @@ libdocinfo_la_LIBADD = $(XED_LIBS) uidir = $(XED_PLUGINS_DATA_DIR)/docinfo ui_DATA = docinfo.ui -plugin_in_files = docinfo.xed-plugin.desktop.in +plugin_in_files = docinfo.plugin.desktop.in -%.xed-plugin: %.xed-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache -plugin_DATA = $(plugin_in_files:.xed-plugin.desktop.in=.xed-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) EXTRA_DIST = $(ui_DATA) $(plugin_in_files) diff --git a/plugins/docinfo/docinfo.xed-plugin.desktop.in b/plugins/docinfo/docinfo.plugin.desktop.in similarity index 95% rename from plugins/docinfo/docinfo.xed-plugin.desktop.in rename to plugins/docinfo/docinfo.plugin.desktop.in index 944f628..b4da32b 100644 --- a/plugins/docinfo/docinfo.xed-plugin.desktop.in +++ b/plugins/docinfo/docinfo.plugin.desktop.in @@ -1,4 +1,4 @@ -[Xed Plugin] +[Plugin] Module=docinfo IAge=2 _Name=Document Statistics diff --git a/plugins/filebrowser/Makefile.am b/plugins/filebrowser/Makefile.am index 865b1de..9613fff 100644 --- a/plugins/filebrowser/Makefile.am +++ b/plugins/filebrowser/Makefile.am @@ -44,9 +44,9 @@ libfilebrowser_la_LIBADD = $(XED_LIBS) uidir = $(XED_PLUGINS_DATA_DIR)/filebrowser ui_DATA = xed-file-browser-widget-ui.xml -plugin_in_files = filebrowser.xed-plugin.desktop.in +plugin_in_files = filebrowser.plugin.desktop.in -%.xed-plugin: %.xed-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache xed-file-browser-enum-types.h: xed-file-browser-enum-types.h.template $(NOINST_H_FILES) $(GLIB_MKENUMS) (cd $(srcdir) && $(GLIB_MKENUMS) --template xed-file-browser-enum-types.h.template $(NOINST_H_FILES)) > $@ @@ -63,7 +63,7 @@ xed-file-browser-marshal.c: xed-file-browser-marshal.list $(GLIB_GENMARSHAL) $(AM_V_GEN) echo "#include \"xed-file-browser-marshal.h\"" > $@ && \ $(GLIB_GENMARSHAL) $< --body --prefix=xed_file_browser_marshal >> $@ -plugin_DATA = $(plugin_in_files:.xed-plugin.desktop.in=.xed-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) @INTLTOOL_XML_NOMERGE_RULE@ filebrowser_gschema_in = org.x.editor.plugins.filebrowser.gschema.xml.in diff --git a/plugins/filebrowser/filebrowser.xed-plugin.desktop.in b/plugins/filebrowser/filebrowser.plugin.desktop.in similarity index 95% rename from plugins/filebrowser/filebrowser.xed-plugin.desktop.in rename to plugins/filebrowser/filebrowser.plugin.desktop.in index 8ff3c73..625f2d0 100644 --- a/plugins/filebrowser/filebrowser.xed-plugin.desktop.in +++ b/plugins/filebrowser/filebrowser.plugin.desktop.in @@ -1,4 +1,4 @@ -[Xed Plugin] +[Plugin] Loader=C Module=filebrowser IAge=2 diff --git a/plugins/modelines/Makefile.am b/plugins/modelines/Makefile.am index 6485fe1..e3cdc0b 100644 --- a/plugins/modelines/Makefile.am +++ b/plugins/modelines/Makefile.am @@ -22,10 +22,10 @@ libmodelines_la_SOURCES = \ libmodelines_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS) libmodelines_la_LIBADD = $(XED_LIBS) -plugin_in_files = modelines.xed-plugin.desktop.in -%.xed-plugin: %.xed-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +plugin_in_files = modelines.plugin.desktop.in +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache -plugin_DATA = $(plugin_in_files:.xed-plugin.desktop.in=.xed-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) EXTRA_DIST = \ $(plugin_in_files) \ diff --git a/plugins/modelines/modelines.xed-plugin.desktop.in b/plugins/modelines/modelines.plugin.desktop.in similarity index 94% rename from plugins/modelines/modelines.xed-plugin.desktop.in rename to plugins/modelines/modelines.plugin.desktop.in index 70f7521..cfd5b42 100644 --- a/plugins/modelines/modelines.xed-plugin.desktop.in +++ b/plugins/modelines/modelines.plugin.desktop.in @@ -1,4 +1,4 @@ -[Xed Plugin] +[Plugin] Module=modelines IAge=2 _Name=Modelines diff --git a/plugins/sort/Makefile.am b/plugins/sort/Makefile.am index 1738e80..13e65f8 100644 --- a/plugins/sort/Makefile.am +++ b/plugins/sort/Makefile.am @@ -5,7 +5,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir) \ $(XED_CFLAGS) \ $(WARN_CFLAGS) \ - $(DISABLE_DEPRECATED_CFLAGS) + $(DISABLE_DEPRECATED_CFLAGS) plugin_LTLIBRARIES = libsort.la @@ -19,11 +19,11 @@ libsort_la_LIBADD = $(XED_LIBS) uidir = $(XED_PLUGINS_DATA_DIR)/sort ui_DATA = sort.ui -plugin_in_files = sort.xed-plugin.desktop.in +plugin_in_files = sort.plugin.desktop.in -%.xed-plugin: %.xed-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache -plugin_DATA = $(plugin_in_files:.xed-plugin.desktop.in=.xed-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) EXTRA_DIST = $(ui_DATA) $(plugin_in_files) diff --git a/plugins/sort/sort.xed-plugin.desktop.in b/plugins/sort/sort.plugin.desktop.in similarity index 97% rename from plugins/sort/sort.xed-plugin.desktop.in rename to plugins/sort/sort.plugin.desktop.in index 8cc189c..4b56701 100644 --- a/plugins/sort/sort.xed-plugin.desktop.in +++ b/plugins/sort/sort.plugin.desktop.in @@ -1,4 +1,4 @@ -[Xed Plugin] +[Plugin] Module=sort IAge=2 _Name=Sort diff --git a/plugins/spell/Makefile.am b/plugins/spell/Makefile.am index e9a9156..1afd0d3 100644 --- a/plugins/spell/Makefile.am +++ b/plugins/spell/Makefile.am @@ -6,7 +6,7 @@ AM_CPPFLAGS = \ $(XED_CFLAGS) \ $(ENCHANT_CFLAGS) \ $(WARN_CFLAGS) \ - $(DISABLE_DEPRECATED_CFLAGS) + $(DISABLE_DEPRECATED_CFLAGS) BUILT_SOURCES = \ xed-spell-marshal.c \ @@ -29,9 +29,9 @@ libspell_la_SOURCES = \ xed-automatic-spell-checker.h \ xed-spell-utils.c \ xed-spell-utils.h \ - $(BUILT_SOURCES) + $(BUILT_SOURCES) -libspell_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS) +libspell_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS) libspell_la_LIBADD = $(XED_LIBS) $(ENCHANT_LIBS) uidir = $(XED_PLUGINS_DATA_DIR)/spell @@ -44,11 +44,11 @@ xed-spell-marshal.c: xed-spell-marshal.list $(GLIB_GENMARSHAL) $(AM_V_GEN) echo "#include \"xed-spell-marshal.h\"" > $@ && \ $(GLIB_GENMARSHAL) $< --body --prefix=xed_marshal >> $@ -plugin_in_files = spell.xed-plugin.desktop.in +plugin_in_files = spell.plugin.desktop.in -%.xed-plugin: %.xed-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache -plugin_DATA = $(plugin_in_files:.xed-plugin.desktop.in=.xed-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) @INTLTOOL_XML_NOMERGE_RULE@ spell_gschema_in = org.x.editor.plugins.spell.gschema.xml.in diff --git a/plugins/spell/spell.xed-plugin.desktop.in b/plugins/spell/spell.plugin.desktop.in similarity index 94% rename from plugins/spell/spell.xed-plugin.desktop.in rename to plugins/spell/spell.plugin.desktop.in index d418daa..9ddb813 100644 --- a/plugins/spell/spell.xed-plugin.desktop.in +++ b/plugins/spell/spell.plugin.desktop.in @@ -1,4 +1,4 @@ -[Xed Plugin] +[Plugin] Module=spell IAge=2 _Name=Spell Checker diff --git a/plugins/taglist/Makefile.am b/plugins/taglist/Makefile.am index d4c4f02..124d427 100644 --- a/plugins/taglist/Makefile.am +++ b/plugins/taglist/Makefile.am @@ -15,7 +15,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir) \ $(XED_CFLAGS) \ $(WARN_CFLAGS) \ - $(DISABLE_DEPRECATED_CFLAGS) + $(DISABLE_DEPRECATED_CFLAGS) plugin_LTLIBRARIES = libtaglist.la @@ -30,9 +30,9 @@ libtaglist_la_SOURCES = \ libtaglist_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS) libtaglist_la_LIBADD = $(XED_LIBS) -plugin_in_files = taglist.xed-plugin.desktop.in +plugin_in_files = taglist.plugin.desktop.in -%.xed-plugin: %.xed-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache GZIP_ENV = -9 @@ -41,7 +41,7 @@ GZIP_ENV = -9 LC_ALL=C $(INTLTOOL_MERGE) $(top_srcdir)/po $< $(@:.gz=) -x -u -c $(top_builddir)/po/.intltool-merge-cache GZIP=$(GZIP_ENV) gzip -n -f $(@:.gz=) -plugin_DATA = $(plugin_in_files:.xed-plugin.desktop.in=.xed-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) EXTRA_DIST = \ $(taglist_in_files) $(taglist_DATA) \ diff --git a/plugins/taglist/taglist.xed-plugin.desktop.in b/plugins/taglist/taglist.plugin.desktop.in similarity index 95% rename from plugins/taglist/taglist.xed-plugin.desktop.in rename to plugins/taglist/taglist.plugin.desktop.in index 774adcb..00b0795 100644 --- a/plugins/taglist/taglist.xed-plugin.desktop.in +++ b/plugins/taglist/taglist.plugin.desktop.in @@ -1,4 +1,4 @@ -[Xed Plugin] +[Plugin] Module=taglist IAge=2 _Name=Tag list diff --git a/plugins/time/Makefile.am b/plugins/time/Makefile.am index afd1e26..808aef0 100644 --- a/plugins/time/Makefile.am +++ b/plugins/time/Makefile.am @@ -5,7 +5,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir) \ $(XED_CFLAGS) \ $(WARN_CFLAGS) \ - $(DISABLE_DEPRECATED_CFLAGS) + $(DISABLE_DEPRECATED_CFLAGS) plugin_LTLIBRARIES = libtime.la @@ -21,11 +21,11 @@ ui_DATA = \ xed-time-dialog.ui \ xed-time-setup-dialog.ui -plugin_in_files = time.xed-plugin.desktop.in +plugin_in_files = time.plugin.desktop.in -%.xed-plugin: %.xed-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache -plugin_DATA = $(plugin_in_files:.xed-plugin.desktop.in=.xed-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) @INTLTOOL_XML_NOMERGE_RULE@ time_gschema_in = org.x.editor.plugins.time.gschema.xml.in diff --git a/plugins/time/time.xed-plugin.desktop.in b/plugins/time/time.plugin.desktop.in similarity index 95% rename from plugins/time/time.xed-plugin.desktop.in rename to plugins/time/time.plugin.desktop.in index aaaa6ed..a59f208 100644 --- a/plugins/time/time.xed-plugin.desktop.in +++ b/plugins/time/time.plugin.desktop.in @@ -1,4 +1,4 @@ -[Xed Plugin] +[Plugin] Module=time IAge=2 _Name=Insert Date/Time diff --git a/plugins/trailsave/Makefile.am b/plugins/trailsave/Makefile.am index 77b99be..5705584 100644 --- a/plugins/trailsave/Makefile.am +++ b/plugins/trailsave/Makefile.am @@ -16,11 +16,11 @@ libtrailsave_la_SOURCES = \ libtrailsave_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS) libtrailsave_la_LIBADD = $(XED_LIBS) -plugin_in_files = trailsave.xed-plugin.desktop.in +plugin_in_files = trailsave.plugin.desktop.in -%.xed-plugin: %.xed-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache -plugin_DATA = $(plugin_in_files:.xed-plugin.desktop.in=.xed-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) EXTRA_DIST = $(plugin_in_files) diff --git a/plugins/trailsave/trailsave.xed-plugin.desktop.in b/plugins/trailsave/trailsave.plugin.desktop.in similarity index 95% rename from plugins/trailsave/trailsave.xed-plugin.desktop.in rename to plugins/trailsave/trailsave.plugin.desktop.in index d6a647a..b212431 100644 --- a/plugins/trailsave/trailsave.xed-plugin.desktop.in +++ b/plugins/trailsave/trailsave.plugin.desktop.in @@ -1,4 +1,4 @@ -[Xed Plugin] +[Plugin] Module=trailsave IAge=2 _Name=Save Without Trailing Spaces diff --git a/po/POTFILES.in b/po/POTFILES.in index 0885337..3cf8b13 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -45,21 +45,21 @@ xed/xed-ui.xml xed/xed-utils.c xed/xed-view.c xed/xed-window.c -plugins/changecase/changecase.xed-plugin.desktop.in +plugins/changecase/changecase.plugin.desktop.in plugins/changecase/xed-changecase-plugin.c -plugins/docinfo/docinfo.xed-plugin.desktop.in +plugins/docinfo/docinfo.plugin.desktop.in [type: gettext/glade]plugins/docinfo/docinfo.ui plugins/docinfo/xed-docinfo-plugin.c -plugins/filebrowser/filebrowser.xed-plugin.desktop.in +plugins/filebrowser/filebrowser.plugin.desktop.in [type: gettext/gsettings]plugins/filebrowser/org.x.editor.plugins.filebrowser.gschema.xml.in plugins/filebrowser/xed-file-bookmarks-store.c plugins/filebrowser/xed-file-browser-plugin.c plugins/filebrowser/xed-file-browser-store.c plugins/filebrowser/xed-file-browser-view.c plugins/filebrowser/xed-file-browser-widget.c -plugins/modelines/modelines.xed-plugin.desktop.in +plugins/modelines/modelines.plugin.desktop.in plugins/sort/xed-sort-plugin.c -plugins/sort/sort.xed-plugin.desktop.in +plugins/sort/sort.plugin.desktop.in [type: gettext/glade]plugins/sort/sort.ui [type: gettext/gsettings]plugins/spell/org.x.editor.plugins.spell.gschema.xml.in plugins/spell/xed-automatic-spell-checker.c @@ -71,18 +71,18 @@ plugins/spell/xed-spell-plugin.c [type: gettext/glade]plugins/spell/languages-dialog.ui [type: gettext/glade]plugins/spell/spell-checker.ui [type: gettext/glade]plugins/spell/xed-spell-setup-dialog.ui -plugins/spell/spell.xed-plugin.desktop.in +plugins/spell/spell.plugin.desktop.in plugins/taglist/xed-taglist-plugin.c plugins/taglist/xed-taglist-plugin-panel.c plugins/taglist/xed-taglist-plugin-parser.c plugins/taglist/HTML.tags.xml.in plugins/taglist/Latex.tags.xml.in -plugins/taglist/taglist.xed-plugin.desktop.in +plugins/taglist/taglist.plugin.desktop.in plugins/taglist/XSLT.tags.xml.in plugins/taglist/XUL.tags.xml.in [type: gettext/gsettings]plugins/time/org.x.editor.plugins.time.gschema.xml.in plugins/time/xed-time-plugin.c -plugins/time/time.xed-plugin.desktop.in -plugins/trailsave/trailsave.xed-plugin.desktop.in +plugins/time/time.plugin.desktop.in +plugins/trailsave/trailsave.plugin.desktop.in [type: gettext/glade]plugins/time/xed-time-dialog.ui [type: gettext/glade]plugins/time/xed-time-setup-dialog.ui From f314622cf0bf373d19ccfad1e46fe48757506867 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 18:49:12 -0800 Subject: [PATCH 038/132] Remove old plugin system and docs for it Adapted from: https://github.com/mate-desktop/pluma/commit/3860e7b99fc652c7d193cf81f565ea56b507b51a#diff-c949f93d03f44a4217d7a138f9e2e54a --- Makefile.am | 2 +- configure.ac | 4 - debian/control | 1 + debian/rules | 1 - debian/xed.install | 1 - docs/reference/Makefile.am | 2 - docs/reference/xed-docs.sgml | 3 +- docs/reference/xed-sections.txt | 24 - docs/reference/xed.types | 2 - plugin-loaders/Makefile.am | 3 - plugin-loaders/c/Makefile.am | 24 - plugin-loaders/c/xed-plugin-loader-c.c | 182 ----- plugin-loaders/c/xed-plugin-loader-c.h | 60 -- po/POTFILES.in | 1 - xed/xed-object-module.c | 343 ---------- xed/xed-object-module.h | 94 --- xed/xed-plugin-info-priv.h | 67 -- xed/xed-plugin-info.c | 396 ----------- xed/xed-plugin-info.h | 63 -- xed/xed-plugin-loader.c | 131 ---- xed/xed-plugin-loader.h | 106 --- xed/xed-plugin-manager.c | 893 ------------------------- xed/xed-plugin-manager.h | 83 --- xed/xed-plugin.c | 334 --------- xed/xed-plugin.h | 240 ------- 25 files changed, 3 insertions(+), 3057 deletions(-) delete mode 100644 plugin-loaders/Makefile.am delete mode 100644 plugin-loaders/c/Makefile.am delete mode 100644 plugin-loaders/c/xed-plugin-loader-c.c delete mode 100644 plugin-loaders/c/xed-plugin-loader-c.h delete mode 100644 xed/xed-object-module.c delete mode 100644 xed/xed-object-module.h delete mode 100644 xed/xed-plugin-info-priv.h delete mode 100644 xed/xed-plugin-info.c delete mode 100644 xed/xed-plugin-info.h delete mode 100644 xed/xed-plugin-loader.c delete mode 100644 xed/xed-plugin-loader.h delete mode 100644 xed/xed-plugin-manager.c delete mode 100644 xed/xed-plugin-manager.h delete mode 100644 xed/xed-plugin.c delete mode 100644 xed/xed-plugin.h diff --git a/Makefile.am b/Makefile.am index 28f1d33..10d8f88 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} -SUBDIRS = xed pixmaps po data plugin-loaders plugins docs help +SUBDIRS = xed pixmaps po data plugins docs help if ENABLE_TESTS SUBDIRS += tests diff --git a/configure.ac b/configure.ac index 9b900d0..77ffa4e 100644 --- a/configure.ac +++ b/configure.ac @@ -221,10 +221,8 @@ AC_ARG_ENABLE([tests], AM_CONDITIONAL(ENABLE_TESTS, test x$enable_tests = xyes) PLUGIN_LIBTOOL_FLAGS="-module -avoid-version" -LOADER_LIBTOOL_FLAGS="-module -avoid-version" AC_SUBST(PLUGIN_LIBTOOL_FLAGS) -AC_SUBST(LOADER_LIBTOOL_FLAGS) XED_PLUGINS_DATA_DIR="$datadir/xed/plugins" AC_SUBST(XED_PLUGINS_DATA_DIR) @@ -248,8 +246,6 @@ xed/smclient/Makefile xed/Makefile help/Makefile pixmaps/Makefile -plugin-loaders/Makefile -plugin-loaders/c/Makefile plugins/Makefile plugins/changecase/Makefile plugins/docinfo/Makefile diff --git a/debian/control b/debian/control index 7dfecfe..a3e97b3 100644 --- a/debian/control +++ b/debian/control @@ -13,6 +13,7 @@ Build-Depends: autotools-dev, libglib2.0-dev, libgtk-3-dev, libgtksourceview-3.0-dev, + libpeas-dev, libsm-dev, libx11-dev, libxml2-dev, diff --git a/debian/rules b/debian/rules index 9088701..e9f4ad1 100755 --- a/debian/rules +++ b/debian/rules @@ -6,7 +6,6 @@ DHFLAGS=--parallel dh $@ $(DHFLAGS) override_dh_install: - rm -rfv debian/tmp/usr/lib/*/xed/plugin-loaders/*.la rm -rfv debian/tmp/usr/lib/*/xed/plugins/*.la dh_install --fail-missing diff --git a/debian/xed.install b/debian/xed.install index 6bdd29d..4135f88 100644 --- a/debian/xed.install +++ b/debian/xed.install @@ -1,5 +1,4 @@ usr/bin/ -usr/lib/*/xed/plugin-loaders/*.so usr/lib/*/xed/plugins/ usr/lib/xed/xed-bugreport.sh usr/share/applications/ diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am index a890721..9321582 100644 --- a/docs/reference/Makefile.am +++ b/docs/reference/Makefile.am @@ -46,8 +46,6 @@ IGNORE_HFILES= \ xed-documents-panel.h \ xed-io-error-message-area.h \ xed-languages-manager.h \ - xed-object-module.h \ - xed-plugin-manager.h \ xed-plugins-engine.h \ xed-prefs-manager-private.h \ xed-session.h \ diff --git a/docs/reference/xed-docs.sgml b/docs/reference/xed-docs.sgml index 8259134..6ec388c 100644 --- a/docs/reference/xed-docs.sgml +++ b/docs/reference/xed-docs.sgml @@ -1,5 +1,5 @@ - @@ -17,7 +17,6 @@ - diff --git a/docs/reference/xed-sections.txt b/docs/reference/xed-sections.txt index dac318e..8b8dd1a 100644 --- a/docs/reference/xed-sections.txt +++ b/docs/reference/xed-sections.txt @@ -236,30 +236,6 @@ XED_IS_PANEL_CLASS XED_PANEL_GET_CLASS -
-xed-plugin -XedPlugin -XedPlugin -xed_plugin_activate -xed_plugin_deactivate -xed_plugin_update_ui -xed_plugin_is_configurable -xed_plugin_create_configure_dialog -XED_PLUGIN_REGISTER_TYPE - -XED_PLUGIN -XED_IS_PLUGIN -XED_TYPE_PLUGIN -xed_plugin_get_type -XED_PLUGIN_CLASS -XED_IS_PLUGIN_CLASS -XED_PLUGIN_GET_CLASS -XED_PLUGIN_REGISTER_TYPE_WITH_CODE -XED_PLUGIN_REGISTER_TYPE -XED_PLUGIN_DEFINE_TYPE_WITH_CODE -XED_PLUGIN_DEFINE_TYPE -
-
xed-print-job-preview XedPrintJobPreviewPrivate diff --git a/docs/reference/xed.types b/docs/reference/xed.types index a47ea4a..ce31662 100644 --- a/docs/reference/xed.types +++ b/docs/reference/xed.types @@ -8,7 +8,6 @@ #include "xed-message-type.h" #include "xed-notebook.h" #include "xed-panel.h" -#include "xed-plugin.h" #include "xed-progress-message-area.h" #include "xed-statusbar.h" #include "xed-tab.h" @@ -24,7 +23,6 @@ xed_message_bus_get_type xed_message_type_get_type xed_notebook_get_type xed_panel_get_type -xed_plugin_get_type xed_progress_message_area_get_type xed_statusbar_get_type xed_tab_get_type diff --git a/plugin-loaders/Makefile.am b/plugin-loaders/Makefile.am deleted file mode 100644 index 2573ec3..0000000 --- a/plugin-loaders/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = c - --include $(top_srcdir)/git.mk diff --git a/plugin-loaders/c/Makefile.am b/plugin-loaders/c/Makefile.am deleted file mode 100644 index b25782c..0000000 --- a/plugin-loaders/c/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ -# C plugin loader - -loaderdir = $(libdir)/xed/plugin-loaders - -AM_CPPFLAGS = \ - -I$(top_srcdir) \ - $(XED_CFLAGS) \ - $(WARN_CFLAGS) \ - $(DISABLE_DEPRECATED_CFLAGS) \ - -DXED_LOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\" - -loader_LTLIBRARIES = libcloader.la - -NOINST_H_FILES = \ - xed-plugin-loader-c.h - -libcloader_la_SOURCES = \ - xed-plugin-loader-c.c \ - $(NOINST_H_FILES) - -libcloader_la_LDFLAGS = $(LOADER_LIBTOOL_FLAGS) -libcloader_la_LIBADD = $(XED_LIBS) - --include $(top_srcdir)/git.mk diff --git a/plugin-loaders/c/xed-plugin-loader-c.c b/plugin-loaders/c/xed-plugin-loader-c.c deleted file mode 100644 index 86db43a..0000000 --- a/plugin-loaders/c/xed-plugin-loader-c.c +++ /dev/null @@ -1,182 +0,0 @@ -/* - * xed-plugin-loader-c.c - * This file is part of xed - * - * Copyright (C) 2008 - Jesse van den Kieboom - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "xed-plugin-loader-c.h" -#include - -#define XED_PLUGIN_LOADER_C_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), XED_TYPE_PLUGIN_LOADER_C, XedPluginLoaderCPrivate)) - -struct _XedPluginLoaderCPrivate -{ - GHashTable *loaded_plugins; -}; - -static void xed_plugin_loader_iface_init (gpointer g_iface, gpointer iface_data); - -XED_PLUGIN_LOADER_REGISTER_TYPE (XedPluginLoaderC, xed_plugin_loader_c, G_TYPE_OBJECT, xed_plugin_loader_iface_init); - - -static const gchar * -xed_plugin_loader_iface_get_id (void) -{ - return "C"; -} - -static XedPlugin * -xed_plugin_loader_iface_load (XedPluginLoader *loader, - XedPluginInfo *info, - const gchar *path) -{ - XedPluginLoaderC *cloader = XED_PLUGIN_LOADER_C (loader); - XedObjectModule *module; - const gchar *module_name; - XedPlugin *result; - - module = (XedObjectModule *)g_hash_table_lookup (cloader->priv->loaded_plugins, info); - module_name = xed_plugin_info_get_module_name (info); - - if (module == NULL) - { - /* For now we force all modules to be resident */ - module = xed_object_module_new (module_name, - path, - "register_xed_plugin", - TRUE); - - /* Infos are available for all the lifetime of the loader. - * If this changes, we should use weak refs or something */ - - g_hash_table_insert (cloader->priv->loaded_plugins, info, module); - } - - if (!g_type_module_use (G_TYPE_MODULE (module))) - { - g_warning ("Could not load plugin module: %s", xed_plugin_info_get_name (info)); - - return NULL; - } - - /* TODO: for now we force data-dir-name = module-name... if needed we can - * add a datadir field to the plugin descriptor file. - */ - result = (XedPlugin *)xed_object_module_new_object (module, - "install-dir", path, - "data-dir-name", module_name, - NULL); - - if (!result) - { - g_warning ("Could not create plugin object: %s", xed_plugin_info_get_name (info)); - g_type_module_unuse (G_TYPE_MODULE (module)); - - return NULL; - } - - g_type_module_unuse (G_TYPE_MODULE (module)); - - return result; -} - -static void -xed_plugin_loader_iface_unload (XedPluginLoader *loader, - XedPluginInfo *info) -{ - //XedPluginLoaderC *cloader = XED_PLUGIN_LOADER_C (loader); - - /* this is a no-op, since the type module will be properly unused as - the last reference to the plugin dies. When the plugin is activated - again, the library will be reloaded */ -} - -static void -xed_plugin_loader_iface_init (gpointer g_iface, - gpointer iface_data) -{ - XedPluginLoaderInterface *iface = (XedPluginLoaderInterface *)g_iface; - - iface->get_id = xed_plugin_loader_iface_get_id; - iface->load = xed_plugin_loader_iface_load; - iface->unload = xed_plugin_loader_iface_unload; -} - -static void -xed_plugin_loader_c_finalize (GObject *object) -{ - XedPluginLoaderC *cloader = XED_PLUGIN_LOADER_C (object); - GList *infos; - GList *item; - - /* FIXME: this sanity check it's not efficient. Let's remove it - * once we are confident with the code */ - - infos = g_hash_table_get_keys (cloader->priv->loaded_plugins); - - for (item = infos; item; item = item->next) - { - XedPluginInfo *info = (XedPluginInfo *)item->data; - - if (xed_plugin_info_is_active (info)) - { - g_warning ("There are still C plugins loaded during destruction"); - break; - } - } - - g_list_free (infos); - - g_hash_table_destroy (cloader->priv->loaded_plugins); - - G_OBJECT_CLASS (xed_plugin_loader_c_parent_class)->finalize (object); -} - -static void -xed_plugin_loader_c_class_init (XedPluginLoaderCClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = xed_plugin_loader_c_finalize; - - g_type_class_add_private (object_class, sizeof (XedPluginLoaderCPrivate)); -} - -static void -xed_plugin_loader_c_class_finalize (XedPluginLoaderCClass *klass) -{ -} - -static void -xed_plugin_loader_c_init (XedPluginLoaderC *self) -{ - self->priv = XED_PLUGIN_LOADER_C_GET_PRIVATE (self); - - /* loaded_plugins maps XedPluginInfo to a XedObjectModule */ - self->priv->loaded_plugins = g_hash_table_new (g_direct_hash, - g_direct_equal); -} - -XedPluginLoaderC * -xed_plugin_loader_c_new () -{ - GObject *loader = g_object_new (XED_TYPE_PLUGIN_LOADER_C, NULL); - - return XED_PLUGIN_LOADER_C (loader); -} diff --git a/plugin-loaders/c/xed-plugin-loader-c.h b/plugin-loaders/c/xed-plugin-loader-c.h deleted file mode 100644 index e6c3b02..0000000 --- a/plugin-loaders/c/xed-plugin-loader-c.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * xed-plugin-loader-c.h - * This file is part of xed - * - * Copyright (C) 2008 - Jesse van den Kieboom - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __XED_PLUGIN_LOADER_C_H__ -#define __XED_PLUGIN_LOADER_C_H__ - -#include - -G_BEGIN_DECLS - -#define XED_TYPE_PLUGIN_LOADER_C (xed_plugin_loader_c_get_type ()) -#define XED_PLUGIN_LOADER_C(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_PLUGIN_LOADER_C, XedPluginLoaderC)) -#define XED_PLUGIN_LOADER_C_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_PLUGIN_LOADER_C, XedPluginLoaderC const)) -#define XED_PLUGIN_LOADER_C_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_PLUGIN_LOADER_C, XedPluginLoaderCClass)) -#define XED_IS_PLUGIN_LOADER_C(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_PLUGIN_LOADER_C)) -#define XED_IS_PLUGIN_LOADER_C_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_PLUGIN_LOADER_C)) -#define XED_PLUGIN_LOADER_C_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_PLUGIN_LOADER_C, XedPluginLoaderCClass)) - -typedef struct _XedPluginLoaderC XedPluginLoaderC; -typedef struct _XedPluginLoaderCClass XedPluginLoaderCClass; -typedef struct _XedPluginLoaderCPrivate XedPluginLoaderCPrivate; - -struct _XedPluginLoaderC { - GObject parent; - - XedPluginLoaderCPrivate *priv; -}; - -struct _XedPluginLoaderCClass { - GObjectClass parent_class; -}; - -GType xed_plugin_loader_c_get_type (void) G_GNUC_CONST; -XedPluginLoaderC *xed_plugin_loader_c_new(void); - -/* All the loaders must implement this function */ -G_MODULE_EXPORT GType register_xed_plugin_loader (GTypeModule * module); - -G_END_DECLS - -#endif /* __XED_PLUGIN_LOADER_C_H__ */ diff --git a/po/POTFILES.in b/po/POTFILES.in index 3cf8b13..31510e8 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -27,7 +27,6 @@ xed/xed-help.c xed/xed-io-error-message-area.c xed/xed-notebook.c xed/xed-panel.c -xed/xed-plugin-manager.c xed/xed-plugins-engine.c xed/xed-prefs-manager.c xed/xed-print-job.c diff --git a/xed/xed-object-module.c b/xed/xed-object-module.c deleted file mode 100644 index 236c320..0000000 --- a/xed/xed-object-module.c +++ /dev/null @@ -1,343 +0,0 @@ -/* - * xed-object-module.c - * This file is part of xed - * - * Copyright (C) 2005 - Paolo Maggi - * Copyright (C) 2008 - Jesse van den Kieboom - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* This is a modified version of ephy-module.c from Epiphany source code. - * Here the original copyright assignment: - * - * Copyright (C) 2003 Marco Pesenti Gritti - * Copyright (C) 2003, 2004 Christian Persch - * - */ - -/* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id: xed-module.c 6314 2008-06-05 12:57:53Z pborelli $ - */ - -#include "config.h" - -#include "xed-object-module.h" -#include "xed-debug.h" - -typedef GType (*XedObjectModuleRegisterFunc) (GTypeModule *); - -enum { - PROP_0, - PROP_MODULE_NAME, - PROP_PATH, - PROP_TYPE_REGISTRATION, - PROP_RESIDENT -}; - -struct _XedObjectModulePrivate -{ - GModule *library; - - GType type; - gchar *path; - gchar *module_name; - gchar *type_registration; - - gboolean resident; -}; - -G_DEFINE_TYPE (XedObjectModule, xed_object_module, G_TYPE_TYPE_MODULE); - -static gboolean -xed_object_module_load (GTypeModule *gmodule) -{ - XedObjectModule *module = XED_OBJECT_MODULE (gmodule); - XedObjectModuleRegisterFunc register_func; - gchar *path; - - xed_debug_message (DEBUG_PLUGINS, "Loading %s module from %s", - module->priv->module_name, module->priv->path); - - path = g_module_build_path (module->priv->path, module->priv->module_name); - g_return_val_if_fail (path != NULL, FALSE); - xed_debug_message (DEBUG_PLUGINS, "Module filename: %s", path); - - module->priv->library = g_module_open (path, - G_MODULE_BIND_LAZY); - g_free (path); - - if (module->priv->library == NULL) - { - g_warning ("%s: %s", module->priv->module_name, g_module_error()); - - return FALSE; - } - - /* extract symbols from the lib */ - if (!g_module_symbol (module->priv->library, module->priv->type_registration, - (void *) ®ister_func)) - { - g_warning ("%s: %s", module->priv->module_name, g_module_error()); - g_module_close (module->priv->library); - - return FALSE; - } - - /* symbol can still be NULL even though g_module_symbol - * returned TRUE */ - if (register_func == NULL) - { - g_warning ("Symbol '%s' should not be NULL", module->priv->type_registration); - g_module_close (module->priv->library); - - return FALSE; - } - - module->priv->type = register_func (gmodule); - - if (module->priv->type == 0) - { - g_warning ("Invalid object contained by module %s", module->priv->module_name); - return FALSE; - } - - if (module->priv->resident) - { - g_module_make_resident (module->priv->library); - } - - return TRUE; -} - -static void -xed_object_module_unload (GTypeModule *gmodule) -{ - XedObjectModule *module = XED_OBJECT_MODULE (gmodule); - - xed_debug_message (DEBUG_PLUGINS, "Unloading %s", module->priv->path); - - g_module_close (module->priv->library); - - module->priv->library = NULL; - module->priv->type = 0; -} - -static void -xed_object_module_init (XedObjectModule *module) -{ - xed_debug_message (DEBUG_PLUGINS, "XedObjectModule %p initialising", module); - - module->priv = G_TYPE_INSTANCE_GET_PRIVATE (module, - XED_TYPE_OBJECT_MODULE, - XedObjectModulePrivate); -} - -static void -xed_object_module_finalize (GObject *object) -{ - XedObjectModule *module = XED_OBJECT_MODULE (object); - - xed_debug_message (DEBUG_PLUGINS, "XedObjectModule %p finalising", module); - - g_free (module->priv->path); - g_free (module->priv->module_name); - g_free (module->priv->type_registration); - - G_OBJECT_CLASS (xed_object_module_parent_class)->finalize (object); -} - -static void -xed_object_module_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - XedObjectModule *module = XED_OBJECT_MODULE (object); - - switch (prop_id) - { - case PROP_MODULE_NAME: - g_value_set_string (value, module->priv->module_name); - break; - case PROP_PATH: - g_value_set_string (value, module->priv->path); - break; - case PROP_TYPE_REGISTRATION: - g_value_set_string (value, module->priv->type_registration); - break; - case PROP_RESIDENT: - g_value_set_boolean (value, module->priv->resident); - break; - default: - g_return_if_reached (); - } -} - -static void -xed_object_module_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - XedObjectModule *module = XED_OBJECT_MODULE (object); - - switch (prop_id) - { - case PROP_MODULE_NAME: - module->priv->module_name = g_value_dup_string (value); - g_type_module_set_name (G_TYPE_MODULE (object), - module->priv->module_name); - break; - case PROP_PATH: - module->priv->path = g_value_dup_string (value); - break; - case PROP_TYPE_REGISTRATION: - module->priv->type_registration = g_value_dup_string (value); - break; - case PROP_RESIDENT: - module->priv->resident = g_value_get_boolean (value); - break; - default: - g_return_if_reached (); - } -} - -static void -xed_object_module_class_init (XedObjectModuleClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (klass); - - object_class->set_property = xed_object_module_set_property; - object_class->get_property = xed_object_module_get_property; - object_class->finalize = xed_object_module_finalize; - - module_class->load = xed_object_module_load; - module_class->unload = xed_object_module_unload; - - g_object_class_install_property (object_class, - PROP_MODULE_NAME, - g_param_spec_string ("module-name", - "Module Name", - "The module to load for this object", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, - PROP_PATH, - g_param_spec_string ("path", - "Path", - "The path to use when loading this module", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, - PROP_TYPE_REGISTRATION, - g_param_spec_string ("type-registration", - "Type Registration", - "The name of the type registration function", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, - PROP_RESIDENT, - g_param_spec_boolean ("resident", - "Resident", - "Whether the module is resident", - FALSE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - - g_type_class_add_private (klass, sizeof (XedObjectModulePrivate)); -} - -XedObjectModule * -xed_object_module_new (const gchar *module_name, - const gchar *path, - const gchar *type_registration, - gboolean resident) -{ - return (XedObjectModule *)g_object_new (XED_TYPE_OBJECT_MODULE, - "module-name", - module_name, - "path", - path, - "type-registration", - type_registration, - "resident", - resident, - NULL); -} - -GObject * -xed_object_module_new_object (XedObjectModule *module, - const gchar *first_property_name, - ...) -{ - va_list var_args; - GObject *result; - - g_return_val_if_fail (module->priv->type != 0, NULL); - - xed_debug_message (DEBUG_PLUGINS, "Creating object of type %s", - g_type_name (module->priv->type)); - - va_start (var_args, first_property_name); - result = g_object_new_valist (module->priv->type, first_property_name, var_args); - va_end (var_args); - - return result; -} - -const gchar * -xed_object_module_get_path (XedObjectModule *module) -{ - g_return_val_if_fail (XED_IS_OBJECT_MODULE (module), NULL); - - return module->priv->path; -} - -const gchar * -xed_object_module_get_module_name (XedObjectModule *module) -{ - g_return_val_if_fail (XED_IS_OBJECT_MODULE (module), NULL); - - return module->priv->module_name; -} - -const gchar * -xed_object_module_get_type_registration (XedObjectModule *module) -{ - g_return_val_if_fail (XED_IS_OBJECT_MODULE (module), NULL); - - return module->priv->type_registration; -} - -GType -xed_object_module_get_object_type (XedObjectModule *module) -{ - g_return_val_if_fail (XED_IS_OBJECT_MODULE (module), 0); - - return module->priv->type; -} diff --git a/xed/xed-object-module.h b/xed/xed-object-module.h deleted file mode 100644 index 1258deb..0000000 --- a/xed/xed-object-module.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * xed-object-module.h - * This file is part of xed - * - * Copyright (C) 2005 - Paolo Maggi - * Copyright (C) 2008 - Jesse van den Kieboom - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* This is a modified version of xed-module.h from Epiphany source code. - * Here the original copyright assignment: - * - * Copyright (C) 2003 Marco Pesenti Gritti - * Copyright (C) 2003, 2004 Christian Persch - * - */ - -/* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id: xed-module.h 6263 2008-05-05 10:52:10Z sfre $ - */ - -#ifndef __XED_OBJECT_MODULE_H__ -#define __XED_OBJECT_MODULE_H__ - -#include -#include -#include - -G_BEGIN_DECLS - -#define XED_TYPE_OBJECT_MODULE (xed_object_module_get_type ()) -#define XED_OBJECT_MODULE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_OBJECT_MODULE, XedObjectModule)) -#define XED_OBJECT_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_OBJECT_MODULE, XedObjectModuleClass)) -#define XED_IS_OBJECT_MODULE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_OBJECT_MODULE)) -#define XED_IS_OBJECT_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_OBJECT_MODULE)) -#define XED_OBJECT_MODULE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_OBJECT_MODULE, XedObjectModuleClass)) - -typedef struct _XedObjectModule XedObjectModule; -typedef struct _XedObjectModulePrivate XedObjectModulePrivate; - -struct _XedObjectModule -{ - GTypeModule parent; - - XedObjectModulePrivate *priv; -}; - -typedef struct _XedObjectModuleClass XedObjectModuleClass; - -struct _XedObjectModuleClass -{ - GTypeModuleClass parent_class; - - /* Virtual class methods */ - void (* garbage_collect) (); -}; - -GType xed_object_module_get_type (void) G_GNUC_CONST; - -XedObjectModule *xed_object_module_new (const gchar *module_name, - const gchar *path, - const gchar *type_registration, - gboolean resident); - -GObject *xed_object_module_new_object (XedObjectModule *module, - const gchar *first_property_name, - ...); - -GType xed_object_module_get_object_type (XedObjectModule *module); -const gchar *xed_object_module_get_path (XedObjectModule *module); -const gchar *xed_object_module_get_module_name (XedObjectModule *module); -const gchar *xed_object_module_get_type_registration (XedObjectModule *module); - -G_END_DECLS - -#endif diff --git a/xed/xed-plugin-info-priv.h b/xed/xed-plugin-info-priv.h deleted file mode 100644 index 79d8742..0000000 --- a/xed/xed-plugin-info-priv.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * xed-plugin-info-priv.h - * This file is part of xed - * - * Copyright (C) 2002-2005 - Paolo Maggi - * Copyright (C) 2007 - Paolo Maggi, Steve Frécinaux - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2002-2007. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#ifndef __XED_PLUGIN_INFO_PRIV_H__ -#define __XED_PLUGIN_INFO_PRIV_H__ - -#include "xed-plugin-info.h" -#include "xed-plugin.h" - -struct _XedPluginInfo -{ - gint refcount; - - XedPlugin *plugin; - gchar *file; - - gchar *module_name; - gchar *loader; - gchar **dependencies; - - gchar *name; - gchar *desc; - gchar *icon_name; - gchar **authors; - gchar *copyright; - gchar *website; - gchar *version; - - /* A plugin is unavailable if it is not possible to activate it - due to an error loading the plugin module */ - gint available : 1; -}; - -XedPluginInfo *_xed_plugin_info_new (const gchar *file); -void _xed_plugin_info_ref (XedPluginInfo *info); -void _xed_plugin_info_unref (XedPluginInfo *info); - - -#endif /* __XED_PLUGIN_INFO_PRIV_H__ */ diff --git a/xed/xed-plugin-info.c b/xed/xed-plugin-info.c deleted file mode 100644 index aa6f249..0000000 --- a/xed/xed-plugin-info.c +++ /dev/null @@ -1,396 +0,0 @@ -/* - * xed-plugin-info.c - * This file is part of xed - * - * Copyright (C) 2002-2005 - Paolo Maggi - * Copyright (C) 2007 - Paolo Maggi, Steve Frécinaux - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2002-2007. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#include "xed-plugin-info.h" -#include "xed-plugin-info-priv.h" -#include "xed-debug.h" -#include "xed-plugin.h" - -void -_xed_plugin_info_ref (XedPluginInfo *info) -{ - g_atomic_int_inc (&info->refcount); -} - -static XedPluginInfo * -xed_plugin_info_copy (XedPluginInfo *info) -{ - _xed_plugin_info_ref (info); - return info; -} - -void -_xed_plugin_info_unref (XedPluginInfo *info) -{ - if (!g_atomic_int_dec_and_test (&info->refcount)) - return; - - if (info->plugin != NULL) - { - xed_debug_message (DEBUG_PLUGINS, "Unref plugin %s", info->name); - - g_object_unref (info->plugin); - } - - g_free (info->file); - g_free (info->module_name); - g_strfreev (info->dependencies); - g_free (info->name); - g_free (info->desc); - g_free (info->icon_name); - g_free (info->website); - g_free (info->copyright); - g_free (info->loader); - g_free (info->version); - g_strfreev (info->authors); - - g_free (info); -} - -/** - * xed_plugin_info_get_type: - * - * Retrieves the #GType object which is associated with the #XedPluginInfo - * class. - * - * Return value: the GType associated with #XedPluginInfo. - **/ -GType -xed_plugin_info_get_type (void) -{ - static GType the_type = 0; - - if (G_UNLIKELY (!the_type)) - the_type = g_boxed_type_register_static ( - "XedPluginInfo", - (GBoxedCopyFunc) xed_plugin_info_copy, - (GBoxedFreeFunc) _xed_plugin_info_unref); - - return the_type; -} - -/** - * xed_plugin_info_new: - * @filename: the filename where to read the plugin information - * - * Creates a new #XedPluginInfo from a file on the disk. - * - * Return value: a newly created #XedPluginInfo. - */ -XedPluginInfo * -_xed_plugin_info_new (const gchar *file) -{ - XedPluginInfo *info; - GKeyFile *plugin_file = NULL; - gchar *str; - - g_return_val_if_fail (file != NULL, NULL); - - xed_debug_message (DEBUG_PLUGINS, "Loading plugin: %s", file); - - info = g_new0 (XedPluginInfo, 1); - info->refcount = 1; - info->file = g_strdup (file); - - plugin_file = g_key_file_new (); - if (!g_key_file_load_from_file (plugin_file, file, G_KEY_FILE_NONE, NULL)) - { - g_warning ("Bad plugin file: %s", file); - goto error; - } - - if (!g_key_file_has_key (plugin_file, - "Xed Plugin", - "IAge", - NULL)) - { - xed_debug_message (DEBUG_PLUGINS, - "IAge key does not exist in file: %s", file); - goto error; - } - - /* Check IAge=2 */ - if (g_key_file_get_integer (plugin_file, - "Xed Plugin", - "IAge", - NULL) != 2) - { - xed_debug_message (DEBUG_PLUGINS, - "Wrong IAge in file: %s", file); - goto error; - } - - /* Get module name */ - str = g_key_file_get_string (plugin_file, - "Xed Plugin", - "Module", - NULL); - - if ((str != NULL) && (*str != '\0')) - { - info->module_name = str; - } - else - { - g_warning ("Could not find 'Module' in %s", file); - g_free (str); - goto error; - } - - /* Get the dependency list */ - info->dependencies = g_key_file_get_string_list (plugin_file, - "Xed Plugin", - "Depends", - NULL, - NULL); - if (info->dependencies == NULL) - { - xed_debug_message (DEBUG_PLUGINS, "Could not find 'Depends' in %s", file); - info->dependencies = g_new0 (gchar *, 1); - } - - /* Get the loader for this plugin */ - str = g_key_file_get_string (plugin_file, - "Xed Plugin", - "Loader", - NULL); - - if ((str != NULL) && (*str != '\0')) - { - info->loader = str; - } - else - { - /* default to the C loader */ - info->loader = g_strdup("c"); - g_free (str); - } - - /* Get Name */ - str = g_key_file_get_locale_string (plugin_file, - "Xed Plugin", - "Name", - NULL, NULL); - if (str) - info->name = str; - else - { - g_warning ("Could not find 'Name' in %s", file); - goto error; - } - - /* Get Description */ - str = g_key_file_get_locale_string (plugin_file, - "Xed Plugin", - "Description", - NULL, NULL); - if (str) - info->desc = str; - else - xed_debug_message (DEBUG_PLUGINS, "Could not find 'Description' in %s", file); - - /* Get Icon */ - str = g_key_file_get_locale_string (plugin_file, - "Xed Plugin", - "Icon", - NULL, NULL); - if (str) - info->icon_name = str; - else - xed_debug_message (DEBUG_PLUGINS, "Could not find 'Icon' in %s, using 'xed-plugin'", file); - - - /* Get Authors */ - info->authors = g_key_file_get_string_list (plugin_file, - "Xed Plugin", - "Authors", - NULL, - NULL); - if (info->authors == NULL) - xed_debug_message (DEBUG_PLUGINS, "Could not find 'Authors' in %s", file); - - - /* Get Copyright */ - str = g_key_file_get_string (plugin_file, - "Xed Plugin", - "Copyright", - NULL); - if (str) - info->copyright = str; - else - xed_debug_message (DEBUG_PLUGINS, "Could not find 'Copyright' in %s", file); - - /* Get Website */ - str = g_key_file_get_string (plugin_file, - "Xed Plugin", - "Website", - NULL); - if (str) - info->website = str; - else - xed_debug_message (DEBUG_PLUGINS, "Could not find 'Website' in %s", file); - - /* Get Version */ - str = g_key_file_get_string (plugin_file, - "Xed Plugin", - "Version", - NULL); - if (str) - info->version = str; - else - xed_debug_message (DEBUG_PLUGINS, "Could not find 'Version' in %s", file); - - g_key_file_free (plugin_file); - - /* If we know nothing about the availability of the plugin, - set it as available */ - info->available = TRUE; - - return info; - -error: - g_free (info->file); - g_free (info->module_name); - g_free (info->name); - g_free (info->loader); - g_free (info); - g_key_file_free (plugin_file); - - return NULL; -} - -gboolean -xed_plugin_info_is_active (XedPluginInfo *info) -{ - g_return_val_if_fail (info != NULL, FALSE); - - return info->available && info->plugin != NULL; -} - -gboolean -xed_plugin_info_is_available (XedPluginInfo *info) -{ - g_return_val_if_fail (info != NULL, FALSE); - - return info->available != FALSE; -} - -gboolean -xed_plugin_info_is_configurable (XedPluginInfo *info) -{ - xed_debug_message (DEBUG_PLUGINS, "Is '%s' configurable?", info->name); - - g_return_val_if_fail (info != NULL, FALSE); - - if (info->plugin == NULL || !info->available) - return FALSE; - - return xed_plugin_is_configurable (info->plugin); -} - -const gchar * -xed_plugin_info_get_module_name (XedPluginInfo *info) -{ - g_return_val_if_fail (info != NULL, NULL); - - return info->module_name; -} - -const gchar * -xed_plugin_info_get_name (XedPluginInfo *info) -{ - g_return_val_if_fail (info != NULL, NULL); - - return info->name; -} - -const gchar * -xed_plugin_info_get_description (XedPluginInfo *info) -{ - g_return_val_if_fail (info != NULL, NULL); - - return info->desc; -} - -const gchar * -xed_plugin_info_get_icon_name (XedPluginInfo *info) -{ - g_return_val_if_fail (info != NULL, NULL); - - /* use the xed-plugin icon as a default if the plugin does not - have its own */ - if (info->icon_name != NULL && - gtk_icon_theme_has_icon (gtk_icon_theme_get_default (), - info->icon_name)) - return info->icon_name; - else - return "xed-plugin"; -} - -const gchar ** -xed_plugin_info_get_authors (XedPluginInfo *info) -{ - g_return_val_if_fail (info != NULL, (const gchar **)NULL); - - return (const gchar **) info->authors; -} - -const gchar * -xed_plugin_info_get_website (XedPluginInfo *info) -{ - g_return_val_if_fail (info != NULL, NULL); - - return info->website; -} - -const gchar * -xed_plugin_info_get_copyright (XedPluginInfo *info) -{ - g_return_val_if_fail (info != NULL, NULL); - - return info->copyright; -} - -const gchar * -xed_plugin_info_get_version (XedPluginInfo *info) -{ - g_return_val_if_fail (info != NULL, NULL); - - return info->version; -} diff --git a/xed/xed-plugin-info.h b/xed/xed-plugin-info.h deleted file mode 100644 index b8e4395..0000000 --- a/xed/xed-plugin-info.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * xed-plugin-info.h - * This file is part of xed - * - * Copyright (C) 2002-2005 - Paolo Maggi - * Copyright (C) 2007 - Paolo Maggi, Steve Frécinaux - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2002-2007. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#ifndef __XED_PLUGIN_INFO_H__ -#define __XED_PLUGIN_INFO_H__ - -#include - -G_BEGIN_DECLS - -#define XED_TYPE_PLUGIN_INFO (xed_plugin_info_get_type ()) -#define XED_PLUGIN_INFO(obj) ((XedPluginInfo *) (obj)) - -typedef struct _XedPluginInfo XedPluginInfo; - -GType xed_plugin_info_get_type (void) G_GNUC_CONST; - -gboolean xed_plugin_info_is_active (XedPluginInfo *info); -gboolean xed_plugin_info_is_available (XedPluginInfo *info); -gboolean xed_plugin_info_is_configurable (XedPluginInfo *info); - -const gchar *xed_plugin_info_get_module_name (XedPluginInfo *info); - -const gchar *xed_plugin_info_get_name (XedPluginInfo *info); -const gchar *xed_plugin_info_get_description (XedPluginInfo *info); -const gchar *xed_plugin_info_get_icon_name (XedPluginInfo *info); -const gchar **xed_plugin_info_get_authors (XedPluginInfo *info); -const gchar *xed_plugin_info_get_website (XedPluginInfo *info); -const gchar *xed_plugin_info_get_copyright (XedPluginInfo *info); -const gchar *xed_plugin_info_get_version (XedPluginInfo *info); - -G_END_DECLS - -#endif /* __XED_PLUGIN_INFO_H__ */ - diff --git a/xed/xed-plugin-loader.c b/xed/xed-plugin-loader.c deleted file mode 100644 index 1c7e728..0000000 --- a/xed/xed-plugin-loader.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * xed-plugin-loader.c - * This file is part of xed - * - * Copyright (C) 2008 - Jesse van den Kieboom - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "xed-plugin-loader.h" - -static void -xed_plugin_loader_base_init (gpointer g_class) -{ - static gboolean initialized = FALSE; - - if (G_UNLIKELY (!initialized)) - { - /* create interface signals here. */ - initialized = TRUE; - } -} - -GType -xed_plugin_loader_get_type (void) -{ - static GType type = 0; - - if (G_UNLIKELY (type == 0)) - { - static const GTypeInfo info = - { - sizeof (XedPluginLoaderInterface), - xed_plugin_loader_base_init, /* base_init */ - NULL, /* base_finalize */ - NULL, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - 0, - 0, /* n_preallocs */ - NULL /* instance_init */ - }; - - type = g_type_register_static (G_TYPE_INTERFACE, "XedPluginLoader", &info, 0); - } - - return type; -} - -const gchar * -xed_plugin_loader_type_get_id (GType type) -{ - GTypeClass *klass; - XedPluginLoaderInterface *iface; - - klass = g_type_class_ref (type); - - if (klass == NULL) - { - g_warning ("Could not get class info for plugin loader"); - return NULL; - } - - iface = g_type_interface_peek (klass, XED_TYPE_PLUGIN_LOADER); - - if (iface == NULL) - { - g_warning ("Could not get plugin loader interface"); - g_type_class_unref (klass); - - return NULL; - } - - g_return_val_if_fail (iface->get_id != NULL, NULL); - return iface->get_id (); -} - -XedPlugin * -xed_plugin_loader_load (XedPluginLoader *loader, - XedPluginInfo *info, - const gchar *path) -{ - XedPluginLoaderInterface *iface; - - g_return_val_if_fail (XED_IS_PLUGIN_LOADER (loader), NULL); - - iface = XED_PLUGIN_LOADER_GET_INTERFACE (loader); - g_return_val_if_fail (iface->load != NULL, NULL); - - return iface->load (loader, info, path); -} - -void -xed_plugin_loader_unload (XedPluginLoader *loader, - XedPluginInfo *info) -{ - XedPluginLoaderInterface *iface; - - g_return_if_fail (XED_IS_PLUGIN_LOADER (loader)); - - iface = XED_PLUGIN_LOADER_GET_INTERFACE (loader); - g_return_if_fail (iface->unload != NULL); - - iface->unload (loader, info); -} - -void -xed_plugin_loader_garbage_collect (XedPluginLoader *loader) -{ - XedPluginLoaderInterface *iface; - - g_return_if_fail (XED_IS_PLUGIN_LOADER (loader)); - - iface = XED_PLUGIN_LOADER_GET_INTERFACE (loader); - - if (iface->garbage_collect != NULL) - iface->garbage_collect (loader); -} diff --git a/xed/xed-plugin-loader.h b/xed/xed-plugin-loader.h deleted file mode 100644 index d30fb25..0000000 --- a/xed/xed-plugin-loader.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * xed-plugin-loader.h - * This file is part of xed - * - * Copyright (C) 2008 - Jesse van den Kieboom - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __XED_PLUGIN_LOADER_H__ -#define __XED_PLUGIN_LOADER_H__ - -#include -#include -#include - -G_BEGIN_DECLS - -#define XED_TYPE_PLUGIN_LOADER (xed_plugin_loader_get_type ()) -#define XED_PLUGIN_LOADER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_PLUGIN_LOADER, XedPluginLoader)) -#define XED_IS_PLUGIN_LOADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_PLUGIN_LOADER)) -#define XED_PLUGIN_LOADER_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), XED_TYPE_PLUGIN_LOADER, XedPluginLoaderInterface)) - -typedef struct _XedPluginLoader XedPluginLoader; /* dummy object */ -typedef struct _XedPluginLoaderInterface XedPluginLoaderInterface; - -struct _XedPluginLoaderInterface { - GTypeInterface parent; - - const gchar *(*get_id) (void); - - XedPlugin *(*load) (XedPluginLoader *loader, - XedPluginInfo *info, - const gchar *path); - - void (*unload) (XedPluginLoader *loader, - XedPluginInfo *info); - - void (*garbage_collect) (XedPluginLoader *loader); -}; - -GType xed_plugin_loader_get_type (void); - -const gchar *xed_plugin_loader_type_get_id (GType type); -XedPlugin *xed_plugin_loader_load (XedPluginLoader *loader, - XedPluginInfo *info, - const gchar *path); -void xed_plugin_loader_unload (XedPluginLoader *loader, - XedPluginInfo *info); -void xed_plugin_loader_garbage_collect (XedPluginLoader *loader); - -/** - * XED_PLUGIN_LOADER_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init): - * - * Utility macro used to register interfaces for gobject types in plugin loaders. - */ -#define XED_PLUGIN_LOADER_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) \ - const GInterfaceInfo g_implement_interface_info = \ - { \ - (GInterfaceInitFunc) iface_init, \ - NULL, \ - NULL \ - }; \ - \ - g_type_module_add_interface (type_module, \ - g_define_type_id, \ - TYPE_IFACE, \ - &g_implement_interface_info); - -/** - * XED_PLUGIN_LOADER_REGISTER_TYPE(PluginLoaderName, plugin_loader_name, PARENT_TYPE, loader_interface_init): - * - * Utility macro used to register plugin loaders. - */ -#define XED_PLUGIN_LOADER_REGISTER_TYPE(PluginLoaderName, plugin_loader_name, PARENT_TYPE, loader_iface_init) \ - G_DEFINE_DYNAMIC_TYPE_EXTENDED (PluginLoaderName, \ - plugin_loader_name, \ - PARENT_TYPE, \ - 0, \ - XED_PLUGIN_LOADER_IMPLEMENT_INTERFACE(XED_TYPE_PLUGIN_LOADER, loader_iface_init)); \ - \ - \ -G_MODULE_EXPORT GType \ -register_xed_plugin_loader (GTypeModule *type_module) \ -{ \ - plugin_loader_name##_register_type (type_module); \ - \ - return plugin_loader_name##_get_type(); \ -} - -G_END_DECLS - -#endif /* __XED_PLUGIN_LOADER_H__ */ diff --git a/xed/xed-plugin-manager.c b/xed/xed-plugin-manager.c deleted file mode 100644 index 7365614..0000000 --- a/xed/xed-plugin-manager.c +++ /dev/null @@ -1,893 +0,0 @@ -/* - * xed-plugin-manager.c - * This file is part of xed - * - * Copyright (C) 2002 Paolo Maggi and James Willcox - * Copyright (C) 2003-2006 Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 1998-2006. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include - -#include "xed-plugin-manager.h" -#include "xed-utils.h" -#include "xed-plugins-engine.h" -#include "xed-plugin.h" -#include "xed-debug.h" - -enum -{ - ACTIVE_COLUMN, - AVAILABLE_COLUMN, - INFO_COLUMN, - N_COLUMNS -}; - -#define PLUGIN_MANAGER_NAME_TITLE _("Plugin") -#define PLUGIN_MANAGER_ACTIVE_TITLE _("Enabled") - -#define XED_PLUGIN_MANAGER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_PLUGIN_MANAGER, XedPluginManagerPrivate)) - -struct _XedPluginManagerPrivate -{ - GtkWidget *tree; - - GtkWidget *about_button; - GtkWidget *configure_button; - - XedPluginsEngine *engine; - - GtkWidget *about; - - GtkWidget *popup_menu; -}; - -G_DEFINE_TYPE(XedPluginManager, xed_plugin_manager, GTK_TYPE_BOX) - -static XedPluginInfo *plugin_manager_get_selected_plugin (XedPluginManager *pm); -static void plugin_manager_toggle_active (XedPluginManager *pm, GtkTreeIter *iter, GtkTreeModel *model); -static void xed_plugin_manager_finalize (GObject *object); - -static void -xed_plugin_manager_class_init (XedPluginManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = xed_plugin_manager_finalize; - - g_type_class_add_private (object_class, sizeof (XedPluginManagerPrivate)); -} - -static void -about_button_cb (GtkWidget *button, - XedPluginManager *pm) -{ - XedPluginInfo *info; - - xed_debug (DEBUG_PLUGINS); - - info = plugin_manager_get_selected_plugin (pm); - - g_return_if_fail (info != NULL); - - /* if there is another about dialog already open destroy it */ - if (pm->priv->about) - gtk_widget_destroy (pm->priv->about); - - pm->priv->about = g_object_new (GTK_TYPE_ABOUT_DIALOG, - "program-name", xed_plugin_info_get_name (info), - "copyright", xed_plugin_info_get_copyright (info), - "authors", xed_plugin_info_get_authors (info), - "comments", xed_plugin_info_get_description (info), - "website", xed_plugin_info_get_website (info), - "logo-icon-name", xed_plugin_info_get_icon_name (info), - "version", xed_plugin_info_get_version (info), - NULL); - - gtk_window_set_destroy_with_parent (GTK_WINDOW (pm->priv->about), - TRUE); - - g_signal_connect (pm->priv->about, - "response", - G_CALLBACK (gtk_widget_destroy), - NULL); - g_signal_connect (pm->priv->about, - "destroy", - G_CALLBACK (gtk_widget_destroyed), - &pm->priv->about); - - gtk_window_set_transient_for (GTK_WINDOW (pm->priv->about), - GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET(pm)))); - gtk_widget_show (pm->priv->about); -} - -static void -configure_button_cb (GtkWidget *button, - XedPluginManager *pm) -{ - XedPluginInfo *info; - GtkWindow *toplevel; - - xed_debug (DEBUG_PLUGINS); - - info = plugin_manager_get_selected_plugin (pm); - - g_return_if_fail (info != NULL); - - xed_debug_message (DEBUG_PLUGINS, "Configuring: %s\n", - xed_plugin_info_get_name (info)); - - toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET(pm))); - - xed_plugins_engine_configure_plugin (pm->priv->engine, - info, toplevel); - - xed_debug_message (DEBUG_PLUGINS, "Done"); -} - -static void -plugin_manager_view_info_cell_cb (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell, - GtkTreeModel *tree_model, - GtkTreeIter *iter, - gpointer data) -{ - XedPluginInfo *info; - gchar *text; - - g_return_if_fail (tree_model != NULL); - g_return_if_fail (tree_column != NULL); - - gtk_tree_model_get (tree_model, iter, INFO_COLUMN, &info, -1); - - if (info == NULL) - return; - - text = g_markup_printf_escaped ("%s\n%s", - xed_plugin_info_get_name (info), - xed_plugin_info_get_description (info)); - g_object_set (G_OBJECT (cell), - "markup", text, - "sensitive", xed_plugin_info_is_available (info), - NULL); - - g_free (text); -} - -static void -plugin_manager_view_icon_cell_cb (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell, - GtkTreeModel *tree_model, - GtkTreeIter *iter, - gpointer data) -{ - XedPluginInfo *info; - - g_return_if_fail (tree_model != NULL); - g_return_if_fail (tree_column != NULL); - - gtk_tree_model_get (tree_model, iter, INFO_COLUMN, &info, -1); - - if (info == NULL) - return; - - g_object_set (G_OBJECT (cell), - "icon-name", xed_plugin_info_get_icon_name (info), - "sensitive", xed_plugin_info_is_available (info), - NULL); -} - - -static void -active_toggled_cb (GtkCellRendererToggle *cell, - gchar *path_str, - XedPluginManager *pm) -{ - GtkTreeIter iter; - GtkTreePath *path; - GtkTreeModel *model; - - xed_debug (DEBUG_PLUGINS); - - path = gtk_tree_path_new_from_string (path_str); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (pm->priv->tree)); - g_return_if_fail (model != NULL); - - gtk_tree_model_get_iter (model, &iter, path); - - if (&iter != NULL) - plugin_manager_toggle_active (pm, &iter, model); - - gtk_tree_path_free (path); -} - -static void -cursor_changed_cb (GtkTreeView *view, - gpointer data) -{ - XedPluginManager *pm = data; - XedPluginInfo *info; - - xed_debug (DEBUG_PLUGINS); - - info = plugin_manager_get_selected_plugin (pm); - - gtk_widget_set_sensitive (GTK_WIDGET (pm->priv->about_button), - info != NULL); - gtk_widget_set_sensitive (GTK_WIDGET (pm->priv->configure_button), - (info != NULL) && - xed_plugin_info_is_configurable (info)); -} - -static void -row_activated_cb (GtkTreeView *tree_view, - GtkTreePath *path, - GtkTreeViewColumn *column, - gpointer data) -{ - XedPluginManager *pm = data; - GtkTreeIter iter; - GtkTreeModel *model; - - xed_debug (DEBUG_PLUGINS); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (pm->priv->tree)); - - g_return_if_fail (model != NULL); - - gtk_tree_model_get_iter (model, &iter, path); - - g_return_if_fail (&iter != NULL); - - plugin_manager_toggle_active (pm, &iter, model); -} - -static void -plugin_manager_populate_lists (XedPluginManager *pm) -{ - const GList *plugins; - GtkListStore *model; - GtkTreeIter iter; - - xed_debug (DEBUG_PLUGINS); - - plugins = xed_plugins_engine_get_plugin_list (pm->priv->engine); - - model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (pm->priv->tree))); - - while (plugins) - { - XedPluginInfo *info; - info = (XedPluginInfo *)plugins->data; - - gtk_list_store_append (model, &iter); - gtk_list_store_set (model, &iter, - ACTIVE_COLUMN, xed_plugin_info_is_active (info), - AVAILABLE_COLUMN, xed_plugin_info_is_available (info), - INFO_COLUMN, info, - -1); - - plugins = plugins->next; - } - - if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) - { - GtkTreeSelection *selection; - XedPluginInfo* info; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (pm->priv->tree)); - g_return_if_fail (selection != NULL); - - gtk_tree_selection_select_iter (selection, &iter); - - gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, - INFO_COLUMN, &info, -1); - - gtk_widget_set_sensitive (GTK_WIDGET (pm->priv->configure_button), - xed_plugin_info_is_configurable (info)); - } -} - -static gboolean -plugin_manager_set_active (XedPluginManager *pm, - GtkTreeIter *iter, - GtkTreeModel *model, - gboolean active) -{ - XedPluginInfo *info; - gboolean res = TRUE; - - xed_debug (DEBUG_PLUGINS); - - gtk_tree_model_get (model, iter, INFO_COLUMN, &info, -1); - - g_return_val_if_fail (info != NULL, FALSE); - - if (active) - { - /* activate the plugin */ - if (!xed_plugins_engine_activate_plugin (pm->priv->engine, info)) { - xed_debug_message (DEBUG_PLUGINS, "Could not activate %s.\n", - xed_plugin_info_get_name (info)); - - res = FALSE; - } - } - else - { - /* deactivate the plugin */ - if (!xed_plugins_engine_deactivate_plugin (pm->priv->engine, info)) { - xed_debug_message (DEBUG_PLUGINS, "Could not deactivate %s.\n", - xed_plugin_info_get_name (info)); - - res = FALSE; - } - } - - return res; -} - -static void -plugin_manager_toggle_active (XedPluginManager *pm, - GtkTreeIter *iter, - GtkTreeModel *model) -{ - gboolean active; - - xed_debug (DEBUG_PLUGINS); - - gtk_tree_model_get (model, iter, ACTIVE_COLUMN, &active, -1); - - active ^= 1; - - plugin_manager_set_active (pm, iter, model, active); -} - -static XedPluginInfo * -plugin_manager_get_selected_plugin (XedPluginManager *pm) -{ - XedPluginInfo *info = NULL; - GtkTreeModel *model; - GtkTreeIter iter; - GtkTreeSelection *selection; - - xed_debug (DEBUG_PLUGINS); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (pm->priv->tree)); - g_return_val_if_fail (model != NULL, NULL); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (pm->priv->tree)); - g_return_val_if_fail (selection != NULL, NULL); - - if (gtk_tree_selection_get_selected (selection, NULL, &iter)) - { - gtk_tree_model_get (model, &iter, INFO_COLUMN, &info, -1); - } - - return info; -} - -static void -plugin_manager_set_active_all (XedPluginManager *pm, - gboolean active) -{ - GtkTreeModel *model; - GtkTreeIter iter; - - xed_debug (DEBUG_PLUGINS); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (pm->priv->tree)); - - g_return_if_fail (model != NULL); - - gtk_tree_model_get_iter_first (model, &iter); - - do { - plugin_manager_set_active (pm, &iter, model, active); - } - while (gtk_tree_model_iter_next (model, &iter)); -} - -/* Callback used as the interactive search comparison function */ -static gboolean -name_search_cb (GtkTreeModel *model, - gint column, - const gchar *key, - GtkTreeIter *iter, - gpointer data) -{ - XedPluginInfo *info; - gchar *normalized_string; - gchar *normalized_key; - gchar *case_normalized_string; - gchar *case_normalized_key; - gint key_len; - gboolean retval; - - gtk_tree_model_get (model, iter, INFO_COLUMN, &info, -1); - if (!info) - return FALSE; - - normalized_string = g_utf8_normalize (xed_plugin_info_get_name (info), -1, G_NORMALIZE_ALL); - normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL); - case_normalized_string = g_utf8_casefold (normalized_string, -1); - case_normalized_key = g_utf8_casefold (normalized_key, -1); - - key_len = strlen (case_normalized_key); - - /* Oddly enough, this callback must return whether to stop the search - * because we found a match, not whether we actually matched. - */ - retval = (strncmp (case_normalized_key, case_normalized_string, key_len) != 0); - - g_free (normalized_key); - g_free (normalized_string); - g_free (case_normalized_key); - g_free (case_normalized_string); - - return retval; -} - -static void -enable_plugin_menu_cb (GtkMenu *menu, - XedPluginManager *pm) -{ - GtkTreeModel *model; - GtkTreeIter iter; - GtkTreeSelection *selection; - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (pm->priv->tree)); - g_return_if_fail (model != NULL); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (pm->priv->tree)); - g_return_if_fail (selection != NULL); - - if (gtk_tree_selection_get_selected (selection, NULL, &iter)) - plugin_manager_toggle_active (pm, &iter, model); -} - -static void -enable_all_menu_cb (GtkMenu *menu, - XedPluginManager *pm) -{ - plugin_manager_set_active_all (pm, TRUE); -} - -static void -disable_all_menu_cb (GtkMenu *menu, - XedPluginManager *pm) -{ - plugin_manager_set_active_all (pm, FALSE); -} - -static GtkWidget * -create_tree_popup_menu (XedPluginManager *pm) -{ - GtkWidget *menu; - GtkWidget *item; - GtkWidget *image; - XedPluginInfo *info; - - info = plugin_manager_get_selected_plugin (pm); - - menu = gtk_menu_new (); - - item = gtk_image_menu_item_new_with_mnemonic (_("_About")); - image = gtk_image_new_from_stock (GTK_STOCK_ABOUT, - GTK_ICON_SIZE_MENU); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); - g_signal_connect (item, "activate", - G_CALLBACK (about_button_cb), pm); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - - item = gtk_image_menu_item_new_with_mnemonic (_("C_onfigure")); - image = gtk_image_new_from_stock (GTK_STOCK_PREFERENCES, - GTK_ICON_SIZE_MENU); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); - g_signal_connect (item, "activate", - G_CALLBACK (configure_button_cb), pm); - gtk_widget_set_sensitive (item, xed_plugin_info_is_configurable (info)); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - - item = gtk_check_menu_item_new_with_mnemonic (_("A_ctivate")); - gtk_widget_set_sensitive (item, xed_plugin_info_is_available (info)); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), - xed_plugin_info_is_active (info)); - g_signal_connect (item, "toggled", - G_CALLBACK (enable_plugin_menu_cb), pm); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - - item = gtk_separator_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - - item = gtk_menu_item_new_with_mnemonic (_("Ac_tivate All")); - g_signal_connect (item, "activate", - G_CALLBACK (enable_all_menu_cb), pm); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - - item = gtk_menu_item_new_with_mnemonic (_("_Deactivate All")); - g_signal_connect (item, "activate", - G_CALLBACK (disable_all_menu_cb), pm); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - - gtk_widget_show_all (menu); - - return menu; -} - -static void -tree_popup_menu_detach (XedPluginManager *pm, - GtkMenu *menu) -{ - pm->priv->popup_menu = NULL; -} - -static void -show_tree_popup_menu (GtkTreeView *tree, - XedPluginManager *pm, - GdkEventButton *event) -{ - if (pm->priv->popup_menu) - gtk_widget_destroy (pm->priv->popup_menu); - - pm->priv->popup_menu = create_tree_popup_menu (pm); - - gtk_menu_attach_to_widget (GTK_MENU (pm->priv->popup_menu), - GTK_WIDGET (pm), - (GtkMenuDetachFunc) tree_popup_menu_detach); - - if (event != NULL) - { - gtk_menu_popup (GTK_MENU (pm->priv->popup_menu), NULL, NULL, - NULL, NULL, - event->button, event->time); - } - else - { - gtk_menu_popup (GTK_MENU (pm->priv->popup_menu), NULL, NULL, - xed_utils_menu_position_under_tree_view, tree, - 0, gtk_get_current_event_time ()); - - gtk_menu_shell_select_first (GTK_MENU_SHELL (pm->priv->popup_menu), - FALSE); - } -} - -static gboolean -button_press_event_cb (GtkWidget *tree, - GdkEventButton *event, - XedPluginManager *pm) -{ - /* We want the treeview selection to be updated before showing the menu. - * This code is evil, thanks to Federico Mena Quintero's black magic. - * See: http://mail.gnome.org/archives/gtk-devel-list/2006-February/msg00168.html - * FIXME: Let's remove it asap. - */ - - static gboolean in_press = FALSE; - gboolean handled; - - if (in_press) - return FALSE; /* we re-entered */ - - if (GDK_BUTTON_PRESS != event->type || 3 != event->button) - return FALSE; /* let the normal handler run */ - - in_press = TRUE; - handled = gtk_widget_event (tree, (GdkEvent *) event); - in_press = FALSE; - - if (!handled) - return FALSE; - - /* The selection is fully updated by now */ - show_tree_popup_menu (GTK_TREE_VIEW (tree), pm, event); - return TRUE; -} - -static gboolean -popup_menu_cb (GtkTreeView *tree, - XedPluginManager *pm) -{ - show_tree_popup_menu (tree, pm, NULL); - return TRUE; -} - -static gint -model_name_sort_func (GtkTreeModel *model, - GtkTreeIter *iter1, - GtkTreeIter *iter2, - gpointer user_data) -{ - XedPluginInfo *info1, *info2; - - gtk_tree_model_get (model, iter1, INFO_COLUMN, &info1, -1); - gtk_tree_model_get (model, iter2, INFO_COLUMN, &info2, -1); - - return g_utf8_collate (xed_plugin_info_get_name (info1), - xed_plugin_info_get_name (info2)); -} - -static void -plugin_manager_construct_tree (XedPluginManager *pm) -{ - GtkTreeViewColumn *column; - GtkCellRenderer *cell; - GtkListStore *model; - - xed_debug (DEBUG_PLUGINS); - - model = gtk_list_store_new (N_COLUMNS, - G_TYPE_BOOLEAN, - G_TYPE_BOOLEAN, - G_TYPE_POINTER); - - gtk_tree_view_set_model (GTK_TREE_VIEW (pm->priv->tree), - GTK_TREE_MODEL (model)); - g_object_unref (model); - - gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (pm->priv->tree), TRUE); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (pm->priv->tree), FALSE); - - /* first column */ - cell = gtk_cell_renderer_toggle_new (); - g_object_set (cell, "xpad", 6, NULL); - g_signal_connect (cell, - "toggled", - G_CALLBACK (active_toggled_cb), - pm); - column = gtk_tree_view_column_new_with_attributes (PLUGIN_MANAGER_ACTIVE_TITLE, - cell, - "active", - ACTIVE_COLUMN, - "activatable", - AVAILABLE_COLUMN, - "sensitive", - AVAILABLE_COLUMN, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (pm->priv->tree), column); - - /* second column */ - column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_title (column, PLUGIN_MANAGER_NAME_TITLE); - gtk_tree_view_column_set_resizable (column, TRUE); - - cell = gtk_cell_renderer_pixbuf_new (); - gtk_tree_view_column_pack_start (column, cell, FALSE); - g_object_set (cell, "stock-size", GTK_ICON_SIZE_SMALL_TOOLBAR, NULL); - gtk_tree_view_column_set_cell_data_func (column, cell, - plugin_manager_view_icon_cell_cb, - pm, NULL); - - cell = gtk_cell_renderer_text_new (); - gtk_tree_view_column_pack_start (column, cell, TRUE); - g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL); - gtk_tree_view_column_set_cell_data_func (column, cell, - plugin_manager_view_info_cell_cb, - pm, NULL); - - - gtk_tree_view_column_set_spacing (column, 6); - gtk_tree_view_append_column (GTK_TREE_VIEW (pm->priv->tree), column); - - /* Sort on the plugin names */ - gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (model), - model_name_sort_func, - NULL, - NULL); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model), - GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, - GTK_SORT_ASCENDING); - - /* Enable search for our non-string column */ - gtk_tree_view_set_search_column (GTK_TREE_VIEW (pm->priv->tree), - INFO_COLUMN); - gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (pm->priv->tree), - name_search_cb, - NULL, - NULL); - - g_signal_connect (pm->priv->tree, - "cursor_changed", - G_CALLBACK (cursor_changed_cb), - pm); - g_signal_connect (pm->priv->tree, - "row_activated", - G_CALLBACK (row_activated_cb), - pm); - - g_signal_connect (pm->priv->tree, - "button-press-event", - G_CALLBACK (button_press_event_cb), - pm); - g_signal_connect (pm->priv->tree, - "popup-menu", - G_CALLBACK (popup_menu_cb), - pm); - gtk_widget_show (pm->priv->tree); -} - -static void -plugin_toggled_cb (XedPluginsEngine *engine, - XedPluginInfo *info, - XedPluginManager *pm) -{ - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreeIter iter; - gboolean info_found = FALSE; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (pm->priv->tree)); - - if (gtk_tree_selection_get_selected (selection, &model, &iter)) - { - /* There is an item selected: it's probably the one we want! */ - XedPluginInfo *tinfo; - gtk_tree_model_get (model, &iter, INFO_COLUMN, &tinfo, -1); - info_found = info == tinfo; - } - - if (!info_found) - { - gtk_tree_model_get_iter_first (model, &iter); - - do - { - XedPluginInfo *tinfo; - gtk_tree_model_get (model, &iter, INFO_COLUMN, &tinfo, -1); - info_found = info == tinfo; - } - while (!info_found && gtk_tree_model_iter_next (model, &iter)); - } - - if (!info_found) - { - g_warning ("XedPluginManager: plugin '%s' not found in the tree model", - xed_plugin_info_get_name (info)); - return; - } - - gtk_list_store_set (GTK_LIST_STORE (model), &iter, ACTIVE_COLUMN, xed_plugin_info_is_active (info), -1); -} - -static void -xed_plugin_manager_init (XedPluginManager *pm) -{ - GtkWidget *label; - GtkWidget *viewport; - GtkWidget *hbuttonbox; - - xed_debug (DEBUG_PLUGINS); - - pm->priv = XED_PLUGIN_MANAGER_GET_PRIVATE (pm); - - gtk_orientable_set_orientation (GTK_ORIENTABLE (pm), - GTK_ORIENTATION_VERTICAL); - - /* - * Always we create the manager, firstly we rescan the plugins directory - */ - xed_plugins_engine_rescan_plugins (xed_plugins_engine_get_default ()); - - gtk_box_set_spacing (GTK_BOX (pm), 6); - - label = gtk_label_new_with_mnemonic (_("Active _Plugins:")); - gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - - gtk_box_pack_start (GTK_BOX (pm), label, FALSE, TRUE, 0); - - viewport = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (viewport), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (viewport), - GTK_SHADOW_IN); - - gtk_box_pack_start (GTK_BOX (pm), viewport, TRUE, TRUE, 0); - - pm->priv->tree = gtk_tree_view_new (); - gtk_container_add (GTK_CONTAINER (viewport), pm->priv->tree); - - gtk_label_set_mnemonic_widget (GTK_LABEL (label), pm->priv->tree); - - hbuttonbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL); - - gtk_box_pack_start (GTK_BOX (pm), hbuttonbox, FALSE, FALSE, 0); - gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_END); - gtk_box_set_spacing (GTK_BOX (hbuttonbox), 8); - - pm->priv->about_button = xed_gtk_button_new_with_stock_icon (_("_About Plugin"), - GTK_STOCK_ABOUT); - gtk_container_add (GTK_CONTAINER (hbuttonbox), pm->priv->about_button); - - pm->priv->configure_button = xed_gtk_button_new_with_stock_icon (_("C_onfigure Plugin"), - GTK_STOCK_PREFERENCES); - gtk_container_add (GTK_CONTAINER (hbuttonbox), pm->priv->configure_button); - - /* setup a window of a sane size. */ - gtk_widget_set_size_request (GTK_WIDGET (viewport), 270, 100); - - g_signal_connect (pm->priv->about_button, - "clicked", - G_CALLBACK (about_button_cb), - pm); - g_signal_connect (pm->priv->configure_button, - "clicked", - G_CALLBACK (configure_button_cb), - pm); - - plugin_manager_construct_tree (pm); - - /* get the plugin engine and populate the treeview */ - pm->priv->engine = xed_plugins_engine_get_default (); - - g_signal_connect_after (pm->priv->engine, - "activate-plugin", - G_CALLBACK (plugin_toggled_cb), - pm); - g_signal_connect_after (pm->priv->engine, - "deactivate-plugin", - G_CALLBACK (plugin_toggled_cb), - pm); - - if (xed_plugins_engine_get_plugin_list (pm->priv->engine) != NULL) - { - plugin_manager_populate_lists (pm); - } - else - { - gtk_widget_set_sensitive (pm->priv->about_button, FALSE); - gtk_widget_set_sensitive (pm->priv->configure_button, FALSE); - } -} - -static void -xed_plugin_manager_finalize (GObject *object) -{ - XedPluginManager *pm = XED_PLUGIN_MANAGER (object); - - g_signal_handlers_disconnect_by_func (pm->priv->engine, - plugin_toggled_cb, - pm); - - if (pm->priv->popup_menu) - gtk_widget_destroy (pm->priv->popup_menu); - - G_OBJECT_CLASS (xed_plugin_manager_parent_class)->finalize (object); - -} - -GtkWidget *xed_plugin_manager_new (void) -{ - return g_object_new (XED_TYPE_PLUGIN_MANAGER,0); -} diff --git a/xed/xed-plugin-manager.h b/xed/xed-plugin-manager.h deleted file mode 100644 index be1923f..0000000 --- a/xed/xed-plugin-manager.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * xed-plugin-manager.h - * This file is part of xed - * - * Copyright (C) 2002-2005 Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2002-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#ifndef __XED_PLUGIN_MANAGER_H__ -#define __XED_PLUGIN_MANAGER_H__ - -#include - -G_BEGIN_DECLS - -/* - * Type checking and casting macros - */ -#define XED_TYPE_PLUGIN_MANAGER (xed_plugin_manager_get_type()) -#define XED_PLUGIN_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_PLUGIN_MANAGER, XedPluginManager)) -#define XED_PLUGIN_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_PLUGIN_MANAGER, XedPluginManagerClass)) -#define XED_IS_PLUGIN_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_PLUGIN_MANAGER)) -#define XED_IS_PLUGIN_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_PLUGIN_MANAGER)) -#define XED_PLUGIN_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_PLUGIN_MANAGER, XedPluginManagerClass)) - -/* Private structure type */ -typedef struct _XedPluginManagerPrivate XedPluginManagerPrivate; - -/* - * Main object structure - */ -typedef struct _XedPluginManager XedPluginManager; - -struct _XedPluginManager -{ - GtkBox vbox; - - /*< private > */ - XedPluginManagerPrivate *priv; -}; - -/* - * Class definition - */ -typedef struct _XedPluginManagerClass XedPluginManagerClass; - -struct _XedPluginManagerClass -{ - GtkBoxClass parent_class; -}; - -/* - * Public methods - */ -GType xed_plugin_manager_get_type (void) G_GNUC_CONST; - -GtkWidget *xed_plugin_manager_new (void); - -G_END_DECLS - -#endif /* __XED_PLUGIN_MANAGER_H__ */ diff --git a/xed/xed-plugin.c b/xed/xed-plugin.c deleted file mode 100644 index 87c3eb9..0000000 --- a/xed/xed-plugin.c +++ /dev/null @@ -1,334 +0,0 @@ -/* - * xed-plugin.h - * This file is part of xed - * - * Copyright (C) 2002-2005 Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2002-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "xed-plugin.h" -#include "xed-dirs.h" - -/* properties */ -enum { - PROP_0, - PROP_INSTALL_DIR, - PROP_DATA_DIR_NAME, - PROP_DATA_DIR -}; - -typedef struct _XedPluginPrivate XedPluginPrivate; - -struct _XedPluginPrivate -{ - gchar *install_dir; - gchar *data_dir_name; -}; - -#define XED_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_PLUGIN, XedPluginPrivate)) - -G_DEFINE_TYPE(XedPlugin, xed_plugin, G_TYPE_OBJECT) - -static void -dummy (XedPlugin *plugin, XedWindow *window) -{ - /* Empty */ -} - -static GtkWidget * -create_configure_dialog (XedPlugin *plugin) -{ - return NULL; -} - -static gboolean -is_configurable (XedPlugin *plugin) -{ - return (XED_PLUGIN_GET_CLASS (plugin)->create_configure_dialog != - create_configure_dialog); -} - -static void -xed_plugin_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - switch (prop_id) - { - case PROP_INSTALL_DIR: - g_value_take_string (value, xed_plugin_get_install_dir (XED_PLUGIN (object))); - break; - case PROP_DATA_DIR: - g_value_take_string (value, xed_plugin_get_data_dir (XED_PLUGIN (object))); - break; - default: - g_return_if_reached (); - } -} - -static void -xed_plugin_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - XedPluginPrivate *priv = XED_PLUGIN_GET_PRIVATE (object); - - switch (prop_id) - { - case PROP_INSTALL_DIR: - priv->install_dir = g_value_dup_string (value); - break; - case PROP_DATA_DIR_NAME: - priv->data_dir_name = g_value_dup_string (value); - break; - default: - g_return_if_reached (); - } -} - -static void -xed_plugin_finalize (GObject *object) -{ - XedPluginPrivate *priv = XED_PLUGIN_GET_PRIVATE (object); - - g_free (priv->install_dir); - g_free (priv->data_dir_name); - - G_OBJECT_CLASS (xed_plugin_parent_class)->finalize (object); -} - -static void -xed_plugin_class_init (XedPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - klass->activate = dummy; - klass->deactivate = dummy; - klass->update_ui = dummy; - - klass->create_configure_dialog = create_configure_dialog; - klass->is_configurable = is_configurable; - - object_class->get_property = xed_plugin_get_property; - object_class->set_property = xed_plugin_set_property; - object_class->finalize = xed_plugin_finalize; - - g_object_class_install_property (object_class, - PROP_INSTALL_DIR, - g_param_spec_string ("install-dir", - "Install Directory", - "The directory where the plugin is installed", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - /* the basename of the data dir is set at construction time by the plugin loader - * while the full path is constructed on the fly to take into account relocability - * that's why we have a writeonly prop and a readonly prop */ - g_object_class_install_property (object_class, - PROP_DATA_DIR_NAME, - g_param_spec_string ("data-dir-name", - "Basename of the data directory", - "The basename of the directory where the plugin should look for its data files", - NULL, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (object_class, - PROP_DATA_DIR, - g_param_spec_string ("data-dir", - "Data Directory", - "The full path of the directory where the plugin should look for its data files", - NULL, - G_PARAM_READABLE)); - - g_type_class_add_private (klass, sizeof (XedPluginPrivate)); -} - -static void -xed_plugin_init (XedPlugin *plugin) -{ - /* Empty */ -} - -/** - * xed_plugin_get_install_dir: - * @plugin: a #XedPlugin - * - * Get the path of the directory where the plugin is installed. - * - * Return value: a newly allocated string with the path of the - * directory where the plugin is installed - */ -gchar * -xed_plugin_get_install_dir (XedPlugin *plugin) -{ - g_return_val_if_fail (XED_IS_PLUGIN (plugin), NULL); - - return g_strdup (XED_PLUGIN_GET_PRIVATE (plugin)->install_dir); -} - -/** - * xed_plugin_get_data_dir: - * @plugin: a #XedPlugin - * - * Get the path of the directory where the plugin should look for - * its data files. - * - * Return value: a newly allocated string with the path of the - * directory where the plugin should look for its data files - */ -gchar * -xed_plugin_get_data_dir (XedPlugin *plugin) -{ - XedPluginPrivate *priv; - gchar *xed_lib_dir; - gchar *data_dir; - - g_return_val_if_fail (XED_IS_PLUGIN (plugin), NULL); - - priv = XED_PLUGIN_GET_PRIVATE (plugin); - - /* If it's a "user" plugin the data dir is - * install_dir/data_dir_name if instead it's a - * "system" plugin the data dir is under xed_data_dir, - * so it's under $prefix/share/xed/plugins/data_dir_name - * where data_dir_name usually it's the name of the plugin - */ - xed_lib_dir = xed_dirs_get_xed_lib_dir (); - - /* CHECK: is checking the prefix enough or should we be more - * careful about normalizing paths etc? */ - if (g_str_has_prefix (priv->install_dir, xed_lib_dir)) - { - gchar *xed_data_dir; - - xed_data_dir = xed_dirs_get_xed_data_dir (); - - data_dir = g_build_filename (xed_data_dir, - "plugins", - priv->data_dir_name, - NULL); - - g_free (xed_data_dir); - } - else - { - data_dir = g_build_filename (priv->install_dir, - priv->data_dir_name, - NULL); - } - - g_free (xed_lib_dir); - - return data_dir; -} - -/** - * xed_plugin_activate: - * @plugin: a #XedPlugin - * @window: a #XedWindow - * - * Activates the plugin. - */ -void -xed_plugin_activate (XedPlugin *plugin, - XedWindow *window) -{ - g_return_if_fail (XED_IS_PLUGIN (plugin)); - g_return_if_fail (XED_IS_WINDOW (window)); - - XED_PLUGIN_GET_CLASS (plugin)->activate (plugin, window); -} - -/** - * xed_plugin_deactivate: - * @plugin: a #XedPlugin - * @window: a #XedWindow - * - * Deactivates the plugin. - */ -void -xed_plugin_deactivate (XedPlugin *plugin, - XedWindow *window) -{ - g_return_if_fail (XED_IS_PLUGIN (plugin)); - g_return_if_fail (XED_IS_WINDOW (window)); - - XED_PLUGIN_GET_CLASS (plugin)->deactivate (plugin, window); -} - -/** - * xed_plugin_update_ui: - * @plugin: a #XedPlugin - * @window: a #XedWindow - * - * Triggers an update of the user interface to take into account state changes - * caused by the plugin. - */ -void -xed_plugin_update_ui (XedPlugin *plugin, - XedWindow *window) -{ - g_return_if_fail (XED_IS_PLUGIN (plugin)); - g_return_if_fail (XED_IS_WINDOW (window)); - - XED_PLUGIN_GET_CLASS (plugin)->update_ui (plugin, window); -} - -/** - * xed_plugin_is_configurable: - * @plugin: a #XedPlugin - * - * Whether the plugin is configurable. - * - * Returns: TRUE if the plugin is configurable: - */ -gboolean -xed_plugin_is_configurable (XedPlugin *plugin) -{ - g_return_val_if_fail (XED_IS_PLUGIN (plugin), FALSE); - - return XED_PLUGIN_GET_CLASS (plugin)->is_configurable (plugin); -} - -/** - * xed_plugin_create_configure_dialog: - * @plugin: a #XedPlugin - * - * Creates the configure dialog widget for the plugin. - * - * Returns: the configure dialog widget for the plugin. - */ -GtkWidget * -xed_plugin_create_configure_dialog (XedPlugin *plugin) -{ - g_return_val_if_fail (XED_IS_PLUGIN (plugin), NULL); - - return XED_PLUGIN_GET_CLASS (plugin)->create_configure_dialog (plugin); -} diff --git a/xed/xed-plugin.h b/xed/xed-plugin.h deleted file mode 100644 index 6e68da0..0000000 --- a/xed/xed-plugin.h +++ /dev/null @@ -1,240 +0,0 @@ -/* - * xed-plugin.h - * This file is part of xed - * - * Copyright (C) 2002-2005 - Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2002-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#ifndef __XED_PLUGIN_H__ -#define __XED_PLUGIN_H__ - -#include - -#include -#include - -/* TODO: add a .h file that includes all the .h files normally needed to - * develop a plugin */ - -G_BEGIN_DECLS - -/* - * Type checking and casting macros - */ -#define XED_TYPE_PLUGIN (xed_plugin_get_type()) -#define XED_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_PLUGIN, XedPlugin)) -#define XED_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_PLUGIN, XedPluginClass)) -#define XED_IS_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_PLUGIN)) -#define XED_IS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_PLUGIN)) -#define XED_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_PLUGIN, XedPluginClass)) - -/* - * Main object structure - */ -typedef struct _XedPlugin XedPlugin; - -struct _XedPlugin -{ - GObject parent; -}; - -/* - * Class definition - */ -typedef struct _XedPluginClass XedPluginClass; - -struct _XedPluginClass -{ - GObjectClass parent_class; - - /* Virtual public methods */ - - void (*activate) (XedPlugin *plugin, - XedWindow *window); - void (*deactivate) (XedPlugin *plugin, - XedWindow *window); - - void (*update_ui) (XedPlugin *plugin, - XedWindow *window); - - GtkWidget *(*create_configure_dialog) - (XedPlugin *plugin); - - /* Plugins should not override this, it's handled automatically by - the XedPluginClass */ - gboolean (*is_configurable) - (XedPlugin *plugin); - - /* Padding for future expansion */ - void (*_xed_reserved1) (void); - void (*_xed_reserved2) (void); - void (*_xed_reserved3) (void); - void (*_xed_reserved4) (void); -}; - -/* - * Public methods - */ -GType xed_plugin_get_type (void) G_GNUC_CONST; - -gchar *xed_plugin_get_install_dir (XedPlugin *plugin); -gchar *xed_plugin_get_data_dir (XedPlugin *plugin); - -void xed_plugin_activate (XedPlugin *plugin, - XedWindow *window); -void xed_plugin_deactivate (XedPlugin *plugin, - XedWindow *window); - -void xed_plugin_update_ui (XedPlugin *plugin, - XedWindow *window); - -gboolean xed_plugin_is_configurable (XedPlugin *plugin); -GtkWidget *xed_plugin_create_configure_dialog - (XedPlugin *plugin); - -/** - * XED_PLUGIN_REGISTER_TYPE_WITH_CODE(PluginName, plugin_name, CODE): - * - * Utility macro used to register plugins with additional code. - */ -#define XED_PLUGIN_REGISTER_TYPE_WITH_CODE(PluginName, plugin_name, CODE) \ - G_DEFINE_DYNAMIC_TYPE_EXTENDED (PluginName, \ - plugin_name, \ - XED_TYPE_PLUGIN, \ - 0, \ - GTypeModule *module G_GNUC_UNUSED = type_module; /* back compat */ \ - CODE) \ - \ -/* This is not very nice, but G_DEFINE_DYNAMIC wants it and our old macro \ - * did not support it */ \ -static void \ -plugin_name##_class_finalize (PluginName##Class *klass) \ -{ \ -} \ - \ - \ -G_MODULE_EXPORT GType \ -register_xed_plugin (GTypeModule *type_module) \ -{ \ - plugin_name##_register_type (type_module); \ - \ - return plugin_name##_get_type(); \ -} - -/** - * XED_PLUGIN_REGISTER_TYPE(PluginName, plugin_name): - * - * Utility macro used to register plugins. - */ -#define XED_PLUGIN_REGISTER_TYPE(PluginName, plugin_name) \ - XED_PLUGIN_REGISTER_TYPE_WITH_CODE(PluginName, plugin_name, ;) - -/** - * XED_PLUGIN_DEFINE_TYPE_WITH_CODE(ObjectName, object_name, PARENT_TYPE, CODE): - * - * Utility macro used to register gobject types in plugins with additional code. - * - * Deprecated: use G_DEFINE_DYNAMIC_TYPE_EXTENDED instead - */ -#define XED_PLUGIN_DEFINE_TYPE_WITH_CODE(ObjectName, object_name, PARENT_TYPE, CODE) \ - \ -static GType g_define_type_id = 0; \ - \ -GType \ -object_name##_get_type (void) \ -{ \ - return g_define_type_id; \ -} \ - \ -static void object_name##_init (ObjectName *self); \ -static void object_name##_class_init (ObjectName##Class *klass); \ -static gpointer object_name##_parent_class = NULL; \ -static void object_name##_class_intern_init (gpointer klass) \ -{ \ - object_name##_parent_class = g_type_class_peek_parent (klass); \ - object_name##_class_init ((ObjectName##Class *) klass); \ -} \ - \ -GType \ -object_name##_register_type (GTypeModule *type_module) \ -{ \ - GTypeModule *module G_GNUC_UNUSED = type_module; /* back compat */ \ - static const GTypeInfo our_info = \ - { \ - sizeof (ObjectName##Class), \ - NULL, /* base_init */ \ - NULL, /* base_finalize */ \ - (GClassInitFunc) object_name##_class_intern_init, \ - NULL, \ - NULL, /* class_data */ \ - sizeof (ObjectName), \ - 0, /* n_preallocs */ \ - (GInstanceInitFunc) object_name##_init \ - }; \ - \ - g_define_type_id = g_type_module_register_type (type_module, \ - PARENT_TYPE, \ - #ObjectName, \ - &our_info, \ - 0); \ - \ - CODE \ - \ - return g_define_type_id; \ -} - - -/** - * XED_PLUGIN_DEFINE_TYPE(ObjectName, object_name, PARENT_TYPE): - * - * Utility macro used to register gobject types in plugins. - * - * Deprecated: use G_DEFINE_DYNAMIC instead - */ -#define XED_PLUGIN_DEFINE_TYPE(ObjectName, object_name, PARENT_TYPE) \ - XED_PLUGIN_DEFINE_TYPE_WITH_CODE(ObjectName, object_name, PARENT_TYPE, ;) - -/** - * XED_PLUGIN_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init): - * - * Utility macro used to register interfaces for gobject types in plugins. - */ -#define XED_PLUGIN_IMPLEMENT_INTERFACE(object_name, TYPE_IFACE, iface_init) \ - const GInterfaceInfo object_name##_interface_info = \ - { \ - (GInterfaceInitFunc) iface_init, \ - NULL, \ - NULL \ - }; \ - \ - g_type_module_add_interface (type_module, \ - g_define_type_id, \ - TYPE_IFACE, \ - &object_name##_interface_info); - -G_END_DECLS - -#endif /* __XED_PLUGIN_H__ */ From 64be9e8ecda259fa341c18b38d4b7f1823319bcb Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 18:57:15 -0800 Subject: [PATCH 039/132] enable dh_girepository helper to fill ${gir:Depends} properly Adapted from: https://github.com/mate-desktop/debian-packages/commit/08f71335b27a9257256b59865a5ffce41e7994a0 --- debian/rules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/rules b/debian/rules index e9f4ad1..dc10b29 100755 --- a/debian/rules +++ b/debian/rules @@ -3,7 +3,7 @@ DHFLAGS=--parallel %: - dh $@ $(DHFLAGS) + dh $@ $(DHFLAGS) --with gir override_dh_install: rm -rfv debian/tmp/usr/lib/*/xed/plugins/*.la From f9a658f82333ec370b2e17e1d39d1c57c25463d8 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 19:04:39 -0800 Subject: [PATCH 040/132] taglist plugin: don't look for taglist in non-existing legacy dirs --- plugins/taglist/xed-taglist-plugin-parser.c | 22 --------------------- 1 file changed, 22 deletions(-) diff --git a/plugins/taglist/xed-taglist-plugin-parser.c b/plugins/taglist/xed-taglist-plugin-parser.c index 99c3ab4..bb0bdc1 100644 --- a/plugins/taglist/xed-taglist-plugin-parser.c +++ b/plugins/taglist/xed-taglist-plugin-parser.c @@ -44,7 +44,6 @@ #include "xed-taglist-plugin-parser.h" /* we screwed up so we still look here for compatibility */ -#define USER_XED_TAGLIST_PLUGIN_LOCATION_LEGACY ".xed/plugins/taglist/" #define USER_XED_TAGLIST_PLUGIN_LOCATION "xed/taglist/" TagList* taglist = NULL; @@ -603,32 +602,11 @@ TagList* create_taglist(const gchar* data_dir) } const gchar* home; - const gchar* envvar; /* load user's taglists */ - /* legacy dir */ home = g_get_home_dir (); if (home != NULL) - { - pdir = g_build_filename (home, - USER_XED_TAGLIST_PLUGIN_LOCATION_LEGACY, - NULL); - parse_taglist_dir (pdir); - g_free (pdir); - } - - /* Support old libmate env var */ - envvar = g_getenv ("MATE22_USER_DIR"); - if (envvar != NULL) - { - pdir = g_build_filename (envvar, - USER_XED_TAGLIST_PLUGIN_LOCATION, - NULL); - parse_taglist_dir (pdir); - g_free (pdir); - } - else if (home != NULL) { pdir = g_build_filename(home, ".config", USER_XED_TAGLIST_PLUGIN_LOCATION, NULL); parse_taglist_dir(pdir); From 26f81393174b2b2127fa260c69c3a97c58406cdf Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 19:32:38 -0800 Subject: [PATCH 041/132] xed-panel: Clean up the layout of the panels Make sure the bottom panel lays out properly when we actually have a plugin that lives there --- xed/xed-panel.c | 105 ++++++++++++++++++++++++++++++++++++++++-------- xed/xed-panel.h | 102 +++++++++++++++++++++++----------------------- 2 files changed, 139 insertions(+), 68 deletions(-) diff --git a/xed/xed-panel.c b/xed/xed-panel.c index 13d7357..0d0bb70 100644 --- a/xed/xed-panel.c +++ b/xed/xed-panel.c @@ -47,6 +47,8 @@ struct _XedPanelPrivate { GtkOrientation orientation; + GtkWidget *main_box; + /* Title bar (vertical panel only) */ GtkWidget *title_image; GtkWidget *title_label; @@ -87,7 +89,7 @@ static GObject *xed_panel_constructor (GType type, GObjectConstructParam *construct_properties); -G_DEFINE_TYPE (XedPanel, xed_panel, GTK_TYPE_BOX) +G_DEFINE_TYPE (XedPanel, xed_panel, GTK_TYPE_BIN) static void xed_panel_finalize (GObject *obj) @@ -158,6 +160,71 @@ xed_panel_focus_document (XedPanel *panel) } } +static void +xed_panel_get_size (GtkWidget *widget, + GtkOrientation orientation, + gint *minimum, + gint *natural) +{ + GtkBin *bin = GTK_BIN (widget); + GtkWidget *child; + + if (minimum) + { + *minimum = 0; + } + + if (natural) + { + *natural = 0; + } + + child = gtk_bin_get_child (bin); + if (child && gtk_widget_get_visible (child)) + { + if (orientation == GTK_ORIENTATION_HORIZONTAL) + { + gtk_widget_get_preferred_width (child, minimum, natural); + } + else + { + gtk_widget_get_preferred_height (child, minimum, natural); + } + } +} + +static void +xed_panel_get_preferred_width (GtkWidget *widget, + gint *minimum, + gint *natural) +{ + xed_panel_get_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum, natural); +} + +static void +xed_panel_get_preferred_height (GtkWidget *widget, + gint *minimum, + gint *natural) +{ + xed_panel_get_size (widget, GTK_ORIENTATION_VERTICAL, minimum, natural); +} + +static void +xed_panel_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + GtkBin *bin = GTK_BIN (widget); + GtkWidget *child; + + GTK_WIDGET_CLASS (xed_panel_parent_class)->size_allocate (widget, allocation); + + child = gtk_bin_get_child (bin); + if (child && gtk_widget_get_visible (child)) + { + gtk_widget_size_allocate (child, allocation); + } +} + static void xed_panel_grab_focus (GtkWidget *w) { @@ -191,23 +258,25 @@ xed_panel_class_init (XedPanelClass *klass) object_class->get_property = xed_panel_get_property; object_class->set_property = xed_panel_set_property; - g_object_class_install_property (object_class, - PROP_ORIENTATION, - g_param_spec_enum ("panel-orientation", - "Panel Orientation", - "The panel's orientation", - GTK_TYPE_ORIENTATION, - GTK_ORIENTATION_VERTICAL, - G_PARAM_WRITABLE | - G_PARAM_READABLE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - + widget_class->get_preferred_width = xed_panel_get_preferred_width; + widget_class->get_preferred_height = xed_panel_get_preferred_height; + widget_class->size_allocate = xed_panel_size_allocate; widget_class->grab_focus = xed_panel_grab_focus; klass->close = xed_panel_close; klass->focus_document = xed_panel_focus_document; + g_object_class_install_property (object_class, + PROP_ORIENTATION, + g_param_spec_enum ("orientation", + "Panel Orientation", + "The panel's orientation", + GTK_TYPE_ORIENTATION, + GTK_ORIENTATION_VERTICAL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + signals[ITEM_ADDED] = g_signal_new ("item_added", G_OBJECT_CLASS_TYPE (klass), @@ -384,7 +453,9 @@ xed_panel_init (XedPanel *panel) { panel->priv = XED_PANEL_GET_PRIVATE (panel); - gtk_orientable_set_orientation (GTK_ORIENTABLE (panel), GTK_ORIENTATION_VERTICAL); + panel->priv->main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + gtk_widget_show (panel->priv->main_box); + gtk_container_add (GTK_CONTAINER (panel), panel->priv->main_box); } static void @@ -441,7 +512,7 @@ build_horizontal_panel (XedPanel *panel) gtk_widget_show_all (box); - gtk_box_pack_start (GTK_BOX (panel), box, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (panel->priv->main_box), box, TRUE, TRUE, 0); } static void @@ -456,7 +527,7 @@ build_vertical_panel (XedPanel *panel) title_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); gtk_container_set_border_width (GTK_CONTAINER (title_hbox), 5); - gtk_box_pack_start (GTK_BOX (panel), title_hbox, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (panel->priv->main_box), title_hbox, FALSE, FALSE, 0); icon_name_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_pack_start (GTK_BOX (title_hbox), icon_name_hbox, TRUE, TRUE, 0); @@ -477,7 +548,7 @@ build_vertical_panel (XedPanel *panel) gtk_widget_show_all (title_hbox); - gtk_box_pack_start (GTK_BOX (panel), panel->priv->notebook, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (panel->priv->main_box), panel->priv->notebook, TRUE, TRUE, 0); } static GObject * diff --git a/xed/xed-panel.h b/xed/xed-panel.h index 5cf152f..b915946 100644 --- a/xed/xed-panel.h +++ b/xed/xed-panel.h @@ -2,7 +2,7 @@ * xed-panel.h * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -38,12 +38,12 @@ G_BEGIN_DECLS /* * Type checking and casting macros */ -#define XED_TYPE_PANEL (xed_panel_get_type()) -#define XED_PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_PANEL, XedPanel)) -#define XED_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_PANEL, XedPanelClass)) -#define XED_IS_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_PANEL)) -#define XED_IS_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_PANEL)) -#define XED_PANEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_PANEL, XedPanelClass)) +#define XED_TYPE_PANEL (xed_panel_get_type()) +#define XED_PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_PANEL, XedPanel)) +#define XED_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_PANEL, XedPanelClass)) +#define XED_IS_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_PANEL)) +#define XED_IS_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_PANEL)) +#define XED_PANEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_PANEL, XedPanelClass)) /* Private structure type */ typedef struct _XedPanelPrivate XedPanelPrivate; @@ -53,12 +53,12 @@ typedef struct _XedPanelPrivate XedPanelPrivate; */ typedef struct _XedPanel XedPanel; -struct _XedPanel +struct _XedPanel { - GtkBox vbox; + GtkBin parent; - /*< private > */ - XedPanelPrivate *priv; + /*< private > */ + XedPanelPrivate *priv; }; /* @@ -66,64 +66,64 @@ struct _XedPanel */ typedef struct _XedPanelClass XedPanelClass; -struct _XedPanelClass +struct _XedPanelClass { - GtkBoxClass parent_class; + GtkBinClass parent_class; - void (* item_added) (XedPanel *panel, - GtkWidget *item); - void (* item_removed) (XedPanel *panel, - GtkWidget *item); + void (* item_added) (XedPanel *panel, + GtkWidget *item); + void (* item_removed) (XedPanel *panel, + GtkWidget *item); - /* Keybinding signals */ - void (* close) (XedPanel *panel); - void (* focus_document) (XedPanel *panel); + /* Keybinding signals */ + void (* close) (XedPanel *panel); + void (* focus_document) (XedPanel *panel); - /* Padding for future expansion */ - void (*_xed_reserved1) (void); - void (*_xed_reserved2) (void); - void (*_xed_reserved3) (void); - void (*_xed_reserved4) (void); + /* Padding for future expansion */ + void (*_xed_reserved1) (void); + void (*_xed_reserved2) (void); + void (*_xed_reserved3) (void); + void (*_xed_reserved4) (void); }; /* * Public methods */ -GType xed_panel_get_type (void) G_GNUC_CONST; +GType xed_panel_get_type (void) G_GNUC_CONST; -GtkWidget *xed_panel_new (GtkOrientation orientation); +GtkWidget *xed_panel_new (GtkOrientation orientation); -void xed_panel_add_item (XedPanel *panel, - GtkWidget *item, - const gchar *name, - GtkWidget *image); +void xed_panel_add_item (XedPanel *panel, + GtkWidget *item, + const gchar *name, + GtkWidget *image); -void xed_panel_add_item_with_stock_icon (XedPanel *panel, - GtkWidget *item, - const gchar *name, - const gchar *stock_id); +void xed_panel_add_item_with_stock_icon (XedPanel *panel, + GtkWidget *item, + const gchar *name, + const gchar *stock_id); -gboolean xed_panel_remove_item (XedPanel *panel, - GtkWidget *item); +gboolean xed_panel_remove_item (XedPanel *panel, + GtkWidget *item); -gboolean xed_panel_activate_item (XedPanel *panel, - GtkWidget *item); +gboolean xed_panel_activate_item (XedPanel *panel, + GtkWidget *item); -gboolean xed_panel_item_is_active (XedPanel *panel, - GtkWidget *item); +gboolean xed_panel_item_is_active (XedPanel *panel, + GtkWidget *item); -GtkOrientation xed_panel_get_orientation (XedPanel *panel); +GtkOrientation xed_panel_get_orientation (XedPanel *panel); -gint xed_panel_get_n_items (XedPanel *panel); +gint xed_panel_get_n_items (XedPanel *panel); /* * Non exported functions */ -gint _xed_panel_get_active_item_id (XedPanel *panel); +gint _xed_panel_get_active_item_id (XedPanel *panel); -void _xed_panel_set_active_item_by_id (XedPanel *panel, - gint id); +void _xed_panel_set_active_item_by_id (XedPanel *panel, + gint id); G_END_DECLS From 3a6de664e1d6bc4a9ca2cc1967d080ed57dc049f Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 20:26:21 -0800 Subject: [PATCH 042/132] xed-sort-plugin.c: Clean up code styling --- plugins/sort/xed-sort-plugin.c | 596 ++++++++++++++++----------------- 1 file changed, 283 insertions(+), 313 deletions(-) diff --git a/plugins/sort/xed-sort-plugin.c b/plugins/sort/xed-sort-plugin.c index 1027f31..a93cdd2 100644 --- a/plugins/sort/xed-sort-plugin.c +++ b/plugins/sort/xed-sort-plugin.c @@ -58,397 +58,372 @@ enum typedef struct { - GtkWidget *dialog; - GtkWidget *col_num_spinbutton; - GtkWidget *reverse_order_checkbutton; - GtkWidget *ignore_case_checkbutton; - GtkWidget *remove_dups_checkbutton; + GtkWidget *dialog; + GtkWidget *col_num_spinbutton; + GtkWidget *reverse_order_checkbutton; + GtkWidget *ignore_case_checkbutton; + GtkWidget *remove_dups_checkbutton; - XedDocument *doc; + XedDocument *doc; - GtkTextIter start, end; /* selection */ + GtkTextIter start, end; /* selection */ } SortDialog; struct _XedSortPluginPrivate { GtkWidget *window; - GtkActionGroup *ui_action_group; - guint ui_id; + GtkActionGroup *ui_action_group; + guint ui_id; }; typedef struct { - gboolean ignore_case; - gboolean reverse_order; - gboolean remove_duplicates; - gint starting_column; + gboolean ignore_case; + gboolean reverse_order; + gboolean remove_duplicates; + gint starting_column; } SortInfo; -static void sort_cb (GtkAction *action, XedSortPlugin *plugin); +static void sort_cb (GtkAction *action, + XedSortPlugin *plugin); static void sort_real (SortDialog *dialog); static const GtkActionEntry action_entries[] = { - { "Sort", - "view-sort-ascending-symbolic", - N_("S_ort..."), - NULL, - N_("Sort the current document or selection"), - G_CALLBACK (sort_cb) } + { "Sort", + "view-sort-ascending-symbolic", + N_("S_ort..."), + NULL, + N_("Sort the current document or selection"), + G_CALLBACK (sort_cb) + } }; static void -sort_dialog_destroy (GObject *obj, - gpointer dialog_pointer) +sort_dialog_destroy (GObject *obj, + gpointer dialog_pointer) { - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - g_slice_free (SortDialog, dialog_pointer); + g_slice_free (SortDialog, dialog_pointer); } static void sort_dialog_response_handler (GtkDialog *widget, - gint res_id, - SortDialog *dialog) + gint res_id, + SortDialog *dialog) { - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - switch (res_id) - { - case GTK_RESPONSE_OK: - sort_real (dialog); - gtk_widget_destroy (dialog->dialog); - break; + switch (res_id) + { + case GTK_RESPONSE_OK: + sort_real (dialog); + gtk_widget_destroy (dialog->dialog); + break; - case GTK_RESPONSE_HELP: - xed_help_display (GTK_WINDOW (widget), - NULL, - "xed-sort-plugin"); - break; + case GTK_RESPONSE_HELP: + xed_help_display (GTK_WINDOW (widget), NULL, "xed-sort-plugin"); + break; - case GTK_RESPONSE_CANCEL: - gtk_widget_destroy (dialog->dialog); - break; - } + case GTK_RESPONSE_CANCEL: + gtk_widget_destroy (dialog->dialog); + break; + } } /* NOTE: we store the current selection in the dialog since focusing * the text field (like the combo box) looses the documnent selection. * Storing the selection ONLY works because the dialog is modal */ static void -get_current_selection (XedWindow *window, SortDialog *dialog) +get_current_selection (XedWindow *window, + SortDialog *dialog) { - XedDocument *doc; + XedDocument *doc; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - doc = xed_window_get_active_document (window); + doc = xed_window_get_active_document (window); - if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), - &dialog->start, - &dialog->end)) - { - /* No selection, get the whole document. */ - gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), - &dialog->start, - &dialog->end); - } + if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &dialog->start, &dialog->end)) + { + /* No selection, get the whole document. */ + gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &dialog->start, &dialog->end); + } } static SortDialog * get_sort_dialog (XedSortPlugin *plugin) { XedWindow *window; - SortDialog *dialog; - GtkWidget *error_widget; - gboolean ret; - gchar *data_dir; - gchar *ui_file; + SortDialog *dialog; + GtkWidget *error_widget; + gboolean ret; + gchar *data_dir; + gchar *ui_file; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); window = XED_WINDOW (plugin->priv->window); - dialog = g_slice_new (SortDialog); + dialog = g_slice_new (SortDialog); - data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); - ui_file = g_build_filename (data_dir, "sort.ui", NULL); - g_free (data_dir); - ret = xed_utils_get_ui_objects (ui_file, - NULL, - &error_widget, - "sort_dialog", &dialog->dialog, - "reverse_order_checkbutton", &dialog->reverse_order_checkbutton, - "col_num_spinbutton", &dialog->col_num_spinbutton, - "ignore_case_checkbutton", &dialog->ignore_case_checkbutton, - "remove_dups_checkbutton", &dialog->remove_dups_checkbutton, - NULL); - g_free (ui_file); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); + ui_file = g_build_filename (data_dir, "sort.ui", NULL); + g_free (data_dir); + ret = xed_utils_get_ui_objects (ui_file, + NULL, + &error_widget, + "sort_dialog", &dialog->dialog, + "reverse_order_checkbutton", &dialog->reverse_order_checkbutton, + "col_num_spinbutton", &dialog->col_num_spinbutton, + "ignore_case_checkbutton", &dialog->ignore_case_checkbutton, + "remove_dups_checkbutton", &dialog->remove_dups_checkbutton, + NULL); + g_free (ui_file); - if (!ret) - { - const gchar *err_message; + if (!ret) + { + const gchar *err_message; - err_message = gtk_label_get_label (GTK_LABEL (error_widget)); - xed_warning (GTK_WINDOW (window), - "%s", err_message); + err_message = gtk_label_get_label (GTK_LABEL (error_widget)); + xed_warning (GTK_WINDOW (window), "%s", err_message); - g_slice_free (SortDialog, dialog); - gtk_widget_destroy (error_widget); + g_slice_free (SortDialog, dialog); + gtk_widget_destroy (error_widget); - return NULL; - } + return NULL; + } - gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), - GTK_RESPONSE_OK); + gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), GTK_RESPONSE_OK); - g_signal_connect (dialog->dialog, - "destroy", - G_CALLBACK (sort_dialog_destroy), - dialog); + g_signal_connect (dialog->dialog, "destroy", G_CALLBACK (sort_dialog_destroy), dialog); + g_signal_connect (dialog->dialog, "response", G_CALLBACK (sort_dialog_response_handler), dialog); - g_signal_connect (dialog->dialog, - "response", - G_CALLBACK (sort_dialog_response_handler), - dialog); + get_current_selection (window, dialog); - get_current_selection (window, dialog); - - return dialog; + return dialog; } static void -sort_cb (GtkAction *action, - XedSortPlugin *plugin) +sort_cb (GtkAction *action, + XedSortPlugin *plugin) { XedWindow *window; - XedDocument *doc; - GtkWindowGroup *wg; - SortDialog *dialog; + XedDocument *doc; + GtkWindowGroup *wg; + SortDialog *dialog; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - window = XED_WINDOW (plugin->priv->window); + window = XED_WINDOW (plugin->priv->window); doc = xed_window_get_active_document (window); - g_return_if_fail (doc != NULL); + g_return_if_fail (doc != NULL); - dialog = get_sort_dialog (plugin); - g_return_if_fail (dialog != NULL); + dialog = get_sort_dialog (plugin); + g_return_if_fail (dialog != NULL); - wg = xed_window_get_group (window); - gtk_window_group_add_window (wg, - GTK_WINDOW (dialog->dialog)); + wg = xed_window_get_group (window); + gtk_window_group_add_window (wg, GTK_WINDOW (dialog->dialog)); - dialog->doc = doc; + dialog->doc = doc; - gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), - GTK_WINDOW (window)); + gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), GTK_WINDOW (window)); + gtk_window_set_modal (GTK_WINDOW (dialog->dialog), TRUE); - gtk_window_set_modal (GTK_WINDOW (dialog->dialog), - TRUE); - - gtk_widget_show (GTK_WIDGET (dialog->dialog)); + gtk_widget_show (GTK_WIDGET (dialog->dialog)); } /* Compares two strings for the sorting algorithm. Uses the UTF-8 processing * functions in GLib to be as correct as possible.*/ static gint compare_algorithm (gconstpointer s1, - gconstpointer s2, - gpointer data) + gconstpointer s2, + gpointer data) { - gint length1, length2; - gint ret; - gchar *string1, *string2; - gchar *substring1, *substring2; - gchar *key1, *key2; - SortInfo *sort_info; + gint length1, length2; + gint ret; + gchar *string1, *string2; + gchar *substring1, *substring2; + gchar *key1, *key2; + SortInfo *sort_info; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - sort_info = (SortInfo *) data; - g_return_val_if_fail (sort_info != NULL, -1); + sort_info = (SortInfo *) data; + g_return_val_if_fail (sort_info != NULL, -1); - if (!sort_info->ignore_case) - { - string1 = *((gchar **) s1); - string2 = *((gchar **) s2); - } - else - { - string1 = g_utf8_casefold (*((gchar **) s1), -1); - string2 = g_utf8_casefold (*((gchar **) s2), -1); - } + if (!sort_info->ignore_case) + { + string1 = *((gchar **) s1); + string2 = *((gchar **) s2); + } + else + { + string1 = g_utf8_casefold (*((gchar **) s1), -1); + string2 = g_utf8_casefold (*((gchar **) s2), -1); + } - length1 = g_utf8_strlen (string1, -1); - length2 = g_utf8_strlen (string2, -1); + length1 = g_utf8_strlen (string1, -1); + length2 = g_utf8_strlen (string2, -1); - if ((length1 < sort_info->starting_column) && - (length2 < sort_info->starting_column)) - { - ret = 0; - } - else if (length1 < sort_info->starting_column) - { - ret = -1; - } - else if (length2 < sort_info->starting_column) - { - ret = 1; - } - else if (sort_info->starting_column < 1) - { - key1 = g_utf8_collate_key (string1, -1); - key2 = g_utf8_collate_key (string2, -1); - ret = strcmp (key1, key2); + if ((length1 < sort_info->starting_column) && + (length2 < sort_info->starting_column)) + { + ret = 0; + } + else if (length1 < sort_info->starting_column) + { + ret = -1; + } + else if (length2 < sort_info->starting_column) + { + ret = 1; + } + else if (sort_info->starting_column < 1) + { + key1 = g_utf8_collate_key (string1, -1); + key2 = g_utf8_collate_key (string2, -1); + ret = strcmp (key1, key2); - g_free (key1); - g_free (key2); - } - else - { - /* A character column offset is required, so figure out - * the correct offset into the UTF-8 string. */ - substring1 = g_utf8_offset_to_pointer (string1, sort_info->starting_column); - substring2 = g_utf8_offset_to_pointer (string2, sort_info->starting_column); + g_free (key1); + g_free (key2); + } + else + { + /* A character column offset is required, so figure out + * the correct offset into the UTF-8 string. */ + substring1 = g_utf8_offset_to_pointer (string1, sort_info->starting_column); + substring2 = g_utf8_offset_to_pointer (string2, sort_info->starting_column); - key1 = g_utf8_collate_key (substring1, -1); - key2 = g_utf8_collate_key (substring2, -1); - ret = strcmp (key1, key2); + key1 = g_utf8_collate_key (substring1, -1); + key2 = g_utf8_collate_key (substring2, -1); + ret = strcmp (key1, key2); - g_free (key1); - g_free (key2); - } + g_free (key1); + g_free (key2); + } - /* Do the necessary cleanup. */ - if (sort_info->ignore_case) - { - g_free (string1); - g_free (string2); - } + /* Do the necessary cleanup. */ + if (sort_info->ignore_case) + { + g_free (string1); + g_free (string2); + } - if (sort_info->reverse_order) - { - ret = -1 * ret; - } + if (sort_info->reverse_order) + { + ret = -1 * ret; + } - return ret; + return ret; } static gchar * get_line_slice (GtkTextBuffer *buf, - gint line) + gint line) { - GtkTextIter start, end; - char *ret; + GtkTextIter start, end; + char *ret; - gtk_text_buffer_get_iter_at_line (buf, &start, line); - end = start; + gtk_text_buffer_get_iter_at_line (buf, &start, line); + end = start; - if (!gtk_text_iter_ends_line (&start)) - gtk_text_iter_forward_to_line_end (&end); + if (!gtk_text_iter_ends_line (&start)) + { + gtk_text_iter_forward_to_line_end (&end); + } - ret= gtk_text_buffer_get_slice (buf, - &start, - &end, - TRUE); + ret= gtk_text_buffer_get_slice (buf, &start, &end, TRUE); - g_assert (ret != NULL); + g_assert (ret != NULL); - return ret; + return ret; } static void sort_real (SortDialog *dialog) { - XedDocument *doc; - GtkTextIter start, end; - gint start_line, end_line; - gint i; - gchar *last_row = NULL; - gint num_lines; - gchar **lines; - SortInfo *sort_info; + XedDocument *doc; + GtkTextIter start, end; + gint start_line, end_line; + gint i; + gchar *last_row = NULL; + gint num_lines; + gchar **lines; + SortInfo *sort_info; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - doc = dialog->doc; - g_return_if_fail (doc != NULL); + doc = dialog->doc; + g_return_if_fail (doc != NULL); - sort_info = g_new0 (SortInfo, 1); - sort_info->ignore_case = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->ignore_case_checkbutton)); - sort_info->reverse_order = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->reverse_order_checkbutton)); - sort_info->remove_duplicates = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->remove_dups_checkbutton)); - sort_info->starting_column = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dialog->col_num_spinbutton)) - 1; + sort_info = g_new0 (SortInfo, 1); + sort_info->ignore_case = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->ignore_case_checkbutton)); + sort_info->reverse_order = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->reverse_order_checkbutton)); + sort_info->remove_duplicates = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->remove_dups_checkbutton)); + sort_info->starting_column = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dialog->col_num_spinbutton)) - 1; - start = dialog->start; - end = dialog->end; - start_line = gtk_text_iter_get_line (&start); - end_line = gtk_text_iter_get_line (&end); + start = dialog->start; + end = dialog->end; + start_line = gtk_text_iter_get_line (&start); + end_line = gtk_text_iter_get_line (&end); - /* if we are at line start our last line is the previus one. - * Otherwise the last line is the current one but we try to - * move the iter after the line terminator */ - if (gtk_text_iter_get_line_offset (&end) == 0) - end_line = MAX (start_line, end_line - 1); - else - gtk_text_iter_forward_line (&end); + /* if we are at line start our last line is the previus one. + * Otherwise the last line is the current one but we try to + * move the iter after the line terminator */ + if (gtk_text_iter_get_line_offset (&end) == 0) + { + end_line = MAX (start_line, end_line - 1); + } + else + { + gtk_text_iter_forward_line (&end); + } - num_lines = end_line - start_line + 1; - lines = g_new0 (gchar *, num_lines + 1); + num_lines = end_line - start_line + 1; + lines = g_new0 (gchar *, num_lines + 1); - xed_debug_message (DEBUG_PLUGINS, "Building list..."); + xed_debug_message (DEBUG_PLUGINS, "Building list..."); - for (i = 0; i < num_lines; i++) - { - lines[i] = get_line_slice (GTK_TEXT_BUFFER (doc), start_line + i); - } + for (i = 0; i < num_lines; i++) + { + lines[i] = get_line_slice (GTK_TEXT_BUFFER (doc), start_line + i); + } - lines[num_lines] = NULL; + lines[num_lines] = NULL; - xed_debug_message (DEBUG_PLUGINS, "Sort list..."); + xed_debug_message (DEBUG_PLUGINS, "Sort list..."); - g_qsort_with_data (lines, - num_lines, - sizeof (gpointer), - compare_algorithm, - sort_info); + g_qsort_with_data (lines, num_lines, sizeof (gpointer), compare_algorithm, sort_info); - xed_debug_message (DEBUG_PLUGINS, "Rebuilding document..."); + xed_debug_message (DEBUG_PLUGINS, "Rebuilding document..."); - gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (doc)); + gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (doc)); - gtk_text_buffer_delete (GTK_TEXT_BUFFER (doc), - &start, - &end); + gtk_text_buffer_delete (GTK_TEXT_BUFFER (doc), &start, &end); - for (i = 0; i < num_lines; i++) - { - if (sort_info->remove_duplicates && - last_row != NULL && - (strcmp (last_row, lines[i]) == 0)) - continue; + for (i = 0; i < num_lines; i++) + { + if (sort_info->remove_duplicates && last_row != NULL && (strcmp (last_row, lines[i]) == 0)) + { + continue; + } - gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), - &start, - lines[i], - -1); - gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), - &start, - "\n", - -1); + gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), &start, lines[i], -1); + gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), &start, "\n", -1); - last_row = lines[i]; - } + last_row = lines[i]; + } - gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (doc)); + gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (doc)); - g_strfreev (lines); - g_free (sort_info); + g_strfreev (lines); + g_free (sort_info); - xed_debug_message (DEBUG_PLUGINS, "Done."); + xed_debug_message (DEBUG_PLUGINS, "Done."); } static void @@ -457,9 +432,9 @@ xed_sort_plugin_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - XedSortPlugin *plugin = XED_SORT_PLUGIN (object); + XedSortPlugin *plugin = XED_SORT_PLUGIN (object); - switch (prop_id) + switch (prop_id) { case PROP_OBJECT: plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); @@ -476,9 +451,9 @@ xed_sort_plugin_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - XedSortPlugin *plugin = XED_SORT_PLUGIN (object); + XedSortPlugin *plugin = XED_SORT_PLUGIN (object); - switch (prop_id) + switch (prop_id) { case PROP_OBJECT: g_value_set_object (value, plugin->priv->window); @@ -493,16 +468,16 @@ static void update_ui (XedSortPluginPrivate *data) { XedWindow *window; - XedView *view; + XedView *view; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); window = XED_WINDOW (data->window); - view = xed_window_get_active_view (window); + view = xed_window_get_active_view (window); - gtk_action_group_set_sensitive (data->ui_action_group, - (view != NULL) && - gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); + gtk_action_group_set_sensitive (data->ui_action_group, + (view != NULL) && + gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); } static void @@ -511,39 +486,36 @@ xed_sort_plugin_activate (PeasActivatable *activatable) XedSortPlugin *plugin; XedSortPluginPrivate *data; XedWindow *window; - GtkUIManager *manager; + GtkUIManager *manager; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - plugin = XED_SORT_PLUGIN (activatable); + plugin = XED_SORT_PLUGIN (activatable); data = plugin->priv; window = XED_WINDOW (data->window); - manager = xed_window_get_ui_manager (window); + manager = xed_window_get_ui_manager (window); - data->ui_action_group = gtk_action_group_new ("XedSortPluginActions"); - gtk_action_group_set_translation_domain (data->ui_action_group, - GETTEXT_PACKAGE); - gtk_action_group_add_actions (data->ui_action_group, - action_entries, - G_N_ELEMENTS (action_entries), - plugin); + data->ui_action_group = gtk_action_group_new ("XedSortPluginActions"); + gtk_action_group_set_translation_domain (data->ui_action_group, GETTEXT_PACKAGE); + gtk_action_group_add_actions (data->ui_action_group, + action_entries, + G_N_ELEMENTS (action_entries), + plugin); - gtk_ui_manager_insert_action_group (manager, - data->ui_action_group, - -1); + gtk_ui_manager_insert_action_group (manager, data->ui_action_group, -1); - data->ui_id = gtk_ui_manager_new_merge_id (manager); + data->ui_id = gtk_ui_manager_new_merge_id (manager); - gtk_ui_manager_add_ui (manager, - data->ui_id, - MENU_PATH, - "Sort", - "Sort", - GTK_UI_MANAGER_MENUITEM, - FALSE); + gtk_ui_manager_add_ui (manager, + data->ui_id, + MENU_PATH, + "Sort", + "Sort", + GTK_UI_MANAGER_MENUITEM, + FALSE); - update_ui (data); + update_ui (data); } static void @@ -551,33 +523,31 @@ xed_sort_plugin_deactivate (PeasActivatable *activatable) { XedSortPluginPrivate *data; XedWindow *window; - GtkUIManager *manager; + GtkUIManager *manager; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - data = XED_SORT_PLUGIN (activatable)->priv; + data = XED_SORT_PLUGIN (activatable)->priv; window = XED_WINDOW (data->window); - manager = xed_window_get_ui_manager (window); + manager = xed_window_get_ui_manager (window); - gtk_ui_manager_remove_ui (manager, - data->ui_id); - gtk_ui_manager_remove_action_group (manager, - data->ui_action_group); + gtk_ui_manager_remove_ui (manager, data->ui_id); + gtk_ui_manager_remove_action_group (manager, data->ui_action_group); } static void xed_sort_plugin_update_state (PeasActivatable *activatable) { - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - update_ui (XED_SORT_PLUGIN (activatable)->priv); + update_ui (XED_SORT_PLUGIN (activatable)->priv); } static void xed_sort_plugin_init (XedSortPlugin *plugin) { - xed_debug_message (DEBUG_PLUGINS, "XedSortPlugin initializing"); + xed_debug_message (DEBUG_PLUGINS, "XedSortPlugin initializing"); plugin->priv = XED_SORT_PLUGIN_GET_PRIVATE (plugin); } @@ -585,7 +555,7 @@ xed_sort_plugin_init (XedSortPlugin *plugin) static void xed_sort_plugin_dispose (GObject *object) { - XedSortPlugin *plugin = XED_SORT_PLUGIN (object); + XedSortPlugin *plugin = XED_SORT_PLUGIN (object); xed_debug_message (DEBUG_PLUGINS, "XedSortPlugin disposing"); @@ -601,15 +571,15 @@ xed_sort_plugin_dispose (GObject *object) plugin->priv->ui_action_group = NULL; } - G_OBJECT_CLASS (xed_sort_plugin_parent_class)->dispose (object); + G_OBJECT_CLASS (xed_sort_plugin_parent_class)->dispose (object); } static void xed_sort_plugin_class_init (XedSortPluginClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->dispose = xed_sort_plugin_dispose; + object_class->dispose = xed_sort_plugin_dispose; object_class->set_property = xed_sort_plugin_set_property; object_class->get_property = xed_sort_plugin_get_property; @@ -637,7 +607,7 @@ peas_register_types (PeasObjectModule *module) { xed_sort_plugin_register_type (G_TYPE_MODULE (module)); - peas_object_module_register_extension_type (module, + peas_object_module_register_extension_type (module, PEAS_TYPE_ACTIVATABLE, XED_TYPE_SORT_PLUGIN); } From c78bf46d380fefcc784c55d1ba74ea63541d528e Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 23:43:42 -0800 Subject: [PATCH 043/132] Add buttons to the statusbar to show/hide the panels --- xed/xed-statusbar.c | 4 -- xed/xed-window-private.h | 103 ++++++++++++++++++++------------------- xed/xed-window.c | 75 ++++++++++++++++++++++------ 3 files changed, 113 insertions(+), 69 deletions(-) diff --git a/xed/xed-statusbar.c b/xed/xed-statusbar.c index b287acc..05f2d40 100644 --- a/xed/xed-statusbar.c +++ b/xed/xed-statusbar.c @@ -179,10 +179,6 @@ xed_statusbar_init (XedStatusbar *statusbar) gtk_box_pack_start (GTK_BOX (statusbar), statusbar->priv->error_frame, FALSE, TRUE, 0); - - gtk_box_reorder_child (GTK_BOX (statusbar), - statusbar->priv->error_frame, - 0); } /** diff --git a/xed/xed-window-private.h b/xed/xed-window-private.h index 84a4b99..4cc95ce 100644 --- a/xed/xed-window-private.h +++ b/xed/xed-window-private.h @@ -43,75 +43,78 @@ G_BEGIN_DECLS struct _XedWindowPrivate { - GtkWidget *notebook; + GtkWidget *notebook; - GtkWidget *side_panel; - GtkWidget *bottom_panel; + GtkWidget *side_panel; + GtkWidget *bottom_panel; - GtkWidget *hpaned; - GtkWidget *vpaned; + GtkWidget *hpaned; + GtkWidget *vpaned; - GtkWidget *tab_width_combo; - GtkWidget *language_combo; + GtkWidget *tab_width_combo; + GtkWidget *language_combo; + GtkWidget *show_side_pane_button; + GtkWidget *show_bottom_pane_button; + GtkWidget *bottom_pane_button_revealer; - XedMessageBus *message_bus; + XedMessageBus *message_bus; PeasExtensionSet *extensions; - /* Widgets for fullscreen mode */ - GtkWidget *fullscreen_controls; + /* Widgets for fullscreen mode */ + GtkWidget *fullscreen_controls; GtkWidget *fullscreen_controls_container; - guint fullscreen_animation_timeout_id; - gboolean fullscreen_animation_enter; + guint fullscreen_animation_timeout_id; + gboolean fullscreen_animation_enter; - /* statusbar and context ids for statusbar messages */ - GtkWidget *statusbar; - GtkWidget *searchbar; - guint generic_message_cid; - guint tip_message_cid; - guint tab_width_id; - guint spaces_instead_of_tabs_id; - guint language_changed_id; + /* statusbar and context ids for statusbar messages */ + GtkWidget *statusbar; + GtkWidget *searchbar; + guint generic_message_cid; + guint tip_message_cid; + guint tab_width_id; + guint spaces_instead_of_tabs_id; + guint language_changed_id; - /* Menus & Toolbars */ - GtkUIManager *manager; - GtkActionGroup *action_group; - GtkActionGroup *always_sensitive_action_group; - GtkActionGroup *close_action_group; - GtkActionGroup *quit_action_group; - GtkActionGroup *panes_action_group; - GtkActionGroup *languages_action_group; - GtkActionGroup *documents_list_action_group; - guint documents_list_menu_ui_id; - GtkWidget *toolbar; - GtkWidget *menubar; + /* Menus & Toolbars */ + GtkUIManager *manager; + GtkActionGroup *action_group; + GtkActionGroup *always_sensitive_action_group; + GtkActionGroup *close_action_group; + GtkActionGroup *quit_action_group; + GtkActionGroup *panes_action_group; + GtkActionGroup *languages_action_group; + GtkActionGroup *documents_list_action_group; + guint documents_list_menu_ui_id; + GtkWidget *toolbar; + GtkWidget *menubar; - /* recent files */ - GtkActionGroup *recents_action_group; - guint recents_menu_ui_id; - gulong recents_handler_id; + /* recent files */ + GtkActionGroup *recents_action_group; + guint recents_menu_ui_id; + gulong recents_handler_id; - XedTab *active_tab; - gint num_tabs; + XedTab *active_tab; + gint num_tabs; - gint num_tabs_with_error; + gint num_tabs_with_error; - gint width; - gint height; - GdkWindowState window_state; + gint width; + gint height; + GdkWindowState window_state; - gint side_panel_size; - gint bottom_panel_size; + gint side_panel_size; + gint bottom_panel_size; - XedWindowState state; + XedWindowState state; - gint bottom_panel_item_removed_handler_id; + gint bottom_panel_item_removed_handler_id; - GtkWindowGroup *window_group; + GtkWindowGroup *window_group; - GFile *default_location; + GFile *default_location; - gboolean removing_tabs : 1; - gboolean dispose_has_run : 1; + gboolean removing_tabs : 1; + gboolean dispose_has_run : 1; }; G_END_DECLS diff --git a/xed/xed-window.c b/xed/xed-window.c index 2967974..b509ebc 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -1619,14 +1619,18 @@ static void create_statusbar (XedWindow *window, GtkWidget *main_box) { + GtkWidget *image; + GtkWidget *button_box; + GtkAction *action; + xed_debug (DEBUG_WINDOW); window->priv->statusbar = xed_statusbar_new (); window->priv->searchbar = xed_searchbar_new (window, TRUE); - window->priv->generic_message_cid = gtk_statusbar_get_context_id (GTK_STATUSBAR(window->priv->statusbar), + window->priv->generic_message_cid = gtk_statusbar_get_context_id (GTK_STATUSBAR (window->priv->statusbar), "generic_message"); - window->priv->tip_message_cid = gtk_statusbar_get_context_id (GTK_STATUSBAR(window->priv->statusbar), + window->priv->tip_message_cid = gtk_statusbar_get_context_id (GTK_STATUSBAR (window->priv->statusbar), "tip_message"); gtk_box_pack_end (GTK_BOX(main_box), window->priv->statusbar, FALSE, TRUE, 0); @@ -1649,6 +1653,38 @@ create_statusbar (XedWindow *window, g_signal_connect(G_OBJECT (window->priv->language_combo), "changed", G_CALLBACK (language_combo_changed), window); + button_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); + gtk_widget_set_margin_top (button_box, 4); + gtk_widget_set_margin_bottom (button_box, 4); + gtk_box_pack_start (GTK_BOX (window->priv->statusbar), button_box, FALSE, FALSE, 0); + + window->priv->show_side_pane_button = gtk_toggle_button_new (); + image = gtk_image_new_from_icon_name ("view-left-pane-symbolic", GTK_ICON_SIZE_INVALID); + gtk_image_set_pixel_size (GTK_IMAGE (image), 12); + gtk_container_add (GTK_CONTAINER (window->priv->show_side_pane_button), image); + gtk_box_pack_start (GTK_BOX (button_box), window->priv->show_side_pane_button, FALSE, FALSE, 0); + + action = gtk_action_group_get_action (window->priv->panes_action_group, "ViewSidePane"); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (window->priv->show_side_pane_button), action); + gtk_widget_set_tooltip_text (window->priv->show_side_pane_button, gtk_action_get_tooltip (action)); + + window->priv->bottom_pane_button_revealer = gtk_revealer_new (); + gtk_revealer_set_transition_type (GTK_REVEALER (window->priv->bottom_pane_button_revealer), + GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT); + gtk_box_pack_start (GTK_BOX (button_box), window->priv->bottom_pane_button_revealer, FALSE, FALSE, 0); + + window->priv->show_bottom_pane_button = gtk_toggle_button_new (); + image = gtk_image_new_from_icon_name ("view-bottom-pane-symbolic", GTK_ICON_SIZE_INVALID); + gtk_image_set_pixel_size (GTK_IMAGE (image), 12); + gtk_container_add (GTK_CONTAINER (window->priv->show_bottom_pane_button), image); + gtk_container_add (GTK_CONTAINER (window->priv->bottom_pane_button_revealer), window->priv->show_bottom_pane_button); + + action = gtk_action_group_get_action (window->priv->panes_action_group, "ViewBottomPane"); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (window->priv->show_bottom_pane_button), action); + gtk_widget_set_tooltip_text (window->priv->show_bottom_pane_button, gtk_action_get_tooltip (action)); + + gtk_widget_show_all (button_box); + g_signal_connect_after(G_OBJECT (window->priv->statusbar), "show", G_CALLBACK (statusbar_visibility_changed), window); @@ -1657,8 +1693,9 @@ create_statusbar (XedWindow *window, set_statusbar_style (window, NULL); - gtk_box_pack_end (GTK_BOX(main_box), window->priv->searchbar, FALSE, FALSE, 0); + gtk_box_pack_end (GTK_BOX (main_box), window->priv->searchbar, FALSE, FALSE, 0); + gtk_box_reorder_child (GTK_BOX (window->priv->statusbar), button_box, 0); } static XedWindow * @@ -3102,7 +3139,7 @@ bottom_panel_visibility_changed (XedPanel *bottom_panel, gboolean visible; GtkAction *action; - visible = gtk_widget_get_visible (GTK_WIDGET(bottom_panel)); + visible = gtk_widget_get_visible (GTK_WIDGET (bottom_panel)); if (xed_prefs_manager_bottom_panel_visible_can_set ()) { @@ -3124,21 +3161,23 @@ bottom_panel_visibility_changed (XedPanel *bottom_panel, } static void -bottom_panel_item_removed (XedPanel *panel, +bottom_panel_item_removed (XedPanel *panel, GtkWidget *item, XedWindow *window) { if (xed_panel_get_n_items (panel) == 0) { GtkAction *action; - gtk_widget_hide (GTK_WIDGET(panel)); + + gtk_widget_hide (GTK_WIDGET (panel)); + gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->bottom_pane_button_revealer), FALSE); action = gtk_action_group_get_action (window->priv->panes_action_group, "ViewBottomPane"); gtk_action_set_sensitive (action, FALSE); } } static void -bottom_panel_item_added (XedPanel *panel, +bottom_panel_item_added (XedPanel *panel, GtkWidget *item, XedWindow *window) { @@ -3148,9 +3187,12 @@ bottom_panel_item_added (XedPanel *panel, { GtkAction *action; gboolean show; + + gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->bottom_pane_button_revealer), TRUE); + action = gtk_action_group_get_action (window->priv->panes_action_group, "ViewBottomPane"); gtk_action_set_sensitive (action, TRUE); - show = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION(action)); + show = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); if (show) { gtk_widget_show (GTK_WIDGET(panel)); @@ -3163,9 +3205,7 @@ create_bottom_panel (XedWindow *window) { xed_debug (DEBUG_WINDOW); window->priv->bottom_panel = xed_panel_new (GTK_ORIENTATION_HORIZONTAL); - gtk_paned_pack2 (GTK_PANED(window->priv->vpaned), window->priv->bottom_panel, - FALSE, - FALSE); + gtk_paned_pack2 (GTK_PANED (window->priv->vpaned), window->priv->bottom_panel, FALSE, FALSE); g_signal_connect_after(window->priv->bottom_panel, "show", G_CALLBACK (bottom_panel_visibility_changed), window); g_signal_connect_after(window->priv->bottom_panel, "hide", G_CALLBACK (bottom_panel_visibility_changed), window); } @@ -3178,7 +3218,7 @@ init_panels_visibility (XedWindow *window) /* side pane */ active_page = xed_prefs_manager_get_side_panel_active_page (); - _xed_panel_set_active_item_by_id (XED_PANEL(window->priv->side_panel), active_page); + _xed_panel_set_active_item_by_id (XED_PANEL (window->priv->side_panel), active_page); if (xed_prefs_manager_get_side_pane_visible ()) { @@ -3186,7 +3226,7 @@ init_panels_visibility (XedWindow *window) } /* bottom pane, it can be empty */ - if (xed_panel_get_n_items (XED_PANEL(window->priv->bottom_panel)) > 0) + if (xed_panel_get_n_items (XED_PANEL (window->priv->bottom_panel)) > 0) { active_page = xed_prefs_manager_get_bottom_panel_active_page (); _xed_panel_set_active_item_by_id (XED_PANEL(window->priv->bottom_panel), active_page); @@ -3195,17 +3235,22 @@ init_panels_visibility (XedWindow *window) { gtk_widget_show (window->priv->bottom_panel); } + + gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->bottom_pane_button_revealer), TRUE); } else { GtkAction *action; + action = gtk_action_group_get_action (window->priv->panes_action_group, "ViewBottomPane"); gtk_action_set_sensitive (action, FALSE); + gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->bottom_pane_button_revealer), FALSE); } /* start track sensitivity after the initial state is set */ - window->priv->bottom_panel_item_removed_handler_id = g_signal_connect(window->priv->bottom_panel, "item_removed", - G_CALLBACK (bottom_panel_item_removed), window); + window->priv->bottom_panel_item_removed_handler_id = + g_signal_connect (window->priv->bottom_panel, "item_removed", + G_CALLBACK (bottom_panel_item_removed), window); g_signal_connect(window->priv->bottom_panel, "item_added", G_CALLBACK (bottom_panel_item_added), window); } From 5d258f1e67a18c14894b48c8ddc938e8dbb8b5bd Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Tue, 27 Dec 2016 00:17:15 -0800 Subject: [PATCH 044/132] xed-window: Stop using deprecated (v/h)box --- xed/xed-window.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/xed/xed-window.c b/xed/xed-window.c index b509ebc..8360e1c 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -3352,7 +3352,7 @@ xed_window_init (XedWindow *window) xed_debug (DEBUG_WINDOW); - window->priv = XED_WINDOW_GET_PRIVATE(window); + window->priv = XED_WINDOW_GET_PRIVATE (window); window->priv->active_tab = NULL; window->priv->num_tabs = 0; window->priv->removing_tabs = FALSE; @@ -3364,10 +3364,10 @@ xed_window_init (XedWindow *window) window->priv->message_bus = xed_message_bus_new (); window->priv->window_group = gtk_window_group_new (); - gtk_window_group_add_window (window->priv->window_group, GTK_WINDOW(window)); + gtk_window_group_add_window (window->priv->window_group, GTK_WINDOW (window)); main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - gtk_container_add (GTK_CONTAINER(window), main_box); + gtk_container_add (GTK_CONTAINER (window), main_box); gtk_widget_show (main_box); /* Add menu bar and toolbar bar */ @@ -3377,12 +3377,12 @@ xed_window_init (XedWindow *window) if (geteuid () == 0) { GtkWidget *root_bar = gtk_info_bar_new (); - gtk_info_bar_set_message_type (GTK_INFO_BAR(root_bar), GTK_MESSAGE_ERROR); - GtkWidget *content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR(root_bar)); + gtk_info_bar_set_message_type (GTK_INFO_BAR (root_bar), GTK_MESSAGE_ERROR); + GtkWidget *content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (root_bar)); GtkWidget *label = gtk_label_new (_("Elevated Privileges")); gtk_widget_show (label); - gtk_container_add (GTK_CONTAINER(content_area), label); - gtk_box_pack_start (GTK_BOX(main_box), root_bar, FALSE, FALSE, 0); + gtk_container_add (GTK_CONTAINER (content_area), label); + gtk_box_pack_start (GTK_BOX (main_box), root_bar, FALSE, FALSE, 0); gtk_widget_set_visible (root_bar, TRUE); } @@ -3391,12 +3391,11 @@ xed_window_init (XedWindow *window) /* Add the main area */ xed_debug_message (DEBUG_WINDOW, "Add main area"); - window->priv->hpaned = gtk_hpaned_new (); - gtk_box_pack_start (GTK_BOX(main_box), window->priv->hpaned, TRUE, TRUE, 0); + window->priv->hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL); + gtk_box_pack_start (GTK_BOX (main_box), window->priv->hpaned, TRUE, TRUE, 0); - window->priv->vpaned = gtk_vpaned_new (); - gtk_paned_pack2 (GTK_PANED(window->priv->hpaned), window->priv->vpaned, TRUE, - FALSE); + window->priv->vpaned = gtk_paned_new (GTK_ORIENTATION_VERTICAL); + gtk_paned_pack2 (GTK_PANED (window->priv->hpaned), window->priv->vpaned, TRUE, FALSE); xed_debug_message (DEBUG_WINDOW, "Create xed notebook"); window->priv->notebook = xed_notebook_new (); @@ -3423,30 +3422,28 @@ xed_window_init (XedWindow *window) NULL, 0, GDK_ACTION_COPY); /* Add uri targets */ - tl = gtk_drag_dest_get_target_list (GTK_WIDGET(window)); + tl = gtk_drag_dest_get_target_list (GTK_WIDGET (window)); if (tl == NULL) { tl = gtk_target_list_new (NULL, 0); - gtk_drag_dest_set_target_list (GTK_WIDGET(window), tl); + gtk_drag_dest_set_target_list (GTK_WIDGET (window), tl); gtk_target_list_unref (tl); } gtk_target_list_add_uri_targets (tl, TARGET_URI_LIST); - /* connect instead of override, so that we can - * share the cb code with the view */ - g_signal_connect(window, "drag_data_received", G_CALLBACK (drag_data_received_cb), NULL); + /* connect instead of override, so that we can share the cb code with the view */ + g_signal_connect (window, "drag_data_received", G_CALLBACK (drag_data_received_cb), NULL); - /* we can get the clipboard only after the widget - * is realized */ - g_signal_connect(window, "realize", G_CALLBACK (window_realized), NULL); - g_signal_connect(window, "unrealize", G_CALLBACK (window_unrealized), NULL); + /* we can get the clipboard only after the widget is realized */ + g_signal_connect (window, "realize", G_CALLBACK (window_realized), NULL); + g_signal_connect (window, "unrealize", G_CALLBACK (window_unrealized), NULL); /* Check if the window is active for fullscreen */ - g_signal_connect(window, "notify::is-active", G_CALLBACK (check_window_is_active), NULL); + g_signal_connect (window, "notify::is-active", G_CALLBACK (check_window_is_active), NULL); - g_signal_connect(GTK_WIDGET (window), "key-press-event", G_CALLBACK (on_key_pressed), window); + g_signal_connect (GTK_WIDGET (window), "key-press-event", G_CALLBACK (on_key_pressed), window); xed_debug_message (DEBUG_WINDOW, "Update plugins ui"); From 6bc12a2be07e7b125eeb3f630ecf6c66d8c90c32 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Tue, 27 Dec 2016 01:11:19 -0800 Subject: [PATCH 045/132] xed-panel: Remove the header and close button Now that we have the buttons on the statusbar for opening and closing the side and bottom panels, we don't really need these anymore --- xed/xed-panel.c | 141 +----------------------------------------------- 1 file changed, 1 insertion(+), 140 deletions(-) diff --git a/xed/xed-panel.c b/xed/xed-panel.c index 0d0bb70..90d9a7f 100644 --- a/xed/xed-panel.c +++ b/xed/xed-panel.c @@ -48,12 +48,6 @@ struct _XedPanelPrivate GtkOrientation orientation; GtkWidget *main_box; - - /* Title bar (vertical panel only) */ - GtkWidget *title_image; - GtkWidget *title_label; - - /* Notebook */ GtkWidget *notebook; }; @@ -391,63 +385,6 @@ set_gtk_image_from_gtk_image (GtkImage *image, } } -static void -sync_title (XedPanel *panel, - XedPanelItem *item) -{ - if (panel->priv->orientation != GTK_ORIENTATION_VERTICAL) - { - return; - } - - if (item != NULL) - { - gtk_label_set_text (GTK_LABEL (panel->priv->title_label), item->name); - - set_gtk_image_from_gtk_image (GTK_IMAGE (panel->priv->title_image), GTK_IMAGE (item->icon)); - } - else - { - gtk_label_set_text (GTK_LABEL (panel->priv->title_label), _("Empty")); - gtk_image_set_from_stock (GTK_IMAGE (panel->priv->title_image), GTK_STOCK_FILE, GTK_ICON_SIZE_MENU); - } -} - -static void -notebook_page_changed (GtkNotebook *notebook, - GtkWidget *page, - guint page_num, - XedPanel *panel) -{ - GtkWidget *item; - XedPanelItem *data; - - item = gtk_notebook_get_nth_page (notebook, page_num); - g_return_if_fail (item != NULL); - - data = (XedPanelItem *)g_object_get_data (G_OBJECT (item), PANEL_ITEM_KEY); - g_return_if_fail (data != NULL); - - sync_title (panel, data); -} - -static void -panel_show (XedPanel *panel, - gpointer user_data) -{ - gint page; - GtkNotebook *nb; - - nb = GTK_NOTEBOOK (panel->priv->notebook); - - page = gtk_notebook_get_current_page (nb); - - if (page != -1) - { - notebook_page_changed (nb, NULL, page, panel); - } -} - static void xed_panel_init (XedPanel *panel) { @@ -458,25 +395,6 @@ xed_panel_init (XedPanel *panel) gtk_container_add (GTK_CONTAINER (panel), panel->priv->main_box); } -static void -close_button_clicked_cb (GtkWidget *widget, - GtkWidget *panel) -{ - gtk_widget_hide (panel); -} - -static GtkWidget * -create_close_button (XedPanel *panel) -{ - GtkWidget *button; - - button = xed_close_button_new (); - gtk_widget_set_tooltip_text (button, _("Hide panel")); - g_signal_connect (button, "clicked", G_CALLBACK (close_button_clicked_cb), panel); - - return button; -} - static void build_notebook_for_panel (XedPanel *panel) { @@ -488,66 +406,17 @@ build_notebook_for_panel (XedPanel *panel) gtk_notebook_popup_enable (GTK_NOTEBOOK (panel->priv->notebook)); gtk_widget_show (GTK_WIDGET (panel->priv->notebook)); - - g_signal_connect (panel->priv->notebook, "switch-page", G_CALLBACK (notebook_page_changed), panel); } static void build_horizontal_panel (XedPanel *panel) { - GtkWidget *box; - GtkWidget *sidebar; - GtkWidget *close_button; - - box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_start (GTK_BOX (box), panel->priv->notebook, TRUE, TRUE, 0); - - /* Toolbar, close button and first separator */ - sidebar = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6); - gtk_container_set_border_width (GTK_CONTAINER (sidebar), 4); - gtk_box_pack_start (GTK_BOX (box), sidebar, FALSE, FALSE, 0); - - close_button = create_close_button (panel); - gtk_box_pack_start (GTK_BOX (sidebar), close_button, FALSE, FALSE, 0); - - gtk_widget_show_all (box); - - gtk_box_pack_start (GTK_BOX (panel->priv->main_box), box, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (panel->priv->main_box), panel->priv->notebook, TRUE, TRUE, 0); } static void build_vertical_panel (XedPanel *panel) { - GtkWidget *close_button; - GtkWidget *title_hbox; - GtkWidget *icon_name_hbox; - GtkWidget *dummy_label; - - /* Create title hbox */ - title_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_container_set_border_width (GTK_CONTAINER (title_hbox), 5); - - gtk_box_pack_start (GTK_BOX (panel->priv->main_box), title_hbox, FALSE, FALSE, 0); - - icon_name_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_start (GTK_BOX (title_hbox), icon_name_hbox, TRUE, TRUE, 0); - - panel->priv->title_image = gtk_image_new_from_stock (GTK_STOCK_FILE, GTK_ICON_SIZE_MENU); - gtk_box_pack_start (GTK_BOX (icon_name_hbox), panel->priv->title_image, FALSE, TRUE, 0); - - dummy_label = gtk_label_new (" "); - gtk_box_pack_start (GTK_BOX (icon_name_hbox), dummy_label, FALSE, FALSE, 0); - - panel->priv->title_label = gtk_label_new (_("Empty")); - gtk_misc_set_alignment (GTK_MISC (panel->priv->title_label), 0, 0.5); - gtk_label_set_ellipsize(GTK_LABEL (panel->priv->title_label), PANGO_ELLIPSIZE_END); - gtk_box_pack_start (GTK_BOX (icon_name_hbox), panel->priv->title_label, TRUE, TRUE, 0); - - close_button = create_close_button (panel); - gtk_box_pack_start (GTK_BOX (title_hbox), close_button, FALSE, FALSE, 0); - - gtk_widget_show_all (title_hbox); - gtk_box_pack_start (GTK_BOX (panel->priv->main_box), panel->priv->notebook, TRUE, TRUE, 0); } @@ -575,8 +444,6 @@ xed_panel_constructor (GType type, build_vertical_panel (panel); } - g_signal_connect (panel, "show", G_CALLBACK (panel_show), NULL); - return obj; } @@ -772,12 +639,6 @@ xed_panel_remove_item (XedPanel *panel, gtk_notebook_remove_page (GTK_NOTEBOOK (panel->priv->notebook), page_num); - /* if we removed all the pages, reset the title */ - if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (panel->priv->notebook)) == 0) - { - sync_title (panel, NULL); - } - g_signal_emit (G_OBJECT (panel), signals[ITEM_REMOVED], 0, item); g_object_unref (G_OBJECT (item)); From 4635766fc720dda109e680178e5dc4b284eeee0f Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Tue, 27 Dec 2016 01:30:36 -0800 Subject: [PATCH 046/132] xed-panel: Simplify panel building a bit Now that the panel headers are removed, we no longer need separate functions for creating panels of different orientations --- xed/xed-panel.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/xed/xed-panel.c b/xed/xed-panel.c index 90d9a7f..d6c4dcb 100644 --- a/xed/xed-panel.c +++ b/xed/xed-panel.c @@ -408,18 +408,6 @@ build_notebook_for_panel (XedPanel *panel) gtk_widget_show (GTK_WIDGET (panel->priv->notebook)); } -static void -build_horizontal_panel (XedPanel *panel) -{ - gtk_box_pack_start (GTK_BOX (panel->priv->main_box), panel->priv->notebook, TRUE, TRUE, 0); -} - -static void -build_vertical_panel (XedPanel *panel) -{ - gtk_box_pack_start (GTK_BOX (panel->priv->main_box), panel->priv->notebook, TRUE, TRUE, 0); -} - static GObject * xed_panel_constructor (GType type, guint n_construct_properties, @@ -435,14 +423,7 @@ xed_panel_constructor (GType type, XedPanel *panel = XED_PANEL (obj); build_notebook_for_panel (panel); - if (panel->priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - build_horizontal_panel (panel); - } - else - { - build_vertical_panel (panel); - } + gtk_box_pack_start (GTK_BOX (panel->priv->main_box), panel->priv->notebook, TRUE, TRUE, 0); return obj; } From 5058c692881386d16a415d720f4e9f5fbd76bd00 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Tue, 27 Dec 2016 11:44:05 -0800 Subject: [PATCH 047/132] xed-panel: Move the notebook tabs to the top --- xed/xed-panel.c | 1 - 1 file changed, 1 deletion(-) diff --git a/xed/xed-panel.c b/xed/xed-panel.c index d6c4dcb..bcffb17 100644 --- a/xed/xed-panel.c +++ b/xed/xed-panel.c @@ -401,7 +401,6 @@ build_notebook_for_panel (XedPanel *panel) /* Create the panel notebook */ panel->priv->notebook = gtk_notebook_new (); - gtk_notebook_set_tab_pos (GTK_NOTEBOOK (panel->priv->notebook), GTK_POS_BOTTOM); gtk_notebook_set_scrollable (GTK_NOTEBOOK (panel->priv->notebook), TRUE); gtk_notebook_popup_enable (GTK_NOTEBOOK (panel->priv->notebook)); From 9c9e564ec1fcc20682d52619e67f477b4154366f Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Wed, 28 Dec 2016 11:44:35 -0800 Subject: [PATCH 048/132] Add a few style classes This will allow themes a bit more control over the styling. Since you can no longer select objects by class name in gtk version > 3.20 there is no other easy way to theme these elements. Added classes for "xed-window", "xed-searchbar", "xed-statusbar", and "xed-panel" with additional classes of "side" and "bottom" for the panels --- xed/xed-panel.c | 11 +++++++++++ xed/xed-searchbar.c | 2 ++ xed/xed-statusbar.c | 2 ++ xed/xed-window.c | 12 ++++++------ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/xed/xed-panel.c b/xed/xed-panel.c index bcffb17..fab35d3 100644 --- a/xed/xed-panel.c +++ b/xed/xed-panel.c @@ -424,6 +424,17 @@ xed_panel_constructor (GType type, build_notebook_for_panel (panel); gtk_box_pack_start (GTK_BOX (panel->priv->main_box), panel->priv->notebook, TRUE, TRUE, 0); + gtk_style_context_add_class (gtk_widget_get_style_context (panel), "xed-panel"); + + if (panel->priv->orientation == GTK_ORIENTATION_VERTICAL) + { + gtk_style_context_add_class (gtk_widget_get_style_context (panel), "side"); + } + else + { + gtk_style_context_add_class (gtk_widget_get_style_context (panel), "bottom"); + } + return obj; } diff --git a/xed/xed-searchbar.c b/xed/xed-searchbar.c index 996b9a7..09de427 100755 --- a/xed/xed-searchbar.c +++ b/xed/xed-searchbar.c @@ -564,6 +564,8 @@ xed_searchbar_init (XedSearchbar *searchbar) NULL); g_free (file); + gtk_style_context_add_class (gtk_widget_get_style_context (searchbar), "xed-searchbar"); + searchbar->priv->search_entry = xed_history_entry_new ("history-search-for", TRUE); gtk_widget_set_hexpand (searchbar->priv->search_entry, TRUE); xed_history_entry_set_escape_func (XED_HISTORY_ENTRY (searchbar->priv->search_entry), diff --git a/xed/xed-statusbar.c b/xed/xed-statusbar.c index 05f2d40..ba104e5 100644 --- a/xed/xed-statusbar.c +++ b/xed/xed-statusbar.c @@ -179,6 +179,8 @@ xed_statusbar_init (XedStatusbar *statusbar) gtk_box_pack_start (GTK_BOX (statusbar), statusbar->priv->error_frame, FALSE, TRUE, 0); + + gtk_style_context_add_class (gtk_widget_get_style_context (statusbar), "xed-statusbar"); } /** diff --git a/xed/xed-window.c b/xed/xed-window.c index 8360e1c..138093f 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -3120,15 +3120,13 @@ create_side_panel (XedWindow *window) window->priv->side_panel = xed_panel_new (GTK_ORIENTATION_VERTICAL); - gtk_paned_pack1 (GTK_PANED(window->priv->hpaned), window->priv->side_panel, - FALSE, - FALSE); + gtk_paned_pack1 (GTK_PANED (window->priv->hpaned), window->priv->side_panel, FALSE, FALSE); - g_signal_connect_after(window->priv->side_panel, "show", G_CALLBACK (side_panel_visibility_changed), window); - g_signal_connect_after(window->priv->side_panel, "hide", G_CALLBACK (side_panel_visibility_changed), window); + g_signal_connect_after (window->priv->side_panel, "show", G_CALLBACK (side_panel_visibility_changed), window); + g_signal_connect_after (window->priv->side_panel, "hide", G_CALLBACK (side_panel_visibility_changed), window); documents_panel = xed_documents_panel_new (window); - xed_panel_add_item_with_stock_icon (XED_PANEL(window->priv->side_panel), documents_panel, _("Documents"), + xed_panel_add_item_with_stock_icon (XED_PANEL (window->priv->side_panel), documents_panel, _("Documents"), GTK_STOCK_FILE); } @@ -3366,6 +3364,8 @@ xed_window_init (XedWindow *window) window->priv->window_group = gtk_window_group_new (); gtk_window_group_add_window (window->priv->window_group, GTK_WINDOW (window)); + gtk_style_context_add_class (gtk_widget_get_style_context (window), "xed-window"); + main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_add (GTK_CONTAINER (window), main_box); gtk_widget_show (main_box); From 94188504ab69d6433841481bb9a999de4bac1d30 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Wed, 28 Dec 2016 12:26:17 -0800 Subject: [PATCH 049/132] xed-statusbar: Clean up the styling a bit Make sure the statusbar expands the full width of the window. Do a better job of lining up buttons in the search and status bar as well. --- xed/xed-status-combo-box.c | 2 +- xed/xed-statusbar.c | 1 + xed/xed-window.c | 14 +++++++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/xed/xed-status-combo-box.c b/xed/xed-status-combo-box.c index bad9537..5b47495 100644 --- a/xed/xed-status-combo-box.c +++ b/xed/xed-status-combo-box.c @@ -153,7 +153,7 @@ xed_status_combo_box_class_init (XedStatusComboBoxClass *klass) "-GtkButton-inner-border: 0;\n" "-GtkWidget-focus-line-width : 0;\n" "-GtkWidget-focus-padding : 0;\n" - "padding: 0;\n" + "padding: 2px;\n" "}"; object_class->finalize = xed_status_combo_box_finalize; diff --git a/xed/xed-statusbar.c b/xed/xed-statusbar.c index ba104e5..97499b9 100644 --- a/xed/xed-statusbar.c +++ b/xed/xed-statusbar.c @@ -120,6 +120,7 @@ xed_statusbar_init (XedStatusbar *statusbar) gtk_box_pack_end (GTK_BOX (statusbar), statusbar->priv->overwrite_mode_label, FALSE, TRUE, 0); + gtk_widget_set_margin_right (GTK_WIDGET (statusbar->priv->overwrite_mode_label), 6); statusbar->priv->cursor_position_label = gtk_label_new (NULL); gtk_label_set_width_chars (GTK_LABEL (statusbar->priv->cursor_position_label), diff --git a/xed/xed-window.c b/xed/xed-window.c index 138093f..44bbc5e 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -1633,11 +1633,16 @@ create_statusbar (XedWindow *window, window->priv->tip_message_cid = gtk_statusbar_get_context_id (GTK_STATUSBAR (window->priv->statusbar), "tip_message"); - gtk_box_pack_end (GTK_BOX(main_box), window->priv->statusbar, FALSE, TRUE, 0); + gtk_box_pack_end (GTK_BOX( main_box), window->priv->statusbar, FALSE, TRUE, 0); + + gtk_widget_set_margin_left (GTK_WIDGET (window->priv->statusbar), 0); + gtk_widget_set_margin_right (GTK_WIDGET (window->priv->statusbar), 0); window->priv->tab_width_combo = xed_status_combo_box_new (_("Tab Width")); gtk_widget_show (window->priv->tab_width_combo); - gtk_box_pack_end (GTK_BOX(window->priv->statusbar), window->priv->tab_width_combo, FALSE, TRUE, 0); + gtk_box_pack_end (GTK_BOX (window->priv->statusbar), window->priv->tab_width_combo, FALSE, FALSE, 0); + gtk_widget_set_margin_bottom (GTK_WIDGET (window->priv->tab_width_combo), 2); + gtk_widget_set_margin_top (GTK_WIDGET (window->priv->tab_width_combo), 2); fill_tab_width_combo (window); @@ -1646,7 +1651,9 @@ create_statusbar (XedWindow *window, window->priv->language_combo = xed_status_combo_box_new (NULL); gtk_widget_show (window->priv->language_combo); - gtk_box_pack_end (GTK_BOX(window->priv->statusbar), window->priv->language_combo, FALSE, TRUE, 0); + gtk_widget_set_margin_bottom (GTK_WIDGET (window->priv->language_combo), 2); + gtk_widget_set_margin_top (GTK_WIDGET (window->priv->language_combo), 2); + gtk_box_pack_end (GTK_BOX(window->priv->statusbar), window->priv->language_combo, FALSE, FALSE, 0); fill_language_combo (window); @@ -1656,6 +1663,7 @@ create_statusbar (XedWindow *window, button_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); gtk_widget_set_margin_top (button_box, 4); gtk_widget_set_margin_bottom (button_box, 4); + gtk_widget_set_margin_left (button_box, 6); gtk_box_pack_start (GTK_BOX (window->priv->statusbar), button_box, FALSE, FALSE, 0); window->priv->show_side_pane_button = gtk_toggle_button_new (); From f3791ef8d2aa8c8dba485f2f778e41784e5e01b3 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Fri, 30 Dec 2016 03:17:05 -0800 Subject: [PATCH 050/132] Add view menu entry for word wrap Adds an entry to the "View" menu that allows temporarily overriding the word wrap settings in the preferences. --- xed/xed-commands-view.c | 22 ++++++++++++++ xed/xed-commands.h | 1 + xed/xed-ui.h | 19 +++++++----- xed/xed-ui.xml | 1 + xed/xed-window-private.h | 1 + xed/xed-window.c | 63 +++++++++++++++++++++++++++++++++------- 6 files changed, 89 insertions(+), 18 deletions(-) diff --git a/xed/xed-commands-view.c b/xed/xed-commands-view.c index 78ee31c..9df6fe2 100644 --- a/xed/xed-commands-view.c +++ b/xed/xed-commands-view.c @@ -134,6 +134,28 @@ _xed_cmd_view_toggle_fullscreen_mode (GtkAction *action, _xed_window_fullscreen (window); } +void +_xed_cmd_view_toggle_word_wrap (GtkAction *action, + XedWindow *window) +{ + XedView *view; + gboolean do_word_wrap; + + xed_debug (DEBUG_COMMANDS); + + do_word_wrap = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + view = xed_window_get_active_view (window); + + if (do_word_wrap) + { + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD); + } + else + { + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_NONE); + } +} + void _xed_cmd_view_leave_fullscreen_mode (GtkAction *action, XedWindow *window) diff --git a/xed/xed-commands.h b/xed/xed-commands.h index c053ad2..9a4a693 100644 --- a/xed/xed-commands.h +++ b/xed/xed-commands.h @@ -47,6 +47,7 @@ void _xed_cmd_view_show_statusbar (GtkAction *action, XedWindow *window); void _xed_cmd_view_show_side_pane (GtkAction *action, XedWindow *window); void _xed_cmd_view_show_bottom_pane (GtkAction *action, XedWindow *window); void _xed_cmd_view_toggle_fullscreen_mode (GtkAction *action, XedWindow *window); +void _xed_cmd_view_toggle_word_wrap (GtkAction *action, XedWindow *window); void _xed_cmd_view_leave_fullscreen_mode (GtkAction *action, XedWindow *window); void _xed_cmd_search_find (GtkAction *action, XedWindow *window); diff --git a/xed/xed-ui.h b/xed/xed-ui.h index 321597a..acefb5e 100644 --- a/xed/xed-ui.h +++ b/xed/xed-ui.h @@ -2,7 +2,7 @@ * xed-ui.h * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -67,7 +67,7 @@ static const GtkActionEntry xed_always_sensitive_menu_entries[] = N_("Open the xed manual"), G_CALLBACK (_xed_cmd_help_contents) }, { "HelpAbout", "help-about-symbolic", N_("_About"), NULL, N_("About this application"), G_CALLBACK (_xed_cmd_help_about) }, - + /* Fullscreen toolbar */ { "LeaveFullscreen", "view-restore-symbolic", NULL, NULL, N_("Leave fullscreen mode"), @@ -156,7 +156,10 @@ static const GtkToggleActionEntry xed_always_sensitive_toggle_menu_entries[] = G_CALLBACK (_xed_cmd_view_show_statusbar), TRUE }, { "ViewFullscreen", GTK_STOCK_FULLSCREEN, NULL, "F11", N_("Edit text in fullscreen"), - G_CALLBACK (_xed_cmd_view_toggle_fullscreen_mode), FALSE } + G_CALLBACK (_xed_cmd_view_toggle_fullscreen_mode), FALSE }, + { "ViewWordWrap", NULL, N_("_Word wrap"), NULL, + N_("Set word wrap for the current document"), + G_CALLBACK (_xed_cmd_view_toggle_word_wrap), FALSE } }; /* separate group, should be always sensitive except when there are no panes */ diff --git a/xed/xed-ui.xml b/xed/xed-ui.xml index d859216..6b5fe27 100644 --- a/xed/xed-ui.xml +++ b/xed/xed-ui.xml @@ -55,6 +55,7 @@ + diff --git a/xed/xed-window-private.h b/xed/xed-window-private.h index 4cc95ce..20ecea2 100644 --- a/xed/xed-window-private.h +++ b/xed/xed-window-private.h @@ -74,6 +74,7 @@ struct _XedWindowPrivate guint tab_width_id; guint spaces_instead_of_tabs_id; guint language_changed_id; + guint use_word_wrap_id; /* Menus & Toolbars */ GtkUIManager *manager; diff --git a/xed/xed-window.c b/xed/xed-window.c index 44bbc5e..bd755f9 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -2050,6 +2050,34 @@ language_changed (GObject *object, g_list_free (items); } +static void +word_wrap_changed (GObject *object, + GParamSpec *pspec, + XedWindow *window) +{ + XedView *view; + GtkWrapMode wrap_mode; + GtkAction *action; + gboolean wrap_enabled; + + view = XED_VIEW (object); + wrap_mode = gtk_text_view_get_wrap_mode (GTK_TEXT_VIEW (view)); + action = gtk_action_group_get_action (window->priv->always_sensitive_action_group, "ViewWordWrap"); + + if (wrap_mode == GTK_WRAP_NONE) + { + wrap_enabled = FALSE; + } + else + { + wrap_enabled = TRUE; + } + + g_signal_handlers_block_by_func (action, G_CALLBACK (_xed_cmd_view_toggle_word_wrap), window); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), wrap_enabled); + g_signal_handlers_unblock_by_func (action, G_CALLBACK (_xed_cmd_view_toggle_word_wrap), window); +} + static void notebook_switch_page (GtkNotebook *book, GtkWidget *pg, @@ -2080,10 +2108,15 @@ notebook_switch_page (GtkNotebook *book, if (window->priv->spaces_instead_of_tabs_id) { - g_signal_handler_disconnect (xed_tab_get_view (window->priv->active_tab), - window->priv->spaces_instead_of_tabs_id); + g_signal_handler_disconnect (xed_tab_get_view (window->priv->active_tab), window->priv->spaces_instead_of_tabs_id); window->priv->spaces_instead_of_tabs_id = 0; } + + if (window->priv->use_word_wrap_id) + { + g_signal_handler_disconnect (xed_tab_get_view (window->priv->active_tab), window->priv->use_word_wrap_id); + window->priv->use_word_wrap_id = 0; + } } /* set the active tab */ @@ -2102,7 +2135,7 @@ notebook_switch_page (GtkNotebook *book, */ if (action != NULL) { - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION(action), TRUE); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE); } g_free (action_name); @@ -2113,8 +2146,8 @@ notebook_switch_page (GtkNotebook *book, view = xed_tab_get_view (tab); /* sync the statusbar */ - update_cursor_position_statusbar (GTK_TEXT_BUFFER(xed_tab_get_document (tab)), window); - xed_statusbar_set_overwrite (XED_STATUSBAR(window->priv->statusbar), + update_cursor_position_statusbar (GTK_TEXT_BUFFER (xed_tab_get_document (tab)), window); + xed_statusbar_set_overwrite (XED_STATUSBAR (window->priv->statusbar), gtk_text_view_get_overwrite (GTK_TEXT_VIEW(view))); gtk_widget_show (window->priv->tab_width_combo); @@ -2128,12 +2161,16 @@ notebook_switch_page (GtkNotebook *book, window->priv->language_changed_id = g_signal_connect(xed_tab_get_document (tab), "notify::language", G_CALLBACK (language_changed), window); - /* call it for the first time */ - tab_width_changed (G_OBJECT(view), NULL, window); - spaces_instead_of_tabs_changed (G_OBJECT(view), NULL, window); - language_changed (G_OBJECT(xed_tab_get_document (tab)), NULL, window); + window->priv->use_word_wrap_id = g_signal_connect (view, "notify::wrap-mode", + G_CALLBACK (word_wrap_changed), window); - g_signal_emit (G_OBJECT(window), signals[ACTIVE_TAB_CHANGED], 0, window->priv->active_tab); + /* call it for the first time */ + tab_width_changed (G_OBJECT (view), NULL, window); + spaces_instead_of_tabs_changed (G_OBJECT (view), NULL, window); + language_changed (G_OBJECT (xed_tab_get_document (tab)), NULL, window); + word_wrap_changed (G_OBJECT (view), NULL, window); + + g_signal_emit (G_OBJECT (window), signals[ACTIVE_TAB_CHANGED], 0, window->priv->active_tab); } static void @@ -2887,6 +2924,12 @@ notebook_tab_removed (XedNotebook *notebook, window->priv->language_changed_id = 0; } + if (window->priv->use_word_wrap_id && tab == xed_window_get_active_tab (window)) + { + g_signal_handler_disconnect (view, window->priv->use_word_wrap_id); + window->priv->use_word_wrap_id = 0; + } + g_return_if_fail(window->priv->num_tabs >= 0); if (window->priv->num_tabs == 0) { From 05738f44bb3e108ab6c6cb8e1557f67390076376 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Fri, 30 Dec 2016 11:54:48 -0800 Subject: [PATCH 051/132] preferences-dialog: Clean up code styling --- xed/dialogs/xed-preferences-dialog.c | 1461 ++++++++++++-------------- 1 file changed, 667 insertions(+), 794 deletions(-) diff --git a/xed/dialogs/xed-preferences-dialog.c b/xed/dialogs/xed-preferences-dialog.c index 8d383ec..9053625 100755 --- a/xed/dialogs/xed-preferences-dialog.c +++ b/xed/dialogs/xed-preferences-dialog.c @@ -65,71 +65,71 @@ static GtkWidget *preferences_dialog = NULL; enum { - ID_COLUMN = 0, - NAME_COLUMN, - DESC_COLUMN, - NUM_COLUMNS + ID_COLUMN = 0, + NAME_COLUMN, + DESC_COLUMN, + NUM_COLUMNS }; #define XED_PREFERENCES_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ - XED_TYPE_PREFERENCES_DIALOG, \ - XedPreferencesDialogPrivate)) + XED_TYPE_PREFERENCES_DIALOG, \ + XedPreferencesDialogPrivate)) struct _XedPreferencesDialogPrivate { - GtkWidget *notebook; + GtkWidget *notebook; - /* Font */ - GtkWidget *default_font_checkbutton; - GtkWidget *font_button; - GtkWidget *font_hbox; + /* Font */ + GtkWidget *default_font_checkbutton; + GtkWidget *font_button; + GtkWidget *font_hbox; - /* Style Scheme */ - GtkListStore *schemes_treeview_model; - GtkWidget *schemes_treeview; - GtkWidget *install_scheme_button; - GtkWidget *uninstall_scheme_button; + /* Style Scheme */ + GtkListStore *schemes_treeview_model; + GtkWidget *schemes_treeview; + GtkWidget *install_scheme_button; + GtkWidget *uninstall_scheme_button; - GtkWidget *install_scheme_file_schooser; + GtkWidget *install_scheme_file_schooser; - /* Tabs */ - GtkWidget *tabs_width_spinbutton; - GtkWidget *insert_spaces_checkbutton; - GtkWidget *tabs_width_hbox; + /* Tabs */ + GtkWidget *tabs_width_spinbutton; + GtkWidget *insert_spaces_checkbutton; + GtkWidget *tabs_width_hbox; - /* Auto indentation */ - GtkWidget *auto_indent_checkbutton; + /* Auto indentation */ + GtkWidget *auto_indent_checkbutton; - /* Text Wrapping */ - GtkWidget *wrap_text_checkbutton; - GtkWidget *split_checkbutton; + /* Text Wrapping */ + GtkWidget *wrap_text_checkbutton; + GtkWidget *split_checkbutton; - /* File Saving */ - GtkWidget *backup_copy_checkbutton; - GtkWidget *auto_save_checkbutton; - GtkWidget *auto_save_spinbutton; - GtkWidget *autosave_hbox; + /* File Saving */ + GtkWidget *backup_copy_checkbutton; + GtkWidget *auto_save_checkbutton; + GtkWidget *auto_save_spinbutton; + GtkWidget *autosave_hbox; - /* Line numbers */ - GtkWidget *display_line_numbers_checkbutton; + /* Line numbers */ + GtkWidget *display_line_numbers_checkbutton; - /* Highlight current line */ - GtkWidget *highlight_current_line_checkbutton; + /* Highlight current line */ + GtkWidget *highlight_current_line_checkbutton; - /* Highlight matching bracket */ - GtkWidget *bracket_matching_checkbutton; + /* Highlight matching bracket */ + GtkWidget *bracket_matching_checkbutton; - /* Right margin */ - GtkWidget *right_margin_checkbutton; - GtkWidget *right_margin_position_spinbutton; - GtkWidget *right_margin_position_hbox; + /* Right margin */ + GtkWidget *right_margin_checkbutton; + GtkWidget *right_margin_position_spinbutton; + GtkWidget *right_margin_position_hbox; - /* Plugins manager */ - GtkWidget *plugin_manager_place_holder; + /* Plugins manager */ + GtkWidget *plugin_manager_place_holder; - /* Style Scheme editor dialog */ - GtkWidget *style_scheme_dialog; + /* Style Scheme editor dialog */ + GtkWidget *style_scheme_dialog; }; @@ -139,1051 +139,924 @@ G_DEFINE_TYPE(XedPreferencesDialog, xed_preferences_dialog, GTK_TYPE_DIALOG) static void xed_preferences_dialog_class_init (XedPreferencesDialogClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - g_type_class_add_private (object_class, sizeof (XedPreferencesDialogPrivate)); + g_type_class_add_private (object_class, sizeof (XedPreferencesDialogPrivate)); } static void dialog_response_handler (GtkDialog *dlg, - gint res_id) + gint res_id) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - switch (res_id) - { - case GTK_RESPONSE_HELP: - xed_help_display (GTK_WINDOW (dlg), - NULL, - "xed-prefs"); - - g_signal_stop_emission_by_name (dlg, "response"); - - break; - - default: - gtk_widget_destroy (GTK_WIDGET(dlg)); - } + switch (res_id) + { + case GTK_RESPONSE_HELP: + xed_help_display (GTK_WINDOW (dlg), NULL, "xed-prefs"); + g_signal_stop_emission_by_name (dlg, "response"); + break; + default: + gtk_widget_destroy (GTK_WIDGET(dlg)); + } } static void -tabs_width_spinbutton_value_changed (GtkSpinButton *spin_button, - XedPreferencesDialog *dlg) +tabs_width_spinbutton_value_changed (GtkSpinButton *spin_button, + XedPreferencesDialog *dlg) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->tabs_width_spinbutton)); + g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->tabs_width_spinbutton)); - xed_prefs_manager_set_tabs_size (gtk_spin_button_get_value_as_int (spin_button)); + xed_prefs_manager_set_tabs_size (gtk_spin_button_get_value_as_int (spin_button)); } static void -insert_spaces_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) +insert_spaces_checkbutton_toggled (GtkToggleButton *button, + XedPreferencesDialog *dlg) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->insert_spaces_checkbutton)); + g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->insert_spaces_checkbutton)); - xed_prefs_manager_set_insert_spaces (gtk_toggle_button_get_active (button)); + xed_prefs_manager_set_insert_spaces (gtk_toggle_button_get_active (button)); } static void -auto_indent_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) +auto_indent_checkbutton_toggled (GtkToggleButton *button, + XedPreferencesDialog *dlg) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->auto_indent_checkbutton)); + g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->auto_indent_checkbutton)); - xed_prefs_manager_set_auto_indent (gtk_toggle_button_get_active (button)); + xed_prefs_manager_set_auto_indent (gtk_toggle_button_get_active (button)); } static void -auto_save_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) +auto_save_checkbutton_toggled (GtkToggleButton *button, + XedPreferencesDialog *dlg) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->auto_save_checkbutton)); + g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->auto_save_checkbutton)); - if (gtk_toggle_button_get_active (button)) - { - gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, - xed_prefs_manager_auto_save_interval_can_set()); - - xed_prefs_manager_set_auto_save (TRUE); - } - else - { - gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, FALSE); - xed_prefs_manager_set_auto_save (FALSE); - } + if (gtk_toggle_button_get_active (button)) + { + gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, xed_prefs_manager_auto_save_interval_can_set()); + xed_prefs_manager_set_auto_save (TRUE); + } + else + { + gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, FALSE); + xed_prefs_manager_set_auto_save (FALSE); + } } static void -backup_copy_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) +backup_copy_checkbutton_toggled (GtkToggleButton *button, + XedPreferencesDialog *dlg) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton)); + g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton)); - xed_prefs_manager_set_create_backup_copy (gtk_toggle_button_get_active (button)); + xed_prefs_manager_set_create_backup_copy (gtk_toggle_button_get_active (button)); } static void -auto_save_spinbutton_value_changed (GtkSpinButton *spin_button, - XedPreferencesDialog *dlg) +auto_save_spinbutton_value_changed (GtkSpinButton *spin_button, + XedPreferencesDialog *dlg) { - g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->auto_save_spinbutton)); + g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->auto_save_spinbutton)); - xed_prefs_manager_set_auto_save_interval ( - MAX (1, gtk_spin_button_get_value_as_int (spin_button))); + xed_prefs_manager_set_auto_save_interval (MAX (1, gtk_spin_button_get_value_as_int (spin_button))); } static void setup_editor_page (XedPreferencesDialog *dlg) { - gboolean auto_save; - gint auto_save_interval; + gboolean auto_save; + gint auto_save_interval; - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - /* Set initial state */ - gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->tabs_width_spinbutton), - (guint) xed_prefs_manager_get_tabs_size ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->insert_spaces_checkbutton), - xed_prefs_manager_get_insert_spaces ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_indent_checkbutton), - xed_prefs_manager_get_auto_indent ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton), - xed_prefs_manager_get_create_backup_copy ()); + /* Set initial state */ + gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->tabs_width_spinbutton), + (guint) xed_prefs_manager_get_tabs_size ()); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->insert_spaces_checkbutton), + xed_prefs_manager_get_insert_spaces ()); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_indent_checkbutton), + xed_prefs_manager_get_auto_indent ()); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton), + xed_prefs_manager_get_create_backup_copy ()); - auto_save = xed_prefs_manager_get_auto_save (); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_save_checkbutton), - auto_save); + auto_save = xed_prefs_manager_get_auto_save (); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_save_checkbutton), auto_save); - auto_save_interval = xed_prefs_manager_get_auto_save_interval (); - if (auto_save_interval <= 0) - auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL; + auto_save_interval = xed_prefs_manager_get_auto_save_interval (); + if (auto_save_interval <= 0) + { + auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL; + } - gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->auto_save_spinbutton), - auto_save_interval); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->auto_save_spinbutton), auto_save_interval); - /* Set widget sensitivity */ - gtk_widget_set_sensitive (dlg->priv->tabs_width_hbox, - xed_prefs_manager_tabs_size_can_set ()); - gtk_widget_set_sensitive (dlg->priv->insert_spaces_checkbutton, - xed_prefs_manager_insert_spaces_can_set ()); - gtk_widget_set_sensitive (dlg->priv->auto_indent_checkbutton, - xed_prefs_manager_auto_indent_can_set ()); - gtk_widget_set_sensitive (dlg->priv->backup_copy_checkbutton, - xed_prefs_manager_create_backup_copy_can_set ()); - gtk_widget_set_sensitive (dlg->priv->autosave_hbox, - xed_prefs_manager_auto_save_can_set ()); - gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, - auto_save && - xed_prefs_manager_auto_save_interval_can_set ()); + /* Set widget sensitivity */ + gtk_widget_set_sensitive (dlg->priv->tabs_width_hbox, xed_prefs_manager_tabs_size_can_set ()); + gtk_widget_set_sensitive (dlg->priv->insert_spaces_checkbutton, xed_prefs_manager_insert_spaces_can_set ()); + gtk_widget_set_sensitive (dlg->priv->auto_indent_checkbutton, xed_prefs_manager_auto_indent_can_set ()); + gtk_widget_set_sensitive (dlg->priv->backup_copy_checkbutton, xed_prefs_manager_create_backup_copy_can_set ()); + gtk_widget_set_sensitive (dlg->priv->autosave_hbox, xed_prefs_manager_auto_save_can_set ()); + gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, + auto_save && xed_prefs_manager_auto_save_interval_can_set ()); - /* Connect signal */ - g_signal_connect (dlg->priv->tabs_width_spinbutton, - "value_changed", - G_CALLBACK (tabs_width_spinbutton_value_changed), - dlg); - g_signal_connect (dlg->priv->insert_spaces_checkbutton, - "toggled", - G_CALLBACK (insert_spaces_checkbutton_toggled), - dlg); - g_signal_connect (dlg->priv->auto_indent_checkbutton, - "toggled", - G_CALLBACK (auto_indent_checkbutton_toggled), - dlg); - g_signal_connect (dlg->priv->auto_save_checkbutton, - "toggled", - G_CALLBACK (auto_save_checkbutton_toggled), - dlg); - g_signal_connect (dlg->priv->backup_copy_checkbutton, - "toggled", - G_CALLBACK (backup_copy_checkbutton_toggled), - dlg); - g_signal_connect (dlg->priv->auto_save_spinbutton, - "value_changed", - G_CALLBACK (auto_save_spinbutton_value_changed), - dlg); + /* Connect signal */ + g_signal_connect (dlg->priv->tabs_width_spinbutton, "value_changed", + G_CALLBACK (tabs_width_spinbutton_value_changed), dlg); + g_signal_connect (dlg->priv->insert_spaces_checkbutton, "toggled", + G_CALLBACK (insert_spaces_checkbutton_toggled), dlg); + g_signal_connect (dlg->priv->auto_indent_checkbutton, "toggled", + G_CALLBACK (auto_indent_checkbutton_toggled), dlg); + g_signal_connect (dlg->priv->auto_save_checkbutton, "toggled", + G_CALLBACK (auto_save_checkbutton_toggled), dlg); + g_signal_connect (dlg->priv->backup_copy_checkbutton, "toggled", + G_CALLBACK (backup_copy_checkbutton_toggled), dlg); + g_signal_connect (dlg->priv->auto_save_spinbutton, "value_changed", + G_CALLBACK (auto_save_spinbutton_value_changed), dlg); } static void -display_line_numbers_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) +display_line_numbers_checkbutton_toggled (GtkToggleButton *button, + XedPreferencesDialog *dlg) { - g_return_if_fail (button == - GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton)); + g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton)); - xed_prefs_manager_set_display_line_numbers (gtk_toggle_button_get_active (button)); + xed_prefs_manager_set_display_line_numbers (gtk_toggle_button_get_active (button)); } static void -highlight_current_line_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) +highlight_current_line_checkbutton_toggled (GtkToggleButton *button, + XedPreferencesDialog *dlg) { - g_return_if_fail (button == - GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton)); + g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton)); - xed_prefs_manager_set_highlight_current_line (gtk_toggle_button_get_active (button)); + xed_prefs_manager_set_highlight_current_line (gtk_toggle_button_get_active (button)); } static void -bracket_matching_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) +bracket_matching_checkbutton_toggled (GtkToggleButton *button, + XedPreferencesDialog *dlg) { - g_return_if_fail (button == - GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton)); + g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton)); - xed_prefs_manager_set_bracket_matching ( - gtk_toggle_button_get_active (button)); + xed_prefs_manager_set_bracket_matching (gtk_toggle_button_get_active (button)); } static gboolean split_button_state = TRUE; static void -wrap_mode_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) +wrap_mode_checkbutton_toggled (GtkToggleButton *button, + XedPreferencesDialog *dlg) { - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton))) - { - xed_prefs_manager_set_wrap_mode (GTK_WRAP_NONE); + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton))) + { + xed_prefs_manager_set_wrap_mode (GTK_WRAP_NONE); - gtk_widget_set_sensitive (dlg->priv->split_checkbutton, - FALSE); - gtk_toggle_button_set_inconsistent ( - GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE); - } - else - { - gtk_widget_set_sensitive (dlg->priv->split_checkbutton, - TRUE); - - gtk_toggle_button_set_inconsistent ( - GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), FALSE); + gtk_widget_set_sensitive (dlg->priv->split_checkbutton, FALSE); + gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE); + } + else + { + gtk_widget_set_sensitive (dlg->priv->split_checkbutton, TRUE); + gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), FALSE); - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton))) - { - split_button_state = TRUE; - - xed_prefs_manager_set_wrap_mode (GTK_WRAP_WORD); - } - else - { - split_button_state = FALSE; - - xed_prefs_manager_set_wrap_mode (GTK_WRAP_CHAR); - } - } + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton))) + { + split_button_state = TRUE; + xed_prefs_manager_set_wrap_mode (GTK_WRAP_WORD); + } + else + { + split_button_state = FALSE; + xed_prefs_manager_set_wrap_mode (GTK_WRAP_CHAR); + } + } } static void -right_margin_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) +right_margin_checkbutton_toggled (GtkToggleButton *button, + XedPreferencesDialog *dlg) { - gboolean active; + gboolean active; - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->right_margin_checkbutton)); + g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->right_margin_checkbutton)); - active = gtk_toggle_button_get_active (button); + active = gtk_toggle_button_get_active (button); - xed_prefs_manager_set_display_right_margin (active); + xed_prefs_manager_set_display_right_margin (active); - gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, - active && - xed_prefs_manager_right_margin_position_can_set ()); + gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, + active && xed_prefs_manager_right_margin_position_can_set ()); } static void -right_margin_position_spinbutton_value_changed (GtkSpinButton *spin_button, - XedPreferencesDialog *dlg) +right_margin_position_spinbutton_value_changed (GtkSpinButton *spin_button, + XedPreferencesDialog *dlg) { - gint value; + gint value; - g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton)); + g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton)); - value = CLAMP (gtk_spin_button_get_value_as_int (spin_button), 1, 160); + value = CLAMP (gtk_spin_button_get_value_as_int (spin_button), 1, 160); - xed_prefs_manager_set_right_margin_position (value); + xed_prefs_manager_set_right_margin_position (value); } static void setup_view_page (XedPreferencesDialog *dlg) { - GtkWrapMode wrap_mode; - gboolean display_right_margin; - gboolean wrap_mode_can_set; + GtkWrapMode wrap_mode; + gboolean display_right_margin; + gboolean wrap_mode_can_set; - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - /* Set initial state */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton), - xed_prefs_manager_get_display_line_numbers ()); + /* Set initial state */ + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton), + xed_prefs_manager_get_display_line_numbers ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton), - xed_prefs_manager_get_highlight_current_line ()); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton), + xed_prefs_manager_get_highlight_current_line ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton), - xed_prefs_manager_get_bracket_matching ()); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton), + xed_prefs_manager_get_bracket_matching ()); - wrap_mode = xed_prefs_manager_get_wrap_mode (); - switch (wrap_mode ) - { - case GTK_WRAP_WORD: - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton), TRUE); - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE); - break; - case GTK_WRAP_CHAR: - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton), TRUE); - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), FALSE); - break; - default: - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton), FALSE); - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), split_button_state); - gtk_toggle_button_set_inconsistent ( - GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE); + wrap_mode = xed_prefs_manager_get_wrap_mode (); + switch (wrap_mode ) + { + case GTK_WRAP_WORD: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE); + break; + case GTK_WRAP_CHAR: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), FALSE); + break; + default: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton), FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), split_button_state); + gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE); - } + } - display_right_margin = xed_prefs_manager_get_display_right_margin (); + display_right_margin = xed_prefs_manager_get_display_right_margin (); - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (dlg->priv->right_margin_checkbutton), - display_right_margin); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->right_margin_checkbutton), display_right_margin); - gtk_spin_button_set_value ( - GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton), - (guint)CLAMP (xed_prefs_manager_get_right_margin_position (), 1, 160)); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton), + (guint)CLAMP (xed_prefs_manager_get_right_margin_position (), 1, 160)); - /* Set widgets sensitivity */ - gtk_widget_set_sensitive (dlg->priv->display_line_numbers_checkbutton, - xed_prefs_manager_display_line_numbers_can_set ()); - gtk_widget_set_sensitive (dlg->priv->highlight_current_line_checkbutton, - xed_prefs_manager_highlight_current_line_can_set ()); - gtk_widget_set_sensitive (dlg->priv->bracket_matching_checkbutton, - xed_prefs_manager_bracket_matching_can_set ()); - wrap_mode_can_set = xed_prefs_manager_wrap_mode_can_set (); - gtk_widget_set_sensitive (dlg->priv->wrap_text_checkbutton, - wrap_mode_can_set); - gtk_widget_set_sensitive (dlg->priv->split_checkbutton, - wrap_mode_can_set && - (wrap_mode != GTK_WRAP_NONE)); - gtk_widget_set_sensitive (dlg->priv->right_margin_checkbutton, - xed_prefs_manager_display_right_margin_can_set ()); - gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, - display_right_margin && - xed_prefs_manager_right_margin_position_can_set ()); + /* Set widgets sensitivity */ + gtk_widget_set_sensitive (dlg->priv->display_line_numbers_checkbutton, + xed_prefs_manager_display_line_numbers_can_set ()); + gtk_widget_set_sensitive (dlg->priv->highlight_current_line_checkbutton, + xed_prefs_manager_highlight_current_line_can_set ()); + gtk_widget_set_sensitive (dlg->priv->bracket_matching_checkbutton, xed_prefs_manager_bracket_matching_can_set ()); + wrap_mode_can_set = xed_prefs_manager_wrap_mode_can_set (); + gtk_widget_set_sensitive (dlg->priv->wrap_text_checkbutton, wrap_mode_can_set); + gtk_widget_set_sensitive (dlg->priv->split_checkbutton, wrap_mode_can_set && (wrap_mode != GTK_WRAP_NONE)); + gtk_widget_set_sensitive (dlg->priv->right_margin_checkbutton, xed_prefs_manager_display_right_margin_can_set ()); + gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, + display_right_margin && xed_prefs_manager_right_margin_position_can_set ()); - /* Connect signals */ - g_signal_connect (dlg->priv->display_line_numbers_checkbutton, - "toggled", - G_CALLBACK (display_line_numbers_checkbutton_toggled), - dlg); - g_signal_connect (dlg->priv->highlight_current_line_checkbutton, - "toggled", - G_CALLBACK (highlight_current_line_checkbutton_toggled), - dlg); - g_signal_connect (dlg->priv->bracket_matching_checkbutton, - "toggled", - G_CALLBACK (bracket_matching_checkbutton_toggled), - dlg); - g_signal_connect (dlg->priv->wrap_text_checkbutton, - "toggled", - G_CALLBACK (wrap_mode_checkbutton_toggled), - dlg); - g_signal_connect (dlg->priv->split_checkbutton, - "toggled", - G_CALLBACK (wrap_mode_checkbutton_toggled), - dlg); - g_signal_connect (dlg->priv->right_margin_checkbutton, - "toggled", - G_CALLBACK (right_margin_checkbutton_toggled), - dlg); - g_signal_connect (dlg->priv->right_margin_position_spinbutton, - "value_changed", - G_CALLBACK (right_margin_position_spinbutton_value_changed), - dlg); + /* Connect signals */ + g_signal_connect (dlg->priv->display_line_numbers_checkbutton, "toggled", + G_CALLBACK (display_line_numbers_checkbutton_toggled), dlg); + g_signal_connect (dlg->priv->highlight_current_line_checkbutton, "toggled", + G_CALLBACK (highlight_current_line_checkbutton_toggled), dlg); + g_signal_connect (dlg->priv->bracket_matching_checkbutton, "toggled", + G_CALLBACK (bracket_matching_checkbutton_toggled), dlg); + g_signal_connect (dlg->priv->wrap_text_checkbutton, "toggled", + G_CALLBACK (wrap_mode_checkbutton_toggled), dlg); + g_signal_connect (dlg->priv->split_checkbutton, "toggled", + G_CALLBACK (wrap_mode_checkbutton_toggled), dlg); + g_signal_connect (dlg->priv->right_margin_checkbutton, "toggled", + G_CALLBACK (right_margin_checkbutton_toggled), dlg); + g_signal_connect (dlg->priv->right_margin_position_spinbutton, "value_changed", + G_CALLBACK (right_margin_position_spinbutton_value_changed), dlg); } static void -default_font_font_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) +default_font_font_checkbutton_toggled (GtkToggleButton *button, + XedPreferencesDialog *dlg) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->default_font_checkbutton)); + g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->default_font_checkbutton)); - if (gtk_toggle_button_get_active (button)) - { - gtk_widget_set_sensitive (dlg->priv->font_hbox, FALSE); - xed_prefs_manager_set_use_default_font (TRUE); - } - else - { - gtk_widget_set_sensitive (dlg->priv->font_hbox, - xed_prefs_manager_editor_font_can_set ()); - xed_prefs_manager_set_use_default_font (FALSE); - } + if (gtk_toggle_button_get_active (button)) + { + gtk_widget_set_sensitive (dlg->priv->font_hbox, FALSE); + xed_prefs_manager_set_use_default_font (TRUE); + } + else + { + gtk_widget_set_sensitive (dlg->priv->font_hbox, xed_prefs_manager_editor_font_can_set ()); + xed_prefs_manager_set_use_default_font (FALSE); + } } static void -editor_font_button_font_set (GtkFontButton *font_button, - XedPreferencesDialog *dlg) +editor_font_button_font_set (GtkFontButton *font_button, + XedPreferencesDialog *dlg) { - const gchar *font_name; + const gchar *font_name; - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - g_return_if_fail (font_button == GTK_FONT_BUTTON (dlg->priv->font_button)); + g_return_if_fail (font_button == GTK_FONT_BUTTON (dlg->priv->font_button)); - /* FIXME: Can this fail? Gtk docs are a bit terse... 21-02-2004 pbor */ - font_name = gtk_font_button_get_font_name (font_button); - if (!font_name) - { - g_warning ("Could not get font name"); - return; - } + /* FIXME: Can this fail? Gtk docs are a bit terse... 21-02-2004 pbor */ + font_name = gtk_font_button_get_font_name (font_button); + if (!font_name) + { + g_warning ("Could not get font name"); + return; + } - xed_prefs_manager_set_editor_font (font_name); + xed_prefs_manager_set_editor_font (font_name); } static void setup_font_colors_page_font_section (XedPreferencesDialog *dlg) { - gboolean use_default_font; - gchar *editor_font = NULL; - gchar *label; + gboolean use_default_font; + gchar *editor_font = NULL; + gchar *label; - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - gtk_widget_set_tooltip_text (dlg->priv->font_button, - _("Click on this button to select the font to be used by the editor")); + gtk_widget_set_tooltip_text (dlg->priv->font_button, + _("Click on this button to select the font to be used by the editor")); - xed_utils_set_atk_relation (dlg->priv->font_button, - dlg->priv->default_font_checkbutton, - ATK_RELATION_CONTROLLED_BY); - xed_utils_set_atk_relation (dlg->priv->default_font_checkbutton, - dlg->priv->font_button, - ATK_RELATION_CONTROLLER_FOR); + xed_utils_set_atk_relation (dlg->priv->font_button, + dlg->priv->default_font_checkbutton, + ATK_RELATION_CONTROLLED_BY); + xed_utils_set_atk_relation (dlg->priv->default_font_checkbutton, + dlg->priv->font_button, + ATK_RELATION_CONTROLLER_FOR); - editor_font = xed_prefs_manager_get_system_font (); - label = g_strdup_printf(_("_Use the system fixed width font (%s)"), - editor_font); - gtk_button_set_label (GTK_BUTTON (dlg->priv->default_font_checkbutton), - label); - g_free (editor_font); - g_free (label); + editor_font = xed_prefs_manager_get_system_font (); + label = g_strdup_printf(_("_Use the system fixed width font (%s)"), editor_font); + gtk_button_set_label (GTK_BUTTON (dlg->priv->default_font_checkbutton), label); + g_free (editor_font); + g_free (label); - /* read current config and setup initial state */ - use_default_font = xed_prefs_manager_get_use_default_font (); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->default_font_checkbutton), - use_default_font); + /* read current config and setup initial state */ + use_default_font = xed_prefs_manager_get_use_default_font (); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->default_font_checkbutton), use_default_font); - editor_font = xed_prefs_manager_get_editor_font (); - if (editor_font != NULL) - { - gtk_font_button_set_font_name (GTK_FONT_BUTTON (dlg->priv->font_button), - editor_font); - g_free (editor_font); - } + editor_font = xed_prefs_manager_get_editor_font (); + if (editor_font != NULL) + { + gtk_font_button_set_font_name (GTK_FONT_BUTTON (dlg->priv->font_button), editor_font); + g_free (editor_font); + } - /* Connect signals */ - g_signal_connect (dlg->priv->default_font_checkbutton, - "toggled", - G_CALLBACK (default_font_font_checkbutton_toggled), - dlg); - g_signal_connect (dlg->priv->font_button, - "font_set", - G_CALLBACK (editor_font_button_font_set), - dlg); + /* Connect signals */ + g_signal_connect (dlg->priv->default_font_checkbutton, "toggled", + G_CALLBACK (default_font_font_checkbutton_toggled), dlg); + g_signal_connect (dlg->priv->font_button, "font_set", + G_CALLBACK (editor_font_button_font_set), dlg); - /* Set initial widget sensitivity */ - gtk_widget_set_sensitive (dlg->priv->default_font_checkbutton, - xed_prefs_manager_use_default_font_can_set ()); + /* Set initial widget sensitivity */ + gtk_widget_set_sensitive (dlg->priv->default_font_checkbutton, xed_prefs_manager_use_default_font_can_set ()); - if (use_default_font) - gtk_widget_set_sensitive (dlg->priv->font_hbox, FALSE); - else - gtk_widget_set_sensitive (dlg->priv->font_hbox, - xed_prefs_manager_editor_font_can_set ()); + if (use_default_font) + { + gtk_widget_set_sensitive (dlg->priv->font_hbox, FALSE); + } + else + { + gtk_widget_set_sensitive (dlg->priv->font_hbox, xed_prefs_manager_editor_font_can_set ()); + } } static void set_buttons_sensisitivity_according_to_scheme (XedPreferencesDialog *dlg, - const gchar *scheme_id) + const gchar *scheme_id) { - gboolean editable; + gboolean editable; - editable = (scheme_id != NULL) && - _xed_style_scheme_manager_scheme_is_xed_user_scheme ( - xed_get_style_scheme_manager (), - scheme_id); + editable = (scheme_id != NULL) && + _xed_style_scheme_manager_scheme_is_xed_user_scheme (xed_get_style_scheme_manager (), scheme_id); - gtk_widget_set_sensitive (dlg->priv->uninstall_scheme_button, - editable); + gtk_widget_set_sensitive (dlg->priv->uninstall_scheme_button, editable); } static void -style_scheme_changed (GtkWidget *treeview, - XedPreferencesDialog *dlg) +style_scheme_changed (GtkWidget *treeview, + XedPreferencesDialog *dlg) { - GtkTreePath *path; - GtkTreeIter iter; - gchar *id; + GtkTreePath *path; + GtkTreeIter iter; + gchar *id; - gtk_tree_view_get_cursor (GTK_TREE_VIEW (dlg->priv->schemes_treeview), &path, NULL); - gtk_tree_model_get_iter (GTK_TREE_MODEL (dlg->priv->schemes_treeview_model), - &iter, path); - gtk_tree_path_free (path); - gtk_tree_model_get (GTK_TREE_MODEL (dlg->priv->schemes_treeview_model), - &iter, ID_COLUMN, &id, -1); + gtk_tree_view_get_cursor (GTK_TREE_VIEW (dlg->priv->schemes_treeview), &path, NULL); + gtk_tree_model_get_iter (GTK_TREE_MODEL (dlg->priv->schemes_treeview_model), &iter, path); + gtk_tree_path_free (path); + gtk_tree_model_get (GTK_TREE_MODEL (dlg->priv->schemes_treeview_model), &iter, ID_COLUMN, &id, -1); - xed_prefs_manager_set_source_style_scheme (id); + xed_prefs_manager_set_source_style_scheme (id); - set_buttons_sensisitivity_according_to_scheme (dlg, id); + set_buttons_sensisitivity_according_to_scheme (dlg, id); - g_free (id); + g_free (id); } static const gchar * ensure_color_scheme_id (const gchar *id) { - GtkSourceStyleScheme *scheme = NULL; - GtkSourceStyleSchemeManager *manager = xed_get_style_scheme_manager (); + GtkSourceStyleScheme *scheme = NULL; + GtkSourceStyleSchemeManager *manager = xed_get_style_scheme_manager (); - if (id == NULL) - { - gchar *pref_id; + if (id == NULL) + { + gchar *pref_id; - pref_id = xed_prefs_manager_get_source_style_scheme (); - scheme = gtk_source_style_scheme_manager_get_scheme (manager, - pref_id); - g_free (pref_id); - } - else - { - scheme = gtk_source_style_scheme_manager_get_scheme (manager, - id); - } + pref_id = xed_prefs_manager_get_source_style_scheme (); + scheme = gtk_source_style_scheme_manager_get_scheme (manager, pref_id); + g_free (pref_id); + } + else + { + scheme = gtk_source_style_scheme_manager_get_scheme (manager, id); + } - if (scheme == NULL) - { - /* Fall-back to classic style scheme */ - scheme = gtk_source_style_scheme_manager_get_scheme (manager, - "classic"); - } + if (scheme == NULL) + { + /* Fall-back to classic style scheme */ + scheme = gtk_source_style_scheme_manager_get_scheme (manager, "classic"); + } - if (scheme == NULL) - { - /* Cannot determine default style scheme -> broken GtkSourceView installation */ - return NULL; - } + if (scheme == NULL) + { + /* Cannot determine default style scheme -> broken GtkSourceView installation */ + return NULL; + } - return gtk_source_style_scheme_get_id (scheme); + return gtk_source_style_scheme_get_id (scheme); } /* If def_id is NULL, use the default scheme as returned by * xed_style_scheme_manager_get_default_scheme. If this one returns NULL * use the first available scheme as default */ static const gchar * -populate_color_scheme_list (XedPreferencesDialog *dlg, const gchar *def_id) +populate_color_scheme_list (XedPreferencesDialog *dlg, + const gchar *def_id) { - GSList *schemes; - GSList *l; + GSList *schemes; + GSList *l; - gtk_list_store_clear (dlg->priv->schemes_treeview_model); + gtk_list_store_clear (dlg->priv->schemes_treeview_model); - def_id = ensure_color_scheme_id (def_id); - if (def_id == NULL) - { - g_warning ("Cannot build the list of available color schemes.\n" - "Please check your GtkSourceView installation."); - return NULL; - } + def_id = ensure_color_scheme_id (def_id); + if (def_id == NULL) + { + g_warning ("Cannot build the list of available color schemes.\n" + "Please check your GtkSourceView installation."); + return NULL; + } - schemes = xed_style_scheme_manager_list_schemes_sorted (xed_get_style_scheme_manager ()); - l = schemes; - while (l != NULL) - { - GtkSourceStyleScheme *scheme; - const gchar *id; - const gchar *name; - const gchar *description; - GtkTreeIter iter; + schemes = xed_style_scheme_manager_list_schemes_sorted (xed_get_style_scheme_manager ()); + l = schemes; + while (l != NULL) + { + GtkSourceStyleScheme *scheme; + const gchar *id; + const gchar *name; + const gchar *description; + GtkTreeIter iter; - scheme = GTK_SOURCE_STYLE_SCHEME (l->data); + scheme = GTK_SOURCE_STYLE_SCHEME (l->data); - id = gtk_source_style_scheme_get_id (scheme); - name = gtk_source_style_scheme_get_name (scheme); - description = gtk_source_style_scheme_get_description (scheme); + id = gtk_source_style_scheme_get_id (scheme); + name = gtk_source_style_scheme_get_name (scheme); + description = gtk_source_style_scheme_get_description (scheme); - gtk_list_store_append (dlg->priv->schemes_treeview_model, &iter); - gtk_list_store_set (dlg->priv->schemes_treeview_model, - &iter, - ID_COLUMN, id, - NAME_COLUMN, name, - DESC_COLUMN, description, - -1); + gtk_list_store_append (dlg->priv->schemes_treeview_model, &iter); + gtk_list_store_set (dlg->priv->schemes_treeview_model, + &iter, + ID_COLUMN, id, + NAME_COLUMN, name, + DESC_COLUMN, description, + -1); - g_return_val_if_fail (def_id != NULL, NULL); - if (strcmp (id, def_id) == 0) - { - GtkTreeSelection *selection; + g_return_val_if_fail (def_id != NULL, NULL); + if (strcmp (id, def_id) == 0) + { + GtkTreeSelection *selection; - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->schemes_treeview)); - gtk_tree_selection_select_iter (selection, &iter); - } + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->schemes_treeview)); + gtk_tree_selection_select_iter (selection, &iter); + } - l = g_slist_next (l); - } + l = g_slist_next (l); + } - g_slist_free (schemes); + g_slist_free (schemes); - return def_id; + return def_id; } static void -add_scheme_chooser_response_cb (GtkDialog *chooser, - gint res_id, - XedPreferencesDialog *dlg) +add_scheme_chooser_response_cb (GtkDialog *chooser, + gint res_id, + XedPreferencesDialog *dlg) { - gchar* filename; - const gchar *scheme_id; + gchar* filename; + const gchar *scheme_id; - if (res_id != GTK_RESPONSE_ACCEPT) - { - gtk_widget_hide (GTK_WIDGET (chooser)); - return; - } + if (res_id != GTK_RESPONSE_ACCEPT) + { + gtk_widget_hide (GTK_WIDGET (chooser)); + return; + } - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser)); - if (filename == NULL) - return; + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser)); + if (filename == NULL) + return; - gtk_widget_hide (GTK_WIDGET (chooser)); + gtk_widget_hide (GTK_WIDGET (chooser)); - scheme_id = _xed_style_scheme_manager_install_scheme ( - xed_get_style_scheme_manager (), - filename); - g_free (filename); + scheme_id = _xed_style_scheme_manager_install_scheme (xed_get_style_scheme_manager (), filename); + g_free (filename); - if (scheme_id == NULL) - { - xed_warning (GTK_WINDOW (dlg), - _("The selected color scheme cannot be installed.")); + if (scheme_id == NULL) + { + xed_warning (GTK_WINDOW (dlg), _("The selected color scheme cannot be installed.")); + return; + } - return; - } + xed_prefs_manager_set_source_style_scheme (scheme_id); - xed_prefs_manager_set_source_style_scheme (scheme_id); + scheme_id = populate_color_scheme_list (dlg, scheme_id); - scheme_id = populate_color_scheme_list (dlg, scheme_id); - - set_buttons_sensisitivity_according_to_scheme (dlg, scheme_id); + set_buttons_sensisitivity_according_to_scheme (dlg, scheme_id); } static void -install_scheme_clicked (GtkButton *button, - XedPreferencesDialog *dlg) +install_scheme_clicked (GtkButton *button, + XedPreferencesDialog *dlg) { - GtkWidget *chooser; - GtkFileFilter *filter; + GtkWidget *chooser; + GtkFileFilter *filter; - if (dlg->priv->install_scheme_file_schooser != NULL) { - gtk_window_present (GTK_WINDOW (dlg->priv->install_scheme_file_schooser)); - gtk_widget_grab_focus (dlg->priv->install_scheme_file_schooser); - return; - } + if (dlg->priv->install_scheme_file_schooser != NULL) + { + gtk_window_present (GTK_WINDOW (dlg->priv->install_scheme_file_schooser)); + gtk_widget_grab_focus (dlg->priv->install_scheme_file_schooser); + return; + } - chooser = gtk_file_chooser_dialog_new (_("Add Scheme"), - GTK_WINDOW (dlg), - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - NULL); + chooser = gtk_file_chooser_dialog_new (_("Add Scheme"), + GTK_WINDOW (dlg), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + NULL); - xed_dialog_add_button (GTK_DIALOG (chooser), - _("A_dd Scheme"), - GTK_STOCK_ADD, - GTK_RESPONSE_ACCEPT); + xed_dialog_add_button (GTK_DIALOG (chooser), _("A_dd Scheme"), + GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT); - gtk_window_set_destroy_with_parent (GTK_WINDOW (chooser), TRUE); + gtk_window_set_destroy_with_parent (GTK_WINDOW (chooser), TRUE); - /* Filters */ - filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, _("Color Scheme Files")); - gtk_file_filter_add_pattern (filter, "*.xml"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); + /* Filters */ + filter = gtk_file_filter_new (); + gtk_file_filter_set_name (filter, _("Color Scheme Files")); + gtk_file_filter_add_pattern (filter, "*.xml"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); - gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), filter); + gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), filter); - filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, _("All Files")); - gtk_file_filter_add_pattern (filter, "*"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); + filter = gtk_file_filter_new (); + gtk_file_filter_set_name (filter, _("All Files")); + gtk_file_filter_add_pattern (filter, "*"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); - gtk_dialog_set_default_response (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT); + gtk_dialog_set_default_response (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT); - g_signal_connect (chooser, - "response", - G_CALLBACK (add_scheme_chooser_response_cb), - dlg); + g_signal_connect (chooser, "response", + G_CALLBACK (add_scheme_chooser_response_cb), dlg); - dlg->priv->install_scheme_file_schooser = chooser; + dlg->priv->install_scheme_file_schooser = chooser; - g_object_add_weak_pointer (G_OBJECT (chooser), - (gpointer) &dlg->priv->install_scheme_file_schooser); + g_object_add_weak_pointer (G_OBJECT (chooser), (gpointer) &dlg->priv->install_scheme_file_schooser); - gtk_widget_show (chooser); + gtk_widget_show (chooser); } static void -uninstall_scheme_clicked (GtkButton *button, - XedPreferencesDialog *dlg) +uninstall_scheme_clicked (GtkButton *button, + XedPreferencesDialog *dlg) { - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreeIter iter; + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreeIter iter; - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->schemes_treeview)); - model = GTK_TREE_MODEL (dlg->priv->schemes_treeview_model); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->schemes_treeview)); + model = GTK_TREE_MODEL (dlg->priv->schemes_treeview_model); - if (gtk_tree_selection_get_selected (selection, - &model, - &iter)) - { - gchar *id; - gchar *name; + if (gtk_tree_selection_get_selected (selection, &model, &iter)) + { + gchar *id; + gchar *name; - gtk_tree_model_get (model, &iter, - ID_COLUMN, &id, - NAME_COLUMN, &name, - -1); + gtk_tree_model_get (model, &iter, ID_COLUMN, &id, NAME_COLUMN, &name, -1); - if (!_xed_style_scheme_manager_uninstall_scheme (xed_get_style_scheme_manager (), id)) - { - xed_warning (GTK_WINDOW (dlg), - _("Could not remove color scheme \"%s\"."), - name); - } - else - { - const gchar *real_new_id; - gchar *new_id = NULL; - GtkTreePath *path; - GtkTreeIter new_iter; - gboolean new_iter_set = FALSE; + if (!_xed_style_scheme_manager_uninstall_scheme (xed_get_style_scheme_manager (), id)) + { + xed_warning (GTK_WINDOW (dlg), _("Could not remove color scheme \"%s\"."), name); + } + else + { + const gchar *real_new_id; + gchar *new_id = NULL; + GtkTreePath *path; + GtkTreeIter new_iter; + gboolean new_iter_set = FALSE; - /* If the removed style scheme is the last of the list, - * set as new default style scheme the previous one, - * otherwise set the next one. - * To make this possible, we need to get the id of the - * new default style scheme before re-populating the list. - * Fall back to "classic" if it is not possible to get - * the id - */ - path = gtk_tree_model_get_path (model, &iter); + /* If the removed style scheme is the last of the list, + * set as new default style scheme the previous one, + * otherwise set the next one. + * To make this possible, we need to get the id of the + * new default style scheme before re-populating the list. + * Fall back to "classic" if it is not possible to get + * the id + */ + path = gtk_tree_model_get_path (model, &iter); - /* Try to move to the next path */ - gtk_tree_path_next (path); - if (!gtk_tree_model_get_iter (model, &new_iter, path)) - { - /* It seems the removed style scheme was the - * last of the list. Try to move to the - * previous one */ - gtk_tree_path_free (path); + /* Try to move to the next path */ + gtk_tree_path_next (path); + if (!gtk_tree_model_get_iter (model, &new_iter, path)) + { + /* It seems the removed style scheme was the + * last of the list. Try to move to the + * previous one */ + gtk_tree_path_free (path); - path = gtk_tree_model_get_path (model, &iter); + path = gtk_tree_model_get_path (model, &iter); - gtk_tree_path_prev (path); - if (gtk_tree_model_get_iter (model, &new_iter, path)) - new_iter_set = TRUE; - } - else - new_iter_set = TRUE; + gtk_tree_path_prev (path); + if (gtk_tree_model_get_iter (model, &new_iter, path)) + { + new_iter_set = TRUE; + } + } + else + { + new_iter_set = TRUE; + } - gtk_tree_path_free (path); + gtk_tree_path_free (path); - if (new_iter_set) - gtk_tree_model_get (model, &new_iter, - ID_COLUMN, &new_id, - -1); + if (new_iter_set) + { + gtk_tree_model_get (model, &new_iter, ID_COLUMN, &new_id, -1); + } - real_new_id = populate_color_scheme_list (dlg, new_id); - g_free (new_id); + real_new_id = populate_color_scheme_list (dlg, new_id); + g_free (new_id); - set_buttons_sensisitivity_according_to_scheme (dlg, real_new_id); + set_buttons_sensisitivity_according_to_scheme (dlg, real_new_id); - if (real_new_id != NULL) - xed_prefs_manager_set_source_style_scheme (real_new_id); - } + if (real_new_id != NULL) + { + xed_prefs_manager_set_source_style_scheme (real_new_id); + } + } - g_free (id); - g_free (name); - } + g_free (id); + g_free (name); + } } static void scheme_description_cell_data_func (GtkTreeViewColumn *column, - GtkCellRenderer *renderer, - GtkTreeModel *model, - GtkTreeIter *iter, - gpointer data) + GtkCellRenderer *renderer, + GtkTreeModel *model, + GtkTreeIter *iter, + gpointer data) { - gchar *name; - gchar *desc; - gchar *text; + gchar *name; + gchar *desc; + gchar *text; - gtk_tree_model_get (model, iter, - NAME_COLUMN, &name, - DESC_COLUMN, &desc, - -1); + gtk_tree_model_get (model, iter, NAME_COLUMN, &name, DESC_COLUMN, &desc, -1); - if (desc != NULL) - { - text = g_markup_printf_escaped ("%s - %s", - name, - desc); - } - else - { - text = g_markup_printf_escaped ("%s", - name); - } + if (desc != NULL) + { + text = g_markup_printf_escaped ("%s - %s", name, desc); + } + else + { + text = g_markup_printf_escaped ("%s", name); + } - g_free (name); - g_free (desc); + g_free (name); + g_free (desc); - g_object_set (G_OBJECT (renderer), - "markup", - text, - NULL); + g_object_set (G_OBJECT (renderer), "markup", text, NULL); - g_free (text); + g_free (text); } static void setup_font_colors_page_style_scheme_section (XedPreferencesDialog *dlg) { - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - GtkTreeSelection *selection; - const gchar *def_id; + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + GtkTreeSelection *selection; + const gchar *def_id; - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - /* Create GtkListStore for styles & setup treeview. */ - dlg->priv->schemes_treeview_model = gtk_list_store_new (NUM_COLUMNS, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING); + /* Create GtkListStore for styles & setup treeview. */ + dlg->priv->schemes_treeview_model = gtk_list_store_new (NUM_COLUMNS, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (dlg->priv->schemes_treeview_model), - 0, - GTK_SORT_ASCENDING); - gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->priv->schemes_treeview), - GTK_TREE_MODEL (dlg->priv->schemes_treeview_model)); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (dlg->priv->schemes_treeview_model), + 0, GTK_SORT_ASCENDING); + gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->priv->schemes_treeview), + GTK_TREE_MODEL (dlg->priv->schemes_treeview_model)); - column = gtk_tree_view_column_new (); + column = gtk_tree_view_column_new (); - renderer = gtk_cell_renderer_text_new (); - g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); - gtk_tree_view_column_pack_start (column, renderer, TRUE); - gtk_tree_view_column_set_cell_data_func (column, - renderer, - scheme_description_cell_data_func, - dlg, - NULL); + renderer = gtk_cell_renderer_text_new (); + g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); + gtk_tree_view_column_pack_start (column, renderer, TRUE); + gtk_tree_view_column_set_cell_data_func (column, + renderer, + scheme_description_cell_data_func, + dlg, + NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->schemes_treeview), - column); + gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->schemes_treeview), column); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->schemes_treeview)); - gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->schemes_treeview)); + gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); - def_id = populate_color_scheme_list (dlg, NULL); + def_id = populate_color_scheme_list (dlg, NULL); - /* Connect signals */ - g_signal_connect (dlg->priv->schemes_treeview, - "cursor-changed", - G_CALLBACK (style_scheme_changed), - dlg); - g_signal_connect (dlg->priv->install_scheme_button, - "clicked", - G_CALLBACK (install_scheme_clicked), - dlg); - g_signal_connect (dlg->priv->uninstall_scheme_button, - "clicked", - G_CALLBACK (uninstall_scheme_clicked), - dlg); + /* Connect signals */ + g_signal_connect (dlg->priv->schemes_treeview, "cursor-changed", + G_CALLBACK (style_scheme_changed), dlg); + g_signal_connect (dlg->priv->install_scheme_button, "clicked", + G_CALLBACK (install_scheme_clicked), dlg); + g_signal_connect (dlg->priv->uninstall_scheme_button, "clicked", + G_CALLBACK (uninstall_scheme_clicked), dlg); - /* Set initial widget sensitivity */ - set_buttons_sensisitivity_according_to_scheme (dlg, def_id); + /* Set initial widget sensitivity */ + set_buttons_sensisitivity_according_to_scheme (dlg, def_id); } static void setup_font_colors_page (XedPreferencesDialog *dlg) { - setup_font_colors_page_font_section (dlg); - setup_font_colors_page_style_scheme_section (dlg); + setup_font_colors_page_font_section (dlg); + setup_font_colors_page_style_scheme_section (dlg); } static void setup_plugins_page (XedPreferencesDialog *dlg) { - GtkWidget *page_content; + GtkWidget *page_content; - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - page_content = peas_gtk_plugin_manager_new (NULL); - g_return_if_fail (page_content != NULL); + page_content = peas_gtk_plugin_manager_new (NULL); + g_return_if_fail (page_content != NULL); - gtk_box_pack_start (GTK_BOX (dlg->priv->plugin_manager_place_holder), - page_content, - TRUE, - TRUE, - 0); + gtk_box_pack_start (GTK_BOX (dlg->priv->plugin_manager_place_holder), page_content, TRUE, TRUE, 0); - gtk_widget_show_all (page_content); + gtk_widget_show_all (page_content); } static void xed_preferences_dialog_init (XedPreferencesDialog *dlg) { - GtkWidget *error_widget; - gboolean ret; - gchar *file; - gchar *root_objects[] = { - "notebook", - "adjustment1", - "adjustment2", - "adjustment3", - "install_scheme_image", - NULL - }; + GtkWidget *error_widget; + gboolean ret; + gchar *file; + gchar *root_objects[] = { + "notebook", + "adjustment1", + "adjustment2", + "adjustment3", + "install_scheme_image", + NULL + }; - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - dlg->priv = XED_PREFERENCES_DIALOG_GET_PRIVATE (dlg); + dlg->priv = XED_PREFERENCES_DIALOG_GET_PRIVATE (dlg); - gtk_dialog_add_buttons (GTK_DIALOG (dlg), - GTK_STOCK_CLOSE, - GTK_RESPONSE_CLOSE, - GTK_STOCK_HELP, - GTK_RESPONSE_HELP, - NULL); + gtk_dialog_add_buttons (GTK_DIALOG (dlg), + GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, + GTK_STOCK_HELP, GTK_RESPONSE_HELP, + NULL); - gtk_window_set_title (GTK_WINDOW (dlg), _("Xed Preferences")); - gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE); - gtk_window_set_destroy_with_parent (GTK_WINDOW (dlg), TRUE); + gtk_window_set_title (GTK_WINDOW (dlg), _("Xed Preferences")); + gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE); + gtk_window_set_destroy_with_parent (GTK_WINDOW (dlg), TRUE); - /* HIG defaults */ - gtk_container_set_border_width (GTK_CONTAINER (dlg), 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), 2); /* 2 * 5 + 2 = 12 */ - gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 6); + /* HIG defaults */ + gtk_container_set_border_width (GTK_CONTAINER (dlg), 5); + gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), 2); /* 2 * 5 + 2 = 12 */ + gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 5); + gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 6); - g_signal_connect (dlg, - "response", - G_CALLBACK (dialog_response_handler), - NULL); + g_signal_connect (dlg, "response", + G_CALLBACK (dialog_response_handler), NULL); - file = xed_dirs_get_ui_file ("xed-preferences-dialog.ui"); - ret = xed_utils_get_ui_objects (file, - root_objects, - &error_widget, + file = xed_dirs_get_ui_file ("xed-preferences-dialog.ui"); + ret = xed_utils_get_ui_objects (file, root_objects, &error_widget, + "notebook", &dlg->priv->notebook, - "notebook", &dlg->priv->notebook, + "display_line_numbers_checkbutton", &dlg->priv->display_line_numbers_checkbutton, + "highlight_current_line_checkbutton", &dlg->priv->highlight_current_line_checkbutton, + "bracket_matching_checkbutton", &dlg->priv->bracket_matching_checkbutton, + "wrap_text_checkbutton", &dlg->priv->wrap_text_checkbutton, + "split_checkbutton", &dlg->priv->split_checkbutton, - "display_line_numbers_checkbutton", &dlg->priv->display_line_numbers_checkbutton, - "highlight_current_line_checkbutton", &dlg->priv->highlight_current_line_checkbutton, - "bracket_matching_checkbutton", &dlg->priv->bracket_matching_checkbutton, - "wrap_text_checkbutton", &dlg->priv->wrap_text_checkbutton, - "split_checkbutton", &dlg->priv->split_checkbutton, + "right_margin_checkbutton", &dlg->priv->right_margin_checkbutton, + "right_margin_position_spinbutton", &dlg->priv->right_margin_position_spinbutton, + "right_margin_position_hbox", &dlg->priv->right_margin_position_hbox, - "right_margin_checkbutton", &dlg->priv->right_margin_checkbutton, - "right_margin_position_spinbutton", &dlg->priv->right_margin_position_spinbutton, - "right_margin_position_hbox", &dlg->priv->right_margin_position_hbox, + "tabs_width_spinbutton", &dlg->priv->tabs_width_spinbutton, + "tabs_width_hbox", &dlg->priv->tabs_width_hbox, + "insert_spaces_checkbutton", &dlg->priv->insert_spaces_checkbutton, - "tabs_width_spinbutton", &dlg->priv->tabs_width_spinbutton, - "tabs_width_hbox", &dlg->priv->tabs_width_hbox, - "insert_spaces_checkbutton", &dlg->priv->insert_spaces_checkbutton, + "auto_indent_checkbutton", &dlg->priv->auto_indent_checkbutton, - "auto_indent_checkbutton", &dlg->priv->auto_indent_checkbutton, + "autosave_hbox", &dlg->priv->autosave_hbox, + "backup_copy_checkbutton", &dlg->priv->backup_copy_checkbutton, + "auto_save_checkbutton", &dlg->priv->auto_save_checkbutton, + "auto_save_spinbutton", &dlg->priv->auto_save_spinbutton, - "autosave_hbox", &dlg->priv->autosave_hbox, - "backup_copy_checkbutton", &dlg->priv->backup_copy_checkbutton, - "auto_save_checkbutton", &dlg->priv->auto_save_checkbutton, - "auto_save_spinbutton", &dlg->priv->auto_save_spinbutton, + "default_font_checkbutton", &dlg->priv->default_font_checkbutton, + "font_button", &dlg->priv->font_button, + "font_hbox", &dlg->priv->font_hbox, - "default_font_checkbutton", &dlg->priv->default_font_checkbutton, - "font_button", &dlg->priv->font_button, - "font_hbox", &dlg->priv->font_hbox, + "schemes_treeview", &dlg->priv->schemes_treeview, + "install_scheme_button", &dlg->priv->install_scheme_button, + "uninstall_scheme_button", &dlg->priv->uninstall_scheme_button, - "schemes_treeview", &dlg->priv->schemes_treeview, - "install_scheme_button", &dlg->priv->install_scheme_button, - "uninstall_scheme_button", &dlg->priv->uninstall_scheme_button, + "plugin_manager_place_holder", &dlg->priv->plugin_manager_place_holder, - "plugin_manager_place_holder", &dlg->priv->plugin_manager_place_holder, + NULL); + g_free (file); - NULL); - g_free (file); + if (!ret) + { + gtk_widget_show (error_widget); + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), error_widget, TRUE, TRUE, 0); + return; + } - if (!ret) - { - gtk_widget_show (error_widget); + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), dlg->priv->notebook, FALSE, FALSE, 0); + g_object_unref (dlg->priv->notebook); + gtk_container_set_border_width (GTK_CONTAINER (dlg->priv->notebook), 5); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), - error_widget, - TRUE, TRUE, 0); - - return; - } - - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), - dlg->priv->notebook, FALSE, FALSE, 0); - g_object_unref (dlg->priv->notebook); - gtk_container_set_border_width (GTK_CONTAINER (dlg->priv->notebook), 5); - - setup_editor_page (dlg); - setup_view_page (dlg); - setup_font_colors_page (dlg); - setup_plugins_page (dlg); + setup_editor_page (dlg); + setup_view_page (dlg); + setup_font_colors_page (dlg); + setup_plugins_page (dlg); } void xed_show_preferences_dialog (XedWindow *parent) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - g_return_if_fail (XED_IS_WINDOW (parent)); + g_return_if_fail (XED_IS_WINDOW (parent)); - if (preferences_dialog == NULL) - { - preferences_dialog = GTK_WIDGET (g_object_new (XED_TYPE_PREFERENCES_DIALOG, NULL)); - g_signal_connect (preferences_dialog, - "destroy", - G_CALLBACK (gtk_widget_destroyed), - &preferences_dialog); - } + if (preferences_dialog == NULL) + { + preferences_dialog = GTK_WIDGET (g_object_new (XED_TYPE_PREFERENCES_DIALOG, NULL)); + g_signal_connect (preferences_dialog, "destroy", + G_CALLBACK (gtk_widget_destroyed), &preferences_dialog); + } - if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (preferences_dialog))) - { - gtk_window_set_transient_for (GTK_WINDOW (preferences_dialog), - GTK_WINDOW (parent)); - } + if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (preferences_dialog))) + { + gtk_window_set_transient_for (GTK_WINDOW (preferences_dialog), GTK_WINDOW (parent)); + } - gtk_window_present (GTK_WINDOW (preferences_dialog)); + gtk_window_present (GTK_WINDOW (preferences_dialog)); } From 95a302a46f843bba9ddfe8d82333efee86dc2a23 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Fri, 30 Dec 2016 12:21:47 -0800 Subject: [PATCH 052/132] preferences-dialog: Clean up uses of GtkStock --- xed/dialogs/xed-preferences-dialog.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/xed/dialogs/xed-preferences-dialog.c b/xed/dialogs/xed-preferences-dialog.c index 9053625..1b60525 100755 --- a/xed/dialogs/xed-preferences-dialog.c +++ b/xed/dialogs/xed-preferences-dialog.c @@ -725,11 +725,10 @@ install_scheme_clicked (GtkButton *button, chooser = gtk_file_chooser_dialog_new (_("Add Scheme"), GTK_WINDOW (dlg), GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + _("Cancel"), GTK_RESPONSE_CANCEL, NULL); - xed_dialog_add_button (GTK_DIALOG (chooser), _("A_dd Scheme"), - GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT); + gtk_dialog_add_button (GTK_DIALOG (chooser), _("Add Scheme"), GTK_RESPONSE_ACCEPT); gtk_window_set_destroy_with_parent (GTK_WINDOW (chooser), TRUE); @@ -967,8 +966,8 @@ xed_preferences_dialog_init (XedPreferencesDialog *dlg) dlg->priv = XED_PREFERENCES_DIALOG_GET_PRIVATE (dlg); gtk_dialog_add_buttons (GTK_DIALOG (dlg), - GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, - GTK_STOCK_HELP, GTK_RESPONSE_HELP, + _("Close"), GTK_RESPONSE_CLOSE, + _("Help"), GTK_RESPONSE_HELP, NULL); gtk_window_set_title (GTK_WINDOW (dlg), _("Xed Preferences")); From 50c216b17bb56573613de0f0e588687713f8c3f7 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 31 Dec 2016 14:18:31 -0800 Subject: [PATCH 053/132] Allow scrolling on notebook tabs to change the active page This is enabled by default but has a setting in the preferences so it can be disabled. --- data/org.x.editor.gschema.xml.in | 5 + xed/dialogs/xed-preferences-dialog.c | 21 + xed/dialogs/xed-preferences-dialog.ui | 2233 +++++++++++++------------ xed/xed-notebook.c | 230 ++- xed/xed-notebook.h | 24 +- xed/xed-prefs-manager-app.c | 37 + xed/xed-prefs-manager.c | 117 +- xed/xed-prefs-manager.h | 8 + xed/xed-window.c | 3 + 9 files changed, 1508 insertions(+), 1170 deletions(-) diff --git a/data/org.x.editor.gschema.xml.in b/data/org.x.editor.gschema.xml.in index 8dc46c9..3d27f97 100644 --- a/data/org.x.editor.gschema.xml.in +++ b/data/org.x.editor.gschema.xml.in @@ -126,6 +126,11 @@ Bottom Panel is Visible Whether the bottom panel at the bottom of editing windows should be visible. + + true + Allow changing active tabs by scrolling + Whether you can change active tabs by scrolling. + 5 Maximum Recent Files diff --git a/xed/dialogs/xed-preferences-dialog.c b/xed/dialogs/xed-preferences-dialog.c index 1b60525..28c4dfa 100755 --- a/xed/dialogs/xed-preferences-dialog.c +++ b/xed/dialogs/xed-preferences-dialog.c @@ -125,6 +125,9 @@ struct _XedPreferencesDialogPrivate GtkWidget *right_margin_position_spinbutton; GtkWidget *right_margin_position_hbox; + /* Tab scrolling */ + GtkWidget *tab_scrolling_checkbutton; + /* Plugins manager */ GtkWidget *plugin_manager_place_holder; @@ -234,6 +237,17 @@ auto_save_spinbutton_value_changed (GtkSpinButton *spin_button, xed_prefs_manager_set_auto_save_interval (MAX (1, gtk_spin_button_get_value_as_int (spin_button))); } +static void +tab_scrolling_checkbutton_toggled (GtkToggleButton *button, + XedPreferencesDialog *dlg) +{ + xed_debug (DEBUG_PREFS); + + g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->tab_scrolling_checkbutton)); + + xed_prefs_manager_set_enable_tab_scrolling (gtk_toggle_button_get_active (button)); +} + static void setup_editor_page (XedPreferencesDialog *dlg) { @@ -251,6 +265,8 @@ setup_editor_page (XedPreferencesDialog *dlg) xed_prefs_manager_get_auto_indent ()); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton), xed_prefs_manager_get_create_backup_copy ()); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->tab_scrolling_checkbutton), + xed_prefs_manager_get_enable_tab_scrolling ()); auto_save = xed_prefs_manager_get_auto_save (); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_save_checkbutton), auto_save); @@ -271,6 +287,7 @@ setup_editor_page (XedPreferencesDialog *dlg) gtk_widget_set_sensitive (dlg->priv->autosave_hbox, xed_prefs_manager_auto_save_can_set ()); gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, auto_save && xed_prefs_manager_auto_save_interval_can_set ()); + gtk_widget_set_sensitive (dlg->priv->tab_scrolling_checkbutton, xed_prefs_manager_enable_tab_scrolling_can_set ()); /* Connect signal */ g_signal_connect (dlg->priv->tabs_width_spinbutton, "value_changed", @@ -285,6 +302,8 @@ setup_editor_page (XedPreferencesDialog *dlg) G_CALLBACK (backup_copy_checkbutton_toggled), dlg); g_signal_connect (dlg->priv->auto_save_spinbutton, "value_changed", G_CALLBACK (auto_save_spinbutton_value_changed), dlg); + g_signal_connect (dlg->priv->tab_scrolling_checkbutton, "toggled", + G_CALLBACK (tab_scrolling_checkbutton_toggled), dlg); } static void @@ -1008,6 +1027,8 @@ xed_preferences_dialog_init (XedPreferencesDialog *dlg) "auto_save_checkbutton", &dlg->priv->auto_save_checkbutton, "auto_save_spinbutton", &dlg->priv->auto_save_spinbutton, + "tab_scrolling_checkbutton", &dlg->priv->tab_scrolling_checkbutton, + "default_font_checkbutton", &dlg->priv->default_font_checkbutton, "font_button", &dlg->priv->font_button, "font_hbox", &dlg->priv->font_hbox, diff --git a/xed/dialogs/xed-preferences-dialog.ui b/xed/dialogs/xed-preferences-dialog.ui index ac801a9..8aa0957 100755 --- a/xed/dialogs/xed-preferences-dialog.ui +++ b/xed/dialogs/xed-preferences-dialog.ui @@ -1,1063 +1,47 @@ - + + - - + - 80 1 160 + 80 1 10 - 8 1 24 + 8 1 4 - 8 1 100 + 8 1 10 + False gtk-add + False Preferences False True dialog - + True + False vertical - - - True - True - 6 - - - True - 12 - vertical - 18 - - - True - vertical - 6 - - - True - 0 - Text Wrapping - - - - - - False - False - 0 - - - - - True - - - True - - - - False - False - 0 - - - - - True - vertical - 6 - - - Enable text _wrapping - True - True - False - True - True - - - False - False - 0 - - - - - Do not _split words over two lines - True - True - False - True - True - - - False - False - 1 - - - - - 1 - - - - - 1 - - - - - 0 - - - - - True - vertical - 6 - - - True - 0 - Line Numbers - - - - - - False - False - 0 - - - - - True - - - True - - - - False - False - 0 - - - - - True - 6 - - - _Display line numbers - True - True - False - True - True - - - False - False - 0 - - - - - 1 - - - - - 1 - - - - - False - False - 1 - - - - - True - vertical - 6 - - - True - 0 - Current Line - - - - - - False - False - 0 - - - - - True - - - True - - - - False - False - 0 - - - - - True - vertical - 6 - - - Highlight current _line - True - True - False - True - True - - - False - False - 0 - - - - - 1 - - - - - 1 - - - - - False - 2 - - - - - True - vertical - 6 - - - True - 0 - Right Margin - - - - - - False - False - 0 - - - - - True - - - True - - - - False - False - 0 - - - - - True - vertical - 6 - - - Display right _margin - True - True - False - True - True - - - False - False - 0 - - - - - True - 6 - - - True - 0 - _Right margin at column: - True - right_margin_position_spinbutton - - - False - False - 0 - - - - - True - True - adjustment1 - 1 - True - True - - - False - False - 1 - - - - - False - False - 1 - - - - - 1 - - - - - 1 - - - - - False - False - 3 - - - - - True - vertical - 6 - - - True - 0 - Bracket Matching - - - - - - False - False - 0 - - - - - True - - - True - - - - False - False - 0 - - - - - True - vertical - 6 - - - Highlight matching _bracket - True - True - False - True - True - - - False - False - 0 - - - - - 1 - - - - - 1 - - - - - 4 - - - - - - - True - View - - - False - - - - - True - 12 - vertical - 18 - - - True - vertical - 6 - - - True - 0 - Tab Stops - - - - - - False - False - 0 - - - - - True - - - True - - - - False - False - 0 - - - - - True - vertical - 6 - - - True - 6 - - - True - _Tab width: - True - center - tabs_width_spinbutton - - - False - False - 0 - - - - - True - True - adjustment2 - 1 - True - - - False - False - 1 - - - - - 0 - - - - - Insert _spaces instead of tabs - True - True - False - True - True - - - False - False - 1 - - - - - False - False - 1 - - - - - False - False - 1 - - - - - False - False - 0 - - - - - True - vertical - 6 - - - True - 0 - Automatic Indentation - - - - - - False - False - 0 - - - - - True - - - True - - - - False - False - 0 - - - - - _Enable automatic indentation - True - True - False - True - True - - - False - False - 1 - - - - - False - False - 1 - - - - - False - False - 1 - - - - - True - vertical - 6 - - - True - 0 - File Saving - - - - - - False - False - 0 - - - - - True - - - True - - - - False - False - 0 - - - - - True - vertical - 6 - - - Create a _backup copy of files before saving - True - True - False - True - True - - - False - False - 0 - - - - - True - 6 - - - _Autosave files every - True - True - False - True - True - - - False - False - 0 - - - - - True - True - adjustment3 - 1 - True - - - False - False - 1 - - - - - True - _minutes - True - center - auto_save_spinbutton - - - False - False - 2 - - - - - 1 - - - - - False - False - 1 - - - - - 1 - - - - - False - False - 2 - - - - - 1 - - - - - True - Editor - - - 1 - False - - - - - True - 12 - vertical - 18 - - - True - vertical - 6 - - - True - 0 - Font - - - - - - False - False - 0 - - - - - True - - - True - - - - False - False - 0 - - - - - True - vertical - 6 - - - _Use the system fixed width font (%s) - True - True - False - True - True - - - False - False - 0 - - - - - True - 12 - - - True - 0 - Editor _font: - True - center - font_button - - - False - False - 0 - - - - - True - True - False - Pick the editor font - True - - - 1 - - - - - False - False - 1 - - - - - 1 - - - - - 1 - - - - - False - False - 0 - - - - - True - vertical - 6 - - - True - 0 - Color Scheme - - - - - - False - False - 0 - - - - - True - - - True - - - - False - False - 0 - - - - - True - vertical - 6 - - - True - True - automatic - automatic - etched-in - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - False - True - - - - - 0 - - - - - True - 6 - end - - - _Add... - True - True - False - install_scheme_image - True - - - False - False - 0 - - - - - gtk-remove - True - True - False - True - - - False - False - 1 - - - - - False - 1 - - - - - 1 - - - - - 1 - - - - - 1 - - - - - 2 - - - - - True - Font & Colors - - - 2 - False - - - - - True - 12 - vertical - - - - - - 3 - - - - - True - Plugins - - - 3 - False - - - - - 1 - - - + True + False end @@ -1092,10 +76,1203 @@ False + False end 0 + + + True + True + 6 + + + True + False + 12 + 18 + + + True + False + 6 + + + True + False + Text Wrapping + 0 + + + + + + False + False + 0 + + + + + True + False + + + True + False + + + + False + False + 0 + + + + + True + False + 6 + + + Enable text _wrapping + True + True + False + True + 0.5 + True + + + False + False + 0 + + + + + Do not _split words over two lines + True + True + False + True + 0.5 + True + + + False + False + 1 + + + + + True + True + 1 + + + + + True + True + 1 + + + + + True + True + 0 + + + + + True + False + 6 + + + True + False + Line Numbers + 0 + + + + + + False + False + 0 + + + + + True + False + + + True + False + + + + False + False + 0 + + + + + True + False + 6 + + + _Display line numbers + True + True + False + True + 0.5 + True + + + False + False + 0 + + + + + True + True + 1 + + + + + True + True + 1 + + + + + False + False + 1 + + + + + True + False + 6 + + + True + False + Current Line + 0 + + + + + + False + False + 0 + + + + + True + False + + + True + False + + + + False + False + 0 + + + + + True + False + 6 + + + Highlight current _line + True + True + False + True + 0.5 + True + + + False + False + 0 + + + + + True + True + 1 + + + + + True + True + 1 + + + + + False + True + 2 + + + + + True + False + 6 + + + True + False + Right Margin + 0 + + + + + + False + False + 0 + + + + + True + False + + + True + False + + + + False + False + 0 + + + + + True + False + 6 + + + Display right _margin + True + True + False + True + 0.5 + True + + + False + False + 0 + + + + + True + False + 6 + + + True + False + _Right margin at column: + True + right_margin_position_spinbutton + 0 + + + False + False + 0 + + + + + True + True + adjustment1 + 1 + True + True + + + False + False + 1 + + + + + False + False + 1 + + + + + True + True + 1 + + + + + True + True + 1 + + + + + False + False + 3 + + + + + True + False + 6 + + + True + False + Bracket Matching + 0 + + + + + + False + False + 0 + + + + + True + False + + + True + False + + + + False + False + 0 + + + + + True + False + 6 + + + Highlight matching _bracket + True + True + False + True + 0.5 + True + + + False + False + 0 + + + + + True + True + 1 + + + + + True + True + 1 + + + + + True + True + 4 + + + + + + + True + False + View + + + False + + + + + True + False + 12 + 18 + + + True + False + 6 + + + True + False + Tab Stops + 0 + + + + + + False + False + 0 + + + + + True + False + + + True + False + + + + False + False + 0 + + + + + True + False + 6 + + + True + False + 6 + + + True + False + _Tab width: + True + center + tabs_width_spinbutton + + + False + False + 0 + + + + + True + True + adjustment2 + 1 + True + + + False + False + 1 + + + + + True + True + 0 + + + + + Insert _spaces instead of tabs + True + True + False + True + 0.5 + True + + + False + False + 1 + + + + + False + False + 1 + + + + + False + False + 1 + + + + + False + False + 0 + + + + + True + False + 6 + + + True + False + Automatic Indentation + 0 + + + + + + False + False + 0 + + + + + True + False + + + True + False + + + + False + False + 0 + + + + + _Enable automatic indentation + True + True + False + True + 0.5 + True + + + False + False + 1 + + + + + False + False + 1 + + + + + False + False + 1 + + + + + True + False + 6 + + + True + False + File Saving + 0 + + + + + + False + False + 0 + + + + + True + False + + + True + False + + + + False + False + 0 + + + + + True + False + 6 + + + Create a _backup copy of files before saving + True + True + False + True + 0.5 + True + + + False + False + 0 + + + + + True + False + 6 + + + _Autosave files every + True + True + False + True + 0.5 + True + + + False + False + 0 + + + + + True + True + adjustment3 + 1 + True + + + False + False + 1 + + + + + True + False + _minutes + True + center + auto_save_spinbutton + + + False + False + 2 + + + + + True + True + 1 + + + + + False + False + 1 + + + + + True + True + 1 + + + + + False + False + 2 + + + + + True + False + vertical + 6 + + + True + False + Tab Scrolling + 0 + + + + + + False + False + 0 + + + + + True + False + + + True + False + + + + False + True + 0 + + + + + Allow mouse wheel scrolling to change tabs + True + True + False + 0 + True + + + False + True + 1 + + + + + False + False + 1 + + + + + True + True + 3 + + + + + 1 + + + + + True + False + Editor + + + 1 + False + + + + + True + False + 12 + 18 + + + True + False + 6 + + + True + False + Font + 0 + + + + + + False + False + 0 + + + + + True + False + + + True + False + + + + False + False + 0 + + + + + True + False + 6 + + + _Use the system fixed width font (%s) + True + True + False + True + 0.5 + True + + + False + False + 0 + + + + + True + False + 12 + + + True + False + Editor _font: + True + center + font_button + 0 + + + False + False + 0 + + + + + True + True + False + Sans 12 + Pick the editor font + True + + + True + True + 1 + + + + + False + False + 1 + + + + + True + True + 1 + + + + + True + True + 1 + + + + + False + False + 0 + + + + + True + False + 6 + + + True + False + Color Scheme + 0 + + + + + + False + False + 0 + + + + + True + False + + + True + False + + + + False + False + 0 + + + + + True + False + 6 + + + True + True + etched-in + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + True + + + + + + + + True + True + 0 + + + + + True + False + 6 + end + + + _Add... + True + True + False + install_scheme_image + True + + + False + False + 0 + + + + + gtk-remove + True + True + False + True + + + False + False + 1 + + + + + False + True + 1 + + + + + True + True + 1 + + + + + True + True + 1 + + + + + True + True + 1 + + + + + 2 + + + + + True + False + Font & Colors + + + 2 + False + + + + + True + False + 12 + + + + + + 3 + + + + + True + False + Plugins + + + 3 + False + + + + + False + True + 1 + + diff --git a/xed/xed-notebook.c b/xed/xed-notebook.c index 46b9589..2e2cbd0 100644 --- a/xed/xed-notebook.c +++ b/xed/xed-notebook.c @@ -2,7 +2,7 @@ * xed-notebook.c * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. */ /* This file is a modified version of the epiphany file ephy-notebook.c @@ -64,6 +64,7 @@ struct _XedNotebookPrivate gint always_show_tabs : 1; gint close_buttons_sensitive : 1; gint tab_drag_and_drop_enabled : 1; + gint tab_scrolling_enabled : 1; guint destroy_has_run : 1; }; @@ -205,7 +206,7 @@ find_notebook_at_pointer (gint abs_x, gint abs_y) gdk_window_get_user_data (toplevel_win, &toplevel); /* toplevel should be an XedWindow */ - if ((toplevel != NULL) && + if ((toplevel != NULL) && XED_IS_WINDOW (toplevel)) { return XED_NOTEBOOK (_xed_window_get_notebook @@ -218,7 +219,7 @@ find_notebook_at_pointer (gint abs_x, gint abs_y) static gboolean is_in_notebook_window (XedNotebook *notebook, - gint abs_x, + gint abs_x, gint abs_y) { XedNotebook *nb_at_pointer; @@ -231,8 +232,8 @@ is_in_notebook_window (XedNotebook *notebook, } static gint -find_tab_num_at_pos (XedNotebook *notebook, - gint abs_x, +find_tab_num_at_pos (XedNotebook *notebook, + gint abs_x, gint abs_y) { GtkPositionType tab_pos; @@ -295,12 +296,12 @@ find_tab_num_at_pos (XedNotebook *notebook, ++page_num; } - + return AFTER_ALL_TABS; } -static gint -find_notebook_and_tab_at_pos (gint abs_x, +static gint +find_notebook_and_tab_at_pos (gint abs_x, gint abs_y, XedNotebook **notebook, gint *page_num) @@ -310,7 +311,7 @@ find_notebook_and_tab_at_pos (gint abs_x, { return NOT_IN_APP_WINDOWS; } - + *page_num = find_tab_num_at_pos (*notebook, abs_x, abs_y); if (*page_num < 0) @@ -331,8 +332,8 @@ find_notebook_and_tab_at_pos (gint abs_x, * @dest_position: the position for @tab * * Moves @tab from @src to @dest. - * If dest_position is greater than or equal to the number of tabs - * of the destination nootebook or negative, tab will be moved to the + * If dest_position is greater than or equal to the number of tabs + * of the destination nootebook or negative, tab will be moved to the * end of the tabs. */ void @@ -341,7 +342,7 @@ xed_notebook_move_tab (XedNotebook *src, XedTab *tab, gint dest_position) { - g_return_if_fail (XED_IS_NOTEBOOK (src)); + g_return_if_fail (XED_IS_NOTEBOOK (src)); g_return_if_fail (XED_IS_NOTEBOOK (dest)); g_return_if_fail (src != dest); g_return_if_fail (XED_IS_TAB (tab)); @@ -360,8 +361,8 @@ xed_notebook_move_tab (XedNotebook *src, * @dest_position: the position for @tab * * Reorders the page containing @tab, so that it appears in @dest_position position. - * If dest_position is greater than or equal to the number of tabs - * of the destination notebook or negative, tab will be moved to the + * If dest_position is greater than or equal to the number of tabs + * of the destination notebook or negative, tab will be moved to the * end of the tabs. */ void @@ -370,24 +371,24 @@ xed_notebook_reorder_tab (XedNotebook *src, gint dest_position) { gint old_position; - - g_return_if_fail (XED_IS_NOTEBOOK (src)); + + g_return_if_fail (XED_IS_NOTEBOOK (src)); g_return_if_fail (XED_IS_TAB (tab)); - old_position = gtk_notebook_page_num (GTK_NOTEBOOK (src), + old_position = gtk_notebook_page_num (GTK_NOTEBOOK (src), GTK_WIDGET (tab)); - + if (old_position == dest_position) return; - gtk_notebook_reorder_child (GTK_NOTEBOOK (src), + gtk_notebook_reorder_child (GTK_NOTEBOOK (src), GTK_WIDGET (tab), dest_position); - + if (!src->priv->drag_in_progress) { - g_signal_emit (G_OBJECT (src), - signals[TABS_REORDERED], + g_signal_emit (G_OBJECT (src), + signals[TABS_REORDERED], 0); } } @@ -412,8 +413,8 @@ drag_start (XedNotebook *notebook, gdk_pointer_grab (gtk_widget_get_window (GTK_WIDGET (notebook)), FALSE, GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, - NULL, - cursor, + NULL, + cursor, time); } } @@ -423,8 +424,8 @@ drag_stop (XedNotebook *notebook) { if (notebook->priv->drag_in_progress) { - g_signal_emit (G_OBJECT (notebook), - signals[TABS_REORDERED], + g_signal_emit (G_OBJECT (notebook), + signals[TABS_REORDERED], 0); } @@ -451,10 +452,10 @@ move_current_tab (XedNotebook *notebook, if (dest_position != cur_page_num) { GtkWidget *cur_tab; - + cur_tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), cur_page_num); - + xed_notebook_reorder_tab (XED_NOTEBOOK (notebook), XED_TAB (cur_tab), dest_position); @@ -474,11 +475,11 @@ motion_notify_cb (XedNotebook *notebook, { if (notebook->priv->tab_drag_and_drop_enabled == FALSE) return FALSE; - + if (gtk_drag_check_threshold (GTK_WIDGET (notebook), notebook->priv->x_start, notebook->priv->y_start, - event->x_root, + event->x_root, event->y_root)) { drag_start (notebook, event->time); @@ -490,16 +491,16 @@ motion_notify_cb (XedNotebook *notebook, result = find_notebook_and_tab_at_pos ((gint)event->x_root, (gint)event->y_root, - &dest, + &dest, &page_num); if (result != NOT_IN_APP_WINDOWS) { if (dest != notebook) { - move_current_tab_to_another_notebook (notebook, + move_current_tab_to_another_notebook (notebook, dest, - event, + event, page_num); } else @@ -530,7 +531,7 @@ move_current_tab_to_another_notebook (XedNotebook *src, g_return_if_fail (dest != src); cur_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (src)); - tab = XED_TAB (gtk_notebook_get_nth_page (GTK_NOTEBOOK (src), + tab = XED_TAB (gtk_notebook_get_nth_page (GTK_NOTEBOOK (src), cur_page)); /* stop drag in origin window */ @@ -574,8 +575,8 @@ button_release_cb (XedNotebook *notebook, { /* Tab was detached */ g_signal_emit (G_OBJECT (notebook), - signals[TAB_DETACHED], - 0, + signals[TAB_DETACHED], + 0, cur_page); } @@ -606,27 +607,27 @@ button_press_cb (XedNotebook *notebook, tab_clicked = find_tab_num_at_pos (notebook, event->x_root, event->y_root); - - if ((event->button == 1) && - (event->type == GDK_BUTTON_PRESS) && + + if ((event->button == 1) && + (event->type == GDK_BUTTON_PRESS) && (tab_clicked >= 0)) { notebook->priv->x_start = event->x_root; notebook->priv->y_start = event->y_root; - + notebook->priv->motion_notify_handler_id = g_signal_connect (G_OBJECT (notebook), "motion-notify-event", - G_CALLBACK (motion_notify_cb), + G_CALLBACK (motion_notify_cb), NULL); } - else if ((event->type == GDK_BUTTON_PRESS) && + else if ((event->type == GDK_BUTTON_PRESS) && (event->button == 3 || event->button == 2)) { if (tab_clicked == -1) { // CHECK: do we really need it? - + /* consume event, so that we don't pop up the context menu when * the mouse if not over a tab label */ @@ -635,7 +636,7 @@ button_press_cb (XedNotebook *notebook, else { /* Switch to the page the mouse is over, but don't consume the event */ - gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), + gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), tab_clicked); } } @@ -643,6 +644,42 @@ button_press_cb (XedNotebook *notebook, return FALSE; } +static gboolean +notebook_scroll_event_cb (XedNotebook *notebook, + GdkEventScroll *event, + gpointer data) +{ + GtkWidget *event_widget; + + if (!notebook->priv->tab_scrolling_enabled) + { + return TRUE; + } + + event_widget = gtk_get_event_widget ((GdkEvent *) event); + + if (event_widget == NULL) + { + return FALSE; + } + + switch (event->direction) + { + case GDK_SCROLL_DOWN: + case GDK_SCROLL_RIGHT: + gtk_notebook_next_page (GTK_NOTEBOOK (notebook)); + break; + case GDK_SCROLL_UP: + case GDK_SCROLL_LEFT: + gtk_notebook_prev_page (GTK_NOTEBOOK (notebook)); + break; + default: + break; + } + + return TRUE; +} + /** * xed_notebook_new: * @@ -689,7 +726,7 @@ xed_notebook_switch_page_cb (GtkNotebook *notebook, * and the pref is not set. */ static void -update_tabs_visibility (XedNotebook *nb, +update_tabs_visibility (XedNotebook *nb, gboolean before_inserting) { gboolean show_tabs; @@ -711,28 +748,33 @@ xed_notebook_init (XedNotebook *notebook) notebook->priv->close_buttons_sensitive = TRUE; notebook->priv->tab_drag_and_drop_enabled = TRUE; - + notebook->priv->tab_scrolling_enabled = TRUE; + gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE); gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE); gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE); notebook->priv->always_show_tabs = TRUE; - g_signal_connect (notebook, + g_signal_connect (notebook, "button-press-event", - (GCallback)button_press_cb, + (GCallback)button_press_cb, NULL); - g_signal_connect (notebook, + g_signal_connect (notebook, "button-release-event", (GCallback)button_release_cb, NULL); - gtk_widget_add_events (GTK_WIDGET (notebook), + gtk_widget_add_events (GTK_WIDGET (notebook), GDK_BUTTON1_MOTION_MASK); - g_signal_connect_after (G_OBJECT (notebook), + g_signal_connect_after (G_OBJECT (notebook), "switch_page", G_CALLBACK (xed_notebook_switch_page_cb), NULL); + + gtk_widget_add_events (GTK_WIDGET (notebook), GDK_SCROLL_MASK); + g_signal_connect (notebook, "scroll-event", + G_CALLBACK (notebook_scroll_event_cb), NULL); } static void @@ -755,17 +797,17 @@ xed_notebook_change_current_page (GtkNotebook *notebook, { gboolean wrap_around; gint current; - + current = gtk_notebook_get_current_page (notebook); if (current != -1) { current = current + offset; - + g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)), "gtk-keynav-wrap-around", &wrap_around, NULL); - + if (wrap_around) { if (current < 0) @@ -777,7 +819,7 @@ xed_notebook_change_current_page (GtkNotebook *notebook, current = 0; } } - + gtk_notebook_set_current_page (notebook, current); } else @@ -849,7 +891,7 @@ remove_tab_label (XedNotebook *nb, * Sets the visibility of the tabs in the @nb. */ void -xed_notebook_set_always_show_tabs (XedNotebook *nb, +xed_notebook_set_always_show_tabs (XedNotebook *nb, gboolean show_tabs) { g_return_if_fail (XED_IS_NOTEBOOK (nb)); @@ -880,7 +922,7 @@ xed_notebook_add_tab (XedNotebook *nb, g_return_if_fail (XED_IS_TAB (tab)); tab_label = create_tab_label (nb, tab); - gtk_notebook_insert_page (GTK_NOTEBOOK (nb), + gtk_notebook_insert_page (GTK_NOTEBOOK (nb), GTK_WIDGET (tab), tab_label, position); @@ -889,19 +931,19 @@ xed_notebook_add_tab (XedNotebook *nb, g_signal_emit (G_OBJECT (nb), signals[TAB_ADDED], 0, tab); /* The signal handler may have reordered the tabs */ - position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), + position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (tab)); if (jump_to) { XedView *view; - + gtk_notebook_set_current_page (GTK_NOTEBOOK (nb), position); - g_object_set_data (G_OBJECT (tab), + g_object_set_data (G_OBJECT (tab), "jump_to", GINT_TO_POINTER (jump_to)); view = xed_tab_get_view (tab); - + gtk_widget_grab_focus (GTK_WIDGET (view)); } } @@ -930,7 +972,7 @@ smart_tab_switching_on_closure (XedNotebook *nb, child = GTK_WIDGET (l->data); page_num = gtk_notebook_page_num (GTK_NOTEBOOK (nb), child); - gtk_notebook_set_current_page (GTK_NOTEBOOK (nb), + gtk_notebook_set_current_page (GTK_NOTEBOOK (nb), page_num); } } @@ -996,9 +1038,9 @@ xed_notebook_remove_tab (XedNotebook *nb, */ void xed_notebook_remove_all_tabs (XedNotebook *nb) -{ +{ g_return_if_fail (XED_IS_NOTEBOOK (nb)); - + g_list_free (nb->priv->focused_pages); nb->priv->focused_pages = NULL; @@ -1072,13 +1114,13 @@ xed_notebook_set_tab_drag_and_drop_enabled (XedNotebook *nb, gboolean enable) { g_return_if_fail (XED_IS_NOTEBOOK (nb)); - + enable = (enable != FALSE); - + if (enable == nb->priv->tab_drag_and_drop_enabled) return; - - nb->priv->tab_drag_and_drop_enabled = enable; + + nb->priv->tab_drag_and_drop_enabled = enable; } /** @@ -1089,11 +1131,49 @@ xed_notebook_set_tab_drag_and_drop_enabled (XedNotebook *nb, * * Returns: %TRUE if the drag and drop is enabled. */ -gboolean +gboolean xed_notebook_get_tab_drag_and_drop_enabled (XedNotebook *nb) { g_return_val_if_fail (XED_IS_NOTEBOOK (nb), TRUE); - + return nb->priv->tab_drag_and_drop_enabled; } +/** + * xed_notebook_set_tab_scrolling_enabled: + * @nb: a #XedNotebook + * @enable: %TRUE to enable tab scrolling + * + * Sets whether tab scrolling in the @nb is enabled. + */ +void +xed_notebook_set_tab_scrolling_enabled (XedNotebook *nb, + gboolean enable) +{ + g_return_if_fail (XED_IS_NOTEBOOK (nb)); + + enable = (enable != FALSE); + + if (enable == nb->priv->tab_scrolling_enabled) + { + return; + } + + nb->priv->tab_scrolling_enabled = enable; +} + +/** + * xed_notebook_get_tab_scrolling_enabled: + * @nb: a #XedNotebook + * + * Whether notebook tab scrolling is enabled + * + * Returns: %TRUE if tab scrolling is enabled + */ +gboolean +xed_notebook_get_tab_scrolling_enabled (XedNotebook *nb) +{ + g_return_val_if_fail (XED_IS_NOTEBOOK (nb), TRUE); + + return nb->priv->tab_scrolling_enabled; +} diff --git a/xed/xed-notebook.h b/xed/xed-notebook.h index f75fb2e..215b509 100644 --- a/xed/xed-notebook.h +++ b/xed/xed-notebook.h @@ -2,7 +2,7 @@ * xed-notebook.h * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. */ /* This file is a modified version of the epiphany file ephy-notebook.h @@ -34,7 +34,7 @@ * Copyright (C) 2003, 2004 Christian Persch * */ - + #ifndef XED_NOTEBOOK_H #define XED_NOTEBOOK_H @@ -62,7 +62,7 @@ typedef struct _XedNotebookPrivate XedNotebookPrivate; * Main object structure */ typedef struct _XedNotebook XedNotebook; - + struct _XedNotebook { GtkNotebook notebook; @@ -113,14 +113,14 @@ void xed_notebook_remove_all_tabs (XedNotebook *nb); void xed_notebook_reorder_tab (XedNotebook *src, XedTab *tab, gint dest_position); - + void xed_notebook_move_tab (XedNotebook *src, XedNotebook *dest, XedTab *tab, gint dest_position); /* FIXME: do we really need this function ? */ -void xed_notebook_set_always_show_tabs +void xed_notebook_set_always_show_tabs (XedNotebook *nb, gboolean show_tabs); @@ -138,6 +138,10 @@ void xed_notebook_set_tab_drag_and_drop_enabled gboolean xed_notebook_get_tab_drag_and_drop_enabled (XedNotebook *nb); +void xed_notebook_set_tab_scrolling_enabled (XedNotebook *nb, + gboolean enable); +gboolean xed_notebook_get_tab_scrolling_enabled (XedNotebook *nb); + G_END_DECLS #endif /* XED_NOTEBOOK_H */ diff --git a/xed/xed-prefs-manager-app.c b/xed/xed-prefs-manager-app.c index 56c4c0d..63957b3 100644 --- a/xed/xed-prefs-manager-app.c +++ b/xed/xed-prefs-manager-app.c @@ -43,6 +43,7 @@ #include "xed-debug.h" #include "xed-view.h" #include "xed-window.h" +#include "xed-notebook.h" #include "xed-window-private.h" #include "xed-plugins-engine.h" #include "xed-style-scheme-manager.h" @@ -84,6 +85,10 @@ static void xed_prefs_manager_smart_home_end_changed (GSettings *settings, gchar *key, gpointer user_data); +static void xed_prefs_manager_enable_tab_scrolling_changed (GSettings *settings, + gchar *key, + gpointer user_data); + static void xed_prefs_manager_hl_current_line_changed (GSettings *settings, gchar *key, gpointer user_data); @@ -660,6 +665,9 @@ xed_prefs_manager_app_init (void) G_CALLBACK (xed_prefs_manager_smart_home_end_changed), NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_ENABLE_TAB_SCROLLING, + G_CALLBACK (xed_prefs_manager_enable_tab_scrolling_changed), NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_HIGHLIGHT_CURRENT_LINE, G_CALLBACK (xed_prefs_manager_hl_current_line_changed), @@ -1168,6 +1176,35 @@ xed_prefs_manager_smart_home_end_changed (GSettings *settings, } } +static void +xed_prefs_manager_enable_tab_scrolling_changed (GSettings *settings, + gchar *key, + gpointer user_data) +{ + xed_debug (DEBUG_PREFS); + + g_printerr ("Tab scrolling changed\n"); + + if (strcmp (key, GPM_ENABLE_TAB_SCROLLING) == 0) + { + gboolean enable; + const GList *windows; + + enable = g_settings_get_boolean (settings, key); + + windows = xed_app_get_windows (xed_app_get_default ()); + while (windows != NULL) + { + XedNotebook *notebook; + + notebook = XED_NOTEBOOK (_xed_window_get_notebook (windows->data)); + xed_notebook_set_tab_scrolling_enabled (notebook, enable); + + windows = g_list_next (windows); + } + } +} + static void xed_prefs_manager_syntax_hl_enable_changed (GSettings *settings, gchar *key, diff --git a/xed/xed-prefs-manager.c b/xed/xed-prefs-manager.c index 55fc695..1834341 100644 --- a/xed/xed-prefs-manager.c +++ b/xed/xed-prefs-manager.c @@ -3,7 +3,7 @@ * xed-prefs-manager.c * This file is part of xed * - * Copyright (C) 2002 Paolo Maggi + * Copyright (C) 2002 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,14 +17,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2002. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2002. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. */ #ifdef HAVE_CONFIG_H @@ -65,7 +65,7 @@ xed_prefs_manager_ ## name ## _can_set (void) \ xed_debug (DEBUG_PREFS); \ \ return xed_prefs_manager_key_is_writable (key); \ -} +} @@ -92,7 +92,7 @@ xed_prefs_manager_ ## name ## _can_set (void) \ xed_debug (DEBUG_PREFS); \ \ return xed_prefs_manager_key_is_writable (key); \ -} +} @@ -119,7 +119,7 @@ xed_prefs_manager_ ## name ## _can_set (void) \ xed_debug (DEBUG_PREFS); \ \ return xed_prefs_manager_key_is_writable (key); \ -} +} XedPrefsManager *xed_prefs_manager = NULL; @@ -162,7 +162,7 @@ xed_prefs_manager_shutdown (void) xed_prefs_manager->interface_settings = NULL; } -static gboolean +static gboolean xed_prefs_manager_get_bool (const gchar* key) { xed_debug (DEBUG_PREFS); @@ -170,7 +170,7 @@ xed_prefs_manager_get_bool (const gchar* key) return g_settings_get_boolean (xed_prefs_manager->settings, key); } -static gint +static gint xed_prefs_manager_get_int (const gchar* key) { xed_debug (DEBUG_PREFS); @@ -186,7 +186,7 @@ xed_prefs_manager_get_string (const gchar* key) return g_settings_get_string (xed_prefs_manager->settings, key); } -static void +static void xed_prefs_manager_set_bool (const gchar* key, gboolean value) { xed_debug (DEBUG_PREFS); @@ -197,7 +197,7 @@ xed_prefs_manager_set_bool (const gchar* key, gboolean value) g_settings_set_boolean (xed_prefs_manager->settings, key, value); } -static void +static void xed_prefs_manager_set_int (const gchar* key, gint value) { xed_debug (DEBUG_PREFS); @@ -208,20 +208,20 @@ xed_prefs_manager_set_int (const gchar* key, gint value) g_settings_set_int (xed_prefs_manager->settings, key, value); } -static void +static void xed_prefs_manager_set_string (const gchar* key, const gchar* value) { xed_debug (DEBUG_PREFS); g_return_if_fail (value != NULL); - + g_return_if_fail (g_settings_is_writable ( xed_prefs_manager->settings, key)); g_settings_set_string (xed_prefs_manager->settings, key, value); } -static gboolean +static gboolean xed_prefs_manager_key_is_writable (const gchar* key) { xed_debug (DEBUG_PREFS); @@ -267,13 +267,13 @@ DEFINE_INT_PREF (auto_save_interval, DEFINE_INT_PREF (undo_actions_limit, GPM_UNDO_ACTIONS_LIMIT) -static GtkWrapMode +static GtkWrapMode get_wrap_mode_from_string (const gchar* str) { GtkWrapMode res; g_return_val_if_fail (str != NULL, GTK_WRAP_WORD); - + if (strcmp (str, "GTK_WRAP_NONE") == 0) res = GTK_WRAP_NONE; else @@ -293,9 +293,9 @@ xed_prefs_manager_get_wrap_mode (void) { gchar *str; GtkWrapMode res; - + xed_debug (DEBUG_PREFS); - + str = xed_prefs_manager_get_string (GPM_WRAP_MODE); res = get_wrap_mode_from_string (str); @@ -304,12 +304,12 @@ xed_prefs_manager_get_wrap_mode (void) return res; } - + void xed_prefs_manager_set_wrap_mode (GtkWrapMode wp) { const gchar * str; - + xed_debug (DEBUG_PREFS); switch (wp) @@ -329,30 +329,30 @@ xed_prefs_manager_set_wrap_mode (GtkWrapMode wp) xed_prefs_manager_set_string (GPM_WRAP_MODE, str); } - + gboolean xed_prefs_manager_wrap_mode_can_set (void) { xed_debug (DEBUG_PREFS); - + return xed_prefs_manager_key_is_writable (GPM_WRAP_MODE); } /* Tabs size */ -DEFINE_INT_PREF (tabs_size, +DEFINE_INT_PREF (tabs_size, GPM_TABS_SIZE) /* Insert spaces */ -DEFINE_BOOL_PREF (insert_spaces, +DEFINE_BOOL_PREF (insert_spaces, GPM_INSERT_SPACES) /* Auto indent */ -DEFINE_BOOL_PREF (auto_indent, +DEFINE_BOOL_PREF (auto_indent, GPM_AUTO_INDENT) /* Display line numbers */ -DEFINE_BOOL_PREF (display_line_numbers, +DEFINE_BOOL_PREF (display_line_numbers, GPM_DISPLAY_LINE_NUMBERS) /* Toolbar visibility */ @@ -362,15 +362,18 @@ DEFINE_BOOL_PREF (toolbar_visible, /* Statusbar visiblity */ DEFINE_BOOL_PREF (statusbar_visible, GPM_STATUSBAR_VISIBLE) - + /* Side Pane visiblity */ DEFINE_BOOL_PREF (side_pane_visible, GPM_SIDE_PANE_VISIBLE) - + /* Bottom Panel visiblity */ DEFINE_BOOL_PREF (bottom_panel_visible, GPM_BOTTOM_PANEL_VISIBLE) +/* Tab scrolling */ +DEFINE_BOOL_PREF (enable_tab_scrolling, GPM_ENABLE_TAB_SCROLLING) + /* Print syntax highlighting */ DEFINE_BOOL_PREF (print_syntax_hl, GPM_PRINT_SYNTAX) @@ -386,9 +389,9 @@ xed_prefs_manager_get_print_wrap_mode (void) { gchar *str; GtkWrapMode res; - + xed_debug (DEBUG_PREFS); - + str = xed_prefs_manager_get_string (GPM_PRINT_WRAP_MODE); if (strcmp (str, "GTK_WRAP_NONE") == 0) @@ -405,7 +408,7 @@ xed_prefs_manager_get_print_wrap_mode (void) return res; } - + void xed_prefs_manager_set_print_wrap_mode (GtkWrapMode pwp) { @@ -434,11 +437,11 @@ gboolean xed_prefs_manager_print_wrap_mode_can_set (void) { xed_debug (DEBUG_PREFS); - + return xed_prefs_manager_key_is_writable (GPM_PRINT_WRAP_MODE); } -/* Print line numbers */ +/* Print line numbers */ DEFINE_INT_PREF (print_line_numbers, GPM_PRINT_LINE_NUMBERS) @@ -481,8 +484,8 @@ xed_prefs_manager_get_default_print_font_numbers (void) return xed_prefs_manager_get_default_string_value (GPM_PRINT_FONT_NUMBERS); } -/* Max number of files in "Recent Files" menu. - * This is configurable only using gsettings, dconf or dconf-editor +/* Max number of files in "Recent Files" menu. + * This is configurable only using gsettings, dconf or dconf-editor */ gint xed_prefs_manager_get_max_recents (void) @@ -556,16 +559,16 @@ xed_prefs_manager_get_auto_detected_encodings (void) strings = xed_prefs_manager_get_gslist (xed_prefs_manager->settings, GPM_AUTO_DETECTED_ENCODINGS); if (strings != NULL) - { + { GSList *tmp; const XedEncoding *enc; tmp = strings; - + while (tmp) { const char *charset = tmp->data; - + if (strcmp (charset, "CURRENT") == 0) g_get_charset (&charset); @@ -583,7 +586,7 @@ xed_prefs_manager_get_auto_detected_encodings (void) } g_slist_foreach (strings, (GFunc) g_free, NULL); - g_slist_free (strings); + g_slist_free (strings); res = g_slist_reverse (res); } @@ -607,12 +610,12 @@ xed_prefs_manager_get_shown_in_menu_encodings (void) strings = xed_prefs_manager_get_gslist (xed_prefs_manager->settings, GPM_SHOWN_IN_MENU_ENCODINGS); if (strings != NULL) - { + { GSList *tmp; const XedEncoding *enc; tmp = strings; - + while (tmp) { const char *charset = tmp->data; @@ -633,7 +636,7 @@ xed_prefs_manager_get_shown_in_menu_encodings (void) } g_slist_foreach (strings, (GFunc) g_free, NULL); - g_slist_free (strings); + g_slist_free (strings); res = g_slist_reverse (res); } @@ -643,9 +646,9 @@ xed_prefs_manager_get_shown_in_menu_encodings (void) void xed_prefs_manager_set_shown_in_menu_encodings (const GSList *encs) -{ +{ GSList *list = NULL; - + g_return_if_fail (xed_prefs_manager != NULL); g_return_if_fail (xed_prefs_manager->settings != NULL); g_return_if_fail (xed_prefs_manager_shown_in_menu_encodings_can_set ()); @@ -654,7 +657,7 @@ xed_prefs_manager_set_shown_in_menu_encodings (const GSList *encs) { const XedEncoding *enc; const gchar *charset; - + enc = (const XedEncoding *)encs->data; charset = xed_encoding_get_charset (enc); @@ -676,7 +679,7 @@ gboolean xed_prefs_manager_shown_in_menu_encodings_can_set (void) { xed_debug (DEBUG_PREFS); - + return xed_prefs_manager_key_is_writable (GPM_SHOWN_IN_MENU_ENCODINGS); } @@ -688,12 +691,12 @@ DEFINE_BOOL_PREF (highlight_current_line, /* Highlight matching bracket */ DEFINE_BOOL_PREF (bracket_matching, GPM_BRACKET_MATCHING) - + /* Display Right Margin */ DEFINE_BOOL_PREF (display_right_margin, GPM_DISPLAY_RIGHT_MARGIN) -/* Right Margin Position */ +/* Right Margin Position */ DEFINE_INT_PREF (right_margin_position, GPM_RIGHT_MARGIN_POSITION) @@ -732,7 +735,7 @@ xed_prefs_manager_get_smart_home_end (void) return res; } - + void xed_prefs_manager_set_smart_home_end (GtkSourceSmartHomeEndType smart_he) { @@ -765,7 +768,7 @@ gboolean xed_prefs_manager_smart_home_end_can_set (void) { xed_debug (DEBUG_PREFS); - + return xed_prefs_manager_key_is_writable (GPM_SMART_HOME_END); } @@ -785,7 +788,7 @@ GSList * xed_prefs_manager_get_writable_vfs_schemes (void) { GSList *strings; - + xed_debug (DEBUG_PREFS); g_return_val_if_fail (xed_prefs_manager != NULL, NULL); @@ -794,8 +797,8 @@ xed_prefs_manager_get_writable_vfs_schemes (void) strings = xed_prefs_manager_get_gslist (xed_prefs_manager->settings, GPM_WRITABLE_VFS_SCHEMES); /* The 'file' scheme is writable by default. */ - strings = g_slist_prepend (strings, g_strdup ("file")); - + strings = g_slist_prepend (strings, g_strdup ("file")); + xed_debug_message (DEBUG_PREFS, "Done"); return strings; @@ -829,7 +832,7 @@ xed_prefs_manager_get_active_plugins (void) void xed_prefs_manager_set_active_plugins (const GSList *plugins) -{ +{ g_return_if_fail (xed_prefs_manager != NULL); g_return_if_fail (xed_prefs_manager->settings != NULL); g_return_if_fail (xed_prefs_manager_active_plugins_can_set ()); diff --git a/xed/xed-prefs-manager.h b/xed/xed-prefs-manager.h index 41e45e9..600ff61 100644 --- a/xed/xed-prefs-manager.h +++ b/xed/xed-prefs-manager.h @@ -81,6 +81,8 @@ #define GPM_BOTTOM_PANEL_VISIBLE "bottom-panel-visible" +#define GPM_ENABLE_TAB_SCROLLING "enable-tab-scrolling" + #define GPM_MAX_RECENTS "max-recents" /* Print */ @@ -201,6 +203,12 @@ gboolean xed_prefs_manager_side_pane_visible_can_set (void); gboolean xed_prefs_manager_get_bottom_panel_visible (void); void xed_prefs_manager_set_bottom_panel_visible (gboolean tv); gboolean xed_prefs_manager_bottom_panel_visible_can_set(void); + +/* Tab scrolling enabled */ +gboolean xed_prefs_manager_get_enable_tab_scrolling (void); +void xed_prefs_manager_set_enable_tab_scrolling (gboolean tv); +gboolean xed_prefs_manager_enable_tab_scrolling_can_set (void); + /* Print syntax highlighting */ gboolean xed_prefs_manager_get_print_syntax_hl (void); void xed_prefs_manager_set_print_syntax_hl (gboolean ps); diff --git a/xed/xed-window.c b/xed/xed-window.c index bd755f9..e682dc5 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -3368,6 +3368,9 @@ add_notebook (XedWindow *window, { gtk_paned_pack1 (GTK_PANED(window->priv->vpaned), notebook, TRUE, TRUE); gtk_widget_show (notebook); + + xed_notebook_set_tab_scrolling_enabled (XED_NOTEBOOK (notebook), xed_prefs_manager_get_enable_tab_scrolling ()); + connect_notebook_signals (window, notebook); } From 33f6b71edac5a2c9a77fb984f42ab653bc69e834 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 31 Dec 2016 15:00:49 -0800 Subject: [PATCH 054/132] xed-prefs-manager-app: Remove some leftover logging --- xed/xed-prefs-manager-app.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/xed/xed-prefs-manager-app.c b/xed/xed-prefs-manager-app.c index 63957b3..f9ff6c8 100644 --- a/xed/xed-prefs-manager-app.c +++ b/xed/xed-prefs-manager-app.c @@ -1183,8 +1183,6 @@ xed_prefs_manager_enable_tab_scrolling_changed (GSettings *settings, { xed_debug (DEBUG_PREFS); - g_printerr ("Tab scrolling changed\n"); - if (strcmp (key, GPM_ENABLE_TAB_SCROLLING) == 0) { gboolean enable; From d80329db5cff5cbf15a84a9da093e68f5209195a Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 31 Dec 2016 16:33:21 -0800 Subject: [PATCH 055/132] xed-notebook.c: Clean up the code formatting --- xed/xed-notebook.c | 1138 +++++++++++++++++++++----------------------- 1 file changed, 542 insertions(+), 596 deletions(-) diff --git a/xed/xed-notebook.c b/xed/xed-notebook.c index 2e2cbd0..b51e2ba 100644 --- a/xed/xed-notebook.c +++ b/xed/xed-notebook.c @@ -56,16 +56,16 @@ struct _XedNotebookPrivate { - GList *focused_pages; - gulong motion_notify_handler_id; - gint x_start; - gint y_start; - gint drag_in_progress : 1; - gint always_show_tabs : 1; - gint close_buttons_sensitive : 1; - gint tab_drag_and_drop_enabled : 1; + GList *focused_pages; + gulong motion_notify_handler_id; + gint x_start; + gint y_start; + gint drag_in_progress : 1; + gint always_show_tabs : 1; + gint close_buttons_sensitive : 1; + gint tab_drag_and_drop_enabled : 1; gint tab_scrolling_enabled : 1; - guint destroy_has_run : 1; + guint destroy_has_run : 1; }; G_DEFINE_TYPE(XedNotebook, xed_notebook, GTK_TYPE_NOTEBOOK) @@ -73,12 +73,12 @@ G_DEFINE_TYPE(XedNotebook, xed_notebook, GTK_TYPE_NOTEBOOK) static void xed_notebook_finalize (GObject *object); static gboolean xed_notebook_change_current_page (GtkNotebook *notebook, - gint offset); + gint offset); -static void move_current_tab_to_another_notebook (XedNotebook *src, - XedNotebook *dest, - GdkEventMotion *event, - gint dest_position); +static void move_current_tab_to_another_notebook (XedNotebook *src, + XedNotebook *dest, + GdkEventMotion *event, + gint dest_position); /* Local variables */ static GdkCursor *cursor = NULL; @@ -86,12 +86,12 @@ static GdkCursor *cursor = NULL; /* Signals */ enum { - TAB_ADDED, - TAB_REMOVED, - TABS_REORDERED, - TAB_DETACHED, - TAB_CLOSE_REQUEST, - LAST_SIGNAL + TAB_ADDED, + TAB_REMOVED, + TABS_REORDERED, + TAB_DETACHED, + TAB_CLOSE_REQUEST, + LAST_SIGNAL }; static guint signals[LAST_SIGNAL] = { 0 }; @@ -99,178 +99,175 @@ static guint signals[LAST_SIGNAL] = { 0 }; static void xed_notebook_dispose (GObject *object) { - XedNotebook *notebook = XED_NOTEBOOK (object); + XedNotebook *notebook = XED_NOTEBOOK (object); - if (!notebook->priv->destroy_has_run) - { - GList *children, *l; + if (!notebook->priv->destroy_has_run) + { + GList *children, *l; - children = gtk_container_get_children (GTK_CONTAINER (notebook)); + children = gtk_container_get_children (GTK_CONTAINER (notebook)); - for (l = children; l != NULL; l = g_list_next (l)) - { - xed_notebook_remove_tab (notebook, - XED_TAB (l->data)); - } + for (l = children; l != NULL; l = g_list_next (l)) + { + xed_notebook_remove_tab (notebook, XED_TAB (l->data)); + } - g_list_free (children); - notebook->priv->destroy_has_run = TRUE; - } + g_list_free (children); + notebook->priv->destroy_has_run = TRUE; + } - G_OBJECT_CLASS (xed_notebook_parent_class)->dispose (object); + G_OBJECT_CLASS (xed_notebook_parent_class)->dispose (object); } static void xed_notebook_class_init (XedNotebookClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkNotebookClass *notebook_class = GTK_NOTEBOOK_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkNotebookClass *notebook_class = GTK_NOTEBOOK_CLASS (klass); - object_class->finalize = xed_notebook_finalize; - object_class->dispose = xed_notebook_dispose; + object_class->finalize = xed_notebook_finalize; + object_class->dispose = xed_notebook_dispose; - notebook_class->change_current_page = xed_notebook_change_current_page; + notebook_class->change_current_page = xed_notebook_change_current_page; - signals[TAB_ADDED] = - g_signal_new ("tab_added", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (XedNotebookClass, tab_added), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - XED_TYPE_TAB); - signals[TAB_REMOVED] = - g_signal_new ("tab_removed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (XedNotebookClass, tab_removed), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - XED_TYPE_TAB); - signals[TAB_DETACHED] = - g_signal_new ("tab_detached", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (XedNotebookClass, tab_detached), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - XED_TYPE_TAB); - signals[TABS_REORDERED] = - g_signal_new ("tabs_reordered", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (XedNotebookClass, tabs_reordered), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - signals[TAB_CLOSE_REQUEST] = - g_signal_new ("tab-close-request", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedNotebookClass, tab_close_request), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - XED_TYPE_TAB); + signals[TAB_ADDED] = + g_signal_new ("tab_added", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (XedNotebookClass, tab_added), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, + XED_TYPE_TAB); + signals[TAB_REMOVED] = + g_signal_new ("tab_removed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (XedNotebookClass, tab_removed), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, + XED_TYPE_TAB); + signals[TAB_DETACHED] = + g_signal_new ("tab_detached", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (XedNotebookClass, tab_detached), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, + XED_TYPE_TAB); + signals[TABS_REORDERED] = + g_signal_new ("tabs_reordered", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (XedNotebookClass, tabs_reordered), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + signals[TAB_CLOSE_REQUEST] = + g_signal_new ("tab-close-request", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedNotebookClass, tab_close_request), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, + XED_TYPE_TAB); - g_type_class_add_private (object_class, sizeof(XedNotebookPrivate)); + g_type_class_add_private (object_class, sizeof(XedNotebookPrivate)); } static XedNotebook * -find_notebook_at_pointer (gint abs_x, gint abs_y) +find_notebook_at_pointer (gint abs_x, + gint abs_y) { - GdkWindow *win_at_pointer; - GdkWindow *toplevel_win; - gpointer toplevel = NULL; - gint x, y; + GdkWindow *win_at_pointer; + GdkWindow *toplevel_win; + gpointer toplevel = NULL; + gint x, y; - /* FIXME multi-head */ - win_at_pointer = gdk_window_at_pointer (&x, &y); - if (win_at_pointer == NULL) - { - /* We are outside all windows of the same application */ - return NULL; - } + /* FIXME multi-head */ + win_at_pointer = gdk_window_at_pointer (&x, &y); + if (win_at_pointer == NULL) + { + /* We are outside all windows of the same application */ + return NULL; + } - toplevel_win = gdk_window_get_toplevel (win_at_pointer); + toplevel_win = gdk_window_get_toplevel (win_at_pointer); - /* get the GtkWidget which owns the toplevel GdkWindow */ - gdk_window_get_user_data (toplevel_win, &toplevel); + /* get the GtkWidget which owns the toplevel GdkWindow */ + gdk_window_get_user_data (toplevel_win, &toplevel); - /* toplevel should be an XedWindow */ - if ((toplevel != NULL) && - XED_IS_WINDOW (toplevel)) - { - return XED_NOTEBOOK (_xed_window_get_notebook - (XED_WINDOW (toplevel))); - } + /* toplevel should be an XedWindow */ + if ((toplevel != NULL) && XED_IS_WINDOW (toplevel)) + { + return XED_NOTEBOOK (_xed_window_get_notebook (XED_WINDOW (toplevel))); + } - /* We are outside all windows containing a notebook */ - return NULL; + /* We are outside all windows containing a notebook */ + return NULL; } static gboolean is_in_notebook_window (XedNotebook *notebook, - gint abs_x, - gint abs_y) + gint abs_x, + gint abs_y) { - XedNotebook *nb_at_pointer; + XedNotebook *nb_at_pointer; - g_return_val_if_fail (notebook != NULL, FALSE); + g_return_val_if_fail (notebook != NULL, FALSE); - nb_at_pointer = find_notebook_at_pointer (abs_x, abs_y); + nb_at_pointer = find_notebook_at_pointer (abs_x, abs_y); - return (nb_at_pointer == notebook); + return (nb_at_pointer == notebook); } static gint find_tab_num_at_pos (XedNotebook *notebook, - gint abs_x, - gint abs_y) + gint abs_x, + gint abs_y) { - GtkPositionType tab_pos; - int page_num = 0; - GtkNotebook *nb = GTK_NOTEBOOK (notebook); - GtkWidget *page; + GtkPositionType tab_pos; + int page_num = 0; + GtkNotebook *nb = GTK_NOTEBOOK (notebook); + GtkWidget *page; - tab_pos = gtk_notebook_get_tab_pos (GTK_NOTEBOOK (notebook)); + tab_pos = gtk_notebook_get_tab_pos (GTK_NOTEBOOK (notebook)); - /* For some reason unfullscreen + quick click can - cause a wrong click event to be reported to the tab */ - if (!is_in_notebook_window (notebook, abs_x, abs_y)) - { - return NOT_IN_APP_WINDOWS; - } + /* For some reason unfullscreen + quick click can + cause a wrong click event to be reported to the tab */ + if (!is_in_notebook_window (notebook, abs_x, abs_y)) + { + return NOT_IN_APP_WINDOWS; + } - while ((page = gtk_notebook_get_nth_page (nb, page_num)) != NULL) - { - GtkAllocation allocation; - GtkWidget *tab; + while ((page = gtk_notebook_get_nth_page (nb, page_num)) != NULL) + { + GtkAllocation allocation; + GtkWidget *tab; gint min_x, min_y; - gint max_x, max_y; - gint x_root, y_root; + gint max_x, max_y; + gint x_root, y_root; - tab = gtk_notebook_get_tab_label (nb, page); - g_return_val_if_fail (tab != NULL, AFTER_ALL_TABS); + tab = gtk_notebook_get_tab_label (nb, page); + g_return_val_if_fail (tab != NULL, AFTER_ALL_TABS); - if (!gtk_widget_get_mapped (tab)) - { - ++page_num; - continue; - } + if (!gtk_widget_get_mapped (tab)) + { + ++page_num; + continue; + } - gdk_window_get_origin (GDK_WINDOW (gtk_widget_get_window (tab)), - &x_root, &y_root); + gdk_window_get_origin (GDK_WINDOW (gtk_widget_get_window (tab)), &x_root, &y_root); - gtk_widget_get_allocation(tab, &allocation); + gtk_widget_get_allocation(tab, &allocation); min_x = x_root + allocation.x; max_x = x_root + allocation.x + allocation.width; @@ -294,34 +291,34 @@ find_tab_num_at_pos (XedNotebook *notebook, return page_num; } - ++page_num; - } + ++page_num; + } - return AFTER_ALL_TABS; + return AFTER_ALL_TABS; } static gint -find_notebook_and_tab_at_pos (gint abs_x, - gint abs_y, - XedNotebook **notebook, - gint *page_num) +find_notebook_and_tab_at_pos (gint abs_x, + gint abs_y, + XedNotebook **notebook, + gint *page_num) { - *notebook = find_notebook_at_pointer (abs_x, abs_y); - if (*notebook == NULL) - { - return NOT_IN_APP_WINDOWS; - } + *notebook = find_notebook_at_pointer (abs_x, abs_y); + if (*notebook == NULL) + { + return NOT_IN_APP_WINDOWS; + } - *page_num = find_tab_num_at_pos (*notebook, abs_x, abs_y); + *page_num = find_tab_num_at_pos (*notebook, abs_x, abs_y); - if (*page_num < 0) - { - return *page_num; - } - else - { - return 0; - } + if (*page_num < 0) + { + return *page_num; + } + else + { + return 0; + } } /** @@ -338,20 +335,20 @@ find_notebook_and_tab_at_pos (gint abs_x, */ void xed_notebook_move_tab (XedNotebook *src, - XedNotebook *dest, - XedTab *tab, - gint dest_position) + XedNotebook *dest, + XedTab *tab, + gint dest_position) { - g_return_if_fail (XED_IS_NOTEBOOK (src)); - g_return_if_fail (XED_IS_NOTEBOOK (dest)); - g_return_if_fail (src != dest); - g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail (XED_IS_NOTEBOOK (src)); + g_return_if_fail (XED_IS_NOTEBOOK (dest)); + g_return_if_fail (src != dest); + g_return_if_fail (XED_IS_TAB (tab)); - /* make sure the tab isn't destroyed while we move it */ - g_object_ref (tab); - xed_notebook_remove_tab (src, tab); - xed_notebook_add_tab (dest, tab, dest_position, TRUE); - g_object_unref (tab); + /* make sure the tab isn't destroyed while we move it */ + g_object_ref (tab); + xed_notebook_remove_tab (src, tab); + xed_notebook_add_tab (dest, tab, dest_position, TRUE); + g_object_unref (tab); } /** @@ -367,75 +364,71 @@ xed_notebook_move_tab (XedNotebook *src, */ void xed_notebook_reorder_tab (XedNotebook *src, - XedTab *tab, - gint dest_position) + XedTab *tab, + gint dest_position) { - gint old_position; + gint old_position; - g_return_if_fail (XED_IS_NOTEBOOK (src)); - g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail (XED_IS_NOTEBOOK (src)); + g_return_if_fail (XED_IS_TAB (tab)); - old_position = gtk_notebook_page_num (GTK_NOTEBOOK (src), - GTK_WIDGET (tab)); + old_position = gtk_notebook_page_num (GTK_NOTEBOOK (src), GTK_WIDGET (tab)); - if (old_position == dest_position) - return; + if (old_position == dest_position) + { + return; + } - gtk_notebook_reorder_child (GTK_NOTEBOOK (src), - GTK_WIDGET (tab), - dest_position); + gtk_notebook_reorder_child (GTK_NOTEBOOK (src), GTK_WIDGET (tab), dest_position); - if (!src->priv->drag_in_progress) - { - g_signal_emit (G_OBJECT (src), - signals[TABS_REORDERED], - 0); - } + if (!src->priv->drag_in_progress) + { + g_signal_emit (G_OBJECT (src), signals[TABS_REORDERED], 0); + } } static void drag_start (XedNotebook *notebook, - guint32 time) + guint32 time) { - notebook->priv->drag_in_progress = TRUE; + notebook->priv->drag_in_progress = TRUE; - /* get a new cursor, if necessary */ - /* FIXME multi-head */ - if (cursor == NULL) - cursor = gdk_cursor_new (GDK_FLEUR); + /* get a new cursor, if necessary */ + /* FIXME multi-head */ + if (cursor == NULL) + { + cursor = gdk_cursor_new (GDK_FLEUR); + } - /* grab the pointer */ - gtk_grab_add (GTK_WIDGET (notebook)); + /* grab the pointer */ + gtk_grab_add (GTK_WIDGET (notebook)); - /* FIXME multi-head */ - if (!gdk_pointer_is_grabbed ()) - { - gdk_pointer_grab (gtk_widget_get_window (GTK_WIDGET (notebook)), - FALSE, - GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, - NULL, - cursor, - time); - } + /* FIXME multi-head */ + if (!gdk_pointer_is_grabbed ()) + { + gdk_pointer_grab (gtk_widget_get_window (GTK_WIDGET (notebook)), + FALSE, + GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, + NULL, + cursor, + time); + } } static void drag_stop (XedNotebook *notebook) { - if (notebook->priv->drag_in_progress) - { - g_signal_emit (G_OBJECT (notebook), - signals[TABS_REORDERED], - 0); - } + if (notebook->priv->drag_in_progress) + { + g_signal_emit (G_OBJECT (notebook), signals[TABS_REORDERED], 0); + } - notebook->priv->drag_in_progress = FALSE; - if (notebook->priv->motion_notify_handler_id != 0) - { - g_signal_handler_disconnect (G_OBJECT (notebook), - notebook->priv->motion_notify_handler_id); - notebook->priv->motion_notify_handler_id = 0; - } + notebook->priv->drag_in_progress = FALSE; + if (notebook->priv->motion_notify_handler_id != 0) + { + g_signal_handler_disconnect (G_OBJECT (notebook), notebook->priv->motion_notify_handler_id); + notebook->priv->motion_notify_handler_id = 0; + } } /* This function is only called during dnd, we don't need to emit TABS_REORDERED @@ -443,205 +436,182 @@ drag_stop (XedNotebook *notebook) */ static void move_current_tab (XedNotebook *notebook, - gint dest_position) + gint dest_position) { - gint cur_page_num; + gint cur_page_num; - cur_page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)); + cur_page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)); - if (dest_position != cur_page_num) - { - GtkWidget *cur_tab; + if (dest_position != cur_page_num) + { + GtkWidget *cur_tab; - cur_tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), - cur_page_num); - - xed_notebook_reorder_tab (XED_NOTEBOOK (notebook), - XED_TAB (cur_tab), - dest_position); - } + cur_tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), cur_page_num); + xed_notebook_reorder_tab (XED_NOTEBOOK (notebook), XED_TAB (cur_tab), dest_position); + } } static gboolean -motion_notify_cb (XedNotebook *notebook, - GdkEventMotion *event, - gpointer data) +motion_notify_cb (XedNotebook *notebook, + GdkEventMotion *event, + gpointer data) { - XedNotebook *dest; - gint page_num; - gint result; + XedNotebook *dest; + gint page_num; + gint result; - if (notebook->priv->drag_in_progress == FALSE) - { - if (notebook->priv->tab_drag_and_drop_enabled == FALSE) - return FALSE; + if (notebook->priv->drag_in_progress == FALSE) + { + if (notebook->priv->tab_drag_and_drop_enabled == FALSE) + { + return FALSE; + } - if (gtk_drag_check_threshold (GTK_WIDGET (notebook), - notebook->priv->x_start, - notebook->priv->y_start, - event->x_root, - event->y_root)) - { - drag_start (notebook, event->time); - return TRUE; - } + if (gtk_drag_check_threshold (GTK_WIDGET (notebook), + notebook->priv->x_start, + notebook->priv->y_start, + event->x_root, + event->y_root)) + { + drag_start (notebook, event->time); + return TRUE; + } - return FALSE; - } + return FALSE; + } - result = find_notebook_and_tab_at_pos ((gint)event->x_root, - (gint)event->y_root, - &dest, - &page_num); + result = find_notebook_and_tab_at_pos ((gint)event->x_root, (gint)event->y_root, &dest, &page_num); - if (result != NOT_IN_APP_WINDOWS) - { - if (dest != notebook) - { - move_current_tab_to_another_notebook (notebook, - dest, - event, - page_num); - } - else - { - g_return_val_if_fail (page_num >= -1, FALSE); - move_current_tab (notebook, page_num); - } - } + if (result != NOT_IN_APP_WINDOWS) + { + if (dest != notebook) + { + move_current_tab_to_another_notebook (notebook, dest, event, page_num); + } + else + { + g_return_val_if_fail (page_num >= -1, FALSE); + move_current_tab (notebook, page_num); + } + } - return FALSE; + return FALSE; } static void -move_current_tab_to_another_notebook (XedNotebook *src, - XedNotebook *dest, - GdkEventMotion *event, - gint dest_position) +move_current_tab_to_another_notebook (XedNotebook *src, + XedNotebook *dest, + GdkEventMotion *event, + gint dest_position) { - XedTab *tab; - gint cur_page; + XedTab *tab; + gint cur_page; - /* This is getting tricky, the tab was dragged in a notebook - * in another window of the same app, we move the tab - * to that new notebook, and let this notebook handle the - * drag - */ - g_return_if_fail (XED_IS_NOTEBOOK (dest)); - g_return_if_fail (dest != src); + /* This is getting tricky, the tab was dragged in a notebook + * in another window of the same app, we move the tab + * to that new notebook, and let this notebook handle the + * drag + */ + g_return_if_fail (XED_IS_NOTEBOOK (dest)); + g_return_if_fail (dest != src); - cur_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (src)); - tab = XED_TAB (gtk_notebook_get_nth_page (GTK_NOTEBOOK (src), - cur_page)); + cur_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (src)); + tab = XED_TAB (gtk_notebook_get_nth_page (GTK_NOTEBOOK (src), cur_page)); - /* stop drag in origin window */ - /* ungrab the pointer if it's grabbed */ - drag_stop (src); - if (gdk_pointer_is_grabbed ()) - { - gdk_pointer_ungrab (event->time); - } - gtk_grab_remove (GTK_WIDGET (src)); + /* stop drag in origin window */ + /* ungrab the pointer if it's grabbed */ + drag_stop (src); + if (gdk_pointer_is_grabbed ()) + { + gdk_pointer_ungrab (event->time); + } + gtk_grab_remove (GTK_WIDGET (src)); - xed_notebook_move_tab (src, dest, tab, dest_position); + xed_notebook_move_tab (src, dest, tab, dest_position); - /* start drag handling in dest notebook */ - dest->priv->motion_notify_handler_id = - g_signal_connect (G_OBJECT (dest), - "motion-notify-event", - G_CALLBACK (motion_notify_cb), - NULL); + /* start drag handling in dest notebook */ + dest->priv->motion_notify_handler_id = g_signal_connect (G_OBJECT (dest), "motion-notify-event", + G_CALLBACK (motion_notify_cb), NULL); - drag_start (dest, event->time); + drag_start (dest, event->time); } static gboolean -button_release_cb (XedNotebook *notebook, - GdkEventButton *event, - gpointer data) +button_release_cb (XedNotebook *notebook, + GdkEventButton *event, + gpointer data) { - if (notebook->priv->drag_in_progress) - { - gint cur_page_num; - GtkWidget *cur_page; + if (notebook->priv->drag_in_progress) + { + gint cur_page_num; + GtkWidget *cur_page; - cur_page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)); - cur_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), - cur_page_num); + cur_page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)); + cur_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), cur_page_num); - /* CHECK: I don't follow the code here -- Paolo */ - if (!is_in_notebook_window (notebook, event->x_root, event->y_root) && - (gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) > 1)) - { - /* Tab was detached */ - g_signal_emit (G_OBJECT (notebook), - signals[TAB_DETACHED], - 0, - cur_page); - } + /* CHECK: I don't follow the code here -- Paolo */ + if (!is_in_notebook_window (notebook, event->x_root, event->y_root) && + (gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) > 1)) + { + /* Tab was detached */ + g_signal_emit (G_OBJECT (notebook), signals[TAB_DETACHED], 0, cur_page); + } - /* ungrab the pointer if it's grabbed */ - if (gdk_pointer_is_grabbed ()) - { - gdk_pointer_ungrab (event->time); - } - gtk_grab_remove (GTK_WIDGET (notebook)); - } + /* ungrab the pointer if it's grabbed */ + if (gdk_pointer_is_grabbed ()) + { + gdk_pointer_ungrab (event->time); + } + gtk_grab_remove (GTK_WIDGET (notebook)); + } - /* This must be called even if a drag isn't happening */ - drag_stop (notebook); + /* This must be called even if a drag isn't happening */ + drag_stop (notebook); - return FALSE; + return FALSE; } static gboolean -button_press_cb (XedNotebook *notebook, - GdkEventButton *event, - gpointer data) +button_press_cb (XedNotebook *notebook, + GdkEventButton *event, + gpointer data) { - gint tab_clicked; + gint tab_clicked; - if (notebook->priv->drag_in_progress) - return TRUE; + if (notebook->priv->drag_in_progress) + { + return TRUE; + } - tab_clicked = find_tab_num_at_pos (notebook, - event->x_root, - event->y_root); + tab_clicked = find_tab_num_at_pos (notebook, event->x_root, event->y_root); - if ((event->button == 1) && - (event->type == GDK_BUTTON_PRESS) && - (tab_clicked >= 0)) - { - notebook->priv->x_start = event->x_root; - notebook->priv->y_start = event->y_root; + if ((event->button == 1) && (event->type == GDK_BUTTON_PRESS) && (tab_clicked >= 0)) + { + notebook->priv->x_start = event->x_root; + notebook->priv->y_start = event->y_root; - notebook->priv->motion_notify_handler_id = - g_signal_connect (G_OBJECT (notebook), - "motion-notify-event", - G_CALLBACK (motion_notify_cb), - NULL); - } - else if ((event->type == GDK_BUTTON_PRESS) && - (event->button == 3 || event->button == 2)) - { - if (tab_clicked == -1) - { - // CHECK: do we really need it? + notebook->priv->motion_notify_handler_id = g_signal_connect (G_OBJECT (notebook), "motion-notify-event", + G_CALLBACK (motion_notify_cb), NULL); + } + else if ((event->type == GDK_BUTTON_PRESS) && (event->button == 3 || event->button == 2)) + { + if (tab_clicked == -1) + { + // CHECK: do we really need it? - /* consume event, so that we don't pop up the context menu when - * the mouse if not over a tab label - */ - return TRUE; - } - else - { - /* Switch to the page the mouse is over, but don't consume the event */ - gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), - tab_clicked); - } - } + /* consume event, so that we don't pop up the context menu when + * the mouse if not over a tab label + */ + return TRUE; + } + else + { + /* Switch to the page the mouse is over, but don't consume the event */ + gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), tab_clicked); + } + } - return FALSE; + return FALSE; } static gboolean @@ -690,35 +660,33 @@ notebook_scroll_event_cb (XedNotebook *notebook, GtkWidget * xed_notebook_new (void) { - return GTK_WIDGET (g_object_new (XED_TYPE_NOTEBOOK, NULL)); + return GTK_WIDGET (g_object_new (XED_TYPE_NOTEBOOK, NULL)); } static void -xed_notebook_switch_page_cb (GtkNotebook *notebook, - GtkWidget *page, - guint page_num, - gpointer data) +xed_notebook_switch_page_cb (GtkNotebook *notebook, + GtkWidget *page, + guint page_num, + gpointer data) { - XedNotebook *nb = XED_NOTEBOOK (notebook); - GtkWidget *child; - XedView *view; + XedNotebook *nb = XED_NOTEBOOK (notebook); + GtkWidget *child; + XedView *view; - child = gtk_notebook_get_nth_page (notebook, page_num); + child = gtk_notebook_get_nth_page (notebook, page_num); - /* Remove the old page, we dont want to grow unnecessarily - * the list */ - if (nb->priv->focused_pages) - { - nb->priv->focused_pages = - g_list_remove (nb->priv->focused_pages, child); - } + /* Remove the old page, we dont want to grow unnecessarily + * the list */ + if (nb->priv->focused_pages) + { + nb->priv->focused_pages = g_list_remove (nb->priv->focused_pages, child); + } - nb->priv->focused_pages = g_list_append (nb->priv->focused_pages, - child); + nb->priv->focused_pages = g_list_append (nb->priv->focused_pages, child); - /* give focus to the view */ - view = xed_tab_get_view (XED_TAB (child)); - gtk_widget_grab_focus (GTK_WIDGET (view)); + /* give focus to the view */ + view = xed_tab_get_view (XED_TAB (child)); + gtk_widget_grab_focus (GTK_WIDGET (view)); } /* @@ -727,50 +695,43 @@ xed_notebook_switch_page_cb (GtkNotebook *notebook, */ static void update_tabs_visibility (XedNotebook *nb, - gboolean before_inserting) + gboolean before_inserting) { - gboolean show_tabs; - guint num; + gboolean show_tabs; + guint num; - num = gtk_notebook_get_n_pages (GTK_NOTEBOOK (nb)); + num = gtk_notebook_get_n_pages (GTK_NOTEBOOK (nb)); - if (before_inserting) num++; + if (before_inserting) num++; - show_tabs = (nb->priv->always_show_tabs || num > 1); + show_tabs = (nb->priv->always_show_tabs || num > 1); - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nb), show_tabs); + gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nb), show_tabs); } static void xed_notebook_init (XedNotebook *notebook) { - notebook->priv = XED_NOTEBOOK_GET_PRIVATE (notebook); + notebook->priv = XED_NOTEBOOK_GET_PRIVATE (notebook); - notebook->priv->close_buttons_sensitive = TRUE; - notebook->priv->tab_drag_and_drop_enabled = TRUE; + notebook->priv->close_buttons_sensitive = TRUE; + notebook->priv->tab_drag_and_drop_enabled = TRUE; notebook->priv->tab_scrolling_enabled = TRUE; - gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE); - gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE); - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE); + gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE); + gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE); + gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE); - notebook->priv->always_show_tabs = TRUE; + notebook->priv->always_show_tabs = TRUE; - g_signal_connect (notebook, - "button-press-event", - (GCallback)button_press_cb, - NULL); - g_signal_connect (notebook, - "button-release-event", - (GCallback)button_release_cb, - NULL); - gtk_widget_add_events (GTK_WIDGET (notebook), - GDK_BUTTON1_MOTION_MASK); + g_signal_connect (notebook, "button-press-event", + (GCallback)button_press_cb, NULL); + g_signal_connect (notebook, "button-release-event", + (GCallback)button_release_cb, NULL); + gtk_widget_add_events (GTK_WIDGET (notebook), GDK_BUTTON1_MOTION_MASK); - g_signal_connect_after (G_OBJECT (notebook), - "switch_page", - G_CALLBACK (xed_notebook_switch_page_cb), - NULL); + g_signal_connect_after (G_OBJECT (notebook), "switch_page", + G_CALLBACK (xed_notebook_switch_page_cb), NULL); gtk_widget_add_events (GTK_WIDGET (notebook), GDK_SCROLL_MASK); g_signal_connect (notebook, "scroll-event", @@ -780,11 +741,11 @@ xed_notebook_init (XedNotebook *notebook) static void xed_notebook_finalize (GObject *object) { - XedNotebook *notebook = XED_NOTEBOOK (object); + XedNotebook *notebook = XED_NOTEBOOK (object); - g_list_free (notebook->priv->focused_pages); + g_list_free (notebook->priv->focused_pages); - G_OBJECT_CLASS (xed_notebook_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_notebook_parent_class)->finalize (object); } /* @@ -793,94 +754,90 @@ xed_notebook_finalize (GObject *object) */ static gboolean xed_notebook_change_current_page (GtkNotebook *notebook, - gint offset) + gint offset) { - gboolean wrap_around; - gint current; + gboolean wrap_around; + gint current; - current = gtk_notebook_get_current_page (notebook); + current = gtk_notebook_get_current_page (notebook); - if (current != -1) - { - current = current + offset; + if (current != -1) + { + current = current + offset; - g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)), - "gtk-keynav-wrap-around", &wrap_around, - NULL); + g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)), + "gtk-keynav-wrap-around", &wrap_around, NULL); - if (wrap_around) - { - if (current < 0) - { - current = gtk_notebook_get_n_pages (notebook) - 1; - } - else if (current >= gtk_notebook_get_n_pages (notebook)) - { - current = 0; - } - } + if (wrap_around) + { + if (current < 0) + { + current = gtk_notebook_get_n_pages (notebook) - 1; + } + else if (current >= gtk_notebook_get_n_pages (notebook)) + { + current = 0; + } + } - gtk_notebook_set_current_page (notebook, current); - } - else - { - gtk_widget_error_bell (GTK_WIDGET (notebook)); - } + gtk_notebook_set_current_page (notebook, current); + } + else + { + gtk_widget_error_bell (GTK_WIDGET (notebook)); + } - return TRUE; + return TRUE; } static void -close_button_clicked_cb (XedTabLabel *tab_label, XedNotebook *notebook) +close_button_clicked_cb (XedTabLabel *tab_label, + XedNotebook *notebook) { - XedTab *tab; + XedTab *tab; - tab = xed_tab_label_get_tab (tab_label); - g_signal_emit (notebook, signals[TAB_CLOSE_REQUEST], 0, tab); + tab = xed_tab_label_get_tab (tab_label); + g_signal_emit (notebook, signals[TAB_CLOSE_REQUEST], 0, tab); } static GtkWidget * create_tab_label (XedNotebook *nb, - XedTab *tab) + XedTab *tab) { - GtkWidget *tab_label; + GtkWidget *tab_label; - tab_label = xed_tab_label_new (tab); + tab_label = xed_tab_label_new (tab); - g_signal_connect (tab_label, - "close-clicked", - G_CALLBACK (close_button_clicked_cb), - nb); + g_signal_connect (tab_label, "close-clicked", + G_CALLBACK (close_button_clicked_cb), nb); - g_object_set_data (G_OBJECT (tab), "tab-label", tab_label); + g_object_set_data (G_OBJECT (tab), "tab-label", tab_label); - return tab_label; + return tab_label; } static GtkWidget * get_tab_label (XedTab *tab) { - GtkWidget *tab_label; + GtkWidget *tab_label; - tab_label = GTK_WIDGET (g_object_get_data (G_OBJECT (tab), "tab-label")); - g_return_val_if_fail (tab_label != NULL, NULL); + tab_label = GTK_WIDGET (g_object_get_data (G_OBJECT (tab), "tab-label")); + g_return_val_if_fail (tab_label != NULL, NULL); - return tab_label; + return tab_label; } static void remove_tab_label (XedNotebook *nb, - XedTab *tab) + XedTab *tab) { - GtkWidget *tab_label; + GtkWidget *tab_label; - tab_label = get_tab_label (tab); + tab_label = get_tab_label (tab); - g_signal_handlers_disconnect_by_func (tab_label, - G_CALLBACK (close_button_clicked_cb), - nb); + g_signal_handlers_disconnect_by_func (tab_label, G_CALLBACK (close_button_clicked_cb), nb); - g_object_set_data (G_OBJECT (tab), "tab-label", NULL); + g_object_set_data (G_OBJECT (tab), "tab-label", NULL); } /** @@ -892,13 +849,13 @@ remove_tab_label (XedNotebook *nb, */ void xed_notebook_set_always_show_tabs (XedNotebook *nb, - gboolean show_tabs) + gboolean show_tabs) { - g_return_if_fail (XED_IS_NOTEBOOK (nb)); + g_return_if_fail (XED_IS_NOTEBOOK (nb)); - nb->priv->always_show_tabs = (show_tabs != FALSE); + nb->priv->always_show_tabs = (show_tabs != FALSE); - update_tabs_visibility (nb, FALSE); + update_tabs_visibility (nb, FALSE); } /** @@ -912,91 +869,82 @@ xed_notebook_set_always_show_tabs (XedNotebook *nb, */ void xed_notebook_add_tab (XedNotebook *nb, - XedTab *tab, - gint position, - gboolean jump_to) + XedTab *tab, + gint position, + gboolean jump_to) { - GtkWidget *tab_label; + GtkWidget *tab_label; - g_return_if_fail (XED_IS_NOTEBOOK (nb)); - g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail (XED_IS_NOTEBOOK (nb)); + g_return_if_fail (XED_IS_TAB (tab)); - tab_label = create_tab_label (nb, tab); - gtk_notebook_insert_page (GTK_NOTEBOOK (nb), - GTK_WIDGET (tab), - tab_label, - position); - update_tabs_visibility (nb, TRUE); + tab_label = create_tab_label (nb, tab); + gtk_notebook_insert_page (GTK_NOTEBOOK (nb), GTK_WIDGET (tab), tab_label, position); + update_tabs_visibility (nb, TRUE); - g_signal_emit (G_OBJECT (nb), signals[TAB_ADDED], 0, tab); + g_signal_emit (G_OBJECT (nb), signals[TAB_ADDED], 0, tab); - /* The signal handler may have reordered the tabs */ - position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), - GTK_WIDGET (tab)); + /* The signal handler may have reordered the tabs */ + position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (tab)); - if (jump_to) - { - XedView *view; + if (jump_to) + { + XedView *view; - gtk_notebook_set_current_page (GTK_NOTEBOOK (nb), position); - g_object_set_data (G_OBJECT (tab), - "jump_to", - GINT_TO_POINTER (jump_to)); - view = xed_tab_get_view (tab); + gtk_notebook_set_current_page (GTK_NOTEBOOK (nb), position); + g_object_set_data (G_OBJECT (tab), "jump_to", GINT_TO_POINTER (jump_to)); + view = xed_tab_get_view (tab); - gtk_widget_grab_focus (GTK_WIDGET (view)); - } + gtk_widget_grab_focus (GTK_WIDGET (view)); + } } static void smart_tab_switching_on_closure (XedNotebook *nb, - XedTab *tab) + XedTab *tab) { - gboolean jump_to; + gboolean jump_to; - jump_to = GPOINTER_TO_INT (g_object_get_data - (G_OBJECT (tab), "jump_to")); + jump_to = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tab), "jump_to")); - if (!jump_to || !nb->priv->focused_pages) - { - gtk_notebook_next_page (GTK_NOTEBOOK (nb)); - } - else - { - GList *l; - GtkWidget *child; - int page_num; + if (!jump_to || !nb->priv->focused_pages) + { + gtk_notebook_next_page (GTK_NOTEBOOK (nb)); + } + else + { + GList *l; + GtkWidget *child; + int page_num; - /* activate the last focused tab */ - l = g_list_last (nb->priv->focused_pages); - child = GTK_WIDGET (l->data); - page_num = gtk_notebook_page_num (GTK_NOTEBOOK (nb), - child); - gtk_notebook_set_current_page (GTK_NOTEBOOK (nb), - page_num); - } + /* activate the last focused tab */ + l = g_list_last (nb->priv->focused_pages); + child = GTK_WIDGET (l->data); + page_num = gtk_notebook_page_num (GTK_NOTEBOOK (nb), child); + gtk_notebook_set_current_page (GTK_NOTEBOOK (nb), page_num); + } } static void remove_tab (XedTab *tab, - XedNotebook *nb) + XedNotebook *nb) { - gint position; + gint position; - position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (tab)); + position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (tab)); - /* we ref the tab so that it's still alive while the tabs_removed - * signal is processed. - */ - g_object_ref (tab); + /* we ref the tab so that it's still alive while the tabs_removed + * signal is processed. + */ + g_object_ref (tab); - remove_tab_label (nb, tab); - gtk_notebook_remove_page (GTK_NOTEBOOK (nb), position); - update_tabs_visibility (nb, FALSE); + remove_tab_label (nb, tab); + gtk_notebook_remove_page (GTK_NOTEBOOK (nb), position); + update_tabs_visibility (nb, FALSE); - g_signal_emit (G_OBJECT (nb), signals[TAB_REMOVED], 0, tab); + g_signal_emit (G_OBJECT (nb), signals[TAB_REMOVED], 0, tab); - g_object_unref (tab); + g_object_unref (tab); } /** @@ -1008,26 +956,25 @@ remove_tab (XedTab *tab, */ void xed_notebook_remove_tab (XedNotebook *nb, - XedTab *tab) + XedTab *tab) { - gint position, curr; + gint position, curr; - g_return_if_fail (XED_IS_NOTEBOOK (nb)); - g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail (XED_IS_NOTEBOOK (nb)); + g_return_if_fail (XED_IS_TAB (tab)); - /* Remove the page from the focused pages list */ - nb->priv->focused_pages = g_list_remove (nb->priv->focused_pages, - tab); + /* Remove the page from the focused pages list */ + nb->priv->focused_pages = g_list_remove (nb->priv->focused_pages, tab); - position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (tab)); - curr = gtk_notebook_get_current_page (GTK_NOTEBOOK (nb)); + position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (tab)); + curr = gtk_notebook_get_current_page (GTK_NOTEBOOK (nb)); - if (position == curr) - { - smart_tab_switching_on_closure (nb, tab); - } + if (position == curr) + { + smart_tab_switching_on_closure (nb, tab); + } - remove_tab (tab, nb); + remove_tab (tab, nb); } /** @@ -1039,26 +986,23 @@ xed_notebook_remove_tab (XedNotebook *nb, void xed_notebook_remove_all_tabs (XedNotebook *nb) { - g_return_if_fail (XED_IS_NOTEBOOK (nb)); + g_return_if_fail (XED_IS_NOTEBOOK (nb)); - g_list_free (nb->priv->focused_pages); - nb->priv->focused_pages = NULL; + g_list_free (nb->priv->focused_pages); + nb->priv->focused_pages = NULL; - gtk_container_foreach (GTK_CONTAINER (nb), - (GtkCallback)remove_tab, - nb); + gtk_container_foreach (GTK_CONTAINER (nb), (GtkCallback)remove_tab, nb); } static void set_close_buttons_sensitivity (XedTab *tab, XedNotebook *nb) { - GtkWidget *tab_label; + GtkWidget *tab_label; - tab_label = get_tab_label (tab); + tab_label = get_tab_label (tab); - xed_tab_label_set_close_button_sensitive (XED_TAB_LABEL (tab_label), - nb->priv->close_buttons_sensitive); + xed_tab_label_set_close_button_sensitive (XED_TAB_LABEL (tab_label), nb->priv->close_buttons_sensitive); } /** @@ -1070,20 +1014,20 @@ set_close_buttons_sensitivity (XedTab *tab, */ void xed_notebook_set_close_buttons_sensitive (XedNotebook *nb, - gboolean sensitive) + gboolean sensitive) { - g_return_if_fail (XED_IS_NOTEBOOK (nb)); + g_return_if_fail (XED_IS_NOTEBOOK (nb)); - sensitive = (sensitive != FALSE); + sensitive = (sensitive != FALSE); - if (sensitive == nb->priv->close_buttons_sensitive) - return; + if (sensitive == nb->priv->close_buttons_sensitive) + { + return; + } - nb->priv->close_buttons_sensitive = sensitive; + nb->priv->close_buttons_sensitive = sensitive; - gtk_container_foreach (GTK_CONTAINER (nb), - (GtkCallback)set_close_buttons_sensitivity, - nb); + gtk_container_foreach (GTK_CONTAINER (nb), (GtkCallback)set_close_buttons_sensitivity, nb); } /** @@ -1097,9 +1041,9 @@ xed_notebook_set_close_buttons_sensitive (XedNotebook *nb, gboolean xed_notebook_get_close_buttons_sensitive (XedNotebook *nb) { - g_return_val_if_fail (XED_IS_NOTEBOOK (nb), TRUE); + g_return_val_if_fail (XED_IS_NOTEBOOK (nb), TRUE); - return nb->priv->close_buttons_sensitive; + return nb->priv->close_buttons_sensitive; } /** @@ -1111,16 +1055,18 @@ xed_notebook_get_close_buttons_sensitive (XedNotebook *nb) */ void xed_notebook_set_tab_drag_and_drop_enabled (XedNotebook *nb, - gboolean enable) + gboolean enable) { - g_return_if_fail (XED_IS_NOTEBOOK (nb)); + g_return_if_fail (XED_IS_NOTEBOOK (nb)); - enable = (enable != FALSE); + enable = (enable != FALSE); - if (enable == nb->priv->tab_drag_and_drop_enabled) - return; + if (enable == nb->priv->tab_drag_and_drop_enabled) + { + return; + } - nb->priv->tab_drag_and_drop_enabled = enable; + nb->priv->tab_drag_and_drop_enabled = enable; } /** @@ -1134,9 +1080,9 @@ xed_notebook_set_tab_drag_and_drop_enabled (XedNotebook *nb, gboolean xed_notebook_get_tab_drag_and_drop_enabled (XedNotebook *nb) { - g_return_val_if_fail (XED_IS_NOTEBOOK (nb), TRUE); + g_return_val_if_fail (XED_IS_NOTEBOOK (nb), TRUE); - return nb->priv->tab_drag_and_drop_enabled; + return nb->priv->tab_drag_and_drop_enabled; } /** From 63f465880707106982f964a3b761b2948868f560 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 31 Dec 2016 21:21:06 -0800 Subject: [PATCH 056/132] xed-pref-manager-app.c: Clean up code style --- xed/xed-prefs-manager-app.c | 1614 +++++++++++++++++------------------ 1 file changed, 769 insertions(+), 845 deletions(-) diff --git a/xed/xed-prefs-manager-app.c b/xed/xed-prefs-manager-app.c index f9ff6c8..c9e34bf 100644 --- a/xed/xed-prefs-manager-app.c +++ b/xed/xed-prefs-manager-app.c @@ -49,81 +49,81 @@ #include "xed-style-scheme-manager.h" #include "xed-dirs.h" -static void xed_prefs_manager_editor_font_changed (GSettings *settings, - gchar *key, - gpointer user_data); +static void xed_prefs_manager_editor_font_changed (GSettings *settings, + gchar *key, + gpointer user_data); -static void xed_prefs_manager_system_font_changed (GSettings *settings, - gchar *key, - gpointer user_data); +static void xed_prefs_manager_system_font_changed (GSettings *settings, + gchar *key, + gpointer user_data); -static void xed_prefs_manager_tabs_size_changed (GSettings *settings, - gchar *key, - gpointer user_data); +static void xed_prefs_manager_tabs_size_changed (GSettings *settings, + gchar *key, + gpointer user_data); -static void xed_prefs_manager_wrap_mode_changed (GSettings *settings, - gchar *key, - gpointer user_data); +static void xed_prefs_manager_wrap_mode_changed (GSettings *settings, + gchar *key, + gpointer user_data); -static void xed_prefs_manager_line_numbers_changed (GSettings *settings, - gchar *key, - gpointer user_data); +static void xed_prefs_manager_line_numbers_changed (GSettings *settings, + gchar *key, + gpointer user_data); -static void xed_prefs_manager_auto_indent_changed (GSettings *settings, - gchar *key, - gpointer user_data); +static void xed_prefs_manager_auto_indent_changed (GSettings *settings, + gchar *key, + gpointer user_data); -static void xed_prefs_manager_undo_changed (GSettings *settings, - gchar *key, - gpointer user_data); +static void xed_prefs_manager_undo_changed (GSettings *settings, + gchar *key, + gpointer user_data); -static void xed_prefs_manager_right_margin_changed (GSettings *settings, - gchar *key, - gpointer user_data); +static void xed_prefs_manager_right_margin_changed (GSettings *settings, + gchar *key, + gpointer user_data); -static void xed_prefs_manager_smart_home_end_changed (GSettings *settings, - gchar *key, - gpointer user_data); +static void xed_prefs_manager_smart_home_end_changed (GSettings *settings, + gchar *key, + gpointer user_data); static void xed_prefs_manager_enable_tab_scrolling_changed (GSettings *settings, gchar *key, gpointer user_data); -static void xed_prefs_manager_hl_current_line_changed (GSettings *settings, - gchar *key, - gpointer user_data); +static void xed_prefs_manager_hl_current_line_changed (GSettings *settings, + gchar *key, + gpointer user_data); -static void xed_prefs_manager_bracket_matching_changed(GSettings *settings, - gchar *key, - gpointer user_data); +static void xed_prefs_manager_bracket_matching_changed (GSettings *settings, + gchar *key, + gpointer user_data); -static void xed_prefs_manager_syntax_hl_enable_changed(GSettings *settings, - gchar *key, - gpointer user_data); +static void xed_prefs_manager_syntax_hl_enable_changed (GSettings *settings, + gchar *key, + gpointer user_data); -static void xed_prefs_manager_search_hl_enable_changed(GSettings *settings, - gchar *key, - gpointer user_data); +static void xed_prefs_manager_search_hl_enable_changed (GSettings *settings, + gchar *key, + gpointer user_data); -static void xed_prefs_manager_source_style_scheme_changed(GSettings *settings, - gchar *key, - gpointer user_data); +static void xed_prefs_manager_source_style_scheme_changed (GSettings *settings, + gchar *key, + gpointer user_data); -static void xed_prefs_manager_max_recents_changed (GSettings *settings, - gchar *key, - gpointer user_data); +static void xed_prefs_manager_max_recents_changed (GSettings *settings, + gchar *key, + gpointer user_data); -static void xed_prefs_manager_auto_save_changed (GSettings *settings, - gchar *key, - gpointer user_data); +static void xed_prefs_manager_auto_save_changed (GSettings *settings, + gchar *key, + gpointer user_data); /* GUI state is serialized to a .desktop file, not in GSettings */ -#define XED_STATE_DEFAULT_WINDOW_STATE 0 -#define XED_STATE_DEFAULT_WINDOW_WIDTH 650 -#define XED_STATE_DEFAULT_WINDOW_HEIGHT 500 -#define XED_STATE_DEFAULT_SIDE_PANEL_SIZE 200 -#define XED_STATE_DEFAULT_BOTTOM_PANEL_SIZE 140 +#define XED_STATE_DEFAULT_WINDOW_STATE 0 +#define XED_STATE_DEFAULT_WINDOW_WIDTH 650 +#define XED_STATE_DEFAULT_WINDOW_HEIGHT 500 +#define XED_STATE_DEFAULT_SIDE_PANEL_SIZE 200 +#define XED_STATE_DEFAULT_BOTTOM_PANEL_SIZE 140 #define XED_STATE_FILE_LOCATION "xed.ini" @@ -152,444 +152,419 @@ static gint active_file_filter = -1; static gchar * get_state_filename (void) { - gchar *config_dir; - gchar *filename = NULL; + gchar *config_dir; + gchar *filename = NULL; - config_dir = xed_dirs_get_user_config_dir (); + config_dir = xed_dirs_get_user_config_dir (); - if (config_dir != NULL) - { - filename = g_build_filename (config_dir, - XED_STATE_FILE_LOCATION, - NULL); - g_free (config_dir); - } + if (config_dir != NULL) + { + filename = g_build_filename (config_dir, XED_STATE_FILE_LOCATION, NULL); + g_free (config_dir); + } - return filename; + return filename; } static GKeyFile * get_xed_state_file (void) { - static GKeyFile *state_file = NULL; + static GKeyFile *state_file = NULL; - if (state_file == NULL) - { - gchar *filename; - GError *err = NULL; + if (state_file == NULL) + { + gchar *filename; + GError *err = NULL; - state_file = g_key_file_new (); + state_file = g_key_file_new (); + filename = get_state_filename (); - filename = get_state_filename (); + if (!g_key_file_load_from_file (state_file, filename, G_KEY_FILE_NONE, &err)) + { + if (err->domain != G_FILE_ERROR || err->code != G_FILE_ERROR_NOENT) + { + g_warning ("Could not load xed state file: %s\n", err->message); + } - if (!g_key_file_load_from_file (state_file, - filename, - G_KEY_FILE_NONE, - &err)) - { - if (err->domain != G_FILE_ERROR || - err->code != G_FILE_ERROR_NOENT) - { - g_warning ("Could not load xed state file: %s\n", - err->message); - } + g_error_free (err); + } - g_error_free (err); - } + g_free (filename); + } - g_free (filename); - } - - return state_file; + return state_file; } static void xed_state_get_int (const gchar *group, - const gchar *key, - gint defval, - gint *result) + const gchar *key, + gint defval, + gint *result) { - GKeyFile *state_file; - gint res; - GError *err = NULL; + GKeyFile *state_file; + gint res; + GError *err = NULL; - state_file = get_xed_state_file (); - res = g_key_file_get_integer (state_file, - group, - key, - &err); + state_file = get_xed_state_file (); + res = g_key_file_get_integer (state_file, group, key, &err); - if (err != NULL) - { - if ((err->domain != G_KEY_FILE_ERROR) || - ((err->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND && - err->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND))) - { - g_warning ("Could not get state value %s::%s : %s\n", - group, - key, - err->message); - } + if (err != NULL) + { + if ((err->domain != G_KEY_FILE_ERROR) || + ((err->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND && + err->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND))) + { + g_warning ("Could not get state value %s::%s : %s\n", group, key, err->message); + } - *result = defval; - g_error_free (err); - } - else - { - *result = res; - } + *result = defval; + g_error_free (err); + } + else + { + *result = res; + } } static void xed_state_set_int (const gchar *group, - const gchar *key, - gint value) + const gchar *key, + gint value) { - GKeyFile *state_file; + GKeyFile *state_file; - state_file = get_xed_state_file (); - g_key_file_set_integer (state_file, - group, - key, - value); + state_file = get_xed_state_file (); + g_key_file_set_integer (state_file, group, key, value); } static gboolean xed_state_file_sync (void) { - GKeyFile *state_file; - gchar *config_dir; - gchar *filename = NULL; - gchar *content = NULL; - gsize length; - gint res; - GError *err = NULL; - gboolean ret = FALSE; + GKeyFile *state_file; + gchar *config_dir; + gchar *filename = NULL; + gchar *content = NULL; + gsize length; + gint res; + GError *err = NULL; + gboolean ret = FALSE; - state_file = get_xed_state_file (); - g_return_val_if_fail (state_file != NULL, FALSE); + state_file = get_xed_state_file (); + g_return_val_if_fail (state_file != NULL, FALSE); - config_dir = xed_dirs_get_user_config_dir (); - if (config_dir == NULL) - { - g_warning ("Could not get config directory\n"); - return ret; - } + config_dir = xed_dirs_get_user_config_dir (); + if (config_dir == NULL) + { + g_warning ("Could not get config directory\n"); + return ret; + } - res = g_mkdir_with_parents (config_dir, 0755); - if (res < 0) - { - g_warning ("Could not create config directory\n"); - goto out; - } + res = g_mkdir_with_parents (config_dir, 0755); + if (res < 0) + { + g_warning ("Could not create config directory\n"); + goto out; + } - content = g_key_file_to_data (state_file, - &length, - &err); + content = g_key_file_to_data (state_file, &length, &err); - if (err != NULL) - { - g_warning ("Could not get data from state file: %s\n", - err->message); - goto out; - } + if (err != NULL) + { + g_warning ("Could not get data from state file: %s\n", err->message); + goto out; + } - if (content != NULL) - { - filename = get_state_filename (); - if (!g_file_set_contents (filename, - content, - length, - &err)) - { - g_warning ("Could not write xed state file: %s\n", - err->message); - goto out; - } - } + if (content != NULL) + { + filename = get_state_filename (); + if (!g_file_set_contents (filename, content, length, &err)) + { + g_warning ("Could not write xed state file: %s\n", err->message); + goto out; + } + } - ret = TRUE; + ret = TRUE; out: - if (err != NULL) - g_error_free (err); + if (err != NULL) + { + g_error_free (err); + } - g_free (config_dir); - g_free (filename); - g_free (content); + g_free (config_dir); + g_free (filename); + g_free (content); - return ret; + return ret; } /* Window state */ gint xed_prefs_manager_get_window_state (void) { - if (window_state == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_WINDOW_STATE, - XED_STATE_DEFAULT_WINDOW_STATE, - &window_state); - } + if (window_state == -1) + { + xed_state_get_int (XED_STATE_WINDOW_GROUP, + XED_STATE_WINDOW_STATE, + XED_STATE_DEFAULT_WINDOW_STATE, + &window_state); + } - return window_state; + return window_state; } void xed_prefs_manager_set_window_state (gint ws) { - g_return_if_fail (ws > -1); + g_return_if_fail (ws > -1); - window_state = ws; + window_state = ws; - xed_state_set_int (XED_STATE_WINDOW_GROUP, - XED_STATE_WINDOW_STATE, - ws); + xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_WINDOW_STATE, ws); } gboolean xed_prefs_manager_window_state_can_set (void) { - return TRUE; + return TRUE; } /* Window size */ void -xed_prefs_manager_get_window_size (gint *width, gint *height) +xed_prefs_manager_get_window_size (gint *width, + gint *height) { - g_return_if_fail (width != NULL && height != NULL); + g_return_if_fail (width != NULL && height != NULL); - if (window_width == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_WINDOW_WIDTH, - XED_STATE_DEFAULT_WINDOW_WIDTH, - &window_width); - } + if (window_width == -1) + { + xed_state_get_int (XED_STATE_WINDOW_GROUP, + XED_STATE_WINDOW_WIDTH, + XED_STATE_DEFAULT_WINDOW_WIDTH, + &window_width); + } - if (window_height == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_WINDOW_HEIGHT, - XED_STATE_DEFAULT_WINDOW_HEIGHT, - &window_height); - } + if (window_height == -1) + { + xed_state_get_int (XED_STATE_WINDOW_GROUP, + XED_STATE_WINDOW_HEIGHT, + XED_STATE_DEFAULT_WINDOW_HEIGHT, + &window_height); + } - *width = window_width; - *height = window_height; + *width = window_width; + *height = window_height; } void -xed_prefs_manager_get_default_window_size (gint *width, gint *height) +xed_prefs_manager_get_default_window_size (gint *width, + gint *height) { - g_return_if_fail (width != NULL && height != NULL); + g_return_if_fail (width != NULL && height != NULL); - *width = XED_STATE_DEFAULT_WINDOW_WIDTH; - *height = XED_STATE_DEFAULT_WINDOW_HEIGHT; + *width = XED_STATE_DEFAULT_WINDOW_WIDTH; + *height = XED_STATE_DEFAULT_WINDOW_HEIGHT; } void -xed_prefs_manager_set_window_size (gint width, gint height) +xed_prefs_manager_set_window_size (gint width, + gint height) { - g_return_if_fail (width > -1 && height > -1); + g_return_if_fail (width > -1 && height > -1); - window_width = width; - window_height = height; + window_width = width; + window_height = height; - xed_state_set_int (XED_STATE_WINDOW_GROUP, - XED_STATE_WINDOW_WIDTH, - width); - xed_state_set_int (XED_STATE_WINDOW_GROUP, - XED_STATE_WINDOW_HEIGHT, - height); + xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_WINDOW_WIDTH, width); + xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_WINDOW_HEIGHT, height); } gboolean xed_prefs_manager_window_size_can_set (void) { - return TRUE; + return TRUE; } /* Side panel */ gint xed_prefs_manager_get_side_panel_size (void) { - if (side_panel_size == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_SIDE_PANEL_SIZE, - XED_STATE_DEFAULT_SIDE_PANEL_SIZE, - &side_panel_size); - } + if (side_panel_size == -1) + { + xed_state_get_int (XED_STATE_WINDOW_GROUP, + XED_STATE_SIDE_PANEL_SIZE, + XED_STATE_DEFAULT_SIDE_PANEL_SIZE, + &side_panel_size); + } - return side_panel_size; + return side_panel_size; } gint xed_prefs_manager_get_default_side_panel_size (void) { - return XED_STATE_DEFAULT_SIDE_PANEL_SIZE; + return XED_STATE_DEFAULT_SIDE_PANEL_SIZE; } void xed_prefs_manager_set_side_panel_size (gint ps) { - g_return_if_fail (ps > -1); + g_return_if_fail (ps > -1); - if (side_panel_size == ps) - return; + if (side_panel_size == ps) + { + return; + } - side_panel_size = ps; - xed_state_set_int (XED_STATE_WINDOW_GROUP, - XED_STATE_SIDE_PANEL_SIZE, - ps); + side_panel_size = ps; + xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_SIDE_PANEL_SIZE, ps); } gboolean xed_prefs_manager_side_panel_size_can_set (void) { - return TRUE; + return TRUE; } gint xed_prefs_manager_get_side_panel_active_page (void) { - if (side_panel_active_page == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_SIDE_PANEL_ACTIVE_PAGE, - 0, - &side_panel_active_page); - } + if (side_panel_active_page == -1) + { + xed_state_get_int (XED_STATE_WINDOW_GROUP, + XED_STATE_SIDE_PANEL_ACTIVE_PAGE, + 0, + &side_panel_active_page); + } - return side_panel_active_page; + return side_panel_active_page; } void xed_prefs_manager_set_side_panel_active_page (gint id) { - if (side_panel_active_page == id) - return; + if (side_panel_active_page == id) + { + return; + } - side_panel_active_page = id; - xed_state_set_int (XED_STATE_WINDOW_GROUP, - XED_STATE_SIDE_PANEL_ACTIVE_PAGE, - id); + side_panel_active_page = id; + xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_SIDE_PANEL_ACTIVE_PAGE, id); } gboolean xed_prefs_manager_side_panel_active_page_can_set (void) { - return TRUE; + return TRUE; } /* Bottom panel */ gint xed_prefs_manager_get_bottom_panel_size (void) { - if (bottom_panel_size == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_BOTTOM_PANEL_SIZE, - XED_STATE_DEFAULT_BOTTOM_PANEL_SIZE, - &bottom_panel_size); - } + if (bottom_panel_size == -1) + { + xed_state_get_int (XED_STATE_WINDOW_GROUP, + XED_STATE_BOTTOM_PANEL_SIZE, + XED_STATE_DEFAULT_BOTTOM_PANEL_SIZE, + &bottom_panel_size); + } - return bottom_panel_size; + return bottom_panel_size; } gint xed_prefs_manager_get_default_bottom_panel_size (void) { - return XED_STATE_DEFAULT_BOTTOM_PANEL_SIZE; + return XED_STATE_DEFAULT_BOTTOM_PANEL_SIZE; } void xed_prefs_manager_set_bottom_panel_size (gint ps) { - g_return_if_fail (ps > -1); + g_return_if_fail (ps > -1); - if (bottom_panel_size == ps) - return; + if (bottom_panel_size == ps) + { + return; + } - bottom_panel_size = ps; - xed_state_set_int (XED_STATE_WINDOW_GROUP, - XED_STATE_BOTTOM_PANEL_SIZE, - ps); + bottom_panel_size = ps; + xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_BOTTOM_PANEL_SIZE, ps); } gboolean xed_prefs_manager_bottom_panel_size_can_set (void) { - return TRUE; + return TRUE; } gint xed_prefs_manager_get_bottom_panel_active_page (void) { - if (bottom_panel_active_page == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_BOTTOM_PANEL_ACTIVE_PAGE, - 0, - &bottom_panel_active_page); - } + if (bottom_panel_active_page == -1) + { + xed_state_get_int (XED_STATE_WINDOW_GROUP, + XED_STATE_BOTTOM_PANEL_ACTIVE_PAGE, + 0, + &bottom_panel_active_page); + } - return bottom_panel_active_page; + return bottom_panel_active_page; } void xed_prefs_manager_set_bottom_panel_active_page (gint id) { - if (bottom_panel_active_page == id) - return; + if (bottom_panel_active_page == id) + { + return; + } - bottom_panel_active_page = id; - xed_state_set_int (XED_STATE_WINDOW_GROUP, - XED_STATE_BOTTOM_PANEL_ACTIVE_PAGE, - id); + bottom_panel_active_page = id; + xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_BOTTOM_PANEL_ACTIVE_PAGE, id); } gboolean xed_prefs_manager_bottom_panel_active_page_can_set (void) { - return TRUE; + return TRUE; } /* File filter */ gint xed_prefs_manager_get_active_file_filter (void) { - if (active_file_filter == -1) - { - xed_state_get_int (XED_STATE_FILEFILTER_GROUP, - XED_STATE_FILEFILTER_ID, - 0, - &active_file_filter); - } + if (active_file_filter == -1) + { + xed_state_get_int (XED_STATE_FILEFILTER_GROUP, + XED_STATE_FILEFILTER_ID, + 0, + &active_file_filter); + } - return active_file_filter; + return active_file_filter; } void xed_prefs_manager_set_active_file_filter (gint id) { - g_return_if_fail (id >= 0); + g_return_if_fail (id >= 0); - if (active_file_filter == id) - return; + if (active_file_filter == id) + { + return; + } - active_file_filter = id; - xed_state_set_int (XED_STATE_FILEFILTER_GROUP, - XED_STATE_FILEFILTER_ID, - id); + active_file_filter = id; + xed_state_set_int (XED_STATE_FILEFILTER_GROUP, XED_STATE_FILEFILTER_ID, id); } gboolean xed_prefs_manager_active_file_filter_can_set (void) { - return TRUE; + return TRUE; } /* Normal prefs are stored in GSettings */ @@ -597,583 +572,540 @@ xed_prefs_manager_active_file_filter_can_set (void) gboolean xed_prefs_manager_app_init (void) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - g_return_val_if_fail (xed_prefs_manager == NULL, FALSE); + g_return_val_if_fail (xed_prefs_manager == NULL, FALSE); - xed_prefs_manager_init (); + xed_prefs_manager_init (); - if (xed_prefs_manager != NULL) - { - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_USE_DEFAULT_FONT, - G_CALLBACK (xed_prefs_manager_editor_font_changed), - NULL); + if (xed_prefs_manager != NULL) + { + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_USE_DEFAULT_FONT, + G_CALLBACK (xed_prefs_manager_editor_font_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_EDITOR_FONT, - G_CALLBACK (xed_prefs_manager_editor_font_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_EDITOR_FONT, + G_CALLBACK (xed_prefs_manager_editor_font_changed), NULL); - g_signal_connect (xed_prefs_manager->interface_settings, - "changed::" GPM_SYSTEM_FONT, - G_CALLBACK (xed_prefs_manager_system_font_changed), - NULL); + g_signal_connect (xed_prefs_manager->interface_settings, "changed::" GPM_SYSTEM_FONT, + G_CALLBACK (xed_prefs_manager_system_font_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_TABS_SIZE, - G_CALLBACK (xed_prefs_manager_tabs_size_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_TABS_SIZE, + G_CALLBACK (xed_prefs_manager_tabs_size_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_INSERT_SPACES, - G_CALLBACK (xed_prefs_manager_tabs_size_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_INSERT_SPACES, + G_CALLBACK (xed_prefs_manager_tabs_size_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_WRAP_MODE, - G_CALLBACK (xed_prefs_manager_wrap_mode_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_WRAP_MODE, + G_CALLBACK (xed_prefs_manager_wrap_mode_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_DISPLAY_LINE_NUMBERS, - G_CALLBACK (xed_prefs_manager_line_numbers_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_DISPLAY_LINE_NUMBERS, + G_CALLBACK (xed_prefs_manager_line_numbers_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_AUTO_INDENT, - G_CALLBACK (xed_prefs_manager_auto_indent_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_AUTO_INDENT, + G_CALLBACK (xed_prefs_manager_auto_indent_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_UNDO_ACTIONS_LIMIT, - G_CALLBACK (xed_prefs_manager_undo_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_UNDO_ACTIONS_LIMIT, + G_CALLBACK (xed_prefs_manager_undo_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_DISPLAY_RIGHT_MARGIN, - G_CALLBACK (xed_prefs_manager_right_margin_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_DISPLAY_RIGHT_MARGIN, + G_CALLBACK (xed_prefs_manager_right_margin_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_RIGHT_MARGIN_POSITION, - G_CALLBACK (xed_prefs_manager_right_margin_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_RIGHT_MARGIN_POSITION, + G_CALLBACK (xed_prefs_manager_right_margin_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_SMART_HOME_END, - G_CALLBACK (xed_prefs_manager_smart_home_end_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_SMART_HOME_END, + G_CALLBACK (xed_prefs_manager_smart_home_end_changed), NULL); g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_ENABLE_TAB_SCROLLING, G_CALLBACK (xed_prefs_manager_enable_tab_scrolling_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_HIGHLIGHT_CURRENT_LINE, - G_CALLBACK (xed_prefs_manager_hl_current_line_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_HIGHLIGHT_CURRENT_LINE, + G_CALLBACK (xed_prefs_manager_hl_current_line_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_BRACKET_MATCHING, - G_CALLBACK (xed_prefs_manager_bracket_matching_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_BRACKET_MATCHING, + G_CALLBACK (xed_prefs_manager_bracket_matching_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_SYNTAX_HL_ENABLE, - G_CALLBACK (xed_prefs_manager_syntax_hl_enable_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_SYNTAX_HL_ENABLE, + G_CALLBACK (xed_prefs_manager_syntax_hl_enable_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_SEARCH_HIGHLIGHTING_ENABLE, - G_CALLBACK (xed_prefs_manager_search_hl_enable_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_SEARCH_HIGHLIGHTING_ENABLE, + G_CALLBACK (xed_prefs_manager_search_hl_enable_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_SOURCE_STYLE_SCHEME, - G_CALLBACK (xed_prefs_manager_source_style_scheme_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_SOURCE_STYLE_SCHEME, + G_CALLBACK (xed_prefs_manager_source_style_scheme_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_MAX_RECENTS, - G_CALLBACK (xed_prefs_manager_max_recents_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_MAX_RECENTS, + G_CALLBACK (xed_prefs_manager_max_recents_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_CREATE_BACKUP_COPY, - G_CALLBACK (xed_prefs_manager_auto_save_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_CREATE_BACKUP_COPY, + G_CALLBACK (xed_prefs_manager_auto_save_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_AUTO_SAVE_INTERVAL, - G_CALLBACK (xed_prefs_manager_auto_save_changed), - NULL); + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_AUTO_SAVE_INTERVAL, + G_CALLBACK (xed_prefs_manager_auto_save_changed), NULL); - g_signal_connect (xed_prefs_manager->settings, - "changed::" GPM_WRITABLE_VFS_SCHEMES, - G_CALLBACK (xed_prefs_manager_auto_save_changed), - NULL); - } + g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_WRITABLE_VFS_SCHEMES, + G_CALLBACK (xed_prefs_manager_auto_save_changed), NULL); + } - return xed_prefs_manager != NULL; + return xed_prefs_manager != NULL; } /* This function must be called before exiting xed */ void xed_prefs_manager_app_shutdown (void) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - xed_prefs_manager_shutdown (); + xed_prefs_manager_shutdown (); - xed_state_file_sync (); + xed_state_file_sync (); } static void xed_prefs_manager_editor_font_changed (GSettings *settings, - gchar *key, - gpointer user_data) + gchar *key, + gpointer user_data) { - GList *views; - GList *l; - gchar *font = NULL; - gboolean def = TRUE; - gint ts; + GList *views; + GList *l; + gchar *font = NULL; + gboolean def = TRUE; + gint ts; - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - if (strcmp (key, GPM_USE_DEFAULT_FONT) == 0) - { - def = g_settings_get_boolean (settings, key); + if (strcmp (key, GPM_USE_DEFAULT_FONT) == 0) + { + def = g_settings_get_boolean (settings, key); - if (def) - font = xed_prefs_manager_get_system_font (); - else - font = xed_prefs_manager_get_editor_font (); - } - else if (strcmp (key, GPM_EDITOR_FONT) == 0) - { - font = g_settings_get_string (settings, key); + if (def) + { + font = xed_prefs_manager_get_system_font (); + } + else + { + font = xed_prefs_manager_get_editor_font (); + } + } + else if (strcmp (key, GPM_EDITOR_FONT) == 0) + { + font = g_settings_get_string (settings, key); + def = xed_prefs_manager_get_use_default_font (); + } + else + { + return; + } - def = xed_prefs_manager_get_use_default_font (); - } - else - return; + g_return_if_fail (font != NULL); - g_return_if_fail (font != NULL); + ts = xed_prefs_manager_get_tabs_size (); - ts = xed_prefs_manager_get_tabs_size (); + views = xed_app_get_views (xed_app_get_default ()); + l = views; - views = xed_app_get_views (xed_app_get_default ()); - l = views; + while (l != NULL) + { + /* Note: we use def=FALSE to avoid XedView to query GSettings */ + xed_view_set_font (XED_VIEW (l->data), FALSE, font); + gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); - while (l != NULL) - { - /* Note: we use def=FALSE to avoid XedView to query GSettings */ - xed_view_set_font (XED_VIEW (l->data), FALSE, font); - gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); + l = l->next; + } - l = l->next; - } - - g_list_free (views); - g_free (font); + g_list_free (views); + g_free (font); } static void xed_prefs_manager_system_font_changed (GSettings *settings, - gchar *key, - gpointer user_data) + gchar *key, + gpointer user_data) { - GList *views; - GList *l; - gchar *font; - gint ts; + GList *views; + GList *l; + gchar *font; + gint ts; - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - if (strcmp (key, GPM_SYSTEM_FONT) != 0) - return; + if (strcmp (key, GPM_SYSTEM_FONT) != 0) + { + return; + } - if (!xed_prefs_manager_get_use_default_font ()) - return; + if (!xed_prefs_manager_get_use_default_font ()) + { + return; + } - font = g_settings_get_string (settings, key); + font = g_settings_get_string (settings, key); - ts = xed_prefs_manager_get_tabs_size (); + ts = xed_prefs_manager_get_tabs_size (); - views = xed_app_get_views (xed_app_get_default ()); - l = views; + views = xed_app_get_views (xed_app_get_default ()); + l = views; - while (l != NULL) - { - /* Note: we use def=FALSE to avoid XedView to query GSettings */ - xed_view_set_font (XED_VIEW (l->data), FALSE, font); + while (l != NULL) + { + /* Note: we use def=FALSE to avoid XedView to query GSettings */ + xed_view_set_font (XED_VIEW (l->data), FALSE, font); - gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); - l = l->next; - } + gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); + l = l->next; + } - g_list_free (views); - g_free (font); + g_list_free (views); + g_free (font); } static void xed_prefs_manager_tabs_size_changed (GSettings *settings, - gchar *key, - gpointer user_data) + gchar *key, + gpointer user_data) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - if (strcmp (key, GPM_TABS_SIZE) == 0) - { - gint tab_width; - GList *views; - GList *l; + if (strcmp (key, GPM_TABS_SIZE) == 0) + { + gint tab_width; + GList *views; + GList *l; - tab_width = g_settings_get_int (settings, key); + tab_width = g_settings_get_int (settings, key); + tab_width = CLAMP (tab_width, 1, 24); - tab_width = CLAMP (tab_width, 1, 24); + views = xed_app_get_views (xed_app_get_default ()); + l = views; - views = xed_app_get_views (xed_app_get_default ()); - l = views; + while (l != NULL) + { + gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), tab_width); + l = l->next; + } - while (l != NULL) - { - gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), - tab_width); + g_list_free (views); + } + else if (strcmp (key, GPM_INSERT_SPACES) == 0) + { + gboolean enable; + GList *views; + GList *l; - l = l->next; - } + enable = g_settings_get_boolean (settings, key); - g_list_free (views); - } - else if (strcmp (key, GPM_INSERT_SPACES) == 0) - { - gboolean enable; - GList *views; - GList *l; + views = xed_app_get_views (xed_app_get_default ()); + l = views; - enable = g_settings_get_boolean (settings, key); + while (l != NULL) + { + gtk_source_view_set_insert_spaces_instead_of_tabs (GTK_SOURCE_VIEW (l->data), enable); + l = l->next; + } - views = xed_app_get_views (xed_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_insert_spaces_instead_of_tabs ( - GTK_SOURCE_VIEW (l->data), - enable); - - l = l->next; - } - - g_list_free (views); - } + g_list_free (views); + } } static GtkWrapMode get_wrap_mode_from_string (const gchar* str) { - GtkWrapMode res; + GtkWrapMode res; - g_return_val_if_fail (str != NULL, GTK_WRAP_WORD); + g_return_val_if_fail (str != NULL, GTK_WRAP_WORD); - if (strcmp (str, "GTK_WRAP_NONE") == 0) - res = GTK_WRAP_NONE; - else - { - if (strcmp (str, "GTK_WRAP_CHAR") == 0) - res = GTK_WRAP_CHAR; - else - res = GTK_WRAP_WORD; - } + if (strcmp (str, "GTK_WRAP_NONE") == 0) + { + res = GTK_WRAP_NONE; + } + else + { + if (strcmp (str, "GTK_WRAP_CHAR") == 0) + { + res = GTK_WRAP_CHAR; + } + else + { + res = GTK_WRAP_WORD; + } + } - return res; + return res; } static void xed_prefs_manager_wrap_mode_changed (GSettings *settings, - gchar *key, - gpointer user_data) + gchar *key, + gpointer user_data) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - if (strcmp (key, GPM_WRAP_MODE) == 0) - { - GtkWrapMode wrap_mode; - GList *views; - GList *l; + if (strcmp (key, GPM_WRAP_MODE) == 0) + { + GtkWrapMode wrap_mode; + GList *views; + GList *l; - wrap_mode = get_wrap_mode_from_string (g_settings_get_string(settings, key)); + wrap_mode = get_wrap_mode_from_string (g_settings_get_string(settings, key)); - views = xed_app_get_views (xed_app_get_default ()); - l = views; + views = xed_app_get_views (xed_app_get_default ()); + l = views; - while (l != NULL) - { - gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (l->data), - wrap_mode); + while (l != NULL) + { + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (l->data), wrap_mode); + l = l->next; + } - l = l->next; - } - - g_list_free (views); - } + g_list_free (views); + } } static void xed_prefs_manager_line_numbers_changed (GSettings *settings, - gchar *key, - gpointer user_data) + gchar *key, + gpointer user_data) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - if (strcmp (key, GPM_DISPLAY_LINE_NUMBERS) == 0) - { - gboolean dln; - GList *views; - GList *l; + if (strcmp (key, GPM_DISPLAY_LINE_NUMBERS) == 0) + { + gboolean dln; + GList *views; + GList *l; - dln = g_settings_get_boolean (settings, key); + dln = g_settings_get_boolean (settings, key); - views = xed_app_get_views (xed_app_get_default ()); - l = views; + views = xed_app_get_views (xed_app_get_default ()); + l = views; - while (l != NULL) - { - gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (l->data), - dln); + while (l != NULL) + { + gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (l->data), dln); + l = l->next; + } - l = l->next; - } - - g_list_free (views); - } + g_list_free (views); + } } static void xed_prefs_manager_hl_current_line_changed (GSettings *settings, - gchar *key, - gpointer user_data) + gchar *key, + gpointer user_data) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - if (strcmp (key, GPM_HIGHLIGHT_CURRENT_LINE) == 0) - { - gboolean hl; - GList *views; - GList *l; + if (strcmp (key, GPM_HIGHLIGHT_CURRENT_LINE) == 0) + { + gboolean hl; + GList *views; + GList *l; - hl = g_settings_get_boolean (settings, key); + hl = g_settings_get_boolean (settings, key); - views = xed_app_get_views (xed_app_get_default ()); - l = views; + views = xed_app_get_views (xed_app_get_default ()); + l = views; - while (l != NULL) - { - gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (l->data), - hl); + while (l != NULL) + { + gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (l->data), hl); + l = l->next; + } - l = l->next; - } - - g_list_free (views); - } + g_list_free (views); + } } static void xed_prefs_manager_bracket_matching_changed (GSettings *settings, - gchar *key, - gpointer user_data) + gchar *key, + gpointer user_data) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - if (strcmp (key, GPM_BRACKET_MATCHING) == 0) - { - gboolean enable; - GList *docs; - GList *l; + if (strcmp (key, GPM_BRACKET_MATCHING) == 0) + { + gboolean enable; + GList *docs; + GList *l; - enable = g_settings_get_boolean (settings, key); + enable = g_settings_get_boolean (settings, key); - docs = xed_app_get_documents (xed_app_get_default ()); - l = docs; + docs = xed_app_get_documents (xed_app_get_default ()); + l = docs; - while (l != NULL) - { - gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (l->data), - enable); + while (l != NULL) + { + gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (l->data), enable); + l = l->next; + } - l = l->next; - } - - g_list_free (docs); - } + g_list_free (docs); + } } static void xed_prefs_manager_auto_indent_changed (GSettings *settings, - gchar *key, - gpointer user_data) + gchar *key, + gpointer user_data) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - if (strcmp (key, GPM_AUTO_INDENT) == 0) - { - gboolean enable; - GList *views; - GList *l; + if (strcmp (key, GPM_AUTO_INDENT) == 0) + { + gboolean enable; + GList *views; + GList *l; - enable = g_settings_get_boolean (settings, key); + enable = g_settings_get_boolean (settings, key); - views = xed_app_get_views (xed_app_get_default ()); - l = views; + views = xed_app_get_views (xed_app_get_default ()); + l = views; - while (l != NULL) - { - gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (l->data), - enable); + while (l != NULL) + { + gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (l->data), enable); + l = l->next; + } - l = l->next; - } - - g_list_free (views); - } + g_list_free (views); + } } static void xed_prefs_manager_undo_changed (GSettings *settings, - gchar *key, - gpointer user_data) + gchar *key, + gpointer user_data) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - if (strcmp (key, GPM_UNDO_ACTIONS_LIMIT) == 0) - { - gint ul; - GList *docs; - GList *l; + if (strcmp (key, GPM_UNDO_ACTIONS_LIMIT) == 0) + { + gint ul; + GList *docs; + GList *l; - ul = g_settings_get_int (settings, key); + ul = g_settings_get_int (settings, key); - ul = CLAMP (ul, -1, 250); + ul = CLAMP (ul, -1, 250); - docs = xed_app_get_documents (xed_app_get_default ()); - l = docs; + docs = xed_app_get_documents (xed_app_get_default ()); + l = docs; - while (l != NULL) - { - gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (l->data), - ul); + while (l != NULL) + { + gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (l->data), ul); + l = l->next; + } - l = l->next; - } - - g_list_free (docs); - } + g_list_free (docs); + } } static void xed_prefs_manager_right_margin_changed (GSettings *settings, - gchar *key, - gpointer user_data) + gchar *key, + gpointer user_data) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - if (strcmp (key, GPM_RIGHT_MARGIN_POSITION) == 0) - { - gint pos; - GList *views; - GList *l; + if (strcmp (key, GPM_RIGHT_MARGIN_POSITION) == 0) + { + gint pos; + GList *views; + GList *l; - pos = g_settings_get_int (settings, key); + pos = g_settings_get_int (settings, key); - pos = CLAMP (pos, 1, 160); + pos = CLAMP (pos, 1, 160); - views = xed_app_get_views (xed_app_get_default ()); - l = views; + views = xed_app_get_views (xed_app_get_default ()); + l = views; - while (l != NULL) - { - gtk_source_view_set_right_margin_position (GTK_SOURCE_VIEW (l->data), - pos); + while (l != NULL) + { + gtk_source_view_set_right_margin_position (GTK_SOURCE_VIEW (l->data), pos); + l = l->next; + } - l = l->next; - } + g_list_free (views); + } + else if (strcmp (key, GPM_DISPLAY_RIGHT_MARGIN) == 0) + { + gboolean display; + GList *views; + GList *l; - g_list_free (views); - } - else if (strcmp (key, GPM_DISPLAY_RIGHT_MARGIN) == 0) - { - gboolean display; - GList *views; - GList *l; + display = g_settings_get_boolean (settings, key); - display = g_settings_get_boolean (settings, key); + views = xed_app_get_views (xed_app_get_default ()); + l = views; - views = xed_app_get_views (xed_app_get_default ()); - l = views; + while (l != NULL) + { + gtk_source_view_set_show_right_margin (GTK_SOURCE_VIEW (l->data), display); + l = l->next; + } - while (l != NULL) - { - gtk_source_view_set_show_right_margin (GTK_SOURCE_VIEW (l->data), - display); - - l = l->next; - } - - g_list_free (views); - } + g_list_free (views); + } } static GtkSourceSmartHomeEndType get_smart_home_end_from_string (const gchar *str) { - GtkSourceSmartHomeEndType res; + GtkSourceSmartHomeEndType res; - g_return_val_if_fail (str != NULL, GTK_SOURCE_SMART_HOME_END_AFTER); + g_return_val_if_fail (str != NULL, GTK_SOURCE_SMART_HOME_END_AFTER); - if (strcmp (str, "DISABLED") == 0) - res = GTK_SOURCE_SMART_HOME_END_DISABLED; - else if (strcmp (str, "BEFORE") == 0) - res = GTK_SOURCE_SMART_HOME_END_BEFORE; - else if (strcmp (str, "ALWAYS") == 0) - res = GTK_SOURCE_SMART_HOME_END_ALWAYS; - else - res = GTK_SOURCE_SMART_HOME_END_AFTER; + if (strcmp (str, "DISABLED") == 0) + { + res = GTK_SOURCE_SMART_HOME_END_DISABLED; + } + else if (strcmp (str, "BEFORE") == 0) + { + res = GTK_SOURCE_SMART_HOME_END_BEFORE; + } + else if (strcmp (str, "ALWAYS") == 0) + { + res = GTK_SOURCE_SMART_HOME_END_ALWAYS; + } + else + { + res = GTK_SOURCE_SMART_HOME_END_AFTER; + } - return res; + return res; } static void xed_prefs_manager_smart_home_end_changed (GSettings *settings, - gchar *key, - gpointer user_data) + gchar *key, + gpointer user_data) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - if (strcmp (key, GPM_SMART_HOME_END) == 0) - { - GtkSourceSmartHomeEndType smart_he; - GList *views; - GList *l; + if (strcmp (key, GPM_SMART_HOME_END) == 0) + { + GtkSourceSmartHomeEndType smart_he; + GList *views; + GList *l; - smart_he = get_smart_home_end_from_string (g_settings_get_string (settings, key)); + smart_he = get_smart_home_end_from_string (g_settings_get_string (settings, key)); - views = xed_app_get_views (xed_app_get_default ()); - l = views; + views = xed_app_get_views (xed_app_get_default ()); + l = views; - while (l != NULL) - { - gtk_source_view_set_smart_home_end (GTK_SOURCE_VIEW (l->data), - smart_he); + while (l != NULL) + { + gtk_source_view_set_smart_home_end (GTK_SOURCE_VIEW (l->data), smart_he); + l = l->next; + } - l = l->next; - } - - g_list_free (views); - } + g_list_free (views); + } } static void @@ -1205,139 +1137,129 @@ xed_prefs_manager_enable_tab_scrolling_changed (GSettings *settings, static void xed_prefs_manager_syntax_hl_enable_changed (GSettings *settings, - gchar *key, - gpointer user_data) + gchar *key, + gpointer user_data) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - if (strcmp (key, GPM_SYNTAX_HL_ENABLE) == 0) - { - gboolean enable; - GList *docs; - GList *l; - const GList *windows; + if (strcmp (key, GPM_SYNTAX_HL_ENABLE) == 0) + { + gboolean enable; + GList *docs; + GList *l; + const GList *windows; - enable = g_settings_get_boolean (settings, key); + enable = g_settings_get_boolean (settings, key); - docs = xed_app_get_documents (xed_app_get_default ()); - l = docs; + docs = xed_app_get_documents (xed_app_get_default ()); + l = docs; - while (l != NULL) - { - g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); + while (l != NULL) + { + g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); - gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (l->data), - enable); + gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (l->data), enable); + l = l->next; + } - l = l->next; - } + g_list_free (docs); - g_list_free (docs); + /* update the sensitivity of the Higlight Mode menu item */ + windows = xed_app_get_windows (xed_app_get_default ()); + while (windows != NULL) + { + GtkUIManager *ui; + GtkAction *a; - /* update the sensitivity of the Higlight Mode menu item */ - windows = xed_app_get_windows (xed_app_get_default ()); - while (windows != NULL) - { - GtkUIManager *ui; - GtkAction *a; + ui = xed_window_get_ui_manager (XED_WINDOW (windows->data)); + a = gtk_ui_manager_get_action (ui, "/MenuBar/ViewMenu/ViewHighlightModeMenu"); + gtk_action_set_sensitive (a, enable); - ui = xed_window_get_ui_manager (XED_WINDOW (windows->data)); - - a = gtk_ui_manager_get_action (ui, - "/MenuBar/ViewMenu/ViewHighlightModeMenu"); - - gtk_action_set_sensitive (a, enable); - - windows = g_list_next (windows); - } - } + windows = g_list_next (windows); + } + } } static void xed_prefs_manager_search_hl_enable_changed (GSettings *settings, - gchar *key, - gpointer user_data) + gchar *key, + gpointer user_data) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - if (strcmp (key, GPM_SEARCH_HIGHLIGHTING_ENABLE) == 0) - { - gboolean enable; - GList *docs; - GList *l; + if (strcmp (key, GPM_SEARCH_HIGHLIGHTING_ENABLE) == 0) + { + gboolean enable; + GList *docs; + GList *l; - enable = g_settings_get_boolean (settings, key); + enable = g_settings_get_boolean (settings, key); - docs = xed_app_get_documents (xed_app_get_default ()); - l = docs; + docs = xed_app_get_documents (xed_app_get_default ()); + l = docs; - while (l != NULL) - { - g_return_if_fail (XED_IS_DOCUMENT (l->data)); + while (l != NULL) + { + g_return_if_fail (XED_IS_DOCUMENT (l->data)); - xed_document_set_enable_search_highlighting (XED_DOCUMENT (l->data), - enable); + xed_document_set_enable_search_highlighting (XED_DOCUMENT (l->data), enable); + l = l->next; + } - l = l->next; - } - - g_list_free (docs); - } + g_list_free (docs); + } } static void xed_prefs_manager_source_style_scheme_changed (GSettings *settings, - gchar *key, - gpointer user_data) + gchar *key, + gpointer user_data) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - if (strcmp (key, GPM_SOURCE_STYLE_SCHEME) == 0) - { - static gchar *old_scheme = NULL; - gchar *scheme; - GtkSourceStyleScheme *style; - GList *docs; - GList *l; + if (strcmp (key, GPM_SOURCE_STYLE_SCHEME) == 0) + { + static gchar *old_scheme = NULL; + gchar *scheme; + GtkSourceStyleScheme *style; + GList *docs; + GList *l; - scheme = g_settings_get_string (settings, key); + scheme = g_settings_get_string (settings, key); - if (old_scheme != NULL && (strcmp (scheme, old_scheme) == 0)) - return; + if (old_scheme != NULL && (strcmp (scheme, old_scheme) == 0)) + { + return; + } - g_free (old_scheme); - old_scheme = scheme; + g_free (old_scheme); + old_scheme = scheme; - style = gtk_source_style_scheme_manager_get_scheme ( - xed_get_style_scheme_manager (), - scheme); + style = gtk_source_style_scheme_manager_get_scheme (xed_get_style_scheme_manager (), scheme); - if (style == NULL) - { - g_warning ("Default style scheme '%s' not found, falling back to 'classic'", scheme); + if (style == NULL) + { + g_warning ("Default style scheme '%s' not found, falling back to 'classic'", scheme); - style = gtk_source_style_scheme_manager_get_scheme ( - xed_get_style_scheme_manager (), - "classic"); + style = gtk_source_style_scheme_manager_get_scheme (xed_get_style_scheme_manager (), "classic"); - if (style == NULL) - { - g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation."); - return; - } - } + if (style == NULL) + { + g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation."); + return; + } + } - docs = xed_app_get_documents (xed_app_get_default ()); - for (l = docs; l != NULL; l = l->next) - { - g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); + docs = xed_app_get_documents (xed_app_get_default ()); + for (l = docs; l != NULL; l = l->next) + { + g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); - gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (l->data), - style); - } + gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (l->data), style); + } - g_list_free (docs); - } + g_list_free (docs); + } } static void @@ -1345,78 +1267,80 @@ xed_prefs_manager_max_recents_changed (GSettings *settings, gchar *key, gpointer user_data) { - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - if (strcmp (key, GPM_MAX_RECENTS) == 0) - { - const GList *windows; - gint max; + if (strcmp (key, GPM_MAX_RECENTS) == 0) + { + const GList *windows; + gint max; - max = g_settings_get_int (settings, key); + max = g_settings_get_int (settings, key); - if (max < 0) + if (max < 0) { - max = GPM_DEFAULT_MAX_RECENTS; - } + max = GPM_DEFAULT_MAX_RECENTS; + } - /* FIXME: we have no way at the moment to trigger the - * update of the inline recents in the File menu */ - } + /* FIXME: we have no way at the moment to trigger the + * update of the inline recents in the File menu */ + } } static void xed_prefs_manager_auto_save_changed (GSettings *settings, - gchar *key, - gpointer user_data) + gchar *key, + gpointer user_data) { - GList *docs; - GList *l; + GList *docs; + GList *l; - xed_debug (DEBUG_PREFS); + xed_debug (DEBUG_PREFS); - if (strcmp (key, GPM_AUTO_SAVE) == 0) - { - gboolean auto_save; + if (strcmp (key, GPM_AUTO_SAVE) == 0) + { + gboolean auto_save; - auto_save = g_settings_get_boolean (settings, key); + auto_save = g_settings_get_boolean (settings, key); - docs = xed_app_get_documents (xed_app_get_default ()); - l = docs; + docs = xed_app_get_documents (xed_app_get_default ()); + l = docs; - while (l != NULL) - { - XedDocument *doc = XED_DOCUMENT (l->data); - XedTab *tab = xed_tab_get_from_document (doc); + while (l != NULL) + { + XedDocument *doc = XED_DOCUMENT (l->data); + XedTab *tab = xed_tab_get_from_document (doc); - xed_tab_set_auto_save_enabled (tab, auto_save); + xed_tab_set_auto_save_enabled (tab, auto_save); - l = l->next; - } + l = l->next; + } - g_list_free (docs); - } - else if (strcmp (key, GPM_AUTO_SAVE_INTERVAL) == 0) - { - gint auto_save_interval; + g_list_free (docs); + } + else if (strcmp (key, GPM_AUTO_SAVE_INTERVAL) == 0) + { + gint auto_save_interval; - auto_save_interval = g_settings_get_int (settings, key); + auto_save_interval = g_settings_get_int (settings, key); - if (auto_save_interval <= 0) - auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL; + if (auto_save_interval <= 0) + { + auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL; + } - docs = xed_app_get_documents (xed_app_get_default ()); - l = docs; + docs = xed_app_get_documents (xed_app_get_default ()); + l = docs; - while (l != NULL) - { - XedDocument *doc = XED_DOCUMENT (l->data); - XedTab *tab = xed_tab_get_from_document (doc); + while (l != NULL) + { + XedDocument *doc = XED_DOCUMENT (l->data); + XedTab *tab = xed_tab_get_from_document (doc); - xed_tab_set_auto_save_interval (tab, auto_save_interval); + xed_tab_set_auto_save_interval (tab, auto_save_interval); - l = l->next; - } + l = l->next; + } - g_list_free (docs); - } + g_list_free (docs); + } } From 6e7586c6545bbb83cb6af6ac488a8a51576df287 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 31 Dec 2016 21:21:49 -0800 Subject: [PATCH 057/132] xed-prefs-manager-app.c: Clean up an unused variable --- xed/xed-prefs-manager-app.c | 1 - 1 file changed, 1 deletion(-) diff --git a/xed/xed-prefs-manager-app.c b/xed/xed-prefs-manager-app.c index c9e34bf..741b2c1 100644 --- a/xed/xed-prefs-manager-app.c +++ b/xed/xed-prefs-manager-app.c @@ -1271,7 +1271,6 @@ xed_prefs_manager_max_recents_changed (GSettings *settings, if (strcmp (key, GPM_MAX_RECENTS) == 0) { - const GList *windows; gint max; max = g_settings_get_int (settings, key); From d79bc79dbc4af318f8953c54f3783d15894d9642 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 1 Jan 2017 12:03:45 -0800 Subject: [PATCH 058/132] notebooks: Don't show tabs when the notebook only has one page --- xed/xed-notebook.c | 41 ++++++----------------------------------- xed/xed-notebook.h | 5 ----- xed/xed-panel.c | 13 +++++++++++++ 3 files changed, 19 insertions(+), 40 deletions(-) diff --git a/xed/xed-notebook.c b/xed/xed-notebook.c index b51e2ba..0b21bc0 100644 --- a/xed/xed-notebook.c +++ b/xed/xed-notebook.c @@ -61,7 +61,6 @@ struct _XedNotebookPrivate gint x_start; gint y_start; gint drag_in_progress : 1; - gint always_show_tabs : 1; gint close_buttons_sensitive : 1; gint tab_drag_and_drop_enabled : 1; gint tab_scrolling_enabled : 1; @@ -691,22 +690,14 @@ xed_notebook_switch_page_cb (GtkNotebook *notebook, /* * update_tabs_visibility: Hide tabs if there is only one tab - * and the pref is not set. */ static void -update_tabs_visibility (XedNotebook *nb, - gboolean before_inserting) +update_tabs_visibility (XedNotebook *notebook) { gboolean show_tabs; - guint num; - num = gtk_notebook_get_n_pages (GTK_NOTEBOOK (nb)); - - if (before_inserting) num++; - - show_tabs = (nb->priv->always_show_tabs || num > 1); - - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nb), show_tabs); + show_tabs = (gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) > 1); + gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), show_tabs); } static void @@ -719,11 +710,9 @@ xed_notebook_init (XedNotebook *notebook) notebook->priv->tab_scrolling_enabled = TRUE; gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE); - gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE); + // gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE); gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE); - notebook->priv->always_show_tabs = TRUE; - g_signal_connect (notebook, "button-press-event", (GCallback)button_press_cb, NULL); g_signal_connect (notebook, "button-release-event", @@ -840,24 +829,6 @@ remove_tab_label (XedNotebook *nb, g_object_set_data (G_OBJECT (tab), "tab-label", NULL); } -/** - * xed_notebook_set_always_show_tabs: - * @nb: a #XedNotebook - * @show_tabs: %TRUE to always show the tabs - * - * Sets the visibility of the tabs in the @nb. - */ -void -xed_notebook_set_always_show_tabs (XedNotebook *nb, - gboolean show_tabs) -{ - g_return_if_fail (XED_IS_NOTEBOOK (nb)); - - nb->priv->always_show_tabs = (show_tabs != FALSE); - - update_tabs_visibility (nb, FALSE); -} - /** * xed_notebook_add_tab: * @nb: a #XedNotebook @@ -880,7 +851,7 @@ xed_notebook_add_tab (XedNotebook *nb, tab_label = create_tab_label (nb, tab); gtk_notebook_insert_page (GTK_NOTEBOOK (nb), GTK_WIDGET (tab), tab_label, position); - update_tabs_visibility (nb, TRUE); + update_tabs_visibility (nb); g_signal_emit (G_OBJECT (nb), signals[TAB_ADDED], 0, tab); @@ -940,7 +911,7 @@ remove_tab (XedTab *tab, remove_tab_label (nb, tab); gtk_notebook_remove_page (GTK_NOTEBOOK (nb), position); - update_tabs_visibility (nb, FALSE); + update_tabs_visibility (nb); g_signal_emit (G_OBJECT (nb), signals[TAB_REMOVED], 0, tab); diff --git a/xed/xed-notebook.h b/xed/xed-notebook.h index 215b509..8a8c059 100644 --- a/xed/xed-notebook.h +++ b/xed/xed-notebook.h @@ -119,11 +119,6 @@ void xed_notebook_move_tab (XedNotebook *src, XedTab *tab, gint dest_position); -/* FIXME: do we really need this function ? */ -void xed_notebook_set_always_show_tabs - (XedNotebook *nb, - gboolean show_tabs); - void xed_notebook_set_close_buttons_sensitive (XedNotebook *nb, gboolean sensitive); diff --git a/xed/xed-panel.c b/xed/xed-panel.c index fab35d3..a56a22d 100644 --- a/xed/xed-panel.c +++ b/xed/xed-panel.c @@ -403,6 +403,8 @@ build_notebook_for_panel (XedPanel *panel) gtk_notebook_set_scrollable (GTK_NOTEBOOK (panel->priv->notebook), TRUE); gtk_notebook_popup_enable (GTK_NOTEBOOK (panel->priv->notebook)); + gtk_notebook_set_show_tabs (GTK_NOTEBOOK (panel->priv->notebook), FALSE); + gtk_notebook_set_show_border (GTK_NOTEBOOK (panel->priv->notebook), FALSE); gtk_widget_show (GTK_WIDGET (panel->priv->notebook)); } @@ -505,6 +507,15 @@ build_tab_label (XedPanel *panel, return hbox; } +static void +update_tabs_visibility (XedPanel *panel) +{ + gboolean show_tabs; + + show_tabs = (gtk_notebook_get_n_pages (GTK_NOTEBOOK (panel->priv->notebook)) > 1); + gtk_notebook_set_show_tabs (GTK_NOTEBOOK (panel->priv->notebook), show_tabs); +} + /** * xed_panel_add_item: * @panel: a #XedPanel @@ -561,6 +572,7 @@ xed_panel_add_item (XedPanel *panel, } gtk_notebook_append_page_menu (GTK_NOTEBOOK (panel->priv->notebook), item, tab_label, menu_label); + update_tabs_visibility (panel); g_signal_emit (G_OBJECT (panel), signals[ITEM_ADDED], 0, item); } @@ -629,6 +641,7 @@ xed_panel_remove_item (XedPanel *panel, g_object_ref (G_OBJECT (item)); gtk_notebook_remove_page (GTK_NOTEBOOK (panel->priv->notebook), page_num); + update_tabs_visibility (panel); g_signal_emit (G_OBJECT (panel), signals[ITEM_REMOVED], 0, item); From 55317e21b0fa3a1a28f25451e8eda372bb575c9a Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 1 Jan 2017 12:25:44 -0800 Subject: [PATCH 059/132] xed-window.c: Fix a few missing casts --- xed/xed-window.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xed/xed-window.c b/xed/xed-window.c index e682dc5..85e0c7c 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -129,7 +129,7 @@ on_key_pressed (GtkWidget *widget, gint handled = FALSE; if (event->keyval == GDK_KEY_Escape) { - xed_searchbar_hide (window->priv->searchbar); + xed_searchbar_hide (XED_SEARCHBAR (window->priv->searchbar)); handled = TRUE; } return handled; @@ -1626,7 +1626,7 @@ create_statusbar (XedWindow *window, xed_debug (DEBUG_WINDOW); window->priv->statusbar = xed_statusbar_new (); - window->priv->searchbar = xed_searchbar_new (window, TRUE); + window->priv->searchbar = xed_searchbar_new (GTK_WINDOW (window), TRUE); window->priv->generic_message_cid = gtk_statusbar_get_context_id (GTK_STATUSBAR (window->priv->statusbar), "generic_message"); @@ -3418,7 +3418,7 @@ xed_window_init (XedWindow *window) window->priv->window_group = gtk_window_group_new (); gtk_window_group_add_window (window->priv->window_group, GTK_WINDOW (window)); - gtk_style_context_add_class (gtk_widget_get_style_context (window), "xed-window"); + gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (window)), "xed-window"); main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_add (GTK_CONTAINER (window), main_box); From 4ef02d4837560edd3ad5770c4c72617a92819833 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 1 Jan 2017 13:31:02 -0800 Subject: [PATCH 060/132] xed-utils: Clean up code styling --- xed/xed-utils.c | 1921 ++++++++++++++++++++++++----------------------- 1 file changed, 999 insertions(+), 922 deletions(-) diff --git a/xed/xed-utils.c b/xed/xed-utils.c index 5fb81c1..984eeff 100644 --- a/xed/xed-utils.c +++ b/xed/xed-utils.c @@ -69,148 +69,143 @@ gboolean xed_utils_uri_has_file_scheme (const gchar *uri) { - GFile *gfile; - gboolean res; + GFile *gfile; + gboolean res; - gfile = g_file_new_for_uri (uri); - res = g_file_has_uri_scheme (gfile, "file"); + gfile = g_file_new_for_uri (uri); + res = g_file_has_uri_scheme (gfile, "file"); - g_object_unref (gfile); - return res; + g_object_unref (gfile); + return res; } /* FIXME: we should check for chained URIs */ gboolean xed_utils_uri_has_writable_scheme (const gchar *uri) { - GFile *gfile; - gchar *scheme; - GSList *writable_schemes; - gboolean res; + GFile *gfile; + gchar *scheme; + GSList *writable_schemes; + gboolean res; - gfile = g_file_new_for_uri (uri); - scheme = g_file_get_uri_scheme (gfile); + gfile = g_file_new_for_uri (uri); + scheme = g_file_get_uri_scheme (gfile); - g_return_val_if_fail (scheme != NULL, FALSE); + g_return_val_if_fail (scheme != NULL, FALSE); - g_object_unref (gfile); + g_object_unref (gfile); - writable_schemes = xed_prefs_manager_get_writable_vfs_schemes (); + writable_schemes = xed_prefs_manager_get_writable_vfs_schemes (); - /* CHECK: should we use g_ascii_strcasecmp? - Paolo (Nov 6, 2005) */ - res = (g_slist_find_custom (writable_schemes, - scheme, - (GCompareFunc)strcmp) != NULL); + /* CHECK: should we use g_ascii_strcasecmp? - Paolo (Nov 6, 2005) */ + res = (g_slist_find_custom (writable_schemes, scheme, (GCompareFunc)strcmp) != NULL); - g_slist_foreach (writable_schemes, (GFunc)g_free, NULL); - g_slist_free (writable_schemes); + g_slist_foreach (writable_schemes, (GFunc)g_free, NULL); + g_slist_free (writable_schemes); - g_free (scheme); + g_free (scheme); - return res; + return res; } static void -widget_get_origin (GtkWidget *widget, gint *x, gint *y) +widget_get_origin (GtkWidget *widget, + gint *x, + gint *y) { - GdkWindow *window; + GdkWindow *window; - window = gtk_widget_get_window (widget); - gdk_window_get_origin (window, x, y); + window = gtk_widget_get_window (widget); + gdk_window_get_origin (window, x, y); } void xed_utils_menu_position_under_widget (GtkMenu *menu, - gint *x, - gint *y, - gboolean *push_in, - gpointer user_data) + gint *x, + gint *y, + gboolean *push_in, + gpointer user_data) { - GtkWidget *widget; - GtkRequisition requisition; - GtkAllocation allocation; + GtkWidget *widget; + GtkRequisition requisition; + GtkAllocation allocation; - widget = GTK_WIDGET (user_data); - widget_get_origin (widget, x, y); + widget = GTK_WIDGET (user_data); + widget_get_origin (widget, x, y); - gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &requisition); + gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &requisition); - gtk_widget_get_allocation (widget, &allocation); + gtk_widget_get_allocation (widget, &allocation); - if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) - { - *x += allocation.x + allocation.width - requisition.width; - } - else - { - *x += allocation.x; - } + if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) + { + *x += allocation.x + allocation.width - requisition.width; + } + else + { + *x += allocation.x; + } - *y += allocation.y + allocation.height; + *y += allocation.y + allocation.height; - *push_in = TRUE; + *push_in = TRUE; } void xed_utils_menu_position_under_tree_view (GtkMenu *menu, - gint *x, - gint *y, - gboolean *push_in, - gpointer user_data) + gint *x, + gint *y, + gboolean *push_in, + gpointer user_data) { - GtkTreeView *tree = GTK_TREE_VIEW (user_data); - GtkTreeModel *model; - GtkTreeSelection *selection; - GtkTreeIter iter; + GtkTreeView *tree = GTK_TREE_VIEW (user_data); + GtkTreeModel *model; + GtkTreeSelection *selection; + GtkTreeIter iter; - model = gtk_tree_view_get_model (tree); - g_return_if_fail (model != NULL); + model = gtk_tree_view_get_model (tree); + g_return_if_fail (model != NULL); - selection = gtk_tree_view_get_selection (tree); - g_return_if_fail (selection != NULL); + selection = gtk_tree_view_get_selection (tree); + g_return_if_fail (selection != NULL); - if (gtk_tree_selection_get_selected (selection, NULL, &iter)) - { - GtkTreePath *path; - GdkRectangle rect; + if (gtk_tree_selection_get_selected (selection, NULL, &iter)) + { + GtkTreePath *path; + GdkRectangle rect; - widget_get_origin (GTK_WIDGET (tree), x, y); + widget_get_origin (GTK_WIDGET (tree), x, y); - path = gtk_tree_model_get_path (model, &iter); - gtk_tree_view_get_cell_area (tree, path, - gtk_tree_view_get_column (tree, 0), /* FIXME 0 for RTL ? */ - &rect); - gtk_tree_path_free (path); + path = gtk_tree_model_get_path (model, &iter); + gtk_tree_view_get_cell_area (tree, path, + gtk_tree_view_get_column (tree, 0), /* FIXME 0 for RTL ? */ + &rect); + gtk_tree_path_free (path); - *x += rect.x; - *y += rect.y + rect.height; + *x += rect.x; + *y += rect.y + rect.height; - if (gtk_widget_get_direction (GTK_WIDGET (tree)) == GTK_TEXT_DIR_RTL) - { - GtkRequisition requisition; - gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &requisition); + if (gtk_widget_get_direction (GTK_WIDGET (tree)) == GTK_TEXT_DIR_RTL) + { + GtkRequisition requisition; + gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &requisition); - *x += rect.width - requisition.width; - } - } - else - { - /* no selection -> regular "under widget" positioning */ - xed_utils_menu_position_under_widget (menu, - x, y, push_in, - tree); - } + *x += rect.width - requisition.width; + } + } + else + { + /* no selection -> regular "under widget" positioning */ + xed_utils_menu_position_under_widget (menu, x, y, push_in, tree); + } } /* FIXME: remove this with gtk 2.12, it has gdk_color_to_string */ gchar * xed_gdk_color_to_string (GdkColor color) { - return g_strdup_printf ("#%04x%04x%04x", - color.red, - color.green, - color.blue); + return g_strdup_printf ("#%04x%04x%04x", color.red, color.green, color.blue); } /** @@ -222,16 +217,14 @@ xed_gdk_color_to_string (GdkColor color) */ GtkWidget * xed_gtk_button_new_with_stock_icon (const gchar *label, - const gchar *stock_id) + const gchar *stock_id) { - GtkWidget *button; + GtkWidget *button; - button = gtk_button_new_with_mnemonic (label); - gtk_button_set_image (GTK_BUTTON (button), - gtk_image_new_from_stock (stock_id, - GTK_ICON_SIZE_BUTTON)); + button = gtk_button_new_with_mnemonic (label); + gtk_button_set_image (GTK_BUTTON (button), gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON)); - return button; + return button; } /** @@ -245,67 +238,72 @@ xed_gtk_button_new_with_stock_icon (const gchar *label, */ GtkWidget * xed_dialog_add_button (GtkDialog *dialog, - const gchar *text, - const gchar *stock_id, - gint response_id) + const gchar *text, + const gchar *stock_id, + gint response_id) { - GtkWidget *button; + GtkWidget *button; - g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL); - g_return_val_if_fail (text != NULL, NULL); - g_return_val_if_fail (stock_id != NULL, NULL); + g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL); + g_return_val_if_fail (text != NULL, NULL); + g_return_val_if_fail (stock_id != NULL, NULL); - button = xed_gtk_button_new_with_stock_icon (text, stock_id); - g_return_val_if_fail (button != NULL, NULL); + button = xed_gtk_button_new_with_stock_icon (text, stock_id); + g_return_val_if_fail (button != NULL, NULL); - gtk_widget_set_can_default (button, TRUE); + gtk_widget_set_can_default (button, TRUE); - gtk_widget_show (button); + gtk_widget_show (button); - gtk_dialog_add_action_widget (dialog, button, response_id); + gtk_dialog_add_action_widget (dialog, button, response_id); - return button; + return button; } /* * n: len of the string in bytes */ gboolean -g_utf8_caselessnmatch (const char *s1, const char *s2, gssize n1, gssize n2) +g_utf8_caselessnmatch (const char *s1, + const char *s2, + gssize n1, + gssize n2) { - gchar *casefold; - gchar *normalized_s1; - gchar *normalized_s2; - gint len_s1; - gint len_s2; - gboolean ret = FALSE; + gchar *casefold; + gchar *normalized_s1; + gchar *normalized_s2; + gint len_s1; + gint len_s2; + gboolean ret = FALSE; - g_return_val_if_fail (s1 != NULL, FALSE); - g_return_val_if_fail (s2 != NULL, FALSE); - g_return_val_if_fail (n1 > 0, FALSE); - g_return_val_if_fail (n2 > 0, FALSE); + g_return_val_if_fail (s1 != NULL, FALSE); + g_return_val_if_fail (s2 != NULL, FALSE); + g_return_val_if_fail (n1 > 0, FALSE); + g_return_val_if_fail (n2 > 0, FALSE); - casefold = g_utf8_casefold (s1, n1); - normalized_s1 = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD); - g_free (casefold); + casefold = g_utf8_casefold (s1, n1); + normalized_s1 = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD); + g_free (casefold); - casefold = g_utf8_casefold (s2, n2); - normalized_s2 = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD); - g_free (casefold); + casefold = g_utf8_casefold (s2, n2); + normalized_s2 = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD); + g_free (casefold); - len_s1 = strlen (normalized_s1); - len_s2 = strlen (normalized_s2); + len_s1 = strlen (normalized_s1); + len_s2 = strlen (normalized_s2); - if (len_s1 < len_s2) - goto finally_2; + if (len_s1 < len_s2) + { + goto finally_2; + } - ret = (strncmp (normalized_s1, normalized_s2, len_s2) == 0); + ret = (strncmp (normalized_s1, normalized_s2, len_s2) == 0); finally_2: - g_free (normalized_s1); - g_free (normalized_s2); + g_free (normalized_s1); + g_free (normalized_s2); - return ret; + return ret; } /** @@ -318,22 +316,28 @@ finally_2: * for a specified gtk widget. */ void -xed_utils_set_atk_name_description (GtkWidget *widget, - const gchar *name, - const gchar *description) +xed_utils_set_atk_name_description (GtkWidget *widget, + const gchar *name, + const gchar *description) { - AtkObject *aobj; + AtkObject *aobj; - aobj = gtk_widget_get_accessible (widget); + aobj = gtk_widget_get_accessible (widget); - if (!(GTK_IS_ACCESSIBLE (aobj))) - return; + if (!(GTK_IS_ACCESSIBLE (aobj))) + { + return; + } - if(name) - atk_object_set_name (aobj, name); + if (name) + { + atk_object_set_name (aobj, name); + } - if(description) - atk_object_set_description (aobj, description); + if (description) + { + atk_object_set_description (aobj, description); + } } /** @@ -346,219 +350,230 @@ xed_utils_set_atk_name_description (GtkWidget *widget, * between 2 specified widgets. */ void -xed_utils_set_atk_relation (GtkWidget *obj1, - GtkWidget *obj2, - AtkRelationType rel_type ) +xed_utils_set_atk_relation (GtkWidget *obj1, + GtkWidget *obj2, + AtkRelationType rel_type ) { - AtkObject *atk_obj1, *atk_obj2; - AtkRelationSet *relation_set; - AtkObject *targets[1]; - AtkRelation *relation; + AtkObject *atk_obj1, *atk_obj2; + AtkRelationSet *relation_set; + AtkObject *targets[1]; + AtkRelation *relation; - atk_obj1 = gtk_widget_get_accessible (obj1); - atk_obj2 = gtk_widget_get_accessible (obj2); + atk_obj1 = gtk_widget_get_accessible (obj1); + atk_obj2 = gtk_widget_get_accessible (obj2); - if (!(GTK_IS_ACCESSIBLE (atk_obj1)) || !(GTK_IS_ACCESSIBLE (atk_obj2))) - return; + if (!(GTK_IS_ACCESSIBLE (atk_obj1)) || !(GTK_IS_ACCESSIBLE (atk_obj2))) + { + return; + } - relation_set = atk_object_ref_relation_set (atk_obj1); - targets[0] = atk_obj2; + relation_set = atk_object_ref_relation_set (atk_obj1); + targets[0] = atk_obj2; - relation = atk_relation_new (targets, 1, rel_type); - atk_relation_set_add (relation_set, relation); + relation = atk_relation_new (targets, 1, rel_type); + atk_relation_set_add (relation_set, relation); - g_object_unref (G_OBJECT (relation)); + g_object_unref (G_OBJECT (relation)); } gboolean xed_utils_uri_exists (const gchar* text_uri) { - GFile *gfile; - gboolean res; + GFile *gfile; + gboolean res; - g_return_val_if_fail (text_uri != NULL, FALSE); + g_return_val_if_fail (text_uri != NULL, FALSE); - xed_debug_message (DEBUG_UTILS, "text_uri: %s", text_uri); + xed_debug_message (DEBUG_UTILS, "text_uri: %s", text_uri); - gfile = g_file_new_for_uri (text_uri); - res = g_file_query_exists (gfile, NULL); + gfile = g_file_new_for_uri (text_uri); + res = g_file_query_exists (gfile, NULL); - g_object_unref (gfile); + g_object_unref (gfile); - xed_debug_message (DEBUG_UTILS, res ? "TRUE" : "FALSE"); + xed_debug_message (DEBUG_UTILS, res ? "TRUE" : "FALSE"); - return res; + return res; } gchar * xed_utils_escape_search_text (const gchar* text) { - GString *str; - gint length; - const gchar *p; - const gchar *end; + GString *str; + gint length; + const gchar *p; + const gchar *end; - if (text == NULL) - return NULL; + if (text == NULL) + { + return NULL; + } - xed_debug_message (DEBUG_SEARCH, "Text: %s", text); + xed_debug_message (DEBUG_SEARCH, "Text: %s", text); - length = strlen (text); + length = strlen (text); - /* no escape when typing. - * The short circuit works only for ascii, but we only - * care about not escaping a single '\' */ - if (length == 1) - return g_strdup (text); + /* no escape when typing. + * The short circuit works only for ascii, but we only + * care about not escaping a single '\' */ + if (length == 1) + { + return g_strdup (text); + } - str = g_string_new (""); + str = g_string_new (""); - p = text; - end = text + length; + p = text; + end = text + length; - while (p != end) - { - const gchar *next; - next = g_utf8_next_char (p); + while (p != end) + { + const gchar *next; + next = g_utf8_next_char (p); - switch (*p) - { - case '\n': - g_string_append (str, "\\n"); - break; - case '\r': - g_string_append (str, "\\r"); - break; - case '\t': - g_string_append (str, "\\t"); - break; - case '\\': - g_string_append (str, "\\\\"); - break; - default: - g_string_append_len (str, p, next - p); - break; - } + switch (*p) + { + case '\n': + g_string_append (str, "\\n"); + break; + case '\r': + g_string_append (str, "\\r"); + break; + case '\t': + g_string_append (str, "\\t"); + break; + case '\\': + g_string_append (str, "\\\\"); + break; + default: + g_string_append_len (str, p, next - p); + break; + } - p = next; - } + p = next; + } - return g_string_free (str, FALSE); + return g_string_free (str, FALSE); } gchar * xed_utils_unescape_search_text (const gchar *text) { - GString *str; - gint length; - gboolean drop_prev = FALSE; - const gchar *cur; - const gchar *end; - const gchar *prev; + GString *str; + gint length; + gboolean drop_prev = FALSE; + const gchar *cur; + const gchar *end; + const gchar *prev; - if (text == NULL) - return NULL; + if (text == NULL) + { + return NULL; + } - length = strlen (text); + length = strlen (text); - str = g_string_new (""); + str = g_string_new (""); - cur = text; - end = text + length; - prev = NULL; + cur = text; + end = text + length; + prev = NULL; - while (cur != end) - { - const gchar *next; - next = g_utf8_next_char (cur); + while (cur != end) + { + const gchar *next; + next = g_utf8_next_char (cur); - if (prev && (*prev == '\\')) - { - switch (*cur) - { - case 'n': - str = g_string_append (str, "\n"); - break; - case 'r': - str = g_string_append (str, "\r"); - break; - case 't': - str = g_string_append (str, "\t"); - break; - case '\\': - str = g_string_append (str, "\\"); - drop_prev = TRUE; - break; - default: - str = g_string_append (str, "\\"); - str = g_string_append_len (str, cur, next - cur); - break; - } - } - else if (*cur != '\\') - { - str = g_string_append_len (str, cur, next - cur); - } - else if ((next == end) && (*cur == '\\')) - { - str = g_string_append (str, "\\"); - } + if (prev && (*prev == '\\')) + { + switch (*cur) + { + case 'n': + str = g_string_append (str, "\n"); + break; + case 'r': + str = g_string_append (str, "\r"); + break; + case 't': + str = g_string_append (str, "\t"); + break; + case '\\': + str = g_string_append (str, "\\"); + drop_prev = TRUE; + break; + default: + str = g_string_append (str, "\\"); + str = g_string_append_len (str, cur, next - cur); + break; + } + } + else if (*cur != '\\') + { + str = g_string_append_len (str, cur, next - cur); + } + else if ((next == end) && (*cur == '\\')) + { + str = g_string_append (str, "\\"); + } - if (!drop_prev) - { - prev = cur; - } - else - { - prev = NULL; - drop_prev = FALSE; - } + if (!drop_prev) + { + prev = cur; + } + else + { + prev = NULL; + drop_prev = FALSE; + } - cur = next; - } + cur = next; + } - return g_string_free (str, FALSE); + return g_string_free (str, FALSE); } void -xed_warning (GtkWindow *parent, const gchar *format, ...) +xed_warning (GtkWindow *parent, + const gchar *format, + ...) { - va_list args; - gchar *str; - GtkWidget *dialog; - GtkWindowGroup *wg = NULL; + va_list args; + gchar *str; + GtkWidget *dialog; + GtkWindowGroup *wg = NULL; - g_return_if_fail (format != NULL); + g_return_if_fail (format != NULL); - if (parent != NULL) - wg = gtk_window_get_group (parent); + if (parent != NULL) + { + wg = gtk_window_get_group (parent); + } - va_start (args, format); - str = g_strdup_vprintf (format, args); - va_end (args); + va_start (args, format); + str = g_strdup_vprintf (format, args); + va_end (args); - dialog = gtk_message_dialog_new_with_markup ( - parent, - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - "%s", str); + dialog = gtk_message_dialog_new_with_markup (parent, + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "%s", str); - g_free (str); + g_free (str); - if (wg != NULL) - gtk_window_group_add_window (wg, GTK_WINDOW (dialog)); + if (wg != NULL) + { + gtk_window_group_add_window (wg, GTK_WINDOW (dialog)); + } - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); - gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); - g_signal_connect (G_OBJECT (dialog), - "response", - G_CALLBACK (gtk_widget_destroy), - NULL); + g_signal_connect (G_OBJECT (dialog), "response", + G_CALLBACK (gtk_widget_destroy), NULL); - gtk_widget_show (dialog); + gtk_widget_show (dialog); } /* @@ -566,155 +581,161 @@ xed_warning (GtkWindow *parent, const gchar *format, ...) */ gchar * xed_utils_escape_underscores (const gchar* text, - gssize length) + gssize length) { - GString *str; - const gchar *p; - const gchar *end; + GString *str; + const gchar *p; + const gchar *end; - g_return_val_if_fail (text != NULL, NULL); + g_return_val_if_fail (text != NULL, NULL); - if (length < 0) - length = strlen (text); + if (length < 0) + { + length = strlen (text); + } - str = g_string_sized_new (length); + str = g_string_sized_new (length); - p = text; - end = text + length; + p = text; + end = text + length; - while (p != end) - { - const gchar *next; - next = g_utf8_next_char (p); + while (p != end) + { + const gchar *next; + next = g_utf8_next_char (p); - switch (*p) - { - case '_': - g_string_append (str, "__"); - break; - default: - g_string_append_len (str, p, next - p); - break; - } + switch (*p) + { + case '_': + g_string_append (str, "__"); + break; + default: + g_string_append_len (str, p, next - p); + break; + } - p = next; - } + p = next; + } - return g_string_free (str, FALSE); + return g_string_free (str, FALSE); } /* the following functions are taken from eel */ static gchar * xed_utils_str_truncate (const gchar *string, - guint truncate_length, - gboolean middle) + guint truncate_length, + gboolean middle) { - GString *truncated; - guint length; - guint n_chars; - guint num_left_chars; - guint right_offset; - guint delimiter_length; - const gchar *delimiter = "\342\200\246"; + GString *truncated; + guint length; + guint n_chars; + guint num_left_chars; + guint right_offset; + guint delimiter_length; + const gchar *delimiter = "\342\200\246"; - g_return_val_if_fail (string != NULL, NULL); + g_return_val_if_fail (string != NULL, NULL); - length = strlen (string); + length = strlen (string); - g_return_val_if_fail (g_utf8_validate (string, length, NULL), NULL); + g_return_val_if_fail (g_utf8_validate (string, length, NULL), NULL); - /* It doesnt make sense to truncate strings to less than - * the size of the delimiter plus 2 characters (one on each - * side) - */ - delimiter_length = g_utf8_strlen (delimiter, -1); - if (truncate_length < (delimiter_length + 2)) { - return g_strdup (string); - } + /* It doesnt make sense to truncate strings to less than + * the size of the delimiter plus 2 characters (one on each + * side) + */ + delimiter_length = g_utf8_strlen (delimiter, -1); + if (truncate_length < (delimiter_length + 2)) + { + return g_strdup (string); + } - n_chars = g_utf8_strlen (string, length); + n_chars = g_utf8_strlen (string, length); - /* Make sure the string is not already small enough. */ - if (n_chars <= truncate_length) { - return g_strdup (string); - } + /* Make sure the string is not already small enough. */ + if (n_chars <= truncate_length) + { + return g_strdup (string); + } - /* Find the 'middle' where the truncation will occur. */ - if (middle) - { - num_left_chars = (truncate_length - delimiter_length) / 2; - right_offset = n_chars - truncate_length + num_left_chars + delimiter_length; + /* Find the 'middle' where the truncation will occur. */ + if (middle) + { + num_left_chars = (truncate_length - delimiter_length) / 2; + right_offset = n_chars - truncate_length + num_left_chars + delimiter_length; - truncated = g_string_new_len (string, - g_utf8_offset_to_pointer (string, num_left_chars) - string); - g_string_append (truncated, delimiter); - g_string_append (truncated, g_utf8_offset_to_pointer (string, right_offset)); - } - else - { - num_left_chars = truncate_length - delimiter_length; - truncated = g_string_new_len (string, - g_utf8_offset_to_pointer (string, num_left_chars) - string); - g_string_append (truncated, delimiter); - } + truncated = g_string_new_len (string, g_utf8_offset_to_pointer (string, num_left_chars) - string); + g_string_append (truncated, delimiter); + g_string_append (truncated, g_utf8_offset_to_pointer (string, right_offset)); + } + else + { + num_left_chars = truncate_length - delimiter_length; + truncated = g_string_new_len (string, g_utf8_offset_to_pointer (string, num_left_chars) - string); + g_string_append (truncated, delimiter); + } - return g_string_free (truncated, FALSE); + return g_string_free (truncated, FALSE); } gchar * xed_utils_str_middle_truncate (const gchar *string, - guint truncate_length) + guint truncate_length) { - return xed_utils_str_truncate (string, truncate_length, TRUE); + return xed_utils_str_truncate (string, truncate_length, TRUE); } gchar * xed_utils_str_end_truncate (const gchar *string, - guint truncate_length) + guint truncate_length) { - return xed_utils_str_truncate (string, truncate_length, FALSE); + return xed_utils_str_truncate (string, truncate_length, FALSE); } gchar * xed_utils_make_valid_utf8 (const char *name) { - GString *string; - const char *remainder, *invalid; - int remaining_bytes, valid_bytes; + GString *string; + const char *remainder, *invalid; + int remaining_bytes, valid_bytes; - g_return_val_if_fail (name != NULL, NULL); + g_return_val_if_fail (name != NULL, NULL); - string = NULL; - remainder = name; - remaining_bytes = strlen (name); + string = NULL; + remainder = name; + remaining_bytes = strlen (name); - while (remaining_bytes != 0) { - if (g_utf8_validate (remainder, remaining_bytes, &invalid)) { - break; - } - valid_bytes = invalid - remainder; + while (remaining_bytes != 0) + { + if (g_utf8_validate (remainder, remaining_bytes, &invalid)) + { + break; + } + valid_bytes = invalid - remainder; - if (string == NULL) { - string = g_string_sized_new (remaining_bytes); - } - g_string_append_len (string, remainder, valid_bytes); - /* append U+FFFD REPLACEMENT CHARACTER */ - g_string_append (string, "\357\277\275"); + if (string == NULL) + { + string = g_string_sized_new (remaining_bytes); + } + g_string_append_len (string, remainder, valid_bytes); + /* append U+FFFD REPLACEMENT CHARACTER */ + g_string_append (string, "\357\277\275"); - remaining_bytes -= valid_bytes + 1; - remainder = invalid + 1; - } + remaining_bytes -= valid_bytes + 1; + remainder = invalid + 1; + } - if (string == NULL) { - return g_strdup (name); - } + if (string == NULL) + { + return g_strdup (name); + } - g_string_append (string, remainder); + g_string_append (string, remainder); - g_assert (g_utf8_validate (string->str, -1, NULL)); + g_assert (g_utf8_validate (string->str, -1, NULL)); - return g_string_free (string, FALSE); + return g_string_free (string, FALSE); } /** @@ -725,27 +746,27 @@ xed_utils_make_valid_utf8 (const char *name) gchar * xed_utils_uri_get_dirname (const gchar *uri) { - gchar *res; - gchar *str; + gchar *res; + gchar *str; - g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (uri != NULL, NULL); - /* CHECK: does it work with uri chaining? - Paolo */ - str = g_path_get_dirname (uri); - g_return_val_if_fail (str != NULL, g_strdup (".")); + /* CHECK: does it work with uri chaining? - Paolo */ + str = g_path_get_dirname (uri); + g_return_val_if_fail (str != NULL, g_strdup (".")); - if ((strlen (str) == 1) && (*str == '.')) - { - g_free (str); + if ((strlen (str) == 1) && (*str == '.')) + { + g_free (str); - return NULL; - } + return NULL; + } - res = xed_utils_replace_home_dir_with_tilde (str); + res = xed_utils_replace_home_dir_with_tilde (str); - g_free (str); + g_free (str); - return res; + return res; } /** @@ -762,109 +783,113 @@ xed_utils_uri_get_dirname (const gchar *uri) gchar * xed_utils_location_get_dirname_for_display (GFile *location) { - gchar *uri; - gchar *res; - GMount *mount; + gchar *uri; + gchar *res; + GMount *mount; - g_return_val_if_fail (location != NULL, NULL); + g_return_val_if_fail (location != NULL, NULL); - /* we use the parse name, that is either the local path - * or an uri but which is utf8 safe */ - uri = g_file_get_parse_name (location); + /* we use the parse name, that is either the local path + * or an uri but which is utf8 safe */ + uri = g_file_get_parse_name (location); - /* FIXME: this is sync... is it a problem? */ - mount = g_file_find_enclosing_mount (location, NULL, NULL); - if (mount != NULL) - { - gchar *mount_name; - gchar *path = NULL; - gchar *dirname; + /* FIXME: this is sync... is it a problem? */ + mount = g_file_find_enclosing_mount (location, NULL, NULL); + if (mount != NULL) + { + gchar *mount_name; + gchar *path = NULL; + gchar *dirname; - mount_name = g_mount_get_name (mount); - g_object_unref (mount); + mount_name = g_mount_get_name (mount); + g_object_unref (mount); - /* obtain the "path" part of the uri */ - xed_utils_decode_uri (uri, - NULL, NULL, - NULL, NULL, - &path); + /* obtain the "path" part of the uri */ + xed_utils_decode_uri (uri, + NULL, NULL, + NULL, NULL, + &path); - if (path == NULL) - { - dirname = xed_utils_uri_get_dirname (uri); - } - else - { - dirname = xed_utils_uri_get_dirname (path); - } + if (path == NULL) + { + dirname = xed_utils_uri_get_dirname (uri); + } + else + { + dirname = xed_utils_uri_get_dirname (path); + } - if (dirname == NULL || strcmp (dirname, ".") == 0) - { - res = mount_name; - } - else - { - res = g_strdup_printf ("%s %s", mount_name, dirname); - g_free (mount_name); - } + if (dirname == NULL || strcmp (dirname, ".") == 0) + { + res = mount_name; + } + else + { + res = g_strdup_printf ("%s %s", mount_name, dirname); + g_free (mount_name); + } - g_free (path); - g_free (dirname); - } - else - { - /* fallback for local files or uris without mounts */ - res = xed_utils_uri_get_dirname (uri); - } + g_free (path); + g_free (dirname); + } + else + { + /* fallback for local files or uris without mounts */ + res = xed_utils_uri_get_dirname (uri); + } - g_free (uri); + g_free (uri); - return res; + return res; } gchar * xed_utils_replace_home_dir_with_tilde (const gchar *uri) { - gchar *tmp; - gchar *home; + gchar *tmp; + gchar *home; - g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (uri != NULL, NULL); - /* Note that g_get_home_dir returns a const string */ - tmp = (gchar *)g_get_home_dir (); + /* Note that g_get_home_dir returns a const string */ + tmp = (gchar *)g_get_home_dir (); - if (tmp == NULL) - return g_strdup (uri); + if (tmp == NULL) + { + return g_strdup (uri); + } - home = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL); - if (home == NULL) - return g_strdup (uri); + home = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL); + if (home == NULL) + { + return g_strdup (uri); + } - if (strcmp (uri, home) == 0) - { - g_free (home); + if (strcmp (uri, home) == 0) + { + g_free (home); - return g_strdup ("~"); - } + return g_strdup ("~"); + } - tmp = home; - home = g_strdup_printf ("%s/", tmp); - g_free (tmp); + tmp = home; + home = g_strdup_printf ("%s/", tmp); + g_free (tmp); - if (g_str_has_prefix (uri, home)) - { - gchar *res; + if (g_str_has_prefix (uri, home)) + { + gchar *res; - res = g_strdup_printf ("~/%s", uri + strlen (home)); + res = g_strdup_printf ("~/%s", uri + strlen (home)); - g_free (home); + g_free (home); - return res; - } + return res; + } - g_free (home); + g_free (home); - return g_strdup (uri); + return g_strdup (uri); } /* the following two functions are courtesy of galeon */ @@ -883,40 +908,44 @@ guint xed_utils_get_current_workspace (GdkScreen *screen) { #ifdef GDK_WINDOWING_X11 - GdkWindow *root_win; - GdkDisplay *display; - Atom type; - gint format; - gulong nitems; - gulong bytes_after; - guint *current_desktop; - gint err, result; - guint ret = 0; + GdkWindow *root_win; + GdkDisplay *display; + Atom type; + gint format; + gulong nitems; + gulong bytes_after; + guint *current_desktop; + gint err, result; + guint ret = 0; - g_return_val_if_fail (GDK_IS_SCREEN (screen), 0); + g_return_val_if_fail (GDK_IS_SCREEN (screen), 0); - root_win = gdk_screen_get_root_window (screen); - display = gdk_screen_get_display (screen); + root_win = gdk_screen_get_root_window (screen); + display = gdk_screen_get_display (screen); - gdk_error_trap_push (); - result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (root_win), - gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"), - 0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems, - &bytes_after, (gpointer) ¤t_desktop); - err = gdk_error_trap_pop (); + gdk_error_trap_push (); + result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (root_win), + gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"), + 0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems, + &bytes_after, (gpointer) ¤t_desktop); + err = gdk_error_trap_pop (); - if (err != Success || result != Success) - return ret; + if (err != Success || result != Success) + { + return ret; + } - if (type == XA_CARDINAL && format == 32 && nitems > 0) - ret = current_desktop[0]; + if (type == XA_CARDINAL && format == 32 && nitems > 0) + { + ret = current_desktop[0]; + } - XFree (current_desktop); - return ret; + XFree (current_desktop); + return ret; #else - /* FIXME: on mac etc proably there are native APIs - * to get the current workspace etc */ - return 0; + /* FIXME: on mac etc proably there are native APIs + * to get the current workspace etc */ + return 0; #endif } @@ -933,41 +962,45 @@ guint xed_utils_get_window_workspace (GtkWindow *gtkwindow) { #ifdef GDK_WINDOWING_X11 - GdkWindow *window; - GdkDisplay *display; - Atom type; - gint format; - gulong nitems; - gulong bytes_after; - guint *workspace; - gint err, result; - guint ret = XED_ALL_WORKSPACES; + GdkWindow *window; + GdkDisplay *display; + Atom type; + gint format; + gulong nitems; + gulong bytes_after; + guint *workspace; + gint err, result; + guint ret = XED_ALL_WORKSPACES; - g_return_val_if_fail (GTK_IS_WINDOW (gtkwindow), 0); - g_return_val_if_fail (gtk_widget_get_realized (GTK_WIDGET (gtkwindow)), 0); + g_return_val_if_fail (GTK_IS_WINDOW (gtkwindow), 0); + g_return_val_if_fail (gtk_widget_get_realized (GTK_WIDGET (gtkwindow)), 0); - window = gtk_widget_get_window (GTK_WIDGET (gtkwindow)); - display = gdk_window_get_display (window); + window = gtk_widget_get_window (GTK_WIDGET (gtkwindow)); + display = gdk_window_get_display (window); - gdk_error_trap_push (); - result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), - gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"), - 0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems, - &bytes_after, (gpointer) &workspace); - err = gdk_error_trap_pop (); + gdk_error_trap_push (); + result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), + gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"), + 0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems, + &bytes_after, (gpointer) &workspace); + err = gdk_error_trap_pop (); - if (err != Success || result != Success) - return ret; + if (err != Success || result != Success) + { + return ret; + } - if (type == XA_CARDINAL && format == 32 && nitems > 0) - ret = workspace[0]; + if (type == XA_CARDINAL && format == 32 && nitems > 0) + { + ret = workspace[0]; + } - XFree (workspace); - return ret; + XFree (workspace); + return ret; #else - /* FIXME: on mac etc proably there are native APIs - * to get the current workspace etc */ - return 0; + /* FIXME: on mac etc proably there are native APIs + * to get the current workspace etc */ + return 0; #endif } @@ -982,144 +1015,160 @@ xed_utils_get_window_workspace (GtkWindow *gtkwindow) */ void xed_utils_get_current_viewport (GdkScreen *screen, - gint *x, - gint *y) + gint *x, + gint *y) { #ifdef GDK_WINDOWING_X11 - GdkWindow *root_win; - GdkDisplay *display; - Atom type; - gint format; - gulong nitems; - gulong bytes_after; - gulong *coordinates; - gint err, result; + GdkWindow *root_win; + GdkDisplay *display; + Atom type; + gint format; + gulong nitems; + gulong bytes_after; + gulong *coordinates; + gint err, result; - g_return_if_fail (GDK_IS_SCREEN (screen)); - g_return_if_fail (x != NULL && y != NULL); + g_return_if_fail (GDK_IS_SCREEN (screen)); + g_return_if_fail (x != NULL && y != NULL); - /* Default values for the viewport origin */ - *x = 0; - *y = 0; + /* Default values for the viewport origin */ + *x = 0; + *y = 0; - root_win = gdk_screen_get_root_window (screen); - display = gdk_screen_get_display (screen); + root_win = gdk_screen_get_root_window (screen); + display = gdk_screen_get_display (screen); - gdk_error_trap_push (); - result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (root_win), - gdk_x11_get_xatom_by_name_for_display (display, "_NET_DESKTOP_VIEWPORT"), - 0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems, - &bytes_after, (void*) &coordinates); - err = gdk_error_trap_pop (); + gdk_error_trap_push (); + result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (root_win), + gdk_x11_get_xatom_by_name_for_display (display, "_NET_DESKTOP_VIEWPORT"), + 0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems, + &bytes_after, (void*) &coordinates); + err = gdk_error_trap_pop (); - if (err != Success || result != Success) - return; + if (err != Success || result != Success) + { + return; + } - if (type != XA_CARDINAL || format != 32 || nitems < 2) - { - XFree (coordinates); - return; - } + if (type != XA_CARDINAL || format != 32 || nitems < 2) + { + XFree (coordinates); + return; + } - *x = coordinates[0]; - *y = coordinates[1]; - XFree (coordinates); + *x = coordinates[0]; + *y = coordinates[1]; + XFree (coordinates); #else - /* FIXME: on mac etc proably there are native APIs - * to get the current workspace etc */ - *x = 0; - *y = 0; + /* FIXME: on mac etc proably there are native APIs + * to get the current workspace etc */ + *x = 0; + *y = 0; #endif } static gboolean is_valid_scheme_character (gchar c) { - return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.'; + return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.'; } static gboolean has_valid_scheme (const gchar *uri) { - const gchar *p; + const gchar *p; - p = uri; + p = uri; - if (!is_valid_scheme_character (*p)) { - return FALSE; - } + if (!is_valid_scheme_character (*p)) + { + return FALSE; + } - do { - p++; - } while (is_valid_scheme_character (*p)); + do + { + p++; + } while (is_valid_scheme_character (*p)); - return *p == ':'; + return *p == ':'; } gboolean xed_utils_is_valid_uri (const gchar *uri) { - const guchar *p; + const guchar *p; - if (uri == NULL) - return FALSE; + if (uri == NULL) + { + return FALSE; + } - if (!has_valid_scheme (uri)) - return FALSE; + if (!has_valid_scheme (uri)) + { + return FALSE; + } - /* We expect to have a fully valid set of characters */ - for (p = (const guchar *)uri; *p; p++) { - if (*p == '%') - { - ++p; - if (!g_ascii_isxdigit (*p)) - return FALSE; + /* We expect to have a fully valid set of characters */ + for (p = (const guchar *)uri; *p; p++) + { + if (*p == '%') + { + ++p; + if (!g_ascii_isxdigit (*p)) + { + return FALSE; + } - ++p; - if (!g_ascii_isxdigit (*p)) - return FALSE; - } - else - { - if (*p <= 32 || *p >= 128) - return FALSE; - } - } + ++p; + if (!g_ascii_isxdigit (*p)) + { + return FALSE; + } + } + else + { + if (*p <= 32 || *p >= 128) + { + return FALSE; + } + } + } - return TRUE; + return TRUE; } static GtkWidget * -handle_builder_error (const gchar *message, ...) +handle_builder_error (const gchar *message, + ...) { - GtkWidget *label; - gchar *msg; - gchar *msg_plain; - va_list args; + GtkWidget *label; + gchar *msg; + gchar *msg_plain; + va_list args; - va_start (args, message); - msg_plain = g_strdup_vprintf (message, args); - va_end (args); + va_start (args, message); + msg_plain = g_strdup_vprintf (message, args); + va_end (args); - label = gtk_label_new (NULL); - gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); + label = gtk_label_new (NULL); + gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); - msg = g_strconcat ("", - msg_plain, "\n\n", - _("Please check your installation."), - NULL); + msg = g_strconcat ("", + msg_plain, "\n\n", + _("Please check your installation."), + NULL); - gtk_label_set_markup (GTK_LABEL (label), msg); + gtk_label_set_markup (GTK_LABEL (label), msg); - g_free (msg_plain); - g_free (msg); + g_free (msg_plain); + g_free (msg); - gtk_widget_set_margin_left (label, 5); - gtk_widget_set_margin_right (label, 5); - gtk_widget_set_margin_top (label, 5); - gtk_widget_set_margin_bottom (label, 5); + gtk_widget_set_margin_left (label, 5); + gtk_widget_set_margin_right (label, 5); + gtk_widget_set_margin_top (label, 5); + gtk_widget_set_margin_bottom (label, 5); - return label; + return label; } /* FIXME this is an issue for introspection */ @@ -1141,129 +1190,126 @@ handle_builder_error (const gchar *message, ...) */ gboolean xed_utils_get_ui_objects (const gchar *filename, - gchar **root_objects, - GtkWidget **error_widget, - const gchar *object_name, - ...) + gchar **root_objects, + GtkWidget **error_widget, + const gchar *object_name, + ...) { - GtkBuilder *builder; - va_list args; - const gchar *name; - GError *error = NULL; - gchar *filename_markup; - gboolean ret = TRUE; + GtkBuilder *builder; + va_list args; + const gchar *name; + GError *error = NULL; + gchar *filename_markup; + gboolean ret = TRUE; - g_return_val_if_fail (filename != NULL, FALSE); - g_return_val_if_fail (error_widget != NULL, FALSE); - g_return_val_if_fail (object_name != NULL, FALSE); + g_return_val_if_fail (filename != NULL, FALSE); + g_return_val_if_fail (error_widget != NULL, FALSE); + g_return_val_if_fail (object_name != NULL, FALSE); - filename_markup = g_markup_printf_escaped ("%s", filename); - *error_widget = NULL; + filename_markup = g_markup_printf_escaped ("%s", filename); + *error_widget = NULL; - builder = gtk_builder_new (); + builder = gtk_builder_new (); - if (root_objects != NULL) - { - gtk_builder_add_objects_from_file (builder, - filename, - root_objects, - &error); - } - else - { - gtk_builder_add_from_file (builder, - filename, - &error); - } + if (root_objects != NULL) + { + gtk_builder_add_objects_from_file (builder, filename, root_objects, &error); + } + else + { + gtk_builder_add_from_file (builder, filename, &error); + } - if (error != NULL) - { - *error_widget = handle_builder_error (_("Unable to open UI file %s. Error: %s"), - filename_markup, - error->message); - g_error_free (error); - g_free (filename_markup); - g_object_unref (builder); + if (error != NULL) + { + *error_widget = handle_builder_error (_("Unable to open UI file %s. Error: %s"), + filename_markup, + error->message); + g_error_free (error); + g_free (filename_markup); + g_object_unref (builder); - return FALSE; - } + return FALSE; + } - va_start (args, object_name); - for (name = object_name; name; name = va_arg (args, const gchar *) ) - { - GObject **gobj; + va_start (args, object_name); + for (name = object_name; name; name = va_arg (args, const gchar *) ) + { + GObject **gobj; - gobj = va_arg (args, GObject **); - *gobj = gtk_builder_get_object (builder, name); + gobj = va_arg (args, GObject **); + *gobj = gtk_builder_get_object (builder, name); - if (!*gobj) - { - *error_widget = handle_builder_error (_("Unable to find the object '%s' inside file %s."), - name, - filename_markup), - ret = FALSE; - break; - } + if (!*gobj) + { + *error_widget = handle_builder_error (_("Unable to find the object '%s' inside file %s."), + name, + filename_markup), + ret = FALSE; + break; + } - /* we return a new ref for the root objects, - * the others are already reffed by their parent root object */ - if (root_objects != NULL) - { - gint i; + /* we return a new ref for the root objects, + * the others are already reffed by their parent root object */ + if (root_objects != NULL) + { + gint i; - for (i = 0; root_objects[i] != NULL; ++i) - { - if ((strcmp (name, root_objects[i]) == 0)) - { - g_object_ref (*gobj); - } - } - } - } - va_end (args); + for (i = 0; root_objects[i] != NULL; ++i) + { + if ((strcmp (name, root_objects[i]) == 0)) + { + g_object_ref (*gobj); + } + } + } + } + va_end (args); - g_free (filename_markup); - g_object_unref (builder); + g_free (filename_markup); + g_object_unref (builder); - return ret; + return ret; } gchar * xed_utils_make_canonical_uri_from_shell_arg (const gchar *str) { - GFile *gfile; - gchar *uri; + GFile *gfile; + gchar *uri; - g_return_val_if_fail (str != NULL, NULL); - g_return_val_if_fail (*str != '\0', NULL); + g_return_val_if_fail (str != NULL, NULL); + g_return_val_if_fail (*str != '\0', NULL); - /* Note for the future: - * FIXME: is still still relevant? - * - * paolo: and flame whoever tells - * you that file:///mate/test_files/hëllò - * doesn't work --- that's not a valid URI - * - * federico: well, another solution that - * does not requires patch to _from_shell_args - * is to check that the string returned by it - * contains only ASCII chars - * paolo: hmmmm, isn't there - * mate_vfs_is_uri_valid() or something? - * : I will use xed_utils_is_valid_uri () - * - */ + /* Note for the future: + * FIXME: is still still relevant? + * + * paolo: and flame whoever tells + * you that file:///mate/test_files/hëllò + * doesn't work --- that's not a valid URI + * + * federico: well, another solution that + * does not requires patch to _from_shell_args + * is to check that the string returned by it + * contains only ASCII chars + * paolo: hmmmm, isn't there + * mate_vfs_is_uri_valid() or something? + * : I will use xed_utils_is_valid_uri () + * + */ - gfile = g_file_new_for_commandline_arg (str); - uri = g_file_get_uri (gfile); - g_object_unref (gfile); + gfile = g_file_new_for_commandline_arg (str); + uri = g_file_get_uri (gfile); + g_object_unref (gfile); - if (xed_utils_is_valid_uri (uri)) - return uri; + if (xed_utils_is_valid_uri (uri)) + { + return uri; + } - g_free (uri); - return NULL; + g_free (uri); + return NULL; } /** @@ -1276,16 +1322,18 @@ xed_utils_make_canonical_uri_from_shell_arg (const gchar *str) gboolean xed_utils_file_has_parent (GFile *gfile) { - GFile *parent; - gboolean ret; + GFile *parent; + gboolean ret; - parent = g_file_get_parent (gfile); - ret = parent != NULL; + parent = g_file_get_parent (gfile); + ret = parent != NULL; - if (parent) - g_object_unref (parent); + if (parent) + { + g_object_unref (parent); + } - return ret; + return ret; } /** @@ -1297,77 +1345,81 @@ xed_utils_file_has_parent (GFile *gfile) gchar * xed_utils_basename_for_display (gchar const *uri) { - gchar *name; - GFile *gfile; - gchar *hn; + gchar *name; + GFile *gfile; + gchar *hn; - g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (uri != NULL, NULL); - gfile = g_file_new_for_uri (uri); + gfile = g_file_new_for_uri (uri); - /* First, try to query the display name, but only on local files */ - if (g_file_has_uri_scheme (gfile, "file")) - { - GFileInfo *info; - info = g_file_query_info (gfile, - G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, - G_FILE_QUERY_INFO_NONE, - NULL, - NULL); + /* First, try to query the display name, but only on local files */ + if (g_file_has_uri_scheme (gfile, "file")) + { + GFileInfo *info; + info = g_file_query_info (gfile, + G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, + G_FILE_QUERY_INFO_NONE, + NULL, + NULL); - if (info) - { - /* Simply get the display name to use as the basename */ - name = g_strdup (g_file_info_get_display_name (info)); - g_object_unref (info); - } - else - { - /* This is a local file, and therefore we will use - * g_filename_display_basename on the local path */ - gchar *local_path; + if (info) + { + /* Simply get the display name to use as the basename */ + name = g_strdup (g_file_info_get_display_name (info)); + g_object_unref (info); + } + else + { + /* This is a local file, and therefore we will use + * g_filename_display_basename on the local path */ + gchar *local_path; - local_path = g_file_get_path (gfile); - name = g_filename_display_basename (local_path); - g_free (local_path); - } - } - else if (xed_utils_file_has_parent (gfile) || !xed_utils_decode_uri (uri, NULL, NULL, &hn, NULL, NULL)) - { - /* For remote files with a parent (so not just http://foo.com) - or remote file for which the decoding of the host name fails, - use the _parse_name and take basename of that */ - gchar *parse_name; - gchar *base; + local_path = g_file_get_path (gfile); + name = g_filename_display_basename (local_path); + g_free (local_path); + } + } + else if (xed_utils_file_has_parent (gfile) || !xed_utils_decode_uri (uri, NULL, NULL, &hn, NULL, NULL)) + { + /* For remote files with a parent (so not just http://foo.com) + or remote file for which the decoding of the host name fails, + use the _parse_name and take basename of that */ + gchar *parse_name; + gchar *base; - parse_name = g_file_get_parse_name (gfile); - base = g_filename_display_basename (parse_name); - name = g_uri_unescape_string (base, NULL); + parse_name = g_file_get_parse_name (gfile); + base = g_filename_display_basename (parse_name); + name = g_uri_unescape_string (base, NULL); - g_free (base); - g_free (parse_name); - } - else - { - /* display '/ on ' using the decoded host */ - gchar *hn_utf8; + g_free (base); + g_free (parse_name); + } + else + { + /* display '/ on ' using the decoded host */ + gchar *hn_utf8; - if (hn != NULL) - hn_utf8 = xed_utils_make_valid_utf8 (hn); - else - /* we should never get here */ - hn_utf8 = g_strdup ("?"); + if (hn != NULL) + { + hn_utf8 = xed_utils_make_valid_utf8 (hn); + } + else + { + /* we should never get here */ + hn_utf8 = g_strdup ("?"); + } - /* Translators: '/ on ' */ - name = g_strdup_printf (_("/ on %s"), hn_utf8); + /* Translators: '/ on ' */ + name = g_strdup_printf (_("/ on %s"), hn_utf8); - g_free (hn_utf8); - g_free (hn); - } + g_free (hn_utf8); + g_free (hn); + } - g_object_unref (gfile); + g_object_unref (gfile); - return name; + return name; } /** @@ -1384,14 +1436,14 @@ xed_utils_basename_for_display (gchar const *uri) gchar * xed_utils_uri_for_display (const gchar *uri) { - GFile *gfile; - gchar *parse_name; + GFile *gfile; + gchar *parse_name; - gfile = g_file_new_for_uri (uri); - parse_name = g_file_get_parse_name (gfile); - g_object_unref (gfile); + gfile = g_file_new_for_uri (uri); + parse_name = g_file_get_parse_name (gfile); + g_object_unref (gfile); - return parse_name; + return parse_name; } /** @@ -1401,47 +1453,51 @@ xed_utils_uri_for_display (const gchar *uri) * Create a list of valid uri's from a uri-list drop. * * Return value: (transfer full): a string array which will hold the uris or %NULL if there - * were no valid uris. g_strfreev should be used when the - * string array is no longer used + * were no valid uris. g_strfreev should be used when the + * string array is no longer used */ gchar ** xed_utils_drop_get_uris (GtkSelectionData *selection_data) { - gchar **uris; - gint i; - gint p = 0; - gchar **uri_list; + gchar **uris; + gint i; + gint p = 0; + gchar **uri_list; - uris = g_uri_list_extract_uris ((gchar *) gtk_selection_data_get_data (selection_data)); - uri_list = g_new0(gchar *, g_strv_length (uris) + 1); + uris = g_uri_list_extract_uris ((gchar *) gtk_selection_data_get_data (selection_data)); + uri_list = g_new0(gchar *, g_strv_length (uris) + 1); - for (i = 0; uris[i] != NULL; i++) - { - gchar *uri; + for (i = 0; uris[i] != NULL; i++) + { + gchar *uri; - uri = xed_utils_make_canonical_uri_from_shell_arg (uris[i]); + uri = xed_utils_make_canonical_uri_from_shell_arg (uris[i]); - /* Silently ignore malformed URI/filename */ - if (uri != NULL) - uri_list[p++] = uri; - } + /* Silently ignore malformed URI/filename */ + if (uri != NULL) + { + uri_list[p++] = uri; + } + } - g_strfreev (uris); + g_strfreev (uris); - if (*uri_list == NULL) - { - g_free(uri_list); - return NULL; - } + if (*uri_list == NULL) + { + g_free(uri_list); + return NULL; + } - return uri_list; + return uri_list; } static void null_ptr (gchar **ptr) { - if (ptr) - *ptr = NULL; + if (ptr) + { + *ptr = NULL; + } } /** @@ -1463,128 +1519,149 @@ null_ptr (gchar **ptr) */ gboolean xed_utils_decode_uri (const gchar *uri, - gchar **scheme, - gchar **user, - gchar **host, - gchar **port, - gchar **path + gchar **scheme, + gchar **user, + gchar **host, + gchar **port, + gchar **path ) { - /* Largely copied from glib/gio/gdummyfile.c:_g_decode_uri. This - * functionality should be in glib/gio, but for now we implement it - * ourselves (see bug #546182) */ + /* Largely copied from glib/gio/gdummyfile.c:_g_decode_uri. This + * functionality should be in glib/gio, but for now we implement it + * ourselves (see bug #546182) */ - const char *p, *in, *hier_part_start, *hier_part_end; - char *out; - char c; + const char *p, *in, *hier_part_start, *hier_part_end; + char *out; + char c; - /* From RFC 3986 Decodes: - * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] - */ + /* From RFC 3986 Decodes: + * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] + */ - p = uri; + p = uri; - null_ptr (scheme); - null_ptr (user); - null_ptr (port); - null_ptr (host); - null_ptr (path); + null_ptr (scheme); + null_ptr (user); + null_ptr (port); + null_ptr (host); + null_ptr (path); - /* Decode scheme: - * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) - */ + /* Decode scheme: + * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) + */ - if (!g_ascii_isalpha (*p)) - return FALSE; + if (!g_ascii_isalpha (*p)) + { + return FALSE; + } - while (1) - { - c = *p++; + while (1) + { + c = *p++; - if (c == ':') - break; + if (c == ':') + { + break; + } - if (!(g_ascii_isalnum(c) || - c == '+' || - c == '-' || - c == '.')) - return FALSE; - } + if (!(g_ascii_isalnum(c) || c == '+' || c == '-' || c == '.')) + { + return FALSE; + } + } - if (scheme) - { - *scheme = g_malloc (p - uri); - out = *scheme; + if (scheme) + { + *scheme = g_malloc (p - uri); + out = *scheme; - for (in = uri; in < p - 1; in++) - *out++ = g_ascii_tolower (*in); + for (in = uri; in < p - 1; in++) + { + *out++ = g_ascii_tolower (*in); + } - *out = '\0'; - } + *out = '\0'; + } - hier_part_start = p; - hier_part_end = p + strlen (p); + hier_part_start = p; + hier_part_end = p + strlen (p); - if (hier_part_start[0] == '/' && hier_part_start[1] == '/') - { - const char *authority_start, *authority_end; - const char *userinfo_start, *userinfo_end; - const char *host_start, *host_end; - const char *port_start; + if (hier_part_start[0] == '/' && hier_part_start[1] == '/') + { + const char *authority_start, *authority_end; + const char *userinfo_start, *userinfo_end; + const char *host_start, *host_end; + const char *port_start; - authority_start = hier_part_start + 2; - /* authority is always followed by / or nothing */ - authority_end = memchr (authority_start, '/', hier_part_end - authority_start); + authority_start = hier_part_start + 2; + /* authority is always followed by / or nothing */ + authority_end = memchr (authority_start, '/', hier_part_end - authority_start); - if (authority_end == NULL) - authority_end = hier_part_end; + if (authority_end == NULL) + { + authority_end = hier_part_end; + } - /* 3.2: - * authority = [ userinfo "@" ] host [ ":" port ] - */ + /* 3.2: + * authority = [ userinfo "@" ] host [ ":" port ] + */ - userinfo_end = memchr (authority_start, '@', authority_end - authority_start); + userinfo_end = memchr (authority_start, '@', authority_end - authority_start); - if (userinfo_end) - { - userinfo_start = authority_start; + if (userinfo_end) + { + userinfo_start = authority_start; - if (user) - *user = g_uri_unescape_segment (userinfo_start, userinfo_end, NULL); + if (user) + { + *user = g_uri_unescape_segment (userinfo_start, userinfo_end, NULL); + } - if (user && *user == NULL) - { - if (scheme) - g_free (*scheme); + if (user && *user == NULL) + { + if (scheme) + { + g_free (*scheme); + } - return FALSE; - } + return FALSE; + } - host_start = userinfo_end + 1; - } - else - host_start = authority_start; + host_start = userinfo_end + 1; + } + else + { + host_start = authority_start; + } - port_start = memchr (host_start, ':', authority_end - host_start); + port_start = memchr (host_start, ':', authority_end - host_start); - if (port_start) - { - host_end = port_start++; + if (port_start) + { + host_end = port_start++; - if (port) - *port = g_strndup (port_start, authority_end - port_start); - } - else - host_end = authority_end; + if (port) + { + *port = g_strndup (port_start, authority_end - port_start); + } + } + else + { + host_end = authority_end; + } - if (host) - *host = g_strndup (host_start, host_end - host_start); + if (host) + { + *host = g_strndup (host_start, host_end - host_start); + } - hier_part_start = authority_end; - } + hier_part_start = authority_end; + } - if (path) - *path = g_uri_unescape_segment (hier_part_start, hier_part_end, "/"); + if (path) + { + *path = g_uri_unescape_segment (hier_part_start, hier_part_end, "/"); + } - return TRUE; + return TRUE; } From ea1f2055e7fa0acab71035a2e74a09e6e6f324fa Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 1 Jan 2017 13:53:19 -0800 Subject: [PATCH 061/132] xed-utils.h: Clean up code styling --- xed/xed-utils.h | 151 ++++++++++++++++++++++++------------------------ 1 file changed, 75 insertions(+), 76 deletions(-) diff --git a/xed/xed-utils.h b/xed/xed-utils.h index c1c30f5..819dba3 100644 --- a/xed/xed-utils.h +++ b/xed/xed-utils.h @@ -18,14 +18,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 1998-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 1998-2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -48,108 +48,107 @@ G_BEGIN_DECLS enum { XED_ALL_WORKSPACES = 0xffffffff }; -gboolean xed_utils_uri_has_writable_scheme (const gchar *uri); -gboolean xed_utils_uri_has_file_scheme (const gchar *uri); +gboolean xed_utils_uri_has_writable_scheme (const gchar *uri); +gboolean xed_utils_uri_has_file_scheme (const gchar *uri); -void xed_utils_menu_position_under_widget (GtkMenu *menu, - gint *x, - gint *y, - gboolean *push_in, - gpointer user_data); +void xed_utils_menu_position_under_widget (GtkMenu *menu, + gint *x, + gint *y, + gboolean *push_in, + gpointer user_data); -void xed_utils_menu_position_under_tree_view - (GtkMenu *menu, - gint *x, - gint *y, - gboolean *push_in, - gpointer user_data); +void xed_utils_menu_position_under_tree_view (GtkMenu *menu, + gint *x, + gint *y, + gboolean *push_in, + gpointer user_data); -gchar *xed_gdk_color_to_string (GdkColor color); +gchar *xed_gdk_color_to_string (GdkColor color); -GtkWidget *xed_gtk_button_new_with_stock_icon (const gchar *label, - const gchar *stock_id); +GtkWidget *xed_gtk_button_new_with_stock_icon (const gchar *label, + const gchar *stock_id); -GtkWidget *xed_dialog_add_button (GtkDialog *dialog, - const gchar *text, - const gchar *stock_id, - gint response_id); +GtkWidget *xed_dialog_add_button (GtkDialog *dialog, + const gchar *text, + const gchar *stock_id, + gint response_id); -gchar *xed_utils_escape_underscores (const gchar *text, - gssize length); +gchar *xed_utils_escape_underscores (const gchar *text, + gssize length); -gchar *xed_utils_str_middle_truncate (const gchar *string, - guint truncate_length); +gchar *xed_utils_str_middle_truncate (const gchar *string, + guint truncate_length); -gchar *xed_utils_str_end_truncate (const gchar *string, - guint truncate_length); +gchar *xed_utils_str_end_truncate (const gchar *string, + guint truncate_length); -gboolean g_utf8_caselessnmatch (const char *s1, - const char *s2, - gssize n1, - gssize n2); +gboolean g_utf8_caselessnmatch (const char *s1, + const char *s2, + gssize n1, + gssize n2); -void xed_utils_set_atk_name_description (GtkWidget *widget, - const gchar *name, - const gchar *description); +void xed_utils_set_atk_name_description (GtkWidget *widget, + const gchar *name, + const gchar *description); -void xed_utils_set_atk_relation (GtkWidget *obj1, - GtkWidget *obj2, - AtkRelationType rel_type); +void xed_utils_set_atk_relation (GtkWidget *obj1, + GtkWidget *obj2, + AtkRelationType rel_type); -gboolean xed_utils_uri_exists (const gchar* text_uri); +gboolean xed_utils_uri_exists (const gchar* text_uri); -gchar *xed_utils_escape_search_text (const gchar *text); +gchar *xed_utils_escape_search_text (const gchar *text); -gchar *xed_utils_unescape_search_text (const gchar *text); +gchar *xed_utils_unescape_search_text (const gchar *text); -void xed_warning (GtkWindow *parent, - const gchar *format, - ...) G_GNUC_PRINTF(2, 3); +void xed_warning (GtkWindow *parent, + const gchar *format, + ...) G_GNUC_PRINTF(2, 3); -gchar *xed_utils_make_valid_utf8 (const char *name); +gchar *xed_utils_make_valid_utf8 (const char *name); /* Note that this function replace home dir with ~ */ -gchar *xed_utils_uri_get_dirname (const char *uri); +gchar *xed_utils_uri_get_dirname (const char *uri); -gchar *xed_utils_location_get_dirname_for_display - (GFile *location); +gchar *xed_utils_location_get_dirname_for_display (GFile *location); -gchar *xed_utils_replace_home_dir_with_tilde (const gchar *uri); +gchar *xed_utils_replace_home_dir_with_tilde (const gchar *uri); -guint xed_utils_get_current_workspace (GdkScreen *screen); +guint xed_utils_get_current_workspace (GdkScreen *screen); -guint xed_utils_get_window_workspace (GtkWindow *gtkwindow); +guint xed_utils_get_window_workspace (GtkWindow *gtkwindow); -void xed_utils_get_current_viewport (GdkScreen *screen, - gint *x, - gint *y); +void xed_utils_get_current_viewport (GdkScreen *screen, + gint *x, + gint *y); -gboolean xed_utils_is_valid_uri (const gchar *uri); +gboolean xed_utils_is_valid_uri (const gchar *uri); -gboolean xed_utils_get_ui_objects (const gchar *filename, - gchar **root_objects, - GtkWidget **error_widget, - const gchar *object_name, - ...) G_GNUC_NULL_TERMINATED; +gboolean xed_utils_get_ui_objects (const gchar *filename, + gchar **root_objects, + GtkWidget **error_widget, + const gchar *object_name, + ...) G_GNUC_NULL_TERMINATED; -gboolean xed_utils_file_has_parent (GFile *gfile); +gboolean xed_utils_file_has_parent (GFile *gfile); /* Return NULL if str is not a valid URI and/or filename */ -gchar *xed_utils_make_canonical_uri_from_shell_arg - (const gchar *str); - -gchar *xed_utils_uri_for_display (const gchar *uri); -gchar *xed_utils_basename_for_display (const gchar *uri); -gboolean xed_utils_decode_uri (const gchar *uri, - gchar **scheme, - gchar **user, - gchar **port, - gchar **host, - gchar **path); +gchar *xed_utils_make_canonical_uri_from_shell_arg (const gchar *str); + +gchar *xed_utils_uri_for_display (const gchar *uri); + +gchar *xed_utils_basename_for_display (const gchar *uri); + +gboolean xed_utils_decode_uri (const gchar *uri, + gchar **scheme, + gchar **user, + gchar **port, + gchar **host, + gchar **path); /* Turns data from a drop into a list of well formatted uris */ -gchar **xed_utils_drop_get_uris (GtkSelectionData *selection_data); +gchar **xed_utils_drop_get_uris (GtkSelectionData *selection_data); G_END_DECLS From 8ab7e902bb8db6ff5d1fb2b8dd732df0603a21af Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 1 Jan 2017 13:57:28 -0800 Subject: [PATCH 062/132] xed-utils: Remove a couple functions We want to move away from use of deprecated GtkStock so remove a couple of functions that rely on it. They aren't being used anywhere anyway. --- xed/xed-utils.c | 52 ------------------------------------------------- xed/xed-utils.h | 8 -------- 2 files changed, 60 deletions(-) diff --git a/xed/xed-utils.c b/xed/xed-utils.c index 984eeff..6c7ba7d 100644 --- a/xed/xed-utils.c +++ b/xed/xed-utils.c @@ -208,58 +208,6 @@ xed_gdk_color_to_string (GdkColor color) return g_strdup_printf ("#%04x%04x%04x", color.red, color.green, color.blue); } -/** - * xed_gtk_button_new_with_stock_icon: - * @label: - * @stock_id: - * - * Returns: (transfer full): - */ -GtkWidget * -xed_gtk_button_new_with_stock_icon (const gchar *label, - const gchar *stock_id) -{ - GtkWidget *button; - - button = gtk_button_new_with_mnemonic (label); - gtk_button_set_image (GTK_BUTTON (button), gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON)); - - return button; -} - -/** - * xed_dialog_add_button: - * @dialog: - * @text: - * @stock_id: - * @response_id: - * - * Returns: (transfer none): - */ -GtkWidget * -xed_dialog_add_button (GtkDialog *dialog, - const gchar *text, - const gchar *stock_id, - gint response_id) -{ - GtkWidget *button; - - g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL); - g_return_val_if_fail (text != NULL, NULL); - g_return_val_if_fail (stock_id != NULL, NULL); - - button = xed_gtk_button_new_with_stock_icon (text, stock_id); - g_return_val_if_fail (button != NULL, NULL); - - gtk_widget_set_can_default (button, TRUE); - - gtk_widget_show (button); - - gtk_dialog_add_action_widget (dialog, button, response_id); - - return button; -} - /* * n: len of the string in bytes */ diff --git a/xed/xed-utils.h b/xed/xed-utils.h index 819dba3..71f9f29 100644 --- a/xed/xed-utils.h +++ b/xed/xed-utils.h @@ -65,14 +65,6 @@ void xed_utils_menu_position_under_tree_view (GtkMenu *menu, gchar *xed_gdk_color_to_string (GdkColor color); -GtkWidget *xed_gtk_button_new_with_stock_icon (const gchar *label, - const gchar *stock_id); - -GtkWidget *xed_dialog_add_button (GtkDialog *dialog, - const gchar *text, - const gchar *stock_id, - gint response_id); - gchar *xed_utils_escape_underscores (const gchar *text, gssize length); From ded60fbe2086fff715bea68234ac0ba373569168 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 1 Jan 2017 15:41:06 -0800 Subject: [PATCH 063/132] xed-panel: Clean up more uses of GtkStock Also update a couple of the plugins that call this functionality --- plugins/filebrowser/xed-file-browser-plugin.c | 27 ++--- plugins/taglist/xed-taglist-plugin.c | 5 +- xed/xed-panel.c | 103 +----------------- xed/xed-panel.h | 7 +- xed/xed-window.c | 2 +- 5 files changed, 20 insertions(+), 124 deletions(-) diff --git a/plugins/filebrowser/xed-file-browser-plugin.c b/plugins/filebrowser/xed-file-browser-plugin.c index 2e360f7..0f28829 100644 --- a/plugins/filebrowser/xed-file-browser-plugin.c +++ b/plugins/filebrowser/xed-file-browser-plugin.c @@ -531,8 +531,8 @@ xed_file_browser_plugin_activate (PeasActivatable *activatable) XedFileBrowserPluginPrivate *data; XedWindow *window; XedPanel * panel; - GtkWidget * image; - GdkPixbuf * pixbuf; + // GtkWidget * image; + // GdkPixbuf * pixbuf; XedFileBrowserStore * store; gchar *data_dir; GSettingsSchemaSource *schema_source; @@ -578,21 +578,18 @@ xed_file_browser_plugin_activate (PeasActivatable *activatable) data); panel = xed_window_get_side_panel (window); - pixbuf = xed_file_browser_utils_pixbuf_from_theme("system-file-manager", - GTK_ICON_SIZE_MENU); + // pixbuf = xed_file_browser_utils_pixbuf_from_theme("system-file-manager", + // GTK_ICON_SIZE_MENU); - if (pixbuf) { - image = gtk_image_new_from_pixbuf(pixbuf); - g_object_unref(pixbuf); - } else { - image = gtk_image_new_from_stock(GTK_STOCK_INDEX, GTK_ICON_SIZE_MENU); - } + // if (pixbuf) { + // image = gtk_image_new_from_pixbuf(pixbuf); + // g_object_unref(pixbuf); + // } else { + // image = gtk_image_new_from_stock(GTK_STOCK_INDEX, GTK_ICON_SIZE_MENU); + // } - gtk_widget_show(image); - xed_panel_add_item (panel, - GTK_WIDGET (data->tree_widget), - _("File Browser"), - image); + // gtk_widget_show(image); + xed_panel_add_item (panel, GTK_WIDGET (data->tree_widget), _("File Browser"), "system-file-manager"); gtk_widget_show (GTK_WIDGET (data->tree_widget)); add_popup_ui (data); diff --git a/plugins/taglist/xed-taglist-plugin.c b/plugins/taglist/xed-taglist-plugin.c index 0f5076f..8d379dc 100644 --- a/plugins/taglist/xed-taglist-plugin.c +++ b/plugins/taglist/xed-taglist-plugin.c @@ -121,10 +121,7 @@ xed_taglist_plugin_activate (PeasActivatable *activatable) priv->taglist_panel = xed_taglist_plugin_panel_new (window, data_dir); g_free (data_dir); - xed_panel_add_item_with_stock_icon (side_panel, - priv->taglist_panel, - _("Tags"), - GTK_STOCK_ADD); + xed_panel_add_item (side_panel, priv->taglist_panel, _("Tags"), "list-add"); } static void diff --git a/xed/xed-panel.c b/xed/xed-panel.c index a56a22d..2877c38 100644 --- a/xed/xed-panel.c +++ b/xed/xed-panel.c @@ -323,68 +323,6 @@ xed_panel_class_init (XedPanelClass *klass) 0); } -/* This is ugly, since it supports only known - * storage types of GtkImage, otherwise fall back - * to the empty icon. - * See http://bugzilla.gnome.org/show_bug.cgi?id=317520. - */ -static void -set_gtk_image_from_gtk_image (GtkImage *image, - GtkImage *source) -{ - switch (gtk_image_get_storage_type (source)) - { - case GTK_IMAGE_EMPTY: - gtk_image_clear (image); - break; - case GTK_IMAGE_PIXBUF: - { - GdkPixbuf *pb; - - pb = gtk_image_get_pixbuf (source); - gtk_image_set_from_pixbuf (image, pb); - } - break; - case GTK_IMAGE_STOCK: - { - gchar *s_id; - GtkIconSize s; - - gtk_image_get_stock (source, &s_id, &s); - gtk_image_set_from_stock (image, s_id, s); - } - break; - case GTK_IMAGE_ICON_SET: - { - GtkIconSet *is; - GtkIconSize s; - - gtk_image_get_icon_set (source, &is, &s); - gtk_image_set_from_icon_set (image, is, s); - } - break; - case GTK_IMAGE_ANIMATION: - { - GdkPixbufAnimation *a; - - a = gtk_image_get_animation (source); - gtk_image_set_from_animation (image, a); - } - break; - case GTK_IMAGE_ICON_NAME: - { - const gchar *n; - GtkIconSize s; - - gtk_image_get_icon_name (source, &n, &s); - gtk_image_set_from_icon_name (image, n, s); - } - break; - default: - gtk_image_set_from_stock (image, GTK_STOCK_FILE, GTK_ICON_SIZE_MENU); - } -} - static void xed_panel_init (XedPanel *panel) { @@ -521,7 +459,7 @@ update_tabs_visibility (XedPanel *panel) * @panel: a #XedPanel * @item: the #GtkWidget to add to the @panel * @name: the name to be shown in the @panel - * @image: the image to be shown in the @panel + * @icon_name: the name of the icon to be shown in the @panel * * Adds a new item to the @panel. */ @@ -529,35 +467,29 @@ void xed_panel_add_item (XedPanel *panel, GtkWidget *item, const gchar *name, - GtkWidget *image) + const gchar *icon_name) { XedPanelItem *data; GtkWidget *tab_label; GtkWidget *menu_label; - gint w, h; g_return_if_fail (XED_IS_PANEL (panel)); g_return_if_fail (GTK_IS_WIDGET (item)); g_return_if_fail (name != NULL); - g_return_if_fail (image == NULL || GTK_IS_IMAGE (image)); data = g_new (XedPanelItem, 1); data->name = g_strdup (name); - if (image == NULL) + if (icon_name) { - /* default to empty */ - data->icon = gtk_image_new_from_stock (GTK_STOCK_FILE, GTK_ICON_SIZE_MENU); + data->icon = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); } else { - data->icon = image; + data->icon = gtk_image_new_from_icon_name ("text-x-generic", GTK_ICON_SIZE_MENU); } - gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &w, &h); - gtk_widget_set_size_request (data->icon, w, h); - g_object_set_data (G_OBJECT (item), PANEL_ITEM_KEY, data); tab_label = build_tab_label (panel, item, data->name, data->icon); @@ -577,31 +509,6 @@ xed_panel_add_item (XedPanel *panel, g_signal_emit (G_OBJECT (panel), signals[ITEM_ADDED], 0, item); } -/** - * xed_panel_add_item_with_stock_icon: - * @panel: a #XedPanel - * @item: the #GtkWidget to add to the @panel - * @name: the name to be shown in the @panel - * @stock_id: a stock id - * - * Same as xed_panel_add_item() but using an image from stock. - */ -void -xed_panel_add_item_with_stock_icon (XedPanel *panel, - GtkWidget *item, - const gchar *name, - const gchar *stock_id) -{ - GtkWidget *icon = NULL; - - if (stock_id != NULL) - { - icon = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU); - } - - xed_panel_add_item (panel, item, name, icon); -} - /** * xed_panel_remove_item: * @panel: a #XedPanel diff --git a/xed/xed-panel.h b/xed/xed-panel.h index b915946..667b9c4 100644 --- a/xed/xed-panel.h +++ b/xed/xed-panel.h @@ -96,12 +96,7 @@ GtkWidget *xed_panel_new (GtkOrientation orientation); void xed_panel_add_item (XedPanel *panel, GtkWidget *item, const gchar *name, - GtkWidget *image); - -void xed_panel_add_item_with_stock_icon (XedPanel *panel, - GtkWidget *item, - const gchar *name, - const gchar *stock_id); + const gchar *icon_name); gboolean xed_panel_remove_item (XedPanel *panel, GtkWidget *item); diff --git a/xed/xed-window.c b/xed/xed-window.c index 85e0c7c..797cca0 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -3177,7 +3177,7 @@ create_side_panel (XedWindow *window) g_signal_connect_after (window->priv->side_panel, "hide", G_CALLBACK (side_panel_visibility_changed), window); documents_panel = xed_documents_panel_new (window); - xed_panel_add_item_with_stock_icon (XED_PANEL (window->priv->side_panel), documents_panel, _("Documents"), + xed_panel_add_item (XED_PANEL (window->priv->side_panel), documents_panel, _("Documents"), GTK_STOCK_FILE); } From 412ce3e228ee84c8744b36161214325c9a98887f Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 1 Jan 2017 15:45:02 -0800 Subject: [PATCH 064/132] xed-panel.c: Add a couple of missing casts --- xed/xed-panel.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xed/xed-panel.c b/xed/xed-panel.c index 2877c38..81cab98 100644 --- a/xed/xed-panel.c +++ b/xed/xed-panel.c @@ -364,15 +364,15 @@ xed_panel_constructor (GType type, build_notebook_for_panel (panel); gtk_box_pack_start (GTK_BOX (panel->priv->main_box), panel->priv->notebook, TRUE, TRUE, 0); - gtk_style_context_add_class (gtk_widget_get_style_context (panel), "xed-panel"); + gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (panel)), "xed-panel"); if (panel->priv->orientation == GTK_ORIENTATION_VERTICAL) { - gtk_style_context_add_class (gtk_widget_get_style_context (panel), "side"); + gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (panel)), "side"); } else { - gtk_style_context_add_class (gtk_widget_get_style_context (panel), "bottom"); + gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (panel)), "bottom"); } return obj; From 8ebb54b824ae1bf091b81a24b782dbc2765eda33 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 1 Jan 2017 16:02:46 -0800 Subject: [PATCH 065/132] xed-status-combo-box: Don't use deprecated GtkArrow --- xed/xed-status-combo-box.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xed/xed-status-combo-box.c b/xed/xed-status-combo-box.c index 5b47495..b3a74b0 100644 --- a/xed/xed-status-combo-box.c +++ b/xed/xed-status-combo-box.c @@ -345,7 +345,7 @@ xed_status_combo_box_init (XedStatusComboBox *self) gtk_box_pack_start (GTK_BOX (self->priv->hbox), self->priv->item, TRUE, TRUE, 0); - self->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); + self->priv->arrow = gtk_image_new_from_icon_name ("pan-down-symbolic", GTK_ICON_SIZE_MENU); gtk_widget_show (self->priv->arrow); gtk_widget_set_halign (self->priv->arrow, GTK_ALIGN_CENTER); From b082e73a6117e556663f68641e6b98a5c614fa79 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 1 Jan 2017 16:12:36 -0800 Subject: [PATCH 066/132] xed-status-combo-box.c: Clean up some code styling --- xed/xed-status-combo-box.c | 85 ++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 49 deletions(-) diff --git a/xed/xed-status-combo-box.c b/xed/xed-status-combo-box.c index b3a74b0..d27d112 100644 --- a/xed/xed-status-combo-box.c +++ b/xed/xed-status-combo-box.c @@ -74,9 +74,9 @@ xed_status_combo_box_finalize (GObject *object) static void xed_status_combo_box_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { XedStatusComboBox *obj = XED_STATUS_COMBO_BOX (object); @@ -93,9 +93,9 @@ xed_status_combo_box_get_property (GObject *object, static void xed_status_combo_box_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { XedStatusComboBox *obj = XED_STATUS_COMBO_BOX (object); @@ -117,9 +117,7 @@ xed_status_combo_box_destroy (GtkWidget *widget) if (combo->priv->menu) { - g_signal_handlers_disconnect_by_func (combo->priv->menu, - menu_deactivate, - combo); + g_signal_handlers_disconnect_by_func (combo->priv->menu, menu_deactivate, combo); gtk_menu_detach (GTK_MENU (combo->priv->menu)); } @@ -128,7 +126,7 @@ xed_status_combo_box_destroy (GtkWidget *widget) static void xed_status_combo_box_changed (XedStatusComboBox *combo, - GtkMenuItem *item) + GtkMenuItem *item) { const gchar *text; @@ -189,17 +187,17 @@ xed_status_combo_box_class_init (XedStatusComboBoxClass *klass) } static void -menu_deactivate (GtkMenu *menu, +menu_deactivate (GtkMenu *menu, XedStatusComboBox *combo) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo->priv->button), FALSE); } static void -menu_position_func (GtkMenu *menu, - gint *x, - gint *y, - gboolean *push_in, +menu_position_func (GtkMenu *menu, + gint *x, + gint *y, + gboolean *push_in, XedStatusComboBox *combo) { GtkRequisition request; @@ -225,15 +223,14 @@ menu_position_func (GtkMenu *menu, static void show_menu (XedStatusComboBox *combo, - guint button, - guint32 time) + guint button, + guint32 time) { GtkRequisition request; gint max_height; GtkAllocation allocation; - gtk_widget_get_preferred_size (combo->priv->menu, - &request, NULL); + gtk_widget_get_preferred_size (combo->priv->menu, &request, NULL); /* do something relative to our own height here, maybe we can do better */ gtk_widget_get_allocation (GTK_WIDGET (combo), &allocation); @@ -257,8 +254,7 @@ show_menu (XedStatusComboBox *combo, if (combo->priv->current_item) { - gtk_menu_shell_select_item (GTK_MENU_SHELL (combo->priv->menu), - combo->priv->current_item); + gtk_menu_shell_select_item (GTK_MENU_SHELL (combo->priv->menu), combo->priv->current_item); } } @@ -274,8 +270,8 @@ menu_detached (GtkWidget *widget, } static gboolean -button_press_event (GtkWidget *widget, - GdkEventButton *event, +button_press_event (GtkWidget *widget, + GdkEventButton *event, XedStatusComboBox *combo) { if (event->type == GDK_BUTTON_PRESS && event->button == 1) @@ -354,18 +350,12 @@ xed_status_combo_box_init (XedStatusComboBox *self) gtk_box_pack_start (GTK_BOX (self->priv->hbox), self->priv->arrow, FALSE, TRUE, 0); self->priv->menu = gtk_menu_new (); - gtk_menu_attach_to_widget (GTK_MENU (self->priv->menu), - GTK_WIDGET (self), - menu_detached); + gtk_menu_attach_to_widget (GTK_MENU (self->priv->menu), GTK_WIDGET (self), menu_detached); - g_signal_connect (self->priv->button, - "button-press-event", - G_CALLBACK (button_press_event), - self); - g_signal_connect (self->priv->menu, - "deactivate", - G_CALLBACK (menu_deactivate), - self); + g_signal_connect (self->priv->button, "button-press-event", + G_CALLBACK (button_press_event), self); + g_signal_connect (self->priv->menu, "deactivate", + G_CALLBACK (menu_deactivate), self); context = gtk_widget_get_style_context (GTK_WIDGET (self->priv->button)); gtk_style_context_add_provider (context, @@ -396,7 +386,7 @@ xed_status_combo_box_new (const gchar *label) */ void xed_status_combo_box_set_label (XedStatusComboBox *combo, - const gchar *label) + const gchar *label) { gchar *text; @@ -416,7 +406,7 @@ xed_status_combo_box_get_label (XedStatusComboBox *combo) } static void -item_activated (GtkMenuItem *item, +item_activated (GtkMenuItem *item, XedStatusComboBox *combo) { xed_status_combo_box_set_item (combo, item); @@ -430,8 +420,8 @@ item_activated (GtkMenuItem *item, */ void xed_status_combo_box_add_item (XedStatusComboBox *combo, - GtkMenuItem *item, - const gchar *text) + GtkMenuItem *item, + const gchar *text) { g_return_if_fail (XED_IS_STATUS_COMBO_BOX (combo)); g_return_if_fail (GTK_IS_MENU_ITEM (item)); @@ -444,13 +434,12 @@ xed_status_combo_box_add_item (XedStatusComboBox *combo, void xed_status_combo_box_remove_item (XedStatusComboBox *combo, - GtkMenuItem *item) + GtkMenuItem *item) { g_return_if_fail (XED_IS_STATUS_COMBO_BOX (combo)); g_return_if_fail (GTK_IS_MENU_ITEM (item)); - gtk_container_remove (GTK_CONTAINER (combo->priv->menu), - GTK_WIDGET (item)); + gtk_container_remove (GTK_CONTAINER (combo->priv->menu), GTK_WIDGET (item)); } @@ -470,7 +459,7 @@ xed_status_combo_box_get_items (XedStatusComboBox *combo) const gchar * xed_status_combo_box_get_item_text (XedStatusComboBox *combo, - GtkMenuItem *item) + GtkMenuItem *item) { const gchar *ret = NULL; @@ -490,21 +479,19 @@ xed_status_combo_box_get_item_text (XedStatusComboBox *combo, */ void xed_status_combo_box_set_item_text (XedStatusComboBox *combo, - GtkMenuItem *item, - const gchar *text) + GtkMenuItem *item, + const gchar *text) { g_return_if_fail (XED_IS_STATUS_COMBO_BOX (combo)); g_return_if_fail (GTK_IS_MENU_ITEM (item)); - g_object_set_data_full (G_OBJECT (item), - COMBO_BOX_TEXT_DATA, - g_strdup (text), - (GDestroyNotify)g_free); + g_object_set_data_full (G_OBJECT (item), COMBO_BOX_TEXT_DATA, + g_strdup (text), (GDestroyNotify)g_free); } void xed_status_combo_box_set_item (XedStatusComboBox *combo, - GtkMenuItem *item) + GtkMenuItem *item) { g_return_if_fail (XED_IS_STATUS_COMBO_BOX (combo)); g_return_if_fail (GTK_IS_MENU_ITEM (item)); From baea0e93b91314fd498ba16ba6ec13a96e6a39ad Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 1 Jan 2017 18:20:19 -0800 Subject: [PATCH 067/132] xed-tab.c: Clean up code style --- xed/xed-tab.c | 3426 ++++++++++++++++++++++++------------------------- 1 file changed, 1659 insertions(+), 1767 deletions(-) diff --git a/xed/xed-tab.c b/xed/xed-tab.c index 3a09ff4..a15953c 100644 --- a/xed/xed-tab.c +++ b/xed/xed-tab.c @@ -51,46 +51,46 @@ struct _XedTabPrivate { - XedTabState state; + XedTabState state; - GtkWidget *view; - GtkWidget *view_scrolled_window; + GtkWidget *view; + GtkWidget *view_scrolled_window; - GtkWidget *message_area; - GtkWidget *print_preview; + GtkWidget *message_area; + GtkWidget *print_preview; - XedPrintJob *print_job; + XedPrintJob *print_job; - /* tmp data for saving */ - gchar *tmp_save_uri; + /* tmp data for saving */ + gchar *tmp_save_uri; - /* tmp data for loading */ - gint tmp_line_pos; - const XedEncoding *tmp_encoding; + /* tmp data for loading */ + gint tmp_line_pos; + const XedEncoding *tmp_encoding; - GTimer *timer; - guint times_called; + GTimer *timer; + guint times_called; - XedDocumentSaveFlags save_flags; + XedDocumentSaveFlags save_flags; - gint auto_save_interval; - guint auto_save_timeout; + gint auto_save_interval; + guint auto_save_timeout; - gint not_editable : 1; - gint auto_save : 1; + gint not_editable : 1; + gint auto_save : 1; - gint ask_if_externally_modified : 1; + gint ask_if_externally_modified : 1; }; G_DEFINE_TYPE(XedTab, xed_tab, GTK_TYPE_BOX) enum { - PROP_0, - PROP_NAME, - PROP_STATE, - PROP_AUTO_SAVE, - PROP_AUTO_SAVE_INTERVAL + PROP_0, + PROP_NAME, + PROP_STATE, + PROP_AUTO_SAVE, + PROP_AUTO_SAVE_INTERVAL }; static gboolean xed_tab_auto_save (XedTab *tab); @@ -98,193 +98,189 @@ static gboolean xed_tab_auto_save (XedTab *tab); static void install_auto_save_timeout (XedTab *tab) { - gint timeout; + gint timeout; - xed_debug (DEBUG_TAB); + xed_debug (DEBUG_TAB); - g_return_if_fail (tab->priv->auto_save_timeout <= 0); - g_return_if_fail (tab->priv->auto_save); - g_return_if_fail (tab->priv->auto_save_interval > 0); + g_return_if_fail (tab->priv->auto_save_timeout <= 0); + g_return_if_fail (tab->priv->auto_save); + g_return_if_fail (tab->priv->auto_save_interval > 0); - g_return_if_fail (tab->priv->state != XED_TAB_STATE_LOADING); - g_return_if_fail (tab->priv->state != XED_TAB_STATE_SAVING); - g_return_if_fail (tab->priv->state != XED_TAB_STATE_REVERTING); - g_return_if_fail (tab->priv->state != XED_TAB_STATE_LOADING_ERROR); - g_return_if_fail (tab->priv->state != XED_TAB_STATE_SAVING_ERROR); - g_return_if_fail (tab->priv->state != XED_TAB_STATE_SAVING_ERROR); - g_return_if_fail (tab->priv->state != XED_TAB_STATE_REVERTING_ERROR); + g_return_if_fail (tab->priv->state != XED_TAB_STATE_LOADING); + g_return_if_fail (tab->priv->state != XED_TAB_STATE_SAVING); + g_return_if_fail (tab->priv->state != XED_TAB_STATE_REVERTING); + g_return_if_fail (tab->priv->state != XED_TAB_STATE_LOADING_ERROR); + g_return_if_fail (tab->priv->state != XED_TAB_STATE_SAVING_ERROR); + g_return_if_fail (tab->priv->state != XED_TAB_STATE_SAVING_ERROR); + g_return_if_fail (tab->priv->state != XED_TAB_STATE_REVERTING_ERROR); - /* Add a new timeout */ - timeout = g_timeout_add_seconds (tab->priv->auto_save_interval * 60, - (GSourceFunc) xed_tab_auto_save, - tab); + /* Add a new timeout */ + timeout = g_timeout_add_seconds (tab->priv->auto_save_interval * 60, (GSourceFunc) xed_tab_auto_save, tab); - tab->priv->auto_save_timeout = timeout; + tab->priv->auto_save_timeout = timeout; } static gboolean install_auto_save_timeout_if_needed (XedTab *tab) { - XedDocument *doc; + XedDocument *doc; - xed_debug (DEBUG_TAB); + xed_debug (DEBUG_TAB); - g_return_val_if_fail (tab->priv->auto_save_timeout <= 0, FALSE); - g_return_val_if_fail ((tab->priv->state == XED_TAB_STATE_NORMAL) || - (tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW) || - (tab->priv->state == XED_TAB_STATE_CLOSING), FALSE); + g_return_val_if_fail (tab->priv->auto_save_timeout <= 0, FALSE); + g_return_val_if_fail ((tab->priv->state == XED_TAB_STATE_NORMAL) || + (tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW) || + (tab->priv->state == XED_TAB_STATE_CLOSING), FALSE); - if (tab->priv->state == XED_TAB_STATE_CLOSING) - return FALSE; + if (tab->priv->state == XED_TAB_STATE_CLOSING) + { + return FALSE; + } - doc = xed_tab_get_document (tab); + doc = xed_tab_get_document (tab); - if (tab->priv->auto_save && - !xed_document_is_untitled (doc) && - !xed_document_get_readonly (doc)) - { - install_auto_save_timeout (tab); + if (tab->priv->auto_save && !xed_document_is_untitled (doc) && !xed_document_get_readonly (doc)) + { + install_auto_save_timeout (tab); - return TRUE; - } + return TRUE; + } - return FALSE; + return FALSE; } static void remove_auto_save_timeout (XedTab *tab) { - xed_debug (DEBUG_TAB); + xed_debug (DEBUG_TAB); - /* FIXME: check sugli stati */ + /* FIXME: check sugli stati */ - g_return_if_fail (tab->priv->auto_save_timeout > 0); + g_return_if_fail (tab->priv->auto_save_timeout > 0); - g_source_remove (tab->priv->auto_save_timeout); - tab->priv->auto_save_timeout = 0; + g_source_remove (tab->priv->auto_save_timeout); + tab->priv->auto_save_timeout = 0; } static void xed_tab_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - XedTab *tab = XED_TAB (object); + XedTab *tab = XED_TAB (object); - switch (prop_id) - { - case PROP_NAME: - g_value_take_string (value, - _xed_tab_get_name (tab)); - break; - case PROP_STATE: - g_value_set_enum (value, - xed_tab_get_state (tab)); - break; - case PROP_AUTO_SAVE: - g_value_set_boolean (value, - xed_tab_get_auto_save_enabled (tab)); - break; - case PROP_AUTO_SAVE_INTERVAL: - g_value_set_int (value, - xed_tab_get_auto_save_interval (tab)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_NAME: + g_value_take_string (value, _xed_tab_get_name (tab)); + break; + case PROP_STATE: + g_value_set_enum (value, xed_tab_get_state (tab)); + break; + case PROP_AUTO_SAVE: + g_value_set_boolean (value, xed_tab_get_auto_save_enabled (tab)); + break; + case PROP_AUTO_SAVE_INTERVAL: + g_value_set_int (value, xed_tab_get_auto_save_interval (tab)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_tab_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - XedTab *tab = XED_TAB (object); + XedTab *tab = XED_TAB (object); - switch (prop_id) - { - case PROP_AUTO_SAVE: - xed_tab_set_auto_save_enabled (tab, - g_value_get_boolean (value)); - break; - case PROP_AUTO_SAVE_INTERVAL: - xed_tab_set_auto_save_interval (tab, - g_value_get_int (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_AUTO_SAVE: + xed_tab_set_auto_save_enabled (tab, g_value_get_boolean (value)); + break; + case PROP_AUTO_SAVE_INTERVAL: + xed_tab_set_auto_save_interval (tab, g_value_get_int (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_tab_finalize (GObject *object) { - XedTab *tab = XED_TAB (object); + XedTab *tab = XED_TAB (object); - if (tab->priv->timer != NULL) - g_timer_destroy (tab->priv->timer); + if (tab->priv->timer != NULL) + { + g_timer_destroy (tab->priv->timer); + } - g_free (tab->priv->tmp_save_uri); + g_free (tab->priv->tmp_save_uri); - if (tab->priv->auto_save_timeout > 0) - remove_auto_save_timeout (tab); + if (tab->priv->auto_save_timeout > 0) + { + remove_auto_save_timeout (tab); + } - G_OBJECT_CLASS (xed_tab_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_tab_parent_class)->finalize (object); } static void xed_tab_class_init (XedTabClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = xed_tab_finalize; - object_class->get_property = xed_tab_get_property; - object_class->set_property = xed_tab_set_property; + object_class->finalize = xed_tab_finalize; + object_class->get_property = xed_tab_get_property; + object_class->set_property = xed_tab_set_property; - g_object_class_install_property (object_class, - PROP_NAME, - g_param_spec_string ("name", - "Name", - "The tab's name", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, + PROP_NAME, + g_param_spec_string ("name", + "Name", + "The tab's name", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (object_class, - PROP_STATE, - g_param_spec_enum ("state", - "State", - "The tab's state", - XED_TYPE_TAB_STATE, - XED_TAB_STATE_NORMAL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, + PROP_STATE, + g_param_spec_enum ("state", + "State", + "The tab's state", + XED_TYPE_TAB_STATE, + XED_TAB_STATE_NORMAL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (object_class, - PROP_AUTO_SAVE, - g_param_spec_boolean ("autosave", - "Autosave", - "Autosave feature", - TRUE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, + PROP_AUTO_SAVE, + g_param_spec_boolean ("autosave", + "Autosave", + "Autosave feature", + TRUE, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (object_class, - PROP_AUTO_SAVE_INTERVAL, - g_param_spec_int ("autosave-interval", - "AutosaveInterval", - "Time between two autosaves", - 0, - G_MAXINT, - 0, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, + PROP_AUTO_SAVE_INTERVAL, + g_param_spec_int ("autosave-interval", + "AutosaveInterval", + "Time between two autosaves", + 0, + G_MAXINT, + 0, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); - g_type_class_add_private (object_class, sizeof (XedTabPrivate)); + g_type_class_add_private (object_class, sizeof (XedTabPrivate)); } /** @@ -298,289 +294,288 @@ xed_tab_class_init (XedTabClass *klass) XedTabState xed_tab_get_state (XedTab *tab) { - g_return_val_if_fail (XED_IS_TAB (tab), XED_TAB_STATE_NORMAL); + g_return_val_if_fail (XED_IS_TAB (tab), XED_TAB_STATE_NORMAL); - return tab->priv->state; + return tab->priv->state; } static void -set_cursor_according_to_state (GtkTextView *view, - XedTabState state) +set_cursor_according_to_state (GtkTextView *view, + XedTabState state) { - GdkCursor *cursor; - GdkWindow *text_window; - GdkWindow *left_window; + GdkCursor *cursor; + GdkWindow *text_window; + GdkWindow *left_window; - text_window = gtk_text_view_get_window (view, GTK_TEXT_WINDOW_TEXT); - left_window = gtk_text_view_get_window (view, GTK_TEXT_WINDOW_LEFT); + text_window = gtk_text_view_get_window (view, GTK_TEXT_WINDOW_TEXT); + left_window = gtk_text_view_get_window (view, GTK_TEXT_WINDOW_LEFT); - if ((state == XED_TAB_STATE_LOADING) || - (state == XED_TAB_STATE_REVERTING) || - (state == XED_TAB_STATE_SAVING) || - (state == XED_TAB_STATE_PRINTING) || - (state == XED_TAB_STATE_PRINT_PREVIEWING) || - (state == XED_TAB_STATE_CLOSING)) - { - cursor = gdk_cursor_new_for_display ( - gtk_widget_get_display (GTK_WIDGET (view)), - GDK_WATCH); + if ((state == XED_TAB_STATE_LOADING) || + (state == XED_TAB_STATE_REVERTING) || + (state == XED_TAB_STATE_SAVING) || + (state == XED_TAB_STATE_PRINTING) || + (state == XED_TAB_STATE_PRINT_PREVIEWING) || + (state == XED_TAB_STATE_CLOSING)) + { + cursor = gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (view)), GDK_WATCH); - if (text_window != NULL) - gdk_window_set_cursor (text_window, cursor); - if (left_window != NULL) - gdk_window_set_cursor (left_window, cursor); + if (text_window != NULL) + { + gdk_window_set_cursor (text_window, cursor); + } + if (left_window != NULL) + { + gdk_window_set_cursor (left_window, cursor); + } - g_object_unref (cursor); - } - else - { - cursor = gdk_cursor_new_for_display ( - gtk_widget_get_display (GTK_WIDGET (view)), - GDK_XTERM); + g_object_unref (cursor); + } + else + { + cursor = gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (view)), GDK_XTERM); - if (text_window != NULL) - gdk_window_set_cursor (text_window, cursor); - if (left_window != NULL) - gdk_window_set_cursor (left_window, NULL); + if (text_window != NULL) + { + gdk_window_set_cursor (text_window, cursor); + } + if (left_window != NULL) + { + gdk_window_set_cursor (left_window, NULL); + } - g_object_unref (cursor); - } + g_object_unref (cursor); + } } static void view_realized (GtkTextView *view, - XedTab *tab) + XedTab *tab) { - set_cursor_according_to_state (view, tab->priv->state); + set_cursor_according_to_state (view, tab->priv->state); } static void set_view_properties_according_to_state (XedTab *tab, - XedTabState state) + XedTabState state) { - gboolean val; + gboolean val; - val = ((state == XED_TAB_STATE_NORMAL) && - (tab->priv->print_preview == NULL) && - !tab->priv->not_editable); - gtk_text_view_set_editable (GTK_TEXT_VIEW (tab->priv->view), val); + val = ((state == XED_TAB_STATE_NORMAL) && (tab->priv->print_preview == NULL) && !tab->priv->not_editable); + gtk_text_view_set_editable (GTK_TEXT_VIEW (tab->priv->view), val); - val = ((state != XED_TAB_STATE_LOADING) && - (state != XED_TAB_STATE_CLOSING)); - gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (tab->priv->view), val); + val = ((state != XED_TAB_STATE_LOADING) && (state != XED_TAB_STATE_CLOSING)); + gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (tab->priv->view), val); - val = ((state != XED_TAB_STATE_LOADING) && - (state != XED_TAB_STATE_CLOSING) && - (xed_prefs_manager_get_highlight_current_line ())); - gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (tab->priv->view), val); + val = ((state != XED_TAB_STATE_LOADING) && + (state != XED_TAB_STATE_CLOSING) && + (xed_prefs_manager_get_highlight_current_line ())); + gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (tab->priv->view), val); } static void xed_tab_set_state (XedTab *tab, - XedTabState state) + XedTabState state) { - g_return_if_fail (XED_IS_TAB (tab)); - g_return_if_fail ((state >= 0) && (state < XED_TAB_NUM_OF_STATES)); + g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail ((state >= 0) && (state < XED_TAB_NUM_OF_STATES)); - if (tab->priv->state == state) - return; + if (tab->priv->state == state) + { + return; + } - tab->priv->state = state; + tab->priv->state = state; - set_view_properties_according_to_state (tab, state); + set_view_properties_according_to_state (tab, state); - if ((state == XED_TAB_STATE_LOADING_ERROR) || /* FIXME: add other states if needed */ - (state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW)) - { - gtk_widget_hide (tab->priv->view_scrolled_window); - } - else - { - if (tab->priv->print_preview == NULL) - gtk_widget_show (tab->priv->view_scrolled_window); - } + if ((state == XED_TAB_STATE_LOADING_ERROR) || /* FIXME: add other states if needed */ + (state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW)) + { + gtk_widget_hide (tab->priv->view_scrolled_window); + } + else + { + if (tab->priv->print_preview == NULL) + { + gtk_widget_show (tab->priv->view_scrolled_window); + } + } - set_cursor_according_to_state (GTK_TEXT_VIEW (tab->priv->view), - state); + set_cursor_according_to_state (GTK_TEXT_VIEW (tab->priv->view), state); - g_object_notify (G_OBJECT (tab), "state"); + g_object_notify (G_OBJECT (tab), "state"); } static void document_uri_notify_handler (XedDocument *document, - GParamSpec *pspec, - XedTab *tab) + GParamSpec *pspec, + XedTab *tab) { - xed_debug (DEBUG_TAB); + xed_debug (DEBUG_TAB); - /* Notify the change in the URI */ - g_object_notify (G_OBJECT (tab), "name"); + /* Notify the change in the URI */ + g_object_notify (G_OBJECT (tab), "name"); } static void document_shortname_notify_handler (XedDocument *document, - GParamSpec *pspec, - XedTab *tab) + GParamSpec *pspec, + XedTab *tab) { - xed_debug (DEBUG_TAB); + xed_debug (DEBUG_TAB); - /* Notify the change in the shortname */ - g_object_notify (G_OBJECT (tab), "name"); + /* Notify the change in the shortname */ + g_object_notify (G_OBJECT (tab), "name"); } static void document_modified_changed (GtkTextBuffer *document, - XedTab *tab) + XedTab *tab) { - g_object_notify (G_OBJECT (tab), "name"); + g_object_notify (G_OBJECT (tab), "name"); } static void -set_message_area (XedTab *tab, - GtkWidget *message_area) +set_message_area (XedTab *tab, + GtkWidget *message_area) { - if (tab->priv->message_area == message_area) - return; + if (tab->priv->message_area == message_area) + { + return; + } - if (tab->priv->message_area != NULL) - gtk_widget_destroy (tab->priv->message_area); + if (tab->priv->message_area != NULL) + { + gtk_widget_destroy (tab->priv->message_area); + } - tab->priv->message_area = message_area; + tab->priv->message_area = message_area; - if (message_area == NULL) - return; + if (message_area == NULL) + { + return; + } - gtk_box_pack_start (GTK_BOX (tab), - tab->priv->message_area, - FALSE, - FALSE, - 0); + gtk_box_pack_start (GTK_BOX (tab), tab->priv->message_area, FALSE, FALSE, 0); - g_object_add_weak_pointer (G_OBJECT (tab->priv->message_area), - (gpointer *)&tab->priv->message_area); + g_object_add_weak_pointer (G_OBJECT (tab->priv->message_area), (gpointer *)&tab->priv->message_area); } static void remove_tab (XedTab *tab) { - XedNotebook *notebook; + XedNotebook *notebook; - notebook = XED_NOTEBOOK (gtk_widget_get_parent (GTK_WIDGET (tab))); + notebook = XED_NOTEBOOK (gtk_widget_get_parent (GTK_WIDGET (tab))); - xed_notebook_remove_tab (notebook, tab); + xed_notebook_remove_tab (notebook, tab); } static void -io_loading_error_message_area_response (GtkWidget *message_area, - gint response_id, - XedTab *tab) +io_loading_error_message_area_response (GtkWidget *message_area, + gint response_id, + XedTab *tab) { - XedDocument *doc; - XedView *view; - gchar *uri; - const XedEncoding *encoding; + XedDocument *doc; + XedView *view; + gchar *uri; + const XedEncoding *encoding; - doc = xed_tab_get_document (tab); - g_return_if_fail (XED_IS_DOCUMENT (doc)); + doc = xed_tab_get_document (tab); + g_return_if_fail (XED_IS_DOCUMENT (doc)); - view = xed_tab_get_view (tab); - g_return_if_fail (XED_IS_VIEW (view)); + view = xed_tab_get_view (tab); + g_return_if_fail (XED_IS_VIEW (view)); - uri = xed_document_get_uri (doc); - g_return_if_fail (uri != NULL); + uri = xed_document_get_uri (doc); + g_return_if_fail (uri != NULL); - switch (response_id) - { - case GTK_RESPONSE_OK: - encoding = xed_conversion_error_message_area_get_encoding ( - GTK_WIDGET (message_area)); + switch (response_id) + { + case GTK_RESPONSE_OK: + encoding = xed_conversion_error_message_area_get_encoding (GTK_WIDGET (message_area)); - if (encoding != NULL) - { - tab->priv->tmp_encoding = encoding; - } + if (encoding != NULL) + { + tab->priv->tmp_encoding = encoding; + } - set_message_area (tab, NULL); - xed_tab_set_state (tab, XED_TAB_STATE_LOADING); + set_message_area (tab, NULL); + xed_tab_set_state (tab, XED_TAB_STATE_LOADING); - g_return_if_fail (tab->priv->auto_save_timeout <= 0); + g_return_if_fail (tab->priv->auto_save_timeout <= 0); - xed_document_load (doc, - uri, - tab->priv->tmp_encoding, - tab->priv->tmp_line_pos, - FALSE); - break; - case GTK_RESPONSE_YES: - /* This means that we want to edit the document anyway */ - set_message_area (tab, NULL); - _xed_document_set_readonly (doc, FALSE); - break; - case GTK_RESPONSE_NO: - /* We don't want to edit the document just show it */ - set_message_area (tab, NULL); - break; - default: - _xed_recent_remove (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), uri); + xed_document_load (doc, uri, tab->priv->tmp_encoding, tab->priv->tmp_line_pos, FALSE); + break; + case GTK_RESPONSE_YES: + /* This means that we want to edit the document anyway */ + set_message_area (tab, NULL); + _xed_document_set_readonly (doc, FALSE); + break; + case GTK_RESPONSE_NO: + /* We don't want to edit the document just show it */ + set_message_area (tab, NULL); + break; + default: + _xed_recent_remove (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), uri); - remove_tab (tab); - break; - } + remove_tab (tab); + break; + } - g_free (uri); + g_free (uri); } static void -file_already_open_warning_message_area_response (GtkWidget *message_area, - gint response_id, - XedTab *tab) +file_already_open_warning_message_area_response (GtkWidget *message_area, + gint response_id, + XedTab *tab) { - XedView *view; + XedView *view; - view = xed_tab_get_view (tab); + view = xed_tab_get_view (tab); - if (response_id == GTK_RESPONSE_YES) - { - tab->priv->not_editable = FALSE; + if (response_id == GTK_RESPONSE_YES) + { + tab->priv->not_editable = FALSE; - gtk_text_view_set_editable (GTK_TEXT_VIEW (view), - TRUE); - } + gtk_text_view_set_editable (GTK_TEXT_VIEW (view), TRUE); + } - gtk_widget_destroy (message_area); + gtk_widget_destroy (message_area); - gtk_widget_grab_focus (GTK_WIDGET (view)); + gtk_widget_grab_focus (GTK_WIDGET (view)); } static void -load_cancelled (GtkWidget *area, - gint response_id, - XedTab *tab) +load_cancelled (GtkWidget *area, + gint response_id, + XedTab *tab) { - g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); + g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); - g_object_ref (tab); - xed_document_load_cancel (xed_tab_get_document (tab)); - g_object_unref (tab); + g_object_ref (tab); + xed_document_load_cancel (xed_tab_get_document (tab)); + g_object_unref (tab); } static void -unrecoverable_reverting_error_message_area_response (GtkWidget *message_area, - gint response_id, - XedTab *tab) +unrecoverable_reverting_error_message_area_response (GtkWidget *message_area, + gint response_id, + XedTab *tab) { - XedView *view; + XedView *view; - xed_tab_set_state (tab, - XED_TAB_STATE_NORMAL); + xed_tab_set_state (tab, + XED_TAB_STATE_NORMAL); - set_message_area (tab, NULL); + set_message_area (tab, NULL); - view = xed_tab_get_view (tab); + view = xed_tab_get_view (tab); - gtk_widget_grab_focus (GTK_WIDGET (view)); + gtk_widget_grab_focus (GTK_WIDGET (view)); - install_auto_save_timeout_if_needed (tab); + install_auto_save_timeout_if_needed (tab); } #define MAX_MSG_LENGTH 100 @@ -588,1002 +583,915 @@ unrecoverable_reverting_error_message_area_response (GtkWidget *message_a static void show_loading_message_area (XedTab *tab) { - GtkWidget *area; - XedDocument *doc = NULL; - gchar *name; - gchar *dirname = NULL; - gchar *msg = NULL; - gchar *name_markup; - gchar *dirname_markup; - gint len; + GtkWidget *area; + XedDocument *doc = NULL; + gchar *name; + gchar *dirname = NULL; + gchar *msg = NULL; + gchar *name_markup; + gchar *dirname_markup; + gint len; - if (tab->priv->message_area != NULL) - return; + if (tab->priv->message_area != NULL) + { + return; + } - xed_debug (DEBUG_TAB); + xed_debug (DEBUG_TAB); - doc = xed_tab_get_document (tab); - g_return_if_fail (doc != NULL); + doc = xed_tab_get_document (tab); + g_return_if_fail (doc != NULL); - name = xed_document_get_short_name_for_display (doc); - len = g_utf8_strlen (name, -1); + name = xed_document_get_short_name_for_display (doc); + len = g_utf8_strlen (name, -1); - /* if the name is awfully long, truncate it and be done with it, - * otherwise also show the directory (ellipsized if needed) - */ - if (len > MAX_MSG_LENGTH) - { - gchar *str; + /* if the name is awfully long, truncate it and be done with it, + * otherwise also show the directory (ellipsized if needed) + */ + if (len > MAX_MSG_LENGTH) + { + gchar *str; - str = xed_utils_str_middle_truncate (name, MAX_MSG_LENGTH); - g_free (name); - name = str; - } - else - { - GFile *file; + str = xed_utils_str_middle_truncate (name, MAX_MSG_LENGTH); + g_free (name); + name = str; + } + else + { + GFile *file; - file = xed_document_get_location (doc); - if (file != NULL) - { - gchar *str; + file = xed_document_get_location (doc); + if (file != NULL) + { + gchar *str; - str = xed_utils_location_get_dirname_for_display (file); - g_object_unref (file); + str = xed_utils_location_get_dirname_for_display (file); + g_object_unref (file); - /* use the remaining space for the dir, but use a min of 20 chars - * so that we do not end up with a dirname like "(a...b)". - * This means that in the worst case when the filename is long 99 - * we have a title long 99 + 20, but I think it's a rare enough - * case to be acceptable. It's justa darn title afterall :) - */ - dirname = xed_utils_str_middle_truncate (str, - MAX (20, MAX_MSG_LENGTH - len)); - g_free (str); - } - } + /* use the remaining space for the dir, but use a min of 20 chars + * so that we do not end up with a dirname like "(a...b)". + * This means that in the worst case when the filename is long 99 + * we have a title long 99 + 20, but I think it's a rare enough + * case to be acceptable. It's justa darn title afterall :) + */ + dirname = xed_utils_str_middle_truncate (str, MAX (20, MAX_MSG_LENGTH - len)); + g_free (str); + } + } - name_markup = g_markup_printf_escaped ("%s", name); + name_markup = g_markup_printf_escaped ("%s", name); - if (tab->priv->state == XED_TAB_STATE_REVERTING) - { - if (dirname != NULL) - { - dirname_markup = g_markup_printf_escaped ("%s", dirname); + if (tab->priv->state == XED_TAB_STATE_REVERTING) + { + if (dirname != NULL) + { + dirname_markup = g_markup_printf_escaped ("%s", dirname); - /* Translators: the first %s is a file name (e.g. test.txt) the second one - is a directory (e.g. ssh://master.gnome.org/home/users/paolo) */ - msg = g_strdup_printf (_("Reverting %s from %s"), - name_markup, - dirname_markup); - g_free (dirname_markup); - } - else - { - msg = g_strdup_printf (_("Reverting %s"), - name_markup); - } + /* Translators: the first %s is a file name (e.g. test.txt) the second one + is a directory (e.g. ssh://master.gnome.org/home/users/paolo) */ + msg = g_strdup_printf (_("Reverting %s from %s"), name_markup, dirname_markup); + g_free (dirname_markup); + } + else + { + msg = g_strdup_printf (_("Reverting %s"), name_markup); + } - area = xed_progress_message_area_new (GTK_STOCK_REVERT_TO_SAVED, - msg, - TRUE); - } - else - { - if (dirname != NULL) - { - dirname_markup = g_markup_printf_escaped ("%s", dirname); + area = xed_progress_message_area_new (GTK_STOCK_REVERT_TO_SAVED, msg, TRUE); + } + else + { + if (dirname != NULL) + { + dirname_markup = g_markup_printf_escaped ("%s", dirname); - /* Translators: the first %s is a file name (e.g. test.txt) the second one - is a directory (e.g. ssh://master.gnome.org/home/users/paolo) */ - msg = g_strdup_printf (_("Loading %s from %s"), - name_markup, - dirname_markup); - g_free (dirname_markup); - } - else - { - msg = g_strdup_printf (_("Loading %s"), - name_markup); - } + /* Translators: the first %s is a file name (e.g. test.txt) the second one + is a directory (e.g. ssh://master.gnome.org/home/users/paolo) */ + msg = g_strdup_printf (_("Loading %s from %s"), name_markup, dirname_markup); + g_free (dirname_markup); + } + else + { + msg = g_strdup_printf (_("Loading %s"), name_markup); + } - area = xed_progress_message_area_new (GTK_STOCK_OPEN, - msg, - TRUE); - } + area = xed_progress_message_area_new (GTK_STOCK_OPEN, msg, TRUE); + } - g_signal_connect (area, - "response", - G_CALLBACK (load_cancelled), - tab); + g_signal_connect (area, "response", + G_CALLBACK (load_cancelled), tab); - gtk_widget_show (area); + gtk_widget_show (area); - set_message_area (tab, area); + set_message_area (tab, area); - g_free (msg); - g_free (name); - g_free (name_markup); - g_free (dirname); + g_free (msg); + g_free (name); + g_free (name_markup); + g_free (dirname); } static void show_saving_message_area (XedTab *tab) { - GtkWidget *area; - XedDocument *doc = NULL; - gchar *short_name; - gchar *from; - gchar *to = NULL; - gchar *from_markup; - gchar *to_markup; - gchar *msg = NULL; - gint len; + GtkWidget *area; + XedDocument *doc = NULL; + gchar *short_name; + gchar *from; + gchar *to = NULL; + gchar *from_markup; + gchar *to_markup; + gchar *msg = NULL; + gint len; - g_return_if_fail (tab->priv->tmp_save_uri != NULL); + g_return_if_fail (tab->priv->tmp_save_uri != NULL); - if (tab->priv->message_area != NULL) - return; + if (tab->priv->message_area != NULL) + { + return; + } - xed_debug (DEBUG_TAB); + xed_debug (DEBUG_TAB); - doc = xed_tab_get_document (tab); - g_return_if_fail (doc != NULL); + doc = xed_tab_get_document (tab); + g_return_if_fail (doc != NULL); - short_name = xed_document_get_short_name_for_display (doc); + short_name = xed_document_get_short_name_for_display (doc); - len = g_utf8_strlen (short_name, -1); + len = g_utf8_strlen (short_name, -1); - /* if the name is awfully long, truncate it and be done with it, - * otherwise also show the directory (ellipsized if needed) - */ - if (len > MAX_MSG_LENGTH) - { - from = xed_utils_str_middle_truncate (short_name, - MAX_MSG_LENGTH); - g_free (short_name); - } - else - { - gchar *str; + /* if the name is awfully long, truncate it and be done with it, + * otherwise also show the directory (ellipsized if needed) + */ + if (len > MAX_MSG_LENGTH) + { + from = xed_utils_str_middle_truncate (short_name, MAX_MSG_LENGTH); + g_free (short_name); + } + else + { + gchar *str; - from = short_name; + from = short_name; - to = xed_utils_uri_for_display (tab->priv->tmp_save_uri); + to = xed_utils_uri_for_display (tab->priv->tmp_save_uri); - str = xed_utils_str_middle_truncate (to, - MAX (20, MAX_MSG_LENGTH - len)); - g_free (to); + str = xed_utils_str_middle_truncate (to, MAX (20, MAX_MSG_LENGTH - len)); + g_free (to); - to = str; - } + to = str; + } - from_markup = g_markup_printf_escaped ("%s", from); + from_markup = g_markup_printf_escaped ("%s", from); - if (to != NULL) - { - to_markup = g_markup_printf_escaped ("%s", to); + if (to != NULL) + { + to_markup = g_markup_printf_escaped ("%s", to); - /* Translators: the first %s is a file name (e.g. test.txt) the second one - is a directory (e.g. ssh://master.gnome.org/home/users/paolo) */ - msg = g_strdup_printf (_("Saving %s to %s"), - from_markup, - to_markup); - g_free (to_markup); - } - else - { - msg = g_strdup_printf (_("Saving %s"), from_markup); - } + /* Translators: the first %s is a file name (e.g. test.txt) the second one + is a directory (e.g. ssh://master.gnome.org/home/users/paolo) */ + msg = g_strdup_printf (_("Saving %s to %s"), from_markup, to_markup); + g_free (to_markup); + } + else + { + msg = g_strdup_printf (_("Saving %s"), from_markup); + } - area = xed_progress_message_area_new (GTK_STOCK_SAVE, - msg, - FALSE); + area = xed_progress_message_area_new (GTK_STOCK_SAVE, msg, FALSE); - gtk_widget_show (area); + gtk_widget_show (area); - set_message_area (tab, area); + set_message_area (tab, area); - g_free (msg); - g_free (to); - g_free (from); - g_free (from_markup); + g_free (msg); + g_free (to); + g_free (from); + g_free (from_markup); } static void -message_area_set_progress (XedTab *tab, - goffset size, - goffset total_size) +message_area_set_progress (XedTab *tab, + goffset size, + goffset total_size) { - if (tab->priv->message_area == NULL) - return; + if (tab->priv->message_area == NULL) + { + return; + } - xed_debug_message (DEBUG_TAB, "%" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, size, total_size); + xed_debug_message (DEBUG_TAB, "%" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, size, total_size); - g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); + g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); - if (total_size == 0) - { - if (size != 0) - xed_progress_message_area_pulse ( - XED_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); - else - xed_progress_message_area_set_fraction ( - XED_PROGRESS_MESSAGE_AREA (tab->priv->message_area), - 0); - } - else - { - gdouble frac; + if (total_size == 0) + { + if (size != 0) + xed_progress_message_area_pulse (XED_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); + else + xed_progress_message_area_set_fraction (XED_PROGRESS_MESSAGE_AREA (tab->priv->message_area), 0); + } + else + { + gdouble frac; - frac = (gdouble)size / (gdouble)total_size; + frac = (gdouble)size / (gdouble)total_size; - xed_progress_message_area_set_fraction ( - XED_PROGRESS_MESSAGE_AREA (tab->priv->message_area), - frac); - } + xed_progress_message_area_set_fraction (XED_PROGRESS_MESSAGE_AREA (tab->priv->message_area), frac); + } } static void document_loading (XedDocument *document, - goffset size, - goffset total_size, - XedTab *tab) + goffset size, + goffset total_size, + XedTab *tab) { - gdouble et; - gdouble total_time; + gdouble et; + gdouble total_time; - g_return_if_fail ((tab->priv->state == XED_TAB_STATE_LOADING) || - (tab->priv->state == XED_TAB_STATE_REVERTING)); + g_return_if_fail ((tab->priv->state == XED_TAB_STATE_LOADING) || (tab->priv->state == XED_TAB_STATE_REVERTING)); - xed_debug_message (DEBUG_TAB, "%" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, size, total_size); + xed_debug_message (DEBUG_TAB, "%" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, size, total_size); - if (tab->priv->timer == NULL) - { - g_return_if_fail (tab->priv->times_called == 0); - tab->priv->timer = g_timer_new (); - } + if (tab->priv->timer == NULL) + { + g_return_if_fail (tab->priv->times_called == 0); + tab->priv->timer = g_timer_new (); + } - et = g_timer_elapsed (tab->priv->timer, NULL); + et = g_timer_elapsed (tab->priv->timer, NULL); - /* et : total_time = size : total_size */ - total_time = (et * total_size) / size; + /* et : total_time = size : total_size */ + total_time = (et * total_size) / size; - if ((total_time - et) > 3.0) - { - show_loading_message_area (tab); - } + if ((total_time - et) > 3.0) + { + show_loading_message_area (tab); + } - message_area_set_progress (tab, size, total_size); + message_area_set_progress (tab, size, total_size); } static gboolean remove_tab_idle (XedTab *tab) { - remove_tab (tab); + remove_tab (tab); - return FALSE; + return FALSE; } static void -document_loaded (XedDocument *document, - const GError *error, - XedTab *tab) +document_loaded (XedDocument *document, + const GError *error, + XedTab *tab) { - GtkWidget *emsg; - GFile *location; - gchar *uri; - const XedEncoding *encoding; + GtkWidget *emsg; + GFile *location; + gchar *uri; + const XedEncoding *encoding; - g_return_if_fail ((tab->priv->state == XED_TAB_STATE_LOADING) || - (tab->priv->state == XED_TAB_STATE_REVERTING)); - g_return_if_fail (tab->priv->auto_save_timeout <= 0); + g_return_if_fail ((tab->priv->state == XED_TAB_STATE_LOADING) || (tab->priv->state == XED_TAB_STATE_REVERTING)); + g_return_if_fail (tab->priv->auto_save_timeout <= 0); - if (tab->priv->timer != NULL) - { - g_timer_destroy (tab->priv->timer); - tab->priv->timer = NULL; - } - tab->priv->times_called = 0; + if (tab->priv->timer != NULL) + { + g_timer_destroy (tab->priv->timer); + tab->priv->timer = NULL; + } + tab->priv->times_called = 0; - set_message_area (tab, NULL); + set_message_area (tab, NULL); - location = xed_document_get_location (document); - uri = xed_document_get_uri (document); + location = xed_document_get_location (document); + uri = xed_document_get_uri (document); - /* if the error is CONVERSION FALLBACK don't treat it as a normal error */ - if (error != NULL && - (error->domain != XED_DOCUMENT_ERROR || error->code != XED_DOCUMENT_ERROR_CONVERSION_FALLBACK)) - { - if (tab->priv->state == XED_TAB_STATE_LOADING) - xed_tab_set_state (tab, XED_TAB_STATE_LOADING_ERROR); - else - xed_tab_set_state (tab, XED_TAB_STATE_REVERTING_ERROR); + /* if the error is CONVERSION FALLBACK don't treat it as a normal error */ + if (error != NULL && (error->domain != XED_DOCUMENT_ERROR || error->code != XED_DOCUMENT_ERROR_CONVERSION_FALLBACK)) + { + if (tab->priv->state == XED_TAB_STATE_LOADING) + { + xed_tab_set_state (tab, XED_TAB_STATE_LOADING_ERROR); + } + else + { + xed_tab_set_state (tab, XED_TAB_STATE_REVERTING_ERROR); + } - encoding = xed_document_get_encoding (document); + encoding = xed_document_get_encoding (document); - if (error->domain == G_IO_ERROR && - error->code == G_IO_ERROR_CANCELLED) - { - /* remove the tab, but in an idle handler, since - * we are in the handler of doc loaded and we - * don't want doc and tab to be finalized now. - */ - g_idle_add ((GSourceFunc) remove_tab_idle, tab); + if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED) + { + /* remove the tab, but in an idle handler, since + * we are in the handler of doc loaded and we + * don't want doc and tab to be finalized now. + */ + g_idle_add ((GSourceFunc) remove_tab_idle, tab); - goto end; - } - else - { - _xed_recent_remove (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), uri); + goto end; + } + else + { + _xed_recent_remove (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), uri); - if (tab->priv->state == XED_TAB_STATE_LOADING_ERROR) - { - emsg = xed_io_loading_error_message_area_new (uri, - tab->priv->tmp_encoding, - error); - g_signal_connect (emsg, - "response", - G_CALLBACK (io_loading_error_message_area_response), - tab); - } - else - { - g_return_if_fail (tab->priv->state == XED_TAB_STATE_REVERTING_ERROR); + if (tab->priv->state == XED_TAB_STATE_LOADING_ERROR) + { + emsg = xed_io_loading_error_message_area_new (uri, tab->priv->tmp_encoding, error); + g_signal_connect (emsg, "response", + G_CALLBACK (io_loading_error_message_area_response), tab); + } + else + { + g_return_if_fail (tab->priv->state == XED_TAB_STATE_REVERTING_ERROR); - emsg = xed_unrecoverable_reverting_error_message_area_new (uri, - error); + emsg = xed_unrecoverable_reverting_error_message_area_new (uri, error); - g_signal_connect (emsg, - "response", - G_CALLBACK (unrecoverable_reverting_error_message_area_response), - tab); - } + g_signal_connect (emsg, "response", + G_CALLBACK (unrecoverable_reverting_error_message_area_response), tab); + } - set_message_area (tab, emsg); - } + set_message_area (tab, emsg); + } - gtk_info_bar_set_default_response (GTK_INFO_BAR (emsg), - GTK_RESPONSE_CANCEL); + gtk_info_bar_set_default_response (GTK_INFO_BAR (emsg), GTK_RESPONSE_CANCEL); - gtk_widget_show (emsg); + gtk_widget_show (emsg); - g_object_unref (location); - g_free (uri); + g_object_unref (location); + g_free (uri); - return; - } - else - { - gchar *mime; - GList *all_documents; - GList *l; + return; + } + else + { + gchar *mime; + GList *all_documents; + GList *l; - g_return_if_fail (uri != NULL); + g_return_if_fail (uri != NULL); - mime = xed_document_get_mime_type (document); - _xed_recent_add (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), - uri, - mime); - g_free (mime); + mime = xed_document_get_mime_type (document); + _xed_recent_add (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), uri, mime); + g_free (mime); - if (error && - error->domain == XED_DOCUMENT_ERROR && - error->code == XED_DOCUMENT_ERROR_CONVERSION_FALLBACK) - { - GtkWidget *emsg; + if (error && error->domain == XED_DOCUMENT_ERROR && error->code == XED_DOCUMENT_ERROR_CONVERSION_FALLBACK) + { + GtkWidget *emsg; - _xed_document_set_readonly (document, TRUE); + _xed_document_set_readonly (document, TRUE); - emsg = xed_io_loading_error_message_area_new (uri, - tab->priv->tmp_encoding, - error); + emsg = xed_io_loading_error_message_area_new (uri, tab->priv->tmp_encoding, error); - set_message_area (tab, emsg); + set_message_area (tab, emsg); - g_signal_connect (emsg, - "response", - G_CALLBACK (io_loading_error_message_area_response), - tab); + g_signal_connect (emsg, "response", + G_CALLBACK (io_loading_error_message_area_response), tab); - gtk_info_bar_set_default_response (GTK_INFO_BAR (emsg), - GTK_RESPONSE_CANCEL); + gtk_info_bar_set_default_response (GTK_INFO_BAR (emsg), GTK_RESPONSE_CANCEL); - gtk_widget_show (emsg); - } + gtk_widget_show (emsg); + } - /* Scroll to the cursor when the document is loaded */ - xed_view_scroll_to_cursor (XED_VIEW (tab->priv->view)); + /* Scroll to the cursor when the document is loaded */ + xed_view_scroll_to_cursor (XED_VIEW (tab->priv->view)); - all_documents = xed_app_get_documents (xed_app_get_default ()); + all_documents = xed_app_get_documents (xed_app_get_default ()); - for (l = all_documents; l != NULL; l = g_list_next (l)) - { - XedDocument *d = XED_DOCUMENT (l->data); + for (l = all_documents; l != NULL; l = g_list_next (l)) + { + XedDocument *d = XED_DOCUMENT (l->data); - if (d != document) - { - GFile *loc; + if (d != document) + { + GFile *loc; - loc = xed_document_get_location (d); + loc = xed_document_get_location (d); - if ((loc != NULL) && - g_file_equal (location, loc)) - { - GtkWidget *w; - XedView *view; + if ((loc != NULL) && g_file_equal (location, loc)) + { + GtkWidget *w; + XedView *view; - view = xed_tab_get_view (tab); + view = xed_tab_get_view (tab); - tab->priv->not_editable = TRUE; + tab->priv->not_editable = TRUE; - w = xed_file_already_open_warning_message_area_new (uri); + w = xed_file_already_open_warning_message_area_new (uri); - set_message_area (tab, w); + set_message_area (tab, w); - gtk_info_bar_set_default_response (GTK_INFO_BAR (w), - GTK_RESPONSE_CANCEL); + gtk_info_bar_set_default_response (GTK_INFO_BAR (w), GTK_RESPONSE_CANCEL); - gtk_widget_show (w); + gtk_widget_show (w); - g_signal_connect (w, - "response", - G_CALLBACK (file_already_open_warning_message_area_response), - tab); + g_signal_connect (w, "response", + G_CALLBACK (file_already_open_warning_message_area_response), tab); - g_object_unref (loc); - break; - } + g_object_unref (loc); + break; + } - if (loc != NULL) - g_object_unref (loc); - } - } + if (loc != NULL) + { + g_object_unref (loc); + } + } + } - g_list_free (all_documents); + g_list_free (all_documents); - xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); + xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); - install_auto_save_timeout_if_needed (tab); + install_auto_save_timeout_if_needed (tab); - tab->priv->ask_if_externally_modified = TRUE; - } + tab->priv->ask_if_externally_modified = TRUE; + } end: - g_object_unref (location); - g_free (uri); + g_object_unref (location); + g_free (uri); - tab->priv->tmp_line_pos = 0; - tab->priv->tmp_encoding = NULL; + tab->priv->tmp_line_pos = 0; + tab->priv->tmp_encoding = NULL; } static void -document_saving (XedDocument *document, - goffset size, - goffset total_size, - XedTab *tab) +document_saving (XedDocument *document, + goffset size, + goffset total_size, + XedTab *tab) { - gdouble et; - gdouble total_time; + gdouble et; + gdouble total_time; - g_return_if_fail (tab->priv->state == XED_TAB_STATE_SAVING); + g_return_if_fail (tab->priv->state == XED_TAB_STATE_SAVING); - xed_debug_message (DEBUG_TAB, "%" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, size, total_size); + xed_debug_message (DEBUG_TAB, "%" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, size, total_size); - if (tab->priv->timer == NULL) - { - g_return_if_fail (tab->priv->times_called == 0); - tab->priv->timer = g_timer_new (); - } + if (tab->priv->timer == NULL) + { + g_return_if_fail (tab->priv->times_called == 0); + tab->priv->timer = g_timer_new (); + } - et = g_timer_elapsed (tab->priv->timer, NULL); + et = g_timer_elapsed (tab->priv->timer, NULL); - /* et : total_time = size : total_size */ - total_time = (et * total_size)/size; + /* et : total_time = size : total_size */ + total_time = (et * total_size)/size; - if ((total_time - et) > 3.0) - { - show_saving_message_area (tab); - } + if ((total_time - et) > 3.0) + { + show_saving_message_area (tab); + } - message_area_set_progress (tab, size, total_size); + message_area_set_progress (tab, size, total_size); - tab->priv->times_called++; + tab->priv->times_called++; } static void end_saving (XedTab *tab) { - /* Reset tmp data for saving */ - g_free (tab->priv->tmp_save_uri); - tab->priv->tmp_save_uri = NULL; - tab->priv->tmp_encoding = NULL; + /* Reset tmp data for saving */ + g_free (tab->priv->tmp_save_uri); + tab->priv->tmp_save_uri = NULL; + tab->priv->tmp_encoding = NULL; - install_auto_save_timeout_if_needed (tab); + install_auto_save_timeout_if_needed (tab); } static void -unrecoverable_saving_error_message_area_response (GtkWidget *message_area, - gint response_id, - XedTab *tab) +unrecoverable_saving_error_message_area_response (GtkWidget *message_area, + gint response_id, + XedTab *tab) { - XedView *view; + XedView *view; - if (tab->priv->print_preview != NULL) - xed_tab_set_state (tab, XED_TAB_STATE_SHOWING_PRINT_PREVIEW); - else - xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); + if (tab->priv->print_preview != NULL) + { + xed_tab_set_state (tab, XED_TAB_STATE_SHOWING_PRINT_PREVIEW); + } + else + { + xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); + } - end_saving (tab); + end_saving (tab); - set_message_area (tab, NULL); + set_message_area (tab, NULL); - view = xed_tab_get_view (tab); + view = xed_tab_get_view (tab); - gtk_widget_grab_focus (GTK_WIDGET (view)); + gtk_widget_grab_focus (GTK_WIDGET (view)); } static void -no_backup_error_message_area_response (GtkWidget *message_area, - gint response_id, - XedTab *tab) +no_backup_error_message_area_response (GtkWidget *message_area, + gint response_id, + XedTab *tab) { - if (response_id == GTK_RESPONSE_YES) - { - XedDocument *doc; + if (response_id == GTK_RESPONSE_YES) + { + XedDocument *doc; - doc = xed_tab_get_document (tab); - g_return_if_fail (XED_IS_DOCUMENT (doc)); + doc = xed_tab_get_document (tab); + g_return_if_fail (XED_IS_DOCUMENT (doc)); - set_message_area (tab, NULL); + set_message_area (tab, NULL); - g_return_if_fail (tab->priv->tmp_save_uri != NULL); - g_return_if_fail (tab->priv->tmp_encoding != NULL); + g_return_if_fail (tab->priv->tmp_save_uri != NULL); + g_return_if_fail (tab->priv->tmp_encoding != NULL); - xed_tab_set_state (tab, XED_TAB_STATE_SAVING); + xed_tab_set_state (tab, XED_TAB_STATE_SAVING); - /* don't bug the user again with this... */ - tab->priv->save_flags |= XED_DOCUMENT_SAVE_IGNORE_BACKUP; + /* don't bug the user again with this... */ + tab->priv->save_flags |= XED_DOCUMENT_SAVE_IGNORE_BACKUP; - g_return_if_fail (tab->priv->auto_save_timeout <= 0); + g_return_if_fail (tab->priv->auto_save_timeout <= 0); - /* Force saving */ - xed_document_save (doc, tab->priv->save_flags); - } - else - { - unrecoverable_saving_error_message_area_response (message_area, - response_id, - tab); - } + /* Force saving */ + xed_document_save (doc, tab->priv->save_flags); + } + else + { + unrecoverable_saving_error_message_area_response (message_area, response_id, tab); + } } static void -externally_modified_error_message_area_response (GtkWidget *message_area, - gint response_id, - XedTab *tab) +externally_modified_error_message_area_response (GtkWidget *message_area, + gint response_id, + XedTab *tab) { - if (response_id == GTK_RESPONSE_YES) - { - XedDocument *doc; + if (response_id == GTK_RESPONSE_YES) + { + XedDocument *doc; - doc = xed_tab_get_document (tab); - g_return_if_fail (XED_IS_DOCUMENT (doc)); + doc = xed_tab_get_document (tab); + g_return_if_fail (XED_IS_DOCUMENT (doc)); - set_message_area (tab, NULL); + set_message_area (tab, NULL); - g_return_if_fail (tab->priv->tmp_save_uri != NULL); - g_return_if_fail (tab->priv->tmp_encoding != NULL); + g_return_if_fail (tab->priv->tmp_save_uri != NULL); + g_return_if_fail (tab->priv->tmp_encoding != NULL); - xed_tab_set_state (tab, XED_TAB_STATE_SAVING); + xed_tab_set_state (tab, XED_TAB_STATE_SAVING); - g_return_if_fail (tab->priv->auto_save_timeout <= 0); + g_return_if_fail (tab->priv->auto_save_timeout <= 0); - /* ignore mtime should not be persisted in save flags across saves */ + /* ignore mtime should not be persisted in save flags across saves */ - /* Force saving */ - xed_document_save (doc, tab->priv->save_flags | XED_DOCUMENT_SAVE_IGNORE_MTIME); - } - else - { - unrecoverable_saving_error_message_area_response (message_area, - response_id, - tab); - } + /* Force saving */ + xed_document_save (doc, tab->priv->save_flags | XED_DOCUMENT_SAVE_IGNORE_MTIME); + } + else + { + unrecoverable_saving_error_message_area_response (message_area, response_id, tab); + } } static void -recoverable_saving_error_message_area_response (GtkWidget *message_area, - gint response_id, - XedTab *tab) +recoverable_saving_error_message_area_response (GtkWidget *message_area, + gint response_id, + XedTab *tab) { - XedDocument *doc; + XedDocument *doc; - doc = xed_tab_get_document (tab); - g_return_if_fail (XED_IS_DOCUMENT (doc)); + doc = xed_tab_get_document (tab); + g_return_if_fail (XED_IS_DOCUMENT (doc)); - if (response_id == GTK_RESPONSE_OK) - { - const XedEncoding *encoding; + if (response_id == GTK_RESPONSE_OK) + { + const XedEncoding *encoding; - encoding = xed_conversion_error_message_area_get_encoding ( - GTK_WIDGET (message_area)); + encoding = xed_conversion_error_message_area_get_encoding (GTK_WIDGET (message_area)); - g_return_if_fail (encoding != NULL); + g_return_if_fail (encoding != NULL); - set_message_area (tab, NULL); + set_message_area (tab, NULL); - g_return_if_fail (tab->priv->tmp_save_uri != NULL); + g_return_if_fail (tab->priv->tmp_save_uri != NULL); - xed_tab_set_state (tab, XED_TAB_STATE_SAVING); + xed_tab_set_state (tab, XED_TAB_STATE_SAVING); - tab->priv->tmp_encoding = encoding; + tab->priv->tmp_encoding = encoding; - xed_debug_message (DEBUG_TAB, "Force saving with URI '%s'", tab->priv->tmp_save_uri); + xed_debug_message (DEBUG_TAB, "Force saving with URI '%s'", tab->priv->tmp_save_uri); - g_return_if_fail (tab->priv->auto_save_timeout <= 0); + g_return_if_fail (tab->priv->auto_save_timeout <= 0); - xed_document_save_as (doc, - tab->priv->tmp_save_uri, - tab->priv->tmp_encoding, - tab->priv->save_flags); - } - else - { - unrecoverable_saving_error_message_area_response (message_area, - response_id, - tab); - } + xed_document_save_as (doc, tab->priv->tmp_save_uri, tab->priv->tmp_encoding, tab->priv->save_flags); + } + else + { + unrecoverable_saving_error_message_area_response (message_area, response_id, tab); + } } static void -document_saved (XedDocument *document, - const GError *error, - XedTab *tab) +document_saved (XedDocument *document, + const GError *error, + XedTab *tab) { - GtkWidget *emsg; + GtkWidget *emsg; - g_return_if_fail (tab->priv->state == XED_TAB_STATE_SAVING); + g_return_if_fail (tab->priv->state == XED_TAB_STATE_SAVING); - g_return_if_fail (tab->priv->tmp_save_uri != NULL); - g_return_if_fail (tab->priv->tmp_encoding != NULL); - g_return_if_fail (tab->priv->auto_save_timeout <= 0); + g_return_if_fail (tab->priv->tmp_save_uri != NULL); + g_return_if_fail (tab->priv->tmp_encoding != NULL); + g_return_if_fail (tab->priv->auto_save_timeout <= 0); - g_timer_destroy (tab->priv->timer); - tab->priv->timer = NULL; - tab->priv->times_called = 0; + g_timer_destroy (tab->priv->timer); + tab->priv->timer = NULL; + tab->priv->times_called = 0; - set_message_area (tab, NULL); + set_message_area (tab, NULL); - if (error != NULL) - { - xed_tab_set_state (tab, XED_TAB_STATE_SAVING_ERROR); + if (error != NULL) + { + xed_tab_set_state (tab, XED_TAB_STATE_SAVING_ERROR); - if (error->domain == XED_DOCUMENT_ERROR && - error->code == XED_DOCUMENT_ERROR_EXTERNALLY_MODIFIED) - { - /* This error is recoverable */ - emsg = xed_externally_modified_saving_error_message_area_new ( - tab->priv->tmp_save_uri, - error); - g_return_if_fail (emsg != NULL); + if (error->domain == XED_DOCUMENT_ERROR && error->code == XED_DOCUMENT_ERROR_EXTERNALLY_MODIFIED) + { + /* This error is recoverable */ + emsg = xed_externally_modified_saving_error_message_area_new (tab->priv->tmp_save_uri, error); + g_return_if_fail (emsg != NULL); - set_message_area (tab, emsg); + set_message_area (tab, emsg); - g_signal_connect (emsg, - "response", - G_CALLBACK (externally_modified_error_message_area_response), - tab); - } - else if ((error->domain == XED_DOCUMENT_ERROR && - error->code == XED_DOCUMENT_ERROR_CANT_CREATE_BACKUP) || - (error->domain == G_IO_ERROR && - error->code == G_IO_ERROR_CANT_CREATE_BACKUP)) - { - /* This error is recoverable */ - emsg = xed_no_backup_saving_error_message_area_new ( - tab->priv->tmp_save_uri, - error); - g_return_if_fail (emsg != NULL); + g_signal_connect (emsg, "response", + G_CALLBACK (externally_modified_error_message_area_response), tab); + } + else if ((error->domain == XED_DOCUMENT_ERROR && + error->code == XED_DOCUMENT_ERROR_CANT_CREATE_BACKUP) || + (error->domain == G_IO_ERROR && + error->code == G_IO_ERROR_CANT_CREATE_BACKUP)) + { + /* This error is recoverable */ + emsg = xed_no_backup_saving_error_message_area_new (tab->priv->tmp_save_uri, error); + g_return_if_fail (emsg != NULL); - set_message_area (tab, emsg); + set_message_area (tab, emsg); - g_signal_connect (emsg, - "response", - G_CALLBACK (no_backup_error_message_area_response), - tab); - } - else if (error->domain == XED_DOCUMENT_ERROR || - (error->domain == G_IO_ERROR && - error->code != G_IO_ERROR_INVALID_DATA && - error->code != G_IO_ERROR_PARTIAL_INPUT)) - { - /* These errors are _NOT_ recoverable */ - _xed_recent_remove (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), - tab->priv->tmp_save_uri); + g_signal_connect (emsg, "response", + G_CALLBACK (no_backup_error_message_area_response), tab); + } + else if (error->domain == XED_DOCUMENT_ERROR || + (error->domain == G_IO_ERROR && + error->code != G_IO_ERROR_INVALID_DATA && + error->code != G_IO_ERROR_PARTIAL_INPUT)) + { + /* These errors are _NOT_ recoverable */ + _xed_recent_remove (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), tab->priv->tmp_save_uri); - emsg = xed_unrecoverable_saving_error_message_area_new (tab->priv->tmp_save_uri, - error); - g_return_if_fail (emsg != NULL); + emsg = xed_unrecoverable_saving_error_message_area_new (tab->priv->tmp_save_uri, error); + g_return_if_fail (emsg != NULL); - set_message_area (tab, emsg); + set_message_area (tab, emsg); - g_signal_connect (emsg, - "response", - G_CALLBACK (unrecoverable_saving_error_message_area_response), - tab); - } - else - { - /* This error is recoverable */ - g_return_if_fail (error->domain == G_CONVERT_ERROR || - error->domain == G_IO_ERROR); + g_signal_connect (emsg, "response", + G_CALLBACK (unrecoverable_saving_error_message_area_response), tab); + } + else + { + /* This error is recoverable */ + g_return_if_fail (error->domain == G_CONVERT_ERROR || error->domain == G_IO_ERROR); - emsg = xed_conversion_error_while_saving_message_area_new ( - tab->priv->tmp_save_uri, - tab->priv->tmp_encoding, - error); + emsg = xed_conversion_error_while_saving_message_area_new (tab->priv->tmp_save_uri, + tab->priv->tmp_encoding, + error); - set_message_area (tab, emsg); + set_message_area (tab, emsg); - g_signal_connect (emsg, - "response", - G_CALLBACK (recoverable_saving_error_message_area_response), - tab); - } + g_signal_connect (emsg, "response", + G_CALLBACK (recoverable_saving_error_message_area_response), tab); + } - gtk_info_bar_set_default_response (GTK_INFO_BAR (emsg), - GTK_RESPONSE_CANCEL); + gtk_info_bar_set_default_response (GTK_INFO_BAR (emsg), GTK_RESPONSE_CANCEL); - gtk_widget_show (emsg); - } - else - { - gchar *mime = xed_document_get_mime_type (document); + gtk_widget_show (emsg); + } + else + { + gchar *mime = xed_document_get_mime_type (document); - _xed_recent_add (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), - tab->priv->tmp_save_uri, - mime); - g_free (mime); + _xed_recent_add (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), tab->priv->tmp_save_uri, mime); + g_free (mime); - if (tab->priv->print_preview != NULL) - xed_tab_set_state (tab, XED_TAB_STATE_SHOWING_PRINT_PREVIEW); - else - xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); + if (tab->priv->print_preview != NULL) + { + xed_tab_set_state (tab, XED_TAB_STATE_SHOWING_PRINT_PREVIEW); + } + else + { + xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); + } - tab->priv->ask_if_externally_modified = TRUE; + tab->priv->ask_if_externally_modified = TRUE; - end_saving (tab); - } + end_saving (tab); + } } static void -externally_modified_notification_message_area_response (GtkWidget *message_area, - gint response_id, - XedTab *tab) +externally_modified_notification_message_area_response (GtkWidget *message_area, + gint response_id, + XedTab *tab) { - XedView *view; + XedView *view; - set_message_area (tab, NULL); - view = xed_tab_get_view (tab); + set_message_area (tab, NULL); + view = xed_tab_get_view (tab); - if (response_id == GTK_RESPONSE_OK) - { - _xed_tab_revert (tab); - } - else - { - tab->priv->ask_if_externally_modified = FALSE; + if (response_id == GTK_RESPONSE_OK) + { + _xed_tab_revert (tab); + } + else + { + tab->priv->ask_if_externally_modified = FALSE; - /* go back to normal state */ - xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); - } + /* go back to normal state */ + xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); + } - gtk_widget_grab_focus (GTK_WIDGET (view)); + gtk_widget_grab_focus (GTK_WIDGET (view)); } static void display_externally_modified_notification (XedTab *tab) { - GtkWidget *message_area; - XedDocument *doc; - gchar *uri; - gboolean document_modified; + GtkWidget *message_area; + XedDocument *doc; + gchar *uri; + gboolean document_modified; - doc = xed_tab_get_document (tab); - g_return_if_fail (XED_IS_DOCUMENT (doc)); + doc = xed_tab_get_document (tab); + g_return_if_fail (XED_IS_DOCUMENT (doc)); - /* uri cannot be NULL, we're here because - * the file we're editing changed on disk */ - uri = xed_document_get_uri (doc); - g_return_if_fail (uri != NULL); + /* uri cannot be NULL, we're here because + * the file we're editing changed on disk */ + uri = xed_document_get_uri (doc); + g_return_if_fail (uri != NULL); - document_modified = gtk_text_buffer_get_modified (GTK_TEXT_BUFFER(doc)); - message_area = xed_externally_modified_message_area_new (uri, document_modified); - g_free (uri); + document_modified = gtk_text_buffer_get_modified (GTK_TEXT_BUFFER(doc)); + message_area = xed_externally_modified_message_area_new (uri, document_modified); + g_free (uri); - tab->priv->message_area = NULL; - set_message_area (tab, message_area); - gtk_widget_show (message_area); + tab->priv->message_area = NULL; + set_message_area (tab, message_area); + gtk_widget_show (message_area); - g_signal_connect (message_area, - "response", - G_CALLBACK (externally_modified_notification_message_area_response), - tab); + g_signal_connect (message_area, "response", + G_CALLBACK (externally_modified_notification_message_area_response), tab); } static gboolean view_focused_in (GtkWidget *widget, GdkEventFocus *event, - XedTab *tab) + XedTab *tab) { - XedDocument *doc; + XedDocument *doc; - g_return_val_if_fail (XED_IS_TAB (tab), FALSE); + g_return_val_if_fail (XED_IS_TAB (tab), FALSE); - /* we try to detect file changes only in the normal state */ - if (tab->priv->state != XED_TAB_STATE_NORMAL) - { - return FALSE; - } + /* we try to detect file changes only in the normal state */ + if (tab->priv->state != XED_TAB_STATE_NORMAL) + { + return FALSE; + } - /* we already asked, don't bug the user again */ - if (!tab->priv->ask_if_externally_modified) - { - return FALSE; - } + /* we already asked, don't bug the user again */ + if (!tab->priv->ask_if_externally_modified) + { + return FALSE; + } - doc = xed_tab_get_document (tab); + doc = xed_tab_get_document (tab); - /* If file was never saved or is remote we do not check */ - if (!xed_document_is_local (doc)) - { - return FALSE; - } + /* If file was never saved or is remote we do not check */ + if (!xed_document_is_local (doc)) + { + return FALSE; + } - if (_xed_document_check_externally_modified (doc)) - { - xed_tab_set_state (tab, XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION); + if (_xed_document_check_externally_modified (doc)) + { + xed_tab_set_state (tab, XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION); - display_externally_modified_notification (tab); + display_externally_modified_notification (tab); - return FALSE; - } + return FALSE; + } - return FALSE; + return FALSE; } static GMountOperation * tab_mount_operation_factory (XedDocument *doc, - gpointer userdata) + gpointer userdata) { - XedTab *tab = XED_TAB (userdata); - GtkWidget *window; + XedTab *tab = XED_TAB (userdata); + GtkWidget *window; - window = gtk_widget_get_toplevel (GTK_WIDGET (tab)); - return gtk_mount_operation_new (GTK_WINDOW (window)); + window = gtk_widget_get_toplevel (GTK_WIDGET (tab)); + return gtk_mount_operation_new (GTK_WINDOW (window)); } static void xed_tab_init (XedTab *tab) { - GtkWidget *sw; - XedDocument *doc; + GtkWidget *sw; + XedDocument *doc; - tab->priv = XED_TAB_GET_PRIVATE (tab); + tab->priv = XED_TAB_GET_PRIVATE (tab); - tab->priv->state = XED_TAB_STATE_NORMAL; + tab->priv->state = XED_TAB_STATE_NORMAL; - tab->priv->not_editable = FALSE; + tab->priv->not_editable = FALSE; - tab->priv->save_flags = 0; + tab->priv->save_flags = 0; - tab->priv->ask_if_externally_modified = TRUE; + tab->priv->ask_if_externally_modified = TRUE; - gtk_orientable_set_orientation (GTK_ORIENTABLE (tab), - GTK_ORIENTATION_VERTICAL); + gtk_orientable_set_orientation (GTK_ORIENTABLE (tab), GTK_ORIENTATION_VERTICAL); - /* Create the scrolled window */ - sw = gtk_scrolled_window_new (NULL, NULL); - tab->priv->view_scrolled_window = sw; + /* Create the scrolled window */ + sw = gtk_scrolled_window_new (NULL, NULL); + tab->priv->view_scrolled_window = sw; - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - /* Manage auto save data */ - tab->priv->auto_save = xed_prefs_manager_get_auto_save (); - tab->priv->auto_save = (tab->priv->auto_save != FALSE); + /* Manage auto save data */ + tab->priv->auto_save = xed_prefs_manager_get_auto_save (); + tab->priv->auto_save = (tab->priv->auto_save != FALSE); - tab->priv->auto_save_interval = xed_prefs_manager_get_auto_save_interval (); - if (tab->priv->auto_save_interval <= 0) - tab->priv->auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL; + tab->priv->auto_save_interval = xed_prefs_manager_get_auto_save_interval (); + if (tab->priv->auto_save_interval <= 0) + { + tab->priv->auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL; + } - /* Create the view */ - doc = xed_document_new (); - g_object_set_data (G_OBJECT (doc), XED_TAB_KEY, tab); + /* Create the view */ + doc = xed_document_new (); + g_object_set_data (G_OBJECT (doc), XED_TAB_KEY, tab); - _xed_document_set_mount_operation_factory (doc, - tab_mount_operation_factory, - tab); + _xed_document_set_mount_operation_factory (doc, tab_mount_operation_factory, tab); - tab->priv->view = xed_view_new (doc); - g_object_unref (doc); - gtk_widget_show (tab->priv->view); - g_object_set_data (G_OBJECT (tab->priv->view), XED_TAB_KEY, tab); + tab->priv->view = xed_view_new (doc); + g_object_unref (doc); + gtk_widget_show (tab->priv->view); + g_object_set_data (G_OBJECT (tab->priv->view), XED_TAB_KEY, tab); - gtk_box_pack_end (GTK_BOX (tab), sw, TRUE, TRUE, 0); - gtk_container_add (GTK_CONTAINER (sw), tab->priv->view); - gtk_widget_show (sw); + gtk_box_pack_end (GTK_BOX (tab), sw, TRUE, TRUE, 0); + gtk_container_add (GTK_CONTAINER (sw), tab->priv->view); + gtk_widget_show (sw); - g_signal_connect (doc, - "notify::uri", - G_CALLBACK (document_uri_notify_handler), - tab); - g_signal_connect (doc, - "notify::shortname", - G_CALLBACK (document_shortname_notify_handler), - tab); - g_signal_connect (doc, - "modified_changed", - G_CALLBACK (document_modified_changed), - tab); - g_signal_connect (doc, - "loading", - G_CALLBACK (document_loading), - tab); - g_signal_connect (doc, - "loaded", - G_CALLBACK (document_loaded), - tab); - g_signal_connect (doc, - "saving", - G_CALLBACK (document_saving), - tab); - g_signal_connect (doc, - "saved", - G_CALLBACK (document_saved), - tab); + g_signal_connect (doc, "notify::uri", + G_CALLBACK (document_uri_notify_handler), tab); + g_signal_connect (doc, "notify::shortname", + G_CALLBACK (document_shortname_notify_handler), tab); + g_signal_connect (doc, "modified_changed", + G_CALLBACK (document_modified_changed), tab); + g_signal_connect (doc, "loading", + G_CALLBACK (document_loading), tab); + g_signal_connect (doc, "loaded", + G_CALLBACK (document_loaded), tab); + g_signal_connect (doc, "saving", + G_CALLBACK (document_saving), tab); + g_signal_connect (doc, "saved", + G_CALLBACK (document_saved), tab); - g_signal_connect_after (tab->priv->view, - "focus-in-event", - G_CALLBACK (view_focused_in), - tab); - - g_signal_connect_after (tab->priv->view, - "realize", - G_CALLBACK (view_realized), - tab); + g_signal_connect_after (tab->priv->view, "focus-in-event", + G_CALLBACK (view_focused_in), tab); + g_signal_connect_after (tab->priv->view, "realize", + G_CALLBACK (view_realized), tab); } GtkWidget * _xed_tab_new (void) { - return GTK_WIDGET (g_object_new (XED_TYPE_TAB, NULL)); + return GTK_WIDGET (g_object_new (XED_TYPE_TAB, NULL)); } /* Whether create is TRUE, creates a new empty document if location does not refer to an existing file */ GtkWidget * -_xed_tab_new_from_uri (const gchar *uri, - const XedEncoding *encoding, - gint line_pos, - gboolean create) +_xed_tab_new_from_uri (const gchar *uri, + const XedEncoding *encoding, + gint line_pos, + gboolean create) { - XedTab *tab; + XedTab *tab; - g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (uri != NULL, NULL); - tab = XED_TAB (_xed_tab_new ()); + tab = XED_TAB (_xed_tab_new ()); - _xed_tab_load (tab, - uri, - encoding, - line_pos, - create); + _xed_tab_load (tab, uri, encoding, line_pos, create); - return GTK_WIDGET (tab); + return GTK_WIDGET (tab); } /** @@ -1597,7 +1505,7 @@ _xed_tab_new_from_uri (const gchar *uri, XedView * xed_tab_get_view (XedTab *tab) { - return XED_VIEW (tab->priv->view); + return XED_VIEW (tab->priv->view); } /** @@ -1611,8 +1519,7 @@ xed_tab_get_view (XedTab *tab) XedDocument * xed_tab_get_document (XedTab *tab) { - return XED_DOCUMENT (gtk_text_view_get_buffer ( - GTK_TEXT_VIEW (tab->priv->view))); + return XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (tab->priv->view))); } #define MAX_DOC_NAME_LENGTH 40 @@ -1620,224 +1527,235 @@ xed_tab_get_document (XedTab *tab) gchar * _xed_tab_get_name (XedTab *tab) { - XedDocument *doc; - gchar *name; - gchar *docname; - gchar *tab_name; + XedDocument *doc; + gchar *name; + gchar *docname; + gchar *tab_name; - g_return_val_if_fail (XED_IS_TAB (tab), NULL); + g_return_val_if_fail (XED_IS_TAB (tab), NULL); - doc = xed_tab_get_document (tab); + doc = xed_tab_get_document (tab); - name = xed_document_get_short_name_for_display (doc); + name = xed_document_get_short_name_for_display (doc); - /* Truncate the name so it doesn't get insanely wide. */ - docname = xed_utils_str_middle_truncate (name, MAX_DOC_NAME_LENGTH); + /* Truncate the name so it doesn't get insanely wide. */ + docname = xed_utils_str_middle_truncate (name, MAX_DOC_NAME_LENGTH); - if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc))) - { - tab_name = g_strdup_printf ("*%s", docname); - } - else - { + if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc))) + { + tab_name = g_strdup_printf ("*%s", docname); + } + else + { #if 0 - if (xed_document_get_readonly (doc)) - { - tab_name = g_strdup_printf ("%s [%s]", docname, - /*Read only*/ _("RO")); - } - else - { - tab_name = g_strdup_printf ("%s", docname); - } + if (xed_document_get_readonly (doc)) + { + tab_name = g_strdup_printf ("%s [%s]", docname, + /*Read only*/ _("RO")); + } + else + { + tab_name = g_strdup_printf ("%s", docname); + } #endif - tab_name = g_strdup (docname); - } + tab_name = g_strdup (docname); + } - g_free (docname); - g_free (name); + g_free (docname); + g_free (name); - return tab_name; + return tab_name; } gchar * -_xed_tab_get_tooltips (XedTab *tab) +_xed_tab_get_tooltips (XedTab *tab) { - XedDocument *doc; - gchar *tip; - gchar *uri; - gchar *ruri; - gchar *ruri_markup; + XedDocument *doc; + gchar *tip; + gchar *uri; + gchar *ruri; + gchar *ruri_markup; - g_return_val_if_fail (XED_IS_TAB (tab), NULL); + g_return_val_if_fail (XED_IS_TAB (tab), NULL); - doc = xed_tab_get_document (tab); + doc = xed_tab_get_document (tab); - uri = xed_document_get_uri_for_display (doc); - g_return_val_if_fail (uri != NULL, NULL); + uri = xed_document_get_uri_for_display (doc); + g_return_val_if_fail (uri != NULL, NULL); - ruri = xed_utils_replace_home_dir_with_tilde (uri); - g_free (uri); + ruri = xed_utils_replace_home_dir_with_tilde (uri); + g_free (uri); - ruri_markup = g_markup_printf_escaped ("%s", ruri); + ruri_markup = g_markup_printf_escaped ("%s", ruri); - switch (tab->priv->state) - { - gchar *content_type; - gchar *mime_type; - gchar *content_description; - gchar *content_full_description; - gchar *encoding; - const XedEncoding *enc; + switch (tab->priv->state) + { + gchar *content_type; + gchar *mime_type; + gchar *content_description; + gchar *content_full_description; + gchar *encoding; + const XedEncoding *enc; - case XED_TAB_STATE_LOADING_ERROR: - tip = g_strdup_printf (_("Error opening file %s"), - ruri_markup); - break; + case XED_TAB_STATE_LOADING_ERROR: + tip = g_strdup_printf (_("Error opening file %s"), ruri_markup); + break; - case XED_TAB_STATE_REVERTING_ERROR: - tip = g_strdup_printf (_("Error reverting file %s"), - ruri_markup); - break; + case XED_TAB_STATE_REVERTING_ERROR: + tip = g_strdup_printf (_("Error reverting file %s"), ruri_markup); + break; - case XED_TAB_STATE_SAVING_ERROR: - tip = g_strdup_printf (_("Error saving file %s"), - ruri_markup); - break; - default: - content_type = xed_document_get_content_type (doc); - mime_type = xed_document_get_mime_type (doc); - content_description = g_content_type_get_description (content_type); + case XED_TAB_STATE_SAVING_ERROR: + tip = g_strdup_printf (_("Error saving file %s"), ruri_markup); + break; + default: + content_type = xed_document_get_content_type (doc); + mime_type = xed_document_get_mime_type (doc); + content_description = g_content_type_get_description (content_type); - if (content_description == NULL) - content_full_description = g_strdup (mime_type); - else - content_full_description = g_strdup_printf ("%s (%s)", - content_description, mime_type); + if (content_description == NULL) + { + content_full_description = g_strdup (mime_type); + } + else + { + content_full_description = g_strdup_printf ("%s (%s)", content_description, mime_type); + } - g_free (content_type); - g_free (mime_type); - g_free (content_description); + g_free (content_type); + g_free (mime_type); + g_free (content_description); - enc = xed_document_get_encoding (doc); + enc = xed_document_get_encoding (doc); - if (enc == NULL) - encoding = g_strdup (_("Unicode (UTF-8)")); - else - encoding = xed_encoding_to_string (enc); + if (enc == NULL) + { + encoding = g_strdup (_("Unicode (UTF-8)")); + } + else + { + encoding = xed_encoding_to_string (enc); + } - tip = g_markup_printf_escaped ("%s %s\n\n" - "%s %s\n" - "%s %s", - _("Name:"), ruri, - _("MIME Type:"), content_full_description, - _("Encoding:"), encoding); + tip = g_markup_printf_escaped ("%s %s\n\n" + "%s %s\n" + "%s %s", + _("Name:"), ruri, + _("MIME Type:"), content_full_description, + _("Encoding:"), encoding); - g_free (encoding); - g_free (content_full_description); + g_free (encoding); + g_free (content_full_description); - break; - } + break; + } - g_free (ruri); - g_free (ruri_markup); + g_free (ruri); + g_free (ruri_markup); - return tip; + return tip; } static GdkPixbuf * resize_icon (GdkPixbuf *pixbuf, - gint size) + gint size) { - gint width, height; + gint width, height; - width = gdk_pixbuf_get_width (pixbuf); - height = gdk_pixbuf_get_height (pixbuf); + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); - /* if the icon is larger than the nominal size, scale down */ - if (MAX (width, height) > size) - { - GdkPixbuf *scaled_pixbuf; + /* if the icon is larger than the nominal size, scale down */ + if (MAX (width, height) > size) + { + GdkPixbuf *scaled_pixbuf; - if (width > height) - { - height = height * size / width; - width = size; - } - else - { - width = width * size / height; - height = size; - } + if (width > height) + { + height = height * size / width; + width = size; + } + else + { + width = width * size / height; + height = size; + } - scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf, - width, - height, - GDK_INTERP_BILINEAR); - g_object_unref (pixbuf); - pixbuf = scaled_pixbuf; - } + scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR); + g_object_unref (pixbuf); + pixbuf = scaled_pixbuf; + } - return pixbuf; + return pixbuf; } static GdkPixbuf * get_stock_icon (GtkIconTheme *theme, - const gchar *stock, - gint size) + const gchar *stock, + gint size) { - GdkPixbuf *pixbuf; + GdkPixbuf *pixbuf; - pixbuf = gtk_icon_theme_load_icon (theme, stock, size, 0, NULL); - if (pixbuf == NULL) - return NULL; + pixbuf = gtk_icon_theme_load_icon (theme, stock, size, 0, NULL); + if (pixbuf == NULL) + { + return NULL; + } - return resize_icon (pixbuf, size); + return resize_icon (pixbuf, size); } static GdkPixbuf * get_icon (GtkIconTheme *theme, - GFile *location, - gint size) + GFile *location, + gint size) { - GdkPixbuf *pixbuf; - GtkIconInfo *icon_info; - GFileInfo *info; - GIcon *gicon; + GdkPixbuf *pixbuf; + GtkIconInfo *icon_info; + GFileInfo *info; + GIcon *gicon; - if (location == NULL) - return get_stock_icon (theme, GTK_STOCK_FILE, size); + if (location == NULL) + { + return get_stock_icon (theme, GTK_STOCK_FILE, size); + } - /* FIXME: Doing a sync stat is bad, this should be fixed */ - info = g_file_query_info (location, - G_FILE_ATTRIBUTE_STANDARD_ICON, - G_FILE_QUERY_INFO_NONE, - NULL, - NULL); - if (info == NULL) - return get_stock_icon (theme, GTK_STOCK_FILE, size); + /* FIXME: Doing a sync stat is bad, this should be fixed */ + info = g_file_query_info (location, + G_FILE_ATTRIBUTE_STANDARD_ICON, + G_FILE_QUERY_INFO_NONE, + NULL, + NULL); + if (info == NULL) + { + return get_stock_icon (theme, GTK_STOCK_FILE, size); + } - gicon = g_file_info_get_icon (info); + gicon = g_file_info_get_icon (info); - if (gicon == NULL) - { - g_object_unref (info); - return get_stock_icon (theme, GTK_STOCK_FILE, size); - } + if (gicon == NULL) + { + g_object_unref (info); + return get_stock_icon (theme, GTK_STOCK_FILE, size); + } - icon_info = gtk_icon_theme_lookup_by_gicon (theme, gicon, size, 0); - g_object_unref (info); + icon_info = gtk_icon_theme_lookup_by_gicon (theme, gicon, size, 0); + g_object_unref (info); - if (icon_info == NULL) - return get_stock_icon (theme, GTK_STOCK_FILE, size); + if (icon_info == NULL) + { + return get_stock_icon (theme, GTK_STOCK_FILE, size); + } - pixbuf = gtk_icon_info_load_icon (icon_info, NULL); - gtk_icon_info_free (icon_info); + pixbuf = gtk_icon_info_load_icon (icon_info, NULL); + gtk_icon_info_free (icon_info); - if (pixbuf == NULL) - return get_stock_icon (theme, GTK_STOCK_FILE, size); + if (pixbuf == NULL) + { + return get_stock_icon (theme, GTK_STOCK_FILE, size); + } - return resize_icon (pixbuf, size); + return resize_icon (pixbuf, size); } /* FIXME: add support for theme changed. I think it should be as easy as @@ -1845,84 +1763,72 @@ get_icon (GtkIconTheme *theme, GdkPixbuf * _xed_tab_get_icon (XedTab *tab) { - GdkPixbuf *pixbuf; - GtkIconTheme *theme; - GdkScreen *screen; - gint icon_size; + GdkPixbuf *pixbuf; + GtkIconTheme *theme; + GdkScreen *screen; + gint icon_size; - g_return_val_if_fail (XED_IS_TAB (tab), NULL); + g_return_val_if_fail (XED_IS_TAB (tab), NULL); - screen = gtk_widget_get_screen (GTK_WIDGET (tab)); + screen = gtk_widget_get_screen (GTK_WIDGET (tab)); - theme = gtk_icon_theme_get_for_screen (screen); - g_return_val_if_fail (theme != NULL, NULL); + theme = gtk_icon_theme_get_for_screen (screen); + g_return_val_if_fail (theme != NULL, NULL); - gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, NULL, &icon_size); + gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, NULL, &icon_size); - switch (tab->priv->state) - { - case XED_TAB_STATE_LOADING: - pixbuf = get_stock_icon (theme, - GTK_STOCK_OPEN, - icon_size); - break; + switch (tab->priv->state) + { + case XED_TAB_STATE_LOADING: + pixbuf = get_stock_icon (theme, GTK_STOCK_OPEN, icon_size); + break; - case XED_TAB_STATE_REVERTING: - pixbuf = get_stock_icon (theme, - GTK_STOCK_REVERT_TO_SAVED, - icon_size); - break; + case XED_TAB_STATE_REVERTING: + pixbuf = get_stock_icon (theme, GTK_STOCK_REVERT_TO_SAVED, icon_size); + break; - case XED_TAB_STATE_SAVING: - pixbuf = get_stock_icon (theme, - GTK_STOCK_SAVE, - icon_size); - break; + case XED_TAB_STATE_SAVING: + pixbuf = get_stock_icon (theme, GTK_STOCK_SAVE, icon_size); + break; - case XED_TAB_STATE_PRINTING: - pixbuf = get_stock_icon (theme, - GTK_STOCK_PRINT, - icon_size); - break; + case XED_TAB_STATE_PRINTING: + pixbuf = get_stock_icon (theme, GTK_STOCK_PRINT, icon_size); + break; - case XED_TAB_STATE_PRINT_PREVIEWING: - case XED_TAB_STATE_SHOWING_PRINT_PREVIEW: - pixbuf = get_stock_icon (theme, - GTK_STOCK_PRINT_PREVIEW, - icon_size); - break; + case XED_TAB_STATE_PRINT_PREVIEWING: + case XED_TAB_STATE_SHOWING_PRINT_PREVIEW: + pixbuf = get_stock_icon (theme, GTK_STOCK_PRINT_PREVIEW, icon_size); + break; - case XED_TAB_STATE_LOADING_ERROR: - case XED_TAB_STATE_REVERTING_ERROR: - case XED_TAB_STATE_SAVING_ERROR: - case XED_TAB_STATE_GENERIC_ERROR: - pixbuf = get_stock_icon (theme, - GTK_STOCK_DIALOG_ERROR, - icon_size); - break; + case XED_TAB_STATE_LOADING_ERROR: + case XED_TAB_STATE_REVERTING_ERROR: + case XED_TAB_STATE_SAVING_ERROR: + case XED_TAB_STATE_GENERIC_ERROR: + pixbuf = get_stock_icon (theme, GTK_STOCK_DIALOG_ERROR, icon_size); + break; - case XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION: - pixbuf = get_stock_icon (theme, - GTK_STOCK_DIALOG_WARNING, - icon_size); - break; + case XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION: + pixbuf = get_stock_icon (theme, GTK_STOCK_DIALOG_WARNING, icon_size); + break; - default: - { - GFile *location; - XedDocument *doc; + default: + { + GFile *location; + XedDocument *doc; - doc = xed_tab_get_document (tab); + doc = xed_tab_get_document (tab); - location = xed_document_get_location (doc); - pixbuf = get_icon (theme, location, icon_size); + location = xed_document_get_location (doc); + pixbuf = get_icon (theme, location, icon_size); - if (location) - g_object_unref (location); - } - } + if (location) + { + g_object_unref (location); + } + } + } - return pixbuf; + return pixbuf; } /** @@ -1936,248 +1842,245 @@ _xed_tab_get_icon (XedTab *tab) XedTab * xed_tab_get_from_document (XedDocument *doc) { - gpointer res; + gpointer res; - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - res = g_object_get_data (G_OBJECT (doc), XED_TAB_KEY); + res = g_object_get_data (G_OBJECT (doc), XED_TAB_KEY); - return (res != NULL) ? XED_TAB (res) : NULL; + return (res != NULL) ? XED_TAB (res) : NULL; } void _xed_tab_load (XedTab *tab, - const gchar *uri, - const XedEncoding *encoding, - gint line_pos, - gboolean create) + const gchar *uri, + const XedEncoding *encoding, + gint line_pos, + gboolean create) { - XedDocument *doc; + XedDocument *doc; - g_return_if_fail (XED_IS_TAB (tab)); - g_return_if_fail (tab->priv->state == XED_TAB_STATE_NORMAL); + g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail (tab->priv->state == XED_TAB_STATE_NORMAL); - doc = xed_tab_get_document (tab); - g_return_if_fail (XED_IS_DOCUMENT (doc)); + doc = xed_tab_get_document (tab); + g_return_if_fail (XED_IS_DOCUMENT (doc)); - xed_tab_set_state (tab, XED_TAB_STATE_LOADING); + xed_tab_set_state (tab, XED_TAB_STATE_LOADING); - tab->priv->tmp_line_pos = line_pos; - tab->priv->tmp_encoding = encoding; + tab->priv->tmp_line_pos = line_pos; + tab->priv->tmp_encoding = encoding; - if (tab->priv->auto_save_timeout > 0) - remove_auto_save_timeout (tab); + if (tab->priv->auto_save_timeout > 0) + { + remove_auto_save_timeout (tab); + } - xed_document_load (doc, - uri, - encoding, - line_pos, - create); + xed_document_load (doc, uri, encoding, line_pos, create); } void _xed_tab_revert (XedTab *tab) { - XedDocument *doc; - gchar *uri; + XedDocument *doc; + gchar *uri; - g_return_if_fail (XED_IS_TAB (tab)); - g_return_if_fail ((tab->priv->state == XED_TAB_STATE_NORMAL) || - (tab->priv->state == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION)); + g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail ((tab->priv->state == XED_TAB_STATE_NORMAL) || + (tab->priv->state == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION)); - if (tab->priv->state == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) - { - set_message_area (tab, NULL); - } + if (tab->priv->state == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) + { + set_message_area (tab, NULL); + } - doc = xed_tab_get_document (tab); - g_return_if_fail (XED_IS_DOCUMENT (doc)); + doc = xed_tab_get_document (tab); + g_return_if_fail (XED_IS_DOCUMENT (doc)); - xed_tab_set_state (tab, XED_TAB_STATE_REVERTING); + xed_tab_set_state (tab, XED_TAB_STATE_REVERTING); - uri = xed_document_get_uri (doc); - g_return_if_fail (uri != NULL); + uri = xed_document_get_uri (doc); + g_return_if_fail (uri != NULL); - tab->priv->tmp_line_pos = 0; - tab->priv->tmp_encoding = xed_document_get_encoding (doc); + tab->priv->tmp_line_pos = 0; + tab->priv->tmp_encoding = xed_document_get_encoding (doc); - if (tab->priv->auto_save_timeout > 0) - remove_auto_save_timeout (tab); + if (tab->priv->auto_save_timeout > 0) + { + remove_auto_save_timeout (tab); + } - xed_document_load (doc, - uri, - tab->priv->tmp_encoding, - 0, - FALSE); + xed_document_load (doc, uri, tab->priv->tmp_encoding, 0, FALSE); - g_free (uri); + g_free (uri); } void _xed_tab_save (XedTab *tab) { - XedDocument *doc; - XedDocumentSaveFlags save_flags; + XedDocument *doc; + XedDocumentSaveFlags save_flags; - g_return_if_fail (XED_IS_TAB (tab)); - g_return_if_fail ((tab->priv->state == XED_TAB_STATE_NORMAL) || - (tab->priv->state == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) || - (tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW)); - g_return_if_fail (tab->priv->tmp_save_uri == NULL); - g_return_if_fail (tab->priv->tmp_encoding == NULL); + g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail ((tab->priv->state == XED_TAB_STATE_NORMAL) || + (tab->priv->state == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) || + (tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW)); + g_return_if_fail (tab->priv->tmp_save_uri == NULL); + g_return_if_fail (tab->priv->tmp_encoding == NULL); - doc = xed_tab_get_document (tab); - g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail (!xed_document_is_untitled (doc)); + doc = xed_tab_get_document (tab); + g_return_if_fail (XED_IS_DOCUMENT (doc)); + g_return_if_fail (!xed_document_is_untitled (doc)); - if (tab->priv->state == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) - { - /* We already told the user about the external - * modification: hide the message area and set - * the save flag. - */ + if (tab->priv->state == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) + { + /* We already told the user about the external + * modification: hide the message area and set + * the save flag. + */ - set_message_area (tab, NULL); - save_flags = tab->priv->save_flags | XED_DOCUMENT_SAVE_IGNORE_MTIME; - } - else - { - save_flags = tab->priv->save_flags; - } + set_message_area (tab, NULL); + save_flags = tab->priv->save_flags | XED_DOCUMENT_SAVE_IGNORE_MTIME; + } + else + { + save_flags = tab->priv->save_flags; + } - xed_tab_set_state (tab, XED_TAB_STATE_SAVING); + xed_tab_set_state (tab, XED_TAB_STATE_SAVING); - /* uri used in error messages, will be freed in document_saved */ - tab->priv->tmp_save_uri = xed_document_get_uri (doc); - tab->priv->tmp_encoding = xed_document_get_encoding (doc); + /* uri used in error messages, will be freed in document_saved */ + tab->priv->tmp_save_uri = xed_document_get_uri (doc); + tab->priv->tmp_encoding = xed_document_get_encoding (doc); - if (tab->priv->auto_save_timeout > 0) - remove_auto_save_timeout (tab); + if (tab->priv->auto_save_timeout > 0) + { + remove_auto_save_timeout (tab); + } - xed_document_save (doc, save_flags); + xed_document_save (doc, save_flags); } static gboolean xed_tab_auto_save (XedTab *tab) { - XedDocument *doc; + XedDocument *doc; - xed_debug (DEBUG_TAB); + xed_debug (DEBUG_TAB); - g_return_val_if_fail (tab->priv->tmp_save_uri == NULL, FALSE); - g_return_val_if_fail (tab->priv->tmp_encoding == NULL, FALSE); + g_return_val_if_fail (tab->priv->tmp_save_uri == NULL, FALSE); + g_return_val_if_fail (tab->priv->tmp_encoding == NULL, FALSE); - doc = xed_tab_get_document (tab); + doc = xed_tab_get_document (tab); - g_return_val_if_fail (!xed_document_is_untitled (doc), FALSE); - g_return_val_if_fail (!xed_document_get_readonly (doc), FALSE); + g_return_val_if_fail (!xed_document_is_untitled (doc), FALSE); + g_return_val_if_fail (!xed_document_get_readonly (doc), FALSE); - g_return_val_if_fail (tab->priv->auto_save_timeout > 0, FALSE); - g_return_val_if_fail (tab->priv->auto_save, FALSE); - g_return_val_if_fail (tab->priv->auto_save_interval > 0, FALSE); + g_return_val_if_fail (tab->priv->auto_save_timeout > 0, FALSE); + g_return_val_if_fail (tab->priv->auto_save, FALSE); + g_return_val_if_fail (tab->priv->auto_save_interval > 0, FALSE); - if (!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER(doc))) - { - xed_debug_message (DEBUG_TAB, "Document not modified"); + if (!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER(doc))) + { + xed_debug_message (DEBUG_TAB, "Document not modified"); - return TRUE; - } + return TRUE; + } - if ((tab->priv->state != XED_TAB_STATE_NORMAL) && - (tab->priv->state != XED_TAB_STATE_SHOWING_PRINT_PREVIEW)) - { - /* Retry after 30 seconds */ - guint timeout; + if ((tab->priv->state != XED_TAB_STATE_NORMAL) && (tab->priv->state != XED_TAB_STATE_SHOWING_PRINT_PREVIEW)) + { + /* Retry after 30 seconds */ + guint timeout; - xed_debug_message (DEBUG_TAB, "Retry after 30 seconds"); + xed_debug_message (DEBUG_TAB, "Retry after 30 seconds"); - /* Add a new timeout */ - timeout = g_timeout_add_seconds (30, - (GSourceFunc) xed_tab_auto_save, - tab); + /* Add a new timeout */ + timeout = g_timeout_add_seconds (30, (GSourceFunc) xed_tab_auto_save, tab); - tab->priv->auto_save_timeout = timeout; + tab->priv->auto_save_timeout = timeout; - /* Returns FALSE so the old timeout is "destroyed" */ - return FALSE; - } + /* Returns FALSE so the old timeout is "destroyed" */ + return FALSE; + } - xed_tab_set_state (tab, XED_TAB_STATE_SAVING); + xed_tab_set_state (tab, XED_TAB_STATE_SAVING); - /* uri used in error messages, will be freed in document_saved */ - tab->priv->tmp_save_uri = xed_document_get_uri (doc); - tab->priv->tmp_encoding = xed_document_get_encoding (doc); + /* uri used in error messages, will be freed in document_saved */ + tab->priv->tmp_save_uri = xed_document_get_uri (doc); + tab->priv->tmp_encoding = xed_document_get_encoding (doc); - /* Set auto_save_timeout to 0 since the timeout is going to be destroyed */ - tab->priv->auto_save_timeout = 0; + /* Set auto_save_timeout to 0 since the timeout is going to be destroyed */ + tab->priv->auto_save_timeout = 0; - /* Since we are autosaving, we need to preserve the backup that was produced - the last time the user "manually" saved the file. In the case a recoverable - error happens while saving, the last backup is not preserved since the user - expressed his willing of saving the file */ - xed_document_save (doc, tab->priv->save_flags | XED_DOCUMENT_SAVE_PRESERVE_BACKUP); + /* Since we are autosaving, we need to preserve the backup that was produced + the last time the user "manually" saved the file. In the case a recoverable + error happens while saving, the last backup is not preserved since the user + expressed his willing of saving the file */ + xed_document_save (doc, tab->priv->save_flags | XED_DOCUMENT_SAVE_PRESERVE_BACKUP); - xed_debug_message (DEBUG_TAB, "Done"); + xed_debug_message (DEBUG_TAB, "Done"); - /* Returns FALSE so the old timeout is "destroyed" */ - return FALSE; + /* Returns FALSE so the old timeout is "destroyed" */ + return FALSE; } void _xed_tab_save_as (XedTab *tab, - const gchar *uri, - const XedEncoding *encoding, - XedDocumentNewlineType newline_type) + const gchar *uri, + const XedEncoding *encoding, + XedDocumentNewlineType newline_type) { - XedDocument *doc; - XedDocumentSaveFlags save_flags; + XedDocument *doc; + XedDocumentSaveFlags save_flags; - g_return_if_fail (XED_IS_TAB (tab)); - g_return_if_fail ((tab->priv->state == XED_TAB_STATE_NORMAL) || - (tab->priv->state == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) || - (tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW)); - g_return_if_fail (encoding != NULL); + g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail ((tab->priv->state == XED_TAB_STATE_NORMAL) || + (tab->priv->state == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) || + (tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW)); + g_return_if_fail (encoding != NULL); - g_return_if_fail (tab->priv->tmp_save_uri == NULL); - g_return_if_fail (tab->priv->tmp_encoding == NULL); + g_return_if_fail (tab->priv->tmp_save_uri == NULL); + g_return_if_fail (tab->priv->tmp_encoding == NULL); - doc = xed_tab_get_document (tab); - g_return_if_fail (XED_IS_DOCUMENT (doc)); + doc = xed_tab_get_document (tab); + g_return_if_fail (XED_IS_DOCUMENT (doc)); - /* reset the save flags, when saving as */ - tab->priv->save_flags = 0; + /* reset the save flags, when saving as */ + tab->priv->save_flags = 0; - if (tab->priv->state == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) - { - /* We already told the user about the external - * modification: hide the message area and set - * the save flag. - */ + if (tab->priv->state == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) + { + /* We already told the user about the external + * modification: hide the message area and set + * the save flag. + */ - set_message_area (tab, NULL); - save_flags = tab->priv->save_flags | XED_DOCUMENT_SAVE_IGNORE_MTIME; - } - else - { - save_flags = tab->priv->save_flags; - } + set_message_area (tab, NULL); + save_flags = tab->priv->save_flags | XED_DOCUMENT_SAVE_IGNORE_MTIME; + } + else + { + save_flags = tab->priv->save_flags; + } - xed_tab_set_state (tab, XED_TAB_STATE_SAVING); + xed_tab_set_state (tab, XED_TAB_STATE_SAVING); - /* uri used in error messages... strdup because errors are async - * and the string can go away, will be freed in document_saved */ - tab->priv->tmp_save_uri = g_strdup (uri); - tab->priv->tmp_encoding = encoding; + /* uri used in error messages... strdup because errors are async + * and the string can go away, will be freed in document_saved */ + tab->priv->tmp_save_uri = g_strdup (uri); + tab->priv->tmp_encoding = encoding; - if (tab->priv->auto_save_timeout > 0) - remove_auto_save_timeout (tab); + if (tab->priv->auto_save_timeout > 0) + { + remove_auto_save_timeout (tab); + } - /* FIXME: this should behave the same as encoding, setting it here - makes it persistent (if save fails, it's remembered). It's not - a very big deal, but would be nice to have them follow the - same pattern. This can be changed once we break API for 3.0 */ - xed_document_set_newline_type (doc, newline_type); - xed_document_save_as (doc, uri, encoding, tab->priv->save_flags); + /* FIXME: this should behave the same as encoding, setting it here + makes it persistent (if save fails, it's remembered). It's not + a very big deal, but would be nice to have them follow the + same pattern. This can be changed once we break API for 3.0 */ + xed_document_set_newline_type (doc, newline_type); + xed_document_save_as (doc, uri, encoding, tab->priv->save_flags); } #define XED_PAGE_SETUP_KEY "xed-page-setup-key" @@ -2186,435 +2089,418 @@ _xed_tab_save_as (XedTab *tab, static GtkPageSetup * get_page_setup (XedTab *tab) { - gpointer data; - XedDocument *doc; + gpointer data; + XedDocument *doc; - doc = xed_tab_get_document (tab); + doc = xed_tab_get_document (tab); + data = g_object_get_data (G_OBJECT (doc), XED_PAGE_SETUP_KEY); - data = g_object_get_data (G_OBJECT (doc), - XED_PAGE_SETUP_KEY); - - if (data == NULL) - { - return _xed_app_get_default_page_setup (xed_app_get_default()); - } - else - { - return gtk_page_setup_copy (GTK_PAGE_SETUP (data)); - } + if (data == NULL) + { + return _xed_app_get_default_page_setup (xed_app_get_default()); + } + else + { + return gtk_page_setup_copy (GTK_PAGE_SETUP (data)); + } } static GtkPrintSettings * get_print_settings (XedTab *tab) { - gpointer data; - XedDocument *doc; - GtkPrintSettings *settings; - gchar *uri, *name; + gpointer data; + XedDocument *doc; + GtkPrintSettings *settings; + gchar *uri, *name; - doc = xed_tab_get_document (tab); + doc = xed_tab_get_document (tab); - data = g_object_get_data (G_OBJECT (doc), - XED_PRINT_SETTINGS_KEY); + data = g_object_get_data (G_OBJECT (doc), XED_PRINT_SETTINGS_KEY); - if (data == NULL) - { - settings = _xed_app_get_default_print_settings (xed_app_get_default()); - } - else - { - settings = gtk_print_settings_copy (GTK_PRINT_SETTINGS (data)); - } + if (data == NULL) + { + settings = _xed_app_get_default_print_settings (xed_app_get_default()); + } + else + { + settings = gtk_print_settings_copy (GTK_PRINT_SETTINGS (data)); + } - name = xed_document_get_short_name_for_display (doc); - uri = g_strconcat ("file://", - g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS), - "/", name, ".pdf", NULL); + name = xed_document_get_short_name_for_display (doc); + uri = g_strconcat ("file://", + g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS), + "/", name, ".pdf", NULL); - gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri); + gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri); - g_free (uri); - g_free (name); + g_free (uri); + g_free (name); - return settings; + return settings; } /* FIXME: show the message area only if the operation will be "long" */ static void printing_cb (XedPrintJob *job, - XedPrintJobStatus status, - XedTab *tab) + XedPrintJobStatus status, + XedTab *tab) { - g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); + g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); - gtk_widget_show (tab->priv->message_area); + gtk_widget_show (tab->priv->message_area); - xed_progress_message_area_set_text (XED_PROGRESS_MESSAGE_AREA (tab->priv->message_area), - xed_print_job_get_status_string (job)); + xed_progress_message_area_set_text (XED_PROGRESS_MESSAGE_AREA (tab->priv->message_area), + xed_print_job_get_status_string (job)); - xed_progress_message_area_set_fraction (XED_PROGRESS_MESSAGE_AREA (tab->priv->message_area), - xed_print_job_get_progress (job)); + xed_progress_message_area_set_fraction (XED_PROGRESS_MESSAGE_AREA (tab->priv->message_area), + xed_print_job_get_progress (job)); } static void store_print_settings (XedTab *tab, - XedPrintJob *job) + XedPrintJob *job) { - XedDocument *doc; - GtkPrintSettings *settings; - GtkPageSetup *page_setup; + XedDocument *doc; + GtkPrintSettings *settings; + GtkPageSetup *page_setup; - doc = xed_tab_get_document (tab); + doc = xed_tab_get_document (tab); - settings = xed_print_job_get_print_settings (job); + settings = xed_print_job_get_print_settings (job); - /* clear n-copies settings since we do not want to - * persist that one */ - gtk_print_settings_unset (settings, - GTK_PRINT_SETTINGS_N_COPIES); + /* clear n-copies settings since we do not want to + * persist that one */ + gtk_print_settings_unset (settings, GTK_PRINT_SETTINGS_N_COPIES); - /* remember settings for this document */ - g_object_set_data_full (G_OBJECT (doc), - XED_PRINT_SETTINGS_KEY, - g_object_ref (settings), - (GDestroyNotify)g_object_unref); + /* remember settings for this document */ + g_object_set_data_full (G_OBJECT (doc), XED_PRINT_SETTINGS_KEY, + g_object_ref (settings), (GDestroyNotify)g_object_unref); - /* make them the default */ - _xed_app_set_default_print_settings (xed_app_get_default (), - settings); + /* make them the default */ + _xed_app_set_default_print_settings (xed_app_get_default (), settings); - page_setup = xed_print_job_get_page_setup (job); + page_setup = xed_print_job_get_page_setup (job); - /* remember page setup for this document */ - g_object_set_data_full (G_OBJECT (doc), - XED_PAGE_SETUP_KEY, - g_object_ref (page_setup), - (GDestroyNotify)g_object_unref); + /* remember page setup for this document */ + g_object_set_data_full (G_OBJECT (doc), XED_PAGE_SETUP_KEY, + g_object_ref (page_setup), (GDestroyNotify)g_object_unref); - /* make it the default */ - _xed_app_set_default_page_setup (xed_app_get_default (), - page_setup); + /* make it the default */ + _xed_app_set_default_page_setup (xed_app_get_default (), page_setup); } static void done_printing_cb (XedPrintJob *job, - XedPrintJobResult result, - const GError *error, - XedTab *tab) + XedPrintJobResult result, + const GError *error, + XedTab *tab) { - XedView *view; + XedView *view; - g_return_if_fail (tab->priv->state == XED_TAB_STATE_PRINT_PREVIEWING || - tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW || - tab->priv->state == XED_TAB_STATE_PRINTING); + g_return_if_fail (tab->priv->state == XED_TAB_STATE_PRINT_PREVIEWING || + tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW || + tab->priv->state == XED_TAB_STATE_PRINTING); - if (tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW) - { - /* print preview has been destroyed... */ - tab->priv->print_preview = NULL; - } - else - { - g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); + if (tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW) + { + /* print preview has been destroyed... */ + tab->priv->print_preview = NULL; + } + else + { + g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); - set_message_area (tab, NULL); /* destroy the message area */ - } + set_message_area (tab, NULL); /* destroy the message area */ + } - // TODO: check status and error + // TODO: check status and error - if (result == XED_PRINT_JOB_RESULT_OK) - { - store_print_settings (tab, job); - } + if (result == XED_PRINT_JOB_RESULT_OK) + { + store_print_settings (tab, job); + } #if 0 - if (tab->priv->print_preview != NULL) - { - /* If we were printing while showing the print preview, - see bug #352658 */ - gtk_widget_destroy (tab->priv->print_preview); - g_return_if_fail (tab->priv->state == XED_TAB_STATE_PRINTING); - } + if (tab->priv->print_preview != NULL) + { + /* If we were printing while showing the print preview, + see bug #352658 */ + gtk_widget_destroy (tab->priv->print_preview); + g_return_if_fail (tab->priv->state == XED_TAB_STATE_PRINTING); + } #endif - xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); + xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); - view = xed_tab_get_view (tab); - gtk_widget_grab_focus (GTK_WIDGET (view)); + view = xed_tab_get_view (tab); + gtk_widget_grab_focus (GTK_WIDGET (view)); - g_object_unref (tab->priv->print_job); - tab->priv->print_job = NULL; + g_object_unref (tab->priv->print_job); + tab->priv->print_job = NULL; } #if 0 static void print_preview_destroyed (GtkWidget *preview, - XedTab *tab) + XedTab *tab) { - tab->priv->print_preview = NULL; + tab->priv->print_preview = NULL; - if (tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW) - { - XedView *view; + if (tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW) + { + XedView *view; - xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); + xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); - view = xed_tab_get_view (tab); - gtk_widget_grab_focus (GTK_WIDGET (view)); - } - else - { - /* This should happen only when printing while showing the print - * preview. In this case let us continue whithout changing - * the state and show the document. See bug #352658 */ - gtk_widget_show (tab->priv->view_scrolled_window); + view = xed_tab_get_view (tab); + gtk_widget_grab_focus (GTK_WIDGET (view)); + } + else + { + /* This should happen only when printing while showing the print + * preview. In this case let us continue whithout changing + * the state and show the document. See bug #352658 */ + gtk_widget_show (tab->priv->view_scrolled_window); - g_return_if_fail (tab->priv->state == XED_TAB_STATE_PRINTING); - } + g_return_if_fail (tab->priv->state == XED_TAB_STATE_PRINTING); + } } #endif static void -show_preview_cb (XedPrintJob *job, - XedPrintPreview *preview, - XedTab *tab) +show_preview_cb (XedPrintJob *job, + XedPrintPreview *preview, + XedTab *tab) { -// g_return_if_fail (tab->priv->state == XED_TAB_STATE_PRINT_PREVIEWING); - g_return_if_fail (tab->priv->print_preview == NULL); +// g_return_if_fail (tab->priv->state == XED_TAB_STATE_PRINT_PREVIEWING); + g_return_if_fail (tab->priv->print_preview == NULL); - set_message_area (tab, NULL); /* destroy the message area */ + set_message_area (tab, NULL); /* destroy the message area */ - tab->priv->print_preview = GTK_WIDGET (preview); - gtk_box_pack_end (GTK_BOX (tab), - tab->priv->print_preview, - TRUE, - TRUE, - 0); - gtk_widget_show (tab->priv->print_preview); - gtk_widget_grab_focus (tab->priv->print_preview); + tab->priv->print_preview = GTK_WIDGET (preview); + gtk_box_pack_end (GTK_BOX (tab), tab->priv->print_preview, TRUE, TRUE, 0); + gtk_widget_show (tab->priv->print_preview); + gtk_widget_grab_focus (tab->priv->print_preview); /* when the preview gets destroyed we get "done" signal - g_signal_connect (tab->priv->print_preview, - "destroy", - G_CALLBACK (print_preview_destroyed), - tab); + g_signal_connect (tab->priv->print_preview, + "destroy", + G_CALLBACK (print_preview_destroyed), + tab); */ - xed_tab_set_state (tab, XED_TAB_STATE_SHOWING_PRINT_PREVIEW); + xed_tab_set_state (tab, XED_TAB_STATE_SHOWING_PRINT_PREVIEW); } #if 0 static void set_print_preview (XedTab *tab, - GtkWidget *print_preview) + GtkWidget *print_preview) { - if (tab->priv->print_preview == print_preview) - return; + if (tab->priv->print_preview == print_preview) + return; - if (tab->priv->print_preview != NULL) - gtk_widget_destroy (tab->priv->print_preview); + if (tab->priv->print_preview != NULL) + gtk_widget_destroy (tab->priv->print_preview); - tab->priv->print_preview = print_preview; + tab->priv->print_preview = print_preview; - gtk_box_pack_end (GTK_BOX (tab), - tab->priv->print_preview, - TRUE, - TRUE, - 0); + gtk_box_pack_end (GTK_BOX (tab), + tab->priv->print_preview, + TRUE, + TRUE, + 0); - gtk_widget_grab_focus (tab->priv->print_preview); + gtk_widget_grab_focus (tab->priv->print_preview); - g_signal_connect (tab->priv->print_preview, - "destroy", - G_CALLBACK (print_preview_destroyed), - tab); + g_signal_connect (tab->priv->print_preview, + "destroy", + G_CALLBACK (print_preview_destroyed), + tab); } static void preview_finished_cb (GtkSourcePrintJob *pjob, XedTab *tab) { - MatePrintJob *gjob; - GtkWidget *preview = NULL; + MatePrintJob *gjob; + GtkWidget *preview = NULL; - g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); - set_message_area (tab, NULL); /* destroy the message area */ + g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); + set_message_area (tab, NULL); /* destroy the message area */ - gjob = gtk_source_print_job_get_print_job (pjob); + gjob = gtk_source_print_job_get_print_job (pjob); - preview = xed_print_job_preview_new (gjob); - g_object_unref (gjob); + preview = xed_print_job_preview_new (gjob); + g_object_unref (gjob); - set_print_preview (tab, preview); + set_print_preview (tab, preview); - gtk_widget_show (preview); - g_object_unref (pjob); + gtk_widget_show (preview); + g_object_unref (pjob); - xed_tab_set_state (tab, XED_TAB_STATE_SHOWING_PRINT_PREVIEW); + xed_tab_set_state (tab, XED_TAB_STATE_SHOWING_PRINT_PREVIEW); } #endif static void -print_cancelled (GtkWidget *area, - gint response_id, - XedTab *tab) +print_cancelled (GtkWidget *area, + gint response_id, + XedTab *tab) { - g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); + g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area)); - xed_print_job_cancel (tab->priv->print_job); + xed_print_job_cancel (tab->priv->print_job); - g_debug ("print_cancelled"); + g_debug ("print_cancelled"); } static void -show_printing_message_area (XedTab *tab, gboolean preview) +show_printing_message_area (XedTab *tab, + gboolean preview) { - GtkWidget *area; + GtkWidget *area; - if (preview) - area = xed_progress_message_area_new (GTK_STOCK_PRINT_PREVIEW, - "", - TRUE); - else - area = xed_progress_message_area_new (GTK_STOCK_PRINT, - "", - TRUE); + if (preview) + { + area = xed_progress_message_area_new (GTK_STOCK_PRINT_PREVIEW, "", TRUE); + } + else + { + area = xed_progress_message_area_new (GTK_STOCK_PRINT, "", TRUE); + } - g_signal_connect (area, - "response", - G_CALLBACK (print_cancelled), - tab); + g_signal_connect (area, "response", + G_CALLBACK (print_cancelled), tab); - set_message_area (tab, area); + set_message_area (tab, area); } static void -xed_tab_print_or_print_preview (XedTab *tab, - GtkPrintOperationAction print_action) +xed_tab_print_or_print_preview (XedTab *tab, + GtkPrintOperationAction print_action) { - XedView *view; - gboolean is_preview; - GtkPageSetup *setup; - GtkPrintSettings *settings; - GtkPrintOperationResult res; - GError *error = NULL; + XedView *view; + gboolean is_preview; + GtkPageSetup *setup; + GtkPrintSettings *settings; + GtkPrintOperationResult res; + GError *error = NULL; - g_return_if_fail (tab->priv->print_job == NULL); - g_return_if_fail (tab->priv->state == XED_TAB_STATE_NORMAL); + g_return_if_fail (tab->priv->print_job == NULL); + g_return_if_fail (tab->priv->state == XED_TAB_STATE_NORMAL); - view = xed_tab_get_view (tab); + view = xed_tab_get_view (tab); - is_preview = (print_action == GTK_PRINT_OPERATION_ACTION_PREVIEW); + is_preview = (print_action == GTK_PRINT_OPERATION_ACTION_PREVIEW); - tab->priv->print_job = xed_print_job_new (view); - g_object_add_weak_pointer (G_OBJECT (tab->priv->print_job), - (gpointer *) &tab->priv->print_job); + tab->priv->print_job = xed_print_job_new (view); + g_object_add_weak_pointer (G_OBJECT (tab->priv->print_job), (gpointer *) &tab->priv->print_job); - show_printing_message_area (tab, is_preview); + show_printing_message_area (tab, is_preview); - g_signal_connect (tab->priv->print_job, - "printing", - G_CALLBACK (printing_cb), - tab); - g_signal_connect (tab->priv->print_job, - "show-preview", - G_CALLBACK (show_preview_cb), - tab); - g_signal_connect (tab->priv->print_job, - "done", - G_CALLBACK (done_printing_cb), - tab); + g_signal_connect (tab->priv->print_job, "printing", + G_CALLBACK (printing_cb), tab); + g_signal_connect (tab->priv->print_job, "show-preview", + G_CALLBACK (show_preview_cb), tab); + g_signal_connect (tab->priv->print_job, "done", + G_CALLBACK (done_printing_cb), tab); - if (is_preview) - xed_tab_set_state (tab, XED_TAB_STATE_PRINT_PREVIEWING); - else - xed_tab_set_state (tab, XED_TAB_STATE_PRINTING); + if (is_preview) + { + xed_tab_set_state (tab, XED_TAB_STATE_PRINT_PREVIEWING); + } + else + { + xed_tab_set_state (tab, XED_TAB_STATE_PRINTING); + } - setup = get_page_setup (tab); - settings = get_print_settings (tab); + setup = get_page_setup (tab); + settings = get_print_settings (tab); - res = xed_print_job_print (tab->priv->print_job, - print_action, - setup, - settings, - GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), - &error); + res = xed_print_job_print (tab->priv->print_job, + print_action, + setup, + settings, + GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), + &error); - // TODO: manage res in the correct way - if (res == GTK_PRINT_OPERATION_RESULT_ERROR) - { - /* FIXME: go in error state */ - xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); - g_warning ("Async print preview failed (%s)", error->message); - g_object_unref (tab->priv->print_job); - g_error_free (error); - } + // TODO: manage res in the correct way + if (res == GTK_PRINT_OPERATION_RESULT_ERROR) + { + /* FIXME: go in error state */ + xed_tab_set_state (tab, XED_TAB_STATE_NORMAL); + g_warning ("Async print preview failed (%s)", error->message); + g_object_unref (tab->priv->print_job); + g_error_free (error); + } } void -_xed_tab_print (XedTab *tab) +_xed_tab_print (XedTab *tab) { - g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail (XED_IS_TAB (tab)); - /* FIXME: currently we can have just one printoperation going on - * at a given time, so before starting the print we close the preview. - * Would be nice to handle it properly though */ - if (tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW) - { - gtk_widget_destroy (tab->priv->print_preview); - } + /* FIXME: currently we can have just one printoperation going on + * at a given time, so before starting the print we close the preview. + * Would be nice to handle it properly though */ + if (tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW) + { + gtk_widget_destroy (tab->priv->print_preview); + } - xed_tab_print_or_print_preview (tab, - GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); + xed_tab_print_or_print_preview (tab, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); } void -_xed_tab_print_preview (XedTab *tab) +_xed_tab_print_preview (XedTab *tab) { - g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail (XED_IS_TAB (tab)); - xed_tab_print_or_print_preview (tab, - GTK_PRINT_OPERATION_ACTION_PREVIEW); + xed_tab_print_or_print_preview (tab, GTK_PRINT_OPERATION_ACTION_PREVIEW); } void _xed_tab_mark_for_closing (XedTab *tab) { - g_return_if_fail (XED_IS_TAB (tab)); - g_return_if_fail (tab->priv->state == XED_TAB_STATE_NORMAL); + g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail (tab->priv->state == XED_TAB_STATE_NORMAL); - xed_tab_set_state (tab, XED_TAB_STATE_CLOSING); + xed_tab_set_state (tab, XED_TAB_STATE_CLOSING); } gboolean _xed_tab_can_close (XedTab *tab) { - XedDocument *doc; - XedTabState ts; + XedDocument *doc; + XedTabState ts; - g_return_val_if_fail (XED_IS_TAB (tab), FALSE); + g_return_val_if_fail (XED_IS_TAB (tab), FALSE); - ts = xed_tab_get_state (tab); + ts = xed_tab_get_state (tab); - /* if we are loading or reverting, the tab can be closed */ - if ((ts == XED_TAB_STATE_LOADING) || - (ts == XED_TAB_STATE_LOADING_ERROR) || - (ts == XED_TAB_STATE_REVERTING) || - (ts == XED_TAB_STATE_REVERTING_ERROR)) /* CHECK: I'm not sure this is the right behavior for REVERTING ERROR */ - return TRUE; + /* if we are loading or reverting, the tab can be closed */ + if ((ts == XED_TAB_STATE_LOADING) || + (ts == XED_TAB_STATE_LOADING_ERROR) || + (ts == XED_TAB_STATE_REVERTING) || + (ts == XED_TAB_STATE_REVERTING_ERROR)) /* CHECK: I'm not sure this is the right behavior for REVERTING ERROR */ + { + return TRUE; + } - /* Do not close tab with saving errors */ - if (ts == XED_TAB_STATE_SAVING_ERROR) - return FALSE; + /* Do not close tab with saving errors */ + if (ts == XED_TAB_STATE_SAVING_ERROR) + { + return FALSE; + } - doc = xed_tab_get_document (tab); + doc = xed_tab_get_document (tab); - /* TODO: we need to save the file also if it has been externally - modified - Paolo (Oct 10, 2005) */ + /* TODO: we need to save the file also if it has been externally + modified - Paolo (Oct 10, 2005) */ - return (!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)) && - !xed_document_get_deleted (doc)); + return (!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)) && !xed_document_get_deleted (doc)); } /** @@ -2626,13 +2512,13 @@ _xed_tab_can_close (XedTab *tab) * Return value: %TRUE if the autosave is enabled, else %FALSE **/ gboolean -xed_tab_get_auto_save_enabled (XedTab *tab) +xed_tab_get_auto_save_enabled (XedTab *tab) { - xed_debug (DEBUG_TAB); + xed_debug (DEBUG_TAB); - g_return_val_if_fail (XED_IS_TAB (tab), FALSE); + g_return_val_if_fail (XED_IS_TAB (tab), FALSE); - return tab->priv->auto_save; + return tab->priv->auto_save; } /** @@ -2644,50 +2530,52 @@ xed_tab_get_auto_save_enabled (XedTab *tab) * autosave timeout if the document is new or is read-only **/ void -xed_tab_set_auto_save_enabled (XedTab *tab, - gboolean enable) +xed_tab_set_auto_save_enabled (XedTab *tab, + gboolean enable) { - XedDocument *doc = NULL; - xed_debug (DEBUG_TAB); + XedDocument *doc = NULL; + xed_debug (DEBUG_TAB); - g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail (XED_IS_TAB (tab)); - doc = xed_tab_get_document (tab); + doc = xed_tab_get_document (tab); - if (tab->priv->auto_save == enable) - return; + if (tab->priv->auto_save == enable) + { + return; + } - tab->priv->auto_save = enable; + tab->priv->auto_save = enable; - if (enable && - (tab->priv->auto_save_timeout <=0) && - !xed_document_is_untitled (doc) && - !xed_document_get_readonly (doc)) - { - if ((tab->priv->state != XED_TAB_STATE_LOADING) && - (tab->priv->state != XED_TAB_STATE_SAVING) && - (tab->priv->state != XED_TAB_STATE_REVERTING) && - (tab->priv->state != XED_TAB_STATE_LOADING_ERROR) && - (tab->priv->state != XED_TAB_STATE_SAVING_ERROR) && - (tab->priv->state != XED_TAB_STATE_REVERTING_ERROR)) - { - install_auto_save_timeout (tab); - } - /* else: the timeout will be installed when loading/saving/reverting - will terminate */ + if (enable && + (tab->priv->auto_save_timeout <=0) && + !xed_document_is_untitled (doc) && + !xed_document_get_readonly (doc)) + { + if ((tab->priv->state != XED_TAB_STATE_LOADING) && + (tab->priv->state != XED_TAB_STATE_SAVING) && + (tab->priv->state != XED_TAB_STATE_REVERTING) && + (tab->priv->state != XED_TAB_STATE_LOADING_ERROR) && + (tab->priv->state != XED_TAB_STATE_SAVING_ERROR) && + (tab->priv->state != XED_TAB_STATE_REVERTING_ERROR)) + { + install_auto_save_timeout (tab); + } + /* else: the timeout will be installed when loading/saving/reverting + will terminate */ - return; - } + return; + } - if (!enable && (tab->priv->auto_save_timeout > 0)) - { - remove_auto_save_timeout (tab); + if (!enable && (tab->priv->auto_save_timeout > 0)) + { + remove_auto_save_timeout (tab); - return; - } + return; + } - g_return_if_fail ((!enable && (tab->priv->auto_save_timeout <= 0)) || - xed_document_is_untitled (doc) || xed_document_get_readonly (doc)); + g_return_if_fail ((!enable && (tab->priv->auto_save_timeout <= 0)) || + xed_document_is_untitled (doc) || xed_document_get_readonly (doc)); } /** @@ -2701,11 +2589,11 @@ xed_tab_set_auto_save_enabled (XedTab *tab, gint xed_tab_get_auto_save_interval (XedTab *tab) { - xed_debug (DEBUG_TAB); + xed_debug (DEBUG_TAB); - g_return_val_if_fail (XED_IS_TAB (tab), 0); + g_return_val_if_fail (XED_IS_TAB (tab), 0); - return tab->priv->auto_save_interval; + return tab->priv->auto_save_interval; } /** @@ -2720,45 +2608,49 @@ xed_tab_get_auto_save_interval (XedTab *tab) **/ void xed_tab_set_auto_save_interval (XedTab *tab, - gint interval) + gint interval) { - XedDocument *doc = NULL; + XedDocument *doc = NULL; - xed_debug (DEBUG_TAB); + xed_debug (DEBUG_TAB); - g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail (XED_IS_TAB (tab)); - doc = xed_tab_get_document(tab); + doc = xed_tab_get_document(tab); - g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail (interval > 0); + g_return_if_fail (XED_IS_DOCUMENT (doc)); + g_return_if_fail (interval > 0); - if (tab->priv->auto_save_interval == interval) - return; + if (tab->priv->auto_save_interval == interval) + { + return; + } - tab->priv->auto_save_interval = interval; + tab->priv->auto_save_interval = interval; - if (!tab->priv->auto_save) - return; + if (!tab->priv->auto_save) + { + return; + } - if (tab->priv->auto_save_timeout > 0) - { - g_return_if_fail (!xed_document_is_untitled (doc)); - g_return_if_fail (!xed_document_get_readonly (doc)); + if (tab->priv->auto_save_timeout > 0) + { + g_return_if_fail (!xed_document_is_untitled (doc)); + g_return_if_fail (!xed_document_get_readonly (doc)); - remove_auto_save_timeout (tab); + remove_auto_save_timeout (tab); - install_auto_save_timeout (tab); - } + install_auto_save_timeout (tab); + } } void -xed_tab_set_info_bar (XedTab *tab, - GtkWidget *info_bar) +xed_tab_set_info_bar (XedTab *tab, + GtkWidget *info_bar) { - g_return_if_fail (XED_IS_TAB (tab)); - g_return_if_fail (info_bar == NULL || GTK_IS_WIDGET (info_bar)); + g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail (info_bar == NULL || GTK_IS_WIDGET (info_bar)); - /* FIXME: this can cause problems with the tab state machine */ - set_message_area (tab, info_bar); + /* FIXME: this can cause problems with the tab state machine */ + set_message_area (tab, info_bar); } From d77659fdcd763f92e8e568022cea57ef45bdb092 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 1 Jan 2017 21:41:09 -0800 Subject: [PATCH 068/132] xed-tab: Clean up some uses of GtkStock --- xed/xed-tab-label.c | 23 ++++++---- xed/xed-tab.c | 108 ++++++++++++-------------------------------- 2 files changed, 44 insertions(+), 87 deletions(-) diff --git a/xed/xed-tab-label.c b/xed/xed-tab-label.c index 22bd3ec..47d36e9 100644 --- a/xed/xed-tab-label.c +++ b/xed/xed-tab-label.c @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ @@ -108,7 +108,7 @@ xed_tab_label_get_property (GObject *object, } static void -close_button_clicked_cb (GtkWidget *widget, +close_button_clicked_cb (GtkWidget *widget, XedTabLabel *tab_label) { g_signal_emit (tab_label, signals[CLOSE_CLICKED], 0, NULL); @@ -172,12 +172,17 @@ sync_state (XedTab *tab, GParamSpec *pspec, XedTabLabel *tab_label) GdkPixbuf *pixbuf; pixbuf = _xed_tab_get_icon (tab); - gtk_image_set_from_pixbuf (GTK_IMAGE (tab_label->priv->icon), pixbuf); - if (pixbuf != NULL) - g_object_unref (pixbuf); - - gtk_widget_show (tab_label->priv->icon); + if (pixbuf != NULL) + { + gtk_image_set_from_pixbuf (GTK_IMAGE (tab_label->priv->icon), pixbuf); + g_clear_object (&pixbuf); + gtk_widget_show (tab_label->priv->icon); + } + else + { + gtk_widget_hide (tab_label->priv->icon); + } gtk_widget_hide (tab_label->priv->spinner); gtk_spinner_stop (GTK_SPINNER (tab_label->priv->spinner)); @@ -218,7 +223,7 @@ static void xed_tab_label_class_init (XedTabLabelClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - + object_class->finalize = xed_tab_label_finalize; object_class->set_property = xed_tab_label_set_property; object_class->get_property = xed_tab_label_get_property; @@ -329,7 +334,7 @@ xed_tab_label_set_close_button_sensitive (XedTabLabel *tab_label, state = xed_tab_get_state (tab_label->priv->tab); - gtk_widget_set_sensitive (tab_label->priv->close_button, + gtk_widget_set_sensitive (tab_label->priv->close_button, tab_label->priv->close_button_sensitive && (state != XED_TAB_STATE_CLOSING) && (state != XED_TAB_STATE_SAVING) && diff --git a/xed/xed-tab.c b/xed/xed-tab.c index a15953c..77b9947 100644 --- a/xed/xed-tab.c +++ b/xed/xed-tab.c @@ -1656,55 +1656,6 @@ _xed_tab_get_tooltips (XedTab *tab) return tip; } -static GdkPixbuf * -resize_icon (GdkPixbuf *pixbuf, - gint size) -{ - gint width, height; - - width = gdk_pixbuf_get_width (pixbuf); - height = gdk_pixbuf_get_height (pixbuf); - - /* if the icon is larger than the nominal size, scale down */ - if (MAX (width, height) > size) - { - GdkPixbuf *scaled_pixbuf; - - if (width > height) - { - height = height * size / width; - width = size; - } - else - { - width = width * size / height; - height = size; - } - - scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR); - g_object_unref (pixbuf); - pixbuf = scaled_pixbuf; - } - - return pixbuf; -} - -static GdkPixbuf * -get_stock_icon (GtkIconTheme *theme, - const gchar *stock, - gint size) -{ - GdkPixbuf *pixbuf; - - pixbuf = gtk_icon_theme_load_icon (theme, stock, size, 0, NULL); - if (pixbuf == NULL) - { - return NULL; - } - - return resize_icon (pixbuf, size); -} - static GdkPixbuf * get_icon (GtkIconTheme *theme, GFile *location, @@ -1717,7 +1668,7 @@ get_icon (GtkIconTheme *theme, if (location == NULL) { - return get_stock_icon (theme, GTK_STOCK_FILE, size); + return gtk_icon_theme_load_icon (theme, "text-x-generic", size, 0, NULL); } /* FIXME: Doing a sync stat is bad, this should be fixed */ @@ -1728,7 +1679,7 @@ get_icon (GtkIconTheme *theme, NULL); if (info == NULL) { - return get_stock_icon (theme, GTK_STOCK_FILE, size); + return gtk_icon_theme_load_icon (theme, "text-x-generic", size, 0, NULL); } gicon = g_file_info_get_icon (info); @@ -1736,7 +1687,7 @@ get_icon (GtkIconTheme *theme, if (gicon == NULL) { g_object_unref (info); - return get_stock_icon (theme, GTK_STOCK_FILE, size); + return gtk_icon_theme_load_icon (theme, "text-x-generic", size, 0, NULL); } icon_info = gtk_icon_theme_lookup_by_gicon (theme, gicon, size, 0); @@ -1744,18 +1695,18 @@ get_icon (GtkIconTheme *theme, if (icon_info == NULL) { - return get_stock_icon (theme, GTK_STOCK_FILE, size); + return gtk_icon_theme_load_icon (theme, "text-x-generic", size, 0, NULL); } pixbuf = gtk_icon_info_load_icon (icon_info, NULL); - gtk_icon_info_free (icon_info); + g_object_unref (icon_info); if (pixbuf == NULL) { - return get_stock_icon (theme, GTK_STOCK_FILE, size); + return gtk_icon_theme_load_icon (theme, "text-x-generic", size, 0, NULL); } - return resize_icon (pixbuf, size); + return pixbuf; } /* FIXME: add support for theme changed. I think it should be as easy as @@ -1763,15 +1714,15 @@ get_icon (GtkIconTheme *theme, GdkPixbuf * _xed_tab_get_icon (XedTab *tab) { - GdkPixbuf *pixbuf; - GtkIconTheme *theme; GdkScreen *screen; + GtkIconTheme *theme; gint icon_size; + const gchar *icon_name; + GdkPixbuf *pixbuf = NULL; g_return_val_if_fail (XED_IS_TAB (tab), NULL); screen = gtk_widget_get_screen (GTK_WIDGET (tab)); - theme = gtk_icon_theme_get_for_screen (screen); g_return_val_if_fail (theme != NULL, NULL); @@ -1780,52 +1731,53 @@ _xed_tab_get_icon (XedTab *tab) switch (tab->priv->state) { case XED_TAB_STATE_LOADING: - pixbuf = get_stock_icon (theme, GTK_STOCK_OPEN, icon_size); + icon_name = "document-open-symbolic"; break; case XED_TAB_STATE_REVERTING: - pixbuf = get_stock_icon (theme, GTK_STOCK_REVERT_TO_SAVED, icon_size); + icon_name = "document-revert-symbolic"; break; case XED_TAB_STATE_SAVING: - pixbuf = get_stock_icon (theme, GTK_STOCK_SAVE, icon_size); + icon_name = "document-save-symbolic"; break; case XED_TAB_STATE_PRINTING: - pixbuf = get_stock_icon (theme, GTK_STOCK_PRINT, icon_size); + icon_name = "printer-printing-symbolic"; break; case XED_TAB_STATE_PRINT_PREVIEWING: case XED_TAB_STATE_SHOWING_PRINT_PREVIEW: - pixbuf = get_stock_icon (theme, GTK_STOCK_PRINT_PREVIEW, icon_size); + icon_name = "printer-symbolic"; break; case XED_TAB_STATE_LOADING_ERROR: case XED_TAB_STATE_REVERTING_ERROR: case XED_TAB_STATE_SAVING_ERROR: case XED_TAB_STATE_GENERIC_ERROR: - pixbuf = get_stock_icon (theme, GTK_STOCK_DIALOG_ERROR, icon_size); + icon_name = "dialog-error-symbolic"; break; case XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION: - pixbuf = get_stock_icon (theme, GTK_STOCK_DIALOG_WARNING, icon_size); + icon_name = "dialog-warning-symbolic"; break; default: - { - GFile *location; - XedDocument *doc; + icon_name = NULL; + } - doc = xed_tab_get_document (tab); + if (icon_name != NULL) + { + pixbuf = gtk_icon_theme_load_icon (theme, icon_name, icon_size, 0, NULL); + } + else + { + GFile *location; + XedDocument *doc; - location = xed_document_get_location (doc); - pixbuf = get_icon (theme, location, icon_size); - - if (location) - { - g_object_unref (location); - } - } + doc = xed_tab_get_document (tab); + location = xed_document_get_location (doc); + pixbuf = get_icon (theme, location, icon_size); } return pixbuf; From c2eab264a35f98e11fbdc22e10d0450f6ca433ae Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 2 Jan 2017 16:14:42 -0800 Subject: [PATCH 069/132] xed-window: Use a better icon for the documents panel tab --- xed/xed-window.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xed/xed-window.c b/xed/xed-window.c index 797cca0..4324f82 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -3177,8 +3177,7 @@ create_side_panel (XedWindow *window) g_signal_connect_after (window->priv->side_panel, "hide", G_CALLBACK (side_panel_visibility_changed), window); documents_panel = xed_documents_panel_new (window); - xed_panel_add_item (XED_PANEL (window->priv->side_panel), documents_panel, _("Documents"), - GTK_STOCK_FILE); + xed_panel_add_item (XED_PANEL (window->priv->side_panel), documents_panel, _("Documents"), "text-x-generic"); } static void From 663511c1d1c31b85f9e8dae6f70b16ea4e10e234 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 7 Jan 2017 01:14:21 -0800 Subject: [PATCH 070/132] xed-print-preview.c: Clean up code styling --- xed/xed-print-preview.c | 1649 +++++++++++++++++++-------------------- 1 file changed, 805 insertions(+), 844 deletions(-) diff --git a/xed/xed-print-preview.c b/xed/xed-print-preview.c index ec2271e..63cff00 100644 --- a/xed/xed-print-preview.c +++ b/xed/xed-print-preview.c @@ -44,140 +44,138 @@ struct _XedPrintPreviewPrivate { - GtkPrintOperation *operation; - GtkPrintContext *context; - GtkPrintOperationPreview *gtk_preview; + GtkPrintOperation *operation; + GtkPrintContext *context; + GtkPrintOperationPreview *gtk_preview; - GtkWidget *layout; - GtkWidget *scrolled_window; + GtkWidget *layout; + GtkWidget *scrolled_window; - GtkToolItem *next; - GtkToolItem *prev; - GtkWidget *page_entry; - GtkWidget *last; - GtkToolItem *multi; - GtkToolItem *zoom_one; - GtkToolItem *zoom_fit; - GtkToolItem *zoom_in; - GtkToolItem *zoom_out; + GtkToolItem *next; + GtkToolItem *prev; + GtkWidget *page_entry; + GtkWidget *last; + GtkToolItem *multi; + GtkToolItem *zoom_one; + GtkToolItem *zoom_fit; + GtkToolItem *zoom_in; + GtkToolItem *zoom_out; - /* real size of the page in inches */ - double paper_w; - double paper_h; - double dpi; + /* real size of the page in inches */ + double paper_w; + double paper_h; + double dpi; - double scale; + double scale; - /* size of the tile of a page (including padding - * and drop shadow) in pixels */ - gint tile_w; - gint tile_h; + /* size of the tile of a page (including padding + * and drop shadow) in pixels */ + gint tile_w; + gint tile_h; - GtkPageOrientation orientation; + GtkPageOrientation orientation; - /* multipage support */ - gint rows; - gint cols; + /* multipage support */ + gint rows; + gint cols; - guint n_pages; - guint cur_page; + guint n_pages; + guint cur_page; }; G_DEFINE_TYPE (XedPrintPreview, xed_print_preview, GTK_TYPE_BOX) -static void +static void xed_print_preview_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - //XedPrintPreview *preview = XED_PRINT_PREVIEW (object); - - switch (prop_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + //XedPrintPreview *preview = XED_PRINT_PREVIEW (object); + + switch (prop_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } -static void +static void xed_print_preview_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - //XedPrintPreview *preview = XED_PRINT_PREVIEW (object); - - switch (prop_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + //XedPrintPreview *preview = XED_PRINT_PREVIEW (object); + + switch (prop_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_print_preview_finalize (GObject *object) { - //XedPrintPreview *preview = XED_PRINT_PREVIEW (object); + //XedPrintPreview *preview = XED_PRINT_PREVIEW (object); - G_OBJECT_CLASS (xed_print_preview_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_print_preview_parent_class)->finalize (object); } static void xed_print_preview_grab_focus (GtkWidget *widget) { - XedPrintPreview *preview; + XedPrintPreview *preview; - preview = XED_PRINT_PREVIEW (widget); + preview = XED_PRINT_PREVIEW (widget); - gtk_widget_grab_focus (GTK_WIDGET (preview->priv->layout)); + gtk_widget_grab_focus (GTK_WIDGET (preview->priv->layout)); } -static void +static void xed_print_preview_class_init (XedPrintPreviewClass *klass) { - GObjectClass *object_class; - GtkWidgetClass *widget_class; + GObjectClass *object_class; + GtkWidgetClass *widget_class; - object_class = G_OBJECT_CLASS (klass); - widget_class = GTK_WIDGET_CLASS (klass); + object_class = G_OBJECT_CLASS (klass); + widget_class = GTK_WIDGET_CLASS (klass); - object_class->get_property = xed_print_preview_get_property; - object_class->set_property = xed_print_preview_set_property; - object_class->finalize = xed_print_preview_finalize; + object_class->get_property = xed_print_preview_get_property; + object_class->set_property = xed_print_preview_set_property; + object_class->finalize = xed_print_preview_finalize; - widget_class->grab_focus = xed_print_preview_grab_focus; + widget_class->grab_focus = xed_print_preview_grab_focus; - g_type_class_add_private (object_class, sizeof(XedPrintPreviewPrivate)); + g_type_class_add_private (object_class, sizeof(XedPrintPreviewPrivate)); } static void update_layout_size (XedPrintPreview *preview) { - XedPrintPreviewPrivate *priv; + XedPrintPreviewPrivate *priv; - priv = preview->priv; + priv = preview->priv; - /* force size of the drawing area to make the scrolled window work */ - gtk_layout_set_size (GTK_LAYOUT (priv->layout), - priv->tile_w * priv->cols, - priv->tile_h * priv->rows); + /* force size of the drawing area to make the scrolled window work */ + gtk_layout_set_size (GTK_LAYOUT (priv->layout), priv->tile_w * priv->cols, priv->tile_h * priv->rows); - gtk_widget_queue_draw (preview->priv->layout); + gtk_widget_queue_draw (preview->priv->layout); } static void set_rows_and_cols (XedPrintPreview *preview, - gint rows, - gint cols) + gint rows, + gint cols) { - /* TODO: set the zoom appropriately */ + /* TODO: set the zoom appropriately */ - preview->priv->rows = rows; - preview->priv->cols = cols; - update_layout_size (preview); + preview->priv->rows = rows; + preview->priv->cols = cols; + update_layout_size (preview); } /* get the paper size in points: these must be used only @@ -186,17 +184,17 @@ set_rows_and_cols (XedPrintPreview *preview, static double get_paper_width (XedPrintPreview *preview) { - return preview->priv->paper_w * preview->priv->dpi; + return preview->priv->paper_w * preview->priv->dpi; } static double get_paper_height (XedPrintPreview *preview) { - return preview->priv->paper_h * preview->priv->dpi; + return preview->priv->paper_h * preview->priv->dpi; } #define PAGE_PAD 12 -#define PAGE_SHADOW_OFFSET 5 +#define PAGE_SHADOW_OFFSET 5 /* The tile size is the size of the area where a page * will be drawn including the padding and idependent @@ -206,25 +204,25 @@ get_paper_height (XedPrintPreview *preview) static void update_tile_size (XedPrintPreview *preview) { - XedPrintPreviewPrivate *priv; - gint w, h; + XedPrintPreviewPrivate *priv; + gint w, h; - priv = preview->priv; + priv = preview->priv; - w = 2 * PAGE_PAD + floor (priv->scale * get_paper_width (preview) + 0.5); - h = 2 * PAGE_PAD + floor (priv->scale * get_paper_height (preview) + 0.5); + w = 2 * PAGE_PAD + floor (priv->scale * get_paper_width (preview) + 0.5); + h = 2 * PAGE_PAD + floor (priv->scale * get_paper_height (preview) + 0.5); - if ((priv->orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) || - (priv->orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE)) - { - priv->tile_w = h; - priv->tile_h = w; - } - else - { - priv->tile_w = w; - priv->tile_h = h; - } + if ((priv->orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) || + (priv->orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE)) + { + priv->tile_w = h; + priv->tile_h = w; + } + else + { + priv->tile_w = w; + priv->tile_h = h; + } } /* Zoom should always be set with one of these two function @@ -232,67 +230,63 @@ update_tile_size (XedPrintPreview *preview) static void set_zoom_factor (XedPrintPreview *preview, - double zoom) + double zoom) { - XedPrintPreviewPrivate *priv; + XedPrintPreviewPrivate *priv; - priv = preview->priv; + priv = preview->priv; - priv->scale = zoom; + priv->scale = zoom; - update_tile_size (preview); - update_layout_size (preview); + update_tile_size (preview); + update_layout_size (preview); } static void set_zoom_fit_to_size (XedPrintPreview *preview) { - XedPrintPreviewPrivate *priv; - double width, height; - double p_width, p_height; - double zoomx, zoomy; + XedPrintPreviewPrivate *priv; + double width, height; + double p_width, p_height; + double zoomx, zoomy; - priv = preview->priv; + priv = preview->priv; - g_object_get (gtk_layout_get_hadjustment (GTK_LAYOUT (priv->layout)), - "page-size", &width, - NULL); - g_object_get (gtk_layout_get_vadjustment (GTK_LAYOUT (priv->layout)), - "page-size", &height, - NULL); + g_object_get (gtk_layout_get_hadjustment (GTK_LAYOUT (priv->layout)), "page-size", &width, NULL); + g_object_get (gtk_layout_get_vadjustment (GTK_LAYOUT (priv->layout)), "page-size", &height, NULL); - width /= priv->cols; - height /= priv->rows; + width /= priv->cols; + height /= priv->rows; - if ((priv->orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) || - (priv->orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE)) - { - p_width = get_paper_height (preview); - p_height = get_paper_width (preview); - } - else - { - p_width = get_paper_width (preview); - p_height = get_paper_height (preview); - } + if ((priv->orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) || + (priv->orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE)) + { + p_width = get_paper_height (preview); + p_height = get_paper_width (preview); + } + else + { + p_width = get_paper_width (preview); + p_height = get_paper_height (preview); + } - zoomx = MAX (1, width - 2 * PAGE_PAD) / p_width; - zoomy = MAX (1, height - 2 * PAGE_PAD) / p_height; + zoomx = MAX (1, width - 2 * PAGE_PAD) / p_width; + zoomy = MAX (1, height - 2 * PAGE_PAD) / p_height; - if (zoomx <= zoomy) - { - priv->tile_w = width; - priv->tile_h = floor (0.5 + width * (p_height / p_width)); - priv->scale = zoomx; - } - else - { - priv->tile_w = floor (0.5 + height * (p_width / p_height)); - priv->tile_h = height; - priv->scale = zoomy; - } + if (zoomx <= zoomy) + { + priv->tile_w = width; + priv->tile_h = floor (0.5 + width * (p_height / p_width)); + priv->scale = zoomx; + } + else + { + priv->tile_w = floor (0.5 + height * (p_width / p_height)); + priv->tile_h = height; + priv->scale = zoomy; + } - update_layout_size (preview); + update_layout_size (preview); } #define ZOOM_IN_FACTOR (1.2) @@ -301,746 +295,721 @@ set_zoom_fit_to_size (XedPrintPreview *preview) static void zoom_in (XedPrintPreview *preview) { - set_zoom_factor (preview, - preview->priv->scale * ZOOM_IN_FACTOR); + set_zoom_factor (preview, preview->priv->scale * ZOOM_IN_FACTOR); } static void zoom_out (XedPrintPreview *preview) { - set_zoom_factor (preview, - preview->priv->scale * ZOOM_OUT_FACTOR); + set_zoom_factor (preview, preview->priv->scale * ZOOM_OUT_FACTOR); } static void -goto_page (XedPrintPreview *preview, gint page) +goto_page (XedPrintPreview *preview, + gint page) { - gchar c[32]; + gchar c[32]; - g_snprintf (c, 32, "%d", page + 1); - gtk_entry_set_text (GTK_ENTRY (preview->priv->page_entry), c); + g_snprintf (c, 32, "%d", page + 1); + gtk_entry_set_text (GTK_ENTRY (preview->priv->page_entry), c); - gtk_widget_set_sensitive (GTK_WIDGET (preview->priv->prev), - (page > 0) && (preview->priv->n_pages > 1)); - gtk_widget_set_sensitive (GTK_WIDGET (preview->priv->next), - (page != (preview->priv->n_pages - 1)) && - (preview->priv->n_pages > 1)); + gtk_widget_set_sensitive (GTK_WIDGET (preview->priv->prev), (page > 0) && (preview->priv->n_pages > 1)); + gtk_widget_set_sensitive (GTK_WIDGET (preview->priv->next), + (page != (preview->priv->n_pages - 1)) && + (preview->priv->n_pages > 1)); - if (page != preview->priv->cur_page) - { - preview->priv->cur_page = page; - if (preview->priv->n_pages > 0) - gtk_widget_queue_draw (preview->priv->layout); - } + if (page != preview->priv->cur_page) + { + preview->priv->cur_page = page; + if (preview->priv->n_pages > 0) + { + gtk_widget_queue_draw (preview->priv->layout); + } + } } static void -prev_button_clicked (GtkWidget *button, - XedPrintPreview *preview) +prev_button_clicked (GtkWidget *button, + XedPrintPreview *preview) { - GdkEvent *event; - gint page; + GdkEvent *event; + gint page; - event = gtk_get_current_event (); + event = gtk_get_current_event (); - if (event->button.state & GDK_SHIFT_MASK) - page = 0; - else - page = preview->priv->cur_page - preview->priv->rows * preview->priv->cols; + if (event->button.state & GDK_SHIFT_MASK) + { + page = 0; + } + else + { + page = preview->priv->cur_page - preview->priv->rows * preview->priv->cols; + } - goto_page (preview, MAX (page, 0)); + goto_page (preview, MAX (page, 0)); - gdk_event_free (event); + gdk_event_free (event); } static void -next_button_clicked (GtkWidget *button, - XedPrintPreview *preview) +next_button_clicked (GtkWidget *button, + XedPrintPreview *preview) { - GdkEvent *event; - gint page; + GdkEvent *event; + gint page; - event = gtk_get_current_event (); + event = gtk_get_current_event (); - if (event->button.state & GDK_SHIFT_MASK) - page = preview->priv->n_pages - 1; - else - page = preview->priv->cur_page + preview->priv->rows * preview->priv->cols; + if (event->button.state & GDK_SHIFT_MASK) + { + page = preview->priv->n_pages - 1; + } + else + { + page = preview->priv->cur_page + preview->priv->rows * preview->priv->cols; + } - goto_page (preview, MIN (page, preview->priv->n_pages - 1)); + goto_page (preview, MIN (page, preview->priv->n_pages - 1)); - gdk_event_free (event); + gdk_event_free (event); } static void -page_entry_activated (GtkEntry *entry, - XedPrintPreview *preview) +page_entry_activated (GtkEntry *entry, + XedPrintPreview *preview) { - const gchar *text; - gint page; + const gchar *text; + gint page; - text = gtk_entry_get_text (entry); + text = gtk_entry_get_text (entry); - page = CLAMP (atoi (text), 1, preview->priv->n_pages) - 1; - goto_page (preview, page); + page = CLAMP (atoi (text), 1, preview->priv->n_pages) - 1; + goto_page (preview, page); - gtk_widget_grab_focus (GTK_WIDGET (preview->priv->layout)); + gtk_widget_grab_focus (GTK_WIDGET (preview->priv->layout)); } static void page_entry_insert_text (GtkEditable *editable, - const gchar *text, - gint length, - gint *position) + const gchar *text, + gint length, + gint *position) { - gunichar c; - const gchar *p; - const gchar *end; + gunichar c; + const gchar *p; + const gchar *end; - p = text; - end = text + length; + p = text; + end = text + length; - while (p != end) - { - const gchar *next; - next = g_utf8_next_char (p); + while (p != end) + { + const gchar *next; + next = g_utf8_next_char (p); - c = g_utf8_get_char (p); + c = g_utf8_get_char (p); - if (!g_unichar_isdigit (c)) - { - g_signal_stop_emission_by_name (editable, "insert-text"); - break; - } + if (!g_unichar_isdigit (c)) + { + g_signal_stop_emission_by_name (editable, "insert-text"); + break; + } - p = next; - } + p = next; + } } -static gboolean -page_entry_focus_out (GtkWidget *widget, - GdkEventFocus *event, - XedPrintPreview *preview) +static gboolean +page_entry_focus_out (GtkWidget *widget, + GdkEventFocus *event, + XedPrintPreview *preview) { - const gchar *text; - gint page; + const gchar *text; + gint page; - text = gtk_entry_get_text (GTK_ENTRY (widget)); - page = atoi (text) - 1; + text = gtk_entry_get_text (GTK_ENTRY (widget)); + page = atoi (text) - 1; - /* Reset the page number only if really needed */ - if (page != preview->priv->cur_page) - { - gchar *str; + /* Reset the page number only if really needed */ + if (page != preview->priv->cur_page) + { + gchar *str; - str = g_strdup_printf ("%d", preview->priv->cur_page + 1); - gtk_entry_set_text (GTK_ENTRY (widget), str); - g_free (str); - } + str = g_strdup_printf ("%d", preview->priv->cur_page + 1); + gtk_entry_set_text (GTK_ENTRY (widget), str); + g_free (str); + } - return FALSE; + return FALSE; } static void -on_1x1_clicked (GtkMenuItem *i, XedPrintPreview *preview) +on_1x1_clicked (GtkMenuItem *i, + XedPrintPreview *preview) { - set_rows_and_cols (preview, 1, 1); + set_rows_and_cols (preview, 1, 1); } static void -on_1x2_clicked (GtkMenuItem *i, XedPrintPreview *preview) +on_1x2_clicked (GtkMenuItem *i, + XedPrintPreview *preview) { - set_rows_and_cols (preview, 1, 2); + set_rows_and_cols (preview, 1, 2); } static void -on_2x1_clicked (GtkMenuItem *i, XedPrintPreview *preview) +on_2x1_clicked (GtkMenuItem *i, + XedPrintPreview *preview) { - set_rows_and_cols (preview, 2, 1); + set_rows_and_cols (preview, 2, 1); } static void -on_2x2_clicked (GtkMenuItem *i, XedPrintPreview *preview) +on_2x2_clicked (GtkMenuItem *i, + XedPrintPreview *preview) { - set_rows_and_cols (preview, 2, 2); + set_rows_and_cols (preview, 2, 2); } static void -multi_button_clicked (GtkWidget *button, - XedPrintPreview *preview) +multi_button_clicked (GtkWidget *button, + XedPrintPreview *preview) { - GtkWidget *m, *i; + GtkWidget *m, *i; - m = gtk_menu_new (); - gtk_widget_show (m); - g_signal_connect (m, - "selection_done", - G_CALLBACK (gtk_widget_destroy), - m); + m = gtk_menu_new (); + gtk_widget_show (m); + g_signal_connect (m, "selection_done", + G_CALLBACK (gtk_widget_destroy), m); - i = gtk_menu_item_new_with_label ("1x1"); - gtk_widget_show (i); - gtk_menu_attach (GTK_MENU (m), i, 0, 1, 0, 1); - g_signal_connect (i, "activate", G_CALLBACK (on_1x1_clicked), preview); + i = gtk_menu_item_new_with_label ("1x1"); + gtk_widget_show (i); + gtk_menu_attach (GTK_MENU (m), i, 0, 1, 0, 1); + g_signal_connect (i, "activate", G_CALLBACK (on_1x1_clicked), preview); - i = gtk_menu_item_new_with_label ("2x1"); - gtk_widget_show (i); - gtk_menu_attach (GTK_MENU (m), i, 0, 1, 1, 2); - g_signal_connect (i, "activate", G_CALLBACK (on_2x1_clicked), preview); + i = gtk_menu_item_new_with_label ("2x1"); + gtk_widget_show (i); + gtk_menu_attach (GTK_MENU (m), i, 0, 1, 1, 2); + g_signal_connect (i, "activate", G_CALLBACK (on_2x1_clicked), preview); - i = gtk_menu_item_new_with_label ("1x2"); - gtk_widget_show (i); - gtk_menu_attach (GTK_MENU (m), i, 1, 2, 0, 1); - g_signal_connect (i, "activate", G_CALLBACK (on_1x2_clicked), preview); + i = gtk_menu_item_new_with_label ("1x2"); + gtk_widget_show (i); + gtk_menu_attach (GTK_MENU (m), i, 1, 2, 0, 1); + g_signal_connect (i, "activate", G_CALLBACK (on_1x2_clicked), preview); - i = gtk_menu_item_new_with_label ("2x2"); - gtk_widget_show (i); - gtk_menu_attach (GTK_MENU (m), i, 1, 2, 1, 2); - g_signal_connect (i, "activate", G_CALLBACK (on_2x2_clicked), preview); + i = gtk_menu_item_new_with_label ("2x2"); + gtk_widget_show (i); + gtk_menu_attach (GTK_MENU (m), i, 1, 2, 1, 2); + g_signal_connect (i, "activate", G_CALLBACK (on_2x2_clicked), preview); - gtk_menu_popup (GTK_MENU (m), - NULL, NULL, NULL, preview, 0, - GDK_CURRENT_TIME); + gtk_menu_popup (GTK_MENU (m), NULL, NULL, NULL, preview, 0, GDK_CURRENT_TIME); } static void -zoom_one_button_clicked (GtkWidget *button, - XedPrintPreview *preview) +zoom_one_button_clicked (GtkWidget *button, + XedPrintPreview *preview) { - set_zoom_factor (preview, 1); + set_zoom_factor (preview, 1); } static void -zoom_fit_button_clicked (GtkWidget *button, - XedPrintPreview *preview) +zoom_fit_button_clicked (GtkWidget *button, + XedPrintPreview *preview) { - set_zoom_fit_to_size (preview); + set_zoom_fit_to_size (preview); } static void -zoom_in_button_clicked (GtkWidget *button, - XedPrintPreview *preview) +zoom_in_button_clicked (GtkWidget *button, + XedPrintPreview *preview) { - zoom_in (preview); + zoom_in (preview); } static void -zoom_out_button_clicked (GtkWidget *button, - XedPrintPreview *preview) +zoom_out_button_clicked (GtkWidget *button, + XedPrintPreview *preview) { - zoom_out (preview); + zoom_out (preview); } static void -close_button_clicked (GtkWidget *button, - XedPrintPreview *preview) +close_button_clicked (GtkWidget *button, + XedPrintPreview *preview) { - gtk_widget_destroy (GTK_WIDGET (preview)); + gtk_widget_destroy (GTK_WIDGET (preview)); } static void create_bar (XedPrintPreview *preview) { - XedPrintPreviewPrivate *priv; - GtkWidget *toolbar; - GtkToolItem *i; - AtkObject *atko; - GtkWidget *status; + XedPrintPreviewPrivate *priv; + GtkWidget *toolbar; + GtkToolItem *i; + AtkObject *atko; + GtkWidget *status; - priv = preview->priv; + priv = preview->priv; - toolbar = gtk_toolbar_new (); - gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), - GTK_TOOLBAR_BOTH_HORIZ); - gtk_widget_show (toolbar); - gtk_box_pack_start (GTK_BOX (preview), - toolbar, - FALSE, FALSE, 0); + toolbar = gtk_toolbar_new (); + gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ); + gtk_widget_show (toolbar); + gtk_box_pack_start (GTK_BOX (preview), toolbar, FALSE, FALSE, 0); - priv->prev = gtk_tool_button_new_from_stock (GTK_STOCK_GO_BACK); - gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->prev), - "P_revious Page"); - gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (priv->prev), TRUE); - gtk_tool_item_set_tooltip_text (priv->prev, _("Show the previous page")); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->prev, -1); - g_signal_connect (priv->prev, - "clicked", - G_CALLBACK (prev_button_clicked), - preview); - gtk_widget_show (GTK_WIDGET (priv->prev)); + priv->prev = gtk_tool_button_new_from_stock (GTK_STOCK_GO_BACK); + gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->prev), "P_revious Page"); + gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (priv->prev), TRUE); + gtk_tool_item_set_tooltip_text (priv->prev, _("Show the previous page")); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->prev, -1); + g_signal_connect (priv->prev, "clicked", + G_CALLBACK (prev_button_clicked), preview); + gtk_widget_show (GTK_WIDGET (priv->prev)); - priv->next = gtk_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD); - gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->next), - "_Next Page"); - gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (priv->next), TRUE); - gtk_tool_item_set_tooltip_text (priv->next, _("Show the next page")); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->next, -1); - g_signal_connect (priv->next, - "clicked", - G_CALLBACK (next_button_clicked), - preview); - gtk_widget_show (GTK_WIDGET (priv->next)); + priv->next = gtk_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD); + gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->next), "_Next Page"); + gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (priv->next), TRUE); + gtk_tool_item_set_tooltip_text (priv->next, _("Show the next page")); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->next, -1); + g_signal_connect (priv->next, "clicked", + G_CALLBACK (next_button_clicked), preview); + gtk_widget_show (GTK_WIDGET (priv->next)); - i = gtk_separator_tool_item_new (); - gtk_widget_show (GTK_WIDGET (i)); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); + i = gtk_separator_tool_item_new (); + gtk_widget_show (GTK_WIDGET (i)); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); - status = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); - priv->page_entry = gtk_entry_new (); - gtk_entry_set_width_chars (GTK_ENTRY (priv->page_entry), 3); - gtk_entry_set_max_length (GTK_ENTRY (priv->page_entry), 6); - gtk_widget_set_tooltip_text (priv->page_entry, _("Current page (Alt+P)")); + status = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); + priv->page_entry = gtk_entry_new (); + gtk_entry_set_width_chars (GTK_ENTRY (priv->page_entry), 3); + gtk_entry_set_max_length (GTK_ENTRY (priv->page_entry), 6); + gtk_widget_set_tooltip_text (priv->page_entry, _("Current page (Alt+P)")); - g_signal_connect (priv->page_entry, - "activate", - G_CALLBACK (page_entry_activated), - preview); - g_signal_connect (priv->page_entry, - "insert-text", - G_CALLBACK (page_entry_insert_text), - NULL); - g_signal_connect (priv->page_entry, - "focus-out-event", - G_CALLBACK (page_entry_focus_out), - preview); + g_signal_connect (priv->page_entry, "activate", + G_CALLBACK (page_entry_activated), preview); + g_signal_connect (priv->page_entry, "insert-text", + G_CALLBACK (page_entry_insert_text), NULL); + g_signal_connect (priv->page_entry, "focus-out-event", + G_CALLBACK (page_entry_focus_out), preview); - gtk_box_pack_start (GTK_BOX (status), - priv->page_entry, - FALSE, FALSE, 0); - /* gtk_label_set_mnemonic_widget ((GtkLabel *) l, mp->priv->page_entry); */ + gtk_box_pack_start (GTK_BOX (status), priv->page_entry, FALSE, FALSE, 0); + /* gtk_label_set_mnemonic_widget ((GtkLabel *) l, mp->priv->page_entry); */ - /* We are displaying 'XXX of XXX'. */ - gtk_box_pack_start (GTK_BOX (status), - /* Translators: the "of" from "1 of 19" in print preview. */ - gtk_label_new (_("of")), - FALSE, FALSE, 0); + /* We are displaying 'XXX of XXX'. */ + /* Translators: the "of" from "1 of 19" in print preview. */ + gtk_box_pack_start (GTK_BOX (status), gtk_label_new (_("of")), FALSE, FALSE, 0); - priv->last = gtk_label_new (""); - gtk_box_pack_start (GTK_BOX (status), - priv->last, - FALSE, FALSE, 0); - atko = gtk_widget_get_accessible (priv->last); - atk_object_set_name (atko, _("Page total")); - atk_object_set_description (atko, _("The total number of pages in the document")); + priv->last = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX (status), priv->last, FALSE, FALSE, 0); + atko = gtk_widget_get_accessible (priv->last); + atk_object_set_name (atko, _("Page total")); + atk_object_set_description (atko, _("The total number of pages in the document")); - gtk_widget_show_all (status); + gtk_widget_show_all (status); - i = gtk_tool_item_new (); - gtk_container_add (GTK_CONTAINER (i), status); - gtk_widget_show (GTK_WIDGET (i)); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); + i = gtk_tool_item_new (); + gtk_container_add (GTK_CONTAINER (i), status); + gtk_widget_show (GTK_WIDGET (i)); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); - i = gtk_separator_tool_item_new (); - gtk_widget_show (GTK_WIDGET (i)); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); - - priv->multi = gtk_tool_button_new_from_stock (GTK_STOCK_DND_MULTIPLE); - gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->multi), - "_Show Multiple Pages"); - gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (priv->multi), TRUE); - gtk_tool_item_set_tooltip_text (priv->multi, _("Show multiple pages")); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->multi, -1); - g_signal_connect (priv->multi, - "clicked", - G_CALLBACK (multi_button_clicked), - preview); - gtk_widget_show (GTK_WIDGET (priv->multi)); + i = gtk_separator_tool_item_new (); + gtk_widget_show (GTK_WIDGET (i)); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); - i = gtk_separator_tool_item_new (); - gtk_widget_show (GTK_WIDGET (i)); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); + priv->multi = gtk_tool_button_new_from_stock (GTK_STOCK_DND_MULTIPLE); + gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->multi), "_Show Multiple Pages"); + gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (priv->multi), TRUE); + gtk_tool_item_set_tooltip_text (priv->multi, _("Show multiple pages")); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->multi, -1); + g_signal_connect (priv->multi, "clicked", + G_CALLBACK (multi_button_clicked), preview); + gtk_widget_show (GTK_WIDGET (priv->multi)); - priv->zoom_one = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_100); - gtk_tool_item_set_tooltip_text (priv->zoom_one, _("Zoom 1:1")); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->zoom_one, -1); - g_signal_connect (priv->zoom_one, - "clicked", - G_CALLBACK (zoom_one_button_clicked), - preview); - gtk_widget_show (GTK_WIDGET (priv->zoom_one)); + i = gtk_separator_tool_item_new (); + gtk_widget_show (GTK_WIDGET (i)); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); - priv->zoom_fit = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_FIT); - gtk_tool_item_set_tooltip_text (priv->zoom_fit, _("Zoom to fit the whole page")); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->zoom_fit, -1); - g_signal_connect (priv->zoom_fit, - "clicked", - G_CALLBACK (zoom_fit_button_clicked), - preview); - gtk_widget_show (GTK_WIDGET (priv->zoom_fit)); + priv->zoom_one = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_100); + gtk_tool_item_set_tooltip_text (priv->zoom_one, _("Zoom 1:1")); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->zoom_one, -1); + g_signal_connect (priv->zoom_one, "clicked", + G_CALLBACK (zoom_one_button_clicked), preview); + gtk_widget_show (GTK_WIDGET (priv->zoom_one)); - priv->zoom_in = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_IN); - gtk_tool_item_set_tooltip_text (priv->zoom_in, _("Zoom the page in")); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->zoom_in, -1); - g_signal_connect (priv->zoom_in, - "clicked", - G_CALLBACK (zoom_in_button_clicked), - preview); - gtk_widget_show (GTK_WIDGET (priv->zoom_in)); + priv->zoom_fit = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_FIT); + gtk_tool_item_set_tooltip_text (priv->zoom_fit, _("Zoom to fit the whole page")); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->zoom_fit, -1); + g_signal_connect (priv->zoom_fit, "clicked", + G_CALLBACK (zoom_fit_button_clicked), preview); + gtk_widget_show (GTK_WIDGET (priv->zoom_fit)); - priv->zoom_out = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_OUT); - gtk_tool_item_set_tooltip_text (priv->zoom_out, _("Zoom the page out")); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->zoom_out, -1); - g_signal_connect (priv->zoom_out, - "clicked", - G_CALLBACK (zoom_out_button_clicked), - preview); - gtk_widget_show (GTK_WIDGET (priv->zoom_out)); + priv->zoom_in = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_IN); + gtk_tool_item_set_tooltip_text (priv->zoom_in, _("Zoom the page in")); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->zoom_in, -1); + g_signal_connect (priv->zoom_in, "clicked", + G_CALLBACK (zoom_in_button_clicked), preview); + gtk_widget_show (GTK_WIDGET (priv->zoom_in)); - i = gtk_separator_tool_item_new (); - gtk_widget_show (GTK_WIDGET (i)); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); + priv->zoom_out = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_OUT); + gtk_tool_item_set_tooltip_text (priv->zoom_out, _("Zoom the page out")); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->zoom_out, -1); + g_signal_connect (priv->zoom_out, "clicked", + G_CALLBACK (zoom_out_button_clicked), preview); + gtk_widget_show (GTK_WIDGET (priv->zoom_out)); - i = gtk_tool_button_new (NULL, _("_Close Preview")); - gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (i), TRUE); - gtk_tool_item_set_is_important (i, TRUE); - gtk_tool_item_set_tooltip_text (i, _("Close print preview")); - g_signal_connect (i, "clicked", - G_CALLBACK (close_button_clicked), preview); - gtk_widget_show (GTK_WIDGET (i)); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); + i = gtk_separator_tool_item_new (); + gtk_widget_show (GTK_WIDGET (i)); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); + + i = gtk_tool_button_new (NULL, _("_Close Preview")); + gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (i), TRUE); + gtk_tool_item_set_is_important (i, TRUE); + gtk_tool_item_set_tooltip_text (i, _("Close print preview")); + g_signal_connect (i, "clicked", + G_CALLBACK (close_button_clicked), preview); + gtk_widget_show (GTK_WIDGET (i)); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); } static gint get_first_page_displayed (XedPrintPreview *preview) { - XedPrintPreviewPrivate *priv; + XedPrintPreviewPrivate *priv; - priv = preview->priv; + priv = preview->priv; - return priv->cur_page - priv->cur_page % (priv->cols * priv->rows); + return priv->cur_page - priv->cur_page % (priv->cols * priv->rows); } /* returns the page number (starting from 0) or -1 if no page */ static gint get_page_at_coords (XedPrintPreview *preview, - gint x, - gint y) + gint x, + gint y) { - XedPrintPreviewPrivate *priv; - GtkAdjustment *hadj, *vadj; - gint r, c, pg; + XedPrintPreviewPrivate *priv; + GtkAdjustment *hadj, *vadj; + gint r, c, pg; - priv = preview->priv; + priv = preview->priv; - if (priv->tile_h <= 0 || priv->tile_h <= 0) - return -1; + if (priv->tile_h <= 0 || priv->tile_h <= 0) + { + return -1; + } - hadj = gtk_layout_get_hadjustment (GTK_LAYOUT (priv->layout)); - vadj = gtk_layout_get_vadjustment (GTK_LAYOUT (priv->layout)); + hadj = gtk_layout_get_hadjustment (GTK_LAYOUT (priv->layout)); + vadj = gtk_layout_get_vadjustment (GTK_LAYOUT (priv->layout)); - x += gtk_adjustment_get_value (hadj); - y += gtk_adjustment_get_value (vadj); + x += gtk_adjustment_get_value (hadj); + y += gtk_adjustment_get_value (vadj); - r = 1 + y / (priv->tile_h); - c = 1 + x / (priv->tile_w); + r = 1 + y / (priv->tile_h); + c = 1 + x / (priv->tile_w); - if (c > priv->cols) - return -1; + if (c > priv->cols) + { + return -1; + } - pg = get_first_page_displayed (preview) - 1; - pg += (r - 1) * priv->cols + c; + pg = get_first_page_displayed (preview) - 1; + pg += (r - 1) * priv->cols + c; - if (pg >= priv->n_pages) - return -1; + if (pg >= priv->n_pages) + { + return -1; + } - /* FIXME: we could try to be picky and check - * if we actually are inside the page */ - return pg; + /* FIXME: we could try to be picky and check + * if we actually are inside the page */ + return pg; } static gboolean -preview_layout_query_tooltip (GtkWidget *widget, - gint x, - gint y, - gboolean keyboard_tip, - GtkTooltip *tooltip, - XedPrintPreview *preview) +preview_layout_query_tooltip (GtkWidget *widget, + gint x, + gint y, + gboolean keyboard_tip, + GtkTooltip *tooltip, + XedPrintPreview *preview) { - gint pg; - gchar *tip; + gint pg; + gchar *tip; - pg = get_page_at_coords (preview, x, y); - if (pg < 0) - return FALSE; + pg = get_page_at_coords (preview, x, y); + if (pg < 0) + { + return FALSE; + } - tip = g_strdup_printf (_("Page %d of %d"), pg + 1, preview->priv->n_pages); - gtk_tooltip_set_text (tooltip, tip); - g_free (tip); + tip = g_strdup_printf (_("Page %d of %d"), pg + 1, preview->priv->n_pages); + gtk_tooltip_set_text (tooltip, tip); + g_free (tip); - return TRUE; + return TRUE; } static gint -preview_layout_key_press (GtkWidget *widget, - GdkEventKey *event, - XedPrintPreview *preview) +preview_layout_key_press (GtkWidget *widget, + GdkEventKey *event, + XedPrintPreview *preview) { - XedPrintPreviewPrivate *priv; - GtkAdjustment *hadj, *vadj; - double x, y; - guint h, w; - double hlower, hupper, vlower, vupper; - double hpage, vpage; - double hstep, vstep; - gboolean domove = FALSE; - gboolean ret = TRUE; + XedPrintPreviewPrivate *priv; + GtkAdjustment *hadj, *vadj; + double x, y; + guint h, w; + double hlower, hupper, vlower, vupper; + double hpage, vpage; + double hstep, vstep; + gboolean domove = FALSE; + gboolean ret = TRUE; - priv = preview->priv; + priv = preview->priv; - hadj = gtk_layout_get_hadjustment (GTK_LAYOUT (priv->layout)); - vadj = gtk_layout_get_vadjustment (GTK_LAYOUT (priv->layout)); + hadj = gtk_layout_get_hadjustment (GTK_LAYOUT (priv->layout)); + vadj = gtk_layout_get_vadjustment (GTK_LAYOUT (priv->layout)); - x = gtk_adjustment_get_value (hadj); - y = gtk_adjustment_get_value (vadj); + x = gtk_adjustment_get_value (hadj); + y = gtk_adjustment_get_value (vadj); - g_object_get (hadj, - "lower", &hlower, - "upper", &hupper, - "page-size", &hpage, - NULL); - g_object_get (vadj, - "lower", &vlower, - "upper", &vupper, - "page-size", &vpage, - NULL); + g_object_get (hadj, + "lower", &hlower, + "upper", &hupper, + "page-size", &hpage, + NULL); + g_object_get (vadj, + "lower", &vlower, + "upper", &vupper, + "page-size", &vpage, + NULL); - gtk_layout_get_size (GTK_LAYOUT (priv->layout), &w, &h); + gtk_layout_get_size (GTK_LAYOUT (priv->layout), &w, &h); - hstep = 10; - vstep = 10; + hstep = 10; + vstep = 10; - switch (event->keyval) { - case '1': - set_zoom_fit_to_size (preview); - break; - case '+': - case '=': - case GDK_KEY_KP_Add: - zoom_in (preview); - break; - case '-': - case '_': - case GDK_KEY_KP_Subtract: - zoom_out (preview); - break; - case GDK_KEY_KP_Right: - case GDK_KEY_Right: - if (event->state & GDK_SHIFT_MASK) - x = hupper - hpage; - else - x = MIN (hupper - hpage, x + hstep); - domove = TRUE; - break; - case GDK_KEY_KP_Left: - case GDK_KEY_Left: - if (event->state & GDK_SHIFT_MASK) - x = hlower; - else - x = MAX (hlower, x - hstep); - domove = TRUE; - break; - case GDK_KEY_KP_Up: - case GDK_KEY_Up: - if (event->state & GDK_SHIFT_MASK) - goto page_up; - y = MAX (vlower, y - vstep); - domove = TRUE; - break; - case GDK_KEY_KP_Down: - case GDK_KEY_Down: - if (event->state & GDK_SHIFT_MASK) - goto page_down; - y = MIN (vupper - vpage, y + vstep); - domove = TRUE; - break; - case GDK_KEY_KP_Page_Up: - case GDK_KEY_Page_Up: - case GDK_KEY_Delete: - case GDK_KEY_KP_Delete: - case GDK_KEY_BackSpace: - page_up: - if (y <= vlower) - { - if (preview->priv->cur_page > 0) - { - goto_page (preview, preview->priv->cur_page - 1); - y = (vupper - vpage); - } - } - else - { - y = vlower; - } - domove = TRUE; - break; - case GDK_KEY_KP_Page_Down: - case GDK_KEY_Page_Down: - case ' ': - page_down: - if (y >= (vupper - vpage)) - { - if (preview->priv->cur_page < preview->priv->n_pages - 1) - { - goto_page (preview, preview->priv->cur_page + 1); - y = vlower; - } - } - else - { - y = (vupper - vpage); - } - domove = TRUE; - break; - case GDK_KEY_KP_Home: - case GDK_KEY_Home: - goto_page (preview, 0); - y = 0; - domove = TRUE; - break; - case GDK_KEY_KP_End: - case GDK_KEY_End: - goto_page (preview, preview->priv->n_pages - 1); - y = 0; - domove = TRUE; - break; - case GDK_KEY_Escape: - gtk_widget_destroy (GTK_WIDGET (preview)); - break; - case 'c': - if (event->state & GDK_MOD1_MASK) - { - gtk_widget_destroy (GTK_WIDGET (preview)); - } - break; - case 'p': - if (event->state & GDK_MOD1_MASK) - { - gtk_widget_grab_focus (preview->priv->page_entry); - } - break; - default: - /* by default do not stop the default handler */ - ret = FALSE; - } + switch (event->keyval) + { + case '1': + set_zoom_fit_to_size (preview); + break; + case '+': + case '=': + case GDK_KEY_KP_Add: + zoom_in (preview); + break; + case '-': + case '_': + case GDK_KEY_KP_Subtract: + zoom_out (preview); + break; + case GDK_KEY_KP_Right: + case GDK_KEY_Right: + if (event->state & GDK_SHIFT_MASK) + x = hupper - hpage; + else + x = MIN (hupper - hpage, x + hstep); + domove = TRUE; + break; + case GDK_KEY_KP_Left: + case GDK_KEY_Left: + if (event->state & GDK_SHIFT_MASK) + x = hlower; + else + x = MAX (hlower, x - hstep); + domove = TRUE; + break; + case GDK_KEY_KP_Up: + case GDK_KEY_Up: + if (event->state & GDK_SHIFT_MASK) + goto page_up; + y = MAX (vlower, y - vstep); + domove = TRUE; + break; + case GDK_KEY_KP_Down: + case GDK_KEY_Down: + if (event->state & GDK_SHIFT_MASK) + goto page_down; + y = MIN (vupper - vpage, y + vstep); + domove = TRUE; + break; + case GDK_KEY_KP_Page_Up: + case GDK_KEY_Page_Up: + case GDK_KEY_Delete: + case GDK_KEY_KP_Delete: + case GDK_KEY_BackSpace: + page_up: + if (y <= vlower) + { + if (preview->priv->cur_page > 0) + { + goto_page (preview, preview->priv->cur_page - 1); + y = (vupper - vpage); + } + } + else + { + y = vlower; + } + domove = TRUE; + break; + case GDK_KEY_KP_Page_Down: + case GDK_KEY_Page_Down: + case ' ': + page_down: + if (y >= (vupper - vpage)) + { + if (preview->priv->cur_page < preview->priv->n_pages - 1) + { + goto_page (preview, preview->priv->cur_page + 1); + y = vlower; + } + } + else + { + y = (vupper - vpage); + } + domove = TRUE; + break; + case GDK_KEY_KP_Home: + case GDK_KEY_Home: + goto_page (preview, 0); + y = 0; + domove = TRUE; + break; + case GDK_KEY_KP_End: + case GDK_KEY_End: + goto_page (preview, preview->priv->n_pages - 1); + y = 0; + domove = TRUE; + break; + case GDK_KEY_Escape: + gtk_widget_destroy (GTK_WIDGET (preview)); + break; + case 'c': + if (event->state & GDK_MOD1_MASK) + { + gtk_widget_destroy (GTK_WIDGET (preview)); + } + break; + case 'p': + if (event->state & GDK_MOD1_MASK) + { + gtk_widget_grab_focus (preview->priv->page_entry); + } + break; + default: + /* by default do not stop the default handler */ + ret = FALSE; + } - if (domove) - { - gtk_adjustment_set_value (hadj, x); - gtk_adjustment_set_value (vadj, y); + if (domove) + { + gtk_adjustment_set_value (hadj, x); + gtk_adjustment_set_value (vadj, y); - gtk_adjustment_value_changed (hadj); - gtk_adjustment_value_changed (vadj); - } + gtk_adjustment_value_changed (hadj); + gtk_adjustment_value_changed (vadj); + } - return ret; + return ret; } static void create_preview_layout (XedPrintPreview *preview) { - XedPrintPreviewPrivate *priv; - AtkObject *atko; + XedPrintPreviewPrivate *priv; + AtkObject *atko; - priv = preview->priv; + priv = preview->priv; - priv->layout = gtk_layout_new (NULL, NULL); -// gtk_widget_set_double_buffered (priv->layout, FALSE); + priv->layout = gtk_layout_new (NULL, NULL); +// gtk_widget_set_double_buffered (priv->layout, FALSE); - atko = gtk_widget_get_accessible (GTK_WIDGET (priv->layout)); - atk_object_set_name (atko, _("Page Preview")); - atk_object_set_description (atko, _("The preview of a page in the document to be printed")); + atko = gtk_widget_get_accessible (GTK_WIDGET (priv->layout)); + atk_object_set_name (atko, _("Page Preview")); + atk_object_set_description (atko, _("The preview of a page in the document to be printed")); - gtk_widget_add_events (priv->layout, - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_KEY_PRESS_MASK); + gtk_widget_add_events (priv->layout, + GDK_POINTER_MOTION_MASK | + GDK_BUTTON_PRESS_MASK | + GDK_KEY_PRESS_MASK); - gtk_widget_set_can_focus (priv->layout, TRUE); + gtk_widget_set_can_focus (priv->layout, TRUE); - g_signal_connect (priv->layout, - "key-press-event", - G_CALLBACK (preview_layout_key_press), - preview); + g_signal_connect (priv->layout, "key-press-event", + G_CALLBACK (preview_layout_key_press), preview); - g_object_set (priv->layout, "has-tooltip", TRUE, NULL); - g_signal_connect (priv->layout, - "query-tooltip", - G_CALLBACK (preview_layout_query_tooltip), - preview); + g_object_set (priv->layout, "has-tooltip", TRUE, NULL); + g_signal_connect (priv->layout, "query-tooltip", + G_CALLBACK (preview_layout_query_tooltip), preview); - priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); + priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); - gtk_container_add (GTK_CONTAINER (priv->scrolled_window), priv->layout); - gtk_box_pack_end (GTK_BOX (preview), - priv->scrolled_window, - TRUE, TRUE, 0); + gtk_container_add (GTK_CONTAINER (priv->scrolled_window), priv->layout); + gtk_box_pack_end (GTK_BOX (preview), priv->scrolled_window, TRUE, TRUE, 0); - gtk_widget_show_all (GTK_WIDGET (priv->scrolled_window)); - gtk_widget_grab_focus (GTK_WIDGET (priv->layout)); + gtk_widget_show_all (GTK_WIDGET (priv->scrolled_window)); + gtk_widget_grab_focus (GTK_WIDGET (priv->layout)); } static void xed_print_preview_init (XedPrintPreview *preview) { - XedPrintPreviewPrivate *priv; - - priv = G_TYPE_INSTANCE_GET_PRIVATE (preview, - XED_TYPE_PRINT_PREVIEW, - XedPrintPreviewPrivate); + XedPrintPreviewPrivate *priv; - preview->priv = priv; + priv = G_TYPE_INSTANCE_GET_PRIVATE (preview, XED_TYPE_PRINT_PREVIEW, XedPrintPreviewPrivate); - priv->operation = NULL; - priv->context = NULL; - priv->gtk_preview = NULL; + preview->priv = priv; - gtk_orientable_set_orientation (GTK_ORIENTABLE (preview), - GTK_ORIENTATION_VERTICAL); + priv->operation = NULL; + priv->context = NULL; + priv->gtk_preview = NULL; - create_bar (preview); - create_preview_layout (preview); + gtk_orientable_set_orientation (GTK_ORIENTABLE (preview), GTK_ORIENTATION_VERTICAL); - // FIXME - priv->cur_page = 0; - priv->paper_w = 0; - priv->paper_h = 0; - priv->dpi = PRINTER_DPI; - priv->scale = 1.0; - priv->rows = 1; - priv->cols = 1; + create_bar (preview); + create_preview_layout (preview); + + // FIXME + priv->cur_page = 0; + priv->paper_w = 0; + priv->paper_h = 0; + priv->dpi = PRINTER_DPI; + priv->scale = 1.0; + priv->rows = 1; + priv->cols = 1; } static void -draw_page_content (cairo_t *cr, - gint page_number, - XedPrintPreview *preview) +draw_page_content (cairo_t *cr, + gint page_number, + XedPrintPreview *preview) { - /* scale to the desired size */ - cairo_scale (cr, preview->priv->scale, preview->priv->scale); + /* scale to the desired size */ + cairo_scale (cr, preview->priv->scale, preview->priv->scale); - /* rotate acording to page orientation if needed */ - if ((preview->priv->orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) || - (preview->priv->orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE)) - { - cairo_matrix_t matrix; + /* rotate acording to page orientation if needed */ + if ((preview->priv->orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) || + (preview->priv->orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE)) + { + cairo_matrix_t matrix; - cairo_matrix_init (&matrix, - 0, -1, - 1, 0, - 0, get_paper_width (preview)); - cairo_transform (cr, &matrix); - } + cairo_matrix_init (&matrix, + 0, -1, + 1, 0, + 0, get_paper_width (preview)); + cairo_transform (cr, &matrix); + } - gtk_print_context_set_cairo_context (preview->priv->context, - cr, - preview->priv->dpi, - preview->priv->dpi); + gtk_print_context_set_cairo_context (preview->priv->context, + cr, + preview->priv->dpi, + preview->priv->dpi); - gtk_print_operation_preview_render_page (preview->priv->gtk_preview, - page_number); + gtk_print_operation_preview_render_page (preview->priv->gtk_preview, page_number); } /* For the frame, we scale and rotate manually, since @@ -1048,202 +1017,195 @@ draw_page_content (cairo_t *cr, * the drop shadow should be on the bottom right no matter * the orientation */ static void -draw_page_frame (cairo_t *cr, - XedPrintPreview *preview) +draw_page_frame (cairo_t *cr, + XedPrintPreview *preview) { - double w, h; + double w, h; - w = get_paper_width (preview); - h = get_paper_height (preview); + w = get_paper_width (preview); + h = get_paper_height (preview); - if ((preview->priv->orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) || - (preview->priv->orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE)) - { - double tmp; + if ((preview->priv->orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) || + (preview->priv->orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE)) + { + double tmp; - tmp = w; - w = h; - h = tmp; - } + tmp = w; + w = h; + h = tmp; + } - w *= preview->priv->scale; - h *= preview->priv->scale; + w *= preview->priv->scale; + h *= preview->priv->scale; - /* drop shadow */ - cairo_set_source_rgb (cr, 0, 0, 0); - cairo_rectangle (cr, - PAGE_SHADOW_OFFSET, PAGE_SHADOW_OFFSET, - w, h); - cairo_fill (cr); + /* drop shadow */ + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_rectangle (cr, PAGE_SHADOW_OFFSET, PAGE_SHADOW_OFFSET, w, h); + cairo_fill (cr); - /* page frame */ - cairo_set_source_rgb (cr, 1, 1, 1); - cairo_rectangle (cr, - 0, 0, - w, h); - cairo_fill_preserve (cr); - cairo_set_source_rgb (cr, 0, 0, 0); - cairo_set_line_width (cr, 1); - cairo_stroke (cr); + /* page frame */ + cairo_set_source_rgb (cr, 1, 1, 1); + cairo_rectangle (cr, 0, 0, w, h); + cairo_fill_preserve (cr); + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_set_line_width (cr, 1); + cairo_stroke (cr); } static void -draw_page (cairo_t *cr, - double x, - double y, - gint page_number, - XedPrintPreview *preview) +draw_page (cairo_t *cr, + double x, + double y, + gint page_number, + XedPrintPreview *preview) { - cairo_save (cr); + cairo_save (cr); - /* move to the page top left corner */ - cairo_translate (cr, x + PAGE_PAD, y + PAGE_PAD); + /* move to the page top left corner */ + cairo_translate (cr, x + PAGE_PAD, y + PAGE_PAD); - draw_page_frame (cr, preview); - draw_page_content (cr, page_number, preview); + draw_page_frame (cr, preview); + draw_page_content (cr, page_number, preview); - cairo_restore (cr); + cairo_restore (cr); } static gboolean -preview_draw (GtkWidget *widget, - cairo_t *cr, - XedPrintPreview *preview) +preview_draw (GtkWidget *widget, + cairo_t *cr, + XedPrintPreview *preview) { - XedPrintPreviewPrivate *priv; - GdkWindow *bin_window; - gint pg; - gint i, j; + XedPrintPreviewPrivate *priv; + GdkWindow *bin_window; + gint pg; + gint i, j; - priv = preview->priv; + priv = preview->priv; - bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (priv->layout)); + bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (priv->layout)); - if (!gtk_cairo_should_draw_window (cr, bin_window)) - return TRUE; + if (!gtk_cairo_should_draw_window (cr, bin_window)) + { + return TRUE; + } - cairo_save (cr); + cairo_save (cr); - gtk_cairo_transform_to_window (cr, widget, bin_window); + gtk_cairo_transform_to_window (cr, widget, bin_window); - /* get the first page to display */ - pg = get_first_page_displayed (preview); + /* get the first page to display */ + pg = get_first_page_displayed (preview); - for (i = 0; i < priv->cols; ++i) - { - for (j = 0; j < priv->rows; ++j) - { - if (!gtk_print_operation_preview_is_selected (priv->gtk_preview, - pg)) - { - continue; - } + for (i = 0; i < priv->cols; ++i) + { + for (j = 0; j < priv->rows; ++j) + { + if (!gtk_print_operation_preview_is_selected (priv->gtk_preview, pg)) + { + continue; + } - if (pg == priv->n_pages) - break; + if (pg == priv->n_pages) + { + break; + } - draw_page (cr, - j * priv->tile_w, - i * priv->tile_h, - pg, - preview); + draw_page (cr, j * priv->tile_w, i * priv->tile_h, pg, preview); - ++pg; - } - } + ++pg; + } + } - cairo_restore (cr); + cairo_restore (cr); - return TRUE; + return TRUE; } static double get_screen_dpi (XedPrintPreview *preview) { - GdkScreen *screen; - double dpi; + GdkScreen *screen; + double dpi; - screen = gtk_widget_get_screen (GTK_WIDGET (preview)); + screen = gtk_widget_get_screen (GTK_WIDGET (preview)); - dpi = gdk_screen_get_resolution (screen); - if (dpi < 30. || 600. < dpi) - { - g_warning ("Invalid the x-resolution for the screen, assuming 96dpi"); - dpi = 96.; - } + dpi = gdk_screen_get_resolution (screen); + if (dpi < 30. || 600. < dpi) + { + g_warning ("Invalid the x-resolution for the screen, assuming 96dpi"); + dpi = 96.; + } - return dpi; + return dpi; } static void set_n_pages (XedPrintPreview *preview, - gint n_pages) + gint n_pages) { - gchar *str; + gchar *str; - preview->priv->n_pages = n_pages; + preview->priv->n_pages = n_pages; - // FIXME: count the visible pages + // FIXME: count the visible pages - str = g_strdup_printf ("%d", n_pages); - gtk_label_set_markup (GTK_LABEL (preview->priv->last), str); - g_free (str); + str = g_strdup_printf ("%d", n_pages); + gtk_label_set_markup (GTK_LABEL (preview->priv->last), str); + g_free (str); } static void preview_ready (GtkPrintOperationPreview *gtk_preview, - GtkPrintContext *context, - XedPrintPreview *preview) + GtkPrintContext *context, + XedPrintPreview *preview) { - gint n_pages; + gint n_pages; - g_object_get (preview->priv->operation, "n-pages", &n_pages, NULL); - set_n_pages (preview, n_pages); - goto_page (preview, 0); + g_object_get (preview->priv->operation, "n-pages", &n_pages, NULL); + set_n_pages (preview, n_pages); + goto_page (preview, 0); - /* figure out the dpi */ - preview->priv->dpi = get_screen_dpi (preview); + /* figure out the dpi */ + preview->priv->dpi = get_screen_dpi (preview); - set_zoom_factor (preview, 1.0); + set_zoom_factor (preview, 1.0); - /* let the default gtklayout handler clear the background */ - g_signal_connect_after (preview->priv->layout, - "draw", - G_CALLBACK (preview_draw), - preview); + /* let the default gtklayout handler clear the background */ + g_signal_connect_after (preview->priv->layout, "draw", + G_CALLBACK (preview_draw), preview); - gtk_widget_queue_draw (preview->priv->layout); + gtk_widget_queue_draw (preview->priv->layout); } static void update_paper_size (XedPrintPreview *preview, - GtkPageSetup *page_setup) + GtkPageSetup *page_setup) { - GtkPaperSize *paper_size; + GtkPaperSize *paper_size; - paper_size = gtk_page_setup_get_paper_size (page_setup); + paper_size = gtk_page_setup_get_paper_size (page_setup); - preview->priv->paper_w = gtk_paper_size_get_width (paper_size, GTK_UNIT_INCH); - preview->priv->paper_h = gtk_paper_size_get_height (paper_size, GTK_UNIT_INCH); + preview->priv->paper_w = gtk_paper_size_get_width (paper_size, GTK_UNIT_INCH); + preview->priv->paper_h = gtk_paper_size_get_height (paper_size, GTK_UNIT_INCH); - preview->priv->orientation = gtk_page_setup_get_orientation (page_setup); + preview->priv->orientation = gtk_page_setup_get_orientation (page_setup); } static void -preview_got_page_size (GtkPrintOperationPreview *gtk_preview, - GtkPrintContext *context, - GtkPageSetup *page_setup, - XedPrintPreview *preview) +preview_got_page_size (GtkPrintOperationPreview *gtk_preview, + GtkPrintContext *context, + GtkPageSetup *page_setup, + XedPrintPreview *preview) { - update_paper_size (preview, page_setup); + update_paper_size (preview, page_setup); } /* HACK: we need a dummy surface to paginate... can we use something simpler? */ static cairo_status_t dummy_write_func (G_GNUC_UNUSED gpointer closure, - G_GNUC_UNUSED const guchar *data, - G_GNUC_UNUSED guint length) + G_GNUC_UNUSED const guchar *data, + G_GNUC_UNUSED guint length) { return CAIRO_STATUS_SUCCESS; } @@ -1252,8 +1214,8 @@ dummy_write_func (G_GNUC_UNUSED gpointer closure, static cairo_surface_t * create_preview_surface_platform (GtkPaperSize *paper_size, - double *dpi_x, - double *dpi_y) + double *dpi_x, + double *dpi_y) { double width, height; cairo_surface_t *sf; @@ -1263,15 +1225,14 @@ create_preview_surface_platform (GtkPaperSize *paper_size, *dpi_x = *dpi_y = PRINTER_DPI; - sf = cairo_pdf_surface_create_for_stream (dummy_write_func, NULL, - width, height); + sf = cairo_pdf_surface_create_for_stream (dummy_write_func, NULL, width, height); return sf; } static cairo_surface_t * create_preview_surface (XedPrintPreview *preview, - double *dpi_x, - double *dpi_y) + double *dpi_x, + double *dpi_y) { GtkPageSetup *page_setup; GtkPaperSize *paper_size; @@ -1285,45 +1246,45 @@ create_preview_surface (XedPrintPreview *preview, GtkWidget * xed_print_preview_new (GtkPrintOperation *op, - GtkPrintOperationPreview *gtk_preview, - GtkPrintContext *context) + GtkPrintOperationPreview *gtk_preview, + GtkPrintContext *context) { - XedPrintPreview *preview; - GtkPageSetup *page_setup; - cairo_surface_t *surface; - cairo_t *cr; - double dpi_x, dpi_y; + XedPrintPreview *preview; + GtkPageSetup *page_setup; + cairo_surface_t *surface; + cairo_t *cr; + double dpi_x, dpi_y; - g_return_val_if_fail (GTK_IS_PRINT_OPERATION (op), NULL); - g_return_val_if_fail (GTK_IS_PRINT_OPERATION_PREVIEW (gtk_preview), NULL); + g_return_val_if_fail (GTK_IS_PRINT_OPERATION (op), NULL); + g_return_val_if_fail (GTK_IS_PRINT_OPERATION_PREVIEW (gtk_preview), NULL); - preview = g_object_new (XED_TYPE_PRINT_PREVIEW, NULL); + preview = g_object_new (XED_TYPE_PRINT_PREVIEW, NULL); - preview->priv->operation = g_object_ref (op); - preview->priv->gtk_preview = g_object_ref (gtk_preview); - preview->priv->context = g_object_ref (context); + preview->priv->operation = g_object_ref (op); + preview->priv->gtk_preview = g_object_ref (gtk_preview); + preview->priv->context = g_object_ref (context); - /* FIXME: is this legal?? */ - gtk_print_operation_set_unit (op, GTK_UNIT_POINTS); + /* FIXME: is this legal?? */ + gtk_print_operation_set_unit (op, GTK_UNIT_POINTS); - g_signal_connect (gtk_preview, "ready", - G_CALLBACK (preview_ready), preview); - g_signal_connect (gtk_preview, "got-page-size", - G_CALLBACK (preview_got_page_size), preview); + g_signal_connect (gtk_preview, "ready", + G_CALLBACK (preview_ready), preview); + g_signal_connect (gtk_preview, "got-page-size", + G_CALLBACK (preview_got_page_size), preview); - page_setup = gtk_print_context_get_page_setup (preview->priv->context); - update_paper_size (preview, page_setup); + page_setup = gtk_print_context_get_page_setup (preview->priv->context); + update_paper_size (preview, page_setup); - /* FIXME: we need a cr to paginate... but we can't get the drawing - * area surface because it's not there yet... for now I create - * a dummy pdf surface */ + /* FIXME: we need a cr to paginate... but we can't get the drawing + * area surface because it's not there yet... for now I create + * a dummy pdf surface */ - surface = create_preview_surface (preview, &dpi_x, &dpi_y); - cr = cairo_create (surface); - gtk_print_context_set_cairo_context (context, cr, dpi_x, dpi_y); - cairo_destroy (cr); - cairo_surface_destroy (surface); + surface = create_preview_surface (preview, &dpi_x, &dpi_y); + cr = cairo_create (surface); + gtk_print_context_set_cairo_context (context, cr, dpi_x, dpi_y); + cairo_destroy (cr); + cairo_surface_destroy (surface); - return GTK_WIDGET (preview); + return GTK_WIDGET (preview); } From 5a9258087a39f8d05d73666afda653f399ec82a5 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 7 Jan 2017 02:52:00 -0800 Subject: [PATCH 071/132] xed-print-preview.c: Restyle the toolbar Make it look nicer and at the same time clean up some more uses of GtkStock --- xed/xed-print-preview.c | 115 +++++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 49 deletions(-) diff --git a/xed/xed-print-preview.c b/xed/xed-print-preview.c index 63cff00..6bb1809 100644 --- a/xed/xed-print-preview.c +++ b/xed/xed-print-preview.c @@ -51,15 +51,15 @@ struct _XedPrintPreviewPrivate GtkWidget *layout; GtkWidget *scrolled_window; - GtkToolItem *next; - GtkToolItem *prev; + GtkWidget *next; + GtkWidget *prev; GtkWidget *page_entry; GtkWidget *last; - GtkToolItem *multi; - GtkToolItem *zoom_one; - GtkToolItem *zoom_fit; - GtkToolItem *zoom_in; - GtkToolItem *zoom_out; + GtkWidget *multi; + GtkWidget *zoom_one; + GtkWidget *zoom_fit; + GtkWidget *zoom_in; + GtkWidget *zoom_out; /* real size of the page in inches */ double paper_w; @@ -548,31 +548,36 @@ create_bar (XedPrintPreview *preview) GtkToolItem *i; AtkObject *atko; GtkWidget *status; + GtkWidget *box; + GtkWidget *close_button; priv = preview->priv; toolbar = gtk_toolbar_new (); - gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ); + gtk_style_context_add_class (gtk_widget_get_style_context (toolbar), "inline-toolbar"); gtk_widget_show (toolbar); gtk_box_pack_start (GTK_BOX (preview), toolbar, FALSE, FALSE, 0); - priv->prev = gtk_tool_button_new_from_stock (GTK_STOCK_GO_BACK); - gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->prev), "P_revious Page"); - gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (priv->prev), TRUE); - gtk_tool_item_set_tooltip_text (priv->prev, _("Show the previous page")); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->prev, -1); + i = gtk_tool_item_new (); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); + + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_style_context_add_class (gtk_widget_get_style_context (box), "linked"); + gtk_container_add (GTK_CONTAINER (i), box); + + priv->prev = gtk_button_new_from_icon_name ("go-previous-symbolic", GTK_ICON_SIZE_MENU); + gtk_box_pack_start (GTK_BOX (box), priv->prev, FALSE, FALSE, 0); + gtk_widget_set_tooltip_text (priv->prev, _("Show the previous page")); g_signal_connect (priv->prev, "clicked", G_CALLBACK (prev_button_clicked), preview); - gtk_widget_show (GTK_WIDGET (priv->prev)); - priv->next = gtk_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD); - gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->next), "_Next Page"); - gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (priv->next), TRUE); - gtk_tool_item_set_tooltip_text (priv->next, _("Show the next page")); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->next, -1); + priv->next = gtk_button_new_from_icon_name ("go-next-symbolic", GTK_ICON_SIZE_MENU); + gtk_box_pack_start (GTK_BOX (box), priv->next, FALSE, FALSE, 0); + gtk_widget_set_tooltip_text (priv->next, _("Show the next page")); g_signal_connect (priv->next, "clicked", G_CALLBACK (next_button_clicked), preview); - gtk_widget_show (GTK_WIDGET (priv->next)); + + gtk_widget_show_all (GTK_WIDGET (i)); i = gtk_separator_tool_item_new (); gtk_widget_show (GTK_WIDGET (i)); @@ -615,59 +620,71 @@ create_bar (XedPrintPreview *preview) gtk_widget_show (GTK_WIDGET (i)); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); - priv->multi = gtk_tool_button_new_from_stock (GTK_STOCK_DND_MULTIPLE); - gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->multi), "_Show Multiple Pages"); - gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (priv->multi), TRUE); - gtk_tool_item_set_tooltip_text (priv->multi, _("Show multiple pages")); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->multi, -1); + i = gtk_tool_item_new (); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_container_add (GTK_CONTAINER (i), box); + + priv->multi = gtk_button_new_from_icon_name ("view-grid-symbolic", GTK_ICON_SIZE_MENU); + gtk_box_pack_start (GTK_BOX (box), priv->multi, FALSE, FALSE, 0); + gtk_widget_set_tooltip_text (priv->multi, _("Show multiple pages")); g_signal_connect (priv->multi, "clicked", G_CALLBACK (multi_button_clicked), preview); - gtk_widget_show (GTK_WIDGET (priv->multi)); + + gtk_widget_show_all (GTK_WIDGET (i)); i = gtk_separator_tool_item_new (); gtk_widget_show (GTK_WIDGET (i)); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); - priv->zoom_one = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_100); - gtk_tool_item_set_tooltip_text (priv->zoom_one, _("Zoom 1:1")); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->zoom_one, -1); + i = gtk_tool_item_new (); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_style_context_add_class (gtk_widget_get_style_context (box), "linked"); + gtk_container_add (GTK_CONTAINER (i), box); + + priv->zoom_one = gtk_button_new_from_icon_name ("zoom-original-symbolic", GTK_ICON_SIZE_MENU); + gtk_box_pack_start (GTK_BOX (box), priv->zoom_one, FALSE, FALSE, 0); + gtk_widget_set_tooltip_text (priv->zoom_one, _("Zoom 1:1")); g_signal_connect (priv->zoom_one, "clicked", G_CALLBACK (zoom_one_button_clicked), preview); - gtk_widget_show (GTK_WIDGET (priv->zoom_one)); - priv->zoom_fit = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_FIT); - gtk_tool_item_set_tooltip_text (priv->zoom_fit, _("Zoom to fit the whole page")); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->zoom_fit, -1); + priv->zoom_fit = gtk_button_new_from_icon_name ("zoom-fit-best-symbolic", GTK_ICON_SIZE_MENU); + gtk_box_pack_start (GTK_BOX (box), priv->zoom_fit, FALSE, FALSE, 0); + gtk_widget_set_tooltip_text (priv->zoom_fit, _("Zoom to fit the whole page")); g_signal_connect (priv->zoom_fit, "clicked", G_CALLBACK (zoom_fit_button_clicked), preview); - gtk_widget_show (GTK_WIDGET (priv->zoom_fit)); - priv->zoom_in = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_IN); - gtk_tool_item_set_tooltip_text (priv->zoom_in, _("Zoom the page in")); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->zoom_in, -1); + priv->zoom_in = gtk_button_new_from_icon_name ("zoom-in-symbolic", GTK_ICON_SIZE_MENU); + gtk_box_pack_start (GTK_BOX (box), priv->zoom_in, FALSE, FALSE, 0); + gtk_widget_set_tooltip_text (priv->zoom_in, _("Zoom the page in")); g_signal_connect (priv->zoom_in, "clicked", G_CALLBACK (zoom_in_button_clicked), preview); - gtk_widget_show (GTK_WIDGET (priv->zoom_in)); - priv->zoom_out = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_OUT); - gtk_tool_item_set_tooltip_text (priv->zoom_out, _("Zoom the page out")); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->zoom_out, -1); + priv->zoom_out = gtk_button_new_from_icon_name ("zoom-out-symbolic", GTK_ICON_SIZE_MENU); + gtk_box_pack_start (GTK_BOX (box), priv->zoom_out, FALSE, FALSE, 0); + gtk_widget_set_tooltip_text (priv->zoom_out, _("Zoom the page out")); g_signal_connect (priv->zoom_out, "clicked", G_CALLBACK (zoom_out_button_clicked), preview); - gtk_widget_show (GTK_WIDGET (priv->zoom_out)); + + gtk_widget_show_all (GTK_WIDGET (i)); i = gtk_separator_tool_item_new (); gtk_widget_show (GTK_WIDGET (i)); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); - i = gtk_tool_button_new (NULL, _("_Close Preview")); - gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (i), TRUE); - gtk_tool_item_set_is_important (i, TRUE); - gtk_tool_item_set_tooltip_text (i, _("Close print preview")); - g_signal_connect (i, "clicked", - G_CALLBACK (close_button_clicked), preview); - gtk_widget_show (GTK_WIDGET (i)); + i = gtk_tool_item_new (); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1); + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_container_add (GTK_CONTAINER (i), box); + + close_button = gtk_button_new_with_mnemonic (_("_Close preview")); + gtk_box_pack_start (GTK_BOX (box), close_button, FALSE, FALSE, 0); + gtk_widget_set_tooltip_text (close_button, _("Close print preview")); + g_signal_connect (close_button, "clicked", + G_CALLBACK (close_button_clicked), preview); + + gtk_widget_show_all (GTK_WIDGET (i)); } static gint From 01ace1d02f2c112f763cb7aa342a56ec9b3b01f4 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 7 Jan 2017 03:24:46 -0800 Subject: [PATCH 072/132] xed-print-preview.c: Don't you deprecated gtk_layout_get_*adjustment --- xed/xed-print-preview.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xed/xed-print-preview.c b/xed/xed-print-preview.c index 6bb1809..54164d4 100644 --- a/xed/xed-print-preview.c +++ b/xed/xed-print-preview.c @@ -252,8 +252,8 @@ set_zoom_fit_to_size (XedPrintPreview *preview) priv = preview->priv; - g_object_get (gtk_layout_get_hadjustment (GTK_LAYOUT (priv->layout)), "page-size", &width, NULL); - g_object_get (gtk_layout_get_vadjustment (GTK_LAYOUT (priv->layout)), "page-size", &height, NULL); + g_object_get (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (priv->layout)), "page-size", &width, NULL); + g_object_get (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (priv->layout)), "page-size", &height, NULL); width /= priv->cols; height /= priv->rows; @@ -714,8 +714,8 @@ get_page_at_coords (XedPrintPreview *preview, return -1; } - hadj = gtk_layout_get_hadjustment (GTK_LAYOUT (priv->layout)); - vadj = gtk_layout_get_vadjustment (GTK_LAYOUT (priv->layout)); + hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (priv->layout)); + vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (priv->layout)); x += gtk_adjustment_get_value (hadj); y += gtk_adjustment_get_value (vadj); @@ -782,8 +782,8 @@ preview_layout_key_press (GtkWidget *widget, priv = preview->priv; - hadj = gtk_layout_get_hadjustment (GTK_LAYOUT (priv->layout)); - vadj = gtk_layout_get_vadjustment (GTK_LAYOUT (priv->layout)); + hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (priv->layout)); + vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (priv->layout)); x = gtk_adjustment_get_value (hadj); y = gtk_adjustment_get_value (vadj); From a1671a6227b9d6bf192115b219f719b184a9bbb1 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 7 Jan 2017 04:13:12 -0800 Subject: [PATCH 073/132] xed-progress-message-area.c: Clean up code style --- xed/xed-progress-message-area.c | 246 +++++++++++++++----------------- 1 file changed, 118 insertions(+), 128 deletions(-) diff --git a/xed/xed-progress-message-area.c b/xed/xed-progress-message-area.c index 87696fb..78cbdd2 100644 --- a/xed/xed-progress-message-area.c +++ b/xed/xed-progress-message-area.c @@ -2,7 +2,7 @@ * xed-progress-message-area.c * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,20 +16,20 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ - + /* TODO: add properties */ - + #ifdef HAVE_CONFIG_H #include #endif @@ -40,9 +40,10 @@ #include "xed-progress-message-area.h" -enum { - PROP_0, - PROP_HAS_CANCEL_BUTTON +enum +{ + PROP_0, + PROP_HAS_CANCEL_BUTTON }; @@ -50,194 +51,183 @@ enum { struct _XedProgressMessageAreaPrivate { - GtkWidget *image; - GtkWidget *label; - GtkWidget *progress; + GtkWidget *image; + GtkWidget *label; + GtkWidget *progress; }; G_DEFINE_TYPE(XedProgressMessageArea, xed_progress_message_area, GTK_TYPE_INFO_BAR) static void xed_progress_message_area_set_has_cancel_button (XedProgressMessageArea *area, - gboolean has_button) + gboolean has_button) { - if (has_button) - gtk_info_bar_add_button (GTK_INFO_BAR (area), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); + if (has_button) + { + gtk_info_bar_add_button (GTK_INFO_BAR (area), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + } - g_object_notify (G_OBJECT (area), "has-cancel-button"); + g_object_notify (G_OBJECT (area), "has-cancel-button"); } static void xed_progress_message_area_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - XedProgressMessageArea *area; + XedProgressMessageArea *area; - area = XED_PROGRESS_MESSAGE_AREA (object); + area = XED_PROGRESS_MESSAGE_AREA (object); - switch (prop_id) - { - case PROP_HAS_CANCEL_BUTTON: - xed_progress_message_area_set_has_cancel_button (area, - g_value_get_boolean (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_HAS_CANCEL_BUTTON: + xed_progress_message_area_set_has_cancel_button (area, g_value_get_boolean (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -xed_progress_message_area_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) +xed_progress_message_area_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { - switch (prop_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } -static void +static void xed_progress_message_area_class_init (XedProgressMessageAreaClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - gobject_class->set_property = xed_progress_message_area_set_property; - gobject_class->get_property = xed_progress_message_area_get_property; + gobject_class->set_property = xed_progress_message_area_set_property; + gobject_class->get_property = xed_progress_message_area_get_property; - g_object_class_install_property (gobject_class, - PROP_HAS_CANCEL_BUTTON, - g_param_spec_boolean ("has-cancel-button", - "Has Cancel Button", - "If the message area has a cancel button", - TRUE, - G_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (gobject_class, + PROP_HAS_CANCEL_BUTTON, + g_param_spec_boolean ("has-cancel-button", + "Has Cancel Button", + "If the message area has a cancel button", + TRUE, + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); - g_type_class_add_private (gobject_class, sizeof(XedProgressMessageAreaPrivate)); + g_type_class_add_private (gobject_class, sizeof(XedProgressMessageAreaPrivate)); } static void xed_progress_message_area_init (XedProgressMessageArea *area) { - GtkWidget *vbox; - GtkWidget *hbox; - - area->priv = XED_PROGRESS_MESSAGE_AREA_GET_PRIVATE (area); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_widget_show (vbox); + GtkWidget *vbox; + GtkWidget *hbox; - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); - gtk_widget_show (hbox); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + area->priv = XED_PROGRESS_MESSAGE_AREA_GET_PRIVATE (area); - area->priv->image = gtk_image_new_from_icon_name (GTK_STOCK_MISSING_IMAGE, - GTK_ICON_SIZE_SMALL_TOOLBAR); - gtk_widget_show (area->priv->image); - gtk_widget_set_halign (area->priv->image, GTK_ALIGN_CENTER); - gtk_widget_set_valign (area->priv->image, GTK_ALIGN_CENTER); - gtk_box_pack_start (GTK_BOX (hbox), area->priv->image, FALSE, FALSE, 4); - - area->priv->label = gtk_label_new (""); - gtk_widget_show (area->priv->label); - gtk_box_pack_start (GTK_BOX (hbox), area->priv->label, TRUE, TRUE, 0); - gtk_label_set_use_markup (GTK_LABEL (area->priv->label), TRUE); - gtk_misc_set_alignment (GTK_MISC (area->priv->label), 0.0, 0.5); - gtk_label_set_ellipsize (GTK_LABEL (area->priv->label), - PANGO_ELLIPSIZE_END); + vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_widget_show (vbox); - area->priv->progress = gtk_progress_bar_new (); - gtk_widget_show (area->priv->progress); - gtk_box_pack_start (GTK_BOX (vbox), area->priv->progress, TRUE, FALSE, 0); - gtk_widget_set_size_request (area->priv->progress, -1, 15); + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); + gtk_widget_show (hbox); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - GtkWidget *content; - - content = gtk_info_bar_get_content_area (GTK_INFO_BAR (area)); - gtk_container_add (GTK_CONTAINER (content), vbox); + area->priv->image = gtk_image_new_from_icon_name (GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_SMALL_TOOLBAR); + gtk_widget_show (area->priv->image); + gtk_widget_set_halign (area->priv->image, GTK_ALIGN_CENTER); + gtk_widget_set_valign (area->priv->image, GTK_ALIGN_CENTER); + gtk_box_pack_start (GTK_BOX (hbox), area->priv->image, FALSE, FALSE, 4); + + area->priv->label = gtk_label_new (""); + gtk_widget_show (area->priv->label); + gtk_box_pack_start (GTK_BOX (hbox), area->priv->label, TRUE, TRUE, 0); + gtk_label_set_use_markup (GTK_LABEL (area->priv->label), TRUE); + gtk_misc_set_alignment (GTK_MISC (area->priv->label), 0.0, 0.5); + gtk_label_set_ellipsize (GTK_LABEL (area->priv->label), PANGO_ELLIPSIZE_END); + + area->priv->progress = gtk_progress_bar_new (); + gtk_widget_show (area->priv->progress); + gtk_box_pack_start (GTK_BOX (vbox), area->priv->progress, TRUE, FALSE, 0); + gtk_widget_set_size_request (area->priv->progress, -1, 15); + + GtkWidget *content; + + content = gtk_info_bar_get_content_area (GTK_INFO_BAR (area)); + gtk_container_add (GTK_CONTAINER (content), vbox); } GtkWidget * xed_progress_message_area_new (const gchar *stock_id, - const gchar *markup, - gboolean has_cancel) + const gchar *markup, + gboolean has_cancel) { - XedProgressMessageArea *area; + XedProgressMessageArea *area; - g_return_val_if_fail (stock_id != NULL, NULL); - g_return_val_if_fail (markup != NULL, NULL); + g_return_val_if_fail (stock_id != NULL, NULL); + g_return_val_if_fail (markup != NULL, NULL); - area = XED_PROGRESS_MESSAGE_AREA (g_object_new (XED_TYPE_PROGRESS_MESSAGE_AREA, - "has-cancel-button", has_cancel, - NULL)); + area = XED_PROGRESS_MESSAGE_AREA (g_object_new (XED_TYPE_PROGRESS_MESSAGE_AREA, + "has-cancel-button", has_cancel, + NULL)); - xed_progress_message_area_set_stock_image (area, - stock_id); + xed_progress_message_area_set_stock_image (area, stock_id); + xed_progress_message_area_set_markup (area, markup); - xed_progress_message_area_set_markup (area, - markup); - - return GTK_WIDGET (area); + return GTK_WIDGET (area); } void xed_progress_message_area_set_stock_image (XedProgressMessageArea *area, - const gchar *stock_id) + const gchar *stock_id) { - g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area)); - g_return_if_fail (stock_id != NULL); - - gtk_image_set_from_stock (GTK_IMAGE (area->priv->image), - stock_id, - GTK_ICON_SIZE_SMALL_TOOLBAR); + g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area)); + g_return_if_fail (stock_id != NULL); + + gtk_image_set_from_stock (GTK_IMAGE (area->priv->image), stock_id, GTK_ICON_SIZE_SMALL_TOOLBAR); } void xed_progress_message_area_set_markup (XedProgressMessageArea *area, - const gchar *markup) + const gchar *markup) { - g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area)); - g_return_if_fail (markup != NULL); + g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area)); + g_return_if_fail (markup != NULL); - gtk_label_set_markup (GTK_LABEL (area->priv->label), - markup); + gtk_label_set_markup (GTK_LABEL (area->priv->label), markup); } void xed_progress_message_area_set_text (XedProgressMessageArea *area, - const gchar *text) + const gchar *text) { - g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area)); - g_return_if_fail (text != NULL); + g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area)); + g_return_if_fail (text != NULL); - gtk_label_set_text (GTK_LABEL (area->priv->label), - text); + gtk_label_set_text (GTK_LABEL (area->priv->label), text); } void xed_progress_message_area_set_fraction (XedProgressMessageArea *area, - gdouble fraction) + gdouble fraction) { - g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area)); + g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area)); - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (area->priv->progress), - fraction); + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (area->priv->progress), fraction); } void xed_progress_message_area_pulse (XedProgressMessageArea *area) { - g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area)); + g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area)); - gtk_progress_bar_pulse (GTK_PROGRESS_BAR (area->priv->progress)); + gtk_progress_bar_pulse (GTK_PROGRESS_BAR (area->priv->progress)); } From 32fd96e3276028bc442e7529b341e254bbd10e87 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 7 Jan 2017 12:58:32 -0800 Subject: [PATCH 074/132] xed-progress-message-area: Clean up more uses of GtkStock --- docs/reference/xed-sections.txt | 2 +- xed/xed-progress-message-area.c | 18 ++++++------ xed/xed-progress-message-area.h | 52 ++++++++++++++++----------------- xed/xed-tab.c | 10 +++---- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/docs/reference/xed-sections.txt b/docs/reference/xed-sections.txt index 8b8dd1a..8a789f0 100644 --- a/docs/reference/xed-sections.txt +++ b/docs/reference/xed-sections.txt @@ -275,7 +275,7 @@ XedProgressMessageAreaPrivate XedProgressMessageArea XedProgressMessageArea xed_progress_message_area_new -xed_progress_message_area_set_stock_image +xed_progress_message_area_set_image xed_progress_message_area_set_markup xed_progress_message_area_set_text xed_progress_message_area_set_fraction diff --git a/xed/xed-progress-message-area.c b/xed/xed-progress-message-area.c index 78cbdd2..cbb86e0 100644 --- a/xed/xed-progress-message-area.c +++ b/xed/xed-progress-message-area.c @@ -64,7 +64,7 @@ xed_progress_message_area_set_has_cancel_button (XedProgressMessageArea *area, { if (has_button) { - gtk_info_bar_add_button (GTK_INFO_BAR (area), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + gtk_info_bar_add_button (GTK_INFO_BAR (area), _("Cancel"), GTK_RESPONSE_CANCEL); } g_object_notify (G_OBJECT (area), "has-cancel-button"); @@ -141,7 +141,7 @@ xed_progress_message_area_init (XedProgressMessageArea *area) gtk_widget_show (hbox); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - area->priv->image = gtk_image_new_from_icon_name (GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_SMALL_TOOLBAR); + area->priv->image = gtk_image_new_from_icon_name ("image-missing", GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_widget_show (area->priv->image); gtk_widget_set_halign (area->priv->image, GTK_ALIGN_CENTER); gtk_widget_set_valign (area->priv->image, GTK_ALIGN_CENTER); @@ -166,33 +166,33 @@ xed_progress_message_area_init (XedProgressMessageArea *area) } GtkWidget * -xed_progress_message_area_new (const gchar *stock_id, +xed_progress_message_area_new (const gchar *icon_name, const gchar *markup, gboolean has_cancel) { XedProgressMessageArea *area; - g_return_val_if_fail (stock_id != NULL, NULL); + g_return_val_if_fail (icon_name != NULL, NULL); g_return_val_if_fail (markup != NULL, NULL); area = XED_PROGRESS_MESSAGE_AREA (g_object_new (XED_TYPE_PROGRESS_MESSAGE_AREA, "has-cancel-button", has_cancel, NULL)); - xed_progress_message_area_set_stock_image (area, stock_id); + xed_progress_message_area_set_image (area, icon_name); xed_progress_message_area_set_markup (area, markup); return GTK_WIDGET (area); } void -xed_progress_message_area_set_stock_image (XedProgressMessageArea *area, - const gchar *stock_id) +xed_progress_message_area_set_image (XedProgressMessageArea *area, + const gchar *icon_name) { g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area)); - g_return_if_fail (stock_id != NULL); + g_return_if_fail (icon_name != NULL); - gtk_image_set_from_stock (GTK_IMAGE (area->priv->image), stock_id, GTK_ICON_SIZE_SMALL_TOOLBAR); + gtk_image_set_from_icon_name (GTK_IMAGE (area->priv->image), icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR); } void diff --git a/xed/xed-progress-message-area.h b/xed/xed-progress-message-area.h index 4b830db..35d4416 100644 --- a/xed/xed-progress-message-area.h +++ b/xed/xed-progress-message-area.h @@ -2,7 +2,7 @@ * xed-progress-message-area.h * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -53,12 +53,12 @@ typedef struct _XedProgressMessageAreaPrivate XedProgressMessageAreaPrivate; */ typedef struct _XedProgressMessageArea XedProgressMessageArea; -struct _XedProgressMessageArea +struct _XedProgressMessageArea { - GtkInfoBar parent; + GtkInfoBar parent; - /*< private > */ - XedProgressMessageAreaPrivate *priv; + /*< private > */ + XedProgressMessageAreaPrivate *priv; }; /* @@ -66,34 +66,34 @@ struct _XedProgressMessageArea */ typedef struct _XedProgressMessageAreaClass XedProgressMessageAreaClass; -struct _XedProgressMessageAreaClass +struct _XedProgressMessageAreaClass { - GtkInfoBarClass parent_class; + GtkInfoBarClass parent_class; }; /* * Public methods */ -GType xed_progress_message_area_get_type (void) G_GNUC_CONST; +GType xed_progress_message_area_get_type (void) G_GNUC_CONST; -GtkWidget *xed_progress_message_area_new (const gchar *stock_id, - const gchar *markup, - gboolean has_cancel); +GtkWidget *xed_progress_message_area_new (const gchar *icon_name, + const gchar *markup, + gboolean has_cancel); -void xed_progress_message_area_set_stock_image (XedProgressMessageArea *area, - const gchar *stock_id); +void xed_progress_message_area_set_image (XedProgressMessageArea *area, + const gchar *icon_name); -void xed_progress_message_area_set_markup (XedProgressMessageArea *area, - const gchar *markup); +void xed_progress_message_area_set_markup (XedProgressMessageArea *area, + const gchar *markup); -void xed_progress_message_area_set_text (XedProgressMessageArea *area, - const gchar *text); +void xed_progress_message_area_set_text (XedProgressMessageArea *area, + const gchar *text); -void xed_progress_message_area_set_fraction (XedProgressMessageArea *area, - gdouble fraction); +void xed_progress_message_area_set_fraction (XedProgressMessageArea *area, + gdouble fraction); + +void xed_progress_message_area_pulse (XedProgressMessageArea *area); -void xed_progress_message_area_pulse (XedProgressMessageArea *area); - G_END_DECLS diff --git a/xed/xed-tab.c b/xed/xed-tab.c index 77b9947..f33754b 100644 --- a/xed/xed-tab.c +++ b/xed/xed-tab.c @@ -657,7 +657,7 @@ show_loading_message_area (XedTab *tab) msg = g_strdup_printf (_("Reverting %s"), name_markup); } - area = xed_progress_message_area_new (GTK_STOCK_REVERT_TO_SAVED, msg, TRUE); + area = xed_progress_message_area_new ("document-revert-symbolic", msg, TRUE); } else { @@ -675,7 +675,7 @@ show_loading_message_area (XedTab *tab) msg = g_strdup_printf (_("Loading %s"), name_markup); } - area = xed_progress_message_area_new (GTK_STOCK_OPEN, msg, TRUE); + area = xed_progress_message_area_new ("document-open-symbolic", msg, TRUE); } g_signal_connect (area, "response", @@ -758,7 +758,7 @@ show_saving_message_area (XedTab *tab) msg = g_strdup_printf (_("Saving %s"), from_markup); } - area = xed_progress_message_area_new (GTK_STOCK_SAVE, msg, FALSE); + area = xed_progress_message_area_new ("document-save-symbolic", msg, FALSE); gtk_widget_show (area); @@ -2316,11 +2316,11 @@ show_printing_message_area (XedTab *tab, if (preview) { - area = xed_progress_message_area_new (GTK_STOCK_PRINT_PREVIEW, "", TRUE); + area = xed_progress_message_area_new ("document-print-preview-symbolic", "", TRUE); } else { - area = xed_progress_message_area_new (GTK_STOCK_PRINT, "", TRUE); + area = xed_progress_message_area_new ("document-print-symbolic", "", TRUE); } g_signal_connect (area, "response", From d45e07b7a1e1b1dac1793543721b3e77d72948c8 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 8 Jan 2017 04:00:44 -0800 Subject: [PATCH 075/132] Install introspection data and lib into a private dir --- debian/control | 50 +-------------------------------------- debian/gir1.2-xed.install | 2 -- debian/xed-common.install | 12 +++++----- debian/xed-dev.install | 4 +++- debian/xed-doc.install | 1 - debian/xed.install | 9 ++++--- xed/Makefile.am | 26 +++++++++++++------- xed/xed-plugins-engine.c | 37 ++++++++++++++++++----------- 8 files changed, 56 insertions(+), 85 deletions(-) delete mode 100644 debian/gir1.2-xed.install delete mode 100644 debian/xed-doc.install diff --git a/debian/control b/debian/control index a3e97b3..0e2f191 100644 --- a/debian/control +++ b/debian/control @@ -117,52 +117,4 @@ Description: generic text editor (debugging symbols) provided to help debugging problems. . The debugging symbols are installed in /usr/lib/debug and will - automatically be used by gdb. - -Package: xed-doc -Section: doc -Architecture: all -Depends: ${misc:Depends}, -Description: generic text editor (documentation files) - Xed is a text editor which supports most standard editor features, - extending this basic functionality with other features not usually - found in simple text editors. Xed is a graphical application which - supports editing multiple text files in one window (known sometimes as - tabs or MDI). - . - Xed fully supports international text through its use of the - Unicode UTF-8 encoding in edited files. Its core feature set includes syntax - highlighting of source code, auto indentation and printing and print preview - support. - . - Xed is also extensible through its plugin system, which currently - includes support for spell checking, comparing files, viewing CVS - ChangeLogs, and adjusting indentation levels. - . - This package contains the documentation files. - -Package: gir1.2-xed -Architecture: any -Depends: ${gir:Depends}, - ${misc:Depends}, - ${shlibs:Depends}, -Description: GObject introspection data for Xed - Xed is a text editor which supports most standard editor features, - extending this basic functionality with other features not usually - found in simple text editors. Xed is a graphical application which - supports editing multiple text files in one window (known sometimes as - tabs or MDI). - . - Xed fully supports international text through its use of the - Unicode UTF-8 encoding in edited files. Its core feature set includes syntax - highlighting of source code, auto indentation and printing and print preview - support. - . - Xed is also extensible through its plugin system, which currently - includes support for spell checking, comparing files, viewing CVS - ChangeLogs, and adjusting indentation levels. - . - This package contains introspection data for Xed. - . - It can be used by packages using the GIRepository format to generate - dynamic bindings. \ No newline at end of file + automatically be used by gdb. \ No newline at end of file diff --git a/debian/gir1.2-xed.install b/debian/gir1.2-xed.install deleted file mode 100644 index d8bd766..0000000 --- a/debian/gir1.2-xed.install +++ /dev/null @@ -1,2 +0,0 @@ -usr/lib/*/girepository-1.0 -usr/share/gir-1.0 \ No newline at end of file diff --git a/debian/xed-common.install b/debian/xed-common.install index 2235f57..ea36e5f 100644 --- a/debian/xed-common.install +++ b/debian/xed-common.install @@ -1,7 +1,7 @@ -usr/share/appdata/ -usr/share/glib-2.0/ -usr/share/help/ -usr/share/locale/ -usr/share/xed/icons/ -usr/share/xed/plugins/ +usr/share/appdata +usr/share/glib-2.0 +usr/share/help +usr/share/locale +usr/share/xed/icons +usr/share/xed/plugins usr/share/xed/ui/ diff --git a/debian/xed-dev.install b/debian/xed-dev.install index f91091d..20c7fd4 100644 --- a/debian/xed-dev.install +++ b/debian/xed-dev.install @@ -1,2 +1,4 @@ -usr/include/xed/ +usr/include usr/lib/*/pkgconfig/ +usr/share/gtk-doc +usr/share/xed/gir-1.0 diff --git a/debian/xed-doc.install b/debian/xed-doc.install deleted file mode 100644 index d6da04c..0000000 --- a/debian/xed-doc.install +++ /dev/null @@ -1 +0,0 @@ -usr/share/gtk-doc/ diff --git a/debian/xed.install b/debian/xed.install index 4135f88..61d679f 100644 --- a/debian/xed.install +++ b/debian/xed.install @@ -1,5 +1,8 @@ -usr/bin/ -usr/lib/*/xed/plugins/ +usr/bin/xed +usr/lib/*/xed/plugins/*.plugin +usr/lib/*/xed/girepository-1.0/ +usr/lib/*/xed/plugins/*.plugin +usr/lib/*/xed/plugins/*.so usr/lib/xed/xed-bugreport.sh -usr/share/applications/ +usr/share/applications/xed.desktop usr/share/man/ diff --git a/xed/Makefile.am b/xed/Makefile.am index e7d6d36..fadeb3e 100644 --- a/xed/Makefile.am +++ b/xed/Makefile.am @@ -19,7 +19,11 @@ AM_CPPFLAGS = \ xed_SOURCES = \ xed.c -xed_LDADD = libxed.la $(XED_LIBS) $(EGG_SMCLIENT_LIBS) $(INTROSPECTION_LIBS) +xed_LDADD = \ + libxed.la \ + $(XED_LIBS) \ + $(EGG_SMCLIENT_LIBS) \ + $(INTROSPECTION_LIBS) xed_LDFLAGS = -export-dynamic -no-undefined -export-symbols-regex "^[[^_]].*" @@ -152,8 +156,8 @@ libxed_c_files = \ xedtextregion.c libxed_la_SOURCES = \ - $(libxed_c_files) \ $(BUILT_SOURCES) \ + $(libxed_c_files) \ $(BACON_FILES) \ $(POSIXIO_FILES) \ $(NOINST_H_FILES) \ @@ -194,22 +198,26 @@ CLEANFILES = $(BUILT_SOURCES) if HAVE_INTROSPECTION -include $(INTROSPECTION_MAKEFILE) INTROSPECTION_GIRS = Xed-1.0.gir -INTROSPECTION_SCANNER_ARGS = -I$(top_srcdir) --warn-all + + Xed-1.0.gir: xed -Xed_1_0_gir_INCLUDES = Gtk-3.0 GtkSource-3.0 -Xed_1_0_gir_FILES = $(INST_H_FILES) $(libxed_c_files) $(BUILT_SOURCES) +INTROSPECTION_SCANNER_ARGS = -I$(top_srcdir) --warn-all +Xed_1_0_gir_NAMESPACE = Xed Xed_1_0_gir_VERSION = 1.0 Xed_1_0_gir_PROGRAM = $(builddir)/xed -Xed_1_0_gir_NAMESPACE = Xed +Xed_1_0_gir_FILES = $(INST_H_FILES) $(libxed_c_files) $(BUILT_SOURCES) +Xed_1_0_gir_INCLUDES = Gtk-3.0 GtkSource-3.0 -girdir = $(datadir)/gir-1.0 +girdir = $(datadir)/xed/gir-1.0 gir_DATA = $(INTROSPECTION_GIRS) -typelibdir = $(libdir)/girepository-1.0 +typelibdir = $(libdir)/xed/girepository-1.0 typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib) -CLEANFILES += $(gir_DATA) $(typelib_DATA) +CLEANFILES += \ + $(gir_DATA) \ + $(typelib_DATA) endif dist-hook: diff --git a/xed/xed-plugins-engine.c b/xed/xed-plugins-engine.c index c3160ab..d0a6caf 100644 --- a/xed/xed-plugins-engine.c +++ b/xed/xed-plugins-engine.c @@ -55,7 +55,7 @@ XedPluginsEngine *default_engine = NULL; static void xed_plugins_engine_init (XedPluginsEngine *engine) { - gchar *private_path; + gchar *typelib_dir; GError *error = NULL; xed_debug (DEBUG_PLUGINS); @@ -66,6 +66,17 @@ xed_plugins_engine_init (XedPluginsEngine *engine) peas_engine_enable_loader (PEAS_ENGINE (engine), "python3"); + typelib_dir = g_build_filename (xed_dirs_get_xed_lib_dir (), "girepository-1.0", NULL); + + if (!g_irepository_require_private (g_irepository_get_default (), typelib_dir, "Xed", "1.0", 0, &error)) + { + g_warning ("Could not load Xed repository: %s", error->message); + g_error_free (error); + error = NULL; + } + + g_free (typelib_dir); + /* This should be moved to libpeas */ if (!g_irepository_require (g_irepository_get_default (), "Peas", "1.0", 0, &error)) { @@ -81,16 +92,16 @@ xed_plugins_engine_init (XedPluginsEngine *engine) error = NULL; } - private_path = g_build_filename (LIBDIR, "girepository-1.0", NULL); + // private_path = g_build_filename (LIBDIR, "girepository-1.0", NULL); - if (!g_irepository_require_private (g_irepository_get_default (), private_path, "Xed", "1.0", 0, &error)) - { - g_warning ("Could not load Xed repository: %s", error->message); - g_error_free (error); - error = NULL; - } + // if (!g_irepository_require_private (g_irepository_get_default (), private_path, "Xed", "1.0", 0, &error)) + // { + // g_warning ("Could not load Xed repository: %s", error->message); + // g_error_free (error); + // error = NULL; + // } - g_free (private_path); + // g_free (private_path); peas_engine_add_search_path (PEAS_ENGINE (engine), xed_dirs_get_user_plugins_dir (), @@ -131,13 +142,11 @@ xed_plugins_engine_class_init (XedPluginsEngineClass *klass) XedPluginsEngine * xed_plugins_engine_get_default (void) { - if (default_engine != NULL) + if (default_engine == NULL) { - return default_engine; + default_engine = XED_PLUGINS_ENGINE (g_object_new (XED_TYPE_PLUGINS_ENGINE, NULL)); + g_object_add_weak_pointer (G_OBJECT (default_engine), (gpointer) &default_engine); } - default_engine = XED_PLUGINS_ENGINE (g_object_new (XED_TYPE_PLUGINS_ENGINE, NULL)); - g_object_add_weak_pointer (G_OBJECT (default_engine), (gpointer) &default_engine); - return default_engine; } From b9e5097250d4e0fc3e75afc191c70daff1ebc584 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 9 Jan 2017 11:57:48 -0800 Subject: [PATCH 076/132] Add new (App/Window/View)Activatable interfaces for plugins Currently only the modelines and filebrowser plugins are updated to these new interfaces --- debian/xed-common.install | 2 +- debian/xed.install | 3 +- plugins/Makefile.am | 29 +- .../filebrowser/xed-file-bookmarks-store.h | 2 +- plugins/filebrowser/xed-file-browser-plugin.c | 1472 +++-- plugins/filebrowser/xed-file-browser-plugin.h | 4 +- plugins/filebrowser/xed-file-browser-store.c | 5222 +++++++++-------- plugins/filebrowser/xed-file-browser-store.h | 164 +- plugins/filebrowser/xed-file-browser-view.c | 1804 +++--- plugins/filebrowser/xed-file-browser-view.h | 71 +- plugins/filebrowser/xed-file-browser-widget.c | 36 +- plugins/filebrowser/xed-file-browser-widget.h | 2 +- plugins/modelines/modeline-parser.c | 83 +- plugins/modelines/modeline-parser.h | 14 +- plugins/modelines/xed-modeline-plugin.c | 235 +- plugins/modelines/xed-modeline-plugin.h | 3 +- xed/Makefile.am | 8 +- xed/xed-app-activatable.c | 108 + xed/xed-app-activatable.h | 61 + xed/xed-app.c | 55 +- xed/xed-view-activatable.c | 96 + xed/xed-view-activatable.h | 60 + xed/xed-view.c | 56 +- xed/xed-window-activatable.c | 117 + xed/xed-window-activatable.h | 62 + xed/xed-window.c | 76 +- 26 files changed, 5361 insertions(+), 4484 deletions(-) create mode 100644 xed/xed-app-activatable.c create mode 100644 xed/xed-app-activatable.h create mode 100644 xed/xed-view-activatable.c create mode 100644 xed/xed-view-activatable.h create mode 100644 xed/xed-window-activatable.c create mode 100644 xed/xed-window-activatable.h diff --git a/debian/xed-common.install b/debian/xed-common.install index ea36e5f..361f4b2 100644 --- a/debian/xed-common.install +++ b/debian/xed-common.install @@ -1,7 +1,7 @@ usr/share/appdata +usr/share/xed/plugins usr/share/glib-2.0 usr/share/help usr/share/locale usr/share/xed/icons -usr/share/xed/plugins usr/share/xed/ui/ diff --git a/debian/xed.install b/debian/xed.install index 61d679f..85dfd41 100644 --- a/debian/xed.install +++ b/debian/xed.install @@ -1,8 +1,7 @@ usr/bin/xed -usr/lib/*/xed/plugins/*.plugin usr/lib/*/xed/girepository-1.0/ +usr/lib/xed/xed-bugreport.sh usr/lib/*/xed/plugins/*.plugin usr/lib/*/xed/plugins/*.so -usr/lib/xed/xed-bugreport.sh usr/share/applications/xed.desktop usr/share/man/ diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 391a2a5..ced1a61 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,26 +1,9 @@ -DIST_SUBDIRS = \ - changecase \ - docinfo \ - filebrowser \ - modelines \ - sort \ - spell \ - taglist \ - time \ - trailsave +DIST_SUBDIRS = \ + filebrowser \ + modelines -SUBDIRS = \ - changecase \ - docinfo \ - filebrowser \ - modelines \ - sort \ - taglist \ - time \ - trailsave - -if ENABLE_ENCHANT -SUBDIRS += spell -endif +SUBDIRS = \ + filebrowser \ + modelines -include $(top_srcdir)/git.mk diff --git a/plugins/filebrowser/xed-file-bookmarks-store.h b/plugins/filebrowser/xed-file-bookmarks-store.h index 57fe961..9fe22ff 100644 --- a/plugins/filebrowser/xed-file-bookmarks-store.h +++ b/plugins/filebrowser/xed-file-bookmarks-store.h @@ -77,7 +77,7 @@ struct _XedFileBookmarksStoreClass }; GType xed_file_bookmarks_store_get_type (void) G_GNUC_CONST; -void _xed_file_bookmarks_store_register_type (GTypeModule * module); +void _xed_file_bookmarks_store_register_type (GTypeModule *type_module); XedFileBookmarksStore *xed_file_bookmarks_store_new (void); gchar *xed_file_bookmarks_store_get_uri (XedFileBookmarksStore * model, diff --git a/plugins/filebrowser/xed-file-browser-plugin.c b/plugins/filebrowser/xed-file-browser-plugin.c index 0f28829..52241c6 100644 --- a/plugins/filebrowser/xed-file-browser-plugin.c +++ b/plugins/filebrowser/xed-file-browser-plugin.c @@ -24,15 +24,16 @@ #include #endif -#include -#include -#include +#include #include -#include +#include +#include +#include #include #include -#include -#include +#include +#include +#include #include "xed-file-browser-enum-types.h" #include "xed-file-browser-plugin.h" @@ -41,74 +42,74 @@ #include "xed-file-browser-widget.h" #include "xed-file-browser-messages.h" -#define FILE_BROWSER_SCHEMA "org.x.editor.plugins.filebrowser" -#define FILE_BROWSER_ONLOAD_SCHEMA "org.x.editor.plugins.filebrowser.on-load" +#define FILE_BROWSER_SCHEMA "org.x.editor.plugins.filebrowser" +#define FILE_BROWSER_ONLOAD_SCHEMA "org.x.editor.plugins.filebrowser.on-load" -#define XED_FILE_BROWSER_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPluginPrivate)) +#define XED_FILE_BROWSER_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPluginPrivate)) struct _XedFileBrowserPluginPrivate { - GtkWidget *window; + XedWindow *window; - XedFileBrowserWidget * tree_widget; - gulong merge_id; - GtkActionGroup * action_group; - GtkActionGroup * single_selection_action_group; - gboolean auto_root; - gulong end_loading_handle; + XedFileBrowserWidget *tree_widget; + gulong merge_id; + GtkActionGroup *action_group; + GtkActionGroup *single_selection_action_group; + gboolean auto_root; + gulong end_loading_handle; - GSettings *settings; - GSettings *onload_settings; + GSettings *settings; + GSettings *onload_settings; }; enum { PROP_0, - PROP_OBJECT + PROP_WINDOW }; -static void on_uri_activated_cb (XedFileBrowserWidget * widget, - gchar const *uri, - XedWindow * window); -static void on_error_cb (XedFileBrowserWidget * widget, - guint code, - gchar const *message, - XedFileBrowserPluginPrivate * data); -static void on_model_set_cb (XedFileBrowserView * widget, - GParamSpec *arg1, - XedFileBrowserPluginPrivate * data); -static void on_virtual_root_changed_cb (XedFileBrowserStore * model, - GParamSpec * param, - XedFileBrowserPluginPrivate * data); -static void on_filter_mode_changed_cb (XedFileBrowserStore * model, - GParamSpec * param, - XedFileBrowserPluginPrivate * data); -static void on_rename_cb (XedFileBrowserStore * model, - const gchar * olduri, - const gchar * newuri, - XedWindow * window); -static void on_filter_pattern_changed_cb (XedFileBrowserWidget * widget, - GParamSpec * param, - XedFileBrowserPluginPrivate * data); -static void on_tab_added_cb (XedWindow * window, - XedTab * tab, - XedFileBrowserPluginPrivate * data); -static gboolean on_confirm_delete_cb (XedFileBrowserWidget * widget, - XedFileBrowserStore * store, - GList * rows, - XedFileBrowserPluginPrivate * data); -static gboolean on_confirm_no_trash_cb (XedFileBrowserWidget * widget, - GList * files, - XedWindow * window); +static void on_uri_activated_cb (XedFileBrowserWidget *widget, + gchar const *uri, + XedWindow *window); +static void on_error_cb (XedFileBrowserWidget *widget, + guint code, + gchar const *message, + XedFileBrowserPlugin *plugin); +static void on_model_set_cb (XedFileBrowserView *widget, + GParamSpec *arg1, + XedFileBrowserPlugin *plugin); +static void on_virtual_root_changed_cb (XedFileBrowserStore *model, + GParamSpec *param, + XedFileBrowserPlugin *plugin); +static void on_filter_mode_changed_cb (XedFileBrowserStore *model, + GParamSpec *param, + XedFileBrowserPlugin *plugin); +static void on_rename_cb (XedFileBrowserStore *model, + const gchar *olduri, + const gchar *newuri, + XedWindow *window); +static void on_filter_pattern_changed_cb (XedFileBrowserWidget *widget, + GParamSpec *param, + XedFileBrowserPlugin *plugin); +static void on_tab_added_cb (XedWindow *window, + XedTab *tab, + XedFileBrowserPlugin *plugin); +static gboolean on_confirm_delete_cb (XedFileBrowserWidget *widget, + XedFileBrowserStore *store, + GList *rows, + XedFileBrowserPlugin *plugin); +static gboolean on_confirm_no_trash_cb (XedFileBrowserWidget *widget, + GList *files, + XedWindow *window); -static void peas_activatable_iface_init (PeasActivatableInterface *iface); +static void xed_window_activatable_iface_init (XedWindowActivatableInterface *iface); G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedFileBrowserPlugin, xed_file_browser_plugin, PEAS_TYPE_EXTENSION_BASE, 0, - G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, - peas_activatable_iface_init) \ + G_IMPLEMENT_INTERFACE_DYNAMIC (XED_TYPE_WINDOW_ACTIVATABLE, + xed_window_activatable_iface_init) \ \ xed_file_browser_enum_and_flag_register_type (type_module); \ _xed_file_browser_store_register_type (type_module); \ @@ -119,21 +120,17 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedFileBrowserPlugin, static void -xed_file_browser_plugin_init (XedFileBrowserPlugin * plugin) +xed_file_browser_plugin_init (XedFileBrowserPlugin *plugin) { - plugin->priv = XED_FILE_BROWSER_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = XED_FILE_BROWSER_PLUGIN_GET_PRIVATE (plugin); } static void -xed_file_browser_plugin_dispose (GObject * object) +xed_file_browser_plugin_dispose (GObject *object) { XedFileBrowserPlugin *plugin = XED_FILE_BROWSER_PLUGIN (object); - if (plugin->priv->window != NULL) - { - g_object_unref (plugin->priv->window); - plugin->priv->window = NULL; - } + g_clear_object (&plugin->priv->window); G_OBJECT_CLASS (xed_file_browser_plugin_parent_class)->dispose (object); } @@ -144,12 +141,12 @@ xed_file_browser_plugin_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - XedFileBrowserPlugin *plugin = XED_FILE_BROWSER_PLUGIN (object); + XedFileBrowserPlugin *plugin = XED_FILE_BROWSER_PLUGIN (object); switch (prop_id) { - case PROP_OBJECT: - plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + case PROP_WINDOW: + plugin->priv->window = XED_WINDOW (g_value_dup_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -159,15 +156,15 @@ xed_file_browser_plugin_set_property (GObject *object, static void xed_file_browser_plugin_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - XedFileBrowserPlugin *plugin = XED_FILE_BROWSER_PLUGIN (object); + XedFileBrowserPlugin *plugin = XED_FILE_BROWSER_PLUGIN (object); switch (prop_id) { - case PROP_OBJECT: + case PROP_WINDOW: g_value_set_object (value, plugin->priv->window); break; default: @@ -177,251 +174,259 @@ xed_file_browser_plugin_get_property (GObject *object, } static void -on_end_loading_cb (XedFileBrowserStore * store, - GtkTreeIter * iter, - XedFileBrowserPluginPrivate * data) +on_end_loading_cb (XedFileBrowserStore *store, + GtkTreeIter *iter, + XedFileBrowserPlugin *plugin) { - /* Disconnect the signal */ - g_signal_handler_disconnect (store, data->end_loading_handle); - data->end_loading_handle = 0; - data->auto_root = FALSE; + XedFileBrowserPluginPrivate *priv = plugin->priv; + + /* Disconnect the signal */ + g_signal_handler_disconnect (store, priv->end_loading_handle); + priv->end_loading_handle = 0; + priv->auto_root = FALSE; } static void -prepare_auto_root (XedFileBrowserPluginPrivate *data) +prepare_auto_root (XedFileBrowserPlugin *plugin) { - XedFileBrowserStore *store; + XedFileBrowserPluginPrivate *priv = plugin->priv; + XedFileBrowserStore *store; - data->auto_root = TRUE; + priv->auto_root = TRUE; - store = xed_file_browser_widget_get_browser_store (data->tree_widget); + store = xed_file_browser_widget_get_browser_store (priv->tree_widget); - if (data->end_loading_handle != 0) { - g_signal_handler_disconnect (store, data->end_loading_handle); - data->end_loading_handle = 0; - } + if (priv->end_loading_handle != 0) + { + g_signal_handler_disconnect (store, priv->end_loading_handle); + priv->end_loading_handle = 0; + } - data->end_loading_handle = g_signal_connect (store, - "end-loading", - G_CALLBACK (on_end_loading_cb), - data); + priv->end_loading_handle = g_signal_connect (store, "end-loading", + G_CALLBACK (on_end_loading_cb), plugin); } static void -restore_default_location (XedFileBrowserPluginPrivate *data) +restore_default_location (XedFileBrowserPlugin *plugin) { - gchar * root; - gchar * virtual_root; - gboolean bookmarks; - gboolean remote; + XedFileBrowserPluginPrivate *priv = plugin->priv; + gchar *root; + gchar *virtual_root; + gboolean bookmarks; + gboolean remote; - bookmarks = !g_settings_get_boolean (data->onload_settings, "tree-view"); + bookmarks = !g_settings_get_boolean (priv->onload_settings, "tree-view"); - if (bookmarks) { - xed_file_browser_widget_show_bookmarks (data->tree_widget); - return; - } + if (bookmarks) + { + xed_file_browser_widget_show_bookmarks (priv->tree_widget); + return; + } - root = g_settings_get_string (data->onload_settings, "root"); - virtual_root = g_settings_get_string (data->onload_settings, "virtual-root"); + root = g_settings_get_string (priv->onload_settings, "root"); + virtual_root = g_settings_get_string (priv->onload_settings, "virtual-root"); - remote = g_settings_get_boolean (data->onload_settings, "enable-remote"); + remote = g_settings_get_boolean (priv->onload_settings, "enable-remote"); - if (root != NULL && *root != '\0') { - GFile *file; + if (root != NULL && *root != '\0') { + GFile *file; - file = g_file_new_for_uri (root); + file = g_file_new_for_uri (root); - if (remote || g_file_is_native (file)) { - if (virtual_root != NULL && *virtual_root != '\0') { - prepare_auto_root (data); - xed_file_browser_widget_set_root_and_virtual_root (data->tree_widget, - root, - virtual_root); - } else { - prepare_auto_root (data); - xed_file_browser_widget_set_root (data->tree_widget, - root, - TRUE); - } - } + if (remote || g_file_is_native (file)) + { + if (virtual_root != NULL && *virtual_root != '\0') + { + prepare_auto_root (plugin); + xed_file_browser_widget_set_root_and_virtual_root (priv->tree_widget, root, virtual_root); + } + else + { + prepare_auto_root (plugin); + xed_file_browser_widget_set_root (priv->tree_widget, root, TRUE); + } + } - g_object_unref (file); - } + g_object_unref (file); + } - g_free (root); - g_free (virtual_root); + g_free (root); + g_free (virtual_root); } static void -restore_filter (XedFileBrowserPluginPrivate *data) +restore_filter (XedFileBrowserPlugin *plugin) { - gchar *filter_mode; - XedFileBrowserStoreFilterMode mode; - gchar *pattern; + XedFileBrowserPluginPrivate *priv = plugin->priv; + gchar *filter_mode; + XedFileBrowserStoreFilterMode mode; + gchar *pattern; - /* Get filter_mode */ - filter_mode = g_settings_get_string (data->settings, "filter-mode"); + /* Get filter_mode */ + filter_mode = g_settings_get_string (priv->settings, "filter-mode"); - /* Filter mode */ - mode = xed_file_browser_store_filter_mode_get_default (); + /* Filter mode */ + mode = xed_file_browser_store_filter_mode_get_default (); - if (filter_mode != NULL) { - if (strcmp (filter_mode, "hidden") == 0) { - mode = XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN; - } else if (strcmp (filter_mode, "binary") == 0) { - mode = XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY; - } else if (strcmp (filter_mode, "hidden_and_binary") == 0 || - strcmp (filter_mode, "binary_and_hidden") == 0) { - mode = XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN | - XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY; - } else if (strcmp (filter_mode, "none") == 0 || - *filter_mode == '\0') { - mode = XED_FILE_BROWSER_STORE_FILTER_MODE_NONE; - } - } + if (filter_mode != NULL) { + if (strcmp (filter_mode, "hidden") == 0) { + mode = XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN; + } else if (strcmp (filter_mode, "binary") == 0) { + mode = XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY; + } else if (strcmp (filter_mode, "hidden_and_binary") == 0 || + strcmp (filter_mode, "binary_and_hidden") == 0) { + mode = XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN | + XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY; + } else if (strcmp (filter_mode, "none") == 0 || + *filter_mode == '\0') { + mode = XED_FILE_BROWSER_STORE_FILTER_MODE_NONE; + } + } - /* Set the filter mode */ - xed_file_browser_store_set_filter_mode ( - xed_file_browser_widget_get_browser_store (data->tree_widget), - mode); + /* Set the filter mode */ + xed_file_browser_store_set_filter_mode (xed_file_browser_widget_get_browser_store (priv->tree_widget), mode); - pattern = g_settings_get_string (data->settings, "filter-pattern"); + pattern = g_settings_get_string (priv->settings, "filter-pattern"); - xed_file_browser_widget_set_filter_pattern (data->tree_widget, - pattern); + xed_file_browser_widget_set_filter_pattern (priv->tree_widget, pattern); - g_free (filter_mode); - g_free (pattern); + g_free (filter_mode); + g_free (pattern); } static void -set_root_from_doc (XedFileBrowserPluginPrivate * data, - XedDocument * doc) +set_root_from_doc (XedFileBrowserPlugin *plugin, + XedDocument *doc) { - GFile *file; - GFile *parent; + XedFileBrowserPluginPrivate *priv = plugin->priv; + GFile *file; + GFile *parent; - if (doc == NULL) - return; + if (doc == NULL) + { + return; + } - file = xed_document_get_location (doc); - if (file == NULL) - return; + file = xed_document_get_location (doc); + if (file == NULL) + { + return; + } - parent = g_file_get_parent (file); + parent = g_file_get_parent (file); - if (parent != NULL) { - gchar * root; + if (parent != NULL) + { + gchar * root; - root = g_file_get_uri (parent); + root = g_file_get_uri (parent); - xed_file_browser_widget_set_root (data->tree_widget, - root, - TRUE); + xed_file_browser_widget_set_root (priv->tree_widget, + root, + TRUE); - g_object_unref (parent); - g_free (root); - } + g_object_unref (parent); + g_free (root); + } - g_object_unref (file); + g_object_unref (file); } static void -on_action_set_active_root (GtkAction * action, - XedFileBrowserPluginPrivate * data) +on_action_set_active_root (GtkAction *action, + XedFileBrowserPlugin *plugin) { - set_root_from_doc (data, xed_window_get_active_document (XED_WINDOW (data->window))); + set_root_from_doc (plugin, xed_window_get_active_document (XED_WINDOW (plugin->priv->window))); } static gchar * -get_terminal (XedFileBrowserPluginPrivate * data) +get_terminal (XedFileBrowserPlugin *plugin) { - // TODO : Identify the DE, find the preferred terminal application (xterminal shouldn't be hardcoded here, it should be set as default in the DE prefs) - return g_strdup ("xterminal"); + // TODO : Identify the DE, find the preferred terminal application (xterminal shouldn't be hardcoded here, it should be set as default in the DE prefs) + return g_strdup ("xterminal"); } static void -on_action_open_terminal (GtkAction * action, - XedFileBrowserPluginPrivate * data) +on_action_open_terminal (GtkAction *action, + XedFileBrowserPlugin *plugin) { - gchar * terminal; - gchar * wd = NULL; - gchar * local; - gchar * argv[2]; - GFile * file; + XedFileBrowserPluginPrivate *priv = plugin->priv; + gchar *terminal; + gchar *wd = NULL; + gchar *local; + gchar *argv[2]; + GFile *file; - GtkTreeIter iter; - XedFileBrowserStore * store; + GtkTreeIter iter; + XedFileBrowserStore *store; - /* Get the current directory */ - if (!xed_file_browser_widget_get_selected_directory (data->tree_widget, &iter)) - return; + /* Get the current directory */ + if (!xed_file_browser_widget_get_selected_directory (priv->tree_widget, &iter)) + { + return; + } - store = xed_file_browser_widget_get_browser_store (data->tree_widget); - gtk_tree_model_get (GTK_TREE_MODEL (store), - &iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, - &wd, - -1); + store = xed_file_browser_widget_get_browser_store (priv->tree_widget); + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, XED_FILE_BROWSER_STORE_COLUMN_URI, &wd, -1); - if (wd == NULL) - return; + if (wd == NULL) + { + return; + } - terminal = get_terminal (data); + terminal = get_terminal (plugin); - file = g_file_new_for_uri (wd); - local = g_file_get_path (file); - g_object_unref (file); + file = g_file_new_for_uri (wd); + local = g_file_get_path (file); + g_object_unref (file); - argv[0] = terminal; - argv[1] = NULL; + argv[0] = terminal; + argv[1] = NULL; - g_spawn_async (local, - argv, - NULL, - G_SPAWN_SEARCH_PATH, - NULL, - NULL, - NULL, - NULL); + g_spawn_async (local, + argv, + NULL, + G_SPAWN_SEARCH_PATH, + NULL, + NULL, + NULL, + NULL); - g_free (terminal); - g_free (wd); - g_free (local); + g_free (terminal); + g_free (wd); + g_free (local); } static void -on_selection_changed_cb (GtkTreeSelection *selection, - XedFileBrowserPluginPrivate *data) +on_selection_changed_cb (GtkTreeSelection *selection, + XedFileBrowserPlugin *plugin) { - GtkTreeView * tree_view; - GtkTreeModel * model; - GtkTreeIter iter; - gboolean sensitive; - gchar * uri; + XedFileBrowserPluginPrivate *priv = plugin->priv; + GtkTreeView *tree_view; + GtkTreeModel *model; + GtkTreeIter iter; + gboolean sensitive; + gchar *uri; - tree_view = GTK_TREE_VIEW (xed_file_browser_widget_get_browser_view (data->tree_widget)); - model = gtk_tree_view_get_model (tree_view); + tree_view = GTK_TREE_VIEW (xed_file_browser_widget_get_browser_view (priv->tree_widget)); + model = gtk_tree_view_get_model (tree_view); - if (!XED_IS_FILE_BROWSER_STORE (model)) - return; + if (!XED_IS_FILE_BROWSER_STORE (model)) + { + return; + } - sensitive = xed_file_browser_widget_get_selected_directory (data->tree_widget, &iter); + sensitive = xed_file_browser_widget_get_selected_directory (priv->tree_widget, &iter); - if (sensitive) { - gtk_tree_model_get (model, &iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, - &uri, -1); + if (sensitive) + { + gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, -1); - sensitive = xed_utils_uri_has_file_scheme (uri); - g_free (uri); - } + sensitive = xed_utils_uri_has_file_scheme (uri); + g_free (uri); + } - gtk_action_set_sensitive ( - gtk_action_group_get_action (data->single_selection_action_group, - "OpenTerminal"), - sensitive); + gtk_action_set_sensitive (gtk_action_group_get_action (priv->single_selection_action_group, "OpenTerminal"), sensitive); } #define POPUP_UI "" \ @@ -443,233 +448,200 @@ on_selection_changed_cb (GtkTreeSelection *selection, static GtkActionEntry extra_actions[] = { - {"SetActiveRoot", "go-jump-symbolic", N_("_Set root to active document"), - NULL, - N_("Set the root to the active document location"), - G_CALLBACK (on_action_set_active_root)} + {"SetActiveRoot", "go-jump-symbolic", N_("_Set root to active document"), + NULL, + N_("Set the root to the active document location"), + G_CALLBACK (on_action_set_active_root)} }; static GtkActionEntry extra_single_selection_actions[] = { - {"OpenTerminal", "utilities-terminal", N_("_Open terminal here"), - NULL, - N_("Open a terminal at the currently opened directory"), - G_CALLBACK (on_action_open_terminal)} + {"OpenTerminal", "utilities-terminal", N_("_Open terminal here"), + NULL, + N_("Open a terminal at the currently opened directory"), + G_CALLBACK (on_action_open_terminal)} }; static void -add_popup_ui (XedFileBrowserPluginPrivate *data) +add_popup_ui (XedFileBrowserPlugin *plugin) { - GtkUIManager * manager; - GtkActionGroup * action_group; - GError * error = NULL; + XedFileBrowserPluginPrivate *priv = plugin->priv; + GtkUIManager * manager; + GtkActionGroup * action_group; + GError * error = NULL; - manager = xed_file_browser_widget_get_ui_manager (data->tree_widget); + manager = xed_file_browser_widget_get_ui_manager (priv->tree_widget); - action_group = gtk_action_group_new ("FileBrowserPluginExtra"); - gtk_action_group_set_translation_domain (action_group, NULL); - gtk_action_group_add_actions (action_group, - extra_actions, - G_N_ELEMENTS (extra_actions), - data); - gtk_ui_manager_insert_action_group (manager, action_group, 0); - data->action_group = action_group; + action_group = gtk_action_group_new ("FileBrowserPluginExtra"); + gtk_action_group_set_translation_domain (action_group, NULL); + gtk_action_group_add_actions (action_group, + extra_actions, + G_N_ELEMENTS (extra_actions), + plugin); + gtk_ui_manager_insert_action_group (manager, action_group, 0); + priv->action_group = action_group; - action_group = gtk_action_group_new ("FileBrowserPluginSingleSelectionExtra"); - gtk_action_group_set_translation_domain (action_group, NULL); - gtk_action_group_add_actions (action_group, - extra_single_selection_actions, - G_N_ELEMENTS (extra_single_selection_actions), - data); - gtk_ui_manager_insert_action_group (manager, action_group, 0); - data->single_selection_action_group = action_group; + action_group = gtk_action_group_new ("FileBrowserPluginSingleSelectionExtra"); + gtk_action_group_set_translation_domain (action_group, NULL); + gtk_action_group_add_actions (action_group, + extra_single_selection_actions, + G_N_ELEMENTS (extra_single_selection_actions), + priv->window); + gtk_ui_manager_insert_action_group (manager, action_group, 0); + priv->single_selection_action_group = action_group; - data->merge_id = gtk_ui_manager_add_ui_from_string (manager, - POPUP_UI, - -1, - &error); + priv->merge_id = gtk_ui_manager_add_ui_from_string (manager, + POPUP_UI, + -1, + &error); - if (data->merge_id == 0) { - g_warning("Unable to merge UI: %s", error->message); - g_error_free(error); - } + if (priv->merge_id == 0) + { + g_warning("Unable to merge UI: %s", error->message); + g_error_free(error); + } } static void -remove_popup_ui (XedFileBrowserPluginPrivate *data) +remove_popup_ui (XedFileBrowserPlugin *plugin) { - GtkUIManager * manager; + XedFileBrowserPluginPrivate *priv = plugin->priv; + GtkUIManager * manager; - manager = xed_file_browser_widget_get_ui_manager (data->tree_widget); - gtk_ui_manager_remove_ui (manager, data->merge_id); + manager = xed_file_browser_widget_get_ui_manager (priv->tree_widget); + gtk_ui_manager_remove_ui (manager, priv->merge_id); - gtk_ui_manager_remove_action_group (manager, data->action_group); - g_object_unref (data->action_group); + gtk_ui_manager_remove_action_group (manager, priv->action_group); + g_object_unref (priv->action_group); - gtk_ui_manager_remove_action_group (manager, data->single_selection_action_group); - g_object_unref (data->single_selection_action_group); + gtk_ui_manager_remove_action_group (manager, priv->single_selection_action_group); + g_object_unref (priv->single_selection_action_group); } static void -xed_file_browser_plugin_update_state (PeasActivatable *activatable) +xed_file_browser_plugin_update_state (XedWindowActivatable *activatable) { - XedFileBrowserPluginPrivate *data; - XedDocument * doc; + XedFileBrowserPluginPrivate *priv = XED_FILE_BROWSER_PLUGIN (activatable)->priv; + XedDocument * doc; - data = XED_FILE_BROWSER_PLUGIN (activatable)->priv; + doc = xed_window_get_active_document (XED_WINDOW (priv->window)); - doc = xed_window_get_active_document (XED_WINDOW (data->window)); - - gtk_action_set_sensitive (gtk_action_group_get_action (data->action_group, - "SetActiveRoot"), - doc != NULL && - !xed_document_is_untitled (doc)); + gtk_action_set_sensitive (gtk_action_group_get_action (priv->action_group, + "SetActiveRoot"), + doc != NULL && !xed_document_is_untitled (doc)); } static void -xed_file_browser_plugin_activate (PeasActivatable *activatable) +xed_file_browser_plugin_activate (XedWindowActivatable *activatable) { - XedFileBrowserPluginPrivate *data; - XedWindow *window; - XedPanel * panel; - // GtkWidget * image; - // GdkPixbuf * pixbuf; - XedFileBrowserStore * store; - gchar *data_dir; - GSettingsSchemaSource *schema_source; - GSettingsSchema *schema; + XedFileBrowserPlugin *plugin = XED_FILE_BROWSER_PLUGIN (activatable); + XedFileBrowserPluginPrivate *priv; + XedPanel *panel; + XedFileBrowserStore *store; + gchar *data_dir; + GSettingsSchemaSource *schema_source; + GSettingsSchema *schema; - data = XED_FILE_BROWSER_PLUGIN (activatable)->priv; - window = XED_WINDOW (data->window); + priv = plugin->priv; - data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (activatable)); - data->tree_widget = XED_FILE_BROWSER_WIDGET (xed_file_browser_widget_new (data_dir)); - g_free (data_dir); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (activatable)); + priv->tree_widget = XED_FILE_BROWSER_WIDGET (xed_file_browser_widget_new (data_dir)); + g_free (data_dir); - data->settings = g_settings_new (FILE_BROWSER_SCHEMA); - data->onload_settings = g_settings_new (FILE_BROWSER_ONLOAD_SCHEMA); + priv->settings = g_settings_new (FILE_BROWSER_SCHEMA); + priv->onload_settings = g_settings_new (FILE_BROWSER_ONLOAD_SCHEMA); - g_signal_connect (data->tree_widget, - "uri-activated", - G_CALLBACK (on_uri_activated_cb), window); + g_signal_connect (priv->tree_widget, "uri-activated", + G_CALLBACK (on_uri_activated_cb), priv->window); - g_signal_connect (data->tree_widget, - "error", G_CALLBACK (on_error_cb), data); + g_signal_connect (priv->tree_widget, "error", + G_CALLBACK (on_error_cb), plugin); - g_signal_connect (data->tree_widget, - "notify::filter-pattern", - G_CALLBACK (on_filter_pattern_changed_cb), - data); + g_signal_connect (priv->tree_widget, "notify::filter-pattern", + G_CALLBACK (on_filter_pattern_changed_cb), plugin); - g_signal_connect (data->tree_widget, - "confirm-delete", - G_CALLBACK (on_confirm_delete_cb), - data); + g_signal_connect (priv->tree_widget, "confirm-delete", + G_CALLBACK (on_confirm_delete_cb), plugin); - g_signal_connect (data->tree_widget, - "confirm-no-trash", - G_CALLBACK (on_confirm_no_trash_cb), - window); + g_signal_connect (priv->tree_widget, "confirm-no-trash", + G_CALLBACK (on_confirm_no_trash_cb), priv->window); - g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW - (xed_file_browser_widget_get_browser_view - (data->tree_widget))), - "changed", - G_CALLBACK (on_selection_changed_cb), - data); + g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (xed_file_browser_widget_get_browser_view (priv->tree_widget))), + "changed", G_CALLBACK (on_selection_changed_cb), plugin); - panel = xed_window_get_side_panel (window); - // pixbuf = xed_file_browser_utils_pixbuf_from_theme("system-file-manager", - // GTK_ICON_SIZE_MENU); + panel = xed_window_get_side_panel (priv->window); + xed_panel_add_item (panel, GTK_WIDGET (priv->tree_widget), _("File Browser"), "system-file-manager"); + gtk_widget_show (GTK_WIDGET (priv->tree_widget)); - // if (pixbuf) { - // image = gtk_image_new_from_pixbuf(pixbuf); - // g_object_unref(pixbuf); - // } else { - // image = gtk_image_new_from_stock(GTK_STOCK_INDEX, GTK_ICON_SIZE_MENU); - // } + add_popup_ui (plugin); - // gtk_widget_show(image); - xed_panel_add_item (panel, GTK_WIDGET (data->tree_widget), _("File Browser"), "system-file-manager"); - gtk_widget_show (GTK_WIDGET (data->tree_widget)); + /* Restore filter options */ + restore_filter (plugin); - add_popup_ui (data); + /* Connect signals to store the last visited location */ + g_signal_connect (xed_file_browser_widget_get_browser_view (priv->tree_widget), "notify::model", + G_CALLBACK (on_model_set_cb), plugin); - /* Restore filter options */ - restore_filter (data); + store = xed_file_browser_widget_get_browser_store (priv->tree_widget); + g_signal_connect (store, "notify::virtual-root", + G_CALLBACK (on_virtual_root_changed_cb), plugin); - /* Connect signals to store the last visited location */ - g_signal_connect (xed_file_browser_widget_get_browser_view (data->tree_widget), - "notify::model", - G_CALLBACK (on_model_set_cb), - data); + g_signal_connect (store, "notify::filter-mode", + G_CALLBACK (on_filter_mode_changed_cb), plugin); - store = xed_file_browser_widget_get_browser_store (data->tree_widget); - g_signal_connect (store, - "notify::virtual-root", - G_CALLBACK (on_virtual_root_changed_cb), - data); + g_signal_connect (store, "rename", + G_CALLBACK (on_rename_cb), priv->window); - g_signal_connect (store, - "notify::filter-mode", - G_CALLBACK (on_filter_mode_changed_cb), - data); + g_signal_connect (priv->window, "tab-added", + G_CALLBACK (on_tab_added_cb), plugin); - g_signal_connect (store, - "rename", - G_CALLBACK (on_rename_cb), - window); + /* Register messages on the bus */ + xed_file_browser_messages_register (priv->window, priv->tree_widget); - g_signal_connect (window, - "tab-added", - G_CALLBACK (on_tab_added_cb), - data); - - /* Register messages on the bus */ - xed_file_browser_messages_register (window, data->tree_widget); - - xed_file_browser_plugin_update_state (activatable); + xed_file_browser_plugin_update_state (activatable); } static void -xed_file_browser_plugin_deactivate (PeasActivatable *activatable) +xed_file_browser_plugin_deactivate (XedWindowActivatable *activatable) { - XedFileBrowserPluginPrivate *data; - XedWindow *window; - XedPanel * panel; + XedFileBrowserPlugin *plugin = XED_FILE_BROWSER_PLUGIN (activatable); + XedFileBrowserPluginPrivate *priv = plugin->priv; + XedPanel * panel; - data = XED_FILE_BROWSER_PLUGIN (activatable)->priv; - window = XED_WINDOW (data->window); + /* Unregister messages from the bus */ + xed_file_browser_messages_unregister (priv->window); - /* Unregister messages from the bus */ - xed_file_browser_messages_unregister (window); + /* Disconnect signals */ + g_signal_handlers_disconnect_by_func (priv->window, G_CALLBACK (on_tab_added_cb), plugin); - /* Disconnect signals */ - g_signal_handlers_disconnect_by_func (window, - G_CALLBACK (on_tab_added_cb), - data); + g_object_unref (priv->settings); + g_object_unref (priv->onload_settings); - g_object_unref (data->settings); - g_object_unref (data->onload_settings); + remove_popup_ui (plugin); - remove_popup_ui (data); - - panel = xed_window_get_side_panel (window); - xed_panel_remove_item (panel, GTK_WIDGET (data->tree_widget)); + panel = xed_window_get_side_panel (priv->window); + xed_panel_remove_item (panel, GTK_WIDGET (priv->tree_widget)); } static void xed_file_browser_plugin_class_init (XedFileBrowserPluginClass * klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->dispose = xed_file_browser_plugin_dispose; + object_class->dispose = xed_file_browser_plugin_dispose; object_class->set_property = xed_file_browser_plugin_set_property; object_class->get_property = xed_file_browser_plugin_get_property; - g_object_class_override_property (object_class, PROP_OBJECT, "object"); + g_object_class_override_property (object_class, PROP_WINDOW, "window"); - g_type_class_add_private (object_class, - sizeof (XedFileBrowserPluginPrivate)); + g_type_class_add_private (object_class, sizeof (XedFileBrowserPluginPrivate)); +} + +static void +xed_window_activatable_iface_init (XedWindowActivatableInterface *iface) +{ + iface->activate = xed_file_browser_plugin_activate; + iface->deactivate = xed_file_browser_plugin_deactivate; + iface->update_state = xed_file_browser_plugin_update_state; } static void @@ -678,12 +650,365 @@ xed_file_browser_plugin_class_finalize (XedFileBrowserPluginClass *klass) /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ } +/* Callbacks */ static void -peas_activatable_iface_init (PeasActivatableInterface *iface) +on_uri_activated_cb (XedFileBrowserWidget *tree_widget, + gchar const *uri, + XedWindow *window) { - iface->activate = xed_file_browser_plugin_activate; - iface->deactivate = xed_file_browser_plugin_deactivate; - iface->update_state = xed_file_browser_plugin_update_state; + xed_commands_load_uri (window, uri, NULL, 0); +} + +static void +on_error_cb (XedFileBrowserWidget *tree_widget, + guint code, + gchar const *message, + XedFileBrowserPlugin *plugin) +{ + XedFileBrowserPluginPrivate *priv = plugin->priv; + gchar * title; + GtkWidget * dlg; + + /* Do not show the error when the root has been set automatically */ + if (priv->auto_root && (code == XED_FILE_BROWSER_ERROR_SET_ROOT || + code == XED_FILE_BROWSER_ERROR_LOAD_DIRECTORY)) + { + /* Show bookmarks */ + xed_file_browser_widget_show_bookmarks (priv->tree_widget); + return; + } + + switch (code) { + case XED_FILE_BROWSER_ERROR_NEW_DIRECTORY: + title = _("An error occurred while creating a new directory"); + break; + case XED_FILE_BROWSER_ERROR_NEW_FILE: + title = _("An error occurred while creating a new file"); + break; + case XED_FILE_BROWSER_ERROR_RENAME: + title = _("An error occurred while renaming a file or directory"); + break; + case XED_FILE_BROWSER_ERROR_DELETE: + title = _("An error occurred while deleting a file or directory"); + break; + case XED_FILE_BROWSER_ERROR_OPEN_DIRECTORY: + title = _("An error occurred while opening a directory in the file manager"); + break; + case XED_FILE_BROWSER_ERROR_SET_ROOT: + title = _("An error occurred while setting a root directory"); + break; + case XED_FILE_BROWSER_ERROR_LOAD_DIRECTORY: + title = _("An error occurred while loading a directory"); + break; + default: + title = _("An error occurred"); + break; + } + + dlg = gtk_message_dialog_new (GTK_WINDOW (priv->window), + GTK_DIALOG_MODAL | + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, + "%s", title); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg), "%s", message); + + gtk_dialog_run (GTK_DIALOG (dlg)); + gtk_widget_destroy (dlg); +} + +static void +on_model_set_cb (XedFileBrowserView *widget, + GParamSpec *arg1, + XedFileBrowserPlugin *plugin) +{ + XedFileBrowserPluginPrivate *priv = plugin->priv; + GtkTreeModel * model; + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (xed_file_browser_widget_get_browser_view (priv->tree_widget))); + + if (model == NULL) + { + return; + } + + g_settings_set_boolean (priv->onload_settings, "tree-view", XED_IS_FILE_BROWSER_STORE (model)); +} + +static void +on_filter_mode_changed_cb (XedFileBrowserStore *model, + GParamSpec *param, + XedFileBrowserPlugin *plugin) +{ + XedFileBrowserPluginPrivate *priv = plugin->priv; + XedFileBrowserStoreFilterMode mode; + + mode = xed_file_browser_store_get_filter_mode (model); + + if ((mode & XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN) && + (mode & XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY)) + { + g_settings_set_string (priv->settings, "filter-mode", "hidden_and_binary"); + } + else if (mode & XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN) + { + g_settings_set_string (priv->settings, "filter-mode", "hidden"); + } + else if (mode & XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY) + { + g_settings_set_string (priv->settings, "filter-mode", "binary"); + }else + { + g_settings_set_string (priv->settings, "filter-mode", "none"); + } +} + +static void +on_rename_cb (XedFileBrowserStore *store, + const gchar *olduri, + const gchar *newuri, + XedWindow *window) +{ + XedApp *app; + GList *documents; + GList *item; + XedDocument *doc; + GFile *docfile; + GFile *oldfile; + GFile *newfile; + gchar *uri; + + /* Find all documents and set its uri to newuri where it matches olduri */ + app = xed_app_get_default (); + documents = xed_app_get_documents (app); + + oldfile = g_file_new_for_uri (olduri); + newfile = g_file_new_for_uri (newuri); + + for (item = documents; item; item = item->next) + { + doc = XED_DOCUMENT (item->data); + uri = xed_document_get_uri (doc); + + if (!uri) + { + continue; + } + + docfile = g_file_new_for_uri (uri); + + if (g_file_equal (docfile, oldfile)) + { + xed_document_set_uri (doc, newuri); + } + else + { + gchar *relative; + + relative = g_file_get_relative_path (oldfile, docfile); + + if (relative) + { + /* relative now contains the part in docfile without + the prefix oldfile */ + + g_object_unref (docfile); + g_free (uri); + + docfile = g_file_get_child (newfile, relative); + uri = g_file_get_uri (docfile); + + xed_document_set_uri (doc, uri); + } + + g_free (relative); + } + + g_free (uri); + g_object_unref (docfile); + } + + g_object_unref (oldfile); + g_object_unref (newfile); + + g_list_free (documents); +} + +static void +on_filter_pattern_changed_cb (XedFileBrowserWidget *widget, + GParamSpec *param, + XedFileBrowserPlugin *plugin) +{ + XedFileBrowserPluginPrivate *priv = plugin->priv; + gchar * pattern; + + g_object_get (G_OBJECT (widget), "filter-pattern", &pattern, NULL); + + if (pattern == NULL) + { + g_settings_set_string (priv->settings, "filter-pattern", ""); + } + else + { + g_settings_set_string (priv->settings, "filter-pattern", pattern); + } + + g_free (pattern); +} + +static void +on_virtual_root_changed_cb (XedFileBrowserStore *store, + GParamSpec *param, + XedFileBrowserPlugin *plugin) +{ + XedFileBrowserPluginPrivate *priv = plugin->priv; + gchar * root; + gchar * virtual_root; + + root = xed_file_browser_store_get_root (store); + + if (!root) + { + return; + } + + g_settings_set_string (priv->onload_settings, "root", root); + + virtual_root = xed_file_browser_store_get_virtual_root (store); + + if (!virtual_root) + { + /* Set virtual to same as root then */ + g_settings_set_string (priv->onload_settings, "virtual-root", root); + } + else + { + g_settings_set_string (priv->onload_settings, "virtual-root", virtual_root); + } + + g_signal_handlers_disconnect_by_func (XED_WINDOW (priv->window), G_CALLBACK (on_tab_added_cb), plugin); + + g_free (root); + g_free (virtual_root); +} + +static void +on_tab_added_cb (XedWindow *window, + XedTab *tab, + XedFileBrowserPlugin *plugin) +{ + XedFileBrowserPluginPrivate *priv = plugin->priv; + gboolean open; + gboolean load_default = TRUE; + + open = g_settings_get_boolean (priv->settings, "open-at-first-doc"); + + if (open) + { + XedDocument *doc; + gchar *uri; + + doc = xed_tab_get_document (tab); + uri = xed_document_get_uri (doc); + + if (uri != NULL && xed_utils_uri_has_file_scheme (uri)) + { + prepare_auto_root (plugin); + set_root_from_doc (plugin, doc); + load_default = FALSE; + } + + g_free (uri); + } + + if (load_default) + restore_default_location (plugin); + + /* Disconnect this signal, it's only called once */ + g_signal_handlers_disconnect_by_func (window, G_CALLBACK (on_tab_added_cb), plugin); +} + +static gchar * +get_filename_from_path (GtkTreeModel *model, + GtkTreePath *path) +{ + GtkTreeIter iter; + gchar *uri; + + gtk_tree_model_get_iter (model, &iter, path); + gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, -1); + + return xed_file_browser_utils_uri_basename (uri); +} + +static gboolean +on_confirm_no_trash_cb (XedFileBrowserWidget *widget, + GList *files, + XedWindow *window) +{ + gchar *normal; + gchar *message; + gchar *secondary; + gboolean result; + + message = _("Cannot move file to trash, do you\nwant to delete permanently?"); + + if (files->next == NULL) + { + normal = xed_file_browser_utils_file_basename (G_FILE (files->data)); + secondary = g_strdup_printf (_("The file \"%s\" cannot be moved to the trash."), normal); + g_free (normal); + } + else + { + secondary = g_strdup (_("The selected files cannot be moved to the trash.")); + } + + result = xed_file_browser_utils_confirmation_dialog (window, + GTK_MESSAGE_QUESTION, + message, + secondary, + GTK_STOCK_DELETE, + NULL); + g_free (secondary); + + return result; +} + +static gboolean +on_confirm_delete_cb (XedFileBrowserWidget *widget, + XedFileBrowserStore *store, + GList *paths, + XedFileBrowserPlugin *plugin) +{ + XedFileBrowserPluginPrivate *priv = plugin->priv; + gchar *normal; + gchar *message; + gchar *secondary; + gboolean result; + + if (paths->next == NULL) + { + normal = get_filename_from_path (GTK_TREE_MODEL (store), (GtkTreePath *)(paths->data)); + message = g_strdup_printf (_("Are you sure you want to permanently delete \"%s\"?"), normal); + g_free (normal); + } + else + { + message = g_strdup (_("Are you sure you want to permanently delete the selected files?")); + } + + secondary = _("If you delete an item, it is permanently lost."); + + result = xed_file_browser_utils_confirmation_dialog (XED_WINDOW (priv->window), + GTK_MESSAGE_QUESTION, + message, + secondary, + GTK_STOCK_DELETE, + NULL); + + g_free (message); + + return result; } G_MODULE_EXPORT void @@ -692,345 +1017,8 @@ peas_register_types (PeasObjectModule *module) xed_file_browser_plugin_register_type (G_TYPE_MODULE (module)); peas_object_module_register_extension_type (module, - PEAS_TYPE_ACTIVATABLE, + XED_TYPE_WINDOW_ACTIVATABLE, XED_TYPE_FILE_BROWSER_PLUGIN); } -/* Callbacks */ -static void -on_uri_activated_cb (XedFileBrowserWidget * tree_widget, - gchar const *uri, XedWindow * window) -{ - xed_commands_load_uri (window, uri, NULL, 0); -} - -static void -on_error_cb (XedFileBrowserWidget * tree_widget, - guint code, gchar const *message, XedFileBrowserPluginPrivate * data) -{ - gchar * title; - GtkWidget * dlg; - - /* Do not show the error when the root has been set automatically */ - if (data->auto_root && (code == XED_FILE_BROWSER_ERROR_SET_ROOT || - code == XED_FILE_BROWSER_ERROR_LOAD_DIRECTORY)) - { - /* Show bookmarks */ - xed_file_browser_widget_show_bookmarks (data->tree_widget); - return; - } - - switch (code) { - case XED_FILE_BROWSER_ERROR_NEW_DIRECTORY: - title = - _("An error occurred while creating a new directory"); - break; - case XED_FILE_BROWSER_ERROR_NEW_FILE: - title = _("An error occurred while creating a new file"); - break; - case XED_FILE_BROWSER_ERROR_RENAME: - title = - _ - ("An error occurred while renaming a file or directory"); - break; - case XED_FILE_BROWSER_ERROR_DELETE: - title = - _ - ("An error occurred while deleting a file or directory"); - break; - case XED_FILE_BROWSER_ERROR_OPEN_DIRECTORY: - title = - _ - ("An error occurred while opening a directory in the file manager"); - break; - case XED_FILE_BROWSER_ERROR_SET_ROOT: - title = - _("An error occurred while setting a root directory"); - break; - case XED_FILE_BROWSER_ERROR_LOAD_DIRECTORY: - title = - _("An error occurred while loading a directory"); - break; - default: - title = _("An error occurred"); - break; - } - - dlg = gtk_message_dialog_new (GTK_WINDOW (data->window), - GTK_DIALOG_MODAL | - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, - "%s", title); - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg), - "%s", message); - - gtk_dialog_run (GTK_DIALOG (dlg)); - gtk_widget_destroy (dlg); -} - -static void -on_model_set_cb (XedFileBrowserView * widget, - GParamSpec *arg1, - XedFileBrowserPluginPrivate * data) -{ - GtkTreeModel * model; - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (xed_file_browser_widget_get_browser_view (data->tree_widget))); - - if (model == NULL) - return; - - g_settings_set_boolean (data->onload_settings, - "tree-view", - XED_IS_FILE_BROWSER_STORE (model)); -} - -static void -on_filter_mode_changed_cb (XedFileBrowserStore * model, - GParamSpec * param, - XedFileBrowserPluginPrivate * data) -{ - XedFileBrowserStoreFilterMode mode; - - mode = xed_file_browser_store_get_filter_mode (model); - - if ((mode & XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN) && - (mode & XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY)) { - g_settings_set_string (data->settings, "filter-mode", "hidden_and_binary"); - } else if (mode & XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN) { - g_settings_set_string (data->settings, "filter-mode", "hidden"); - } else if (mode & XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY) { - g_settings_set_string (data->settings, "filter-mode", "binary"); - } else { - g_settings_set_string (data->settings, "filter-mode", "none"); - } -} - -static void -on_rename_cb (XedFileBrowserStore * store, - const gchar * olduri, - const gchar * newuri, - XedWindow * window) -{ - XedApp * app; - GList * documents; - GList * item; - XedDocument * doc; - GFile * docfile; - GFile * oldfile; - GFile * newfile; - gchar * uri; - - /* Find all documents and set its uri to newuri where it matches olduri */ - app = xed_app_get_default (); - documents = xed_app_get_documents (app); - - oldfile = g_file_new_for_uri (olduri); - newfile = g_file_new_for_uri (newuri); - - for (item = documents; item; item = item->next) { - doc = XED_DOCUMENT (item->data); - uri = xed_document_get_uri (doc); - - if (!uri) - continue; - - docfile = g_file_new_for_uri (uri); - - if (g_file_equal (docfile, oldfile)) { - xed_document_set_uri (doc, newuri); - } else { - gchar *relative; - - relative = g_file_get_relative_path (oldfile, docfile); - - if (relative) { - /* relative now contains the part in docfile without - the prefix oldfile */ - - g_object_unref (docfile); - g_free (uri); - - docfile = g_file_get_child (newfile, relative); - uri = g_file_get_uri (docfile); - - xed_document_set_uri (doc, uri); - } - - g_free (relative); - } - - g_free (uri); - g_object_unref (docfile); - } - - g_object_unref (oldfile); - g_object_unref (newfile); - - g_list_free (documents); -} - -static void -on_filter_pattern_changed_cb (XedFileBrowserWidget * widget, - GParamSpec * param, - XedFileBrowserPluginPrivate * data) -{ - gchar * pattern; - - g_object_get (G_OBJECT (widget), "filter-pattern", &pattern, NULL); - - if (pattern == NULL) - g_settings_set_string (data->settings, "filter-pattern", ""); - else - g_settings_set_string (data->settings, "filter-pattern", pattern); - - g_free (pattern); -} - -static void -on_virtual_root_changed_cb (XedFileBrowserStore * store, - GParamSpec * param, - XedFileBrowserPluginPrivate * data) -{ - gchar * root; - gchar * virtual_root; - - root = xed_file_browser_store_get_root (store); - - if (!root) - return; - - g_settings_set_string (data->onload_settings, "root", root); - - virtual_root = xed_file_browser_store_get_virtual_root (store); - - if (!virtual_root) { - /* Set virtual to same as root then */ - g_settings_set_string (data->onload_settings, "virtual-root", root); - } else { - g_settings_set_string (data->onload_settings, "virtual-root", virtual_root); - } - - g_signal_handlers_disconnect_by_func (XED_WINDOW (data->window), - G_CALLBACK (on_tab_added_cb), - data); - - g_free (root); - g_free (virtual_root); -} - -static void -on_tab_added_cb (XedWindow * window, - XedTab * tab, - XedFileBrowserPluginPrivate *data) -{ - gboolean open; - gboolean load_default = TRUE; - - open = g_settings_get_boolean (data->settings, "open-at-first-doc"); - - if (open) { - XedDocument *doc; - gchar *uri; - - doc = xed_tab_get_document (tab); - - uri = xed_document_get_uri (doc); - - if (uri != NULL && xed_utils_uri_has_file_scheme (uri)) { - prepare_auto_root (data); - set_root_from_doc (data, doc); - load_default = FALSE; - } - - g_free (uri); - } - - if (load_default) - restore_default_location (data); - - /* Disconnect this signal, it's only called once */ - g_signal_handlers_disconnect_by_func (window, - G_CALLBACK (on_tab_added_cb), - data); -} - -static gchar * -get_filename_from_path (GtkTreeModel *model, GtkTreePath *path) -{ - GtkTreeIter iter; - gchar *uri; - - gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, - -1); - - return xed_file_browser_utils_uri_basename (uri); -} - -static gboolean -on_confirm_no_trash_cb (XedFileBrowserWidget * widget, - GList * files, - XedWindow * window) -{ - gchar *normal; - gchar *message; - gchar *secondary; - gboolean result; - - message = _("Cannot move file to trash, do you\nwant to delete permanently?"); - - if (files->next == NULL) { - normal = xed_file_browser_utils_file_basename (G_FILE (files->data)); - secondary = g_strdup_printf (_("The file \"%s\" cannot be moved to the trash."), normal); - g_free (normal); - } else { - secondary = g_strdup (_("The selected files cannot be moved to the trash.")); - } - - result = xed_file_browser_utils_confirmation_dialog (window, - GTK_MESSAGE_QUESTION, - message, - secondary, - GTK_STOCK_DELETE, - NULL); - g_free (secondary); - - return result; -} - -static gboolean -on_confirm_delete_cb (XedFileBrowserWidget *widget, - XedFileBrowserStore *store, - GList *paths, - XedFileBrowserPluginPrivate *data) -{ - gchar *normal; - gchar *message; - gchar *secondary; - gboolean result; - - if (paths->next == NULL) { - normal = get_filename_from_path (GTK_TREE_MODEL (store), (GtkTreePath *)(paths->data)); - message = g_strdup_printf (_("Are you sure you want to permanently delete \"%s\"?"), normal); - g_free (normal); - } else { - message = g_strdup (_("Are you sure you want to permanently delete the selected files?")); - } - - secondary = _("If you delete an item, it is permanently lost."); - - result = xed_file_browser_utils_confirmation_dialog (XED_WINDOW (data->window), - GTK_MESSAGE_QUESTION, - message, - secondary, - GTK_STOCK_DELETE, - NULL); - - g_free (message); - - return result; -} - // ex:ts=8:noet: diff --git a/plugins/filebrowser/xed-file-browser-plugin.h b/plugins/filebrowser/xed-file-browser-plugin.h index b6fed71..c4f0c03 100644 --- a/plugins/filebrowser/xed-file-browser-plugin.h +++ b/plugins/filebrowser/xed-file-browser-plugin.h @@ -33,7 +33,7 @@ G_BEGIN_DECLS * Type checking and casting macros */ #define XED_TYPE_FILE_BROWSER_PLUGIN (xed_file_browser_plugin_get_type ()) -#define XED_FILE_BROWSER_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPlugin)) +#define XED_FILE_BROWSER_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPlugin)) #define XED_FILE_BROWSER_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPluginClass)) #define XED_IS_FILE_BROWSER_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_FILE_BROWSER_PLUGIN)) #define XED_IS_FILE_BROWSER_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_FILE_BROWSER_PLUGIN)) @@ -65,7 +65,7 @@ struct _XedFileBrowserPluginClass GType xed_file_browser_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT void peas_register_types (PeasObjectModule * module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS #endif /* __XED_FILE_BROWSER_PLUGIN_H__ */ diff --git a/plugins/filebrowser/xed-file-browser-store.c b/plugins/filebrowser/xed-file-browser-store.c index f8965ab..dade6dc 100644 --- a/plugins/filebrowser/xed-file-browser-store.c +++ b/plugins/filebrowser/xed-file-browser-store.c @@ -35,196 +35,195 @@ #include "xed-file-browser-utils.h" #define XED_FILE_BROWSER_STORE_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), \ - XED_TYPE_FILE_BROWSER_STORE, \ - XedFileBrowserStorePrivate)) + XED_TYPE_FILE_BROWSER_STORE, \ + XedFileBrowserStorePrivate)) -#define NODE_IS_DIR(node) (FILE_IS_DIR((node)->flags)) -#define NODE_IS_HIDDEN(node) (FILE_IS_HIDDEN((node)->flags)) -#define NODE_IS_TEXT(node) (FILE_IS_TEXT((node)->flags)) -#define NODE_LOADED(node) (FILE_LOADED((node)->flags)) -#define NODE_IS_FILTERED(node) (FILE_IS_FILTERED((node)->flags)) -#define NODE_IS_DUMMY(node) (FILE_IS_DUMMY((node)->flags)) +#define NODE_IS_DIR(node) (FILE_IS_DIR((node)->flags)) +#define NODE_IS_HIDDEN(node) (FILE_IS_HIDDEN((node)->flags)) +#define NODE_IS_TEXT(node) (FILE_IS_TEXT((node)->flags)) +#define NODE_LOADED(node) (FILE_LOADED((node)->flags)) +#define NODE_IS_FILTERED(node) (FILE_IS_FILTERED((node)->flags)) +#define NODE_IS_DUMMY(node) (FILE_IS_DUMMY((node)->flags)) -#define FILE_BROWSER_NODE_DIR(node) ((FileBrowserNodeDir *)(node)) +#define FILE_BROWSER_NODE_DIR(node) ((FileBrowserNodeDir *)(node)) #define DIRECTORY_LOAD_ITEMS_PER_CALLBACK 100 #define STANDARD_ATTRIBUTE_TYPES G_FILE_ATTRIBUTE_STANDARD_TYPE "," \ - G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN "," \ - G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP "," \ - G_FILE_ATTRIBUTE_STANDARD_NAME "," \ - G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," \ - G_FILE_ATTRIBUTE_STANDARD_ICON + G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN "," \ + G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP "," \ + G_FILE_ATTRIBUTE_STANDARD_NAME "," \ + G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," \ + G_FILE_ATTRIBUTE_STANDARD_ICON typedef struct _FileBrowserNode FileBrowserNode; typedef struct _FileBrowserNodeDir FileBrowserNodeDir; -typedef struct _AsyncData AsyncData; -typedef struct _AsyncNode AsyncNode; +typedef struct _AsyncData AsyncData; +typedef struct _AsyncNode AsyncNode; -typedef gint (*SortFunc) (FileBrowserNode * node1, - FileBrowserNode * node2); +typedef gint (*SortFunc) (FileBrowserNode *node1, FileBrowserNode *node2); struct _AsyncData { - XedFileBrowserStore * model; - GCancellable * cancellable; - gboolean trash; - GList * files; - GList * iter; - gboolean removed; + XedFileBrowserStore *model; + GCancellable *cancellable; + gboolean trash; + GList *files; + GList *iter; + gboolean removed; }; struct _AsyncNode { - FileBrowserNodeDir *dir; - GCancellable *cancellable; - GSList *original_children; + FileBrowserNodeDir *dir; + GCancellable *cancellable; + GSList *original_children; }; typedef struct { - XedFileBrowserStore * model; - gchar * virtual_root; - GMountOperation * operation; - GCancellable * cancellable; + XedFileBrowserStore *model; + gchar *virtual_root; + GMountOperation *operation; + GCancellable *cancellable; } MountInfo; struct _FileBrowserNode { - GFile *file; - guint flags; - gchar *name; + GFile *file; + guint flags; + gchar *name; - GdkPixbuf *icon; - GdkPixbuf *emblem; + GdkPixbuf *icon; + GdkPixbuf *emblem; - FileBrowserNode *parent; - gint pos; - gboolean inserted; + FileBrowserNode *parent; + gint pos; + gboolean inserted; }; struct _FileBrowserNodeDir { - FileBrowserNode node; - GSList *children; - GHashTable *hidden_file_hash; + FileBrowserNode node; + GSList *children; + GHashTable *hidden_file_hash; - GCancellable *cancellable; - GFileMonitor *monitor; - XedFileBrowserStore *model; + GCancellable *cancellable; + GFileMonitor *monitor; + XedFileBrowserStore *model; }; struct _XedFileBrowserStorePrivate { - FileBrowserNode *root; - FileBrowserNode *virtual_root; - GType column_types[XED_FILE_BROWSER_STORE_COLUMN_NUM]; + FileBrowserNode *root; + FileBrowserNode *virtual_root; + GType column_types[XED_FILE_BROWSER_STORE_COLUMN_NUM]; - XedFileBrowserStoreFilterMode filter_mode; - XedFileBrowserStoreFilterFunc filter_func; - gpointer filter_user_data; + XedFileBrowserStoreFilterMode filter_mode; + XedFileBrowserStoreFilterFunc filter_func; + gpointer filter_user_data; - SortFunc sort_func; + SortFunc sort_func; - GSList *async_handles; - MountInfo *mount_info; + GSList *async_handles; + MountInfo *mount_info; }; -static FileBrowserNode *model_find_node (XedFileBrowserStore *model, - FileBrowserNode *node, - GFile *uri); -static void model_remove_node (XedFileBrowserStore * model, - FileBrowserNode * node, - GtkTreePath * path, - gboolean free_nodes); +static FileBrowserNode *model_find_node (XedFileBrowserStore *model, + FileBrowserNode *node, + GFile *uri); +static void model_remove_node (XedFileBrowserStore *model, + FileBrowserNode *node, + GtkTreePath *path, + gboolean free_nodes); -static void set_virtual_root_from_node (XedFileBrowserStore * model, - FileBrowserNode * node); +static void set_virtual_root_from_node (XedFileBrowserStore *model, + FileBrowserNode *node); -static void xed_file_browser_store_iface_init (GtkTreeModelIface * iface); -static GtkTreeModelFlags xed_file_browser_store_get_flags (GtkTreeModel * tree_model); -static gint xed_file_browser_store_get_n_columns (GtkTreeModel * tree_model); -static GType xed_file_browser_store_get_column_type (GtkTreeModel * tree_model, - gint index); -static gboolean xed_file_browser_store_get_iter (GtkTreeModel * tree_model, - GtkTreeIter * iter, - GtkTreePath * path); -static GtkTreePath *xed_file_browser_store_get_path (GtkTreeModel * tree_model, - GtkTreeIter * iter); -static void xed_file_browser_store_get_value (GtkTreeModel * tree_model, - GtkTreeIter * iter, - gint column, - GValue * value); -static gboolean xed_file_browser_store_iter_next (GtkTreeModel * tree_model, - GtkTreeIter * iter); -static gboolean xed_file_browser_store_iter_children (GtkTreeModel * tree_model, - GtkTreeIter * iter, - GtkTreeIter * parent); -static gboolean xed_file_browser_store_iter_has_child (GtkTreeModel * tree_model, - GtkTreeIter * iter); -static gint xed_file_browser_store_iter_n_children (GtkTreeModel * tree_model, - GtkTreeIter * iter); +static void xed_file_browser_store_iface_init (GtkTreeModelIface *iface); +static GtkTreeModelFlags xed_file_browser_store_get_flags (GtkTreeModel *tree_model); +static gint xed_file_browser_store_get_n_columns (GtkTreeModel *tree_model); +static GType xed_file_browser_store_get_column_type (GtkTreeModel *tree_model, + gint index); +static gboolean xed_file_browser_store_get_iter (GtkTreeModel *tree_model, + GtkTreeIter *iter, + GtkTreePath *path); +static GtkTreePath *xed_file_browser_store_get_path (GtkTreeModel *tree_model, + GtkTreeIter *iter); +static void xed_file_browser_store_get_value (GtkTreeModel *tree_model, + GtkTreeIter *iter, + gint column, + GValue *value); +static gboolean xed_file_browser_store_iter_next (GtkTreeModel *tree_model, + GtkTreeIter *iter); +static gboolean xed_file_browser_store_iter_children (GtkTreeModel *tree_model, + GtkTreeIter *iter, + GtkTreeIter *parent); +static gboolean xed_file_browser_store_iter_has_child (GtkTreeModel *tree_model, + GtkTreeIter *iter); +static gint xed_file_browser_store_iter_n_children (GtkTreeModel *tree_model, + GtkTreeIter * iter); static gboolean xed_file_browser_store_iter_nth_child (GtkTreeModel * tree_model, - GtkTreeIter * iter, - GtkTreeIter * parent, - gint n); + GtkTreeIter * iter, + GtkTreeIter * parent, + gint n); static gboolean xed_file_browser_store_iter_parent (GtkTreeModel * tree_model, - GtkTreeIter * iter, - GtkTreeIter * child); -static void xed_file_browser_store_row_inserted (GtkTreeModel * tree_model, - GtkTreePath * path, - GtkTreeIter * iter); + GtkTreeIter * iter, + GtkTreeIter * child); +static void xed_file_browser_store_row_inserted (GtkTreeModel * tree_model, + GtkTreePath * path, + GtkTreeIter * iter); static void xed_file_browser_store_drag_source_init (GtkTreeDragSourceIface * iface); static gboolean xed_file_browser_store_row_draggable (GtkTreeDragSource * drag_source, - GtkTreePath * path); + GtkTreePath * path); static gboolean xed_file_browser_store_drag_data_delete (GtkTreeDragSource * drag_source, - GtkTreePath * path); + GtkTreePath * path); static gboolean xed_file_browser_store_drag_data_get (GtkTreeDragSource * drag_source, - GtkTreePath * path, - GtkSelectionData * selection_data); + GtkTreePath * path, + GtkSelectionData * selection_data); static void file_browser_node_free (XedFileBrowserStore * model, - FileBrowserNode * node); + FileBrowserNode * node); static void model_add_node (XedFileBrowserStore * model, - FileBrowserNode * child, - FileBrowserNode * parent); + FileBrowserNode * child, + FileBrowserNode * parent); static void model_clear (XedFileBrowserStore * model, - gboolean free_nodes); + gboolean free_nodes); static gint model_sort_default (FileBrowserNode * node1, - FileBrowserNode * node2); + FileBrowserNode * node2); static void model_check_dummy (XedFileBrowserStore * model, - FileBrowserNode * node); -static void next_files_async (GFileEnumerator * enumerator, - AsyncNode * async); + FileBrowserNode * node); +static void next_files_async (GFileEnumerator * enumerator, + AsyncNode * async); G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedFileBrowserStore, xed_file_browser_store, - G_TYPE_OBJECT, - 0, - G_IMPLEMENT_INTERFACE_DYNAMIC (GTK_TYPE_TREE_MODEL, - xed_file_browser_store_iface_init) - G_IMPLEMENT_INTERFACE_DYNAMIC (GTK_TYPE_TREE_DRAG_SOURCE, - xed_file_browser_store_drag_source_init)) + G_TYPE_OBJECT, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (GTK_TYPE_TREE_MODEL, + xed_file_browser_store_iface_init) + G_IMPLEMENT_INTERFACE_DYNAMIC (GTK_TYPE_TREE_DRAG_SOURCE, + xed_file_browser_store_drag_source_init)) /* Properties */ enum { - PROP_0, + PROP_0, - PROP_ROOT, - PROP_VIRTUAL_ROOT, - PROP_FILTER_MODE + PROP_ROOT, + PROP_VIRTUAL_ROOT, + PROP_FILTER_MODE }; /* Signals */ enum { - BEGIN_LOADING, - END_LOADING, - ERROR, - NO_TRASH, - RENAME, - BEGIN_REFRESH, - END_REFRESH, - UNLOAD, - NUM_SIGNALS + BEGIN_LOADING, + END_LOADING, + ERROR, + NO_TRASH, + RENAME, + BEGIN_REFRESH, + END_REFRESH, + UNLOAD, + NUM_SIGNALS }; static guint model_signals[NUM_SIGNALS] = { 0 }; @@ -232,197 +231,200 @@ static guint model_signals[NUM_SIGNALS] = { 0 }; static void cancel_mount_operation (XedFileBrowserStore *obj) { - if (obj->priv->mount_info != NULL) - { - obj->priv->mount_info->model = NULL; - g_cancellable_cancel (obj->priv->mount_info->cancellable); - obj->priv->mount_info = NULL; - } + if (obj->priv->mount_info != NULL) + { + obj->priv->mount_info->model = NULL; + g_cancellable_cancel (obj->priv->mount_info->cancellable); + obj->priv->mount_info = NULL; + } } static void xed_file_browser_store_finalize (GObject * object) { - XedFileBrowserStore *obj = XED_FILE_BROWSER_STORE (object); - GSList *item; + XedFileBrowserStore *obj = XED_FILE_BROWSER_STORE (object); + GSList *item; - /* Free all the nodes */ - file_browser_node_free (obj, obj->priv->root); + /* Free all the nodes */ + file_browser_node_free (obj, obj->priv->root); - /* Cancel any asynchronous operations */ - for (item = obj->priv->async_handles; item; item = item->next) - { - AsyncData *data = (AsyncData *) (item->data); - g_cancellable_cancel (data->cancellable); + /* Cancel any asynchronous operations */ + for (item = obj->priv->async_handles; item; item = item->next) + { + AsyncData *data = (AsyncData *) (item->data); + g_cancellable_cancel (data->cancellable); - data->removed = TRUE; - } + data->removed = TRUE; + } - cancel_mount_operation (obj); + cancel_mount_operation (obj); - g_slist_free (obj->priv->async_handles); - G_OBJECT_CLASS (xed_file_browser_store_parent_class)->finalize (object); + g_slist_free (obj->priv->async_handles); + G_OBJECT_CLASS (xed_file_browser_store_parent_class)->finalize (object); } static void set_gvalue_from_node (GValue *value, FileBrowserNode *node) { - gchar * uri; + gchar * uri; - if (node == NULL || !node->file) { - g_value_set_string (value, NULL); - } else { - uri = g_file_get_uri (node->file); - g_value_take_string (value, uri); - } + if (node == NULL || !node->file) + { + g_value_set_string (value, NULL); + } + else + { + uri = g_file_get_uri (node->file); + g_value_take_string (value, uri); + } } static void xed_file_browser_store_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - XedFileBrowserStore *obj = XED_FILE_BROWSER_STORE (object); + XedFileBrowserStore *obj = XED_FILE_BROWSER_STORE (object); - switch (prop_id) - { - case PROP_ROOT: - set_gvalue_from_node (value, obj->priv->root); - break; - case PROP_VIRTUAL_ROOT: - set_gvalue_from_node (value, obj->priv->virtual_root); - break; - case PROP_FILTER_MODE: - g_value_set_flags (value, obj->priv->filter_mode); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_ROOT: + set_gvalue_from_node (value, obj->priv->root); + break; + case PROP_VIRTUAL_ROOT: + set_gvalue_from_node (value, obj->priv->virtual_root); + break; + case PROP_FILTER_MODE: + g_value_set_flags (value, obj->priv->filter_mode); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_file_browser_store_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - XedFileBrowserStore *obj = XED_FILE_BROWSER_STORE (object); + XedFileBrowserStore *obj = XED_FILE_BROWSER_STORE (object); - switch (prop_id) - { - case PROP_FILTER_MODE: - xed_file_browser_store_set_filter_mode (obj, - g_value_get_flags (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_FILTER_MODE: + xed_file_browser_store_set_filter_mode (obj, g_value_get_flags (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_file_browser_store_class_init (XedFileBrowserStoreClass * klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = xed_file_browser_store_finalize; + object_class->finalize = xed_file_browser_store_finalize; - object_class->get_property = xed_file_browser_store_get_property; - object_class->set_property = xed_file_browser_store_set_property; + object_class->get_property = xed_file_browser_store_get_property; + object_class->set_property = xed_file_browser_store_set_property; - g_object_class_install_property (object_class, PROP_ROOT, - g_param_spec_string ("root", - "Root", - "The root uri", - NULL, - G_PARAM_READABLE)); + g_object_class_install_property (object_class, PROP_ROOT, + g_param_spec_string ("root", + "Root", + "The root uri", + NULL, + G_PARAM_READABLE)); - g_object_class_install_property (object_class, PROP_VIRTUAL_ROOT, - g_param_spec_string ("virtual-root", - "Virtual Root", - "The virtual root uri", - NULL, - G_PARAM_READABLE)); + g_object_class_install_property (object_class, PROP_VIRTUAL_ROOT, + g_param_spec_string ("virtual-root", + "Virtual Root", + "The virtual root uri", + NULL, + G_PARAM_READABLE)); - g_object_class_install_property (object_class, PROP_FILTER_MODE, - g_param_spec_flags ("filter-mode", - "Filter Mode", - "The filter mode", - XED_TYPE_FILE_BROWSER_STORE_FILTER_MODE, - xed_file_browser_store_filter_mode_get_default (), - G_PARAM_READWRITE)); + g_object_class_install_property (object_class, PROP_FILTER_MODE, + g_param_spec_flags ("filter-mode", + "Filter Mode", + "The filter mode", + XED_TYPE_FILE_BROWSER_STORE_FILTER_MODE, + xed_file_browser_store_filter_mode_get_default (), + G_PARAM_READWRITE)); - model_signals[BEGIN_LOADING] = - g_signal_new ("begin-loading", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedFileBrowserStoreClass, - begin_loading), NULL, NULL, - g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, - GTK_TYPE_TREE_ITER); - model_signals[END_LOADING] = - g_signal_new ("end-loading", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedFileBrowserStoreClass, - end_loading), NULL, NULL, - g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, - GTK_TYPE_TREE_ITER); - model_signals[ERROR] = - g_signal_new ("error", G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedFileBrowserStoreClass, - error), NULL, NULL, - xed_file_browser_marshal_VOID__UINT_STRING, - G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING); - model_signals[NO_TRASH] = - g_signal_new ("no-trash", G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedFileBrowserStoreClass, - no_trash), g_signal_accumulator_true_handled, NULL, - xed_file_browser_marshal_BOOL__POINTER, - G_TYPE_BOOLEAN, 1, G_TYPE_POINTER); - model_signals[RENAME] = - g_signal_new ("rename", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedFileBrowserStoreClass, - rename), NULL, NULL, - xed_file_browser_marshal_VOID__STRING_STRING, - G_TYPE_NONE, 2, - G_TYPE_STRING, - G_TYPE_STRING); - model_signals[BEGIN_REFRESH] = - g_signal_new ("begin-refresh", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedFileBrowserStoreClass, - begin_refresh), NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - model_signals[END_REFRESH] = - g_signal_new ("end-refresh", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedFileBrowserStoreClass, - end_refresh), NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - model_signals[UNLOAD] = - g_signal_new ("unload", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedFileBrowserStoreClass, - unload), NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, - G_TYPE_STRING); + model_signals[BEGIN_LOADING] = + g_signal_new ("begin-loading", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedFileBrowserStoreClass, + begin_loading), NULL, NULL, + g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, + GTK_TYPE_TREE_ITER); + model_signals[END_LOADING] = + g_signal_new ("end-loading", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedFileBrowserStoreClass, + end_loading), NULL, NULL, + g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, + GTK_TYPE_TREE_ITER); + model_signals[ERROR] = + g_signal_new ("error", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedFileBrowserStoreClass, + error), NULL, NULL, + xed_file_browser_marshal_VOID__UINT_STRING, + G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING); + model_signals[NO_TRASH] = + g_signal_new ("no-trash", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedFileBrowserStoreClass, + no_trash), g_signal_accumulator_true_handled, NULL, + xed_file_browser_marshal_BOOL__POINTER, + G_TYPE_BOOLEAN, 1, G_TYPE_POINTER); + model_signals[RENAME] = + g_signal_new ("rename", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedFileBrowserStoreClass, + rename), NULL, NULL, + xed_file_browser_marshal_VOID__STRING_STRING, + G_TYPE_NONE, 2, + G_TYPE_STRING, + G_TYPE_STRING); + model_signals[BEGIN_REFRESH] = + g_signal_new ("begin-refresh", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedFileBrowserStoreClass, + begin_refresh), NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + model_signals[END_REFRESH] = + g_signal_new ("end-refresh", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedFileBrowserStoreClass, + end_refresh), NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + model_signals[UNLOAD] = + g_signal_new ("unload", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedFileBrowserStoreClass, + unload), NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, + G_TYPE_STRING); - g_type_class_add_private (object_class, - sizeof (XedFileBrowserStorePrivate)); + g_type_class_add_private (object_class, sizeof (XedFileBrowserStorePrivate)); } static void @@ -434,545 +436,602 @@ xed_file_browser_store_class_finalize (XedFileBrowserStoreClass *klass) static void xed_file_browser_store_iface_init (GtkTreeModelIface * iface) { - iface->get_flags = xed_file_browser_store_get_flags; - iface->get_n_columns = xed_file_browser_store_get_n_columns; - iface->get_column_type = xed_file_browser_store_get_column_type; - iface->get_iter = xed_file_browser_store_get_iter; - iface->get_path = xed_file_browser_store_get_path; - iface->get_value = xed_file_browser_store_get_value; - iface->iter_next = xed_file_browser_store_iter_next; - iface->iter_children = xed_file_browser_store_iter_children; - iface->iter_has_child = xed_file_browser_store_iter_has_child; - iface->iter_n_children = xed_file_browser_store_iter_n_children; - iface->iter_nth_child = xed_file_browser_store_iter_nth_child; - iface->iter_parent = xed_file_browser_store_iter_parent; - iface->row_inserted = xed_file_browser_store_row_inserted; + iface->get_flags = xed_file_browser_store_get_flags; + iface->get_n_columns = xed_file_browser_store_get_n_columns; + iface->get_column_type = xed_file_browser_store_get_column_type; + iface->get_iter = xed_file_browser_store_get_iter; + iface->get_path = xed_file_browser_store_get_path; + iface->get_value = xed_file_browser_store_get_value; + iface->iter_next = xed_file_browser_store_iter_next; + iface->iter_children = xed_file_browser_store_iter_children; + iface->iter_has_child = xed_file_browser_store_iter_has_child; + iface->iter_n_children = xed_file_browser_store_iter_n_children; + iface->iter_nth_child = xed_file_browser_store_iter_nth_child; + iface->iter_parent = xed_file_browser_store_iter_parent; + iface->row_inserted = xed_file_browser_store_row_inserted; } static void xed_file_browser_store_drag_source_init (GtkTreeDragSourceIface * iface) { - iface->row_draggable = xed_file_browser_store_row_draggable; - iface->drag_data_delete = xed_file_browser_store_drag_data_delete; - iface->drag_data_get = xed_file_browser_store_drag_data_get; + iface->row_draggable = xed_file_browser_store_row_draggable; + iface->drag_data_delete = xed_file_browser_store_drag_data_delete; + iface->drag_data_get = xed_file_browser_store_drag_data_get; } static void xed_file_browser_store_init (XedFileBrowserStore * obj) { - obj->priv = XED_FILE_BROWSER_STORE_GET_PRIVATE (obj); + obj->priv = XED_FILE_BROWSER_STORE_GET_PRIVATE (obj); - obj->priv->column_types[XED_FILE_BROWSER_STORE_COLUMN_URI] = - G_TYPE_STRING; - obj->priv->column_types[XED_FILE_BROWSER_STORE_COLUMN_NAME] = - G_TYPE_STRING; - obj->priv->column_types[XED_FILE_BROWSER_STORE_COLUMN_FLAGS] = - G_TYPE_UINT; - obj->priv->column_types[XED_FILE_BROWSER_STORE_COLUMN_ICON] = - GDK_TYPE_PIXBUF; - obj->priv->column_types[XED_FILE_BROWSER_STORE_COLUMN_EMBLEM] = - GDK_TYPE_PIXBUF; + obj->priv->column_types[XED_FILE_BROWSER_STORE_COLUMN_URI] = G_TYPE_STRING; + obj->priv->column_types[XED_FILE_BROWSER_STORE_COLUMN_NAME] = G_TYPE_STRING; + obj->priv->column_types[XED_FILE_BROWSER_STORE_COLUMN_FLAGS] = G_TYPE_UINT; + obj->priv->column_types[XED_FILE_BROWSER_STORE_COLUMN_ICON] = GDK_TYPE_PIXBUF; + obj->priv->column_types[XED_FILE_BROWSER_STORE_COLUMN_EMBLEM] = GDK_TYPE_PIXBUF; - // Default filter mode is hiding the hidden files - obj->priv->filter_mode = xed_file_browser_store_filter_mode_get_default (); - obj->priv->sort_func = model_sort_default; + // Default filter mode is hiding the hidden files + obj->priv->filter_mode = xed_file_browser_store_filter_mode_get_default (); + obj->priv->sort_func = model_sort_default; } static gboolean -node_has_parent (FileBrowserNode * node, FileBrowserNode * parent) +node_has_parent (FileBrowserNode *node, + FileBrowserNode *parent) { - if (node->parent == NULL) - return FALSE; + if (node->parent == NULL) + { + return FALSE; + } - if (node->parent == parent) - return TRUE; + if (node->parent == parent) + { + return TRUE; + } - return node_has_parent (node->parent, parent); + return node_has_parent (node->parent, parent); } static gboolean -node_in_tree (XedFileBrowserStore * model, FileBrowserNode * node) +node_in_tree (XedFileBrowserStore *model, + FileBrowserNode *node) { - return node_has_parent (node, model->priv->virtual_root); + return node_has_parent (node, model->priv->virtual_root); } static gboolean -model_node_visibility (XedFileBrowserStore * model, - FileBrowserNode * node) +model_node_visibility (XedFileBrowserStore *model, + FileBrowserNode *node) { - if (node == NULL) - return FALSE; + if (node == NULL) + { + return FALSE; + } - if (NODE_IS_DUMMY (node)) - return !NODE_IS_HIDDEN (node); + if (NODE_IS_DUMMY (node)) + { + return !NODE_IS_HIDDEN (node); + } - if (node == model->priv->virtual_root) - return TRUE; + if (node == model->priv->virtual_root) + { + return TRUE; + } - if (!node_has_parent (node, model->priv->virtual_root)) - return FALSE; + if (!node_has_parent (node, model->priv->virtual_root)) + { + return FALSE; + } - return !NODE_IS_FILTERED (node); + return !NODE_IS_FILTERED (node); } static gboolean -model_node_inserted (XedFileBrowserStore * model, - FileBrowserNode * node) +model_node_inserted (XedFileBrowserStore *model, + FileBrowserNode *node) { - return node == model->priv->virtual_root || (model_node_visibility (model, node) && node->inserted); + return node == model->priv->virtual_root || (model_node_visibility (model, node) && node->inserted); } /* Interface implementation */ static GtkTreeModelFlags -xed_file_browser_store_get_flags (GtkTreeModel * tree_model) +xed_file_browser_store_get_flags (GtkTreeModel *tree_model) { - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), - (GtkTreeModelFlags) 0); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), (GtkTreeModelFlags) 0); - return GTK_TREE_MODEL_ITERS_PERSIST; + return GTK_TREE_MODEL_ITERS_PERSIST; } static gint -xed_file_browser_store_get_n_columns (GtkTreeModel * tree_model) +xed_file_browser_store_get_n_columns (GtkTreeModel *tree_model) { - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), 0); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), 0); - return XED_FILE_BROWSER_STORE_COLUMN_NUM; + return XED_FILE_BROWSER_STORE_COLUMN_NUM; } static GType -xed_file_browser_store_get_column_type (GtkTreeModel * tree_model, gint idx) +xed_file_browser_store_get_column_type (GtkTreeModel *tree_model, + gint idx) { - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), - G_TYPE_INVALID); - g_return_val_if_fail (idx < XED_FILE_BROWSER_STORE_COLUMN_NUM && - idx >= 0, G_TYPE_INVALID); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), G_TYPE_INVALID); + g_return_val_if_fail (idx < XED_FILE_BROWSER_STORE_COLUMN_NUM && idx >= 0, G_TYPE_INVALID); - return XED_FILE_BROWSER_STORE (tree_model)->priv->column_types[idx]; + return XED_FILE_BROWSER_STORE (tree_model)->priv->column_types[idx]; } static gboolean -xed_file_browser_store_get_iter (GtkTreeModel * tree_model, - GtkTreeIter * iter, GtkTreePath * path) +xed_file_browser_store_get_iter (GtkTreeModel *tree_model, + GtkTreeIter *iter, + GtkTreePath *path) { - gint * indices, depth, i; - FileBrowserNode * node; - XedFileBrowserStore * model; - gint num; + gint *indices, depth, i; + FileBrowserNode *node; + XedFileBrowserStore *model; + gint num; - g_assert (XED_IS_FILE_BROWSER_STORE (tree_model)); - g_assert (path != NULL); + g_assert (XED_IS_FILE_BROWSER_STORE (tree_model)); + g_assert (path != NULL); - model = XED_FILE_BROWSER_STORE (tree_model); - indices = gtk_tree_path_get_indices (path); - depth = gtk_tree_path_get_depth (path); - node = model->priv->virtual_root; + model = XED_FILE_BROWSER_STORE (tree_model); + indices = gtk_tree_path_get_indices (path); + depth = gtk_tree_path_get_depth (path); + node = model->priv->virtual_root; - for (i = 0; i < depth; ++i) { - GSList * item; + for (i = 0; i < depth; ++i) + { + GSList * item; - if (node == NULL) - return FALSE; + if (node == NULL) + { + return FALSE; + } - num = 0; + num = 0; - if (!NODE_IS_DIR (node)) - return FALSE; + if (!NODE_IS_DIR (node)) + { + return FALSE; + } - for (item = FILE_BROWSER_NODE_DIR (node)->children; item; item = item->next) { - FileBrowserNode * child; + for (item = FILE_BROWSER_NODE_DIR (node)->children; item; item = item->next) + { + FileBrowserNode * child; - child = (FileBrowserNode *) (item->data); + child = (FileBrowserNode *) (item->data); - if (model_node_inserted (model, child)) { - if (num == indices[i]) { - node = child; - break; - } + if (model_node_inserted (model, child)) + { + if (num == indices[i]) + { + node = child; + break; + } - num++; - } - } + num++; + } + } - if (item == NULL) - return FALSE; + if (item == NULL) + { + return FALSE; + } - node = (FileBrowserNode *) (item->data); - } + node = (FileBrowserNode *) (item->data); + } - iter->user_data = node; - iter->user_data2 = NULL; - iter->user_data3 = NULL; + iter->user_data = node; + iter->user_data2 = NULL; + iter->user_data3 = NULL; - return node != NULL; + return node != NULL; } static GtkTreePath * -xed_file_browser_store_get_path_real (XedFileBrowserStore * model, - FileBrowserNode * node) +xed_file_browser_store_get_path_real (XedFileBrowserStore *model, + FileBrowserNode *node) { - GtkTreePath *path; - gint num = 0; + GtkTreePath *path; + gint num = 0; - path = gtk_tree_path_new (); + path = gtk_tree_path_new (); - while (node != model->priv->virtual_root) { - GSList *item; + while (node != model->priv->virtual_root) + { + GSList *item; - if (node->parent == NULL) { - gtk_tree_path_free (path); - return NULL; - } + if (node->parent == NULL) + { + gtk_tree_path_free (path); + return NULL; + } - num = 0; + num = 0; - for (item = FILE_BROWSER_NODE_DIR (node->parent)->children; item; item = item->next) { - FileBrowserNode *check; + for (item = FILE_BROWSER_NODE_DIR (node->parent)->children; item; item = item->next) + { + FileBrowserNode *check; - check = (FileBrowserNode *) (item->data); + check = (FileBrowserNode *) (item->data); - if (model_node_visibility (model, check) && (check == node || check->inserted)) { - if (check == node) { - gtk_tree_path_prepend_index (path, - num); - break; - } + if (model_node_visibility (model, check) && (check == node || check->inserted)) + { + if (check == node) + { + gtk_tree_path_prepend_index (path, num); + break; + } - ++num; - } else if (check == node) { - if (NODE_IS_DUMMY (node)) - g_warning ("Dummy not visible???"); + ++num; + } + else if (check == node) + { + if (NODE_IS_DUMMY (node)) + { + g_warning ("Dummy not visible???"); + } - gtk_tree_path_free (path); - return NULL; - } - } + gtk_tree_path_free (path); + return NULL; + } + } - node = node->parent; - } + node = node->parent; + } - return path; + return path; } static GtkTreePath * -xed_file_browser_store_get_path (GtkTreeModel * tree_model, - GtkTreeIter * iter) +xed_file_browser_store_get_path (GtkTreeModel *tree_model, + GtkTreeIter *iter) { - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), NULL); - g_return_val_if_fail (iter != NULL, NULL); - g_return_val_if_fail (iter->user_data != NULL, NULL); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), NULL); + g_return_val_if_fail (iter != NULL, NULL); + g_return_val_if_fail (iter->user_data != NULL, NULL); - return xed_file_browser_store_get_path_real (XED_FILE_BROWSER_STORE (tree_model), - (FileBrowserNode *) (iter->user_data)); + return xed_file_browser_store_get_path_real (XED_FILE_BROWSER_STORE (tree_model), + (FileBrowserNode *) (iter->user_data)); } static void -xed_file_browser_store_get_value (GtkTreeModel * tree_model, - GtkTreeIter * iter, - gint column, - GValue * value) +xed_file_browser_store_get_value (GtkTreeModel *tree_model, + GtkTreeIter *iter, + gint column, + GValue *value) { - FileBrowserNode *node; + FileBrowserNode *node; - g_return_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model)); - g_return_if_fail (iter != NULL); - g_return_if_fail (iter->user_data != NULL); + g_return_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model)); + g_return_if_fail (iter != NULL); + g_return_if_fail (iter->user_data != NULL); - node = (FileBrowserNode *) (iter->user_data); + node = (FileBrowserNode *) (iter->user_data); - g_value_init (value, XED_FILE_BROWSER_STORE (tree_model)->priv->column_types[column]); + g_value_init (value, XED_FILE_BROWSER_STORE (tree_model)->priv->column_types[column]); - switch (column) { - case XED_FILE_BROWSER_STORE_COLUMN_URI: - set_gvalue_from_node (value, node); - break; - case XED_FILE_BROWSER_STORE_COLUMN_NAME: - g_value_set_string (value, node->name); - break; - case XED_FILE_BROWSER_STORE_COLUMN_FLAGS: - g_value_set_uint (value, node->flags); - break; - case XED_FILE_BROWSER_STORE_COLUMN_ICON: - g_value_set_object (value, node->icon); - break; - case XED_FILE_BROWSER_STORE_COLUMN_EMBLEM: - g_value_set_object (value, node->emblem); - break; - default: - g_return_if_reached (); - } + switch (column) + { + case XED_FILE_BROWSER_STORE_COLUMN_URI: + set_gvalue_from_node (value, node); + break; + case XED_FILE_BROWSER_STORE_COLUMN_NAME: + g_value_set_string (value, node->name); + break; + case XED_FILE_BROWSER_STORE_COLUMN_FLAGS: + g_value_set_uint (value, node->flags); + break; + case XED_FILE_BROWSER_STORE_COLUMN_ICON: + g_value_set_object (value, node->icon); + break; + case XED_FILE_BROWSER_STORE_COLUMN_EMBLEM: + g_value_set_object (value, node->emblem); + break; + default: + g_return_if_reached (); + } } static gboolean -xed_file_browser_store_iter_next (GtkTreeModel * tree_model, - GtkTreeIter * iter) +xed_file_browser_store_iter_next (GtkTreeModel *tree_model, + GtkTreeIter *iter) { - XedFileBrowserStore * model; - FileBrowserNode * node; - GSList * item; - GSList * first; + XedFileBrowserStore *model; + FileBrowserNode *node; + GSList *item; + GSList *first; - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), - FALSE); - g_return_val_if_fail (iter != NULL, FALSE); - g_return_val_if_fail (iter->user_data != NULL, FALSE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), FALSE); + g_return_val_if_fail (iter != NULL, FALSE); + g_return_val_if_fail (iter->user_data != NULL, FALSE); - model = XED_FILE_BROWSER_STORE (tree_model); - node = (FileBrowserNode *) (iter->user_data); + model = XED_FILE_BROWSER_STORE (tree_model); + node = (FileBrowserNode *) (iter->user_data); - if (node->parent == NULL) - return FALSE; + if (node->parent == NULL) + { + return FALSE; + } - first = g_slist_next (g_slist_find (FILE_BROWSER_NODE_DIR (node->parent)->children, node)); + first = g_slist_next (g_slist_find (FILE_BROWSER_NODE_DIR (node->parent)->children, node)); - for (item = first; item; item = item->next) { - if (model_node_inserted (model, (FileBrowserNode *) (item->data))) { - iter->user_data = item->data; - return TRUE; - } - } + for (item = first; item; item = item->next) + { + if (model_node_inserted (model, (FileBrowserNode *) (item->data))) + { + iter->user_data = item->data; + return TRUE; + } + } - return FALSE; + return FALSE; } static gboolean -xed_file_browser_store_iter_children (GtkTreeModel * tree_model, - GtkTreeIter * iter, - GtkTreeIter * parent) +xed_file_browser_store_iter_children (GtkTreeModel *tree_model, + GtkTreeIter *iter, + GtkTreeIter *parent) { - FileBrowserNode * node; - XedFileBrowserStore * model; - GSList * item; + FileBrowserNode *node; + XedFileBrowserStore *model; + GSList *item; - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), - FALSE); - g_return_val_if_fail (parent == NULL - || parent->user_data != NULL, FALSE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), FALSE); + g_return_val_if_fail (parent == NULL || parent->user_data != NULL, FALSE); - model = XED_FILE_BROWSER_STORE (tree_model); + model = XED_FILE_BROWSER_STORE (tree_model); - if (parent == NULL) - node = model->priv->virtual_root; - else - node = (FileBrowserNode *) (parent->user_data); + if (parent == NULL) + { + node = model->priv->virtual_root; + } + else + { + node = (FileBrowserNode *) (parent->user_data); + } - if (node == NULL) - return FALSE; + if (node == NULL) + { + return FALSE; + } - if (!NODE_IS_DIR (node)) - return FALSE; + if (!NODE_IS_DIR (node)) + { + return FALSE; + } - for (item = FILE_BROWSER_NODE_DIR (node)->children; item; item = item->next) { - if (model_node_inserted (model, (FileBrowserNode *) (item->data))) { - iter->user_data = item->data; - return TRUE; - } - } + for (item = FILE_BROWSER_NODE_DIR (node)->children; item; item = item->next) + { + if (model_node_inserted (model, (FileBrowserNode *) (item->data))) + { + iter->user_data = item->data; + return TRUE; + } + } - return FALSE; + return FALSE; } static gboolean -filter_tree_model_iter_has_child_real (XedFileBrowserStore * model, - FileBrowserNode * node) +filter_tree_model_iter_has_child_real (XedFileBrowserStore *model, + FileBrowserNode *node) { - GSList *item; + GSList *item; - if (!NODE_IS_DIR (node)) - return FALSE; + if (!NODE_IS_DIR (node)) + { + return FALSE; + } - for (item = FILE_BROWSER_NODE_DIR (node)->children; item; item = item->next) { - if (model_node_inserted (model, (FileBrowserNode *) (item->data))) - return TRUE; - } + for (item = FILE_BROWSER_NODE_DIR (node)->children; item; item = item->next) + { + if (model_node_inserted (model, (FileBrowserNode *) (item->data))) + { + return TRUE; + } + } - return FALSE; + return FALSE; } static gboolean -xed_file_browser_store_iter_has_child (GtkTreeModel * tree_model, - GtkTreeIter * iter) +xed_file_browser_store_iter_has_child (GtkTreeModel *tree_model, + GtkTreeIter *iter) { - FileBrowserNode *node; - XedFileBrowserStore *model; + FileBrowserNode *node; + XedFileBrowserStore *model; - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), - FALSE); - g_return_val_if_fail (iter == NULL - || iter->user_data != NULL, FALSE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), FALSE); + g_return_val_if_fail (iter == NULL || iter->user_data != NULL, FALSE); - model = XED_FILE_BROWSER_STORE (tree_model); + model = XED_FILE_BROWSER_STORE (tree_model); - if (iter == NULL) - node = model->priv->virtual_root; - else - node = (FileBrowserNode *) (iter->user_data); + if (iter == NULL) + { + node = model->priv->virtual_root; + } + else + { + node = (FileBrowserNode *) (iter->user_data); + } - return filter_tree_model_iter_has_child_real (model, node); + return filter_tree_model_iter_has_child_real (model, node); } static gint -xed_file_browser_store_iter_n_children (GtkTreeModel * tree_model, - GtkTreeIter * iter) +xed_file_browser_store_iter_n_children (GtkTreeModel *tree_model, + GtkTreeIter *iter) { - FileBrowserNode *node; - XedFileBrowserStore *model; - GSList *item; - gint num = 0; + FileBrowserNode *node; + XedFileBrowserStore *model; + GSList *item; + gint num = 0; - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), - FALSE); - g_return_val_if_fail (iter == NULL - || iter->user_data != NULL, FALSE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), FALSE); + g_return_val_if_fail (iter == NULL || iter->user_data != NULL, FALSE); - model = XED_FILE_BROWSER_STORE (tree_model); + model = XED_FILE_BROWSER_STORE (tree_model); - if (iter == NULL) - node = model->priv->virtual_root; - else - node = (FileBrowserNode *) (iter->user_data); + if (iter == NULL) + { + node = model->priv->virtual_root; + } + else + { + node = (FileBrowserNode *) (iter->user_data); + } - if (!NODE_IS_DIR (node)) - return 0; + if (!NODE_IS_DIR (node)) + { + return 0; + } - for (item = FILE_BROWSER_NODE_DIR (node)->children; item; item = item->next) - if (model_node_inserted (model, (FileBrowserNode *) (item->data))) - ++num; + for (item = FILE_BROWSER_NODE_DIR (node)->children; item; item = item->next) + { + if (model_node_inserted (model, (FileBrowserNode *) (item->data))) + { + ++num; + } + } - return num; + return num; } static gboolean -xed_file_browser_store_iter_nth_child (GtkTreeModel * tree_model, - GtkTreeIter * iter, - GtkTreeIter * parent, gint n) +xed_file_browser_store_iter_nth_child (GtkTreeModel *tree_model, + GtkTreeIter *iter, + GtkTreeIter *parent, gint n) { - FileBrowserNode *node; - XedFileBrowserStore *model; - GSList *item; - gint num = 0; + FileBrowserNode *node; + XedFileBrowserStore *model; + GSList *item; + gint num = 0; - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), - FALSE); - g_return_val_if_fail (parent == NULL - || parent->user_data != NULL, FALSE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), FALSE); + g_return_val_if_fail (parent == NULL || parent->user_data != NULL, FALSE); - model = XED_FILE_BROWSER_STORE (tree_model); + model = XED_FILE_BROWSER_STORE (tree_model); - if (parent == NULL) - node = model->priv->virtual_root; - else - node = (FileBrowserNode *) (parent->user_data); + if (parent == NULL) + { + node = model->priv->virtual_root; + } + else + { + node = (FileBrowserNode *) (parent->user_data); + } - if (!NODE_IS_DIR (node)) - return FALSE; + if (!NODE_IS_DIR (node)) + { + return FALSE; + } - for (item = FILE_BROWSER_NODE_DIR (node)->children; item; - item = item->next) { - if (model_node_inserted (model, (FileBrowserNode *) (item->data))) { - if (num == n) { - iter->user_data = item->data; - return TRUE; - } + for (item = FILE_BROWSER_NODE_DIR (node)->children; item; item = item->next) + { + if (model_node_inserted (model, (FileBrowserNode *) (item->data))) + { + if (num == n) + { + iter->user_data = item->data; + return TRUE; + } - ++num; - } - } + ++num; + } + } - return FALSE; + return FALSE; } static gboolean -xed_file_browser_store_iter_parent (GtkTreeModel * tree_model, - GtkTreeIter * iter, - GtkTreeIter * child) +xed_file_browser_store_iter_parent (GtkTreeModel *tree_model, + GtkTreeIter *iter, + GtkTreeIter *child) { - FileBrowserNode *node; - XedFileBrowserStore *model; + FileBrowserNode *node; + XedFileBrowserStore *model; - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), FALSE); - g_return_val_if_fail (child != NULL, FALSE); - g_return_val_if_fail (child->user_data != NULL, FALSE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model), FALSE); + g_return_val_if_fail (child != NULL, FALSE); + g_return_val_if_fail (child->user_data != NULL, FALSE); - node = (FileBrowserNode *) (child->user_data); - model = XED_FILE_BROWSER_STORE (tree_model); + node = (FileBrowserNode *) (child->user_data); + model = XED_FILE_BROWSER_STORE (tree_model); - if (!node_in_tree (model, node)) - return FALSE; + if (!node_in_tree (model, node)) + { + return FALSE; + } - if (node->parent == NULL) - return FALSE; + if (node->parent == NULL) + { + return FALSE; + } - iter->user_data = node->parent; - return TRUE; + iter->user_data = node->parent; + return TRUE; } static void -xed_file_browser_store_row_inserted (GtkTreeModel * tree_model, - GtkTreePath * path, - GtkTreeIter * iter) +xed_file_browser_store_row_inserted (GtkTreeModel *tree_model, + GtkTreePath *path, + GtkTreeIter *iter) { - FileBrowserNode * node = (FileBrowserNode *)(iter->user_data); + FileBrowserNode * node = (FileBrowserNode *)(iter->user_data); - node->inserted = TRUE; + node->inserted = TRUE; } static gboolean -xed_file_browser_store_row_draggable (GtkTreeDragSource * drag_source, - GtkTreePath * path) +xed_file_browser_store_row_draggable (GtkTreeDragSource *drag_source, + GtkTreePath *path) { - GtkTreeIter iter; - XedFileBrowserStoreFlag flags; + GtkTreeIter iter; + XedFileBrowserStoreFlag flags; - if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (drag_source), - &iter, path)) - { - return FALSE; - } + if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (drag_source), &iter, path)) + { + return FALSE; + } - gtk_tree_model_get (GTK_TREE_MODEL (drag_source), &iter, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - -1); + gtk_tree_model_get (GTK_TREE_MODEL (drag_source), &iter, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, -1); - return !FILE_IS_DUMMY(flags); + return !FILE_IS_DUMMY(flags); } static gboolean -xed_file_browser_store_drag_data_delete (GtkTreeDragSource * drag_source, - GtkTreePath * path) +xed_file_browser_store_drag_data_delete (GtkTreeDragSource *drag_source, + GtkTreePath *path) { - return FALSE; + return FALSE; } static gboolean -xed_file_browser_store_drag_data_get (GtkTreeDragSource * drag_source, - GtkTreePath * path, - GtkSelectionData * selection_data) +xed_file_browser_store_drag_data_get (GtkTreeDragSource *drag_source, + GtkTreePath *path, + GtkSelectionData *selection_data) { - GtkTreeIter iter; - gchar *uri; - gchar *uris[2] = {0, }; - gboolean ret; + GtkTreeIter iter; + gchar *uri; + gchar *uris[2] = {0, }; + gboolean ret; - if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (drag_source), - &iter, path)) - { - return FALSE; - } + if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (drag_source), &iter, path)) + { + return FALSE; + } - gtk_tree_model_get (GTK_TREE_MODEL (drag_source), &iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, - -1); + gtk_tree_model_get (GTK_TREE_MODEL (drag_source), &iter, XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, -1); - g_assert (uri); + g_assert (uri); - uris[0] = uri; - ret = gtk_selection_data_set_uris (selection_data, uris); + uris[0] = uri; + ret = gtk_selection_data_set_uris (selection_data, uris); - g_free (uri); + g_free (uri); - return ret; + return ret; } #define FILTER_HIDDEN(mode) (mode & XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN) @@ -980,425 +1039,479 @@ xed_file_browser_store_drag_data_get (GtkTreeDragSource * drag_source, /* Private */ static void -model_begin_loading (XedFileBrowserStore * model, FileBrowserNode * node) +model_begin_loading (XedFileBrowserStore *model, + FileBrowserNode *node) { - GtkTreeIter iter; + GtkTreeIter iter; - iter.user_data = node; - g_signal_emit (model, model_signals[BEGIN_LOADING], 0, &iter); + iter.user_data = node; + g_signal_emit (model, model_signals[BEGIN_LOADING], 0, &iter); } static void -model_end_loading (XedFileBrowserStore * model, FileBrowserNode * node) +model_end_loading (XedFileBrowserStore *model, + FileBrowserNode *node) { - GtkTreeIter iter; + GtkTreeIter iter; - iter.user_data = node; - g_signal_emit (model, model_signals[END_LOADING], 0, &iter); + iter.user_data = node; + g_signal_emit (model, model_signals[END_LOADING], 0, &iter); } static void -model_node_update_visibility (XedFileBrowserStore * model, - FileBrowserNode * node) +model_node_update_visibility (XedFileBrowserStore *model, + FileBrowserNode *node) { - GtkTreeIter iter; + GtkTreeIter iter; - node->flags &= ~XED_FILE_BROWSER_STORE_FLAG_IS_FILTERED; + node->flags &= ~XED_FILE_BROWSER_STORE_FLAG_IS_FILTERED; - if (FILTER_HIDDEN (model->priv->filter_mode) && - NODE_IS_HIDDEN (node)) - node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_FILTERED; - else if (FILTER_BINARY (model->priv->filter_mode) && - (!NODE_IS_TEXT (node) && !NODE_IS_DIR (node))) - node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_FILTERED; - else if (model->priv->filter_func) { - iter.user_data = node; + if (FILTER_HIDDEN (model->priv->filter_mode) && NODE_IS_HIDDEN (node)) + { + node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_FILTERED; + } + else if (FILTER_BINARY (model->priv->filter_mode) && (!NODE_IS_TEXT (node) && !NODE_IS_DIR (node))) + { + node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_FILTERED; + } + else if (model->priv->filter_func) + { + iter.user_data = node; - if (!model->priv-> - filter_func (model, &iter, - model->priv->filter_user_data)) - node->flags |= - XED_FILE_BROWSER_STORE_FLAG_IS_FILTERED; - } + if (!model->priv->filter_func (model, &iter, model->priv->filter_user_data)) + { + node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_FILTERED; + } + } } static gint -collate_nodes (FileBrowserNode * node1, FileBrowserNode * node2) +collate_nodes (FileBrowserNode *node1, + FileBrowserNode *node2) { - if (node1->name == NULL) - return -1; - else if (node2->name == NULL) - return 1; - else { - gchar *k1, *k2; - gint result; + if (node1->name == NULL) + { + return -1; + } + else if (node2->name == NULL) + { + return 1; + } + else + { + gchar *k1, *k2; + gint result; - k1 = g_utf8_collate_key_for_filename (node1->name, -1); - k2 = g_utf8_collate_key_for_filename (node2->name, -1); + k1 = g_utf8_collate_key_for_filename (node1->name, -1); + k2 = g_utf8_collate_key_for_filename (node2->name, -1); - result = strcmp (k1, k2); + result = strcmp (k1, k2); - g_free (k1); - g_free (k2); + g_free (k1); + g_free (k2); - return result; - } + return result; + } } static gint -model_sort_default (FileBrowserNode * node1, FileBrowserNode * node2) +model_sort_default (FileBrowserNode *node1, + FileBrowserNode *node2) { - gint f1; - gint f2; + gint f1; + gint f2; - f1 = NODE_IS_DUMMY (node1); - f2 = NODE_IS_DUMMY (node2); + f1 = NODE_IS_DUMMY (node1); + f2 = NODE_IS_DUMMY (node2); - if (f1 && f2) - { - return 0; - } - else if (f1 || f2) - { - return f1 ? -1 : 1; - } + if (f1 && f2) + { + return 0; + } + else if (f1 || f2) + { + return f1 ? -1 : 1; + } - f1 = NODE_IS_DIR (node1); - f2 = NODE_IS_DIR (node2); + f1 = NODE_IS_DIR (node1); + f2 = NODE_IS_DIR (node2); - if (f1 != f2) - { - return f1 ? -1 : 1; - } + if (f1 != f2) + { + return f1 ? -1 : 1; + } - f1 = NODE_IS_HIDDEN (node1); - f2 = NODE_IS_HIDDEN (node2); + f1 = NODE_IS_HIDDEN (node1); + f2 = NODE_IS_HIDDEN (node2); - if (f1 != f2) - { - return f2 ? -1 : 1; - } + if (f1 != f2) + { + return f2 ? -1 : 1; + } - return collate_nodes (node1, node2); + return collate_nodes (node1, node2); } static void -model_resort_node (XedFileBrowserStore * model, FileBrowserNode * node) +model_resort_node (XedFileBrowserStore *model, + FileBrowserNode *node) { - FileBrowserNodeDir *dir; - GSList *item; - FileBrowserNode *child; - gint pos = 0; - GtkTreeIter iter; - GtkTreePath *path; - gint *neworder; + FileBrowserNodeDir *dir; + GSList *item; + FileBrowserNode *child; + gint pos = 0; + GtkTreeIter iter; + GtkTreePath *path; + gint *neworder; - dir = FILE_BROWSER_NODE_DIR (node->parent); + dir = FILE_BROWSER_NODE_DIR (node->parent); - if (!model_node_visibility (model, node->parent)) { - /* Just sort the children of the parent */ - dir->children = g_slist_sort (dir->children, - (GCompareFunc) (model->priv-> - sort_func)); - } else { - /* Store current positions */ - for (item = dir->children; item; item = item->next) { - child = (FileBrowserNode *) (item->data); + if (!model_node_visibility (model, node->parent)) + { + /* Just sort the children of the parent */ + dir->children = g_slist_sort (dir->children, (GCompareFunc) (model->priv->sort_func)); + } + else + { + /* Store current positions */ + for (item = dir->children; item; item = item->next) + { + child = (FileBrowserNode *) (item->data); - if (model_node_visibility (model, child)) - child->pos = pos++; - } + if (model_node_visibility (model, child)) + { + child->pos = pos++; + } + } - dir->children = g_slist_sort (dir->children, - (GCompareFunc) (model->priv-> - sort_func)); - neworder = g_new (gint, pos); - pos = 0; + dir->children = g_slist_sort (dir->children, (GCompareFunc) (model->priv->sort_func)); + neworder = g_new (gint, pos); + pos = 0; - /* Store the new positions */ - for (item = dir->children; item; item = item->next) { - child = (FileBrowserNode *) (item->data); + /* Store the new positions */ + for (item = dir->children; item; item = item->next) + { + child = (FileBrowserNode *) (item->data); - if (model_node_visibility (model, child)) - neworder[pos++] = child->pos; - } + if (model_node_visibility (model, child)) + { + neworder[pos++] = child->pos; + } + } - iter.user_data = node->parent; - path = - xed_file_browser_store_get_path_real (model, - node->parent); + iter.user_data = node->parent; + path = xed_file_browser_store_get_path_real (model, node->parent); - gtk_tree_model_rows_reordered (GTK_TREE_MODEL (model), - path, &iter, neworder); + gtk_tree_model_rows_reordered (GTK_TREE_MODEL (model), path, &iter, neworder); - g_free (neworder); - gtk_tree_path_free (path); - } + g_free (neworder); + gtk_tree_path_free (path); + } } static void -row_changed (XedFileBrowserStore * model, - GtkTreePath ** path, - GtkTreeIter * iter) +row_changed (XedFileBrowserStore *model, + GtkTreePath **path, + GtkTreeIter *iter) { - GtkTreeRowReference *ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (model), *path); + GtkTreeRowReference *ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (model), *path); - /* Insert a copy of the actual path here because the row-inserted - signal may alter the path */ - gtk_tree_model_row_changed (GTK_TREE_MODEL(model), *path, iter); - gtk_tree_path_free (*path); + /* Insert a copy of the actual path here because the row-inserted + signal may alter the path */ + gtk_tree_model_row_changed (GTK_TREE_MODEL(model), *path, iter); + gtk_tree_path_free (*path); - *path = gtk_tree_row_reference_get_path (ref); - gtk_tree_row_reference_free (ref); + *path = gtk_tree_row_reference_get_path (ref); + gtk_tree_row_reference_free (ref); } static void -row_inserted (XedFileBrowserStore * model, - GtkTreePath ** path, - GtkTreeIter * iter) +row_inserted (XedFileBrowserStore *model, + GtkTreePath **path, + GtkTreeIter *iter) { - /* This function creates a row reference for the path because it's - uncertain what might change the actual model/view when we insert - a node, maybe another directory load is triggered for example. - Because functions that use this function rely on the notion that - the path remains pointed towards the inserted node, we use the - reference to keep track. */ - GtkTreeRowReference *ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (model), *path); - GtkTreePath * copy = gtk_tree_path_copy (*path); + /* This function creates a row reference for the path because it's + uncertain what might change the actual model/view when we insert + a node, maybe another directory load is triggered for example. + Because functions that use this function rely on the notion that + the path remains pointed towards the inserted node, we use the + reference to keep track. */ + GtkTreeRowReference *ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (model), *path); + GtkTreePath * copy = gtk_tree_path_copy (*path); - gtk_tree_model_row_inserted (GTK_TREE_MODEL(model), copy, iter); - gtk_tree_path_free (copy); + gtk_tree_model_row_inserted (GTK_TREE_MODEL(model), copy, iter); + gtk_tree_path_free (copy); - if (ref) - { - gtk_tree_path_free (*path); + if (ref) + { + gtk_tree_path_free (*path); - /* To restore the path, we get the path from the reference. But, since - we inserted a row, the path will be one index further than the - actual path of our node. We therefore call gtk_tree_path_prev */ - *path = gtk_tree_row_reference_get_path (ref); - gtk_tree_path_prev (*path); - } + /* To restore the path, we get the path from the reference. But, since + we inserted a row, the path will be one index further than the + actual path of our node. We therefore call gtk_tree_path_prev */ + *path = gtk_tree_row_reference_get_path (ref); + gtk_tree_path_prev (*path); + } - gtk_tree_row_reference_free (ref); + gtk_tree_row_reference_free (ref); } static void -row_deleted (XedFileBrowserStore * model, - const GtkTreePath * path) +row_deleted (XedFileBrowserStore *model, + const GtkTreePath *path) { - GtkTreePath *copy = gtk_tree_path_copy (path); + GtkTreePath *copy = gtk_tree_path_copy (path); - /* Delete a copy of the actual path here because the row-deleted - signal may alter the path */ - gtk_tree_model_row_deleted (GTK_TREE_MODEL(model), copy); - gtk_tree_path_free (copy); + /* Delete a copy of the actual path here because the row-deleted + signal may alter the path */ + gtk_tree_model_row_deleted (GTK_TREE_MODEL(model), copy); + gtk_tree_path_free (copy); } static void -model_refilter_node (XedFileBrowserStore * model, - FileBrowserNode * node, - GtkTreePath ** path) +model_refilter_node (XedFileBrowserStore *model, + FileBrowserNode *node, + GtkTreePath **path) { - gboolean old_visible; - gboolean new_visible; - FileBrowserNodeDir *dir; - GSList *item; - GtkTreeIter iter; - GtkTreePath *tmppath = NULL; - gboolean in_tree; + gboolean old_visible; + gboolean new_visible; + FileBrowserNodeDir *dir; + GSList *item; + GtkTreeIter iter; + GtkTreePath *tmppath = NULL; + gboolean in_tree; - if (node == NULL) - return; + if (node == NULL) + { + return; + } - old_visible = model_node_visibility (model, node); - model_node_update_visibility (model, node); + old_visible = model_node_visibility (model, node); + model_node_update_visibility (model, node); - in_tree = node_in_tree (model, node); + in_tree = node_in_tree (model, node); - if (path == NULL) - { - if (in_tree) - tmppath = xed_file_browser_store_get_path_real (model, - node); - else - tmppath = gtk_tree_path_new_first (); + if (path == NULL) + { + if (in_tree) + { + tmppath = xed_file_browser_store_get_path_real (model, node); + } + else + { + tmppath = gtk_tree_path_new_first (); + } - path = &tmppath; - } + path = &tmppath; + } - if (NODE_IS_DIR (node)) { - if (in_tree) - gtk_tree_path_down (*path); + if (NODE_IS_DIR (node)) + { + if (in_tree) + { + gtk_tree_path_down (*path); + } - dir = FILE_BROWSER_NODE_DIR (node); + dir = FILE_BROWSER_NODE_DIR (node); - for (item = dir->children; item; item = item->next) { - model_refilter_node (model, - (FileBrowserNode *) (item->data), - path); - } + for (item = dir->children; item; item = item->next) + { + model_refilter_node (model, (FileBrowserNode *) (item->data), path); + } - if (in_tree) - gtk_tree_path_up (*path); - } + if (in_tree) + { + gtk_tree_path_up (*path); + } + } - if (in_tree) { - new_visible = model_node_visibility (model, node); + if (in_tree) + { + new_visible = model_node_visibility (model, node); - if (old_visible != new_visible) { - if (old_visible) { - node->inserted = FALSE; - row_deleted (model, *path); - } else { - iter.user_data = node; - row_inserted (model, path, &iter); - gtk_tree_path_next (*path); - } - } else if (old_visible) { - gtk_tree_path_next (*path); - } - } + if (old_visible != new_visible) + { + if (old_visible) + { + node->inserted = FALSE; + row_deleted (model, *path); + } + else + { + iter.user_data = node; + row_inserted (model, path, &iter); + gtk_tree_path_next (*path); + } + } + else if (old_visible) + { + gtk_tree_path_next (*path); + } + } - model_check_dummy (model, node); + model_check_dummy (model, node); - if (tmppath) - gtk_tree_path_free (tmppath); + if (tmppath) + { + gtk_tree_path_free (tmppath); + } } static void -model_refilter (XedFileBrowserStore * model) +model_refilter (XedFileBrowserStore *model) { - model_refilter_node (model, model->priv->root, NULL); + model_refilter_node (model, model->priv->root, NULL); } static void -file_browser_node_set_name (FileBrowserNode * node) +file_browser_node_set_name (FileBrowserNode *node) { - g_free (node->name); + g_free (node->name); - if (node->file) { - node->name = xed_file_browser_utils_file_basename (node->file); - } else { - node->name = NULL; - } + if (node->file) + { + node->name = xed_file_browser_utils_file_basename (node->file); + } + else + { + node->name = NULL; + } } static void -file_browser_node_init (FileBrowserNode * node, GFile * file, - FileBrowserNode * parent) +file_browser_node_init (FileBrowserNode *node, + GFile *file, + FileBrowserNode *parent) { - if (file != NULL) { - node->file = g_object_ref (file); - file_browser_node_set_name (node); - } + if (file != NULL) + { + node->file = g_object_ref (file); + file_browser_node_set_name (node); + } - node->parent = parent; + node->parent = parent; } static FileBrowserNode * -file_browser_node_new (GFile * file, FileBrowserNode * parent) +file_browser_node_new (GFile *file, + FileBrowserNode *parent) { - FileBrowserNode *node = g_slice_new0 (FileBrowserNode); + FileBrowserNode *node = g_slice_new0 (FileBrowserNode); - file_browser_node_init (node, file, parent); - return node; + file_browser_node_init (node, file, parent); + return node; } static FileBrowserNode * -file_browser_node_dir_new (XedFileBrowserStore * model, - GFile * file, FileBrowserNode * parent) +file_browser_node_dir_new (XedFileBrowserStore *model, + GFile *file, + FileBrowserNode *parent) { - FileBrowserNode *node = - (FileBrowserNode *) g_slice_new0 (FileBrowserNodeDir); + FileBrowserNode *node = (FileBrowserNode *) g_slice_new0 (FileBrowserNodeDir); - file_browser_node_init (node, file, parent); + file_browser_node_init (node, file, parent); - node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY; + node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY; - FILE_BROWSER_NODE_DIR (node)->model = model; + FILE_BROWSER_NODE_DIR (node)->model = model; - return node; + return node; } static void -file_browser_node_free_children (XedFileBrowserStore * model, - FileBrowserNode * node) +file_browser_node_free_children (XedFileBrowserStore *model, + FileBrowserNode *node) { - GSList *item; + GSList *item; - if (node == NULL) - return; + if (node == NULL) + { + return; + } - if (NODE_IS_DIR (node)) { - for (item = FILE_BROWSER_NODE_DIR (node)->children; item; - item = item->next) - file_browser_node_free (model, - (FileBrowserNode *) (item-> - data)); + if (NODE_IS_DIR (node)) + { + for (item = FILE_BROWSER_NODE_DIR (node)->children; item; item = item->next) + { + file_browser_node_free (model, (FileBrowserNode *) (item->data)); + } - g_slist_free (FILE_BROWSER_NODE_DIR (node)->children); - FILE_BROWSER_NODE_DIR (node)->children = NULL; + g_slist_free (FILE_BROWSER_NODE_DIR (node)->children); + FILE_BROWSER_NODE_DIR (node)->children = NULL; - /* This node is no longer loaded */ - node->flags &= ~XED_FILE_BROWSER_STORE_FLAG_LOADED; - } + /* This node is no longer loaded */ + node->flags &= ~XED_FILE_BROWSER_STORE_FLAG_LOADED; + } } static void -file_browser_node_free (XedFileBrowserStore * model, - FileBrowserNode * node) +file_browser_node_free (XedFileBrowserStore *model, + FileBrowserNode *node) { - gchar *uri; + gchar *uri; - if (node == NULL) - return; + if (node == NULL) + { + return; + } - if (NODE_IS_DIR (node)) - { - FileBrowserNodeDir *dir; + if (NODE_IS_DIR (node)) + { + FileBrowserNodeDir *dir; - dir = FILE_BROWSER_NODE_DIR (node); + dir = FILE_BROWSER_NODE_DIR (node); - if (dir->cancellable) { - g_cancellable_cancel (dir->cancellable); - g_object_unref (dir->cancellable); + if (dir->cancellable) + { + g_cancellable_cancel (dir->cancellable); + g_object_unref (dir->cancellable); - model_end_loading (model, node); - } + model_end_loading (model, node); + } - file_browser_node_free_children (model, node); + file_browser_node_free_children (model, node); - if (dir->monitor) { - g_file_monitor_cancel (dir->monitor); - g_object_unref (dir->monitor); - } + if (dir->monitor) + { + g_file_monitor_cancel (dir->monitor); + g_object_unref (dir->monitor); + } - if (dir->hidden_file_hash) - g_hash_table_destroy (dir->hidden_file_hash); - } + if (dir->hidden_file_hash) + { + g_hash_table_destroy (dir->hidden_file_hash); + } + } - if (node->file) - { - uri = g_file_get_uri (node->file); - g_signal_emit (model, model_signals[UNLOAD], 0, uri); + if (node->file) + { + uri = g_file_get_uri (node->file); + g_signal_emit (model, model_signals[UNLOAD], 0, uri); - g_free (uri); - g_object_unref (node->file); - } + g_free (uri); + g_object_unref (node->file); + } - if (node->icon) - g_object_unref (node->icon); + if (node->icon) + { + g_object_unref (node->icon); + } - if (node->emblem) - g_object_unref (node->emblem); + if (node->emblem) + { + g_object_unref (node->emblem); + } - g_free (node->name); + g_free (node->name); - if (NODE_IS_DIR (node)) - g_slice_free (FileBrowserNodeDir, (FileBrowserNodeDir *)node); - else - g_slice_free (FileBrowserNode, (FileBrowserNode *)node); + if (NODE_IS_DIR (node)) + { + g_slice_free (FileBrowserNodeDir, (FileBrowserNodeDir *)node); + } + else + { + g_slice_free (FileBrowserNode, (FileBrowserNode *)node); + } } /** @@ -1413,50 +1526,60 @@ file_browser_node_free (XedFileBrowserStore * model, * a node. **/ static void -model_remove_node_children (XedFileBrowserStore * model, - FileBrowserNode * node, - GtkTreePath * path, - gboolean free_nodes) +model_remove_node_children (XedFileBrowserStore *model, + FileBrowserNode *node, + GtkTreePath *path, + gboolean free_nodes) { - FileBrowserNodeDir *dir; - GtkTreePath *path_child; - GSList *list; - GSList *item; + FileBrowserNodeDir *dir; + GtkTreePath *path_child; + GSList *list; + GSList *item; - if (node == NULL || !NODE_IS_DIR (node)) - return; + if (node == NULL || !NODE_IS_DIR (node)) + { + return; + } - dir = FILE_BROWSER_NODE_DIR (node); + dir = FILE_BROWSER_NODE_DIR (node); - if (dir->children == NULL) - return; + if (dir->children == NULL) + { + return; + } - if (!model_node_visibility (model, node)) { - // Node is invisible and therefore the children can just - // be freed - if (free_nodes) - file_browser_node_free_children (model, node); + if (!model_node_visibility (model, node)) + { + // Node is invisible and therefore the children can just + // be freed + if (free_nodes) + { + file_browser_node_free_children (model, node); + } - return; - } + return; + } - if (path == NULL) - path_child = - xed_file_browser_store_get_path_real (model, node); - else - path_child = gtk_tree_path_copy (path); + if (path == NULL) + { + path_child = xed_file_browser_store_get_path_real (model, node); + } + else + { + path_child = gtk_tree_path_copy (path); + } - gtk_tree_path_down (path_child); + gtk_tree_path_down (path_child); - list = g_slist_copy (dir->children); + list = g_slist_copy (dir->children); - for (item = list; item; item = item->next) { - model_remove_node (model, (FileBrowserNode *) (item->data), - path_child, free_nodes); - } + for (item = list; item; item = item->next) + { + model_remove_node (model, (FileBrowserNode *) (item->data), path_child, free_nodes); + } - g_slist_free (list); - gtk_tree_path_free (path_child); + g_slist_free (list); + gtk_tree_path_free (path_child); } /** @@ -1472,53 +1595,63 @@ model_remove_node_children (XedFileBrowserStore * model, * a node. **/ static void -model_remove_node (XedFileBrowserStore * model, - FileBrowserNode * node, - GtkTreePath * path, - gboolean free_nodes) +model_remove_node (XedFileBrowserStore *model, + FileBrowserNode *node, + GtkTreePath *path, + gboolean free_nodes) { - gboolean free_path = FALSE; - FileBrowserNode *parent; + gboolean free_path = FALSE; + FileBrowserNode *parent; - if (path == NULL) { - path = - xed_file_browser_store_get_path_real (model, node); - free_path = TRUE; - } + if (path == NULL) + { + path = xed_file_browser_store_get_path_real (model, node); + free_path = TRUE; + } - model_remove_node_children (model, node, path, free_nodes); + model_remove_node_children (model, node, path, free_nodes); - /* Only delete if the node is visible in the tree (but only when it's - not the virtual root) */ - if (model_node_visibility (model, node) && node != model->priv->virtual_root) - { - node->inserted = FALSE; - row_deleted (model, path); - } + /* Only delete if the node is visible in the tree (but only when it's + not the virtual root) */ + if (model_node_visibility (model, node) && node != model->priv->virtual_root) + { + node->inserted = FALSE; + row_deleted (model, path); + } - if (free_path) - gtk_tree_path_free (path); + if (free_path) + { + gtk_tree_path_free (path); + } - parent = node->parent; + parent = node->parent; - if (free_nodes) { - /* Remove the node from the parents children list */ - if (parent) - FILE_BROWSER_NODE_DIR (node->parent)->children = - g_slist_remove (FILE_BROWSER_NODE_DIR - (node->parent)->children, - node); - } + if (free_nodes) + { + /* Remove the node from the parents children list */ + if (parent) + { + FILE_BROWSER_NODE_DIR (node->parent)->children = g_slist_remove (FILE_BROWSER_NODE_DIR + (node->parent)->children, + node); + } + } - /* If this is the virtual root, than set the parent as the virtual root */ - if (node == model->priv->virtual_root) - set_virtual_root_from_node (model, parent); - else if (parent && model_node_visibility (model, parent) && !(free_nodes && NODE_IS_DUMMY(node))) - model_check_dummy (model, parent); + /* If this is the virtual root, than set the parent as the virtual root */ + if (node == model->priv->virtual_root) + { + set_virtual_root_from_node (model, parent); + } + else if (parent && model_node_visibility (model, parent) && !(free_nodes && NODE_IS_DUMMY(node))) + { + model_check_dummy (model, parent); + } - /* Now free the node if necessary */ - if (free_nodes) - file_browser_node_free (model, node); + /* Now free the node if necessary */ + if (free_nodes) + { + file_browser_node_free (model, node); + } } /** @@ -1531,2099 +1664,2318 @@ model_remove_node (XedFileBrowserStore * model, * nodes in the model. **/ static void -model_clear (XedFileBrowserStore * model, gboolean free_nodes) +model_clear (XedFileBrowserStore *model, + gboolean free_nodes) { - GtkTreePath *path; - FileBrowserNodeDir *dir; - FileBrowserNode *dummy; + GtkTreePath *path; + FileBrowserNodeDir *dir; + FileBrowserNode *dummy; - path = gtk_tree_path_new (); - model_remove_node_children (model, model->priv->virtual_root, path, - free_nodes); - gtk_tree_path_free (path); + path = gtk_tree_path_new (); + model_remove_node_children (model, model->priv->virtual_root, path, free_nodes); + gtk_tree_path_free (path); - /* Remove the dummy if there is one */ - if (model->priv->virtual_root) { - dir = FILE_BROWSER_NODE_DIR (model->priv->virtual_root); + /* Remove the dummy if there is one */ + if (model->priv->virtual_root) + { + dir = FILE_BROWSER_NODE_DIR (model->priv->virtual_root); - if (dir->children != NULL) { - dummy = (FileBrowserNode *) (dir->children->data); + if (dir->children != NULL) + { + dummy = (FileBrowserNode *) (dir->children->data); - if (NODE_IS_DUMMY (dummy) - && model_node_visibility (model, dummy)) { - path = gtk_tree_path_new_first (); + if (NODE_IS_DUMMY (dummy) && model_node_visibility (model, dummy)) + { + path = gtk_tree_path_new_first (); - dummy->inserted = FALSE; - row_deleted (model, path); - gtk_tree_path_free (path); - } - } - } + dummy->inserted = FALSE; + row_deleted (model, path); + gtk_tree_path_free (path); + } + } + } } static void -file_browser_node_unload (XedFileBrowserStore * model, - FileBrowserNode * node, gboolean remove_children) +file_browser_node_unload (XedFileBrowserStore *model, + FileBrowserNode *node, + gboolean remove_children) { - FileBrowserNodeDir *dir; + FileBrowserNodeDir *dir; - if (node == NULL) - return; + if (node == NULL) + { + return; + } - if (!NODE_IS_DIR (node) || !NODE_LOADED (node)) - return; + if (!NODE_IS_DIR (node) || !NODE_LOADED (node)) + { + return; + } - dir = FILE_BROWSER_NODE_DIR (node); + dir = FILE_BROWSER_NODE_DIR (node); - if (remove_children) - model_remove_node_children (model, node, NULL, TRUE); + if (remove_children) + { + model_remove_node_children (model, node, NULL, TRUE); + } - if (dir->cancellable) { - g_cancellable_cancel (dir->cancellable); - g_object_unref (dir->cancellable); + if (dir->cancellable) + { + g_cancellable_cancel (dir->cancellable); + g_object_unref (dir->cancellable); - model_end_loading (model, node); - dir->cancellable = NULL; - } + model_end_loading (model, node); + dir->cancellable = NULL; + } - if (dir->monitor) { - g_file_monitor_cancel (dir->monitor); - g_object_unref (dir->monitor); + if (dir->monitor) + { + g_file_monitor_cancel (dir->monitor); + g_object_unref (dir->monitor); - dir->monitor = NULL; - } + dir->monitor = NULL; + } - node->flags &= ~XED_FILE_BROWSER_STORE_FLAG_LOADED; + node->flags &= ~XED_FILE_BROWSER_STORE_FLAG_LOADED; } static void -model_recomposite_icon_real (XedFileBrowserStore * tree_model, - FileBrowserNode * node, - GFileInfo * info) +model_recomposite_icon_real (XedFileBrowserStore *tree_model, + FileBrowserNode *node, + GFileInfo *info) { - GdkPixbuf *icon; + GdkPixbuf *icon; - g_return_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model)); - g_return_if_fail (node != NULL); + g_return_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model)); + g_return_if_fail (node != NULL); - if (node->file == NULL) - return; + if (node->file == NULL) + { + return; + } - if (info) { - GIcon *gicon = g_file_info_get_icon (info); - if (gicon != NULL) - icon = xed_file_browser_utils_pixbuf_from_icon (gicon, GTK_ICON_SIZE_MENU); - else - icon = NULL; - } else { - icon = xed_file_browser_utils_pixbuf_from_file (node->file, GTK_ICON_SIZE_MENU); - } + if (info) + { + GIcon *gicon = g_file_info_get_icon (info); + if (gicon != NULL) + { + icon = xed_file_browser_utils_pixbuf_from_icon (gicon, GTK_ICON_SIZE_MENU); + } + else + { + icon = NULL; + } + } + else + { + icon = xed_file_browser_utils_pixbuf_from_file (node->file, GTK_ICON_SIZE_MENU); + } - if (node->icon) - g_object_unref (node->icon); + if (node->icon) + { + g_object_unref (node->icon); + } - if (node->emblem) { - gint icon_size; + if (node->emblem) + { + gint icon_size; - gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, NULL, &icon_size); + gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, NULL, &icon_size); - if (icon == NULL) { - node->icon = - gdk_pixbuf_new (gdk_pixbuf_get_colorspace (node->emblem), - gdk_pixbuf_get_has_alpha (node->emblem), - gdk_pixbuf_get_bits_per_sample (node->emblem), - icon_size, - icon_size); - } else { - node->icon = gdk_pixbuf_copy (icon); - g_object_unref (icon); - } + if (icon == NULL) + { + node->icon = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (node->emblem), + gdk_pixbuf_get_has_alpha (node->emblem), + gdk_pixbuf_get_bits_per_sample (node->emblem), + icon_size, + icon_size); + } + else + { + node->icon = gdk_pixbuf_copy (icon); + g_object_unref (icon); + } - gdk_pixbuf_composite (node->emblem, node->icon, - icon_size - 10, icon_size - 10, 10, - 10, icon_size - 10, icon_size - 10, - 1, 1, GDK_INTERP_NEAREST, 255); - } else { - node->icon = icon; - } + gdk_pixbuf_composite (node->emblem, node->icon, + icon_size - 10, icon_size - 10, 10, + 10, icon_size - 10, icon_size - 10, + 1, 1, GDK_INTERP_NEAREST, 255); + } + else + { + node->icon = icon; + } } static void -model_recomposite_icon (XedFileBrowserStore * tree_model, - GtkTreeIter * iter) +model_recomposite_icon (XedFileBrowserStore *tree_model, + GtkTreeIter *iter) { - g_return_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model)); - g_return_if_fail (iter != NULL); - g_return_if_fail (iter->user_data != NULL); + g_return_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model)); + g_return_if_fail (iter != NULL); + g_return_if_fail (iter->user_data != NULL); - model_recomposite_icon_real (tree_model, - (FileBrowserNode *) (iter->user_data), - NULL); + model_recomposite_icon_real (tree_model, (FileBrowserNode *) (iter->user_data), NULL); } static FileBrowserNode * -model_create_dummy_node (XedFileBrowserStore * model, - FileBrowserNode * parent) +model_create_dummy_node (XedFileBrowserStore *model, + FileBrowserNode *parent) { - FileBrowserNode *dummy; + FileBrowserNode *dummy; - dummy = file_browser_node_new (NULL, parent); - dummy->name = g_strdup (_("(Empty)")); + dummy = file_browser_node_new (NULL, parent); + dummy->name = g_strdup (_("(Empty)")); - dummy->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_DUMMY; - dummy->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; + dummy->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_DUMMY; + dummy->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; - return dummy; + return dummy; } static FileBrowserNode * -model_add_dummy_node (XedFileBrowserStore * model, - FileBrowserNode * parent) +model_add_dummy_node (XedFileBrowserStore *model, + FileBrowserNode *parent) { - FileBrowserNode *dummy; + FileBrowserNode *dummy; - dummy = model_create_dummy_node (model, parent); + dummy = model_create_dummy_node (model, parent); - if (model_node_visibility (model, parent)) - dummy->flags &= ~XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; + if (model_node_visibility (model, parent)) + { + dummy->flags &= ~XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; + } - model_add_node (model, dummy, parent); + model_add_node (model, dummy, parent); - return dummy; + return dummy; } static void -model_check_dummy (XedFileBrowserStore * model, FileBrowserNode * node) +model_check_dummy (XedFileBrowserStore *model, + FileBrowserNode *node) { - // Hide the dummy child if needed - if (NODE_IS_DIR (node)) { - FileBrowserNode *dummy; - GtkTreeIter iter; - GtkTreePath *path; - guint flags; - FileBrowserNodeDir *dir; + // Hide the dummy child if needed + if (NODE_IS_DIR (node)) + { + FileBrowserNode *dummy; + GtkTreeIter iter; + GtkTreePath *path; + guint flags; + FileBrowserNodeDir *dir; - dir = FILE_BROWSER_NODE_DIR (node); + dir = FILE_BROWSER_NODE_DIR (node); - if (dir->children == NULL) { - model_add_dummy_node (model, node); - return; - } + if (dir->children == NULL) + { + model_add_dummy_node (model, node); + return; + } - dummy = (FileBrowserNode *) (dir->children->data); + dummy = (FileBrowserNode *) (dir->children->data); - if (!NODE_IS_DUMMY (dummy)) { - dummy = model_create_dummy_node (model, node); - dir->children = g_slist_prepend (dir->children, dummy); - } + if (!NODE_IS_DUMMY (dummy)) + { + dummy = model_create_dummy_node (model, node); + dir->children = g_slist_prepend (dir->children, dummy); + } - if (!model_node_visibility (model, node)) { - dummy->flags |= - XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; - return; - } + if (!model_node_visibility (model, node)) + { + dummy->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; + return; + } - /* Temporarily set the node to invisible to check - * for real children */ - flags = dummy->flags; - dummy->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; + /* Temporarily set the node to invisible to check + * for real children */ + flags = dummy->flags; + dummy->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; - if (!filter_tree_model_iter_has_child_real (model, node)) { - dummy->flags &= - ~XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; + if (!filter_tree_model_iter_has_child_real (model, node)) + { + dummy->flags &= ~XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; - if (FILE_IS_HIDDEN (flags)) { - // Was hidden, needs to be inserted - iter.user_data = dummy; - path = - xed_file_browser_store_get_path_real - (model, dummy); + if (FILE_IS_HIDDEN (flags)) + { + // Was hidden, needs to be inserted + iter.user_data = dummy; + path = xed_file_browser_store_get_path_real (model, dummy); - row_inserted (model, &path, &iter); - gtk_tree_path_free (path); - } - } else { - if (!FILE_IS_HIDDEN (flags)) { - // Was shown, needs to be removed + row_inserted (model, &path, &iter); + gtk_tree_path_free (path); + } + } + else + { + if (!FILE_IS_HIDDEN (flags)) + { + // Was shown, needs to be removed - // To get the path we need to set it to visible temporarily - dummy->flags &= - ~XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; - path = - xed_file_browser_store_get_path_real - (model, dummy); - dummy->flags |= - XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; + // To get the path we need to set it to visible temporarily + dummy->flags &= ~XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; + path = xed_file_browser_store_get_path_real (model, dummy); + dummy->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; - dummy->inserted = FALSE; - row_deleted (model, path); - gtk_tree_path_free (path); - } - } - } + dummy->inserted = FALSE; + row_deleted (model, path); + gtk_tree_path_free (path); + } + } + } } static void -insert_node_sorted (XedFileBrowserStore * model, - FileBrowserNode * child, - FileBrowserNode * parent) +insert_node_sorted (XedFileBrowserStore *model, + FileBrowserNode *child, + FileBrowserNode *parent) { - FileBrowserNodeDir *dir; + FileBrowserNodeDir *dir; - dir = FILE_BROWSER_NODE_DIR (parent); + dir = FILE_BROWSER_NODE_DIR (parent); - if (model->priv->sort_func == NULL) { - dir->children = g_slist_append (dir->children, child); - } else { - dir->children = - g_slist_insert_sorted (dir->children, child, - (GCompareFunc) (model->priv-> - sort_func)); - } + if (model->priv->sort_func == NULL) + { + dir->children = g_slist_append (dir->children, child); + } + else + { + dir->children = g_slist_insert_sorted (dir->children, child, (GCompareFunc) (model->priv->sort_func)); + } } static void -model_add_node (XedFileBrowserStore * model, FileBrowserNode * child, - FileBrowserNode * parent) +model_add_node (XedFileBrowserStore *model, + FileBrowserNode *child, + FileBrowserNode *parent) { - /* Add child to parents children */ - insert_node_sorted (model, child, parent); + /* Add child to parents children */ + insert_node_sorted (model, child, parent); - if (model_node_visibility (model, parent) && - model_node_visibility (model, child)) { - GtkTreeIter iter; - GtkTreePath *path; + if (model_node_visibility (model, parent) && model_node_visibility (model, child)) + { + GtkTreeIter iter; + GtkTreePath *path; - iter.user_data = child; - path = xed_file_browser_store_get_path_real (model, child); + iter.user_data = child; + path = xed_file_browser_store_get_path_real (model, child); - /* Emit row inserted */ - row_inserted (model, &path, &iter); - gtk_tree_path_free (path); - } + /* Emit row inserted */ + row_inserted (model, &path, &iter); + gtk_tree_path_free (path); + } - model_check_dummy (model, parent); - model_check_dummy (model, child); + model_check_dummy (model, parent); + model_check_dummy (model, child); } static void -model_add_nodes_batch (XedFileBrowserStore * model, - GSList * children, - FileBrowserNode * parent) +model_add_nodes_batch (XedFileBrowserStore *model, + GSList *children, + FileBrowserNode *parent) { - GSList *sorted_children; - GSList *child; - GSList *prev; - GSList *l; - FileBrowserNodeDir *dir; + GSList *sorted_children; + GSList *child; + GSList *prev; + GSList *l; + FileBrowserNodeDir *dir; - dir = FILE_BROWSER_NODE_DIR (parent); + dir = FILE_BROWSER_NODE_DIR (parent); - sorted_children = g_slist_sort (children, (GCompareFunc) model->priv->sort_func); + sorted_children = g_slist_sort (children, (GCompareFunc) model->priv->sort_func); - child = sorted_children; - l = dir->children; - prev = NULL; + child = sorted_children; + l = dir->children; + prev = NULL; - model_check_dummy (model, parent); + model_check_dummy (model, parent); - while (child) { - FileBrowserNode *node = child->data; - GtkTreeIter iter; - GtkTreePath *path; + while (child) + { + FileBrowserNode *node = child->data; + GtkTreeIter iter; + GtkTreePath *path; - /* reached the end of the first list, just append the second */ - if (l == NULL) { + /* reached the end of the first list, just append the second */ + if (l == NULL) + { - dir->children = g_slist_concat (dir->children, child); + dir->children = g_slist_concat (dir->children, child); - for (l = child; l; l = l->next) { - if (model_node_visibility (model, parent) && - model_node_visibility (model, l->data)) { - iter.user_data = l->data; - path = xed_file_browser_store_get_path_real (model, l->data); + for (l = child; l; l = l->next) + { + if (model_node_visibility (model, parent) && model_node_visibility (model, l->data)) + { + iter.user_data = l->data; + path = xed_file_browser_store_get_path_real (model, l->data); - // Emit row inserted - row_inserted (model, &path, &iter); - gtk_tree_path_free (path); - } + // Emit row inserted + row_inserted (model, &path, &iter); + gtk_tree_path_free (path); + } - model_check_dummy (model, l->data); - } + model_check_dummy (model, l->data); + } - break; - } + break; + } - if (model->priv->sort_func (l->data, node) > 0) { - GSList *next_child; + if (model->priv->sort_func (l->data, node) > 0) + { + GSList *next_child; - if (prev == NULL) { - /* prepend to the list */ - dir->children = g_slist_prepend (dir->children, child); - } else { - prev->next = child; - } + if (prev == NULL) + { + /* prepend to the list */ + dir->children = g_slist_prepend (dir->children, child); + } + else + { + prev->next = child; + } - next_child = child->next; - prev = child; - child->next = l; - child = next_child; + next_child = child->next; + prev = child; + child->next = l; + child = next_child; - if (model_node_visibility (model, parent) && - model_node_visibility (model, node)) { - iter.user_data = node; - path = xed_file_browser_store_get_path_real (model, node); + if (model_node_visibility (model, parent) && model_node_visibility (model, node)) + { + iter.user_data = node; + path = xed_file_browser_store_get_path_real (model, node); - // Emit row inserted - row_inserted (model, &path, &iter); - gtk_tree_path_free (path); - } + // Emit row inserted + row_inserted (model, &path, &iter); + gtk_tree_path_free (path); + } - model_check_dummy (model, node); + model_check_dummy (model, node); - /* try again at the same l position with the - * next child */ - } else { + /* try again at the same l position with the + * next child */ + } + else + { - /* Move to the next item in the list */ - prev = l; - l = l->next; - } - } + /* Move to the next item in the list */ + prev = l; + l = l->next; + } + } } static gchar const * -backup_content_type (GFileInfo * info) +backup_content_type (GFileInfo *info) { - gchar const * content; + gchar const * content; - if (!g_file_info_get_is_backup (info)) - return NULL; + if (!g_file_info_get_is_backup (info)) + { + return NULL; + } - content = g_file_info_get_content_type (info); + content = g_file_info_get_content_type (info); - if (!content || g_content_type_equals (content, "application/x-trash")) - return "text/plain"; + if (!content || g_content_type_equals (content, "application/x-trash")) + { + return "text/plain"; + } - return content; + return content; } static void -file_browser_node_set_from_info (XedFileBrowserStore * model, - FileBrowserNode * node, - GFileInfo * info, - gboolean isadded) +file_browser_node_set_from_info (XedFileBrowserStore *model, + FileBrowserNode *node, + GFileInfo *info, + gboolean isadded) { - FileBrowserNodeDir * dir; - gchar const * content; - gchar const * name; - gboolean free_info = FALSE; - GtkTreePath * path; - gchar * uri; - GError * error = NULL; + FileBrowserNodeDir *dir; + gchar const *content; + gchar const *name; + gboolean free_info = FALSE; + GtkTreePath *path; + gchar *uri; + GError *error = NULL; - if (info == NULL) { - info = g_file_query_info (node->file, - STANDARD_ATTRIBUTE_TYPES, - G_FILE_QUERY_INFO_NONE, - NULL, - &error); + if (info == NULL) + { + info = g_file_query_info (node->file, + STANDARD_ATTRIBUTE_TYPES, + G_FILE_QUERY_INFO_NONE, + NULL, + &error); - if (!info) { - if (!(error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_FOUND)) { - uri = g_file_get_uri (node->file); - g_warning ("Could not get info for %s: %s", uri, error->message); - g_free (uri); - } - g_error_free (error); + if (!info) + { + if (!(error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_FOUND)) + { + uri = g_file_get_uri (node->file); + g_warning ("Could not get info for %s: %s", uri, error->message); + g_free (uri); + } + g_error_free (error); - return; - } + return; + } - free_info = TRUE; - } + free_info = TRUE; + } - dir = FILE_BROWSER_NODE_DIR (node->parent); - name = g_file_info_get_name (info); + dir = FILE_BROWSER_NODE_DIR (node->parent); + name = g_file_info_get_name (info); - if (g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info)) - node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; - else if (dir != NULL && dir->hidden_file_hash != NULL && - g_hash_table_lookup (dir->hidden_file_hash, name) != NULL) - node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; + if (g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info)) + { + node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; + } + else if (dir != NULL && dir->hidden_file_hash != NULL && g_hash_table_lookup (dir->hidden_file_hash, name) != NULL) + { + node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; + } - if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) - node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY; - else { - if (!(content = backup_content_type (info))) - content = g_file_info_get_content_type (info); + if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) + { + node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY; + } + else + { + if (!(content = backup_content_type (info))) + { + content = g_file_info_get_content_type (info); + } - if (!content || - g_content_type_is_unknown (content) || - g_content_type_is_a (content, "text/plain")) - node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_TEXT; - } + if (!content || + g_content_type_is_unknown (content) || + g_content_type_is_a (content, "text/plain")) + { + node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_TEXT; + } + } - model_recomposite_icon_real (model, node, info); + model_recomposite_icon_real (model, node, info); - if (free_info) - g_object_unref (info); + if (free_info) + { + g_object_unref (info); + } - if (isadded) { - path = xed_file_browser_store_get_path_real (model, node); - model_refilter_node (model, node, &path); - gtk_tree_path_free (path); + if (isadded) + { + path = xed_file_browser_store_get_path_real (model, node); + model_refilter_node (model, node, &path); + gtk_tree_path_free (path); - model_check_dummy (model, node->parent); - } else { - model_node_update_visibility (model, node); - } + model_check_dummy (model, node->parent); + } + else + { + model_node_update_visibility (model, node); + } } static FileBrowserNode * -node_list_contains_file (GSList *children, GFile * file) +node_list_contains_file (GSList *children, + GFile *file) { - GSList *item; + GSList *item; - for (item = children; item; item = item->next) { - FileBrowserNode *node; + for (item = children; item; item = item->next) + { + FileBrowserNode *node; - node = (FileBrowserNode *) (item->data); + node = (FileBrowserNode *) (item->data); - if (node->file != NULL - && g_file_equal (node->file, file)) - return node; - } + if (node->file != NULL && g_file_equal (node->file, file)) + { + return node; + } + } - return NULL; + return NULL; } static FileBrowserNode * -model_add_node_from_file (XedFileBrowserStore * model, - FileBrowserNode * parent, - GFile * file, - GFileInfo * info) +model_add_node_from_file (XedFileBrowserStore *model, + FileBrowserNode *parent, + GFile *file, + GFileInfo *info) { - FileBrowserNode *node; - gboolean free_info = FALSE; - GError * error = NULL; + FileBrowserNode *node; + gboolean free_info = FALSE; + GError * error = NULL; - if ((node = node_list_contains_file (FILE_BROWSER_NODE_DIR (parent)->children, file)) == NULL) { - if (info == NULL) { - info = g_file_query_info (file, - STANDARD_ATTRIBUTE_TYPES, - G_FILE_QUERY_INFO_NONE, - NULL, - &error); - free_info = TRUE; - } + if ((node = node_list_contains_file (FILE_BROWSER_NODE_DIR (parent)->children, file)) == NULL) + { + if (info == NULL) + { + info = g_file_query_info (file, + STANDARD_ATTRIBUTE_TYPES, + G_FILE_QUERY_INFO_NONE, + NULL, + &error); + free_info = TRUE; + } - if (!info) { - g_warning ("Error querying file info: %s", error->message); - g_error_free (error); + if (!info) + { + g_warning ("Error querying file info: %s", error->message); + g_error_free (error); - /* FIXME: What to do now then... */ - node = file_browser_node_new (file, parent); - } else if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { - node = file_browser_node_dir_new (model, file, parent); - } else { - node = file_browser_node_new (file, parent); - } + /* FIXME: What to do now then... */ + node = file_browser_node_new (file, parent); + } + else if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) + { + node = file_browser_node_dir_new (model, file, parent); + } + else + { + node = file_browser_node_new (file, parent); + } - file_browser_node_set_from_info (model, node, info, FALSE); - model_add_node (model, node, parent); + file_browser_node_set_from_info (model, node, info, FALSE); + model_add_node (model, node, parent); - if (info && free_info) - g_object_unref (info); - } + if (info && free_info) + { + g_object_unref (info); + } + } - return node; + return node; } /* We pass in a copy of the list of parent->children so that we do * not have to check if a file already exists among the ones we just * added */ static void -model_add_nodes_from_files (XedFileBrowserStore * model, - FileBrowserNode * parent, - GSList * original_children, - GList * files) +model_add_nodes_from_files (XedFileBrowserStore *model, + FileBrowserNode *parent, + GSList *original_children, + GList *files) { - GList *item; - GSList *nodes = NULL; + GList *item; + GSList *nodes = NULL; - for (item = files; item; item = item->next) { - GFileInfo *info = G_FILE_INFO (item->data); - GFileType type; - gchar const * name; - GFile * file; - FileBrowserNode *node; + for (item = files; item; item = item->next) + { + GFileInfo *info = G_FILE_INFO (item->data); + GFileType type; + gchar const *name; + GFile *file; + FileBrowserNode *node; - type = g_file_info_get_file_type (info); + type = g_file_info_get_file_type (info); - /* Skip all non regular, non directory files */ - if (type != G_FILE_TYPE_REGULAR && - type != G_FILE_TYPE_DIRECTORY && - type != G_FILE_TYPE_SYMBOLIC_LINK) { - g_object_unref (info); - continue; - } + /* Skip all non regular, non directory files */ + if (type != G_FILE_TYPE_REGULAR && + type != G_FILE_TYPE_DIRECTORY && + type != G_FILE_TYPE_SYMBOLIC_LINK) + { + g_object_unref (info); + continue; + } - name = g_file_info_get_name (info); + name = g_file_info_get_name (info); - /* Skip '.' and '..' directories */ - if (type == G_FILE_TYPE_DIRECTORY && - (strcmp (name, ".") == 0 || - strcmp (name, "..") == 0)) { - continue; - } + /* Skip '.' and '..' directories */ + if (type == G_FILE_TYPE_DIRECTORY && + (strcmp (name, ".") == 0 || + strcmp (name, "..") == 0)) + { + continue; + } - file = g_file_get_child (parent->file, name); + file = g_file_get_child (parent->file, name); - if ((node = node_list_contains_file (original_children, file)) == NULL) { + if ((node = node_list_contains_file (original_children, file)) == NULL) + { - if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { - node = file_browser_node_dir_new (model, file, parent); - } else { - node = file_browser_node_new (file, parent); - } + if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) + { + node = file_browser_node_dir_new (model, file, parent); + } + else + { + node = file_browser_node_new (file, parent); + } - file_browser_node_set_from_info (model, node, info, FALSE); + file_browser_node_set_from_info (model, node, info, FALSE); - nodes = g_slist_prepend (nodes, node); - } + nodes = g_slist_prepend (nodes, node); + } - g_object_unref (file); - g_object_unref (info); - } + g_object_unref (file); + g_object_unref (info); + } - if (nodes) - model_add_nodes_batch (model, nodes, parent); + if (nodes) + { + model_add_nodes_batch (model, nodes, parent); + } } static FileBrowserNode * -model_add_node_from_dir (XedFileBrowserStore * model, - FileBrowserNode * parent, - GFile * file) +model_add_node_from_dir (XedFileBrowserStore *model, + FileBrowserNode *parent, + GFile *file) { - FileBrowserNode *node; + FileBrowserNode *node; - /* Check if it already exists */ - if ((node = node_list_contains_file (FILE_BROWSER_NODE_DIR (parent)->children, file)) == NULL) { - node = file_browser_node_dir_new (model, file, parent); - file_browser_node_set_from_info (model, node, NULL, FALSE); + /* Check if it already exists */ + if ((node = node_list_contains_file (FILE_BROWSER_NODE_DIR (parent)->children, file)) == NULL) + { + node = file_browser_node_dir_new (model, file, parent); + file_browser_node_set_from_info (model, node, NULL, FALSE); - if (node->name == NULL) { - file_browser_node_set_name (node); - } + if (node->name == NULL) + { + file_browser_node_set_name (node); + } - if (node->icon == NULL) { - node->icon = xed_file_browser_utils_pixbuf_from_theme ("folder", GTK_ICON_SIZE_MENU); - } + if (node->icon == NULL) + { + node->icon = xed_file_browser_utils_pixbuf_from_theme ("folder", GTK_ICON_SIZE_MENU); + } - model_add_node (model, node, parent); - } + model_add_node (model, node, parent); + } - return node; + return node; } /* Read is sync, but we only do it for local files */ static void parse_dot_hidden_file (FileBrowserNode *directory) { - gsize file_size; - char *file_contents; - GFile *child; - GFileInfo *info; - GFileType type; - int i; - FileBrowserNodeDir * dir = FILE_BROWSER_NODE_DIR (directory); + gsize file_size; + char *file_contents; + GFile *child; + GFileInfo *info; + GFileType type; + int i; + FileBrowserNodeDir * dir = FILE_BROWSER_NODE_DIR (directory); - /* FIXME: We only support .hidden on file: uri's for the moment. - * Need to figure out if we should do this async or sync to extend - * it to all types of uris. - */ - if (directory->file == NULL || !g_file_is_native (directory->file)) { - return; - } + /* FIXME: We only support .hidden on file: uri's for the moment. + * Need to figure out if we should do this async or sync to extend + * it to all types of uris. + */ + if (directory->file == NULL || !g_file_is_native (directory->file)) + { + return; + } - child = g_file_get_child (directory->file, ".hidden"); - info = g_file_query_info (child, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); + child = g_file_get_child (directory->file, ".hidden"); + info = g_file_query_info (child, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); - type = info ? g_file_info_get_file_type (info) : G_FILE_TYPE_UNKNOWN; + type = info ? g_file_info_get_file_type (info) : G_FILE_TYPE_UNKNOWN; - if (info) - g_object_unref (info); + if (info) + { + g_object_unref (info); + } - if (type != G_FILE_TYPE_REGULAR) { - g_object_unref (child); + if (type != G_FILE_TYPE_REGULAR) + { + g_object_unref (child); + return; + } - return; - } + if (!g_file_load_contents (child, NULL, &file_contents, &file_size, NULL, NULL)) + { + g_object_unref (child); + return; + } - if (!g_file_load_contents (child, NULL, &file_contents, &file_size, NULL, NULL)) { - g_object_unref (child); - return; - } + g_object_unref (child); - g_object_unref (child); + if (dir->hidden_file_hash == NULL) + { + dir->hidden_file_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + } - if (dir->hidden_file_hash == NULL) { - dir->hidden_file_hash = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - } + /* Now parse the data */ + i = 0; + while (i < file_size) + { + int start; - /* Now parse the data */ - i = 0; - while (i < file_size) { - int start; + start = i; + while (i < file_size && file_contents[i] != '\n') + { + i++; + } - start = i; - while (i < file_size && file_contents[i] != '\n') { - i++; - } + if (i > start) + { + char *hidden_filename; - if (i > start) { - char *hidden_filename; + hidden_filename = g_strndup (file_contents + start, i - start); + g_hash_table_insert (dir->hidden_file_hash, hidden_filename, hidden_filename); + } - hidden_filename = g_strndup (file_contents + start, i - start); - g_hash_table_insert (dir->hidden_file_hash, - hidden_filename, hidden_filename); - } + i++; - i++; + } - } - - g_free (file_contents); + g_free (file_contents); } static void -on_directory_monitor_event (GFileMonitor * monitor, - GFile * file, - GFile * other_file, - GFileMonitorEvent event_type, - FileBrowserNode * parent) +on_directory_monitor_event (GFileMonitor *monitor, + GFile *file, + GFile *other_file, + GFileMonitorEvent event_type, + FileBrowserNode *parent) { - FileBrowserNode *node; - FileBrowserNodeDir *dir = FILE_BROWSER_NODE_DIR (parent); + FileBrowserNode *node; + FileBrowserNodeDir *dir = FILE_BROWSER_NODE_DIR (parent); - switch (event_type) { - case G_FILE_MONITOR_EVENT_DELETED: - node = node_list_contains_file (dir->children, file); + switch (event_type) + { + case G_FILE_MONITOR_EVENT_DELETED: + node = node_list_contains_file (dir->children, file); - if (node != NULL) { - model_remove_node (dir->model, node, NULL, TRUE); - } - break; - case G_FILE_MONITOR_EVENT_CREATED: - if (g_file_query_exists (file, NULL)) { - model_add_node_from_file (dir->model, parent, file, NULL); - } + if (node != NULL) + { + model_remove_node (dir->model, node, NULL, TRUE); + } + break; + case G_FILE_MONITOR_EVENT_CREATED: + if (g_file_query_exists (file, NULL)) + { + model_add_node_from_file (dir->model, parent, file, NULL); + } - break; - default: - break; - } + break; + default: + break; + } } static void async_node_free (AsyncNode *async) { - g_object_unref (async->cancellable); - g_slist_free (async->original_children); - g_free (async); + g_object_unref (async->cancellable); + g_slist_free (async->original_children); + g_free (async); } static void -model_iterate_next_files_cb (GFileEnumerator * enumerator, - GAsyncResult * result, - AsyncNode * async) +model_iterate_next_files_cb (GFileEnumerator *enumerator, + GAsyncResult *result, + AsyncNode *async) { - GList * files; - GError * error = NULL; - FileBrowserNodeDir * dir = async->dir; - FileBrowserNode * parent = (FileBrowserNode *)dir; + GList *files; + GError *error = NULL; + FileBrowserNodeDir *dir = async->dir; + FileBrowserNode *parent = (FileBrowserNode *)dir; - files = g_file_enumerator_next_files_finish (enumerator, result, &error); + files = g_file_enumerator_next_files_finish (enumerator, result, &error); - if (files == NULL) { - g_file_enumerator_close (enumerator, NULL, NULL); - async_node_free (async); + if (files == NULL) + { + g_file_enumerator_close (enumerator, NULL, NULL); + async_node_free (async); - if (!error) - { - /* We're done loading */ - g_object_unref (dir->cancellable); - dir->cancellable = NULL; + if (!error) + { + /* We're done loading */ + g_object_unref (dir->cancellable); + dir->cancellable = NULL; /* * FIXME: This is temporarly, it is a bug in gio: * http://bugzilla.gnome.org/show_bug.cgi?id=565924 */ - if (g_file_is_native (parent->file) && dir->monitor == NULL) { - dir->monitor = g_file_monitor_directory (parent->file, - G_FILE_MONITOR_NONE, - NULL, - NULL); - if (dir->monitor != NULL) - { - g_signal_connect (dir->monitor, - "changed", - G_CALLBACK (on_directory_monitor_event), - parent); - } - } + if (g_file_is_native (parent->file) && dir->monitor == NULL) + { + dir->monitor = g_file_monitor_directory (parent->file, + G_FILE_MONITOR_NONE, + NULL, + NULL); + if (dir->monitor != NULL) + { + g_signal_connect (dir->monitor, "changed", + G_CALLBACK (on_directory_monitor_event), parent); + } + } - model_check_dummy (dir->model, parent); - model_end_loading (dir->model, parent); - } else { - /* Simply return if we were cancelled */ - if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED) - return; + model_check_dummy (dir->model, parent); + model_end_loading (dir->model, parent); + } + else + { + /* Simply return if we were cancelled */ + if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED) + { + return; + } - /* Otherwise handle the error appropriately */ - g_signal_emit (dir->model, - model_signals[ERROR], - 0, - XED_FILE_BROWSER_ERROR_LOAD_DIRECTORY, - error->message); + /* Otherwise handle the error appropriately */ + g_signal_emit (dir->model, + model_signals[ERROR], + 0, + XED_FILE_BROWSER_ERROR_LOAD_DIRECTORY, + error->message); - file_browser_node_unload (dir->model, (FileBrowserNode *)parent, TRUE); - g_error_free (error); - } - } else if (g_cancellable_is_cancelled (async->cancellable)) { - /* Check cancel state manually */ - g_file_enumerator_close (enumerator, NULL, NULL); - async_node_free (async); - } else { - model_add_nodes_from_files (dir->model, parent, async->original_children, files); + file_browser_node_unload (dir->model, (FileBrowserNode *)parent, TRUE); + g_error_free (error); + } + } + else if (g_cancellable_is_cancelled (async->cancellable)) + { + /* Check cancel state manually */ + g_file_enumerator_close (enumerator, NULL, NULL); + async_node_free (async); + } + else + { + model_add_nodes_from_files (dir->model, parent, async->original_children, files); - g_list_free (files); - next_files_async (enumerator, async); - } + g_list_free (files); + next_files_async (enumerator, async); + } } static void -next_files_async (GFileEnumerator * enumerator, - AsyncNode * async) +next_files_async (GFileEnumerator *enumerator, + AsyncNode *async) { - g_file_enumerator_next_files_async (enumerator, - DIRECTORY_LOAD_ITEMS_PER_CALLBACK, - G_PRIORITY_DEFAULT, - async->cancellable, - (GAsyncReadyCallback)model_iterate_next_files_cb, - async); + g_file_enumerator_next_files_async (enumerator, + DIRECTORY_LOAD_ITEMS_PER_CALLBACK, + G_PRIORITY_DEFAULT, + async->cancellable, + (GAsyncReadyCallback)model_iterate_next_files_cb, + async); } static void -model_iterate_children_cb (GFile * file, - GAsyncResult * result, - AsyncNode * async) +model_iterate_children_cb (GFile *file, + GAsyncResult *result, + AsyncNode *async) { - GError * error = NULL; - GFileEnumerator * enumerator; + GError * error = NULL; + GFileEnumerator * enumerator; - if (g_cancellable_is_cancelled (async->cancellable)) - { - async_node_free (async); - return; - } + if (g_cancellable_is_cancelled (async->cancellable)) + { + async_node_free (async); + return; + } - enumerator = g_file_enumerate_children_finish (file, result, &error); + enumerator = g_file_enumerate_children_finish (file, result, &error); - if (enumerator == NULL) { - /* Simply return if we were cancelled or if the dir is not there */ - FileBrowserNodeDir *dir = async->dir; + if (enumerator == NULL) + { + /* Simply return if we were cancelled or if the dir is not there */ + FileBrowserNodeDir *dir = async->dir; - /* Otherwise handle the error appropriately */ - g_signal_emit (dir->model, - model_signals[ERROR], - 0, - XED_FILE_BROWSER_ERROR_LOAD_DIRECTORY, - error->message); + /* Otherwise handle the error appropriately */ + g_signal_emit (dir->model, + model_signals[ERROR], + 0, + XED_FILE_BROWSER_ERROR_LOAD_DIRECTORY, + error->message); - file_browser_node_unload (dir->model, (FileBrowserNode *)dir, TRUE); - g_error_free (error); - async_node_free (async); - } else { - next_files_async (enumerator, async); - } + file_browser_node_unload (dir->model, (FileBrowserNode *)dir, TRUE); + g_error_free (error); + async_node_free (async); + } + else + { + next_files_async (enumerator, async); + } } static void -model_load_directory (XedFileBrowserStore * model, - FileBrowserNode * node) +model_load_directory (XedFileBrowserStore *model, + FileBrowserNode *node) { - FileBrowserNodeDir *dir; - AsyncNode *async; + FileBrowserNodeDir *dir; + AsyncNode *async; - g_return_if_fail (NODE_IS_DIR (node)); + g_return_if_fail (NODE_IS_DIR (node)); - dir = FILE_BROWSER_NODE_DIR (node); + dir = FILE_BROWSER_NODE_DIR (node); - /* Cancel a previous load */ - if (dir->cancellable != NULL) { - file_browser_node_unload (dir->model, node, TRUE); - } + /* Cancel a previous load */ + if (dir->cancellable != NULL) + { + file_browser_node_unload (dir->model, node, TRUE); + } - node->flags |= XED_FILE_BROWSER_STORE_FLAG_LOADED; - model_begin_loading (model, node); + node->flags |= XED_FILE_BROWSER_STORE_FLAG_LOADED; + model_begin_loading (model, node); - /* Read the '.hidden' file first (if any) */ - parse_dot_hidden_file (node); + /* Read the '.hidden' file first (if any) */ + parse_dot_hidden_file (node); - dir->cancellable = g_cancellable_new (); + dir->cancellable = g_cancellable_new (); - async = g_new (AsyncNode, 1); - async->dir = dir; - async->cancellable = g_object_ref (dir->cancellable); - async->original_children = g_slist_copy (dir->children); + async = g_new (AsyncNode, 1); + async->dir = dir; + async->cancellable = g_object_ref (dir->cancellable); + async->original_children = g_slist_copy (dir->children); - /* Start loading async */ - g_file_enumerate_children_async (node->file, - STANDARD_ATTRIBUTE_TYPES, - G_FILE_QUERY_INFO_NONE, - G_PRIORITY_DEFAULT, - async->cancellable, - (GAsyncReadyCallback)model_iterate_children_cb, - async); + /* Start loading async */ + g_file_enumerate_children_async (node->file, + STANDARD_ATTRIBUTE_TYPES, + G_FILE_QUERY_INFO_NONE, + G_PRIORITY_DEFAULT, + async->cancellable, + (GAsyncReadyCallback)model_iterate_children_cb, + async); } static GList * -get_parent_files (XedFileBrowserStore * model, GFile * file) +get_parent_files (XedFileBrowserStore *model, + GFile *file) { - GList * result = NULL; + GList * result = NULL; - result = g_list_prepend (result, g_object_ref (file)); + result = g_list_prepend (result, g_object_ref (file)); - while ((file = g_file_get_parent (file))) { - if (g_file_equal (file, model->priv->root->file)) { - g_object_unref (file); - break; - } + while ((file = g_file_get_parent (file))) + { + if (g_file_equal (file, model->priv->root->file)) + { + g_object_unref (file); + break; + } - result = g_list_prepend (result, file); - } + result = g_list_prepend (result, file); + } - return result; + return result; } static void -model_fill (XedFileBrowserStore * model, FileBrowserNode * node, - GtkTreePath ** path) +model_fill (XedFileBrowserStore *model, + FileBrowserNode *node, + GtkTreePath **path) { - gboolean free_path = FALSE; - GtkTreeIter iter = {0,}; - GSList *item; - FileBrowserNode *child; + gboolean free_path = FALSE; + GtkTreeIter iter = {0,}; + GSList *item; + FileBrowserNode *child; - if (node == NULL) { - node = model->priv->virtual_root; - *path = gtk_tree_path_new (); - free_path = TRUE; - } + if (node == NULL) + { + node = model->priv->virtual_root; + *path = gtk_tree_path_new (); + free_path = TRUE; + } - if (*path == NULL) { - *path = - xed_file_browser_store_get_path_real (model, node); - free_path = TRUE; - } + if (*path == NULL) + { + *path = xed_file_browser_store_get_path_real (model, node); + free_path = TRUE; + } - if (!model_node_visibility (model, node)) { - if (free_path) - gtk_tree_path_free (*path); + if (!model_node_visibility (model, node)) + { + if (free_path) + { + gtk_tree_path_free (*path); + } - return; - } + return; + } - if (node != model->priv->virtual_root) { - /* Insert node */ - iter.user_data = node; + if (node != model->priv->virtual_root) + { + /* Insert node */ + iter.user_data = node; - row_inserted(model, path, &iter); - } + row_inserted(model, path, &iter); + } - if (NODE_IS_DIR (node)) { - /* Go to the first child */ - gtk_tree_path_down (*path); + if (NODE_IS_DIR (node)) + { + /* Go to the first child */ + gtk_tree_path_down (*path); - for (item = FILE_BROWSER_NODE_DIR (node)->children; item; - item = item->next) { - child = (FileBrowserNode *) (item->data); + for (item = FILE_BROWSER_NODE_DIR (node)->children; item; item = item->next) { + child = (FileBrowserNode *) (item->data); - if (model_node_visibility (model, child)) { - model_fill (model, child, path); + if (model_node_visibility (model, child)) + { + model_fill (model, child, path); - /* Increase path for next child */ - gtk_tree_path_next (*path); - } - } + /* Increase path for next child */ + gtk_tree_path_next (*path); + } + } - /* Move back up to node path */ - gtk_tree_path_up (*path); - } + /* Move back up to node path */ + gtk_tree_path_up (*path); + } - model_check_dummy (model, node); + model_check_dummy (model, node); - if (free_path) - gtk_tree_path_free (*path); + if (free_path) + { + gtk_tree_path_free (*path); + } } static void -set_virtual_root_from_node (XedFileBrowserStore * model, - FileBrowserNode * node) +set_virtual_root_from_node (XedFileBrowserStore *model, + FileBrowserNode *node) { - FileBrowserNode *next; - FileBrowserNode *prev; - FileBrowserNode *check; - FileBrowserNodeDir *dir; - GSList *item; - GSList *copy; - GtkTreePath *empty = NULL; + FileBrowserNode *next; + FileBrowserNode *prev; + FileBrowserNode *check; + FileBrowserNodeDir *dir; + GSList *item; + GSList *copy; + GtkTreePath *empty = NULL; - g_assert (node != NULL); + g_assert (node != NULL); - prev = node; - next = prev->parent; + prev = node; + next = prev->parent; - /* Free all the nodes below that we don't need in cache */ - while (prev != model->priv->root) { - dir = FILE_BROWSER_NODE_DIR (next); - copy = g_slist_copy (dir->children); + /* Free all the nodes below that we don't need in cache */ + while (prev != model->priv->root) + { + dir = FILE_BROWSER_NODE_DIR (next); + copy = g_slist_copy (dir->children); - for (item = copy; item; item = item->next) { - check = (FileBrowserNode *) (item->data); + for (item = copy; item; item = item->next) + { + check = (FileBrowserNode *) (item->data); - if (prev == node) { - /* Only free the children, keeping this depth in cache */ - if (check != node) { - file_browser_node_free_children - (model, check); - file_browser_node_unload (model, - check, - FALSE); - } - } else if (check != prev) { - /* Only free when the node is not in the chain */ - dir->children = - g_slist_remove (dir->children, check); - file_browser_node_free (model, check); - } - } + if (prev == node) + { + /* Only free the children, keeping this depth in cache */ + if (check != node) + { + file_browser_node_free_children (model, check); + file_browser_node_unload (model, check, FALSE); + } + } + else if (check != prev) + { + /* Only free when the node is not in the chain */ + dir->children = g_slist_remove (dir->children, check); + file_browser_node_free (model, check); + } + } - if (prev != node) - file_browser_node_unload (model, next, FALSE); + if (prev != node) + { + file_browser_node_unload (model, next, FALSE); + } - g_slist_free (copy); - prev = next; - next = prev->parent; - } + g_slist_free (copy); + prev = next; + next = prev->parent; + } - /* Free all the nodes up that we don't need in cache */ - for (item = FILE_BROWSER_NODE_DIR (node)->children; item; - item = item->next) { - check = (FileBrowserNode *) (item->data); + /* Free all the nodes up that we don't need in cache */ + for (item = FILE_BROWSER_NODE_DIR (node)->children; item; item = item->next) + { + check = (FileBrowserNode *) (item->data); - if (NODE_IS_DIR (check)) { - for (copy = - FILE_BROWSER_NODE_DIR (check)->children; copy; - copy = copy->next) { - file_browser_node_free_children (model, - (FileBrowserNode - *) - (copy-> - data)); - file_browser_node_unload (model, - (FileBrowserNode - *) (copy->data), - FALSE); - } - } else if (NODE_IS_DUMMY (check)) { - check->flags |= - XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; - } - } + if (NODE_IS_DIR (check)) + { + for (copy = FILE_BROWSER_NODE_DIR (check)->children; copy; copy = copy->next) + { + file_browser_node_free_children (model, (FileBrowserNode *) (copy->data)); + file_browser_node_unload (model, (FileBrowserNode *) (copy->data), FALSE); + } + } + else if (NODE_IS_DUMMY (check)) + { + check->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; + } + } - /* Now finally, set the virtual root, and load it up! */ - model->priv->virtual_root = node; + /* Now finally, set the virtual root, and load it up! */ + model->priv->virtual_root = node; - /* Notify that the virtual-root has changed before loading up new nodes so that the - "root_changed" signal can be emitted before any "inserted" signals */ - g_object_notify (G_OBJECT (model), "virtual-root"); + /* Notify that the virtual-root has changed before loading up new nodes so that the + "root_changed" signal can be emitted before any "inserted" signals */ + g_object_notify (G_OBJECT (model), "virtual-root"); - model_fill (model, NULL, &empty); + model_fill (model, NULL, &empty); - if (!NODE_LOADED (node)) - model_load_directory (model, node); + if (!NODE_LOADED (node)) + { + model_load_directory (model, node); + } } static void -set_virtual_root_from_file (XedFileBrowserStore * model, - GFile * file) +set_virtual_root_from_file (XedFileBrowserStore *model, + GFile *file) { - GList * files; - GList * item; - FileBrowserNode * parent; - GFile * check; + GList * files; + GList * item; + FileBrowserNode * parent; + GFile * check; - /* Always clear the model before altering the nodes */ - model_clear (model, FALSE); + /* Always clear the model before altering the nodes */ + model_clear (model, FALSE); - /* Create the node path, get all the uri's */ - files = get_parent_files (model, file); - parent = model->priv->root; + /* Create the node path, get all the uri's */ + files = get_parent_files (model, file); + parent = model->priv->root; - for (item = files; item; item = item->next) { - check = G_FILE (item->data); + for (item = files; item; item = item->next) + { + check = G_FILE (item->data); - parent = model_add_node_from_dir (model, parent, check); - g_object_unref (check); - } + parent = model_add_node_from_dir (model, parent, check); + g_object_unref (check); + } - g_list_free (files); - set_virtual_root_from_node (model, parent); + g_list_free (files); + set_virtual_root_from_node (model, parent); } static FileBrowserNode * -model_find_node_children (XedFileBrowserStore * model, - FileBrowserNode * parent, - GFile * file) +model_find_node_children (XedFileBrowserStore *model, + FileBrowserNode *parent, + GFile *file) { - FileBrowserNodeDir *dir; - FileBrowserNode *child; - FileBrowserNode *result; - GSList *children; + FileBrowserNodeDir *dir; + FileBrowserNode *child; + FileBrowserNode *result; + GSList *children; - if (!NODE_IS_DIR (parent)) - return NULL; + if (!NODE_IS_DIR (parent)) + { + return NULL; + } - dir = FILE_BROWSER_NODE_DIR (parent); + dir = FILE_BROWSER_NODE_DIR (parent); - for (children = dir->children; children; children = children->next) { - child = (FileBrowserNode *)(children->data); + for (children = dir->children; children; children = children->next) + { + child = (FileBrowserNode *)(children->data); - result = model_find_node (model, child, file); + result = model_find_node (model, child, file); - if (result) - return result; - } + if (result) + { + return result; + } + } - return NULL; + return NULL; } static FileBrowserNode * -model_find_node (XedFileBrowserStore * model, - FileBrowserNode * node, - GFile * file) +model_find_node (XedFileBrowserStore *model, + FileBrowserNode *node, + GFile *file) { - if (node == NULL) - node = model->priv->root; + if (node == NULL) + { + node = model->priv->root; + } - if (node->file && g_file_equal (node->file, file)) - return node; + if (node->file && g_file_equal (node->file, file)) + { + return node; + } - if (NODE_IS_DIR (node) && g_file_has_prefix (file, node->file)) - return model_find_node_children (model, node, file); + if (NODE_IS_DIR (node) && g_file_has_prefix (file, node->file)) + { + return model_find_node_children (model, node, file); + } - return NULL; + return NULL; } static GQuark xed_file_browser_store_error_quark (void) { - static GQuark quark = 0; + static GQuark quark = 0; - if (G_UNLIKELY (quark == 0)) { - quark = g_quark_from_string ("xed_file_browser_store_error"); - } + if (G_UNLIKELY (quark == 0)) + { + quark = g_quark_from_string ("xed_file_browser_store_error"); + } - return quark; + return quark; } static GFile * -unique_new_name (GFile * directory, gchar const * name) +unique_new_name (GFile *directory, + gchar const *name) { - GFile * newuri = NULL; - guint num = 0; - gchar * newname; + GFile * newuri = NULL; + guint num = 0; + gchar * newname; - while (newuri == NULL || g_file_query_exists (newuri, NULL)) { - if (newuri != NULL) - g_object_unref (newuri); + while (newuri == NULL || g_file_query_exists (newuri, NULL)) + { + if (newuri != NULL) + { + g_object_unref (newuri); + } - if (num == 0) - newname = g_strdup (name); - else - newname = g_strdup_printf ("%s(%d)", name, num); + if (num == 0) + { + newname = g_strdup (name); + } + else + { + newname = g_strdup_printf ("%s(%d)", name, num); + } - newuri = g_file_get_child (directory, newname); - g_free (newname); + newuri = g_file_get_child (directory, newname); + g_free (newname); - ++num; - } + ++num; + } - return newuri; + return newuri; } static XedFileBrowserStoreResult -model_root_mounted (XedFileBrowserStore * model, gchar const * virtual_root) +model_root_mounted (XedFileBrowserStore *model, + gchar const *virtual_root) { - model_check_dummy (model, model->priv->root); - g_object_notify (G_OBJECT (model), "root"); + model_check_dummy (model, model->priv->root); + g_object_notify (G_OBJECT (model), "root"); - if (virtual_root != NULL) - return - xed_file_browser_store_set_virtual_root_from_string - (model, virtual_root); - else - set_virtual_root_from_node (model, - model->priv->root); + if (virtual_root != NULL) + { + return xed_file_browser_store_set_virtual_root_from_string (model, virtual_root); + } + else + { + set_virtual_root_from_node (model, model->priv->root); + } - return XED_FILE_BROWSER_STORE_RESULT_OK; + return XED_FILE_BROWSER_STORE_RESULT_OK; } static void -handle_root_error (XedFileBrowserStore * model, GError *error) +handle_root_error (XedFileBrowserStore *model, + GError *error) { - FileBrowserNode * root; + FileBrowserNode * root; - g_signal_emit (model, - model_signals[ERROR], - 0, - XED_FILE_BROWSER_ERROR_SET_ROOT, - error->message); + g_signal_emit (model, + model_signals[ERROR], + 0, + XED_FILE_BROWSER_ERROR_SET_ROOT, + error->message); - /* Set the virtual root to the root */ - root = model->priv->root; - model->priv->virtual_root = root; + /* Set the virtual root to the root */ + root = model->priv->root; + model->priv->virtual_root = root; - /* Set the root to be loaded */ - root->flags |= XED_FILE_BROWSER_STORE_FLAG_LOADED; + /* Set the root to be loaded */ + root->flags |= XED_FILE_BROWSER_STORE_FLAG_LOADED; - /* Check the dummy */ - model_check_dummy (model, root); + /* Check the dummy */ + model_check_dummy (model, root); - g_object_notify (G_OBJECT (model), "root"); - g_object_notify (G_OBJECT (model), "virtual-root"); + g_object_notify (G_OBJECT (model), "root"); + g_object_notify (G_OBJECT (model), "virtual-root"); } static void -mount_cb (GFile * file, - GAsyncResult * res, - MountInfo * mount_info) +mount_cb (GFile *file, + GAsyncResult *res, + MountInfo *mount_info) { - gboolean mounted; - GError * error = NULL; - XedFileBrowserStore * model = mount_info->model; + gboolean mounted; + GError *error = NULL; + XedFileBrowserStore *model = mount_info->model; - mounted = g_file_mount_enclosing_volume_finish (file, res, &error); + mounted = g_file_mount_enclosing_volume_finish (file, res, &error); - if (mount_info->model) - { - model->priv->mount_info = NULL; - model_end_loading (model, model->priv->root); - } + if (mount_info->model) + { + model->priv->mount_info = NULL; + model_end_loading (model, model->priv->root); + } - if (!mount_info->model || g_cancellable_is_cancelled (mount_info->cancellable)) - { - // Reset because it might be reused? - g_cancellable_reset (mount_info->cancellable); - } - else if (mounted) - { - model_root_mounted (model, mount_info->virtual_root); - } - else if (error->code != G_IO_ERROR_CANCELLED) - { - handle_root_error (model, error); - } + if (!mount_info->model || g_cancellable_is_cancelled (mount_info->cancellable)) + { + // Reset because it might be reused? + g_cancellable_reset (mount_info->cancellable); + } + else if (mounted) + { + model_root_mounted (model, mount_info->virtual_root); + } + else if (error->code != G_IO_ERROR_CANCELLED) + { + handle_root_error (model, error); + } - if (error) - g_error_free (error); + if (error) + { + g_error_free (error); + } - g_object_unref (mount_info->operation); - g_object_unref (mount_info->cancellable); - g_free (mount_info->virtual_root); + g_object_unref (mount_info->operation); + g_object_unref (mount_info->cancellable); + g_free (mount_info->virtual_root); - g_free (mount_info); + g_free (mount_info); } static XedFileBrowserStoreResult -model_mount_root (XedFileBrowserStore * model, gchar const * virtual_root) +model_mount_root (XedFileBrowserStore *model, + gchar const *virtual_root) { - GFileInfo * info; - GError * error = NULL; - MountInfo * mount_info; + GFileInfo *info; + GError *error = NULL; + MountInfo *mount_info; - info = g_file_query_info (model->priv->root->file, - G_FILE_ATTRIBUTE_STANDARD_TYPE, - G_FILE_QUERY_INFO_NONE, - NULL, - &error); + info = g_file_query_info (model->priv->root->file, + G_FILE_ATTRIBUTE_STANDARD_TYPE, + G_FILE_QUERY_INFO_NONE, + NULL, + &error); - if (!info) { - if (error->code == G_IO_ERROR_NOT_MOUNTED) { - /* Try to mount it */ - FILE_BROWSER_NODE_DIR (model->priv->root)->cancellable = g_cancellable_new (); + if (!info) + { + if (error->code == G_IO_ERROR_NOT_MOUNTED) + { + /* Try to mount it */ + FILE_BROWSER_NODE_DIR (model->priv->root)->cancellable = g_cancellable_new (); - mount_info = g_new(MountInfo, 1); - mount_info->model = model; - mount_info->virtual_root = g_strdup (virtual_root); + mount_info = g_new(MountInfo, 1); + mount_info->model = model; + mount_info->virtual_root = g_strdup (virtual_root); - /* FIXME: we should be setting the correct window */ - mount_info->operation = gtk_mount_operation_new (NULL); - mount_info->cancellable = g_object_ref (FILE_BROWSER_NODE_DIR (model->priv->root)->cancellable); + /* FIXME: we should be setting the correct window */ + mount_info->operation = gtk_mount_operation_new (NULL); + mount_info->cancellable = g_object_ref (FILE_BROWSER_NODE_DIR (model->priv->root)->cancellable); - model_begin_loading (model, model->priv->root); - g_file_mount_enclosing_volume (model->priv->root->file, - G_MOUNT_MOUNT_NONE, - mount_info->operation, - mount_info->cancellable, - (GAsyncReadyCallback)mount_cb, - mount_info); + model_begin_loading (model, model->priv->root); + g_file_mount_enclosing_volume (model->priv->root->file, + G_MOUNT_MOUNT_NONE, + mount_info->operation, + mount_info->cancellable, + (GAsyncReadyCallback)mount_cb, + mount_info); - model->priv->mount_info = mount_info; - return XED_FILE_BROWSER_STORE_RESULT_MOUNTING; - } - else - { - handle_root_error (model, error); - } + model->priv->mount_info = mount_info; + return XED_FILE_BROWSER_STORE_RESULT_MOUNTING; + } + else + { + handle_root_error (model, error); + } - g_error_free (error); - } else { - g_object_unref (info); + g_error_free (error); + } + else + { + g_object_unref (info); - return model_root_mounted (model, virtual_root); - } + return model_root_mounted (model, virtual_root); + } - return XED_FILE_BROWSER_STORE_RESULT_OK; + return XED_FILE_BROWSER_STORE_RESULT_OK; } /* Public */ XedFileBrowserStore * xed_file_browser_store_new (gchar const *root) { - XedFileBrowserStore *obj = - XED_FILE_BROWSER_STORE (g_object_new - (XED_TYPE_FILE_BROWSER_STORE, - NULL)); + XedFileBrowserStore *obj = XED_FILE_BROWSER_STORE (g_object_new (XED_TYPE_FILE_BROWSER_STORE, NULL)); - xed_file_browser_store_set_root (obj, root); - return obj; + xed_file_browser_store_set_root (obj, root); + return obj; } void -xed_file_browser_store_set_value (XedFileBrowserStore * tree_model, - GtkTreeIter * iter, gint column, - GValue * value) +xed_file_browser_store_set_value (XedFileBrowserStore *tree_model, + GtkTreeIter *iter, gint column, + GValue *value) { - gpointer data; - FileBrowserNode *node; - GtkTreePath *path; + gpointer data; + FileBrowserNode *node; + GtkTreePath *path; - g_return_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model)); - g_return_if_fail (column == - XED_FILE_BROWSER_STORE_COLUMN_EMBLEM); - g_return_if_fail (G_VALUE_HOLDS_OBJECT (value)); - g_return_if_fail (iter != NULL); - g_return_if_fail (iter->user_data != NULL); + g_return_if_fail (XED_IS_FILE_BROWSER_STORE (tree_model)); + g_return_if_fail (column == XED_FILE_BROWSER_STORE_COLUMN_EMBLEM); + g_return_if_fail (G_VALUE_HOLDS_OBJECT (value)); + g_return_if_fail (iter != NULL); + g_return_if_fail (iter->user_data != NULL); - data = g_value_get_object (value); + data = g_value_get_object (value); - if (data) - g_return_if_fail (GDK_IS_PIXBUF (data)); + if (data) + { + g_return_if_fail (GDK_IS_PIXBUF (data)); + } - node = (FileBrowserNode *) (iter->user_data); + node = (FileBrowserNode *) (iter->user_data); - if (node->emblem) - g_object_unref (node->emblem); + if (node->emblem) + { + g_object_unref (node->emblem); + } - if (data) - node->emblem = g_object_ref (GDK_PIXBUF (data)); - else - node->emblem = NULL; + if (data) + { + node->emblem = g_object_ref (GDK_PIXBUF (data)); + } + else + { + node->emblem = NULL; + } - model_recomposite_icon (tree_model, iter); + model_recomposite_icon (tree_model, iter); - if (model_node_visibility (tree_model, node)) { - path = xed_file_browser_store_get_path (GTK_TREE_MODEL (tree_model), - iter); - row_changed (tree_model, &path, iter); - gtk_tree_path_free (path); - } + if (model_node_visibility (tree_model, node)) + { + path = xed_file_browser_store_get_path (GTK_TREE_MODEL (tree_model), iter); + row_changed (tree_model, &path, iter); + gtk_tree_path_free (path); + } } XedFileBrowserStoreResult -xed_file_browser_store_set_virtual_root (XedFileBrowserStore * model, - GtkTreeIter * iter) +xed_file_browser_store_set_virtual_root (XedFileBrowserStore *model, + GtkTreeIter *iter) { - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), - XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); - g_return_val_if_fail (iter != NULL, - XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); - g_return_val_if_fail (iter->user_data != NULL, - XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); + g_return_val_if_fail (iter != NULL, XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); + g_return_val_if_fail (iter->user_data != NULL, XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); - model_clear (model, FALSE); - set_virtual_root_from_node (model, - (FileBrowserNode *) (iter->user_data)); + model_clear (model, FALSE); + set_virtual_root_from_node (model, (FileBrowserNode *) (iter->user_data)); - return TRUE; + return TRUE; } XedFileBrowserStoreResult -xed_file_browser_store_set_virtual_root_from_string - (XedFileBrowserStore * model, gchar const *root) { - GFile *file; +xed_file_browser_store_set_virtual_root_from_string (XedFileBrowserStore *model, + gchar const *root) +{ + GFile *file; - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), - XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); - file = g_file_new_for_uri (root); - if (file == NULL) { - g_warning ("Invalid uri (%s)", root); - return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; - } + file = g_file_new_for_uri (root); + if (file == NULL) + { + g_warning ("Invalid uri (%s)", root); + return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; + } - /* Check if uri is already the virtual root */ - if (model->priv->virtual_root && - g_file_equal (model->priv->virtual_root->file, file)) { - g_object_unref (file); - return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; - } + /* Check if uri is already the virtual root */ + if (model->priv->virtual_root && g_file_equal (model->priv->virtual_root->file, file)) + { + g_object_unref (file); + return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; + } - /* Check if uri is the root itself */ - if (g_file_equal (model->priv->root->file, file)) { - g_object_unref (file); + /* Check if uri is the root itself */ + if (g_file_equal (model->priv->root->file, file)) + { + g_object_unref (file); - /* Always clear the model before altering the nodes */ - model_clear (model, FALSE); - set_virtual_root_from_node (model, model->priv->root); - return XED_FILE_BROWSER_STORE_RESULT_OK; - } + /* Always clear the model before altering the nodes */ + model_clear (model, FALSE); + set_virtual_root_from_node (model, model->priv->root); + return XED_FILE_BROWSER_STORE_RESULT_OK; + } - if (!g_file_has_prefix (file, model->priv->root->file)) { - gchar *str, *str1; + if (!g_file_has_prefix (file, model->priv->root->file)) + { + gchar *str, *str1; - str = g_file_get_parse_name (model->priv->root->file); - str1 = g_file_get_parse_name (file); + str = g_file_get_parse_name (model->priv->root->file); + str1 = g_file_get_parse_name (file); - g_warning - ("Virtual root (%s) is not below actual root (%s)", - str1, str); + g_warning ("Virtual root (%s) is not below actual root (%s)", str1, str); - g_free (str); - g_free (str1); + g_free (str); + g_free (str1); - g_object_unref (file); - return XED_FILE_BROWSER_STORE_RESULT_ERROR; - } + g_object_unref (file); + return XED_FILE_BROWSER_STORE_RESULT_ERROR; + } - set_virtual_root_from_file (model, file); - g_object_unref (file); + set_virtual_root_from_file (model, file); + g_object_unref (file); - return XED_FILE_BROWSER_STORE_RESULT_OK; + return XED_FILE_BROWSER_STORE_RESULT_OK; } XedFileBrowserStoreResult -xed_file_browser_store_set_virtual_root_top (XedFileBrowserStore * - model) +xed_file_browser_store_set_virtual_root_top (XedFileBrowserStore *model) { - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), - XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); - if (model->priv->virtual_root == model->priv->root) - return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; + if (model->priv->virtual_root == model->priv->root) + { + return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; + } - model_clear (model, FALSE); - set_virtual_root_from_node (model, model->priv->root); + model_clear (model, FALSE); + set_virtual_root_from_node (model, model->priv->root); - return XED_FILE_BROWSER_STORE_RESULT_OK; + return XED_FILE_BROWSER_STORE_RESULT_OK; } XedFileBrowserStoreResult -xed_file_browser_store_set_virtual_root_up (XedFileBrowserStore * - model) +xed_file_browser_store_set_virtual_root_up (XedFileBrowserStore *model) { - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), - XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); - if (model->priv->virtual_root == model->priv->root) - return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; + if (model->priv->virtual_root == model->priv->root) + { + return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; + } - model_clear (model, FALSE); - set_virtual_root_from_node (model, - model->priv->virtual_root->parent); + model_clear (model, FALSE); + set_virtual_root_from_node (model, model->priv->virtual_root->parent); - return XED_FILE_BROWSER_STORE_RESULT_OK; + return XED_FILE_BROWSER_STORE_RESULT_OK; } gboolean -xed_file_browser_store_get_iter_virtual_root (XedFileBrowserStore * - model, GtkTreeIter * iter) +xed_file_browser_store_get_iter_virtual_root (XedFileBrowserStore *model, + GtkTreeIter *iter) { - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), FALSE); - g_return_val_if_fail (iter != NULL, FALSE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), FALSE); + g_return_val_if_fail (iter != NULL, FALSE); - if (model->priv->virtual_root == NULL) - return FALSE; + if (model->priv->virtual_root == NULL) + { + return FALSE; + } - iter->user_data = model->priv->virtual_root; - return TRUE; + iter->user_data = model->priv->virtual_root; + return TRUE; } gboolean -xed_file_browser_store_get_iter_root (XedFileBrowserStore * model, - GtkTreeIter * iter) +xed_file_browser_store_get_iter_root (XedFileBrowserStore *model, + GtkTreeIter *iter) { - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), FALSE); - g_return_val_if_fail (iter != NULL, FALSE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), FALSE); + g_return_val_if_fail (iter != NULL, FALSE); - if (model->priv->root == NULL) - return FALSE; + if (model->priv->root == NULL) + { + return FALSE; + } - iter->user_data = model->priv->root; - return TRUE; + iter->user_data = model->priv->root; + return TRUE; } gboolean -xed_file_browser_store_iter_equal (XedFileBrowserStore * model, - GtkTreeIter * iter1, - GtkTreeIter * iter2) +xed_file_browser_store_iter_equal (XedFileBrowserStore *model, + GtkTreeIter *iter1, + GtkTreeIter *iter2) { - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), FALSE); - g_return_val_if_fail (iter1 != NULL, FALSE); - g_return_val_if_fail (iter2 != NULL, FALSE); - g_return_val_if_fail (iter1->user_data != NULL, FALSE); - g_return_val_if_fail (iter2->user_data != NULL, FALSE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), FALSE); + g_return_val_if_fail (iter1 != NULL, FALSE); + g_return_val_if_fail (iter2 != NULL, FALSE); + g_return_val_if_fail (iter1->user_data != NULL, FALSE); + g_return_val_if_fail (iter2->user_data != NULL, FALSE); - return (iter1->user_data == iter2->user_data); + return (iter1->user_data == iter2->user_data); } void xed_file_browser_store_cancel_mount_operation (XedFileBrowserStore *store) { - g_return_if_fail (XED_IS_FILE_BROWSER_STORE (store)); + g_return_if_fail (XED_IS_FILE_BROWSER_STORE (store)); - cancel_mount_operation (store); + cancel_mount_operation (store); } XedFileBrowserStoreResult -xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore * - model, - gchar const *root, - gchar const *virtual_root) +xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore *model, + gchar const *root, + gchar const *virtual_root) { - GFile * file = NULL; - GFile * vfile = NULL; - FileBrowserNode * node; - gboolean equal = FALSE; + GFile * file = NULL; + GFile * vfile = NULL; + FileBrowserNode * node; + gboolean equal = FALSE; - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), - XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); - if (root == NULL && model->priv->root == NULL) - return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; + if (root == NULL && model->priv->root == NULL) + { + return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; + } - if (root != NULL) { - file = g_file_new_for_uri (root); - } + if (root != NULL) + { + file = g_file_new_for_uri (root); + } - if (root != NULL && model->priv->root != NULL) { - equal = g_file_equal (file, model->priv->root->file); + if (root != NULL && model->priv->root != NULL) + { + equal = g_file_equal (file, model->priv->root->file); - if (equal && virtual_root == NULL) { - g_object_unref (file); - return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; - } - } + if (equal && virtual_root == NULL) + { + g_object_unref (file); + return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; + } + } - if (virtual_root) { - vfile = g_file_new_for_uri (virtual_root); + if (virtual_root) + { + vfile = g_file_new_for_uri (virtual_root); - if (equal && g_file_equal (vfile, model->priv->virtual_root->file)) { - if (file) - g_object_unref (file); + if (equal && g_file_equal (vfile, model->priv->virtual_root->file)) + { + if (file) + { + g_object_unref (file); + } - g_object_unref (vfile); - return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; - } + g_object_unref (vfile); + return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; + } - g_object_unref (vfile); - } + g_object_unref (vfile); + } - /* make sure to cancel any previous mount operations */ - cancel_mount_operation (model); + /* make sure to cancel any previous mount operations */ + cancel_mount_operation (model); - /* Always clear the model before altering the nodes */ - model_clear (model, TRUE); - file_browser_node_free (model, model->priv->root); + /* Always clear the model before altering the nodes */ + model_clear (model, TRUE); + file_browser_node_free (model, model->priv->root); - model->priv->root = NULL; - model->priv->virtual_root = NULL; + model->priv->root = NULL; + model->priv->virtual_root = NULL; - if (file != NULL) { - /* Create the root node */ - node = file_browser_node_dir_new (model, file, NULL); + if (file != NULL) + { + /* Create the root node */ + node = file_browser_node_dir_new (model, file, NULL); - g_object_unref (file); + g_object_unref (file); - model->priv->root = node; - return model_mount_root (model, virtual_root); - } else { - g_object_notify (G_OBJECT (model), "root"); - g_object_notify (G_OBJECT (model), "virtual-root"); - } + model->priv->root = node; + return model_mount_root (model, virtual_root); + } + else + { + g_object_notify (G_OBJECT (model), "root"); + g_object_notify (G_OBJECT (model), "virtual-root"); + } - return XED_FILE_BROWSER_STORE_RESULT_OK; + return XED_FILE_BROWSER_STORE_RESULT_OK; } XedFileBrowserStoreResult -xed_file_browser_store_set_root (XedFileBrowserStore * model, - gchar const *root) +xed_file_browser_store_set_root (XedFileBrowserStore *model, + gchar const *root) { - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), - XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); - return xed_file_browser_store_set_root_and_virtual_root (model, - root, - NULL); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); + return xed_file_browser_store_set_root_and_virtual_root (model, root, NULL); } gchar * xed_file_browser_store_get_root (XedFileBrowserStore * model) { - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), NULL); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), NULL); - if (model->priv->root == NULL || model->priv->root->file == NULL) - return NULL; - else - return g_file_get_uri (model->priv->root->file); + if (model->priv->root == NULL || model->priv->root->file == NULL) + { + return NULL; + } + else + { + return g_file_get_uri (model->priv->root->file); + } } gchar * -xed_file_browser_store_get_virtual_root (XedFileBrowserStore * model) +xed_file_browser_store_get_virtual_root (XedFileBrowserStore *model) { - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), NULL); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), NULL); - if (model->priv->virtual_root == NULL || model->priv->virtual_root->file == NULL) - return NULL; - else - return g_file_get_uri (model->priv->virtual_root->file); + if (model->priv->virtual_root == NULL || model->priv->virtual_root->file == NULL) + { + return NULL; + } + else + { + return g_file_get_uri (model->priv->virtual_root->file); + } } void -_xed_file_browser_store_iter_expanded (XedFileBrowserStore * model, - GtkTreeIter * iter) +_xed_file_browser_store_iter_expanded (XedFileBrowserStore *model, + GtkTreeIter *iter) { - FileBrowserNode *node; + FileBrowserNode *node; - g_return_if_fail (XED_IS_FILE_BROWSER_STORE (model)); - g_return_if_fail (iter != NULL); - g_return_if_fail (iter->user_data != NULL); + g_return_if_fail (XED_IS_FILE_BROWSER_STORE (model)); + g_return_if_fail (iter != NULL); + g_return_if_fail (iter->user_data != NULL); - node = (FileBrowserNode *) (iter->user_data); + node = (FileBrowserNode *) (iter->user_data); - if (NODE_IS_DIR (node) && !NODE_LOADED (node)) { - /* Load it now */ - model_load_directory (model, node); - } + if (NODE_IS_DIR (node) && !NODE_LOADED (node)) + { + /* Load it now */ + model_load_directory (model, node); + } } void -_xed_file_browser_store_iter_collapsed (XedFileBrowserStore * model, - GtkTreeIter * iter) +_xed_file_browser_store_iter_collapsed (XedFileBrowserStore *model, + GtkTreeIter *iter) { - FileBrowserNode *node; - GSList *item; + FileBrowserNode *node; + GSList *item; - g_return_if_fail (XED_IS_FILE_BROWSER_STORE (model)); - g_return_if_fail (iter != NULL); - g_return_if_fail (iter->user_data != NULL); + g_return_if_fail (XED_IS_FILE_BROWSER_STORE (model)); + g_return_if_fail (iter != NULL); + g_return_if_fail (iter->user_data != NULL); - node = (FileBrowserNode *) (iter->user_data); + node = (FileBrowserNode *) (iter->user_data); - if (NODE_IS_DIR (node) && NODE_LOADED (node)) { - /* Unload children of the children, keeping 1 depth in cache */ + if (NODE_IS_DIR (node) && NODE_LOADED (node)) + { + /* Unload children of the children, keeping 1 depth in cache */ - for (item = FILE_BROWSER_NODE_DIR (node)->children; item; - item = item->next) { - node = (FileBrowserNode *) (item->data); + for (item = FILE_BROWSER_NODE_DIR (node)->children; item; item = item->next) + { + node = (FileBrowserNode *) (item->data); - if (NODE_IS_DIR (node) && NODE_LOADED (node)) { - file_browser_node_unload (model, node, - TRUE); - model_check_dummy (model, node); - } - } - } + if (NODE_IS_DIR (node) && NODE_LOADED (node)) + { + file_browser_node_unload (model, node, TRUE); + model_check_dummy (model, node); + } + } + } } XedFileBrowserStoreFilterMode -xed_file_browser_store_get_filter_mode (XedFileBrowserStore * model) +xed_file_browser_store_get_filter_mode (XedFileBrowserStore *model) { - return model->priv->filter_mode; + return model->priv->filter_mode; } void -xed_file_browser_store_set_filter_mode (XedFileBrowserStore * model, - XedFileBrowserStoreFilterMode - mode) +xed_file_browser_store_set_filter_mode (XedFileBrowserStore *model, + XedFileBrowserStoreFilterMode mode) { - g_return_if_fail (XED_IS_FILE_BROWSER_STORE (model)); + g_return_if_fail (XED_IS_FILE_BROWSER_STORE (model)); - if (model->priv->filter_mode == mode) - return; + if (model->priv->filter_mode == mode) + { + return; + } - model->priv->filter_mode = mode; - model_refilter (model); + model->priv->filter_mode = mode; + model_refilter (model); - g_object_notify (G_OBJECT (model), "filter-mode"); + g_object_notify (G_OBJECT (model), "filter-mode"); } void -xed_file_browser_store_set_filter_func (XedFileBrowserStore * model, - XedFileBrowserStoreFilterFunc - func, gpointer user_data) +xed_file_browser_store_set_filter_func (XedFileBrowserStore *model, + XedFileBrowserStoreFilterFunc func, + gpointer user_data) { - g_return_if_fail (XED_IS_FILE_BROWSER_STORE (model)); + g_return_if_fail (XED_IS_FILE_BROWSER_STORE (model)); - model->priv->filter_func = func; - model->priv->filter_user_data = user_data; - model_refilter (model); + model->priv->filter_func = func; + model->priv->filter_user_data = user_data; + model_refilter (model); } void -xed_file_browser_store_refilter (XedFileBrowserStore * model) +xed_file_browser_store_refilter (XedFileBrowserStore *model) { - model_refilter (model); + model_refilter (model); } XedFileBrowserStoreFilterMode xed_file_browser_store_filter_mode_get_default (void) { - return XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN; + return XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN; } void -xed_file_browser_store_refresh (XedFileBrowserStore * model) +xed_file_browser_store_refresh (XedFileBrowserStore *model) { - g_return_if_fail (XED_IS_FILE_BROWSER_STORE (model)); + g_return_if_fail (XED_IS_FILE_BROWSER_STORE (model)); - if (model->priv->root == NULL || model->priv->virtual_root == NULL) - return; + if (model->priv->root == NULL || model->priv->virtual_root == NULL) + { + return; + } - /* Clear the model */ - g_signal_emit (model, model_signals[BEGIN_REFRESH], 0); - file_browser_node_unload (model, model->priv->virtual_root, TRUE); - model_load_directory (model, model->priv->virtual_root); - g_signal_emit (model, model_signals[END_REFRESH], 0); + /* Clear the model */ + g_signal_emit (model, model_signals[BEGIN_REFRESH], 0); + file_browser_node_unload (model, model->priv->virtual_root, TRUE); + model_load_directory (model, model->priv->virtual_root); + g_signal_emit (model, model_signals[END_REFRESH], 0); } static void -reparent_node (FileBrowserNode * node, gboolean reparent) +reparent_node (FileBrowserNode *node, + gboolean reparent) { - FileBrowserNodeDir * dir; - GSList * child; - GFile * parent; - gchar * base; + FileBrowserNodeDir *dir; + GSList *child; + GFile *parent; + gchar *base; - if (!node->file) { - return; - } + if (!node->file) + { + return; + } - if (reparent) { - parent = node->parent->file; - base = g_file_get_basename (node->file); - g_object_unref (node->file); + if (reparent) + { + parent = node->parent->file; + base = g_file_get_basename (node->file); + g_object_unref (node->file); - node->file = g_file_get_child (parent, base); - g_free (base); - } + node->file = g_file_get_child (parent, base); + g_free (base); + } - if (NODE_IS_DIR (node)) { - dir = FILE_BROWSER_NODE_DIR (node); + if (NODE_IS_DIR (node)) + { + dir = FILE_BROWSER_NODE_DIR (node); - for (child = dir->children; child; child = child->next) { - reparent_node ((FileBrowserNode *)child->data, TRUE); - } - } + for (child = dir->children; child; child = child->next) + { + reparent_node ((FileBrowserNode *)child->data, TRUE); + } + } } gboolean -xed_file_browser_store_rename (XedFileBrowserStore * model, - GtkTreeIter * iter, - const gchar * new_name, - GError ** error) +xed_file_browser_store_rename (XedFileBrowserStore *model, + GtkTreeIter *iter, + const gchar *new_name, + GError **error) { - FileBrowserNode *node; - GFile * file; - GFile * parent; - GFile * previous; - GError * err = NULL; - gchar * olduri; - gchar * newuri; - GtkTreePath *path; + FileBrowserNode *node; + GFile *file; + GFile *parent; + GFile *previous; + GError *err = NULL; + gchar *olduri; + gchar *newuri; + GtkTreePath *path; - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), FALSE); - g_return_val_if_fail (iter != NULL, FALSE); - g_return_val_if_fail (iter->user_data != NULL, FALSE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), FALSE); + g_return_val_if_fail (iter != NULL, FALSE); + g_return_val_if_fail (iter->user_data != NULL, FALSE); - node = (FileBrowserNode *) (iter->user_data); + node = (FileBrowserNode *) (iter->user_data); - parent = g_file_get_parent (node->file); - g_return_val_if_fail (parent != NULL, FALSE); + parent = g_file_get_parent (node->file); + g_return_val_if_fail (parent != NULL, FALSE); - file = g_file_get_child (parent, new_name); - g_object_unref (parent); + file = g_file_get_child (parent, new_name); + g_object_unref (parent); - if (g_file_equal (node->file, file)) { - g_object_unref (file); - return TRUE; - } + if (g_file_equal (node->file, file)) \ + { + g_object_unref (file); + return TRUE; + } - if (g_file_move (node->file, file, G_FILE_COPY_NONE, NULL, NULL, NULL, &err)) { - previous = node->file; - node->file = file; + if (g_file_move (node->file, file, G_FILE_COPY_NONE, NULL, NULL, NULL, &err)) + { + previous = node->file; + node->file = file; - /* This makes sure the actual info for the node is requeried */ - file_browser_node_set_name (node); - file_browser_node_set_from_info (model, node, NULL, TRUE); + /* This makes sure the actual info for the node is requeried */ + file_browser_node_set_name (node); + file_browser_node_set_from_info (model, node, NULL, TRUE); - reparent_node (node, FALSE); + reparent_node (node, FALSE); - if (model_node_visibility (model, node)) { - path = xed_file_browser_store_get_path_real (model, node); - row_changed (model, &path, iter); - gtk_tree_path_free (path); + if (model_node_visibility (model, node)) + { + path = xed_file_browser_store_get_path_real (model, node); + row_changed (model, &path, iter); + gtk_tree_path_free (path); - /* Reorder this item */ - model_resort_node (model, node); - } else { - g_object_unref (previous); + /* Reorder this item */ + model_resort_node (model, node); + } + else + { + g_object_unref (previous); - if (error != NULL) - *error = g_error_new_literal (xed_file_browser_store_error_quark (), - XED_FILE_BROWSER_ERROR_RENAME, - _("The renamed file is currently filtered out. You need to adjust your filter settings to make the file visible")); - return FALSE; - } + if (error != NULL) + { + *error = g_error_new_literal (xed_file_browser_store_error_quark (), + XED_FILE_BROWSER_ERROR_RENAME, + _("The renamed file is currently filtered out. You need to adjust your filter settings to make the file visible")); + } + return FALSE; + } - olduri = g_file_get_uri (previous); - newuri = g_file_get_uri (node->file); + olduri = g_file_get_uri (previous); + newuri = g_file_get_uri (node->file); - g_signal_emit (model, model_signals[RENAME], 0, olduri, newuri); + g_signal_emit (model, model_signals[RENAME], 0, olduri, newuri); - g_object_unref (previous); - g_free (olduri); - g_free (newuri); + g_object_unref (previous); + g_free (olduri); + g_free (newuri); - return TRUE; - } else { - g_object_unref (file); + return TRUE; + } + else + { + g_object_unref (file); - if (err) { - if (error != NULL) { - *error = - g_error_new_literal - (xed_file_browser_store_error_quark (), - XED_FILE_BROWSER_ERROR_RENAME, - err->message); - } + if (err) + { + if (error != NULL) + { + *error = g_error_new_literal (xed_file_browser_store_error_quark (), + XED_FILE_BROWSER_ERROR_RENAME, + err->message); + } - g_error_free (err); - } + g_error_free (err); + } - return FALSE; - } + return FALSE; + } } static void -async_data_free (AsyncData * data) +async_data_free (AsyncData *data) { - g_object_unref (data->cancellable); + g_object_unref (data->cancellable); - g_list_foreach (data->files, (GFunc)g_object_unref, NULL); - g_list_free (data->files); + g_list_foreach (data->files, (GFunc)g_object_unref, NULL); + g_list_free (data->files); - if (!data->removed) - data->model->priv->async_handles = g_slist_remove (data->model->priv->async_handles, data); + if (!data->removed) + { + data->model->priv->async_handles = g_slist_remove (data->model->priv->async_handles, data); + } - g_free (data); + g_free (data); } static gboolean -emit_no_trash (AsyncData * data) +emit_no_trash (AsyncData *data) { - /* Emit the no trash error */ - gboolean ret; + /* Emit the no trash error */ + gboolean ret; - g_signal_emit (data->model, model_signals[NO_TRASH], 0, data->files, &ret); - return ret; + g_signal_emit (data->model, model_signals[NO_TRASH], 0, data->files, &ret); + return ret; } -typedef struct { - XedFileBrowserStore * model; - GFile * file; +typedef struct +{ + XedFileBrowserStore *model; + GFile *file; } IdleDelete; static gboolean -file_deleted (IdleDelete * data) +file_deleted (IdleDelete *data) { - FileBrowserNode * node; - node = model_find_node (data->model, NULL, data->file); + FileBrowserNode *node; + node = model_find_node (data->model, NULL, data->file); - if (node != NULL) - model_remove_node (data->model, node, NULL, TRUE); + if (node != NULL) + { + model_remove_node (data->model, node, NULL, TRUE); + } - return FALSE; + return FALSE; } static gboolean -delete_files (GIOSchedulerJob * job, - GCancellable * cancellable, - AsyncData * data) +delete_files (GIOSchedulerJob *job, + GCancellable *cancellable, + AsyncData *data) { - GFile * file; - GError * error = NULL; - gboolean ret; - gint code; - IdleDelete delete; + GFile *file; + GError *error = NULL; + gboolean ret; + gint code; + IdleDelete delete; - /* Check if our job is done */ - if (!data->iter) - return FALSE; + /* Check if our job is done */ + if (!data->iter) + { + return FALSE; + } - /* Move a file to the trash */ - file = G_FILE (data->iter->data); + /* Move a file to the trash */ + file = G_FILE (data->iter->data); - if (data->trash) - ret = g_file_trash (file, cancellable, &error); - else - ret = g_file_delete (file, cancellable, &error); + if (data->trash) + { + ret = g_file_trash (file, cancellable, &error); + } + else + { + ret = g_file_delete (file, cancellable, &error); + } - if (ret) { - delete.model = data->model; - delete.file = file; + if (ret) + { + delete.model = data->model; + delete.file = file; - /* Remove the file from the model in the main loop */ - g_io_scheduler_job_send_to_mainloop (job, (GSourceFunc)file_deleted, &delete, NULL); - } else if (!ret && error) { - code = error->code; - g_error_free (error); + /* Remove the file from the model in the main loop */ + g_io_scheduler_job_send_to_mainloop (job, (GSourceFunc)file_deleted, &delete, NULL); + } + else if (!ret && error) + { + code = error->code; + g_error_free (error); - if (data->trash && code == G_IO_ERROR_NOT_SUPPORTED) { - /* Trash is not supported on this system ... */ - if (g_io_scheduler_job_send_to_mainloop (job, (GSourceFunc)emit_no_trash, data, NULL)) - { - /* Changes this into a delete job */ - data->trash = FALSE; - data->iter = data->files; + if (data->trash && code == G_IO_ERROR_NOT_SUPPORTED) + { + /* Trash is not supported on this system ... */ + if (g_io_scheduler_job_send_to_mainloop (job, (GSourceFunc)emit_no_trash, data, NULL)) + { + /* Changes this into a delete job */ + data->trash = FALSE; + data->iter = data->files; - return TRUE; - } + return TRUE; + } - /* End the job */ - return FALSE; - } else if (code == G_IO_ERROR_CANCELLED) { - /* Job has been cancelled, just let the job end */ - return FALSE; - } - } + /* End the job */ + return FALSE; + } + else if (code == G_IO_ERROR_CANCELLED) + { + /* Job has been cancelled, just let the job end */ + return FALSE; + } + } - /* Process the next item */ - data->iter = data->iter->next; - return TRUE; + /* Process the next item */ + data->iter = data->iter->next; + return TRUE; } XedFileBrowserStoreResult xed_file_browser_store_delete_all (XedFileBrowserStore *model, - GList *rows, gboolean trash) + GList *rows, + gboolean trash) { - FileBrowserNode * node; - AsyncData * data; - GList * files = NULL; - GList * row; - GtkTreeIter iter; - GtkTreePath * prev = NULL; - GtkTreePath * path; + FileBrowserNode *node; + AsyncData *data; + GList *files = NULL; + GList *row; + GtkTreeIter iter; + GtkTreePath *prev = NULL; + GtkTreePath *path; - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); - if (rows == NULL) - return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; + if (rows == NULL) + { + return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; + } - /* First we sort the paths so that we can later on remove any - files/directories that are actually subfiles/directories of - a directory that's also deleted */ - rows = g_list_sort (g_list_copy (rows), (GCompareFunc)gtk_tree_path_compare); + /* First we sort the paths so that we can later on remove any + files/directories that are actually subfiles/directories of + a directory that's also deleted */ + rows = g_list_sort (g_list_copy (rows), (GCompareFunc)gtk_tree_path_compare); - for (row = rows; row; row = row->next) { - path = (GtkTreePath *)(row->data); + for (row = rows; row; row = row->next) + { + path = (GtkTreePath *)(row->data); - if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path)) - continue; + if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path)) + { + continue; + } - /* Skip if the current path is actually a descendant of the - previous path */ - if (prev != NULL && gtk_tree_path_is_descendant (path, prev)) - continue; + /* Skip if the current path is actually a descendant of the + previous path */ + if (prev != NULL && gtk_tree_path_is_descendant (path, prev)) + { + continue; + } - prev = path; - node = (FileBrowserNode *)(iter.user_data); - files = g_list_prepend (files, g_object_ref (node->file)); - } + prev = path; + node = (FileBrowserNode *)(iter.user_data); + files = g_list_prepend (files, g_object_ref (node->file)); + } - data = g_new (AsyncData, 1); + data = g_new (AsyncData, 1); - data->model = model; - data->cancellable = g_cancellable_new (); - data->files = files; - data->trash = trash; - data->iter = files; - data->removed = FALSE; + data->model = model; + data->cancellable = g_cancellable_new (); + data->files = files; + data->trash = trash; + data->iter = files; + data->removed = FALSE; - model->priv->async_handles = - g_slist_prepend (model->priv->async_handles, data); + model->priv->async_handles = g_slist_prepend (model->priv->async_handles, data); - g_io_scheduler_push_job ((GIOSchedulerJobFunc)delete_files, - data, - (GDestroyNotify)async_data_free, - G_PRIORITY_DEFAULT, - data->cancellable); - g_list_free (rows); + g_io_scheduler_push_job ((GIOSchedulerJobFunc)delete_files, + data, + (GDestroyNotify)async_data_free, + G_PRIORITY_DEFAULT, + data->cancellable); + g_list_free (rows); - return XED_FILE_BROWSER_STORE_RESULT_OK; + return XED_FILE_BROWSER_STORE_RESULT_OK; } XedFileBrowserStoreResult -xed_file_browser_store_delete (XedFileBrowserStore * model, - GtkTreeIter * iter, gboolean trash) +xed_file_browser_store_delete (XedFileBrowserStore *model, + GtkTreeIter *iter, + gboolean trash) { - FileBrowserNode *node; - GList *rows = NULL; - XedFileBrowserStoreResult result; + FileBrowserNode *node; + GList *rows = NULL; + XedFileBrowserStoreResult result; - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); - g_return_val_if_fail (iter != NULL, XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); - g_return_val_if_fail (iter->user_data != NULL, XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); + g_return_val_if_fail (iter != NULL, XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); + g_return_val_if_fail (iter->user_data != NULL, XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); - node = (FileBrowserNode *) (iter->user_data); + node = (FileBrowserNode *) (iter->user_data); - if (NODE_IS_DUMMY (node)) - return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; + if (NODE_IS_DUMMY (node)) + { + return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; + } - rows = g_list_append(NULL, xed_file_browser_store_get_path_real (model, node)); - result = xed_file_browser_store_delete_all (model, rows, trash); + rows = g_list_append(NULL, xed_file_browser_store_get_path_real (model, node)); + result = xed_file_browser_store_delete_all (model, rows, trash); - g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL); - g_list_free (rows); + g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL); + g_list_free (rows); - return result; + return result; } gboolean -xed_file_browser_store_new_file (XedFileBrowserStore * model, - GtkTreeIter * parent, - GtkTreeIter * iter) +xed_file_browser_store_new_file (XedFileBrowserStore *model, + GtkTreeIter *parent, + GtkTreeIter *iter) { - GFile * file; - GFileOutputStream * stream; - FileBrowserNodeDir *parent_node; - gboolean result = FALSE; - FileBrowserNode *node; - GError * error = NULL; + GFile *file; + GFileOutputStream *stream; + FileBrowserNodeDir *parent_node; + gboolean result = FALSE; + FileBrowserNode *node; + GError *error = NULL; - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), FALSE); - g_return_val_if_fail (parent != NULL, FALSE); - g_return_val_if_fail (parent->user_data != NULL, FALSE); - g_return_val_if_fail (NODE_IS_DIR - ((FileBrowserNode *) (parent->user_data)), - FALSE); - g_return_val_if_fail (iter != NULL, FALSE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), FALSE); + g_return_val_if_fail (parent != NULL, FALSE); + g_return_val_if_fail (parent->user_data != NULL, FALSE); + g_return_val_if_fail (NODE_IS_DIR ((FileBrowserNode *) (parent->user_data)), FALSE); + g_return_val_if_fail (iter != NULL, FALSE); - parent_node = FILE_BROWSER_NODE_DIR (parent->user_data); - /* Translators: This is the default name of new files created by the file browser pane. */ - file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("file")); + parent_node = FILE_BROWSER_NODE_DIR (parent->user_data); + /* Translators: This is the default name of new files created by the file browser pane. */ + file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("file")); - stream = g_file_create (file, G_FILE_CREATE_NONE, NULL, &error); + stream = g_file_create (file, G_FILE_CREATE_NONE, NULL, &error); - if (!stream) - { - g_signal_emit (model, model_signals[ERROR], 0, - XED_FILE_BROWSER_ERROR_NEW_FILE, - error->message); - g_error_free (error); - } else { - g_object_unref (stream); - node = model_add_node_from_file (model, - (FileBrowserNode *)parent_node, - file, - NULL); + if (!stream) + { + g_signal_emit (model, model_signals[ERROR], 0, + XED_FILE_BROWSER_ERROR_NEW_FILE, + error->message); + g_error_free (error); + } + else + { + g_object_unref (stream); + node = model_add_node_from_file (model, + (FileBrowserNode *)parent_node, + file, + NULL); - if (model_node_visibility (model, node)) { - iter->user_data = node; - result = TRUE; - } else { - g_signal_emit (model, model_signals[ERROR], 0, - XED_FILE_BROWSER_ERROR_NEW_FILE, - _ - ("The new file is currently filtered out. You need to adjust your filter settings to make the file visible")); - } - } + if (model_node_visibility (model, node)) + { + iter->user_data = node; + result = TRUE; + } + else + { + g_signal_emit (model, model_signals[ERROR], 0, + XED_FILE_BROWSER_ERROR_NEW_FILE, + _("The new file is currently filtered out. You need to adjust your filter settings to make the file visible")); + } + } - g_object_unref (file); - return result; + g_object_unref (file); + return result; } gboolean -xed_file_browser_store_new_directory (XedFileBrowserStore * model, - GtkTreeIter * parent, - GtkTreeIter * iter) +xed_file_browser_store_new_directory (XedFileBrowserStore *model, + GtkTreeIter *parent, + GtkTreeIter *iter) { - GFile * file; - FileBrowserNodeDir *parent_node; - GError * error = NULL; - FileBrowserNode *node; - gboolean result = FALSE; + GFile *file; + FileBrowserNodeDir *parent_node; + GError *error = NULL; + FileBrowserNode *node; + gboolean result = FALSE; - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), FALSE); - g_return_val_if_fail (parent != NULL, FALSE); - g_return_val_if_fail (parent->user_data != NULL, FALSE); - g_return_val_if_fail (NODE_IS_DIR - ((FileBrowserNode *) (parent->user_data)), - FALSE); - g_return_val_if_fail (iter != NULL, FALSE); + g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), FALSE); + g_return_val_if_fail (parent != NULL, FALSE); + g_return_val_if_fail (parent->user_data != NULL, FALSE); + g_return_val_if_fail (NODE_IS_DIR ((FileBrowserNode *) (parent->user_data)), FALSE); + g_return_val_if_fail (iter != NULL, FALSE); - parent_node = FILE_BROWSER_NODE_DIR (parent->user_data); - /* Translators: This is the default name of new directories created by the file browser pane. */ - file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("directory")); + parent_node = FILE_BROWSER_NODE_DIR (parent->user_data); + /* Translators: This is the default name of new directories created by the file browser pane. */ + file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("directory")); - if (!g_file_make_directory (file, NULL, &error)) { - g_signal_emit (model, model_signals[ERROR], 0, - XED_FILE_BROWSER_ERROR_NEW_DIRECTORY, - error->message); - g_error_free (error); - } else { - node = model_add_node_from_file (model, - (FileBrowserNode *)parent_node, - file, - NULL); + if (!g_file_make_directory (file, NULL, &error)) + { + g_signal_emit (model, model_signals[ERROR], 0, + XED_FILE_BROWSER_ERROR_NEW_DIRECTORY, + error->message); + g_error_free (error); + } + else + { + node = model_add_node_from_file (model, + (FileBrowserNode *)parent_node, + file, + NULL); - if (model_node_visibility (model, node)) { - iter->user_data = node; - result = TRUE; - } else { - g_signal_emit (model, model_signals[ERROR], 0, - XED_FILE_BROWSER_ERROR_NEW_FILE, - _ - ("The new directory is currently filtered out. You need to adjust your filter settings to make the directory visible")); - } - } + if (model_node_visibility (model, node)) + { + iter->user_data = node; + result = TRUE; + } + else + { + g_signal_emit (model, model_signals[ERROR], 0, + XED_FILE_BROWSER_ERROR_NEW_FILE, + _("The new directory is currently filtered out. You need to adjust your filter settings to make the directory visible")); + } + } - g_object_unref (file); - return result; + g_object_unref (file); + return result; } void diff --git a/plugins/filebrowser/xed-file-browser-store.h b/plugins/filebrowser/xed-file-browser-store.h index 28c3e5c..03e3124 100644 --- a/plugins/filebrowser/xed-file-browser-store.h +++ b/plugins/filebrowser/xed-file-browser-store.h @@ -81,10 +81,9 @@ typedef struct _XedFileBrowserStore XedFileBrowserStore; typedef struct _XedFileBrowserStoreClass XedFileBrowserStoreClass; typedef struct _XedFileBrowserStorePrivate XedFileBrowserStorePrivate; -typedef gboolean (*XedFileBrowserStoreFilterFunc) (XedFileBrowserStore - * model, - GtkTreeIter * iter, - gpointer user_data); +typedef gboolean (*XedFileBrowserStoreFilterFunc) (XedFileBrowserStore *model, + GtkTreeIter *iter, + gpointer user_data); struct _XedFileBrowserStore { @@ -97,102 +96,91 @@ struct _XedFileBrowserStoreClass { GObjectClass parent_class; /* Signals */ - void (*begin_loading) (XedFileBrowserStore * model, - GtkTreeIter * iter); - void (*end_loading) (XedFileBrowserStore * model, - GtkTreeIter * iter); - void (*error) (XedFileBrowserStore * model, - guint code, - gchar * message); - gboolean (*no_trash) (XedFileBrowserStore * model, - GList * files); - void (*rename) (XedFileBrowserStore * model, - const gchar * olduri, - const gchar * newuri); - void (*begin_refresh) (XedFileBrowserStore * model); - void (*end_refresh) (XedFileBrowserStore * model); - void (*unload) (XedFileBrowserStore * model, - const gchar * uri); + void (*begin_loading) (XedFileBrowserStore *model, + GtkTreeIter *iter); + void (*end_loading) (XedFileBrowserStore *model, + GtkTreeIter *iter); + void (*error) (XedFileBrowserStore *model, + guint code, + gchar *message); + gboolean (*no_trash) (XedFileBrowserStore *model, + GList *files); + void (*rename) (XedFileBrowserStore *model, + const gchar *olduri, + const gchar *newuri); + void (*begin_refresh) (XedFileBrowserStore *model); + void (*end_refresh) (XedFileBrowserStore *model); + void (*unload) (XedFileBrowserStore *model, + const gchar *uri); }; -GType xed_file_browser_store_get_type (void) G_GNUC_CONST; -void _xed_file_browser_store_register_type (GTypeModule * module); +GType xed_file_browser_store_get_type (void) G_GNUC_CONST; +void _xed_file_browser_store_register_type (GTypeModule *type_module); -XedFileBrowserStore *xed_file_browser_store_new (gchar const *root); +XedFileBrowserStore *xed_file_browser_store_new (gchar const *root); -XedFileBrowserStoreResult -xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore * model, - gchar const *root, - gchar const *virtual_root); -XedFileBrowserStoreResult -xed_file_browser_store_set_root (XedFileBrowserStore * model, - gchar const *root); -XedFileBrowserStoreResult -xed_file_browser_store_set_virtual_root (XedFileBrowserStore * model, - GtkTreeIter * iter); -XedFileBrowserStoreResult -xed_file_browser_store_set_virtual_root_from_string (XedFileBrowserStore * model, - gchar const *root); -XedFileBrowserStoreResult -xed_file_browser_store_set_virtual_root_up (XedFileBrowserStore * model); -XedFileBrowserStoreResult -xed_file_browser_store_set_virtual_root_top (XedFileBrowserStore * model); +XedFileBrowserStoreResult xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore *model, + gchar const *root, + gchar const *virtual_root); +XedFileBrowserStoreResult xed_file_browser_store_set_root (XedFileBrowserStore *model, + gchar const *root); +XedFileBrowserStoreResult xed_file_browser_store_set_virtual_root (XedFileBrowserStore *model, + GtkTreeIter *iter); +XedFileBrowserStoreResult xed_file_browser_store_set_virtual_root_from_string (XedFileBrowserStore *model, + gchar const *root); +XedFileBrowserStoreResult xed_file_browser_store_set_virtual_root_up (XedFileBrowserStore *model); +XedFileBrowserStoreResult xed_file_browser_store_set_virtual_root_top (XedFileBrowserStore *model); -gboolean -xed_file_browser_store_get_iter_virtual_root (XedFileBrowserStore * model, - GtkTreeIter * iter); -gboolean xed_file_browser_store_get_iter_root (XedFileBrowserStore * model, - GtkTreeIter * iter); -gchar * xed_file_browser_store_get_root (XedFileBrowserStore * model); -gchar * xed_file_browser_store_get_virtual_root (XedFileBrowserStore * model); +gboolean xed_file_browser_store_get_iter_virtual_root (XedFileBrowserStore *model, + GtkTreeIter *iter); +gboolean xed_file_browser_store_get_iter_root (XedFileBrowserStore *model, + GtkTreeIter *iter); +gchar * xed_file_browser_store_get_root (XedFileBrowserStore *model); +gchar * xed_file_browser_store_get_virtual_root (XedFileBrowserStore *model); -gboolean xed_file_browser_store_iter_equal (XedFileBrowserStore * model, - GtkTreeIter * iter1, - GtkTreeIter * iter2); +gboolean xed_file_browser_store_iter_equal (XedFileBrowserStore *model, + GtkTreeIter *iter1, + GtkTreeIter *iter2); -void xed_file_browser_store_set_value (XedFileBrowserStore * tree_model, - GtkTreeIter * iter, - gint column, - GValue * value); +void xed_file_browser_store_set_value (XedFileBrowserStore *tree_model, + GtkTreeIter *iter, + gint column, + GValue *value); -void _xed_file_browser_store_iter_expanded (XedFileBrowserStore * model, - GtkTreeIter * iter); -void _xed_file_browser_store_iter_collapsed (XedFileBrowserStore * model, - GtkTreeIter * iter); +void _xed_file_browser_store_iter_expanded (XedFileBrowserStore *model, + GtkTreeIter *iter); +void _xed_file_browser_store_iter_collapsed (XedFileBrowserStore *model, + GtkTreeIter *iter); -XedFileBrowserStoreFilterMode -xed_file_browser_store_get_filter_mode (XedFileBrowserStore * model); -void xed_file_browser_store_set_filter_mode (XedFileBrowserStore * model, - XedFileBrowserStoreFilterMode mode); -void xed_file_browser_store_set_filter_func (XedFileBrowserStore * model, - XedFileBrowserStoreFilterFunc func, - gpointer user_data); -void xed_file_browser_store_refilter (XedFileBrowserStore * model); -XedFileBrowserStoreFilterMode -xed_file_browser_store_filter_mode_get_default (void); +XedFileBrowserStoreFilterMode xed_file_browser_store_get_filter_mode (XedFileBrowserStore *model); +void xed_file_browser_store_set_filter_mode (XedFileBrowserStore *model, + XedFileBrowserStoreFilterMode mode); +void xed_file_browser_store_set_filter_func (XedFileBrowserStore *model, + XedFileBrowserStoreFilterFunc func, + gpointer user_data); +void xed_file_browser_store_refilter (XedFileBrowserStore *model); +XedFileBrowserStoreFilterMode xed_file_browser_store_filter_mode_get_default (void); -void xed_file_browser_store_refresh (XedFileBrowserStore * model); -gboolean xed_file_browser_store_rename (XedFileBrowserStore * model, - GtkTreeIter * iter, - gchar const *new_name, - GError ** error); -XedFileBrowserStoreResult -xed_file_browser_store_delete (XedFileBrowserStore * model, - GtkTreeIter * iter, - gboolean trash); -XedFileBrowserStoreResult -xed_file_browser_store_delete_all (XedFileBrowserStore * model, - GList *rows, - gboolean trash); +void xed_file_browser_store_refresh (XedFileBrowserStore * model); +gboolean xed_file_browser_store_rename (XedFileBrowserStore *model, + GtkTreeIter *iter, + gchar const *new_name, + GError **error); +XedFileBrowserStoreResult xed_file_browser_store_delete (XedFileBrowserStore *model, + GtkTreeIter *iter, + gboolean trash); +XedFileBrowserStoreResult xed_file_browser_store_delete_all (XedFileBrowserStore *model, + GList *rows, + gboolean trash); -gboolean xed_file_browser_store_new_file (XedFileBrowserStore * model, - GtkTreeIter * parent, - GtkTreeIter * iter); -gboolean xed_file_browser_store_new_directory (XedFileBrowserStore * model, - GtkTreeIter * parent, - GtkTreeIter * iter); +gboolean xed_file_browser_store_new_file (XedFileBrowserStore *model, + GtkTreeIter *parent, + GtkTreeIter *iter); +gboolean xed_file_browser_store_new_directory (XedFileBrowserStore *model, + GtkTreeIter *parent, + GtkTreeIter *iter); -void xed_file_browser_store_cancel_mount_operation (XedFileBrowserStore *store); +void xed_file_browser_store_cancel_mount_operation (XedFileBrowserStore *store); G_END_DECLS #endif /* __XED_FILE_BROWSER_STORE_H__ */ diff --git a/plugins/filebrowser/xed-file-browser-view.c b/plugins/filebrowser/xed-file-browser-view.c index 80f3798..f412e2a 100644 --- a/plugins/filebrowser/xed-file-browser-view.c +++ b/plugins/filebrowser/xed-file-browser-view.c @@ -20,6 +20,7 @@ */ #include +#include #include #include #include @@ -31,882 +32,953 @@ #include "xed-file-browser-enum-types.h" #define XED_FILE_BROWSER_VIEW_GET_PRIVATE(object)( \ - G_TYPE_INSTANCE_GET_PRIVATE((object), \ - XED_TYPE_FILE_BROWSER_VIEW, XedFileBrowserViewPrivate)) + G_TYPE_INSTANCE_GET_PRIVATE((object), \ + XED_TYPE_FILE_BROWSER_VIEW, XedFileBrowserViewPrivate)) struct _XedFileBrowserViewPrivate { - GtkTreeViewColumn *column; - GtkCellRenderer *pixbuf_renderer; - GtkCellRenderer *text_renderer; + GtkTreeViewColumn *column; + GtkCellRenderer *pixbuf_renderer; + GtkCellRenderer *text_renderer; - GtkTreeModel *model; - GtkTreeRowReference *editable; + GtkTreeModel *model; + GtkTreeRowReference *editable; - GdkCursor *busy_cursor; + GdkCursor *busy_cursor; - /* CLick policy */ - XedFileBrowserViewClickPolicy click_policy; - GtkTreePath *double_click_path[2]; /* Both clicks in a double click need to be on the same row */ - GtkTreePath *hover_path; - GdkCursor *hand_cursor; - gboolean ignore_release; - gboolean selected_on_button_down; - gint drag_button; - gboolean drag_started; + /* CLick policy */ + XedFileBrowserViewClickPolicy click_policy; + GtkTreePath *double_click_path[2]; /* Both clicks in a double click need to be on the same row */ + GtkTreePath *hover_path; + GdkCursor *hand_cursor; + gboolean ignore_release; + gboolean selected_on_button_down; + gint drag_button; + gboolean drag_started; - gboolean restore_expand_state; - gboolean is_refresh; - GHashTable * expand_state; + gboolean restore_expand_state; + gboolean is_refresh; + GHashTable * expand_state; }; /* Properties */ enum { - PROP_0, + PROP_0, - PROP_CLICK_POLICY, - PROP_RESTORE_EXPAND_STATE + PROP_CLICK_POLICY, + PROP_RESTORE_EXPAND_STATE }; /* Signals */ enum { - ERROR, - FILE_ACTIVATED, - DIRECTORY_ACTIVATED, - BOOKMARK_ACTIVATED, - NUM_SIGNALS + ERROR, + FILE_ACTIVATED, + DIRECTORY_ACTIVATED, + BOOKMARK_ACTIVATED, + NUM_SIGNALS }; static guint signals[NUM_SIGNALS] = { 0 }; static const GtkTargetEntry drag_source_targets[] = { - { "text/uri-list", 0, 0 } + { "text/uri-list", 0, 0 } }; -G_DEFINE_DYNAMIC_TYPE (XedFileBrowserView, xed_file_browser_view, - GTK_TYPE_TREE_VIEW) +G_DEFINE_DYNAMIC_TYPE (XedFileBrowserView, xed_file_browser_view, GTK_TYPE_TREE_VIEW) -static void on_cell_edited (GtkCellRendererText * cell, - gchar * path, - gchar * new_text, - XedFileBrowserView * tree_view); +static void on_cell_edited (GtkCellRendererText *cell, + gchar *path, + gchar *new_text, + XedFileBrowserView *tree_view); -static void on_begin_refresh (XedFileBrowserStore * model, - XedFileBrowserView * view); -static void on_end_refresh (XedFileBrowserStore * model, - XedFileBrowserView * view); +static void on_begin_refresh (XedFileBrowserStore *model, + XedFileBrowserView *view); +static void on_end_refresh (XedFileBrowserStore *model, + XedFileBrowserView *view); -static void on_unload (XedFileBrowserStore * model, - gchar const * uri, - XedFileBrowserView * view); +static void on_unload (XedFileBrowserStore *model, + gchar const *uri, + XedFileBrowserView *view); -static void on_row_inserted (XedFileBrowserStore * model, - GtkTreePath * path, - GtkTreeIter * iter, - XedFileBrowserView * view); +static void on_row_inserted (XedFileBrowserStore *model, + GtkTreePath *path, + GtkTreeIter *iter, + XedFileBrowserView *view); static void -xed_file_browser_view_finalize (GObject * object) +xed_file_browser_view_finalize (GObject *object) { - XedFileBrowserView *obj = XED_FILE_BROWSER_VIEW(object); + XedFileBrowserView *obj = XED_FILE_BROWSER_VIEW(object); - if (obj->priv->hand_cursor) - g_object_unref (obj->priv->hand_cursor); + if (obj->priv->hand_cursor) + { + g_object_unref (obj->priv->hand_cursor); + } - if (obj->priv->hover_path) - gtk_tree_path_free (obj->priv->hover_path); + if (obj->priv->hover_path) + { + gtk_tree_path_free (obj->priv->hover_path); + } - if (obj->priv->expand_state) - { - g_hash_table_destroy (obj->priv->expand_state); - obj->priv->expand_state = NULL; - } + if (obj->priv->expand_state) + { + g_hash_table_destroy (obj->priv->expand_state); + obj->priv->expand_state = NULL; + } - g_object_unref (obj->priv->busy_cursor); + g_object_unref (obj->priv->busy_cursor); - G_OBJECT_CLASS (xed_file_browser_view_parent_class)-> - finalize (object); + G_OBJECT_CLASS (xed_file_browser_view_parent_class)->finalize (object); } static void -add_expand_state (XedFileBrowserView * view, - gchar const * uri) +add_expand_state (XedFileBrowserView *view, + gchar const *uri) { - GFile * file; + GFile * file; - if (!uri) - return; + if (!uri) + { + return; + } - file = g_file_new_for_uri (uri); + file = g_file_new_for_uri (uri); - if (view->priv->expand_state) - g_hash_table_insert (view->priv->expand_state, file, file); - else - g_object_unref (file); + if (view->priv->expand_state) + { + g_hash_table_insert (view->priv->expand_state, file, file); + } + else + { + g_object_unref (file); + } } static void -remove_expand_state (XedFileBrowserView * view, - gchar const * uri) +remove_expand_state (XedFileBrowserView *view, + gchar const *uri) { - GFile * file; + GFile * file; - if (!uri) - return; + if (!uri) + { + return; + } - file = g_file_new_for_uri (uri); + file = g_file_new_for_uri (uri); - if (view->priv->expand_state) - g_hash_table_remove (view->priv->expand_state, file); + if (view->priv->expand_state) + { + g_hash_table_remove (view->priv->expand_state, file); + } - g_object_unref (file); + g_object_unref (file); } static void -row_expanded (GtkTreeView * tree_view, - GtkTreeIter * iter, - GtkTreePath * path) +row_expanded (GtkTreeView *tree_view, + GtkTreeIter *iter, + GtkTreePath *path) { - XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (tree_view); - gchar * uri; + XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (tree_view); + gchar *uri; - if (GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_expanded) - GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_expanded (tree_view, iter, path); + if (GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_expanded) + { + GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_expanded (tree_view, iter, path); + } - if (!XED_IS_FILE_BROWSER_STORE (view->priv->model)) - return; + if (!XED_IS_FILE_BROWSER_STORE (view->priv->model)) + { + return; + } - if (view->priv->restore_expand_state) - { - gtk_tree_model_get (view->priv->model, - iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, - &uri, - -1); + if (view->priv->restore_expand_state) + { + gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, -1); - add_expand_state (view, uri); - g_free (uri); - } + add_expand_state (view, uri); + g_free (uri); + } - _xed_file_browser_store_iter_expanded (XED_FILE_BROWSER_STORE (view->priv->model), - iter); + _xed_file_browser_store_iter_expanded (XED_FILE_BROWSER_STORE (view->priv->model), iter); } static void -row_collapsed (GtkTreeView * tree_view, - GtkTreeIter * iter, - GtkTreePath * path) +row_collapsed (GtkTreeView *tree_view, + GtkTreeIter *iter, + GtkTreePath *path) { - XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (tree_view); - gchar * uri; + XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (tree_view); + gchar * uri; - if (GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_collapsed) - GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_collapsed (tree_view, iter, path); + if (GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_collapsed) + { + GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_collapsed (tree_view, iter, path); + } - if (!XED_IS_FILE_BROWSER_STORE (view->priv->model)) - return; + if (!XED_IS_FILE_BROWSER_STORE (view->priv->model)) + { + return; + } - if (view->priv->restore_expand_state) - { - gtk_tree_model_get (view->priv->model, - iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, - &uri, - -1); + if (view->priv->restore_expand_state) + { + gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, -1); - remove_expand_state (view, uri); - g_free (uri); - } + remove_expand_state (view, uri); + g_free (uri); + } - _xed_file_browser_store_iter_collapsed (XED_FILE_BROWSER_STORE (view->priv->model), - iter); + _xed_file_browser_store_iter_collapsed (XED_FILE_BROWSER_STORE (view->priv->model), iter); } static gboolean -leave_notify_event (GtkWidget *widget, - GdkEventCrossing *event) +leave_notify_event (GtkWidget *widget, + GdkEventCrossing *event) { - XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget); + XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget); - if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE && - view->priv->hover_path != NULL) { - gtk_tree_path_free (view->priv->hover_path); - view->priv->hover_path = NULL; - } + if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE && + view->priv->hover_path != NULL) + { + gtk_tree_path_free (view->priv->hover_path); + view->priv->hover_path = NULL; + } - // Chainup - return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->leave_notify_event (widget, event); + // Chainup + return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->leave_notify_event (widget, event); } static gboolean -enter_notify_event (GtkWidget *widget, - GdkEventCrossing *event) +enter_notify_event (GtkWidget *widget, + GdkEventCrossing *event) { - XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget); + XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget); - if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) { - if (view->priv->hover_path != NULL) - gtk_tree_path_free (view->priv->hover_path); + if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) + { + if (view->priv->hover_path != NULL) + { + gtk_tree_path_free (view->priv->hover_path); + } - gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), - event->x, event->y, - &view->priv->hover_path, - NULL, NULL, NULL); + gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), + event->x, event->y, + &view->priv->hover_path, + NULL, NULL, NULL); - if (view->priv->hover_path != NULL) - gdk_window_set_cursor (gtk_widget_get_window (widget), - view->priv->hand_cursor); - } + if (view->priv->hover_path != NULL) + { + gdk_window_set_cursor (gtk_widget_get_window (widget), view->priv->hand_cursor); + } + } - // Chainup - return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->enter_notify_event (widget, event); + // Chainup + return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->enter_notify_event (widget, event); } static gboolean -motion_notify_event (GtkWidget * widget, - GdkEventMotion * event) +motion_notify_event (GtkWidget *widget, + GdkEventMotion *event) { - GtkTreePath *old_hover_path; - XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget); + GtkTreePath *old_hover_path; + XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget); - if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) { - old_hover_path = view->priv->hover_path; - gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), - event->x, event->y, - &view->priv->hover_path, - NULL, NULL, NULL); + if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) + { + old_hover_path = view->priv->hover_path; + gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), + event->x, event->y, + &view->priv->hover_path, + NULL, NULL, NULL); - if ((old_hover_path != NULL) != (view->priv->hover_path != NULL)) { - if (view->priv->hover_path != NULL) - gdk_window_set_cursor (gtk_widget_get_window (widget), - view->priv->hand_cursor); - else - gdk_window_set_cursor (gtk_widget_get_window (widget), - NULL); - } + if ((old_hover_path != NULL) != (view->priv->hover_path != NULL)) + { + if (view->priv->hover_path != NULL) + { + gdk_window_set_cursor (gtk_widget_get_window (widget), view->priv->hand_cursor); + } + else + { + gdk_window_set_cursor (gtk_widget_get_window (widget), NULL); + } + } - if (old_hover_path != NULL) - gtk_tree_path_free (old_hover_path); - } + if (old_hover_path != NULL) + { + gtk_tree_path_free (old_hover_path); + } + } - // Chainup - return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->motion_notify_event (widget, event); + // Chainup + return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->motion_notify_event (widget, event); } static void set_click_policy_property (XedFileBrowserView *obj, - XedFileBrowserViewClickPolicy click_policy) + XedFileBrowserViewClickPolicy click_policy) { - GtkTreeIter iter; - GdkDisplay *display; - GdkWindow *win; + GtkTreeIter iter; + GdkDisplay *display; + GdkWindow *win; - obj->priv->click_policy = click_policy; + obj->priv->click_policy = click_policy; - if (click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) { - if (obj->priv->hand_cursor == NULL) - obj->priv->hand_cursor = gdk_cursor_new(GDK_HAND2); - } else if (click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE) { - if (obj->priv->hover_path != NULL) { - if (gtk_tree_model_get_iter (GTK_TREE_MODEL (obj->priv->model), - &iter, obj->priv->hover_path)) - gtk_tree_model_row_changed (GTK_TREE_MODEL (obj->priv->model), - obj->priv->hover_path, &iter); + if (click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) + { + if (obj->priv->hand_cursor == NULL) + { + obj->priv->hand_cursor = gdk_cursor_new(GDK_HAND2); + } + } + else if (click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE) + { + if (obj->priv->hover_path != NULL) + { + if (gtk_tree_model_get_iter (GTK_TREE_MODEL (obj->priv->model), &iter, obj->priv->hover_path)) + { + gtk_tree_model_row_changed (GTK_TREE_MODEL (obj->priv->model), obj->priv->hover_path, &iter); + } - gtk_tree_path_free (obj->priv->hover_path); - obj->priv->hover_path = NULL; - } + gtk_tree_path_free (obj->priv->hover_path); + obj->priv->hover_path = NULL; + } - if (gtk_widget_get_realized (GTK_WIDGET (obj))) { - win = gtk_widget_get_window (GTK_WIDGET (obj)); - gdk_window_set_cursor (win, NULL); + if (gtk_widget_get_realized (GTK_WIDGET (obj))) + { + win = gtk_widget_get_window (GTK_WIDGET (obj)); + gdk_window_set_cursor (win, NULL); - display = gtk_widget_get_display (GTK_WIDGET (obj)); + display = gtk_widget_get_display (GTK_WIDGET (obj)); - if (display != NULL) - gdk_display_flush (display); - } + if (display != NULL) + { + gdk_display_flush (display); + } + } - if (obj->priv->hand_cursor) { - g_object_unref (obj->priv->hand_cursor); - obj->priv->hand_cursor = NULL; - } - } + if (obj->priv->hand_cursor) + { + g_object_unref (obj->priv->hand_cursor); + obj->priv->hand_cursor = NULL; + } + } } static void directory_activated (XedFileBrowserView *view, - GtkTreeIter *iter) + GtkTreeIter *iter) { - xed_file_browser_store_set_virtual_root (XED_FILE_BROWSER_STORE (view->priv->model), iter); + xed_file_browser_store_set_virtual_root (XED_FILE_BROWSER_STORE (view->priv->model), iter); } static void -activate_selected_files (XedFileBrowserView *view) { - GtkTreeView *tree_view = GTK_TREE_VIEW (view); - GtkTreeSelection *selection = gtk_tree_view_get_selection (tree_view); - GList *rows, *row; - GtkTreePath *directory = NULL; - GtkTreePath *path; - GtkTreeIter iter; - XedFileBrowserStoreFlag flags; +activate_selected_files (XedFileBrowserView *view) +{ + GtkTreeView *tree_view = GTK_TREE_VIEW (view); + GtkTreeSelection *selection = gtk_tree_view_get_selection (tree_view); + GList *rows, *row; + GtkTreePath *directory = NULL; + GtkTreePath *path; + GtkTreeIter iter; + XedFileBrowserStoreFlag flags; - rows = gtk_tree_selection_get_selected_rows (selection, &view->priv->model); + rows = gtk_tree_selection_get_selected_rows (selection, &view->priv->model); - for (row = rows; row; row = row->next) { - path = (GtkTreePath *)(row->data); + for (row = rows; row; row = row->next) + { + path = (GtkTreePath *)(row->data); - /* Get iter from path */ - if (!gtk_tree_model_get_iter (view->priv->model, &iter, path)) - continue; + /* Get iter from path */ + if (!gtk_tree_model_get_iter (view->priv->model, &iter, path)) + { + continue; + } - gtk_tree_model_get (view->priv->model, &iter, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, -1); + gtk_tree_model_get (view->priv->model, &iter, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, -1); - if (FILE_IS_DIR (flags)) { - if (directory == NULL) - directory = path; + if (FILE_IS_DIR (flags)) + { + if (directory == NULL) + { + directory = path; + } - } else if (!FILE_IS_DUMMY (flags)) { - g_signal_emit (view, signals[FILE_ACTIVATED], 0, &iter); - } - } + } + else if (!FILE_IS_DUMMY (flags)) + { + g_signal_emit (view, signals[FILE_ACTIVATED], 0, &iter); + } + } - if (directory != NULL) { - if (gtk_tree_model_get_iter (view->priv->model, &iter, directory)) - g_signal_emit (view, signals[DIRECTORY_ACTIVATED], 0, &iter); - } + if (directory != NULL) + { + if (gtk_tree_model_get_iter (view->priv->model, &iter, directory)) + { + g_signal_emit (view, signals[DIRECTORY_ACTIVATED], 0, &iter); + } + } - g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL); - g_list_free (rows); + g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL); + g_list_free (rows); } static void -activate_selected_bookmark (XedFileBrowserView *view) { - GtkTreeView *tree_view = GTK_TREE_VIEW (view); - GtkTreeSelection *selection = gtk_tree_view_get_selection (tree_view); - GtkTreeIter iter; +activate_selected_bookmark (XedFileBrowserView *view) +{ + GtkTreeView *tree_view = GTK_TREE_VIEW (view); + GtkTreeSelection *selection = gtk_tree_view_get_selection (tree_view); + GtkTreeIter iter; - if (gtk_tree_selection_get_selected (selection, &view->priv->model, &iter)) - g_signal_emit (view, signals[BOOKMARK_ACTIVATED], 0, &iter); + if (gtk_tree_selection_get_selected (selection, &view->priv->model, &iter)) + { + g_signal_emit (view, signals[BOOKMARK_ACTIVATED], 0, &iter); + } } static void activate_selected_items (XedFileBrowserView *view) { - if (XED_IS_FILE_BROWSER_STORE (view->priv->model)) - activate_selected_files (view); - else if (XED_IS_FILE_BOOKMARKS_STORE (view->priv->model)) - activate_selected_bookmark (view); + if (XED_IS_FILE_BROWSER_STORE (view->priv->model)) + { + activate_selected_files (view); + } + else if (XED_IS_FILE_BOOKMARKS_STORE (view->priv->model)) + { + activate_selected_bookmark (view); + } } static void toggle_hidden_filter (XedFileBrowserView *view) { - XedFileBrowserStoreFilterMode mode; + XedFileBrowserStoreFilterMode mode; - if (XED_IS_FILE_BROWSER_STORE (view->priv->model)) - { - mode = xed_file_browser_store_get_filter_mode - (XED_FILE_BROWSER_STORE (view->priv->model)); - mode ^= XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN; - xed_file_browser_store_set_filter_mode - (XED_FILE_BROWSER_STORE (view->priv->model), mode); - } + if (XED_IS_FILE_BROWSER_STORE (view->priv->model)) + { + mode = xed_file_browser_store_get_filter_mode (XED_FILE_BROWSER_STORE (view->priv->model)); + mode ^= XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN; + xed_file_browser_store_set_filter_mode (XED_FILE_BROWSER_STORE (view->priv->model), mode); + } } static gboolean button_event_modifies_selection (GdkEventButton *event) { - return (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0; + return (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0; } static void drag_begin (GtkWidget *widget, - GdkDragContext *context) + GdkDragContext *context) { - XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget); + XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget); - view->priv->drag_button = 0; - view->priv->drag_started = TRUE; + view->priv->drag_button = 0; + view->priv->drag_started = TRUE; - /* Chain up */ - GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->drag_begin (widget, context); + /* Chain up */ + GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->drag_begin (widget, context); } static void did_not_drag (XedFileBrowserView *view, - GdkEventButton *event) + GdkEventButton *event) { - GtkTreeView *tree_view; - GtkTreeSelection *selection; - GtkTreePath *path; + GtkTreeView *tree_view; + GtkTreeSelection *selection; + GtkTreePath *path; - tree_view = GTK_TREE_VIEW (view); - selection = gtk_tree_view_get_selection (tree_view); + tree_view = GTK_TREE_VIEW (view); + selection = gtk_tree_view_get_selection (tree_view); - if (gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y, - &path, NULL, NULL, NULL)) { - if ((view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) - && !button_event_modifies_selection(event) - && (event->button == 1 || event->button == 2)) { - /* Activate all selected items, and leave them selected */ - activate_selected_items (view); - } else if ((event->button == 1 || event->button == 2) - && ((event->state & GDK_CONTROL_MASK) != 0 || - (event->state & GDK_SHIFT_MASK) == 0) - && view->priv->selected_on_button_down) { - if (!button_event_modifies_selection (event)) { - gtk_tree_selection_unselect_all (selection); - gtk_tree_selection_select_path (selection, path); - } else { - gtk_tree_selection_unselect_path (selection, path); - } - } + if (gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y, &path, NULL, NULL, NULL)) + { + if ((view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) + && !button_event_modifies_selection(event) + && (event->button == 1 || event->button == 2)) + { + /* Activate all selected items, and leave them selected */ + activate_selected_items (view); + } + else if ((event->button == 1 || event->button == 2) + && ((event->state & GDK_CONTROL_MASK) != 0 || + (event->state & GDK_SHIFT_MASK) == 0) + && view->priv->selected_on_button_down) + { + if (!button_event_modifies_selection (event)) + { + gtk_tree_selection_unselect_all (selection); + gtk_tree_selection_select_path (selection, path); + } + else + { + gtk_tree_selection_unselect_path (selection, path); + } + } - gtk_tree_path_free (path); - } + gtk_tree_path_free (path); + } } static gboolean -button_release_event (GtkWidget *widget, - GdkEventButton *event) +button_release_event (GtkWidget *widget, + GdkEventButton *event) { - XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget); + XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget); - if (event->button == view->priv->drag_button) { - view->priv->drag_button = 0; + if (event->button == view->priv->drag_button) + { + view->priv->drag_button = 0; - if (!view->priv->drag_started && - !view->priv->ignore_release) - did_not_drag (view, event); - } + if (!view->priv->drag_started && !view->priv->ignore_release) + { + did_not_drag (view, event); + } + } - /* Chain up */ - return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->button_release_event (widget, event); + /* Chain up */ + return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->button_release_event (widget, event); } static gboolean button_press_event (GtkWidget *widget, - GdkEventButton *event) + GdkEventButton *event) { - int double_click_time; - static int click_count = 0; - static guint32 last_click_time = 0; - XedFileBrowserView *view; - GtkTreeView *tree_view; - GtkTreeSelection *selection; - GtkTreePath *path; - int expander_size; - int horizontal_separator; - gboolean on_expander; - gboolean call_parent; - gboolean selected; - GtkWidgetClass *widget_parent = GTK_WIDGET_CLASS(xed_file_browser_view_parent_class); + int double_click_time; + static int click_count = 0; + static guint32 last_click_time = 0; + XedFileBrowserView *view; + GtkTreeView *tree_view; + GtkTreeSelection *selection; + GtkTreePath *path; + int expander_size; + int horizontal_separator; + gboolean on_expander; + gboolean call_parent; + gboolean selected; + GtkWidgetClass *widget_parent = GTK_WIDGET_CLASS(xed_file_browser_view_parent_class); - tree_view = GTK_TREE_VIEW (widget); - view = XED_FILE_BROWSER_VIEW (widget); - selection = gtk_tree_view_get_selection (tree_view); + tree_view = GTK_TREE_VIEW (widget); + view = XED_FILE_BROWSER_VIEW (widget); + selection = gtk_tree_view_get_selection (tree_view); - /* Get double click time */ - g_object_get (G_OBJECT (gtk_widget_get_settings (widget)), - "gtk-double-click-time", &double_click_time, - NULL); + /* Get double click time */ + g_object_get (G_OBJECT (gtk_widget_get_settings (widget)), + "gtk-double-click-time", &double_click_time, + NULL); - /* Determine click count */ - if (event->time - last_click_time < double_click_time) - click_count++; - else - click_count = 0; + /* Determine click count */ + if (event->time - last_click_time < double_click_time) + { + click_count++; + } + else + { + click_count = 0; + } - last_click_time = event->time; + last_click_time = event->time; - /* Ignore double click if we are in single click mode */ - if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE && - click_count >= 2) { - return TRUE; - } + /* Ignore double click if we are in single click mode */ + if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE && click_count >= 2) + { + return TRUE; + } - view->priv->ignore_release = FALSE; - call_parent = TRUE; + view->priv->ignore_release = FALSE; + call_parent = TRUE; - if (gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y, - &path, NULL, NULL, NULL)) { - /* Keep track of path of last click so double clicks only happen - * on the same item */ - if ((event->button == 1 || event->button == 2) && - event->type == GDK_BUTTON_PRESS) { - if (view->priv->double_click_path[1]) - gtk_tree_path_free (view->priv->double_click_path[1]); + if (gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y, &path, NULL, NULL, NULL)) + { + /* Keep track of path of last click so double clicks only happen + * on the same item */ + if ((event->button == 1 || event->button == 2) && event->type == GDK_BUTTON_PRESS) + { + if (view->priv->double_click_path[1]) + { + gtk_tree_path_free (view->priv->double_click_path[1]); + } - view->priv->double_click_path[1] = view->priv->double_click_path[0]; - view->priv->double_click_path[0] = gtk_tree_path_copy (path); - } + view->priv->double_click_path[1] = view->priv->double_click_path[0]; + view->priv->double_click_path[0] = gtk_tree_path_copy (path); + } - if (event->type == GDK_2BUTTON_PRESS) { - if (view->priv->double_click_path[1] && - gtk_tree_path_compare (view->priv->double_click_path[0], view->priv->double_click_path[1]) == 0) - activate_selected_items (view); + if (event->type == GDK_2BUTTON_PRESS) + { + if (view->priv->double_click_path[1] && + gtk_tree_path_compare (view->priv->double_click_path[0], view->priv->double_click_path[1]) == 0) + { + activate_selected_items (view); + } - /* Chain up */ - widget_parent->button_press_event (widget, event); - } else { - /* We're going to filter out some situations where - * we can't let the default code run because all - * but one row would be would be deselected. We don't - * want that; we want the right click menu or single - * click to apply to everything that's currently selected. */ - selected = gtk_tree_selection_path_is_selected (selection, path); + /* Chain up */ + widget_parent->button_press_event (widget, event); + } + else + { + /* We're going to filter out some situations where + * we can't let the default code run because all + * but one row would be would be deselected. We don't + * want that; we want the right click menu or single + * click to apply to everything that's currently selected. */ + selected = gtk_tree_selection_path_is_selected (selection, path); - if (event->button == 3 && selected) - call_parent = FALSE; + if (event->button == 3 && selected) + { + call_parent = FALSE; + } - if ((event->button == 1 || event->button == 2) && - ((event->state & GDK_CONTROL_MASK) != 0 || - (event->state & GDK_SHIFT_MASK) == 0)) { - gtk_widget_style_get (widget, - "expander-size", &expander_size, - "horizontal-separator", &horizontal_separator, - NULL); - on_expander = (event->x <= horizontal_separator / 2 + - gtk_tree_path_get_depth (path) * expander_size); + if ((event->button == 1 || event->button == 2) && + ((event->state & GDK_CONTROL_MASK) != 0 || + (event->state & GDK_SHIFT_MASK) == 0)) + { + gtk_widget_style_get (widget, + "expander-size", &expander_size, + "horizontal-separator", &horizontal_separator, + NULL); + on_expander = (event->x <= horizontal_separator / 2 + gtk_tree_path_get_depth (path) * expander_size); - view->priv->selected_on_button_down = selected; + view->priv->selected_on_button_down = selected; - if (selected) { - call_parent = on_expander || gtk_tree_selection_count_selected_rows (selection) == 1; - view->priv->ignore_release = call_parent && view->priv->click_policy != XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE; - } else if ((event->state & GDK_CONTROL_MASK) != 0) { - call_parent = FALSE; - gtk_tree_selection_select_path (selection, path); - } else { - view->priv->ignore_release = on_expander; - } - } + if (selected) + { + call_parent = on_expander || gtk_tree_selection_count_selected_rows (selection) == 1; + view->priv->ignore_release = call_parent && view->priv->click_policy != XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE; + } + else if ((event->state & GDK_CONTROL_MASK) != 0) + { + call_parent = FALSE; + gtk_tree_selection_select_path (selection, path); + } + else + { + view->priv->ignore_release = on_expander; + } + } - if (call_parent) { - /* Chain up */ - widget_parent->button_press_event (widget, event); - } else if (selected) { - gtk_widget_grab_focus (widget); - } + if (call_parent) + { + /* Chain up */ + widget_parent->button_press_event (widget, event); + } + else if (selected) + { + gtk_widget_grab_focus (widget); + } - if ((event->button == 1 || event->button == 2) && - event->type == GDK_BUTTON_PRESS) { - view->priv->drag_started = FALSE; - view->priv->drag_button = event->button; - } - } + if ((event->button == 1 || event->button == 2) && + event->type == GDK_BUTTON_PRESS) + { + view->priv->drag_started = FALSE; + view->priv->drag_button = event->button; + } + } - gtk_tree_path_free (path); - } else { - if ((event->button == 1 || event->button == 2) && - event->type == GDK_BUTTON_PRESS) { - if (view->priv->double_click_path[1]) - gtk_tree_path_free (view->priv->double_click_path[1]); + gtk_tree_path_free (path); + } + else + { + if ((event->button == 1 || event->button == 2) && event->type == GDK_BUTTON_PRESS) + { + if (view->priv->double_click_path[1]) + { + gtk_tree_path_free (view->priv->double_click_path[1]); + } - view->priv->double_click_path[1] = view->priv->double_click_path[0]; - view->priv->double_click_path[0] = NULL; - } + view->priv->double_click_path[1] = view->priv->double_click_path[0]; + view->priv->double_click_path[0] = NULL; + } - gtk_tree_selection_unselect_all (selection); - /* Chain up */ - widget_parent->button_press_event (widget, event); - } + gtk_tree_selection_unselect_all (selection); + /* Chain up */ + widget_parent->button_press_event (widget, event); + } - /* We already chained up if nescessary, so just return TRUE */ - return TRUE; + /* We already chained up if nescessary, so just return TRUE */ + return TRUE; } static gboolean key_press_event (GtkWidget *widget, - GdkEventKey *event) + GdkEventKey *event) { - XedFileBrowserView *view; - guint modifiers; - gboolean handled; + XedFileBrowserView *view; + guint modifiers; + gboolean handled; - view = XED_FILE_BROWSER_VIEW (widget); - handled = FALSE; + view = XED_FILE_BROWSER_VIEW (widget); + handled = FALSE; - modifiers = gtk_accelerator_get_default_mod_mask (); + modifiers = gtk_accelerator_get_default_mod_mask (); - switch (event->keyval) { - case GDK_KEY_space: - if (event->state & GDK_CONTROL_MASK) { - handled = FALSE; - break; - } - if (!gtk_widget_has_focus (widget)) { - handled = FALSE; - break; - } + switch (event->keyval) + { + case GDK_KEY_space: + if (event->state & GDK_CONTROL_MASK) + { + handled = FALSE; + break; + } + if (!gtk_widget_has_focus (widget)) + { + handled = FALSE; + break; + } - activate_selected_items (view); - handled = TRUE; - break; + activate_selected_items (view); + handled = TRUE; + break; - case GDK_KEY_Return: - case GDK_KEY_KP_Enter: - activate_selected_items (view); - handled = TRUE; - break; + case GDK_KEY_Return: + case GDK_KEY_KP_Enter: + activate_selected_items (view); + handled = TRUE; + break; - case GDK_KEY_h: - if ((event->state & modifiers) == GDK_CONTROL_MASK) { - toggle_hidden_filter (view); - handled = TRUE; - break; - } + case GDK_KEY_h: + if ((event->state & modifiers) == GDK_CONTROL_MASK) + { + toggle_hidden_filter (view); + handled = TRUE; + break; + } - default: - handled = FALSE; - } + default: + handled = FALSE; + } - /* Chain up */ - if (!handled) - return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->key_press_event (widget, event); + /* Chain up */ + if (!handled) + { + return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->key_press_event (widget, event); + } - return TRUE; + return TRUE; } static void -fill_expand_state (XedFileBrowserView * view, GtkTreeIter * iter) +fill_expand_state (XedFileBrowserView *view, + GtkTreeIter *iter) { - GtkTreePath * path; - GtkTreeIter child; - gchar * uri; + GtkTreePath * path; + GtkTreeIter child; + gchar * uri; - if (!gtk_tree_model_iter_has_child (view->priv->model, iter)) - return; + if (!gtk_tree_model_iter_has_child (view->priv->model, iter)) + { + return; + } - path = gtk_tree_model_get_path (view->priv->model, iter); + path = gtk_tree_model_get_path (view->priv->model, iter); - if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (view), path)) - { - gtk_tree_model_get (view->priv->model, - iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, - &uri, - -1); + if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (view), path)) + { + gtk_tree_model_get (view->priv->model, + iter, + XED_FILE_BROWSER_STORE_COLUMN_URI, + &uri, + -1); - add_expand_state (view, uri); - g_free (uri); - } + add_expand_state (view, uri); + g_free (uri); + } - if (gtk_tree_model_iter_children (view->priv->model, &child, iter)) - { - do { - fill_expand_state (view, &child); - } while (gtk_tree_model_iter_next (view->priv->model, &child)); - } + if (gtk_tree_model_iter_children (view->priv->model, &child, iter)) + { + do + { + fill_expand_state (view, &child); + } while (gtk_tree_model_iter_next (view->priv->model, &child)); + } - gtk_tree_path_free (path); + gtk_tree_path_free (path); } static void -uninstall_restore_signals (XedFileBrowserView * tree_view, - GtkTreeModel * model) +uninstall_restore_signals (XedFileBrowserView *tree_view, + GtkTreeModel *model) { - g_signal_handlers_disconnect_by_func (model, - on_begin_refresh, - tree_view); - - g_signal_handlers_disconnect_by_func (model, - on_end_refresh, - tree_view); - - g_signal_handlers_disconnect_by_func (model, - on_unload, - tree_view); - - g_signal_handlers_disconnect_by_func (model, - on_row_inserted, - tree_view); + g_signal_handlers_disconnect_by_func (model, on_begin_refresh, tree_view); + g_signal_handlers_disconnect_by_func (model, on_end_refresh, tree_view); + g_signal_handlers_disconnect_by_func (model, on_unload, tree_view); + g_signal_handlers_disconnect_by_func (model, on_row_inserted, tree_view); } static void -install_restore_signals (XedFileBrowserView * tree_view, - GtkTreeModel * model) +install_restore_signals (XedFileBrowserView *tree_view, + GtkTreeModel *model) { - g_signal_connect (model, - "begin-refresh", - G_CALLBACK (on_begin_refresh), - tree_view); - - g_signal_connect (model, - "end-refresh", - G_CALLBACK (on_end_refresh), - tree_view); - - g_signal_connect (model, - "unload", - G_CALLBACK (on_unload), - tree_view); - - g_signal_connect_after (model, - "row-inserted", - G_CALLBACK (on_row_inserted), - tree_view); + g_signal_connect (model, "begin-refresh", + G_CALLBACK (on_begin_refresh), tree_view); + g_signal_connect (model, "end-refresh", + G_CALLBACK (on_end_refresh), tree_view); + g_signal_connect (model, "unload", + G_CALLBACK (on_unload), tree_view); + g_signal_connect_after (model, "row-inserted", + G_CALLBACK (on_row_inserted), tree_view); } static void -set_restore_expand_state (XedFileBrowserView * view, - gboolean state) +set_restore_expand_state (XedFileBrowserView *view, + gboolean state) { - if (state == view->priv->restore_expand_state) - return; + if (state == view->priv->restore_expand_state) + { + return; + } - if (view->priv->expand_state) - { - g_hash_table_destroy (view->priv->expand_state); - view->priv->expand_state = NULL; - } + if (view->priv->expand_state) + { + g_hash_table_destroy (view->priv->expand_state); + view->priv->expand_state = NULL; + } - if (state) - { - view->priv->expand_state = g_hash_table_new_full (g_file_hash, - (GEqualFunc)g_file_equal, - g_object_unref, - NULL); + if (state) + { + view->priv->expand_state = g_hash_table_new_full (g_file_hash, + (GEqualFunc)g_file_equal, + g_object_unref, + NULL); - if (view->priv->model && XED_IS_FILE_BROWSER_STORE (view->priv->model)) - { - fill_expand_state (view, NULL); + if (view->priv->model && XED_IS_FILE_BROWSER_STORE (view->priv->model)) + { + fill_expand_state (view, NULL); - install_restore_signals (view, view->priv->model); - } - } - else if (view->priv->model && XED_IS_FILE_BROWSER_STORE (view->priv->model)) - { - uninstall_restore_signals (view, view->priv->model); - } + install_restore_signals (view, view->priv->model); + } + } + else if (view->priv->model && XED_IS_FILE_BROWSER_STORE (view->priv->model)) + { + uninstall_restore_signals (view, view->priv->model); + } - view->priv->restore_expand_state = state; + view->priv->restore_expand_state = state; } static void get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - XedFileBrowserView *obj = XED_FILE_BROWSER_VIEW (object); + XedFileBrowserView *obj = XED_FILE_BROWSER_VIEW (object); - switch (prop_id) - { - case PROP_CLICK_POLICY: - g_value_set_enum (value, obj->priv->click_policy); - break; - case PROP_RESTORE_EXPAND_STATE: - g_value_set_boolean (value, obj->priv->restore_expand_state); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_CLICK_POLICY: + g_value_set_enum (value, obj->priv->click_policy); + break; + case PROP_RESTORE_EXPAND_STATE: + g_value_set_boolean (value, obj->priv->restore_expand_state); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - XedFileBrowserView *obj = XED_FILE_BROWSER_VIEW (object); + XedFileBrowserView *obj = XED_FILE_BROWSER_VIEW (object); - switch (prop_id) - { - case PROP_CLICK_POLICY: - set_click_policy_property (obj, g_value_get_enum (value)); - break; - case PROP_RESTORE_EXPAND_STATE: - set_restore_expand_state (obj, g_value_get_boolean (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_CLICK_POLICY: + set_click_policy_property (obj, g_value_get_enum (value)); + break; + case PROP_RESTORE_EXPAND_STATE: + set_restore_expand_state (obj, g_value_get_boolean (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -xed_file_browser_view_class_init (XedFileBrowserViewClass * klass) +xed_file_browser_view_class_init (XedFileBrowserViewClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkTreeViewClass *tree_view_class = GTK_TREE_VIEW_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkTreeViewClass *tree_view_class = GTK_TREE_VIEW_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - object_class->finalize = xed_file_browser_view_finalize; - object_class->get_property = get_property; - object_class->set_property = set_property; + object_class->finalize = xed_file_browser_view_finalize; + object_class->get_property = get_property; + object_class->set_property = set_property; - /* Event handlers */ - widget_class->motion_notify_event = motion_notify_event; - widget_class->enter_notify_event = enter_notify_event; - widget_class->leave_notify_event = leave_notify_event; - widget_class->button_press_event = button_press_event; - widget_class->button_release_event = button_release_event; - widget_class->drag_begin = drag_begin; - widget_class->key_press_event = key_press_event; + /* Event handlers */ + widget_class->motion_notify_event = motion_notify_event; + widget_class->enter_notify_event = enter_notify_event; + widget_class->leave_notify_event = leave_notify_event; + widget_class->button_press_event = button_press_event; + widget_class->button_release_event = button_release_event; + widget_class->drag_begin = drag_begin; + widget_class->key_press_event = key_press_event; - /* Tree view handlers */ - tree_view_class->row_expanded = row_expanded; - tree_view_class->row_collapsed = row_collapsed; + /* Tree view handlers */ + tree_view_class->row_expanded = row_expanded; + tree_view_class->row_collapsed = row_collapsed; - /* Default handlers */ - klass->directory_activated = directory_activated; + /* Default handlers */ + klass->directory_activated = directory_activated; - g_object_class_install_property (object_class, PROP_CLICK_POLICY, - g_param_spec_enum ("click-policy", - "Click Policy", - "The click policy", - XED_TYPE_FILE_BROWSER_VIEW_CLICK_POLICY, - XED_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + g_object_class_install_property (object_class, PROP_CLICK_POLICY, + g_param_spec_enum ("click-policy", + "Click Policy", + "The click policy", + XED_TYPE_FILE_BROWSER_VIEW_CLICK_POLICY, + XED_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - g_object_class_install_property (object_class, PROP_RESTORE_EXPAND_STATE, - g_param_spec_boolean ("restore-expand-state", - "Restore Expand State", - "Restore expanded state of loaded directories", - FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + g_object_class_install_property (object_class, PROP_RESTORE_EXPAND_STATE, + g_param_spec_boolean ("restore-expand-state", + "Restore Expand State", + "Restore expanded state of loaded directories", + FALSE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - signals[ERROR] = - g_signal_new ("error", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedFileBrowserViewClass, - error), NULL, NULL, - xed_file_browser_marshal_VOID__UINT_STRING, - G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING); - signals[FILE_ACTIVATED] = - g_signal_new ("file-activated", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedFileBrowserViewClass, - file_activated), NULL, NULL, - g_cclosure_marshal_VOID__BOXED, - G_TYPE_NONE, 1, GTK_TYPE_TREE_ITER); - signals[DIRECTORY_ACTIVATED] = - g_signal_new ("directory-activated", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedFileBrowserViewClass, - directory_activated), NULL, NULL, - g_cclosure_marshal_VOID__BOXED, - G_TYPE_NONE, 1, GTK_TYPE_TREE_ITER); - signals[BOOKMARK_ACTIVATED] = - g_signal_new ("bookmark-activated", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedFileBrowserViewClass, - bookmark_activated), NULL, NULL, - g_cclosure_marshal_VOID__BOXED, - G_TYPE_NONE, 1, GTK_TYPE_TREE_ITER); + signals[ERROR] = + g_signal_new ("error", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedFileBrowserViewClass, + error), NULL, NULL, + xed_file_browser_marshal_VOID__UINT_STRING, + G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING); + signals[FILE_ACTIVATED] = + g_signal_new ("file-activated", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedFileBrowserViewClass, + file_activated), NULL, NULL, + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, 1, GTK_TYPE_TREE_ITER); + signals[DIRECTORY_ACTIVATED] = + g_signal_new ("directory-activated", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedFileBrowserViewClass, + directory_activated), NULL, NULL, + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, 1, GTK_TYPE_TREE_ITER); + signals[BOOKMARK_ACTIVATED] = + g_signal_new ("bookmark-activated", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedFileBrowserViewClass, + bookmark_activated), NULL, NULL, + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, 1, GTK_TYPE_TREE_ITER); - g_type_class_add_private (object_class, - sizeof (XedFileBrowserViewPrivate)); + g_type_class_add_private (object_class, sizeof (XedFileBrowserViewPrivate)); } static void @@ -916,347 +988,361 @@ xed_file_browser_view_class_finalize (XedFileBrowserViewClass *klass) } static void -cell_data_cb (GtkTreeViewColumn * tree_column, GtkCellRenderer * cell, - GtkTreeModel * tree_model, GtkTreeIter * iter, - XedFileBrowserView * obj) +cell_data_cb (GtkTreeViewColumn *tree_column, + GtkCellRenderer *cell, + GtkTreeModel *tree_model, + GtkTreeIter *iter, + XedFileBrowserView *obj) { - GtkTreePath *path; - PangoUnderline underline = PANGO_UNDERLINE_NONE; - gboolean editable = FALSE; + GtkTreePath *path; + PangoUnderline underline = PANGO_UNDERLINE_NONE; + gboolean editable = FALSE; - path = gtk_tree_model_get_path (tree_model, iter); + path = gtk_tree_model_get_path (tree_model, iter); - if (obj->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) { - if (obj->priv->hover_path != NULL && - gtk_tree_path_compare (path, obj->priv->hover_path) == 0) - underline = PANGO_UNDERLINE_SINGLE; - } + if (obj->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) + { + if (obj->priv->hover_path != NULL && gtk_tree_path_compare (path, obj->priv->hover_path) == 0) + { + underline = PANGO_UNDERLINE_SINGLE; + } + } - if (XED_IS_FILE_BROWSER_STORE (tree_model)) - { - if (obj->priv->editable != NULL && - gtk_tree_row_reference_valid (obj->priv->editable)) - { - GtkTreePath *edpath = gtk_tree_row_reference_get_path (obj->priv->editable); + if (XED_IS_FILE_BROWSER_STORE (tree_model)) + { + if (obj->priv->editable != NULL && gtk_tree_row_reference_valid (obj->priv->editable)) + { + GtkTreePath *edpath = gtk_tree_row_reference_get_path (obj->priv->editable); - editable = edpath && gtk_tree_path_compare (path, edpath) == 0; - } - } + editable = edpath && gtk_tree_path_compare (path, edpath) == 0; + } + } - gtk_tree_path_free (path); - g_object_set (cell, "editable", editable, "underline", underline, NULL); + gtk_tree_path_free (path); + g_object_set (cell, "editable", editable, "underline", underline, NULL); } static void -xed_file_browser_view_init (XedFileBrowserView * obj) +xed_file_browser_view_init (XedFileBrowserView *obj) { - obj->priv = XED_FILE_BROWSER_VIEW_GET_PRIVATE (obj); + obj->priv = XED_FILE_BROWSER_VIEW_GET_PRIVATE (obj); - obj->priv->column = gtk_tree_view_column_new (); + obj->priv->column = gtk_tree_view_column_new (); - obj->priv->pixbuf_renderer = gtk_cell_renderer_pixbuf_new (); - gtk_tree_view_column_pack_start (obj->priv->column, - obj->priv->pixbuf_renderer, - FALSE); - gtk_tree_view_column_add_attribute (obj->priv->column, - obj->priv->pixbuf_renderer, - "pixbuf", - XED_FILE_BROWSER_STORE_COLUMN_ICON); + obj->priv->pixbuf_renderer = gtk_cell_renderer_pixbuf_new (); + gtk_tree_view_column_pack_start (obj->priv->column, obj->priv->pixbuf_renderer, FALSE); + gtk_tree_view_column_add_attribute (obj->priv->column, + obj->priv->pixbuf_renderer, + "pixbuf", + XED_FILE_BROWSER_STORE_COLUMN_ICON); - obj->priv->text_renderer = gtk_cell_renderer_text_new (); - gtk_tree_view_column_pack_start (obj->priv->column, - obj->priv->text_renderer, TRUE); - gtk_tree_view_column_add_attribute (obj->priv->column, - obj->priv->text_renderer, - "text", - XED_FILE_BROWSER_STORE_COLUMN_NAME); + obj->priv->text_renderer = gtk_cell_renderer_text_new (); + gtk_tree_view_column_pack_start (obj->priv->column, obj->priv->text_renderer, TRUE); + gtk_tree_view_column_add_attribute (obj->priv->column, + obj->priv->text_renderer, + "text", + XED_FILE_BROWSER_STORE_COLUMN_NAME); - g_signal_connect (obj->priv->text_renderer, "edited", - G_CALLBACK (on_cell_edited), obj); + g_signal_connect (obj->priv->text_renderer, "edited", + G_CALLBACK (on_cell_edited), obj); - gtk_tree_view_append_column (GTK_TREE_VIEW (obj), - obj->priv->column); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (obj), FALSE); + gtk_tree_view_append_column (GTK_TREE_VIEW (obj), obj->priv->column); + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (obj), FALSE); - gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (obj), - GDK_BUTTON1_MASK, - drag_source_targets, - G_N_ELEMENTS (drag_source_targets), - GDK_ACTION_COPY); + gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (obj), + GDK_BUTTON1_MASK, + drag_source_targets, + G_N_ELEMENTS (drag_source_targets), + GDK_ACTION_COPY); - obj->priv->busy_cursor = gdk_cursor_new (GDK_WATCH); + obj->priv->busy_cursor = gdk_cursor_new (GDK_WATCH); } static gboolean -bookmarks_separator_func (GtkTreeModel * model, GtkTreeIter * iter, - gpointer user_data) +bookmarks_separator_func (GtkTreeModel *model, + GtkTreeIter *iter, + gpointer user_data) { - guint flags; + guint flags; - gtk_tree_model_get (model, iter, - XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, - &flags, -1); + gtk_tree_model_get (model, iter, XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, &flags, -1); - return (flags & XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR); + return (flags & XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR); } /* Public */ GtkWidget * xed_file_browser_view_new (void) { - XedFileBrowserView *obj = - XED_FILE_BROWSER_VIEW (g_object_new - (XED_TYPE_FILE_BROWSER_VIEW, NULL)); + XedFileBrowserView *obj = XED_FILE_BROWSER_VIEW (g_object_new (XED_TYPE_FILE_BROWSER_VIEW, NULL)); - return GTK_WIDGET (obj); + return GTK_WIDGET (obj); } void -xed_file_browser_view_set_model (XedFileBrowserView * tree_view, - GtkTreeModel * model) +xed_file_browser_view_set_model (XedFileBrowserView *tree_view, + GtkTreeModel *model) { - GtkTreeSelection *selection; + GtkTreeSelection *selection; - if (tree_view->priv->model == model) - return; + if (tree_view->priv->model == model) + { + return; + } - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); - if (XED_IS_FILE_BOOKMARKS_STORE (model)) { - gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); - gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW - (tree_view), - bookmarks_separator_func, - NULL, NULL); - gtk_tree_view_column_set_cell_data_func (tree_view->priv-> - column, - tree_view->priv-> - text_renderer, - (GtkTreeCellDataFunc) - cell_data_cb, - tree_view, NULL); - } else { - gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); - gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW - (tree_view), NULL, - NULL, NULL); - gtk_tree_view_column_set_cell_data_func (tree_view->priv-> - column, - tree_view->priv-> - text_renderer, - (GtkTreeCellDataFunc) - cell_data_cb, - tree_view, NULL); + if (XED_IS_FILE_BOOKMARKS_STORE (model)) + { + gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); + gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW + (tree_view), + bookmarks_separator_func, + NULL, NULL); + gtk_tree_view_column_set_cell_data_func (tree_view->priv-> + column, + tree_view->priv-> + text_renderer, + (GtkTreeCellDataFunc) + cell_data_cb, + tree_view, NULL); + } + else + { + gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); + gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW + (tree_view), NULL, + NULL, NULL); + gtk_tree_view_column_set_cell_data_func (tree_view->priv-> + column, + tree_view->priv-> + text_renderer, + (GtkTreeCellDataFunc) + cell_data_cb, + tree_view, NULL); - if (tree_view->priv->restore_expand_state) - install_restore_signals (tree_view, model); + if (tree_view->priv->restore_expand_state) + { + install_restore_signals (tree_view, model); + } - } + } - if (tree_view->priv->hover_path != NULL) { - gtk_tree_path_free (tree_view->priv->hover_path); - tree_view->priv->hover_path = NULL; - } + if (tree_view->priv->hover_path != NULL) + { + gtk_tree_path_free (tree_view->priv->hover_path); + tree_view->priv->hover_path = NULL; + } - if (XED_IS_FILE_BROWSER_STORE (tree_view->priv->model)) { - if (tree_view->priv->restore_expand_state) - uninstall_restore_signals (tree_view, - tree_view->priv->model); - } + if (XED_IS_FILE_BROWSER_STORE (tree_view->priv->model)) + { + if (tree_view->priv->restore_expand_state) + { + uninstall_restore_signals (tree_view, tree_view->priv->model); + } + } - tree_view->priv->model = model; - gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), model); + tree_view->priv->model = model; + gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), model); } void -xed_file_browser_view_start_rename (XedFileBrowserView * tree_view, - GtkTreeIter * iter) +xed_file_browser_view_start_rename (XedFileBrowserView *tree_view, + GtkTreeIter *iter) { - guint flags; - GtkTreeRowReference *rowref; - GtkTreePath *path; + guint flags; + GtkTreeRowReference *rowref; + GtkTreePath *path; - g_return_if_fail (XED_IS_FILE_BROWSER_VIEW (tree_view)); - g_return_if_fail (XED_IS_FILE_BROWSER_STORE - (tree_view->priv->model)); - g_return_if_fail (iter != NULL); + g_return_if_fail (XED_IS_FILE_BROWSER_VIEW (tree_view)); + g_return_if_fail (XED_IS_FILE_BROWSER_STORE (tree_view->priv->model)); + g_return_if_fail (iter != NULL); - gtk_tree_model_get (tree_view->priv->model, iter, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - -1); + gtk_tree_model_get (tree_view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, -1); - if (!(FILE_IS_DIR (flags) || !FILE_IS_DUMMY (flags))) - return; + if (!(FILE_IS_DIR (flags) || !FILE_IS_DUMMY (flags))) + { + return; + } - path = gtk_tree_model_get_path (tree_view->priv->model, iter); - rowref = gtk_tree_row_reference_new (tree_view->priv->model, path); + path = gtk_tree_model_get_path (tree_view->priv->model, iter); + rowref = gtk_tree_row_reference_new (tree_view->priv->model, path); - /* Start editing */ - gtk_widget_grab_focus (GTK_WIDGET (tree_view)); + /* Start editing */ + gtk_widget_grab_focus (GTK_WIDGET (tree_view)); - if (gtk_tree_path_up (path)) - gtk_tree_view_expand_to_path (GTK_TREE_VIEW (tree_view), - path); + if (gtk_tree_path_up (path)) + { + gtk_tree_view_expand_to_path (GTK_TREE_VIEW (tree_view), path); + } - gtk_tree_path_free (path); - tree_view->priv->editable = rowref; + gtk_tree_path_free (path); + tree_view->priv->editable = rowref; - gtk_tree_view_set_cursor (GTK_TREE_VIEW (tree_view), - gtk_tree_row_reference_get_path (tree_view->priv->editable), - tree_view->priv->column, TRUE); + gtk_tree_view_set_cursor (GTK_TREE_VIEW (tree_view), + gtk_tree_row_reference_get_path (tree_view->priv->editable), + tree_view->priv->column, TRUE); - gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), - gtk_tree_row_reference_get_path (tree_view->priv->editable), - tree_view->priv->column, - FALSE, 0.0, 0.0); + gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), + gtk_tree_row_reference_get_path (tree_view->priv->editable), + tree_view->priv->column, + FALSE, 0.0, 0.0); } void -xed_file_browser_view_set_click_policy (XedFileBrowserView *tree_view, - XedFileBrowserViewClickPolicy policy) +xed_file_browser_view_set_click_policy (XedFileBrowserView *tree_view, + XedFileBrowserViewClickPolicy policy) { - g_return_if_fail (XED_IS_FILE_BROWSER_VIEW (tree_view)); + g_return_if_fail (XED_IS_FILE_BROWSER_VIEW (tree_view)); - set_click_policy_property (tree_view, policy); + set_click_policy_property (tree_view, policy); - g_object_notify (G_OBJECT (tree_view), "click-policy"); + g_object_notify (G_OBJECT (tree_view), "click-policy"); } void -xed_file_browser_view_set_restore_expand_state (XedFileBrowserView * tree_view, - gboolean restore_expand_state) +xed_file_browser_view_set_restore_expand_state (XedFileBrowserView *tree_view, + gboolean restore_expand_state) { - g_return_if_fail (XED_IS_FILE_BROWSER_VIEW (tree_view)); + g_return_if_fail (XED_IS_FILE_BROWSER_VIEW (tree_view)); - set_restore_expand_state (tree_view, restore_expand_state); - g_object_notify (G_OBJECT (tree_view), "restore-expand-state"); + set_restore_expand_state (tree_view, restore_expand_state); + g_object_notify (G_OBJECT (tree_view), "restore-expand-state"); } /* Signal handlers */ static void -on_cell_edited (GtkCellRendererText * cell, gchar * path, gchar * new_text, - XedFileBrowserView * tree_view) +on_cell_edited (GtkCellRendererText *cell, + gchar *path, + gchar *new_text, + XedFileBrowserView *tree_view) { - GtkTreePath * treepath; - GtkTreeIter iter; - gboolean ret; - GError * error = NULL; + GtkTreePath * treepath; + GtkTreeIter iter; + gboolean ret; + GError * error = NULL; - gtk_tree_row_reference_free (tree_view->priv->editable); - tree_view->priv->editable = NULL; + gtk_tree_row_reference_free (tree_view->priv->editable); + tree_view->priv->editable = NULL; - if (new_text == NULL || *new_text == '\0') - return; + if (new_text == NULL || *new_text == '\0') + { + return; + } - treepath = gtk_tree_path_new_from_string (path); - ret = gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_view->priv->model), &iter, treepath); - gtk_tree_path_free (treepath); + treepath = gtk_tree_path_new_from_string (path); + ret = gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_view->priv->model), &iter, treepath); + gtk_tree_path_free (treepath); - if (ret) { - if (xed_file_browser_store_rename (XED_FILE_BROWSER_STORE (tree_view->priv->model), - &iter, new_text, &error)) { - treepath = gtk_tree_model_get_path (GTK_TREE_MODEL (tree_view->priv->model), &iter); - gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), - treepath, NULL, - FALSE, 0.0, 0.0); - gtk_tree_path_free (treepath); - } - else { - if (error) { - g_signal_emit (tree_view, signals[ERROR], 0, - error->code, error->message); - g_error_free (error); - } - } - } + if (ret) + { + if (xed_file_browser_store_rename (XED_FILE_BROWSER_STORE (tree_view->priv->model), &iter, new_text, &error)) + { + treepath = gtk_tree_model_get_path (GTK_TREE_MODEL (tree_view->priv->model), &iter); + gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), treepath, NULL, FALSE, 0.0, 0.0); + gtk_tree_path_free (treepath); + } + else + { + if (error) + { + g_signal_emit (tree_view, signals[ERROR], 0, error->code, error->message); + g_error_free (error); + } + } + } } static void -on_begin_refresh (XedFileBrowserStore * model, - XedFileBrowserView * view) +on_begin_refresh (XedFileBrowserStore *model, + XedFileBrowserView *view) { - /* Store the refresh state, so we can handle unloading of nodes while - refreshing properly */ - view->priv->is_refresh = TRUE; + /* Store the refresh state, so we can handle unloading of nodes while + refreshing properly */ + view->priv->is_refresh = TRUE; } static void -on_end_refresh (XedFileBrowserStore * model, - XedFileBrowserView * view) +on_end_refresh (XedFileBrowserStore *model, + XedFileBrowserView *view) { - /* Store the refresh state, so we can handle unloading of nodes while - refreshing properly */ - view->priv->is_refresh = FALSE; + /* Store the refresh state, so we can handle unloading of nodes while + refreshing properly */ + view->priv->is_refresh = FALSE; } static void -on_unload (XedFileBrowserStore * model, - gchar const * uri, - XedFileBrowserView * view) +on_unload (XedFileBrowserStore *model, + gchar const *uri, + XedFileBrowserView *view) { - /* Don't remove the expand state if we are refreshing */ - if (!view->priv->restore_expand_state || view->priv->is_refresh) - return; + /* Don't remove the expand state if we are refreshing */ + if (!view->priv->restore_expand_state || view->priv->is_refresh) + { + return; + } - remove_expand_state (view, uri); + remove_expand_state (view, uri); } static void -restore_expand_state (XedFileBrowserView * view, - XedFileBrowserStore * model, - GtkTreeIter * iter) +restore_expand_state (XedFileBrowserView *view, + XedFileBrowserStore *model, + GtkTreeIter *iter) { - gchar * uri; - GFile * file; - GtkTreePath * path; + gchar *uri; + GFile *file; + GtkTreePath *path; - gtk_tree_model_get (GTK_TREE_MODEL (model), - iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, - &uri, - -1); + gtk_tree_model_get (GTK_TREE_MODEL (model), + iter, + XED_FILE_BROWSER_STORE_COLUMN_URI, + &uri, + -1); - if (!uri) - return; + if (!uri) + { + return; + } - file = g_file_new_for_uri (uri); - path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), iter); + file = g_file_new_for_uri (uri); + path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), iter); - if (g_hash_table_lookup (view->priv->expand_state, file)) - { - gtk_tree_view_expand_row (GTK_TREE_VIEW (view), - path, - FALSE); - } + if (g_hash_table_lookup (view->priv->expand_state, file)) + { + gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, FALSE); + } - gtk_tree_path_free (path); + gtk_tree_path_free (path); - g_object_unref (file); - g_free (uri); + g_object_unref (file); + g_free (uri); } static void -on_row_inserted (XedFileBrowserStore * model, - GtkTreePath * path, - GtkTreeIter * iter, - XedFileBrowserView * view) +on_row_inserted (XedFileBrowserStore *model, + GtkTreePath *path, + GtkTreeIter *iter, + XedFileBrowserView *view) { - GtkTreeIter parent; - GtkTreePath * copy; + GtkTreeIter parent; + GtkTreePath * copy; - if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (model), iter)) - restore_expand_state (view, model, iter); + if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (model), iter)) + { + restore_expand_state (view, model, iter); + } - copy = gtk_tree_path_copy (path); + copy = gtk_tree_path_copy (path); - if (gtk_tree_path_up (copy) && - (gtk_tree_path_get_depth (copy) != 0) && - gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &parent, copy)) - { - restore_expand_state (view, model, &parent); - } + if (gtk_tree_path_up (copy) && + (gtk_tree_path_get_depth (copy) != 0) && + gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &parent, copy)) + { + restore_expand_state (view, model, &parent); + } - gtk_tree_path_free (copy); + gtk_tree_path_free (copy); } void diff --git a/plugins/filebrowser/xed-file-browser-view.h b/plugins/filebrowser/xed-file-browser-view.h index 353c6c4..2f0e765 100644 --- a/plugins/filebrowser/xed-file-browser-view.h +++ b/plugins/filebrowser/xed-file-browser-view.h @@ -25,60 +25,61 @@ #include G_BEGIN_DECLS -#define XED_TYPE_FILE_BROWSER_VIEW (xed_file_browser_view_get_type ()) -#define XED_FILE_BROWSER_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_VIEW, XedFileBrowserView)) -#define XED_FILE_BROWSER_VIEW_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_VIEW, XedFileBrowserView const)) -#define XED_FILE_BROWSER_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_FILE_BROWSER_VIEW, XedFileBrowserViewClass)) -#define XED_IS_FILE_BROWSER_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_FILE_BROWSER_VIEW)) -#define XED_IS_FILE_BROWSER_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_BROWSER_VIEW)) -#define XED_FILE_BROWSER_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_BROWSER_VIEW, XedFileBrowserViewClass)) +#define XED_TYPE_FILE_BROWSER_VIEW (xed_file_browser_view_get_type ()) +#define XED_FILE_BROWSER_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_VIEW, XedFileBrowserView)) +#define XED_FILE_BROWSER_VIEW_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_VIEW, XedFileBrowserView const)) +#define XED_FILE_BROWSER_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_FILE_BROWSER_VIEW, XedFileBrowserViewClass)) +#define XED_IS_FILE_BROWSER_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_FILE_BROWSER_VIEW)) +#define XED_IS_FILE_BROWSER_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_BROWSER_VIEW)) +#define XED_FILE_BROWSER_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_BROWSER_VIEW, XedFileBrowserViewClass)) typedef struct _XedFileBrowserView XedFileBrowserView; typedef struct _XedFileBrowserViewClass XedFileBrowserViewClass; typedef struct _XedFileBrowserViewPrivate XedFileBrowserViewPrivate; -typedef enum { - XED_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE, - XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE +typedef enum +{ + XED_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE, + XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE } XedFileBrowserViewClickPolicy; struct _XedFileBrowserView { - GtkTreeView parent; + GtkTreeView parent; - XedFileBrowserViewPrivate *priv; + XedFileBrowserViewPrivate *priv; }; struct _XedFileBrowserViewClass { - GtkTreeViewClass parent_class; + GtkTreeViewClass parent_class; - /* Signals */ - void (*error) (XedFileBrowserView * filetree, - guint code, - gchar const *message); - void (*file_activated) (XedFileBrowserView * filetree, - GtkTreeIter *iter); - void (*directory_activated) (XedFileBrowserView * filetree, - GtkTreeIter *iter); - void (*bookmark_activated) (XedFileBrowserView * filetree, - GtkTreeIter *iter); + /* Signals */ + void (*error) (XedFileBrowserView *filetree, + guint code, + gchar const *message); + void (*file_activated) (XedFileBrowserView *filetree, + GtkTreeIter *iter); + void (*directory_activated) (XedFileBrowserView *filetree, + GtkTreeIter *iter); + void (*bookmark_activated) (XedFileBrowserView *filetree, + GtkTreeIter *iter); }; -GType xed_file_browser_view_get_type (void) G_GNUC_CONST; -void _xed_file_browser_view_register_type (GTypeModule * module); +GType xed_file_browser_view_get_type (void) G_GNUC_CONST; +void _xed_file_browser_view_register_type (GTypeModule *type_module); -GtkWidget *xed_file_browser_view_new (void); -void xed_file_browser_view_set_model (XedFileBrowserView * tree_view, - GtkTreeModel * model); -void xed_file_browser_view_start_rename (XedFileBrowserView * tree_view, - GtkTreeIter * iter); -void xed_file_browser_view_set_click_policy (XedFileBrowserView * tree_view, - XedFileBrowserViewClickPolicy policy); -void xed_file_browser_view_set_restore_expand_state (XedFileBrowserView * tree_view, - gboolean restore_expand_state); +GtkWidget *xed_file_browser_view_new (void); +void xed_file_browser_view_set_model (XedFileBrowserView *tree_view, + GtkTreeModel *model); +void xed_file_browser_view_start_rename (XedFileBrowserView *tree_view, + GtkTreeIter *iter); +void xed_file_browser_view_set_click_policy (XedFileBrowserView *tree_view, + XedFileBrowserViewClickPolicy policy); +void xed_file_browser_view_set_restore_expand_state (XedFileBrowserView *tree_view, + gboolean restore_expand_state); G_END_DECLS -#endif /* __XED_FILE_BROWSER_VIEW_H__ */ +#endif /* __XED_FILE_BROWSER_VIEW_H__ */ // ex:ts=8:noet: diff --git a/plugins/filebrowser/xed-file-browser-widget.c b/plugins/filebrowser/xed-file-browser-widget.c index 0d95c9c..a9a8488 100644 --- a/plugins/filebrowser/xed-file-browser-widget.c +++ b/plugins/filebrowser/xed-file-browser-widget.c @@ -43,8 +43,8 @@ #include "xed-file-browser-enum-types.h" #define XED_FILE_BROWSER_WIDGET_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), \ - XED_TYPE_FILE_BROWSER_WIDGET, \ - XedFileBrowserWidgetPrivate)) + XED_TYPE_FILE_BROWSER_WIDGET, \ + XedFileBrowserWidgetPrivate)) #define XML_UI_FILE "xed-file-browser-widget-ui.xml" #define LOCATION_DATA_KEY "xed-file-browser-widget-location" @@ -800,18 +800,15 @@ static GtkActionEntry toplevel_actions[] = static const GtkActionEntry tree_actions_selection[] = { {"FileMoveToTrash", "user-trash", N_("_Move to Trash"), NULL, - N_("Move selected file or folder to trash"), - G_CALLBACK (on_action_file_move_to_trash)}, + N_("Move selected file or folder to trash"), G_CALLBACK (on_action_file_move_to_trash)}, {"FileDelete", "edit-delete-symbolic", N_("_Delete"), NULL, - N_("Delete selected file or folder"), - G_CALLBACK (on_action_file_delete)} + N_("Delete selected file or folder"), G_CALLBACK (on_action_file_delete)} }; static const GtkActionEntry tree_actions_file_selection[] = { - {"FileOpen", "document-open-symbolic", N_("Open"), NULL, - N_("Open selected file"), - G_CALLBACK (on_action_file_open)} + {"FileOpen", "document-open-symbolic", N_("_Open"), NULL, + N_("Open selected file"), G_CALLBACK (on_action_file_open)} }; static const GtkActionEntry tree_actions[] = @@ -823,8 +820,7 @@ static const GtkActionEntry tree_actions[] = static const GtkActionEntry tree_actions_single_most_selection[] = { {"DirectoryNew", "folder-new-symbolic", N_("_New Folder"), NULL, - N_("Add new empty folder"), - G_CALLBACK (on_action_directory_new)}, + N_("Add new empty folder"), G_CALLBACK (on_action_directory_new)}, {"FileNew", "document-new-symbolic", N_("New F_ile"), NULL, N_("Add new empty file"), G_CALLBACK (on_action_file_new)} }; @@ -832,33 +828,27 @@ static const GtkActionEntry tree_actions_single_most_selection[] = static const GtkActionEntry tree_actions_single_selection[] = { {"FileRename", NULL, N_("_Rename"), NULL, - N_("Rename selected file or folder"), - G_CALLBACK (on_action_file_rename)} + N_("Rename selected file or folder"), G_CALLBACK (on_action_file_rename)} }; static const GtkActionEntry tree_actions_sensitive[] = { {"DirectoryPrevious", "go-previous-symbolic", N_("_Previous Location"), NULL, - N_("Go to the previous visited location"), - G_CALLBACK (on_action_directory_previous)}, + N_("Go to the previous visited location"), G_CALLBACK (on_action_directory_previous)}, {"DirectoryNext", "go-next-symbolic", N_("_Next Location"), NULL, N_("Go to the next visited location"), G_CALLBACK (on_action_directory_next)}, {"DirectoryRefresh", "view-refresh-symbolic", N_("Re_fresh View"), NULL, N_("Refresh the view"), G_CALLBACK (on_action_directory_refresh)}, {"DirectoryOpen", "folder-open-symbolic", N_("_View Folder"), NULL, - N_("View folder in file manager"), - G_CALLBACK (on_action_directory_open)} + N_("View folder in file manager"), G_CALLBACK (on_action_directory_open)} }; static const GtkToggleActionEntry tree_actions_toggle[] = { - {"FilterHidden", GTK_STOCK_DIALOG_AUTHENTICATION, - N_("Show _Hidden"), NULL, - N_("Show hidden files and folders"), - G_CALLBACK (on_action_filter_hidden), FALSE}, + {"FilterHidden", GTK_STOCK_DIALOG_AUTHENTICATION, N_("Show _Hidden"), NULL, + N_("Show hidden files and folders"), G_CALLBACK (on_action_filter_hidden), FALSE}, {"FilterBinary", NULL, N_("Show _Binary"), NULL, - N_("Show binary files"), G_CALLBACK (on_action_filter_binary), - FALSE} + N_("Show binary files"), G_CALLBACK (on_action_filter_binary), FALSE} }; static const GtkActionEntry bookmark_actions[] = diff --git a/plugins/filebrowser/xed-file-browser-widget.h b/plugins/filebrowser/xed-file-browser-widget.h index 65f7b49..5d91cf1 100644 --- a/plugins/filebrowser/xed-file-browser-widget.h +++ b/plugins/filebrowser/xed-file-browser-widget.h @@ -71,7 +71,7 @@ struct _XedFileBrowserWidgetClass }; GType xed_file_browser_widget_get_type (void) G_GNUC_CONST; -void _xed_file_browser_widget_register_type (GTypeModule * module); +void _xed_file_browser_widget_register_type (GTypeModule *type_module); GtkWidget *xed_file_browser_widget_new (const gchar *data_dir); diff --git a/plugins/modelines/modeline-parser.c b/plugins/modelines/modeline-parser.c index f0962ef..2661912 100644 --- a/plugins/modelines/modeline-parser.c +++ b/plugins/modelines/modeline-parser.c @@ -64,7 +64,7 @@ typedef struct _ModelineOptions GtkWrapMode wrap_mode; gboolean display_right_margin; guint right_margin_position; - + ModelineSet set; } ModelineOptions; @@ -80,7 +80,10 @@ has_option (ModelineOptions *options, void modeline_parser_init (const gchar *data_dir) { - modelines_data_dir = g_strdup (data_dir); + if (modelines_data_dir == NULL) + { + modelines_data_dir = g_strdup (data_dir); + } } void @@ -94,12 +97,13 @@ modeline_parser_shutdown () if (kate_languages != NULL) g_hash_table_destroy (kate_languages); - + vim_languages = NULL; emacs_languages = NULL; kate_languages = NULL; g_free (modelines_data_dir); + modelines_data_dir = NULL; } static GHashTable * @@ -224,7 +228,7 @@ skip_whitespaces (gchar **s) } /* Parse vi(m) modelines. - * Vi(m) modelines looks like this: + * Vi(m) modelines looks like this: * - first form: [text]{white}{vi:|vim:|ex:}[white]{options} * - second form: [text]{white}{vi:|vim:|ex:}[white]se[t] {options}:[text] * They can happen on the three first or last lines. @@ -289,7 +293,7 @@ parse_vim_modeline (gchar *s, { g_free (options->language_id); options->language_id = get_language_id_vim (value->str); - + options->set |= MODELINE_SET_LANGUAGE; } else if (strcmp (key->str, "et") == 0 || @@ -302,7 +306,7 @@ parse_vim_modeline (gchar *s, strcmp (key->str, "tabstop") == 0) { intval = atoi (value->str); - + if (intval) { options->tab_width = intval; @@ -313,7 +317,7 @@ parse_vim_modeline (gchar *s, strcmp (key->str, "shiftwidth") == 0) { intval = atoi (value->str); - + if (intval) { options->indent_width = intval; @@ -326,18 +330,18 @@ parse_vim_modeline (gchar *s, options->set |= MODELINE_SET_WRAP_MODE; } - else if (strcmp (key->str, "textwidth") == 0) + else if (strcmp (key->str, "textwidth") == 0 || strcmp (key->str, "tw") == 0) { intval = atoi (value->str); - + if (intval) { options->right_margin_position = intval; options->display_right_margin = TRUE; - + options->set |= MODELINE_SET_SHOW_RIGHT_MARGIN | MODELINE_SET_RIGHT_MARGIN_POSITION; - + } } } @@ -406,13 +410,13 @@ parse_emacs_modeline (gchar *s, { g_free (options->language_id); options->language_id = get_language_id_emacs (value->str); - + options->set |= MODELINE_SET_LANGUAGE; } else if (strcmp (key->str, "tab-width") == 0) { intval = atoi (value->str); - + if (intval) { options->tab_width = intval; @@ -422,7 +426,7 @@ parse_emacs_modeline (gchar *s, else if (strcmp (key->str, "indent-offset") == 0) { intval = atoi (value->str); - + if (intval) { options->indent_width = intval; @@ -433,14 +437,14 @@ parse_emacs_modeline (gchar *s, { intval = strcmp (value->str, "nil") == 0; options->insert_spaces = intval; - + options->set |= MODELINE_SET_INSERT_SPACES; } else if (strcmp (key->str, "autowrap") == 0) { intval = strcmp (value->str, "nil") != 0; options->wrap_mode = intval ? GTK_WRAP_WORD : GTK_WRAP_NONE; - + options->set |= MODELINE_SET_WRAP_MODE; } } @@ -504,13 +508,13 @@ parse_kate_modeline (gchar *s, { g_free (options->language_id); options->language_id = get_language_id_kate (value->str); - + options->set |= MODELINE_SET_LANGUAGE; } else if (strcmp (key->str, "tab-width") == 0) { intval = atoi (value->str); - + if (intval) { options->tab_width = intval; @@ -539,17 +543,17 @@ parse_kate_modeline (gchar *s, options->wrap_mode = intval ? GTK_WRAP_WORD : GTK_WRAP_NONE; - options->set |= MODELINE_SET_WRAP_MODE; + options->set |= MODELINE_SET_WRAP_MODE; } else if (strcmp (key->str, "word-wrap-column") == 0) { intval = atoi (value->str); - + if (intval) { options->right_margin_position = intval; options->display_right_margin = TRUE; - + options->set |= MODELINE_SET_RIGHT_MARGIN_POSITION | MODELINE_SET_SHOW_RIGHT_MARGIN; } @@ -611,7 +615,7 @@ check_previous (GtkSourceView *view, ModelineSet set) { GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); - + /* Do not restore default when this is the first time */ if (!previous) return FALSE; @@ -648,7 +652,7 @@ check_previous (GtkSourceView *view, case MODELINE_SET_LANGUAGE: { GtkSourceLanguage *language = gtk_source_buffer_get_language (buffer); - + return (language == NULL && previous->language_id == NULL) || (language != NULL && g_strcmp0 (gtk_source_language_get_id (language), previous->language_id) == 0); @@ -674,7 +678,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) GtkTextBuffer *buffer; GtkTextIter iter, liter; gint line_count; - + options.language_id = NULL; options.set = MODELINE_SET_NONE; @@ -757,7 +761,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) } } - ModelineOptions *previous = g_object_get_data (G_OBJECT (buffer), + ModelineOptions *previous = g_object_get_data (G_OBJECT (buffer), MODELINE_OPTIONS_DATA_KEY); /* Apply the options we got from modelines and restore defaults if @@ -773,17 +777,17 @@ modeline_parser_apply_modeline (GtkSourceView *view) (view, xed_prefs_manager_get_insert_spaces ()); } - + if (has_option (&options, MODELINE_SET_TAB_WIDTH)) { gtk_source_view_set_tab_width (view, options.tab_width); } else if (check_previous (view, previous, MODELINE_SET_TAB_WIDTH)) { - gtk_source_view_set_tab_width (view, + gtk_source_view_set_tab_width (view, xed_prefs_manager_get_tabs_size ()); } - + if (has_option (&options, MODELINE_SET_INDENT_WIDTH)) { gtk_source_view_set_indent_width (view, options.indent_width); @@ -792,39 +796,40 @@ modeline_parser_apply_modeline (GtkSourceView *view) { gtk_source_view_set_indent_width (view, -1); } - + if (has_option (&options, MODELINE_SET_WRAP_MODE)) { gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), options.wrap_mode); } else if (check_previous (view, previous, MODELINE_SET_WRAP_MODE)) { - gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), xed_prefs_manager_get_wrap_mode ()); } - + if (has_option (&options, MODELINE_SET_RIGHT_MARGIN_POSITION)) { gtk_source_view_set_right_margin_position (view, options.right_margin_position); } else if (check_previous (view, previous, MODELINE_SET_RIGHT_MARGIN_POSITION)) { - gtk_source_view_set_right_margin_position (view, + gtk_source_view_set_right_margin_position (view, xed_prefs_manager_get_right_margin_position ()); } - + if (has_option (&options, MODELINE_SET_SHOW_RIGHT_MARGIN)) { gtk_source_view_set_show_right_margin (view, options.display_right_margin); } else if (check_previous (view, previous, MODELINE_SET_SHOW_RIGHT_MARGIN)) { - gtk_source_view_set_show_right_margin (view, + gtk_source_view_set_show_right_margin (view, xed_prefs_manager_get_display_right_margin ()); } - + if (previous) { + g_free (previous->language_id); *previous = options; previous->language_id = g_strdup (options.language_id); } @@ -833,13 +838,13 @@ modeline_parser_apply_modeline (GtkSourceView *view) previous = g_slice_new (ModelineOptions); *previous = options; previous->language_id = g_strdup (options.language_id); - - g_object_set_data_full (G_OBJECT (buffer), - MODELINE_OPTIONS_DATA_KEY, + + g_object_set_data_full (G_OBJECT (buffer), + MODELINE_OPTIONS_DATA_KEY, previous, (GDestroyNotify)free_modeline_options); } - + g_free (options.language_id); } diff --git a/plugins/modelines/modeline-parser.h b/plugins/modelines/modeline-parser.h index 5c97b00..470d7ef 100644 --- a/plugins/modelines/modeline-parser.h +++ b/plugins/modelines/modeline-parser.h @@ -1,14 +1,14 @@ /* * modelie-parser.h * Emacs, Kate and Vim-style modelines support for xed. - * + * * Copyright (C) 2005-2007 - Steve Frécinaux * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -23,14 +23,14 @@ #define __MODELINE_PARSER_H__ #include -#include +#include G_BEGIN_DECLS -void modeline_parser_init (const gchar *data_dir); -void modeline_parser_shutdown (void); -void modeline_parser_apply_modeline (GtkSourceView *view); -void modeline_parser_deactivate (GtkSourceView *view); +void modeline_parser_init (const gchar *data_dir); +void modeline_parser_shutdown (void); +void modeline_parser_apply_modeline (GtkSourceView *view); +void modeline_parser_deactivate (GtkSourceView *view); G_END_DECLS diff --git a/plugins/modelines/xed-modeline-plugin.c b/plugins/modelines/xed-modeline-plugin.c index 47f9d3c..940fdbc 100644 --- a/plugins/modelines/xed-modeline-plugin.c +++ b/plugins/modelines/xed-modeline-plugin.c @@ -20,90 +20,65 @@ */ #ifdef HAVE_CONFIG_H -# include +# include #endif #include #include -#include #include "xed-modeline-plugin.h" #include "modeline-parser.h" -#include #include -#include - -#define DOCUMENT_DATA_KEY "XedModelinePluginDocumentData" +#include +#include struct _XedModelinePluginPrivate { - GtkWidget *window; + XedView *view; - gulong tab_added_handler_id; - gulong tab_removed_handler_id; + gulong document_loaded_handler_id; + gulong document_saved_handler_id; }; -typedef struct -{ - gulong document_loaded_handler_id; - gulong document_saved_handler_id; -} DocumentData; - enum { PROP_0, - PROP_OBJECT + PROP_VIEW }; -static void peas_activatable_iface_init (PeasActivatableInterface *iface); +static void xed_view_activatable_iface_init (XedViewActivatableInterface *iface); G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedModelinePlugin, xed_modeline_plugin, PEAS_TYPE_EXTENSION_BASE, 0, - G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, - peas_activatable_iface_init)) - -static void -document_data_free (DocumentData *ddata) -{ - g_slice_free (DocumentData, ddata); -} + G_IMPLEMENT_INTERFACE_DYNAMIC (XED_TYPE_VIEW_ACTIVATABLE, + xed_view_activatable_iface_init)) static void xed_modeline_plugin_constructed (GObject *object) { - gchar *data_dir; + gchar *data_dir; - data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (object)); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (object)); - modeline_parser_init (data_dir); + modeline_parser_init (data_dir); - g_free (data_dir); + g_free (data_dir); - G_OBJECT_CLASS (xed_modeline_plugin_parent_class)->constructed (object); + G_OBJECT_CLASS (xed_modeline_plugin_parent_class)->constructed (object); } static void xed_modeline_plugin_init (XedModelinePlugin *plugin) { - xed_debug_message (DEBUG_PLUGINS, "XedModelinePlugin initializing"); + xed_debug_message (DEBUG_PLUGINS, "XedModelinePlugin initializing"); plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin, XED_TYPE_MODELINE_PLUGIN, XedModelinePluginPrivate); } -static void -xed_modeline_plugin_finalize (GObject *object) -{ - xed_debug_message (DEBUG_PLUGINS, "XedModelinePlugin finalizing"); - - modeline_parser_shutdown (); - - G_OBJECT_CLASS (xed_modeline_plugin_parent_class)->finalize (object); -} - static void xed_modeline_plugin_dispose (GObject *object) { @@ -111,15 +86,21 @@ xed_modeline_plugin_dispose (GObject *object) xed_debug_message (DEBUG_PLUGINS, "XedModelinePlugin disposing"); - if (plugin->priv->window != NULL) - { - g_object_unref (plugin->priv->window); - plugin->priv->window = NULL; - } + g_clear_object (&plugin->priv->view); G_OBJECT_CLASS (xed_modeline_plugin_parent_class)->dispose (object); } +static void +xed_modeline_plugin_finalize (GObject *object) +{ + xed_debug_message (DEBUG_PLUGINS, "XedModelinePlugin finalizing"); + + modeline_parser_shutdown (); + + G_OBJECT_CLASS (xed_modeline_plugin_parent_class)->finalize (object); +} + static void xed_modeline_plugin_set_property (GObject *object, guint prop_id, @@ -130,8 +111,8 @@ xed_modeline_plugin_set_property (GObject *object, switch (prop_id) { - case PROP_OBJECT: - plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + case PROP_VIEW: + plugin->priv->view = XED_VIEW (g_value_dup_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -149,8 +130,8 @@ xed_modeline_plugin_get_property (GObject *object, switch (prop_id) { - case PROP_OBJECT: - g_value_set_object (value, plugin->priv->window); + case PROP_VIEW: + g_value_set_object (value, plugin->priv->view); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -159,131 +140,49 @@ xed_modeline_plugin_get_property (GObject *object, } static void -on_document_loaded_or_saved (XedDocument *document, - const GError *error, - GtkSourceView *view) +on_document_loaded_or_saved (XedDocument *document, + const GError *error, + GtkSourceView *view) { - modeline_parser_apply_modeline (view); + modeline_parser_apply_modeline (view); } static void -connect_handlers (XedView *view) +xed_modeline_plugin_activate (XedViewActivatable *activatable) { - DocumentData *data; - GtkTextBuffer *doc; + XedModelinePlugin *plugin; + GtkTextBuffer *doc; - doc = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); + xed_debug (DEBUG_PLUGINS); - data = g_slice_new (DocumentData); + plugin = XED_MODELINE_PLUGIN (activatable); - data->document_loaded_handler_id = - g_signal_connect (doc, "loaded", - G_CALLBACK (on_document_loaded_or_saved), - view); - data->document_saved_handler_id = - g_signal_connect (doc, "saved", - G_CALLBACK (on_document_loaded_or_saved), - view); + modeline_parser_apply_modeline (GTK_SOURCE_VIEW (plugin->priv->view)); - g_object_set_data_full (G_OBJECT (doc), DOCUMENT_DATA_KEY, - data, (GDestroyNotify) document_data_free); + doc = gtk_text_view_get_buffer (GTK_TEXT_VIEW (plugin->priv->view)); + + plugin->priv->document_loaded_handler_id = + g_signal_connect (doc, "loaded", + G_CALLBACK (on_document_loaded_or_saved), plugin->priv->view); + plugin->priv->document_saved_handler_id = + g_signal_connect (doc, "saved", + G_CALLBACK (on_document_loaded_or_saved), plugin->priv->view); } static void -disconnect_handlers (XedView *view) +xed_modeline_plugin_deactivate (XedViewActivatable *activatable) { - DocumentData *data; - GtkTextBuffer *doc; + XedModelinePlugin *plugin; + GtkTextBuffer *doc; - doc = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); + xed_debug (DEBUG_PLUGINS); - data = g_object_steal_data (G_OBJECT (doc), DOCUMENT_DATA_KEY); + plugin = XED_MODELINE_PLUGIN (activatable); - if (data) - { - g_signal_handler_disconnect (doc, data->document_loaded_handler_id); - g_signal_handler_disconnect (doc, data->document_saved_handler_id); + doc = gtk_text_view_get_buffer (GTK_TEXT_VIEW (plugin->priv->view)); - document_data_free (data); - } - else - { - g_warning ("Modeline handlers not found"); - } -} - -static void -on_window_tab_added (XedWindow *window, - XedTab *tab, - gpointer user_data) -{ - connect_handlers (xed_tab_get_view (tab)); -} - -static void -on_window_tab_removed (XedWindow *window, - XedTab *tab, - gpointer user_data) -{ - disconnect_handlers (xed_tab_get_view (tab)); -} - -static void -xed_modeline_plugin_activate (PeasActivatable *activatable) -{ - XedModelinePluginPrivate *data; - XedWindow *window; - GList *views; - GList *l; - - xed_debug (DEBUG_PLUGINS); - - data = XED_MODELINE_PLUGIN (activatable)->priv; - window = XED_WINDOW (data->window); - - views = xed_window_get_views (window); - for (l = views; l != NULL; l = l->next) - { - connect_handlers (XED_VIEW (l->data)); - modeline_parser_apply_modeline (GTK_SOURCE_VIEW (l->data)); - } - g_list_free (views); - - data->tab_added_handler_id = - g_signal_connect (window, "tab-added", - G_CALLBACK (on_window_tab_added), NULL); - - data->tab_removed_handler_id = - g_signal_connect (window, "tab-removed", - G_CALLBACK (on_window_tab_removed), NULL); -} - -static void -xed_modeline_plugin_deactivate (PeasActivatable *activatable) -{ - XedModelinePluginPrivate *data; - XedWindow *window; - GList *views; - GList *l; - - xed_debug (DEBUG_PLUGINS); - - data = XED_MODELINE_PLUGIN (activatable)->priv; - window = XED_WINDOW (data->window); - - g_signal_handler_disconnect (window, data->tab_added_handler_id); - g_signal_handler_disconnect (window, data->tab_removed_handler_id); - - views = xed_window_get_views (window); - - for (l = views; l != NULL; l = l->next) - { - disconnect_handlers (XED_VIEW (l->data)); - - modeline_parser_deactivate (GTK_SOURCE_VIEW (l->data)); - } - - g_list_free (views); + g_signal_handler_disconnect (doc, plugin->priv->document_loaded_handler_id); + g_signal_handler_disconnect (doc, plugin->priv->document_saved_handler_id); } static void @@ -292,35 +191,35 @@ xed_modeline_plugin_class_init (XedModelinePluginClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->constructed = xed_modeline_plugin_constructed; - object_class->finalize = xed_modeline_plugin_finalize; object_class->dispose = xed_modeline_plugin_dispose; + object_class->finalize = xed_modeline_plugin_finalize; object_class->set_property = xed_modeline_plugin_set_property; object_class->get_property = xed_modeline_plugin_get_property; - g_object_class_override_property (object_class, PROP_OBJECT, "object"); + g_object_class_override_property (object_class, PROP_VIEW, "view"); g_type_class_add_private (klass, sizeof (XedModelinePluginPrivate)); } +static void +xed_view_activatable_iface_init (XedViewActivatableInterface *iface) +{ + iface->activate = xed_modeline_plugin_activate; + iface->deactivate = xed_modeline_plugin_deactivate; +} + static void xed_modeline_plugin_class_finalize (XedModelinePluginClass *klass) { /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ } -static void -peas_activatable_iface_init (PeasActivatableInterface *iface) -{ - iface->activate = xed_modeline_plugin_activate; - iface->deactivate = xed_modeline_plugin_deactivate; -} - G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module) { xed_modeline_plugin_register_type (G_TYPE_MODULE (module)); peas_object_module_register_extension_type (module, - PEAS_TYPE_ACTIVATABLE, + XED_TYPE_VIEW_ACTIVATABLE, XED_TYPE_MODELINE_PLUGIN); } diff --git a/plugins/modelines/xed-modeline-plugin.h b/plugins/modelines/xed-modeline-plugin.h index 59e8240..8c16507 100644 --- a/plugins/modelines/xed-modeline-plugin.h +++ b/plugins/modelines/xed-modeline-plugin.h @@ -39,10 +39,11 @@ G_BEGIN_DECLS /* Private structure type */ typedef struct _XedModelinePlugin XedModelinePlugin; typedef struct _XedModelinePluginPrivate XedModelinePluginPrivate; +typedef struct _XedModelinePluginClass XedModelinePluginClass; struct _XedModelinePlugin { - PeasExtensionBase parent_instance; + PeasExtensionBase parent; /*< private >*/ XedModelinePluginPrivate *priv; diff --git a/xed/Makefile.am b/xed/Makefile.am index fadeb3e..492c710 100644 --- a/xed/Makefile.am +++ b/xed/Makefile.am @@ -70,6 +70,7 @@ NOINST_H_FILES = \ INST_H_FILES = \ xed-app.h \ + xed-app-activatable.h \ xed-commands.h \ xed-debug.h \ xed-document.h \ @@ -91,7 +92,9 @@ INST_H_FILES = \ xed-tab.h \ xed-utils.h \ xed-view.h \ - xed-window.h + xed-view-activatable.h \ + xed-window.h \ + xed-window-activatable.h if !ENABLE_GVFS_METADATA INST_H_FILES += xed-metadata-manager.h @@ -105,6 +108,7 @@ header_DATA = \ libxed_c_files = \ xed-app.c \ + xed-app-activatable.c \ xed-close-button.c \ xed-commands-documents.c \ xed-commands-edit.c \ @@ -152,7 +156,9 @@ libxed_c_files = \ xed-tab-label.c \ xed-utils.c \ xed-view.c \ + xed-view-activatable.c \ xed-window.c \ + xed-window-activatable.c \ xedtextregion.c libxed_la_SOURCES = \ diff --git a/xed/xed-app-activatable.c b/xed/xed-app-activatable.c new file mode 100644 index 0000000..086e0c9 --- /dev/null +++ b/xed/xed-app-activatable.c @@ -0,0 +1,108 @@ +/* + * xed-app-activatable.h + * This file is part of xed + * + * Copyright (C) 2010 Steve Frécinaux + * Copyright (C) 2010 Jesse van den Kieboom + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "xed-app-activatable.h" +#include "xed-app.h" + +/** + * SECTION:xed-app-activatable + * @short_description: Interface for activatable extensions on apps + * @see_also: #PeasExtensionSet + * + * #XedAppActivatable is an interface which should be implemented by + * extensions that should be activated on a xed application. + **/ + +G_DEFINE_INTERFACE(XedAppActivatable, xed_app_activatable, G_TYPE_OBJECT) + +void +xed_app_activatable_default_init (XedAppActivatableInterface *iface) +{ + static gboolean initialized = FALSE; + + if (!initialized) + { + /** + * XedAppActivatable:app: + * + * The app property contains the xed app for this + * #XedAppActivatable instance. + */ + g_object_interface_install_property (iface, + g_param_spec_object ("app", + "App", + "The xed app", + XED_TYPE_APP, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + initialized = TRUE; + } +} + +/** + * xed_app_activatable_activate: + * @activatable: A #XedAppActivatable. + * + * Activates the extension on the application. + */ +void +xed_app_activatable_activate (XedAppActivatable *activatable) +{ + XedAppActivatableInterface *iface; + + g_return_if_fail (XED_IS_APP_ACTIVATABLE (activatable)); + + iface = XED_APP_ACTIVATABLE_GET_IFACE (activatable); + + if (iface->activate != NULL) + { + iface->activate (activatable); + } +} + +/** + * xed_app_activatable_deactivate: + * @activatable: A #XedAppActivatable. + * + * Deactivates the extension from the application. + * + */ +void +xed_app_activatable_deactivate (XedAppActivatable *activatable) +{ + XedAppActivatableInterface *iface; + + g_return_if_fail (XED_IS_APP_ACTIVATABLE (activatable)); + + iface = XED_APP_ACTIVATABLE_GET_IFACE (activatable); + + if (iface->deactivate != NULL) + { + iface->deactivate (activatable); + } +} diff --git a/xed/xed-app-activatable.h b/xed/xed-app-activatable.h new file mode 100644 index 0000000..19dca02 --- /dev/null +++ b/xed/xed-app-activatable.h @@ -0,0 +1,61 @@ +/* + * xed-app-activatable.h + * This file is part of xed + * + * Copyright (C) 2010 - Steve Frécinaux + * Copyright (C) 2010 - Jesse van den Kieboom + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __XED_APP_ACTIVATABLE_H__ +#define __XED_APP_ACTIVATABLE_H__ + +#include + +G_BEGIN_DECLS + +/* + * Type checking and casting macros + */ +#define XED_TYPE_APP_ACTIVATABLE (xed_app_activatable_get_type ()) +#define XED_APP_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_APP_ACTIVATABLE, XedAppActivatable)) +#define XED_APP_ACTIVATABLE_IFACE(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), XED_TYPE_APP_ACTIVATABLE, XedAppActivatableInterface)) +#define XED_IS_APP_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_APP_ACTIVATABLE)) +#define XED_APP_ACTIVATABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), XED_TYPE_APP_ACTIVATABLE, XedAppActivatableInterface)) + +typedef struct _XedAppActivatable XedAppActivatable; /* dummy typedef */ +typedef struct _XedAppActivatableInterface XedAppActivatableInterface; + +struct _XedAppActivatableInterface +{ + GTypeInterface g_iface; + + /* Virtual public methods */ + void (*activate) (XedAppActivatable *activatable); + void (*deactivate) (XedAppActivatable *activatable); +}; + +/* + * Public methods + */ +GType xed_app_activatable_get_type (void) G_GNUC_CONST; + +void xed_app_activatable_activate (XedAppActivatable *activatable); +void xed_app_activatable_deactivate (XedAppActivatable *activatable); + +G_END_DECLS + +#endif /* __XED_APP_ACTIVATABLE_H__ */ diff --git a/xed/xed-app.c b/xed/xed-app.c index 5ca4f3c..70c520c 100644 --- a/xed/xed-app.c +++ b/xed/xed-app.c @@ -36,6 +36,7 @@ #include #include +#include #include "xed-app.h" #include "xed-prefs-manager-app.h" @@ -45,6 +46,8 @@ #include "xed-utils.h" #include "xed-enum-types.h" #include "xed-dirs.h" +#include "xed-app-activatable.h" +#include "xed-plugins-engine.h" #define XED_PAGE_SETUP_FILE "xed-page-setup" #define XED_PRINT_SETTINGS_FILE "xed-print-settings" @@ -61,8 +64,11 @@ struct _XedAppPrivate { GList *windows; XedWindow *active_window; + GtkPageSetup *page_setup; GtkPrintSettings *print_settings; + + PeasExtensionSet *extensions; }; G_DEFINE_TYPE(XedApp, xed_app, G_TYPE_OBJECT) @@ -87,6 +93,16 @@ xed_app_finalize (GObject *object) G_OBJECT_CLASS (xed_app_parent_class)->finalize (object); } +static void +xed_app_dispose (GObject *object) +{ + XedApp *app = XED_APP (object); + + g_clear_object (&app->priv->extensions); + + G_OBJECT_CLASS (xed_app_parent_class)->dispose (object); +} + static void xed_app_get_property (GObject *object, guint prop_id, @@ -107,9 +123,10 @@ xed_app_class_init (XedAppClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = xed_app_finalize; + object_class->dispose = xed_app_dispose; object_class->get_property = xed_app_get_property; - g_type_class_add_private (object_class, sizeof(XedAppPrivate)); + g_type_class_add_private (object_class, sizeof (XedAppPrivate)); } static gboolean @@ -308,19 +325,40 @@ save_print_settings (XedApp *app) g_free (filename); } +static void +extension_added (PeasExtensionSet *extensions, + PeasPluginInfo *info, + PeasExtension *exten, + XedApp *app) +{ + peas_extension_call (exten, "activate"); +} + +static void +extension_removed (PeasExtensionSet *extensions, + PeasPluginInfo *info, + PeasExtension *exten, + XedApp *app) +{ + peas_extension_call (exten, "deactivate"); +} + static void xed_app_init (XedApp *app) { app->priv = XED_APP_GET_PRIVATE (app); load_accels (); -} -static void -app_weak_notify (gpointer data, - GObject *where_the_app_was) -{ - gtk_main_quit (); + app->priv->extensions = peas_extension_set_new (PEAS_ENGINE (xed_plugins_engine_get_default ()), + XED_TYPE_APP_ACTIVATABLE, "app", app, NULL); + + g_signal_connect (app->priv->extensions, "extension-added", + G_CALLBACK (extension_added), app); + g_signal_connect (app->priv->extensions, "extension-removed", + G_CALLBACK (extension_removed), app); + + peas_extension_set_call (app->priv->extensions, "activate"); } /** @@ -342,7 +380,6 @@ xed_app_get_default (void) app = XED_APP (g_object_new (XED_TYPE_APP, NULL)); g_object_add_weak_pointer (G_OBJECT (app), (gpointer) &app); - g_object_weak_ref (G_OBJECT (app), app_weak_notify, NULL); return app; } @@ -421,7 +458,7 @@ window_destroy (XedWindow *window, save_page_setup (app); save_print_settings (app); - g_object_unref (app); + gtk_main_quit (); } } diff --git a/xed/xed-view-activatable.c b/xed/xed-view-activatable.c new file mode 100644 index 0000000..ea51699 --- /dev/null +++ b/xed/xed-view-activatable.c @@ -0,0 +1,96 @@ +/* + * xed-view-activatable.h + * This file is part of xed + * + * Copyright (C) 2010 Steve Frécinaux + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "xed-view-activatable.h" +#include "xed-view.h" + +/** + * SECTION:xed-view-activatable + * @short_description: Interface for activatable extensions on views + * @see_also: #PeasExtensionSet + * + * #XedViewActivatable is an interface which should be implemented by + * extensions that should be activated on a xed view. + **/ +G_DEFINE_INTERFACE(XedViewActivatable, xed_view_activatable, G_TYPE_OBJECT) + +void +xed_view_activatable_default_init (XedViewActivatableInterface *iface) +{ + /** + * XedViewActivatable:view: + * + * The window property contains the xed window for this + * #XedViewActivatable instance. + */ + g_object_interface_install_property (iface, + g_param_spec_object ("view", + "view", + "A xed view", + XED_TYPE_VIEW, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); +} + +/** + * xed_view_activatable_activate: + * @activatable: A #XedViewActivatable. + * + * Activates the extension on the window property. + */ +void +xed_view_activatable_activate (XedViewActivatable *activatable) +{ + XedViewActivatableInterface *iface; + + g_return_if_fail (XED_IS_VIEW_ACTIVATABLE (activatable)); + + iface = XED_VIEW_ACTIVATABLE_GET_IFACE (activatable); + if (iface->activate != NULL) + { + iface->activate (activatable); + } +} + +/** + * xed_view_activatable_deactivate: + * @activatable: A #XedViewActivatable. + * + * Deactivates the extension on the window property. + */ +void +xed_view_activatable_deactivate (XedViewActivatable *activatable) +{ + XedViewActivatableInterface *iface; + + g_return_if_fail (XED_IS_VIEW_ACTIVATABLE (activatable)); + + iface = XED_VIEW_ACTIVATABLE_GET_IFACE (activatable); + if (iface->deactivate != NULL) + { + iface->deactivate (activatable); + } +} diff --git a/xed/xed-view-activatable.h b/xed/xed-view-activatable.h new file mode 100644 index 0000000..b160680 --- /dev/null +++ b/xed/xed-view-activatable.h @@ -0,0 +1,60 @@ +/* + * xed-view-activatable.h + * This file is part of xed + * + * Copyright (C) 2010 - Steve Frécinaux + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __XED_VIEW_ACTIVATABLE_H__ +#define __XED_VIEW_ACTIVATABLE_H__ + +#include + +G_BEGIN_DECLS + +/* + * Type checking and casting macros + */ +#define XED_TYPE_VIEW_ACTIVATABLE (xed_view_activatable_get_type ()) +#define XED_VIEW_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_VIEW_ACTIVATABLE, XedViewActivatable)) +#define XED_VIEW_ACTIVATABLE_IFACE(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), XED_TYPE_VIEW_ACTIVATABLE, XedViewActivatableInterface)) +#define XED_IS_VIEW_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_VIEW_ACTIVATABLE)) +#define XED_VIEW_ACTIVATABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), XED_TYPE_VIEW_ACTIVATABLE, XedViewActivatableInterface)) + +typedef struct _XedViewActivatable XedViewActivatable; /* dummy typedef */ +typedef struct _XedViewActivatableInterface XedViewActivatableInterface; + +struct _XedViewActivatableInterface +{ + GTypeInterface g_iface; + + /* Virtual public methods */ + void (*activate) (XedViewActivatable *activatable); + void (*deactivate) (XedViewActivatable *activatable); +}; + +/* + * Public methods + */ +GType xed_view_activatable_get_type (void) G_GNUC_CONST; + +void xed_view_activatable_activate (XedViewActivatable *activatable); +void xed_view_activatable_deactivate (XedViewActivatable *activatable); + +G_END_DECLS + +#endif /* __XED_VIEW_ACTIVATABLE_H__ */ diff --git a/xed/xed-view.c b/xed/xed-view.c index 01129a8..74cce53 100644 --- a/xed/xed-view.c +++ b/xed/xed-view.c @@ -6,9 +6,12 @@ #include #include #include +#include #include #include "xed-view.h" +#include "xed-view-activatable.h" +#include "xed-plugins-engine.h" #include "xed-debug.h" #include "xed-prefs-manager.h" #include "xed-prefs-manager-app.h" @@ -34,10 +37,13 @@ struct _XedViewPrivate guint search_entry_changed_id; gboolean disable_popdown; GtkTextBuffer *current_buffer; + PeasExtensionSet *extensions; + guint view_realized : 1; }; static void xed_view_dispose (GObject *object); static void xed_view_finalize (GObject *object); +static void xed_view_realize (GtkWidget *widget); static gint xed_view_focus_out (GtkWidget *widget, GdkEventFocus *event); static gboolean xed_view_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint timestamp); static void xed_view_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, @@ -107,6 +113,7 @@ xed_view_class_init (XedViewClass *klass) widget_class->drag_data_received = xed_view_drag_data_received; widget_class->drag_drop = xed_view_drag_drop; widget_class->button_press_event = xed_view_button_press_event; + widget_class->realize = xed_view_realize; klass->start_interactive_goto_line = start_interactive_goto_line; text_view_class->delete_from_cursor = xed_view_delete_from_cursor; @@ -152,6 +159,24 @@ current_buffer_removed (XedView *view) } } +static void +extension_added (PeasExtensionSet *extensions, + PeasPluginInfo *info, + PeasExtension *exten, + XedView *view) +{ + peas_extension_call (exten, "activate"); +} + +static void +extension_removed (PeasExtensionSet *extensions, + PeasPluginInfo *info, + PeasExtension *exten, + XedView *view) +{ + peas_extension_call (exten, "deactivate"); +} + static void on_notify_buffer_cb (XedView *view, GParamSpec *arg1, @@ -223,6 +248,14 @@ xed_view_init (XedView *view) gtk_target_list_add_uri_targets (tl, TARGET_URI_LIST); } + view->priv->extensions = peas_extension_set_new (PEAS_ENGINE (xed_plugins_engine_get_default ()), + XED_TYPE_VIEW_ACTIVATABLE, "view", view, NULL); + + g_signal_connect (view->priv->extensions, "extension-added", + G_CALLBACK (extension_added), view); + g_signal_connect (view->priv->extensions, "extension-removed", + G_CALLBACK (extension_removed), view); + /* Act on buffer change */ g_signal_connect(view, "notify::buffer", G_CALLBACK (on_notify_buffer_cb), NULL); } @@ -234,6 +267,12 @@ xed_view_dispose (GObject *object) view = XED_VIEW(object); + if (view->priv->extensions != NULL) + { + g_object_unref (view->priv->extensions); + view->priv->extensions = NULL; + } + if (view->priv->search_window != NULL) { gtk_widget_destroy (view->priv->search_window); @@ -261,7 +300,8 @@ xed_view_finalize (GObject *object) XedView *view; view = XED_VIEW(object); current_buffer_removed (view); - (* G_OBJECT_CLASS (xed_view_parent_class)->finalize) (object); + + G_OBJECT_CLASS (xed_view_parent_class)->finalize (object); } static gint @@ -1141,6 +1181,20 @@ xed_view_button_press_event (GtkWidget *widget, return GTK_WIDGET_CLASS (xed_view_parent_class)->button_press_event (widget, event); } +static void +xed_view_realize (GtkWidget *widget) +{ + XedView *view = XED_VIEW (widget); + + if (!view->priv->view_realized) + { + peas_extension_set_call (view->priv->extensions, "activate"); + view->priv->view_realized = TRUE; + } + + GTK_WIDGET_CLASS (xed_view_parent_class)->realize (widget); +} + static void search_highlight_updated_cb (XedDocument *doc, GtkTextIter *start, diff --git a/xed/xed-window-activatable.c b/xed/xed-window-activatable.c new file mode 100644 index 0000000..e7b373b --- /dev/null +++ b/xed/xed-window-activatable.c @@ -0,0 +1,117 @@ +/* + * xed-window-activatable.h + * This file is part of xed + * + * Copyright (C) 2010 Steve Frécinaux + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "xed-window-activatable.h" +#include "xed-window.h" + +/** + * SECTION:xed-window-activatable + * @short_description: Interface for activatable extensions on windows + * @see_also: #PeasExtensionSet + * + * #XedWindowActivatable is an interface which should be implemented by + * extensions that should be activated on a xed main window. + **/ +G_DEFINE_INTERFACE(XedWindowActivatable, xed_window_activatable, G_TYPE_OBJECT) + +void +xed_window_activatable_default_init (XedWindowActivatableInterface *iface) +{ + /** + * XedWindowActivatable:window: + * + * The window property contains the xed window for this + * #XedWindowActivatable instance. + */ + g_object_interface_install_property (iface, + g_param_spec_object ("window", + "Window", + "The xed window", + XED_TYPE_WINDOW, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); +} + +/** + * xed_window_activatable_activate: + * @activatable: A #XedWindowActivatable. + * + * Activates the extension on the window property. + */ +void +xed_window_activatable_activate (XedWindowActivatable *activatable) +{ + XedWindowActivatableInterface *iface; + + g_return_if_fail (XED_IS_WINDOW_ACTIVATABLE (activatable)); + + iface = XED_WINDOW_ACTIVATABLE_GET_IFACE (activatable); + if (iface->activate != NULL) + { + iface->activate (activatable); + } +} + +/** + * xed_window_activatable_deactivate: + * @activatable: A #XedWindowActivatable. + * + * Deactivates the extension on the window property. + */ +void +xed_window_activatable_deactivate (XedWindowActivatable *activatable) +{ + XedWindowActivatableInterface *iface; + + g_return_if_fail (XED_IS_WINDOW_ACTIVATABLE (activatable)); + + iface = XED_WINDOW_ACTIVATABLE_GET_IFACE (activatable); + if (iface->deactivate != NULL) + { + iface->deactivate (activatable); + } +} + +/** + * xed_window_activatable_update_state: + * @activatable: A #XedWindowActivatable. + * + * Triggers an update of the extension insternal state to take into account + * state changes in the window state, due to some event or user action. + */ +void +xed_window_activatable_update_state (XedWindowActivatable *activatable) +{ + XedWindowActivatableInterface *iface; + + g_return_if_fail (XED_IS_WINDOW_ACTIVATABLE (activatable)); + + iface = XED_WINDOW_ACTIVATABLE_GET_IFACE (activatable); + if (iface->update_state != NULL) + { + iface->update_state (activatable); + } +} diff --git a/xed/xed-window-activatable.h b/xed/xed-window-activatable.h new file mode 100644 index 0000000..3476e6a --- /dev/null +++ b/xed/xed-window-activatable.h @@ -0,0 +1,62 @@ +/* + * xed-window-activatable.h + * This file is part of xed + * + * Copyright (C) 2010 - Steve Frécinaux + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __XED_WINDOW_ACTIVATABLE_H__ +#define __XED_WINDOW_ACTIVATABLE_H__ + +#include + +G_BEGIN_DECLS + +/* + * Type checking and casting macros + */ +#define XED_TYPE_WINDOW_ACTIVATABLE (xed_window_activatable_get_type ()) +#define XED_WINDOW_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_WINDOW_ACTIVATABLE, XedWindowActivatable)) +#define XED_WINDOW_ACTIVATABLE_IFACE(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), XED_TYPE_WINDOW_ACTIVATABLE, XedWindowActivatableInterface)) +#define XED_IS_WINDOW_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_WINDOW_ACTIVATABLE)) +#define XED_WINDOW_ACTIVATABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), XED_TYPE_WINDOW_ACTIVATABLE, XedWindowActivatableInterface)) + +typedef struct _XedWindowActivatable XedWindowActivatable; /* dummy typedef */ +typedef struct _XedWindowActivatableInterface XedWindowActivatableInterface; + +struct _XedWindowActivatableInterface +{ + GTypeInterface g_iface; + + /* Virtual public methods */ + void (*activate) (XedWindowActivatable *activatable); + void (*deactivate) (XedWindowActivatable *activatable); + void (*update_state) (XedWindowActivatable *activatable); +}; + +/* + * Public methods + */ +GType xed_window_activatable_get_type (void) G_GNUC_CONST; + +void xed_window_activatable_activate (XedWindowActivatable *activatable); +void xed_window_activatable_deactivate (XedWindowActivatable *activatable); +void xed_window_activatable_update_state (XedWindowActivatable *activatable); + +G_END_DECLS + +#endif /* __XED_WINDOW_ACTIVATABLE_H__ */ diff --git a/xed/xed-window.c b/xed/xed-window.c index 4324f82..77208f3 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include "xed-ui.h" @@ -27,6 +26,7 @@ #include "xed-panel.h" #include "xed-documents-panel.h" #include "xed-plugins-engine.h" +#include "xed-window-activatable.h" #include "xed-enum-types.h" #include "xed-dirs.h" #include "xed-status-combo-box.h" @@ -142,7 +142,7 @@ xed_window_dispose (GObject *object) xed_debug (DEBUG_WINDOW); - window = XED_WINDOW(object); + window = XED_WINDOW (object); /* Stop tracking removal of panes otherwise we always * end up with thinking we had no pane active, since they @@ -163,11 +163,13 @@ xed_window_dispose (GObject *object) if (!window->priv->dispose_has_run) { save_panes_state (window); + /* Note that unreffing the extension will automatically remove all extensions which in turn will deactivate the extension */ g_object_unref (window->priv->extensions); peas_engine_garbage_collect (PEAS_ENGINE (xed_plugins_engine_get_default ())); + window->priv->dispose_has_run = TRUE; } @@ -191,23 +193,10 @@ xed_window_dispose (GObject *object) window->priv->recents_handler_id = 0; } - if (window->priv->manager != NULL) - { - g_object_unref (window->priv->manager); - window->priv->manager = NULL; - } - - if (window->priv->message_bus != NULL) - { - g_object_unref (window->priv->message_bus); - window->priv->message_bus = NULL; - } - - if (window->priv->window_group != NULL) - { - g_object_unref (window->priv->window_group); - window->priv->window_group = NULL; - } + g_clear_object (&window->priv->manager); + g_clear_object (&window->priv->message_bus); + g_clear_object (&window->priv->window_group); + g_clear_object (&window->priv->default_location); /* Now that there have broken some reference loops, force collection again. */ peas_engine_garbage_collect (PEAS_ENGINE (xed_plugins_engine_get_default ())); @@ -218,13 +207,8 @@ xed_window_dispose (GObject *object) static void xed_window_finalize (GObject *object) { - XedWindow *window; xed_debug (DEBUG_WINDOW); - window = XED_WINDOW(object); - if (window->priv->default_location != NULL) - { - g_object_unref (window->priv->default_location); - } + G_OBJECT_CLASS (xed_window_parent_class)->finalize (object); } @@ -646,7 +630,7 @@ set_sensitivity_according_to_tab (XedWindow *window, update_next_prev_doc_sensitivity (window, tab); - peas_extension_set_call (window->priv->extensions, "update_state", window); + peas_extension_set_call (window->priv->extensions, "update_state"); } static void @@ -2376,7 +2360,7 @@ sync_name (XedTab *tab, g_free (escaped_name); g_free (tip); - peas_extension_set_call (window->priv->extensions, "update_state", window); + peas_extension_set_call (window->priv->extensions, "update_state"); } static XedWindow * @@ -2789,7 +2773,7 @@ selection_changed (XedDocument *doc, gtk_action_set_sensitive (action, state_normal && editable && gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER(doc))); - peas_extension_set_call (window->priv->extensions, "update_state", window); + peas_extension_set_call (window->priv->extensions, "update_state"); } static void @@ -2798,7 +2782,7 @@ sync_languages_menu (XedDocument *doc, XedWindow *window) { update_languages_menu (window); - peas_extension_set_call (window->priv->extensions, "update_state", window); + peas_extension_set_call (window->priv->extensions, "update_state"); } static void @@ -2808,7 +2792,7 @@ readonly_changed (XedDocument *doc, { set_sensitivity_according_to_tab (window, window->priv->active_tab); sync_name (window->priv->active_tab, NULL, window); - peas_extension_set_call (window->priv->extensions, "update_state", window); + peas_extension_set_call (window->priv->extensions, "update_state"); } static void @@ -2816,7 +2800,7 @@ editable_changed (XedView *view, GParamSpec *arg1, XedWindow *window) { - peas_extension_set_call (window->priv->extensions, "update_state", window); + peas_extension_set_call (window->priv->extensions, "update_state"); } static void @@ -2964,7 +2948,7 @@ notebook_tab_removed (XedNotebook *notebook, if (window->priv->num_tabs == 0) { - peas_extension_set_call (window->priv->extensions, "update_state", window); + peas_extension_set_call (window->priv->extensions, "update_state"); } update_window_state (window); @@ -3374,21 +3358,21 @@ add_notebook (XedWindow *window, } static void -on_extension_added (PeasExtensionSet *extensions, - PeasPluginInfo *info, - PeasExtension *exten, - XedWindow *window) +extension_added (PeasExtensionSet *extensions, + PeasPluginInfo *info, + PeasExtension *exten, + XedWindow *window) { - peas_extension_call (exten, "activate", window); + peas_extension_call (exten, "activate"); } static void -on_extension_removed (PeasExtensionSet *extensions, - PeasPluginInfo *info, - PeasExtension *exten, - XedWindow *window) +extension_removed (PeasExtensionSet *extensions, + PeasPluginInfo *info, + PeasExtension *exten, + XedWindow *window) { - peas_extension_call (exten, "deactivate", window); + peas_extension_call (exten, "deactivate"); /* Ensure update of the ui manager, because we suspect it does something with expected static strings in the * type module (when unloaded the strings don't exist anymore, and the ui manager update in a idle func) */ @@ -3501,13 +3485,13 @@ xed_window_init (XedWindow *window) xed_debug_message (DEBUG_WINDOW, "Update plugins ui"); window->priv->extensions = peas_extension_set_new (PEAS_ENGINE (xed_plugins_engine_get_default ()), - PEAS_TYPE_ACTIVATABLE, "object", window, NULL); + XED_TYPE_WINDOW_ACTIVATABLE, "window", window, NULL); + + g_signal_connect (window->priv->extensions, "extension-added", G_CALLBACK (extension_added), window); + g_signal_connect (window->priv->extensions, "extension-removed", G_CALLBACK (extension_removed), window); peas_extension_set_call (window->priv->extensions, "activate"); - g_signal_connect (window->priv->extensions, "extension-added", G_CALLBACK (on_extension_added), window); - g_signal_connect (window->priv->extensions, "extension-removed", G_CALLBACK (on_extension_removed), window); - /* set visibility of panes. * This needs to be done after plugins activatation */ init_panels_visibility (window); From e1fad74898085f7660926611e37889f60cfad229 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 9 Jan 2017 14:38:32 -0800 Subject: [PATCH 077/132] docinfo-plugin: Update for WindowActivatable changes --- plugins/Makefile.am | 2 + plugins/docinfo/xed-docinfo-plugin.c | 448 ++++++++++++--------------- plugins/docinfo/xed-docinfo-plugin.h | 25 +- 3 files changed, 205 insertions(+), 270 deletions(-) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index ced1a61..4ef23cc 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,8 +1,10 @@ DIST_SUBDIRS = \ + docinfo \ filebrowser \ modelines SUBDIRS = \ + docinfo \ filebrowser \ modelines diff --git a/plugins/docinfo/xed-docinfo-plugin.c b/plugins/docinfo/xed-docinfo-plugin.c index a8337bd..0db0a83 100644 --- a/plugins/docinfo/xed-docinfo-plugin.c +++ b/plugins/docinfo/xed-docinfo-plugin.c @@ -17,7 +17,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - * $Id$ */ #ifdef HAVE_CONFIG_H @@ -28,32 +27,24 @@ #include /* For strlen (...) */ -#include +#include #include #include -#include #include +#include #include #include #define MENU_PATH "/MenuBar/ToolsMenu/ToolsOps_2" -#define XED_DOCINFO_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ - XED_TYPE_DOCINFO_PLUGIN, \ - XedDocInfoPluginPrivate)) - -static void peas_activatable_iface_init (PeasActivatableInterface *iface); - -G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedDocInfoPlugin, - xed_docinfo_plugin, - PEAS_TYPE_EXTENSION_BASE, - 0, - G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, - peas_activatable_iface_init)) - -typedef struct +struct _XedDocInfoPluginPrivate { + XedWindow *window; + + GtkActionGroup *action_group; + guint ui_id; + GtkWidget *dialog; GtkWidget *file_name_label; GtkWidget *lines_label; @@ -67,105 +58,22 @@ typedef struct GtkWidget *selected_chars_label; GtkWidget *selected_chars_ns_label; GtkWidget *selected_bytes_label; -} DocInfoDialog; - -struct _XedDocInfoPluginPrivate -{ - GtkWidget *window; - - GtkActionGroup *ui_action_group; - guint ui_id; - - DocInfoDialog *dialog; }; enum { PROP_0, - PROP_OBJECT + PROP_WINDOW }; -static void docinfo_dialog_response_cb (GtkDialog *widget, - gint res_id, - XedDocInfoPluginPrivate *data); +static void xed_window_activatable_iface_init (XedWindowActivatableInterface *iface); -static void -docinfo_dialog_destroy_cb (GObject *obj, - XedDocInfoPluginPrivate *data) -{ - xed_debug (DEBUG_PLUGINS); - - if (data != NULL) - { - g_free (data->dialog); - data->dialog = NULL; - } -} - -static DocInfoDialog * -get_docinfo_dialog (XedDocInfoPlugin *plugin) -{ - XedDocInfoPluginPrivate *data; - XedWindow *window; - DocInfoDialog *dialog; - gchar *data_dir; - gchar *ui_file; - GtkWidget *content; - GtkWidget *error_widget; - gboolean ret; - - xed_debug (DEBUG_PLUGINS); - - data = plugin->priv; - window = XED_WINDOW (data->window); - - dialog = g_new (DocInfoDialog, 1); - - data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); - ui_file = g_build_filename (data_dir, "docinfo.ui", NULL); - ret = xed_utils_get_ui_objects (ui_file, - NULL, - &error_widget, - "dialog", &dialog->dialog, - "docinfo_dialog_content", &content, - "file_name_label", &dialog->file_name_label, - "words_label", &dialog->words_label, - "bytes_label", &dialog->bytes_label, - "lines_label", &dialog->lines_label, - "chars_label", &dialog->chars_label, - "chars_ns_label", &dialog->chars_ns_label, - "selection_vbox", &dialog->selection_vbox, - "selected_words_label", &dialog->selected_words_label, - "selected_bytes_label", &dialog->selected_bytes_label, - "selected_lines_label", &dialog->selected_lines_label, - "selected_chars_label", &dialog->selected_chars_label, - "selected_chars_ns_label", &dialog->selected_chars_ns_label, - NULL); - - g_free (data_dir); - g_free (ui_file); - - if (!ret) - { - const gchar *err_message; - - err_message = gtk_label_get_label (GTK_LABEL (error_widget)); - xed_warning (GTK_WINDOW (window), "%s", err_message); - - g_free (dialog); - gtk_widget_destroy (error_widget); - - return NULL; - } - - gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), GTK_RESPONSE_OK); - gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), GTK_WINDOW (window)); - - g_signal_connect (dialog->dialog, "destroy", G_CALLBACK (docinfo_dialog_destroy_cb), data); - g_signal_connect (dialog->dialog, "response", G_CALLBACK (docinfo_dialog_response_cb), data); - - return dialog; -} +G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedDocInfoPlugin, + xed_docinfo_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (XED_TYPE_WINDOW_ACTIVATABLE, + xed_window_activatable_iface_init)) static void calculate_info (XedDocument *doc, @@ -219,9 +127,10 @@ calculate_info (XedDocument *doc, } static void -docinfo_real (XedDocument *doc, - DocInfoDialog *dialog) +update_document_info (XedDocInfoPlugin *plugin, + XedDocument *doc) { + XedDocInfoPluginPrivate *priv; GtkTextIter start, end; gint words = 0; gint chars = 0; @@ -233,6 +142,8 @@ docinfo_real (XedDocument *doc, xed_debug (DEBUG_PLUGINS); + priv = plugin->priv; + gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &start, &end); lines = gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (doc)); @@ -252,35 +163,36 @@ docinfo_real (XedDocument *doc, doc_name = xed_document_get_short_name_for_display (doc); tmp_str = g_strdup_printf ("%s", doc_name); - gtk_label_set_markup (GTK_LABEL (dialog->file_name_label), tmp_str); + gtk_label_set_markup (GTK_LABEL (priv->file_name_label), tmp_str); g_free (doc_name); g_free (tmp_str); tmp_str = g_strdup_printf("%d", lines); - gtk_label_set_text (GTK_LABEL (dialog->lines_label), tmp_str); + gtk_label_set_text (GTK_LABEL (priv->lines_label), tmp_str); g_free (tmp_str); tmp_str = g_strdup_printf("%d", words); - gtk_label_set_text (GTK_LABEL (dialog->words_label), tmp_str); + gtk_label_set_text (GTK_LABEL (priv->words_label), tmp_str); g_free (tmp_str); tmp_str = g_strdup_printf("%d", chars); - gtk_label_set_text (GTK_LABEL (dialog->chars_label), tmp_str); + gtk_label_set_text (GTK_LABEL (priv->chars_label), tmp_str); g_free (tmp_str); tmp_str = g_strdup_printf("%d", chars - white_chars); - gtk_label_set_text (GTK_LABEL (dialog->chars_ns_label), tmp_str); + gtk_label_set_text (GTK_LABEL (priv->chars_ns_label), tmp_str); g_free (tmp_str); tmp_str = g_strdup_printf("%d", bytes); - gtk_label_set_text (GTK_LABEL (dialog->bytes_label), tmp_str); + gtk_label_set_text (GTK_LABEL (priv->bytes_label), tmp_str); g_free (tmp_str); } static void -selectioninfo_real (XedDocument *doc, - DocInfoDialog *dialog) +update_selection_info (XedDocInfoPlugin *plugin, + XedDocument *doc) { + XedDocInfoPluginPrivate *priv; gboolean sel; GtkTextIter start, end; gint words = 0; @@ -292,6 +204,8 @@ selectioninfo_real (XedDocument *doc, xed_debug (DEBUG_PLUGINS); + priv = plugin->priv; + sel = gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &start, &end); if (sel) @@ -306,11 +220,11 @@ selectioninfo_real (XedDocument *doc, xed_debug_message (DEBUG_PLUGINS, "Selected chars non-space: %d", chars - white_chars); xed_debug_message (DEBUG_PLUGINS, "Selected bytes: %d", bytes); - gtk_widget_set_sensitive (dialog->selection_vbox, TRUE); + gtk_widget_set_sensitive (priv->selection_vbox, TRUE); } else { - gtk_widget_set_sensitive (dialog->selection_vbox, FALSE); + gtk_widget_set_sensitive (priv->selection_vbox, FALSE); xed_debug_message (DEBUG_PLUGINS, "Selection empty"); } @@ -321,82 +235,41 @@ selectioninfo_real (XedDocument *doc, } tmp_str = g_strdup_printf("%d", lines); - gtk_label_set_text (GTK_LABEL (dialog->selected_lines_label), tmp_str); + gtk_label_set_text (GTK_LABEL (priv->selected_lines_label), tmp_str); g_free (tmp_str); tmp_str = g_strdup_printf("%d", words); - gtk_label_set_text (GTK_LABEL (dialog->selected_words_label), tmp_str); + gtk_label_set_text (GTK_LABEL (priv->selected_words_label), tmp_str); g_free (tmp_str); tmp_str = g_strdup_printf("%d", chars); - gtk_label_set_text (GTK_LABEL (dialog->selected_chars_label), tmp_str); + gtk_label_set_text (GTK_LABEL (priv->selected_chars_label), tmp_str); g_free (tmp_str); tmp_str = g_strdup_printf("%d", chars - white_chars); - gtk_label_set_text (GTK_LABEL (dialog->selected_chars_ns_label), tmp_str); + gtk_label_set_text (GTK_LABEL (priv->selected_chars_ns_label), tmp_str); g_free (tmp_str); tmp_str = g_strdup_printf("%d", bytes); - gtk_label_set_text (GTK_LABEL (dialog->selected_bytes_label), tmp_str); + gtk_label_set_text (GTK_LABEL (priv->selected_bytes_label), tmp_str); g_free (tmp_str); } static void -docinfo_cb (GtkAction *action, - XedDocInfoPlugin *plugin) +docinfo_dialog_response_cb (GtkDialog *widget, + gint res_id, + XedDocInfoPlugin *plugin) { - XedDocInfoPluginPrivate *data; - XedWindow *window; - XedDocument *doc; + XedDocInfoPluginPrivate *priv; - xed_debug (DEBUG_PLUGINS); - - data = plugin->priv; - window = XED_WINDOW (data->window); - doc = xed_window_get_active_document (window); - g_return_if_fail (doc != NULL); - - if (data->dialog != NULL) - { - gtk_window_present (GTK_WINDOW (data->dialog->dialog)); - gtk_widget_grab_focus (GTK_WIDGET (data->dialog->dialog)); - } - else - { - DocInfoDialog *dialog; - - dialog = get_docinfo_dialog (plugin); - g_return_if_fail (dialog != NULL); - - data->dialog = dialog; - - gtk_widget_show (GTK_WIDGET (dialog->dialog)); - } - - docinfo_real (doc, - data->dialog); - selectioninfo_real (doc, - data->dialog); -} - -static void -docinfo_dialog_response_cb (GtkDialog *widget, - gint res_id, - XedDocInfoPluginPrivate *data) -{ - XedWindow *window; - - xed_debug (DEBUG_PLUGINS); - - window = XED_WINDOW (data->window); + priv = plugin->priv; switch (res_id) { case GTK_RESPONSE_CLOSE: { xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CLOSE"); - gtk_widget_destroy (data->dialog->dialog); - + gtk_widget_destroy (priv->dialog); break; } @@ -406,17 +279,102 @@ docinfo_dialog_response_cb (GtkDialog *widget, xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK"); - doc = xed_window_get_active_document (window); - g_return_if_fail (doc != NULL); - - docinfo_real (doc, data->dialog); - selectioninfo_real (doc, data->dialog); + doc = xed_window_get_active_document (priv->window); + update_document_info (plugin, doc); + update_selection_info (plugin, doc); break; } } } +static void +create_docinfo_dialog (XedDocInfoPlugin *plugin) +{ + XedDocInfoPluginPrivate *priv; + gchar *data_dir; + gchar *ui_file; + GtkWidget *content; + GtkWidget *error_widget; + gboolean ret; + + xed_debug (DEBUG_PLUGINS); + + priv = plugin->priv; + + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); + ui_file = g_build_filename (data_dir, "docinfo.ui", NULL); + ret = xed_utils_get_ui_objects (ui_file, + NULL, + &error_widget, + "dialog", &priv->dialog, + "docinfo_dialog_content", &content, + "file_name_label", &priv->file_name_label, + "words_label", &priv->words_label, + "bytes_label", &priv->bytes_label, + "lines_label", &priv->lines_label, + "chars_label", &priv->chars_label, + "chars_ns_label", &priv->chars_ns_label, + "selection_vbox", &priv->selection_vbox, + "selected_words_label", &priv->selected_words_label, + "selected_bytes_label", &priv->selected_bytes_label, + "selected_lines_label", &priv->selected_lines_label, + "selected_chars_label", &priv->selected_chars_label, + "selected_chars_ns_label", &priv->selected_chars_ns_label, + NULL); + + g_free (data_dir); + g_free (ui_file); + + if (!ret) + { + const gchar *err_message; + + err_message = gtk_label_get_label (GTK_LABEL (error_widget)); + xed_warning (GTK_WINDOW (priv->window), "%s", err_message); + + gtk_widget_destroy (error_widget); + + return; + } + + gtk_dialog_set_default_response (GTK_DIALOG (priv->dialog), GTK_RESPONSE_OK); + gtk_window_set_transient_for (GTK_WINDOW (priv->dialog), GTK_WINDOW (priv->window)); + + g_signal_connect (priv->dialog, "destroy", + G_CALLBACK (gtk_widget_destroyed), &priv->dialog); + g_signal_connect (priv->dialog, "response", + G_CALLBACK (docinfo_dialog_response_cb), plugin); +} + +static void +docinfo_cb (GtkAction *action, + XedDocInfoPlugin *plugin) +{ + XedDocInfoPluginPrivate *priv; + XedDocument *doc; + + xed_debug (DEBUG_PLUGINS); + + priv = plugin->priv; + + doc = xed_window_get_active_document (priv->window); + + if (priv->dialog != NULL) + { + gtk_window_present (GTK_WINDOW (priv->dialog)); + gtk_widget_grab_focus (GTK_WIDGET (priv->dialog)); + } + else + { + create_docinfo_dialog (plugin); + gtk_widget_show (GTK_WIDGET (priv->dialog)); + } + + update_document_info (plugin, doc); + update_selection_info (plugin, doc); +} + static const GtkActionEntry action_entries[] = { { "DocumentStatistics", @@ -427,30 +385,11 @@ static const GtkActionEntry action_entries[] = G_CALLBACK (docinfo_cb) } }; -static void -update_ui (XedDocInfoPluginPrivate *data) -{ - XedWindow *window; - XedView *view; - - xed_debug (DEBUG_PLUGINS); - - window = XED_WINDOW (data->window); - view = xed_window_get_active_view (window); - - gtk_action_group_set_sensitive (data->ui_action_group, (view != NULL)); - - if (data->dialog != NULL) - { - gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog->dialog), GTK_RESPONSE_OK, (view != NULL)); - } -} - static void xed_docinfo_plugin_init (XedDocInfoPlugin *plugin) { xed_debug_message (DEBUG_PLUGINS, "XedDocInfoPlugin initializing"); - plugin->priv = XED_DOCINFO_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin, XED_TYPE_DOCINFO_PLUGIN, XedDocInfoPluginPrivate); } static void @@ -458,23 +397,22 @@ xed_docinfo_plugin_dispose (GObject *object) { XedDocInfoPlugin *plugin = XED_DOCINFO_PLUGIN (object); - xed_debug_message (DEBUG_PLUGINS, "XedDocInfoPlugin disposing"); + xed_debug_message (DEBUG_PLUGINS, "XedDocInfoPlugin dispose"); - if (plugin->priv->window != NULL) - { - g_object_unref (plugin->priv->window); - plugin->priv->window = NULL; - } - - if (plugin->priv->ui_action_group != NULL) - { - g_object_unref (plugin->priv->ui_action_group); - plugin->priv->ui_action_group = NULL; - } + g_clear_object (&plugin->priv->action_group); + g_clear_object (&plugin->priv->window); G_OBJECT_CLASS (xed_docinfo_plugin_parent_class)->dispose (object); } +static void +xed_docinfo_plugin_finalize (GObject *object) +{ + xed_debug_message (DEBUG_PLUGINS, "XedDocInfoPlugin finalizing"); + + G_OBJECT_CLASS (xed_docinfo_plugin_parent_class)->finalize (object); +} + static void xed_docinfo_plugin_set_property (GObject *object, guint prop_id, @@ -485,8 +423,8 @@ xed_docinfo_plugin_set_property (GObject *object, switch (prop_id) { - case PROP_OBJECT: - plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + case PROP_WINDOW: + plugin->priv->window = XED_WINDOW (g_value_dup_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -504,7 +442,7 @@ xed_docinfo_plugin_get_property (GObject *object, switch (prop_id) { - case PROP_OBJECT: + case PROP_WINDOW: g_value_set_object (value, plugin->priv->window); break; default: @@ -514,66 +452,76 @@ xed_docinfo_plugin_get_property (GObject *object, } static void -xed_docinfo_plugin_activate (PeasActivatable *activatable) +update_ui (XedDocInfoPlugin *plugin) { - XedDocInfoPlugin *plugin; - XedDocInfoPluginPrivate *data; - XedWindow *window; + XedDocInfoPluginPrivate *priv; + XedView *view; + + xed_debug (DEBUG_PLUGINS); + + priv = plugin->priv; + + view = xed_window_get_active_view (priv->window); + + gtk_action_group_set_sensitive (priv->action_group, (view != NULL)); + + if (priv->dialog != NULL) + { + gtk_dialog_set_response_sensitive (GTK_DIALOG (priv->dialog), GTK_RESPONSE_OK, (view != NULL)); + } +} + +static void +xed_docinfo_plugin_activate (XedWindowActivatable *activatable) +{ + XedDocInfoPluginPrivate *priv; GtkUIManager *manager; xed_debug (DEBUG_PLUGINS); - plugin = XED_DOCINFO_PLUGIN (activatable); - data = plugin->priv; - window = XED_WINDOW (data->window); + priv = XED_DOCINFO_PLUGIN (activatable)->priv; + manager = xed_window_get_ui_manager (priv->window); - data->dialog = NULL; - data->ui_action_group = gtk_action_group_new ("XedDocInfoPluginActions"); + priv->action_group = gtk_action_group_new ("XedDocinfoPluginActions"); + gtk_action_group_set_translation_domain (priv->action_group, GETTEXT_PACKAGE); + gtk_action_group_add_actions (priv->action_group, action_entries, G_N_ELEMENTS (action_entries), activatable); - gtk_action_group_set_translation_domain (data->ui_action_group, GETTEXT_PACKAGE); - gtk_action_group_add_actions (data->ui_action_group, action_entries, - G_N_ELEMENTS (action_entries), plugin); + gtk_ui_manager_insert_action_group (manager, priv->action_group, -1); - manager = xed_window_get_ui_manager (window); - gtk_ui_manager_insert_action_group (manager, data->ui_action_group, -1); - - data->ui_id = gtk_ui_manager_new_merge_id (manager); + priv->ui_id = gtk_ui_manager_new_merge_id (manager); gtk_ui_manager_add_ui (manager, - data->ui_id, + priv->ui_id, MENU_PATH, "DocumentStatistics", "DocumentStatistics", GTK_UI_MANAGER_MENUITEM, FALSE); - update_ui (data); + update_ui (XED_DOCINFO_PLUGIN (activatable)); } static void -xed_docinfo_plugin_deactivate (PeasActivatable *activatable) +xed_docinfo_plugin_deactivate (XedWindowActivatable *activatable) { - XedDocInfoPluginPrivate *data; - XedWindow *window; + XedDocInfoPluginPrivate *priv; GtkUIManager *manager; xed_debug (DEBUG_PLUGINS); - data = XED_DOCINFO_PLUGIN (activatable)->priv; - window = XED_WINDOW (data->window); + priv = XED_DOCINFO_PLUGIN (activatable)->priv; + manager = xed_window_get_ui_manager (priv->window); - manager = xed_window_get_ui_manager (window); - - gtk_ui_manager_remove_ui (manager, data->ui_id); - gtk_ui_manager_remove_action_group (manager, data->ui_action_group); + gtk_ui_manager_remove_ui (manager, priv->ui_id); + gtk_ui_manager_remove_action_group (manager, priv->action_group); } static void -xed_docinfo_plugin_update_state (PeasActivatable *activatable) +xed_docinfo_plugin_update_state (XedWindowActivatable *activatable) { xed_debug (DEBUG_PLUGINS); - update_ui (XED_DOCINFO_PLUGIN (activatable)->priv); + update_ui (XED_DOCINFO_PLUGIN (activatable)); } static void @@ -582,34 +530,34 @@ xed_docinfo_plugin_class_init (XedDocInfoPluginClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = xed_docinfo_plugin_dispose; + object_class->finalize = xed_docinfo_plugin_finalize; object_class->set_property = xed_docinfo_plugin_set_property; object_class->get_property = xed_docinfo_plugin_get_property; - g_object_class_override_property (object_class, PROP_OBJECT, "object"); + g_object_class_override_property (object_class, PROP_WINDOW, "window"); g_type_class_add_private (klass, sizeof (XedDocInfoPluginPrivate)); } static void -xed_docinfo_plugin_class_finalize (XedDocInfoPluginClass *klass) -{ - /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ -} - -static void -peas_activatable_iface_init (PeasActivatableInterface *iface) +xed_window_activatable_iface_init (XedWindowActivatableInterface *iface) { iface->activate = xed_docinfo_plugin_activate; iface->deactivate = xed_docinfo_plugin_deactivate; iface->update_state = xed_docinfo_plugin_update_state; } +static void +xed_docinfo_plugin_class_finalize (XedDocInfoPluginClass *klass) +{ +} + G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module) { xed_docinfo_plugin_register_type (G_TYPE_MODULE (module)); peas_object_module_register_extension_type (module, - PEAS_TYPE_ACTIVATABLE, + XED_TYPE_WINDOW_ACTIVATABLE, XED_TYPE_DOCINFO_PLUGIN); } diff --git a/plugins/docinfo/xed-docinfo-plugin.h b/plugins/docinfo/xed-docinfo-plugin.h index b6c5cd8..61f8139 100644 --- a/plugins/docinfo/xed-docinfo-plugin.h +++ b/plugins/docinfo/xed-docinfo-plugin.h @@ -30,35 +30,24 @@ G_BEGIN_DECLS -/* - * Type checking and casting macros - */ -#define XED_TYPE_DOCINFO_PLUGIN (xed_docinfo_plugin_get_type ()) +#define XED_TYPE_DOCINFO_PLUGIN (xed_docinfo_plugin_get_type ()) #define XED_DOCINFO_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_DOCINFO_PLUGIN, XedDocInfoPlugin)) #define XED_DOCINFO_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_DOCINFO_PLUGIN, XedDocInfoPluginClass)) #define XED_IS_DOCINFO_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_DOCINFO_PLUGIN)) #define XED_IS_DOCINFO_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_DOCINFO_PLUGIN)) #define XED_DOCINFO_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_DOCINFO_PLUGIN, XedDocInfoPluginClass)) -/* Private structure type */ -typedef struct _XedDocInfoPluginPrivate XedDocInfoPluginPrivate; - -/* - * Main object structure - */ typedef struct _XedDocInfoPlugin XedDocInfoPlugin; +typedef struct _XedDocInfoPluginPrivate XedDocInfoPluginPrivate; +typedef struct _XedDocInfoPluginClass XedDocInfoPluginClass; struct _XedDocInfoPlugin { - PeasExtensionBase parent_instance; + PeasExtensionBase parent; - /*< private >*/ XedDocInfoPluginPrivate *priv; }; -/* - * Class definition - */ typedef struct _XedDocInfoPluginClass XedDocInfoPluginClass; struct _XedDocInfoPluginClass @@ -66,12 +55,8 @@ struct _XedDocInfoPluginClass PeasExtensionBaseClass parent_class; }; -/* - * Public methods - */ -GType xed_docinfo_plugin_get_type (void) G_GNUC_CONST; +GType xed_docinfo_plugin_get_type (void) G_GNUC_CONST; -/* All the plugins must implement this function */ G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS From f65ce8f7cacaf3c9c85058d12042bd8ef8241f37 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 9 Jan 2017 15:54:57 -0800 Subject: [PATCH 078/132] sort-plugin: Port the sort plugin to WindowActivatable --- plugins/Makefile.am | 6 +- plugins/sort/xed-sort-plugin.c | 386 +++++++++++++++------------------ plugins/sort/xed-sort-plugin.h | 36 +-- 3 files changed, 188 insertions(+), 240 deletions(-) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 4ef23cc..4c7368a 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,11 +1,13 @@ DIST_SUBDIRS = \ docinfo \ filebrowser \ - modelines + modelines \ + sort SUBDIRS = \ docinfo \ filebrowser \ - modelines + modelines \ + sort -include $(top_srcdir)/git.mk diff --git a/plugins/sort/xed-sort-plugin.c b/plugins/sort/xed-sort-plugin.c index a93cdd2..5104188 100644 --- a/plugins/sort/xed-sort-plugin.c +++ b/plugins/sort/xed-sort-plugin.c @@ -28,11 +28,10 @@ #include "xed-sort-plugin.h" #include -#include -#include -#include +#include #include +#include #include #include #include @@ -41,53 +40,49 @@ #define MENU_PATH "/MenuBar/EditMenu/EditOps_6" -static void peas_activatable_iface_init (PeasActivatableInterface *iface); +static void xed_window_activatable_iface_init (XedWindowActivatableInterface *iface); G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedSortPlugin, xed_sort_plugin, PEAS_TYPE_EXTENSION_BASE, 0, - G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, - peas_activatable_iface_init)) + G_IMPLEMENT_INTERFACE_DYNAMIC (XED_TYPE_WINDOW_ACTIVATABLE, + xed_window_activatable_iface_init)) -enum +struct _XedSortPluginPrivate { - PROP_0, - PROP_OBJECT -}; + XedWindow *window; + + GtkActionGroup *ui_action_group; + guint ui_id; -typedef struct -{ GtkWidget *dialog; GtkWidget *col_num_spinbutton; GtkWidget *reverse_order_checkbutton; GtkWidget *ignore_case_checkbutton; GtkWidget *remove_dups_checkbutton; - XedDocument *doc; - GtkTextIter start, end; /* selection */ -} SortDialog; - -struct _XedSortPluginPrivate -{ - GtkWidget *window; - - GtkActionGroup *ui_action_group; - guint ui_id; }; typedef struct { - gboolean ignore_case; - gboolean reverse_order; - gboolean remove_duplicates; gint starting_column; + + guint ignore_case : 1; + guint reverse_order : 1; + guint remove_duplicates : 1; } SortInfo; +enum +{ + PROP_0, + PROP_WINDOW +}; + static void sort_cb (GtkAction *action, XedSortPlugin *plugin); -static void sort_real (SortDialog *dialog); +static void sort_real (XedSortPlugin *plugin); static const GtkActionEntry action_entries[] = { @@ -101,34 +96,25 @@ static const GtkActionEntry action_entries[] = }; static void -sort_dialog_destroy (GObject *obj, - gpointer dialog_pointer) -{ - xed_debug (DEBUG_PLUGINS); - - g_slice_free (SortDialog, dialog_pointer); -} - -static void -sort_dialog_response_handler (GtkDialog *widget, - gint res_id, - SortDialog *dialog) +sort_dialog_response_handler (GtkDialog *dlg, + gint res_id, + XedSortPlugin *plugin) { xed_debug (DEBUG_PLUGINS); switch (res_id) { case GTK_RESPONSE_OK: - sort_real (dialog); - gtk_widget_destroy (dialog->dialog); + sort_real (plugin); + gtk_widget_destroy (GTK_WIDGET (dlg)); break; case GTK_RESPONSE_HELP: - xed_help_display (GTK_WINDOW (widget), NULL, "xed-sort-plugin"); + xed_help_display (GTK_WINDOW (dlg), NULL, "xed-sort-plugin"); break; case GTK_RESPONSE_CANCEL: - gtk_widget_destroy (dialog->dialog); + gtk_widget_destroy (GTK_WIDGET (dlg)); break; } } @@ -137,27 +123,28 @@ sort_dialog_response_handler (GtkDialog *widget, * the text field (like the combo box) looses the documnent selection. * Storing the selection ONLY works because the dialog is modal */ static void -get_current_selection (XedWindow *window, - SortDialog *dialog) +get_current_selection (XedSortPlugin *plugin) { + XedSortPluginPrivate *priv; XedDocument *doc; xed_debug (DEBUG_PLUGINS); - doc = xed_window_get_active_document (window); + priv = plugin->priv; - if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &dialog->start, &dialog->end)) + doc = xed_window_get_active_document (priv->window); + + if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &priv->start, &priv->end)) { /* No selection, get the whole document. */ - gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &dialog->start, &dialog->end); + gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &priv->start, &priv->end); } } -static SortDialog * -get_sort_dialog (XedSortPlugin *plugin) +static void +create_sort_dialog (XedSortPlugin *plugin) { - XedWindow *window; - SortDialog *dialog; + XedSortPluginPrivate *priv; GtkWidget *error_widget; gboolean ret; gchar *data_dir; @@ -165,22 +152,20 @@ get_sort_dialog (XedSortPlugin *plugin) xed_debug (DEBUG_PLUGINS); - window = XED_WINDOW (plugin->priv->window); - - dialog = g_slice_new (SortDialog); + priv = plugin->priv; data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); ui_file = g_build_filename (data_dir, "sort.ui", NULL); - g_free (data_dir); ret = xed_utils_get_ui_objects (ui_file, NULL, &error_widget, - "sort_dialog", &dialog->dialog, - "reverse_order_checkbutton", &dialog->reverse_order_checkbutton, - "col_num_spinbutton", &dialog->col_num_spinbutton, - "ignore_case_checkbutton", &dialog->ignore_case_checkbutton, - "remove_dups_checkbutton", &dialog->remove_dups_checkbutton, + "sort_dialog", &priv->dialog, + "reverse_order_checkbutton", &priv->reverse_order_checkbutton, + "col_num_spinbutton", &priv->col_num_spinbutton, + "ignore_case_checkbutton", &priv->ignore_case_checkbutton, + "remove_dups_checkbutton", &priv->remove_dups_checkbutton, NULL); + g_free (data_dir); g_free (ui_file); if (!ret) @@ -188,52 +173,41 @@ get_sort_dialog (XedSortPlugin *plugin) const gchar *err_message; err_message = gtk_label_get_label (GTK_LABEL (error_widget)); - xed_warning (GTK_WINDOW (window), "%s", err_message); + xed_warning (GTK_WINDOW (priv->window), "%s", err_message); - g_slice_free (SortDialog, dialog); gtk_widget_destroy (error_widget); - return NULL; + return; } - gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), GTK_RESPONSE_OK); + gtk_dialog_set_default_response (GTK_DIALOG (priv->dialog), GTK_RESPONSE_OK); - g_signal_connect (dialog->dialog, "destroy", G_CALLBACK (sort_dialog_destroy), dialog); - g_signal_connect (dialog->dialog, "response", G_CALLBACK (sort_dialog_response_handler), dialog); + g_signal_connect (priv->dialog, "destroy", G_CALLBACK (gtk_widget_destroyed), &priv->dialog); + g_signal_connect (priv->dialog, "response", G_CALLBACK (sort_dialog_response_handler), plugin); - get_current_selection (window, dialog); - - return dialog; + get_current_selection (plugin); } static void sort_cb (GtkAction *action, XedSortPlugin *plugin) { - XedWindow *window; - XedDocument *doc; + XedSortPluginPrivate *priv; GtkWindowGroup *wg; - SortDialog *dialog; xed_debug (DEBUG_PLUGINS); - window = XED_WINDOW (plugin->priv->window); + priv = plugin->priv; - doc = xed_window_get_active_document (window); - g_return_if_fail (doc != NULL); + create_sort_dialog (plugin); - dialog = get_sort_dialog (plugin); - g_return_if_fail (dialog != NULL); + wg = xed_window_get_group (priv->window); + gtk_window_group_add_window (wg, GTK_WINDOW (priv->dialog)); - wg = xed_window_get_group (window); - gtk_window_group_add_window (wg, GTK_WINDOW (dialog->dialog)); + gtk_window_set_transient_for (GTK_WINDOW (priv->dialog), GTK_WINDOW (priv->window)); + gtk_window_set_modal (GTK_WINDOW (priv->dialog), TRUE); - dialog->doc = doc; - - gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), GTK_WINDOW (window)); - gtk_window_set_modal (GTK_WINDOW (dialog->dialog), TRUE); - - gtk_widget_show (GTK_WIDGET (dialog->dialog)); + gtk_widget_show (GTK_WIDGET (priv->dialog)); } /* Compares two strings for the sorting algorithm. Uses the UTF-8 processing @@ -344,8 +318,9 @@ get_line_slice (GtkTextBuffer *buf, } static void -sort_real (SortDialog *dialog) +sort_real (XedSortPlugin *plugin) { + XedSortPluginPrivate *priv; XedDocument *doc; GtkTextIter start, end; gint start_line, end_line; @@ -357,17 +332,19 @@ sort_real (SortDialog *dialog) xed_debug (DEBUG_PLUGINS); - doc = dialog->doc; + priv = plugin->priv; + + doc = xed_window_get_active_document (priv->window); g_return_if_fail (doc != NULL); - sort_info = g_new0 (SortInfo, 1); - sort_info->ignore_case = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->ignore_case_checkbutton)); - sort_info->reverse_order = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->reverse_order_checkbutton)); - sort_info->remove_duplicates = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->remove_dups_checkbutton)); - sort_info->starting_column = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dialog->col_num_spinbutton)) - 1; + sort_info = g_slice_new (SortInfo); + sort_info->ignore_case = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->ignore_case_checkbutton)); + sort_info->reverse_order = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->reverse_order_checkbutton)); + sort_info->remove_duplicates = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->remove_dups_checkbutton)); + sort_info->starting_column = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (priv->col_num_spinbutton)) - 1; - start = dialog->start; - end = dialog->end; + start = priv->start; + end = priv->end; start_line = gtk_text_iter_get_line (&start); end_line = gtk_text_iter_get_line (&end); @@ -421,11 +398,107 @@ sort_real (SortDialog *dialog) gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (doc)); g_strfreev (lines); - g_free (sort_info); + g_slice_free (SortInfo, sort_info); xed_debug_message (DEBUG_PLUGINS, "Done."); } +static void +update_ui (XedSortPlugin *plugin) +{ + XedView *view; + + xed_debug (DEBUG_PLUGINS); + + view = xed_window_get_active_view (plugin->priv->window); + + gtk_action_group_set_sensitive (plugin->priv->ui_action_group, + (view != NULL) && + gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); +} + +static void +xed_sort_plugin_activate (XedWindowActivatable *activatable) +{ + XedSortPluginPrivate *priv; + GtkUIManager *manager; + + xed_debug (DEBUG_PLUGINS); + + priv = XED_SORT_PLUGIN (activatable)->priv; + manager = xed_window_get_ui_manager (priv->window); + + priv->ui_action_group = gtk_action_group_new ("XedSortPluginActions"); + gtk_action_group_set_translation_domain (priv->ui_action_group, GETTEXT_PACKAGE); + gtk_action_group_add_actions (priv->ui_action_group, action_entries, G_N_ELEMENTS (action_entries), activatable); + + gtk_ui_manager_insert_action_group (manager, priv->ui_action_group, -1); + + priv->ui_id = gtk_ui_manager_new_merge_id (manager); + + gtk_ui_manager_add_ui (manager, + priv->ui_id, + MENU_PATH, + "Sort", + "Sort", + GTK_UI_MANAGER_MENUITEM, + FALSE); + + update_ui (XED_SORT_PLUGIN (activatable)); +} + +static void +xed_sort_plugin_deactivate (XedWindowActivatable *activatable) +{ + XedSortPluginPrivate *priv; + GtkUIManager *manager; + + xed_debug (DEBUG_PLUGINS); + + priv = XED_SORT_PLUGIN (activatable)->priv; + manager = xed_window_get_ui_manager (priv->window); + + gtk_ui_manager_remove_ui (manager, priv->ui_id); + gtk_ui_manager_remove_action_group (manager, priv->ui_action_group); +} + +static void +xed_sort_plugin_update_state (XedWindowActivatable *activatable) +{ + xed_debug (DEBUG_PLUGINS); + + update_ui (XED_SORT_PLUGIN (activatable)); +} + +static void +xed_sort_plugin_init (XedSortPlugin *plugin) +{ + xed_debug_message (DEBUG_PLUGINS, "XedSortPlugin initializing"); + + plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin, XED_TYPE_SORT_PLUGIN, XedSortPluginPrivate); +} + +static void +xed_sort_plugin_dispose (GObject *object) +{ + XedSortPlugin *plugin = XED_SORT_PLUGIN (object); + + xed_debug_message (DEBUG_PLUGINS, "XedSortPlugin disposing"); + + g_clear_object (&plugin->priv->ui_action_group); + g_clear_object (&plugin->priv->window); + + G_OBJECT_CLASS (xed_sort_plugin_parent_class)->dispose (object); +} + +static void +xed_sort_plugin_finalize (GObject *object) +{ + xed_debug_message (DEBUG_PLUGINS, "XedSortPlugin finalizing"); + + G_OBJECT_CLASS (xed_sort_plugin_parent_class)->finalize (object); +} + static void xed_sort_plugin_set_property (GObject *object, guint prop_id, @@ -436,8 +509,8 @@ xed_sort_plugin_set_property (GObject *object, switch (prop_id) { - case PROP_OBJECT: - plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + case PROP_WINDOW: + plugin->priv->window = XED_WINDOW (g_value_dup_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -455,7 +528,7 @@ xed_sort_plugin_get_property (GObject *object, switch (prop_id) { - case PROP_OBJECT: + case PROP_WINDOW: g_value_set_object (value, plugin->priv->window); break; default: @@ -464,126 +537,17 @@ xed_sort_plugin_get_property (GObject *object, } } -static void -update_ui (XedSortPluginPrivate *data) -{ - XedWindow *window; - XedView *view; - - xed_debug (DEBUG_PLUGINS); - - window = XED_WINDOW (data->window); - view = xed_window_get_active_view (window); - - gtk_action_group_set_sensitive (data->ui_action_group, - (view != NULL) && - gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); -} - -static void -xed_sort_plugin_activate (PeasActivatable *activatable) -{ - XedSortPlugin *plugin; - XedSortPluginPrivate *data; - XedWindow *window; - GtkUIManager *manager; - - xed_debug (DEBUG_PLUGINS); - - plugin = XED_SORT_PLUGIN (activatable); - data = plugin->priv; - window = XED_WINDOW (data->window); - - manager = xed_window_get_ui_manager (window); - - data->ui_action_group = gtk_action_group_new ("XedSortPluginActions"); - gtk_action_group_set_translation_domain (data->ui_action_group, GETTEXT_PACKAGE); - gtk_action_group_add_actions (data->ui_action_group, - action_entries, - G_N_ELEMENTS (action_entries), - plugin); - - gtk_ui_manager_insert_action_group (manager, data->ui_action_group, -1); - - data->ui_id = gtk_ui_manager_new_merge_id (manager); - - gtk_ui_manager_add_ui (manager, - data->ui_id, - MENU_PATH, - "Sort", - "Sort", - GTK_UI_MANAGER_MENUITEM, - FALSE); - - update_ui (data); -} - -static void -xed_sort_plugin_deactivate (PeasActivatable *activatable) -{ - XedSortPluginPrivate *data; - XedWindow *window; - GtkUIManager *manager; - - xed_debug (DEBUG_PLUGINS); - - data = XED_SORT_PLUGIN (activatable)->priv; - window = XED_WINDOW (data->window); - - manager = xed_window_get_ui_manager (window); - - gtk_ui_manager_remove_ui (manager, data->ui_id); - gtk_ui_manager_remove_action_group (manager, data->ui_action_group); -} - -static void -xed_sort_plugin_update_state (PeasActivatable *activatable) -{ - xed_debug (DEBUG_PLUGINS); - - update_ui (XED_SORT_PLUGIN (activatable)->priv); -} - -static void -xed_sort_plugin_init (XedSortPlugin *plugin) -{ - xed_debug_message (DEBUG_PLUGINS, "XedSortPlugin initializing"); - - plugin->priv = XED_SORT_PLUGIN_GET_PRIVATE (plugin); -} - -static void -xed_sort_plugin_dispose (GObject *object) -{ - XedSortPlugin *plugin = XED_SORT_PLUGIN (object); - - xed_debug_message (DEBUG_PLUGINS, "XedSortPlugin disposing"); - - if (plugin->priv->window != NULL) - { - g_object_unref (plugin->priv->window); - plugin->priv->window = NULL; - } - - if (plugin->priv->ui_action_group) - { - g_object_unref (plugin->priv->ui_action_group); - plugin->priv->ui_action_group = NULL; - } - - G_OBJECT_CLASS (xed_sort_plugin_parent_class)->dispose (object); -} - static void xed_sort_plugin_class_init (XedSortPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = xed_sort_plugin_dispose; + object_class->finalize = xed_sort_plugin_finalize; object_class->set_property = xed_sort_plugin_set_property; object_class->get_property = xed_sort_plugin_get_property; - g_object_class_override_property (object_class, PROP_OBJECT, "object"); + g_object_class_override_property (object_class, PROP_WINDOW, "window"); g_type_class_add_private (klass, sizeof (XedSortPluginPrivate)); } @@ -595,7 +559,7 @@ xed_sort_plugin_class_finalize (XedSortPluginClass *klass) } static void -peas_activatable_iface_init (PeasActivatableInterface *iface) +xed_window_activatable_iface_init (XedWindowActivatableInterface *iface) { iface->activate = xed_sort_plugin_activate; iface->deactivate = xed_sort_plugin_deactivate; @@ -608,6 +572,6 @@ peas_register_types (PeasObjectModule *module) xed_sort_plugin_register_type (G_TYPE_MODULE (module)); peas_object_module_register_extension_type (module, - PEAS_TYPE_ACTIVATABLE, + XED_TYPE_WINDOW_ACTIVATABLE, XED_TYPE_SORT_PLUGIN); } diff --git a/plugins/sort/xed-sort-plugin.h b/plugins/sort/xed-sort-plugin.h index 02b97ee..945e6a1 100644 --- a/plugins/sort/xed-sort-plugin.h +++ b/plugins/sort/xed-sort-plugin.h @@ -14,8 +14,6 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ */ #ifndef __XED_SORT_PLUGIN_H__ @@ -28,48 +26,32 @@ G_BEGIN_DECLS -/* - * Type checking and casting macros - */ -#define XED_TYPE_SORT_PLUGIN (xed_sort_plugin_get_type ()) -#define XED_SORT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_SORT_PLUGIN, XedSortPlugin)) -#define XED_SORT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_SORT_PLUGIN, XedSortPluginClass)) -#define XED_IS_SORT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_SORT_PLUGIN)) -#define XED_IS_SORT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_SORT_PLUGIN)) +#define XED_TYPE_SORT_PLUGIN (xed_sort_plugin_get_type ()) +#define XED_SORT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_SORT_PLUGIN, XedSortPlugin)) +#define XED_SORT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_SORT_PLUGIN, XedSortPluginClass)) +#define XED_IS_SORT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_SORT_PLUGIN)) +#define XED_IS_SORT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_SORT_PLUGIN)) #define XED_SORT_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_SORT_PLUGIN, XedSortPluginClass)) -/* Private structure type */ +typedef struct _XedSortPlugin XedSortPlugin; typedef struct _XedSortPluginPrivate XedSortPluginPrivate; - -/* - * Main object structure - */ -typedef struct _XedSortPlugin XedSortPlugin; +typedef struct _XedSortPluginClass XedSortPluginClass; struct _XedSortPlugin { - PeasExtensionBase parent_instance; + PeasExtensionBase parent; /*< private >*/ XedSortPluginPrivate *priv; }; -/* - * Class definition - */ -typedef struct _XedSortPluginClass XedSortPluginClass; - struct _XedSortPluginClass { PeasExtensionBaseClass parent_class; }; -/* - * Public methods - */ -GType xed_sort_plugin_get_type (void) G_GNUC_CONST; +GType xed_sort_plugin_get_type (void) G_GNUC_CONST; -/* All the plugins must implement this function */ G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS From 30a61a9fd8e327ac0a53301f75ab49ece5e9dc0f Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Tue, 10 Jan 2017 03:08:44 -0800 Subject: [PATCH 079/132] spell-plugin: Update to the new WindowActivatable interface --- plugins/Makefile.am | 10 +- plugins/spell/xed-spell-plugin.c | 2550 +++++++++++++++--------------- plugins/spell/xed-spell-plugin.h | 30 +- 3 files changed, 1267 insertions(+), 1323 deletions(-) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 4c7368a..abc91a9 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -2,12 +2,18 @@ DIST_SUBDIRS = \ docinfo \ filebrowser \ modelines \ - sort + sort \ + spell SUBDIRS = \ docinfo \ filebrowser \ modelines \ - sort + sort \ + spell + +if ENABLE_ENCHANT +SUBDIRS += spell +endif -include $(top_srcdir)/git.mk diff --git a/plugins/spell/xed-spell-plugin.c b/plugins/spell/xed-spell-plugin.c index 88e2114..a457a58 100644 --- a/plugins/spell/xed-spell-plugin.c +++ b/plugins/spell/xed-spell-plugin.c @@ -16,8 +16,6 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ */ #ifdef HAVE_CONFIG_H @@ -30,13 +28,11 @@ #include /* For strlen */ #include -#include -#include #include #include +#include #include -#include #include #include @@ -51,1317 +47,146 @@ #define MENU_PATH "/MenuBar/ToolsMenu/ToolsOps_1" #define XED_SPELL_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ - XED_TYPE_SPELL_PLUGIN, \ - XedSpellPluginPrivate)) + XED_TYPE_SPELL_PLUGIN, \ + XedSpellPluginPrivate)) /* GSettings keys */ -#define SPELL_SCHEMA "org.x.editor.plugins.spell" -#define AUTOCHECK_TYPE_KEY "autocheck-type" +#define SPELL_SCHEMA "org.x.editor.plugins.spell" +#define AUTOCHECK_TYPE_KEY "autocheck-type" -static void peas_activatable_iface_init (PeasActivatableInterface *iface); +static void xed_window_activatable_iface_init (XedWindowActivatableInterface *iface); static void peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface); G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedSpellPlugin, xed_spell_plugin, PEAS_TYPE_EXTENSION_BASE, 0, - G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, - peas_activatable_iface_init) + G_IMPLEMENT_INTERFACE_DYNAMIC (XED_TYPE_WINDOW_ACTIVATABLE, + xed_window_activatable_iface_init) G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_GTK_TYPE_CONFIGURABLE, peas_gtk_configurable_iface_init)) -enum -{ - PROP_0, - PROP_OBJECT -}; - struct _XedSpellPluginPrivate { - GtkWidget *window; + XedWindow *window; - GtkActionGroup *action_group; - guint ui_id; - guint message_cid; - gulong tab_added_id; - gulong tab_removed_id; + GtkActionGroup *action_group; + guint ui_id; + guint message_cid; + gulong tab_added_id; + gulong tab_removed_id; - GSettings *settings; + GSettings *settings; }; -static void spell_cb (GtkAction *action, XedSpellPlugin *plugin); -static void set_language_cb (GtkAction *action, XedSpellPlugin *plugin); -static void auto_spell_cb (GtkAction *action, XedSpellPlugin *plugin); - -/* UI actions. */ -static const GtkActionEntry action_entries[] = -{ - { "CheckSpell", - "tools-check-spelling-symbolic", - N_("_Check Spelling..."), - "F7", - N_("Check the current document for incorrect spelling"), - G_CALLBACK (spell_cb) - }, - - { "ConfigSpell", - NULL, - N_("Set _Language..."), - NULL, - N_("Set the language of the current document"), - G_CALLBACK (set_language_cb) - } -}; - -static const GtkToggleActionEntry toggle_action_entries[] = -{ - { "AutoSpell", - NULL, - N_("_Autocheck Spelling"), - NULL, - N_("Automatically spell-check the current document"), - G_CALLBACK (auto_spell_cb), - FALSE - } -}; - -typedef struct _SpellConfigureDialog SpellConfigureDialog; - -struct _SpellConfigureDialog -{ - GtkWidget *content; - - GtkWidget *never; - GtkWidget *always; - GtkWidget *document; - - GSettings *settings; -}; - -typedef enum -{ - AUTOCHECK_NEVER = 0, - AUTOCHECK_DOCUMENT, - AUTOCHECK_ALWAYS -} XedSpellPluginAutocheckType; - typedef struct _CheckRange CheckRange; struct _CheckRange { - GtkTextMark *start_mark; - GtkTextMark *end_mark; + GtkTextMark *start_mark; + GtkTextMark *end_mark; - gint mw_start; /* misspelled word start */ - gint mw_end; /* end */ + gint mw_start; /* misspelled word start */ + gint mw_end; /* end */ - GtkTextMark *current_mark; + GtkTextMark *current_mark; }; +enum +{ + PROP_0, + PROP_WINDOW +}; + +static void spell_cb (GtkAction *action, + XedSpellPlugin *plugin); +static void set_language_cb (GtkAction *action, + XedSpellPlugin *plugin); +static void auto_spell_cb (GtkAction *action, + XedSpellPlugin *plugin); + +/* UI actions. */ +static const GtkActionEntry action_entries[] = +{ + { "CheckSpell", + "tools-check-spelling-symbolic", + N_("_Check Spelling..."), + "F7", + N_("Check the current document for incorrect spelling"), + G_CALLBACK (spell_cb) + }, + + { "ConfigSpell", + NULL, + N_("Set _Language..."), + NULL, + N_("Set the language of the current document"), + G_CALLBACK (set_language_cb) + } +}; + +static const GtkToggleActionEntry toggle_action_entries[] = +{ + { "AutoSpell", + NULL, + N_("_Autocheck Spelling"), + NULL, + N_("Automatically spell-check the current document"), + G_CALLBACK (auto_spell_cb), + FALSE + } +}; + +typedef struct _SpellConfigureWidget SpellConfigureWidget; + +struct _SpellConfigureWidget +{ + GtkWidget *content; + + GtkWidget *never; + GtkWidget *always; + GtkWidget *document; + + GSettings *settings; +}; + +typedef enum +{ + AUTOCHECK_NEVER = 0, + AUTOCHECK_DOCUMENT, + AUTOCHECK_ALWAYS +} XedSpellPluginAutocheckType; + + + static GQuark spell_checker_id = 0; static GQuark check_range_id = 0; static void xed_spell_plugin_init (XedSpellPlugin *plugin) { - xed_debug_message (DEBUG_PLUGINS, "XedSpellPlugin initializing"); + xed_debug_message (DEBUG_PLUGINS, "XedSpellPlugin initializing"); - plugin->priv = XED_SPELL_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin, XED_TYPE_SPELL_PLUGIN, XedSpellPluginPrivate); - plugin->priv->settings = g_settings_new (SPELL_SCHEMA); + plugin->priv->settings = g_settings_new (SPELL_SCHEMA); } static void xed_spell_plugin_dispose (GObject *object) { - XedSpellPlugin *plugin = XED_SPELL_PLUGIN (object); + XedSpellPlugin *plugin = XED_SPELL_PLUGIN (object); - xed_debug_message (DEBUG_PLUGINS, "XedSpellPlugin disposing"); + xed_debug_message (DEBUG_PLUGINS, "XedSpellPlugin disposing"); - if (plugin->priv->window != NULL) - { - g_object_unref (plugin->priv->window); - plugin->priv->window = NULL; - } + g_clear_object (&plugin->priv->settings); + g_clear_object (&plugin->priv->window); + g_clear_object (&plugin->priv->action_group); + g_clear_object (&plugin->priv->settings); - if (plugin->priv->action_group) - { - g_object_unref (plugin->priv->action_group); - plugin->priv->action_group = NULL; - } - - g_object_unref (G_OBJECT (plugin->priv->settings)); - - G_OBJECT_CLASS (xed_spell_plugin_parent_class)->dispose (object); + G_OBJECT_CLASS (xed_spell_plugin_parent_class)->dispose (object); } -static void -set_spell_language_cb (XedSpellChecker *spell, - const XedSpellCheckerLanguage *lang, - XedDocument *doc) -{ - const gchar *key; - - g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail (lang != NULL); - - key = xed_spell_checker_language_to_key (lang); - g_return_if_fail (key != NULL); - - xed_document_set_metadata (doc, XED_METADATA_ATTRIBUTE_SPELL_LANGUAGE, - key, NULL); -} - -static void -set_language_from_metadata (XedSpellChecker *spell, - XedDocument *doc) -{ - const XedSpellCheckerLanguage *lang = NULL; - gchar *value = NULL; - - value = xed_document_get_metadata (doc, XED_METADATA_ATTRIBUTE_SPELL_LANGUAGE); - - if (value != NULL) - { - lang = xed_spell_checker_language_from_key (value); - g_free (value); - } - - if (lang != NULL) - { - g_signal_handlers_block_by_func (spell, set_spell_language_cb, doc); - xed_spell_checker_set_language (spell, lang); - g_signal_handlers_unblock_by_func (spell, set_spell_language_cb, doc); - } -} - -static XedSpellPluginAutocheckType -get_autocheck_type (XedSpellPlugin *plugin) -{ - XedSpellPluginAutocheckType autocheck_type; - - autocheck_type = g_settings_get_enum (plugin->priv->settings, - AUTOCHECK_TYPE_KEY); - - return autocheck_type; -} - -static void -set_autocheck_type (GSettings *settings, - XedSpellPluginAutocheckType autocheck_type) -{ - if (!g_settings_is_writable (settings, - AUTOCHECK_TYPE_KEY)) - { - return; - } - - g_settings_set_enum (settings, - AUTOCHECK_TYPE_KEY, - autocheck_type); -} - -static XedSpellChecker * -get_spell_checker_from_document (XedDocument *doc) -{ - XedSpellChecker *spell; - gpointer data; - - xed_debug (DEBUG_PLUGINS); - - g_return_val_if_fail (doc != NULL, NULL); - - data = g_object_get_qdata (G_OBJECT (doc), spell_checker_id); - - if (data == NULL) - { - spell = xed_spell_checker_new (); - - set_language_from_metadata (spell, doc); - - g_object_set_qdata_full (G_OBJECT (doc), - spell_checker_id, - spell, - (GDestroyNotify) g_object_unref); - - g_signal_connect (spell, - "set_language", - G_CALLBACK (set_spell_language_cb), - doc); - } - else - { - g_return_val_if_fail (XED_IS_SPELL_CHECKER (data), NULL); - spell = XED_SPELL_CHECKER (data); - } - - return spell; -} - -static CheckRange * -get_check_range (XedDocument *doc) -{ - CheckRange *range; - - xed_debug (DEBUG_PLUGINS); - - g_return_val_if_fail (doc != NULL, NULL); - - range = (CheckRange *) g_object_get_qdata (G_OBJECT (doc), check_range_id); - - return range; -} - -static void -update_current (XedDocument *doc, - gint current) -{ - CheckRange *range; - GtkTextIter iter; - GtkTextIter end_iter; - - xed_debug (DEBUG_PLUGINS); - - g_return_if_fail (doc != NULL); - g_return_if_fail (current >= 0); - - range = get_check_range (doc); - g_return_if_fail (range != NULL); - - gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), - &iter, current); - - if (!gtk_text_iter_inside_word (&iter)) - { - /* if we're not inside a word, - * we must be in some spaces. - * skip forward to the beginning of the next word. */ - if (!gtk_text_iter_is_end (&iter)) - { - gtk_text_iter_forward_word_end (&iter); - gtk_text_iter_backward_word_start (&iter); - } - } - else - { - if (!gtk_text_iter_starts_word (&iter)) - gtk_text_iter_backward_word_start (&iter); - } - - gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), - &end_iter, - range->end_mark); - - if (gtk_text_iter_compare (&end_iter, &iter) < 0) - { - gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), - range->current_mark, - &end_iter); - } - else - { - gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), - range->current_mark, - &iter); - } -} - -static void -set_check_range (XedDocument *doc, - GtkTextIter *start, - GtkTextIter *end) -{ - CheckRange *range; - GtkTextIter iter; - - xed_debug (DEBUG_PLUGINS); - - range = get_check_range (doc); - - if (range == NULL) - { - xed_debug_message (DEBUG_PLUGINS, "There was not a previous check range"); - - gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &iter); - - range = g_new0 (CheckRange, 1); - - range->start_mark = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), - "check_range_start_mark", &iter, TRUE); - - range->end_mark = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), - "check_range_end_mark", &iter, FALSE); - - range->current_mark = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), - "check_range_current_mark", &iter, TRUE); - - g_object_set_qdata_full (G_OBJECT (doc), - check_range_id, - range, - (GDestroyNotify)g_free); - } - - if (xed_spell_utils_skip_no_spell_check (start, end)) - { - if (!gtk_text_iter_inside_word (end)) - { - /* if we're neither inside a word, - * we must be in some spaces. - * skip backward to the end of the previous word. */ - if (!gtk_text_iter_is_end (end)) - { - gtk_text_iter_backward_word_start (end); - gtk_text_iter_forward_word_end (end); - } - } - else - { - if (!gtk_text_iter_ends_word (end)) - gtk_text_iter_forward_word_end (end); - } - } - else - { - /* no spell checking in the specified range */ - start = end; - } - - gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), - range->start_mark, - start); - gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), - range->end_mark, - end); - - range->mw_start = -1; - range->mw_end = -1; - - update_current (doc, gtk_text_iter_get_offset (start)); -} - -static gchar * -get_current_word (XedDocument *doc, gint *start, gint *end) -{ - const CheckRange *range; - GtkTextIter end_iter; - GtkTextIter current_iter; - gint range_end; - - xed_debug (DEBUG_PLUGINS); - - g_return_val_if_fail (doc != NULL, NULL); - g_return_val_if_fail (start != NULL, NULL); - g_return_val_if_fail (end != NULL, NULL); - - range = get_check_range (doc); - g_return_val_if_fail (range != NULL, NULL); - - gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), - &end_iter, range->end_mark); - - range_end = gtk_text_iter_get_offset (&end_iter); - - gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), - ¤t_iter, range->current_mark); - - end_iter = current_iter; - - if (!gtk_text_iter_is_end (&end_iter)) - { - xed_debug_message (DEBUG_PLUGINS, "Current is not end"); - - gtk_text_iter_forward_word_end (&end_iter); - } - - *start = gtk_text_iter_get_offset (¤t_iter); - *end = MIN (gtk_text_iter_get_offset (&end_iter), range_end); - - xed_debug_message (DEBUG_PLUGINS, "Current word extends [%d, %d]", *start, *end); - - if (!(*start < *end)) - return NULL; - - return gtk_text_buffer_get_slice (GTK_TEXT_BUFFER (doc), - ¤t_iter, - &end_iter, - TRUE); -} - -static gboolean -goto_next_word (XedDocument *doc) -{ - CheckRange *range; - GtkTextIter current_iter; - GtkTextIter old_current_iter; - GtkTextIter end_iter; - - xed_debug (DEBUG_PLUGINS); - - g_return_val_if_fail (doc != NULL, FALSE); - - range = get_check_range (doc); - g_return_val_if_fail (range != NULL, FALSE); - - gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), - ¤t_iter, - range->current_mark); - gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &end_iter); - - old_current_iter = current_iter; - - gtk_text_iter_forward_word_ends (¤t_iter, 2); - gtk_text_iter_backward_word_start (¤t_iter); - - if (xed_spell_utils_skip_no_spell_check (¤t_iter, &end_iter) && - (gtk_text_iter_compare (&old_current_iter, ¤t_iter) < 0) && - (gtk_text_iter_compare (¤t_iter, &end_iter) < 0)) - { - update_current (doc, gtk_text_iter_get_offset (¤t_iter)); - return TRUE; - } - - return FALSE; -} - -static gchar * -get_next_misspelled_word (XedView *view) -{ - XedDocument *doc; - CheckRange *range; - gint start, end; - gchar *word; - XedSpellChecker *spell; - - g_return_val_if_fail (view != NULL, NULL); - - doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); - g_return_val_if_fail (doc != NULL, NULL); - - range = get_check_range (doc); - g_return_val_if_fail (range != NULL, NULL); - - spell = get_spell_checker_from_document (doc); - g_return_val_if_fail (spell != NULL, NULL); - - word = get_current_word (doc, &start, &end); - if (word == NULL) - return NULL; - - xed_debug_message (DEBUG_PLUGINS, "Word to check: %s", word); - - while (xed_spell_checker_check_word (spell, word, -1)) - { - g_free (word); - - if (!goto_next_word (doc)) - return NULL; - - /* may return null if we reached the end of the selection */ - word = get_current_word (doc, &start, &end); - if (word == NULL) - return NULL; - - xed_debug_message (DEBUG_PLUGINS, "Word to check: %s", word); - } - - if (!goto_next_word (doc)) - update_current (doc, gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc))); - - if (word != NULL) - { - GtkTextIter s, e; - - range->mw_start = start; - range->mw_end = end; - - xed_debug_message (DEBUG_PLUGINS, "Select [%d, %d]", start, end); - - gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &s, start); - gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &e, end); - - gtk_text_buffer_select_range (GTK_TEXT_BUFFER (doc), &s, &e); - - xed_view_scroll_to_cursor (view); - } - else - { - range->mw_start = -1; - range->mw_end = -1; - } - - return word; -} - -static void -ignore_cb (XedSpellCheckerDialog *dlg, - const gchar *w, - XedView *view) -{ - gchar *word = NULL; - - xed_debug (DEBUG_PLUGINS); - - g_return_if_fail (w != NULL); - g_return_if_fail (view != NULL); - - word = get_next_misspelled_word (view); - if (word == NULL) - { - xed_spell_checker_dialog_set_completed (dlg); - - return; - } - - xed_spell_checker_dialog_set_misspelled_word (XED_SPELL_CHECKER_DIALOG (dlg), - word, - -1); - - g_free (word); -} - -static void -change_cb (XedSpellCheckerDialog *dlg, - const gchar *word, - const gchar *change, - XedView *view) -{ - XedDocument *doc; - CheckRange *range; - gchar *w = NULL; - GtkTextIter start, end; - - xed_debug (DEBUG_PLUGINS); - - g_return_if_fail (view != NULL); - g_return_if_fail (word != NULL); - g_return_if_fail (change != NULL); - - doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); - g_return_if_fail (doc != NULL); - - range = get_check_range (doc); - g_return_if_fail (range != NULL); - - gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &start, range->mw_start); - if (range->mw_end < 0) - gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &end); - else - gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &end, range->mw_end); - - w = gtk_text_buffer_get_slice (GTK_TEXT_BUFFER (doc), &start, &end, TRUE); - g_return_if_fail (w != NULL); - - if (strcmp (w, word) != 0) - { - g_free (w); - return; - } - - g_free (w); - - gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER(doc)); - - gtk_text_buffer_delete (GTK_TEXT_BUFFER (doc), &start, &end); - gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), &start, change, -1); - - gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER(doc)); - - update_current (doc, range->mw_start + g_utf8_strlen (change, -1)); - - /* go to next misspelled word */ - ignore_cb (dlg, word, view); -} - -static void -change_all_cb (XedSpellCheckerDialog *dlg, - const gchar *word, - const gchar *change, - XedView *view) -{ - XedDocument *doc; - CheckRange *range; - gchar *w = NULL; - GtkTextIter start, end; - gint flags = 0; - - xed_debug (DEBUG_PLUGINS); - - g_return_if_fail (view != NULL); - g_return_if_fail (word != NULL); - g_return_if_fail (change != NULL); - - doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); - g_return_if_fail (doc != NULL); - - range = get_check_range (doc); - g_return_if_fail (range != NULL); - - gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &start, range->mw_start); - if (range->mw_end < 0) - gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &end); - else - gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &end, range->mw_end); - - w = gtk_text_buffer_get_slice (GTK_TEXT_BUFFER (doc), &start, &end, TRUE); - g_return_if_fail (w != NULL); - - if (strcmp (w, word) != 0) - { - g_free (w); - return; - } - - g_free (w); - - XED_SEARCH_SET_CASE_SENSITIVE (flags, TRUE); - XED_SEARCH_SET_ENTIRE_WORD (flags, TRUE); - - /* CHECK: currently this function does escaping etc */ - xed_document_replace_all (doc, word, change, flags); - - update_current (doc, range->mw_start + g_utf8_strlen (change, -1)); - - /* go to next misspelled word */ - ignore_cb (dlg, word, view); -} - -static void -add_word_cb (XedSpellCheckerDialog *dlg, - const gchar *word, - XedView *view) -{ - g_return_if_fail (view != NULL); - g_return_if_fail (word != NULL); - - /* go to next misspelled word */ - ignore_cb (dlg, word, view); -} - -static void -language_dialog_response (GtkDialog *dlg, - gint res_id, - XedSpellChecker *spell) -{ - if (res_id == GTK_RESPONSE_OK) - { - const XedSpellCheckerLanguage *lang; - - lang = xed_spell_language_get_selected_language (XED_SPELL_LANGUAGE_DIALOG (dlg)); - if (lang != NULL) - xed_spell_checker_set_language (spell, lang); - } - - gtk_widget_destroy (GTK_WIDGET (dlg)); -} - -static SpellConfigureDialog * -get_configure_dialog (XedSpellPlugin *plugin) -{ - SpellConfigureDialog *dialog = NULL; - gchar *data_dir; - gchar *ui_file; - XedSpellPluginAutocheckType autocheck_type; - GtkWidget *error_widget; - gboolean ret; - gchar *root_objects[] = { - "spell_dialog_content", - NULL - }; - - xed_debug (DEBUG_PLUGINS); - - dialog = g_slice_new (SpellConfigureDialog); - dialog->settings = g_object_ref (plugin->priv->settings); - - data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); - ui_file = g_build_filename (data_dir, "xed-spell-setup-dialog.ui", NULL); - ret = xed_utils_get_ui_objects (ui_file, - root_objects, - &error_widget, - "spell_dialog_content", &dialog->content, - "autocheck_never", &dialog->never, - "autocheck_document", &dialog->document, - "autocheck_always", &dialog->always, - NULL); - - g_free (data_dir); - g_free (ui_file); - - if (!ret) - { - return NULL; - } - - autocheck_type = get_autocheck_type (plugin); - - if (autocheck_type == AUTOCHECK_ALWAYS) - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->always), TRUE); - } - else if (autocheck_type == AUTOCHECK_DOCUMENT) - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->document), TRUE); - } - else - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->never), TRUE); - } - - return dialog; -} - -static void -configure_dialog_button_toggled (GtkToggleButton *button, - SpellConfigureDialog *dialog) -{ - xed_debug (DEBUG_PLUGINS); - - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->always))) - { - set_autocheck_type (dialog->settings, AUTOCHECK_ALWAYS); - } - else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->document))) - { - set_autocheck_type (dialog->settings, AUTOCHECK_DOCUMENT); - } - else - { - set_autocheck_type (dialog->settings, AUTOCHECK_NEVER); - } -} - -static void -configure_dialog_destroyed (GtkWidget *widget, - gpointer data) -{ - SpellConfigureDialog *dialog = (SpellConfigureDialog *) data; - - xed_debug (DEBUG_PLUGINS); - - g_object_unref (dialog->settings); - g_slice_free (SpellConfigureDialog, data); -} - -static void -set_language_cb (GtkAction *action, - XedSpellPlugin *plugin) -{ - XedWindow *window; - XedDocument *doc; - XedSpellChecker *spell; - const XedSpellCheckerLanguage *lang; - GtkWidget *dlg; - GtkWindowGroup *wg; - gchar *data_dir; - - xed_debug (DEBUG_PLUGINS); - - window = XED_WINDOW (plugin->priv->window); - doc = xed_window_get_active_document (window); - g_return_if_fail (doc != NULL); - - spell = get_spell_checker_from_document (doc); - g_return_if_fail (spell != NULL); - - lang = xed_spell_checker_get_language (spell); - - data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); - dlg = xed_spell_language_dialog_new (GTK_WINDOW (window), - lang, - data_dir); - g_free (data_dir); - - wg = xed_window_get_group (window); - - gtk_window_group_add_window (wg, GTK_WINDOW (dlg)); - - gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); - - g_signal_connect (dlg, - "response", - G_CALLBACK (language_dialog_response), - spell); - - gtk_widget_show (dlg); -} - -static void -spell_cb (GtkAction *action, - XedSpellPlugin *plugin) -{ - XedSpellPluginPrivate *data; - XedWindow *window; - XedView *view; - XedDocument *doc; - XedSpellChecker *spell; - GtkWidget *dlg; - GtkTextIter start, end; - gchar *word; - gchar *data_dir; - - xed_debug (DEBUG_PLUGINS); - - data = plugin->priv; - window = XED_WINDOW (data->window); - view = xed_window_get_active_view (window); - g_return_if_fail (view != NULL); - - doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); - g_return_if_fail (doc != NULL); - - spell = get_spell_checker_from_document (doc); - g_return_if_fail (spell != NULL); - - if (gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc)) <= 0) - { - GtkWidget *statusbar; - - statusbar = xed_window_get_statusbar (window); - xed_statusbar_flash_message (XED_STATUSBAR (statusbar), - data->message_cid, - _("The document is empty.")); - - return; - } - - if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), - &start, - &end)) - { - /* no selection, get the whole doc */ - gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), - &start, - &end); - } - - set_check_range (doc, &start, &end); - - word = get_next_misspelled_word (view); - if (word == NULL) - { - GtkWidget *statusbar; - - statusbar = xed_window_get_statusbar (window); - xed_statusbar_flash_message (XED_STATUSBAR (statusbar), - data->message_cid, - _("No misspelled words")); - - return; - } - - data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); - dlg = xed_spell_checker_dialog_new_from_spell_checker (spell, data_dir); - g_free (data_dir); - - gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); - gtk_window_set_transient_for (GTK_WINDOW (dlg), - GTK_WINDOW (window)); - - g_signal_connect (dlg, "ignore", G_CALLBACK (ignore_cb), view); - g_signal_connect (dlg, "ignore_all", G_CALLBACK (ignore_cb), view); - - g_signal_connect (dlg, "change", G_CALLBACK (change_cb), view); - g_signal_connect (dlg, "change_all", G_CALLBACK (change_all_cb), view); - - g_signal_connect (dlg, "add_word_to_personal", G_CALLBACK (add_word_cb), view); - - xed_spell_checker_dialog_set_misspelled_word (XED_SPELL_CHECKER_DIALOG (dlg), - word, - -1); - - g_free (word); - - gtk_widget_show (dlg); -} - -static void -set_auto_spell (XedWindow *window, - XedDocument *doc, - gboolean active) -{ - XedAutomaticSpellChecker *autospell; - XedSpellChecker *spell; - - spell = get_spell_checker_from_document (doc); - g_return_if_fail (spell != NULL); - - autospell = xed_automatic_spell_checker_get_from_document (doc); - - if (active) - { - if (autospell == NULL) - { - XedView *active_view; - - active_view = xed_window_get_active_view (window); - g_return_if_fail (active_view != NULL); - - autospell = xed_automatic_spell_checker_new (doc, spell); - xed_automatic_spell_checker_attach_view (autospell, active_view); - xed_automatic_spell_checker_recheck_all (autospell); - } - } - else - { - if (autospell != NULL) - xed_automatic_spell_checker_free (autospell); - } -} - -static void -auto_spell_cb (GtkAction *action, - XedSpellPlugin *plugin) -{ - XedWindow *window; - XedDocument *doc; - gboolean active; - - xed_debug (DEBUG_PLUGINS); - - window = XED_WINDOW (plugin->priv->window); - - active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); - - xed_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated"); - - doc = xed_window_get_active_document (window); - if (doc == NULL) - return; - - if (get_autocheck_type (plugin) == AUTOCHECK_DOCUMENT) - { - xed_document_set_metadata (doc, - XED_METADATA_ATTRIBUTE_SPELL_ENABLED, - active ? "1" : NULL, NULL); - } - - set_auto_spell (window, doc, active); -} - -static void -update_ui (XedSpellPlugin *plugin) -{ - XedSpellPluginPrivate *data; - XedWindow *window; - XedDocument *doc; - XedView *view; - gboolean autospell; - GtkAction *action; - - xed_debug (DEBUG_PLUGINS); - - data = plugin->priv; - window = XED_WINDOW (data->window); - doc = xed_window_get_active_document (window); - view = xed_window_get_active_view (window); - - autospell = (doc != NULL && - xed_automatic_spell_checker_get_from_document (doc) != NULL); - - if (doc != NULL) - { - XedTab *tab; - XedTabState state; - - tab = xed_window_get_active_tab (window); - state = xed_tab_get_state (tab); - - /* If the document is loading we can't get the metadata so we - endup with an useless speller */ - if (state == XED_TAB_STATE_NORMAL) - { - action = gtk_action_group_get_action (data->action_group, - "AutoSpell"); - - g_signal_handlers_block_by_func (action, auto_spell_cb, - plugin); - set_auto_spell (window, doc, autospell); - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), - autospell); - g_signal_handlers_unblock_by_func (action, auto_spell_cb, - plugin); - } - } - - gtk_action_group_set_sensitive (data->action_group, - (view != NULL) && - gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); -} - -static void -set_auto_spell_from_metadata (XedSpellPlugin *plugin, - XedDocument *doc, - GtkActionGroup *action_group) -{ - gboolean active = FALSE; - gchar *active_str = NULL; - XedWindow *window; - XedDocument *active_doc; - XedSpellPluginAutocheckType autocheck_type; - autocheck_type = get_autocheck_type (plugin); - - switch (autocheck_type) - { - case AUTOCHECK_ALWAYS: - { - active = TRUE; - break; - } - case AUTOCHECK_DOCUMENT: - { - active_str = xed_document_get_metadata (doc, - XED_METADATA_ATTRIBUTE_SPELL_ENABLED); - break; - } - case AUTOCHECK_NEVER: - default: - active = FALSE; - break; - } - - if (active_str) - { - active = *active_str == '1'; - - g_free (active_str); - } - - window = XED_WINDOW (plugin->priv->window); - - set_auto_spell (window, doc, active); - - /* In case that the doc is the active one we mark the spell action */ - active_doc = xed_window_get_active_document (window); - - if (active_doc == doc && action_group != NULL) - { - GtkAction *action; - - action = gtk_action_group_get_action (action_group, - "AutoSpell"); - - g_signal_handlers_block_by_func (action, auto_spell_cb, - plugin); - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), - active); - g_signal_handlers_unblock_by_func (action, auto_spell_cb, - plugin); - } -} - -static void -on_document_loaded (XedDocument *doc, - const GError *error, - XedSpellPlugin *plugin) -{ - if (error == NULL) - { - XedSpellChecker *spell; - - spell = XED_SPELL_CHECKER (g_object_get_qdata (G_OBJECT (doc), - spell_checker_id)); - if (spell != NULL) - { - set_language_from_metadata (spell, doc); - } - - set_auto_spell_from_metadata (plugin, doc, plugin->priv->action_group); - } -} - -static void -on_document_saved (XedDocument *doc, - const GError *error, - XedSpellPlugin *plugin) -{ - XedAutomaticSpellChecker *autospell; - XedSpellChecker *spell; - const gchar *key; - - if (error != NULL) - { - return; - } - - /* Make sure to save the metadata here too */ - autospell = xed_automatic_spell_checker_get_from_document (doc); - spell = XED_SPELL_CHECKER (g_object_get_qdata (G_OBJECT (doc), spell_checker_id)); - - if (spell != NULL) - { - key = xed_spell_checker_language_to_key (xed_spell_checker_get_language (spell)); - } - else - { - key = NULL; - } - - if (get_autocheck_type (plugin) == AUTOCHECK_DOCUMENT) - { - - xed_document_set_metadata (doc, - XED_METADATA_ATTRIBUTE_SPELL_ENABLED, - autospell != NULL ? "1" : NULL, - XED_METADATA_ATTRIBUTE_SPELL_LANGUAGE, - key, - NULL); - } - else - { - xed_document_set_metadata (doc, - XED_METADATA_ATTRIBUTE_SPELL_LANGUAGE, - key, - NULL); - } -} - -static void -tab_added_cb (XedWindow *window, - XedTab *tab, - XedSpellPlugin *plugin) -{ - XedDocument *doc; - - doc = xed_tab_get_document (tab); - - g_signal_connect (doc, "loaded", - G_CALLBACK (on_document_loaded), - plugin); - - g_signal_connect (doc, "saved", - G_CALLBACK (on_document_saved), - plugin); -} - -static void -tab_removed_cb (XedWindow *window, - XedTab *tab, - XedSpellPlugin *plugin) -{ - XedDocument *doc; - - doc = xed_tab_get_document (tab); - - g_signal_handlers_disconnect_by_func (doc, on_document_loaded, plugin); - g_signal_handlers_disconnect_by_func (doc, on_document_saved, plugin); -} - -static void -xed_spell_plugin_activate (PeasActivatable *activatable) -{ - XedSpellPlugin *plugin; - XedSpellPluginPrivate *data; - XedWindow *window; - GtkUIManager *manager; - GList *docs, *l; - - xed_debug (DEBUG_PLUGINS); - - plugin = XED_SPELL_PLUGIN (activatable); - data = plugin->priv; - window = XED_WINDOW (data->window); - - manager = xed_window_get_ui_manager (window); - - data->action_group = gtk_action_group_new ("XedSpellPluginActions"); - gtk_action_group_set_translation_domain (data->action_group, - GETTEXT_PACKAGE); - gtk_action_group_add_actions (data->action_group, - action_entries, - G_N_ELEMENTS (action_entries), - plugin); - gtk_action_group_add_toggle_actions (data->action_group, - toggle_action_entries, - G_N_ELEMENTS (toggle_action_entries), - plugin); - - gtk_ui_manager_insert_action_group (manager, data->action_group, -1); - - data->ui_id = gtk_ui_manager_new_merge_id (manager); - - data->message_cid = gtk_statusbar_get_context_id - (GTK_STATUSBAR (xed_window_get_statusbar (window)), - "spell_plugin_message"); - - gtk_ui_manager_add_ui (manager, - data->ui_id, - MENU_PATH, - "CheckSpell", - "CheckSpell", - GTK_UI_MANAGER_MENUITEM, - FALSE); - - gtk_ui_manager_add_ui (manager, - data->ui_id, - MENU_PATH, - "AutoSpell", - "AutoSpell", - GTK_UI_MANAGER_MENUITEM, - FALSE); - - gtk_ui_manager_add_ui (manager, - data->ui_id, - MENU_PATH, - "ConfigSpell", - "ConfigSpell", - GTK_UI_MANAGER_MENUITEM, - FALSE); - - update_ui (plugin); - - docs = xed_window_get_documents (window); - for (l = docs; l != NULL; l = g_list_next (l)) - { - XedDocument *doc = XED_DOCUMENT (l->data); - - set_auto_spell_from_metadata (plugin, doc, - data->action_group); - - g_signal_handlers_disconnect_by_func (doc, - on_document_loaded, - plugin); - - g_signal_handlers_disconnect_by_func (doc, - on_document_saved, - plugin); - } - - data->tab_added_id = - g_signal_connect (window, "tab-added", - G_CALLBACK (tab_added_cb), plugin); - data->tab_removed_id = - g_signal_connect (window, "tab-removed", - G_CALLBACK (tab_removed_cb), plugin); -} - -static void -xed_spell_plugin_deactivate (PeasActivatable *activatable) -{ - XedSpellPluginPrivate *data; - XedWindow *window; - GtkUIManager *manager; - - xed_debug (DEBUG_PLUGINS); - - data = XED_SPELL_PLUGIN (activatable)->priv; - window = XED_WINDOW (data->window); - - manager = xed_window_get_ui_manager (window); - - gtk_ui_manager_remove_ui (manager, data->ui_id); - gtk_ui_manager_remove_action_group (manager, data->action_group); - - g_signal_handler_disconnect (window, data->tab_added_id); - g_signal_handler_disconnect (window, data->tab_removed_id); -} - -static void -xed_spell_plugin_update_state (PeasActivatable *activatable) -{ - xed_debug (DEBUG_PLUGINS); - - update_ui (XED_SPELL_PLUGIN (activatable)); -} static void xed_spell_plugin_set_property (GObject *object, @@ -1369,12 +194,12 @@ xed_spell_plugin_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - XedSpellPlugin *plugin = XED_SPELL_PLUGIN (object); + XedSpellPlugin *plugin = XED_SPELL_PLUGIN (object); - switch (prop_id) + switch (prop_id) { - case PROP_OBJECT: - plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + case PROP_WINDOW: + plugin->priv->window = XED_WINDOW (g_value_dup_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1390,60 +215,1189 @@ xed_spell_plugin_get_property (GObject *object, { XedSpellPlugin *plugin = XED_SPELL_PLUGIN (object); - switch (prop_id) + switch (prop_id) { - case PROP_OBJECT: + case PROP_WINDOW: g_value_set_object (value, plugin->priv->window); break; - default: + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } + +static void +set_spell_language_cb (XedSpellChecker *spell, + const XedSpellCheckerLanguage *lang, + XedDocument *doc) +{ + const gchar *key; + + g_return_if_fail (XED_IS_DOCUMENT (doc)); + g_return_if_fail (lang != NULL); + + key = xed_spell_checker_language_to_key (lang); + g_return_if_fail (key != NULL); + + xed_document_set_metadata (doc, XED_METADATA_ATTRIBUTE_SPELL_LANGUAGE, key, NULL); +} + +static void +set_language_from_metadata (XedSpellChecker *spell, + XedDocument *doc) +{ + const XedSpellCheckerLanguage *lang = NULL; + gchar *value = NULL; + + value = xed_document_get_metadata (doc, XED_METADATA_ATTRIBUTE_SPELL_LANGUAGE); + + if (value != NULL) + { + lang = xed_spell_checker_language_from_key (value); + g_free (value); + } + + if (lang != NULL) + { + g_signal_handlers_block_by_func (spell, set_spell_language_cb, doc); + xed_spell_checker_set_language (spell, lang); + g_signal_handlers_unblock_by_func (spell, set_spell_language_cb, doc); + } +} + +static XedSpellPluginAutocheckType +get_autocheck_type (XedSpellPlugin *plugin) +{ + XedSpellPluginAutocheckType autocheck_type; + + autocheck_type = g_settings_get_enum (plugin->priv->settings, AUTOCHECK_TYPE_KEY); + + return autocheck_type; +} + +static void +set_autocheck_type (GSettings *settings, + XedSpellPluginAutocheckType autocheck_type) +{ + if (!g_settings_is_writable (settings, AUTOCHECK_TYPE_KEY)) + { + return; + } + + g_settings_set_enum (settings, AUTOCHECK_TYPE_KEY, autocheck_type); +} + +static XedSpellChecker * +get_spell_checker_from_document (XedDocument *doc) +{ + XedSpellChecker *spell; + gpointer data; + + xed_debug (DEBUG_PLUGINS); + + g_return_val_if_fail (doc != NULL, NULL); + + data = g_object_get_qdata (G_OBJECT (doc), spell_checker_id); + + if (data == NULL) + { + spell = xed_spell_checker_new (); + + set_language_from_metadata (spell, doc); + + g_object_set_qdata_full (G_OBJECT (doc), + spell_checker_id, + spell, + (GDestroyNotify) g_object_unref); + + g_signal_connect (spell, "set_language", + G_CALLBACK (set_spell_language_cb), doc); + } + else + { + g_return_val_if_fail (XED_IS_SPELL_CHECKER (data), NULL); + spell = XED_SPELL_CHECKER (data); + } + + return spell; +} + +static CheckRange * +get_check_range (XedDocument *doc) +{ + CheckRange *range; + + xed_debug (DEBUG_PLUGINS); + + g_return_val_if_fail (doc != NULL, NULL); + + range = (CheckRange *) g_object_get_qdata (G_OBJECT (doc), check_range_id); + + return range; +} + +static void +update_current (XedDocument *doc, + gint current) +{ + CheckRange *range; + GtkTextIter iter; + GtkTextIter end_iter; + + xed_debug (DEBUG_PLUGINS); + + g_return_if_fail (doc != NULL); + g_return_if_fail (current >= 0); + + range = get_check_range (doc); + g_return_if_fail (range != NULL); + + gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &iter, current); + + if (!gtk_text_iter_inside_word (&iter)) + { + /* if we're not inside a word, + * we must be in some spaces. + * skip forward to the beginning of the next word. */ + if (!gtk_text_iter_is_end (&iter)) + { + gtk_text_iter_forward_word_end (&iter); + gtk_text_iter_backward_word_start (&iter); + } + } + else + { + if (!gtk_text_iter_starts_word (&iter)) + { + gtk_text_iter_backward_word_start (&iter); + } + } + + gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), &end_iter, range->end_mark); + + if (gtk_text_iter_compare (&end_iter, &iter) < 0) + { + gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), range->current_mark, &end_iter); + } + else + { + gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), range->current_mark, &iter); + } +} + +static void +set_check_range (XedDocument *doc, + GtkTextIter *start, + GtkTextIter *end) +{ + CheckRange *range; + GtkTextIter iter; + + xed_debug (DEBUG_PLUGINS); + + range = get_check_range (doc); + + if (range == NULL) + { + xed_debug_message (DEBUG_PLUGINS, "There was not a previous check range"); + + gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &iter); + + range = g_new0 (CheckRange, 1); + + range->start_mark = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), + "check_range_start_mark", &iter, TRUE); + + range->end_mark = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), + "check_range_end_mark", &iter, FALSE); + + range->current_mark = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), + "check_range_current_mark", &iter, TRUE); + + g_object_set_qdata_full (G_OBJECT (doc), check_range_id, range, (GDestroyNotify)g_free); + } + + if (xed_spell_utils_skip_no_spell_check (start, end)) + { + if (!gtk_text_iter_inside_word (end)) + { + /* if we're neither inside a word, + * we must be in some spaces. + * skip backward to the end of the previous word. */ + if (!gtk_text_iter_is_end (end)) + { + gtk_text_iter_backward_word_start (end); + gtk_text_iter_forward_word_end (end); + } + } + else + { + if (!gtk_text_iter_ends_word (end)) + { + gtk_text_iter_forward_word_end (end); + } + } + } + else + { + /* no spell checking in the specified range */ + start = end; + } + + gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), range->start_mark, start); + gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), range->end_mark, end); + + range->mw_start = -1; + range->mw_end = -1; + + update_current (doc, gtk_text_iter_get_offset (start)); +} + +static gchar * +get_current_word (XedDocument *doc, + gint *start, + gint *end) +{ + const CheckRange *range; + GtkTextIter end_iter; + GtkTextIter current_iter; + gint range_end; + + xed_debug (DEBUG_PLUGINS); + + g_return_val_if_fail (doc != NULL, NULL); + g_return_val_if_fail (start != NULL, NULL); + g_return_val_if_fail (end != NULL, NULL); + + range = get_check_range (doc); + g_return_val_if_fail (range != NULL, NULL); + + gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), &end_iter, range->end_mark); + + range_end = gtk_text_iter_get_offset (&end_iter); + + gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), ¤t_iter, range->current_mark); + + end_iter = current_iter; + + if (!gtk_text_iter_is_end (&end_iter)) + { + xed_debug_message (DEBUG_PLUGINS, "Current is not end"); + + gtk_text_iter_forward_word_end (&end_iter); + } + + *start = gtk_text_iter_get_offset (¤t_iter); + *end = MIN (gtk_text_iter_get_offset (&end_iter), range_end); + + xed_debug_message (DEBUG_PLUGINS, "Current word extends [%d, %d]", *start, *end); + + if (!(*start < *end)) + { + return NULL; + } + + return gtk_text_buffer_get_slice (GTK_TEXT_BUFFER (doc), ¤t_iter, &end_iter, TRUE); +} + +static gboolean +goto_next_word (XedDocument *doc) +{ + CheckRange *range; + GtkTextIter current_iter; + GtkTextIter old_current_iter; + GtkTextIter end_iter; + + xed_debug (DEBUG_PLUGINS); + + g_return_val_if_fail (doc != NULL, FALSE); + + range = get_check_range (doc); + g_return_val_if_fail (range != NULL, FALSE); + + gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), ¤t_iter, range->current_mark); + gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &end_iter); + + old_current_iter = current_iter; + + gtk_text_iter_forward_word_ends (¤t_iter, 2); + gtk_text_iter_backward_word_start (¤t_iter); + + if (xed_spell_utils_skip_no_spell_check (¤t_iter, &end_iter) && + (gtk_text_iter_compare (&old_current_iter, ¤t_iter) < 0) && + (gtk_text_iter_compare (¤t_iter, &end_iter) < 0)) + { + update_current (doc, gtk_text_iter_get_offset (¤t_iter)); + return TRUE; + } + + return FALSE; +} + +static gchar * +get_next_misspelled_word (XedView *view) +{ + XedDocument *doc; + CheckRange *range; + gint start, end; + gchar *word; + XedSpellChecker *spell; + + g_return_val_if_fail (view != NULL, NULL); + + doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); + g_return_val_if_fail (doc != NULL, NULL); + + range = get_check_range (doc); + g_return_val_if_fail (range != NULL, NULL); + + spell = get_spell_checker_from_document (doc); + g_return_val_if_fail (spell != NULL, NULL); + + word = get_current_word (doc, &start, &end); + if (word == NULL) + { + return NULL; + } + + xed_debug_message (DEBUG_PLUGINS, "Word to check: %s", word); + + while (xed_spell_checker_check_word (spell, word, -1)) + { + g_free (word); + + if (!goto_next_word (doc)) + { + return NULL; + } + + /* may return null if we reached the end of the selection */ + word = get_current_word (doc, &start, &end); + if (word == NULL) + { + return NULL; + } + + xed_debug_message (DEBUG_PLUGINS, "Word to check: %s", word); + } + + if (!goto_next_word (doc)) + { + update_current (doc, gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc))); + } + + if (word != NULL) + { + GtkTextIter s, e; + + range->mw_start = start; + range->mw_end = end; + + xed_debug_message (DEBUG_PLUGINS, "Select [%d, %d]", start, end); + + gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &s, start); + gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &e, end); + + gtk_text_buffer_select_range (GTK_TEXT_BUFFER (doc), &s, &e); + + xed_view_scroll_to_cursor (view); + } + else + { + range->mw_start = -1; + range->mw_end = -1; + } + + return word; +} + +static void +ignore_cb (XedSpellCheckerDialog *dlg, + const gchar *w, + XedView *view) +{ + gchar *word = NULL; + + xed_debug (DEBUG_PLUGINS); + + g_return_if_fail (w != NULL); + g_return_if_fail (view != NULL); + + word = get_next_misspelled_word (view); + if (word == NULL) + { + xed_spell_checker_dialog_set_completed (dlg); + + return; + } + + xed_spell_checker_dialog_set_misspelled_word (XED_SPELL_CHECKER_DIALOG (dlg), word, -1); + + g_free (word); +} + +static void +change_cb (XedSpellCheckerDialog *dlg, + const gchar *word, + const gchar *change, + XedView *view) +{ + XedDocument *doc; + CheckRange *range; + gchar *w = NULL; + GtkTextIter start, end; + + xed_debug (DEBUG_PLUGINS); + + g_return_if_fail (view != NULL); + g_return_if_fail (word != NULL); + g_return_if_fail (change != NULL); + + doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); + g_return_if_fail (doc != NULL); + + range = get_check_range (doc); + g_return_if_fail (range != NULL); + + gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &start, range->mw_start); + if (range->mw_end < 0) + { + gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &end); + } + else + { + gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &end, range->mw_end); + } + + w = gtk_text_buffer_get_slice (GTK_TEXT_BUFFER (doc), &start, &end, TRUE); + g_return_if_fail (w != NULL); + + if (strcmp (w, word) != 0) + { + g_free (w); + return; + } + + g_free (w); + + gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER(doc)); + + gtk_text_buffer_delete (GTK_TEXT_BUFFER (doc), &start, &end); + gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), &start, change, -1); + + gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER(doc)); + + update_current (doc, range->mw_start + g_utf8_strlen (change, -1)); + + /* go to next misspelled word */ + ignore_cb (dlg, word, view); +} + +static void +change_all_cb (XedSpellCheckerDialog *dlg, + const gchar *word, + const gchar *change, + XedView *view) +{ + XedDocument *doc; + CheckRange *range; + gchar *w = NULL; + GtkTextIter start, end; + gint flags = 0; + + xed_debug (DEBUG_PLUGINS); + + g_return_if_fail (view != NULL); + g_return_if_fail (word != NULL); + g_return_if_fail (change != NULL); + + doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); + g_return_if_fail (doc != NULL); + + range = get_check_range (doc); + g_return_if_fail (range != NULL); + + gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &start, range->mw_start); + if (range->mw_end < 0) + { + gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &end); + } + else + { + gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &end, range->mw_end); + } + + w = gtk_text_buffer_get_slice (GTK_TEXT_BUFFER (doc), &start, &end, TRUE); + g_return_if_fail (w != NULL); + + if (strcmp (w, word) != 0) + { + g_free (w); + return; + } + + g_free (w); + + XED_SEARCH_SET_CASE_SENSITIVE (flags, TRUE); + XED_SEARCH_SET_ENTIRE_WORD (flags, TRUE); + + /* CHECK: currently this function does escaping etc */ + xed_document_replace_all (doc, word, change, flags); + + update_current (doc, range->mw_start + g_utf8_strlen (change, -1)); + + /* go to next misspelled word */ + ignore_cb (dlg, word, view); +} + +static void +add_word_cb (XedSpellCheckerDialog *dlg, + const gchar *word, + XedView *view) +{ + g_return_if_fail (view != NULL); + g_return_if_fail (word != NULL); + + /* go to next misspelled word */ + ignore_cb (dlg, word, view); +} + +static void +language_dialog_response (GtkDialog *dlg, + gint res_id, + XedSpellChecker *spell) +{ + if (res_id == GTK_RESPONSE_OK) + { + const XedSpellCheckerLanguage *lang; + + lang = xed_spell_language_get_selected_language (XED_SPELL_LANGUAGE_DIALOG (dlg)); + if (lang != NULL) + { + xed_spell_checker_set_language (spell, lang); + } + } + + gtk_widget_destroy (GTK_WIDGET (dlg)); +} + +static void +configure_widget_button_toggled (GtkToggleButton *button, + SpellConfigureWidget *conf_widget) +{ + xed_debug (DEBUG_PLUGINS); + + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (conf_widget->always))) + { + set_autocheck_type (conf_widget->settings, AUTOCHECK_ALWAYS); + } + else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (conf_widget->document))) + { + set_autocheck_type (conf_widget->settings, AUTOCHECK_DOCUMENT); + } + else + { + set_autocheck_type (conf_widget->settings, AUTOCHECK_NEVER); + } +} + +static void +configure_widget_destroyed (GtkWidget *widget, + gpointer data) +{ + SpellConfigureWidget *conf_widget = (SpellConfigureWidget *)data; + + xed_debug (DEBUG_PLUGINS); + + g_object_unref (conf_widget->settings); + g_slice_free (SpellConfigureWidget, data); + + xed_debug_message (DEBUG_PLUGINS, "END"); +} + +static SpellConfigureWidget * +get_configure_widget (XedSpellPlugin *plugin) +{ + SpellConfigureWidget *widget; + gchar *data_dir; + gchar *ui_file; + XedSpellPluginAutocheckType autocheck_type; + GtkWidget *error_widget; + gboolean ret; + gchar *root_objects[] = { + "spell_dialog_content", + NULL + }; + + xed_debug (DEBUG_PLUGINS); + + widget = g_slice_new (SpellConfigureWidget); + widget->settings = g_object_ref (plugin->priv->settings); + + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); + ui_file = g_build_filename (data_dir, "xed-spell-setup-dialog.ui", NULL); + ret = xed_utils_get_ui_objects (ui_file, + root_objects, + &error_widget, + "spell_dialog_content", &widget->content, + "autocheck_never", &widget->never, + "autocheck_document", &widget->document, + "autocheck_always", &widget->always, + NULL); + + g_free (data_dir); + g_free (ui_file); + + if (!ret) + { + return NULL; + } + + autocheck_type = get_autocheck_type (plugin); + + if (autocheck_type == AUTOCHECK_ALWAYS) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->always), TRUE); + } + else if (autocheck_type == AUTOCHECK_DOCUMENT) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->document), TRUE); + } + else + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->never), TRUE); + } + + g_signal_connect (widget->always, "toggled", + G_CALLBACK (configure_widget_button_toggled), widget); + g_signal_connect (widget->document, "toggled", + G_CALLBACK (configure_widget_button_toggled), widget); + g_signal_connect (widget->never, "toggled", + G_CALLBACK (configure_widget_button_toggled), widget); + g_signal_connect (widget->content, "destroy", + G_CALLBACK (configure_widget_destroyed), widget); + + return widget; +} + +static void +set_language_cb (GtkAction *action, + XedSpellPlugin *plugin) +{ + XedSpellPluginPrivate *priv; + XedDocument *doc; + XedSpellChecker *spell; + const XedSpellCheckerLanguage *lang; + GtkWidget *dlg; + GtkWindowGroup *wg; + gchar *data_dir; + + xed_debug (DEBUG_PLUGINS); + + priv = plugin->priv; + + doc = xed_window_get_active_document (priv->window); + g_return_if_fail (doc != NULL); + + spell = get_spell_checker_from_document (doc); + g_return_if_fail (spell != NULL); + + lang = xed_spell_checker_get_language (spell); + + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); + dlg = xed_spell_language_dialog_new (GTK_WINDOW (priv->window), lang, data_dir); + g_free (data_dir); + + wg = xed_window_get_group (priv->window); + + gtk_window_group_add_window (wg, GTK_WINDOW (dlg)); + + gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); + + g_signal_connect (dlg, "response", + G_CALLBACK (language_dialog_response), spell); + + gtk_widget_show (dlg); +} + +static void +spell_cb (GtkAction *action, + XedSpellPlugin *plugin) +{ + XedSpellPluginPrivate *priv; + XedView *view; + XedDocument *doc; + XedSpellChecker *spell; + GtkWidget *dlg; + GtkTextIter start, end; + gchar *word; + gchar *data_dir; + + xed_debug (DEBUG_PLUGINS); + + priv = plugin->priv; + + view = xed_window_get_active_view (priv->window); + g_return_if_fail (view != NULL); + + doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); + g_return_if_fail (doc != NULL); + + spell = get_spell_checker_from_document (doc); + g_return_if_fail (spell != NULL); + + if (gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc)) <= 0) + { + GtkWidget *statusbar; + + statusbar = xed_window_get_statusbar (priv->window); + xed_statusbar_flash_message (XED_STATUSBAR (statusbar), priv->message_cid, _("The document is empty.")); + + return; + } + + if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &start, &end)) + { + /* no selection, get the whole doc */ + gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &start, &end); + } + + set_check_range (doc, &start, &end); + + word = get_next_misspelled_word (view); + if (word == NULL) + { + GtkWidget *statusbar; + + statusbar = xed_window_get_statusbar (priv->window); + xed_statusbar_flash_message (XED_STATUSBAR (statusbar), priv->message_cid, _("No misspelled words")); + + return; + } + + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); + dlg = xed_spell_checker_dialog_new_from_spell_checker (spell, data_dir); + g_free (data_dir); + + gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); + gtk_window_set_transient_for (GTK_WINDOW (dlg), GTK_WINDOW (priv->window)); + + g_signal_connect (dlg, "ignore", G_CALLBACK (ignore_cb), view); + g_signal_connect (dlg, "ignore_all", G_CALLBACK (ignore_cb), view); + + g_signal_connect (dlg, "change", G_CALLBACK (change_cb), view); + g_signal_connect (dlg, "change_all", G_CALLBACK (change_all_cb), view); + + g_signal_connect (dlg, "add_word_to_personal", G_CALLBACK (add_word_cb), view); + + xed_spell_checker_dialog_set_misspelled_word (XED_SPELL_CHECKER_DIALOG (dlg), word, -1); + + g_free (word); + + gtk_widget_show (dlg); +} + +static void +set_auto_spell (XedWindow *window, + XedDocument *doc, + gboolean active) +{ + XedAutomaticSpellChecker *autospell; + XedSpellChecker *spell; + + spell = get_spell_checker_from_document (doc); + g_return_if_fail (spell != NULL); + + autospell = xed_automatic_spell_checker_get_from_document (doc); + + if (active) + { + if (autospell == NULL) + { + XedView *active_view; + + active_view = xed_window_get_active_view (window); + g_return_if_fail (active_view != NULL); + + autospell = xed_automatic_spell_checker_new (doc, spell); + xed_automatic_spell_checker_attach_view (autospell, active_view); + xed_automatic_spell_checker_recheck_all (autospell); + } + } + else + { + if (autospell != NULL) + { + xed_automatic_spell_checker_free (autospell); + } + } +} + +static void +auto_spell_cb (GtkAction *action, + XedSpellPlugin *plugin) +{ + XedSpellPluginPrivate *priv; + XedWindow *window; + XedDocument *doc; + gboolean active; + + xed_debug (DEBUG_PLUGINS); + + priv = plugin->priv; + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + + xed_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated"); + + doc = xed_window_get_active_document (priv->window); + if (doc == NULL) + { + return; + } + + if (get_autocheck_type (plugin) == AUTOCHECK_DOCUMENT) + { + xed_document_set_metadata (doc, + XED_METADATA_ATTRIBUTE_SPELL_ENABLED, + active ? "1" : NULL, NULL); + } + + set_auto_spell (priv->window, doc, active); +} + +static void +update_ui (XedSpellPlugin *plugin) +{ + XedSpellPluginPrivate *priv; + XedDocument *doc; + XedView *view; + gboolean autospell; + GtkAction *action; + + xed_debug (DEBUG_PLUGINS); + + priv = plugin->priv; + doc = xed_window_get_active_document (priv->window); + view = xed_window_get_active_view (priv->window); + + autospell = (doc != NULL && xed_automatic_spell_checker_get_from_document (doc) != NULL); + + if (doc != NULL) + { + XedTab *tab; + XedTabState state; + + tab = xed_window_get_active_tab (priv->window); + state = xed_tab_get_state (tab); + + /* If the document is loading we can't get the metadata so we + endup with an useless speller */ + if (state == XED_TAB_STATE_NORMAL) + { + action = gtk_action_group_get_action (priv->action_group, "AutoSpell"); + + g_signal_handlers_block_by_func (action, auto_spell_cb, plugin); + set_auto_spell (priv->window, doc, autospell); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), autospell); + g_signal_handlers_unblock_by_func (action, auto_spell_cb, plugin); + } + } + + gtk_action_group_set_sensitive (priv->action_group, + (view != NULL) && + gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); +} + +static void +set_auto_spell_from_metadata (XedSpellPlugin *plugin, + XedDocument *doc, + GtkActionGroup *action_group) +{ + gboolean active = FALSE; + gchar *active_str = NULL; + XedWindow *window; + XedDocument *active_doc; + XedSpellPluginAutocheckType autocheck_type; + + autocheck_type = get_autocheck_type (plugin); + + switch (autocheck_type) + { + case AUTOCHECK_ALWAYS: + { + active = TRUE; + break; + } + case AUTOCHECK_DOCUMENT: + { + active_str = xed_document_get_metadata (doc, XED_METADATA_ATTRIBUTE_SPELL_ENABLED); + break; + } + case AUTOCHECK_NEVER: + default: + active = FALSE; + break; + } + + if (active_str) + { + active = *active_str == '1'; + + g_free (active_str); + } + + window = XED_WINDOW (plugin->priv->window); + + set_auto_spell (window, doc, active); + + /* In case that the doc is the active one we mark the spell action */ + active_doc = xed_window_get_active_document (window); + + if (active_doc == doc && action_group != NULL) + { + GtkAction *action; + + action = gtk_action_group_get_action (action_group, "AutoSpell"); + + g_signal_handlers_block_by_func (action, auto_spell_cb, plugin); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active); + g_signal_handlers_unblock_by_func (action, auto_spell_cb, plugin); + } +} + +static void +on_document_loaded (XedDocument *doc, + const GError *error, + XedSpellPlugin *plugin) +{ + if (error == NULL) + { + XedSpellChecker *spell; + + spell = XED_SPELL_CHECKER (g_object_get_qdata (G_OBJECT (doc), spell_checker_id)); + if (spell != NULL) + { + set_language_from_metadata (spell, doc); + } + + set_auto_spell_from_metadata (plugin, doc, plugin->priv->action_group); + } +} + +static void +on_document_saved (XedDocument *doc, + const GError *error, + XedSpellPlugin *plugin) +{ + XedAutomaticSpellChecker *autospell; + XedSpellChecker *spell; + const gchar *key; + + if (error != NULL) + { + return; + } + + /* Make sure to save the metadata here too */ + autospell = xed_automatic_spell_checker_get_from_document (doc); + spell = XED_SPELL_CHECKER (g_object_get_qdata (G_OBJECT (doc), spell_checker_id)); + + if (spell != NULL) + { + key = xed_spell_checker_language_to_key (xed_spell_checker_get_language (spell)); + } + else + { + key = NULL; + } + + if (get_autocheck_type (plugin) == AUTOCHECK_DOCUMENT) + { + + xed_document_set_metadata (doc, + XED_METADATA_ATTRIBUTE_SPELL_ENABLED, + autospell != NULL ? "1" : NULL, + XED_METADATA_ATTRIBUTE_SPELL_LANGUAGE, + key, + NULL); + } + else + { + xed_document_set_metadata (doc, XED_METADATA_ATTRIBUTE_SPELL_LANGUAGE, key, NULL); + } +} + +static void +tab_added_cb (XedWindow *window, + XedTab *tab, + XedSpellPlugin *plugin) +{ + XedDocument *doc; + + doc = xed_tab_get_document (tab); + + g_signal_connect (doc, "loaded", + G_CALLBACK (on_document_loaded), plugin); + + g_signal_connect (doc, "saved", + G_CALLBACK (on_document_saved), plugin); +} + +static void +tab_removed_cb (XedWindow *window, + XedTab *tab, + XedSpellPlugin *plugin) +{ + XedDocument *doc; + + doc = xed_tab_get_document (tab); + + g_signal_handlers_disconnect_by_func (doc, on_document_loaded, plugin); + g_signal_handlers_disconnect_by_func (doc, on_document_saved, plugin); +} + +static void +xed_spell_plugin_activate (XedWindowActivatable *activatable) +{ + XedSpellPluginPrivate *priv; + GtkUIManager *manager; + GList *docs, *l; + + xed_debug (DEBUG_PLUGINS); + + priv = XED_SPELL_PLUGIN (activatable)->priv; + + manager = xed_window_get_ui_manager (priv->window); + + priv->action_group = gtk_action_group_new ("XedSpellPluginActions"); + gtk_action_group_set_translation_domain (priv->action_group, GETTEXT_PACKAGE); + gtk_action_group_add_actions (priv->action_group, + action_entries, + G_N_ELEMENTS (action_entries), + activatable); + gtk_action_group_add_toggle_actions (priv->action_group, + toggle_action_entries, + G_N_ELEMENTS (toggle_action_entries), + activatable); + + gtk_ui_manager_insert_action_group (manager, priv->action_group, -1); + + priv->ui_id = gtk_ui_manager_new_merge_id (manager); + + priv->message_cid = gtk_statusbar_get_context_id (GTK_STATUSBAR (xed_window_get_statusbar (priv->window)), + "spell_plugin_message"); + + gtk_ui_manager_add_ui (manager, + priv->ui_id, + MENU_PATH, + "CheckSpell", + "CheckSpell", + GTK_UI_MANAGER_MENUITEM, + FALSE); + + gtk_ui_manager_add_ui (manager, + priv->ui_id, + MENU_PATH, + "AutoSpell", + "AutoSpell", + GTK_UI_MANAGER_MENUITEM, + FALSE); + + gtk_ui_manager_add_ui (manager, + priv->ui_id, + MENU_PATH, + "ConfigSpell", + "ConfigSpell", + GTK_UI_MANAGER_MENUITEM, + FALSE); + + update_ui (XED_SPELL_PLUGIN (activatable)); + + docs = xed_window_get_documents (priv->window); + for (l = docs; l != NULL; l = g_list_next (l)) + { + XedDocument *doc = XED_DOCUMENT (l->data); + + set_auto_spell_from_metadata (activatable, doc, priv->action_group); + + g_signal_handlers_disconnect_by_func (doc, on_document_loaded, activatable); + g_signal_handlers_disconnect_by_func (doc, on_document_saved, activatable); + } + + priv->tab_added_id = g_signal_connect (priv->window, "tab-added", + G_CALLBACK (tab_added_cb), activatable); + priv->tab_removed_id = g_signal_connect (priv->window, "tab-removed", + G_CALLBACK (tab_removed_cb), activatable); +} + +static void +xed_spell_plugin_deactivate (XedWindowActivatable *activatable) +{ + XedSpellPluginPrivate *priv; + GtkUIManager *manager; + + xed_debug (DEBUG_PLUGINS); + + priv = XED_SPELL_PLUGIN (activatable)->priv; + manager = xed_window_get_ui_manager (priv->window); + + gtk_ui_manager_remove_ui (manager, priv->ui_id); + gtk_ui_manager_remove_action_group (manager, priv->action_group); + + g_signal_handler_disconnect (priv->window, priv->tab_added_id); + g_signal_handler_disconnect (priv->window, priv->tab_removed_id); +} + +static void +xed_spell_plugin_update_state (XedWindowActivatable *activatable) +{ + xed_debug (DEBUG_PLUGINS); + + update_ui (XED_SPELL_PLUGIN (activatable)); +} + static GtkWidget * xed_spell_plugin_create_configure_widget (PeasGtkConfigurable *configurable) { - SpellConfigureDialog *dialog; + SpellConfigureWidget *widget; - dialog = get_configure_dialog (XED_SPELL_PLUGIN (configurable)); + widget = get_configure_widget (XED_SPELL_PLUGIN (configurable)); - g_signal_connect (dialog->always, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); - g_signal_connect (dialog->document, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); - g_signal_connect (dialog->never, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); - g_signal_connect (dialog->content, "destroy", G_CALLBACK (configure_dialog_destroyed), dialog); - - return dialog->content; + return widget->content; } static void xed_spell_plugin_class_init (XedSpellPluginClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->dispose = xed_spell_plugin_dispose; + object_class->dispose = xed_spell_plugin_dispose; object_class->set_property = xed_spell_plugin_set_property; object_class->get_property = xed_spell_plugin_get_property; - g_object_class_override_property (object_class, PROP_OBJECT, "object"); + if (spell_checker_id == 0) + { + spell_checker_id = g_quark_from_string ("XedSpellCheckerID"); + } - if (spell_checker_id == 0) - spell_checker_id = g_quark_from_string ("XedSpellCheckerID"); + if (check_range_id == 0) + { + check_range_id = g_quark_from_string ("CheckRangeID"); + } - if (check_range_id == 0) - check_range_id = g_quark_from_string ("CheckRangeID"); + g_object_class_override_property (object_class, PROP_WINDOW, "window"); - g_type_class_add_private (object_class, sizeof (XedSpellPluginPrivate)); + g_type_class_add_private (object_class, sizeof (XedSpellPluginPrivate)); } static void xed_spell_plugin_class_finalize (XedSpellPluginClass *klass) { - /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ } static void -peas_activatable_iface_init (PeasActivatableInterface *iface) +xed_window_activatable_iface_init (XedWindowActivatableInterface *iface) { iface->activate = xed_spell_plugin_activate; iface->deactivate = xed_spell_plugin_deactivate; @@ -1462,7 +1416,7 @@ peas_register_types (PeasObjectModule *module) xed_spell_plugin_register_type (G_TYPE_MODULE (module)); peas_object_module_register_extension_type (module, - PEAS_TYPE_ACTIVATABLE, + XED_TYPE_WINDOW_ACTIVATABLE, XED_TYPE_SPELL_PLUGIN); peas_object_module_register_extension_type (module, diff --git a/plugins/spell/xed-spell-plugin.h b/plugins/spell/xed-spell-plugin.h index be2982c..febcd3d 100644 --- a/plugins/spell/xed-spell-plugin.h +++ b/plugins/spell/xed-spell-plugin.h @@ -30,23 +30,16 @@ G_BEGIN_DECLS -/* - * Type checking and casting macros - */ -#define XED_TYPE_SPELL_PLUGIN (xed_spell_plugin_get_type ()) -#define XED_SPELL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_SPELL_PLUGIN, XedSpellPlugin)) -#define XED_SPELL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_SPELL_PLUGIN, XedSpellPluginClass)) -#define XED_IS_SPELL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_SPELL_PLUGIN)) +#define XED_TYPE_SPELL_PLUGIN (xed_spell_plugin_get_type ()) +#define XED_SPELL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_SPELL_PLUGIN, XedSpellPlugin)) +#define XED_SPELL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_SPELL_PLUGIN, XedSpellPluginClass)) +#define XED_IS_SPELL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_SPELL_PLUGIN)) #define XED_IS_SPELL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_SPELL_PLUGIN)) #define XED_SPELL_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_SPELL_PLUGIN, XedSpellPluginClass)) -/* Private structure type */ +typedef struct _XedSpellPlugin XedSpellPlugin; typedef struct _XedSpellPluginPrivate XedSpellPluginPrivate; - -/* - * Main object structure - */ -typedef struct _XedSpellPlugin XedSpellPlugin; +typedef struct _XedSpellPluginClass XedSpellPluginClass; struct _XedSpellPlugin { @@ -55,22 +48,13 @@ struct _XedSpellPlugin XedSpellPluginPrivate *priv; }; -/* - * Class definition - */ -typedef struct _XedSpellPluginClass XedSpellPluginClass; - struct _XedSpellPluginClass { PeasExtensionBaseClass parent_class; }; -/* - * Public methods - */ -GType xed_spell_plugin_get_type (void) G_GNUC_CONST; +GType xed_spell_plugin_get_type (void) G_GNUC_CONST; -/* All the plugins must implement this function */ G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS From 33cb6f4b3292f259fc8c6c82d3a068c1b3065799 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Wed, 11 Jan 2017 03:00:03 -0800 Subject: [PATCH 080/132] time-plugin: Port to WindowActivatable --- plugins/Makefile.am | 6 +- plugins/time/xed-time-plugin.c | 1397 +++++++++++++++----------------- plugins/time/xed-time-plugin.h | 33 +- 3 files changed, 685 insertions(+), 751 deletions(-) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index abc91a9..d46447c 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -3,14 +3,16 @@ DIST_SUBDIRS = \ filebrowser \ modelines \ sort \ - spell + spell \ + time SUBDIRS = \ docinfo \ filebrowser \ modelines \ sort \ - spell + spell \ + time if ENABLE_ENCHANT SUBDIRS += spell diff --git a/plugins/time/xed-time-plugin.c b/plugins/time/xed-time-plugin.c index f308c31..604e6b9 100644 --- a/plugins/time/xed-time-plugin.c +++ b/plugins/time/xed-time-plugin.c @@ -16,8 +16,6 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ */ /* @@ -38,434 +36,383 @@ #include #include -#include #include -#include -#include #include +#include +#include #include #include #define XED_TIME_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ - XED_TYPE_TIME_PLUGIN, \ - XedTimePluginPrivate)) + XED_TYPE_TIME_PLUGIN, \ + XedTimePluginPrivate)) #define MENU_PATH "/MenuBar/EditMenu/EditOps_4" /* GSettings keys */ -#define TIME_SCHEMA "org.x.editor.plugins.time" -#define PROMPT_TYPE_KEY "prompt-type" -#define SELECTED_FORMAT_KEY "selected-format" -#define CUSTOM_FORMAT_KEY "custom-format" +#define TIME_SCHEMA "org.x.editor.plugins.time" +#define PROMPT_TYPE_KEY "prompt-type" +#define SELECTED_FORMAT_KEY "selected-format" +#define CUSTOM_FORMAT_KEY "custom-format" #define DEFAULT_CUSTOM_FORMAT "%d/%m/%Y %H:%M:%S" static const gchar *formats[] = { - "%c", - "%x", - "%X", - "%x %X", - "%Y-%m-%d %H:%M:%S", - "%a %b %d %H:%M:%S %Z %Y", - "%a %b %d %H:%M:%S %Y", - "%a %d %b %Y %H:%M:%S %Z", - "%a %d %b %Y %H:%M:%S", - "%d/%m/%Y", - "%d/%m/%y", - "%D", - "%A %d %B %Y", - "%A %B %d %Y", - "%Y-%m-%d", - "%d %B %Y", - "%B %d, %Y", - "%A %b %d", - "%H:%M:%S", - "%H:%M", - "%I:%M:%S %p", - "%I:%M %p", - "%H.%M.%S", - "%H.%M", - "%I.%M.%S %p", - "%I.%M %p", - "%d/%m/%Y %H:%M:%S", - "%d/%m/%y %H:%M:%S", + "%c", + "%x", + "%X", + "%x %X", + "%Y-%m-%d %H:%M:%S", + "%a %b %d %H:%M:%S %Z %Y", + "%a %b %d %H:%M:%S %Y", + "%a %d %b %Y %H:%M:%S %Z", + "%a %d %b %Y %H:%M:%S", + "%d/%m/%Y", + "%d/%m/%y", + "%D", + "%A %d %B %Y", + "%A %B %d %Y", + "%Y-%m-%d", + "%d %B %Y", + "%B %d, %Y", + "%A %b %d", + "%H:%M:%S", + "%H:%M", + "%I:%M:%S %p", + "%I:%M %p", + "%H.%M.%S", + "%H.%M", + "%I.%M.%S %p", + "%I.%M %p", + "%d/%m/%Y %H:%M:%S", + "%d/%m/%y %H:%M:%S", #if __GLIBC__ >= 2 - "%a, %d %b %Y %H:%M:%S %z", + "%a, %d %b %Y %H:%M:%S %z", #endif - NULL + NULL }; enum { - COLUMN_FORMATS = 0, - COLUMN_INDEX, - NUM_COLUMNS + COLUMN_FORMATS = 0, + COLUMN_INDEX, + NUM_COLUMNS }; -typedef struct _TimeConfigureDialog TimeConfigureDialog; - -struct _TimeConfigureDialog +typedef enum { - GtkWidget *content; + PROMPT_SELECTED_FORMAT = 0, /* Popup dialog with list preselected */ + PROMPT_CUSTOM_FORMAT, /* Popup dialog with entry preselected */ + USE_SELECTED_FORMAT, /* Use selected format directly */ + USE_CUSTOM_FORMAT /* Use custom format directly */ +} XedTimePluginPromptType; - GtkWidget *list; +typedef struct _TimeConfigureWidget TimeConfigureWidget; - /* Radio buttons to indicate what should be done */ - GtkWidget *prompt; - GtkWidget *use_list; - GtkWidget *custom; +struct _TimeConfigureWidget +{ + GtkWidget *content; - GtkWidget *custom_entry; - GtkWidget *custom_format_example; + GtkWidget *list; - GSettings *settings; + /* Radio buttons to indicate what should be done */ + GtkWidget *prompt; + GtkWidget *use_list; + GtkWidget *custom; + + GtkWidget *custom_entry; + GtkWidget *custom_format_example; + + GSettings *settings; }; typedef struct _ChooseFormatDialog ChooseFormatDialog; struct _ChooseFormatDialog { - GtkWidget *dialog; + GtkWidget *dialog; - GtkWidget *list; + GtkWidget *list; - /* Radio buttons to indicate what should be done */ - GtkWidget *use_list; - GtkWidget *custom; + /* Radio buttons to indicate what should be done */ + GtkWidget *use_list; + GtkWidget *custom; - GtkWidget *custom_entry; - GtkWidget *custom_format_example; + GtkWidget *custom_entry; + GtkWidget *custom_format_example; - /* Info needed for the response handler */ - GtkTextBuffer *buffer; + /* Info needed for the response handler */ + GtkTextBuffer *buffer; GSettings *settings; }; -typedef enum -{ - PROMPT_SELECTED_FORMAT = 0, /* Popup dialog with list preselected */ - PROMPT_CUSTOM_FORMAT, /* Popup dialog with entry preselected */ - USE_SELECTED_FORMAT, /* Use selected format directly */ - USE_CUSTOM_FORMAT /* Use custom format directly */ -} XedTimePluginPromptType; - struct _XedTimePluginPrivate { - GtkWidget *window; + XedWindow *window; GSettings *settings; - GtkActionGroup *action_group; - guint ui_id; + GtkActionGroup *action_group; + guint ui_id; }; enum { PROP_0, - PROP_OBJECT + PROP_WINDOW }; -static void peas_activatable_iface_init (PeasActivatableInterface *iface); +static void xed_window_activatable_iface_init (XedWindowActivatableInterface *iface); static void peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface); G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedTimePlugin, xed_time_plugin, PEAS_TYPE_EXTENSION_BASE, 0, - G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, - peas_activatable_iface_init) + G_IMPLEMENT_INTERFACE_DYNAMIC (XED_TYPE_WINDOW_ACTIVATABLE, + xed_window_activatable_iface_init) G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_GTK_TYPE_CONFIGURABLE, peas_gtk_configurable_iface_init)) -static void time_cb (GtkAction *action, XedTimePlugin *plugin); +static void time_cb (GtkAction *action, + XedTimePlugin *plugin); static const GtkActionEntry action_entries[] = { - { - "InsertDateAndTime", - NULL, - N_("In_sert Date and Time..."), - NULL, - N_("Insert current date and time at the cursor position"), - G_CALLBACK (time_cb) - }, + { + "InsertDateAndTime", + NULL, + N_("In_sert Date and Time..."), + NULL, + N_("Insert current date and time at the cursor position"), + G_CALLBACK (time_cb) + }, }; static void xed_time_plugin_init (XedTimePlugin *plugin) { - xed_debug_message (DEBUG_PLUGINS, "XedTimePlugin initializing"); + xed_debug_message (DEBUG_PLUGINS, "XedTimePlugin initializing"); - plugin->priv = XED_TIME_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = XED_TIME_PLUGIN_GET_PRIVATE (plugin); - plugin->priv->settings = g_settings_new (TIME_SCHEMA); + plugin->priv->settings = g_settings_new (TIME_SCHEMA); } static void xed_time_plugin_finalize (GObject *object) { - XedTimePlugin *plugin = XED_TIME_PLUGIN (object); + XedTimePlugin *plugin = XED_TIME_PLUGIN (object); - xed_debug_message (DEBUG_PLUGINS, "XedTimePlugin finalizing"); + xed_debug_message (DEBUG_PLUGINS, "XedTimePlugin finalizing"); - g_object_unref (G_OBJECT (plugin->priv->settings)); + g_object_unref (G_OBJECT (plugin->priv->settings)); - G_OBJECT_CLASS (xed_time_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_time_plugin_parent_class)->finalize (object); } static void xed_time_plugin_dispose (GObject *object) { - XedTimePlugin *plugin = XED_TIME_PLUGIN (object); + XedTimePlugin *plugin = XED_TIME_PLUGIN (object); xed_debug_message (DEBUG_PLUGINS, "XedTimePlugin disposing"); - if (plugin->priv->window != NULL) - { - g_object_unref (plugin->priv->window); - plugin->priv->window = NULL; - } + g_clear_object (&plugin->priv->window); + g_clear_object (&plugin->priv->action_group); - if (plugin->priv->action_group) - { - g_object_unref (plugin->priv->action_group); - plugin->priv->action_group = NULL; - } - - G_OBJECT_CLASS (xed_time_plugin_parent_class)->dispose (object); + G_OBJECT_CLASS (xed_time_plugin_parent_class)->dispose (object); } static void -update_ui (XedTimePluginPrivate *data) +update_ui (XedTimePlugin *plugin) { - XedWindow *window; - XedView *view; - GtkAction *action; + XedView *view; + GtkAction *action; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - window = XED_WINDOW (data->window); - view = xed_window_get_active_view (window); + view = xed_window_get_active_view (plugin->priv->window); - xed_debug_message (DEBUG_PLUGINS, "View: %p", view); + xed_debug_message (DEBUG_PLUGINS, "View: %p", view); - action = gtk_action_group_get_action (data->action_group, - "InsertDateAndTime"); - gtk_action_set_sensitive (action, - (view != NULL) && - gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); + action = gtk_action_group_get_action (plugin->priv->action_group, "InsertDateAndTime"); + gtk_action_set_sensitive (action, (view != NULL) && gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); } static void -xed_time_plugin_activate (PeasActivatable *activatable) +xed_time_plugin_activate (XedWindowActivatable *activatable) { - XedTimePlugin *plugin; - XedTimePluginPrivate *data; - XedWindow *window; - GtkUIManager *manager; + XedTimePluginPrivate *priv; + GtkUIManager *manager; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - plugin = XED_TIME_PLUGIN (activatable); - data = plugin->priv; - window = XED_WINDOW (data->window); + priv = XED_TIME_PLUGIN (activatable)->priv; + manager = xed_window_get_ui_manager (priv->window); - manager = xed_window_get_ui_manager (window); + priv->action_group = gtk_action_group_new ("XedTimePluginActions"); + gtk_action_group_set_translation_domain (priv->action_group, GETTEXT_PACKAGE); + gtk_action_group_add_actions (priv->action_group, action_entries, G_N_ELEMENTS (action_entries), activatable); - data->action_group = gtk_action_group_new ("XedTimePluginActions"); - gtk_action_group_set_translation_domain (data->action_group, - GETTEXT_PACKAGE); - gtk_action_group_add_actions (data->action_group, - action_entries, - G_N_ELEMENTS (action_entries), - plugin); + gtk_ui_manager_insert_action_group (manager, priv->action_group, -1); - gtk_ui_manager_insert_action_group (manager, data->action_group, -1); + priv->ui_id = gtk_ui_manager_new_merge_id (manager); - data->ui_id = gtk_ui_manager_new_merge_id (manager); + gtk_ui_manager_add_ui (manager, + priv->ui_id, + MENU_PATH, + "InsertDateAndTime", + "InsertDateAndTime", + GTK_UI_MANAGER_MENUITEM, + FALSE); - gtk_ui_manager_add_ui (manager, - data->ui_id, - MENU_PATH, - "InsertDateAndTime", - "InsertDateAndTime", - GTK_UI_MANAGER_MENUITEM, - FALSE); - - update_ui (data); + update_ui (XED_TIME_PLUGIN (activatable)); } static void -xed_time_plugin_deactivate (PeasActivatable *activatable) +xed_time_plugin_deactivate (XedWindowActivatable *activatable) { - XedTimePluginPrivate *data; - XedWindow *window; - GtkUIManager *manager; + XedTimePluginPrivate *priv; + GtkUIManager *manager; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - data = XED_TIME_PLUGIN (activatable)->priv; - window = XED_WINDOW (data->window); + priv = XED_TIME_PLUGIN (activatable)->priv; + manager = xed_window_get_ui_manager (priv->window); - manager = xed_window_get_ui_manager (window); - - gtk_ui_manager_remove_ui (manager, data->ui_id); - gtk_ui_manager_remove_action_group (manager, data->action_group); + gtk_ui_manager_remove_ui (manager, priv->ui_id); + gtk_ui_manager_remove_action_group (manager, priv->action_group); } static void -xed_time_plugin_update_state (PeasActivatable *activatable) +xed_time_plugin_update_state (XedWindowActivatable *activatable) { - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - update_ui (XED_TIME_PLUGIN (activatable)->priv); -} - -/* whether we should prompt the user or use the specified format */ -static XedTimePluginPromptType -get_prompt_type (XedTimePlugin *plugin) -{ - XedTimePluginPromptType prompt_type; - - prompt_type = g_settings_get_enum (plugin->priv->settings, - PROMPT_TYPE_KEY); - - return prompt_type; -} - -static void -set_prompt_type (GSettings *settings, - XedTimePluginPromptType prompt_type) -{ - if (!g_settings_is_writable (settings, - PROMPT_TYPE_KEY)) - { - return; - } - - g_settings_set_enum (settings, - PROMPT_TYPE_KEY, - prompt_type); + update_ui (XED_TIME_PLUGIN (activatable)); } /* The selected format in the list */ static gchar * get_selected_format (XedTimePlugin *plugin) { - gchar *sel_format; + gchar *sel_format; - sel_format = g_settings_get_string (plugin->priv->settings, - SELECTED_FORMAT_KEY); + sel_format = g_settings_get_string (plugin->priv->settings, SELECTED_FORMAT_KEY); - return sel_format ? sel_format : g_strdup (formats [0]); + return sel_format ? sel_format : g_strdup (formats [0]); } -static void -set_selected_format (GSettings *settings, - const gchar *format) -{ - g_return_if_fail (format != NULL); +// static void +// set_selected_format (XedTimePlugin *plugin, +// const gchar *format) +// { +// g_return_if_fail (format != NULL); - if (!g_settings_is_writable (settings, - SELECTED_FORMAT_KEY)) - { - return; - } +// if (!g_settings_is_writable (plugin->priv->settings, SELECTED_FORMAT_KEY)) +// { +// return; +// } - g_settings_set_string (settings, - SELECTED_FORMAT_KEY, - format); -} +// g_settings_set_string (settings, SELECTED_FORMAT_KEY, format); +// } /* the custom format in the entry */ static gchar * get_custom_format (XedTimePlugin *plugin) { - gchar *format; + gchar *format; - format = g_settings_get_string (plugin->priv->settings, - CUSTOM_FORMAT_KEY); + format = g_settings_get_string (plugin->priv->settings, CUSTOM_FORMAT_KEY); - return format ? format : g_strdup (DEFAULT_CUSTOM_FORMAT); + return format ? format : g_strdup (DEFAULT_CUSTOM_FORMAT); } -static void -set_custom_format (GSettings *settings, - const gchar *format) -{ - g_return_if_fail (format != NULL); +// static void +// set_custom_format (XedTimePlugin *plugin, +// const gchar *format) +// { +// g_return_if_fail (format != NULL); - if (!g_settings_is_writable (settings, - CUSTOM_FORMAT_KEY)) - return; +// if (!g_settings_is_writable (plugin->priv->settings, CUSTOM_FORMAT_KEY)) +// { +// return; +// } - g_settings_set_string (settings, - CUSTOM_FORMAT_KEY, - format); -} +// g_settings_set_string (plugin->priv->settings, CUSTOM_FORMAT_KEY, format); +// } static gchar * get_time (const gchar* format) { - gchar *out = NULL; - gchar *out_utf8 = NULL; - time_t clock; - struct tm *now; - size_t out_length = 0; - gchar *locale_format; + gchar *out = NULL; + gchar *out_utf8 = NULL; + time_t clock; + struct tm *now; + size_t out_length = 0; + gchar *locale_format; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - g_return_val_if_fail (format != NULL, NULL); + g_return_val_if_fail (format != NULL, NULL); - if (strlen (format) == 0) - return g_strdup (" "); + if (strlen (format) == 0) + { + return g_strdup (" "); + } - locale_format = g_locale_from_utf8 (format, -1, NULL, NULL, NULL); - if (locale_format == NULL) - return g_strdup (" "); + locale_format = g_locale_from_utf8 (format, -1, NULL, NULL, NULL); + if (locale_format == NULL) + { + return g_strdup (" "); + } - clock = time (NULL); - now = localtime (&clock); + clock = time (NULL); + now = localtime (&clock); - do - { - out_length += 255; - out = g_realloc (out, out_length); - } - while (strftime (out, out_length, locale_format, now) == 0); + do + { + out_length += 255; + out = g_realloc (out, out_length); + } + while (strftime (out, out_length, locale_format, now) == 0); - g_free (locale_format); + g_free (locale_format); - if (g_utf8_validate (out, -1, NULL)) - { - out_utf8 = out; - } - else - { - out_utf8 = g_locale_to_utf8 (out, -1, NULL, NULL, NULL); - g_free (out); + if (g_utf8_validate (out, -1, NULL)) + { + out_utf8 = out; + } + else + { + out_utf8 = g_locale_to_utf8 (out, -1, NULL, NULL, NULL); + g_free (out); - if (out_utf8 == NULL) - out_utf8 = g_strdup (" "); - } + if (out_utf8 == NULL) + { + out_utf8 = g_strdup (" "); + } + } - return out_utf8; + return out_utf8; } static void -configure_dialog_destroyed (GtkWidget *widget, +configure_widget_destroyed (GtkWidget *widget, gpointer data) { - TimeConfigureDialog *dialog = (TimeConfigureDialog *) data; + TimeConfigureWidget *conf_widget = (TimeConfigureWidget *) data; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - g_object_unref (dialog->settings); - g_slice_free (TimeConfigureDialog, data); + g_object_unref (conf_widget->settings); + g_slice_free (TimeConfigureWidget, data); + + xed_debug_message (DEBUG_PLUGINS, "END"); } static void @@ -474,648 +421,648 @@ choose_format_dialog_destroyed (GtkWidget *widget, { xed_debug (DEBUG_PLUGINS); - g_slice_free (ChooseFormatDialog, data); + g_slice_free (ChooseFormatDialog, data); + + xed_debug_message (DEBUG_PLUGINS, "END"); } static GtkTreeModel * -create_model (GtkWidget *listview, - const gchar *sel_format, - XedTimePlugin *plugin) +create_model (GtkWidget *listview, + const gchar *sel_format, + XedTimePlugin *plugin) { - gint i = 0; - GtkListStore *store; - GtkTreeSelection *selection; - GtkTreeIter iter; + gint i = 0; + GtkListStore *store; + GtkTreeSelection *selection; + GtkTreeIter iter; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - /* create list store */ - store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_INT); + /* create list store */ + store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_INT); - /* Set tree view model*/ - gtk_tree_view_set_model (GTK_TREE_VIEW (listview), - GTK_TREE_MODEL (store)); - g_object_unref (G_OBJECT (store)); + /* Set tree view model*/ + gtk_tree_view_set_model (GTK_TREE_VIEW (listview), GTK_TREE_MODEL (store)); + g_object_unref (G_OBJECT (store)); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (listview)); - g_return_val_if_fail (selection != NULL, GTK_TREE_MODEL (store)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (listview)); + g_return_val_if_fail (selection != NULL, GTK_TREE_MODEL (store)); - /* there should always be one line selected */ - gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); + /* there should always be one line selected */ + gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); - /* add data to the list store */ - while (formats[i] != NULL) - { - gchar *str; + /* add data to the list store */ + while (formats[i] != NULL) + { + gchar *str; - str = get_time (formats[i]); + str = get_time (formats[i]); - xed_debug_message (DEBUG_PLUGINS, "%d : %s", i, str); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - COLUMN_FORMATS, str, - COLUMN_INDEX, i, - -1); - g_free (str); + xed_debug_message (DEBUG_PLUGINS, "%d : %s", i, str); + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, COLUMN_FORMATS, str, COLUMN_INDEX, i, -1); + g_free (str); - if (sel_format && strcmp (formats[i], sel_format) == 0) - gtk_tree_selection_select_iter (selection, &iter); + if (sel_format && strcmp (formats[i], sel_format) == 0) + { + gtk_tree_selection_select_iter (selection, &iter); + } - ++i; - } + ++i; + } - /* fall back to select the first iter */ - if (!gtk_tree_selection_get_selected (selection, NULL, NULL)) - { - gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter); - gtk_tree_selection_select_iter (selection, &iter); - } + /* fall back to select the first iter */ + if (!gtk_tree_selection_get_selected (selection, NULL, NULL)) + { + gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter); + gtk_tree_selection_select_iter (selection, &iter); + } - return GTK_TREE_MODEL (store); + return GTK_TREE_MODEL (store); } static void scroll_to_selected (GtkTreeView *tree_view) { - GtkTreeModel *model; - GtkTreeSelection *selection; - GtkTreeIter iter; + GtkTreeModel *model; + GtkTreeSelection *selection; + GtkTreeIter iter; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - model = gtk_tree_view_get_model (tree_view); - g_return_if_fail (model != NULL); + model = gtk_tree_view_get_model (tree_view); + g_return_if_fail (model != NULL); - /* Scroll to selected */ - selection = gtk_tree_view_get_selection (tree_view); - g_return_if_fail (selection != NULL); + /* Scroll to selected */ + selection = gtk_tree_view_get_selection (tree_view); + g_return_if_fail (selection != NULL); - if (gtk_tree_selection_get_selected (selection, NULL, &iter)) - { - GtkTreePath* path; + if (gtk_tree_selection_get_selected (selection, NULL, &iter)) + { + GtkTreePath* path; - path = gtk_tree_model_get_path (model, &iter); - g_return_if_fail (path != NULL); + path = gtk_tree_model_get_path (model, &iter); + g_return_if_fail (path != NULL); - gtk_tree_view_scroll_to_cell (tree_view, - path, NULL, TRUE, 1.0, 0.0); - gtk_tree_path_free (path); - } + gtk_tree_view_scroll_to_cell (tree_view, path, NULL, TRUE, 1.0, 0.0); + gtk_tree_path_free (path); + } } static void -create_formats_list (GtkWidget *listview, - const gchar *sel_format, - XedTimePlugin *plugin) +create_formats_list (GtkWidget *listview, + const gchar *sel_format, + XedTimePlugin *plugin) { - GtkTreeViewColumn *column; - GtkCellRenderer *cell; + GtkTreeViewColumn *column; + GtkCellRenderer *cell; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - g_return_if_fail (listview != NULL); - g_return_if_fail (sel_format != NULL); + g_return_if_fail (listview != NULL); + g_return_if_fail (sel_format != NULL); - /* the Available formats column */ - cell = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ( - _("Available formats"), - cell, - "text", COLUMN_FORMATS, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (listview), column); + /* the Available formats column */ + cell = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes (_("Available formats"), + cell, + "text", COLUMN_FORMATS, + NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (listview), column); - /* Create model, it also add model to the tree view */ - create_model (listview, sel_format, plugin); + /* Create model, it also add model to the tree view */ + create_model (listview, sel_format, plugin); - g_signal_connect (listview, - "realize", - G_CALLBACK (scroll_to_selected), - NULL); + g_signal_connect (listview, "realize", + G_CALLBACK (scroll_to_selected), NULL); - gtk_widget_show (listview); + gtk_widget_show (listview); } static void updated_custom_format_example (GtkEntry *format_entry, - GtkLabel *format_example) + GtkLabel *format_example) { - const gchar *format; - gchar *time; - gchar *str; - gchar *escaped_time; + const gchar *format; + gchar *time; + gchar *str; + gchar *escaped_time; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - g_return_if_fail (GTK_IS_ENTRY (format_entry)); - g_return_if_fail (GTK_IS_LABEL (format_example)); + g_return_if_fail (GTK_IS_ENTRY (format_entry)); + g_return_if_fail (GTK_IS_LABEL (format_example)); - format = gtk_entry_get_text (format_entry); + format = gtk_entry_get_text (format_entry); - time = get_time (format); - escaped_time = g_markup_escape_text (time, -1); + time = get_time (format); + escaped_time = g_markup_escape_text (time, -1); - str = g_strdup_printf ("%s", escaped_time); + str = g_strdup_printf ("%s", escaped_time); - gtk_label_set_markup (format_example, str); + gtk_label_set_markup (format_example, str); - g_free (escaped_time); - g_free (time); - g_free (str); + g_free (escaped_time); + g_free (time); + g_free (str); } static void -choose_format_dialog_button_toggled (GtkToggleButton *button, - ChooseFormatDialog *dialog) +choose_format_dialog_button_toggled (GtkToggleButton *button, + ChooseFormatDialog *dialog) { - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->custom))) - { - gtk_widget_set_sensitive (dialog->list, FALSE); - gtk_widget_set_sensitive (dialog->custom_entry, TRUE); - gtk_widget_set_sensitive (dialog->custom_format_example, TRUE); + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->custom))) + { + gtk_widget_set_sensitive (dialog->list, FALSE); + gtk_widget_set_sensitive (dialog->custom_entry, TRUE); + gtk_widget_set_sensitive (dialog->custom_format_example, TRUE); + } - return; - } - - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list))) - { - gtk_widget_set_sensitive (dialog->list, TRUE); - gtk_widget_set_sensitive (dialog->custom_entry, FALSE); - gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); - - return; - } + else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list))) + { + gtk_widget_set_sensitive (dialog->list, TRUE); + gtk_widget_set_sensitive (dialog->custom_entry, FALSE); + gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); + } + else + { + g_return_if_reached (); + } } static void -configure_dialog_button_toggled (GtkToggleButton *button, TimeConfigureDialog *dialog) +configure_widget_button_toggled (GtkToggleButton *button, + TimeConfigureWidget *conf_widget) { - xed_debug (DEBUG_PLUGINS); + XedTimePluginPromptType prompt_type; - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->custom))) - { - gtk_widget_set_sensitive (dialog->list, FALSE); - gtk_widget_set_sensitive (dialog->custom_entry, TRUE); - gtk_widget_set_sensitive (dialog->custom_format_example, TRUE); + xed_debug (DEBUG_PLUGINS); - set_prompt_type (dialog->settings, USE_CUSTOM_FORMAT); - return; - } + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (conf_widget->custom))) + { + gtk_widget_set_sensitive (conf_widget->list, FALSE); + gtk_widget_set_sensitive (conf_widget->custom_entry, TRUE); + gtk_widget_set_sensitive (conf_widget->custom_format_example, TRUE); - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list))) - { - gtk_widget_set_sensitive (dialog->list, TRUE); - gtk_widget_set_sensitive (dialog->custom_entry, FALSE); - gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); + prompt_type = USE_CUSTOM_FORMAT; + } - set_prompt_type (dialog->settings, USE_SELECTED_FORMAT); - return; - } + else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (conf_widget->use_list))) + { + gtk_widget_set_sensitive (conf_widget->list, TRUE); + gtk_widget_set_sensitive (conf_widget->custom_entry, FALSE); + gtk_widget_set_sensitive (conf_widget->custom_format_example, FALSE); - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->prompt))) - { - gtk_widget_set_sensitive (dialog->list, FALSE); - gtk_widget_set_sensitive (dialog->custom_entry, FALSE); - gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); + prompt_type = USE_SELECTED_FORMAT; + } - set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT); - return; - } + else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (conf_widget->prompt))) + { + gtk_widget_set_sensitive (conf_widget->list, FALSE); + gtk_widget_set_sensitive (conf_widget->custom_entry, FALSE); + gtk_widget_set_sensitive (conf_widget->custom_format_example, FALSE); + + prompt_type = PROMPT_SELECTED_FORMAT; + } + else + { + g_return_if_reached (); + } + + g_settings_set_enum (conf_widget->settings, PROMPT_TYPE_KEY, prompt_type); } static gint get_format_from_list (GtkWidget *listview) { - GtkTreeModel *model; - GtkTreeSelection *selection; - GtkTreeIter iter; + GtkTreeModel *model; + GtkTreeSelection *selection; + GtkTreeIter iter; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - model = gtk_tree_view_get_model (GTK_TREE_VIEW (listview)); - g_return_val_if_fail (model != NULL, 0); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (listview)); + g_return_val_if_fail (model != NULL, 0); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (listview)); - g_return_val_if_fail (selection != NULL, 0); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (listview)); + g_return_val_if_fail (selection != NULL, 0); - if (gtk_tree_selection_get_selected (selection, NULL, &iter)) - { - gint selected_value; + if (gtk_tree_selection_get_selected (selection, NULL, &iter)) + { + gint selected_value; - gtk_tree_model_get (model, &iter, COLUMN_INDEX, &selected_value, -1); + gtk_tree_model_get (model, &iter, COLUMN_INDEX, &selected_value, -1); - xed_debug_message (DEBUG_PLUGINS, "Sel value: %d", selected_value); + xed_debug_message (DEBUG_PLUGINS, "Sel value: %d", selected_value); - return selected_value; - } + return selected_value; + } - g_return_val_if_reached (0); + g_return_val_if_reached (0); } +// static void +// configure_dialog_selection_changed (GtkTreeSelection *selection, +// TimeConfigureDialog *dialog) +// { +// gint sel_format; + +// sel_format = get_format_from_list (dialog->list); +// set_selected_format (dialog->settings, formats[sel_format]); +// } + static void -configure_dialog_selection_changed (GtkTreeSelection *selection, - TimeConfigureDialog *dialog) +on_configure_widget_selection_changed (GtkTreeSelection *selection, + TimeConfigureWidget *conf_widget) { gint sel_format; - sel_format = get_format_from_list (dialog->list); - set_selected_format (dialog->settings, formats[sel_format]); + sel_format = get_format_from_list (conf_widget->list); + g_settings_set_string (conf_widget->settings, SELECTED_FORMAT_KEY, formats[sel_format]); } -static TimeConfigureDialog * -get_configure_dialog (XedTimePlugin *plugin) +static TimeConfigureWidget * +get_configure_widget (XedTimePlugin *plugin) { - TimeConfigureDialog *dialog = NULL; + TimeConfigureWidget *widget = NULL; GtkTreeSelection *selection; - gchar *data_dir; - gchar *ui_file; - GtkWidget *content; - GtkWidget *viewport; - XedTimePluginPromptType prompt_type; - gchar *sf, *cf; - GtkWidget *error_widget; - gboolean ret; - gchar *root_objects[] = { - "time_dialog_content", - NULL - }; + gchar *data_dir; + gchar *ui_file; + GtkWidget *viewport; + XedTimePluginPromptType prompt_type; + gchar *sf; + GtkWidget *error_widget; + gboolean ret; + gchar *root_objects[] = { + "time_dialog_content", + NULL + }; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - dialog = g_slice_new (TimeConfigureDialog); - dialog->settings = g_object_ref (plugin->priv->settings); + widget = g_slice_new (TimeConfigureWidget); + widget->settings = g_object_ref (plugin->priv->settings); - data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); - ui_file = g_build_filename (data_dir, "xed-time-setup-dialog.ui", NULL); - ret = xed_utils_get_ui_objects (ui_file, - root_objects, - &error_widget, - "time_dialog_content", &dialog->content, - "formats_viewport", &viewport, - "formats_tree", &dialog->list, - "always_prompt", &dialog->prompt, - "never_prompt", &dialog->use_list, - "use_custom", &dialog->custom, - "custom_entry", &dialog->custom_entry, - "custom_format_example", &dialog->custom_format_example, - NULL); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); + ui_file = g_build_filename (data_dir, "xed-time-setup-dialog.ui", NULL); + ret = xed_utils_get_ui_objects (ui_file, + root_objects, + &error_widget, + "time_dialog_content", &widget->content, + "formats_viewport", &viewport, + "formats_tree", &widget->list, + "always_prompt", &widget->prompt, + "never_prompt", &widget->use_list, + "use_custom", &widget->custom, + "custom_entry", &widget->custom_entry, + "custom_format_example", &widget->custom_format_example, + NULL); - g_free (data_dir); - g_free (ui_file); + g_free (data_dir); + g_free (ui_file); - if (!ret) - { - return NULL; - } + if (!ret) + { + return NULL; + } - sf = get_selected_format (plugin); - create_formats_list (dialog->list, sf, plugin); - g_free (sf); + sf = get_selected_format (plugin); + create_formats_list (widget->list, sf, plugin); + g_free (sf); - prompt_type = get_prompt_type (plugin); + prompt_type = g_settings_get_enum (plugin->priv->settings, PROMPT_TYPE_KEY); - g_settings_bind (dialog->settings, CUSTOM_FORMAT_KEY, - dialog->custom_entry, "text", + g_settings_bind (widget->settings, CUSTOM_FORMAT_KEY, + widget->custom_entry, "text", G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); - if (prompt_type == USE_CUSTOM_FORMAT) - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->custom), TRUE); + if (prompt_type == USE_CUSTOM_FORMAT) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->custom), TRUE); - gtk_widget_set_sensitive (dialog->list, FALSE); - gtk_widget_set_sensitive (dialog->custom_entry, TRUE); - gtk_widget_set_sensitive (dialog->custom_format_example, TRUE); - } - else if (prompt_type == USE_SELECTED_FORMAT) - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->use_list), TRUE); + gtk_widget_set_sensitive (widget->list, FALSE); + gtk_widget_set_sensitive (widget->custom_entry, TRUE); + gtk_widget_set_sensitive (widget->custom_format_example, TRUE); + } + else if (prompt_type == USE_SELECTED_FORMAT) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->use_list), TRUE); - gtk_widget_set_sensitive (dialog->list, TRUE); - gtk_widget_set_sensitive (dialog->custom_entry, FALSE); - gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); - } - else - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->prompt), TRUE); + gtk_widget_set_sensitive (widget->list, TRUE); + gtk_widget_set_sensitive (widget->custom_entry, FALSE); + gtk_widget_set_sensitive (widget->custom_format_example, FALSE); + } + else + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->prompt), TRUE); - gtk_widget_set_sensitive (dialog->list, FALSE); - gtk_widget_set_sensitive (dialog->custom_entry, FALSE); - gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); - } + gtk_widget_set_sensitive (widget->list, FALSE); + gtk_widget_set_sensitive (widget->custom_entry, FALSE); + gtk_widget_set_sensitive (widget->custom_format_example, FALSE); + } - updated_custom_format_example (GTK_ENTRY (dialog->custom_entry), - GTK_LABEL (dialog->custom_format_example)); + updated_custom_format_example (GTK_ENTRY (widget->custom_entry), GTK_LABEL (widget->custom_format_example)); - /* setup a window of a sane size. */ - gtk_widget_set_size_request (GTK_WIDGET (viewport), 10, 200); + /* setup a window of a sane size. */ + gtk_widget_set_size_request (GTK_WIDGET (viewport), 10, 200); - g_signal_connect (dialog->custom, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); - g_signal_connect (dialog->prompt, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); - g_signal_connect (dialog->use_list, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); - g_signal_connect (dialog->content, "destroy", G_CALLBACK (configure_dialog_destroyed), dialog); - g_signal_connect (dialog->custom_entry, "changed", G_CALLBACK (updated_custom_format_example), dialog->custom_format_example); + g_signal_connect (widget->custom, "toggled", + G_CALLBACK (configure_widget_button_toggled), widget); + g_signal_connect (widget->prompt, "toggled", + G_CALLBACK (configure_widget_button_toggled), widget); + g_signal_connect (widget->use_list, "toggled", + G_CALLBACK (configure_widget_button_toggled), widget); + g_signal_connect (widget->content, "destroy", + G_CALLBACK (configure_widget_destroyed), widget); + g_signal_connect (widget->custom_entry, "changed", + G_CALLBACK (updated_custom_format_example), widget->custom_format_example); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->list)); - g_signal_connect (selection, "changed", G_CALLBACK (configure_dialog_selection_changed), dialog); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget->list)); + g_signal_connect (selection, "changed", + G_CALLBACK (on_configure_widget_selection_changed), widget); - return dialog; + return widget; } static void real_insert_time (GtkTextBuffer *buffer, - const gchar *the_time) + const gchar *the_time) { - xed_debug_message (DEBUG_PLUGINS, "Insert: %s", the_time); + xed_debug_message (DEBUG_PLUGINS, "Insert: %s", the_time); - gtk_text_buffer_begin_user_action (buffer); + gtk_text_buffer_begin_user_action (buffer); - gtk_text_buffer_insert_at_cursor (buffer, the_time, -1); - gtk_text_buffer_insert_at_cursor (buffer, " ", -1); + gtk_text_buffer_insert_at_cursor (buffer, the_time, -1); + gtk_text_buffer_insert_at_cursor (buffer, " ", -1); - gtk_text_buffer_end_user_action (buffer); + gtk_text_buffer_end_user_action (buffer); } static void choose_format_dialog_row_activated (GtkTreeView *list, - GtkTreePath *path, - GtkTreeViewColumn *column, - ChooseFormatDialog *dialog) + GtkTreePath *path, + GtkTreeViewColumn *column, + ChooseFormatDialog *dialog) { - gint sel_format; - gchar *the_time; + gint sel_format; + gchar *the_time; - sel_format = get_format_from_list (dialog->list); - the_time = get_time (formats[sel_format]); + sel_format = get_format_from_list (dialog->list); + the_time = get_time (formats[sel_format]); - set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT); - set_selected_format (dialog->settings, formats[sel_format]); + g_settings_set_enum (dialog->settings, PROMPT_TYPE_KEY, PROMPT_SELECTED_FORMAT); + g_settings_set_string (dialog->settings, SELECTED_FORMAT_KEY, formats[sel_format]); - g_return_if_fail (the_time != NULL); + g_return_if_fail (the_time != NULL); - real_insert_time (dialog->buffer, the_time); + real_insert_time (dialog->buffer, the_time); - g_free (the_time); + g_free (the_time); } static ChooseFormatDialog * -get_choose_format_dialog (GtkWindow *parent, - XedTimePluginPromptType prompt_type, - XedTimePlugin *plugin) +get_choose_format_dialog (GtkWindow *parent, + XedTimePluginPromptType prompt_type, + XedTimePlugin *plugin) { - ChooseFormatDialog *dialog; - gchar *data_dir; - gchar *ui_file; - GtkWidget *error_widget; - gboolean ret; - gchar *sf, *cf; - GtkWindowGroup *wg = NULL; + ChooseFormatDialog *dialog; + gchar *data_dir; + gchar *ui_file; + GtkWidget *error_widget; + gboolean ret; + gchar *sf, *cf; + GtkWindowGroup *wg = NULL; - if (parent != NULL) - wg = gtk_window_get_group (parent); + if (parent != NULL) + { + wg = gtk_window_get_group (parent); + } - dialog = g_slice_new (ChooseFormatDialog); + dialog = g_slice_new (ChooseFormatDialog); dialog->settings = plugin->priv->settings; - data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); - ui_file = g_build_filename (data_dir, "xed-time-dialog.ui", NULL); - ret = xed_utils_get_ui_objects (ui_file, - NULL, - &error_widget, - "choose_format_dialog", &dialog->dialog, - "choice_list", &dialog->list, - "use_sel_format_radiobutton", &dialog->use_list, - "use_custom_radiobutton", &dialog->custom, - "custom_entry", &dialog->custom_entry, - "custom_format_example", &dialog->custom_format_example, - NULL); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); + ui_file = g_build_filename (data_dir, "xed-time-dialog.ui", NULL); + ret = xed_utils_get_ui_objects (ui_file, + NULL, + &error_widget, + "choose_format_dialog", &dialog->dialog, + "choice_list", &dialog->list, + "use_sel_format_radiobutton", &dialog->use_list, + "use_custom_radiobutton", &dialog->custom, + "custom_entry", &dialog->custom_entry, + "custom_format_example", &dialog->custom_format_example, + NULL); - g_free (data_dir); - g_free (ui_file); + g_free (data_dir); + g_free (ui_file); - if (!ret) - { - GtkWidget *err_dialog; + if (!ret) + { + GtkWidget *err_dialog; - err_dialog = gtk_dialog_new_with_buttons (NULL, - parent, - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, - NULL); + err_dialog = gtk_dialog_new_with_buttons (NULL, + parent, + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + NULL); - if (wg != NULL) - gtk_window_group_add_window (wg, GTK_WINDOW (err_dialog)); + if (wg != NULL) + { + gtk_window_group_add_window (wg, GTK_WINDOW (err_dialog)); + } - gtk_window_set_resizable (GTK_WINDOW (err_dialog), FALSE); - gtk_dialog_set_default_response (GTK_DIALOG (err_dialog), GTK_RESPONSE_OK); + gtk_window_set_resizable (GTK_WINDOW (err_dialog), FALSE); + gtk_dialog_set_default_response (GTK_DIALOG (err_dialog), GTK_RESPONSE_OK); - gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (err_dialog))), - error_widget); + gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (err_dialog))), error_widget); - g_signal_connect (G_OBJECT (err_dialog), - "response", - G_CALLBACK (gtk_widget_destroy), - NULL); + g_signal_connect (G_OBJECT (err_dialog), "response", + G_CALLBACK (gtk_widget_destroy), NULL); - gtk_widget_show_all (err_dialog); + gtk_widget_show_all (err_dialog); - return NULL; - } + return NULL; + } - gtk_window_group_add_window (wg, - GTK_WINDOW (dialog->dialog)); - gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), parent); - gtk_window_set_modal (GTK_WINDOW (dialog->dialog), TRUE); + gtk_window_group_add_window (wg, GTK_WINDOW (dialog->dialog)); + gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), parent); + gtk_window_set_modal (GTK_WINDOW (dialog->dialog), TRUE); - sf = get_selected_format (plugin); - create_formats_list (dialog->list, sf, plugin); - g_free (sf); + sf = get_selected_format (plugin); + create_formats_list (dialog->list, sf, plugin); + g_free (sf); - cf = get_custom_format (plugin); - gtk_entry_set_text (GTK_ENTRY(dialog->custom_entry), cf); - g_free (cf); + cf = get_custom_format (plugin); + gtk_entry_set_text (GTK_ENTRY (dialog->custom_entry), cf); + g_free (cf); - updated_custom_format_example (GTK_ENTRY (dialog->custom_entry), - GTK_LABEL (dialog->custom_format_example)); + updated_custom_format_example (GTK_ENTRY (dialog->custom_entry), + GTK_LABEL (dialog->custom_format_example)); - if (prompt_type == PROMPT_CUSTOM_FORMAT) - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->custom), TRUE); + if (prompt_type == PROMPT_CUSTOM_FORMAT) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->custom), TRUE); - gtk_widget_set_sensitive (dialog->list, FALSE); - gtk_widget_set_sensitive (dialog->custom_entry, TRUE); - gtk_widget_set_sensitive (dialog->custom_format_example, TRUE); - } - else if (prompt_type == PROMPT_SELECTED_FORMAT) - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->use_list), TRUE); + gtk_widget_set_sensitive (dialog->list, FALSE); + gtk_widget_set_sensitive (dialog->custom_entry, TRUE); + gtk_widget_set_sensitive (dialog->custom_format_example, TRUE); + } + else if (prompt_type == PROMPT_SELECTED_FORMAT) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->use_list), TRUE); - gtk_widget_set_sensitive (dialog->list, TRUE); - gtk_widget_set_sensitive (dialog->custom_entry, FALSE); - gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); - } - else - { - g_return_val_if_reached (NULL); - } + gtk_widget_set_sensitive (dialog->list, TRUE); + gtk_widget_set_sensitive (dialog->custom_entry, FALSE); + gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); + } + else + { + g_return_val_if_reached (NULL); + } - /* setup a window of a sane size. */ - gtk_widget_set_size_request (dialog->list, 10, 200); + /* setup a window of a sane size. */ + gtk_widget_set_size_request (dialog->list, 10, 200); - gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), - GTK_RESPONSE_OK); + gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), GTK_RESPONSE_OK); - g_signal_connect (dialog->custom, - "toggled", - G_CALLBACK (choose_format_dialog_button_toggled), - dialog); - g_signal_connect (dialog->use_list, - "toggled", - G_CALLBACK (choose_format_dialog_button_toggled), - dialog); - g_signal_connect (dialog->dialog, - "destroy", - G_CALLBACK (choose_format_dialog_destroyed), - dialog); - g_signal_connect (dialog->custom_entry, - "changed", - G_CALLBACK (updated_custom_format_example), - dialog->custom_format_example); - g_signal_connect (dialog->list, - "row_activated", - G_CALLBACK (choose_format_dialog_row_activated), - dialog); + g_signal_connect (dialog->custom, "toggled", + G_CALLBACK (choose_format_dialog_button_toggled), dialog); + g_signal_connect (dialog->use_list, "toggled", + G_CALLBACK (choose_format_dialog_button_toggled), dialog); + g_signal_connect (dialog->dialog, "destroy", + G_CALLBACK (choose_format_dialog_destroyed), dialog); + g_signal_connect (dialog->custom_entry, "changed", + G_CALLBACK (updated_custom_format_example), dialog->custom_format_example); + g_signal_connect (dialog->list, "row_activated", + G_CALLBACK (choose_format_dialog_row_activated), dialog); - gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE); + gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE); - return dialog; + return dialog; } static void choose_format_dialog_response_cb (GtkWidget *widget, - gint response, - ChooseFormatDialog *dialog) + gint response, + ChooseFormatDialog *dialog) { - switch (response) - { - case GTK_RESPONSE_HELP: - { - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_HELP"); - xed_help_display (GTK_WINDOW (widget), - NULL, - "xed-insert-date-time-plugin"); - break; - } - case GTK_RESPONSE_OK: - { - gchar *the_time; + switch (response) + { + case GTK_RESPONSE_HELP: + { + xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_HELP"); + xed_help_display (GTK_WINDOW (widget), NULL, "xed-insert-date-time-plugin"); + break; + } + case GTK_RESPONSE_OK: + { + gchar *the_time; - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK"); + xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK"); - /* Get the user's chosen format */ - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list))) - { - gint sel_format; + /* Get the user's chosen format */ + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list))) + { + gint sel_format; - sel_format = get_format_from_list (dialog->list); - the_time = get_time (formats[sel_format]); + sel_format = get_format_from_list (dialog->list); + the_time = get_time (formats[sel_format]); - set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT); - set_selected_format (dialog->settings, formats[sel_format]); - } - else - { - const gchar *format; + g_settings_set_enum (dialog->settings, PROMPT_TYPE_KEY, PROMPT_SELECTED_FORMAT); + g_settings_set_string (dialog->settings, SELECTED_FORMAT_KEY, formats[sel_format]); + } + else + { + const gchar *format; - format = gtk_entry_get_text (GTK_ENTRY (dialog->custom_entry)); - the_time = get_time (format); + format = gtk_entry_get_text (GTK_ENTRY (dialog->custom_entry)); + the_time = get_time (format); - set_prompt_type (dialog->settings, PROMPT_CUSTOM_FORMAT); - set_custom_format (dialog->settings, format); - } + g_settings_set_enum (dialog->settings, PROMPT_TYPE_KEY, PROMPT_CUSTOM_FORMAT); + g_settings_set_string (dialog->settings, CUSTOM_FORMAT_KEY, format); + } - g_return_if_fail (the_time != NULL); + g_return_if_fail (the_time != NULL); - real_insert_time (dialog->buffer, the_time); - g_free (the_time); + real_insert_time (dialog->buffer, the_time); + g_free (the_time); - gtk_widget_destroy (dialog->dialog); - break; - } - case GTK_RESPONSE_CANCEL: - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CANCEL"); - gtk_widget_destroy (dialog->dialog); - } + gtk_widget_destroy (dialog->dialog); + break; + } + case GTK_RESPONSE_CANCEL: + xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CANCEL"); + gtk_widget_destroy (dialog->dialog); + } } static void time_cb (GtkAction *action, - XedTimePlugin *plugin) + XedTimePlugin *plugin) { - XedWindow *window; - GtkTextBuffer *buffer; - gchar *the_time = NULL; - XedTimePluginPromptType prompt_type; + XedTimePluginPrivate *priv; + GtkTextBuffer *buffer; + gchar *the_time = NULL; + XedTimePluginPromptType prompt_type; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - window = XED_WINDOW (plugin->priv->window); - buffer = GTK_TEXT_BUFFER (xed_window_get_active_document (window)); - g_return_if_fail (buffer != NULL); + priv = plugin->priv; - prompt_type = get_prompt_type (plugin); + buffer = GTK_TEXT_BUFFER (xed_window_get_active_document (priv->window)); + g_return_if_fail (buffer != NULL); - if (prompt_type == USE_CUSTOM_FORMAT) + prompt_type = g_settings_get_enum (plugin->priv->settings, PROMPT_TYPE_KEY); + + if (prompt_type == USE_CUSTOM_FORMAT) + { + gchar *cf = get_custom_format (plugin); + the_time = get_time (cf); + g_free (cf); + } + else if (prompt_type == USE_SELECTED_FORMAT) + { + gchar *sf = get_selected_format (plugin); + the_time = get_time (sf); + g_free (sf); + } + else + { + ChooseFormatDialog *dialog; + + dialog = get_choose_format_dialog (GTK_WINDOW (priv->window), prompt_type, plugin); + if (dialog != NULL) { - gchar *cf = get_custom_format (plugin); - the_time = get_time (cf); - g_free (cf); - } - else if (prompt_type == USE_SELECTED_FORMAT) - { - gchar *sf = get_selected_format (plugin); - the_time = get_time (sf); - g_free (sf); - } - else - { - ChooseFormatDialog *dialog; + dialog->buffer = buffer; + dialog->settings = priv->settings; - dialog = get_choose_format_dialog (GTK_WINDOW (window), - prompt_type, - plugin); - if (dialog != NULL) - { - dialog->buffer = buffer; - dialog->settings = plugin->priv->settings; + g_signal_connect (dialog->dialog, "response", + G_CALLBACK (choose_format_dialog_response_cb), dialog); - g_signal_connect (dialog->dialog, - "response", - G_CALLBACK (choose_format_dialog_response_cb), - dialog); + gtk_widget_show (GTK_WIDGET (dialog->dialog)); + } - gtk_widget_show (GTK_WIDGET (dialog->dialog)); - } + return; + } - return; - } + g_return_if_fail (the_time != NULL); - g_return_if_fail (the_time != NULL); + real_insert_time (buffer, the_time); - real_insert_time (buffer, the_time); - - g_free (the_time); + g_free (the_time); } static GtkWidget * xed_time_plugin_create_configure_widget (PeasGtkConfigurable *configurable) { - TimeConfigureDialog *dialog; + TimeConfigureWidget *widget; - dialog = get_configure_dialog (XED_TIME_PLUGIN (configurable)); + widget = get_configure_widget (XED_TIME_PLUGIN (configurable)); - return dialog->content; + return widget->content; } static void @@ -1128,8 +1075,8 @@ xed_time_plugin_set_property (GObject *object, switch (prop_id) { - case PROP_OBJECT: - plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + case PROP_WINDOW: + plugin->priv->window = XED_WINDOW (g_value_dup_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1147,7 +1094,7 @@ xed_time_plugin_get_property (GObject *object, switch (prop_id) { - case PROP_OBJECT: + case PROP_WINDOW: g_value_set_object (value, plugin->priv->window); break; default: @@ -1159,16 +1106,16 @@ xed_time_plugin_get_property (GObject *object, static void xed_time_plugin_class_init (XedTimePluginClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = xed_time_plugin_finalize; + object_class->finalize = xed_time_plugin_finalize; object_class->dispose = xed_time_plugin_dispose; object_class->set_property = xed_time_plugin_set_property; object_class->get_property = xed_time_plugin_get_property; - g_object_class_override_property (object_class, PROP_OBJECT, "object"); + g_object_class_override_property (object_class, PROP_WINDOW, "window"); - g_type_class_add_private (object_class, sizeof (XedTimePluginPrivate)); + g_type_class_add_private (object_class, sizeof (XedTimePluginPrivate)); } static void @@ -1178,7 +1125,7 @@ xed_time_plugin_class_finalize (XedTimePluginClass *klass) } static void -peas_activatable_iface_init (PeasActivatableInterface *iface) +xed_window_activatable_iface_init (XedWindowActivatableInterface *iface) { iface->activate = xed_time_plugin_activate; iface->deactivate = xed_time_plugin_deactivate; @@ -1197,7 +1144,7 @@ peas_register_types (PeasObjectModule *module) xed_time_plugin_register_type (G_TYPE_MODULE (module)); peas_object_module_register_extension_type (module, - PEAS_TYPE_ACTIVATABLE, + XED_TYPE_WINDOW_ACTIVATABLE, XED_TYPE_TIME_PLUGIN); peas_object_module_register_extension_type (module, diff --git a/plugins/time/xed-time-plugin.h b/plugins/time/xed-time-plugin.h index 436ed05..1019ce9 100644 --- a/plugins/time/xed-time-plugin.h +++ b/plugins/time/xed-time-plugin.h @@ -30,23 +30,16 @@ G_BEGIN_DECLS -/* - * Type checking and casting macros - */ -#define XED_TYPE_TIME_PLUGIN (xed_time_plugin_get_type ()) -#define XED_TIME_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TIME_PLUGIN, XedTimePlugin)) -#define XED_TIME_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TIME_PLUGIN, XedTimePluginClass)) -#define XED_IS_TIME_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TIME_PLUGIN)) -#define XED_IS_TIME_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TIME_PLUGIN)) +#define XED_TYPE_TIME_PLUGIN (xed_time_plugin_get_type ()) +#define XED_TIME_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TIME_PLUGIN, XedTimePlugin)) +#define XED_TIME_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TIME_PLUGIN, XedTimePluginClass)) +#define XED_IS_TIME_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TIME_PLUGIN)) +#define XED_IS_TIME_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TIME_PLUGIN)) #define XED_TIME_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_TIME_PLUGIN, XedTimePluginClass)) -/* Private structure type */ -typedef struct _XedTimePluginPrivate XedTimePluginPrivate; - -/* - * Main object structure - */ -typedef struct _XedTimePlugin XedTimePlugin; +typedef struct _XedTimePlugin XedTimePlugin; +typedef struct _XedTimePluginPrivate XedTimePluginPrivate; +typedef struct _XedTimePluginClass XedTimePluginClass; struct _XedTimePlugin { @@ -56,20 +49,12 @@ struct _XedTimePlugin XedTimePluginPrivate *priv; }; -/* - * Class definition - */ -typedef struct _XedTimePluginClass XedTimePluginClass; - struct _XedTimePluginClass { PeasExtensionBaseClass parent_class; }; -/* - * Public methods - */ -GType xed_time_plugin_get_type (void) G_GNUC_CONST; +GType xed_time_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); From 769f1baaaa657a5f626af9563b72413bf2a907ab Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Wed, 11 Jan 2017 12:33:03 -0800 Subject: [PATCH 081/132] changecase-plugin: Port to WindowActivatable --- plugins/Makefile.am | 2 + plugins/changecase/xed-changecase-plugin.c | 124 +++++++++------------ plugins/changecase/xed-changecase-plugin.h | 33 ++---- 3 files changed, 63 insertions(+), 96 deletions(-) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index d46447c..f31e42b 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,4 +1,5 @@ DIST_SUBDIRS = \ + changecase \ docinfo \ filebrowser \ modelines \ @@ -7,6 +8,7 @@ DIST_SUBDIRS = \ time SUBDIRS = \ + changecase \ docinfo \ filebrowser \ modelines \ diff --git a/plugins/changecase/xed-changecase-plugin.c b/plugins/changecase/xed-changecase-plugin.c index 52b9e4e..0adc91c 100644 --- a/plugins/changecase/xed-changecase-plugin.c +++ b/plugins/changecase/xed-changecase-plugin.c @@ -26,29 +26,26 @@ #include "xed-changecase-plugin.h" -#include +#include #include -#include #include +#include #include -#define XED_CHANGECASE_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ - XED_TYPE_CHANGECASE_PLUGIN, \ - XedChangecasePluginPrivate)) - -static void peas_activatable_iface_init (PeasActivatableInterface *iface); +static void xed_window_activatable_iface_init (XedWindowActivatableInterface *iface); G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedChangecasePlugin, xed_changecase_plugin, PEAS_TYPE_EXTENSION_BASE, 0, - G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, - peas_activatable_iface_init)) + G_IMPLEMENT_INTERFACE_DYNAMIC (XED_TYPE_WINDOW_ACTIVATABLE, + xed_window_activatable_iface_init)) struct _XedChangecasePluginPrivate { - GtkWidget *window; + XedWindow *window; + GtkActionGroup *action_group; guint ui_id; }; @@ -56,7 +53,7 @@ struct _XedChangecasePluginPrivate enum { PROP_0, - PROP_OBJECT + PROP_WINDOW }; typedef enum { @@ -197,20 +194,20 @@ change_case (XedWindow *window, switch (choice) { - case TO_UPPER_CASE: - do_upper_case (GTK_TEXT_BUFFER (doc), &start, &end); - break; - case TO_LOWER_CASE: - do_lower_case (GTK_TEXT_BUFFER (doc), &start, &end); - break; - case INVERT_CASE: - do_invert_case (GTK_TEXT_BUFFER (doc), &start, &end); - break; - case TO_TITLE_CASE: - do_title_case (GTK_TEXT_BUFFER (doc), &start, &end); - break; - default: - g_return_if_reached (); + case TO_UPPER_CASE: + do_upper_case (GTK_TEXT_BUFFER (doc), &start, &end); + break; + case TO_LOWER_CASE: + do_lower_case (GTK_TEXT_BUFFER (doc), &start, &end); + break; + case INVERT_CASE: + do_invert_case (GTK_TEXT_BUFFER (doc), &start, &end); + break; + case TO_TITLE_CASE: + do_title_case (GTK_TEXT_BUFFER (doc), &start, &end); + break; + default: + g_return_if_reached (); } gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (doc)); @@ -282,7 +279,7 @@ xed_changecase_plugin_init (XedChangecasePlugin *plugin) { xed_debug_message (DEBUG_PLUGINS, "XedChangecasePlugin initializing"); - plugin->priv = XED_CHANGECASE_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin, XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePluginPrivate); } static void @@ -292,17 +289,8 @@ xed_changecase_plugin_dispose (GObject *object) xed_debug_message (DEBUG_PLUGINS, "XedChangecasePlugin disposing"); - if (plugin->priv->window != NULL) - { - g_object_unref (plugin->priv->window); - plugin->priv->window = NULL; - } - - if (plugin->priv->action_group != NULL) - { - g_object_unref (plugin->priv->action_group); - plugin->priv->action_group = NULL; - } + g_clear_object (&plugin->priv->window); + g_clear_object (&plugin->priv->action_group); G_OBJECT_CLASS (xed_changecase_plugin_parent_class)->dispose (object); } @@ -317,8 +305,8 @@ xed_changecase_plugin_set_property (GObject *object, switch (prop_id) { - case PROP_OBJECT: - plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + case PROP_WINDOW: + plugin->priv->window = XED_WINDOW (g_value_dup_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -336,7 +324,7 @@ xed_changecase_plugin_get_property (GObject *object, switch (prop_id) { - case PROP_OBJECT: + case PROP_WINDOW: g_value_set_object (value, plugin->priv->window); break; default: @@ -346,17 +334,15 @@ xed_changecase_plugin_get_property (GObject *object, } static void -update_ui (XedChangecasePluginPrivate *data) +update_ui (XedChangecasePlugin *plugin) { - XedWindow *window; GtkTextView *view; GtkAction *action; gboolean sensitive = FALSE; xed_debug (DEBUG_PLUGINS); - window = XED_WINDOW (data->window); - view = GTK_TEXT_VIEW (xed_window_get_active_view (window)); + view = GTK_TEXT_VIEW (xed_window_get_active_view (plugin->priv->window)); if (view != NULL) { @@ -366,65 +352,61 @@ update_ui (XedChangecasePluginPrivate *data) sensitive = (gtk_text_view_get_editable (view) && gtk_text_buffer_get_has_selection (buffer)); } - action = gtk_action_group_get_action (data->action_group, "ChangeCase"); + action = gtk_action_group_get_action (plugin->priv->action_group, "ChangeCase"); gtk_action_set_sensitive (action, sensitive); } static void -xed_changecase_plugin_activate (PeasActivatable *activatable) +xed_changecase_plugin_activate (XedWindowActivatable *activatable) { - XedChangecasePluginPrivate *data; - XedWindow *window; + XedChangecasePluginPrivate *priv; GtkUIManager *manager; GError *error = NULL; xed_debug (DEBUG_PLUGINS); - data = XED_CHANGECASE_PLUGIN (activatable)->priv; - window = XED_WINDOW (data->window); + priv = XED_CHANGECASE_PLUGIN (activatable)->priv; - manager = xed_window_get_ui_manager (window); + manager = xed_window_get_ui_manager (priv->window); - data->action_group = gtk_action_group_new ("XedChangecasePluginActions"); - gtk_action_group_set_translation_domain (data->action_group, GETTEXT_PACKAGE); - gtk_action_group_add_actions (data->action_group, action_entries, G_N_ELEMENTS (action_entries), window); + priv->action_group = gtk_action_group_new ("XedChangecasePluginActions"); + gtk_action_group_set_translation_domain (priv->action_group, GETTEXT_PACKAGE); + gtk_action_group_add_actions (priv->action_group, action_entries, G_N_ELEMENTS (action_entries), priv->window); - gtk_ui_manager_insert_action_group (manager, data->action_group, -1); + gtk_ui_manager_insert_action_group (manager, priv->action_group, -1); - data->ui_id = gtk_ui_manager_add_ui_from_string (manager, submenu, -1, &error); - if (data->ui_id == 0) + priv->ui_id = gtk_ui_manager_add_ui_from_string (manager, submenu, -1, &error); + if (priv->ui_id == 0) { g_warning ("%s", error->message); return; } - update_ui (data); + update_ui (XED_CHANGECASE_PLUGIN (activatable)); } static void -xed_changecase_plugin_deactivate (PeasActivatable *activatable) +xed_changecase_plugin_deactivate (XedWindowActivatable *activatable) { - XedChangecasePluginPrivate *data; - XedWindow *window; + XedChangecasePluginPrivate *priv; GtkUIManager *manager; xed_debug (DEBUG_PLUGINS); - data = XED_CHANGECASE_PLUGIN (activatable)->priv; - window = XED_WINDOW (data->window); + priv = XED_CHANGECASE_PLUGIN (activatable)->priv; - manager = xed_window_get_ui_manager (window); + manager = xed_window_get_ui_manager (priv->window); - gtk_ui_manager_remove_ui (manager, data->ui_id); - gtk_ui_manager_remove_action_group (manager, data->action_group); + gtk_ui_manager_remove_ui (manager, priv->ui_id); + gtk_ui_manager_remove_action_group (manager, priv->action_group); } static void -xed_changecase_plugin_update_state (PeasActivatable *activatable) +xed_changecase_plugin_update_state (XedWindowActivatable *activatable) { xed_debug (DEBUG_PLUGINS); - update_ui (XED_CHANGECASE_PLUGIN (activatable)->priv); + update_ui (XED_CHANGECASE_PLUGIN (activatable)); } static void @@ -436,7 +418,7 @@ xed_changecase_plugin_class_init (XedChangecasePluginClass *klass) object_class->set_property = xed_changecase_plugin_set_property; object_class->get_property = xed_changecase_plugin_get_property; - g_object_class_override_property (object_class, PROP_OBJECT, "object"); + g_object_class_override_property (object_class, PROP_WINDOW, "window"); g_type_class_add_private (klass, sizeof (XedChangecasePluginPrivate)); } @@ -448,7 +430,7 @@ xed_changecase_plugin_class_finalize (XedChangecasePluginClass *klass) } static void -peas_activatable_iface_init (PeasActivatableInterface *iface) +xed_window_activatable_iface_init (XedWindowActivatableInterface *iface) { iface->activate = xed_changecase_plugin_activate; iface->deactivate = xed_changecase_plugin_deactivate; @@ -461,6 +443,6 @@ peas_register_types (PeasObjectModule *module) xed_changecase_plugin_register_type (G_TYPE_MODULE (module)); peas_object_module_register_extension_type (module, - PEAS_TYPE_ACTIVATABLE, + XED_TYPE_WINDOW_ACTIVATABLE, XED_TYPE_CHANGECASE_PLUGIN); } diff --git a/plugins/changecase/xed-changecase-plugin.h b/plugins/changecase/xed-changecase-plugin.h index 6053c4c..e5f50da 100644 --- a/plugins/changecase/xed-changecase-plugin.h +++ b/plugins/changecase/xed-changecase-plugin.h @@ -16,8 +16,6 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ */ #ifndef __XED_CHANGECASE_PLUGIN_H__ @@ -30,22 +28,16 @@ G_BEGIN_DECLS -/* - * Type checking and casting macros - */ -#define XED_TYPE_CHANGECASE_PLUGIN (xed_changecase_plugin_get_type ()) -#define XED_CHANGECASE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePlugin)) -#define XED_CHANGECASE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePluginClass)) -#define XED_IS_CHANGECASE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_CHANGECASE_PLUGIN)) +#define XED_TYPE_CHANGECASE_PLUGIN (xed_changecase_plugin_get_type ()) +#define XED_CHANGECASE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePlugin)) +#define XED_CHANGECASE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePluginClass)) +#define XED_IS_CHANGECASE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_CHANGECASE_PLUGIN)) #define XED_IS_CHANGECASE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_CHANGECASE_PLUGIN)) #define XED_CHANGECASE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePluginClass)) -typedef struct _XedChangecasePluginPrivate XedChangecasePluginPrivate; - -/* - * Main object structure - */ -typedef struct _XedChangecasePlugin XedChangecasePlugin; +typedef struct _XedChangecasePlugin XedChangecasePlugin; +typedef struct _XedChangecasePluginPrivate XedChangecasePluginPrivate; +typedef struct _XedChangecasePluginClass XedChangecasePluginClass; struct _XedChangecasePlugin { @@ -55,22 +47,13 @@ struct _XedChangecasePlugin XedChangecasePluginPrivate *priv; }; -/* - * Class definition - */ -typedef struct _XedChangecasePluginClass XedChangecasePluginClass; - struct _XedChangecasePluginClass { PeasExtensionBaseClass parent_class; }; -/* - * Public methods - */ -GType xed_changecase_plugin_get_type (void) G_GNUC_CONST; +GType xed_changecase_plugin_get_type (void) G_GNUC_CONST; -/* All the plugins must implement this function */ G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS From cd3ab1695d3de94be5bcfa9d98178fd803bb0ef1 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Wed, 11 Jan 2017 22:52:37 -0800 Subject: [PATCH 082/132] taglist-plugin: Port to WindowActivatable --- plugins/Makefile.am | 2 + plugins/taglist/xed-taglist-plugin.c | 107 ++++++++++++--------------- plugins/taglist/xed-taglist-plugin.h | 27 ++----- 3 files changed, 56 insertions(+), 80 deletions(-) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index f31e42b..522da2c 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -5,6 +5,7 @@ DIST_SUBDIRS = \ modelines \ sort \ spell \ + taglist \ time SUBDIRS = \ @@ -14,6 +15,7 @@ SUBDIRS = \ modelines \ sort \ spell \ + taglist \ time if ENABLE_ENCHANT diff --git a/plugins/taglist/xed-taglist-plugin.c b/plugins/taglist/xed-taglist-plugin.c index 8d379dc..ea23652 100644 --- a/plugins/taglist/xed-taglist-plugin.c +++ b/plugins/taglist/xed-taglist-plugin.c @@ -36,59 +36,54 @@ #include "xed-taglist-plugin-parser.h" #include -#include -#include #include +#include #include #define XED_TAGLIST_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginPrivate)) struct _XedTaglistPluginPrivate { - GtkWidget *window; + XedWindow *window; GtkWidget *taglist_panel; }; -static void peas_activatable_iface_init (PeasActivatableInterface *iface); +static void xed_window_activatable_iface_init (XedWindowActivatableInterface *iface); G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedTaglistPlugin, xed_taglist_plugin, PEAS_TYPE_EXTENSION_BASE, 0, - G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, - peas_activatable_iface_init) \ - \ - _xed_taglist_plugin_panel_register_type (type_module); \ + G_IMPLEMENT_INTERFACE_DYNAMIC (XED_TYPE_WINDOW_ACTIVATABLE, + xed_window_activatable_iface_init) \ + \ + _xed_taglist_plugin_panel_register_type (type_module); \ ) enum { PROP_0, - PROP_OBJECT + PROP_WINDOW }; static void xed_taglist_plugin_init (XedTaglistPlugin *plugin) { - plugin->priv = XED_TAGLIST_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = XED_TAGLIST_PLUGIN_GET_PRIVATE (plugin); - xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin initializing"); + xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin initializing"); } static void xed_taglist_plugin_dispose (GObject *object) { - XedTaglistPlugin *plugin = XED_TAGLIST_PLUGIN (object); + XedTaglistPlugin *plugin = XED_TAGLIST_PLUGIN (object); - xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin disposing"); + xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin disposing"); - if (plugin->priv->window != NULL) - { - g_object_unref (plugin->priv->window); - plugin->priv->window = NULL; - } + g_clear_object (&plugin->priv->window); G_OBJECT_CLASS (xed_taglist_plugin_parent_class)->dispose (object); } @@ -98,64 +93,58 @@ xed_taglist_plugin_finalize (GObject *object) { xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin finalizing"); - free_taglist (); + free_taglist (); - G_OBJECT_CLASS (xed_taglist_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_taglist_plugin_parent_class)->finalize (object); } static void -xed_taglist_plugin_activate (PeasActivatable *activatable) +xed_taglist_plugin_activate (XedWindowActivatable *activatable) { XedTaglistPluginPrivate *priv; - XedWindow *window; - XedPanel *side_panel; - gchar *data_dir; + XedPanel *side_panel; + gchar *data_dir; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); priv = XED_TAGLIST_PLUGIN (activatable)->priv; - window = XED_WINDOW (priv->window); - side_panel = xed_window_get_side_panel (window); + side_panel = xed_window_get_side_panel (priv->window); - data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (activatable)); - priv->taglist_panel = xed_taglist_plugin_panel_new (window, data_dir); - g_free (data_dir); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (activatable)); + priv->taglist_panel = xed_taglist_plugin_panel_new (priv->window, data_dir); + g_free (data_dir); - xed_panel_add_item (side_panel, priv->taglist_panel, _("Tags"), "list-add"); + xed_panel_add_item (side_panel, priv->taglist_panel, _("Tags"), "list-add"); } static void -xed_taglist_plugin_deactivate (PeasActivatable *activatable) +xed_taglist_plugin_deactivate (XedWindowActivatable *activatable) { XedTaglistPluginPrivate *priv; - XedWindow *window; - XedPanel *side_panel; + XedPanel *side_panel; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - priv = XED_TAGLIST_PLUGIN (activatable)->priv; - window = XED_WINDOW (priv->window); - side_panel = xed_window_get_side_panel (window); + priv = XED_TAGLIST_PLUGIN (activatable)->priv; + side_panel = xed_window_get_side_panel (priv->window); - xed_panel_remove_item (side_panel, priv->taglist_panel); + xed_panel_remove_item (side_panel, priv->taglist_panel); } static void -xed_taglist_plugin_update_state (PeasActivatable *activatable) +xed_taglist_plugin_update_state (XedWindowActivatable *activatable) { - XedTaglistPluginPrivate *priv; - XedWindow *window; - XedView *view; + XedTaglistPluginPrivate *priv; + XedView *view; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - priv = XED_TAGLIST_PLUGIN (activatable)->priv; - window = XED_WINDOW (priv->window); - view = xed_window_get_active_view (window); + priv = XED_TAGLIST_PLUGIN (activatable)->priv; + view = xed_window_get_active_view (priv->window); - gtk_widget_set_sensitive (priv->taglist_panel, - (view != NULL) && - gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); + gtk_widget_set_sensitive (priv->taglist_panel, + (view != NULL) && + gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); } static void @@ -168,8 +157,8 @@ xed_taglist_plugin_set_property (GObject *object, switch (prop_id) { - case PROP_OBJECT: - plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + case PROP_WINDOW: + plugin->priv->window = XED_WINDOW (g_value_dup_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -187,7 +176,7 @@ xed_taglist_plugin_get_property (GObject *object, switch (prop_id) { - case PROP_OBJECT: + case PROP_WINDOW: g_value_set_object (value, plugin->priv->window); break; default: @@ -199,16 +188,16 @@ xed_taglist_plugin_get_property (GObject *object, static void xed_taglist_plugin_class_init (XedTaglistPluginClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = xed_taglist_plugin_finalize; + object_class->finalize = xed_taglist_plugin_finalize; object_class->dispose = xed_taglist_plugin_dispose; object_class->set_property = xed_taglist_plugin_set_property; object_class->get_property = xed_taglist_plugin_get_property; - g_object_class_override_property (object_class, PROP_OBJECT, "object"); + g_object_class_override_property (object_class, PROP_WINDOW, "window"); - g_type_class_add_private (object_class, sizeof (XedTaglistPluginPrivate)); + g_type_class_add_private (object_class, sizeof (XedTaglistPluginPrivate)); } static void @@ -218,7 +207,7 @@ xed_taglist_plugin_class_finalize (XedTaglistPluginClass *klass) } static void -peas_activatable_iface_init (PeasActivatableInterface *iface) +xed_window_activatable_iface_init (XedWindowActivatableInterface *iface) { iface->activate = xed_taglist_plugin_activate; iface->deactivate = xed_taglist_plugin_deactivate; @@ -231,6 +220,6 @@ peas_register_types (PeasObjectModule *module) xed_taglist_plugin_register_type (G_TYPE_MODULE (module)); peas_object_module_register_extension_type (module, - PEAS_TYPE_ACTIVATABLE, + XED_TYPE_WINDOW_ACTIVATABLE, XED_TYPE_TAGLIST_PLUGIN); } diff --git a/plugins/taglist/xed-taglist-plugin.h b/plugins/taglist/xed-taglist-plugin.h index aa40462..4a2d035 100644 --- a/plugins/taglist/xed-taglist-plugin.h +++ b/plugins/taglist/xed-taglist-plugin.h @@ -23,8 +23,6 @@ * Modified by the xed Team, 2002-2005. See the AUTHORS file for a * list of people on the xed Team. * See the ChangeLog files for a list of changes. - * - * $Id$ */ #ifndef __XED_TAGLIST_PLUGIN_H__ @@ -40,20 +38,16 @@ G_BEGIN_DECLS /* * Type checking and casting macros */ -#define XED_TYPE_TAGLIST_PLUGIN (xed_taglist_plugin_get_type ()) -#define XED_TAGLIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPlugin)) -#define XED_TAGLIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginClass)) +#define XED_TYPE_TAGLIST_PLUGIN (xed_taglist_plugin_get_type ()) +#define XED_TAGLIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPlugin)) +#define XED_TAGLIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginClass)) #define XED_IS_TAGLIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TAGLIST_PLUGIN)) #define XED_IS_TAGLIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TAGLIST_PLUGIN)) #define XED_TAGLIST_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginClass)) -/* Private structure type */ -typedef struct _XedTaglistPluginPrivate XedTaglistPluginPrivate; - -/* - * Main object structure - */ typedef struct _XedTaglistPlugin XedTaglistPlugin; +typedef struct _XedTaglistPluginPrivate XedTaglistPluginPrivate; +typedef struct _XedTaglistPluginClass XedTaglistPluginClass; struct _XedTaglistPlugin { @@ -63,22 +57,13 @@ struct _XedTaglistPlugin XedTaglistPluginPrivate *priv; }; -/* - * Class definition - */ -typedef struct _XedTaglistPluginClass XedTaglistPluginClass; - struct _XedTaglistPluginClass { PeasExtensionBaseClass parent_class; }; -/* - * Public methods - */ -GType xed_taglist_plugin_get_type (void) G_GNUC_CONST; +GType xed_taglist_plugin_get_type (void) G_GNUC_CONST; -/* All the plugins must implement this function */ G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS From 77ae5a404834889e20859a3ee20f142152377508 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Wed, 11 Jan 2017 23:21:23 -0800 Subject: [PATCH 083/132] trailsave-plugin: Port to WindowActivatable --- plugins/Makefile.am | 6 +- plugins/trailsave/xed-trail-save-plugin.c | 293 +++++++++++----------- plugins/trailsave/xed-trail-save-plugin.h | 30 +-- 3 files changed, 154 insertions(+), 175 deletions(-) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 522da2c..ebe0703 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -6,7 +6,8 @@ DIST_SUBDIRS = \ sort \ spell \ taglist \ - time + time \ + trailsave SUBDIRS = \ changecase \ @@ -16,7 +17,8 @@ SUBDIRS = \ sort \ spell \ taglist \ - time + time \ + trailsave if ENABLE_ENCHANT SUBDIRS += spell diff --git a/plugins/trailsave/xed-trail-save-plugin.c b/plugins/trailsave/xed-trail-save-plugin.c index 86f5914..a6a4dc7 100644 --- a/plugins/trailsave/xed-trail-save-plugin.c +++ b/plugins/trailsave/xed-trail-save-plugin.c @@ -14,220 +14,217 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ */ #ifdef HAVE_CONFIG_H #include #endif -#include - -#include -#include - #include "xed-trail-save-plugin.h" -#define XED_TRAIL_SAVE_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ - XED_TYPE_TRAIL_SAVE_PLUGIN, \ - XedTrailSavePluginPrivate)) +#include +#include +#include -static void peas_activatable_iface_init (PeasActivatableInterface *iface); +#define XED_TRAIL_SAVE_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ + XED_TYPE_TRAIL_SAVE_PLUGIN, \ + XedTrailSavePluginPrivate)) + +static void xed_window_activatable_iface_init (XedWindowActivatableInterface *iface); G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedTrailSavePlugin, xed_trail_save_plugin, PEAS_TYPE_EXTENSION_BASE, 0, - G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, - peas_activatable_iface_init)) + G_IMPLEMENT_INTERFACE_DYNAMIC (XED_TYPE_WINDOW_ACTIVATABLE, + xed_window_activatable_iface_init)) struct _XedTrailSavePluginPrivate { - GtkWidget *window; + XedWindow *window; }; enum { PROP_0, - PROP_OBJECT + PROP_WINDOW }; static void strip_trailing_spaces (GtkTextBuffer *text_buffer) { - gint line_count, line_num; - GtkTextIter line_start, line_end; - gchar *slice; - gchar byte; - gint byte_index; - gint strip_start_index, strip_end_index; - gboolean should_strip; - GtkTextIter strip_start, strip_end; + gint line_count, line_num; + GtkTextIter line_start, line_end; + gchar *slice; + gchar byte; + gint byte_index; + gint strip_start_index, strip_end_index; + gboolean should_strip; + GtkTextIter strip_start, strip_end; - g_assert (text_buffer != NULL); + g_assert (text_buffer != NULL); - line_count = gtk_text_buffer_get_line_count (text_buffer); + line_count = gtk_text_buffer_get_line_count (text_buffer); - for (line_num = 0; line_num < line_count; ++line_num) - { - /* Get line text */ - gtk_text_buffer_get_iter_at_line (text_buffer, &line_start, line_num); + for (line_num = 0; line_num < line_count; ++line_num) + { + /* Get line text */ + gtk_text_buffer_get_iter_at_line (text_buffer, &line_start, line_num); - if (line_num == line_count - 1) - { - gtk_text_buffer_get_end_iter (text_buffer, &line_end); - } - else - { - gtk_text_buffer_get_iter_at_line (text_buffer, &line_end, line_num + 1); - } + if (line_num == line_count - 1) + { + gtk_text_buffer_get_end_iter (text_buffer, &line_end); + } + else + { + gtk_text_buffer_get_iter_at_line (text_buffer, &line_end, line_num + 1); + } - slice = gtk_text_buffer_get_slice (text_buffer, &line_start, &line_end, TRUE); + slice = gtk_text_buffer_get_slice (text_buffer, &line_start, &line_end, TRUE); - if (slice == NULL) - { - continue; - } + if (slice == NULL) + { + continue; + } - /* Find indices of bytes that should be stripped */ - should_strip = FALSE; + /* Find indices of bytes that should be stripped */ + should_strip = FALSE; - for (byte_index = 0; slice [byte_index] != 0; ++byte_index) - { - byte = slice [byte_index]; + for (byte_index = 0; slice [byte_index] != 0; ++byte_index) + { + byte = slice [byte_index]; - if ((byte == ' ') || (byte == '\t')) - { - if (!should_strip) - { - strip_start_index = byte_index; - should_strip = TRUE; - } + if ((byte == ' ') || (byte == '\t')) + { + if (!should_strip) + { + strip_start_index = byte_index; + should_strip = TRUE; + } - strip_end_index = byte_index + 1; - } - else if ((byte == '\r') || (byte == '\n')) - { - break; - } - else - { - should_strip = FALSE; - } - } + strip_end_index = byte_index + 1; + } + else if ((byte == '\r') || (byte == '\n')) + { + break; + } + else + { + should_strip = FALSE; + } + } - g_free (slice); + g_free (slice); - /* Strip trailing spaces */ - if (should_strip) - { - gtk_text_buffer_get_iter_at_line_index (text_buffer, &strip_start, line_num, strip_start_index); - gtk_text_buffer_get_iter_at_line_index (text_buffer, &strip_end, line_num, strip_end_index); - gtk_text_buffer_delete (text_buffer, &strip_start, &strip_end); - } - } + /* Strip trailing spaces */ + if (should_strip) + { + gtk_text_buffer_get_iter_at_line_index (text_buffer, &strip_start, line_num, strip_start_index); + gtk_text_buffer_get_iter_at_line_index (text_buffer, &strip_end, line_num, strip_end_index); + gtk_text_buffer_delete (text_buffer, &strip_start, &strip_end); + } + } } static void -on_save (XedDocument *document, - const gchar *uri, - XedEncoding *encoding, - XedDocumentSaveFlags save_flags, - XedTrailSavePlugin *plugin) +on_save (XedDocument *document, + const gchar *uri, + XedEncoding *encoding, + XedDocumentSaveFlags save_flags, + XedTrailSavePlugin *plugin) { - GtkTextBuffer *text_buffer = GTK_TEXT_BUFFER (document); + GtkTextBuffer *text_buffer = GTK_TEXT_BUFFER (document); - strip_trailing_spaces (text_buffer); + strip_trailing_spaces (text_buffer); } static void -on_tab_added (XedWindow *window, - XedTab *tab, - XedTrailSavePlugin *plugin) +on_tab_added (XedWindow *window, + XedTab *tab, + XedTrailSavePlugin *plugin) { - XedDocument *document; + XedDocument *document; - document = xed_tab_get_document (tab); - g_signal_connect (document, "save", G_CALLBACK (on_save), plugin); + document = xed_tab_get_document (tab); + g_signal_connect (document, "save", + G_CALLBACK (on_save), plugin); } static void -on_tab_removed (XedWindow *window, - XedTab *tab, - XedTrailSavePlugin *plugin) +on_tab_removed (XedWindow *window, + XedTab *tab, + XedTrailSavePlugin *plugin) { - XedDocument *document; + XedDocument *document; - document = xed_tab_get_document (tab); - g_signal_handlers_disconnect_by_data (document, plugin); + document = xed_tab_get_document (tab); + g_signal_handlers_disconnect_by_data (document, plugin); } static void -xed_trail_save_plugin_activate (PeasActivatable *activatable) +xed_trail_save_plugin_activate (XedWindowActivatable *activatable) { - XedTrailSavePlugin *plugin; - XedWindow *window; - GList *documents; - GList *documents_iter; - XedDocument *document; + XedTrailSavePluginPrivate *priv; + GList *documents; + GList *documents_iter; + XedDocument *document; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - plugin = XED_TRAIL_SAVE_PLUGIN (activatable); - window = XED_WINDOW (plugin->priv->window); + priv = XED_TRAIL_SAVE_PLUGIN (activatable)->priv; - g_signal_connect (window, "tab_added", G_CALLBACK (on_tab_added), plugin); - g_signal_connect (window, "tab_removed", G_CALLBACK (on_tab_removed), plugin); + g_signal_connect (priv->window, "tab_added", + G_CALLBACK (on_tab_added), XED_TRAIL_SAVE_PLUGIN (activatable)); + g_signal_connect (priv->window, "tab_removed", + G_CALLBACK (on_tab_removed), XED_TRAIL_SAVE_PLUGIN (activatable)); - documents = xed_window_get_documents (window); + documents = xed_window_get_documents (priv->window); - for (documents_iter = documents; - documents_iter && documents_iter->data; - documents_iter = documents_iter->next) - { - document = (XedDocument *) documents_iter->data; - g_signal_connect (document, "save", G_CALLBACK (on_save), plugin); - } + for (documents_iter = documents; + documents_iter && documents_iter->data; + documents_iter = documents_iter->next) + { + document = (XedDocument *) documents_iter->data; + g_signal_connect (document, "save", + G_CALLBACK (on_save), XED_TRAIL_SAVE_PLUGIN (activatable)); + } - g_list_free (documents); + g_list_free (documents); } static void -xed_trail_save_plugin_deactivate (PeasActivatable *activatable) +xed_trail_save_plugin_deactivate (XedWindowActivatable *activatable) { - XedTrailSavePlugin *plugin; - XedWindow *window; - GList *documents; - GList *documents_iter; - XedDocument *document; + XedTrailSavePluginPrivate *priv; + GList *documents; + GList *documents_iter; + XedDocument *document; - xed_debug (DEBUG_PLUGINS); + xed_debug (DEBUG_PLUGINS); - plugin = XED_TRAIL_SAVE_PLUGIN (activatable); - window = XED_WINDOW (plugin->priv->window); + priv = XED_TRAIL_SAVE_PLUGIN (activatable)->priv; - g_signal_handlers_disconnect_by_data (window, plugin); + g_signal_handlers_disconnect_by_data (priv->window, XED_TRAIL_SAVE_PLUGIN (activatable)); - documents = xed_window_get_documents (window); + documents = xed_window_get_documents (priv->window); - for (documents_iter = documents; - documents_iter && documents_iter->data; - documents_iter = documents_iter->next) - { - document = (XedDocument *) documents_iter->data; - g_signal_handlers_disconnect_by_data (document, plugin); - } + for (documents_iter = documents; + documents_iter && documents_iter->data; + documents_iter = documents_iter->next) + { + document = (XedDocument *) documents_iter->data; + g_signal_handlers_disconnect_by_data (document, XED_TRAIL_SAVE_PLUGIN (activatable)); + } - g_list_free (documents); + g_list_free (documents); } static void xed_trail_save_plugin_init (XedTrailSavePlugin *plugin) { - xed_debug_message (DEBUG_PLUGINS, "XedTrailSavePlugin initializing"); + xed_debug_message (DEBUG_PLUGINS, "XedTrailSavePlugin initializing"); - plugin->priv = XED_TRAIL_SAVE_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin, XED_TYPE_TRAIL_SAVE_PLUGIN, XedTrailSavePluginPrivate); } static void @@ -237,11 +234,7 @@ xed_trail_save_plugin_dispose (GObject *object) xed_debug_message (DEBUG_PLUGINS, "XedTrailSavePlugin disposing"); - if (plugin->priv->window != NULL) - { - g_object_unref (plugin->priv->window); - plugin->priv->window = NULL; - } + g_clear_object (&plugin->priv->window); G_OBJECT_CLASS (xed_trail_save_plugin_parent_class)->dispose (object); } @@ -252,12 +245,12 @@ xed_trail_save_plugin_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - XedTrailSavePlugin *plugin = XED_TRAIL_SAVE_PLUGIN (object); + XedTrailSavePlugin *plugin = XED_TRAIL_SAVE_PLUGIN (object); - switch (prop_id) + switch (prop_id) { - case PROP_OBJECT: - plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + case PROP_WINDOW: + plugin->priv->window = XED_WINDOW (g_value_dup_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -275,7 +268,7 @@ xed_trail_save_plugin_get_property (GObject *object, switch (prop_id) { - case PROP_OBJECT: + case PROP_WINDOW: g_value_set_object (value, plugin->priv->window); break; default: @@ -287,13 +280,13 @@ xed_trail_save_plugin_get_property (GObject *object, static void xed_trail_save_plugin_class_init (XedTrailSavePluginClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->dispose = xed_trail_save_plugin_dispose; + object_class->dispose = xed_trail_save_plugin_dispose; object_class->set_property = xed_trail_save_plugin_set_property; object_class->get_property = xed_trail_save_plugin_get_property; - g_object_class_override_property (object_class, PROP_OBJECT, "object"); + g_object_class_override_property (object_class, PROP_WINDOW, "window"); g_type_class_add_private (object_class, sizeof (XedTrailSavePluginPrivate)); } @@ -305,7 +298,7 @@ xed_trail_save_plugin_class_finalize (XedTrailSavePluginClass *klass) } static void -peas_activatable_iface_init (PeasActivatableInterface *iface) +xed_window_activatable_iface_init (XedWindowActivatableInterface *iface) { iface->activate = xed_trail_save_plugin_activate; iface->deactivate = xed_trail_save_plugin_deactivate; @@ -316,7 +309,7 @@ peas_register_types (PeasObjectModule *module) { xed_trail_save_plugin_register_type (G_TYPE_MODULE (module)); - peas_object_module_register_extension_type (module, - PEAS_TYPE_ACTIVATABLE, + peas_object_module_register_extension_type (module, + XED_TYPE_WINDOW_ACTIVATABLE, XED_TYPE_TRAIL_SAVE_PLUGIN); } diff --git a/plugins/trailsave/xed-trail-save-plugin.h b/plugins/trailsave/xed-trail-save-plugin.h index 8454fac..ce66d8f 100644 --- a/plugins/trailsave/xed-trail-save-plugin.h +++ b/plugins/trailsave/xed-trail-save-plugin.h @@ -28,23 +28,16 @@ G_BEGIN_DECLS -/* - * Type checking and casting macros - */ -#define XED_TYPE_TRAIL_SAVE_PLUGIN (xed_trail_save_plugin_get_type ()) -#define XED_TRAIL_SAVE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TRAIL_SAVE_PLUGIN, XedTrailSavePlugin)) -#define XED_TRAIL_SAVE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TRAIL_SAVE_PLUGIN, XedTrailSavePluginClass)) -#define XED_IS_TRAIL_SAVE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TRAIL_SAVE_PLUGIN)) +#define XED_TYPE_TRAIL_SAVE_PLUGIN (xed_trail_save_plugin_get_type ()) +#define XED_TRAIL_SAVE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TRAIL_SAVE_PLUGIN, XedTrailSavePlugin)) +#define XED_TRAIL_SAVE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TRAIL_SAVE_PLUGIN, XedTrailSavePluginClass)) +#define XED_IS_TRAIL_SAVE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TRAIL_SAVE_PLUGIN)) #define XED_IS_TRAIL_SAVE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TRAIL_SAVE_PLUGIN)) #define XED_TRAIL_SAVE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_TRAIL_SAVE_PLUGIN, XedTrailSavePluginClass)) -/* Private structure type */ -typedef struct _XedTrailSavePluginPrivate XedTrailSavePluginPrivate; - -/* - * Main object structure - */ typedef struct _XedTrailSavePlugin XedTrailSavePlugin; +typedef struct _XedTrailSavePluginPrivate XedTrailSavePluginPrivate; +typedef struct _XedTrailSavePluginClass XedTrailSavePluginClass; struct _XedTrailSavePlugin { @@ -54,22 +47,13 @@ struct _XedTrailSavePlugin XedTrailSavePluginPrivate *priv; }; -/* - * Class definition - */ -typedef struct _XedTrailSavePluginClass XedTrailSavePluginClass; - struct _XedTrailSavePluginClass { PeasExtensionBaseClass parent_class; }; -/* - * Public methods - */ -GType xed_trail_save_plugin_get_type (void) G_GNUC_CONST; +GType xed_trail_save_plugin_get_type (void) G_GNUC_CONST; -/* All the plugins must implement this function */ G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS From c03a0a3e7d364cbb29ff49af7217de71c38490bc Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Wed, 11 Jan 2017 23:47:49 -0800 Subject: [PATCH 084/132] time-plugin: Clean up a bit from libpeas port --- plugins/time/xed-time-plugin.c | 40 +--------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/plugins/time/xed-time-plugin.c b/plugins/time/xed-time-plugin.c index 604e6b9..eb840a6 100644 --- a/plugins/time/xed-time-plugin.c +++ b/plugins/time/xed-time-plugin.c @@ -307,20 +307,6 @@ get_selected_format (XedTimePlugin *plugin) return sel_format ? sel_format : g_strdup (formats [0]); } -// static void -// set_selected_format (XedTimePlugin *plugin, -// const gchar *format) -// { -// g_return_if_fail (format != NULL); - -// if (!g_settings_is_writable (plugin->priv->settings, SELECTED_FORMAT_KEY)) -// { -// return; -// } - -// g_settings_set_string (settings, SELECTED_FORMAT_KEY, format); -// } - /* the custom format in the entry */ static gchar * get_custom_format (XedTimePlugin *plugin) @@ -332,20 +318,6 @@ get_custom_format (XedTimePlugin *plugin) return format ? format : g_strdup (DEFAULT_CUSTOM_FORMAT); } -// static void -// set_custom_format (XedTimePlugin *plugin, -// const gchar *format) -// { -// g_return_if_fail (format != NULL); - -// if (!g_settings_is_writable (plugin->priv->settings, CUSTOM_FORMAT_KEY)) -// { -// return; -// } - -// g_settings_set_string (plugin->priv->settings, CUSTOM_FORMAT_KEY, format); -// } - static gchar * get_time (const gchar* format) { @@ -663,16 +635,6 @@ get_format_from_list (GtkWidget *listview) g_return_val_if_reached (0); } -// static void -// configure_dialog_selection_changed (GtkTreeSelection *selection, -// TimeConfigureDialog *dialog) -// { -// gint sel_format; - -// sel_format = get_format_from_list (dialog->list); -// set_selected_format (dialog->settings, formats[sel_format]); -// } - static void on_configure_widget_selection_changed (GtkTreeSelection *selection, TimeConfigureWidget *conf_widget) @@ -866,7 +828,7 @@ get_choose_format_dialog (GtkWindow *parent, err_dialog = gtk_dialog_new_with_buttons (NULL, parent, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + _("_OK"), GTK_RESPONSE_ACCEPT, NULL); if (wg != NULL) From c65c6f2a3eb015472584c14df3293515666fa287 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Thu, 12 Jan 2017 23:59:23 -0800 Subject: [PATCH 085/132] spell-plugin: Clean up a few things Clean up a couple files, remove deprecated widgets from the UI files and clean up the styling of a couple dialogs a bit --- plugins/spell/languages-dialog.ui | 116 +- plugins/spell/spell-checker.ui | 361 ++--- plugins/spell/xed-automatic-spell-checker.c | 1376 +++++++++---------- plugins/spell/xed-spell-language-dialog.c | 356 +++-- plugins/spell/xed-spell-language-dialog.h | 30 +- plugins/spell/xed-spell-plugin.c | 5 +- plugins/spell/xed-spell-setup-dialog.ui | 271 ++-- 7 files changed, 1220 insertions(+), 1295 deletions(-) diff --git a/plugins/spell/languages-dialog.ui b/plugins/spell/languages-dialog.ui index 1bc8603..28ec4fb 100644 --- a/plugins/spell/languages-dialog.ui +++ b/plugins/spell/languages-dialog.ui @@ -1,136 +1,132 @@ - + + + + False 5 Set language - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE True - True True - True - False - False - GDK_WINDOW_TYPE_HINT_DIALOG - GDK_GRAVITY_NORTH_WEST - True - False + dialog - + True - False + False 2 - + True - GTK_BUTTONBOX_END + False + end - True - True - True gtk-help + True + True + True + False True - GTK_RELIEF_NORMAL - True + + True + True + 0 + - True - True - True gtk-cancel + True + True + True + False True - GTK_RELIEF_NORMAL - True + + True + True + 1 + - True - True - True gtk-ok + True + True + True + False True - GTK_RELIEF_NORMAL - True + + True + True + 2 + - 0 False True - GTK_PACK_END + end + 0 - - 5 + True - False + False + True + True + 5 + vertical 11 True + False Select the _language of the current document. True - False - GTK_JUSTIFY_LEFT True - False - 0 - 0.5 - 0 - 0 languages_treeview - PANGO_ELLIPSIZE_NONE - -1 - False - 0 + 0 - 0 False False + 0 + 180 True True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - GTK_SHADOW_ETCHED_IN - GTK_CORNER_TOP_LEFT + etched-in 180 True True False - False - False - True - False - False - False + + + - 0 True True + 1 - 0 - True + False True + 0 diff --git a/plugins/spell/spell-checker.ui b/plugins/spell/spell-checker.ui index ea84290..f5f8a30 100644 --- a/plugins/spell/spell-checker.ui +++ b/plugins/spell/spell-checker.ui @@ -1,479 +1,366 @@ - - + + - - gtk-spell-check - 4 - - - gtk-add - 4 - - - gtk-go-down - 4 - - - gtk-convert - 4 - - - gtk-goto-bottom - 4 - - - gtk-convert - 4 - + - True - Check spelling - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False + False False - False + True + dialog + True + Check spelling - - 12 + True - False + False + 12 + vertical 6 - + True - 2 - 2 - False + False + True 6 12 True + False Misspelled word: - False - False - GTK_JUSTIFY_CENTER - False - False 0 - 0.5 - 0 - 0 0 - 1 0 - 1 - fill - True + False word - False True - GTK_JUSTIFY_CENTER - False - False + center 0 - 0.5 - 0 - 0 - - - 1 - 2 0 - 1 - fill - - + True + False Change _to: True - False - GTK_JUSTIFY_CENTER - False - False 0 - 0.5 - 0 - 0 - word_entry 0 - 1 1 - 2 - fill - - + True - False + False + True 12 True True - True - True - 0 - - True - False + True - 0 - True + False True + 0 + Check _Word True True - GTK_RELIEF_NORMAL - check_word_image - Check _Word + True True - 0 False - False + True + 1 1 - 2 1 - 2 - fill - 0 False True + 0 - + True - 3 - 2 - False + False 6 12 - + True + False _Suggestions: True - False - GTK_JUSTIFY_CENTER - False - False 0 - 0.5 - 0 - 0 - suggestions_list 0 - 1 0 - 1 - fill - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - GTK_SHADOW_ETCHED_IN - GTK_CORNER_TOP_LEFT + True + True + True + in - 200 True True False - False - False - True + + + 0 - 1 1 - 2 - + True - True + False + 6 + vertical 12 - + True - 2 - 2 - True + False 12 12 - True - True - GTK_RELIEF_NORMAL - ignore_image _Ignore - True - - - 0 - 1 - 0 - 1 - expand - - - - True True - GTK_RELIEF_NORMAL - change_image - Cha_nge + True True 0 - 1 - 1 - 2 - expand + 0 + Ignore _All True True - GTK_RELIEF_NORMAL - ignore_all_image - Ignore _All + True True 1 - 2 0 - 1 - expand + + + + + Cha_nge + True + True + True + True + + + 0 + 1 + Change A_ll True True - GTK_RELIEF_NORMAL - change_all_image - Change A_ll + True True 1 - 2 1 - 2 - expand - 0 - True + False True + 0 - + True - False + False + vertical 11 - + True + False User dictionary: - False True - GTK_JUSTIFY_LEFT - False - False - 7.45058e-09 - 0.5 - 0 - 0 + 0 - 0 False True + 0 - + True - True + False 6 + True + Add w_ord True True - GTK_RELIEF_NORMAL - add_word_image - Add w_ord + True True - 0 - True + False True + 0 - 0 False - False + True + 2 - 0 - True - False + False + True + 1 1 - 2 1 - 2 - + True - False + False 12 - + True + False Language: - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - 0 False - False + True + 0 True + False Language - False True - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - - - - 0 False - False + True + 1 0 - 1 2 - 3 - fill - fill - + True - GTK_BUTTONBOX_END - 0 + False + True + end + _Close True - True True - gtk-close - True - GTK_RELIEF_NORMAL + True + end + True + + + True + True + 0 + 1 - 2 - 2 - 3 - fill - fill + 3 + + + + + + + + + - 0 True True + 1 diff --git a/plugins/spell/xed-automatic-spell-checker.c b/plugins/spell/xed-automatic-spell-checker.c index 35feec0..1202920 100644 --- a/plugins/spell/xed-automatic-spell-checker.c +++ b/plugins/spell/xed-automatic-spell-checker.c @@ -3,7 +3,7 @@ * xed-automatic-spell-checker.c * This file is part of xed * - * Copyright (C) 2002 Paolo Maggi + * Copyright (C) 2002 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,14 +17,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ /* - * Modified by the xed Team, 2002. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2002. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. */ /* This is a modified version of gtkspell 2.0.5 (gtkspell.sf.net) */ @@ -43,18 +43,19 @@ #include "xed-automatic-spell-checker.h" #include "xed-spell-utils.h" -struct _XedAutomaticSpellChecker { - XedDocument *doc; - GSList *views; - - GtkTextMark *mark_insert_start; - GtkTextMark *mark_insert_end; - gboolean deferred_check; +struct _XedAutomaticSpellChecker +{ + XedDocument *doc; + GSList *views; - GtkTextTag *tag_highlight; - GtkTextMark *mark_click; + GtkTextMark *mark_insert_start; + GtkTextMark *mark_insert_end; + gboolean deferred_check; - XedSpellChecker *spell_checker; + GtkTextTag *tag_highlight; + GtkTextMark *mark_click; + + XedSpellChecker *spell_checker; }; static GQuark automatic_spell_checker_id = 0; @@ -63,164 +64,164 @@ static GQuark suggestion_id = 0; static void xed_automatic_spell_checker_free_internal (XedAutomaticSpellChecker *spell); static void -view_destroy (XedView *view, XedAutomaticSpellChecker *spell) +view_destroy (XedView *view, + XedAutomaticSpellChecker *spell) { - xed_automatic_spell_checker_detach_view (spell, view); + xed_automatic_spell_checker_detach_view (spell, view); } static void -check_word (XedAutomaticSpellChecker *spell, GtkTextIter *start, GtkTextIter *end) +check_word (XedAutomaticSpellChecker *spell, + GtkTextIter *start, + GtkTextIter *end) { - gchar *word; + gchar *word; - word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->doc), start, end, FALSE); + word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->doc), start, end, FALSE); - /* - g_print ("Check word: %s [%d - %d]\n", word, gtk_text_iter_get_offset (start), - gtk_text_iter_get_offset (end)); - */ + /* + g_print ("Check word: %s [%d - %d]\n", word, gtk_text_iter_get_offset (start), + gtk_text_iter_get_offset (end)); + */ - if (!xed_spell_checker_check_word (spell->spell_checker, word, -1)) - { - /* - g_print ("Apply tag: [%d - %d]\n", gtk_text_iter_get_offset (start), - gtk_text_iter_get_offset (end)); - */ - gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (spell->doc), - spell->tag_highlight, - start, - end); - } - - g_free (word); + if (!xed_spell_checker_check_word (spell->spell_checker, word, -1)) + { + /* + g_print ("Apply tag: [%d - %d]\n", gtk_text_iter_get_offset (start), + gtk_text_iter_get_offset (end)); + */ + gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (spell->doc), spell->tag_highlight, start, end); + } + + g_free (word); } static void -check_range (XedAutomaticSpellChecker *spell, - GtkTextIter start, - GtkTextIter end, - gboolean force_all) +check_range (XedAutomaticSpellChecker *spell, + GtkTextIter start, + GtkTextIter end, + gboolean force_all) { - /* we need to "split" on word boundaries. - * luckily, Pango knows what "words" are - * so we don't have to figure it out. */ + /* we need to "split" on word boundaries. + * luckily, Pango knows what "words" are + * so we don't have to figure it out. */ - GtkTextIter wstart; - GtkTextIter wend; - GtkTextIter cursor; - GtkTextIter precursor; - gboolean highlight; + GtkTextIter wstart; + GtkTextIter wend; + GtkTextIter cursor; + GtkTextIter precursor; + gboolean highlight; - /* - g_print ("Check range: [%d - %d]\n", gtk_text_iter_get_offset (&start), - gtk_text_iter_get_offset (&end)); - */ + /* + g_print ("Check range: [%d - %d]\n", gtk_text_iter_get_offset (&start), + gtk_text_iter_get_offset (&end)); + */ - if (gtk_text_iter_inside_word (&end)) - gtk_text_iter_forward_word_end (&end); - - if (!gtk_text_iter_starts_word (&start)) - { - if (gtk_text_iter_inside_word (&start) || - gtk_text_iter_ends_word (&start)) - { - gtk_text_iter_backward_word_start (&start); - } - else - { - /* if we're neither at the beginning nor inside a word, - * me must be in some spaces. - * skip forward to the beginning of the next word. */ - - if (gtk_text_iter_forward_word_end (&start)) - gtk_text_iter_backward_word_start (&start); - } - } + if (gtk_text_iter_inside_word (&end)) + { + gtk_text_iter_forward_word_end (&end); + } - gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (spell->doc), - &cursor, - gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (spell->doc))); - - precursor = cursor; - gtk_text_iter_backward_char (&precursor); - - highlight = gtk_text_iter_has_tag (&cursor, spell->tag_highlight) || - gtk_text_iter_has_tag (&precursor, spell->tag_highlight); - - gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (spell->doc), - spell->tag_highlight, - &start, - &end); + if (!gtk_text_iter_starts_word (&start)) + { + if (gtk_text_iter_inside_word (&start) || gtk_text_iter_ends_word (&start)) + { + gtk_text_iter_backward_word_start (&start); + } + else + { + /* if we're neither at the beginning nor inside a word, + * me must be in some spaces. + * skip forward to the beginning of the next word. */ - /* Fix a corner case when replacement occurs at beginning of buffer: - * An iter at offset 0 seems to always be inside a word, - * even if it's not. Possibly a pango bug. - */ - if (gtk_text_iter_get_offset (&start) == 0) - { - gtk_text_iter_forward_word_end(&start); - gtk_text_iter_backward_word_start(&start); - } + if (gtk_text_iter_forward_word_end (&start)) + { + gtk_text_iter_backward_word_start (&start); + } + } + } - wstart = start; - - while (xed_spell_utils_skip_no_spell_check (&wstart, &end) && - gtk_text_iter_compare (&wstart, &end) < 0) - { - gboolean inword; + gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (spell->doc), + &cursor, + gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (spell->doc))); - /* move wend to the end of the current word. */ - wend = wstart; - - gtk_text_iter_forward_word_end (&wend); + precursor = cursor; + gtk_text_iter_backward_char (&precursor); - inword = (gtk_text_iter_compare (&wstart, &cursor) < 0) && - (gtk_text_iter_compare (&cursor, &wend) <= 0); - - if (inword && !force_all) - { - /* this word is being actively edited, - * only check if it's already highligted, - * otherwise defer this check until later. */ - if (highlight) - check_word (spell, &wstart, &wend); - else - spell->deferred_check = TRUE; - } - else - { - check_word (spell, &wstart, &wend); - spell->deferred_check = FALSE; - } + highlight = gtk_text_iter_has_tag (&cursor, spell->tag_highlight) || + gtk_text_iter_has_tag (&precursor, spell->tag_highlight); - /* now move wend to the beginning of the next word, */ - gtk_text_iter_forward_word_end (&wend); - gtk_text_iter_backward_word_start (&wend); - - /* make sure we've actually advanced - * (we don't advance in some corner cases), */ - if (gtk_text_iter_equal (&wstart, &wend)) - break; /* we're done in these cases.. */ + gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (spell->doc), spell->tag_highlight, &start, &end); - /* and then pick this as the new next word beginning. */ - wstart = wend; - } + /* Fix a corner case when replacement occurs at beginning of buffer: + * An iter at offset 0 seems to always be inside a word, + * even if it's not. Possibly a pango bug. + */ + if (gtk_text_iter_get_offset (&start) == 0) + { + gtk_text_iter_forward_word_end(&start); + gtk_text_iter_backward_word_start(&start); + } + + wstart = start; + + while (xed_spell_utils_skip_no_spell_check (&wstart, &end) && gtk_text_iter_compare (&wstart, &end) < 0) + { + gboolean inword; + + /* move wend to the end of the current word. */ + wend = wstart; + + gtk_text_iter_forward_word_end (&wend); + + inword = (gtk_text_iter_compare (&wstart, &cursor) < 0) && (gtk_text_iter_compare (&cursor, &wend) <= 0); + + if (inword && !force_all) + { + /* this word is being actively edited, + * only check if it's already highligted, + * otherwise defer this check until later. */ + if (highlight) + { + check_word (spell, &wstart, &wend); + } + else + { + spell->deferred_check = TRUE; + } + } + else + { + check_word (spell, &wstart, &wend); + spell->deferred_check = FALSE; + } + + /* now move wend to the beginning of the next word, */ + gtk_text_iter_forward_word_end (&wend); + gtk_text_iter_backward_word_start (&wend); + + /* make sure we've actually advanced + * (we don't advance in some corner cases), */ + if (gtk_text_iter_equal (&wstart, &wend)) + { + break; /* we're done in these cases.. */ + } + + /* and then pick this as the new next word beginning. */ + wstart = wend; + } } static void -check_deferred_range (XedAutomaticSpellChecker *spell, - gboolean force_all) +check_deferred_range (XedAutomaticSpellChecker *spell, + gboolean force_all) { - GtkTextIter start, end; + GtkTextIter start, end; - gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (spell->doc), - &start, - spell->mark_insert_start); - gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (spell->doc), - &end, - spell->mark_insert_end); + gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (spell->doc), &start, spell->mark_insert_start); + gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (spell->doc), &end, spell->mark_insert_end); - check_range (spell, start, end, force_all); + check_range (spell, start, end, force_all); } /* insertion works like this: @@ -231,24 +232,30 @@ check_deferred_range (XedAutomaticSpellChecker *spell, * this may be overkill for the common case (inserting one character). */ static void -insert_text_before (GtkTextBuffer *buffer, GtkTextIter *iter, - gchar *text, gint len, XedAutomaticSpellChecker *spell) +insert_text_before (GtkTextBuffer *buffer, + GtkTextIter *iter, + gchar *text, + gint len, + XedAutomaticSpellChecker *spell) { - gtk_text_buffer_move_mark (buffer, spell->mark_insert_start, iter); + gtk_text_buffer_move_mark (buffer, spell->mark_insert_start, iter); } static void -insert_text_after (GtkTextBuffer *buffer, GtkTextIter *iter, - gchar *text, gint len, XedAutomaticSpellChecker *spell) +insert_text_after (GtkTextBuffer *buffer, + GtkTextIter *iter, + gchar *text, + gint len, + XedAutomaticSpellChecker *spell) { - GtkTextIter start; + GtkTextIter start; - /* we need to check a range of text. */ - gtk_text_buffer_get_iter_at_mark (buffer, &start, spell->mark_insert_start); - - check_range (spell, start, *iter, FALSE); + /* we need to check a range of text. */ + gtk_text_buffer_get_iter_at_mark (buffer, &start, spell->mark_insert_start); - gtk_text_buffer_move_mark (buffer, spell->mark_insert_end, iter); + check_range (spell, start, *iter, FALSE); + + gtk_text_buffer_move_mark (buffer, spell->mark_insert_end, iter); } /* deleting is more simple: we're given the range of deleted text. @@ -259,757 +266,702 @@ insert_text_after (GtkTextBuffer *buffer, GtkTextIter *iter, */ static void -delete_range_after (GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end, - XedAutomaticSpellChecker *spell) +delete_range_after (GtkTextBuffer *buffer, + GtkTextIter *start, + GtkTextIter *end, + XedAutomaticSpellChecker *spell) { - check_range (spell, *start, *end, FALSE); + check_range (spell, *start, *end, FALSE); } static void -mark_set (GtkTextBuffer *buffer, - GtkTextIter *iter, - GtkTextMark *mark, - XedAutomaticSpellChecker *spell) +mark_set (GtkTextBuffer *buffer, + GtkTextIter *iter, + GtkTextMark *mark, + XedAutomaticSpellChecker *spell) { - /* if the cursor has moved and there is a deferred check so handle it now */ - if ((mark == gtk_text_buffer_get_insert (buffer)) && spell->deferred_check) - check_deferred_range (spell, FALSE); + /* if the cursor has moved and there is a deferred check so handle it now */ + if ((mark == gtk_text_buffer_get_insert (buffer)) && spell->deferred_check) + { + check_deferred_range (spell, FALSE); + } } static void -get_word_extents_from_mark (GtkTextBuffer *buffer, - GtkTextIter *start, - GtkTextIter *end, - GtkTextMark *mark) +get_word_extents_from_mark (GtkTextBuffer *buffer, + GtkTextIter *start, + GtkTextIter *end, + GtkTextMark *mark) { - gtk_text_buffer_get_iter_at_mark(buffer, start, mark); - - if (!gtk_text_iter_starts_word (start)) - gtk_text_iter_backward_word_start (start); - - *end = *start; - - if (gtk_text_iter_inside_word (end)) - gtk_text_iter_forward_word_end (end); + gtk_text_buffer_get_iter_at_mark(buffer, start, mark); + + if (!gtk_text_iter_starts_word (start)) + { + gtk_text_iter_backward_word_start (start); + } + + *end = *start; + + if (gtk_text_iter_inside_word (end)) + { + gtk_text_iter_forward_word_end (end); + } } static void -remove_tag_to_word (XedAutomaticSpellChecker *spell, const gchar *word) +remove_tag_to_word (XedAutomaticSpellChecker *spell, + const gchar *word) { - GtkTextIter iter; - GtkTextIter match_start, match_end; + GtkTextIter iter; + GtkTextIter match_start, match_end; - gboolean found; + gboolean found; - gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (spell->doc), &iter, 0); - - found = TRUE; + gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (spell->doc), &iter, 0); - while (found) - { - found = gtk_text_iter_forward_search (&iter, - word, - GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY, - &match_start, - &match_end, - NULL); + found = TRUE; - if (found) - { - if (gtk_text_iter_starts_word (&match_start) && - gtk_text_iter_ends_word (&match_end)) - { - gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (spell->doc), - spell->tag_highlight, - &match_start, - &match_end); - } + while (found) + { + found = gtk_text_iter_forward_search (&iter, + word, + GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY, + &match_start, + &match_end, + NULL); - iter = match_end; - } - } + if (found) + { + if (gtk_text_iter_starts_word (&match_start) && gtk_text_iter_ends_word (&match_end)) + { + gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (spell->doc), + spell->tag_highlight, + &match_start, + &match_end); + } + + iter = match_end; + } + } } static void -add_to_dictionary (GtkWidget *menuitem, XedAutomaticSpellChecker *spell) +add_to_dictionary (GtkWidget *menuitem, + XedAutomaticSpellChecker *spell) { - gchar *word; - - GtkTextIter start, end; - - get_word_extents_from_mark (GTK_TEXT_BUFFER (spell->doc), &start, &end, spell->mark_click); + gchar *word; - word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->doc), - &start, - &end, - FALSE); - - xed_spell_checker_add_word_to_personal (spell->spell_checker, word, -1); + GtkTextIter start, end; - g_free (word); + get_word_extents_from_mark (GTK_TEXT_BUFFER (spell->doc), &start, &end, spell->mark_click); + + word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->doc), &start, &end, FALSE); + + xed_spell_checker_add_word_to_personal (spell->spell_checker, word, -1); + + g_free (word); } static void -ignore_all (GtkWidget *menuitem, XedAutomaticSpellChecker *spell) +ignore_all (GtkWidget *menuitem, + XedAutomaticSpellChecker *spell) { - gchar *word; - - GtkTextIter start, end; - - get_word_extents_from_mark (GTK_TEXT_BUFFER (spell->doc), &start, &end, spell->mark_click); + gchar *word; - word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->doc), - &start, - &end, - FALSE); - - xed_spell_checker_add_word_to_session (spell->spell_checker, word, -1); + GtkTextIter start, end; - g_free (word); + get_word_extents_from_mark (GTK_TEXT_BUFFER (spell->doc), &start, &end, spell->mark_click); + + word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->doc), &start, &end, FALSE); + + xed_spell_checker_add_word_to_session (spell->spell_checker, word, -1); + + g_free (word); } static void -replace_word (GtkWidget *menuitem, XedAutomaticSpellChecker *spell) +replace_word (GtkWidget *menuitem, + XedAutomaticSpellChecker *spell) { - gchar *oldword; - const gchar *newword; - - GtkTextIter start, end; + gchar *oldword; + const gchar *newword; - get_word_extents_from_mark (GTK_TEXT_BUFFER (spell->doc), &start, &end, spell->mark_click); + GtkTextIter start, end; - oldword = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->doc), &start, &end, FALSE); - - newword = g_object_get_qdata (G_OBJECT (menuitem), suggestion_id); - g_return_if_fail (newword != NULL); + get_word_extents_from_mark (GTK_TEXT_BUFFER (spell->doc), &start, &end, spell->mark_click); - gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (spell->doc)); + oldword = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->doc), &start, &end, FALSE); - gtk_text_buffer_delete (GTK_TEXT_BUFFER (spell->doc), &start, &end); - gtk_text_buffer_insert (GTK_TEXT_BUFFER (spell->doc), &start, newword, -1); + newword = g_object_get_qdata (G_OBJECT (menuitem), suggestion_id); + g_return_if_fail (newword != NULL); - gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (spell->doc)); + gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (spell->doc)); - xed_spell_checker_set_correction (spell->spell_checker, - oldword, strlen (oldword), - newword, strlen (newword)); + gtk_text_buffer_delete (GTK_TEXT_BUFFER (spell->doc), &start, &end); + gtk_text_buffer_insert (GTK_TEXT_BUFFER (spell->doc), &start, newword, -1); - g_free (oldword); + gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (spell->doc)); + + xed_spell_checker_set_correction (spell->spell_checker, + oldword, strlen (oldword), + newword, strlen (newword)); + + g_free (oldword); } static GtkWidget * -build_suggestion_menu (XedAutomaticSpellChecker *spell, const gchar *word) +build_suggestion_menu (XedAutomaticSpellChecker *spell, + const gchar *word) { - GtkWidget *topmenu, *menu; - GtkWidget *mi; - GSList *suggestions; - GSList *list; - gchar *label_text; - - topmenu = menu = gtk_menu_new(); + GtkWidget *topmenu, *menu; + GtkWidget *mi; + GSList *suggestions; + GSList *list; + gchar *label_text; - suggestions = xed_spell_checker_get_suggestions (spell->spell_checker, word, -1); + topmenu = menu = gtk_menu_new(); - list = suggestions; + suggestions = xed_spell_checker_get_suggestions (spell->spell_checker, word, -1); - if (suggestions == NULL) - { - /* no suggestions. put something in the menu anyway... */ - GtkWidget *label; - /* Translators: Displayed in the "Check Spelling" dialog if there are no suggestions for the current misspelled word */ - label = gtk_label_new (_("(no suggested words)")); - - mi = gtk_menu_item_new (); - gtk_widget_set_sensitive (mi, FALSE); - gtk_container_add (GTK_CONTAINER(mi), label); - gtk_widget_show_all (mi); - gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), mi); - } - else - { - gint count = 0; - - /* build a set of menus with suggestions. */ - while (suggestions != NULL) - { - GtkWidget *label; + list = suggestions; - if (count == 10) - { - /* Separator */ - mi = gtk_menu_item_new (); - gtk_widget_show (mi); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); - - mi = gtk_menu_item_new_with_mnemonic (_("_More...")); - gtk_widget_show (mi); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); + if (suggestions == NULL) + { + /* no suggestions. put something in the menu anyway... */ + GtkWidget *label; + /* Translators: Displayed in the "Check Spelling" dialog if there are no suggestions for the current misspelled word */ + label = gtk_label_new (_("(no suggested words)")); - menu = gtk_menu_new (); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), menu); - count = 0; - } - - label_text = g_strdup_printf ("%s", (gchar*) suggestions->data); - - label = gtk_label_new (label_text); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + mi = gtk_menu_item_new (); + gtk_widget_set_sensitive (mi, FALSE); + gtk_container_add (GTK_CONTAINER(mi), label); + gtk_widget_show_all (mi); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), mi); + } + else + { + gint count = 0; - mi = gtk_menu_item_new (); - gtk_container_add (GTK_CONTAINER(mi), label); - - gtk_widget_show_all (mi); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); + /* build a set of menus with suggestions. */ + while (suggestions != NULL) + { + GtkWidget *label; - g_object_set_qdata_full (G_OBJECT (mi), - suggestion_id, - g_strdup (suggestions->data), - (GDestroyNotify)g_free); + if (count == 10) + { + /* Separator */ + mi = gtk_menu_item_new (); + gtk_widget_show (mi); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); - g_free (label_text); - g_signal_connect (mi, - "activate", - G_CALLBACK (replace_word), - spell); + mi = gtk_menu_item_new_with_mnemonic (_("_More...")); + gtk_widget_show (mi); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); - count++; + menu = gtk_menu_new (); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), menu); + count = 0; + } - suggestions = g_slist_next (suggestions); - } - } + label_text = g_strdup_printf ("%s", (gchar*) suggestions->data); - /* free the suggestion list */ - suggestions = list; + label = gtk_label_new (label_text); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + gtk_widget_set_halign (label, GTK_ALIGN_START); - while (list) - { - g_free (list->data); - list = g_slist_next (list); - } + mi = gtk_menu_item_new (); + gtk_container_add (GTK_CONTAINER (mi), label); - g_slist_free (suggestions); + gtk_widget_show_all (mi); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); - /* Separator */ - mi = gtk_menu_item_new (); - gtk_widget_show (mi); - gtk_menu_shell_append (GTK_MENU_SHELL (topmenu), mi); + g_object_set_qdata_full (G_OBJECT (mi), + suggestion_id, + g_strdup (suggestions->data), + (GDestroyNotify)g_free); - /* Ignore all */ - mi = gtk_image_menu_item_new_with_mnemonic (_("_Ignore All")); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), - gtk_image_new_from_stock (GTK_STOCK_GOTO_BOTTOM, - GTK_ICON_SIZE_MENU)); - - g_signal_connect (mi, - "activate", - G_CALLBACK(ignore_all), - spell); + g_free (label_text); + g_signal_connect (mi, "activate", + G_CALLBACK (replace_word), spell); - gtk_widget_show_all (mi); + count++; - gtk_menu_shell_append (GTK_MENU_SHELL (topmenu), mi); + suggestions = g_slist_next (suggestions); + } + } - /* + Add to Dictionary */ - mi = gtk_image_menu_item_new_with_mnemonic (_("_Add")); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), - gtk_image_new_from_stock (GTK_STOCK_ADD, - GTK_ICON_SIZE_MENU)); + /* free the suggestion list */ + suggestions = list; - g_signal_connect (mi, - "activate", - G_CALLBACK (add_to_dictionary), - spell); + while (list) + { + g_free (list->data); + list = g_slist_next (list); + } - gtk_widget_show_all (mi); - - gtk_menu_shell_append (GTK_MENU_SHELL (topmenu), mi); + g_slist_free (suggestions); - return topmenu; + /* Separator */ + mi = gtk_menu_item_new (); + gtk_widget_show (mi); + gtk_menu_shell_append (GTK_MENU_SHELL (topmenu), mi); + + /* Ignore all */ + mi = gtk_menu_item_new_with_mnemonic (_("_Ignore All")); + + g_signal_connect (mi, "activate", + G_CALLBACK(ignore_all), spell); + + gtk_widget_show_all (mi); + + gtk_menu_shell_append (GTK_MENU_SHELL (topmenu), mi); + + /* + Add to Dictionary */ + mi = gtk_menu_item_new_with_mnemonic (_("_Add")); + + g_signal_connect (mi, "activate", + G_CALLBACK (add_to_dictionary), spell); + + gtk_widget_show_all (mi); + + gtk_menu_shell_append (GTK_MENU_SHELL (topmenu), mi); + + return topmenu; } static void -populate_popup (GtkTextView *textview, GtkMenu *menu, XedAutomaticSpellChecker *spell) +populate_popup (GtkTextView *textview, + GtkMenu *menu, + XedAutomaticSpellChecker *spell) { - GtkWidget *img, *mi; - GtkTextIter start, end; - char *word; + GtkWidget *mi; + GtkTextIter start, end; + char *word; - /* we need to figure out if they picked a misspelled word. */ - get_word_extents_from_mark (GTK_TEXT_BUFFER (spell->doc), &start, &end, spell->mark_click); + /* we need to figure out if they picked a misspelled word. */ + get_word_extents_from_mark (GTK_TEXT_BUFFER (spell->doc), &start, &end, spell->mark_click); - /* if our highlight algorithm ever messes up, - * this isn't correct, either. */ - if (!gtk_text_iter_has_tag (&start, spell->tag_highlight)) - return; /* word wasn't misspelled. */ + /* if our highlight algorithm ever messes up, + * this isn't correct, either. */ + if (!gtk_text_iter_has_tag (&start, spell->tag_highlight)) + { + return; /* word wasn't misspelled. */ + } - /* menu separator comes first. */ - mi = gtk_menu_item_new (); - gtk_widget_show (mi); - gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), mi); + /* menu separator comes first. */ + mi = gtk_menu_item_new (); + gtk_widget_show (mi); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), mi); - /* then, on top of it, the suggestions menu. */ - img = gtk_image_new_from_stock (GTK_STOCK_SPELL_CHECK, GTK_ICON_SIZE_MENU); - mi = gtk_image_menu_item_new_with_mnemonic (_("_Spelling Suggestions...")); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), img); + /* then, on top of it, the suggestions menu. */ + mi = gtk_menu_item_new_with_mnemonic (_("_Spelling Suggestions...")); - word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->doc), &start, &end, FALSE); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), - build_suggestion_menu (spell, word)); - g_free(word); + word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->doc), &start, &end, FALSE); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), build_suggestion_menu (spell, word)); + g_free(word); - gtk_widget_show_all (mi); - gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), mi); + gtk_widget_show_all (mi); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), mi); } void xed_automatic_spell_checker_recheck_all (XedAutomaticSpellChecker *spell) { - GtkTextIter start, end; + GtkTextIter start, end; - g_return_if_fail (spell != NULL); + g_return_if_fail (spell != NULL); - gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (spell->doc), &start, &end); + gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (spell->doc), &start, &end); - check_range (spell, start, end, TRUE); + check_range (spell, start, end, TRUE); } -static void -add_word_signal_cb (XedSpellChecker *checker, - const gchar *word, - gint len, - XedAutomaticSpellChecker *spell) +static void +add_word_signal_cb (XedSpellChecker *checker, + const gchar *word, + gint len, + XedAutomaticSpellChecker *spell) { - gchar *w; + gchar *w; - if (len < 0) - w = g_strdup (word); - else - w = g_strndup (word, len); + if (len < 0) + { + w = g_strdup (word); + } + else + { + w = g_strndup (word, len); + } - remove_tag_to_word (spell, w); + remove_tag_to_word (spell, w); - g_free (w); + g_free (w); } -static void +static void set_language_cb (XedSpellChecker *checker, - const XedSpellCheckerLanguage *lang, - XedAutomaticSpellChecker *spell) + const XedSpellCheckerLanguage *lang, + XedAutomaticSpellChecker *spell) { - xed_automatic_spell_checker_recheck_all (spell); + xed_automatic_spell_checker_recheck_all (spell); } -static void +static void clear_session_cb (XedSpellChecker *checker, - XedAutomaticSpellChecker *spell) + XedAutomaticSpellChecker *spell) { - xed_automatic_spell_checker_recheck_all (spell); + xed_automatic_spell_checker_recheck_all (spell); } /* When the user right-clicks on a word, they want to check that word. * Here, we do NOT move the cursor to the location of the clicked-upon word - * since that prevents the use of edit functions on the context menu. + * since that prevents the use of edit functions on the context menu. */ static gboolean -button_press_event (GtkTextView *view, - GdkEventButton *event, - XedAutomaticSpellChecker *spell) +button_press_event (GtkTextView *view, + GdkEventButton *event, + XedAutomaticSpellChecker *spell) { - if (event->button == 3) - { - gint x, y; - GtkTextIter iter; + if (event->button == 3) + { + gint x, y; + GtkTextIter iter; - GtkTextBuffer *buffer = gtk_text_view_get_buffer (view); + GtkTextBuffer *buffer = gtk_text_view_get_buffer (view); - /* handle deferred check if it exists */ - if (spell->deferred_check) - check_deferred_range (spell, TRUE); + /* handle deferred check if it exists */ + if (spell->deferred_check) + { + check_deferred_range (spell, TRUE); + } - gtk_text_view_window_to_buffer_coords (view, - GTK_TEXT_WINDOW_TEXT, - event->x, event->y, - &x, &y); - - gtk_text_view_get_iter_at_location (view, &iter, x, y); + gtk_text_view_window_to_buffer_coords (view, GTK_TEXT_WINDOW_TEXT, event->x, event->y, &x, &y); - gtk_text_buffer_move_mark (buffer, spell->mark_click, &iter); - } + gtk_text_view_get_iter_at_location (view, &iter, x, y); - return FALSE; /* false: let gtk process this event, too. - we don't want to eat any events. */ + gtk_text_buffer_move_mark (buffer, spell->mark_click, &iter); + } + + return FALSE; /* false: let gtk process this event, too. + we don't want to eat any events. */ } /* Move the insert mark before popping up the menu, otherwise it * will contain the wrong set of suggestions. */ static gboolean -popup_menu_event (GtkTextView *view, XedAutomaticSpellChecker *spell) +popup_menu_event (GtkTextView *view, + XedAutomaticSpellChecker *spell) { - GtkTextIter iter; - GtkTextBuffer *buffer; + GtkTextIter iter; + GtkTextBuffer *buffer; - buffer = gtk_text_view_get_buffer (view); + buffer = gtk_text_view_get_buffer (view); - /* handle deferred check if it exists */ - if (spell->deferred_check) - check_deferred_range (spell, TRUE); + /* handle deferred check if it exists */ + if (spell->deferred_check) + { + check_deferred_range (spell, TRUE); + } - gtk_text_buffer_get_iter_at_mark (buffer, &iter, - gtk_text_buffer_get_insert (buffer)); - gtk_text_buffer_move_mark (buffer, spell->mark_click, &iter); + gtk_text_buffer_get_iter_at_mark (buffer, &iter, gtk_text_buffer_get_insert (buffer)); + gtk_text_buffer_move_mark (buffer, spell->mark_click, &iter); - return FALSE; + return FALSE; } static void -tag_table_changed (GtkTextTagTable *table, - XedAutomaticSpellChecker *spell) -{ - g_return_if_fail (spell->tag_highlight != NULL); - - gtk_text_tag_set_priority (spell->tag_highlight, - gtk_text_tag_table_get_size (table) - 1); -} - -static void -tag_added_or_removed (GtkTextTagTable *table, - GtkTextTag *tag, - XedAutomaticSpellChecker *spell) -{ - tag_table_changed (table, spell); -} - -static void -tag_changed (GtkTextTagTable *table, - GtkTextTag *tag, - gboolean size_changed, - XedAutomaticSpellChecker *spell) -{ - tag_table_changed (table, spell); -} - -static void -highlight_updated (GtkSourceBuffer *buffer, - GtkTextIter *start, - GtkTextIter *end, +tag_table_changed (GtkTextTagTable *table, XedAutomaticSpellChecker *spell) { - check_range (spell, *start, *end, FALSE); + g_return_if_fail (spell->tag_highlight != NULL); + + gtk_text_tag_set_priority (spell->tag_highlight, gtk_text_tag_table_get_size (table) - 1); +} + +static void +tag_added_or_removed (GtkTextTagTable *table, + GtkTextTag *tag, + XedAutomaticSpellChecker *spell) +{ + tag_table_changed (table, spell); +} + +static void +tag_changed (GtkTextTagTable *table, + GtkTextTag *tag, + gboolean size_changed, + XedAutomaticSpellChecker *spell) +{ + tag_table_changed (table, spell); +} + +static void +highlight_updated (GtkSourceBuffer *buffer, + GtkTextIter *start, + GtkTextIter *end, + XedAutomaticSpellChecker *spell) +{ + check_range (spell, *start, *end, FALSE); } static void spell_tag_destroyed (XedAutomaticSpellChecker *spell, - GObject *where_the_object_was) + GObject *where_the_object_was) { - spell->tag_highlight = NULL; + spell->tag_highlight = NULL; } XedAutomaticSpellChecker * xed_automatic_spell_checker_new (XedDocument *doc, - XedSpellChecker *checker) + XedSpellChecker *checker) { - XedAutomaticSpellChecker *spell; - GtkTextTagTable *tag_table; - GtkTextIter start, end; + XedAutomaticSpellChecker *spell; + GtkTextTagTable *tag_table; + GtkTextIter start, end; - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - g_return_val_if_fail (XED_IS_SPELL_CHECKER (checker), NULL); - g_return_val_if_fail ((spell = xed_automatic_spell_checker_get_from_document (doc)) == NULL, - spell); - - /* attach to the widget */ - spell = g_new0 (XedAutomaticSpellChecker, 1); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + g_return_val_if_fail (XED_IS_SPELL_CHECKER (checker), NULL); + g_return_val_if_fail ((spell = xed_automatic_spell_checker_get_from_document (doc)) == NULL, spell); - spell->doc = doc; - spell->spell_checker = g_object_ref (checker); + /* attach to the widget */ + spell = g_new0 (XedAutomaticSpellChecker, 1); - if (automatic_spell_checker_id == 0) - { - automatic_spell_checker_id = - g_quark_from_string ("XedAutomaticSpellCheckerID"); - } - if (suggestion_id == 0) - { - suggestion_id = g_quark_from_string ("XedAutoSuggestionID"); - } + spell->doc = doc; + spell->spell_checker = g_object_ref (checker); - g_object_set_qdata_full (G_OBJECT (doc), - automatic_spell_checker_id, - spell, - (GDestroyNotify)xed_automatic_spell_checker_free_internal); + if (automatic_spell_checker_id == 0) + { + automatic_spell_checker_id = g_quark_from_string ("XedAutomaticSpellCheckerID"); + } + if (suggestion_id == 0) + { + suggestion_id = g_quark_from_string ("XedAutoSuggestionID"); + } - g_signal_connect (doc, - "insert-text", - G_CALLBACK (insert_text_before), - spell); - g_signal_connect_after (doc, - "insert-text", - G_CALLBACK (insert_text_after), - spell); - g_signal_connect_after (doc, - "delete-range", - G_CALLBACK (delete_range_after), - spell); - g_signal_connect (doc, - "mark-set", - G_CALLBACK (mark_set), - spell); + g_object_set_qdata_full (G_OBJECT (doc), automatic_spell_checker_id, + spell, (GDestroyNotify)xed_automatic_spell_checker_free_internal); - g_signal_connect (doc, - "highlight-updated", - G_CALLBACK (highlight_updated), - spell); + g_signal_connect (doc, "insert-text", + G_CALLBACK (insert_text_before), spell); + g_signal_connect_after (doc, "insert-text", + G_CALLBACK (insert_text_after), spell); + g_signal_connect_after (doc, "delete-range", + G_CALLBACK (delete_range_after), spell); + g_signal_connect (doc, "mark-set", + G_CALLBACK (mark_set), spell); - g_signal_connect (spell->spell_checker, - "add_word_to_session", - G_CALLBACK (add_word_signal_cb), - spell); - g_signal_connect (spell->spell_checker, - "add_word_to_personal", - G_CALLBACK (add_word_signal_cb), - spell); - g_signal_connect (spell->spell_checker, - "clear_session", - G_CALLBACK (clear_session_cb), - spell); - g_signal_connect (spell->spell_checker, - "set_language", - G_CALLBACK (set_language_cb), - spell); + g_signal_connect (doc, "highlight-updated", + G_CALLBACK (highlight_updated), spell); - spell->tag_highlight = gtk_text_buffer_create_tag ( - GTK_TEXT_BUFFER (doc), - "gtkspell-misspelled", - "underline", PANGO_UNDERLINE_ERROR, - NULL); + g_signal_connect (spell->spell_checker, "add_word_to_session", + G_CALLBACK (add_word_signal_cb), spell); + g_signal_connect (spell->spell_checker, "add_word_to_personal", + G_CALLBACK (add_word_signal_cb), spell); + g_signal_connect (spell->spell_checker, "clear_session", + G_CALLBACK (clear_session_cb), spell); + g_signal_connect (spell->spell_checker, "set_language", + G_CALLBACK (set_language_cb), spell); - g_object_weak_ref (G_OBJECT (spell->tag_highlight), - (GWeakNotify)spell_tag_destroyed, - spell); + spell->tag_highlight = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (doc), + "gtkspell-misspelled", + "underline", PANGO_UNDERLINE_ERROR, + NULL); - tag_table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (doc)); + g_object_weak_ref (G_OBJECT (spell->tag_highlight), (GWeakNotify)spell_tag_destroyed, spell); - gtk_text_tag_set_priority (spell->tag_highlight, - gtk_text_tag_table_get_size (tag_table) - 1); + tag_table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (doc)); - g_signal_connect (tag_table, - "tag-added", - G_CALLBACK (tag_added_or_removed), - spell); - g_signal_connect (tag_table, - "tag-removed", - G_CALLBACK (tag_added_or_removed), - spell); - g_signal_connect (tag_table, - "tag-changed", - G_CALLBACK (tag_changed), - spell); + gtk_text_tag_set_priority (spell->tag_highlight, gtk_text_tag_table_get_size (tag_table) - 1); - /* we create the mark here, but we don't use it until text is - * inserted, so we don't really care where iter points. */ - gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &start, &end); - - spell->mark_insert_start = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc), - "xed-automatic-spell-checker-insert-start"); + g_signal_connect (tag_table, "tag-added", + G_CALLBACK (tag_added_or_removed), spell); + g_signal_connect (tag_table, "tag-removed", + G_CALLBACK (tag_added_or_removed), spell); + g_signal_connect (tag_table, "tag-changed", + G_CALLBACK (tag_changed), spell); - if (spell->mark_insert_start == NULL) - { - spell->mark_insert_start = - gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), - "xed-automatic-spell-checker-insert-start", - &start, - TRUE); - } - else - { - gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), - spell->mark_insert_start, - &start); - } + /* we create the mark here, but we don't use it until text is + * inserted, so we don't really care where iter points. */ + gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &start, &end); - spell->mark_insert_end = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc), - "xed-automatic-spell-checker-insert-end"); + spell->mark_insert_start = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc), + "xed-automatic-spell-checker-insert-start"); - if (spell->mark_insert_end == NULL) - { - spell->mark_insert_end = - gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), - "xed-automatic-spell-checker-insert-end", - &start, - TRUE); - } - else - { - gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), - spell->mark_insert_end, - &start); - } + if (spell->mark_insert_start == NULL) + { + spell->mark_insert_start = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), + "xed-automatic-spell-checker-insert-start", + &start, + TRUE); + } + else + { + gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), spell->mark_insert_start, &start); + } - spell->mark_click = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc), - "xed-automatic-spell-checker-click"); + spell->mark_insert_end = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc), + "xed-automatic-spell-checker-insert-end"); - if (spell->mark_click == NULL) - { - spell->mark_click = - gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), - "xed-automatic-spell-checker-click", - &start, - TRUE); - } - else - { - gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), - spell->mark_click, - &start); - } + if (spell->mark_insert_end == NULL) + { + spell->mark_insert_end = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), + "xed-automatic-spell-checker-insert-end", + &start, + TRUE); + } + else + { + gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), spell->mark_insert_end, &start); + } - spell->deferred_check = FALSE; + spell->mark_click = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc), + "xed-automatic-spell-checker-click"); - return spell; + if (spell->mark_click == NULL) + { + spell->mark_click = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), + "xed-automatic-spell-checker-click", + &start, + TRUE); + } + else + { + gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), spell->mark_click, &start); + } + + spell->deferred_check = FALSE; + + return spell; } XedAutomaticSpellChecker * xed_automatic_spell_checker_get_from_document (const XedDocument *doc) { - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - if (automatic_spell_checker_id == 0) - return NULL; + if (automatic_spell_checker_id == 0) + { + return NULL; + } - return g_object_get_qdata (G_OBJECT (doc), automatic_spell_checker_id); -} + return g_object_get_qdata (G_OBJECT (doc), automatic_spell_checker_id); +} void xed_automatic_spell_checker_free (XedAutomaticSpellChecker *spell) { - g_return_if_fail (spell != NULL); - g_return_if_fail (xed_automatic_spell_checker_get_from_document (spell->doc) == spell); - - if (automatic_spell_checker_id == 0) - return; + g_return_if_fail (spell != NULL); + g_return_if_fail (xed_automatic_spell_checker_get_from_document (spell->doc) == spell); - g_object_set_qdata (G_OBJECT (spell->doc), automatic_spell_checker_id, NULL); + if (automatic_spell_checker_id == 0) + { + return; + } + + g_object_set_qdata (G_OBJECT (spell->doc), automatic_spell_checker_id, NULL); } static void xed_automatic_spell_checker_free_internal (XedAutomaticSpellChecker *spell) { - GtkTextTagTable *table; - GtkTextIter start, end; - GSList *list; - - g_return_if_fail (spell != NULL); + GtkTextTagTable *table; + GtkTextIter start, end; + GSList *list; - table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (spell->doc)); + g_return_if_fail (spell != NULL); - if (table != NULL && spell->tag_highlight != NULL) - { - gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (spell->doc), - &start, - &end); - gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (spell->doc), - spell->tag_highlight, - &start, - &end); + table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (spell->doc)); - g_signal_handlers_disconnect_matched (G_OBJECT (table), - G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, - spell); + if (table != NULL && spell->tag_highlight != NULL) + { + gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (spell->doc), &start, &end); + gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (spell->doc), spell->tag_highlight, &start, &end); - gtk_text_tag_table_remove (table, spell->tag_highlight); - } - - g_signal_handlers_disconnect_matched (G_OBJECT (spell->doc), - G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, - spell); + g_signal_handlers_disconnect_matched (G_OBJECT (table), + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, + spell); - g_signal_handlers_disconnect_matched (G_OBJECT (spell->spell_checker), - G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, - spell); + gtk_text_tag_table_remove (table, spell->tag_highlight); + } - g_object_unref (spell->spell_checker); + g_signal_handlers_disconnect_matched (G_OBJECT (spell->doc), + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, + spell); - list = spell->views; - while (list != NULL) - { - XedView *view = XED_VIEW (list->data); - - g_signal_handlers_disconnect_matched (G_OBJECT (view), - G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, - spell); + g_signal_handlers_disconnect_matched (G_OBJECT (spell->spell_checker), + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, + spell); - g_signal_handlers_disconnect_matched (G_OBJECT (view), - G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, - spell); + g_object_unref (spell->spell_checker); - list = g_slist_next (list); - } + list = spell->views; + while (list != NULL) + { + XedView *view = XED_VIEW (list->data); - g_slist_free (spell->views); - - g_free (spell); + g_signal_handlers_disconnect_matched (G_OBJECT (view), + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, + spell); + + g_signal_handlers_disconnect_matched (G_OBJECT (view), + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, + spell); + + list = g_slist_next (list); + } + + g_slist_free (spell->views); + + g_free (spell); } void -xed_automatic_spell_checker_attach_view ( - XedAutomaticSpellChecker *spell, - XedView *view) +xed_automatic_spell_checker_attach_view (XedAutomaticSpellChecker *spell, + XedView *view) { - g_return_if_fail (spell != NULL); - g_return_if_fail (XED_IS_VIEW (view)); + g_return_if_fail (spell != NULL); + g_return_if_fail (XED_IS_VIEW (view)); - g_return_if_fail (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)) == - GTK_TEXT_BUFFER (spell->doc)); + g_return_if_fail (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)) == GTK_TEXT_BUFFER (spell->doc)); - g_signal_connect (view, - "button-press-event", - G_CALLBACK (button_press_event), - spell); - g_signal_connect (view, - "popup-menu", - G_CALLBACK (popup_menu_event), - spell); - g_signal_connect (view, - "populate-popup", - G_CALLBACK (populate_popup), - spell); - g_signal_connect (view, - "destroy", - G_CALLBACK (view_destroy), - spell); + g_signal_connect (view, "button-press-event", + G_CALLBACK (button_press_event), spell); + g_signal_connect (view, "popup-menu", + G_CALLBACK (popup_menu_event), spell); + g_signal_connect (view, "populate-popup", + G_CALLBACK (populate_popup), spell); + g_signal_connect (view, "destroy", + G_CALLBACK (view_destroy), spell); - spell->views = g_slist_prepend (spell->views, view); + spell->views = g_slist_prepend (spell->views, view); } -void -xed_automatic_spell_checker_detach_view ( - XedAutomaticSpellChecker *spell, - XedView *view) +void +xed_automatic_spell_checker_detach_view (XedAutomaticSpellChecker *spell, + XedView *view) { - g_return_if_fail (spell != NULL); - g_return_if_fail (XED_IS_VIEW (view)); + g_return_if_fail (spell != NULL); + g_return_if_fail (XED_IS_VIEW (view)); - g_return_if_fail (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)) == - GTK_TEXT_BUFFER (spell->doc)); - g_return_if_fail (spell->views != NULL); + g_return_if_fail (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)) == GTK_TEXT_BUFFER (spell->doc)); + g_return_if_fail (spell->views != NULL); - g_signal_handlers_disconnect_matched (G_OBJECT (view), - G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, - spell); + g_signal_handlers_disconnect_matched (G_OBJECT (view), + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, + spell); - g_signal_handlers_disconnect_matched (G_OBJECT (view), - G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, - spell); + g_signal_handlers_disconnect_matched (G_OBJECT (view), + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, + spell); - spell->views = g_slist_remove (spell->views, view); + spell->views = g_slist_remove (spell->views, view); } diff --git a/plugins/spell/xed-spell-language-dialog.c b/plugins/spell/xed-spell-language-dialog.c index b0d9029..ee1efab 100644 --- a/plugins/spell/xed-spell-language-dialog.c +++ b/plugins/spell/xed-spell-language-dialog.c @@ -3,7 +3,7 @@ * xed-spell-language-dialog.c * This file is part of xed * - * Copyright (C) 2002 Paolo Maggi + * Copyright (C) 2002 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,14 +17,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2002. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2002. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. */ #ifdef HAVE_CONFIG_H @@ -41,268 +41,244 @@ enum { - COLUMN_LANGUAGE_NAME = 0, - COLUMN_LANGUAGE_POINTER, - ENCODING_NUM_COLS + COLUMN_LANGUAGE_NAME = 0, + COLUMN_LANGUAGE_POINTER, + ENCODING_NUM_COLS }; -struct _XedSpellLanguageDialog +struct _XedSpellLanguageDialog { - GtkDialog dialog; + GtkDialog dialog; - GtkWidget *languages_treeview; - GtkTreeModel *model; + GtkWidget *languages_treeview; + GtkTreeModel *model; }; -G_DEFINE_TYPE(XedSpellLanguageDialog, xed_spell_language_dialog, GTK_TYPE_DIALOG) +G_DEFINE_TYPE (XedSpellLanguageDialog, xed_spell_language_dialog, GTK_TYPE_DIALOG) -static void +static void xed_spell_language_dialog_class_init (XedSpellLanguageDialogClass *klass) { - /* GObjectClass *object_class = G_OBJECT_CLASS (klass); */ + /* GObjectClass *object_class = G_OBJECT_CLASS (klass); */ } static void dialog_response_handler (GtkDialog *dlg, - gint res_id) + gint res_id) { - if (res_id == GTK_RESPONSE_HELP) - { - xed_help_display (GTK_WINDOW (dlg), - NULL, - "xed-spell-checker-plugin"); + if (res_id == GTK_RESPONSE_HELP) + { + xed_help_display (GTK_WINDOW (dlg), NULL, "xed-spell-checker-plugin"); - g_signal_stop_emission_by_name (dlg, "response"); - } -} - -static void -scroll_to_selected (GtkTreeView *tree_view) -{ - GtkTreeModel *model; - GtkTreeSelection *selection; - GtkTreeIter iter; - - model = gtk_tree_view_get_model (tree_view); - g_return_if_fail (model != NULL); - - /* Scroll to selected */ - selection = gtk_tree_view_get_selection (tree_view); - g_return_if_fail (selection != NULL); - - if (gtk_tree_selection_get_selected (selection, NULL, &iter)) - { - GtkTreePath* path; - - path = gtk_tree_model_get_path (model, &iter); - g_return_if_fail (path != NULL); - - gtk_tree_view_scroll_to_cell (tree_view, - path, NULL, TRUE, 1.0, 0.0); - gtk_tree_path_free (path); - } + g_signal_stop_emission_by_name (dlg, "response"); + } } static void -language_row_activated (GtkTreeView *tree_view, - GtkTreePath *path, - GtkTreeViewColumn *column, - XedSpellLanguageDialog *dialog) +scroll_to_selected (GtkTreeView *tree_view) { - gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); + GtkTreeModel *model; + GtkTreeSelection *selection; + GtkTreeIter iter; + + model = gtk_tree_view_get_model (tree_view); + g_return_if_fail (model != NULL); + + /* Scroll to selected */ + selection = gtk_tree_view_get_selection (tree_view); + g_return_if_fail (selection != NULL); + + if (gtk_tree_selection_get_selected (selection, NULL, &iter)) + { + GtkTreePath* path; + + path = gtk_tree_model_get_path (model, &iter); + g_return_if_fail (path != NULL); + + gtk_tree_view_scroll_to_cell (tree_view, path, NULL, TRUE, 1.0, 0.0); + gtk_tree_path_free (path); + } +} + +static void +language_row_activated (GtkTreeView *tree_view, + GtkTreePath *path, + GtkTreeViewColumn *column, + XedSpellLanguageDialog *dialog) +{ + gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); } static void create_dialog (XedSpellLanguageDialog *dlg, - const gchar *data_dir) + const gchar *data_dir) { - GtkWidget *error_widget; - GtkWidget *content; - gboolean ret; - GtkCellRenderer *cell; - GtkTreeViewColumn *column; - gchar *ui_file; - gchar *root_objects[] = { - "content", - NULL - }; - - gtk_dialog_add_buttons (GTK_DIALOG (dlg), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, - GTK_RESPONSE_OK, - GTK_STOCK_HELP, - GTK_RESPONSE_HELP, - NULL); + GtkWidget *error_widget; + GtkWidget *content; + gboolean ret; + GtkCellRenderer *cell; + GtkTreeViewColumn *column; + gchar *ui_file; + gchar *root_objects[] = { + "content", + NULL + }; - gtk_window_set_title (GTK_WINDOW (dlg), _("Set language")); - gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); - gtk_window_set_destroy_with_parent (GTK_WINDOW (dlg), TRUE); + gtk_dialog_add_buttons (GTK_DIALOG (dlg), + _("_Cancel"), GTK_RESPONSE_CANCEL, + _("_OK"), GTK_RESPONSE_OK, + _("_Help"), GTK_RESPONSE_HELP, + NULL); - /* HIG defaults */ - gtk_container_set_border_width (GTK_CONTAINER (dlg), 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), - 2); /* 2 * 5 + 2 = 12 */ - gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), - 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), - 6); + gtk_window_set_title (GTK_WINDOW (dlg), _("Set language")); + gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); + gtk_window_set_destroy_with_parent (GTK_WINDOW (dlg), TRUE); - g_signal_connect (dlg, - "response", - G_CALLBACK (dialog_response_handler), - NULL); + /* HIG defaults */ + gtk_container_set_border_width (GTK_CONTAINER (dlg), 5); + gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), 2); + gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 5); + gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 6); - ui_file = g_build_filename (data_dir, "languages-dialog.ui", NULL); - ret = xed_utils_get_ui_objects (ui_file, - root_objects, - &error_widget, - "content", &content, - "languages_treeview", &dlg->languages_treeview, - NULL); - g_free (ui_file); - - if (!ret) - { - gtk_widget_show (error_widget); + g_signal_connect (dlg, "response", + G_CALLBACK (dialog_response_handler), NULL); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), - error_widget, - TRUE, TRUE, 0); + ui_file = g_build_filename (data_dir, "languages-dialog.ui", NULL); + ret = xed_utils_get_ui_objects (ui_file, + root_objects, + &error_widget, + "content", &content, + "languages_treeview", &dlg->languages_treeview, + NULL); + g_free (ui_file); - return; - } + if (!ret) + { + gtk_widget_show (error_widget); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), - content, TRUE, TRUE, 0); - g_object_unref (content); - gtk_container_set_border_width (GTK_CONTAINER (content), 5); + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), error_widget, TRUE, TRUE, 0); - dlg->model = GTK_TREE_MODEL (gtk_list_store_new (ENCODING_NUM_COLS, - G_TYPE_STRING, - G_TYPE_POINTER)); + return; + } - gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->languages_treeview), - dlg->model); + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), content, TRUE, TRUE, 0); + g_object_unref (content); + gtk_container_set_border_width (GTK_CONTAINER (content), 5); - g_object_unref (dlg->model); + dlg->model = GTK_TREE_MODEL (gtk_list_store_new (ENCODING_NUM_COLS, G_TYPE_STRING, G_TYPE_POINTER)); - /* Add the encoding column */ - cell = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes (_("Languages"), - cell, - "text", - COLUMN_LANGUAGE_NAME, - NULL); - - gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->languages_treeview), - column); + gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->languages_treeview), dlg->model); - gtk_tree_view_set_search_column (GTK_TREE_VIEW (dlg->languages_treeview), - COLUMN_LANGUAGE_NAME); + g_object_unref (dlg->model); - g_signal_connect (dlg->languages_treeview, - "realize", - G_CALLBACK (scroll_to_selected), - dlg); - g_signal_connect (dlg->languages_treeview, - "row-activated", - G_CALLBACK (language_row_activated), - dlg); + /* Add the encoding column */ + cell = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes (_("Languages"), + cell, + "text", + COLUMN_LANGUAGE_NAME, + NULL); + + gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->languages_treeview), column); + + gtk_tree_view_set_search_column (GTK_TREE_VIEW (dlg->languages_treeview), COLUMN_LANGUAGE_NAME); + + g_signal_connect (dlg->languages_treeview, "realize", + G_CALLBACK (scroll_to_selected), dlg); + g_signal_connect (dlg->languages_treeview, "row-activated", + G_CALLBACK (language_row_activated), dlg); } static void xed_spell_language_dialog_init (XedSpellLanguageDialog *dlg) { - + } static void populate_language_list (XedSpellLanguageDialog *dlg, - const XedSpellCheckerLanguage *cur_lang) + const XedSpellCheckerLanguage *cur_lang) { - GtkListStore *store; - GtkTreeIter iter; + GtkListStore *store; + GtkTreeIter iter; - const GSList* langs; + const GSList* langs; - /* create list store */ - store = GTK_LIST_STORE (dlg->model); + /* create list store */ + store = GTK_LIST_STORE (dlg->model); - langs = xed_spell_checker_get_available_languages (); + langs = xed_spell_checker_get_available_languages (); - while (langs) - { - const gchar *name; + while (langs) + { + const gchar *name; - name = xed_spell_checker_language_to_string ((const XedSpellCheckerLanguage*)langs->data); + name = xed_spell_checker_language_to_string ((const XedSpellCheckerLanguage*)langs->data); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - COLUMN_LANGUAGE_NAME, name, - COLUMN_LANGUAGE_POINTER, langs->data, - -1); + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + COLUMN_LANGUAGE_NAME, name, + COLUMN_LANGUAGE_POINTER, langs->data, + -1); - if (langs->data == cur_lang) - { - GtkTreeSelection *selection; + if (langs->data == cur_lang) + { + GtkTreeSelection *selection; - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->languages_treeview)); - g_return_if_fail (selection != NULL); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->languages_treeview)); + g_return_if_fail (selection != NULL); - gtk_tree_selection_select_iter (selection, &iter); - } + gtk_tree_selection_select_iter (selection, &iter); + } - langs = g_slist_next (langs); - } + langs = g_slist_next (langs); + } } GtkWidget * -xed_spell_language_dialog_new (GtkWindow *parent, - const XedSpellCheckerLanguage *cur_lang, - const gchar *data_dir) +xed_spell_language_dialog_new (GtkWindow *parent, + const XedSpellCheckerLanguage *cur_lang, + const gchar *data_dir) { - XedSpellLanguageDialog *dlg; + XedSpellLanguageDialog *dlg; - g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL); + g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL); - dlg = g_object_new (XED_TYPE_SPELL_LANGUAGE_DIALOG, NULL); + dlg = g_object_new (XED_TYPE_SPELL_LANGUAGE_DIALOG, NULL); - create_dialog (dlg, data_dir); + create_dialog (dlg, data_dir); - populate_language_list (dlg, cur_lang); + populate_language_list (dlg, cur_lang); - gtk_window_set_transient_for (GTK_WINDOW (dlg), parent); - gtk_widget_grab_focus (dlg->languages_treeview); + gtk_window_set_transient_for (GTK_WINDOW (dlg), parent); + gtk_widget_grab_focus (dlg->languages_treeview); - return GTK_WIDGET (dlg); + return GTK_WIDGET (dlg); } const XedSpellCheckerLanguage * xed_spell_language_get_selected_language (XedSpellLanguageDialog *dlg) { - GValue value = {0, }; - const XedSpellCheckerLanguage* lang; + GValue value = {0, }; + const XedSpellCheckerLanguage* lang; - GtkTreeIter iter; - GtkTreeSelection *selection; + GtkTreeIter iter; + GtkTreeSelection *selection; - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->languages_treeview)); - g_return_val_if_fail (selection != NULL, NULL); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->languages_treeview)); + g_return_val_if_fail (selection != NULL, NULL); - if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) - return NULL; + if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) + { + return NULL; + } - gtk_tree_model_get_value (dlg->model, - &iter, - COLUMN_LANGUAGE_POINTER, - &value); + gtk_tree_model_get_value (dlg->model, &iter, COLUMN_LANGUAGE_POINTER, &value); - lang = (const XedSpellCheckerLanguage* ) g_value_get_pointer (&value); + lang = (const XedSpellCheckerLanguage* ) g_value_get_pointer (&value); - return lang; + return lang; } diff --git a/plugins/spell/xed-spell-language-dialog.h b/plugins/spell/xed-spell-language-dialog.h index 488040c..b11c454 100644 --- a/plugins/spell/xed-spell-language-dialog.h +++ b/plugins/spell/xed-spell-language-dialog.h @@ -3,7 +3,7 @@ * xed-spell-language-dialog.h * This file is part of xed * - * Copyright (C) 2002 Paolo Maggi + * Copyright (C) 2002 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,14 +17,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2002. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2002. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. */ #ifndef __XED_SPELL_LANGUAGE_DIALOG_H__ @@ -44,22 +44,20 @@ G_BEGIN_DECLS typedef struct _XedSpellLanguageDialog XedSpellLanguageDialog; - typedef struct _XedSpellLanguageDialogClass XedSpellLanguageDialogClass; -struct _XedSpellLanguageDialogClass +struct _XedSpellLanguageDialogClass { - GtkDialogClass parent_class; + GtkDialogClass parent_class; }; -GType xed_spell_language_dialog_get_type (void) G_GNUC_CONST; +GType xed_spell_language_dialog_get_type (void) G_GNUC_CONST; -GtkWidget *xed_spell_language_dialog_new (GtkWindow *parent, - const XedSpellCheckerLanguage *cur_lang, - const gchar *data_dir); +GtkWidget *xed_spell_language_dialog_new (GtkWindow *parent, + const XedSpellCheckerLanguage *cur_lang, + const gchar *data_dir); -const XedSpellCheckerLanguage * - xed_spell_language_get_selected_language (XedSpellLanguageDialog *dlg); +const XedSpellCheckerLanguage *xed_spell_language_get_selected_language (XedSpellLanguageDialog *dlg); G_END_DECLS diff --git a/plugins/spell/xed-spell-plugin.c b/plugins/spell/xed-spell-plugin.c index a457a58..2765bc0 100644 --- a/plugins/spell/xed-spell-plugin.c +++ b/plugins/spell/xed-spell-plugin.c @@ -27,7 +27,7 @@ #include /* For strlen */ -#include +#include #include #include @@ -1039,7 +1039,6 @@ auto_spell_cb (GtkAction *action, XedSpellPlugin *plugin) { XedSpellPluginPrivate *priv; - XedWindow *window; XedDocument *doc; gboolean active; @@ -1319,7 +1318,7 @@ xed_spell_plugin_activate (XedWindowActivatable *activatable) { XedDocument *doc = XED_DOCUMENT (l->data); - set_auto_spell_from_metadata (activatable, doc, priv->action_group); + set_auto_spell_from_metadata (XED_SPELL_PLUGIN (activatable), doc, priv->action_group); g_signal_handlers_disconnect_by_func (doc, on_document_loaded, activatable); g_signal_handlers_disconnect_by_func (doc, on_document_saved, activatable); diff --git a/plugins/spell/xed-spell-setup-dialog.ui b/plugins/spell/xed-spell-setup-dialog.ui index abc878d..d9b56ab 100644 --- a/plugins/spell/xed-spell-setup-dialog.ui +++ b/plugins/spell/xed-spell-setup-dialog.ui @@ -1,29 +1,25 @@ - + - + + False - _Configure Spell Checker plugin... - False - normal + dialog - True False - 8 + vertical + 2 - True False end - - gtk-help + + button True True - True - False - True + True True @@ -32,13 +28,11 @@ - - gtk-cancel + + button True True - True - False - True + True True @@ -47,13 +41,11 @@ - - gtk-ok + + button True True - True - False - True + True True @@ -64,42 +56,208 @@ False - True - end + False 0 - + True False + 12 + 8 vertical + 12 True False - Autocheck spelling on document load... + Autocheck settings 0 + False - False + True 0 - - _Never autocheck + True - True - False - True - 0 - True - True + False + 30 + vertical + 12 + + + True + False + 12 + + + True + True + False + 0 + True + True + + + 0 + 0 + 2 + + + + + True + False + Never + 0 + + + + + + 1 + 0 + + + + + True + False + Never autocheck spelling on document load + 0 + + + 1 + 1 + + + + + False + True + 0 + + + + + True + False + 12 + + + True + True + False + 0 + True + True + autocheck_never + + + 0 + 0 + 2 + + + + + True + False + Remember by document + 0 + + + + + + 1 + 0 + + + + + True + False + Remembers the setting for each document on load + 0 + + + 1 + 1 + + + + + False + True + 1 + + + + + True + False + 12 + + + True + True + False + 0 + True + True + autocheck_never + + + 0 + 0 + 2 + + + + + True + False + Always + 0 + + + + + + 1 + 0 + + + + + True + False + Always autocheck on document load + 0 + + + 1 + 1 + + + + + False + True + 2 + + False @@ -107,42 +265,6 @@ 1 - - - _Remember autocheck by document - True - True - False - True - 0 - True - True - autocheck_never - - - False - True - 2 - - - - - _Always autocheck - True - True - False - True - 0 - True - True - autocheck_never - - - False - True - 3 - - False @@ -152,10 +274,5 @@ - - button1 - button3 - button4 - From 422dc034f49f9cc71f8e70b9cf45baee053e468c Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Fri, 13 Jan 2017 02:44:53 -0800 Subject: [PATCH 086/132] Clean up uses of deprecated GtkMisc --- xed/dialogs/xed-close-confirmation-dialog.c | 5 ++--- xed/xed-file-chooser-dialog.c | 4 ++-- xed/xed-io-error-message-area.c | 20 ++++++++++---------- xed/xed-panel.c | 4 ++-- xed/xed-progress-message-area.c | 2 +- xed/xed-tab-label.c | 2 +- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/xed/dialogs/xed-close-confirmation-dialog.c b/xed/dialogs/xed-close-confirmation-dialog.c index 6de1101..e667ad5 100755 --- a/xed/dialogs/xed-close-confirmation-dialog.c +++ b/xed/dialogs/xed-close-confirmation-dialog.c @@ -471,7 +471,6 @@ build_single_doc_dialog (XedCloseConfirmationDialog *dlg) primary_label = gtk_label_new (NULL); gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); gtk_widget_set_can_focus (GTK_WIDGET (primary_label), FALSE); @@ -639,7 +638,7 @@ build_multiple_docs_dialog (XedCloseConfirmationDialog *dlg) gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); gtk_widget_set_halign (GTK_WIDGET (primary_label), GTK_ALIGN_START); - gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); + gtk_widget_set_halign (primary_label, GTK_ALIGN_START); gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); str = g_strdup_printf (ngettext ("There is %d document with unsaved changes. " @@ -663,7 +662,7 @@ build_multiple_docs_dialog (XedCloseConfirmationDialog *dlg) gtk_box_pack_start (GTK_BOX (vbox2), select_label, FALSE, FALSE, 0); gtk_label_set_line_wrap (GTK_LABEL (select_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (select_label), 0.0, 0.5); + gtk_widget_set_halign (select_label, GTK_ALIGN_START); scrolledwindow = gtk_scrolled_window_new (NULL, NULL); gtk_box_pack_start (GTK_BOX (vbox2), scrolledwindow, TRUE, TRUE, 0); diff --git a/xed/xed-file-chooser-dialog.c b/xed/xed-file-chooser-dialog.c index 8c906f4..d7c0aa1 100644 --- a/xed/xed-file-chooser-dialog.c +++ b/xed/xed-file-chooser-dialog.c @@ -80,7 +80,7 @@ create_option_menu (XedFileChooserDialog *dialog) GtkWidget *menu; label = gtk_label_new_with_mnemonic (_("C_haracter Encoding:")); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_widget_set_halign (label, GTK_ALIGN_START); menu = xed_encodings_combo_box_new ( gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE); @@ -145,7 +145,7 @@ create_newline_combo (XedFileChooserDialog *dialog) GtkTreeIter iter; label = gtk_label_new_with_mnemonic (_("L_ine Ending:")); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_widget_set_halign (label, GTK_ALIGN_START); store = gtk_list_store_new (2, G_TYPE_STRING, XED_TYPE_DOCUMENT_NEWLINE_TYPE); combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store)); diff --git a/xed/xed-io-error-message-area.c b/xed/xed-io-error-message-area.c index f11f17a..876f6d2 100644 --- a/xed/xed-io-error-message-area.c +++ b/xed/xed-io-error-message-area.c @@ -134,7 +134,7 @@ set_message_area_text_and_icon (GtkWidget *message_area, gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0); gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); + gtk_widget_set_halign (primary_label, GTK_ALIGN_START); gtk_widget_set_can_focus (primary_label, TRUE); gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); @@ -148,7 +148,7 @@ set_message_area_text_and_icon (GtkWidget *message_area, gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); + gtk_widget_set_halign (secondary_label, GTK_ALIGN_START); } gtk_widget_show_all (hbox_content); @@ -466,7 +466,7 @@ create_conversion_error_message_area (const gchar *primary_text, gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0); gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); + gtk_widget_set_halign (primary_label, GTK_ALIGN_START); gtk_widget_set_can_focus (primary_label, TRUE); gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); @@ -480,7 +480,7 @@ create_conversion_error_message_area (const gchar *primary_text, gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); + gtk_widget_set_halign (secondary_label, GTK_ALIGN_START); } create_combo_box (message_area, vbox); @@ -724,7 +724,7 @@ xed_file_already_open_warning_message_area_new (const gchar *uri) gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0); gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); + gtk_widget_set_halign (primary_label, GTK_ALIGN_START); gtk_widget_set_can_focus (primary_label, TRUE); gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); @@ -738,7 +738,7 @@ xed_file_already_open_warning_message_area_new (const gchar *uri) gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); + gtk_widget_set_halign (secondary_label, GTK_ALIGN_START); gtk_widget_show_all (hbox_content); set_contents (message_area, hbox_content); @@ -811,7 +811,7 @@ xed_externally_modified_saving_error_message_area_new (const gchar *uri, gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0); gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); + gtk_widget_set_halign (primary_label, GTK_ALIGN_START); gtk_widget_set_can_focus (primary_label, TRUE); gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); @@ -824,7 +824,7 @@ xed_externally_modified_saving_error_message_area_new (const gchar *uri, gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); + gtk_widget_set_halign (secondary_label, GTK_ALIGN_START); gtk_widget_show_all (hbox_content); set_contents (message_area, hbox_content); @@ -906,7 +906,7 @@ xed_no_backup_saving_error_message_area_new (const gchar *uri, gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0); gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); + gtk_widget_set_halign (primary_label, GTK_ALIGN_START); gtk_widget_set_can_focus (primary_label, TRUE); gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); @@ -921,7 +921,7 @@ xed_no_backup_saving_error_message_area_new (const gchar *uri, gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); + gtk_widget_set_halign (secondary_label, GTK_ALIGN_START); gtk_widget_show_all (hbox_content); set_contents (message_area, hbox_content); diff --git a/xed/xed-panel.c b/xed/xed-panel.c index 81cab98..785cca8 100644 --- a/xed/xed-panel.c +++ b/xed/xed-panel.c @@ -422,7 +422,7 @@ build_tab_label (XedPanel *panel, /* setup label */ label = gtk_label_new (name); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_widget_set_halign (label, GTK_ALIGN_START); gtk_widget_set_margin_left (label, 0); gtk_widget_set_margin_right (label, 0); gtk_widget_set_margin_top (label, 0); @@ -496,7 +496,7 @@ xed_panel_add_item (XedPanel *panel, menu_label = gtk_label_new (name); - gtk_misc_set_alignment (GTK_MISC (menu_label), 0.0, 0.5); + gtk_widget_set_halign (menu_label, GTK_ALIGN_START); if (!gtk_widget_get_visible (item)) { diff --git a/xed/xed-progress-message-area.c b/xed/xed-progress-message-area.c index cbb86e0..f915702 100644 --- a/xed/xed-progress-message-area.c +++ b/xed/xed-progress-message-area.c @@ -151,7 +151,7 @@ xed_progress_message_area_init (XedProgressMessageArea *area) gtk_widget_show (area->priv->label); gtk_box_pack_start (GTK_BOX (hbox), area->priv->label, TRUE, TRUE, 0); gtk_label_set_use_markup (GTK_LABEL (area->priv->label), TRUE); - gtk_misc_set_alignment (GTK_MISC (area->priv->label), 0.0, 0.5); + gtk_widget_set_halign (area->priv->label, GTK_ALIGN_START); gtk_label_set_ellipsize (GTK_LABEL (area->priv->label), PANGO_ELLIPSIZE_END); area->priv->progress = gtk_progress_bar_new (); diff --git a/xed/xed-tab-label.c b/xed/xed-tab-label.c index 47d36e9..bd01717 100644 --- a/xed/xed-tab-label.c +++ b/xed/xed-tab-label.c @@ -297,7 +297,7 @@ xed_tab_label_init (XedTabLabel *tab_label) label = gtk_label_new (""); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_widget_set_halign (label, GTK_ALIGN_START); gtk_widget_set_margin_left (label, 0); gtk_widget_set_margin_right (label, 0); gtk_widget_set_margin_top (label, 0); From 66800ca9a3a27bf1ab009ef5efea0f9116793f4b Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Fri, 13 Jan 2017 02:53:46 -0800 Subject: [PATCH 087/132] xed-tab-label.c/h: Clean up code styling --- xed/xed-tab-label.c | 388 ++++++++++++++++++++++---------------------- xed/xed-tab-label.h | 40 ++--- 2 files changed, 213 insertions(+), 215 deletions(-) diff --git a/xed/xed-tab-label.c b/xed/xed-tab-label.c index bd01717..a77c3d9 100644 --- a/xed/xed-tab-label.c +++ b/xed/xed-tab-label.c @@ -34,27 +34,27 @@ /* Signals */ enum { - CLOSE_CLICKED, - LAST_SIGNAL + CLOSE_CLICKED, + LAST_SIGNAL }; enum { - PROP_0, - PROP_TAB + PROP_0, + PROP_TAB }; struct _XedTabLabelPrivate { - XedTab *tab; + XedTab *tab; - GtkWidget *ebox; - GtkWidget *close_button; - GtkWidget *spinner; - GtkWidget *icon; - GtkWidget *label; + GtkWidget *ebox; + GtkWidget *close_button; + GtkWidget *spinner; + GtkWidget *icon; + GtkWidget *label; - gboolean close_button_sensitive; + gboolean close_button_sensitive; }; static guint signals[LAST_SIGNAL] = { 0 }; @@ -64,114 +64,119 @@ G_DEFINE_TYPE (XedTabLabel, xed_tab_label, GTK_TYPE_BOX) static void xed_tab_label_finalize (GObject *object) { - G_OBJECT_CLASS (xed_tab_label_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_tab_label_parent_class)->finalize (object); } static void xed_tab_label_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - XedTabLabel *tab_label = XED_TAB_LABEL (object); + XedTabLabel *tab_label = XED_TAB_LABEL (object); - switch (prop_id) - { - case PROP_TAB: - tab_label->priv->tab = XED_TAB (g_value_get_object (value)); - break; + switch (prop_id) + { + case PROP_TAB: + tab_label->priv->tab = XED_TAB (g_value_get_object (value)); + break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_tab_label_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - XedTabLabel *tab_label = XED_TAB_LABEL (object); + XedTabLabel *tab_label = XED_TAB_LABEL (object); - switch (prop_id) - { - case PROP_TAB: - g_value_set_object (value, tab_label->priv->tab); - break; + switch (prop_id) + { + case PROP_TAB: + g_value_set_object (value, tab_label->priv->tab); + break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -close_button_clicked_cb (GtkWidget *widget, - XedTabLabel *tab_label) +close_button_clicked_cb (GtkWidget *widget, + XedTabLabel *tab_label) { - g_signal_emit (tab_label, signals[CLOSE_CLICKED], 0, NULL); + g_signal_emit (tab_label, signals[CLOSE_CLICKED], 0, NULL); } static void -sync_tip (XedTab *tab, XedTabLabel *tab_label) +sync_tip (XedTab *tab, + XedTabLabel *tab_label) { - gchar *str; + gchar *str; - str = _xed_tab_get_tooltips (tab); - g_return_if_fail (str != NULL); + str = _xed_tab_get_tooltips (tab); + g_return_if_fail (str != NULL); - gtk_widget_set_tooltip_markup (tab_label->priv->ebox, str); - g_free (str); + gtk_widget_set_tooltip_markup (tab_label->priv->ebox, str); + g_free (str); } static void -sync_name (XedTab *tab, GParamSpec *pspec, XedTabLabel *tab_label) +sync_name (XedTab *tab, + GParamSpec *pspec, + XedTabLabel *tab_label) { - gchar *str; + gchar *str; - g_return_if_fail (tab == tab_label->priv->tab); + g_return_if_fail (tab == tab_label->priv->tab); - str = _xed_tab_get_name (tab); - g_return_if_fail (str != NULL); + str = _xed_tab_get_name (tab); + g_return_if_fail (str != NULL); - gtk_label_set_text (GTK_LABEL (tab_label->priv->label), str); - g_free (str); + gtk_label_set_text (GTK_LABEL (tab_label->priv->label), str); + g_free (str); - sync_tip (tab, tab_label); + sync_tip (tab, tab_label); } static void -sync_state (XedTab *tab, GParamSpec *pspec, XedTabLabel *tab_label) +sync_state (XedTab *tab, + GParamSpec *pspec, + XedTabLabel *tab_label) { - XedTabState state; + XedTabState state; - g_return_if_fail (tab == tab_label->priv->tab); + g_return_if_fail (tab == tab_label->priv->tab); - state = xed_tab_get_state (tab); + state = xed_tab_get_state (tab); - gtk_widget_set_sensitive (tab_label->priv->close_button, - tab_label->priv->close_button_sensitive && - (state != XED_TAB_STATE_CLOSING) && - (state != XED_TAB_STATE_SAVING) && - (state != XED_TAB_STATE_SHOWING_PRINT_PREVIEW) && - (state != XED_TAB_STATE_SAVING_ERROR)); + gtk_widget_set_sensitive (tab_label->priv->close_button, + tab_label->priv->close_button_sensitive && + (state != XED_TAB_STATE_CLOSING) && + (state != XED_TAB_STATE_SAVING) && + (state != XED_TAB_STATE_SHOWING_PRINT_PREVIEW) && + (state != XED_TAB_STATE_SAVING_ERROR)); - if ((state == XED_TAB_STATE_LOADING) || - (state == XED_TAB_STATE_SAVING) || - (state == XED_TAB_STATE_REVERTING)) - { - gtk_widget_hide (tab_label->priv->icon); + if ((state == XED_TAB_STATE_LOADING) || + (state == XED_TAB_STATE_SAVING) || + (state == XED_TAB_STATE_REVERTING)) + { + gtk_widget_hide (tab_label->priv->icon); - gtk_widget_show (tab_label->priv->spinner); - gtk_spinner_start (GTK_SPINNER (tab_label->priv->spinner)); - } - else - { - GdkPixbuf *pixbuf; + gtk_widget_show (tab_label->priv->spinner); + gtk_spinner_start (GTK_SPINNER (tab_label->priv->spinner)); + } + else + { + GdkPixbuf *pixbuf; - pixbuf = _xed_tab_get_icon (tab); + pixbuf = _xed_tab_get_icon (tab); if (pixbuf != NULL) { @@ -184,183 +189,176 @@ sync_state (XedTab *tab, GParamSpec *pspec, XedTabLabel *tab_label) gtk_widget_hide (tab_label->priv->icon); } - gtk_widget_hide (tab_label->priv->spinner); - gtk_spinner_stop (GTK_SPINNER (tab_label->priv->spinner)); - } + gtk_widget_hide (tab_label->priv->spinner); + gtk_spinner_stop (GTK_SPINNER (tab_label->priv->spinner)); + } - /* sync tip since encoding is known only after load/save end */ - sync_tip (tab, tab_label); + /* sync tip since encoding is known only after load/save end */ + sync_tip (tab, tab_label); } static void xed_tab_label_constructed (GObject *object) { - XedTabLabel *tab_label = XED_TAB_LABEL (object); + XedTabLabel *tab_label = XED_TAB_LABEL (object); - if (!tab_label->priv->tab) - { - g_critical ("The tab label was not properly constructed"); - return; - } + if (!tab_label->priv->tab) + { + g_critical ("The tab label was not properly constructed"); + return; + } - sync_name (tab_label->priv->tab, NULL, tab_label); - sync_state (tab_label->priv->tab, NULL, tab_label); + sync_name (tab_label->priv->tab, NULL, tab_label); + sync_state (tab_label->priv->tab, NULL, tab_label); - g_signal_connect_object (tab_label->priv->tab, - "notify::name", - G_CALLBACK (sync_name), - tab_label, - 0); + g_signal_connect_object (tab_label->priv->tab, "notify::name", + G_CALLBACK (sync_name), tab_label, 0); - g_signal_connect_object (tab_label->priv->tab, - "notify::state", - G_CALLBACK (sync_state), - tab_label, - 0); + g_signal_connect_object (tab_label->priv->tab, "notify::state", + G_CALLBACK (sync_state), tab_label, 0); } static void xed_tab_label_class_init (XedTabLabelClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = xed_tab_label_finalize; - object_class->set_property = xed_tab_label_set_property; - object_class->get_property = xed_tab_label_get_property; - object_class->constructed = xed_tab_label_constructed; + object_class->finalize = xed_tab_label_finalize; + object_class->set_property = xed_tab_label_set_property; + object_class->get_property = xed_tab_label_get_property; + object_class->constructed = xed_tab_label_constructed; - signals[CLOSE_CLICKED] = - g_signal_new ("close-clicked", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedTabLabelClass, close_clicked), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); + signals[CLOSE_CLICKED] = + g_signal_new ("close-clicked", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedTabLabelClass, close_clicked), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); - g_object_class_install_property (object_class, - PROP_TAB, - g_param_spec_object ("tab", - "Tab", - "The XedTab", - XED_TYPE_TAB, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, + PROP_TAB, + g_param_spec_object ("tab", + "Tab", + "The XedTab", + XED_TYPE_TAB, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); - g_type_class_add_private (object_class, sizeof(XedTabLabelPrivate)); + g_type_class_add_private (object_class, sizeof(XedTabLabelPrivate)); } static void xed_tab_label_init (XedTabLabel *tab_label) { - GtkWidget *ebox; - GtkWidget *hbox; - GtkWidget *close_button; - GtkWidget *spinner; - GtkWidget *icon; - GtkWidget *label; - GtkWidget *dummy_label; + GtkWidget *ebox; + GtkWidget *hbox; + GtkWidget *close_button; + GtkWidget *spinner; + GtkWidget *icon; + GtkWidget *label; + GtkWidget *dummy_label; - tab_label->priv = XED_TAB_LABEL_GET_PRIVATE (tab_label); + tab_label->priv = XED_TAB_LABEL_GET_PRIVATE (tab_label); - tab_label->priv->close_button_sensitive = TRUE; + tab_label->priv->close_button_sensitive = TRUE; - gtk_orientable_set_orientation (GTK_ORIENTABLE (tab_label), - GTK_ORIENTATION_HORIZONTAL); - ebox = gtk_event_box_new (); - gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE); - gtk_box_pack_start (GTK_BOX (tab_label), ebox, TRUE, TRUE, 0); - tab_label->priv->ebox = ebox; + gtk_orientable_set_orientation (GTK_ORIENTABLE (tab_label), GTK_ORIENTATION_HORIZONTAL); + ebox = gtk_event_box_new (); + gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE); + gtk_box_pack_start (GTK_BOX (tab_label), ebox, TRUE, TRUE, 0); + tab_label->priv->ebox = ebox; - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); - gtk_container_add (GTK_CONTAINER (ebox), hbox); + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); + gtk_container_add (GTK_CONTAINER (ebox), hbox); - close_button = xed_close_button_new (); - gtk_widget_set_tooltip_text (close_button, _("Close document")); - gtk_box_pack_start (GTK_BOX (tab_label), close_button, FALSE, FALSE, 0); - tab_label->priv->close_button = close_button; + close_button = xed_close_button_new (); + gtk_widget_set_tooltip_text (close_button, _("Close document")); + gtk_box_pack_start (GTK_BOX (tab_label), close_button, FALSE, FALSE, 0); + tab_label->priv->close_button = close_button; - g_signal_connect (close_button, - "clicked", - G_CALLBACK (close_button_clicked_cb), - tab_label); + g_signal_connect (close_button, "clicked", + G_CALLBACK (close_button_clicked_cb), tab_label); - spinner = gtk_spinner_new (); - gtk_box_pack_start (GTK_BOX (hbox), spinner, FALSE, FALSE, 0); - tab_label->priv->spinner = spinner; + spinner = gtk_spinner_new (); + gtk_box_pack_start (GTK_BOX (hbox), spinner, FALSE, FALSE, 0); + tab_label->priv->spinner = spinner; - /* setup icon, empty by default */ - icon = gtk_image_new (); - gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0); - tab_label->priv->icon = icon; + /* setup icon, empty by default */ + icon = gtk_image_new (); + gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0); + tab_label->priv->icon = icon; - label = gtk_label_new (""); + label = gtk_label_new (""); - gtk_widget_set_halign (label, GTK_ALIGN_START); - gtk_widget_set_margin_left (label, 0); - gtk_widget_set_margin_right (label, 0); - gtk_widget_set_margin_top (label, 0); - gtk_widget_set_margin_bottom (label, 0); + gtk_widget_set_halign (label, GTK_ALIGN_START); + gtk_widget_set_margin_left (label, 0); + gtk_widget_set_margin_right (label, 0); + gtk_widget_set_margin_top (label, 0); + gtk_widget_set_margin_bottom (label, 0); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - tab_label->priv->label = label; + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + tab_label->priv->label = label; - dummy_label = gtk_label_new (""); - gtk_box_pack_start (GTK_BOX (hbox), dummy_label, TRUE, TRUE, 0); + dummy_label = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX (hbox), dummy_label, TRUE, TRUE, 0); - gtk_widget_show (ebox); - gtk_widget_show (hbox); - gtk_widget_show (close_button); - gtk_widget_show (icon); - gtk_widget_show (label); - gtk_widget_show (dummy_label); + gtk_widget_show (ebox); + gtk_widget_show (hbox); + gtk_widget_show (close_button); + gtk_widget_show (icon); + gtk_widget_show (label); + gtk_widget_show (dummy_label); } void xed_tab_label_set_close_button_sensitive (XedTabLabel *tab_label, - gboolean sensitive) + gboolean sensitive) { - XedTabState state; + XedTabState state; - g_return_if_fail (XED_IS_TAB_LABEL (tab_label)); + g_return_if_fail (XED_IS_TAB_LABEL (tab_label)); - sensitive = (sensitive != FALSE); + sensitive = (sensitive != FALSE); - if (sensitive == tab_label->priv->close_button_sensitive) - return; + if (sensitive == tab_label->priv->close_button_sensitive) + { + return; + } - tab_label->priv->close_button_sensitive = sensitive; + tab_label->priv->close_button_sensitive = sensitive; - state = xed_tab_get_state (tab_label->priv->tab); + state = xed_tab_get_state (tab_label->priv->tab); - gtk_widget_set_sensitive (tab_label->priv->close_button, - tab_label->priv->close_button_sensitive && - (state != XED_TAB_STATE_CLOSING) && - (state != XED_TAB_STATE_SAVING) && - (state != XED_TAB_STATE_SHOWING_PRINT_PREVIEW) && - (state != XED_TAB_STATE_PRINTING) && - (state != XED_TAB_STATE_PRINT_PREVIEWING) && - (state != XED_TAB_STATE_SAVING_ERROR)); + gtk_widget_set_sensitive (tab_label->priv->close_button, + tab_label->priv->close_button_sensitive && + (state != XED_TAB_STATE_CLOSING) && + (state != XED_TAB_STATE_SAVING) && + (state != XED_TAB_STATE_SHOWING_PRINT_PREVIEW) && + (state != XED_TAB_STATE_PRINTING) && + (state != XED_TAB_STATE_PRINT_PREVIEWING) && + (state != XED_TAB_STATE_SAVING_ERROR)); } XedTab * xed_tab_label_get_tab (XedTabLabel *tab_label) { - g_return_val_if_fail (XED_IS_TAB_LABEL (tab_label), NULL); + g_return_val_if_fail (XED_IS_TAB_LABEL (tab_label), NULL); - return tab_label->priv->tab; + return tab_label->priv->tab; } GtkWidget * xed_tab_label_new (XedTab *tab) { - XedTabLabel *tab_label; + XedTabLabel *tab_label; - tab_label = g_object_new (XED_TYPE_TAB_LABEL, - "homogeneous", FALSE, - "tab", tab, - NULL); + tab_label = g_object_new (XED_TYPE_TAB_LABEL, + "homogeneous", FALSE, + "tab", tab, + NULL); - return GTK_WIDGET (tab_label); + return GTK_WIDGET (tab_label); } diff --git a/xed/xed-tab-label.h b/xed/xed-tab-label.h index 768996e..d35f839 100644 --- a/xed/xed-tab-label.h +++ b/xed/xed-tab-label.h @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ @@ -28,38 +28,38 @@ G_BEGIN_DECLS -#define XED_TYPE_TAB_LABEL (xed_tab_label_get_type ()) -#define XED_TAB_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_TAB_LABEL, XedTabLabel)) -#define XED_TAB_LABEL_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_TAB_LABEL, XedTabLabel const)) -#define XED_TAB_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_TAB_LABEL, XedTabLabelClass)) -#define XED_IS_TAB_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_TAB_LABEL)) -#define XED_IS_TAB_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_TAB_LABEL)) -#define XED_TAB_LABEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_TAB_LABEL, XedTabLabelClass)) +#define XED_TYPE_TAB_LABEL (xed_tab_label_get_type ()) +#define XED_TAB_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_TAB_LABEL, XedTabLabel)) +#define XED_TAB_LABEL_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_TAB_LABEL, XedTabLabel const)) +#define XED_TAB_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_TAB_LABEL, XedTabLabelClass)) +#define XED_IS_TAB_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_TAB_LABEL)) +#define XED_IS_TAB_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_TAB_LABEL)) +#define XED_TAB_LABEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_TAB_LABEL, XedTabLabelClass)) -typedef struct _XedTabLabel XedTabLabel; -typedef struct _XedTabLabelClass XedTabLabelClass; -typedef struct _XedTabLabelPrivate XedTabLabelPrivate; +typedef struct _XedTabLabel XedTabLabel; +typedef struct _XedTabLabelClass XedTabLabelClass; +typedef struct _XedTabLabelPrivate XedTabLabelPrivate; struct _XedTabLabel { - GtkBox parent; + GtkBox parent; - XedTabLabelPrivate *priv; + XedTabLabelPrivate *priv; }; struct _XedTabLabelClass { - GtkBoxClass parent_class; + GtkBoxClass parent_class; - void (* close_clicked) (XedTabLabel *tab_label); + void (* close_clicked) (XedTabLabel *tab_label); }; -GType xed_tab_label_get_type (void) G_GNUC_CONST; +GType xed_tab_label_get_type (void) G_GNUC_CONST; -GtkWidget *xed_tab_label_new (XedTab *tab); +GtkWidget *xed_tab_label_new (XedTab *tab); -XedTab *xed_tab_label_get_tab (XedTabLabel *tab_label); +XedTab *xed_tab_label_get_tab (XedTabLabel *tab_label); -void xed_tab_label_set_close_button_sensitive (XedTabLabel *tab_label, - gboolean sensitive); +void xed_tab_label_set_close_button_sensitive (XedTabLabel *tab_label, + gboolean sensitive); G_END_DECLS From 9dc61e0df560216bc91ba1fa7d362ba3fff13684 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Fri, 13 Jan 2017 03:10:01 -0800 Subject: [PATCH 088/132] xed-file-dialog.c/h: Clean up code styling --- xed/xed-file-chooser-dialog.c | 605 ++++++++++++++++------------------ xed/xed-file-chooser-dialog.h | 59 ++-- 2 files changed, 307 insertions(+), 357 deletions(-) diff --git a/xed/xed-file-chooser-dialog.c b/xed/xed-file-chooser-dialog.c index d7c0aa1..b87add6 100644 --- a/xed/xed-file-chooser-dialog.c +++ b/xed/xed-file-chooser-dialog.c @@ -50,17 +50,17 @@ #define XED_FILE_CHOOSER_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_FILE_CHOOSER_DIALOG, XedFileChooserDialogPrivate)) -#define ALL_FILES _("All Files") -#define ALL_TEXT_FILES _("All Text Files") +#define ALL_FILES _("All Files") +#define ALL_TEXT_FILES _("All Text Files") struct _XedFileChooserDialogPrivate { - GtkWidget *option_menu; - GtkWidget *extra_widget; + GtkWidget *option_menu; + GtkWidget *extra_widget; - GtkWidget *newline_label; - GtkWidget *newline_combo; - GtkListStore *newline_store; + GtkWidget *newline_label; + GtkWidget *newline_combo; + GtkListStore *newline_store; }; G_DEFINE_TYPE(XedFileChooserDialog, xed_file_chooser_dialog, GTK_TYPE_FILE_CHOOSER_DIALOG) @@ -68,56 +68,47 @@ G_DEFINE_TYPE(XedFileChooserDialog, xed_file_chooser_dialog, GTK_TYPE_FILE_CHOOS static void xed_file_chooser_dialog_class_init (XedFileChooserDialogClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - g_type_class_add_private (object_class, sizeof(XedFileChooserDialogPrivate)); + g_type_class_add_private (object_class, sizeof(XedFileChooserDialogPrivate)); } static void create_option_menu (XedFileChooserDialog *dialog) { - GtkWidget *label; - GtkWidget *menu; + GtkWidget *label; + GtkWidget *menu; - label = gtk_label_new_with_mnemonic (_("C_haracter Encoding:")); - gtk_widget_set_halign (label, GTK_ALIGN_START); + label = gtk_label_new_with_mnemonic (_("C_haracter Encoding:")); + gtk_widget_set_halign (label, GTK_ALIGN_START); - menu = xed_encodings_combo_box_new ( - gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE); + menu = xed_encodings_combo_box_new ( + gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), menu); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), menu); - gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), - label, - FALSE, - TRUE, - 0); + gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), label, FALSE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), menu, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), - menu, - TRUE, - TRUE, - 0); + gtk_widget_show (label); + gtk_widget_show (menu); - gtk_widget_show (label); - gtk_widget_show (menu); - - dialog->priv->option_menu = menu; + dialog->priv->option_menu = menu; } static void update_newline_visibility (XedFileChooserDialog *dialog) { - if (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE) - { - gtk_widget_show (dialog->priv->newline_label); - gtk_widget_show (dialog->priv->newline_combo); - } - else - { - gtk_widget_hide (dialog->priv->newline_label); - gtk_widget_hide (dialog->priv->newline_combo); - } + if (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE) + { + gtk_widget_show (dialog->priv->newline_label); + gtk_widget_show (dialog->priv->newline_combo); + } + else + { + gtk_widget_hide (dialog->priv->newline_label); + gtk_widget_hide (dialog->priv->newline_combo); + } } static void @@ -127,325 +118,298 @@ newline_combo_append (GtkComboBox *combo, const gchar *label, XedDocumentNewlineType newline_type) { - gtk_list_store_append (store, iter); - gtk_list_store_set (store, iter, 0, label, 1, newline_type, -1); + gtk_list_store_append (store, iter); + gtk_list_store_set (store, iter, 0, label, 1, newline_type, -1); - if (newline_type == XED_DOCUMENT_NEWLINE_TYPE_DEFAULT) - { - gtk_combo_box_set_active_iter (combo, iter); - } + if (newline_type == XED_DOCUMENT_NEWLINE_TYPE_DEFAULT) + { + gtk_combo_box_set_active_iter (combo, iter); + } } static void create_newline_combo (XedFileChooserDialog *dialog) { - GtkWidget *label, *combo; - GtkListStore *store; - GtkCellRenderer *renderer; - GtkTreeIter iter; + GtkWidget *label, *combo; + GtkListStore *store; + GtkCellRenderer *renderer; + GtkTreeIter iter; - label = gtk_label_new_with_mnemonic (_("L_ine Ending:")); - gtk_widget_set_halign (label, GTK_ALIGN_START); + label = gtk_label_new_with_mnemonic (_("L_ine Ending:")); + gtk_widget_set_halign (label, GTK_ALIGN_START); - store = gtk_list_store_new (2, G_TYPE_STRING, XED_TYPE_DOCUMENT_NEWLINE_TYPE); - combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store)); - renderer = gtk_cell_renderer_text_new (); + store = gtk_list_store_new (2, G_TYPE_STRING, XED_TYPE_DOCUMENT_NEWLINE_TYPE); + combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store)); + renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), - renderer, - TRUE); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE); - gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), - renderer, - "text", - 0); + gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), renderer, "text", 0); - newline_combo_append (GTK_COMBO_BOX (combo), - store, - &iter, - _("Unix/Linux"), - XED_DOCUMENT_NEWLINE_TYPE_LF); + newline_combo_append (GTK_COMBO_BOX (combo), store, &iter, _("Unix/Linux"), XED_DOCUMENT_NEWLINE_TYPE_LF); + newline_combo_append (GTK_COMBO_BOX (combo), store, &iter, _("Mac OS Classic"), XED_DOCUMENT_NEWLINE_TYPE_CR); + newline_combo_append (GTK_COMBO_BOX (combo), store, &iter, _("Windows"), XED_DOCUMENT_NEWLINE_TYPE_CR_LF); - newline_combo_append (GTK_COMBO_BOX (combo), - store, - &iter, - _("Mac OS Classic"), - XED_DOCUMENT_NEWLINE_TYPE_CR); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo); - newline_combo_append (GTK_COMBO_BOX (combo), - store, - &iter, - _("Windows"), - XED_DOCUMENT_NEWLINE_TYPE_CR_LF); + gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), label, FALSE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), combo, TRUE, TRUE, 0); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo); + dialog->priv->newline_combo = combo; + dialog->priv->newline_label = label; + dialog->priv->newline_store = store; - gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), - label, - FALSE, - TRUE, - 0); - - gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), - combo, - TRUE, - TRUE, - 0); - - dialog->priv->newline_combo = combo; - dialog->priv->newline_label = label; - dialog->priv->newline_store = store; - - update_newline_visibility (dialog); + update_newline_visibility (dialog); } static void create_extra_widget (XedFileChooserDialog *dialog) { - dialog->priv->extra_widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + dialog->priv->extra_widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_widget_show (dialog->priv->extra_widget); + gtk_widget_show (dialog->priv->extra_widget); - create_option_menu (dialog); - create_newline_combo (dialog); + create_option_menu (dialog); + create_newline_combo (dialog); - gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), - dialog->priv->extra_widget); + gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), dialog->priv->extra_widget); } static void action_changed (XedFileChooserDialog *dialog, - GParamSpec *pspec, - gpointer data) + GParamSpec *pspec, + gpointer data) { - GtkFileChooserAction action; + GtkFileChooserAction action; - action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)); + action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)); - switch (action) - { - case GTK_FILE_CHOOSER_ACTION_OPEN: - g_object_set (dialog->priv->option_menu, - "save_mode", FALSE, - NULL); - gtk_widget_show (dialog->priv->option_menu); - break; - case GTK_FILE_CHOOSER_ACTION_SAVE: - g_object_set (dialog->priv->option_menu, - "save_mode", TRUE, - NULL); - gtk_widget_show (dialog->priv->option_menu); - break; - default: - gtk_widget_hide (dialog->priv->option_menu); - } + switch (action) + { + case GTK_FILE_CHOOSER_ACTION_OPEN: + g_object_set (dialog->priv->option_menu, "save_mode", FALSE, NULL); + gtk_widget_show (dialog->priv->option_menu); + break; + case GTK_FILE_CHOOSER_ACTION_SAVE: + g_object_set (dialog->priv->option_menu, "save_mode", TRUE, NULL); + gtk_widget_show (dialog->priv->option_menu); + break; + default: + gtk_widget_hide (dialog->priv->option_menu); + } - update_newline_visibility (dialog); + update_newline_visibility (dialog); } static void filter_changed (XedFileChooserDialog *dialog, - GParamSpec *pspec, - gpointer data) + GParamSpec *pspec, + gpointer data) { - GtkFileFilter *filter; + GtkFileFilter *filter; - if (!xed_prefs_manager_active_file_filter_can_set ()) - return; + if (!xed_prefs_manager_active_file_filter_can_set ()) + { + return; + } - filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)); - if (filter != NULL) - { - const gchar *name; - gint id = 0; + filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)); + if (filter != NULL) + { + const gchar *name; + gint id = 0; - name = gtk_file_filter_get_name (filter); - g_return_if_fail (name != NULL); + name = gtk_file_filter_get_name (filter); + g_return_if_fail (name != NULL); - if (strcmp (name, ALL_TEXT_FILES) == 0) - id = 1; + if (strcmp (name, ALL_TEXT_FILES) == 0) + { + id = 1; + } - xed_debug_message (DEBUG_COMMANDS, "Active filter: %s (%d)", name, id); + xed_debug_message (DEBUG_COMMANDS, "Active filter: %s (%d)", name, id); - xed_prefs_manager_set_active_file_filter (id); - } + xed_prefs_manager_set_active_file_filter (id); + } } /* FIXME: use globs too - Paolo (Aug. 27, 2007) */ static gboolean all_text_files_filter (const GtkFileFilterInfo *filter_info, - gpointer data) + gpointer data) { - static GSList *known_mime_types = NULL; - GSList *mime_types; + static GSList *known_mime_types = NULL; + GSList *mime_types; - if (known_mime_types == NULL) - { - GtkSourceLanguageManager *lm; - const gchar * const *languages; + if (known_mime_types == NULL) + { + GtkSourceLanguageManager *lm; + const gchar * const *languages; - lm = xed_get_language_manager (); - languages = gtk_source_language_manager_get_language_ids (lm); + lm = xed_get_language_manager (); + languages = gtk_source_language_manager_get_language_ids (lm); - while ((languages != NULL) && (*languages != NULL)) - { - gchar **mime_types; - gint i; - GtkSourceLanguage *lang; + while ((languages != NULL) && (*languages != NULL)) + { + gchar **mime_types; + gint i; + GtkSourceLanguage *lang; - lang = gtk_source_language_manager_get_language (lm, *languages); - g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (lang), FALSE); - ++languages; + lang = gtk_source_language_manager_get_language (lm, *languages); + g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (lang), FALSE); + ++languages; - mime_types = gtk_source_language_get_mime_types (lang); - if (mime_types == NULL) - continue; + mime_types = gtk_source_language_get_mime_types (lang); + if (mime_types == NULL) + { + continue; + } - for (i = 0; mime_types[i] != NULL; i++) - { - if (!g_content_type_is_a (mime_types[i], "text/plain")) - { - xed_debug_message (DEBUG_COMMANDS, - "Mime-type %s is not related to text/plain", - mime_types[i]); + for (i = 0; mime_types[i] != NULL; i++) + { + if (!g_content_type_is_a (mime_types[i], "text/plain")) + { + xed_debug_message (DEBUG_COMMANDS, + "Mime-type %s is not related to text/plain", + mime_types[i]); - known_mime_types = g_slist_prepend (known_mime_types, - g_strdup (mime_types[i])); - } - } + known_mime_types = g_slist_prepend (known_mime_types, g_strdup (mime_types[i])); + } + } - g_strfreev (mime_types); - } + g_strfreev (mime_types); + } - /* known_mime_types always has "text/plain" as first item" */ - known_mime_types = g_slist_prepend (known_mime_types, g_strdup ("text/plain")); - } + /* known_mime_types always has "text/plain" as first item" */ + known_mime_types = g_slist_prepend (known_mime_types, g_strdup ("text/plain")); + } - /* known mime_types contains "text/plain" and then the list of mime-types unrelated to "text/plain" - * that xed recognizes */ + /* known mime_types contains "text/plain" and then the list of mime-types unrelated to "text/plain" + * that xed recognizes */ - if (filter_info->mime_type == NULL) - return FALSE; + if (filter_info->mime_type == NULL) + { + return FALSE; + } - /* - * The filter is matching: - * - the mime-types beginning with "text/" - * - the mime-types inheriting from a known mime-type (note the text/plain is - * the first known mime-type) - */ + /* + * The filter is matching: + * - the mime-types beginning with "text/" + * - the mime-types inheriting from a known mime-type (note the text/plain is + * the first known mime-type) + */ - if (strncmp (filter_info->mime_type, "text/", 5) == 0) - return TRUE; + if (strncmp (filter_info->mime_type, "text/", 5) == 0) + { + return TRUE; + } - mime_types = known_mime_types; - while (mime_types != NULL) - { - if (g_content_type_is_a (filter_info->mime_type, (const gchar*)mime_types->data)) - return TRUE; + mime_types = known_mime_types; + while (mime_types != NULL) + { + if (g_content_type_is_a (filter_info->mime_type, (const gchar*)mime_types->data)) + { + return TRUE; + } - mime_types = g_slist_next (mime_types); - } + mime_types = g_slist_next (mime_types); + } - return FALSE; + return FALSE; } static void xed_file_chooser_dialog_init (XedFileChooserDialog *dialog) { - dialog->priv = XED_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog); + dialog->priv = XED_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog); } static GtkWidget * xed_file_chooser_dialog_new_valist (const gchar *title, - GtkWindow *parent, - GtkFileChooserAction action, - const XedEncoding *encoding, - const gchar *first_button_text, - va_list varargs) + GtkWindow *parent, + GtkFileChooserAction action, + const XedEncoding *encoding, + const gchar *first_button_text, + va_list varargs) { - GtkWidget *result; - const char *button_text = first_button_text; - gint response_id; - GtkFileFilter *filter; - gint active_filter; + GtkWidget *result; + const char *button_text = first_button_text; + gint response_id; + GtkFileFilter *filter; + gint active_filter; - g_return_val_if_fail (parent != NULL, NULL); + g_return_val_if_fail (parent != NULL, NULL); - result = g_object_new (XED_TYPE_FILE_CHOOSER_DIALOG, - "title", title, - "local-only", FALSE, - "action", action, - "select-multiple", action == GTK_FILE_CHOOSER_ACTION_OPEN, - NULL); + result = g_object_new (XED_TYPE_FILE_CHOOSER_DIALOG, + "title", title, + "local-only", FALSE, + "action", action, + "select-multiple", action == GTK_FILE_CHOOSER_ACTION_OPEN, + NULL); - create_extra_widget (XED_FILE_CHOOSER_DIALOG (result)); + create_extra_widget (XED_FILE_CHOOSER_DIALOG (result)); - g_signal_connect (result, - "notify::action", - G_CALLBACK (action_changed), - NULL); + g_signal_connect (result, "notify::action", + G_CALLBACK (action_changed), NULL); - if (encoding != NULL) - xed_encodings_combo_box_set_selected_encoding ( - XED_ENCODINGS_COMBO_BOX (XED_FILE_CHOOSER_DIALOG (result)->priv->option_menu), - encoding); + if (encoding != NULL) + { + xed_encodings_combo_box_set_selected_encoding ( + XED_ENCODINGS_COMBO_BOX (XED_FILE_CHOOSER_DIALOG (result)->priv->option_menu), encoding); + } - active_filter = xed_prefs_manager_get_active_file_filter (); - xed_debug_message (DEBUG_COMMANDS, "Active filter: %d", active_filter); + active_filter = xed_prefs_manager_get_active_file_filter (); + xed_debug_message (DEBUG_COMMANDS, "Active filter: %d", active_filter); - /* Filters */ - filter = gtk_file_filter_new (); + /* Filters */ + filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, ALL_FILES); - gtk_file_filter_add_pattern (filter, "*"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (result), filter); - gtk_file_chooser_set_action (GTK_FILE_CHOOSER (result), action); + gtk_file_filter_set_name (filter, ALL_FILES); + gtk_file_filter_add_pattern (filter, "*"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (result), filter); + gtk_file_chooser_set_action (GTK_FILE_CHOOSER (result), action); - if (active_filter != 1) - { - /* Make this filter the default */ - gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (result), filter); - } + if (active_filter != 1) + { + /* Make this filter the default */ + gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (result), filter); + } - filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, ALL_TEXT_FILES); - gtk_file_filter_add_custom (filter, - GTK_FILE_FILTER_MIME_TYPE, - all_text_files_filter, - NULL, - NULL); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (result), filter); + filter = gtk_file_filter_new (); + gtk_file_filter_set_name (filter, ALL_TEXT_FILES); + gtk_file_filter_add_custom (filter, GTK_FILE_FILTER_MIME_TYPE, all_text_files_filter, NULL, NULL); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (result), filter); - if (active_filter == 1) - { - /* Make this filter the default */ - gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (result), filter); - } + if (active_filter == 1) + { + /* Make this filter the default */ + gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (result), filter); + } - g_signal_connect (result, - "notify::filter", - G_CALLBACK (filter_changed), - NULL); + g_signal_connect (result, "notify::filter", + G_CALLBACK (filter_changed), NULL); - gtk_window_set_transient_for (GTK_WINDOW (result), parent); - gtk_window_set_destroy_with_parent (GTK_WINDOW (result), TRUE); + gtk_window_set_transient_for (GTK_WINDOW (result), parent); + gtk_window_set_destroy_with_parent (GTK_WINDOW (result), TRUE); - while (button_text) - { - response_id = va_arg (varargs, gint); + while (button_text) + { + response_id = va_arg (varargs, gint); - gtk_dialog_add_button (GTK_DIALOG (result), button_text, response_id); - if ((response_id == GTK_RESPONSE_OK) || - (response_id == GTK_RESPONSE_ACCEPT) || - (response_id == GTK_RESPONSE_YES) || - (response_id == GTK_RESPONSE_APPLY)) - gtk_dialog_set_default_response (GTK_DIALOG (result), response_id); + gtk_dialog_add_button (GTK_DIALOG (result), button_text, response_id); + if ((response_id == GTK_RESPONSE_OK) || + (response_id == GTK_RESPONSE_ACCEPT) || + (response_id == GTK_RESPONSE_YES) || + (response_id == GTK_RESPONSE_APPLY)) + { + gtk_dialog_set_default_response (GTK_DIALOG (result), response_id); + } - button_text = va_arg (varargs, const gchar *); - } + button_text = va_arg (varargs, const gchar *); + } - return result; + return result; } /** @@ -466,98 +430,87 @@ xed_file_chooser_dialog_new_valist (const gchar *title, **/ GtkWidget * xed_file_chooser_dialog_new (const gchar *title, - GtkWindow *parent, - GtkFileChooserAction action, - const XedEncoding *encoding, - const gchar *first_button_text, - ...) + GtkWindow *parent, + GtkFileChooserAction action, + const XedEncoding *encoding, + const gchar *first_button_text, + ...) { - GtkWidget *result; - va_list varargs; + GtkWidget *result; + va_list varargs; - va_start (varargs, first_button_text); - result = xed_file_chooser_dialog_new_valist (title, parent, action, - encoding, first_button_text, - varargs); - va_end (varargs); + va_start (varargs, first_button_text); + result = xed_file_chooser_dialog_new_valist (title, parent, action, encoding, first_button_text, varargs); + va_end (varargs); - return result; + return result; } void xed_file_chooser_dialog_set_encoding (XedFileChooserDialog *dialog, - const XedEncoding *encoding) + const XedEncoding *encoding) { - g_return_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog)); - g_return_if_fail (XED_IS_ENCODINGS_COMBO_BOX (dialog->priv->option_menu)); + g_return_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog)); + g_return_if_fail (XED_IS_ENCODINGS_COMBO_BOX (dialog->priv->option_menu)); - xed_encodings_combo_box_set_selected_encoding ( - XED_ENCODINGS_COMBO_BOX (dialog->priv->option_menu), - encoding); + xed_encodings_combo_box_set_selected_encoding (XED_ENCODINGS_COMBO_BOX (dialog->priv->option_menu), encoding); } const XedEncoding * xed_file_chooser_dialog_get_encoding (XedFileChooserDialog *dialog) { - g_return_val_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog), NULL); - g_return_val_if_fail (XED_IS_ENCODINGS_COMBO_BOX (dialog->priv->option_menu), NULL); - g_return_val_if_fail ((gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_OPEN || - gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE), NULL); + g_return_val_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog), NULL); + g_return_val_if_fail (XED_IS_ENCODINGS_COMBO_BOX (dialog->priv->option_menu), NULL); + g_return_val_if_fail ((gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_OPEN || + gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE), NULL); - return xed_encodings_combo_box_get_selected_encoding ( - XED_ENCODINGS_COMBO_BOX (dialog->priv->option_menu)); + return xed_encodings_combo_box_get_selected_encoding (XED_ENCODINGS_COMBO_BOX (dialog->priv->option_menu)); } void xed_file_chooser_dialog_set_newline_type (XedFileChooserDialog *dialog, - XedDocumentNewlineType newline_type) + XedDocumentNewlineType newline_type) { - GtkTreeIter iter; - GtkTreeModel *model; + GtkTreeIter iter; + GtkTreeModel *model; - g_return_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog)); - g_return_if_fail (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE); + g_return_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog)); + g_return_if_fail (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE); - model = GTK_TREE_MODEL (dialog->priv->newline_store); + model = GTK_TREE_MODEL (dialog->priv->newline_store); - if (!gtk_tree_model_get_iter_first (model, &iter)) - { - return; - } + if (!gtk_tree_model_get_iter_first (model, &iter)) + { + return; + } - do - { - XedDocumentNewlineType nt; + do + { + XedDocumentNewlineType nt; - gtk_tree_model_get (model, &iter, 1, &nt, -1); + gtk_tree_model_get (model, &iter, 1, &nt, -1); - if (newline_type == nt) - { - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (dialog->priv->newline_combo), - &iter); - break; - } - } while (gtk_tree_model_iter_next (model, &iter)); + if (newline_type == nt) + { + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (dialog->priv->newline_combo), &iter); + break; + } + } while (gtk_tree_model_iter_next (model, &iter)); } XedDocumentNewlineType xed_file_chooser_dialog_get_newline_type (XedFileChooserDialog *dialog) { - GtkTreeIter iter; - XedDocumentNewlineType newline_type; + GtkTreeIter iter; + XedDocumentNewlineType newline_type; - g_return_val_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog), XED_DOCUMENT_NEWLINE_TYPE_DEFAULT); - g_return_val_if_fail (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE, - XED_DOCUMENT_NEWLINE_TYPE_DEFAULT); + g_return_val_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog), XED_DOCUMENT_NEWLINE_TYPE_DEFAULT); + g_return_val_if_fail (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE, + XED_DOCUMENT_NEWLINE_TYPE_DEFAULT); - gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->priv->newline_combo), - &iter); + gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->priv->newline_combo), &iter); - gtk_tree_model_get (GTK_TREE_MODEL (dialog->priv->newline_store), - &iter, - 1, - &newline_type, - -1); + gtk_tree_model_get (GTK_TREE_MODEL (dialog->priv->newline_store), &iter, 1, &newline_type, -1); - return newline_type; + return newline_type; } diff --git a/xed/xed-file-chooser-dialog.h b/xed/xed-file-chooser-dialog.h index b7cc837..53fa030 100644 --- a/xed/xed-file-chooser-dialog.h +++ b/xed/xed-file-chooser-dialog.h @@ -2,7 +2,7 @@ * xed-file-chooser-dialog.h * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -46,43 +46,40 @@ G_BEGIN_DECLS #define XED_IS_FILE_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_CHOOSER_DIALOG)) #define XED_FILE_CHOOSER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_CHOOSER_DIALOG, XedFileChooserDialogClass)) -typedef struct _XedFileChooserDialog XedFileChooserDialog; -typedef struct _XedFileChooserDialogClass XedFileChooserDialogClass; - +typedef struct _XedFileChooserDialog XedFileChooserDialog; typedef struct _XedFileChooserDialogPrivate XedFileChooserDialogPrivate; - -struct _XedFileChooserDialogClass -{ - GtkFileChooserDialogClass parent_class; -}; +typedef struct _XedFileChooserDialogClass XedFileChooserDialogClass; struct _XedFileChooserDialog { - GtkFileChooserDialog parent_instance; + GtkFileChooserDialog parent_instance; - XedFileChooserDialogPrivate *priv; + XedFileChooserDialogPrivate *priv; }; -GType xed_file_chooser_dialog_get_type (void) G_GNUC_CONST; +struct _XedFileChooserDialogClass +{ + GtkFileChooserDialogClass parent_class; +}; -GtkWidget *xed_file_chooser_dialog_new (const gchar *title, - GtkWindow *parent, - GtkFileChooserAction action, - const XedEncoding *encoding, - const gchar *first_button_text, - ...); +GType xed_file_chooser_dialog_get_type (void) G_GNUC_CONST; -void xed_file_chooser_dialog_set_encoding (XedFileChooserDialog *dialog, - const XedEncoding *encoding); +GtkWidget *xed_file_chooser_dialog_new (const gchar *title, + GtkWindow *parent, + GtkFileChooserAction action, + const XedEncoding *encoding, + const gchar *first_button_text, + ...); -const XedEncoding - *xed_file_chooser_dialog_get_encoding (XedFileChooserDialog *dialog); +void xed_file_chooser_dialog_set_encoding (XedFileChooserDialog *dialog, + const XedEncoding *encoding); -void xed_file_chooser_dialog_set_newline_type (XedFileChooserDialog *dialog, - XedDocumentNewlineType newline_type); +const XedEncoding *xed_file_chooser_dialog_get_encoding (XedFileChooserDialog *dialog); -XedDocumentNewlineType - xed_file_chooser_dialog_get_newline_type (XedFileChooserDialog *dialog); +void xed_file_chooser_dialog_set_newline_type (XedFileChooserDialog *dialog, + XedDocumentNewlineType newline_type); + +XedDocumentNewlineType xed_file_chooser_dialog_get_newline_type (XedFileChooserDialog *dialog); G_END_DECLS From c5d8a4378a536bb5308048946e48d16e216d2067 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Fri, 13 Jan 2017 03:21:50 -0800 Subject: [PATCH 089/132] xed-statusbar.c/h: Clean up code styling --- xed/xed-statusbar.c | 93 +++++++++++++++++---------------------------- xed/xed-statusbar.h | 60 ++++++++++++++--------------- 2 files changed, 65 insertions(+), 88 deletions(-) diff --git a/xed/xed-statusbar.c b/xed/xed-statusbar.c index 97499b9..97eb85c 100644 --- a/xed/xed-statusbar.c +++ b/xed/xed-statusbar.c @@ -39,26 +39,26 @@ #include "xed-statusbar.h" #define XED_STATUSBAR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object),\ - XED_TYPE_STATUSBAR,\ - XedStatusbarPrivate)) + XED_TYPE_STATUSBAR,\ + XedStatusbarPrivate)) struct _XedStatusbarPrivate { - GtkWidget *overwrite_mode_label; - GtkWidget *cursor_position_label; + GtkWidget *overwrite_mode_label; + GtkWidget *cursor_position_label; - GtkWidget *state_frame; - GtkWidget *load_image; - GtkWidget *save_image; - GtkWidget *print_image; + GtkWidget *state_frame; + GtkWidget *load_image; + GtkWidget *save_image; + GtkWidget *print_image; - GtkWidget *error_frame; - GtkWidget *error_event_box; + GtkWidget *error_frame; + GtkWidget *error_event_box; /* tmp flash timeout data */ - guint flash_timeout; - guint flash_context_id; - guint flash_message_id; + guint flash_timeout; + guint flash_context_id; + guint flash_message_id; }; G_DEFINE_TYPE(XedStatusbar, xed_statusbar, GTK_TYPE_STATUSBAR) @@ -114,25 +114,18 @@ xed_statusbar_init (XedStatusbar *statusbar) gtk_widget_set_margin_bottom (GTK_WIDGET (statusbar), 0); statusbar->priv->overwrite_mode_label = gtk_label_new (NULL); - gtk_label_set_width_chars (GTK_LABEL (statusbar->priv->overwrite_mode_label), - get_overwrite_mode_length ()); + gtk_label_set_width_chars (GTK_LABEL (statusbar->priv->overwrite_mode_label), get_overwrite_mode_length ()); gtk_widget_show (statusbar->priv->overwrite_mode_label); - gtk_box_pack_end (GTK_BOX (statusbar), - statusbar->priv->overwrite_mode_label, - FALSE, TRUE, 0); + gtk_box_pack_end (GTK_BOX (statusbar), statusbar->priv->overwrite_mode_label, FALSE, TRUE, 0); gtk_widget_set_margin_right (GTK_WIDGET (statusbar->priv->overwrite_mode_label), 6); statusbar->priv->cursor_position_label = gtk_label_new (NULL); - gtk_label_set_width_chars (GTK_LABEL (statusbar->priv->cursor_position_label), - CURSOR_POSITION_LABEL_WIDTH_CHARS); + gtk_label_set_width_chars (GTK_LABEL (statusbar->priv->cursor_position_label), CURSOR_POSITION_LABEL_WIDTH_CHARS); gtk_widget_show (statusbar->priv->cursor_position_label); - gtk_box_pack_end (GTK_BOX (statusbar), - statusbar->priv->cursor_position_label, - FALSE, TRUE, 0); + gtk_box_pack_end (GTK_BOX (statusbar), statusbar->priv->cursor_position_label, FALSE, TRUE, 0); statusbar->priv->state_frame = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (statusbar->priv->state_frame), - GTK_SHADOW_IN); + gtk_frame_set_shadow_type (GTK_FRAME (statusbar->priv->state_frame), GTK_SHADOW_IN); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_container_add (GTK_CONTAINER (statusbar->priv->state_frame), hbox); @@ -143,19 +136,11 @@ xed_statusbar_init (XedStatusbar *statusbar) gtk_widget_show (hbox); - gtk_box_pack_start (GTK_BOX (hbox), - statusbar->priv->load_image, - FALSE, TRUE, 4); - gtk_box_pack_start (GTK_BOX (hbox), - statusbar->priv->save_image, - FALSE, TRUE, 4); - gtk_box_pack_start (GTK_BOX (hbox), - statusbar->priv->print_image, - FALSE, TRUE, 4); + gtk_box_pack_start (GTK_BOX (hbox), statusbar->priv->load_image, FALSE, TRUE, 4); + gtk_box_pack_start (GTK_BOX (hbox), statusbar->priv->save_image, FALSE, TRUE, 4); + gtk_box_pack_start (GTK_BOX (hbox), statusbar->priv->print_image, FALSE, TRUE, 4); - gtk_box_pack_start (GTK_BOX (statusbar), - statusbar->priv->state_frame, - FALSE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (statusbar), statusbar->priv->state_frame, FALSE, TRUE, 0); statusbar->priv->error_frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (statusbar->priv->error_frame), GTK_SHADOW_IN); @@ -168,18 +153,13 @@ xed_statusbar_init (XedStatusbar *statusbar) gtk_widget_set_margin_bottom (error_image, 0); statusbar->priv->error_event_box = gtk_event_box_new (); - gtk_event_box_set_visible_window (GTK_EVENT_BOX (statusbar->priv->error_event_box), - FALSE); + gtk_event_box_set_visible_window (GTK_EVENT_BOX (statusbar->priv->error_event_box), FALSE); gtk_widget_show (statusbar->priv->error_event_box); - gtk_container_add (GTK_CONTAINER (statusbar->priv->error_frame), - statusbar->priv->error_event_box); - gtk_container_add (GTK_CONTAINER (statusbar->priv->error_event_box), - error_image); + gtk_container_add (GTK_CONTAINER (statusbar->priv->error_frame), statusbar->priv->error_event_box); + gtk_container_add (GTK_CONTAINER (statusbar->priv->error_event_box), error_image); - gtk_box_pack_start (GTK_BOX (statusbar), - statusbar->priv->error_frame, - FALSE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (statusbar), statusbar->priv->error_frame, FALSE, TRUE, 0); gtk_style_context_add_class (gtk_widget_get_style_context (statusbar), "xed-statusbar"); } @@ -206,7 +186,7 @@ xed_statusbar_new (void) **/ void xed_statusbar_set_overwrite (XedStatusbar *statusbar, - gboolean overwrite) + gboolean overwrite) { gchar *msg; @@ -237,8 +217,8 @@ xed_statusbar_clear_overwrite (XedStatusbar *statusbar) **/ void xed_statusbar_set_cursor_position (XedStatusbar *statusbar, - gint line, - gint col) + gint line, + gint col) { gchar *msg = NULL; @@ -279,8 +259,8 @@ remove_message_timeout (XedStatusbar *statusbar) */ void xed_statusbar_flash_message (XedStatusbar *statusbar, - guint context_id, - const gchar *format, ...) + guint context_id, + const gchar *format, ...) { const guint32 flash_length = 3000; /* three seconds */ va_list args; @@ -305,9 +285,7 @@ xed_statusbar_flash_message (XedStatusbar *statusbar, } statusbar->priv->flash_context_id = context_id; - statusbar->priv->flash_message_id = gtk_statusbar_push (GTK_STATUSBAR (statusbar), - context_id, - msg); + statusbar->priv->flash_message_id = gtk_statusbar_push (GTK_STATUSBAR (statusbar), context_id, msg); statusbar->priv->flash_timeout = g_timeout_add (flash_length, (GSourceFunc) remove_message_timeout, @@ -318,8 +296,8 @@ xed_statusbar_flash_message (XedStatusbar *statusbar, void xed_statusbar_set_window_state (XedStatusbar *statusbar, - XedWindowState state, - gint num_of_errors) + XedWindowState state, + gint num_of_errors) { g_return_if_fail (XED_IS_STATUSBAR (statusbar)); @@ -354,8 +332,7 @@ xed_statusbar_set_window_state (XedStatusbar *statusbar, num_of_errors), num_of_errors); - gtk_widget_set_tooltip_text (statusbar->priv->error_event_box, - tip); + gtk_widget_set_tooltip_text (statusbar->priv->error_event_box, tip); g_free (tip); gtk_widget_show (statusbar->priv->error_frame); diff --git a/xed/xed-statusbar.h b/xed/xed-statusbar.h index cda2537..47c8002 100644 --- a/xed/xed-statusbar.h +++ b/xed/xed-statusbar.h @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. */ #ifndef XED_STATUSBAR_H @@ -34,22 +34,22 @@ G_BEGIN_DECLS -#define XED_TYPE_STATUSBAR (xed_statusbar_get_type ()) -#define XED_STATUSBAR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_STATUSBAR, XedStatusbar)) -#define XED_STATUSBAR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_STATUSBAR, XedStatusbarClass)) -#define XED_IS_STATUSBAR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_STATUSBAR)) -#define XED_IS_STATUSBAR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_STATUSBAR)) -#define XED_STATUSBAR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_STATUSBAR, XedStatusbarClass)) +#define XED_TYPE_STATUSBAR (xed_statusbar_get_type ()) +#define XED_STATUSBAR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_STATUSBAR, XedStatusbar)) +#define XED_STATUSBAR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_STATUSBAR, XedStatusbarClass)) +#define XED_IS_STATUSBAR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_STATUSBAR)) +#define XED_IS_STATUSBAR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_STATUSBAR)) +#define XED_STATUSBAR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_STATUSBAR, XedStatusbarClass)) -typedef struct _XedStatusbar XedStatusbar; -typedef struct _XedStatusbarPrivate XedStatusbarPrivate; -typedef struct _XedStatusbarClass XedStatusbarClass; +typedef struct _XedStatusbar XedStatusbar; +typedef struct _XedStatusbarPrivate XedStatusbarPrivate; +typedef struct _XedStatusbarClass XedStatusbarClass; struct _XedStatusbar { GtkStatusbar parent; - /* */ + /* */ XedStatusbarPrivate *priv; }; @@ -58,29 +58,29 @@ struct _XedStatusbarClass GtkStatusbarClass parent_class; }; -GType xed_statusbar_get_type (void) G_GNUC_CONST; +GType xed_statusbar_get_type (void) G_GNUC_CONST; -GtkWidget *xed_statusbar_new (void); +GtkWidget *xed_statusbar_new (void); /* FIXME: status is not defined in any .h */ #define XedStatus gint -void xed_statusbar_set_window_state (XedStatusbar *statusbar, - XedWindowState state, - gint num_of_errors); +void xed_statusbar_set_window_state (XedStatusbar *statusbar, + XedWindowState state, + gint num_of_errors); -void xed_statusbar_set_overwrite (XedStatusbar *statusbar, - gboolean overwrite); +void xed_statusbar_set_overwrite (XedStatusbar *statusbar, + gboolean overwrite); -void xed_statusbar_set_cursor_position (XedStatusbar *statusbar, - gint line, - gint col); +void xed_statusbar_set_cursor_position (XedStatusbar *statusbar, + gint line, + gint col); -void xed_statusbar_clear_overwrite (XedStatusbar *statusbar); +void xed_statusbar_clear_overwrite (XedStatusbar *statusbar); -void xed_statusbar_flash_message (XedStatusbar *statusbar, - guint context_id, - const gchar *format, - ...) G_GNUC_PRINTF(3, 4); +void xed_statusbar_flash_message (XedStatusbar *statusbar, + guint context_id, + const gchar *format, + ...) G_GNUC_PRINTF(3, 4); G_END_DECLS From d38b1cd953f607f0a08041fde12b6e15970de221 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Fri, 13 Jan 2017 03:24:27 -0800 Subject: [PATCH 090/132] xed-statusbar: Fix a missing cast --- xed/xed-statusbar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xed/xed-statusbar.c b/xed/xed-statusbar.c index 97eb85c..68fb289 100644 --- a/xed/xed-statusbar.c +++ b/xed/xed-statusbar.c @@ -161,7 +161,7 @@ xed_statusbar_init (XedStatusbar *statusbar) gtk_box_pack_start (GTK_BOX (statusbar), statusbar->priv->error_frame, FALSE, TRUE, 0); - gtk_style_context_add_class (gtk_widget_get_style_context (statusbar), "xed-statusbar"); + gtk_style_context_add_class (gtk_widget_get_style_context GTK_WIDGET (statusbar), "xed-statusbar"); } /** From 5267b52c7011941fefb70ef18a906707de795535 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Fri, 13 Jan 2017 03:33:53 -0800 Subject: [PATCH 091/132] xed-searchbar: Add a couple missing casts and remove an unused variable --- xed/xed-searchbar.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/xed/xed-searchbar.c b/xed/xed-searchbar.c index 09de427..0fae5de 100755 --- a/xed/xed-searchbar.c +++ b/xed/xed-searchbar.c @@ -51,9 +51,8 @@ static void xed_searchbar_class_init (XedSearchbarClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); - GtkBindingSet *binding_set; + g_type_class_add_private (object_class, sizeof(XedSearchbarPrivate)); - binding_set = gtk_binding_set_by_class (klass); } #define XED_SEARCHBAR_KEY "xed-searchbar-key" @@ -564,7 +563,7 @@ xed_searchbar_init (XedSearchbar *searchbar) NULL); g_free (file); - gtk_style_context_add_class (gtk_widget_get_style_context (searchbar), "xed-searchbar"); + gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (searchbar)), "xed-searchbar"); searchbar->priv->search_entry = xed_history_entry_new ("history-search-for", TRUE); gtk_widget_set_hexpand (searchbar->priv->search_entry, TRUE); @@ -653,7 +652,7 @@ xed_searchbar_new (GtkWindow *parent, { XedSearchbar *searchbar; searchbar = g_object_new (XED_TYPE_SEARCHBAR, NULL); - searchbar->window = parent; + searchbar->window = XED_WINDOW (parent); return GTK_WIDGET(searchbar); } From 6a997b1b79dee3009dcb857f9942814d1cb12fd7 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Fri, 13 Jan 2017 03:49:38 -0800 Subject: [PATCH 092/132] xed-searchbar.c/h: Clean up styling a bit --- xed/xed-searchbar.c | 225 +++++++++++++++++++++++--------------------- xed/xed-searchbar.h | 19 +--- 2 files changed, 119 insertions(+), 125 deletions(-) diff --git a/xed/xed-searchbar.c b/xed/xed-searchbar.c index 0fae5de..1dbb842 100755 --- a/xed/xed-searchbar.c +++ b/xed/xed-searchbar.c @@ -21,12 +21,14 @@ /* Signals */ enum { - SHOW_REPLACE, LAST_SIGNAL + SHOW_REPLACE, + LAST_SIGNAL }; struct _XedSearchbarPrivate { gboolean show_replace; + GtkWidget *revealer; GtkWidget *grid; GtkWidget *search_label; @@ -50,7 +52,7 @@ G_DEFINE_TYPE(XedSearchbar, xed_searchbar, GTK_TYPE_BOX) static void xed_searchbar_class_init (XedSearchbarClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); g_type_class_add_private (object_class, sizeof(XedSearchbarPrivate)); } @@ -61,46 +63,51 @@ xed_searchbar_class_init (XedSearchbarClass *klass) /* Use occurrences only for Replace All */ static void text_found (XedWindow *window, - gint occurrences) + gint occurrences) { if (occurrences > 1) { - xed_statusbar_flash_message (XED_STATUSBAR(window->priv->statusbar), window->priv->generic_message_cid, - ngettext ("Found and replaced %d occurrence", "Found and replaced %d occurrences", occurrences), - occurrences); + xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar), + window->priv->generic_message_cid, + ngettext ("Found and replaced %d occurrence", "Found and replaced %d occurrences", + occurrences), + occurrences); } else { if (occurrences == 1) { - xed_statusbar_flash_message (XED_STATUSBAR(window->priv->statusbar), window->priv->generic_message_cid, + xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar), + window->priv->generic_message_cid, _("Found and replaced one occurrence")); } else { - xed_statusbar_flash_message (XED_STATUSBAR(window->priv->statusbar), window->priv->generic_message_cid, + xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar), + window->priv->generic_message_cid, " "); } } } static void -text_not_found (XedWindow *window, +text_not_found (XedWindow *window, const gchar *text) { gchar *searched; searched = xed_utils_str_end_truncate (text, MAX_MSG_LENGTH); - xed_statusbar_flash_message (XED_STATUSBAR(window->priv->statusbar), window->priv->generic_message_cid, + xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar), + window->priv->generic_message_cid, _("\"%s\" not found"), searched); g_free (searched); } static gboolean -run_search (XedView *view, - gboolean wrap_around, - gboolean search_backwards, - gboolean jump_to_next_result) +run_search (XedView *view, + gboolean wrap_around, + gboolean search_backwards, + gboolean jump_to_next_result) { XedDocument *doc; GtkTextIter start_iter; @@ -110,14 +117,16 @@ run_search (XedView *view, gboolean found = FALSE; doc = XED_DOCUMENT(gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); - gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER(doc), &start_iter, &end_iter); + gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &start_iter, &end_iter); if (!search_backwards) { - if (jump_to_next_result) { + if (jump_to_next_result) + { found = xed_document_search_forward (doc, &end_iter, NULL, &match_start, &match_end); } - else { + else + { found = xed_document_search_forward (doc, &start_iter, NULL, &match_start, &match_end); } } @@ -142,13 +151,13 @@ run_search (XedView *view, if (found) { - gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER(doc), &match_start); - gtk_text_buffer_move_mark_by_name (GTK_TEXT_BUFFER(doc), "selection_bound", &match_end); + gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &match_start); + gtk_text_buffer_move_mark_by_name (GTK_TEXT_BUFFER (doc), "selection_bound", &match_end); xed_view_scroll_to_cursor (view); } else { - gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER(doc), &start_iter); + gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &start_iter); } return found; @@ -156,8 +165,8 @@ run_search (XedView *view, static void do_find (XedSearchbar *searchbar, - gboolean search_backwards, - gboolean jump_to_next_result) + gboolean search_backwards, + gboolean jump_to_next_result) { XedView *active_view; XedDocument *doc; @@ -178,15 +187,15 @@ do_find (XedSearchbar *searchbar, return; } - doc = XED_DOCUMENT(gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view))); + doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view))); match_case = xed_searchbar_get_match_case (searchbar); entire_word = xed_searchbar_get_entire_word (searchbar); wrap_around = xed_searchbar_get_wrap_around (searchbar); entry_text = xed_searchbar_get_search_text (searchbar); - XED_SEARCH_SET_CASE_SENSITIVE(flags, match_case); - XED_SEARCH_SET_ENTIRE_WORD(flags, entire_word); + XED_SEARCH_SET_CASE_SENSITIVE (flags, match_case); + XED_SEARCH_SET_ENTIRE_WORD (flags, entire_word); search_text = xed_document_get_search_text (doc, &old_flags); @@ -211,20 +220,20 @@ do_find (XedSearchbar *searchbar, void xed_searchbar_find_again (XedSearchbar *searchbar, - gboolean backward) + gboolean backward) { XedView *active_view; gboolean wrap_around = TRUE; gpointer data; active_view = xed_window_get_active_view (searchbar->window); - g_return_if_fail(active_view != NULL); + g_return_if_fail (active_view != NULL); - data = g_object_get_data (G_OBJECT(searchbar->window), XED_SEARCHBAR_KEY); + data = g_object_get_data (G_OBJECT (searchbar->window), XED_SEARCHBAR_KEY); if (data != NULL) { - wrap_around = xed_searchbar_get_wrap_around (XED_SEARCHBAR(data)); + wrap_around = xed_searchbar_get_wrap_around (XED_SEARCHBAR (data)); } run_search (active_view, wrap_around, backward, TRUE); @@ -232,7 +241,7 @@ xed_searchbar_find_again (XedSearchbar *searchbar, static void search_buttons_set_sensitive (XedSearchbar *searchbar, - gboolean sensitive) + gboolean sensitive) { gtk_widget_set_sensitive (searchbar->priv->find_button, sensitive); gtk_widget_set_sensitive (searchbar->priv->find_prev_button, sensitive); @@ -242,14 +251,14 @@ search_buttons_set_sensitive (XedSearchbar *searchbar, /* FIXME: move in xed-document.c and share it with xed-view */ static gboolean -get_selected_text (GtkTextBuffer *doc, - gchar **selected_text, - gint *len) +get_selected_text (GtkTextBuffer *doc, + gchar **selected_text, + gint *len) { GtkTextIter start, end; - g_return_val_if_fail(selected_text != NULL, FALSE); - g_return_val_if_fail(*selected_text == NULL, FALSE); + g_return_val_if_fail (selected_text != NULL, FALSE); + g_return_val_if_fail (*selected_text == NULL, FALSE); if (!gtk_text_buffer_get_selection_bounds (doc, &start, &end)) { @@ -272,10 +281,10 @@ get_selected_text (GtkTextBuffer *doc, static void replace_selected_text (GtkTextBuffer *buffer, - const gchar *replace) + const gchar *replace) { - g_return_if_fail(gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)); - g_return_if_fail(replace != NULL); + g_return_if_fail (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)); + g_return_if_fail (replace != NULL); gtk_text_buffer_begin_user_action (buffer); gtk_text_buffer_delete_selection (buffer, FALSE, TRUE); @@ -301,25 +310,25 @@ do_replace (XedSearchbar *searchbar) } search_entry_text = xed_searchbar_get_search_text (searchbar); - g_return_if_fail((search_entry_text) != NULL); - g_return_if_fail((*search_entry_text) != '\0'); + g_return_if_fail ((search_entry_text) != NULL); + g_return_if_fail ((*search_entry_text) != '\0'); /* replace text may be "", we just delete */ replace_entry_text = xed_searchbar_get_replace_text (searchbar); - g_return_if_fail((replace_entry_text) != NULL); + g_return_if_fail ((replace_entry_text) != NULL); unescaped_search_text = xed_utils_unescape_search_text (search_entry_text); - get_selected_text (GTK_TEXT_BUFFER(doc), &selected_text, NULL); + get_selected_text (GTK_TEXT_BUFFER (doc), &selected_text, NULL); match_case = xed_searchbar_get_match_case (searchbar); - if ((selected_text == NULL) - || (match_case && (strcmp (selected_text, unescaped_search_text) != 0)) - || (!match_case && !g_utf8_caselessnmatch (selected_text, - unescaped_search_text, - strlen (selected_text), - strlen (unescaped_search_text)) != 0)) + if ((selected_text == NULL) || + (match_case && (strcmp (selected_text, unescaped_search_text) != 0)) || + (!match_case && !g_utf8_caselessnmatch (selected_text, + unescaped_search_text, + strlen (selected_text), + strlen (unescaped_search_text)) != 0)) { do_find (searchbar, FALSE, TRUE ); g_free (unescaped_search_text); @@ -329,7 +338,7 @@ do_replace (XedSearchbar *searchbar) } unescaped_replace_text = xed_utils_unescape_search_text (replace_entry_text); - replace_selected_text (GTK_TEXT_BUFFER(doc), unescaped_replace_text); + replace_selected_text (GTK_TEXT_BUFFER (doc), unescaped_replace_text); g_free (unescaped_search_text); g_free (selected_text); @@ -356,21 +365,21 @@ do_replace_all (XedSearchbar *searchbar) return; } - doc = XED_DOCUMENT(gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view))); + doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view))); search_entry_text = xed_searchbar_get_search_text (searchbar); - g_return_if_fail((search_entry_text) != NULL); - g_return_if_fail((*search_entry_text) != '\0'); + g_return_if_fail ((search_entry_text) != NULL); + g_return_if_fail ((*search_entry_text) != '\0'); /* replace text may be "", we just delete all occurrences */ replace_entry_text = xed_searchbar_get_replace_text (searchbar); - g_return_if_fail((replace_entry_text) != NULL); + g_return_if_fail ((replace_entry_text) != NULL); match_case = xed_searchbar_get_match_case (searchbar); entire_word = xed_searchbar_get_entire_word (searchbar); - XED_SEARCH_SET_CASE_SENSITIVE(flags, match_case); - XED_SEARCH_SET_ENTIRE_WORD(flags, entire_word); + XED_SEARCH_SET_CASE_SENSITIVE (flags, match_case); + XED_SEARCH_SET_ENTIRE_WORD (flags, entire_word); count = xed_document_replace_all (doc, search_entry_text, replace_entry_text, flags); @@ -388,9 +397,9 @@ do_replace_all (XedSearchbar *searchbar) static void insert_text_handler (GtkEditable *editable, const gchar *text, - gint length, - gint *position, - gpointer data) + gint length, + gint *position, + gpointer data) { static gboolean insert_text = FALSE; gchar *escaped_text; @@ -473,7 +482,7 @@ remember_replace_entry (XedSearchbar *searchbar) } static void -find_button_clicked_callback (GtkWidget *button, +find_button_clicked_callback (GtkWidget *button, XedSearchbar *searchbar) { remember_search_entry (searchbar); @@ -481,15 +490,15 @@ find_button_clicked_callback (GtkWidget *button, } static void -toggle_button_clicked_callback (GtkWidget *button, - XedSearchbar *searchbar) +toggle_button_clicked_callback (GtkWidget *button, + XedSearchbar *searchbar) { remember_search_entry (searchbar); do_find (searchbar, FALSE, FALSE); } static void -find_prev_button_clicked_callback (GtkWidget *button, +find_prev_button_clicked_callback (GtkWidget *button, XedSearchbar *searchbar) { remember_search_entry (searchbar); @@ -497,7 +506,7 @@ find_prev_button_clicked_callback (GtkWidget *button, } static void -replace_button_clicked_callback (GtkWidget *button, +replace_button_clicked_callback (GtkWidget *button, XedSearchbar *searchbar) { remember_search_entry (searchbar); @@ -506,7 +515,7 @@ replace_button_clicked_callback (GtkWidget *button, } static void -replace_all_button_clicked_callback (GtkWidget *button, +replace_all_button_clicked_callback (GtkWidget *button, XedSearchbar *searchbar) { remember_search_entry (searchbar); @@ -515,7 +524,7 @@ replace_all_button_clicked_callback (GtkWidget *button, } static void -on_search_text_entry_activated (GtkEntry *widget, +on_search_text_entry_activated (GtkEntry *widget, XedSearchbar *searchbar) { remember_search_entry (searchbar); @@ -523,7 +532,7 @@ on_search_text_entry_activated (GtkEntry *widget, } static void -close_button_clicked_callback (GtkWidget *button, +close_button_clicked_callback (GtkWidget *button, XedSearchbar *searchbar) { xed_searchbar_hide (searchbar); @@ -577,7 +586,7 @@ xed_searchbar_init (XedSearchbar *searchbar) gtk_grid_attach (GTK_GRID (searchbar->priv->grid), searchbar->priv->search_entry, 2, 0, 1, 1); searchbar->priv->replace_entry = xed_history_entry_new ("history-replace-with", TRUE); - xed_history_entry_set_escape_func (XED_HISTORY_ENTRY(searchbar->priv->replace_entry), + xed_history_entry_set_escape_func (XED_HISTORY_ENTRY (searchbar->priv->replace_entry), (XedHistoryEntryEscapeFunc) xed_utils_escape_search_text); searchbar->priv->replace_text_entry = xed_history_entry_get_entry ( @@ -648,17 +657,17 @@ xed_searchbar_init (XedSearchbar *searchbar) GtkWidget * xed_searchbar_new (GtkWindow *parent, - gboolean show_replace) + gboolean show_replace) { XedSearchbar *searchbar; searchbar = g_object_new (XED_TYPE_SEARCHBAR, NULL); searchbar->window = XED_WINDOW (parent); - return GTK_WIDGET(searchbar); + return GTK_WIDGET (searchbar); } void xed_searchbar_show (XedSearchbar *searchbar, - gboolean show_replace) + gboolean show_replace) { XedDocument *doc; gboolean selection_exists; @@ -667,9 +676,9 @@ xed_searchbar_show (XedSearchbar *searchbar, gint sel_len; doc = xed_window_get_active_document (searchbar->window); - g_return_if_fail(doc != NULL); + g_return_if_fail (doc != NULL); - selection_exists = get_selected_text (GTK_TEXT_BUFFER(doc), &find_text, &sel_len); + selection_exists = get_selected_text (GTK_TEXT_BUFFER (doc), &find_text, &sel_len); if (selection_exists && find_text != NULL && sel_len < 80) { @@ -680,11 +689,11 @@ xed_searchbar_show (XedSearchbar *searchbar, * search for '\n' and then open the search searchbar again, * you'll get an unprintable single-character literal '\n' in the "search for" box). */ - search_text = xed_searchbar_get_search_text (XED_SEARCHBAR(searchbar)); + search_text = xed_searchbar_get_search_text (XED_SEARCHBAR (searchbar)); if (!(search_text != NULL && !strcmp (xed_utils_unescape_search_text (search_text), find_text))) { /* General case */ - xed_searchbar_set_search_text (XED_SEARCHBAR(searchbar), find_text); + xed_searchbar_set_search_text (XED_SEARCHBAR (searchbar), find_text); } g_free (find_text); } @@ -692,15 +701,15 @@ xed_searchbar_show (XedSearchbar *searchbar, { g_free (find_text); } - gtk_revealer_set_transition_type (GTK_REVEALER(searchbar->priv->revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP); - gtk_revealer_set_reveal_child (GTK_REVEALER(searchbar->priv->revealer), TRUE); + gtk_revealer_set_transition_type (GTK_REVEALER (searchbar->priv->revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP); + gtk_revealer_set_reveal_child (GTK_REVEALER (searchbar->priv->revealer), TRUE); if (show_replace) { gtk_widget_show (searchbar->priv->replace_label); gtk_widget_show (searchbar->priv->replace_entry); gtk_widget_show (searchbar->priv->replace_all_button); gtk_widget_show (searchbar->priv->replace_button); - gtk_grid_set_row_spacing (GTK_GRID(searchbar->priv->grid), 10); + gtk_grid_set_row_spacing (GTK_GRID (searchbar->priv->grid), 10); } else { @@ -708,7 +717,7 @@ xed_searchbar_show (XedSearchbar *searchbar, gtk_widget_hide (searchbar->priv->replace_entry); gtk_widget_hide (searchbar->priv->replace_all_button); gtk_widget_hide (searchbar->priv->replace_button); - gtk_grid_set_row_spacing (GTK_GRID(searchbar->priv->grid), 0); + gtk_grid_set_row_spacing (GTK_GRID (searchbar->priv->grid), 0); } gtk_widget_show (searchbar->priv->find_button); @@ -718,14 +727,14 @@ xed_searchbar_show (XedSearchbar *searchbar, void xed_searchbar_hide (XedSearchbar *searchbar) { - gtk_revealer_set_transition_type (GTK_REVEALER(searchbar->priv->revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN); - gtk_revealer_set_reveal_child (GTK_REVEALER(searchbar->priv->revealer), FALSE); + gtk_revealer_set_transition_type (GTK_REVEALER (searchbar->priv->revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN); + gtk_revealer_set_reveal_child (GTK_REVEALER (searchbar->priv->revealer), FALSE); // focus document XedView *active_view = xed_window_get_active_view (searchbar->window); if (active_view != NULL) { - gtk_widget_grab_focus (GTK_WIDGET(active_view)); + gtk_widget_grab_focus (GTK_WIDGET (active_view)); } // remove highlighting @@ -734,11 +743,11 @@ xed_searchbar_hide (XedSearchbar *searchbar) void xed_searchbar_set_search_text (XedSearchbar *searchbar, - const gchar *text) + const gchar *text) { - g_return_if_fail(XED_IS_SEARCHBAR (searchbar)); - g_return_if_fail(text != NULL); - gtk_entry_set_text (GTK_ENTRY(searchbar->priv->search_text_entry), text); + g_return_if_fail (XED_IS_SEARCHBAR (searchbar)); + g_return_if_fail (text != NULL); + gtk_entry_set_text (GTK_ENTRY (searchbar->priv->search_text_entry), text); search_buttons_set_sensitive (searchbar, (text != '\0')); } @@ -748,68 +757,68 @@ xed_searchbar_set_search_text (XedSearchbar *searchbar, const gchar * xed_searchbar_get_search_text (XedSearchbar *searchbar) { - g_return_val_if_fail(XED_IS_SEARCHBAR (searchbar), NULL); - return gtk_entry_get_text (GTK_ENTRY(searchbar->priv->search_text_entry)); + g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), NULL); + return gtk_entry_get_text (GTK_ENTRY (searchbar->priv->search_text_entry)); } void xed_searchbar_set_replace_text (XedSearchbar *searchbar, - const gchar *text) + const gchar *text) { - g_return_if_fail(XED_IS_SEARCHBAR (searchbar)); - g_return_if_fail(text != NULL); + g_return_if_fail (XED_IS_SEARCHBAR (searchbar)); + g_return_if_fail (text != NULL); - gtk_entry_set_text (GTK_ENTRY(searchbar->priv->replace_text_entry), text); + gtk_entry_set_text (GTK_ENTRY (searchbar->priv->replace_text_entry), text); } const gchar * xed_searchbar_get_replace_text (XedSearchbar *searchbar) { - g_return_val_if_fail(XED_IS_SEARCHBAR (searchbar), NULL); - return gtk_entry_get_text (GTK_ENTRY(searchbar->priv->replace_text_entry)); + g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), NULL); + return gtk_entry_get_text (GTK_ENTRY (searchbar->priv->replace_text_entry)); } void xed_searchbar_set_match_case (XedSearchbar *searchbar, - gboolean match_case) + gboolean match_case) { - g_return_if_fail(XED_IS_SEARCHBAR (searchbar)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(searchbar->priv->match_case_checkbutton), match_case); + g_return_if_fail (XED_IS_SEARCHBAR (searchbar)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (searchbar->priv->match_case_checkbutton), match_case); } gboolean xed_searchbar_get_match_case (XedSearchbar *searchbar) { - g_return_val_if_fail(XED_IS_SEARCHBAR (searchbar), FALSE); - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(searchbar->priv->match_case_checkbutton)); + g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), FALSE); + return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (searchbar->priv->match_case_checkbutton)); } void xed_searchbar_set_entire_word (XedSearchbar *searchbar, - gboolean entire_word) + gboolean entire_word) { - g_return_if_fail(XED_IS_SEARCHBAR (searchbar)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(searchbar->priv->entire_word_checkbutton), entire_word); + g_return_if_fail (XED_IS_SEARCHBAR (searchbar)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (searchbar->priv->entire_word_checkbutton), entire_word); } gboolean xed_searchbar_get_entire_word (XedSearchbar *searchbar) { - g_return_val_if_fail(XED_IS_SEARCHBAR (searchbar), FALSE); - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(searchbar->priv->entire_word_checkbutton)); + g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), FALSE); + return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (searchbar->priv->entire_word_checkbutton)); } void xed_searchbar_set_wrap_around (XedSearchbar *searchbar, - gboolean wrap_around) + gboolean wrap_around) { - g_return_if_fail(XED_IS_SEARCHBAR (searchbar)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(searchbar->priv->wrap_around_checkbutton), wrap_around); + g_return_if_fail (XED_IS_SEARCHBAR (searchbar)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (searchbar->priv->wrap_around_checkbutton), wrap_around); } gboolean xed_searchbar_get_wrap_around (XedSearchbar *searchbar) { - g_return_val_if_fail(XED_IS_SEARCHBAR (searchbar), FALSE); - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(searchbar->priv->wrap_around_checkbutton)); + g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), FALSE); + return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (searchbar->priv->wrap_around_checkbutton)); } diff --git a/xed/xed-searchbar.h b/xed/xed-searchbar.h index d3b1af5..13b125d 100755 --- a/xed/xed-searchbar.h +++ b/xed/xed-searchbar.h @@ -7,9 +7,6 @@ G_BEGIN_DECLS -/* - * Type checking and casting macros - */ #define XED_TYPE_SEARCHBAR (xed_searchbar_get_type()) #define XED_SEARCHBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_SEARCHBAR, XedSearchbar)) #define XED_SEARCHBAR_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_SEARCHBAR, XedSearchbar const)) @@ -18,13 +15,9 @@ G_BEGIN_DECLS #define XED_IS_SEARCHBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_SEARCHBAR)) #define XED_SEARCHBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_SEARCHBAR, XedSearchbarClass)) -/* Private structure type */ +typedef struct _XedSearchbar XedSearchbar; typedef struct _XedSearchbarPrivate XedSearchbarPrivate; - -/* - * Main object structure - */ -typedef struct _XedSearchbar XedSearchbar; +typedef struct _XedSearchbarClass XedSearchbarClass; struct _XedSearchbar { @@ -35,11 +28,6 @@ struct _XedSearchbar XedSearchbarPrivate *priv; }; -/* - * Class definition - */ -typedef struct _XedSearchbarClass XedSearchbarClass; - struct _XedSearchbarClass { GtkBoxClass parent_class; @@ -55,9 +43,6 @@ enum XED_SEARCHBAR_REPLACE_ALL_RESPONSE }; -/* - * Public methods - */ GType xed_searchbar_get_type (void) G_GNUC_CONST; GtkWidget *xed_searchbar_new (GtkWindow *parent, gboolean show_replace); From f21c6e93618d8ee6a49eb3cc27e9c46c44f3f3bc Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 14 Jan 2017 11:48:19 -0800 Subject: [PATCH 093/132] Port to the use of GFile instead of URIs and merge gio document loader and saver into document loader and saver --- .../filebrowser/xed-file-bookmarks-store.c | 19 +- .../filebrowser/xed-file-bookmarks-store.h | 20 +- .../filebrowser/xed-file-browser-marshal.list | 2 +- .../filebrowser/xed-file-browser-messages.c | 1563 ++++++++--------- plugins/filebrowser/xed-file-browser-plugin.c | 140 +- plugins/filebrowser/xed-file-browser-store.c | 145 +- plugins/filebrowser/xed-file-browser-store.h | 24 +- plugins/filebrowser/xed-file-browser-utils.c | 63 +- plugins/filebrowser/xed-file-browser-utils.h | 5 +- plugins/filebrowser/xed-file-browser-view.c | 70 +- plugins/filebrowser/xed-file-browser-widget.c | 131 +- plugins/filebrowser/xed-file-browser-widget.h | 10 +- tests/document-loader.c | 4 +- tests/document-saver.c | 6 +- xed/Makefile.am | 4 - xed/xed-commands-file.c | 124 +- xed/xed-commands.h | 4 +- xed/xed-document-loader.c | 996 ++++++++--- xed/xed-document-loader.h | 92 +- xed/xed-document-saver.c | 1120 +++++++++--- xed/xed-document-saver.h | 96 +- xed/xed-document.c | 221 ++- xed/xed-document.h | 68 +- xed/xed-gio-document-loader.c | 708 -------- xed/xed-gio-document-loader.h | 79 - xed/xed-gio-document-saver.c | 775 -------- xed/xed-gio-document-saver.h | 76 - xed/xed-io-error-message-area.c | 77 +- xed/xed-io-error-message-area.h | 30 +- xed/xed-marshal.list | 4 +- xed/xed-metadata-manager.c | 114 +- xed/xed-metadata-manager.h | 18 +- xed/xed-session.c | 110 +- xed/xed-tab.c | 166 +- xed/xed-tab.h | 158 +- xed/xed-utils.c | 124 +- xed/xed-utils.h | 11 +- xed/xed-window.c | 85 +- xed/xed-window.h | 36 +- 39 files changed, 3420 insertions(+), 4078 deletions(-) delete mode 100644 xed/xed-gio-document-loader.c delete mode 100644 xed/xed-gio-document-loader.h delete mode 100644 xed/xed-gio-document-saver.c delete mode 100644 xed/xed-gio-document-saver.h diff --git a/plugins/filebrowser/xed-file-bookmarks-store.c b/plugins/filebrowser/xed-file-bookmarks-store.c index ad1904e..6074b5d 100644 --- a/plugins/filebrowser/xed-file-bookmarks-store.c +++ b/plugins/filebrowser/xed-file-bookmarks-store.c @@ -535,6 +535,7 @@ init_bookmarks (XedFileBookmarksStore * model) { if (**line) { + GFile *location; gchar *pos; gchar *name; @@ -553,10 +554,12 @@ init_bookmarks (XedFileBookmarksStore * model) /* the bookmarks file should contain valid * URIs, but paranoia is good */ - if (xed_utils_is_valid_uri (*line)) + location = g_file_new_for_uri (*line); + if (xed_utils_is_valid_location (location)) { added |= add_bookmark (model, name, *line); } + g_object_unref (location); } } @@ -844,14 +847,14 @@ xed_file_bookmarks_store_new (void) return model; } -gchar * -xed_file_bookmarks_store_get_uri (XedFileBookmarksStore *model, - GtkTreeIter *iter) +GFile * +xed_file_bookmarks_store_get_location (XedFileBookmarksStore *model, + GtkTreeIter *iter) { - GObject * obj; - GFile * file = NULL; + GObject *obj; + GFile *file = NULL; guint flags; - gchar * ret = NULL; + GFile *ret = NULL; gboolean isfs; g_return_val_if_fail (XED_IS_FILE_BOOKMARKS_STORE (model), NULL); @@ -884,7 +887,7 @@ xed_file_bookmarks_store_get_uri (XedFileBookmarksStore *model, if (file) { - ret = g_file_get_uri (file); + ret = g_file_dup (file); g_object_unref (file); } diff --git a/plugins/filebrowser/xed-file-bookmarks-store.h b/plugins/filebrowser/xed-file-bookmarks-store.h index 9fe22ff..80276f5 100644 --- a/plugins/filebrowser/xed-file-bookmarks-store.h +++ b/plugins/filebrowser/xed-file-bookmarks-store.h @@ -25,13 +25,13 @@ #include G_BEGIN_DECLS -#define XED_TYPE_FILE_BOOKMARKS_STORE (xed_file_bookmarks_store_get_type ()) -#define XED_FILE_BOOKMARKS_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStore)) -#define XED_FILE_BOOKMARKS_STORE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStore const)) +#define XED_TYPE_FILE_BOOKMARKS_STORE (xed_file_bookmarks_store_get_type ()) +#define XED_FILE_BOOKMARKS_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStore)) +#define XED_FILE_BOOKMARKS_STORE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStore const)) #define XED_FILE_BOOKMARKS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStoreClass)) -#define XED_IS_FILE_BOOKMARKS_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_FILE_BOOKMARKS_STORE)) +#define XED_IS_FILE_BOOKMARKS_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_FILE_BOOKMARKS_STORE)) #define XED_IS_FILE_BOOKMARKS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_BOOKMARKS_STORE)) -#define XED_FILE_BOOKMARKS_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStoreClass)) +#define XED_FILE_BOOKMARKS_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStoreClass)) typedef struct _XedFileBookmarksStore XedFileBookmarksStore; typedef struct _XedFileBookmarksStoreClass XedFileBookmarksStoreClass; @@ -76,13 +76,13 @@ struct _XedFileBookmarksStoreClass GtkTreeStoreClass parent_class; }; -GType xed_file_bookmarks_store_get_type (void) G_GNUC_CONST; -void _xed_file_bookmarks_store_register_type (GTypeModule *type_module); +GType xed_file_bookmarks_store_get_type (void) G_GNUC_CONST; +void _xed_file_bookmarks_store_register_type (GTypeModule *type_module); XedFileBookmarksStore *xed_file_bookmarks_store_new (void); -gchar *xed_file_bookmarks_store_get_uri (XedFileBookmarksStore * model, - GtkTreeIter * iter); -void xed_file_bookmarks_store_refresh (XedFileBookmarksStore * model); +GFile *xed_file_bookmarks_store_get_location (XedFileBookmarksStore * model, + GtkTreeIter * iter); +void xed_file_bookmarks_store_refresh (XedFileBookmarksStore * model); G_END_DECLS #endif /* __XED_FILE_BOOKMARKS_STORE_H__ */ diff --git a/plugins/filebrowser/xed-file-browser-marshal.list b/plugins/filebrowser/xed-file-browser-marshal.list index 5fa72c8..9b24776 100644 --- a/plugins/filebrowser/xed-file-browser-marshal.list +++ b/plugins/filebrowser/xed-file-browser-marshal.list @@ -1,5 +1,5 @@ VOID:UINT,STRING -VOID:STRING,STRING +VOID:OBJECT,OBJECT BOOL:OBJECT,POINTER BOOL:POINTER BOOL:VOID diff --git a/plugins/filebrowser/xed-file-browser-messages.c b/plugins/filebrowser/xed-file-browser-messages.c index 818751c..102027d 100644 --- a/plugins/filebrowser/xed-file-browser-messages.c +++ b/plugins/filebrowser/xed-file-browser-messages.c @@ -2,1032 +2,1029 @@ #include "xed-file-browser-store.h" #include -#define MESSAGE_OBJECT_PATH "/plugins/filebrowser" -#define WINDOW_DATA_KEY "XedFileBrowserMessagesWindowData" +#define MESSAGE_OBJECT_PATH "/plugins/filebrowser" +#define WINDOW_DATA_KEY "XedFileBrowserMessagesWindowData" #define BUS_CONNECT(bus, name, data) xed_message_bus_connect(bus, MESSAGE_OBJECT_PATH, #name, (XedMessageCallback) message_##name##_cb, data, NULL) typedef struct { - XedWindow *window; - XedMessage *message; + XedWindow *window; + XedMessage *message; } MessageCacheData; typedef struct { - guint row_inserted_id; - guint row_deleted_id; - guint root_changed_id; - guint begin_loading_id; - guint end_loading_id; + guint row_inserted_id; + guint row_deleted_id; + guint root_changed_id; + guint begin_loading_id; + guint end_loading_id; - GList *merge_ids; - GtkActionGroup *merged_actions; - - XedMessageBus *bus; - XedFileBrowserWidget *widget; - GHashTable *row_tracking; - - GHashTable *filters; + GList *merge_ids; + GtkActionGroup *merged_actions; + + XedMessageBus *bus; + XedFileBrowserWidget *widget; + GHashTable *row_tracking; + + GHashTable *filters; } WindowData; typedef struct { - gulong id; - - XedWindow *window; - XedMessage *message; + gulong id; + + XedWindow *window; + XedMessage *message; } FilterData; static WindowData * window_data_new (XedWindow *window, - XedFileBrowserWidget *widget) + XedFileBrowserWidget *widget) { - WindowData *data = g_slice_new (WindowData); - GtkUIManager *manager; - GList *groups; - - data->bus = xed_window_get_message_bus (window); - data->widget = widget; - data->row_tracking = g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify)g_free, - (GDestroyNotify)gtk_tree_row_reference_free); + WindowData *data = g_slice_new (WindowData); + GtkUIManager *manager; + GList *groups; - data->filters = g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify)g_free, - NULL); - - manager = xed_file_browser_widget_get_ui_manager (widget); + data->bus = xed_window_get_message_bus (window); + data->widget = widget; + data->row_tracking = g_hash_table_new_full (g_str_hash, + g_str_equal, + (GDestroyNotify)g_free, + (GDestroyNotify)gtk_tree_row_reference_free); - data->merge_ids = NULL; - data->merged_actions = gtk_action_group_new ("MessageMergedActions"); - - groups = gtk_ui_manager_get_action_groups (manager); - gtk_ui_manager_insert_action_group (manager, data->merged_actions, g_list_length (groups)); - - g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, data); + data->filters = g_hash_table_new_full (g_str_hash, + g_str_equal, + (GDestroyNotify)g_free, + NULL); - return data; + manager = xed_file_browser_widget_get_ui_manager (widget); + + data->merge_ids = NULL; + data->merged_actions = gtk_action_group_new ("MessageMergedActions"); + + groups = gtk_ui_manager_get_action_groups (manager); + gtk_ui_manager_insert_action_group (manager, data->merged_actions, g_list_length (groups)); + + g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, data); + + return data; } static WindowData * get_window_data (XedWindow * window) { - return (WindowData *) (g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY)); + return (WindowData *) (g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY)); } static void window_data_free (XedWindow *window) { - WindowData *data = get_window_data (window); - GtkUIManager *manager; - GList *item; - - g_hash_table_destroy (data->row_tracking); - g_hash_table_destroy (data->filters); + WindowData *data = get_window_data (window); + GtkUIManager *manager; + GList *item; - manager = xed_file_browser_widget_get_ui_manager (data->widget); - gtk_ui_manager_remove_action_group (manager, data->merged_actions); - - for (item = data->merge_ids; item; item = item->next) - gtk_ui_manager_remove_ui (manager, GPOINTER_TO_INT (item->data)); + g_hash_table_destroy (data->row_tracking); + g_hash_table_destroy (data->filters); - g_list_free (data->merge_ids); - g_object_unref (data->merged_actions); + manager = xed_file_browser_widget_get_ui_manager (data->widget); + gtk_ui_manager_remove_action_group (manager, data->merged_actions); - g_slice_free (WindowData, data); + for (item = data->merge_ids; item; item = item->next) + gtk_ui_manager_remove_ui (manager, GPOINTER_TO_INT (item->data)); - g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL); + g_list_free (data->merge_ids); + g_object_unref (data->merged_actions); + + g_slice_free (WindowData, data); + + g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL); } static FilterData * -filter_data_new (XedWindow *window, - XedMessage *message) +filter_data_new (XedWindow *window, + XedMessage *message) { - FilterData *data = g_slice_new (FilterData); - WindowData *wdata; - - data->window = window; - data->id = 0; - data->message = message; - - wdata = get_window_data (window); - - g_hash_table_insert (wdata->filters, - xed_message_type_identifier (xed_message_get_object_path (message), - xed_message_get_method (message)), - data); + FilterData *data = g_slice_new (FilterData); + WindowData *wdata; - return data; + data->window = window; + data->id = 0; + data->message = message; + + wdata = get_window_data (window); + + g_hash_table_insert (wdata->filters, + xed_message_type_identifier (xed_message_get_object_path (message), + xed_message_get_method (message)), + data); + + return data; } static void filter_data_free (FilterData *data) { - WindowData *wdata = get_window_data (data->window); - gchar *identifier; - - identifier = xed_message_type_identifier (xed_message_get_object_path (data->message), - xed_message_get_method (data->message)); - - g_hash_table_remove (wdata->filters, identifier); - g_free (identifier); + WindowData *wdata = get_window_data (data->window); + gchar *identifier; - g_object_unref (data->message); - g_slice_free (FilterData, data); + identifier = xed_message_type_identifier (xed_message_get_object_path (data->message), + xed_message_get_method (data->message)); + + g_hash_table_remove (wdata->filters, identifier); + g_free (identifier); + + g_object_unref (data->message); + g_slice_free (FilterData, data); } static GtkTreePath * -track_row_lookup (WindowData *data, - const gchar *id) +track_row_lookup (WindowData *data, + const gchar *id) { - GtkTreeRowReference *ref; - - ref = (GtkTreeRowReference *)g_hash_table_lookup (data->row_tracking, id); - - if (!ref) - return NULL; - - return gtk_tree_row_reference_get_path (ref); + GtkTreeRowReference *ref; + + ref = (GtkTreeRowReference *)g_hash_table_lookup (data->row_tracking, id); + + if (!ref) + return NULL; + + return gtk_tree_row_reference_get_path (ref); } static void message_cache_data_free (MessageCacheData *data) { - g_object_unref (data->message); - g_slice_free (MessageCacheData, data); + g_object_unref (data->message); + g_slice_free (MessageCacheData, data); } static MessageCacheData * message_cache_data_new (XedWindow *window, - XedMessage *message) + XedMessage *message) { - MessageCacheData *data = g_slice_new (MessageCacheData); - - data->window = window; - data->message = message; - - return data; + MessageCacheData *data = g_slice_new (MessageCacheData); + + data->window = window; + data->message = message; + + return data; } static void message_get_root_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { - XedFileBrowserStore *store; - gchar *uri; - - store = xed_file_browser_widget_get_browser_store (data->widget); - uri = xed_file_browser_store_get_virtual_root (store); - - xed_message_set (message, "uri", uri, NULL); - g_free (uri); + XedFileBrowserStore *store; + GFile *location; + + store = xed_file_browser_widget_get_browser_store (data->widget); + location = xed_file_browser_store_get_virtual_root (store); + + if (location) + { + xed_message_set (message, "location", location, NULL); + g_object_unref (location); + } } static void message_set_root_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { - gchar *root = NULL; - gchar *virtual = NULL; - - xed_message_get (message, "uri", &root, NULL); - - if (!root) - return; - - if (xed_message_has_key (message, "virtual")) - xed_message_get (message, "virtual", &virtual, NULL); + GFile *root; + GFile *virtual = NULL; - if (virtual) - xed_file_browser_widget_set_root_and_virtual_root (data->widget, root, virtual); - else - xed_file_browser_widget_set_root (data->widget, root, TRUE); - - g_free (root); - g_free (virtual); + xed_message_get (message, "location", &root, NULL); + + if (!root) + return; + + if (xed_message_has_key (message, "virtual")) + xed_message_get (message, "virtual", &virtual, NULL); + + if (virtual) + xed_file_browser_widget_set_root_and_virtual_root (data->widget, root, virtual); + else + xed_file_browser_widget_set_root (data->widget, root, TRUE); } static void message_set_emblem_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { - gchar *id = NULL; - gchar *emblem = NULL; - GtkTreePath *path; - XedFileBrowserStore *store; - - xed_message_get (message, "id", &id, "emblem", &emblem, NULL); - - if (!id || !emblem) - { - g_free (id); - g_free (emblem); - - return; - } - - path = track_row_lookup (data, id); - - if (path != NULL) - { - GError *error = NULL; - GdkPixbuf *pixbuf; - - pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), - emblem, - 10, - 0, - &error); - - if (pixbuf) - { - GValue value = { 0, }; - GtkTreeIter iter; - - store = xed_file_browser_widget_get_browser_store (data->widget); - - if (gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path)) - { - g_value_init (&value, GDK_TYPE_PIXBUF); - g_value_set_object (&value, pixbuf); - - xed_file_browser_store_set_value (store, - &iter, - XED_FILE_BROWSER_STORE_COLUMN_EMBLEM, - &value); - - g_value_unset (&value); - } - - g_object_unref (pixbuf); - } - - if (error) - g_error_free (error); - } - - g_free (id); - g_free (emblem); + gchar *id = NULL; + gchar *emblem = NULL; + GtkTreePath *path; + XedFileBrowserStore *store; + + xed_message_get (message, "id", &id, "emblem", &emblem, NULL); + + if (!id || !emblem) + { + g_free (id); + g_free (emblem); + + return; + } + + path = track_row_lookup (data, id); + + if (path != NULL) + { + GError *error = NULL; + GdkPixbuf *pixbuf; + + pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), + emblem, + 10, + 0, + &error); + + if (pixbuf) + { + GValue value = { 0, }; + GtkTreeIter iter; + + store = xed_file_browser_widget_get_browser_store (data->widget); + + if (gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path)) + { + g_value_init (&value, GDK_TYPE_PIXBUF); + g_value_set_object (&value, pixbuf); + + xed_file_browser_store_set_value (store, + &iter, + XED_FILE_BROWSER_STORE_COLUMN_EMBLEM, + &value); + + g_value_unset (&value); + } + + g_object_unref (pixbuf); + } + + if (error) + g_error_free (error); + } + + g_free (id); + g_free (emblem); } static gchar * item_id (const gchar *path, - const gchar *uri) + GFile *location) { - return g_strconcat (path, "::", uri, NULL); + gchar *uri; + gchar *id; + + uri = g_file_get_uri (location); + id = g_strconcat (path, "::", uri, NULL); + g_free (uri); + + return id; } static gchar * track_row (WindowData *data, - XedFileBrowserStore *store, - GtkTreePath *path, - const gchar *uri) + XedFileBrowserStore *store, + GtkTreePath *path, + GFile *location) { - GtkTreeRowReference *ref; - gchar *id; - gchar *pathstr; - - pathstr = gtk_tree_path_to_string (path); - id = item_id (pathstr, uri); - - ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (store), path); - g_hash_table_insert (data->row_tracking, g_strdup (id), ref); - - g_free (pathstr); - - return id; + GtkTreeRowReference *ref; + gchar *id; + gchar *pathstr; + + pathstr = gtk_tree_path_to_string (path); + id = item_id (pathstr, location); + + ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (store), path); + g_hash_table_insert (data->row_tracking, g_strdup (id), ref); + + g_free (pathstr); + + return id; } static void -set_item_message (WindowData *data, - GtkTreeIter *iter, - GtkTreePath *path, - XedMessage *message) +set_item_message (WindowData *data, + GtkTreeIter *iter, + GtkTreePath *path, + XedMessage *message) { - XedFileBrowserStore *store; - gchar *uri = NULL; - guint flags = 0; - gchar *track_id; - - store = xed_file_browser_widget_get_browser_store (data->widget); - - gtk_tree_model_get (GTK_TREE_MODEL (store), iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - -1); - - if (!uri) - return; + XedFileBrowserStore *store; + GFile *location; + guint flags = 0; + gchar *track_id; - if (path && gtk_tree_path_get_depth (path) != 0) - track_id = track_row (data, store, path, uri); - else - track_id = NULL; + store = xed_file_browser_widget_get_browser_store (data->widget); - xed_message_set (message, - "id", track_id, - "uri", uri, - NULL); - - if (xed_message_has_key (message, "is_directory")) - { - xed_message_set (message, - "is_directory", FILE_IS_DIR (flags), - NULL); - } + gtk_tree_model_get (GTK_TREE_MODEL (store), iter, + XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, + XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, + -1); - g_free (uri); - g_free (track_id); + if (!location) + return; + + if (path && gtk_tree_path_get_depth (path) != 0) + track_id = track_row (data, store, path, location); + else + track_id = NULL; + + xed_message_set (message, + "id", track_id, + "location", location, + NULL); + + if (xed_message_has_key (message, "is_directory")) + { + xed_message_set (message, + "is_directory", FILE_IS_DIR (flags), + NULL); + } + + g_free (track_id); } static gboolean custom_message_filter_func (XedFileBrowserWidget *widget, - XedFileBrowserStore *store, - GtkTreeIter *iter, - FilterData *data) + XedFileBrowserStore *store, + GtkTreeIter *iter, + FilterData *data) { - WindowData *wdata = get_window_data (data->window); - gchar *uri = NULL; - guint flags = 0; - gboolean filter = FALSE; - GtkTreePath *path; - - gtk_tree_model_get (GTK_TREE_MODEL (store), iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - -1); - - if (!uri || FILE_IS_DUMMY (flags)) - { - g_free (uri); - return FALSE; - } - - path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter); - set_item_message (wdata, iter, path, data->message); - gtk_tree_path_free (path); - - xed_message_set (data->message, "filter", filter, NULL); + WindowData *wdata = get_window_data (data->window); + GFile *location; + guint flags = 0; + gboolean filter = FALSE; + GtkTreePath *path; - xed_message_bus_send_message_sync (wdata->bus, data->message); - xed_message_get (data->message, "filter", &filter, NULL); - - return !filter; + gtk_tree_model_get (GTK_TREE_MODEL (store), iter, + XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, + XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, + -1); + + if (!location || FILE_IS_DUMMY (flags)) + { + return FALSE; + } + + path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter); + set_item_message (wdata, iter, path, data->message); + gtk_tree_path_free (path); + + xed_message_set (data->message, "filter", filter, NULL); + + xed_message_bus_send_message_sync (wdata->bus, data->message); + xed_message_get (data->message, "filter", &filter, NULL); + + return !filter; } static void message_add_filter_cb (XedMessageBus *bus, - XedMessage *message, - XedWindow *window) + XedMessage *message, + XedWindow *window) { - gchar *object_path = NULL; - gchar *method = NULL; - gulong id; - XedMessageType *message_type; - XedMessage *cbmessage; - FilterData *filter_data; - WindowData *data = get_window_data (window); - - xed_message_get (message, - "object_path", &object_path, - "method", &method, - NULL); - - // Check if there exists such a 'callback' message - if (!object_path || !method) - { - g_free (object_path); - g_free (method); - - return; - } - - message_type = xed_message_bus_lookup (bus, object_path, method); - - if (!message_type) - { - g_free (object_path); - g_free (method); - - return; - } - - // Check if the message type has the correct arguments - if (xed_message_type_lookup (message_type, "id") != G_TYPE_STRING || - xed_message_type_lookup (message_type, "uri") != G_TYPE_STRING || - xed_message_type_lookup (message_type, "is_directory") != G_TYPE_BOOLEAN || - xed_message_type_lookup (message_type, "filter") != G_TYPE_BOOLEAN) - { - return; - } - - cbmessage = xed_message_type_instantiate (message_type, - "id", NULL, - "uri", NULL, - "is_directory", FALSE, - "filter", FALSE, - NULL); + gchar *object_path = NULL; + gchar *method = NULL; + gulong id; + XedMessageType *message_type; + XedMessage *cbmessage; + FilterData *filter_data; + WindowData *data = get_window_data (window); - // Register the custom filter on the widget - filter_data = filter_data_new (window, cbmessage); - id = xed_file_browser_widget_add_filter (data->widget, - (XedFileBrowserWidgetFilterFunc)custom_message_filter_func, - filter_data, - (GDestroyNotify)filter_data_free); + xed_message_get (message, + "object_path", &object_path, + "method", &method, + NULL); - filter_data->id = id; + // Check if there exists such a 'callback' message + if (!object_path || !method) + { + g_free (object_path); + g_free (method); + + return; + } + + message_type = xed_message_bus_lookup (bus, object_path, method); + + if (!message_type) + { + g_free (object_path); + g_free (method); + + return; + } + + // Check if the message type has the correct arguments + if (xed_message_type_lookup (message_type, "id") != G_TYPE_STRING || + xed_message_type_lookup (message_type, "location") != G_TYPE_FILE || + xed_message_type_lookup (message_type, "is_directory") != G_TYPE_BOOLEAN || + xed_message_type_lookup (message_type, "filter") != G_TYPE_BOOLEAN) + { + return; + } + + cbmessage = xed_message_type_instantiate (message_type, + "id", NULL, + "location", NULL, + "is_directory", FALSE, + "filter", FALSE, + NULL); + + // Register the custom filter on the widget + filter_data = filter_data_new (window, cbmessage); + id = xed_file_browser_widget_add_filter (data->widget, + (XedFileBrowserWidgetFilterFunc)custom_message_filter_func, + filter_data, + (GDestroyNotify)filter_data_free); + + filter_data->id = id; } static void message_remove_filter_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { - gulong id = 0; - - xed_message_get (message, "id", &id, NULL); - - if (!id) - return; - - xed_file_browser_widget_remove_filter (data->widget, id); + gulong id = 0; + + xed_message_get (message, "id", &id, NULL); + + if (!id) + return; + + xed_file_browser_widget_remove_filter (data->widget, id); } static void message_up_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { - XedFileBrowserStore *store = xed_file_browser_widget_get_browser_store (data->widget); - - xed_file_browser_store_set_virtual_root_up (store); + XedFileBrowserStore *store = xed_file_browser_widget_get_browser_store (data->widget); + + xed_file_browser_store_set_virtual_root_up (store); } static void message_history_back_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { - xed_file_browser_widget_history_back (data->widget); + xed_file_browser_widget_history_back (data->widget); } static void message_history_forward_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { - xed_file_browser_widget_history_forward (data->widget); + xed_file_browser_widget_history_forward (data->widget); } static void message_refresh_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { - xed_file_browser_widget_refresh (data->widget); + xed_file_browser_widget_refresh (data->widget); } static void message_set_show_hidden_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { - gboolean active = FALSE; - XedFileBrowserStore *store; - XedFileBrowserStoreFilterMode mode; - - xed_message_get (message, "active", &active, NULL); - - store = xed_file_browser_widget_get_browser_store (data->widget); - mode = xed_file_browser_store_get_filter_mode (store); - - if (active) - mode &= ~XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN; - else - mode |= XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN; + gboolean active = FALSE; + XedFileBrowserStore *store; + XedFileBrowserStoreFilterMode mode; - xed_file_browser_store_set_filter_mode (store, mode); + xed_message_get (message, "active", &active, NULL); + + store = xed_file_browser_widget_get_browser_store (data->widget); + mode = xed_file_browser_store_get_filter_mode (store); + + if (active) + mode &= ~XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN; + else + mode |= XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN; + + xed_file_browser_store_set_filter_mode (store, mode); } static void message_set_show_binary_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { - gboolean active = FALSE; - XedFileBrowserStore *store; - XedFileBrowserStoreFilterMode mode; - - xed_message_get (message, "active", &active, NULL); - - store = xed_file_browser_widget_get_browser_store (data->widget); - mode = xed_file_browser_store_get_filter_mode (store); - - if (active) - mode &= ~XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY; - else - mode |= XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY; + gboolean active = FALSE; + XedFileBrowserStore *store; + XedFileBrowserStoreFilterMode mode; - xed_file_browser_store_set_filter_mode (store, mode); + xed_message_get (message, "active", &active, NULL); + + store = xed_file_browser_widget_get_browser_store (data->widget); + mode = xed_file_browser_store_get_filter_mode (store); + + if (active) + mode &= ~XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY; + else + mode |= XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY; + + xed_file_browser_store_set_filter_mode (store, mode); } static void message_show_bookmarks_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { - xed_file_browser_widget_show_bookmarks (data->widget); + xed_file_browser_widget_show_bookmarks (data->widget); } static void message_show_files_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { - xed_file_browser_widget_show_files (data->widget); + xed_file_browser_widget_show_files (data->widget); } static void message_add_context_item_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { - GtkAction *action = NULL; - gchar *path = NULL; - gchar *name; - GtkUIManager *manager; - guint merge_id; - - xed_message_get (message, - "action", &action, - "path", &path, - NULL); - - if (!action || !path) - { - if (action) - g_object_unref (action); + GtkAction *action = NULL; + gchar *path = NULL; + gchar *name; + GtkUIManager *manager; + guint merge_id; - g_free (path); - return; - } - - gtk_action_group_add_action (data->merged_actions, action); - manager = xed_file_browser_widget_get_ui_manager (data->widget); - name = g_strconcat (gtk_action_get_name (action), "MenuItem", NULL); - merge_id = gtk_ui_manager_new_merge_id (manager); - - gtk_ui_manager_add_ui (manager, - merge_id, - path, - name, - gtk_action_get_name (action), - GTK_UI_MANAGER_AUTO, - FALSE); - - if (gtk_ui_manager_get_widget (manager, path)) - { - data->merge_ids = g_list_prepend (data->merge_ids, GINT_TO_POINTER (merge_id)); - xed_message_set (message, "id", merge_id, NULL); - } - else - { - xed_message_set (message, "id", 0, NULL); - } - - g_object_unref (action); - g_free (path); - g_free (name); + xed_message_get (message, + "action", &action, + "path", &path, + NULL); + + if (!action || !path) + { + if (action) + g_object_unref (action); + + g_free (path); + return; + } + + gtk_action_group_add_action (data->merged_actions, action); + manager = xed_file_browser_widget_get_ui_manager (data->widget); + name = g_strconcat (gtk_action_get_name (action), "MenuItem", NULL); + merge_id = gtk_ui_manager_new_merge_id (manager); + + gtk_ui_manager_add_ui (manager, + merge_id, + path, + name, + gtk_action_get_name (action), + GTK_UI_MANAGER_AUTO, + FALSE); + + if (gtk_ui_manager_get_widget (manager, path)) + { + data->merge_ids = g_list_prepend (data->merge_ids, GINT_TO_POINTER (merge_id)); + xed_message_set (message, "id", merge_id, NULL); + } + else + { + xed_message_set (message, "id", 0, NULL); + } + + g_object_unref (action); + g_free (path); + g_free (name); } static void message_remove_context_item_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { - guint merge_id = 0; - GtkUIManager *manager; - - xed_message_get (message, "id", &merge_id, NULL); - - if (merge_id == 0) - return; - - manager = xed_file_browser_widget_get_ui_manager (data->widget); - - data->merge_ids = g_list_remove (data->merge_ids, GINT_TO_POINTER (merge_id)); - gtk_ui_manager_remove_ui (manager, merge_id); + guint merge_id = 0; + GtkUIManager *manager; + + xed_message_get (message, "id", &merge_id, NULL); + + if (merge_id == 0) + return; + + manager = xed_file_browser_widget_get_ui_manager (data->widget); + + data->merge_ids = g_list_remove (data->merge_ids, GINT_TO_POINTER (merge_id)); + gtk_ui_manager_remove_ui (manager, merge_id); } static void message_get_view_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { - XedFileBrowserView *view; - view = xed_file_browser_widget_get_browser_view (data->widget); + XedFileBrowserView *view; + view = xed_file_browser_widget_get_browser_view (data->widget); - xed_message_set (message, "view", view, NULL); + xed_message_set (message, "view", view, NULL); } static void register_methods (XedWindow *window, - XedFileBrowserWidget *widget) + XedFileBrowserWidget *widget) { - XedMessageBus *bus = xed_window_get_message_bus (window); - WindowData *data = get_window_data (window); + XedMessageBus *bus = xed_window_get_message_bus (window); + WindowData *data = get_window_data (window); - /* Register method calls */ - xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "get_root", - 1, - "uri", G_TYPE_STRING, - NULL); - - xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "set_root", - 1, - "uri", G_TYPE_STRING, - "virtual", G_TYPE_STRING, - NULL); - - xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "set_emblem", - 0, - "id", G_TYPE_STRING, - "emblem", G_TYPE_STRING, - NULL); - - xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "add_filter", - 1, - "object_path", G_TYPE_STRING, - "method", G_TYPE_STRING, - "id", G_TYPE_ULONG, - NULL); - - xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "remove_filter", - 0, - "id", G_TYPE_ULONG, - NULL); - - xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "add_context_item", - 1, - "action", GTK_TYPE_ACTION, - "path", G_TYPE_STRING, - "id", G_TYPE_UINT, - NULL); + /* Register method calls */ + xed_message_bus_register (bus, + MESSAGE_OBJECT_PATH, "get_root", + 1, + "location", G_TYPE_FILE, + NULL); - xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "remove_context_item", - 0, - "id", G_TYPE_UINT, - NULL); - - xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "up", 0, NULL); - - xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "history_back", 0, NULL); - xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "history_forward", 0, NULL); - - xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "refresh", 0, NULL); + xed_message_bus_register (bus, + MESSAGE_OBJECT_PATH, "set_root", + 1, + "location", G_TYPE_FILE, + "virtual", G_TYPE_STRING, + NULL); - xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "set_show_hidden", - 0, - "active", G_TYPE_BOOLEAN, - NULL); - xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "set_show_binary", - 0, - "active", G_TYPE_BOOLEAN, - NULL); + xed_message_bus_register (bus, + MESSAGE_OBJECT_PATH, "set_emblem", + 0, + "id", G_TYPE_STRING, + "emblem", G_TYPE_STRING, + NULL); - xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "show_bookmarks", 0, NULL); - xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "show_files", 0, NULL); + xed_message_bus_register (bus, + MESSAGE_OBJECT_PATH, "add_filter", + 1, + "object_path", G_TYPE_STRING, + "method", G_TYPE_STRING, + "id", G_TYPE_ULONG, + NULL); - xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "get_view", - 1, - "view", XED_TYPE_FILE_BROWSER_VIEW, - NULL); + xed_message_bus_register (bus, + MESSAGE_OBJECT_PATH, "remove_filter", + 0, + "id", G_TYPE_ULONG, + NULL); - BUS_CONNECT (bus, get_root, data); - BUS_CONNECT (bus, set_root, data); - BUS_CONNECT (bus, set_emblem, data); - BUS_CONNECT (bus, add_filter, window); - BUS_CONNECT (bus, remove_filter, data); + xed_message_bus_register (bus, + MESSAGE_OBJECT_PATH, "add_context_item", + 1, + "action", GTK_TYPE_ACTION, + "path", G_TYPE_STRING, + "id", G_TYPE_UINT, + NULL); - BUS_CONNECT (bus, add_context_item, data); - BUS_CONNECT (bus, remove_context_item, data); + xed_message_bus_register (bus, + MESSAGE_OBJECT_PATH, "remove_context_item", + 0, + "id", G_TYPE_UINT, + NULL); - BUS_CONNECT (bus, up, data); - BUS_CONNECT (bus, history_back, data); - BUS_CONNECT (bus, history_forward, data); + xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "up", 0, NULL); - BUS_CONNECT (bus, refresh, data); - - BUS_CONNECT (bus, set_show_hidden, data); - BUS_CONNECT (bus, set_show_binary, data); - - BUS_CONNECT (bus, show_bookmarks, data); - BUS_CONNECT (bus, show_files, data); + xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "history_back", 0, NULL); + xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "history_forward", 0, NULL); - BUS_CONNECT (bus, get_view, data); + xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "refresh", 0, NULL); + + xed_message_bus_register (bus, + MESSAGE_OBJECT_PATH, "set_show_hidden", + 0, + "active", G_TYPE_BOOLEAN, + NULL); + xed_message_bus_register (bus, + MESSAGE_OBJECT_PATH, "set_show_binary", + 0, + "active", G_TYPE_BOOLEAN, + NULL); + + xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "show_bookmarks", 0, NULL); + xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "show_files", 0, NULL); + + xed_message_bus_register (bus, + MESSAGE_OBJECT_PATH, "get_view", + 1, + "view", XED_TYPE_FILE_BROWSER_VIEW, + NULL); + + BUS_CONNECT (bus, get_root, data); + BUS_CONNECT (bus, set_root, data); + BUS_CONNECT (bus, set_emblem, data); + BUS_CONNECT (bus, add_filter, window); + BUS_CONNECT (bus, remove_filter, data); + + BUS_CONNECT (bus, add_context_item, data); + BUS_CONNECT (bus, remove_context_item, data); + + BUS_CONNECT (bus, up, data); + BUS_CONNECT (bus, history_back, data); + BUS_CONNECT (bus, history_forward, data); + + BUS_CONNECT (bus, refresh, data); + + BUS_CONNECT (bus, set_show_hidden, data); + BUS_CONNECT (bus, set_show_binary, data); + + BUS_CONNECT (bus, show_bookmarks, data); + BUS_CONNECT (bus, show_files, data); + + BUS_CONNECT (bus, get_view, data); } static void store_row_inserted (XedFileBrowserStore *store, - GtkTreePath *path, - GtkTreeIter *iter, - MessageCacheData *data) + GtkTreePath *path, + GtkTreeIter *iter, + MessageCacheData *data) { - gchar *uri = NULL; - guint flags = 0; + guint flags = 0; - gtk_tree_model_get (GTK_TREE_MODEL (store), iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - -1); - - if (!FILE_IS_DUMMY (flags) && !FILE_IS_FILTERED (flags)) - { - WindowData *wdata = get_window_data (data->window); - - set_item_message (wdata, iter, path, data->message); - xed_message_bus_send_message_sync (wdata->bus, data->message); - } - - g_free (uri); + gtk_tree_model_get (GTK_TREE_MODEL (store), iter, + XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, + -1); + + if (!FILE_IS_DUMMY (flags) && !FILE_IS_FILTERED (flags)) + { + WindowData *wdata = get_window_data (data->window); + + set_item_message (wdata, iter, path, data->message); + xed_message_bus_send_message_sync (wdata->bus, data->message); + } } static void store_row_deleted (XedFileBrowserStore *store, - GtkTreePath *path, - MessageCacheData *data) + GtkTreePath *path, + MessageCacheData *data) { - GtkTreeIter iter; - gchar *uri = NULL; - guint flags = 0; - - if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path)) - return; - - gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - -1); - - if (!FILE_IS_DUMMY (flags) && !FILE_IS_FILTERED (flags)) - { - WindowData *wdata = get_window_data (data->window); - - set_item_message (wdata, &iter, path, data->message); - xed_message_bus_send_message_sync (wdata->bus, data->message); - } - - g_free (uri); + GtkTreeIter iter; + guint flags = 0; + + if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path)) + return; + + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, + XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, + -1); + + if (!FILE_IS_DUMMY (flags) && !FILE_IS_FILTERED (flags)) + { + WindowData *wdata = get_window_data (data->window); + + set_item_message (wdata, &iter, path, data->message); + xed_message_bus_send_message_sync (wdata->bus, data->message); + } } static void store_virtual_root_changed (XedFileBrowserStore *store, - GParamSpec *spec, - MessageCacheData *data) + GParamSpec *spec, + MessageCacheData *data) { - WindowData *wdata = get_window_data (data->window); - gchar *uri; - - uri = xed_file_browser_store_get_virtual_root (store); - - if (!uri) - return; - - xed_message_set (data->message, - "uri", uri, - NULL); - - xed_message_bus_send_message_sync (wdata->bus, data->message); - - g_free (uri); + WindowData *wdata = get_window_data (data->window); + GFile *vroot; + + vroot = xed_file_browser_store_get_virtual_root (store); + + if (!vroot) + return; + + xed_message_set (data->message, + "location", vroot, + NULL); + + xed_message_bus_send_message_sync (wdata->bus, data->message); + + g_object_unref (vroot); } static void store_begin_loading (XedFileBrowserStore *store, - GtkTreeIter *iter, - MessageCacheData *data) + GtkTreeIter *iter, + MessageCacheData *data) { - GtkTreePath *path; - WindowData *wdata = get_window_data (data->window); - - path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter); - - set_item_message (wdata, iter, path, data->message); - - xed_message_bus_send_message_sync (wdata->bus, data->message); - gtk_tree_path_free (path); + GtkTreePath *path; + WindowData *wdata = get_window_data (data->window); + + path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter); + + set_item_message (wdata, iter, path, data->message); + + xed_message_bus_send_message_sync (wdata->bus, data->message); + gtk_tree_path_free (path); } static void store_end_loading (XedFileBrowserStore *store, - GtkTreeIter *iter, - MessageCacheData *data) + GtkTreeIter *iter, + MessageCacheData *data) { - GtkTreePath *path; - WindowData *wdata = get_window_data (data->window); - - path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter); - - set_item_message (wdata, iter, path, data->message); - - xed_message_bus_send_message_sync (wdata->bus, data->message); - gtk_tree_path_free (path); + GtkTreePath *path; + WindowData *wdata = get_window_data (data->window); + + path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter); + + set_item_message (wdata, iter, path, data->message); + + xed_message_bus_send_message_sync (wdata->bus, data->message); + gtk_tree_path_free (path); } - + static void register_signals (XedWindow *window, - XedFileBrowserWidget *widget) + XedFileBrowserWidget *widget) { - XedMessageBus *bus = xed_window_get_message_bus (window); - XedFileBrowserStore *store; - XedMessageType *inserted_type; - XedMessageType *deleted_type; - XedMessageType *begin_loading_type; - XedMessageType *end_loading_type; - XedMessageType *root_changed_type; - - XedMessage *message; - WindowData *data; + XedMessageBus *bus = xed_window_get_message_bus (window); + XedFileBrowserStore *store; + XedMessageType *inserted_type; + XedMessageType *deleted_type; + XedMessageType *begin_loading_type; + XedMessageType *end_loading_type; + XedMessageType *root_changed_type; - /* Register signals */ - root_changed_type = xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "root_changed", - 0, - "id", G_TYPE_STRING, - "uri", G_TYPE_STRING, - NULL); - - begin_loading_type = xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "begin_loading", - 0, - "id", G_TYPE_STRING, - "uri", G_TYPE_STRING, - NULL); + XedMessage *message; + WindowData *data; - end_loading_type = xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "end_loading", - 0, - "id", G_TYPE_STRING, - "uri", G_TYPE_STRING, - NULL); + /* Register signals */ + root_changed_type = xed_message_bus_register (bus, + MESSAGE_OBJECT_PATH, "root_changed", + 0, + "id", G_TYPE_STRING, + "location", G_TYPE_FILE, + NULL); - inserted_type = xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "inserted", - 0, - "id", G_TYPE_STRING, - "uri", G_TYPE_STRING, - "is_directory", G_TYPE_BOOLEAN, - NULL); + begin_loading_type = xed_message_bus_register (bus, + MESSAGE_OBJECT_PATH, "begin_loading", + 0, + "id", G_TYPE_STRING, + "location", G_TYPE_FILE, + NULL); - deleted_type = xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "deleted", - 0, - "id", G_TYPE_STRING, - "uri", G_TYPE_STRING, - "is_directory", G_TYPE_BOOLEAN, - NULL); + end_loading_type = xed_message_bus_register (bus, + MESSAGE_OBJECT_PATH, "end_loading", + 0, + "id", G_TYPE_STRING, + "location", G_TYPE_FILE, + NULL); - store = xed_file_browser_widget_get_browser_store (widget); - - message = xed_message_type_instantiate (inserted_type, - "id", NULL, - "uri", NULL, - "is_directory", FALSE, - NULL); + inserted_type = xed_message_bus_register (bus, + MESSAGE_OBJECT_PATH, "inserted", + 0, + "id", G_TYPE_STRING, + "location", G_TYPE_FILE, + "is_directory", G_TYPE_BOOLEAN, + NULL); - data = get_window_data (window); + deleted_type = xed_message_bus_register (bus, + MESSAGE_OBJECT_PATH, "deleted", + 0, + "id", G_TYPE_STRING, + "location", G_TYPE_FILE, + "is_directory", G_TYPE_BOOLEAN, + NULL); - data->row_inserted_id = - g_signal_connect_data (store, - "row-inserted", - G_CALLBACK (store_row_inserted), - message_cache_data_new (window, message), - (GClosureNotify)message_cache_data_free, - 0); + store = xed_file_browser_widget_get_browser_store (widget); - message = xed_message_type_instantiate (deleted_type, - "id", NULL, - "uri", NULL, - "is_directory", FALSE, - NULL); - data->row_deleted_id = - g_signal_connect_data (store, - "row-deleted", - G_CALLBACK (store_row_deleted), - message_cache_data_new (window, message), - (GClosureNotify)message_cache_data_free, - 0); - - message = xed_message_type_instantiate (root_changed_type, - "id", NULL, - "uri", NULL, - NULL); - data->root_changed_id = - g_signal_connect_data (store, - "notify::virtual-root", - G_CALLBACK (store_virtual_root_changed), - message_cache_data_new (window, message), - (GClosureNotify)message_cache_data_free, - 0); + message = xed_message_type_instantiate (inserted_type, + "id", NULL, + "location", NULL, + "is_directory", FALSE, + NULL); - message = xed_message_type_instantiate (begin_loading_type, - "id", NULL, - "uri", NULL, - NULL); - data->begin_loading_id = - g_signal_connect_data (store, - "begin_loading", - G_CALLBACK (store_begin_loading), - message_cache_data_new (window, message), - (GClosureNotify)message_cache_data_free, - 0); + data = get_window_data (window); - message = xed_message_type_instantiate (end_loading_type, - "id", NULL, - "uri", NULL, - NULL); - data->end_loading_id = - g_signal_connect_data (store, - "end_loading", - G_CALLBACK (store_end_loading), - message_cache_data_new (window, message), - (GClosureNotify)message_cache_data_free, - 0); + data->row_inserted_id = + g_signal_connect_data (store, + "row-inserted", + G_CALLBACK (store_row_inserted), + message_cache_data_new (window, message), + (GClosureNotify)message_cache_data_free, + 0); + + message = xed_message_type_instantiate (deleted_type, + "id", NULL, + "location", NULL, + "is_directory", FALSE, + NULL); + data->row_deleted_id = + g_signal_connect_data (store, + "row-deleted", + G_CALLBACK (store_row_deleted), + message_cache_data_new (window, message), + (GClosureNotify)message_cache_data_free, + 0); + + message = xed_message_type_instantiate (root_changed_type, + "id", NULL, + "location", NULL, + NULL); + data->root_changed_id = + g_signal_connect_data (store, + "notify::virtual-root", + G_CALLBACK (store_virtual_root_changed), + message_cache_data_new (window, message), + (GClosureNotify)message_cache_data_free, + 0); + + message = xed_message_type_instantiate (begin_loading_type, + "id", NULL, + "location", NULL, + NULL); + data->begin_loading_id = + g_signal_connect_data (store, + "begin_loading", + G_CALLBACK (store_begin_loading), + message_cache_data_new (window, message), + (GClosureNotify)message_cache_data_free, + 0); + + message = xed_message_type_instantiate (end_loading_type, + "id", NULL, + "location", NULL, + NULL); + data->end_loading_id = + g_signal_connect_data (store, + "end_loading", + G_CALLBACK (store_end_loading), + message_cache_data_new (window, message), + (GClosureNotify)message_cache_data_free, + 0); } static void message_unregistered (XedMessageBus *bus, - XedMessageType *message_type, - XedWindow *window) + XedMessageType *message_type, + XedWindow *window) { - gchar *identifier = xed_message_type_identifier (xed_message_type_get_object_path (message_type), - xed_message_type_get_method (message_type)); - FilterData *data; - WindowData *wdata = get_window_data (window); - - data = g_hash_table_lookup (wdata->filters, identifier); - - if (data) - xed_file_browser_widget_remove_filter (wdata->widget, data->id); - - g_free (identifier); + gchar *identifier = xed_message_type_identifier (xed_message_type_get_object_path (message_type), + xed_message_type_get_method (message_type)); + FilterData *data; + WindowData *wdata = get_window_data (window); + + data = g_hash_table_lookup (wdata->filters, identifier); + + if (data) + xed_file_browser_widget_remove_filter (wdata->widget, data->id); + + g_free (identifier); } -void -xed_file_browser_messages_register (XedWindow *window, - XedFileBrowserWidget *widget) +void +xed_file_browser_messages_register (XedWindow *window, + XedFileBrowserWidget *widget) { - window_data_new (window, widget); - - register_methods (window, widget); - register_signals (window, widget); - - g_signal_connect (xed_window_get_message_bus (window), - "unregistered", - G_CALLBACK (message_unregistered), - window); + window_data_new (window, widget); + + register_methods (window, widget); + register_signals (window, widget); + + g_signal_connect (xed_window_get_message_bus (window), + "unregistered", + G_CALLBACK (message_unregistered), + window); } static void cleanup_signals (XedWindow *window) { - WindowData *data = get_window_data (window); - XedFileBrowserStore *store; - - store = xed_file_browser_widget_get_browser_store (data->widget); - - g_signal_handler_disconnect (store, data->row_inserted_id); - g_signal_handler_disconnect (store, data->row_deleted_id); - g_signal_handler_disconnect (store, data->root_changed_id); - g_signal_handler_disconnect (store, data->begin_loading_id); - g_signal_handler_disconnect (store, data->end_loading_id); - - g_signal_handlers_disconnect_by_func (data->bus, message_unregistered, window); + WindowData *data = get_window_data (window); + XedFileBrowserStore *store; + + store = xed_file_browser_widget_get_browser_store (data->widget); + + g_signal_handler_disconnect (store, data->row_inserted_id); + g_signal_handler_disconnect (store, data->row_deleted_id); + g_signal_handler_disconnect (store, data->root_changed_id); + g_signal_handler_disconnect (store, data->begin_loading_id); + g_signal_handler_disconnect (store, data->end_loading_id); + + g_signal_handlers_disconnect_by_func (data->bus, message_unregistered, window); } void xed_file_browser_messages_unregister (XedWindow *window) { - XedMessageBus *bus = xed_window_get_message_bus (window); - - cleanup_signals (window); - xed_message_bus_unregister_all (bus, MESSAGE_OBJECT_PATH); + XedMessageBus *bus = xed_window_get_message_bus (window); - window_data_free (window); + cleanup_signals (window); + xed_message_bus_unregister_all (bus, MESSAGE_OBJECT_PATH); + + window_data_free (window); } diff --git a/plugins/filebrowser/xed-file-browser-plugin.c b/plugins/filebrowser/xed-file-browser-plugin.c index 52241c6..7319199 100644 --- a/plugins/filebrowser/xed-file-browser-plugin.c +++ b/plugins/filebrowser/xed-file-browser-plugin.c @@ -68,9 +68,9 @@ enum PROP_WINDOW }; -static void on_uri_activated_cb (XedFileBrowserWidget *widget, - gchar const *uri, - XedWindow *window); +static void on_location_activated_cb (XedFileBrowserWidget *widget, + GFile *location, + XedWindow *window); static void on_error_cb (XedFileBrowserWidget *widget, guint code, gchar const *message, @@ -85,8 +85,8 @@ static void on_filter_mode_changed_cb (XedFileBrowserStore *model, GParamSpec *param, XedFileBrowserPlugin *plugin); static void on_rename_cb (XedFileBrowserStore *model, - const gchar *olduri, - const gchar *newuri, + GFile *oldfile, + GFile *newfile, XedWindow *window); static void on_filter_pattern_changed_cb (XedFileBrowserWidget *widget, GParamSpec *param, @@ -229,25 +229,28 @@ restore_default_location (XedFileBrowserPlugin *plugin) remote = g_settings_get_boolean (priv->onload_settings, "enable-remote"); if (root != NULL && *root != '\0') { - GFile *file; + GFile *rootfile; + GFile *vrootfile; - file = g_file_new_for_uri (root); + rootfile = g_file_new_for_uri (root); + vrootfile = g_file_new_for_uri (virtual_root); - if (remote || g_file_is_native (file)) + if (remote || g_file_is_native (rootfile)) { if (virtual_root != NULL && *virtual_root != '\0') { prepare_auto_root (plugin); - xed_file_browser_widget_set_root_and_virtual_root (priv->tree_widget, root, virtual_root); + xed_file_browser_widget_set_root_and_virtual_root (priv->tree_widget, rootfile, vrootfile); } else { prepare_auto_root (plugin); - xed_file_browser_widget_set_root (priv->tree_widget, root, TRUE); + xed_file_browser_widget_set_root (priv->tree_widget, rootfile, TRUE); } } - g_object_unref (file); + g_object_unref (rootfile); + g_object_unref (vrootfile); } g_free (root); @@ -317,16 +320,11 @@ set_root_from_doc (XedFileBrowserPlugin *plugin, if (parent != NULL) { - gchar * root; - - root = g_file_get_uri (parent); - xed_file_browser_widget_set_root (priv->tree_widget, - root, + parent, TRUE); g_object_unref (parent); - g_free (root); } g_object_unref (file); @@ -352,7 +350,6 @@ on_action_open_terminal (GtkAction *action, { XedFileBrowserPluginPrivate *priv = plugin->priv; gchar *terminal; - gchar *wd = NULL; gchar *local; gchar *argv[2]; GFile *file; @@ -367,18 +364,16 @@ on_action_open_terminal (GtkAction *action, } store = xed_file_browser_widget_get_browser_store (priv->tree_widget); - gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, XED_FILE_BROWSER_STORE_COLUMN_URI, &wd, -1); + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &file, -1); - if (wd == NULL) + if (file == NULL) { return; } terminal = get_terminal (plugin); - file = g_file_new_for_uri (wd); local = g_file_get_path (file); - g_object_unref (file); argv[0] = terminal; argv[1] = NULL; @@ -393,7 +388,6 @@ on_action_open_terminal (GtkAction *action, NULL); g_free (terminal); - g_free (wd); g_free (local); } @@ -406,7 +400,7 @@ on_selection_changed_cb (GtkTreeSelection *selection, GtkTreeModel *model; GtkTreeIter iter; gboolean sensitive; - gchar *uri; + GFile *location; tree_view = GTK_TREE_VIEW (xed_file_browser_widget_get_browser_view (priv->tree_widget)); model = gtk_tree_view_get_model (tree_view); @@ -420,10 +414,9 @@ on_selection_changed_cb (GtkTreeSelection *selection, if (sensitive) { - gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, -1); + gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); - sensitive = xed_utils_uri_has_file_scheme (uri); - g_free (uri); + sensitive = xed_utils_location_has_file_scheme (location); } gtk_action_set_sensitive (gtk_action_group_get_action (priv->single_selection_action_group, "OpenTerminal"), sensitive); @@ -550,8 +543,8 @@ xed_file_browser_plugin_activate (XedWindowActivatable *activatable) priv->settings = g_settings_new (FILE_BROWSER_SCHEMA); priv->onload_settings = g_settings_new (FILE_BROWSER_ONLOAD_SCHEMA); - g_signal_connect (priv->tree_widget, "uri-activated", - G_CALLBACK (on_uri_activated_cb), priv->window); + g_signal_connect (priv->tree_widget, "location-activated", + G_CALLBACK (on_location_activated_cb), priv->window); g_signal_connect (priv->tree_widget, "error", G_CALLBACK (on_error_cb), plugin); @@ -652,11 +645,11 @@ xed_file_browser_plugin_class_finalize (XedFileBrowserPluginClass *klass) /* Callbacks */ static void -on_uri_activated_cb (XedFileBrowserWidget *tree_widget, - gchar const *uri, - XedWindow *window) +on_location_activated_cb (XedFileBrowserWidget *tree_widget, + GFile *location, + XedWindow *window) { - xed_commands_load_uri (window, uri, NULL, 0); + xed_commands_load_location (window, location, NULL, 0); } static void @@ -764,41 +757,33 @@ on_filter_mode_changed_cb (XedFileBrowserStore *model, static void on_rename_cb (XedFileBrowserStore *store, - const gchar *olduri, - const gchar *newuri, - XedWindow *window) + GFile *oldfile, + GFile *newfile, + XedWindow *window) { XedApp *app; GList *documents; GList *item; XedDocument *doc; GFile *docfile; - GFile *oldfile; - GFile *newfile; - gchar *uri; /* Find all documents and set its uri to newuri where it matches olduri */ app = xed_app_get_default (); documents = xed_app_get_documents (app); - oldfile = g_file_new_for_uri (olduri); - newfile = g_file_new_for_uri (newuri); - for (item = documents; item; item = item->next) { doc = XED_DOCUMENT (item->data); - uri = xed_document_get_uri (doc); + docfile = xed_document_get_location (doc); - if (!uri) + if (!docfile) { continue; } - docfile = g_file_new_for_uri (uri); - if (g_file_equal (docfile, oldfile)) { - xed_document_set_uri (doc, newuri); + xed_document_set_location (doc, newfile); } else { @@ -812,24 +797,18 @@ on_rename_cb (XedFileBrowserStore *store, the prefix oldfile */ g_object_unref (docfile); - g_free (uri); docfile = g_file_get_child (newfile, relative); - uri = g_file_get_uri (docfile); - xed_document_set_uri (doc, uri); + xed_document_set_location (doc, docfile); } g_free (relative); } - g_free (uri); g_object_unref (docfile); } - g_object_unref (oldfile); - g_object_unref (newfile); - g_list_free (documents); } @@ -861,8 +840,9 @@ on_virtual_root_changed_cb (XedFileBrowserStore *store, XedFileBrowserPlugin *plugin) { XedFileBrowserPluginPrivate *priv = plugin->priv; - gchar * root; - gchar * virtual_root; + GFile *root; + GFile *virtual_root; + gchar *uri_root = NULL; root = xed_file_browser_store_get_root (store); @@ -870,25 +850,35 @@ on_virtual_root_changed_cb (XedFileBrowserStore *store, { return; } + else + { + uri_root = g_file_get_uri (root); + g_object_unref (root); + } - g_settings_set_string (priv->onload_settings, "root", root); + g_settings_set_string (priv->onload_settings, "root", uri_root); + g_free (uri_root); virtual_root = xed_file_browser_store_get_virtual_root (store); if (!virtual_root) { /* Set virtual to same as root then */ - g_settings_set_string (priv->onload_settings, "virtual-root", root); + g_settings_set_string (priv->onload_settings, "virtual-root", uri_root); } else { - g_settings_set_string (priv->onload_settings, "virtual-root", virtual_root); + gchar *uri_vroot; + + uri_vroot = g_file_get_uri (virtual_root); + + g_settings_set_string (priv->onload_settings, "virtual-root", uri_vroot); + + g_free (uri_vroot); + g_object_unref (virtual_root); } g_signal_handlers_disconnect_by_func (XED_WINDOW (priv->window), G_CALLBACK (on_tab_added_cb), plugin); - - g_free (root); - g_free (virtual_root); } static void @@ -905,23 +895,27 @@ on_tab_added_cb (XedWindow *window, if (open) { XedDocument *doc; - gchar *uri; + GFile *location; doc = xed_tab_get_document (tab); - uri = xed_document_get_uri (doc); + location = xed_document_get_location (doc); - if (uri != NULL && xed_utils_uri_has_file_scheme (uri)) + if (location != NULL) { - prepare_auto_root (plugin); - set_root_from_doc (plugin, doc); - load_default = FALSE; + if (xed_utils_location_has_file_scheme (location)) + { + prepare_auto_root (plugin); + set_root_from_doc (plugin, doc); + load_default = FALSE; + } + g_object_unref (location); } - - g_free (uri); } if (load_default) + { restore_default_location (plugin); + } /* Disconnect this signal, it's only called once */ g_signal_handlers_disconnect_by_func (window, G_CALLBACK (on_tab_added_cb), plugin); @@ -932,12 +926,12 @@ get_filename_from_path (GtkTreeModel *model, GtkTreePath *path) { GtkTreeIter iter; - gchar *uri; + GFile *location; gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, -1); + gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); - return xed_file_browser_utils_uri_basename (uri); + return xed_file_browser_utils_file_basename (location); } static gboolean diff --git a/plugins/filebrowser/xed-file-browser-store.c b/plugins/filebrowser/xed-file-browser-store.c index dade6dc..dbd083c 100644 --- a/plugins/filebrowser/xed-file-browser-store.c +++ b/plugins/filebrowser/xed-file-browser-store.c @@ -81,7 +81,7 @@ struct _AsyncNode typedef struct { XedFileBrowserStore *model; - gchar *virtual_root; + GFile *virtual_root; GMountOperation *operation; GCancellable *cancellable; } MountInfo; @@ -267,16 +267,13 @@ static void set_gvalue_from_node (GValue *value, FileBrowserNode *node) { - gchar * uri; - - if (node == NULL || !node->file) + if (node == NULL) { - g_value_set_string (value, NULL); + g_value_set_object (value, NULL); } else { - uri = g_file_get_uri (node->file); - g_value_take_string (value, uri); + g_value_set_object (value, node->file); } } @@ -335,17 +332,17 @@ xed_file_browser_store_class_init (XedFileBrowserStoreClass * klass) object_class->set_property = xed_file_browser_store_set_property; g_object_class_install_property (object_class, PROP_ROOT, - g_param_spec_string ("root", + g_param_spec_object ("root", "Root", - "The root uri", - NULL, + "The root location", + G_TYPE_FILE, G_PARAM_READABLE)); g_object_class_install_property (object_class, PROP_VIRTUAL_ROOT, - g_param_spec_string ("virtual-root", + g_param_spec_object ("virtual-root", "Virtual Root", - "The virtual root uri", - NULL, + "The virtual root location", + G_TYPE_FILE, G_PARAM_READABLE)); g_object_class_install_property (object_class, PROP_FILTER_MODE, @@ -394,10 +391,10 @@ xed_file_browser_store_class_init (XedFileBrowserStoreClass * klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (XedFileBrowserStoreClass, rename), NULL, NULL, - xed_file_browser_marshal_VOID__STRING_STRING, + xed_file_browser_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 2, - G_TYPE_STRING, - G_TYPE_STRING); + G_TYPE_FILE, + G_TYPE_FILE); model_signals[BEGIN_REFRESH] = g_signal_new ("begin-refresh", G_OBJECT_CLASS_TYPE (object_class), @@ -420,9 +417,9 @@ xed_file_browser_store_class_init (XedFileBrowserStoreClass * klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (XedFileBrowserStoreClass, unload), NULL, NULL, - g_cclosure_marshal_VOID__STRING, + g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, - G_TYPE_STRING); + G_TYPE_FILE); g_type_class_add_private (object_class, sizeof (XedFileBrowserStorePrivate)); } @@ -464,7 +461,7 @@ xed_file_browser_store_init (XedFileBrowserStore * obj) { obj->priv = XED_FILE_BROWSER_STORE_GET_PRIVATE (obj); - obj->priv->column_types[XED_FILE_BROWSER_STORE_COLUMN_URI] = G_TYPE_STRING; + obj->priv->column_types[XED_FILE_BROWSER_STORE_COLUMN_LOCATION] = G_TYPE_FILE; obj->priv->column_types[XED_FILE_BROWSER_STORE_COLUMN_NAME] = G_TYPE_STRING; obj->priv->column_types[XED_FILE_BROWSER_STORE_COLUMN_FLAGS] = G_TYPE_UINT; obj->priv->column_types[XED_FILE_BROWSER_STORE_COLUMN_ICON] = GDK_TYPE_PIXBUF; @@ -713,7 +710,7 @@ xed_file_browser_store_get_value (GtkTreeModel *tree_model, switch (column) { - case XED_FILE_BROWSER_STORE_COLUMN_URI: + case XED_FILE_BROWSER_STORE_COLUMN_LOCATION: set_gvalue_from_node (value, node); break; case XED_FILE_BROWSER_STORE_COLUMN_NAME: @@ -1013,7 +1010,7 @@ xed_file_browser_store_drag_data_get (GtkTreeDragSource *drag_source, GtkSelectionData *selection_data) { GtkTreeIter iter; - gchar *uri; + GFile *location; gchar *uris[2] = {0, }; gboolean ret; @@ -1022,14 +1019,14 @@ xed_file_browser_store_drag_data_get (GtkTreeDragSource *drag_source, return FALSE; } - gtk_tree_model_get (GTK_TREE_MODEL (drag_source), &iter, XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, -1); + gtk_tree_model_get (GTK_TREE_MODEL (drag_source), &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); - g_assert (uri); + g_assert (location); - uris[0] = uri; + uris[0] = g_file_get_uri (location); ret = gtk_selection_data_set_uris (selection_data, uris); - g_free (uri); + g_free (uris[0]); return ret; } @@ -1448,8 +1445,6 @@ static void file_browser_node_free (XedFileBrowserStore *model, FileBrowserNode *node) { - gchar *uri; - if (node == NULL) { return; @@ -1485,10 +1480,7 @@ file_browser_node_free (XedFileBrowserStore *model, if (node->file) { - uri = g_file_get_uri (node->file); - g_signal_emit (model, model_signals[UNLOAD], 0, uri); - - g_free (uri); + g_signal_emit (model, model_signals[UNLOAD], 0, node->file); g_object_unref (node->file); } @@ -2940,14 +2932,14 @@ unique_new_name (GFile *directory, static XedFileBrowserStoreResult model_root_mounted (XedFileBrowserStore *model, - gchar const *virtual_root) + GFile *virtual_root) { model_check_dummy (model, model->priv->root); g_object_notify (G_OBJECT (model), "root"); if (virtual_root != NULL) { - return xed_file_browser_store_set_virtual_root_from_string (model, virtual_root); + return xed_file_browser_store_set_virtual_root_from_location (model, virtual_root); } else { @@ -3028,7 +3020,7 @@ mount_cb (GFile *file, static XedFileBrowserStoreResult model_mount_root (XedFileBrowserStore *model, - gchar const *virtual_root) + GFile *virtual_root) { GFileInfo *info; GError *error = NULL; @@ -3049,7 +3041,7 @@ model_mount_root (XedFileBrowserStore *model, mount_info = g_new(MountInfo, 1); mount_info->model = model; - mount_info->virtual_root = g_strdup (virtual_root); + mount_info->virtual_root = g_file_dup (virtual_root); /* FIXME: we should be setting the correct window */ mount_info->operation = gtk_mount_operation_new (NULL); @@ -3085,7 +3077,7 @@ model_mount_root (XedFileBrowserStore *model, /* Public */ XedFileBrowserStore * -xed_file_browser_store_new (gchar const *root) +xed_file_browser_store_new (GFile *root) { XedFileBrowserStore *obj = XED_FILE_BROWSER_STORE (g_object_new (XED_TYPE_FILE_BROWSER_STORE, NULL)); @@ -3156,56 +3148,52 @@ xed_file_browser_store_set_virtual_root (XedFileBrowserStore *model, } XedFileBrowserStoreResult -xed_file_browser_store_set_virtual_root_from_string (XedFileBrowserStore *model, - gchar const *root) +xed_file_browser_store_set_virtual_root_from_location (XedFileBrowserStore *model, + GFile *root) { - GFile *file; - g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); - file = g_file_new_for_uri (root); - if (file == NULL) + if (root == NULL) { - g_warning ("Invalid uri (%s)", root); + gchar *uri; + + uri = g_file_get_uri (root); + g_warning ("Invalid uri (%s)", uri); + g_free (uri); return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; } /* Check if uri is already the virtual root */ - if (model->priv->virtual_root && g_file_equal (model->priv->virtual_root->file, file)) + if (model->priv->virtual_root && g_file_equal (model->priv->virtual_root->file, root)) { - g_object_unref (file); return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; } /* Check if uri is the root itself */ - if (g_file_equal (model->priv->root->file, file)) + if (g_file_equal (model->priv->root->file, root)) { - g_object_unref (file); - /* Always clear the model before altering the nodes */ model_clear (model, FALSE); set_virtual_root_from_node (model, model->priv->root); return XED_FILE_BROWSER_STORE_RESULT_OK; } - if (!g_file_has_prefix (file, model->priv->root->file)) + if (!g_file_has_prefix (root, model->priv->root->file)) { gchar *str, *str1; str = g_file_get_parse_name (model->priv->root->file); - str1 = g_file_get_parse_name (file); + str1 = g_file_get_parse_name (root); g_warning ("Virtual root (%s) is not below actual root (%s)", str1, str); g_free (str); g_free (str1); - g_object_unref (file); return XED_FILE_BROWSER_STORE_RESULT_ERROR; } - set_virtual_root_from_file (model, file); - g_object_unref (file); + set_virtual_root_from_file (model, root); return XED_FILE_BROWSER_STORE_RESULT_OK; } @@ -3298,11 +3286,9 @@ xed_file_browser_store_cancel_mount_operation (XedFileBrowserStore *store) XedFileBrowserStoreResult xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore *model, - gchar const *root, - gchar const *virtual_root) + GFile *root, + GFile *virtual_root) { - GFile * file = NULL; - GFile * vfile = NULL; FileBrowserNode * node; gboolean equal = FALSE; @@ -3313,38 +3299,22 @@ xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore *model, return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; } - if (root != NULL) - { - file = g_file_new_for_uri (root); - } - if (root != NULL && model->priv->root != NULL) { - equal = g_file_equal (file, model->priv->root->file); + equal = g_file_equal (root, model->priv->root->file); if (equal && virtual_root == NULL) { - g_object_unref (file); return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; } } if (virtual_root) { - vfile = g_file_new_for_uri (virtual_root); - - if (equal && g_file_equal (vfile, model->priv->virtual_root->file)) + if (equal && g_file_equal (virtual_root, model->priv->virtual_root->file)) { - if (file) - { - g_object_unref (file); - } - - g_object_unref (vfile); return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE; } - - g_object_unref (vfile); } /* make sure to cancel any previous mount operations */ @@ -3357,12 +3327,10 @@ xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore *model, model->priv->root = NULL; model->priv->virtual_root = NULL; - if (file != NULL) + if (root != NULL) { /* Create the root node */ - node = file_browser_node_dir_new (model, file, NULL); - - g_object_unref (file); + node = file_browser_node_dir_new (model, root, NULL); model->priv->root = node; return model_mount_root (model, virtual_root); @@ -3378,13 +3346,13 @@ xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore *model, XedFileBrowserStoreResult xed_file_browser_store_set_root (XedFileBrowserStore *model, - gchar const *root) + GFile *root) { g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE); return xed_file_browser_store_set_root_and_virtual_root (model, root, NULL); } -gchar * +GFile * xed_file_browser_store_get_root (XedFileBrowserStore * model) { g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), NULL); @@ -3395,11 +3363,11 @@ xed_file_browser_store_get_root (XedFileBrowserStore * model) } else { - return g_file_get_uri (model->priv->root->file); + return g_file_dup (model->priv->root->file); } } -gchar * +GFile * xed_file_browser_store_get_virtual_root (XedFileBrowserStore *model) { g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), NULL); @@ -3410,7 +3378,7 @@ xed_file_browser_store_get_virtual_root (XedFileBrowserStore *model) } else { - return g_file_get_uri (model->priv->virtual_root->file); + return g_file_dup (model->priv->virtual_root->file); } } @@ -3573,8 +3541,6 @@ xed_file_browser_store_rename (XedFileBrowserStore *model, GFile *parent; GFile *previous; GError *err = NULL; - gchar *olduri; - gchar *newuri; GtkTreePath *path; g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), FALSE); @@ -3628,14 +3594,9 @@ xed_file_browser_store_rename (XedFileBrowserStore *model, return FALSE; } - olduri = g_file_get_uri (previous); - newuri = g_file_get_uri (node->file); - - g_signal_emit (model, model_signals[RENAME], 0, olduri, newuri); + g_signal_emit (model, model_signals[RENAME], 0, previous, node->file); g_object_unref (previous); - g_free (olduri); - g_free (newuri); return TRUE; } diff --git a/plugins/filebrowser/xed-file-browser-store.h b/plugins/filebrowser/xed-file-browser-store.h index 03e3124..99ff5e9 100644 --- a/plugins/filebrowser/xed-file-browser-store.h +++ b/plugins/filebrowser/xed-file-browser-store.h @@ -37,7 +37,7 @@ typedef enum { XED_FILE_BROWSER_STORE_COLUMN_ICON = 0, XED_FILE_BROWSER_STORE_COLUMN_NAME, - XED_FILE_BROWSER_STORE_COLUMN_URI, + XED_FILE_BROWSER_STORE_COLUMN_LOCATION, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, XED_FILE_BROWSER_STORE_COLUMN_EMBLEM, XED_FILE_BROWSER_STORE_COLUMN_NUM @@ -106,28 +106,28 @@ struct _XedFileBrowserStoreClass { gboolean (*no_trash) (XedFileBrowserStore *model, GList *files); void (*rename) (XedFileBrowserStore *model, - const gchar *olduri, - const gchar *newuri); + GFile *oldfile, + GFile *newfile); void (*begin_refresh) (XedFileBrowserStore *model); void (*end_refresh) (XedFileBrowserStore *model); void (*unload) (XedFileBrowserStore *model, - const gchar *uri); + GFile *location); }; GType xed_file_browser_store_get_type (void) G_GNUC_CONST; void _xed_file_browser_store_register_type (GTypeModule *type_module); -XedFileBrowserStore *xed_file_browser_store_new (gchar const *root); +XedFileBrowserStore *xed_file_browser_store_new (GFile *root); XedFileBrowserStoreResult xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore *model, - gchar const *root, - gchar const *virtual_root); + GFile *root, + GFile *virtual_root); XedFileBrowserStoreResult xed_file_browser_store_set_root (XedFileBrowserStore *model, - gchar const *root); + GFile *root); XedFileBrowserStoreResult xed_file_browser_store_set_virtual_root (XedFileBrowserStore *model, GtkTreeIter *iter); -XedFileBrowserStoreResult xed_file_browser_store_set_virtual_root_from_string (XedFileBrowserStore *model, - gchar const *root); +XedFileBrowserStoreResult xed_file_browser_store_set_virtual_root_from_location (XedFileBrowserStore *model, + GFile *root); XedFileBrowserStoreResult xed_file_browser_store_set_virtual_root_up (XedFileBrowserStore *model); XedFileBrowserStoreResult xed_file_browser_store_set_virtual_root_top (XedFileBrowserStore *model); @@ -135,8 +135,8 @@ gboolean xed_file_browser_store_get_iter_virtual_root (XedFileBrowserStore *mode GtkTreeIter *iter); gboolean xed_file_browser_store_get_iter_root (XedFileBrowserStore *model, GtkTreeIter *iter); -gchar * xed_file_browser_store_get_root (XedFileBrowserStore *model); -gchar * xed_file_browser_store_get_virtual_root (XedFileBrowserStore *model); +GFile * xed_file_browser_store_get_root (XedFileBrowserStore *model); +GFile * xed_file_browser_store_get_virtual_root (XedFileBrowserStore *model); gboolean xed_file_browser_store_iter_equal (XedFileBrowserStore *model, GtkTreeIter *iter1, diff --git a/plugins/filebrowser/xed-file-browser-utils.c b/plugins/filebrowser/xed-file-browser-utils.c index 6565713..2c3fbb7 100644 --- a/plugins/filebrowser/xed-file-browser-utils.c +++ b/plugins/filebrowser/xed-file-browser-utils.c @@ -1,5 +1,5 @@ /* - * xed-file-bookmarks-store.c - Xed plugin providing easy file access + * xed-file-bookmarks-store.c - Xed plugin providing easy file access * from the sidepanel * * Copyright (C) 2006 - Jesse van den Kieboom @@ -24,8 +24,8 @@ static GdkPixbuf * process_icon_pixbuf (GdkPixbuf * pixbuf, - gchar const * name, - gint size, + gchar const * name, + gint size, GError * error) { GdkPixbuf * scale; @@ -36,11 +36,11 @@ process_icon_pixbuf (GdkPixbuf * pixbuf, error->message); g_error_free (error); } - + if (pixbuf && gdk_pixbuf_get_width (pixbuf) > size) { - scale = gdk_pixbuf_scale_simple (pixbuf, - size, - size, + scale = gdk_pixbuf_scale_simple (pixbuf, + size, + size, GDK_INTERP_BILINEAR); g_object_unref (pixbuf); pixbuf = scale; @@ -59,10 +59,10 @@ xed_file_browser_utils_pixbuf_from_theme (gchar const * name, gtk_icon_size_lookup (size, &width, NULL); - pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), - name, - width, - 0, + pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), + name, + width, + 0, &error); pixbuf = process_icon_pixbuf (pixbuf, name, width, error); @@ -84,7 +84,7 @@ xed_file_browser_utils_pixbuf_from_icon (GIcon * icon, theme = gtk_icon_theme_get_default (); gtk_icon_size_lookup (size, &width, NULL); - + info = gtk_icon_theme_lookup_by_gicon (theme, icon, width, @@ -92,10 +92,10 @@ xed_file_browser_utils_pixbuf_from_icon (GIcon * icon, if (!info) return NULL; - + ret = gtk_icon_info_load_icon (info, NULL); gtk_icon_info_free (info); - + return ret; } @@ -107,12 +107,12 @@ xed_file_browser_utils_pixbuf_from_file (GFile * file, GFileInfo * info; GdkPixbuf * ret = NULL; - info = g_file_query_info (file, - G_FILE_ATTRIBUTE_STANDARD_ICON, + info = g_file_query_info (file, + G_FILE_ATTRIBUTE_STANDARD_ICON, G_FILE_QUERY_INFO_NONE, - NULL, + NULL, NULL); - + if (!info) return NULL; @@ -121,35 +121,22 @@ xed_file_browser_utils_pixbuf_from_file (GFile * file, ret = xed_file_browser_utils_pixbuf_from_icon (icon, size); g_object_unref (info); - + return ret; } gchar * xed_file_browser_utils_file_basename (GFile * file) { - gchar *uri; - gchar *ret; - - uri = g_file_get_uri (file); - ret = xed_file_browser_utils_uri_basename (uri); - g_free (uri); - - return ret; -} - -gchar * -xed_file_browser_utils_uri_basename (gchar const * uri) -{ - return xed_utils_basename_for_display (uri); + return xed_utils_basename_for_display (file); } gboolean xed_file_browser_utils_confirmation_dialog (XedWindow * window, GtkMessageType type, gchar const *message, - gchar const *secondary, - gchar const * button_stock, + gchar const *secondary, + gchar const * button_stock, gchar const * button_label) { GtkWidget *dlg; @@ -177,18 +164,18 @@ xed_file_browser_utils_confirmation_dialog (XedWindow * window, /* Add custom button */ button = gtk_button_new_from_stock (button_stock); - + if (button_label) { gtk_button_set_use_stock (GTK_BUTTON (button), FALSE); gtk_button_set_label (GTK_BUTTON (button), button_label); } - + gtk_widget_show (button); gtk_widget_set_can_default (button, TRUE); gtk_dialog_add_action_widget (GTK_DIALOG (dlg), button, GTK_RESPONSE_OK); - + ret = gtk_dialog_run (GTK_DIALOG (dlg)); gtk_widget_destroy (dlg); diff --git a/plugins/filebrowser/xed-file-browser-utils.h b/plugins/filebrowser/xed-file-browser-utils.h index b1400c1..bd17b84 100644 --- a/plugins/filebrowser/xed-file-browser-utils.h +++ b/plugins/filebrowser/xed-file-browser-utils.h @@ -13,13 +13,12 @@ GdkPixbuf *xed_file_browser_utils_pixbuf_from_file (GFile * file, GtkIconSize size); gchar * xed_file_browser_utils_file_basename (GFile * file); -gchar * xed_file_browser_utils_uri_basename (gchar const * uri); gboolean xed_file_browser_utils_confirmation_dialog (XedWindow * window, GtkMessageType type, gchar const *message, - gchar const *secondary, - gchar const * button_stock, + gchar const *secondary, + gchar const * button_stock, gchar const * button_label); #endif /* __XED_FILE_BROWSER_UTILS_H__ */ diff --git a/plugins/filebrowser/xed-file-browser-view.c b/plugins/filebrowser/xed-file-browser-view.c index f412e2a..7eddd49 100644 --- a/plugins/filebrowser/xed-file-browser-view.c +++ b/plugins/filebrowser/xed-file-browser-view.c @@ -99,7 +99,7 @@ static void on_end_refresh (XedFileBrowserStore *model, XedFileBrowserView *view); static void on_unload (XedFileBrowserStore *model, - gchar const *uri, + GFile *location, XedFileBrowserView *view); static void on_row_inserted (XedFileBrowserStore *model, @@ -135,46 +135,32 @@ xed_file_browser_view_finalize (GObject *object) static void add_expand_state (XedFileBrowserView *view, - gchar const *uri) + GFile *location) { - GFile * file; - - if (!uri) + if (!location) { return; } - file = g_file_new_for_uri (uri); - if (view->priv->expand_state) { - g_hash_table_insert (view->priv->expand_state, file, file); - } - else - { - g_object_unref (file); + g_hash_table_insert (view->priv->expand_state, location, g_object_ref (location)); } } static void remove_expand_state (XedFileBrowserView *view, - gchar const *uri) + GFile *location) { - GFile * file; - - if (!uri) + if (!location) { return; } - file = g_file_new_for_uri (uri); - if (view->priv->expand_state) { - g_hash_table_remove (view->priv->expand_state, file); + g_hash_table_remove (view->priv->expand_state, location); } - - g_object_unref (file); } static void @@ -183,7 +169,7 @@ row_expanded (GtkTreeView *tree_view, GtkTreePath *path) { XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (tree_view); - gchar *uri; + GFile *location; if (GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_expanded) { @@ -197,10 +183,9 @@ row_expanded (GtkTreeView *tree_view, if (view->priv->restore_expand_state) { - gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, -1); + gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); - add_expand_state (view, uri); - g_free (uri); + add_expand_state (view, location); } _xed_file_browser_store_iter_expanded (XED_FILE_BROWSER_STORE (view->priv->model), iter); @@ -212,7 +197,7 @@ row_collapsed (GtkTreeView *tree_view, GtkTreePath *path) { XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (tree_view); - gchar * uri; + GFile *location; if (GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_collapsed) { @@ -226,10 +211,9 @@ row_collapsed (GtkTreeView *tree_view, if (view->priv->restore_expand_state) { - gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, -1); + gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); - remove_expand_state (view, uri); - g_free (uri); + remove_expand_state (view, location); } _xed_file_browser_store_iter_collapsed (XED_FILE_BROWSER_STORE (view->priv->model), iter); @@ -766,7 +750,7 @@ fill_expand_state (XedFileBrowserView *view, { GtkTreePath * path; GtkTreeIter child; - gchar * uri; + GFile *location; if (!gtk_tree_model_iter_has_child (view->priv->model, iter)) { @@ -779,12 +763,11 @@ fill_expand_state (XedFileBrowserView *view, { gtk_tree_model_get (view->priv->model, iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, - &uri, + XED_FILE_BROWSER_STORE_COLUMN_LOCATION, + &location, -1); - add_expand_state (view, uri); - g_free (uri); + add_expand_state (view, location); } if (gtk_tree_model_iter_children (view->priv->model, &child, iter)) @@ -1273,7 +1256,7 @@ on_end_refresh (XedFileBrowserStore *model, static void on_unload (XedFileBrowserStore *model, - gchar const *uri, + GFile *location, XedFileBrowserView *view) { /* Don't remove the expand state if we are refreshing */ @@ -1282,7 +1265,7 @@ on_unload (XedFileBrowserStore *model, return; } - remove_expand_state (view, uri); + remove_expand_state (view, location); } static void @@ -1290,33 +1273,28 @@ restore_expand_state (XedFileBrowserView *view, XedFileBrowserStore *model, GtkTreeIter *iter) { - gchar *uri; - GFile *file; + GFile *location; GtkTreePath *path; gtk_tree_model_get (GTK_TREE_MODEL (model), iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, - &uri, + XED_FILE_BROWSER_STORE_COLUMN_LOCATION, + &location, -1); - if (!uri) + if (!location) { return; } - file = g_file_new_for_uri (uri); path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), iter); - if (g_hash_table_lookup (view->priv->expand_state, file)) + if (g_hash_table_lookup (view->priv->expand_state, location)) { gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, FALSE); } gtk_tree_path_free (path); - - g_object_unref (file); - g_free (uri); } static void diff --git a/plugins/filebrowser/xed-file-browser-widget.c b/plugins/filebrowser/xed-file-browser-widget.c index a9a8488..6d21fbd 100644 --- a/plugins/filebrowser/xed-file-browser-widget.c +++ b/plugins/filebrowser/xed-file-browser-widget.c @@ -80,7 +80,7 @@ enum /* Signals */ enum { - URI_ACTIVATED, + LOCATION_ACTIVATED, ERROR, CONFIRM_DELETE, CONFIRM_NO_TRASH, @@ -433,14 +433,14 @@ xed_file_browser_widget_class_init (XedFileBrowserWidgetClass * klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - signals[URI_ACTIVATED] = - g_signal_new ("uri-activated", + signals[LOCATION_ACTIVATED] = + g_signal_new ("location-activated", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (XedFileBrowserWidgetClass, - uri_activated), NULL, NULL, - g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, - G_TYPE_STRING); + location_activated), NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, + G_TYPE_FILE); signals[ERROR] = g_signal_new ("error", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, @@ -1060,22 +1060,18 @@ add_bookmark_hash (XedFileBrowserWidget * obj, GtkTreeModel *model; GdkPixbuf * pixbuf; gchar * name; - gchar * uri; - GFile * file; + GFile * location; NameIcon * item; model = GTK_TREE_MODEL (obj->priv->bookmarks_store); - uri = xed_file_bookmarks_store_get_uri (obj->priv-> + location = xed_file_bookmarks_store_get_location (obj->priv-> bookmarks_store, iter); - if (uri == NULL) + if (location == NULL) return; - file = g_file_new_for_uri (uri); - g_free (uri); - gtk_tree_model_get (model, iter, XED_FILE_BOOKMARKS_STORE_COLUMN_ICON, &pixbuf, @@ -1087,7 +1083,7 @@ add_bookmark_hash (XedFileBrowserWidget * obj, item->icon = pixbuf; g_hash_table_insert (obj->priv->bookmarks_hash, - file, + location, item); } @@ -1581,8 +1577,6 @@ jump_to_location (XedFileBrowserWidget * obj, GList * item, GList *(*iter_func) (GList *); GtkWidget *menu_from; GtkWidget *menu_to; - gchar *root; - gchar *virtual_root; if (!obj->priv->locations) return; @@ -1643,15 +1637,9 @@ jump_to_location (XedFileBrowserWidget * obj, GList * item, loc = (Location *) (obj->priv->current_location->data); /* Set the new root + virtual root */ - root = g_file_get_uri (loc->root); - virtual_root = g_file_get_uri (loc->virtual_root); - xed_file_browser_widget_set_root_and_virtual_root (obj, - root, - virtual_root); - - g_free (root); - g_free (virtual_root); + loc->root, + loc->virtual_root); obj->priv->changing_location = FALSE; } @@ -1840,8 +1828,8 @@ xed_file_browser_widget_show_files (XedFileBrowserWidget * obj) void xed_file_browser_widget_set_root_and_virtual_root (XedFileBrowserWidget *obj, - gchar const *root, - gchar const *virtual_root) + GFile *root, + GFile *virtual_root) { XedFileBrowserStoreResult result; @@ -1860,12 +1848,10 @@ xed_file_browser_widget_set_root_and_virtual_root (XedFileBrowserWidget *obj, void xed_file_browser_widget_set_root (XedFileBrowserWidget * obj, - gchar const *root, + GFile *root, gboolean virtual_root) { - GFile *file; GFile *parent; - gchar *str; if (!virtual_root) { xed_file_browser_widget_set_root_and_virtual_root (obj, @@ -1877,16 +1863,11 @@ xed_file_browser_widget_set_root (XedFileBrowserWidget * obj, if (!root) return; - file = g_file_new_for_uri (root); - parent = get_topmost_file (file); - str = g_file_get_uri (parent); + parent = get_topmost_file (root); xed_file_browser_widget_set_root_and_virtual_root - (obj, str, root); + (obj, parent, root); - g_free (str); - - g_object_unref (file); g_object_unref (parent); } @@ -2113,7 +2094,6 @@ activate_mount (XedFileBrowserWidget *widget, GMount *mount) { GFile *root; - gchar *uri; if (!mount) { @@ -2135,11 +2115,9 @@ activate_mount (XedFileBrowserWidget *widget, } root = g_mount_get_root (mount); - uri = g_file_get_uri (root); - xed_file_browser_widget_set_root (widget, uri, FALSE); + xed_file_browser_widget_set_root (widget, root, FALSE); - g_free (uri); g_object_unref (root); } @@ -2370,7 +2348,7 @@ bookmark_open (XedFileBrowserWidget *obj, GtkTreeModel *model, GtkTreeIter *iter) { - gchar *uri; + GFile *location; gint flags; gtk_tree_model_get (model, iter, @@ -2392,11 +2370,11 @@ bookmark_open (XedFileBrowserWidget *obj, return; } - uri = - xed_file_bookmarks_store_get_uri + location = + xed_file_bookmarks_store_get_location (XED_FILE_BOOKMARKS_STORE (model), iter); - if (uri) { + if (location) { /* here we check if the bookmark is a mount point, or if it is a remote bookmark. If that's the case, we will set the root to the uri of the bookmark and not try to set the @@ -2405,18 +2383,18 @@ bookmark_open (XedFileBrowserWidget *obj, if ((flags & XED_FILE_BOOKMARKS_STORE_IS_MOUNT) || (flags & XED_FILE_BOOKMARKS_STORE_IS_REMOTE_BOOKMARK)) { xed_file_browser_widget_set_root (obj, - uri, + location, FALSE); } else { xed_file_browser_widget_set_root (obj, - uri, + location, TRUE); } + + g_object_unref (location); } else { g_warning ("No uri!"); } - - g_free (uri); } static void @@ -2424,19 +2402,17 @@ file_open (XedFileBrowserWidget *obj, GtkTreeModel *model, GtkTreeIter *iter) { - gchar *uri; + GFile *location; gint flags; gtk_tree_model_get (model, iter, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, + XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); if (!FILE_IS_DIR (flags) && !FILE_IS_DUMMY (flags)) { - g_signal_emit (obj, signals[URI_ACTIVATED], 0, uri); + g_signal_emit (obj, signals[LOCATION_ACTIVATED], 0, location); } - - g_free (uri); } static gboolean @@ -2446,17 +2422,20 @@ directory_open (XedFileBrowserWidget *obj, { gboolean result = FALSE; GError *error = NULL; - gchar *uri = NULL; + GFile *location; XedFileBrowserStoreFlag flags; gtk_tree_model_get (model, iter, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, + XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); - if (FILE_IS_DIR (flags)) { + if (FILE_IS_DIR (flags) && location) { + gchar *uri; result = TRUE; + uri = g_file_get_uri (location); + if (!gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (obj)), uri, GDK_CURRENT_TIME, &error)) { g_signal_emit (obj, signals[ERROR], 0, XED_FILE_BROWSER_ERROR_OPEN_DIRECTORY, @@ -2465,9 +2444,9 @@ directory_open (XedFileBrowserWidget *obj, g_error_free (error); error = NULL; } - } - g_free (uri); + g_free (uri); + } return result; } @@ -2514,8 +2493,7 @@ on_virtual_root_changed (XedFileBrowserStore * model, XedFileBrowserWidget * obj) { GtkTreeIter iter; - gchar *uri; - gchar *root_uri; + GFile *location; GtkTreeIter root; GtkAction *action; Location *loc; @@ -2529,8 +2507,8 @@ on_virtual_root_changed (XedFileBrowserStore * model, if (xed_file_browser_store_get_iter_virtual_root (model, &iter)) { gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, - XED_FILE_BROWSER_STORE_COLUMN_URI, - &uri, -1); + XED_FILE_BROWSER_STORE_COLUMN_LOCATION, + &location, -1); if (xed_file_browser_store_get_iter_root (model, &root)) { if (!obj->priv->changing_location) { @@ -2538,14 +2516,9 @@ on_virtual_root_changed (XedFileBrowserStore * model, if (obj->priv->current_location) clear_next_locations (obj); - root_uri = - xed_file_browser_store_get_root - (model); - loc = g_new (Location, 1); - loc->root = g_file_new_for_uri (root_uri); - loc->virtual_root = g_file_new_for_uri (uri); - g_free (root_uri); + loc->root = xed_file_browser_store_get_root (model); + loc->virtual_root = g_object_ref (location); if (obj->priv->current_location) { /* Add current location to the menu so we can go back @@ -2614,7 +2587,6 @@ on_virtual_root_changed (XedFileBrowserStore * model, } check_current_item (obj, TRUE); - g_free (uri); } else { g_message ("NO!"); } @@ -2694,7 +2666,6 @@ on_combo_changed (GtkComboBox * combo, XedFileBrowserWidget * obj) { GtkTreeIter iter; guint id; - gchar * uri; GFile * file; if (!gtk_combo_box_get_active_iter (combo, &iter)) @@ -2713,11 +2684,8 @@ on_combo_changed (GtkComboBox * combo, XedFileBrowserWidget * obj) (obj->priv->combo_model), &iter, COLUMN_FILE, &file, -1); - uri = g_file_get_uri (file); - xed_file_browser_store_set_virtual_root_from_string - (obj->priv->file_store, uri); + xed_file_browser_store_set_virtual_root_from_location (obj->priv->file_store, file); - g_free (uri); g_object_unref (file); break; } @@ -2902,22 +2870,19 @@ on_bookmarks_row_deleted (GtkTreeModel * model, XedFileBrowserWidget *obj) { GtkTreeIter iter; - gchar * uri; - GFile * file; + GFile *location; if (!gtk_tree_model_get_iter (model, &iter, path)) return; - uri = xed_file_bookmarks_store_get_uri (obj->priv->bookmarks_store, &iter); + location = xed_file_bookmarks_store_get_location (obj->priv->bookmarks_store, &iter); - if (!uri) + if (!location) return; - file = g_file_new_for_uri (uri); - g_hash_table_remove (obj->priv->bookmarks_hash, file); + g_hash_table_remove (obj->priv->bookmarks_hash, location); - g_object_unref (file); - g_free (uri); + g_object_unref (location); } static void diff --git a/plugins/filebrowser/xed-file-browser-widget.h b/plugins/filebrowser/xed-file-browser-widget.h index 5d91cf1..73ae4ea 100644 --- a/plugins/filebrowser/xed-file-browser-widget.h +++ b/plugins/filebrowser/xed-file-browser-widget.h @@ -58,8 +58,8 @@ struct _XedFileBrowserWidgetClass GtkBoxClass parent_class; /* Signals */ - void (*uri_activated) (XedFileBrowserWidget * widget, - gchar const *uri); + void (*location_activated) (XedFileBrowserWidget * widget, + GFile *location); void (*error) (XedFileBrowserWidget * widget, guint code, gchar const *message); @@ -79,12 +79,12 @@ void xed_file_browser_widget_show_bookmarks (XedFileBrowserWidget * obj); void xed_file_browser_widget_show_files (XedFileBrowserWidget * obj); void xed_file_browser_widget_set_root (XedFileBrowserWidget * obj, - gchar const *root, + GFile *root, gboolean virtual_root); void xed_file_browser_widget_set_root_and_virtual_root (XedFileBrowserWidget * obj, - gchar const *root, - gchar const *virtual_root); + GFile *root, + GFile *virtual_root); gboolean xed_file_browser_widget_get_selected_directory (XedFileBrowserWidget * obj, diff --git a/tests/document-loader.c b/tests/document-loader.c index 68df659..54ad365 100644 --- a/tests/document-loader.c +++ b/tests/document-loader.c @@ -16,11 +16,11 @@ * * You should have received a copy of the GNU General Public License * along with xed; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ -#include "xed-gio-document-loader.h" +#include "xed-document-loader.h" #include "xed-prefs-manager-app.h" #include #include diff --git a/tests/document-saver.c b/tests/document-saver.c index 2748fe0..9235adf 100644 --- a/tests/document-saver.c +++ b/tests/document-saver.c @@ -16,11 +16,11 @@ * * You should have received a copy of the GNU General Public License * along with xed; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ -#include "xed-gio-document-loader.h" +#include "xed-document-loader.h" #include "xed-prefs-manager-app.h" #include #include @@ -701,7 +701,7 @@ int main (int argc, g_test_add_func ("/document-saver/remote", test_remote); g_test_add_func ("/document-saver/remote-new-line", test_remote_newline); - + if (have_unowned) { diff --git a/xed/Makefile.am b/xed/Makefile.am index 492c710..3b2b1dd 100644 --- a/xed/Makefile.am +++ b/xed/Makefile.am @@ -51,8 +51,6 @@ NOINST_H_FILES = \ xed-document-output-stream.h \ xed-document-saver.h \ xed-documents-panel.h \ - xed-gio-document-loader.h \ - xed-gio-document-saver.h \ xed-history-entry.h \ xed-io-error-message-area.h \ xed-language-manager.h \ @@ -123,9 +121,7 @@ libxed_c_files = \ xed-document-input-stream.c \ xed-document-loader.c \ xed-document-output-stream.c \ - xed-gio-document-loader.c \ xed-document-saver.c \ - xed-gio-document-saver.c \ xed-documents-panel.c \ xed-encodings.c \ xed-encodings-combo-box.c \ diff --git a/xed/xed-commands-file.c b/xed/xed-commands-file.c index 68d3bc8..5948ceb 100644 --- a/xed/xed-commands-file.c +++ b/xed/xed-commands-file.c @@ -124,7 +124,7 @@ is_duplicated_file (GSList *files, /* File loading */ static gint load_file_list (XedWindow *window, - GSList *files, + const GSList *files, const XedEncoding *encoding, gint line_pos, gboolean create) @@ -134,7 +134,7 @@ load_file_list (XedWindow *window, gboolean jump_to = TRUE; /* Whether to jump to the new tab */ GList *win_docs; GSList *files_to_load = NULL; - GSList *l; + const GSList *l; xed_debug (DEBUG_COMMANDS); @@ -197,12 +197,7 @@ load_file_list (XedWindow *window, if (xed_document_is_untouched (doc) && (xed_tab_get_state (tab) == XED_TAB_STATE_NORMAL)) { - gchar *uri; - - // FIXME: pass the GFile to tab when api is there - uri = g_file_get_uri (l->data); - _xed_tab_load (tab, uri, encoding, line_pos, create); - g_free (uri); + _xed_tab_load (tab, l->data, encoding, line_pos, create); l = g_slist_next (l); jump_to = FALSE; @@ -213,14 +208,9 @@ load_file_list (XedWindow *window, while (l != NULL) { - gchar *uri; - g_return_val_if_fail (l->data != NULL, 0); - // FIXME: pass the GFile to tab when api is there - uri = g_file_get_uri (l->data); - tab = xed_window_create_tab_from_uri (window, uri, encoding, line_pos, create, jump_to); - g_free (uri); + tab = xed_window_create_tab_from_location (window, l->data, encoding, line_pos, create, jump_to); if (tab != NULL) { @@ -264,114 +254,62 @@ load_file_list (XedWindow *window, return loaded_files; } - -// FIXME: we should expose API with GFile and just make the uri -// variants backward compat wrappers - -static gint -load_uri_list (XedWindow *window, - const GSList *uris, - const XedEncoding *encoding, - gint line_pos, - gboolean create) -{ - GSList *files = NULL; - const GSList *u; - gint ret; - - for (u = uris; u != NULL; u = u->next) - { - gchar *uri = u->data; - - if (xed_utils_is_valid_uri (uri)) - { - files = g_slist_prepend (files, g_file_new_for_uri (uri)); - } - else - { - g_warning ("invalid uri: %s", uri); - } - } - files = g_slist_reverse (files); - - ret = load_file_list (window, files, encoding, line_pos, create); - - g_slist_foreach (files, (GFunc) g_object_unref, NULL); - g_slist_free (files); - - return ret; -} - /** - * xed_commands_load_uri: + * xed_commands_load_location: * @window: * @uri: * @encoding: (allow-none): * @line_pos: * - * Do nothing if uri does not exist + * Do nothing if location does not exist */ void -xed_commands_load_uri (XedWindow *window, - const gchar *uri, - const XedEncoding *encoding, - gint line_pos) +xed_commands_load_location (XedWindow *window, + GFile *location, + const XedEncoding *encoding, + gint line_pos) { - GSList *uris = NULL; + GSList *locations = NULL; + gchar *uri; g_return_if_fail (XED_IS_WINDOW (window)); - g_return_if_fail (uri != NULL); - g_return_if_fail (xed_utils_is_valid_uri (uri)); + g_return_if_fail (G_IS_FILE (location)); + g_return_if_fail (xed_utils_is_valid_location (location)); + uri = g_file_get_uri (location); xed_debug_message (DEBUG_COMMANDS, "Loading URI '%s'", uri); + g_free (uri); - uris = g_slist_prepend (uris, (gchar *)uri); + locations = g_slist_prepend (locations, location); - load_uri_list (window, uris, encoding, line_pos, FALSE); + load_file_list (window, locations, encoding, line_pos, FALSE); - g_slist_free (uris); + g_slist_free (locations); } /** - * xed_commands_load_uris: + * xed_commands_load_locations: * @window: * @uris: * @encoding: * @line_pos: * - * Ignore non-existing URIs + * Ignore non-existing locations * * Returns: */ gint -xed_commands_load_uris (XedWindow *window, - const GSList *uris, - const XedEncoding *encoding, - gint line_pos) +xed_commands_load_locations (XedWindow *window, + const GSList *locations, + const XedEncoding *encoding, + gint line_pos) { g_return_val_if_fail (XED_IS_WINDOW (window), 0); - g_return_val_if_fail ((uris != NULL) && (uris->data != NULL), 0); + g_return_val_if_fail ((locations != NULL) && (locations->data != NULL), 0); xed_debug (DEBUG_COMMANDS); - return load_uri_list (window, uris, encoding, line_pos, FALSE); -} - -/* - * This should become public once we convert all api to GFile: - */ -static gint -xed_commands_load_files (XedWindow *window, - GSList *files, - const XedEncoding *encoding, - gint line_pos) -{ - g_return_val_if_fail (XED_IS_WINDOW (window), 0); - g_return_val_if_fail ((files != NULL) && (files->data != NULL), 0); - - xed_debug (DEBUG_COMMANDS); - - return load_file_list (window, files, encoding, line_pos, FALSE); + return load_file_list (window, locations, encoding, line_pos, FALSE); } /* @@ -426,7 +364,7 @@ open_dialog_response_cb (XedFileChooserDialog *dialog, /* Remember the folder we navigated to */ _xed_window_set_default_location (window, files->data); - xed_commands_load_files (window, files, encoding, 0); + xed_commands_load_locations (window, files, encoding, 0); g_slist_foreach (files, (GFunc) g_object_unref, NULL); g_slist_free (files); @@ -616,7 +554,6 @@ save_dialog_response_cb (XedFileChooserDialog *dialog, { XedDocument *doc; gchar *parse_name; - gchar *uri; doc = xed_tab_get_document (tab); g_return_if_fail (XED_IS_DOCUMENT (doc)); @@ -634,10 +571,7 @@ save_dialog_response_cb (XedFileChooserDialog *dialog, * even if the saving fails... */ _xed_window_set_default_location (window, file); - // FIXME: pass the GFile to tab when api is there - uri = g_file_get_uri (file); - _xed_tab_save_as (tab, uri, encoding, newline_type); - g_free (uri); + _xed_tab_save_as (tab, file, encoding, newline_type); } g_object_unref (file); diff --git a/xed/xed-commands.h b/xed/xed-commands.h index 9a4a693..b08369d 100644 --- a/xed/xed-commands.h +++ b/xed/xed-commands.h @@ -7,10 +7,10 @@ G_BEGIN_DECLS /* Do nothing if URI does not exist */ -void xed_commands_load_uri (XedWindow *window, const gchar *uri, const XedEncoding *encoding, gint line_pos); +void xed_commands_load_location (XedWindow *window, GFile *location, const XedEncoding *encoding, gint line_pos); /* Ignore non-existing URIs */ -gint xed_commands_load_uris (XedWindow *window, const GSList *uris, const XedEncoding *encoding, gint line_pos); +gint xed_commands_load_locations (XedWindow *window, const GSList *locations, const XedEncoding *encoding, gint line_pos); void xed_commands_save_document (XedWindow *window, XedDocument *document); void xed_commands_save_all_documents (XedWindow *window); diff --git a/xed/xed-document-loader.c b/xed/xed-document-loader.c index 921d6d6..aaee954 100644 --- a/xed/xed-document-loader.c +++ b/xed/xed-document-loader.c @@ -17,10 +17,10 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* * Modified by the xed Team, 2005-2007. See the AUTHORS file for a * list of people on the xed Team. @@ -34,324 +34,898 @@ #endif #include +#include +#include #include "xed-document-loader.h" +#include "xed-document-output-stream.h" +#include "xed-smart-charset-converter.h" +#include "xed-prefs-manager.h" #include "xed-debug.h" #include "xed-metadata-manager.h" #include "xed-utils.h" #include "xed-marshal.h" #include "xed-enum-types.h" -/* Those are for the the xed_document_loader_new() factory */ -#include "xed-gio-document-loader.h" +#ifndef ENABLE_GVFS_METADATA +#include "xed_metadata-manager.h" +#endif -G_DEFINE_ABSTRACT_TYPE(XedDocumentLoader, xed_document_loader, G_TYPE_OBJECT) +typedef struct +{ + XedDocumentLoader *loader; + GCancellable *cancellable; -/* Signals */ + gssize read; + gboolean tried_mount; +}AsyncData; -enum { - LOADING, - LAST_SIGNAL +enum +{ + LOADING, + LAST_SIGNAL }; static guint signals[LAST_SIGNAL] = { 0 }; -/* Properties */ - enum { - PROP_0, - PROP_DOCUMENT, - PROP_URI, - PROP_ENCODING, - PROP_NEWLINE_TYPE + PROP_0, + PROP_DOCUMENT, + PROP_LOCATION, + PROP_ENCODING, + PROP_NEWLINE_TYPE }; +#define READ_CHUNK_SIZE 8192 +#define REMOTE_QUERY_ATTRIBUTES G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," \ + G_FILE_ATTRIBUTE_STANDARD_TYPE "," \ + G_FILE_ATTRIBUTE_TIME_MODIFIED "," \ + G_FILE_ATTRIBUTE_STANDARD_SIZE "," \ + G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE "," \ + XED_METADATA_ATTRIBUTE_ENCODING + +#define XED_DOCUMENT_LOADER_GET_PRIVATE(object) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((object), \ + XED_TYPE_DOCUMENT_LOADER, \ + XedDocumentLoaderPrivate)) + +static void open_async_read (AsyncData *async); + +struct _XedDocumentLoaderPrivate +{ + XedDocument *document; + gboolean used; + + /* Info on the current file */ + GFileInfo *info; + GFile *location; + const XedEncoding *encoding; + const XedEncoding *auto_detected_encoding; + XedDocumentNewlineType auto_detected_newline_type; + + goffset bytes_read; + + /* Handle for remote files */ + GCancellable *cancellable; + GInputStream *stream; + GOutputStream *output; + XedSmartCharsetConverter *converter; + + gchar buffer[READ_CHUNK_SIZE]; + + GError *error; +}; + +G_DEFINE_TYPE(XedDocumentLoader, xed_document_loader, G_TYPE_OBJECT) + static void xed_document_loader_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - XedDocumentLoader *loader = XED_DOCUMENT_LOADER (object); + XedDocumentLoader *loader = XED_DOCUMENT_LOADER (object); - switch (prop_id) - { - case PROP_DOCUMENT: - g_return_if_fail (loader->document == NULL); - loader->document = g_value_get_object (value); - break; - case PROP_URI: - g_return_if_fail (loader->uri == NULL); - loader->uri = g_value_dup_string (value); - break; - case PROP_ENCODING: - g_return_if_fail (loader->encoding == NULL); - loader->encoding = g_value_get_boxed (value); - break; - case PROP_NEWLINE_TYPE: - loader->auto_detected_newline_type = g_value_get_enum (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_DOCUMENT: + g_return_if_fail (loader->priv->document == NULL); + loader->priv->document = g_value_get_object (value); + break; + case PROP_LOCATION: + g_return_if_fail (loader->priv->location == NULL); + loader->priv->location = g_value_dup_object (value); + break; + case PROP_ENCODING: + g_return_if_fail (loader->priv->encoding == NULL); + loader->priv->encoding = g_value_get_boxed (value); + break; + case PROP_NEWLINE_TYPE: + loader->priv->auto_detected_newline_type = g_value_get_enum (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_document_loader_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - XedDocumentLoader *loader = XED_DOCUMENT_LOADER (object); + XedDocumentLoader *loader = XED_DOCUMENT_LOADER (object); - switch (prop_id) - { - case PROP_DOCUMENT: - g_value_set_object (value, loader->document); - break; - case PROP_URI: - g_value_set_string (value, loader->uri); - break; - case PROP_ENCODING: - g_value_set_boxed (value, xed_document_loader_get_encoding (loader)); - break; - case PROP_NEWLINE_TYPE: - g_value_set_enum (value, loader->auto_detected_newline_type); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -xed_document_loader_finalize (GObject *object) -{ - XedDocumentLoader *loader = XED_DOCUMENT_LOADER (object); - - g_free (loader->uri); - - if (loader->info) - g_object_unref (loader->info); - - G_OBJECT_CLASS (xed_document_loader_parent_class)->finalize (object); + switch (prop_id) + { + case PROP_DOCUMENT: + g_value_set_object (value, loader->priv->document); + break; + case PROP_LOCATION: + g_value_set_object (value, loader->priv->location); + break; + case PROP_ENCODING: + g_value_set_boxed (value, xed_document_loader_get_encoding (loader)); + break; + case PROP_NEWLINE_TYPE: + g_value_set_enum (value, loader->priv->auto_detected_newline_type); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_document_loader_dispose (GObject *object) { - XedDocumentLoader *loader = XED_DOCUMENT_LOADER (object); + XedDocumentLoaderPrivate *priv; - if (loader->info != NULL) - { - g_object_unref (loader->info); - loader->info = NULL; - } + priv = XED_DOCUMENT_LOADER (object)->priv; - G_OBJECT_CLASS (xed_document_loader_parent_class)->dispose (object); + if (priv->cancellable != NULL) + { + g_cancellable_cancel (priv->cancellable); + g_object_unref (priv->cancellable); + priv->cancellable = NULL; + } + + if (priv->stream != NULL) + { + g_object_unref (priv->stream); + priv->stream = NULL; + } + + if (priv->output != NULL) + { + g_object_unref (priv->output); + priv->output = NULL; + } + + if (priv->converter != NULL) + { + g_object_unref (priv->converter); + priv->converter = NULL; + } + + if (priv->error != NULL) + { + g_error_free (priv->error); + priv->error = NULL; + } + + if (priv->info != NULL) + { + g_object_unref (priv->info); + priv->info = NULL; + } + + if (priv->location != NULL) + { + g_object_unref (priv->location); + priv->location = NULL; + } + + G_OBJECT_CLASS (xed_document_loader_parent_class)->dispose (object); } static void xed_document_loader_class_init (XedDocumentLoaderClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = xed_document_loader_finalize; - object_class->dispose = xed_document_loader_dispose; - object_class->get_property = xed_document_loader_get_property; - object_class->set_property = xed_document_loader_set_property; + object_class->dispose = xed_document_loader_dispose; + object_class->get_property = xed_document_loader_get_property; + object_class->set_property = xed_document_loader_set_property; - g_object_class_install_property (object_class, - PROP_DOCUMENT, - g_param_spec_object ("document", - "Document", - "The XedDocument this XedDocumentLoader is associated with", - XED_TYPE_DOCUMENT, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, + PROP_DOCUMENT, + g_param_spec_object ("document", + "Document", + "The XedDocument this XedDocumentLoader is associated with", + XED_TYPE_DOCUMENT, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (object_class, - PROP_URI, - g_param_spec_string ("uri", - "URI", - "The URI this XedDocumentLoader loads the document from", - "", - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, + PROP_LOCATION, + g_param_spec_object ("location", + "LOCATION", + "The LOCATION this XedDocumentLoader loads the document from", + G_TYPE_FILE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (object_class, - PROP_ENCODING, - g_param_spec_boxed ("encoding", - "Encoding", - "The encoding of the saved file", - XED_TYPE_ENCODING, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, + PROP_ENCODING, + g_param_spec_boxed ("encoding", + "Encoding", + "The encoding of the saved file", + XED_TYPE_ENCODING, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (object_class, PROP_NEWLINE_TYPE, - g_param_spec_enum ("newline-type", - "Newline type", - "The accepted types of line ending", - XED_TYPE_DOCUMENT_NEWLINE_TYPE, - XED_DOCUMENT_NEWLINE_TYPE_LF, - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_BLURB)); + g_object_class_install_property (object_class, + PROP_NEWLINE_TYPE, + g_param_spec_enum ("newline-type", + "Newline type", + "The accepted types of line ending", + XED_TYPE_DOCUMENT_NEWLINE_TYPE, + XED_DOCUMENT_NEWLINE_TYPE_LF, + G_PARAM_READWRITE | + G_PARAM_STATIC_NAME | + G_PARAM_STATIC_BLURB)); - signals[LOADING] = - g_signal_new ("loading", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedDocumentLoaderClass, loading), - NULL, NULL, - xed_marshal_VOID__BOOLEAN_POINTER, - G_TYPE_NONE, - 2, - G_TYPE_BOOLEAN, - G_TYPE_POINTER); + signals[LOADING] = g_signal_new ("loading", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedDocumentLoaderClass, loading), + NULL, NULL, + xed_marshal_VOID__BOOLEAN_POINTER, + G_TYPE_NONE, + 2, + G_TYPE_BOOLEAN, + G_TYPE_POINTER); + + g_type_class_add_private (object_class, sizeof (XedDocumentLoaderPrivate)); } static void xed_document_loader_init (XedDocumentLoader *loader) { - loader->used = FALSE; - loader->auto_detected_newline_type = XED_DOCUMENT_NEWLINE_TYPE_DEFAULT; + loader->priv = XED_DOCUMENT_LOADER_GET_PRIVATE (loader); + + loader->priv->used = FALSE; + loader->priv->auto_detected_newline_type = XED_DOCUMENT_NEWLINE_TYPE_DEFAULT; + loader->priv->converter = NULL; + loader->priv->error = NULL; +} + +XedDocumentLoader * +xed_document_loader_new (XedDocument *doc, + GFile *location, + const XedEncoding *encoding) +{ + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + + return XED_DOCUMENT_LOADER (g_object_new (XED_TYPE_DOCUMENT_LOADER, + "document", doc, + "location", location, + "encoding", encoding, + NULL)); +} + +static AsyncData * +async_data_new (XedDocumentLoader *loader) +{ + AsyncData *async; + + async = g_slice_new (AsyncData); + async->loader = loader; + async->cancellable = g_object_ref (loader->priv->cancellable); + async->tried_mount = FALSE; + + return async; +} + +static void +async_data_free (AsyncData *async) +{ + g_object_unref (async->cancellable); + g_slice_free (AsyncData, async); +} + +static const XedEncoding * +get_metadata_encoding (XedDocumentLoader *loader) +{ + const XedEncoding *enc = NULL; + +#ifndef ENABLE_GVFS_METADATA + gchar *charset; + GFile *location; + gchar *uri; + + location = xed_document_loader_get_location (loader); + uri = g_file_get_uri (location); + g_object_unref (location); + + charset = xed_metadata_manager_get (uri, "encoding"); + g_free (uri); + + if (charset == NULL) + { + return NULL; + } + + enc = xed_encoding_get_from_charset (charset); + + g_free (charset); +#else + GFileInfo *info; + + info = xed_document_loader_get_info (loader); + + /* check if encoding was set in the metadata */ + if (g_file_info_has_attribute (info, XED_METADATA_ATTRIBUTE_ENCODING)) + { + const gchar *charset; + + charset = g_file_info_get_attribute_string (info, XED_METADATA_ATTRIBUTE_ENCODING); + + if (charset == NULL) + { + return NULL; + } + + enc = xed_encoding_get_from_charset (charset); + } +#endif + + return enc; +} + +static void +remote_load_completed_or_failed (XedDocumentLoader *loader, + AsyncData *async) +{ + xed_document_loader_loading (loader, TRUE, loader->priv->error); + + if (async) + { + async_data_free (async); + } +} + +static void +async_failed (AsyncData *async, + GError *error) +{ + g_propagate_error (&async->loader->priv->error, error); + remote_load_completed_or_failed (async->loader, async); +} + +static void +close_input_stream_ready_cb (GInputStream *stream, + GAsyncResult *res, + AsyncData *async) +{ + GError *error = NULL; + + xed_debug (DEBUG_LOADER); + + /* check cancelled state manually */ + if (g_cancellable_is_cancelled (async->cancellable)) + { + async_data_free (async); + return; + } + + xed_debug_message (DEBUG_SAVER, "Finished closing input stream"); + + if (!g_input_stream_close_finish (stream, res, &error)) + { + xed_debug_message (DEBUG_SAVER, "Closing input stream error: %s", error->message); + + async_failed (async, error); + return; + } + + xed_debug_message (DEBUG_SAVER, "Close output stream"); + if (!g_output_stream_close (async->loader->priv->output, async->cancellable, &error)) + { + async_failed (async, error); + return; + } + + remote_load_completed_or_failed (async->loader, async); +} + +static void +write_complete (AsyncData *async) +{ + if (async->loader->priv->stream) + { + g_input_stream_close_async (G_INPUT_STREAM (async->loader->priv->stream), + G_PRIORITY_HIGH, + async->cancellable, + (GAsyncReadyCallback)close_input_stream_ready_cb, + async); + } +} + +/* prototype, because they call each other... isn't C lovely */ +static void read_file_chunk (AsyncData *async); + +static void +write_file_chunk (AsyncData *async) +{ + XedDocumentLoader *loader; + gssize bytes_written; + GError *error = NULL; + + loader = async->loader; + + /* we use sync methods on doc stream since it is in memory. Using async + would be racy and we can endup with invalidated iters */ + bytes_written = g_output_stream_write (G_OUTPUT_STREAM (loader->priv->output), + loader->priv->buffer, + async->read, + async->cancellable, + &error); + + xed_debug_message (DEBUG_SAVER, "Written: %" G_GSSIZE_FORMAT, bytes_written); + if (bytes_written == -1) + { + xed_debug_message (DEBUG_SAVER, "Write error: %s", error->message); + async_failed (async, error); + return; + } + + /* note that this signal blocks the read... check if it isn't + * a performance problem + */ + xed_document_loader_loading (loader, FALSE, NULL); + + read_file_chunk (async); +} + +static void +async_read_cb (GInputStream *stream, + GAsyncResult *res, + AsyncData *async) +{ + XedDocumentLoader *loader; + GError *error = NULL; + + xed_debug (DEBUG_LOADER); + + /* manually check cancelled state */ + if (g_cancellable_is_cancelled (async->cancellable)) + { + async_data_free (async); + return; + } + + loader = async->loader; + + async->read = g_input_stream_read_finish (stream, res, &error); + + /* error occurred */ + if (async->read == -1) + { + async_failed (async, error); + return; + } + + /* Check for the extremely unlikely case where the file size overflows. */ + if (loader->priv->bytes_read + async->read < loader->priv->bytes_read) + { + g_set_error (&loader->priv->error, + XED_DOCUMENT_ERROR, + XED_DOCUMENT_ERROR_TOO_BIG, + "File too big"); + + async_failed (async, loader->priv->error); + return; + } + + /* Bump the size. */ + loader->priv->bytes_read += async->read; + + /* end of the file, we are done! */ + if (async->read == 0) + { + loader->priv->auto_detected_encoding = xed_smart_charset_converter_get_guessed (loader->priv->converter); + + loader->priv->auto_detected_newline_type = + xed_document_output_stream_detect_newline_type (XED_DOCUMENT_OUTPUT_STREAM (loader->priv->output)); + + /* Check if we needed some fallback char, if so, check if there was + a previous error and if not set a fallback used error */ + /* FIXME Uncomment this when we want to manage conversion fallback */ + /*if ((xed_smart_charset_converter_get_num_fallbacks (loader->priv->converter) != 0) && + loader->priv->error == NULL) + { + g_set_error_literal (&loader->priv->error, + XED_DOCUMENT_ERROR, + XED_DOCUMENT_ERROR_CONVERSION_FALLBACK, + "There was a conversion error and it was " + "needed to use a fallback char"); + }*/ + + write_complete (async); + + return; + } + + write_file_chunk (async); +} + +static void +read_file_chunk (AsyncData *async) +{ + XedDocumentLoader *loader; + + loader = async->loader; + + g_input_stream_read_async (G_INPUT_STREAM (loader->priv->stream), + loader->priv->buffer, + READ_CHUNK_SIZE, + G_PRIORITY_HIGH, + async->cancellable, + (GAsyncReadyCallback) async_read_cb, + async); +} + +static GSList * +get_candidate_encodings (XedDocumentLoader *loader) +{ + const XedEncoding *metadata; + GSList *encodings = NULL; + + encodings = xed_prefs_manager_get_auto_detected_encodings (); + + metadata = get_metadata_encoding (loader); + if (metadata != NULL) + { + encodings = g_slist_prepend (encodings, (gpointer)metadata); + } + + return encodings; +} + +static void +finish_query_info (AsyncData *async) +{ + XedDocumentLoader *loader; + GInputStream *conv_stream; + GFileInfo *info; + GSList *candidate_encodings; + + loader = async->loader; + info = loader->priv->info; + + /* if it's not a regular file, error out... */ + if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_TYPE) && + g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR) + { + g_set_error (&loader->priv->error, + G_IO_ERROR, + G_IO_ERROR_NOT_REGULAR_FILE, + "Not a regular file"); + + remote_load_completed_or_failed (loader, async); + + return; + } + + /* Get the candidate encodings */ + if (loader->priv->encoding == NULL) + { + candidate_encodings = get_candidate_encodings (loader); + } + else + { + candidate_encodings = g_slist_prepend (NULL, (gpointer) loader->priv->encoding); + } + + loader->priv->converter = xed_smart_charset_converter_new (candidate_encodings); + g_slist_free (candidate_encodings); + + conv_stream = g_converter_input_stream_new (loader->priv->stream, G_CONVERTER (loader->priv->converter)); + g_object_unref (loader->priv->stream); + + loader->priv->stream = conv_stream; + + /* Output stream */ + loader->priv->output = xed_document_output_stream_new (loader->priv->document); + + /* start reading */ + read_file_chunk (async); +} + +static void +query_info_cb (GFile *source, + GAsyncResult *res, + AsyncData *async) +{ + GFileInfo *info; + GError *error = NULL; + + xed_debug (DEBUG_LOADER); + + /* manually check the cancelled state */ + if (g_cancellable_is_cancelled (async->cancellable)) + { + async_data_free (async); + return; + } + + /* finish the info query */ + info = g_file_query_info_finish (async->loader->priv->location, res, &error); + + if (info == NULL) + { + /* propagate the error and clean up */ + async_failed (async, error); + return; + } + + async->loader->priv->info = info; + + finish_query_info (async); +} + +static void +mount_ready_callback (GFile *file, + GAsyncResult *res, + AsyncData *async) +{ + GError *error = NULL; + gboolean mounted; + + xed_debug (DEBUG_LOADER); + + /* manual check for cancelled state */ + if (g_cancellable_is_cancelled (async->cancellable)) + { + async_data_free (async); + return; + } + + mounted = g_file_mount_enclosing_volume_finish (file, res, &error); + + if (!mounted) + { + async_failed (async, error); + } + else + { + /* try again to open the file for reading */ + open_async_read (async); + } +} + +static void +recover_not_mounted (AsyncData *async) +{ + XedDocument *doc; + GMountOperation *mount_operation; + + xed_debug (DEBUG_LOADER); + + doc = xed_document_loader_get_document (async->loader); + mount_operation = _xed_document_create_mount_operation (doc); + + async->tried_mount = TRUE; + g_file_mount_enclosing_volume (async->loader->priv->location, + G_MOUNT_MOUNT_NONE, + mount_operation, + async->cancellable, + (GAsyncReadyCallback) mount_ready_callback, + async); + + g_object_unref (mount_operation); +} + +static void +async_read_ready_callback (GObject *source, + GAsyncResult *res, + AsyncData *async) +{ + GError *error = NULL; + XedDocumentLoader *loader; + + xed_debug (DEBUG_LOADER); + + /* manual check for cancelled state */ + if (g_cancellable_is_cancelled (async->cancellable)) + { + async_data_free (async); + return; + } + + loader = async->loader; + + loader->priv->stream = G_INPUT_STREAM (g_file_read_finish (loader->priv->location, res, &error)); + + if (!loader->priv->stream) + { + if (error->code == G_IO_ERROR_NOT_MOUNTED && !async->tried_mount) + { + recover_not_mounted (async); + g_error_free (error); + return; + } + + /* Propagate error */ + g_propagate_error (&loader->priv->error, error); + xed_document_loader_loading (loader, TRUE, loader->priv->error); + + async_data_free (async); + return; + } + + /* get the file info: note we cannot use + * g_file_input_stream_query_info_async since it is not able to get the + * content type etc, beside it is not supported by gvfs. + * Using the file instead of the stream is slightly racy, but for + * loading this is not too bad... + */ + g_file_query_info_async (loader->priv->location, + REMOTE_QUERY_ATTRIBUTES, + G_FILE_QUERY_INFO_NONE, + G_PRIORITY_HIGH, + async->cancellable, + (GAsyncReadyCallback) query_info_cb, + async); +} + +static void +open_async_read (AsyncData *async) +{ + g_file_read_async (async->loader->priv->location, + G_PRIORITY_HIGH, + async->cancellable, + (GAsyncReadyCallback) async_read_ready_callback, + async); } void xed_document_loader_loading (XedDocumentLoader *loader, - gboolean completed, - GError *error) + gboolean completed, + GError *error) { - /* the object will be unrefed in the callback of the loading signal - * (when completed == TRUE), so we need to prevent finalization. - */ - if (completed) - { - g_object_ref (loader); - } + /* the object will be unrefed in the callback of the loading signal + * (when completed == TRUE), so we need to prevent finalization. + */ + if (completed) + { + g_object_ref (loader); + } - g_signal_emit (loader, signals[LOADING], 0, completed, error); + g_signal_emit (loader, signals[LOADING], 0, completed, error); - if (completed) - { - if (error == NULL) - xed_debug_message (DEBUG_LOADER, "load completed"); - else - xed_debug_message (DEBUG_LOADER, "load failed"); + if (completed) + { + if (error == NULL) + { + xed_debug_message (DEBUG_LOADER, "load completed"); + } + else + { + xed_debug_message (DEBUG_LOADER, "load failed"); + } - g_object_unref (loader); - } + g_object_unref (loader); + } } -/* This is a factory method that returns an appopriate loader - * for the given uri. - */ -XedDocumentLoader * -xed_document_loader_new (XedDocument *doc, - const gchar *uri, - const XedEncoding *encoding) -{ - XedDocumentLoader *loader; - GType loader_type; - - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - - /* At the moment we just use gio loader in all cases... - * In the future it would be great to have a PolicyKit - * loader to get permission to save systen files etc */ - loader_type = XED_TYPE_GIO_DOCUMENT_LOADER; - - loader = XED_DOCUMENT_LOADER (g_object_new (loader_type, - "document", doc, - "uri", uri, - "encoding", encoding, - NULL)); - - return loader; -} - -/* If enconding == NULL, the encoding will be autodetected */ void xed_document_loader_load (XedDocumentLoader *loader) { - xed_debug (DEBUG_LOADER); + AsyncData *async; - g_return_if_fail (XED_IS_DOCUMENT_LOADER (loader)); + xed_debug (DEBUG_LOADER); - /* the loader can be used just once, then it must be thrown away */ - g_return_if_fail (loader->used == FALSE); - loader->used = TRUE; + g_return_if_fail (XED_IS_DOCUMENT_LOADER (loader)); - XED_DOCUMENT_LOADER_GET_CLASS (loader)->load (loader); + /* the loader can be used just once, then it must be thrown away */ + g_return_if_fail (loader->priv->used == FALSE); + loader->priv->used = TRUE; + + /* Make sure no load operation is currently running */ + g_return_if_fail (loader->priv->cancellable == NULL); + + /* loading start */ + xed_document_loader_loading (loader, FALSE, NULL); + + loader->priv->cancellable = g_cancellable_new (); + async = async_data_new (loader); + + open_async_read (async); } -gboolean +gboolean xed_document_loader_cancel (XedDocumentLoader *loader) { - xed_debug (DEBUG_LOADER); + xed_debug (DEBUG_LOADER); - g_return_val_if_fail (XED_IS_DOCUMENT_LOADER (loader), FALSE); + g_return_val_if_fail (XED_IS_DOCUMENT_LOADER (loader), FALSE); - return XED_DOCUMENT_LOADER_GET_CLASS (loader)->cancel (loader); + if (loader->priv->cancellable == NULL) + { + return FALSE; + } + + g_cancellable_cancel (loader->priv->cancellable); + + g_set_error (&loader->priv->error, + G_IO_ERROR, + G_IO_ERROR_CANCELLED, + "Operation cancelled"); + + remote_load_completed_or_failed (loader, NULL); + + return TRUE; } XedDocument * xed_document_loader_get_document (XedDocumentLoader *loader) { - g_return_val_if_fail (XED_IS_DOCUMENT_LOADER (loader), NULL); + g_return_val_if_fail (XED_IS_DOCUMENT_LOADER (loader), NULL); - return loader->document; + return loader->priv->document; } /* Returns STDIN_URI if loading from stdin */ -const gchar * -xed_document_loader_get_uri (XedDocumentLoader *loader) +GFile * +xed_document_loader_get_location (XedDocumentLoader *loader) { - g_return_val_if_fail (XED_IS_DOCUMENT_LOADER (loader), NULL); + g_return_val_if_fail (XED_IS_DOCUMENT_LOADER (loader), NULL); - return loader->uri; + return g_file_dup (loader->priv->location); } goffset xed_document_loader_get_bytes_read (XedDocumentLoader *loader) { - g_return_val_if_fail (XED_IS_DOCUMENT_LOADER (loader), 0); + g_return_val_if_fail (XED_IS_DOCUMENT_LOADER (loader), 0); - return XED_DOCUMENT_LOADER_GET_CLASS (loader)->get_bytes_read (loader); + return loader->priv->bytes_read; } const XedEncoding * xed_document_loader_get_encoding (XedDocumentLoader *loader) { - g_return_val_if_fail (XED_IS_DOCUMENT_LOADER (loader), NULL); + g_return_val_if_fail (XED_IS_DOCUMENT_LOADER (loader), NULL); - if (loader->encoding != NULL) - return loader->encoding; + if (loader->priv->encoding != NULL) + { + return loader->priv->encoding; + } - g_return_val_if_fail (loader->auto_detected_encoding != NULL, - xed_encoding_get_current ()); + g_return_val_if_fail (loader->priv->auto_detected_encoding != NULL, xed_encoding_get_current ()); - return loader->auto_detected_encoding; + return loader->priv->auto_detected_encoding; } XedDocumentNewlineType xed_document_loader_get_newline_type (XedDocumentLoader *loader) { - g_return_val_if_fail (XED_IS_DOCUMENT_LOADER (loader), - XED_DOCUMENT_NEWLINE_TYPE_LF); + g_return_val_if_fail (XED_IS_DOCUMENT_LOADER (loader), XED_DOCUMENT_NEWLINE_TYPE_LF); - return loader->auto_detected_newline_type; + return loader->priv->auto_detected_newline_type; } GFileInfo * xed_document_loader_get_info (XedDocumentLoader *loader) { - g_return_val_if_fail (XED_IS_DOCUMENT_LOADER (loader), NULL); + g_return_val_if_fail (XED_IS_DOCUMENT_LOADER (loader), NULL); - return loader->info; + return loader->priv->info; } diff --git a/xed/xed-document-loader.h b/xed/xed-document-loader.h index ff7a8a4..f46f48c 100644 --- a/xed/xed-document-loader.h +++ b/xed/xed-document-loader.h @@ -17,10 +17,10 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* * Modified by the xed Team, 2005-2007. See the AUTHORS file for a * list of people on the xed Team. @@ -36,9 +36,6 @@ G_BEGIN_DECLS -/* - * Type checking and casting macros - */ #define XED_TYPE_DOCUMENT_LOADER (xed_document_loader_get_type()) #define XED_DOCUMENT_LOADER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_DOCUMENT_LOADER, XedDocumentLoader)) #define XED_DOCUMENT_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_DOCUMENT_LOADER, XedDocumentLoaderClass)) @@ -46,84 +43,59 @@ G_BEGIN_DECLS #define XED_IS_DOCUMENT_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_DOCUMENT_LOADER)) #define XED_DOCUMENT_LOADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_DOCUMENT_LOADER, XedDocumentLoaderClass)) -/* Private structure type */ -typedef struct _XedDocumentLoaderPrivate XedDocumentLoaderPrivate; +typedef struct _XedDocumentLoader XedDocumentLoader; +typedef struct _XedDocumentLoaderPrivate XedDocumentLoaderPrivate; +typedef struct _XedDocumentLoaderClass XedDocumentLoaderClass; -/* - * Main object structure - */ -typedef struct _XedDocumentLoader XedDocumentLoader; - -struct _XedDocumentLoader +struct _XedDocumentLoader { - GObject object; + GObject object; - XedDocument *document; - gboolean used; - - /* Info on the current file */ - GFileInfo *info; - gchar *uri; - const XedEncoding *encoding; - const XedEncoding *auto_detected_encoding; - XedDocumentNewlineType auto_detected_newline_type; + XedDocumentLoaderPrivate *priv; }; -/* - * Class definition - */ -typedef struct _XedDocumentLoaderClass XedDocumentLoaderClass; - -struct _XedDocumentLoaderClass +struct _XedDocumentLoaderClass { - GObjectClass parent_class; + GObjectClass parent_class; - /* Signals */ - void (* loading) (XedDocumentLoader *loader, - gboolean completed, - const GError *error); - - /* VTable */ - void (* load) (XedDocumentLoader *loader); - gboolean (* cancel) (XedDocumentLoader *loader); - goffset (* get_bytes_read) (XedDocumentLoader *loader); + /* Signals */ + void (* loading) (XedDocumentLoader *loader, + gboolean completed, + const GError *error); }; -/* - * Public methods - */ -GType xed_document_loader_get_type (void) G_GNUC_CONST; +GType xed_document_loader_get_type (void) G_GNUC_CONST; /* If enconding == NULL, the encoding will be autodetected */ -XedDocumentLoader *xed_document_loader_new (XedDocument *doc, - const gchar *uri, - const XedEncoding *encoding); +XedDocumentLoader *xed_document_loader_new (XedDocument *doc, + GFile *location, + const XedEncoding *encoding); -void xed_document_loader_loading (XedDocumentLoader *loader, - gboolean completed, - GError *error); +void xed_document_loader_loading (XedDocumentLoader *loader, + gboolean completed, + GError *error); -void xed_document_loader_load (XedDocumentLoader *loader); +void xed_document_loader_load (XedDocumentLoader *loader); #if 0 -gboolean xed_document_loader_load_from_stdin (XedDocumentLoader *loader); -#endif -gboolean xed_document_loader_cancel (XedDocumentLoader *loader); +gboolean xed_document_loader_load_from_stdin (XedDocumentLoader *loader); +#endif +gboolean xed_document_loader_cancel (XedDocumentLoader *loader); -XedDocument *xed_document_loader_get_document (XedDocumentLoader *loader); +XedDocument *xed_document_loader_get_document (XedDocumentLoader *loader); /* Returns STDIN_URI if loading from stdin */ -#define STDIN_URI "stdin:" -const gchar *xed_document_loader_get_uri (XedDocumentLoader *loader); +#define STDIN_URI "stdin:" +GFile *xed_document_loader_get_location (XedDocumentLoader *loader); -const XedEncoding *xed_document_loader_get_encoding (XedDocumentLoader *loader); +const XedEncoding *xed_document_loader_get_encoding (XedDocumentLoader *loader); XedDocumentNewlineType xed_document_loader_get_newline_type (XedDocumentLoader *loader); -goffset xed_document_loader_get_bytes_read (XedDocumentLoader *loader); +goffset xed_document_loader_get_bytes_read (XedDocumentLoader *loader); -/* You can get from the info: content_type, time_modified, standard_size, access_can_write +/* You can get from the info: content_type, time_modified, standard_size, access_can_write and also the metadata*/ -GFileInfo *xed_document_loader_get_info (XedDocumentLoader *loader); +GFileInfo *xed_document_loader_get_info (XedDocumentLoader *loader); G_END_DECLS diff --git a/xed/xed-document-saver.c b/xed/xed-document-saver.c index 8108217..25718c7 100644 --- a/xed/xed-document-saver.c +++ b/xed/xed-document-saver.c @@ -31,329 +31,989 @@ #include #endif -#include -#include -#include - #include +#include +#include +#include #include "xed-document-saver.h" #include "xed-debug.h" +#include "xed-document-input-stream.h" #include "xed-prefs-manager.h" #include "xed-marshal.h" #include "xed-utils.h" #include "xed-enum-types.h" -#include "xed-gio-document-saver.h" -G_DEFINE_ABSTRACT_TYPE(XedDocumentSaver, xed_document_saver, G_TYPE_OBJECT) +#define WRITE_CHUNK_SIZE 8192 -/* Signals */ - -enum { - SAVING, - LAST_SIGNAL +enum +{ + SAVING, + LAST_SIGNAL }; static guint signals[LAST_SIGNAL] = { 0 }; -/* Properties */ - -enum { - PROP_0, - PROP_DOCUMENT, - PROP_URI, - PROP_ENCODING, - PROP_NEWLINE_TYPE, - PROP_FLAGS +enum +{ + PROP_0, + PROP_DOCUMENT, + PROP_LOCATION, + PROP_ENCODING, + PROP_NEWLINE_TYPE, + PROP_FLAGS }; +typedef struct +{ + XedDocumentSaver *saver; + gchar buffer[WRITE_CHUNK_SIZE]; + GCancellable *cancellable; + gboolean tried_mount; + gssize written; + gssize read; + GError *error; +}AsyncData; + +#define REMOTE_QUERY_ATTRIBUTES G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," \ + G_FILE_ATTRIBUTE_TIME_MODIFIED + +#define XED_DOCUMENT_SAVER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ + XED_TYPE_DOCUMENT_SAVER, \ + XedDocumentSaverPrivate)) + +static void check_modified_async (AsyncData *async); + +struct _XedDocumentSaverPrivate +{ + GFileInfo *info; + XedDocument *document; + gboolean used; + + GFile *location; + const XedEncoding *encoding; + XedDocumentNewlineType newline_type; + + XedDocumentSaveFlags flags; + + gboolean keep_backup; + + GTimeVal old_mtime; + + goffset size; + goffset bytes_written; + + GCancellable *cancellable; + GOutputStream *stream; + GInputStream *input; + + GError *error; +}; + +G_DEFINE_TYPE(XedDocumentSaver, xed_document_saver, G_TYPE_OBJECT) + static void xed_document_saver_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - XedDocumentSaver *saver = XED_DOCUMENT_SAVER (object); + XedDocumentSaver *saver = XED_DOCUMENT_SAVER (object); - switch (prop_id) - { - case PROP_DOCUMENT: - g_return_if_fail (saver->document == NULL); - saver->document = g_value_get_object (value); - break; - case PROP_URI: - g_return_if_fail (saver->uri == NULL); - saver->uri = g_value_dup_string (value); - break; - case PROP_ENCODING: - g_return_if_fail (saver->encoding == NULL); - saver->encoding = g_value_get_boxed (value); - break; - case PROP_NEWLINE_TYPE: - saver->newline_type = g_value_get_enum (value); - break; - case PROP_FLAGS: - saver->flags = g_value_get_flags (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_DOCUMENT: + g_return_if_fail (saver->priv->document == NULL); + saver->priv->document = g_value_get_object (value); + break; + case PROP_LOCATION: + g_return_if_fail (saver->priv->location == NULL); + saver->priv->location = g_value_dup_object (value); + break; + case PROP_ENCODING: + g_return_if_fail (saver->priv->encoding == NULL); + saver->priv->encoding = g_value_get_boxed (value); + break; + case PROP_NEWLINE_TYPE: + saver->priv->newline_type = g_value_get_enum (value); + break; + case PROP_FLAGS: + saver->priv->flags = g_value_get_flags (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_document_saver_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - XedDocumentSaver *saver = XED_DOCUMENT_SAVER (object); + XedDocumentSaver *saver = XED_DOCUMENT_SAVER (object); - switch (prop_id) - { - case PROP_DOCUMENT: - g_value_set_object (value, saver->document); - break; - case PROP_URI: - g_value_set_string (value, saver->uri); - break; - case PROP_ENCODING: - g_value_set_boxed (value, saver->encoding); - break; - case PROP_NEWLINE_TYPE: - g_value_set_enum (value, saver->newline_type); - break; - case PROP_FLAGS: - g_value_set_flags (value, saver->flags); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -xed_document_saver_finalize (GObject *object) -{ - XedDocumentSaver *saver = XED_DOCUMENT_SAVER (object); - - g_free (saver->uri); - - G_OBJECT_CLASS (xed_document_saver_parent_class)->finalize (object); + switch (prop_id) + { + case PROP_DOCUMENT: + g_value_set_object (value, saver->priv->document); + break; + case PROP_LOCATION: + g_value_set_object (value, saver->priv->location); + break; + case PROP_ENCODING: + g_value_set_boxed (value, saver->priv->encoding); + break; + case PROP_NEWLINE_TYPE: + g_value_set_enum (value, saver->priv->newline_type); + break; + case PROP_FLAGS: + g_value_set_flags (value, saver->priv->flags); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_document_saver_dispose (GObject *object) { - XedDocumentSaver *saver = XED_DOCUMENT_SAVER (object); + XedDocumentSaverPrivate *priv = XED_DOCUMENT_SAVER (object)->priv; - if (saver->info != NULL) - { - g_object_unref (saver->info); - saver->info = NULL; - } + if (priv->cancellable != NULL) + { + g_cancellable_cancel (priv->cancellable); + g_object_unref (priv->cancellable); + priv->cancellable = NULL; + } - G_OBJECT_CLASS (xed_document_saver_parent_class)->dispose (object); + if (priv->error != NULL) + { + g_error_free (priv->error); + priv->error = NULL; + } + + if (priv->stream != NULL) + { + g_object_unref (priv->stream); + priv->stream = NULL; + } + + if (priv->input != NULL) + { + g_object_unref (priv->input); + priv->input = NULL; + } + + if (priv->info != NULL) + { + g_object_unref (priv->info); + priv->info = NULL; + } + + if (priv->location != NULL) + { + g_object_unref (priv->location); + priv->location = NULL; + } + + G_OBJECT_CLASS (xed_document_saver_parent_class)->dispose (object); } -static void +static AsyncData * +async_data_new (XedDocumentSaver *saver) +{ + AsyncData *async; + + async = g_slice_new (AsyncData); + async->saver = saver; + async->cancellable = g_object_ref (saver->priv->cancellable); + + async->tried_mount = FALSE; + async->written = 0; + async->read = 0; + + async->error = NULL; + + return async; +} + +static void +async_data_free (AsyncData *async) +{ + g_object_ref (async->cancellable); + + if (async->error) + { + g_error_free (async->error); + } + + g_slice_free (AsyncData, async); +} + +static void xed_document_saver_class_init (XedDocumentSaverClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = xed_document_saver_finalize; - object_class->dispose = xed_document_saver_dispose; - object_class->set_property = xed_document_saver_set_property; - object_class->get_property = xed_document_saver_get_property; + object_class->dispose = xed_document_saver_dispose; + object_class->set_property = xed_document_saver_set_property; + object_class->get_property = xed_document_saver_get_property; - g_object_class_install_property (object_class, - PROP_DOCUMENT, - g_param_spec_object ("document", - "Document", - "The XedDocument this XedDocumentSaver is associated with", - XED_TYPE_DOCUMENT, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, + PROP_DOCUMENT, + g_param_spec_object ("document", + "Document", + "The XedDocument this XedDocumentSaver is associated with", + XED_TYPE_DOCUMENT, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (object_class, - PROP_URI, - g_param_spec_string ("uri", - "URI", - "The URI this XedDocumentSaver saves the document to", - "", - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, + PROP_LOCATION, + g_param_spec_object ("location", + "LOCATION", + "The LOCATION this XedDocumentSaver saves the document to", + G_TYPE_FILE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (object_class, - PROP_ENCODING, - g_param_spec_boxed ("encoding", - "URI", - "The encoding of the saved file", - XED_TYPE_ENCODING, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, + PROP_ENCODING, + g_param_spec_boxed ("encoding", + "ENCODING", + "The encoding of the saved file", + XED_TYPE_ENCODING, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (object_class, - PROP_NEWLINE_TYPE, - g_param_spec_enum ("newline-type", - "Newline type", - "The accepted types of line ending", - XED_TYPE_DOCUMENT_NEWLINE_TYPE, - XED_DOCUMENT_NEWLINE_TYPE_LF, - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_BLURB | - G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, + PROP_NEWLINE_TYPE, + g_param_spec_enum ("newline-type", + "Newline type", + "The accepted types of line ending", + XED_TYPE_DOCUMENT_NEWLINE_TYPE, + XED_DOCUMENT_NEWLINE_TYPE_LF, + G_PARAM_READWRITE | + G_PARAM_STATIC_NAME | + G_PARAM_STATIC_BLURB | + G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (object_class, - PROP_FLAGS, - g_param_spec_flags ("flags", - "Flags", - "The flags for the saving operation", - XED_TYPE_DOCUMENT_SAVE_FLAGS, - 0, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, + PROP_FLAGS, + g_param_spec_flags ("flags", + "Flags", + "The flags for the saving operation", + XED_TYPE_DOCUMENT_SAVE_FLAGS, + 0, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); - signals[SAVING] = - g_signal_new ("saving", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedDocumentSaverClass, saving), - NULL, NULL, - xed_marshal_VOID__BOOLEAN_POINTER, - G_TYPE_NONE, - 2, - G_TYPE_BOOLEAN, - G_TYPE_POINTER); + signals[SAVING] = + g_signal_new ("saving", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedDocumentSaverClass, saving), + NULL, NULL, + xed_marshal_VOID__BOOLEAN_POINTER, + G_TYPE_NONE, + 2, + G_TYPE_BOOLEAN, + G_TYPE_POINTER); + + g_type_class_add_private (object_class, sizeof (XedDocumentSaverPrivate)); } static void xed_document_saver_init (XedDocumentSaver *saver) { - saver->used = FALSE; + saver->priv = XED_DOCUMENT_SAVER_GET_PRIVATE (saver); + + saver->priv->cancellable = g_cancellable_new (); + saver->priv->error = NULL; + saver->priv->used = FALSE; } XedDocumentSaver * -xed_document_saver_new (XedDocument *doc, - const gchar *uri, - const XedEncoding *encoding, - XedDocumentNewlineType newline_type, - XedDocumentSaveFlags flags) +xed_document_saver_new (XedDocument *doc, + GFile *location, + const XedEncoding *encoding, + XedDocumentNewlineType newline_type, + XedDocumentSaveFlags flags) { - XedDocumentSaver *saver; - GType saver_type; + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + if (encoding == NULL) + { + encoding = xed_encoding_get_utf8 (); + } - saver_type = XED_TYPE_GIO_DOCUMENT_SAVER; + return XED_DOCUMENT_SAVER (g_object_new (XED_TYPE_DOCUMENT_SAVER, + "document", doc, + "location", location, + "encoding", encoding, + "newline_type", newline_type, + "flags", flags, + NULL)); +} - if (encoding == NULL) - encoding = xed_encoding_get_utf8 (); +static void +remote_save_completed_or_failed (XedDocumentSaver *saver, + AsyncData *async) +{ + xed_document_saver_saving (saver, TRUE, saver->priv->error); - saver = XED_DOCUMENT_SAVER (g_object_new (saver_type, - "document", doc, - "uri", uri, - "encoding", encoding, - "newline_type", newline_type, - "flags", flags, - NULL)); + if (async) + { + async_data_free (async); + } +} - return saver; +static void +async_failed (AsyncData *async, + GError *error) +{ + g_propagate_error (&async->saver->priv->error, error); + remote_save_completed_or_failed (async->saver, async); +} + +/* BEGIN NOTE: + * + * This fixes an issue in GOutputStream that applies the atomic replace + * save strategy. The stream moves the written file to the original file + * when the stream is closed. However, there is no way currently to tell + * the stream that the save should be aborted (there could be a + * conversion error). The patch explicitly closes the output stream + * in all these cases with a GCancellable in the cancelled state, causing + * the output stream to close, but not move the file. This makes use + * of an implementation detail in the local file stream and should be + * properly fixed by adding the appropriate API in . Until then, at least + * we prevent data corruption for now. + * + * Relevant bug reports: + * + * Bug 615110 - write file ignore encoding errors (gedit) + * https://bugzilla.gnome.org/show_bug.cgi?id=615110 + * + * Bug 602412 - g_file_replace does not restore original file when there is + * errors while writing (glib/) + * https://bugzilla.gnome.org/show_bug.cgi?id=602412 + */ +static void +cancel_output_stream_ready_cb (GOutputStream *stream, + GAsyncResult *result, + AsyncData *async) +{ + GError *error; + + g_output_stream_close_finish (stream, result, NULL); + + /* check cancelled state manually */ + if (g_cancellable_is_cancelled (async->cancellable) || async->error == NULL) + { + async_data_free (async); + return; + } + + error = async->error; + async->error = NULL; + + async_failed (async, error); +} + +static void +cancel_output_stream (AsyncData *async) +{ + GCancellable *cancellable; + + xed_debug_message (DEBUG_SAVER, "Cancel output stream"); + + cancellable = g_cancellable_new (); + g_cancellable_cancel (cancellable); + + g_output_stream_close_async (async->saver->priv->stream, + G_PRIORITY_HIGH, + cancellable, + (GAsyncReadyCallback)cancel_output_stream_ready_cb, + async); + + g_object_unref (cancellable); +} + +static void +cancel_output_stream_and_fail (AsyncData *async, + GError *error) +{ + + xed_debug_message (DEBUG_SAVER, "Cancel output stream and fail"); + + g_propagate_error (&async->error, error); + cancel_output_stream (async); +} + +/* + * END NOTE + */ + +static void +remote_get_info_cb (GFile *source, + GAsyncResult *res, + AsyncData *async) +{ + XedDocumentSaver *saver; + GFileInfo *info; + GError *error = NULL; + + xed_debug (DEBUG_SAVER); + + /* check cancelled state manually */ + if (g_cancellable_is_cancelled (async->cancellable)) + { + async_data_free (async); + return; + } + + saver = async->saver; + + xed_debug_message (DEBUG_SAVER, "Finished query info on file"); + info = g_file_query_info_finish (source, res, &error); + + if (info != NULL) + { + if (saver->priv->info != NULL) + { + g_object_unref (saver->priv->info); + } + + saver->priv->info = info; + } + else + { + xed_debug_message (DEBUG_SAVER, "Query info failed: %s", error->message); + g_propagate_error (&saver->priv->error, error); + } + + remote_save_completed_or_failed (saver, async); +} + +static void +close_async_ready_get_info_cb (GOutputStream *stream, + GAsyncResult *res, + AsyncData *async) +{ + GError *error = NULL; + + xed_debug (DEBUG_SAVER); + + /* check cancelled state manually */ + if (g_cancellable_is_cancelled (async->cancellable)) + { + async_data_free (async); + return; + } + + xed_debug_message (DEBUG_SAVER, "Finished closing stream"); + + if (!g_output_stream_close_finish (stream, res, &error)) + { + xed_debug_message (DEBUG_SAVER, "Closing stream error: %s", error->message); + + async_failed (async, error); + return; + } + + /* get the file info: note we cannot use + * g_file_output_stream_query_info_async since it is not able to get the + * content type etc, beside it is not supported by gvfs. + * I'm not sure this is actually necessary, can't we just use + * g_content_type_guess (since we have the file name and the data) + */ + + xed_debug_message (DEBUG_SAVER, "Query info on file"); + g_file_query_info_async (async->saver->priv->location, + REMOTE_QUERY_ATTRIBUTES, + G_FILE_QUERY_INFO_NONE, + G_PRIORITY_HIGH, + async->cancellable, + (GAsyncReadyCallback) remote_get_info_cb, + async); +} + +static void +write_complete (AsyncData *async) +{ + GError *error = NULL; + + /* first we close the input stream */ + xed_debug_message (DEBUG_SAVER, "Close input stream"); + if (!g_input_stream_close (async->saver->priv->input, async->cancellable, &error)) + { + xed_debug_message (DEBUG_SAVER, "Closing input stream error: %s", error->message); + cancel_output_stream_and_fail (async, error); + return; + } + + /* now we close the output stream */ + xed_debug_message (DEBUG_SAVER, "Close output stream"); + g_output_stream_close_async (async->saver->priv->stream, + G_PRIORITY_HIGH, + async->cancellable, + (GAsyncReadyCallback)close_async_ready_get_info_cb, + async); +} + +static void read_file_chunk (AsyncData *async); +static void write_file_chunk (AsyncData *async); + +static void +async_write_cb (GOutputStream *stream, + GAsyncResult *res, + AsyncData *async) +{ + XedDocumentSaver *saver; + gssize bytes_written; + GError *error = NULL; + + xed_debug (DEBUG_SAVER); + + /* Check cancelled state manually */ + if (g_cancellable_is_cancelled (async->cancellable)) + { + cancel_output_stream (async); + return; + } + + bytes_written = g_output_stream_write_finish (stream, res, &error); + + xed_debug_message (DEBUG_SAVER, "Written: %" G_GSSIZE_FORMAT, bytes_written); + + if (bytes_written == -1) + { + xed_debug_message (DEBUG_SAVER, "Write error: %s", error->message); + cancel_output_stream_and_fail (async, error); + return; + } + + saver = async->saver; + async->written += bytes_written; + + /* write again */ + if (async->written != async->read) + { + write_file_chunk (async); + return; + } + + /* note that this signal blocks the write... check if it isn't + * a performance problem + */ + xed_document_saver_saving (saver, FALSE, NULL); + + read_file_chunk (async); +} + +static void +write_file_chunk (AsyncData *async) +{ + XedDocumentSaver *saver; + + xed_debug (DEBUG_SAVER); + + saver = async->saver; + + g_output_stream_write_async (G_OUTPUT_STREAM (saver->priv->stream), + async->buffer + async->written, + async->read - async->written, + G_PRIORITY_HIGH, + async->cancellable, + (GAsyncReadyCallback) async_write_cb, + async); +} + +static void +read_file_chunk (AsyncData *async) +{ + XedDocumentSaver *saver; + XedDocumentInputStream *dstream; + GError *error = NULL; + + xed_debug (DEBUG_SAVER); + + saver = async->saver; + async->written = 0; + + /* we use sync methods on doc stream since it is in memory. Using async + would be racy and we can endup with invalidated iters */ + async->read = g_input_stream_read (saver->priv->input, + async->buffer, + WRITE_CHUNK_SIZE, + async->cancellable, + &error); + + if (error != NULL) + { + cancel_output_stream_and_fail (async, error); + return; + } + + /* Check if we finished reading and writing */ + if (async->read == 0) + { + write_complete (async); + return; + } + + /* Get how many chars have been read */ + dstream = XED_DOCUMENT_INPUT_STREAM (saver->priv->input); + saver->priv->bytes_written = xed_document_input_stream_tell (dstream); + + write_file_chunk (async); +} + +static void +async_replace_ready_callback (GFile *source, + GAsyncResult *res, + AsyncData *async) +{ + XedDocumentSaver *saver; + GCharsetConverter *converter; + GFileOutputStream *file_stream; + GError *error = NULL; + + xed_debug (DEBUG_SAVER); + + /* Check cancelled state manually */ + if (g_cancellable_is_cancelled (async->cancellable)) + { + async_data_free (async); + return; + } + + saver = async->saver; + file_stream = g_file_replace_finish (source, res, &error); + + /* handle any error that might occur */ + if (!file_stream) + { + xed_debug_message (DEBUG_SAVER, "Opening file failed: %s", error->message); + async_failed (async, error); + return; + } + + /* FIXME: manage converter error? */ + xed_debug_message (DEBUG_SAVER, "Encoding charset: %s", xed_encoding_get_charset (saver->priv->encoding)); + + if (saver->priv->encoding != xed_encoding_get_utf8 ()) + { + converter = g_charset_converter_new (xed_encoding_get_charset (saver->priv->encoding), "UTF-8", NULL); + saver->priv->stream = g_converter_output_stream_new (G_OUTPUT_STREAM (file_stream), G_CONVERTER (converter)); + + g_object_unref (file_stream); + g_object_unref (converter); + } + else + { + saver->priv->stream = G_OUTPUT_STREAM (file_stream); + } + + saver->priv->input = xed_document_input_stream_new (GTK_TEXT_BUFFER (saver->priv->document), + saver->priv->newline_type); + + saver->priv->size = xed_document_input_stream_get_total_size (XED_DOCUMENT_INPUT_STREAM (saver->priv->input)); + + read_file_chunk (async); +} + +static void +begin_write (AsyncData *async) +{ + XedDocumentSaver *saver; + gboolean backup; + + xed_debug_message (DEBUG_SAVER, "Start replacing file contents"); + + /* For remote files we simply use g_file_replace_async. There is no + * backup as of yet + */ + saver = async->saver; + + /* Do not make backups for remote files so they do not clutter remote systems */ + backup = (saver->priv->keep_backup && xed_document_is_local (saver->priv->document)); + + xed_debug_message (DEBUG_SAVER, "File contents size: %" G_GINT64_FORMAT, saver->priv->size); + xed_debug_message (DEBUG_SAVER, "Calling replace_async"); + xed_debug_message (DEBUG_SAVER, backup ? "Keep backup" : "Discard backup"); + + g_file_replace_async (saver->priv->location, + NULL, + backup, + G_FILE_CREATE_NONE, + G_PRIORITY_HIGH, + async->cancellable, + (GAsyncReadyCallback) async_replace_ready_callback, + async); +} + +static void +mount_ready_callback (GFile *file, + GAsyncResult *res, + AsyncData *async) +{ + GError *error = NULL; + gboolean mounted; + + xed_debug (DEBUG_SAVER); + + /* manual check for cancelled state */ + if (g_cancellable_is_cancelled (async->cancellable)) + { + async_data_free (async); + return; + } + + mounted = g_file_mount_enclosing_volume_finish (file, res, &error); + + if (!mounted) + { + async_failed (async, error); + } + else + { + /* try again to get the modified state */ + check_modified_async (async); + } +} + +static void +recover_not_mounted (AsyncData *async) +{ + XedDocument *doc; + GMountOperation *mount_operation; + + xed_debug (DEBUG_LOADER); + + doc = xed_document_saver_get_document (async->saver); + mount_operation = _xed_document_create_mount_operation (doc); + + async->tried_mount = TRUE; + g_file_mount_enclosing_volume (async->saver->priv->location, + G_MOUNT_MOUNT_NONE, + mount_operation, + async->cancellable, + (GAsyncReadyCallback) mount_ready_callback, + async); + + g_object_unref (mount_operation); +} + +static void +check_modification_callback (GFile *source, + GAsyncResult *res, + AsyncData *async) +{ + XedDocumentSaver *saver; + GError *error = NULL; + GFileInfo *info; + + xed_debug (DEBUG_SAVER); + + /* manually check cancelled state */ + if (g_cancellable_is_cancelled (async->cancellable)) + { + async_data_free (async); + return; + } + + saver = async->saver; + info = g_file_query_info_finish (source, res, &error); + if (info == NULL) + { + if (error->code == G_IO_ERROR_NOT_MOUNTED && !async->tried_mount) + { + recover_not_mounted (async); + g_error_free (error); + return; + } + + /* it's perfectly fine if the file doesn't exist yet */ + if (error->code != G_IO_ERROR_NOT_FOUND) + { + xed_debug_message (DEBUG_SAVER, "Error getting modification: %s", error->message); + + async_failed (async, error); + return; + } + } + + /* check if the mtime is > what we know about it (if we have it) */ + if (info != NULL && g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) + { + GTimeVal mtime; + GTimeVal old_mtime; + + g_file_info_get_modification_time (info, &mtime); + old_mtime = saver->priv->old_mtime; + + if ((old_mtime.tv_sec > 0 || old_mtime.tv_usec > 0) && + (mtime.tv_sec != old_mtime.tv_sec || mtime.tv_usec != old_mtime.tv_usec) && + (saver->priv->flags & XED_DOCUMENT_SAVE_IGNORE_MTIME) == 0) + { + xed_debug_message (DEBUG_SAVER, "File is externally modified"); + g_set_error (&saver->priv->error, + XED_DOCUMENT_ERROR, + XED_DOCUMENT_ERROR_EXTERNALLY_MODIFIED, + "Externally modified"); + + remote_save_completed_or_failed (saver, async); + g_object_unref (info); + + return; + } + } + + if (info != NULL) + { + g_object_unref (info); + } + + /* modification check passed, start write */ + begin_write (async); +} + +static void +check_modified_async (AsyncData *async) +{ + xed_debug_message (DEBUG_SAVER, "Check externally modified"); + + g_file_query_info_async (async->saver->priv->location, + G_FILE_ATTRIBUTE_TIME_MODIFIED, + G_FILE_QUERY_INFO_NONE, + G_PRIORITY_HIGH, + async->cancellable, + (GAsyncReadyCallback) check_modification_callback, + async); +} + +static gboolean +save_remote_file_real (XedDocumentSaver *saver) +{ + AsyncData *async; + + xed_debug_message (DEBUG_SAVER, "Starting save"); + + /* First find out if the file is modified externally. This requires + * a stat, but I don't think we can do this any other way + */ + async = async_data_new (saver); + + check_modified_async (async); + + /* return false to stop timeout */ + return FALSE; +} + +void +xed_document_saver_save (XedDocumentSaver *saver, + GTimeVal *old_mtime) +{ + xed_debug (DEBUG_SAVER); + + g_return_if_fail (XED_IS_DOCUMENT_SAVER (saver)); + g_return_if_fail (saver->priv->location != NULL); + + g_return_if_fail (saver->priv->used == FALSE); + saver->priv->used = TRUE; + + /* CHECK: + report async (in an idle handler) or sync (bool ret) + async is extra work here, sync is special casing in the caller */ + + /* never keep backup of autosaves */ + if ((saver->priv->flags & XED_DOCUMENT_SAVE_PRESERVE_BACKUP) != 0) + { + saver->priv->keep_backup = FALSE; + } + else + { + saver->priv->keep_backup = xed_prefs_manager_get_create_backup_copy (); + } + + saver->priv->old_mtime = *old_mtime; + + /* saving start */ + xed_document_saver_saving (saver, FALSE, NULL); + + g_timeout_add_full (G_PRIORITY_HIGH, 0, (GSourceFunc) save_remote_file_real, saver, NULL); } void xed_document_saver_saving (XedDocumentSaver *saver, - gboolean completed, - GError *error) + gboolean completed, + GError *error) { - /* the object will be unrefed in the callback of the saving - * signal, so we need to prevent finalization. - */ - if (completed) - { - g_object_ref (saver); - } + /* the object will be unrefed in the callback of the saving + * signal, so we need to prevent finalization. + */ + if (completed) + { + g_object_ref (saver); + } - g_signal_emit (saver, signals[SAVING], 0, completed, error); + g_signal_emit (saver, signals[SAVING], 0, completed, error); - if (completed) - { - if (error == NULL) - xed_debug_message (DEBUG_SAVER, "save completed"); - else - xed_debug_message (DEBUG_SAVER, "save failed"); + if (completed) + { + if (error == NULL) + xed_debug_message (DEBUG_SAVER, "save completed"); + else + xed_debug_message (DEBUG_SAVER, "save failed"); - g_object_unref (saver); - } -} - -void -xed_document_saver_save (XedDocumentSaver *saver, - GTimeVal *old_mtime) -{ - xed_debug (DEBUG_SAVER); - - g_return_if_fail (XED_IS_DOCUMENT_SAVER (saver)); - g_return_if_fail (saver->uri != NULL && strlen (saver->uri) > 0); - - g_return_if_fail (saver->used == FALSE); - saver->used = TRUE; - - // CHECK: - // - sanity check a max len for the uri? - // report async (in an idle handler) or sync (bool ret) - // async is extra work here, sync is special casing in the caller - - /* never keep backup of autosaves */ - if ((saver->flags & XED_DOCUMENT_SAVE_PRESERVE_BACKUP) != 0) - saver->keep_backup = FALSE; - else - saver->keep_backup = xed_prefs_manager_get_create_backup_copy (); - - XED_DOCUMENT_SAVER_GET_CLASS (saver)->save (saver, old_mtime); + g_object_unref (saver); + } } XedDocument * xed_document_saver_get_document (XedDocumentSaver *saver) { - g_return_val_if_fail (XED_IS_DOCUMENT_SAVER (saver), NULL); + g_return_val_if_fail (XED_IS_DOCUMENT_SAVER (saver), NULL); - return saver->document; + return saver->priv->document; } -const gchar * -xed_document_saver_get_uri (XedDocumentSaver *saver) +GFile * +xed_document_saver_get_location (XedDocumentSaver *saver) { - g_return_val_if_fail (XED_IS_DOCUMENT_SAVER (saver), NULL); + g_return_val_if_fail (XED_IS_DOCUMENT_SAVER (saver), NULL); - return saver->uri; + return g_file_dup (saver->priv->location); } /* Returns 0 if file size is unknown */ goffset xed_document_saver_get_file_size (XedDocumentSaver *saver) { - g_return_val_if_fail (XED_IS_DOCUMENT_SAVER (saver), 0); + g_return_val_if_fail (XED_IS_DOCUMENT_SAVER (saver), 0); - return XED_DOCUMENT_SAVER_GET_CLASS (saver)->get_file_size (saver); + return saver->priv->size; } goffset xed_document_saver_get_bytes_written (XedDocumentSaver *saver) { - g_return_val_if_fail (XED_IS_DOCUMENT_SAVER (saver), 0); + g_return_val_if_fail (XED_IS_DOCUMENT_SAVER (saver), 0); - return XED_DOCUMENT_SAVER_GET_CLASS (saver)->get_bytes_written (saver); + return saver->priv->bytes_written; } GFileInfo * xed_document_saver_get_info (XedDocumentSaver *saver) { - g_return_val_if_fail (XED_IS_DOCUMENT_SAVER (saver), NULL); + g_return_val_if_fail (XED_IS_DOCUMENT_SAVER (saver), NULL); - return saver->info; + return saver->priv->info; } diff --git a/xed/xed-document-saver.h b/xed/xed-document-saver.h index 89743b1..f0fb6c3 100644 --- a/xed/xed-document-saver.h +++ b/xed/xed-document-saver.h @@ -25,8 +25,6 @@ * Modified by the xed Team, 2005. See the AUTHORS file for a * list of people on the xed Team. * See the ChangeLog files for a list of changes. - * - * $Id$ */ #ifndef __XED_DOCUMENT_SAVER_H__ @@ -36,9 +34,6 @@ G_BEGIN_DECLS -/* - * Type checking and casting macros - */ #define XED_TYPE_DOCUMENT_SAVER (xed_document_saver_get_type()) #define XED_DOCUMENT_SAVER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_DOCUMENT_SAVER, XedDocumentSaver)) #define XED_DOCUMENT_SAVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_DOCUMENT_SAVER, XedDocumentSaverClass)) @@ -46,87 +41,62 @@ G_BEGIN_DECLS #define XED_IS_DOCUMENT_SAVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_DOCUMENT_SAVER)) #define XED_DOCUMENT_SAVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_DOCUMENT_SAVER, XedDocumentSaverClass)) -/* - * Main object structure - */ -typedef struct _XedDocumentSaver XedDocumentSaver; +typedef struct _XedDocumentSaver XedDocumentSaver; +typedef struct _XedDocumentSaverPrivate XedDocumentSaverPrivate; +typedef struct _XedDocumentSaverClass XedDocumentSaverClass; -struct _XedDocumentSaver +struct _XedDocumentSaver { - GObject object; + GObject object; - /*< private >*/ - GFileInfo *info; - XedDocument *document; - gboolean used; - - gchar *uri; - const XedEncoding *encoding; - XedDocumentNewlineType newline_type; - - XedDocumentSaveFlags flags; - - gboolean keep_backup; + /*< private >*/ + XedDocumentSaverPrivate *priv; }; -/* - * Class definition - */ -typedef struct _XedDocumentSaverClass XedDocumentSaverClass; - -struct _XedDocumentSaverClass +struct _XedDocumentSaverClass { - GObjectClass parent_class; + GObjectClass parent_class; - /* Signals */ - void (* saving) (XedDocumentSaver *saver, - gboolean completed, - const GError *error); - - /* VTable */ - void (* save) (XedDocumentSaver *saver, - GTimeVal *old_mtime); - goffset (* get_file_size) (XedDocumentSaver *saver); - goffset (* get_bytes_written) (XedDocumentSaver *saver); + /* Signals */ + void (* saving) (XedDocumentSaver *saver, + gboolean completed, + const GError *error); }; -/* - * Public methods - */ -GType xed_document_saver_get_type (void) G_GNUC_CONST; +GType xed_document_saver_get_type (void) G_GNUC_CONST; /* If enconding == NULL, the encoding will be autodetected */ -XedDocumentSaver *xed_document_saver_new (XedDocument *doc, - const gchar *uri, - const XedEncoding *encoding, - XedDocumentNewlineType newline_type, - XedDocumentSaveFlags flags); +XedDocumentSaver *xed_document_saver_new (XedDocument *doc, + GFile *location, + const XedEncoding *encoding, + XedDocumentNewlineType newline_type, + XedDocumentSaveFlags flags); -void xed_document_saver_saving (XedDocumentSaver *saver, - gboolean completed, - GError *error); -void xed_document_saver_save (XedDocumentSaver *saver, - GTimeVal *old_mtime); +void xed_document_saver_saving (XedDocumentSaver *saver, + gboolean completed, + GError *error); +void xed_document_saver_save (XedDocumentSaver *saver, + GTimeVal *old_mtime); #if 0 -void xed_document_saver_cancel (XedDocumentSaver *saver); +void xed_document_saver_cancel (XedDocumentSaver *saver); #endif -XedDocument *xed_document_saver_get_document (XedDocumentSaver *saver); +XedDocument *xed_document_saver_get_document (XedDocumentSaver *saver); -const gchar *xed_document_saver_get_uri (XedDocumentSaver *saver); +GFile *xed_document_saver_get_location (XedDocumentSaver *saver); /* If backup_uri is NULL no backup will be made */ -const gchar *xed_document_saver_get_backup_uri (XedDocumentSaver *saver); -void *xed_document_saver_set_backup_uri (XedDocumentSaver *saver, - const gchar *backup_uri); +const gchar *xed_document_saver_get_backup_uri (XedDocumentSaver *saver); +void *xed_document_saver_set_backup_uri (XedDocumentSaver *saver, + const gchar *backup_uri); /* Returns 0 if file size is unknown */ -goffset xed_document_saver_get_file_size (XedDocumentSaver *saver); +goffset xed_document_saver_get_file_size (XedDocumentSaver *saver); -goffset xed_document_saver_get_bytes_written (XedDocumentSaver *saver); +goffset xed_document_saver_get_bytes_written (XedDocumentSaver *saver); -GFileInfo *xed_document_saver_get_info (XedDocumentSaver *saver); +GFileInfo *xed_document_saver_get_info (XedDocumentSaver *saver); G_END_DECLS diff --git a/xed/xed-document.c b/xed/xed-document.c index 0f6a0be..51a4d15 100644 --- a/xed/xed-document.c +++ b/xed/xed-document.c @@ -80,12 +80,12 @@ PROFILE (static GTimer *timer = NULL) #define XED_DOCUMENT_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_DOCUMENT, XedDocumentPrivate)) static void xed_document_load_real (XedDocument *doc, - const gchar *uri, + GFile *location, const XedEncoding *encoding, gint line_pos, gboolean create); static void xed_document_save_real (XedDocument *doc, - const gchar *uri, + GFile *location, const XedEncoding *encoding, XedDocumentSaveFlags flags); static void to_search_region_range (XedDocument *doc, @@ -102,7 +102,7 @@ static void delete_range_cb (XedDocument *doc, struct _XedDocumentPrivate { - gchar *uri; + GFile *location; gint untitled_number; gchar *short_name; @@ -150,7 +150,7 @@ enum { PROP_0, - PROP_URI, + PROP_LOCATION, PROP_SHORTNAME, PROP_CONTENT_TYPE, PROP_MIME_TYPE, @@ -237,7 +237,7 @@ xed_document_dispose (GObject *object) * because the language is gone by the time finalize runs. * beside if some plugin prevents proper finalization by * holding a ref to the doc, we still save the metadata */ - if ((!doc->priv->dispose_has_run) && (doc->priv->uri != NULL)) + if ((!doc->priv->dispose_has_run) && (doc->priv->location != NULL)) { GtkTextIter iter; gchar *position; @@ -290,6 +290,12 @@ xed_document_dispose (GObject *object) doc->priv->metadata_info = NULL; } + if (doc->priv->location != NULL) + { + g_object_unref (doc->priv->location); + doc->priv->location = NULL; + } + doc->priv->dispose_has_run = TRUE; G_OBJECT_CLASS (xed_document_parent_class)->dispose (object); @@ -304,11 +310,9 @@ xed_document_finalize (GObject *object) if (doc->priv->untitled_number > 0) { - g_return_if_fail (doc->priv->uri == NULL); release_untitled_number (doc->priv->untitled_number); } - g_free (doc->priv->uri); g_free (doc->priv->content_type); g_free (doc->priv->search_text); @@ -331,8 +335,8 @@ xed_document_get_property (GObject *object, switch (prop_id) { - case PROP_URI: - g_value_set_string (value, doc->priv->uri); + case PROP_LOCATION: + g_value_set_object (value, doc->priv->location); break; case PROP_SHORTNAME: g_value_take_string (value, xed_document_get_short_name_for_display (doc)); @@ -444,11 +448,11 @@ xed_document_class_init (XedDocumentClass *klass) klass->load = xed_document_load_real; klass->save = xed_document_save_real; - g_object_class_install_property (object_class, PROP_URI, - g_param_spec_string ("uri", - "URI", - "The document's URI", - NULL, + g_object_class_install_property (object_class, PROP_LOCATION, + g_param_spec_object ("location", + "LOCATION", + "The document's location", + G_TYPE_FILE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); @@ -543,7 +547,7 @@ xed_document_class_init (XedDocumentClass *klass) /** * XedDocument::load: * @document: the #XedDocument. - * @uri: the uri where to load the document from. + * @location: the location where to load the document from. * @encoding: the #XedEncoding to encode the document. * @line_pos: the line to show. * @create: whether the document should be created if it doesn't exist. @@ -556,10 +560,10 @@ xed_document_class_init (XedDocumentClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (XedDocumentClass, load), NULL, NULL, - xed_marshal_VOID__STRING_BOXED_INT_BOOLEAN, + xed_marshal_VOID__OBJECT_BOXED_INT_BOOLEAN, G_TYPE_NONE, 4, - G_TYPE_STRING, + G_TYPE_FILE, /* we rely on the fact that the XedEncoding pointer stays * the same forever */ XED_TYPE_ENCODING | G_SIGNAL_TYPE_STATIC_SCOPE, @@ -593,7 +597,7 @@ xed_document_class_init (XedDocumentClass *klass) /** * XedDocument::save: * @document: the #XedDocument. - * @uri: the uri where the document is about to be saved. + * @location: the location where the document is about to be saved. * @encoding: the #XedEncoding used to save the document. * @flags: the #XedDocumentSaveFlags for the save operation. * @@ -605,10 +609,10 @@ xed_document_class_init (XedDocumentClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (XedDocumentClass, save), NULL, NULL, - xed_marshal_VOID__STRING_BOXED_FLAGS, + xed_marshal_VOID__OBJECT_BOXED_FLAGS, G_TYPE_NONE, 3, - G_TYPE_STRING, + G_TYPE_FILE, /* we rely on the fact that the XedEncoding pointer stays * the same forever */ XED_TYPE_ENCODING | G_SIGNAL_TYPE_STATIC_SCOPE, @@ -680,7 +684,7 @@ set_language (XedDocument *doc, gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (doc), FALSE); } - if (set_by_user && (doc->priv->uri != NULL)) + if (set_by_user) { xed_document_set_metadata (doc, XED_METADATA_ATTRIBUTE_LANGUAGE, (lang == NULL) ? "_NORMAL_" : gtk_source_language_get_id (lang), @@ -747,18 +751,18 @@ get_default_style_scheme (void) } static void -on_uri_changed (XedDocument *doc, - GParamSpec *pspec, - gpointer useless) +on_location_changed (XedDocument *doc, + GParamSpec *pspec, + gpointer useless) { #ifdef ENABLE_GVFS_METADATA GFile *location; location = xed_document_get_location (doc); - /* load metadata for this uri: we load sync since metadata is + /* load metadata for this location: we load sync since metadata is * always local so it should be fast and we need the information - * right after the uri was set. + * right after the location was set. */ if (location != NULL) { @@ -814,15 +818,15 @@ guess_language (XedDocument *doc, } else { - GFile *file; + GFile *location; gchar *basename = NULL; - file = xed_document_get_location (doc); + location = xed_document_get_location (doc); xed_debug_message (DEBUG_DOCUMENT, "Sniffing Language"); - if (file) + if (location) { - basename = g_file_get_basename (file); + basename = g_file_get_basename (location); } else if (doc->priv->short_name != NULL) { @@ -833,9 +837,9 @@ guess_language (XedDocument *doc, g_free (basename); - if (file != NULL) + if (location != NULL) { - g_object_unref (file); + g_object_unref (location); } } @@ -875,7 +879,7 @@ xed_document_init (XedDocument *doc) doc->priv = XED_DOCUMENT_GET_PRIVATE (doc); - doc->priv->uri = NULL; + doc->priv->location = NULL; doc->priv->untitled_number = get_untitled_number (); doc->priv->metadata_info = NULL; @@ -914,7 +918,7 @@ xed_document_init (XedDocument *doc) g_signal_connect_after (doc, "insert-text", G_CALLBACK (insert_text_cb), NULL); g_signal_connect_after (doc, "delete-range", G_CALLBACK (delete_range_cb), NULL); g_signal_connect (doc, "notify::content-type", G_CALLBACK (on_content_type_changed), NULL); - g_signal_connect (doc, "notify::uri", G_CALLBACK (on_uri_changed), NULL); + g_signal_connect (doc, "notify::location", G_CALLBACK (on_location_changed), NULL); } XedDocument * @@ -953,26 +957,26 @@ set_content_type_no_guess (XedDocument *doc, static void set_content_type (XedDocument *doc, - const gchar *content_type) + const gchar *content_type) { xed_debug (DEBUG_DOCUMENT); if (content_type == NULL) { - GFile *file; + GFile *location; gchar *guessed_type = NULL; /* If content type is null, we guess from the filename */ - file = xed_document_get_location (doc); - if (file != NULL) + location = xed_document_get_location (doc); + if (location != NULL) { gchar *basename; - basename = g_file_get_basename (file); + basename = g_file_get_basename (location); guessed_type = g_content_type_guess (basename, NULL, 0, NULL); g_free (basename); - g_object_unref (file); + g_object_unref (location); } set_content_type_no_guess (doc, guessed_type); @@ -1000,22 +1004,26 @@ xed_document_set_content_type (XedDocument *doc, } static void -set_uri (XedDocument *doc, - const gchar *uri) +set_location (XedDocument *doc, + GFile *location) { xed_debug (DEBUG_DOCUMENT); - g_return_if_fail ((uri == NULL) || xed_utils_is_valid_uri (uri)); + g_return_if_fail ((location == NULL) || xed_utils_is_valid_location (location)); - if (uri != NULL) + if (location != NULL) { - if (doc->priv->uri == uri) + if (doc->priv->location == location) { return; } - g_free (doc->priv->uri); - doc->priv->uri = g_strdup (uri); + if (doc->priv->location != NULL) + { + g_object_unref (doc->priv->location); + } + + doc->priv->location = g_file_dup (location); if (doc->priv->untitled_number > 0) { @@ -1024,7 +1032,7 @@ set_uri (XedDocument *doc, } } - g_object_notify (G_OBJECT (doc), "uri"); + g_object_notify (G_OBJECT (doc), "location"); if (doc->priv->short_name == NULL) { @@ -1043,25 +1051,17 @@ xed_document_get_location (XedDocument *doc) { g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - return doc->priv->uri == NULL ? NULL : g_file_new_for_uri (doc->priv->uri); -} - -gchar * -xed_document_get_uri (XedDocument *doc) -{ - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - - return g_strdup (doc->priv->uri); + return doc->priv->location == NULL ? NULL : g_file_dup (doc->priv->location); } void -xed_document_set_uri (XedDocument *doc, - const gchar *uri) +xed_document_set_location (XedDocument *doc, + GFile *location) { g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail (uri != NULL); + g_return_if_fail (G_IS_FILE (location)); - set_uri (doc, uri); + set_location (doc, location); set_content_type (doc, NULL); } @@ -1076,13 +1076,13 @@ xed_document_get_uri_for_display (XedDocument *doc) { g_return_val_if_fail (XED_IS_DOCUMENT (doc), g_strdup ("")); - if (doc->priv->uri == NULL) + if (doc->priv->location == NULL) { return g_strdup_printf (_("Unsaved Document %d"), doc->priv->untitled_number); } else { - return xed_utils_uri_for_display (doc->priv->uri); + return xed_utils_uri_for_display (doc->priv->location); } } @@ -1101,13 +1101,13 @@ xed_document_get_short_name_for_display (XedDocument *doc) { return g_strdup (doc->priv->short_name); } - else if (doc->priv->uri == NULL) + else if (doc->priv->location == NULL) { return g_strdup_printf (_("Unsaved Document %d"), doc->priv->untitled_number); } else { - return xed_utils_basename_for_display (doc->priv->uri); + return xed_utils_basename_for_display (doc->priv->location); } } @@ -1161,7 +1161,7 @@ xed_document_get_mime_type (XedDocument *doc) /* Note: do not emit the notify::read-only signal */ static gboolean set_readonly (XedDocument *doc, - gboolean readonly) + gboolean readonly) { xed_debug (DEBUG_DOCUMENT); @@ -1209,23 +1209,20 @@ xed_document_get_readonly (XedDocument *doc) gboolean _xed_document_check_externally_modified (XedDocument *doc) { - GFile *gfile; GFileInfo *info; g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - if (doc->priv->uri == NULL) + if (doc->priv->location == NULL) { return FALSE; } - gfile = g_file_new_for_uri (doc->priv->uri); - info = g_file_query_info (gfile, + info = g_file_query_info (doc->priv->location, G_FILE_ATTRIBUTE_TIME_MODIFIED "," \ G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, G_FILE_QUERY_INFO_NONE, NULL, NULL); - g_object_unref (gfile); if (info != NULL) { @@ -1353,7 +1350,7 @@ document_loader_loaded (XedDocumentLoader *loader, /* special case creating a named new doc */ else if (doc->priv->create && (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_FOUND) && - (xed_utils_uri_has_file_scheme (doc->priv->uri))) + (xed_utils_location_has_file_scheme (doc->priv->location))) { reset_temp_loading_data (doc); @@ -1398,17 +1395,21 @@ document_loader_loading (XedDocumentLoader *loader, static void xed_document_load_real (XedDocument *doc, - const gchar *uri, + GFile *location, const XedEncoding *encoding, gint line_pos, gboolean create) { + gchar *uri; + g_return_if_fail (doc->priv->loader == NULL); + uri = g_file_get_uri (location); xed_debug_message (DEBUG_DOCUMENT, "load_real: uri = %s", uri); + g_free (uri); /* create a loader. It will be destroyed when loading is completed */ - doc->priv->loader = xed_document_loader_new (doc, uri, encoding); + doc->priv->loader = xed_document_loader_new (doc, location, encoding); g_signal_connect (doc->priv->loader, "loading", G_CALLBACK (document_loader_loading), doc); @@ -1416,7 +1417,7 @@ xed_document_load_real (XedDocument *doc, doc->priv->requested_encoding = encoding; doc->priv->requested_line_pos = line_pos; - set_uri (doc, uri); + set_location (doc, location); set_content_type (doc, NULL); xed_document_loader_load (doc->priv->loader); @@ -1425,7 +1426,7 @@ xed_document_load_real (XedDocument *doc, /** * xed_document_load: * @doc: the #XedDocument. - * @uri: the uri where to load the document from. + * @location: the location where to load the document from. * @encoding: the #XedEncoding to encode the document. * @line_pos: the line to show. * @create: whether the document should be created if it doesn't exist. @@ -1434,16 +1435,16 @@ xed_document_load_real (XedDocument *doc, */ void xed_document_load (XedDocument *doc, - const gchar *uri, + GFile *location, const XedEncoding *encoding, gint line_pos, gboolean create) { g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail (uri != NULL); - g_return_if_fail (xed_utils_is_valid_uri (uri)); + g_return_if_fail (location != NULL); + g_return_if_fail (xed_utils_is_valid_location (location)); - g_signal_emit (doc, document_signals[LOAD], 0, uri, encoding, line_pos, create); + g_signal_emit (doc, document_signals[LOAD], 0, location, encoding, line_pos, create); } /** @@ -1478,13 +1479,14 @@ document_saver_saving (XedDocumentSaver *saver, /* save was successful */ if (error == NULL) { - const gchar *uri; + GFile *location; const gchar *content_type = NULL; GTimeVal mtime = {0, 0}; GFileInfo *info; - uri = xed_document_saver_get_uri (saver); - set_uri (doc, uri); + location = xed_document_saver_get_location (saver); + set_location (doc, location); + g_object_unref (location); info = xed_document_saver_get_info (saver); @@ -1533,14 +1535,14 @@ document_saver_saving (XedDocumentSaver *saver, static void xed_document_save_real (XedDocument *doc, - const gchar *uri, + GFile *location, const XedEncoding *encoding, XedDocumentSaveFlags flags) { g_return_if_fail (doc->priv->saver == NULL); /* create a saver, it will be destroyed once saving is complete */ - doc->priv->saver = xed_document_saver_new (doc, uri, encoding, doc->priv->newline_type, flags); + doc->priv->saver = xed_document_saver_new (doc, location, encoding, doc->priv->newline_type, flags); g_signal_connect (doc->priv->saver, "saving", G_CALLBACK (document_saver_saving), doc); @@ -1562,15 +1564,15 @@ xed_document_save (XedDocument *doc, XedDocumentSaveFlags flags) { g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail (doc->priv->uri != NULL); + g_return_if_fail (G_IS_FILE (doc->priv->location)); - g_signal_emit (doc, document_signals[SAVE], 0, doc->priv->uri, doc->priv->encoding, flags); + g_signal_emit (doc, document_signals[SAVE], 0, doc->priv->location, doc->priv->encoding, flags); } /** * xed_document_save_as: * @doc: the #XedDocument. - * @uri: the uri where to save the document. + * @location: the location where to save the document. * @encoding: the #XedEncoding to encode the document. * @flags: optionnal #XedDocumentSaveFlags. * @@ -1579,32 +1581,17 @@ xed_document_save (XedDocument *doc, */ void xed_document_save_as (XedDocument *doc, - const gchar *uri, + GFile *location, const XedEncoding *encoding, XedDocumentSaveFlags flags) { g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail (uri != NULL); + g_return_if_fail (G_IS_FILE (location)); g_return_if_fail (encoding != NULL); - /* priv->mtime refers to the the old uri (if any). Thus, it should be + /* priv->mtime refers to the the old location (if any). Thus, it should be * ignored when saving as. */ - g_signal_emit (doc, document_signals[SAVE], 0, uri, encoding, flags | XED_DOCUMENT_SAVE_IGNORE_MTIME); -} - -gboolean -xed_document_insert_file (XedDocument *doc, - GtkTextIter *iter, - const gchar *uri, - const XedEncoding *encoding) -{ - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - g_return_val_if_fail (iter != NULL, FALSE); - g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == GTK_TEXT_BUFFER (doc), FALSE); - - /* TODO */ - - return FALSE; + g_signal_emit (doc, document_signals[SAVE], 0, location, encoding, flags | XED_DOCUMENT_SAVE_IGNORE_MTIME); } gboolean @@ -1612,7 +1599,7 @@ xed_document_is_untouched (XedDocument *doc) { g_return_val_if_fail (XED_IS_DOCUMENT (doc), TRUE); - return (doc->priv->uri == NULL) && (!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc))); + return (doc->priv->location == NULL) && (!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc))); } gboolean @@ -1620,7 +1607,7 @@ xed_document_is_untitled (XedDocument *doc) { g_return_val_if_fail (XED_IS_DOCUMENT (doc), TRUE); - return (doc->priv->uri == NULL); + return (doc->priv->location == NULL); } gboolean @@ -1628,12 +1615,12 @@ xed_document_is_local (XedDocument *doc) { g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - if (doc->priv->uri == NULL) + if (doc->priv->location == NULL) { return FALSE; } - return xed_utils_uri_has_file_scheme (doc->priv->uri); + return xed_utils_location_has_file_scheme (doc->priv->location); } gboolean @@ -1641,7 +1628,8 @@ xed_document_get_deleted (XedDocument *doc) { g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - return doc->priv->uri && !xed_utils_uri_exists (doc->priv->uri); + /* This is done sync, maybe we should do it async? */ + return doc->priv->location && !xed_utils_location_exists (doc->priv->location); } /* @@ -2592,14 +2580,14 @@ gchar * xed_document_get_metadata (XedDocument *doc, const gchar *key) { - gchar *value = NULL; + gchar *uri; g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); g_return_val_if_fail (key != NULL, NULL); if (!xed_document_is_untitled (doc)) { - value = xed_metadata_manager_get (doc->priv->uri, key); + value = xed_metadata_manager_get (doc->priv->location, key); } return value; @@ -2629,7 +2617,10 @@ xed_document_set_metadata (XedDocument *doc, { value = va_arg (var_args, const gchar *); - xed_metadata_manager_set (doc->priv->uri, key, value); + if (doc->priv->location != NULL) + { + xed_metadata_manager_set (doc->priv->uri, key, value); + } } va_end (var_args); diff --git a/xed/xed-document.h b/xed/xed-document.h index 79f4087..ae9d6ef 100644 --- a/xed/xed-document.h +++ b/xed/xed-document.h @@ -3,8 +3,8 @@ * This file is part of xed * * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence - * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi - * Copyright (C) 2002-2005 Paolo Maggi + * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi + * Copyright (C) 2002-2005 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,18 +18,18 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 1998-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 1998-2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ - + #ifndef __XED_DOCUMENT_H__ #define __XED_DOCUMENT_H__ @@ -66,7 +66,7 @@ typedef enum typedef enum { - XED_SEARCH_DONT_SET_FLAGS = 1 << 0, + XED_SEARCH_DONT_SET_FLAGS = 1 << 0, XED_SEARCH_ENTIRE_WORD = 1 << 1, XED_SEARCH_CASE_SENSITIVE = 1 << 2, XED_SEARCH_PARSE_ESCAPES = 1 << 3 @@ -93,11 +93,11 @@ typedef struct _XedDocumentPrivate XedDocumentPrivate; * Main object structure */ typedef struct _XedDocument XedDocument; - + struct _XedDocument { GtkSourceBuffer buffer; - + /*< private > */ XedDocumentPrivate *priv; }; @@ -117,7 +117,7 @@ struct _XedDocumentClass /* Document load */ void (* load) (XedDocument *document, - const gchar *uri, + GFile *location, const XedEncoding *encoding, gint line_pos, gboolean create); @@ -131,7 +131,7 @@ struct _XedDocumentClass /* Document save */ void (* save) (XedDocument *document, - const gchar *uri, + GFile *location, const XedEncoding *encoding, XedDocumentSaveFlags flags); @@ -169,9 +169,8 @@ XedDocument *xed_document_new (void); GFile *xed_document_get_location (XedDocument *doc); -gchar *xed_document_get_uri (XedDocument *doc); -void xed_document_set_uri (XedDocument *doc, - const gchar *uri); +void xed_document_set_location (XedDocument *doc, + GFile *location); gchar *xed_document_get_uri_for_display (XedDocument *doc); @@ -194,23 +193,18 @@ gchar *xed_document_get_mime_type (XedDocument *doc); gboolean xed_document_get_readonly (XedDocument *doc); void xed_document_load (XedDocument *doc, - const gchar *uri, + GFile *location, const XedEncoding *encoding, gint line_pos, - gboolean create); - -gboolean xed_document_insert_file (XedDocument *doc, - GtkTextIter *iter, - const gchar *uri, - const XedEncoding *encoding); + gboolean create); gboolean xed_document_load_cancel (XedDocument *doc); void xed_document_save (XedDocument *doc, XedDocumentSaveFlags flags); -void xed_document_save_as (XedDocument *doc, - const gchar *uri, +void xed_document_save_as (XedDocument *doc, + GFile *location, const XedEncoding *encoding, XedDocumentSaveFlags flags); @@ -221,7 +215,7 @@ gboolean xed_document_is_local (XedDocument *doc); gboolean xed_document_get_deleted (XedDocument *doc); -gboolean xed_document_goto_line (XedDocument *doc, +gboolean xed_document_goto_line (XedDocument *doc, gint line); gboolean xed_document_goto_line_offset(XedDocument *doc, @@ -231,7 +225,7 @@ gboolean xed_document_goto_line_offset(XedDocument *doc, void xed_document_set_search_text (XedDocument *doc, const gchar *text, guint flags); - + gchar *xed_document_get_search_text (XedDocument *doc, guint *flags); @@ -243,7 +237,7 @@ gboolean xed_document_search_forward (XedDocument *doc, const GtkTextIter *end, GtkTextIter *match_start, GtkTextIter *match_end); - + gboolean xed_document_search_backward (XedDocument *doc, const GtkTextIter *start, const GtkTextIter *end, @@ -251,19 +245,19 @@ gboolean xed_document_search_backward (XedDocument *doc, GtkTextIter *match_end); gint xed_document_replace_all (XedDocument *doc, - const gchar *find, - const gchar *replace, + const gchar *find, + const gchar *replace, guint flags); void xed_document_set_language (XedDocument *doc, GtkSourceLanguage *lang); -GtkSourceLanguage +GtkSourceLanguage *xed_document_get_language (XedDocument *doc); -const XedEncoding +const XedEncoding *xed_document_get_encoding (XedDocument *doc); -void xed_document_set_enable_search_highlighting +void xed_document_set_enable_search_highlighting (XedDocument *doc, gboolean enable); @@ -283,13 +277,13 @@ void xed_document_set_metadata (XedDocument *doc, const gchar *first_key, ...); -/* +/* * Non exported functions */ void _xed_document_set_readonly (XedDocument *doc, gboolean readonly); -glong _xed_document_get_seconds_since_last_save_or_load +glong _xed_document_get_seconds_since_last_save_or_load (XedDocument *doc); /* Note: this is a sync stat: use only on local files */ @@ -299,7 +293,7 @@ gboolean _xed_document_check_externally_modified void _xed_document_search_region (XedDocument *doc, const GtkTextIter *start, const GtkTextIter *end); - + /* Search macros */ #define XED_SEARCH_IS_DONT_SET_FLAGS(sflags) ((sflags & XED_SEARCH_DONT_SET_FLAGS) != 0) #define XED_SEARCH_SET_DONT_SET_FLAGS(sflags,state) ((state == TRUE) ? \ @@ -317,7 +311,7 @@ void _xed_document_search_region (XedDocument *doc, #define XED_SEARCH_SET_PARSE_ESCAPES(sflags,state) ((state == TRUE) ? \ (sflags |= XED_SEARCH_PARSE_ESCAPES) : (sflags &= ~XED_SEARCH_PARSE_ESCAPES)) -typedef GMountOperation *(*XedMountOperationFactory)(XedDocument *doc, +typedef GMountOperation *(*XedMountOperationFactory)(XedDocument *doc, gpointer userdata); void _xed_document_set_mount_operation_factory diff --git a/xed/xed-gio-document-loader.c b/xed/xed-gio-document-loader.c deleted file mode 100644 index bbac86c..0000000 --- a/xed/xed-gio-document-loader.c +++ /dev/null @@ -1,708 +0,0 @@ -/* - * xed-gio-document-loader.c - * This file is part of xed - * - * Copyright (C) 2005 - Paolo Maggi - * Copyright (C) 2007 - Paolo Maggi, Steve Frécinaux - * Copyright (C) 2008 - Jesse van den Kieboom - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2005-2008. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#include "xed-gio-document-loader.h" -#include "xed-document-output-stream.h" -#include "xed-smart-charset-converter.h" -#include "xed-prefs-manager.h" -#include "xed-debug.h" -#include "xed-utils.h" - -#ifndef ENABLE_GVFS_METADATA -#include "xed-metadata-manager.h" -#endif - -typedef struct -{ - XedGioDocumentLoader *loader; - GCancellable *cancellable; - - gssize read; - gboolean tried_mount; -} AsyncData; - -#define READ_CHUNK_SIZE 8192 -#define REMOTE_QUERY_ATTRIBUTES G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," \ - G_FILE_ATTRIBUTE_STANDARD_TYPE "," \ - G_FILE_ATTRIBUTE_TIME_MODIFIED "," \ - G_FILE_ATTRIBUTE_STANDARD_SIZE "," \ - G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE "," \ - XED_METADATA_ATTRIBUTE_ENCODING - -#define XED_GIO_DOCUMENT_LOADER_GET_PRIVATE(object) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((object), \ - XED_TYPE_GIO_DOCUMENT_LOADER, \ - XedGioDocumentLoaderPrivate)) - -static void xed_gio_document_loader_load (XedDocumentLoader *loader); -static gboolean xed_gio_document_loader_cancel (XedDocumentLoader *loader); -static goffset xed_gio_document_loader_get_bytes_read (XedDocumentLoader *loader); - -static void open_async_read (AsyncData *async); - -struct _XedGioDocumentLoaderPrivate -{ - /* Info on the current file */ - GFile *gfile; - - goffset bytes_read; - - /* Handle for remote files */ - GCancellable *cancellable; - GInputStream *stream; - GOutputStream *output; - XedSmartCharsetConverter *converter; - - gchar buffer[READ_CHUNK_SIZE]; - - GError *error; -}; - -G_DEFINE_TYPE(XedGioDocumentLoader, xed_gio_document_loader, XED_TYPE_DOCUMENT_LOADER) - -static void -xed_gio_document_loader_dispose (GObject *object) -{ - XedGioDocumentLoaderPrivate *priv; - - priv = XED_GIO_DOCUMENT_LOADER (object)->priv; - - if (priv->cancellable != NULL) - { - g_cancellable_cancel (priv->cancellable); - g_object_unref (priv->cancellable); - priv->cancellable = NULL; - } - - if (priv->stream != NULL) - { - g_object_unref (priv->stream); - priv->stream = NULL; - } - - if (priv->output != NULL) - { - g_object_unref (priv->output); - priv->output = NULL; - } - - if (priv->converter != NULL) - { - g_object_unref (priv->converter); - priv->converter = NULL; - } - - if (priv->gfile != NULL) - { - g_object_unref (priv->gfile); - priv->gfile = NULL; - } - - if (priv->error != NULL) - { - g_error_free (priv->error); - priv->error = NULL; - } - - G_OBJECT_CLASS (xed_gio_document_loader_parent_class)->dispose (object); -} - -static void -xed_gio_document_loader_class_init (XedGioDocumentLoaderClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - XedDocumentLoaderClass *loader_class = XED_DOCUMENT_LOADER_CLASS (klass); - - object_class->dispose = xed_gio_document_loader_dispose; - - loader_class->load = xed_gio_document_loader_load; - loader_class->cancel = xed_gio_document_loader_cancel; - loader_class->get_bytes_read = xed_gio_document_loader_get_bytes_read; - - g_type_class_add_private (object_class, sizeof(XedGioDocumentLoaderPrivate)); -} - -static void -xed_gio_document_loader_init (XedGioDocumentLoader *gvloader) -{ - gvloader->priv = XED_GIO_DOCUMENT_LOADER_GET_PRIVATE (gvloader); - - gvloader->priv->converter = NULL; - gvloader->priv->error = NULL; -} - -static AsyncData * -async_data_new (XedGioDocumentLoader *gvloader) -{ - AsyncData *async; - - async = g_slice_new (AsyncData); - async->loader = gvloader; - async->cancellable = g_object_ref (gvloader->priv->cancellable); - async->tried_mount = FALSE; - - return async; -} - -static void -async_data_free (AsyncData *async) -{ - g_object_unref (async->cancellable); - g_slice_free (AsyncData, async); -} - -static const XedEncoding * -get_metadata_encoding (XedDocumentLoader *loader) -{ - const XedEncoding *enc = NULL; - -#ifndef ENABLE_GVFS_METADATA - gchar *charset; - const gchar *uri; - - uri = xed_document_loader_get_uri (loader); - - charset = xed_metadata_manager_get (uri, "encoding"); - - if (charset == NULL) - return NULL; - - enc = xed_encoding_get_from_charset (charset); - - g_free (charset); -#else - GFileInfo *info; - - info = xed_document_loader_get_info (loader); - - /* check if the encoding was set in the metadata */ - if (g_file_info_has_attribute (info, XED_METADATA_ATTRIBUTE_ENCODING)) - { - const gchar *charset; - - charset = g_file_info_get_attribute_string (info, - XED_METADATA_ATTRIBUTE_ENCODING); - - if (charset == NULL) - return NULL; - - enc = xed_encoding_get_from_charset (charset); - } -#endif - - return enc; -} - -static void -remote_load_completed_or_failed (XedGioDocumentLoader *loader, AsyncData *async) -{ - xed_document_loader_loading (XED_DOCUMENT_LOADER (loader), - TRUE, - loader->priv->error); - - if (async) - async_data_free (async); -} - -static void -async_failed (AsyncData *async, GError *error) -{ - g_propagate_error (&async->loader->priv->error, error); - remote_load_completed_or_failed (async->loader, async); -} - -static void -close_input_stream_ready_cb (GInputStream *stream, - GAsyncResult *res, - AsyncData *async) -{ - GError *error = NULL; - - xed_debug (DEBUG_LOADER); - - /* check cancelled state manually */ - if (g_cancellable_is_cancelled (async->cancellable)) - { - async_data_free (async); - return; - } - - xed_debug_message (DEBUG_SAVER, "Finished closing input stream"); - - if (!g_input_stream_close_finish (stream, res, &error)) - { - xed_debug_message (DEBUG_SAVER, "Closing input stream error: %s", error->message); - - async_failed (async, error); - return; - } - - xed_debug_message (DEBUG_SAVER, "Close output stream"); - if (!g_output_stream_close (async->loader->priv->output, - async->cancellable, &error)) - { - async_failed (async, error); - return; - } - - remote_load_completed_or_failed (async->loader, async); -} - -static void -write_complete (AsyncData *async) -{ - if (async->loader->priv->stream) - g_input_stream_close_async (G_INPUT_STREAM (async->loader->priv->stream), - G_PRIORITY_HIGH, - async->cancellable, - (GAsyncReadyCallback)close_input_stream_ready_cb, - async); -} - -/* prototype, because they call each other... isn't C lovely */ -static void read_file_chunk (AsyncData *async); - -static void -write_file_chunk (AsyncData *async) -{ - XedGioDocumentLoader *gvloader; - gssize bytes_written; - GError *error = NULL; - - gvloader = async->loader; - - /* we use sync methods on doc stream since it is in memory. Using async - would be racy and we can endup with invalidated iters */ - bytes_written = g_output_stream_write (G_OUTPUT_STREAM (gvloader->priv->output), - gvloader->priv->buffer, - async->read, - async->cancellable, - &error); - - xed_debug_message (DEBUG_SAVER, "Written: %" G_GSSIZE_FORMAT, bytes_written); - if (bytes_written == -1) - { - xed_debug_message (DEBUG_SAVER, "Write error: %s", error->message); - async_failed (async, error); - return; - } - - /* note that this signal blocks the read... check if it isn't - * a performance problem - */ - xed_document_loader_loading (XED_DOCUMENT_LOADER (gvloader), - FALSE, - NULL); - - read_file_chunk (async); -} - -static void -async_read_cb (GInputStream *stream, - GAsyncResult *res, - AsyncData *async) -{ - xed_debug (DEBUG_LOADER); - XedGioDocumentLoader *gvloader; - GError *error = NULL; - - xed_debug (DEBUG_LOADER); - - /* manually check cancelled state */ - if (g_cancellable_is_cancelled (async->cancellable)) - { - async_data_free (async); - return; - } - - gvloader = async->loader; - - async->read = g_input_stream_read_finish (stream, res, &error); - - /* error occurred */ - if (async->read == -1) - { - async_failed (async, error); - return; - } - - /* Check for the extremely unlikely case where the file size overflows. */ - if (gvloader->priv->bytes_read + async->read < gvloader->priv->bytes_read) - { - g_set_error (&gvloader->priv->error, - XED_DOCUMENT_ERROR, - XED_DOCUMENT_ERROR_TOO_BIG, - "File too big"); - - async_failed (async, gvloader->priv->error); - return; - } - - /* Bump the size. */ - gvloader->priv->bytes_read += async->read; - - /* end of the file, we are done! */ - if (async->read == 0) - { - XedDocumentLoader *loader; - - loader = XED_DOCUMENT_LOADER (gvloader); - - g_output_stream_flush (gvloader->priv->output, - NULL, - &gvloader->priv->error); - - loader->auto_detected_encoding = - xed_smart_charset_converter_get_guessed (gvloader->priv->converter); - - loader->auto_detected_newline_type = - xed_document_output_stream_detect_newline_type (XED_DOCUMENT_OUTPUT_STREAM (gvloader->priv->output)); - - /* Check if we needed some fallback char, if so, check if there was - a previous error and if not set a fallback used error */ - /* FIXME Uncomment this when we want to manage conversion fallback */ - /*if ((xed_smart_charset_converter_get_num_fallbacks (gvloader->priv->converter) != 0) && - gvloader->priv->error == NULL) - { - g_set_error_literal (&gvloader->priv->error, - XED_DOCUMENT_ERROR, - XED_DOCUMENT_ERROR_CONVERSION_FALLBACK, - "There was a conversion error and it was " - "needed to use a fallback char"); - }*/ - - write_complete (async); - - return; - } - - write_file_chunk (async); -} - -static void -read_file_chunk (AsyncData *async) -{ - XedGioDocumentLoader *gvloader; - - gvloader = async->loader; - - g_input_stream_read_async (G_INPUT_STREAM (gvloader->priv->stream), - gvloader->priv->buffer, - READ_CHUNK_SIZE, - G_PRIORITY_HIGH, - async->cancellable, - (GAsyncReadyCallback) async_read_cb, - async); -} - -static GSList * -get_candidate_encodings (XedGioDocumentLoader *gvloader) -{ - const XedEncoding *metadata; - GSList *encodings = NULL; - - encodings = xed_prefs_manager_get_auto_detected_encodings (); - - metadata = get_metadata_encoding (XED_DOCUMENT_LOADER (gvloader)); - if (metadata != NULL) - { - encodings = g_slist_prepend (encodings, (gpointer)metadata); - } - - return encodings; -} - -static void -finish_query_info (AsyncData *async) -{ - XedGioDocumentLoader *gvloader; - XedDocumentLoader *loader; - GInputStream *conv_stream; - GFileInfo *info; - GSList *candidate_encodings; - - gvloader = async->loader; - loader = XED_DOCUMENT_LOADER (gvloader); - info = loader->info; - - /* if it's not a regular file, error out... */ - if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_TYPE) && - g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR) - { - g_set_error (&gvloader->priv->error, - G_IO_ERROR, - G_IO_ERROR_NOT_REGULAR_FILE, - "Not a regular file"); - - remote_load_completed_or_failed (gvloader, async); - - return; - } - - /* Get the candidate encodings */ - if (loader->encoding == NULL) - { - candidate_encodings = get_candidate_encodings (gvloader); - } - else - { - candidate_encodings = g_slist_prepend (NULL, (gpointer) loader->encoding); - } - - gvloader->priv->converter = xed_smart_charset_converter_new (candidate_encodings); - g_slist_free (candidate_encodings); - - conv_stream = g_converter_input_stream_new (gvloader->priv->stream, - G_CONVERTER (gvloader->priv->converter)); - g_object_unref (gvloader->priv->stream); - - gvloader->priv->stream = conv_stream; - - /* Output stream */ - gvloader->priv->output = xed_document_output_stream_new (loader->document); - - /* start reading */ - read_file_chunk (async); -} - -static void -query_info_cb (GFile *source, - GAsyncResult *res, - AsyncData *async) -{ - XedGioDocumentLoader *gvloader; - GFileInfo *info; - GError *error = NULL; - - xed_debug (DEBUG_LOADER); - - /* manually check the cancelled state */ - if (g_cancellable_is_cancelled (async->cancellable)) - { - async_data_free (async); - return; - } - - gvloader = async->loader; - - /* finish the info query */ - info = g_file_query_info_finish (gvloader->priv->gfile, - res, - &error); - - if (info == NULL) - { - /* propagate the error and clean up */ - async_failed (async, error); - return; - } - - XED_DOCUMENT_LOADER (gvloader)->info = info; - - finish_query_info (async); -} - -static void -mount_ready_callback (GFile *file, - GAsyncResult *res, - AsyncData *async) -{ - GError *error = NULL; - gboolean mounted; - - xed_debug (DEBUG_LOADER); - - /* manual check for cancelled state */ - if (g_cancellable_is_cancelled (async->cancellable)) - { - async_data_free (async); - return; - } - - mounted = g_file_mount_enclosing_volume_finish (file, res, &error); - - if (!mounted) - { - async_failed (async, error); - } - else - { - /* try again to open the file for reading */ - open_async_read (async); - } -} - -static void -recover_not_mounted (AsyncData *async) -{ - XedDocument *doc; - GMountOperation *mount_operation; - - xed_debug (DEBUG_LOADER); - - doc = xed_document_loader_get_document (XED_DOCUMENT_LOADER (async->loader)); - mount_operation = _xed_document_create_mount_operation (doc); - - async->tried_mount = TRUE; - g_file_mount_enclosing_volume (async->loader->priv->gfile, - G_MOUNT_MOUNT_NONE, - mount_operation, - async->cancellable, - (GAsyncReadyCallback) mount_ready_callback, - async); - - g_object_unref (mount_operation); -} - -static void -async_read_ready_callback (GObject *source, - GAsyncResult *res, - AsyncData *async) -{ - GError *error = NULL; - XedGioDocumentLoader *gvloader; - - xed_debug (DEBUG_LOADER); - - /* manual check for cancelled state */ - if (g_cancellable_is_cancelled (async->cancellable)) - { - async_data_free (async); - return; - } - - gvloader = async->loader; - - gvloader->priv->stream = G_INPUT_STREAM (g_file_read_finish (gvloader->priv->gfile, - res, &error)); - - if (!gvloader->priv->stream) - { - if (error->code == G_IO_ERROR_NOT_MOUNTED && !async->tried_mount) - { - recover_not_mounted (async); - g_error_free (error); - return; - } - - /* Propagate error */ - g_propagate_error (&gvloader->priv->error, error); - xed_document_loader_loading (XED_DOCUMENT_LOADER (gvloader), - TRUE, - gvloader->priv->error); - - async_data_free (async); - return; - } - - /* get the file info: note we cannot use - * g_file_input_stream_query_info_async since it is not able to get the - * content type etc, beside it is not supported by gvfs. - * Using the file instead of the stream is slightly racy, but for - * loading this is not too bad... - */ - g_file_query_info_async (gvloader->priv->gfile, - REMOTE_QUERY_ATTRIBUTES, - G_FILE_QUERY_INFO_NONE, - G_PRIORITY_HIGH, - async->cancellable, - (GAsyncReadyCallback) query_info_cb, - async); -} - -static void -open_async_read (AsyncData *async) -{ - g_file_read_async (async->loader->priv->gfile, - G_PRIORITY_HIGH, - async->cancellable, - (GAsyncReadyCallback) async_read_ready_callback, - async); -} - -static void -xed_gio_document_loader_load (XedDocumentLoader *loader) -{ - XedGioDocumentLoader *gvloader = XED_GIO_DOCUMENT_LOADER (loader); - AsyncData *async; - - xed_debug (DEBUG_LOADER); - - /* make sure no load operation is currently running */ - g_return_if_fail (gvloader->priv->cancellable == NULL); - - gvloader->priv->gfile = g_file_new_for_uri (loader->uri); - - /* loading start */ - xed_document_loader_loading (XED_DOCUMENT_LOADER (gvloader), - FALSE, - NULL); - - gvloader->priv->cancellable = g_cancellable_new (); - async = async_data_new (gvloader); - - open_async_read (async); -} - -static goffset -xed_gio_document_loader_get_bytes_read (XedDocumentLoader *loader) -{ - return XED_GIO_DOCUMENT_LOADER (loader)->priv->bytes_read; -} - -static gboolean -xed_gio_document_loader_cancel (XedDocumentLoader *loader) -{ - XedGioDocumentLoader *gvloader = XED_GIO_DOCUMENT_LOADER (loader); - - if (gvloader->priv->cancellable == NULL) - return FALSE; - - g_cancellable_cancel (gvloader->priv->cancellable); - - g_set_error (&gvloader->priv->error, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - "Operation cancelled"); - - remote_load_completed_or_failed (gvloader, NULL); - - return TRUE; -} diff --git a/xed/xed-gio-document-loader.h b/xed/xed-gio-document-loader.h deleted file mode 100644 index 90e44bb..0000000 --- a/xed/xed-gio-document-loader.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * xed-gio-document-loader.h - * This file is part of xed - * - * Copyright (C) 2005 - Paolo Maggi - * Copyright (C) 2007 - Paolo Maggi, Steve Frécinaux - * Copyright (C) 2008 - Jesse van den Kieboom - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2005-2008. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#ifndef __XED_GIO_DOCUMENT_LOADER_H__ -#define __XED_GIO_DOCUMENT_LOADER_H__ - -#include -#include "xed-document-loader.h" - -G_BEGIN_DECLS - -/* - * Type checking and casting macros - */ -#define XED_TYPE_GIO_DOCUMENT_LOADER (xed_gio_document_loader_get_type()) -#define XED_GIO_DOCUMENT_LOADER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_GIO_DOCUMENT_LOADER, XedGioDocumentLoader)) -#define XED_GIO_DOCUMENT_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_GIO_DOCUMENT_LOADER, XedGioDocumentLoaderClass)) -#define XED_IS_GIO_DOCUMENT_LOADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_GIO_DOCUMENT_LOADER)) -#define XED_IS_GIO_DOCUMENT_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_GIO_DOCUMENT_LOADER)) -#define XED_GIO_DOCUMENT_LOADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_GIO_DOCUMENT_LOADER, XedGioDocumentLoaderClass)) - -/* Private structure type */ -typedef struct _XedGioDocumentLoaderPrivate XedGioDocumentLoaderPrivate; - -/* - * Main object structure - */ -typedef struct _XedGioDocumentLoader XedGioDocumentLoader; - -struct _XedGioDocumentLoader -{ - XedDocumentLoader loader; - - /*< private > */ - XedGioDocumentLoaderPrivate *priv; -}; - -/* - * Class definition - */ -typedef XedDocumentLoaderClass XedGioDocumentLoaderClass; - -/* - * Public methods - */ -GType xed_gio_document_loader_get_type (void) G_GNUC_CONST; - -G_END_DECLS - -#endif /* __XED_GIO_DOCUMENT_LOADER_H__ */ diff --git a/xed/xed-gio-document-saver.c b/xed/xed-gio-document-saver.c deleted file mode 100644 index 5d73f8c..0000000 --- a/xed/xed-gio-document-saver.c +++ /dev/null @@ -1,775 +0,0 @@ -/* - * xed-gio-document-saver.c - * This file is part of xed - * - * Copyright (C) 2005-2006 - Paolo Borelli and Paolo Maggi - * Copyright (C) 2007 - Paolo Borelli, Paolo Maggi, Steve Frécinaux - * Copyright (C) 2008 - Jesse van den Kieboom - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2005-2006. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include - -#include "xed-gio-document-saver.h" -#include "xed-document-input-stream.h" -#include "xed-debug.h" - -#define WRITE_CHUNK_SIZE 8192 - -typedef struct -{ - XedGioDocumentSaver *saver; - gchar buffer[WRITE_CHUNK_SIZE]; - GCancellable *cancellable; - gboolean tried_mount; - gssize written; - gssize read; - GError *error; -} AsyncData; - -#define REMOTE_QUERY_ATTRIBUTES G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," \ - G_FILE_ATTRIBUTE_TIME_MODIFIED - -#define XED_GIO_DOCUMENT_SAVER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ - XED_TYPE_GIO_DOCUMENT_SAVER, \ - XedGioDocumentSaverPrivate)) - -static void xed_gio_document_saver_save (XedDocumentSaver *saver, - GTimeVal *old_mtime); -static goffset xed_gio_document_saver_get_file_size (XedDocumentSaver *saver); -static goffset xed_gio_document_saver_get_bytes_written (XedDocumentSaver *saver); - - -static void check_modified_async (AsyncData *async); - -struct _XedGioDocumentSaverPrivate -{ - GTimeVal old_mtime; - - goffset size; - goffset bytes_written; - - GFile *gfile; - GCancellable *cancellable; - GOutputStream *stream; - GInputStream *input; - - GError *error; -}; - -G_DEFINE_TYPE(XedGioDocumentSaver, xed_gio_document_saver, XED_TYPE_DOCUMENT_SAVER) - -static void -xed_gio_document_saver_dispose (GObject *object) -{ - XedGioDocumentSaverPrivate *priv = XED_GIO_DOCUMENT_SAVER (object)->priv; - - if (priv->cancellable != NULL) - { - g_cancellable_cancel (priv->cancellable); - g_object_unref (priv->cancellable); - priv->cancellable = NULL; - } - - if (priv->gfile != NULL) - { - g_object_unref (priv->gfile); - priv->gfile = NULL; - } - - if (priv->error != NULL) - { - g_error_free (priv->error); - priv->error = NULL; - } - - if (priv->stream != NULL) - { - g_object_unref (priv->stream); - priv->stream = NULL; - } - - if (priv->input != NULL) - { - g_object_unref (priv->input); - priv->input = NULL; - } - - G_OBJECT_CLASS (xed_gio_document_saver_parent_class)->dispose (object); -} - -static AsyncData * -async_data_new (XedGioDocumentSaver *gvsaver) -{ - AsyncData *async; - - async = g_slice_new (AsyncData); - async->saver = gvsaver; - async->cancellable = g_object_ref (gvsaver->priv->cancellable); - - async->tried_mount = FALSE; - async->written = 0; - async->read = 0; - - async->error = NULL; - - return async; -} - -static void -async_data_free (AsyncData *async) -{ - g_object_unref (async->cancellable); - - if (async->error) - { - g_error_free (async->error); - } - - g_slice_free (AsyncData, async); -} - -static void -xed_gio_document_saver_class_init (XedGioDocumentSaverClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - XedDocumentSaverClass *saver_class = XED_DOCUMENT_SAVER_CLASS (klass); - - object_class->dispose = xed_gio_document_saver_dispose; - - saver_class->save = xed_gio_document_saver_save; - saver_class->get_file_size = xed_gio_document_saver_get_file_size; - saver_class->get_bytes_written = xed_gio_document_saver_get_bytes_written; - - g_type_class_add_private (object_class, sizeof(XedGioDocumentSaverPrivate)); -} - -static void -xed_gio_document_saver_init (XedGioDocumentSaver *gvsaver) -{ - gvsaver->priv = XED_GIO_DOCUMENT_SAVER_GET_PRIVATE (gvsaver); - - gvsaver->priv->cancellable = g_cancellable_new (); - gvsaver->priv->error = NULL; -} - -static void -remote_save_completed_or_failed (XedGioDocumentSaver *gvsaver, - AsyncData *async) -{ - xed_document_saver_saving (XED_DOCUMENT_SAVER (gvsaver), - TRUE, - gvsaver->priv->error); - - if (async) - async_data_free (async); -} - -static void -async_failed (AsyncData *async, - GError *error) -{ - g_propagate_error (&async->saver->priv->error, error); - remote_save_completed_or_failed (async->saver, async); -} - -/* BEGIN NOTE: - * - * This fixes an issue in GOutputStream that applies the atomic replace - * save strategy. The stream moves the written file to the original file - * when the stream is closed. However, there is no way currently to tell - * the stream that the save should be aborted (there could be a - * conversion error). The patch explicitly closes the output stream - * in all these cases with a GCancellable in the cancelled state, causing - * the output stream to close, but not move the file. This makes use - * of an implementation detail in the local gio file stream and should be - * properly fixed by adding the appropriate API in gio. Until then, at least - * we prevent data corruption for now. - * - * Relevant bug reports: - * - * Bug 615110 - write file ignore encoding errors (xed) - * https://bugzilla.gnome.org/show_bug.cgi?id=615110 - * - * Bug 602412 - g_file_replace does not restore original file when there is - * errors while writing (glib/gio) - * https://bugzilla.gnome.org/show_bug.cgi?id=602412 - */ -static void -cancel_output_stream_ready_cb (GOutputStream *stream, - GAsyncResult *result, - AsyncData *async) -{ - GError *error; - - g_output_stream_close_finish (stream, result, NULL); - - /* check cancelled state manually */ - if (g_cancellable_is_cancelled (async->cancellable) || async->error == NULL) - { - async_data_free (async); - return; - } - - error = async->error; - async->error = NULL; - - async_failed (async, error); -} - -static void -cancel_output_stream (AsyncData *async) -{ - GCancellable *cancellable; - - xed_debug_message (DEBUG_SAVER, "Cancel output stream"); - - cancellable = g_cancellable_new (); - g_cancellable_cancel (cancellable); - - g_output_stream_close_async (async->saver->priv->stream, - G_PRIORITY_HIGH, - cancellable, - (GAsyncReadyCallback)cancel_output_stream_ready_cb, - async); - - g_object_unref (cancellable); -} - -static void -cancel_output_stream_and_fail (AsyncData *async, - GError *error) -{ - - xed_debug_message (DEBUG_SAVER, "Cancel output stream and fail"); - - g_propagate_error (&async->error, error); - cancel_output_stream (async); -} - -/* - * END NOTE - */ - -static void -remote_get_info_cb (GFile *source, - GAsyncResult *res, - AsyncData *async) -{ - XedGioDocumentSaver *saver; - GFileInfo *info; - GError *error = NULL; - - xed_debug (DEBUG_SAVER); - - /* check cancelled state manually */ - if (g_cancellable_is_cancelled (async->cancellable)) - { - async_data_free (async); - return; - } - - saver = async->saver; - - xed_debug_message (DEBUG_SAVER, "Finished query info on file"); - info = g_file_query_info_finish (source, res, &error); - - if (info != NULL) - { - if (XED_DOCUMENT_SAVER (saver)->info != NULL) - g_object_unref (XED_DOCUMENT_SAVER (saver)->info); - - XED_DOCUMENT_SAVER (saver)->info = info; - } - else - { - xed_debug_message (DEBUG_SAVER, "Query info failed: %s", error->message); - g_propagate_error (&saver->priv->error, error); - } - - remote_save_completed_or_failed (saver, async); -} - -static void -close_async_ready_get_info_cb (GOutputStream *stream, - GAsyncResult *res, - AsyncData *async) -{ - GError *error = NULL; - - xed_debug (DEBUG_SAVER); - - /* check cancelled state manually */ - if (g_cancellable_is_cancelled (async->cancellable)) - { - async_data_free (async); - return; - } - - xed_debug_message (DEBUG_SAVER, "Finished closing stream"); - - if (!g_output_stream_close_finish (stream, res, &error)) - { - xed_debug_message (DEBUG_SAVER, "Closing stream error: %s", error->message); - - async_failed (async, error); - return; - } - - /* get the file info: note we cannot use - * g_file_output_stream_query_info_async since it is not able to get the - * content type etc, beside it is not supported by gvfs. - * I'm not sure this is actually necessary, can't we just use - * g_content_type_guess (since we have the file name and the data) - */ - xed_debug_message (DEBUG_SAVER, "Query info on file"); - g_file_query_info_async (async->saver->priv->gfile, - REMOTE_QUERY_ATTRIBUTES, - G_FILE_QUERY_INFO_NONE, - G_PRIORITY_HIGH, - async->cancellable, - (GAsyncReadyCallback) remote_get_info_cb, - async); -} - -static void -write_complete (AsyncData *async) -{ - GError *error = NULL; - - /* first we close the input stream */ - xed_debug_message (DEBUG_SAVER, "Close input stream"); - if (!g_input_stream_close (async->saver->priv->input, - async->cancellable, &error)) - { - xed_debug_message (DEBUG_SAVER, "Closing input stream error: %s", error->message); - cancel_output_stream_and_fail (async, error); - return; - } - - /* now we close the output stream */ - xed_debug_message (DEBUG_SAVER, "Close output stream"); - g_output_stream_close_async (async->saver->priv->stream, - G_PRIORITY_HIGH, - async->cancellable, - (GAsyncReadyCallback)close_async_ready_get_info_cb, - async); -} - -/* prototype, because they call each other... isn't C lovely */ -static void read_file_chunk (AsyncData *async); -static void write_file_chunk (AsyncData *async); - -static void -async_write_cb (GOutputStream *stream, - GAsyncResult *res, - AsyncData *async) -{ - XedGioDocumentSaver *gvsaver; - gssize bytes_written; - GError *error = NULL; - - xed_debug (DEBUG_SAVER); - - /* Check cancelled state manually */ - if (g_cancellable_is_cancelled (async->cancellable)) - { - cancel_output_stream (async); - return; - } - - bytes_written = g_output_stream_write_finish (stream, res, &error); - - xed_debug_message (DEBUG_SAVER, "Written: %" G_GSSIZE_FORMAT, bytes_written); - - if (bytes_written == -1) - { - xed_debug_message (DEBUG_SAVER, "Write error: %s", error->message); - cancel_output_stream_and_fail (async, error); - return; - } - - gvsaver = async->saver; - async->written += bytes_written; - - /* write again */ - if (async->written != async->read) - { - write_file_chunk (async); - return; - } - - /* note that this signal blocks the write... check if it isn't - * a performance problem - */ - xed_document_saver_saving (XED_DOCUMENT_SAVER (gvsaver), - FALSE, - NULL); - - read_file_chunk (async); -} - -static void -write_file_chunk (AsyncData *async) -{ - XedGioDocumentSaver *gvsaver; - - xed_debug (DEBUG_SAVER); - - gvsaver = async->saver; - - g_output_stream_write_async (G_OUTPUT_STREAM (gvsaver->priv->stream), - async->buffer + async->written, - async->read - async->written, - G_PRIORITY_HIGH, - async->cancellable, - (GAsyncReadyCallback) async_write_cb, - async); -} - -static void -read_file_chunk (AsyncData *async) -{ - XedGioDocumentSaver *gvsaver; - XedDocumentInputStream *dstream; - GError *error = NULL; - - xed_debug (DEBUG_SAVER); - - gvsaver = async->saver; - async->written = 0; - - /* we use sync methods on doc stream since it is in memory. Using async - would be racy and we can endup with invalidated iters */ - async->read = g_input_stream_read (gvsaver->priv->input, - async->buffer, - WRITE_CHUNK_SIZE, - async->cancellable, - &error); - - if (error != NULL) - { - cancel_output_stream_and_fail (async, error); - return; - } - - /* Check if we finished reading and writing */ - if (async->read == 0) - { - write_complete (async); - return; - } - - /* Get how many chars have been read */ - dstream = XED_DOCUMENT_INPUT_STREAM (gvsaver->priv->input); - gvsaver->priv->bytes_written = xed_document_input_stream_tell (dstream); - - write_file_chunk (async); -} - -static void -async_replace_ready_callback (GFile *source, - GAsyncResult *res, - AsyncData *async) -{ - XedGioDocumentSaver *gvsaver; - XedDocumentSaver *saver; - GCharsetConverter *converter; - GFileOutputStream *file_stream; - GError *error = NULL; - - xed_debug (DEBUG_SAVER); - - /* Check cancelled state manually */ - if (g_cancellable_is_cancelled (async->cancellable)) - { - async_data_free (async); - return; - } - - gvsaver = async->saver; - saver = XED_DOCUMENT_SAVER (gvsaver); - file_stream = g_file_replace_finish (source, res, &error); - - /* handle any error that might occur */ - if (!file_stream) - { - xed_debug_message (DEBUG_SAVER, "Opening file failed: %s", error->message); - async_failed (async, error); - return; - } - - /* FIXME: manage converter error? */ - xed_debug_message (DEBUG_SAVER, "Encoding charset: %s", - xed_encoding_get_charset (saver->encoding)); - - if (saver->encoding != xed_encoding_get_utf8 ()) - { - converter = g_charset_converter_new (xed_encoding_get_charset (saver->encoding), - "UTF-8", - NULL); - gvsaver->priv->stream = g_converter_output_stream_new (G_OUTPUT_STREAM (file_stream), - G_CONVERTER (converter)); - - g_object_unref (file_stream); - g_object_unref (converter); - } - else - { - gvsaver->priv->stream = G_OUTPUT_STREAM (file_stream); - } - - gvsaver->priv->input = xed_document_input_stream_new (GTK_TEXT_BUFFER (saver->document), - saver->newline_type); - - gvsaver->priv->size = xed_document_input_stream_get_total_size (XED_DOCUMENT_INPUT_STREAM (gvsaver->priv->input)); - - read_file_chunk (async); -} - -static void -begin_write (AsyncData *async) -{ - XedGioDocumentSaver *gvsaver; - XedDocumentSaver *saver; - gboolean backup; - - xed_debug_message (DEBUG_SAVER, "Start replacing file contents"); - - /* For remote files we simply use g_file_replace_async. There is no - * backup as of yet - */ - gvsaver = async->saver; - saver = XED_DOCUMENT_SAVER (gvsaver); - - /* Do not make backups for remote files so they do not clutter remote systems */ - backup = (saver->keep_backup && xed_document_is_local (saver->document)); - - xed_debug_message (DEBUG_SAVER, "File contents size: %" G_GINT64_FORMAT, gvsaver->priv->size); - xed_debug_message (DEBUG_SAVER, "Calling replace_async"); - xed_debug_message (DEBUG_SAVER, backup ? "Keep backup" : "Discard backup"); - - g_file_replace_async (gvsaver->priv->gfile, - NULL, - backup, - G_FILE_CREATE_NONE, - G_PRIORITY_HIGH, - async->cancellable, - (GAsyncReadyCallback) async_replace_ready_callback, - async); -} - -static void -mount_ready_callback (GFile *file, - GAsyncResult *res, - AsyncData *async) -{ - GError *error = NULL; - gboolean mounted; - - xed_debug (DEBUG_SAVER); - - /* manual check for cancelled state */ - if (g_cancellable_is_cancelled (async->cancellable)) - { - async_data_free (async); - return; - } - - mounted = g_file_mount_enclosing_volume_finish (file, res, &error); - - if (!mounted) - { - async_failed (async, error); - } - else - { - /* try again to get the modified state */ - check_modified_async (async); - } -} - -static void -recover_not_mounted (AsyncData *async) -{ - XedDocument *doc; - GMountOperation *mount_operation; - - xed_debug (DEBUG_LOADER); - - doc = xed_document_saver_get_document (XED_DOCUMENT_SAVER (async->saver)); - mount_operation = _xed_document_create_mount_operation (doc); - - async->tried_mount = TRUE; - g_file_mount_enclosing_volume (async->saver->priv->gfile, - G_MOUNT_MOUNT_NONE, - mount_operation, - async->cancellable, - (GAsyncReadyCallback) mount_ready_callback, - async); - - g_object_unref (mount_operation); -} - -static void -check_modification_callback (GFile *source, - GAsyncResult *res, - AsyncData *async) -{ - XedGioDocumentSaver *gvsaver; - GError *error = NULL; - GFileInfo *info; - - xed_debug (DEBUG_SAVER); - - /* manually check cancelled state */ - if (g_cancellable_is_cancelled (async->cancellable)) - { - async_data_free (async); - return; - } - - gvsaver = async->saver; - info = g_file_query_info_finish (source, res, &error); - if (info == NULL) - { - if (error->code == G_IO_ERROR_NOT_MOUNTED && !async->tried_mount) - { - recover_not_mounted (async); - g_error_free (error); - return; - } - - /* it's perfectly fine if the file doesn't exist yet */ - if (error->code != G_IO_ERROR_NOT_FOUND) - { - xed_debug_message (DEBUG_SAVER, "Error getting modification: %s", error->message); - - async_failed (async, error); - return; - } - } - - /* check if the mtime is > what we know about it (if we have it) */ - if (info != NULL && g_file_info_has_attribute (info, - G_FILE_ATTRIBUTE_TIME_MODIFIED)) - { - GTimeVal mtime; - GTimeVal old_mtime; - - g_file_info_get_modification_time (info, &mtime); - old_mtime = gvsaver->priv->old_mtime; - - if ((old_mtime.tv_sec > 0 || old_mtime.tv_usec > 0) && - (mtime.tv_sec != old_mtime.tv_sec || mtime.tv_usec != old_mtime.tv_usec) && - (XED_DOCUMENT_SAVER (gvsaver)->flags & XED_DOCUMENT_SAVE_IGNORE_MTIME) == 0) - { - xed_debug_message (DEBUG_SAVER, "File is externally modified"); - g_set_error (&gvsaver->priv->error, - XED_DOCUMENT_ERROR, - XED_DOCUMENT_ERROR_EXTERNALLY_MODIFIED, - "Externally modified"); - - remote_save_completed_or_failed (gvsaver, async); - g_object_unref (info); - - return; - } - } - - if (info != NULL) - g_object_unref (info); - - /* modification check passed, start write */ - begin_write (async); -} - -static void -check_modified_async (AsyncData *async) -{ - xed_debug_message (DEBUG_SAVER, "Check externally modified"); - - g_file_query_info_async (async->saver->priv->gfile, - G_FILE_ATTRIBUTE_TIME_MODIFIED, - G_FILE_QUERY_INFO_NONE, - G_PRIORITY_HIGH, - async->cancellable, - (GAsyncReadyCallback) check_modification_callback, - async); -} - -static gboolean -save_remote_file_real (XedGioDocumentSaver *gvsaver) -{ - AsyncData *async; - - xed_debug_message (DEBUG_SAVER, "Starting gio save"); - - /* First find out if the file is modified externally. This requires - * a stat, but I don't think we can do this any other way - */ - async = async_data_new (gvsaver); - - check_modified_async (async); - - /* return false to stop timeout */ - return FALSE; -} - -static void -xed_gio_document_saver_save (XedDocumentSaver *saver, - GTimeVal *old_mtime) -{ - XedGioDocumentSaver *gvsaver = XED_GIO_DOCUMENT_SAVER (saver); - - gvsaver->priv->old_mtime = *old_mtime; - gvsaver->priv->gfile = g_file_new_for_uri (saver->uri); - - /* saving start */ - xed_document_saver_saving (saver, FALSE, NULL); - - g_timeout_add_full (G_PRIORITY_HIGH, - 0, - (GSourceFunc) save_remote_file_real, - gvsaver, - NULL); -} - -static goffset -xed_gio_document_saver_get_file_size (XedDocumentSaver *saver) -{ - return XED_GIO_DOCUMENT_SAVER (saver)->priv->size; -} - -static goffset -xed_gio_document_saver_get_bytes_written (XedDocumentSaver *saver) -{ - return XED_GIO_DOCUMENT_SAVER (saver)->priv->bytes_written; -} diff --git a/xed/xed-gio-document-saver.h b/xed/xed-gio-document-saver.h deleted file mode 100644 index be18442..0000000 --- a/xed/xed-gio-document-saver.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * xed-gio-document-saver.h - * This file is part of xed - * - * Copyright (C) 2005 - Paolo Maggi - * Copyrhing (C) 2007 - Paolo Maggi, Steve Frécinaux - * Copyright (C) 2008 - Jesse van den Kieboom - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2005-2007. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - */ - -#ifndef __XED_GIO_DOCUMENT_SAVER_H__ -#define __XED_GIO_DOCUMENT_SAVER_H__ - -#include - -G_BEGIN_DECLS - -/* - * Type checking and casting macros - */ -#define XED_TYPE_GIO_DOCUMENT_SAVER (xed_gio_document_saver_get_type()) -#define XED_GIO_DOCUMENT_SAVER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_GIO_DOCUMENT_SAVER, XedGioDocumentSaver)) -#define XED_GIO_DOCUMENT_SAVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_GIO_DOCUMENT_SAVER, XedGioDocumentSaverClass)) -#define XED_IS_GIO_DOCUMENT_SAVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_GIO_DOCUMENT_SAVER)) -#define XED_IS_GIO_DOCUMENT_SAVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_GIO_DOCUMENT_SAVER)) -#define XED_GIO_DOCUMENT_SAVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_GIO_DOCUMENT_SAVER, XedGioDocumentSaverClass)) - -/* Private structure type */ -typedef struct _XedGioDocumentSaverPrivate XedGioDocumentSaverPrivate; - -/* - * Main object structure - */ -typedef struct _XedGioDocumentSaver XedGioDocumentSaver; - -struct _XedGioDocumentSaver -{ - XedDocumentSaver saver; - - /*< private > */ - XedGioDocumentSaverPrivate *priv; -}; - -/* - * Class definition - */ -typedef XedDocumentSaverClass XedGioDocumentSaverClass; - -/* - * Public methods - */ -GType xed_gio_document_saver_get_type (void) G_GNUC_CONST; - -G_END_DECLS - -#endif /* __XED_GIO_DOCUMENT_SAVER_H__ */ diff --git a/xed/xed-io-error-message-area.c b/xed/xed-io-error-message-area.c index 876f6d2..c4a2fae 100644 --- a/xed/xed-io-error-message-area.c +++ b/xed/xed-io-error-message-area.c @@ -180,7 +180,7 @@ static gboolean parse_gio_error (gint code, gchar **error_message, gchar **message_details, - const gchar *uri, + GFile *location, const gchar *uri_for_display) { gboolean ret = TRUE; @@ -198,7 +198,7 @@ parse_gio_error (gint code, gchar *scheme_string; gchar *scheme_markup; - scheme_string = g_uri_parse_scheme (uri); + scheme_string = g_file_get_uri_scheme (location); if ((scheme_string != NULL) && g_utf8_validate (scheme_string, -1, NULL)) { @@ -240,8 +240,11 @@ parse_gio_error (gint code, */ { gchar *hn = NULL; + gchar *uri; - if (xed_utils_decode_uri (uri, NULL, NULL, &hn, NULL, NULL)) + uri = g_file_get_uri (location); + + if (uri && xed_utils_decode_uri (uri, NULL, NULL, &hn, NULL, NULL)) { if (hn != NULL) { @@ -264,6 +267,8 @@ parse_gio_error (gint code, } } + g_free (uri); + if (!*message_details) { /* use the same string as INVALID_HOST */ @@ -291,7 +296,7 @@ static gboolean parse_xed_error (gint code, gchar **error_message, gchar **message_details, - const gchar *uri, + GFile *location, const gchar *uri_for_display) { gboolean ret = TRUE; @@ -313,18 +318,18 @@ static void parse_error (const GError *error, gchar **error_message, gchar **message_details, - const gchar *uri, + GFile *location, const gchar *uri_for_display) { gboolean ret = FALSE; if (error->domain == G_IO_ERROR) { - ret = parse_gio_error (error->code, error_message, message_details, uri, uri_for_display); + ret = parse_gio_error (error->code, error_message, message_details, location, uri_for_display); } else if (error->domain == XED_DOCUMENT_ERROR) { - ret = parse_xed_error (error->code, error_message, message_details, uri, uri_for_display); + ret = parse_xed_error (error->code, error_message, message_details, location, uri_for_display); } if (!ret) @@ -335,7 +340,7 @@ parse_error (const GError *error, } GtkWidget * -xed_unrecoverable_reverting_error_message_area_new (const gchar *uri, +xed_unrecoverable_reverting_error_message_area_new (GFile *location, const GError *error) { gchar *error_message = NULL; @@ -345,11 +350,11 @@ xed_unrecoverable_reverting_error_message_area_new (const gchar *uri, gchar *temp_uri_for_display; GtkWidget *message_area; - g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (G_IS_FILE (location), NULL); g_return_val_if_fail (error != NULL, NULL); g_return_val_if_fail ((error->domain == XED_DOCUMENT_ERROR) || (error->domain == G_IO_ERROR), NULL); - full_formatted_uri = xed_utils_uri_for_display (uri); + full_formatted_uri = xed_utils_uri_for_display (location); /* Truncate the URI so it doesn't get insanely wide. Note that even * though the dialog uses wrapped text, if the URI doesn't contain @@ -368,7 +373,7 @@ xed_unrecoverable_reverting_error_message_area_new (const gchar *uri, } else { - parse_error (error, &error_message, &message_details, uri, uri_for_display); + parse_error (error, &error_message, &message_details, location, uri_for_display); } if (error_message == NULL) @@ -491,7 +496,7 @@ create_conversion_error_message_area (const gchar *primary_text, } GtkWidget * -xed_io_loading_error_message_area_new (const gchar *uri, +xed_io_loading_error_message_area_new (GFile *location, const XedEncoding *encoding, const GError *error) { @@ -505,13 +510,13 @@ xed_io_loading_error_message_area_new (const gchar *uri, gboolean edit_anyway = FALSE; gboolean convert_error = FALSE; - g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (G_IS_FILE (location), NULL); g_return_val_if_fail (error != NULL, NULL); g_return_val_if_fail ((error->domain == G_CONVERT_ERROR) || (error->domain == XED_DOCUMENT_ERROR) || (error->domain == G_IO_ERROR), NULL); - full_formatted_uri = xed_utils_uri_for_display (uri); + full_formatted_uri = xed_utils_uri_for_display (location); /* Truncate the URI so it doesn't get insanely wide. Note that even * though the dialog uses wrapped text, if the URI doesn't contain @@ -572,7 +577,7 @@ xed_io_loading_error_message_area_new (const gchar *uri, } else { - parse_error (error, &error_message, &message_details, uri, uri_for_display); + parse_error (error, &error_message, &message_details, location, uri_for_display); } if (error_message == NULL) @@ -600,7 +605,7 @@ xed_io_loading_error_message_area_new (const gchar *uri, } GtkWidget * -xed_conversion_error_while_saving_message_area_new (const gchar *uri, +xed_conversion_error_while_saving_message_area_new (GFile *location, const XedEncoding *encoding, const GError *error) { @@ -612,13 +617,13 @@ xed_conversion_error_while_saving_message_area_new (const gchar *uri, gchar *temp_uri_for_display; GtkWidget *message_area; - g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (G_IS_FILE (location), NULL); g_return_val_if_fail (error != NULL, NULL); g_return_val_if_fail (error->domain == G_CONVERT_ERROR || error->domain == G_IO_ERROR, NULL); g_return_val_if_fail (encoding != NULL, NULL); - full_formatted_uri = xed_utils_uri_for_display (uri); + full_formatted_uri = xed_utils_uri_for_display (location); /* Truncate the URI so it doesn't get insanely wide. Note that even * though the dialog uses wrapped text, if the URI doesn't contain @@ -663,7 +668,7 @@ xed_conversion_error_message_area_get_encoding (GtkWidget *message_area) } GtkWidget * -xed_file_already_open_warning_message_area_new (const gchar *uri) +xed_file_already_open_warning_message_area_new (GFile *location) { GtkWidget *message_area; GtkWidget *hbox_content; @@ -679,7 +684,9 @@ xed_file_already_open_warning_message_area_new (const gchar *uri) gchar *uri_for_display; gchar *temp_uri_for_display; - full_formatted_uri = xed_utils_uri_for_display (uri); + g_return_val_if_fail (G_IS_FILE (location), NULL); + + full_formatted_uri = xed_utils_uri_for_display (location); /* Truncate the URI so it doesn't get insanely wide. Note that even * though the dialog uses wrapped text, if the URI doesn't contain @@ -747,7 +754,7 @@ xed_file_already_open_warning_message_area_new (const gchar *uri) } GtkWidget * -xed_externally_modified_saving_error_message_area_new (const gchar *uri, +xed_externally_modified_saving_error_message_area_new (GFile *location, const GError *error) { GtkWidget *message_area; @@ -764,12 +771,12 @@ xed_externally_modified_saving_error_message_area_new (const gchar *uri, gchar *uri_for_display; gchar *temp_uri_for_display; - g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (G_IS_FILE (location), NULL); g_return_val_if_fail (error != NULL, NULL); g_return_val_if_fail (error->domain == XED_DOCUMENT_ERROR, NULL); g_return_val_if_fail (error->code == XED_DOCUMENT_ERROR_EXTERNALLY_MODIFIED, NULL); - full_formatted_uri = xed_utils_uri_for_display (uri); + full_formatted_uri = xed_utils_uri_for_display (location); /* Truncate the URI so it doesn't get insanely wide. Note that even * though the dialog uses wrapped text, if the URI doesn't contain @@ -833,7 +840,7 @@ xed_externally_modified_saving_error_message_area_new (const gchar *uri, } GtkWidget * -xed_no_backup_saving_error_message_area_new (const gchar *uri, +xed_no_backup_saving_error_message_area_new (GFile *location, const GError *error) { GtkWidget *message_area; @@ -850,14 +857,14 @@ xed_no_backup_saving_error_message_area_new (const gchar *uri, gchar *uri_for_display; gchar *temp_uri_for_display; - g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (G_IS_FILE (location), NULL); g_return_val_if_fail (error != NULL, NULL); g_return_val_if_fail (((error->domain == XED_DOCUMENT_ERROR && error->code == XED_DOCUMENT_ERROR_CANT_CREATE_BACKUP) || (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANT_CREATE_BACKUP)), NULL); - full_formatted_uri = xed_utils_uri_for_display (uri); + full_formatted_uri = xed_utils_uri_for_display (location); /* Truncate the URI so it doesn't get insanely wide. Note that even * though the dialog uses wrapped text, if the URI doesn't contain @@ -930,7 +937,7 @@ xed_no_backup_saving_error_message_area_new (const gchar *uri, } GtkWidget * -xed_unrecoverable_saving_error_message_area_new (const gchar *uri, +xed_unrecoverable_saving_error_message_area_new (GFile *location, const GError *error) { gchar *error_message = NULL; @@ -942,11 +949,11 @@ xed_unrecoverable_saving_error_message_area_new (const gchar *uri, gchar *temp_uri_for_display; GtkWidget *message_area; - g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (G_IS_FILE (location), NULL); g_return_val_if_fail (error != NULL, NULL); g_return_val_if_fail ((error->domain == XED_DOCUMENT_ERROR) || (error->domain == G_IO_ERROR), NULL); - full_formatted_uri = xed_utils_uri_for_display (uri); + full_formatted_uri = xed_utils_uri_for_display (location); /* Truncate the URI so it doesn't get insanely wide. Note that even * though the dialog uses wrapped text, if the URI doesn't contain @@ -960,7 +967,7 @@ xed_unrecoverable_saving_error_message_area_new (const gchar *uri, if (is_gio_error (error, G_IO_ERROR_NOT_SUPPORTED)) { - scheme_string = g_uri_parse_scheme (uri); + scheme_string = g_file_get_uri_scheme (location); if ((scheme_string != NULL) && g_utf8_validate (scheme_string, -1, NULL)) { @@ -1025,7 +1032,7 @@ xed_unrecoverable_saving_error_message_area_new (const gchar *uri, } else { - parse_error (error, &error_message, &message_details, uri, uri_for_display); + parse_error (error, &error_message, &message_details, location, uri_for_display); } if (error_message == NULL) @@ -1043,8 +1050,8 @@ xed_unrecoverable_saving_error_message_area_new (const gchar *uri, } GtkWidget * -xed_externally_modified_message_area_new (const gchar *uri, - gboolean document_modified) +xed_externally_modified_message_area_new (GFile *location, + gboolean document_modified) { gchar *full_formatted_uri; gchar *uri_for_display; @@ -1053,9 +1060,9 @@ xed_externally_modified_message_area_new (const gchar *uri, const gchar *secondary_text; GtkWidget *message_area; - g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (G_IS_FILE (location), NULL); - full_formatted_uri = xed_utils_uri_for_display (uri); + full_formatted_uri = xed_utils_uri_for_display (location); /* Truncate the URI so it doesn't get insanely wide. Note that even * though the dialog uses wrapped text, if the URI doesn't contain diff --git a/xed/xed-io-error-message-area.h b/xed/xed-io-error-message-area.h index 607bc8c..a3c99dc 100644 --- a/xed/xed-io-error-message-area.h +++ b/xed/xed-io-error-message-area.h @@ -2,7 +2,7 @@ * xed-io-error-message-area.h * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -35,32 +35,32 @@ G_BEGIN_DECLS -GtkWidget *xed_io_loading_error_message_area_new (const gchar *uri, +GtkWidget *xed_io_loading_error_message_area_new (GFile *location, const XedEncoding *encoding, const GError *error); -GtkWidget *xed_unrecoverable_reverting_error_message_area_new (const gchar *uri, +GtkWidget *xed_unrecoverable_reverting_error_message_area_new (GFile *location, const GError *error); -GtkWidget *xed_conversion_error_while_saving_message_area_new (const gchar *uri, +GtkWidget *xed_conversion_error_while_saving_message_area_new (GFile *location, const XedEncoding *encoding, const GError *error); -const XedEncoding +const XedEncoding *xed_conversion_error_message_area_get_encoding (GtkWidget *message_area); -GtkWidget *xed_file_already_open_warning_message_area_new (const gchar *uri); +GtkWidget *xed_file_already_open_warning_message_area_new (GFile *location); -GtkWidget *xed_externally_modified_saving_error_message_area_new (const gchar *uri, +GtkWidget *xed_externally_modified_saving_error_message_area_new (GFile *location, const GError *error); -GtkWidget *xed_no_backup_saving_error_message_area_new (const gchar *uri, +GtkWidget *xed_no_backup_saving_error_message_area_new (GFile *location, const GError *error); -GtkWidget *xed_unrecoverable_saving_error_message_area_new (const gchar *uri, +GtkWidget *xed_unrecoverable_saving_error_message_area_new (GFile *location, const GError *error); -GtkWidget *xed_externally_modified_message_area_new (const gchar *uri, +GtkWidget *xed_externally_modified_message_area_new (GFile *location, gboolean document_modified); G_END_DECLS diff --git a/xed/xed-marshal.list b/xed/xed-marshal.list index d288294..03d7c9e 100644 --- a/xed/xed-marshal.list +++ b/xed/xed-marshal.list @@ -5,8 +5,8 @@ VOID:BOOLEAN,POINTER VOID:BOXED,BOXED VOID:OBJECT VOID:POINTER -VOID:STRING,BOXED,FLAGS -VOID:STRING,BOXED,INT,BOOLEAN +VOID:OBJECT,BOXED,FLAGS +VOID:OBJECT,BOXED,INT,BOOLEAN VOID:UINT,POINTER VOID:UINT64,UINT64 VOID:VOID diff --git a/xed/xed-metadata-manager.c b/xed/xed-metadata-manager.c index a656d70..16192e0 100644 --- a/xed/xed-metadata-manager.c +++ b/xed/xed-metadata-manager.c @@ -3,7 +3,7 @@ * xed-metadata-manager.c * This file is part of xed * - * Copyright (C) 2003-2007 Paolo Maggi + * Copyright (C) 2003-2007 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,14 +17,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2003-2007. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2003-2007. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. */ #ifdef HAVE_CONFIG_H @@ -56,10 +56,10 @@ struct _Item GHashTable *values; }; - + struct _XedMetadataManager { - gboolean values_loaded; /* It is true if the file + gboolean values_loaded; /* It is true if the file has been read */ guint timeout_id; @@ -76,7 +76,7 @@ static void item_free (gpointer data) { Item *item; - + g_return_if_fail (data != NULL); #ifdef XED_METADATA_VERBOSE_DEBUG @@ -96,7 +96,7 @@ xed_metadata_manager_arm_timeout (void) { if (xed_metadata_manager->timeout_id == 0) { - xed_metadata_manager->timeout_id = + xed_metadata_manager->timeout_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT_IDLE, 2, (GSourceFunc)xed_metadata_manager_save, @@ -117,9 +117,9 @@ xed_metadata_manager_init (void) xed_metadata_manager->values_loaded = FALSE; - xed_metadata_manager->items = - g_hash_table_new_full (g_str_hash, - g_str_equal, + xed_metadata_manager->items = + g_hash_table_new_full (g_str_hash, + g_str_equal, g_free, item_free); @@ -153,13 +153,13 @@ static void parseItem (xmlDocPtr doc, xmlNodePtr cur) { Item *item; - + xmlChar *uri; xmlChar *atime; - + #ifdef XED_METADATA_VERBOSE_DEBUG xed_debug (DEBUG_METADATA); -#endif +#endif if (xmlStrcmp (cur->name, (const xmlChar *)"document") != 0) return; @@ -167,7 +167,7 @@ parseItem (xmlDocPtr doc, xmlNodePtr cur) uri = xmlGetProp (cur, (const xmlChar *)"uri"); if (uri == NULL) return; - + atime = xmlGetProp (cur, (const xmlChar *)"atime"); if (atime == NULL) { @@ -179,9 +179,9 @@ parseItem (xmlDocPtr doc, xmlNodePtr cur) item->atime = g_ascii_strtoull ((char *)atime, NULL, 0); - item->values = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, + item->values = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, g_free); cur = cur->xmlChildrenNode; @@ -198,7 +198,7 @@ parseItem (xmlDocPtr doc, xmlNodePtr cur) if ((key != NULL) && (value != NULL)) g_hash_table_insert (item->values, - g_strdup ((gchar *)key), + g_strdup ((gchar *)key), g_strdup ((gchar *)value)); if (key != NULL) @@ -248,7 +248,7 @@ load_values (void) g_return_val_if_fail (xed_metadata_manager->values_loaded == FALSE, FALSE); xed_metadata_manager->values_loaded = TRUE; - + xmlKeepBlanksDefault (0); /* FIXME: file locking - Paolo */ @@ -269,25 +269,25 @@ load_values (void) } cur = xmlDocGetRootElement (doc); - if (cur == NULL) + if (cur == NULL) { g_message ("The metadata file '%s' is empty", METADATA_FILE); xmlFreeDoc (doc); - + return FALSE; } - if (xmlStrcmp (cur->name, (const xmlChar *) "metadata")) + if (xmlStrcmp (cur->name, (const xmlChar *) "metadata")) { g_message ("File '%s' is of the wrong type", METADATA_FILE); xmlFreeDoc (doc); - + return FALSE; } cur = xmlDocGetRootElement (doc); cur = cur->xmlChildrenNode; - + while (cur != NULL) { parseItem (doc, cur); @@ -301,15 +301,18 @@ load_values (void) } gchar * -xed_metadata_manager_get (const gchar *uri, +xed_metadata_manager_get (GFile *location, const gchar *key) { Item *item; gchar *value; + gchar *uri; - g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (G_IS_FILE (location), NULL); g_return_val_if_fail (key != NULL, NULL); + uri = g_file_get_uri (location); + xed_debug_message (DEBUG_METADATA, "URI: %s --- key: %s", uri, key ); xed_metadata_manager_init (); @@ -327,11 +330,13 @@ xed_metadata_manager_get (const gchar *uri, item = (Item *)g_hash_table_lookup (xed_metadata_manager->items, uri); + g_free (uri); + if (item == NULL) return NULL; item->atime = time (NULL); - + if (item->values == NULL) return NULL; @@ -344,17 +349,20 @@ xed_metadata_manager_get (const gchar *uri, } void -xed_metadata_manager_set (const gchar *uri, +xed_metadata_manager_set (GFile *location, const gchar *key, const gchar *value) { Item *item; + gchar *uri; - g_return_if_fail (uri != NULL); + g_return_if_fail (G_IS_FILE (location)); g_return_if_fail (key != NULL); + uri = g_file_get_uri (location); + xed_debug_message (DEBUG_METADATA, "URI: %s --- key: %s --- value: %s", uri, key, value); - + xed_metadata_manager_init (); if (!xed_metadata_manager->values_loaded) @@ -378,11 +386,11 @@ xed_metadata_manager_set (const gchar *uri, g_strdup (uri), item); } - + if (item->values == NULL) - item->values = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, + item->values = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, g_free); if (value != NULL) g_hash_table_insert (item->values, @@ -394,6 +402,8 @@ xed_metadata_manager_set (const gchar *uri, item->atime = time (NULL); + g_free (uri); + xed_metadata_manager_arm_timeout (); } @@ -404,13 +414,13 @@ save_values (const gchar *key, const gchar *value, xmlNodePtr parent) #ifdef XED_METADATA_VERBOSE_DEBUG xed_debug (DEBUG_METADATA); -#endif +#endif g_return_if_fail (key != NULL); - + if (value == NULL) return; - + xml_node = xmlNewChild (parent, NULL, (const xmlChar *)"entry", @@ -425,7 +435,7 @@ save_values (const gchar *key, const gchar *value, xmlNodePtr parent) #ifdef XED_METADATA_VERBOSE_DEBUG xed_debug_message (DEBUG_METADATA, "entry: %s = %s", key, value); -#endif +#endif } static void @@ -450,14 +460,14 @@ save_item (const gchar *key, const gpointer *data, xmlNodePtr parent) #ifdef XED_METADATA_VERBOSE_DEBUG xed_debug_message (DEBUG_METADATA, "uri: %s", key); -#endif +#endif atime = g_strdup_printf ("%ld", item->atime); - xmlSetProp (xml_node, (const xmlChar *)"atime", (const xmlChar *)atime); + xmlSetProp (xml_node, (const xmlChar *)"atime", (const xmlChar *)atime); #ifdef XED_METADATA_VERBOSE_DEBUG xed_debug_message (DEBUG_METADATA, "atime: %s", atime); -#endif +#endif g_free (atime); @@ -477,7 +487,7 @@ get_oldest (const gchar *key, const gpointer value, const gchar ** key_to_remove } else { - const Item *item_to_remove = + const Item *item_to_remove = g_hash_table_lookup (xed_metadata_manager->items, *key_to_remove); @@ -487,7 +497,7 @@ get_oldest (const gchar *key, const gpointer value, const gchar ** key_to_remove { *key_to_remove = key; } - } + } } static void @@ -502,7 +512,7 @@ resize_items (void) &key_to_remove); g_return_if_fail (key_to_remove != NULL); - + g_hash_table_remove (xed_metadata_manager->items, key_to_remove); } @@ -510,7 +520,7 @@ resize_items (void) static gboolean xed_metadata_manager_save (gpointer data) -{ +{ xmlDocPtr doc; xmlNodePtr root; gchar *file_name; @@ -520,7 +530,7 @@ xed_metadata_manager_save (gpointer data) xed_metadata_manager->timeout_id = 0; resize_items (); - + xmlIndentTreeOutput = TRUE; doc = xmlNewDoc ((const xmlChar *)"1.0"); @@ -533,7 +543,7 @@ xed_metadata_manager_save (gpointer data) g_hash_table_foreach (xed_metadata_manager->items, (GHFunc)save_item, - root); + root); /* FIXME: lock file - Paolo */ file_name = get_metadata_filename (); @@ -554,7 +564,7 @@ xed_metadata_manager_save (gpointer data) g_free (file_name); } - xmlFreeDoc (doc); + xmlFreeDoc (doc); xed_debug_message (DEBUG_METADATA, "DONE"); diff --git a/xed/xed-metadata-manager.h b/xed/xed-metadata-manager.h index 5f26bbe..eef8f1f 100644 --- a/xed/xed-metadata-manager.h +++ b/xed/xed-metadata-manager.h @@ -3,7 +3,7 @@ * xed-metadata-manager.h * This file is part of xed * - * Copyright (C) 2003 Paolo Maggi + * Copyright (C) 2003 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,14 +17,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2003. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2003. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. */ #ifndef __XED_METADATA_MANAGER_H__ @@ -39,9 +39,9 @@ G_BEGIN_DECLS void xed_metadata_manager_shutdown (void); -gchar *xed_metadata_manager_get (const gchar *uri, +gchar *xed_metadata_manager_get (GFile *location, const gchar *key); -void xed_metadata_manager_set (const gchar *uri, +void xed_metadata_manager_set (GFile *location, const gchar *key, const gchar *value); diff --git a/xed/xed-session.c b/xed/xed-session.c index a61ebe7..6067974 100644 --- a/xed/xed-session.c +++ b/xed/xed-session.c @@ -3,7 +3,7 @@ * This file is part of xed * * Copyright (C) 2002 Ximian, Inc. - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * Author: Federico Mena-Quintero * @@ -19,13 +19,13 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ /* - * Modified by the xed Team, 2002-2005. See the AUTHORS file for a - * list of people on the xed Team. + * Modified by the xed Team, 2002-2005. See the AUTHORS file for a + * list of people on the xed Team. * See the ChangeLog files for a list of changes. * * $Id$ @@ -75,7 +75,7 @@ save_window_session (GKeyFile *state_file, GList *docs, *l; GPtrArray *doc_array; XedDocument *active_document; - gchar *uri; + gchar *uri = NULL; xed_debug (DEBUG_SESSION); @@ -96,9 +96,17 @@ save_window_session (GKeyFile *state_file, active_document = xed_window_get_active_document (window); if (active_document) { - uri = xed_document_get_uri (active_document); - g_key_file_set_string (state_file, group_name, - "active-document", uri); + GFile *location; + + location = xed_document_get_location (active_document); + if (location) + { + uri = g_file_get_uri (location); + g_object_unref (location); + } + + g_key_file_set_string (state_file, group_name, "active-document", uri); + g_free (uri); } docs = xed_window_get_documents (window); @@ -106,24 +114,30 @@ save_window_session (GKeyFile *state_file, doc_array = g_ptr_array_new (); for (l = docs; l != NULL; l = g_list_next (l)) { - uri = xed_document_get_uri (XED_DOCUMENT (l->data)); + GFile *location; + + location = xed_document_get_location (XED_DOCUMENT (l->data)); + if (location) + { + uri = g_file_get_uri (location); + g_object_unref (location); + } if (uri != NULL) + { g_ptr_array_add (doc_array, uri); - + } + } - g_list_free (docs); + g_list_free (docs); if (doc_array->len) { - guint i; - g_key_file_set_string_list (state_file, group_name, "documents", (const char **)doc_array->pdata, doc_array->len); - for (i = 0; i < doc_array->len; i++) - g_free (doc_array->pdata[i]); + g_ptr_array_foreach (doc_array, (GFunc) g_free, NULL); } g_ptr_array_free (doc_array, TRUE); } @@ -147,7 +161,7 @@ client_save_state_cb (EggSMClient *client, group_name, XED_WINDOW (windows->data)); g_free (group_name); - + windows = g_list_next (windows); n++; } @@ -376,9 +390,9 @@ client_quit_cb (EggSMClient *client, gpointer data) xed_file_close_all (); xed_debug_message (DEBUG_FILE, "All files closed."); - + matecomponent_mdi_destroy (MATECOMPONENT_MDI (xed_mdi)); - + xed_debug_message (DEBUG_FILE, "Unref xed_mdi."); g_object_unref (G_OBJECT (xed_mdi)); @@ -397,7 +411,7 @@ client_quit_cb (EggSMClient *client, gpointer data) /** * xed_session_init: - * + * * Initializes session management support. This function should be called near * the beginning of the program. **/ @@ -405,7 +419,7 @@ void xed_session_init (void) { xed_debug (DEBUG_SESSION); - + if (master_client) return; @@ -421,14 +435,14 @@ xed_session_init (void) g_signal_connect (master_client, "quit", G_CALLBACK (client_quit_cb), - NULL); + NULL); } /** * xed_session_is_restored: - * + * * Returns whether this xed is running from a restarted session. - * + * * Return value: TRUE if the session manager restarted us, FALSE otherwise. * This should be used to determine whether to pay attention to command line * arguments in case the session was not restored. @@ -459,7 +473,7 @@ parse_window (GKeyFile *state_file, const char *group_name) gboolean visible; XedPanel *panel; GError *error = NULL; - + role = g_key_file_get_string (state_file, group_name, "role", NULL); xed_debug_message (DEBUG_SESSION, "Window role: %s", role); @@ -488,8 +502,8 @@ parse_window (GKeyFile *state_file, const char *group_name) height = -1; } gtk_window_set_default_size (GTK_WINDOW (window), width, height); - - + + visible = g_key_file_get_boolean (state_file, group_name, "side-panel-visible", &error); if (error) @@ -497,9 +511,9 @@ parse_window (GKeyFile *state_file, const char *group_name) g_clear_error (&error); visible = FALSE; } - + panel = xed_window_get_side_panel (window); - + if (visible) { xed_debug_message (DEBUG_SESSION, "Side panel visible"); @@ -510,7 +524,7 @@ parse_window (GKeyFile *state_file, const char *group_name) xed_debug_message (DEBUG_SESSION, "Side panel _NOT_ visible"); gtk_widget_hide (GTK_WIDGET (panel)); } - + visible = g_key_file_get_boolean (state_file, group_name, "bottom-panel-visible", &error); if (error) @@ -518,7 +532,7 @@ parse_window (GKeyFile *state_file, const char *group_name) g_clear_error (&error); visible = FALSE; } - + panel = xed_window_get_bottom_panel (window); if (visible) { @@ -537,40 +551,44 @@ parse_window (GKeyFile *state_file, const char *group_name) "documents", NULL, NULL); if (documents) { - int i; + gint i; gboolean jump_to = FALSE; - + for (i = 0; documents[i]; i++) { + GFile *location; + if (active_document != NULL) - jump_to = strcmp (active_document, - documents[i]) == 0; - + { + jump_to = strcmp (active_document, documents[i]) == 0; + } + xed_debug_message (DEBUG_SESSION, "URI: %s (%s)", documents[i], jump_to ? "active" : "not active"); - xed_window_create_tab_from_uri (window, - documents[i], - NULL, - 0, - FALSE, - jump_to); + + location = g_file_new_for_uri (documents[i]); + xed_window_create_tab_from_location (window, location, NULL, 0, FALSE, jump_to); + if (location) + { + g_object_unref (location); + } } g_strfreev (documents); } - + g_free (active_document); - + gtk_widget_show (GTK_WIDGET (window)); } /** * xed_session_load: - * + * * Loads the session by fetching the necessary information from the session * manager and opening files. - * + * * Return value: TRUE if the session was loaded successfully, FALSE otherwise. **/ gboolean diff --git a/xed/xed-tab.c b/xed/xed-tab.c index f33754b..2fd7ebb 100644 --- a/xed/xed-tab.c +++ b/xed/xed-tab.c @@ -62,7 +62,7 @@ struct _XedTabPrivate XedPrintJob *print_job; /* tmp data for saving */ - gchar *tmp_save_uri; + GFile *tmp_save_location; /* tmp data for loading */ gint tmp_line_pos; @@ -212,6 +212,20 @@ xed_tab_set_property (GObject *object, } } +static void +xed_tab_dispose (GObject *object) +{ + XedTab *tab = XED_TAB (object); + + if (tab->priv->tmp_save_location != NULL) + { + g_object_unref (tab->priv->tmp_save_location); + tab->priv->tmp_save_location = NULL; + } + + G_OBJECT_CLASS (xed_tab_parent_class)->dispose (object); +} + static void xed_tab_finalize (GObject *object) { @@ -222,8 +236,6 @@ xed_tab_finalize (GObject *object) g_timer_destroy (tab->priv->timer); } - g_free (tab->priv->tmp_save_uri); - if (tab->priv->auto_save_timeout > 0) { remove_auto_save_timeout (tab); @@ -237,6 +249,7 @@ xed_tab_class_init (XedTabClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->dispose = xed_tab_dispose; object_class->finalize = xed_tab_finalize; object_class->get_property = xed_tab_get_property; object_class->set_property = xed_tab_set_property; @@ -407,13 +420,13 @@ xed_tab_set_state (XedTab *tab, } static void -document_uri_notify_handler (XedDocument *document, - GParamSpec *pspec, - XedTab *tab) +document_location_notify_handler (XedDocument *document, + GParamSpec *pspec, + XedTab *tab) { xed_debug (DEBUG_TAB); - /* Notify the change in the URI */ + /* Notify the change in the location */ g_object_notify (G_OBJECT (tab), "name"); } @@ -478,7 +491,7 @@ io_loading_error_message_area_response (GtkWidget *message_area, { XedDocument *doc; XedView *view; - gchar *uri; + GFile *location; const XedEncoding *encoding; doc = xed_tab_get_document (tab); @@ -487,8 +500,8 @@ io_loading_error_message_area_response (GtkWidget *message_area, view = xed_tab_get_view (tab); g_return_if_fail (XED_IS_VIEW (view)); - uri = xed_document_get_uri (doc); - g_return_if_fail (uri != NULL); + location = xed_document_get_location (doc); + g_return_if_fail (location != NULL); switch (response_id) { @@ -505,7 +518,7 @@ io_loading_error_message_area_response (GtkWidget *message_area, g_return_if_fail (tab->priv->auto_save_timeout <= 0); - xed_document_load (doc, uri, tab->priv->tmp_encoding, tab->priv->tmp_line_pos, FALSE); + xed_document_load (doc, location, tab->priv->tmp_encoding, tab->priv->tmp_line_pos, FALSE); break; case GTK_RESPONSE_YES: /* This means that we want to edit the document anyway */ @@ -517,13 +530,13 @@ io_loading_error_message_area_response (GtkWidget *message_area, set_message_area (tab, NULL); break; default: - _xed_recent_remove (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), uri); + _xed_recent_remove (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), location); remove_tab (tab); break; } - g_free (uri); + g_object_unref (location); } static void @@ -618,15 +631,15 @@ show_loading_message_area (XedTab *tab) } else { - GFile *file; + GFile *location; - file = xed_document_get_location (doc); - if (file != NULL) + location = xed_document_get_location (doc); + if (location != NULL) { gchar *str; - str = xed_utils_location_get_dirname_for_display (file); - g_object_unref (file); + str = xed_utils_location_get_dirname_for_display (location); + g_object_unref (location); /* use the remaining space for the dir, but use a min of 20 chars * so that we do not end up with a dirname like "(a...b)". @@ -704,7 +717,7 @@ show_saving_message_area (XedTab *tab) gchar *msg = NULL; gint len; - g_return_if_fail (tab->priv->tmp_save_uri != NULL); + g_return_if_fail (tab->priv->tmp_save_location != NULL); if (tab->priv->message_area != NULL) { @@ -734,7 +747,7 @@ show_saving_message_area (XedTab *tab) from = short_name; - to = xed_utils_uri_for_display (tab->priv->tmp_save_uri); + to = xed_utils_uri_for_display (tab->priv->tmp_save_location); str = xed_utils_str_middle_truncate (to, MAX (20, MAX_MSG_LENGTH - len)); g_free (to); @@ -848,7 +861,6 @@ document_loaded (XedDocument *document, { GtkWidget *emsg; GFile *location; - gchar *uri; const XedEncoding *encoding; g_return_if_fail ((tab->priv->state == XED_TAB_STATE_LOADING) || (tab->priv->state == XED_TAB_STATE_REVERTING)); @@ -864,7 +876,6 @@ document_loaded (XedDocument *document, set_message_area (tab, NULL); location = xed_document_get_location (document); - uri = xed_document_get_uri (document); /* if the error is CONVERSION FALLBACK don't treat it as a normal error */ if (error != NULL && (error->domain != XED_DOCUMENT_ERROR || error->code != XED_DOCUMENT_ERROR_CONVERSION_FALLBACK)) @@ -892,11 +903,11 @@ document_loaded (XedDocument *document, } else { - _xed_recent_remove (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), uri); + _xed_recent_remove (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), location); if (tab->priv->state == XED_TAB_STATE_LOADING_ERROR) { - emsg = xed_io_loading_error_message_area_new (uri, tab->priv->tmp_encoding, error); + emsg = xed_io_loading_error_message_area_new (location, tab->priv->tmp_encoding, error); g_signal_connect (emsg, "response", G_CALLBACK (io_loading_error_message_area_response), tab); } @@ -904,7 +915,7 @@ document_loaded (XedDocument *document, { g_return_if_fail (tab->priv->state == XED_TAB_STATE_REVERTING_ERROR); - emsg = xed_unrecoverable_reverting_error_message_area_new (uri, error); + emsg = xed_unrecoverable_reverting_error_message_area_new (location, error); g_signal_connect (emsg, "response", G_CALLBACK (unrecoverable_reverting_error_message_area_response), tab); @@ -918,7 +929,6 @@ document_loaded (XedDocument *document, gtk_widget_show (emsg); g_object_unref (location); - g_free (uri); return; } @@ -928,10 +938,10 @@ document_loaded (XedDocument *document, GList *all_documents; GList *l; - g_return_if_fail (uri != NULL); + g_return_if_fail (location != NULL); mime = xed_document_get_mime_type (document); - _xed_recent_add (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), uri, mime); + _xed_recent_add (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), location, mime); g_free (mime); if (error && error->domain == XED_DOCUMENT_ERROR && error->code == XED_DOCUMENT_ERROR_CONVERSION_FALLBACK) @@ -940,7 +950,7 @@ document_loaded (XedDocument *document, _xed_document_set_readonly (document, TRUE); - emsg = xed_io_loading_error_message_area_new (uri, tab->priv->tmp_encoding, error); + emsg = xed_io_loading_error_message_area_new (location, tab->priv->tmp_encoding, error); set_message_area (tab, emsg); @@ -976,7 +986,7 @@ document_loaded (XedDocument *document, tab->priv->not_editable = TRUE; - w = xed_file_already_open_warning_message_area_new (uri); + w = xed_file_already_open_warning_message_area_new (location); set_message_area (tab, w); @@ -1009,7 +1019,6 @@ document_loaded (XedDocument *document, end: g_object_unref (location); - g_free (uri); tab->priv->tmp_line_pos = 0; tab->priv->tmp_encoding = NULL; @@ -1054,8 +1063,11 @@ static void end_saving (XedTab *tab) { /* Reset tmp data for saving */ - g_free (tab->priv->tmp_save_uri); - tab->priv->tmp_save_uri = NULL; + if (tab->priv->tmp_save_location) + { + g_object_unref (tab->priv->tmp_save_location); + tab->priv->tmp_save_location = NULL; + } tab->priv->tmp_encoding = NULL; install_auto_save_timeout_if_needed (tab); @@ -1100,7 +1112,7 @@ no_backup_error_message_area_response (GtkWidget *message_area, set_message_area (tab, NULL); - g_return_if_fail (tab->priv->tmp_save_uri != NULL); + g_return_if_fail (tab->priv->tmp_save_location != NULL); g_return_if_fail (tab->priv->tmp_encoding != NULL); xed_tab_set_state (tab, XED_TAB_STATE_SAVING); @@ -1133,7 +1145,7 @@ externally_modified_error_message_area_response (GtkWidget *message_area, set_message_area (tab, NULL); - g_return_if_fail (tab->priv->tmp_save_uri != NULL); + g_return_if_fail (tab->priv->tmp_save_location != NULL); g_return_if_fail (tab->priv->tmp_encoding != NULL); xed_tab_set_state (tab, XED_TAB_STATE_SAVING); @@ -1164,6 +1176,7 @@ recoverable_saving_error_message_area_response (GtkWidget *message_area, if (response_id == GTK_RESPONSE_OK) { const XedEncoding *encoding; + gchar *tmp_uri; encoding = xed_conversion_error_message_area_get_encoding (GTK_WIDGET (message_area)); @@ -1171,17 +1184,19 @@ recoverable_saving_error_message_area_response (GtkWidget *message_area, set_message_area (tab, NULL); - g_return_if_fail (tab->priv->tmp_save_uri != NULL); + g_return_if_fail (tab->priv->tmp_save_location != NULL); xed_tab_set_state (tab, XED_TAB_STATE_SAVING); tab->priv->tmp_encoding = encoding; - xed_debug_message (DEBUG_TAB, "Force saving with URI '%s'", tab->priv->tmp_save_uri); + tmp_uri = g_file_get_uri (tab->priv->tmp_save_location); + xed_debug_message (DEBUG_TAB, "Force saving with URI '%s'", tmp_uri); + g_free (tmp_uri); g_return_if_fail (tab->priv->auto_save_timeout <= 0); - xed_document_save_as (doc, tab->priv->tmp_save_uri, tab->priv->tmp_encoding, tab->priv->save_flags); + xed_document_save_as (doc, tab->priv->tmp_save_location, tab->priv->tmp_encoding, tab->priv->save_flags); } else { @@ -1198,7 +1213,7 @@ document_saved (XedDocument *document, g_return_if_fail (tab->priv->state == XED_TAB_STATE_SAVING); - g_return_if_fail (tab->priv->tmp_save_uri != NULL); + g_return_if_fail (tab->priv->tmp_save_location != NULL); g_return_if_fail (tab->priv->tmp_encoding != NULL); g_return_if_fail (tab->priv->auto_save_timeout <= 0); @@ -1215,7 +1230,7 @@ document_saved (XedDocument *document, if (error->domain == XED_DOCUMENT_ERROR && error->code == XED_DOCUMENT_ERROR_EXTERNALLY_MODIFIED) { /* This error is recoverable */ - emsg = xed_externally_modified_saving_error_message_area_new (tab->priv->tmp_save_uri, error); + emsg = xed_externally_modified_saving_error_message_area_new (tab->priv->tmp_save_location, error); g_return_if_fail (emsg != NULL); set_message_area (tab, emsg); @@ -1229,7 +1244,7 @@ document_saved (XedDocument *document, error->code == G_IO_ERROR_CANT_CREATE_BACKUP)) { /* This error is recoverable */ - emsg = xed_no_backup_saving_error_message_area_new (tab->priv->tmp_save_uri, error); + emsg = xed_no_backup_saving_error_message_area_new (tab->priv->tmp_save_location, error); g_return_if_fail (emsg != NULL); set_message_area (tab, emsg); @@ -1243,9 +1258,9 @@ document_saved (XedDocument *document, error->code != G_IO_ERROR_PARTIAL_INPUT)) { /* These errors are _NOT_ recoverable */ - _xed_recent_remove (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), tab->priv->tmp_save_uri); + _xed_recent_remove (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), tab->priv->tmp_save_location); - emsg = xed_unrecoverable_saving_error_message_area_new (tab->priv->tmp_save_uri, error); + emsg = xed_unrecoverable_saving_error_message_area_new (tab->priv->tmp_save_location, error); g_return_if_fail (emsg != NULL); set_message_area (tab, emsg); @@ -1258,7 +1273,7 @@ document_saved (XedDocument *document, /* This error is recoverable */ g_return_if_fail (error->domain == G_CONVERT_ERROR || error->domain == G_IO_ERROR); - emsg = xed_conversion_error_while_saving_message_area_new (tab->priv->tmp_save_uri, + emsg = xed_conversion_error_while_saving_message_area_new (tab->priv->tmp_save_location, tab->priv->tmp_encoding, error); @@ -1276,7 +1291,7 @@ document_saved (XedDocument *document, { gchar *mime = xed_document_get_mime_type (document); - _xed_recent_add (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), tab->priv->tmp_save_uri, mime); + _xed_recent_add (XED_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))), tab->priv->tmp_save_location, mime); g_free (mime); if (tab->priv->print_preview != NULL) @@ -1324,20 +1339,19 @@ display_externally_modified_notification (XedTab *tab) { GtkWidget *message_area; XedDocument *doc; - gchar *uri; + GFile *location; gboolean document_modified; doc = xed_tab_get_document (tab); g_return_if_fail (XED_IS_DOCUMENT (doc)); - /* uri cannot be NULL, we're here because - * the file we're editing changed on disk */ - uri = xed_document_get_uri (doc); - g_return_if_fail (uri != NULL); + /* we're here because the file we're editing changed on disk */ + location = xed_document_get_location (doc); + g_return_if_fail (location != NULL); document_modified = gtk_text_buffer_get_modified (GTK_TEXT_BUFFER(doc)); - message_area = xed_externally_modified_message_area_new (uri, document_modified); - g_free (uri); + message_area = xed_externally_modified_message_area_new (location, document_modified); + g_object_unref (location); tab->priv->message_area = NULL; set_message_area (tab, message_area); @@ -1448,8 +1462,8 @@ xed_tab_init (XedTab *tab) gtk_container_add (GTK_CONTAINER (sw), tab->priv->view); gtk_widget_show (sw); - g_signal_connect (doc, "notify::uri", - G_CALLBACK (document_uri_notify_handler), tab); + g_signal_connect (doc, "notify::location", + G_CALLBACK (document_location_notify_handler), tab); g_signal_connect (doc, "notify::shortname", G_CALLBACK (document_shortname_notify_handler), tab); g_signal_connect (doc, "modified_changed", @@ -1478,18 +1492,18 @@ _xed_tab_new (void) /* Whether create is TRUE, creates a new empty document if location does not refer to an existing file */ GtkWidget * -_xed_tab_new_from_uri (const gchar *uri, - const XedEncoding *encoding, - gint line_pos, - gboolean create) +_xed_tab_new_from_location (GFile *location, + const XedEncoding *encoding, + gint line_pos, + gboolean create) { XedTab *tab; - g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (G_IS_FILE (location), NULL); tab = XED_TAB (_xed_tab_new ()); - _xed_tab_load (tab, uri, encoding, line_pos, create); + _xed_tab_load (tab, location, encoding, line_pos, create); return GTK_WIDGET (tab); } @@ -1805,7 +1819,7 @@ xed_tab_get_from_document (XedDocument *doc) void _xed_tab_load (XedTab *tab, - const gchar *uri, + GFile *location, const XedEncoding *encoding, gint line_pos, gboolean create) @@ -1813,6 +1827,7 @@ _xed_tab_load (XedTab *tab, XedDocument *doc; g_return_if_fail (XED_IS_TAB (tab)); + g_return_if_fail (G_IS_FILE (location)); g_return_if_fail (tab->priv->state == XED_TAB_STATE_NORMAL); doc = xed_tab_get_document (tab); @@ -1828,14 +1843,14 @@ _xed_tab_load (XedTab *tab, remove_auto_save_timeout (tab); } - xed_document_load (doc, uri, encoding, line_pos, create); + xed_document_load (doc, location, encoding, line_pos, create); } void _xed_tab_revert (XedTab *tab) { XedDocument *doc; - gchar *uri; + GFile *location; g_return_if_fail (XED_IS_TAB (tab)); g_return_if_fail ((tab->priv->state == XED_TAB_STATE_NORMAL) || @@ -1851,8 +1866,8 @@ _xed_tab_revert (XedTab *tab) xed_tab_set_state (tab, XED_TAB_STATE_REVERTING); - uri = xed_document_get_uri (doc); - g_return_if_fail (uri != NULL); + location = xed_document_get_location (doc); + g_return_if_fail (location != NULL); tab->priv->tmp_line_pos = 0; tab->priv->tmp_encoding = xed_document_get_encoding (doc); @@ -1862,9 +1877,9 @@ _xed_tab_revert (XedTab *tab) remove_auto_save_timeout (tab); } - xed_document_load (doc, uri, tab->priv->tmp_encoding, 0, FALSE); + xed_document_load (doc, location, tab->priv->tmp_encoding, 0, FALSE); - g_free (uri); + g_object_unref (location); } void @@ -1877,7 +1892,7 @@ _xed_tab_save (XedTab *tab) g_return_if_fail ((tab->priv->state == XED_TAB_STATE_NORMAL) || (tab->priv->state == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) || (tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW)); - g_return_if_fail (tab->priv->tmp_save_uri == NULL); + g_return_if_fail (tab->priv->tmp_save_location == NULL); g_return_if_fail (tab->priv->tmp_encoding == NULL); doc = xed_tab_get_document (tab); @@ -1902,7 +1917,7 @@ _xed_tab_save (XedTab *tab) xed_tab_set_state (tab, XED_TAB_STATE_SAVING); /* uri used in error messages, will be freed in document_saved */ - tab->priv->tmp_save_uri = xed_document_get_uri (doc); + tab->priv->tmp_save_location = xed_document_get_location (doc); tab->priv->tmp_encoding = xed_document_get_encoding (doc); if (tab->priv->auto_save_timeout > 0) @@ -1920,7 +1935,7 @@ xed_tab_auto_save (XedTab *tab) xed_debug (DEBUG_TAB); - g_return_val_if_fail (tab->priv->tmp_save_uri == NULL, FALSE); + g_return_val_if_fail (tab->priv->tmp_save_location == NULL, FALSE); g_return_val_if_fail (tab->priv->tmp_encoding == NULL, FALSE); doc = xed_tab_get_document (tab); @@ -1958,7 +1973,7 @@ xed_tab_auto_save (XedTab *tab) xed_tab_set_state (tab, XED_TAB_STATE_SAVING); /* uri used in error messages, will be freed in document_saved */ - tab->priv->tmp_save_uri = xed_document_get_uri (doc); + tab->priv->tmp_save_location = xed_document_get_location (doc); tab->priv->tmp_encoding = xed_document_get_encoding (doc); /* Set auto_save_timeout to 0 since the timeout is going to be destroyed */ @@ -1978,7 +1993,7 @@ xed_tab_auto_save (XedTab *tab) void _xed_tab_save_as (XedTab *tab, - const gchar *uri, + GFile *location, const XedEncoding *encoding, XedDocumentNewlineType newline_type) { @@ -1989,9 +2004,10 @@ _xed_tab_save_as (XedTab *tab, g_return_if_fail ((tab->priv->state == XED_TAB_STATE_NORMAL) || (tab->priv->state == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) || (tab->priv->state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW)); + g_return_if_fail (G_IS_FILE (location)); g_return_if_fail (encoding != NULL); - g_return_if_fail (tab->priv->tmp_save_uri == NULL); + g_return_if_fail (tab->priv->tmp_save_location == NULL); g_return_if_fail (tab->priv->tmp_encoding == NULL); doc = xed_tab_get_document (tab); @@ -2019,7 +2035,7 @@ _xed_tab_save_as (XedTab *tab, /* uri used in error messages... strdup because errors are async * and the string can go away, will be freed in document_saved */ - tab->priv->tmp_save_uri = g_strdup (uri); + tab->priv->tmp_save_location = g_file_dup (location); tab->priv->tmp_encoding = encoding; if (tab->priv->auto_save_timeout > 0) @@ -2032,7 +2048,7 @@ _xed_tab_save_as (XedTab *tab, a very big deal, but would be nice to have them follow the same pattern. This can be changed once we break API for 3.0 */ xed_document_set_newline_type (doc, newline_type); - xed_document_save_as (doc, uri, encoding, tab->priv->save_flags); + xed_document_save_as (doc, location, encoding, tab->priv->save_flags); } #define XED_PAGE_SETUP_KEY "xed-page-setup-key" diff --git a/xed/xed-tab.h b/xed/xed-tab.h index cce9ec6..80f2972 100644 --- a/xed/xed-tab.h +++ b/xed/xed-tab.h @@ -2,7 +2,7 @@ * xed-tab.h * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -40,26 +40,23 @@ G_BEGIN_DECLS typedef enum { - XED_TAB_STATE_NORMAL = 0, - XED_TAB_STATE_LOADING, - XED_TAB_STATE_REVERTING, - XED_TAB_STATE_SAVING, - XED_TAB_STATE_PRINTING, - XED_TAB_STATE_PRINT_PREVIEWING, - XED_TAB_STATE_SHOWING_PRINT_PREVIEW, - XED_TAB_STATE_GENERIC_NOT_EDITABLE, - XED_TAB_STATE_LOADING_ERROR, - XED_TAB_STATE_REVERTING_ERROR, - XED_TAB_STATE_SAVING_ERROR, - XED_TAB_STATE_GENERIC_ERROR, - XED_TAB_STATE_CLOSING, - XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION, - XED_TAB_NUM_OF_STATES /* This is not a valid state */ + XED_TAB_STATE_NORMAL = 0, + XED_TAB_STATE_LOADING, + XED_TAB_STATE_REVERTING, + XED_TAB_STATE_SAVING, + XED_TAB_STATE_PRINTING, + XED_TAB_STATE_PRINT_PREVIEWING, + XED_TAB_STATE_SHOWING_PRINT_PREVIEW, + XED_TAB_STATE_GENERIC_NOT_EDITABLE, + XED_TAB_STATE_LOADING_ERROR, + XED_TAB_STATE_REVERTING_ERROR, + XED_TAB_STATE_SAVING_ERROR, + XED_TAB_STATE_GENERIC_ERROR, + XED_TAB_STATE_CLOSING, + XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION, + XED_TAB_NUM_OF_STATES /* This is not a valid state */ } XedTabState; -/* - * Type checking and casting macros - */ #define XED_TYPE_TAB (xed_tab_get_type()) #define XED_TAB(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_TAB, XedTab)) #define XED_TAB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_TAB, XedTabClass)) @@ -67,95 +64,74 @@ typedef enum #define XED_IS_TAB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_TAB)) #define XED_TAB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_TAB, XedTabClass)) -/* Private structure type */ -typedef struct _XedTabPrivate XedTabPrivate; +typedef struct _XedTab XedTab; +typedef struct _XedTabPrivate XedTabPrivate; +typedef struct _XedTabClass XedTabClass; -/* - * Main object structure - */ -typedef struct _XedTab XedTab; - -struct _XedTab +struct _XedTab { - GtkBox vbox; + GtkBox vbox; - /*< private > */ - XedTabPrivate *priv; + /*< private > */ + XedTabPrivate *priv; }; -/* - * Class definition - */ -typedef struct _XedTabClass XedTabClass; - -struct _XedTabClass +struct _XedTabClass { - GtkBoxClass parent_class; + GtkBoxClass parent_class; }; -/* - * Public methods - */ -GType xed_tab_get_type (void) G_GNUC_CONST; +GType xed_tab_get_type (void) G_GNUC_CONST; -XedView *xed_tab_get_view (XedTab *tab); +XedView *xed_tab_get_view (XedTab *tab); /* This is only an helper function */ -XedDocument *xed_tab_get_document (XedTab *tab); +XedDocument *xed_tab_get_document (XedTab *tab); +XedTab *xed_tab_get_from_document (XedDocument *doc); -XedTab *xed_tab_get_from_document (XedDocument *doc); +XedTabState xed_tab_get_state (XedTab *tab); -XedTabState xed_tab_get_state (XedTab *tab); +gboolean xed_tab_get_auto_save_enabled (XedTab *tab); +void xed_tab_set_auto_save_enabled (XedTab *tab, + gboolean enable); -gboolean xed_tab_get_auto_save_enabled - (XedTab *tab); +gint xed_tab_get_auto_save_interval (XedTab *tab); +void xed_tab_set_auto_save_interval (XedTab *tab, + gint interval); -void xed_tab_set_auto_save_enabled - (XedTab *tab, - gboolean enable); - -gint xed_tab_get_auto_save_interval - (XedTab *tab); - -void xed_tab_set_auto_save_interval - (XedTab *tab, - gint interval); - -void xed_tab_set_info_bar (XedTab *tab, - GtkWidget *info_bar); +void xed_tab_set_info_bar (XedTab *tab, + GtkWidget *info_bar); /* * Non exported methods */ -GtkWidget *_xed_tab_new (void); +GtkWidget *_xed_tab_new (void); -/* Whether create is TRUE, creates a new empty document if location does +/* Whether create is TRUE, creates a new empty document if location does not refer to an existing file */ -GtkWidget *_xed_tab_new_from_uri (const gchar *uri, - const XedEncoding *encoding, - gint line_pos, - gboolean create); -gchar *_xed_tab_get_name (XedTab *tab); -gchar *_xed_tab_get_tooltips (XedTab *tab); -GdkPixbuf *_xed_tab_get_icon (XedTab *tab); -void _xed_tab_load (XedTab *tab, - const gchar *uri, - const XedEncoding *encoding, - gint line_pos, - gboolean create); -void _xed_tab_revert (XedTab *tab); -void _xed_tab_save (XedTab *tab); -void _xed_tab_save_as (XedTab *tab, - const gchar *uri, - const XedEncoding *encoding, - XedDocumentNewlineType newline_type); +GtkWidget *_xed_tab_new_from_location (GFile *location, + const XedEncoding *encoding, + gint line_pos, + gboolean create); +gchar *_xed_tab_get_name (XedTab *tab); +gchar *_xed_tab_get_tooltips (XedTab *tab); +GdkPixbuf *_xed_tab_get_icon (XedTab *tab); +void _xed_tab_load (XedTab *tab, + GFile *location, + const XedEncoding *encoding, + gint line_pos, + gboolean create); +void _xed_tab_revert (XedTab *tab); +void _xed_tab_save (XedTab *tab); +void _xed_tab_save_as (XedTab *tab, + GFile *location, + const XedEncoding *encoding, + XedDocumentNewlineType newline_type); -void _xed_tab_print (XedTab *tab); -void _xed_tab_print_preview (XedTab *tab); - -void _xed_tab_mark_for_closing (XedTab *tab); - -gboolean _xed_tab_can_close (XedTab *tab); +void _xed_tab_print (XedTab *tab); +void _xed_tab_print_preview (XedTab *tab); +void _xed_tab_mark_for_closing (XedTab *tab); +gboolean _xed_tab_can_close (XedTab *tab); G_END_DECLS diff --git a/xed/xed-utils.c b/xed/xed-utils.c index 6c7ba7d..56bda94 100644 --- a/xed/xed-utils.c +++ b/xed/xed-utils.c @@ -64,48 +64,12 @@ /** * xed_utils_uris_has_file_scheme * - * Returns: %TRUE if @uri is a file: uri and is not a chained uri + * Returns: %TRUE if @location is a file: uri and is not a chained uri */ gboolean -xed_utils_uri_has_file_scheme (const gchar *uri) +xed_utils_location_has_file_scheme (GFile *location) { - GFile *gfile; - gboolean res; - - gfile = g_file_new_for_uri (uri); - res = g_file_has_uri_scheme (gfile, "file"); - - g_object_unref (gfile); - return res; -} - -/* FIXME: we should check for chained URIs */ -gboolean -xed_utils_uri_has_writable_scheme (const gchar *uri) -{ - GFile *gfile; - gchar *scheme; - GSList *writable_schemes; - gboolean res; - - gfile = g_file_new_for_uri (uri); - scheme = g_file_get_uri_scheme (gfile); - - g_return_val_if_fail (scheme != NULL, FALSE); - - g_object_unref (gfile); - - writable_schemes = xed_prefs_manager_get_writable_vfs_schemes (); - - /* CHECK: should we use g_ascii_strcasecmp? - Paolo (Nov 6, 2005) */ - res = (g_slist_find_custom (writable_schemes, scheme, (GCompareFunc)strcmp) != NULL); - - g_slist_foreach (writable_schemes, (GFunc)g_free, NULL); - g_slist_free (writable_schemes); - - g_free (scheme); - - return res; + return g_file_has_uri_scheme (location, "file"); } static void @@ -325,19 +289,18 @@ xed_utils_set_atk_relation (GtkWidget *obj1, } gboolean -xed_utils_uri_exists (const gchar* text_uri) +xed_utils_location_exists (GFile *location) { - GFile *gfile; gboolean res; + gchar *uri; - g_return_val_if_fail (text_uri != NULL, FALSE); + g_return_val_if_fail (G_IS_FILE (location), FALSE); - xed_debug_message (DEBUG_UTILS, "text_uri: %s", text_uri); + uri = g_file_get_uri (location); + xed_debug_message (DEBUG_UTILS, "text_uri: %s", uri); + g_free (uri); - gfile = g_file_new_for_uri (text_uri); - res = g_file_query_exists (gfile, NULL); - - g_object_unref (gfile); + res = g_file_query_exists (location, NULL); xed_debug_message (DEBUG_UTILS, res ? "TRUE" : "FALSE"); @@ -1042,20 +1005,27 @@ has_valid_scheme (const gchar *uri) } gboolean -xed_utils_is_valid_uri (const gchar *uri) +xed_utils_is_valid_location (GFile *location) { const guchar *p; + gchar *uri; + gboolean is_valid; - if (uri == NULL) + if (location == NULL) { return FALSE; } + uri = g_file_get_uri (location); + if (!has_valid_scheme (uri)) { + g_free (uri); return FALSE; } + is_valid = TRUE; + /* We expect to have a fully valid set of characters */ for (p = (const guchar *)uri; *p; p++) { @@ -1064,25 +1034,30 @@ xed_utils_is_valid_uri (const gchar *uri) ++p; if (!g_ascii_isxdigit (*p)) { - return FALSE; + is_valid = FALSE; + break; } ++p; if (!g_ascii_isxdigit (*p)) { - return FALSE; + is_valid = FALSE; + break; } } else { if (*p <= 32 || *p >= 128) { - return FALSE; + is_valid = FALSE; + break; } } } - return TRUE; + g_free (uri); + + return is_valid; } static GtkWidget * @@ -1248,15 +1223,15 @@ xed_utils_make_canonical_uri_from_shell_arg (const gchar *str) */ gfile = g_file_new_for_commandline_arg (str); - uri = g_file_get_uri (gfile); - g_object_unref (gfile); - if (xed_utils_is_valid_uri (uri)) + if (xed_utils_is_valid_location (gfile)) { + uri = g_file_get_uri (gfile); + g_object_unref (gfile); return uri; } - g_free (uri); + g_object_unref (gfile); return NULL; } @@ -1286,26 +1261,26 @@ xed_utils_file_has_parent (GFile *gfile) /** * xed_utils_basename_for_display: - * @uri: uri for which the basename should be displayed + * @location: location for which the basename should be displayed * * Return the basename of a file suitable for display to users. */ gchar * -xed_utils_basename_for_display (gchar const *uri) +xed_utils_basename_for_display (GFile *location) { gchar *name; - GFile *gfile; gchar *hn; + gchar *uri; - g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (G_IS_FILE (location), NULL); - gfile = g_file_new_for_uri (uri); + uri = g_file_get_uri (location); /* First, try to query the display name, but only on local files */ - if (g_file_has_uri_scheme (gfile, "file")) + if (xed_utils_location_has_file_scheme (location)) { GFileInfo *info; - info = g_file_query_info (gfile, + info = g_file_query_info (location, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, G_FILE_QUERY_INFO_NONE, NULL, @@ -1323,12 +1298,12 @@ xed_utils_basename_for_display (gchar const *uri) * g_filename_display_basename on the local path */ gchar *local_path; - local_path = g_file_get_path (gfile); + local_path = g_file_get_path (location); name = g_filename_display_basename (local_path); g_free (local_path); } } - else if (xed_utils_file_has_parent (gfile) || !xed_utils_decode_uri (uri, NULL, NULL, &hn, NULL, NULL)) + else if (xed_utils_file_has_parent (location) || !xed_utils_decode_uri (uri, NULL, NULL, &hn, NULL, NULL)) { /* For remote files with a parent (so not just http://foo.com) or remote file for which the decoding of the host name fails, @@ -1336,7 +1311,7 @@ xed_utils_basename_for_display (gchar const *uri) gchar *parse_name; gchar *base; - parse_name = g_file_get_parse_name (gfile); + parse_name = g_file_get_parse_name (location); base = g_filename_display_basename (parse_name); name = g_uri_unescape_string (base, NULL); @@ -1365,14 +1340,14 @@ xed_utils_basename_for_display (gchar const *uri) g_free (hn); } - g_object_unref (gfile); + g_free (uri); return name; } /** * xed_utils_uri_for_display: - * @uri: uri to be displayed. + * @location: location to be displayed. * * Filter, modify, unescape and change @uri to make it appropriate * for display to users. @@ -1382,16 +1357,9 @@ xed_utils_basename_for_display (gchar const *uri) * Return value: a string which represents @uri and can be displayed. */ gchar * -xed_utils_uri_for_display (const gchar *uri) +xed_utils_uri_for_display (GFile *location) { - GFile *gfile; - gchar *parse_name; - - gfile = g_file_new_for_uri (uri); - parse_name = g_file_get_parse_name (gfile); - g_object_unref (gfile); - - return parse_name; + return g_file_get_parse_name (location); } /** diff --git a/xed/xed-utils.h b/xed/xed-utils.h index 71f9f29..abe83be 100644 --- a/xed/xed-utils.h +++ b/xed/xed-utils.h @@ -48,8 +48,7 @@ G_BEGIN_DECLS enum { XED_ALL_WORKSPACES = 0xffffffff }; -gboolean xed_utils_uri_has_writable_scheme (const gchar *uri); -gboolean xed_utils_uri_has_file_scheme (const gchar *uri); +gboolean xed_utils_location_has_file_scheme (GFile *location); void xed_utils_menu_position_under_widget (GtkMenu *menu, gint *x, @@ -87,7 +86,7 @@ void xed_utils_set_atk_relation (GtkWidget *obj1, GtkWidget *obj2, AtkRelationType rel_type); -gboolean xed_utils_uri_exists (const gchar* text_uri); +gboolean xed_utils_location_exists (GFile *location); gchar *xed_utils_escape_search_text (const gchar *text); @@ -114,7 +113,7 @@ void xed_utils_get_current_viewport (GdkScreen *screen, gint *x, gint *y); -gboolean xed_utils_is_valid_uri (const gchar *uri); +gboolean xed_utils_is_valid_location (GFile *location); gboolean xed_utils_get_ui_objects (const gchar *filename, gchar **root_objects, @@ -127,9 +126,9 @@ gboolean xed_utils_file_has_parent (GFile *gfile); /* Return NULL if str is not a valid URI and/or filename */ gchar *xed_utils_make_canonical_uri_from_shell_arg (const gchar *str); -gchar *xed_utils_uri_for_display (const gchar *uri); +gchar *xed_utils_uri_for_display (GFile *location); -gchar *xed_utils_basename_for_display (const gchar *uri); +gchar *xed_utils_basename_for_display (GFile *location); gboolean xed_utils_decode_uri (const gchar *uri, gchar **scheme, diff --git a/xed/xed-window.c b/xed/xed-window.c index 77208f3..97deae0 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -43,14 +43,20 @@ /* Signals */ enum { - TAB_ADDED, TAB_REMOVED, TABS_REORDERED, ACTIVE_TAB_CHANGED, ACTIVE_TAB_STATE_CHANGED, LAST_SIGNAL + TAB_ADDED, + TAB_REMOVED, + TABS_REORDERED, + ACTIVE_TAB_CHANGED, + ACTIVE_TAB_STATE_CHANGED, + LAST_SIGNAL }; static guint signals[LAST_SIGNAL] = { 0 }; enum { - PROP_0, PROP_STATE + PROP_0, + PROP_STATE }; enum @@ -841,12 +847,13 @@ update_languages_menu (XedWindow *window) } void -_xed_recent_add (XedWindow *window, - const gchar *uri, +_xed_recent_add (XedWindow *window, + GFile *location, const gchar *mime) { GtkRecentManager *recent_manager; GtkRecentData *recent_data; + gchar *uri; static gchar *groups[2] = { "xed", NULL }; @@ -862,8 +869,11 @@ _xed_recent_add (XedWindow *window, recent_data->groups = groups; recent_data->is_private = FALSE; + uri = g_file_get_uri (location); + gtk_recent_manager_add_full (recent_manager, uri, recent_data); + g_free (uri); g_free (recent_data->app_exec); g_slice_free(GtkRecentData, recent_data); @@ -871,29 +881,32 @@ _xed_recent_add (XedWindow *window, void _xed_recent_remove (XedWindow *window, - const gchar *uri) + GFile *location) { GtkRecentManager *recent_manager; + gchar *uri; recent_manager = gtk_recent_manager_get_default (); + uri = g_file_get_uri (location); gtk_recent_manager_remove_item (recent_manager, uri, NULL); + g_free (uri); } static void -open_recent_file (const gchar *uri, +open_recent_file (GFile *location, XedWindow *window) { - GSList *uris = NULL; + GSList *locations = NULL; - uris = g_slist_prepend (uris, (gpointer) uri); + locations = g_slist_prepend (locations, (gpointer) location); - if (xed_commands_load_uris (window, uris, NULL, 0) != 1) + if (xed_commands_load_locations (window, locations, NULL, 0) != 1) { - _xed_recent_remove (window, uri); + _xed_recent_remove (window, location); } - g_slist_free (uris); + g_slist_free (locations); } static void @@ -901,14 +914,20 @@ recents_menu_activate (GtkAction *action, XedWindow *window) { GtkRecentInfo *info; + GFile *location; const gchar *uri; - info = g_object_get_data (G_OBJECT(action), "gtk-recent-info"); - g_return_if_fail(info != NULL); + info = g_object_get_data (G_OBJECT (action), "gtk-recent-info"); + g_return_if_fail (info != NULL); uri = gtk_recent_info_get_uri (info); + location = g_file_new_for_uri (uri); - open_recent_file (uri, window); + if (location) + { + open_recent_file (location, window); + g_object_unref (location); + } } static gint @@ -994,6 +1013,7 @@ update_recent_files_menu (XedWindow *window) gchar *tip; GtkAction *action; GtkRecentInfo *info = l->data; + GFile *location; /* clamp */ if (i >= max_recents) @@ -1017,7 +1037,9 @@ update_recent_files_menu (XedWindow *window) /* gtk_recent_info_get_uri_display (info) is buggy and * works only for local files */ - uri = xed_utils_uri_for_display (gtk_recent_info_get_uri (info)); + location = g_file_new_for_uri (gtk_recent_info_get_uri (info)); + uri = xed_utils_uri_for_display (location); + g_object_unref (location); ruri = xed_utils_replace_home_dir_with_tilde (uri); g_free (uri); @@ -2380,9 +2402,9 @@ get_drop_window (GtkWidget *widget) static void load_uris_from_drop (XedWindow *window, - gchar **uri_list) + gchar **uri_list) { - GSList *uris = NULL; + GSList *locations = NULL; gint i; if (uri_list == NULL) @@ -2392,13 +2414,14 @@ load_uris_from_drop (XedWindow *window, for (i = 0; uri_list[i] != NULL; ++i) { - uris = g_slist_prepend (uris, uri_list[i]); + locations = g_slist_prepend (locations, g_file_new_for_uri (uri_list[i])); } - uris = g_slist_reverse (uris); - xed_commands_load_uris (window, uris, NULL, 0); + locations = g_slist_reverse (locations); + xed_commands_load_locations (window, locations, NULL, 0); - g_slist_free (uris); + g_slist_foreach (locations, (GFunc) g_object_unref, NULL); + g_slist_free (locations); } /* Handle drops on the XedWindow */ @@ -3596,9 +3619,9 @@ xed_window_create_tab (XedWindow *window, } /** - * xed_window_create_tab_from_uri: + * xed_window_create_tab_from_location: * @window: a #XedWindow - * @uri: the uri of the document + * @location: the location of the document * @encoding: a #XedEncoding * @line_pos: the line position to visualize * @create: %TRUE to create a new document in case @uri does exist @@ -3612,19 +3635,19 @@ xed_window_create_tab (XedWindow *window, * Returns: (transfer none): a new #XedTab */ XedTab * -xed_window_create_tab_from_uri (XedWindow *window, - const gchar *uri, - const XedEncoding *encoding, - gint line_pos, - gboolean create, - gboolean jump_to) +xed_window_create_tab_from_location (XedWindow *window, + GFile *location, + const XedEncoding *encoding, + gint line_pos, + gboolean create, + gboolean jump_to) { GtkWidget *tab; g_return_val_if_fail(XED_IS_WINDOW (window), NULL); - g_return_val_if_fail(uri != NULL, NULL); + g_return_val_if_fail(G_IS_FILE (location), NULL); - tab = _xed_tab_new_from_uri (uri, encoding, line_pos, create); + tab = _xed_tab_new_from_location (location, encoding, line_pos, create); if (tab == NULL) { return NULL; diff --git a/xed/xed-window.h b/xed/xed-window.h index 19d52a8..0364e63 100644 --- a/xed/xed-window.h +++ b/xed/xed-window.h @@ -20,23 +20,16 @@ typedef enum XED_WINDOW_STATE_SAVING_SESSION = 1 << 5 } XedWindowState; -/* - * Type checking and casting macros - */ -#define XED_TYPE_WINDOW (xed_window_get_type()) -#define XED_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_WINDOW, XedWindow)) -#define XED_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_WINDOW, XedWindowClass)) -#define XED_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_WINDOW)) -#define XED_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_WINDOW)) -#define XED_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_WINDOW, XedWindowClass)) +#define XED_TYPE_WINDOW (xed_window_get_type()) +#define XED_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_WINDOW, XedWindow)) +#define XED_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_WINDOW, XedWindowClass)) +#define XED_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_WINDOW)) +#define XED_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_WINDOW)) +#define XED_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_WINDOW, XedWindowClass)) -/* Private structure type */ -typedef struct _XedWindowPrivate XedWindowPrivate; - -/* - * Main object structure - */ -typedef struct _XedWindow XedWindow; +typedef struct _XedWindow XedWindow; +typedef struct _XedWindowPrivate XedWindowPrivate; +typedef struct _XedWindowClass XedWindowClass; struct _XedWindow { @@ -46,11 +39,6 @@ struct _XedWindow XedWindowPrivate *priv; }; -/* - * Class definition - */ -typedef struct _XedWindowClass XedWindowClass; - struct _XedWindowClass { GtkWindowClass parent_class; @@ -68,7 +56,7 @@ struct _XedWindowClass */ GType xed_window_get_type (void) G_GNUC_CONST; XedTab *xed_window_create_tab (XedWindow *window, gboolean jump_to); -XedTab *xed_window_create_tab_from_uri (XedWindow *window, const gchar *uri, const XedEncoding *encoding, +XedTab *xed_window_create_tab_from_location (XedWindow *window, GFile *location, const XedEncoding *encoding, gint line_pos, gboolean create, gboolean jump_to); void xed_window_close_tab (XedWindow *window, XedTab *tab); void xed_window_close_all_tabs (XedWindow *window); @@ -115,8 +103,8 @@ void _xed_window_unfullscreen (XedWindow *window); gboolean _xed_window_is_fullscreen (XedWindow *window); /* these are in xed-window because of screen safety */ -void _xed_recent_add (XedWindow *window, const gchar *uri, const gchar *mime); -void _xed_recent_remove (XedWindow *window, const gchar *uri); +void _xed_recent_add (XedWindow *window, GFile *location, const gchar *mime); +void _xed_recent_remove (XedWindow *window, GFile *location); G_END_DECLS From 490303557acd9252d9892afd79fae186f84cbf75 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 16 Jan 2017 15:41:07 -0800 Subject: [PATCH 094/132] Revamp our handling of settings The current handling of settings is a very roundabout leftover from the days of gconf. Simplify and handle the setting more directly. At the same time move handling of saving the window state to gsettings instead of saving it to a config file. --- data/Makefile.am | 2 + data/org.x.editor.gschema.xml.in | 172 +++- plugins/modelines/modeline-parser.c | 37 +- tests/document-loader.c | 3 - tests/document-output-stream.c | 5 +- tests/document-saver.c | 3 - xed/Makefile.am | 8 +- xed/dialogs/xed-encodings-dialog.c | 44 +- xed/dialogs/xed-preferences-dialog.c | 462 ++++----- xed/xed-app.c | 28 +- xed/xed-app.h | 86 +- xed/xed-document-loader.c | 14 +- xed/xed-document-saver.c | 31 +- xed/xed-document.c | 44 +- xed/xed-encodings-combo-box.c | 40 +- xed/xed-encodings.c | 120 ++- xed/xed-encodings.h | 15 +- xed/xed-file-chooser-dialog.c | 28 +- xed/xed-history-entry.c | 680 +++++++------ xed/xed-history-entry.h | 57 +- xed/xed-io-error-message-area.c | 11 +- xed/xed-language-manager.c | 13 +- xed/xed-notebook.c | 24 +- xed/xed-plugins-engine.c | 12 +- xed/xed-prefs-manager-app.c | 1345 -------------------------- xed/xed-prefs-manager-app.h | 84 -- xed/xed-prefs-manager.c | 849 ---------------- xed/xed-prefs-manager.h | 321 ------ xed/xed-print-job.c | 321 +++--- xed/xed-session.c | 1 - xed/xed-settings.c | 750 ++++++++++++++ xed/xed-settings.h | 132 +++ xed/xed-style-scheme-manager.c | 15 +- xed/xed-tab.c | 27 +- xed/xed-utils.c | 1 - xed/xed-utils.h | 1 + xed/xed-view.c | 1026 +++++++++++--------- xed/xed-window-private.h | 70 +- xed/xed-window.c | 176 ++-- xed/xed-window.h | 2 + xed/xed.c | 6 - 41 files changed, 2775 insertions(+), 4291 deletions(-) delete mode 100644 xed/xed-prefs-manager-app.c delete mode 100644 xed/xed-prefs-manager-app.h delete mode 100644 xed/xed-prefs-manager.c delete mode 100644 xed/xed-prefs-manager.h create mode 100644 xed/xed-settings.c create mode 100644 xed/xed-settings.h diff --git a/data/Makefile.am b/data/Makefile.am index 067ad8f..8591f2b 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -4,11 +4,13 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) @INTLTOOL_DESKTOP_RULE@ @INTLTOOL_XML_RULE@ + appdatadir = $(datadir)/appdata appdata_in_files = xed.appdata.xml.in appdata_DATA = $(appdata_in_files:.xml.in=.xml) gsettings_SCHEMAS = org.x.editor.gschema.xml + @GSETTINGS_RULES@ man_MANS = xed.1 diff --git a/data/org.x.editor.gschema.xml.in b/data/org.x.editor.gschema.xml.in index 3d27f97..012b278 100644 --- a/data/org.x.editor.gschema.xml.in +++ b/data/org.x.editor.gschema.xml.in @@ -1,200 +1,330 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true Use Default Font Whether to use the system's default fixed width font for editing text instead of a font specific to xed. If this option is turned off, then the font named in the "Editor Font" option will be used instead of the system font. + 'Monospace 12' Editor Font A custom font that will be used for the editing area. This will only take effect if the "Use Default Font" option is turned off. - + + 'tango' Style Scheme The ID of a GtkSourceView Style Scheme used to color the text. + false Create Backup Copies Whether xed should create backup copies for the files it saves. You can set the backup file extension with the "Backup Copy Extension" option. + false Autosave Whether xed should automatically save modified files after a time interval. You can set the time interval with the "Autosave Interval" option. - + + 10 Autosave Interval Number of minutes after which xed will automatically save modified files. This will only take effect if the "Autosave" option is turned on. + [ 'dav', 'davs', 'ftp', 'sftp', 'smb', 'ssh' ] Writable VFS schemes List of VFS schemes xed supports in write mode. The 'file' scheme is writable by default. + 2000 Maximum Number of Undo Actions Maximum number of actions that xed will be able to undo or redo. Use "-1" for unlimited number of actions. - - 'GTK_WRAP_WORD' + + + 'word' Line Wrapping Mode - Specifies how to wrap long lines in the editing area. Use "GTK_WRAP_NONE" for no wrapping, "GTK_WRAP_WORD" for wrapping at word boundaries, and "GTK_WRAP_CHAR" for wrapping at individual character boundaries. Note that the values are case-sensitive, so make sure they appear exactly as mentioned here. + Specifies how to wrap long lines in the editing area. Use "none" for no wrapping, "word" for wrapping at word boundaries, and "char" for wrapping at individual character boundaries. Note that the values are case-sensitive, so make sure they appear exactly as mentioned here. - + + 4 Tab Size Specifies the number of spaces that should be displayed instead of Tab characters. + true Insert spaces Whether xed should insert spaces instead of tabs. + false Automatic indent Whether xed should enable automatic indentation. + false Display Line Numbers Whether xed should display line numbers in the editing area. + false Highlight Current Line Whether xed should highlight the current line. + false Highlight Matching Bracket Whether xed should highlight the bracket matching the selected one. + false Display Right Margin Whether xed should display the right margin in the editing area. - + + 120 Right Margin Position Specifies the position of the right margin. - + + 'after' Smart Home End - Specifies how the cursor moves when the HOME and END keys are pressed. Use "DISABLED" to always move at the start/end of the line, "AFTER" to move to the start/end of the line the first time the keys are pressed and to the start/end of the text ignoring whitespaces the second time the keys are pressed, "BEFORE" to move to the start/end of the text before moving to the start/end of the line and "ALWAYS" to always move to the start/end of the text instead of the start/end of the line. + Specifies how the cursor moves when the HOME and END keys are pressed. Use "disabled" to always move at the start/end of the line, "after" to move to the start/end of the line the first time the keys are pressed and to the start/end of the text ignoring whitespaces the second time the keys are pressed, "before" to move to the start/end of the text before moving to the start/end of the line and "always" to always move to the start/end of the text instead of the start/end of the line. + true Restore Previous Cursor Position Whether xed should restore the previous cursor position when a file is loaded. - + + true Enable Search Highlighting Whether xed should highlight all the occurrences of the searched text. - + + true Enable Syntax Highlighting Whether xed should enable syntax highlighting. + + + + + true Toolbar is Visible Whether the toolbar should be visible in editing windows. + true Status Bar is Visible Whether the status bar at the bottom of editing windows should be visible. - + + false Side Pane is Visible Whether the side pane at the left of editing windows should be visible. + false Bottom Panel is Visible Whether the bottom panel at the bottom of editing windows should be visible. + true Allow changing active tabs by scrolling Whether you can change active tabs by scrolling. - + + 5 Maximum Recent Files Specifies the maximum number of recently opened files that will be displayed in the "Recent Files" submenu. + + + + + true Print Syntax Highlighting Whether xed should print syntax highlighting when printing documents. + true Print Header Whether xed should include a document header when printing documents. - - 'GTK_WRAP_WORD' + + + 'word' Printing Line Wrapping Mode - Specifies how to wrap long lines for printing. Use "GTK_WRAP_NONE" for no wrapping, "GTK_WRAP_WORD" for wrapping at word boundaries, and "GTK_WRAP_CHAR" for wrapping at individual character boundaries. Note that the values are case-sensitive, so make sure they appear exactly as mentioned here. + Specifies how to wrap long lines for printing. Use "none" for no wrapping, "word" for wrapping at word boundaries, and "char" for wrapping at individual character boundaries. Note that the values are case-sensitive, so make sure they appear exactly as mentioned here. - + + 0 Print Line Numbers If this value is 0, then no line numbers will be inserted when printing a document. Otherwise, xed will print line numbers every such number of lines. + 'Monospace 9' Body Font for Printing Specifies the font to use for a document's body when printing documents. + 'Sans 11' Header Font for Printing Specifies the font to use for page headers when printing a document. This will only take effect if the "Print Header" option is turned on. + 'Sans 8' Line Number Font for Printing Specifies the font to use for line numbers when printing. This will only take effect if the "Print Line Numbers" option is non-zero. - + + + + + + [ 'UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16' ] Automatically Detected Encodings Sorted list of encodings used by xed for automatically detecting the encoding of a file. "CURRENT" represents the current locale encoding. Only recognized encodings are used. - + + [ 'ISO-8859-15' ] Encodings shown in menu List of encodings shown in the Character Encoding menu in open/save file selector. Only recognized encodings are used. + + + + + + + + + + + + + 0 + + + + (650,500) + + + + 200 + + + + 0 + + + + 140 + + + + 0 + + + + + + + + 0 + + + + + + [] History for "search for" entries List of entries in "search for" textbox. + [] History for "replace with" entries List of entries in "replace with" textbox. + + + + + [ 'docinfo', 'modelines', 'filebrowser', 'spell', 'time' ] Active plugins List of active plugins. It contains the "Location" of the active plugins. See the .xed-plugin file for obtaining the "Location" of a given plugin. + + diff --git a/plugins/modelines/modeline-parser.c b/plugins/modelines/modeline-parser.c index 2661912..c900eab 100644 --- a/plugins/modelines/modeline-parser.c +++ b/plugins/modelines/modeline-parser.c @@ -25,8 +25,9 @@ #include #include #include -#include #include +#include +#include #include "modeline-parser.h" #define MODELINES_LANGUAGE_MAPPINGS_FILE "language-mappings" @@ -678,6 +679,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) GtkTextBuffer *buffer; GtkTextIter iter, liter; gint line_count; + GSettings *settings; options.language_id = NULL; options.set = MODELINE_SET_NONE; @@ -764,6 +766,8 @@ modeline_parser_apply_modeline (GtkSourceView *view) ModelineOptions *previous = g_object_get_data (G_OBJECT (buffer), MODELINE_OPTIONS_DATA_KEY); + settings = g_settings_new ("org.x.editor.preferences.editor"); + /* Apply the options we got from modelines and restore defaults if we set them before */ if (has_option (&options, MODELINE_SET_INSERT_SPACES)) @@ -773,9 +777,10 @@ modeline_parser_apply_modeline (GtkSourceView *view) } else if (check_previous (view, previous, MODELINE_SET_INSERT_SPACES)) { - gtk_source_view_set_insert_spaces_instead_of_tabs - (view, - xed_prefs_manager_get_insert_spaces ()); + gboolean insert_spaces; + + insert_spaces = g_settings_get_boolean (settings, XED_SETTINGS_INSERT_SPACES); + gtk_source_view_set_insert_spaces_instead_of_tabs (view, insert_spaces); } if (has_option (&options, MODELINE_SET_TAB_WIDTH)) @@ -784,8 +789,10 @@ modeline_parser_apply_modeline (GtkSourceView *view) } else if (check_previous (view, previous, MODELINE_SET_TAB_WIDTH)) { - gtk_source_view_set_tab_width (view, - xed_prefs_manager_get_tabs_size ()); + guint tab_width; + + tab_width = g_settings_get_uint (settings, XED_SETTINGS_TABS_SIZE); + gtk_source_view_set_tab_width (view, tab_width); } if (has_option (&options, MODELINE_SET_INDENT_WIDTH)) @@ -803,8 +810,10 @@ modeline_parser_apply_modeline (GtkSourceView *view) } else if (check_previous (view, previous, MODELINE_SET_WRAP_MODE)) { - gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), - xed_prefs_manager_get_wrap_mode ()); + GtkWrapMode mode; + + mode = g_settings_get_enum (settings, XED_SETTINGS_WRAP_MODE); + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), mode); } if (has_option (&options, MODELINE_SET_RIGHT_MARGIN_POSITION)) @@ -813,8 +822,10 @@ modeline_parser_apply_modeline (GtkSourceView *view) } else if (check_previous (view, previous, MODELINE_SET_RIGHT_MARGIN_POSITION)) { - gtk_source_view_set_right_margin_position (view, - xed_prefs_manager_get_right_margin_position ()); + guint right_margin_pos; + + right_margin_pos = g_settings_get_uint (settings, XED_SETTINGS_RIGHT_MARGIN_POSITION); + gtk_source_view_set_right_margin_position (view, right_margin_pos); } if (has_option (&options, MODELINE_SET_SHOW_RIGHT_MARGIN)) @@ -823,8 +834,10 @@ modeline_parser_apply_modeline (GtkSourceView *view) } else if (check_previous (view, previous, MODELINE_SET_SHOW_RIGHT_MARGIN)) { - gtk_source_view_set_show_right_margin (view, - xed_prefs_manager_get_display_right_margin ()); + gboolean display_right_margin; + + display_right_margin = g_settings_get_boolean (settings, XED_SETTINGS_DISPLAY_RIGHT_MARGIN); + gtk_source_view_set_show_right_margin (view, display_right_margin); } if (previous) diff --git a/tests/document-loader.c b/tests/document-loader.c index 54ad365..1ad87ff 100644 --- a/tests/document-loader.c +++ b/tests/document-loader.c @@ -21,7 +21,6 @@ */ #include "xed-document-loader.h" -#include "xed-prefs-manager-app.h" #include #include #include @@ -241,8 +240,6 @@ int main (int argc, { g_test_init (&argc, &argv, NULL); - xed_prefs_manager_app_init (); - g_test_add_func ("/document-loader/end-line-stripping", test_end_line_stripping); g_test_add_func ("/document-loader/end-new-line-detection", test_end_new_line_detection); g_test_add_func ("/document-loader/begin-new-line-detection", test_begin_new_line_detection); diff --git a/tests/document-output-stream.c b/tests/document-output-stream.c index b64bbe5..f74036a 100644 --- a/tests/document-output-stream.c +++ b/tests/document-output-stream.c @@ -16,13 +16,12 @@ * * You should have received a copy of the GNU General Public License * along with xed; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ #include "xed-document-output-stream.h" -#include "xed-prefs-manager-app.h" #include #include #include @@ -125,8 +124,6 @@ int main (int argc, { g_test_init (&argc, &argv, NULL); - xed_prefs_manager_app_init (); - g_test_add_func ("/document-output-stream/empty", test_empty); g_test_add_func ("/document-output-stream/consecutive", test_consecutive); diff --git a/tests/document-saver.c b/tests/document-saver.c index 9235adf..646acff 100644 --- a/tests/document-saver.c +++ b/tests/document-saver.c @@ -21,7 +21,6 @@ */ #include "xed-document-loader.h" -#include "xed-prefs-manager-app.h" #include #include #include @@ -684,8 +683,6 @@ int main (int argc, g_test_init (&argc, &argv, NULL); - xed_prefs_manager_app_init (); - g_printf ("\n***\n"); have_unowned = check_unowned_directory (); have_unowned_group = check_unowned_group (); diff --git a/xed/Makefile.am b/xed/Makefile.am index 3b2b1dd..2bb2c57 100644 --- a/xed/Makefile.am +++ b/xed/Makefile.am @@ -55,10 +55,10 @@ NOINST_H_FILES = \ xed-io-error-message-area.h \ xed-language-manager.h \ xed-plugins-engine.h \ - xed-prefs-manager-private.h \ xed-print-job.h \ xed-print-preview.h \ xed-session.h \ + xed-settings.h \ xed-smart-charset-converter.h \ xed-style-scheme-manager.h \ xed-tab-label.h \ @@ -81,8 +81,6 @@ INST_H_FILES = \ xed-message.h \ xed-notebook.h \ xed-panel.h \ - xed-prefs-manager-app.h \ - xed-prefs-manager.h \ xed-progress-message-area.h \ xed-searchbar.h \ xed-statusbar.h \ @@ -136,13 +134,11 @@ libxed_c_files = \ xed-notebook.c \ xed-panel.c \ xed-plugins-engine.c \ - xed-prefs-manager-app.c \ - xed-prefs-manager.c \ - xed-prefs-manager-private.h \ xed-print-job.c \ xed-print-preview.c \ xed-progress-message-area.c \ xed-session.c \ + xed-settings.c \ xed-smart-charset-converter.c \ xed-searchbar.c \ xed-statusbar.c \ diff --git a/xed/dialogs/xed-encodings-dialog.c b/xed/dialogs/xed-encodings-dialog.c index f94d16a..38028d6 100755 --- a/xed/dialogs/xed-encodings-dialog.c +++ b/xed/dialogs/xed-encodings-dialog.c @@ -40,11 +40,11 @@ #include "xed-encodings-dialog.h" #include "xed-encodings.h" -#include "xed-prefs-manager.h" #include "xed-utils.h" #include "xed-debug.h" #include "xed-help.h" #include "xed-dirs.h" +#include "xed-settings.h" #define XED_ENCODINGS_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ XED_TYPE_ENCODINGS_DIALOG, \ @@ -52,12 +52,15 @@ struct _XedEncodingsDialogPrivate { + GSettings *enc_settings; + GtkListStore *available_liststore; GtkListStore *displayed_liststore; - GtkWidget *available_treeview; - GtkWidget *displayed_treeview; - GtkWidget *add_button; - GtkWidget *remove_button; + + GtkWidget *available_treeview; + GtkWidget *displayed_treeview; + GtkWidget *add_button; + GtkWidget *remove_button; GSList *show_in_menu_list; }; @@ -74,12 +77,23 @@ xed_encodings_dialog_finalize (GObject *object) G_OBJECT_CLASS (xed_encodings_dialog_parent_class)->finalize (object); } +static void +xed_encodings_dialog_dispose (GObject *object) +{ + XedEncodingsDialogPrivate *priv = XED_ENCODINGS_DIALOG (object)->priv; + + g_clear_object (&priv->enc_settings); + + G_OBJECT_CLASS (xed_encodings_dialog_parent_class)->dispose (object); +} + static void xed_encodings_dialog_class_init (XedEncodingsDialogClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = xed_encodings_dialog_finalize; + object_class->dispose = xed_encodings_dialog_dispose; g_type_class_add_private (object_class, sizeof (XedEncodingsDialogPrivate)); } @@ -228,14 +242,15 @@ static void init_shown_in_menu_tree_model (XedEncodingsDialog *dialog) { GtkTreeIter iter; + gchar **enc_strv; GSList *list, *tmp; /* add data to the list store */ - list = xed_prefs_manager_get_shown_in_menu_encodings (); + enc_strv = g_settings_get_strv (dialog->priv->enc_settings, XED_SETTINGS_ENCODING_SHOWN_IN_MENU); - tmp = list; + list = _xed_encoding_strv_to_list ((const gchar * const *)enc_strv); - while (tmp != NULL) + for (tmp = list; tmp != NULL; tmp = g_slist_next (tmp)) { const XedEncoding *enc; @@ -248,8 +263,6 @@ init_shown_in_menu_tree_model (XedEncodingsDialog *dialog) COLUMN_CHARSET, xed_encoding_get_charset (enc), COLUMN_NAME, xed_encoding_get_name (enc), -1); - - tmp = g_slist_next (tmp); } g_slist_free (list); @@ -269,8 +282,14 @@ response_handler (GtkDialog *dialog, if (response_id == GTK_RESPONSE_OK) { - g_return_if_fail (xed_prefs_manager_shown_in_menu_encodings_can_set ()); - xed_prefs_manager_set_shown_in_menu_encodings (dlg->priv->show_in_menu_list); + gchar **encs; + + encs = _xed_encoding_list_to_strv (dlg->priv->show_in_menu_list); + g_settings_set_strv (dlg->priv->enc_settings, + XED_SETTINGS_ENCODING_SHOWN_IN_MENU, + (const gchar * const *)encs); + + g_strfreev (encs); } } @@ -294,6 +313,7 @@ xed_encodings_dialog_init (XedEncodingsDialog *dlg) }; dlg->priv = XED_ENCODINGS_DIALOG_GET_PRIVATE (dlg); + dlg->priv->enc_settings = g_settings_new ("org.x.editor.preferences.encodings"); gtk_dialog_add_buttons (GTK_DIALOG (dlg), _("_Cancel"), GTK_RESPONSE_CANCEL, diff --git a/xed/dialogs/xed-preferences-dialog.c b/xed/dialogs/xed-preferences-dialog.c index 28c4dfa..0469f17 100755 --- a/xed/dialogs/xed-preferences-dialog.c +++ b/xed/dialogs/xed-preferences-dialog.c @@ -41,8 +41,6 @@ #include #include -#include - #include "xed-preferences-dialog.h" #include "xed-utils.h" #include "xed-debug.h" @@ -50,6 +48,8 @@ #include "xed-style-scheme-manager.h" #include "xed-help.h" #include "xed-dirs.h" +#include "xed-settings.h" +#include "xed-utils.h" /* * xed-preferences dialog is a singleton since we don't @@ -78,72 +78,87 @@ enum struct _XedPreferencesDialogPrivate { + GSettings *editor; + GSettings *ui; + GtkWidget *notebook; /* Font */ - GtkWidget *default_font_checkbutton; - GtkWidget *font_button; - GtkWidget *font_hbox; + GtkWidget *default_font_checkbutton; + GtkWidget *font_button; + GtkWidget *font_hbox; /* Style Scheme */ - GtkListStore *schemes_treeview_model; - GtkWidget *schemes_treeview; - GtkWidget *install_scheme_button; - GtkWidget *uninstall_scheme_button; + GtkListStore *schemes_treeview_model; + GtkWidget *schemes_treeview; + GtkWidget *install_scheme_button; + GtkWidget *uninstall_scheme_button; - GtkWidget *install_scheme_file_schooser; + GtkWidget *install_scheme_file_schooser; /* Tabs */ - GtkWidget *tabs_width_spinbutton; - GtkWidget *insert_spaces_checkbutton; - GtkWidget *tabs_width_hbox; + GtkWidget *tabs_width_spinbutton; + GtkWidget *insert_spaces_checkbutton; + GtkWidget *tabs_width_hbox; /* Auto indentation */ - GtkWidget *auto_indent_checkbutton; + GtkWidget *auto_indent_checkbutton; /* Text Wrapping */ - GtkWidget *wrap_text_checkbutton; - GtkWidget *split_checkbutton; + GtkWidget *wrap_text_checkbutton; + GtkWidget *split_checkbutton; /* File Saving */ - GtkWidget *backup_copy_checkbutton; - GtkWidget *auto_save_checkbutton; - GtkWidget *auto_save_spinbutton; - GtkWidget *autosave_hbox; + GtkWidget *backup_copy_checkbutton; + GtkWidget *auto_save_checkbutton; + GtkWidget *auto_save_spinbutton; + GtkWidget *autosave_hbox; /* Line numbers */ - GtkWidget *display_line_numbers_checkbutton; + GtkWidget *display_line_numbers_checkbutton; /* Highlight current line */ - GtkWidget *highlight_current_line_checkbutton; + GtkWidget *highlight_current_line_checkbutton; /* Highlight matching bracket */ - GtkWidget *bracket_matching_checkbutton; + GtkWidget *bracket_matching_checkbutton; /* Right margin */ - GtkWidget *right_margin_checkbutton; - GtkWidget *right_margin_position_spinbutton; - GtkWidget *right_margin_position_hbox; + GtkWidget *right_margin_checkbutton; + GtkWidget *right_margin_position_spinbutton; + GtkWidget *right_margin_position_hbox; /* Tab scrolling */ - GtkWidget *tab_scrolling_checkbutton; + GtkWidget *tab_scrolling_checkbutton; /* Plugins manager */ - GtkWidget *plugin_manager_place_holder; + GtkWidget *plugin_manager_place_holder; /* Style Scheme editor dialog */ - GtkWidget *style_scheme_dialog; + GtkWidget *style_scheme_dialog; }; G_DEFINE_TYPE(XedPreferencesDialog, xed_preferences_dialog, GTK_TYPE_DIALOG) +static void +xed_preferences_dialog_dispose (GObject *object) +{ + XedPreferencesDialog *dlg = XED_PREFERENCES_DIALOG (object); + + g_clear_object (&dlg->priv->editor); + g_clear_object (&dlg->priv->ui); + + G_OBJECT_CLASS (xed_preferences_dialog_parent_class)->dispose (object); +} static void xed_preferences_dialog_class_init (XedPreferencesDialogClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->dispose = xed_preferences_dialog_dispose; + g_type_class_add_private (object_class, sizeof (XedPreferencesDialogPrivate)); } @@ -165,172 +180,75 @@ dialog_response_handler (GtkDialog *dlg, } static void -tabs_width_spinbutton_value_changed (GtkSpinButton *spin_button, - XedPreferencesDialog *dlg) +on_auto_save_changed (GSettings *settings, + const gchar *key, + XedPreferencesDialog *dlg) { + gboolean value; + xed_debug (DEBUG_PREFS); - g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->tabs_width_spinbutton)); + value = g_settings_get_boolean (settings, key); - xed_prefs_manager_set_tabs_size (gtk_spin_button_get_value_as_int (spin_button)); -} - -static void -insert_spaces_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->insert_spaces_checkbutton)); - - xed_prefs_manager_set_insert_spaces (gtk_toggle_button_get_active (button)); -} - -static void -auto_indent_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->auto_indent_checkbutton)); - - xed_prefs_manager_set_auto_indent (gtk_toggle_button_get_active (button)); -} - -static void -auto_save_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->auto_save_checkbutton)); - - if (gtk_toggle_button_get_active (button)) - { - gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, xed_prefs_manager_auto_save_interval_can_set()); - xed_prefs_manager_set_auto_save (TRUE); - } - else - { - gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, FALSE); - xed_prefs_manager_set_auto_save (FALSE); - } -} - -static void -backup_copy_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton)); - - xed_prefs_manager_set_create_backup_copy (gtk_toggle_button_get_active (button)); -} - -static void -auto_save_spinbutton_value_changed (GtkSpinButton *spin_button, - XedPreferencesDialog *dlg) -{ - g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->auto_save_spinbutton)); - - xed_prefs_manager_set_auto_save_interval (MAX (1, gtk_spin_button_get_value_as_int (spin_button))); -} - -static void -tab_scrolling_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->tab_scrolling_checkbutton)); - - xed_prefs_manager_set_enable_tab_scrolling (gtk_toggle_button_get_active (button)); + gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, value); } static void setup_editor_page (XedPreferencesDialog *dlg) { gboolean auto_save; - gint auto_save_interval; xed_debug (DEBUG_PREFS); - /* Set initial state */ - gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->tabs_width_spinbutton), - (guint) xed_prefs_manager_get_tabs_size ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->insert_spaces_checkbutton), - xed_prefs_manager_get_insert_spaces ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_indent_checkbutton), - xed_prefs_manager_get_auto_indent ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton), - xed_prefs_manager_get_create_backup_copy ()); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->tab_scrolling_checkbutton), - xed_prefs_manager_get_enable_tab_scrolling ()); - - auto_save = xed_prefs_manager_get_auto_save (); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_save_checkbutton), auto_save); - - auto_save_interval = xed_prefs_manager_get_auto_save_interval (); - if (auto_save_interval <= 0) - { - auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL; - } - - gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->auto_save_spinbutton), auto_save_interval); + /* Get values */ + auto_save = g_settings_get_boolean (dlg->priv->editor, XED_SETTINGS_AUTO_SAVE); /* Set widget sensitivity */ - gtk_widget_set_sensitive (dlg->priv->tabs_width_hbox, xed_prefs_manager_tabs_size_can_set ()); - gtk_widget_set_sensitive (dlg->priv->insert_spaces_checkbutton, xed_prefs_manager_insert_spaces_can_set ()); - gtk_widget_set_sensitive (dlg->priv->auto_indent_checkbutton, xed_prefs_manager_auto_indent_can_set ()); - gtk_widget_set_sensitive (dlg->priv->backup_copy_checkbutton, xed_prefs_manager_create_backup_copy_can_set ()); - gtk_widget_set_sensitive (dlg->priv->autosave_hbox, xed_prefs_manager_auto_save_can_set ()); - gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, - auto_save && xed_prefs_manager_auto_save_interval_can_set ()); - gtk_widget_set_sensitive (dlg->priv->tab_scrolling_checkbutton, xed_prefs_manager_enable_tab_scrolling_can_set ()); + gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, auto_save); /* Connect signal */ - g_signal_connect (dlg->priv->tabs_width_spinbutton, "value_changed", - G_CALLBACK (tabs_width_spinbutton_value_changed), dlg); - g_signal_connect (dlg->priv->insert_spaces_checkbutton, "toggled", - G_CALLBACK (insert_spaces_checkbutton_toggled), dlg); - g_signal_connect (dlg->priv->auto_indent_checkbutton, "toggled", - G_CALLBACK (auto_indent_checkbutton_toggled), dlg); - g_signal_connect (dlg->priv->auto_save_checkbutton, "toggled", - G_CALLBACK (auto_save_checkbutton_toggled), dlg); - g_signal_connect (dlg->priv->backup_copy_checkbutton, "toggled", - G_CALLBACK (backup_copy_checkbutton_toggled), dlg); - g_signal_connect (dlg->priv->auto_save_spinbutton, "value_changed", - G_CALLBACK (auto_save_spinbutton_value_changed), dlg); - g_signal_connect (dlg->priv->tab_scrolling_checkbutton, "toggled", - G_CALLBACK (tab_scrolling_checkbutton_toggled), dlg); -} - -static void -display_line_numbers_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton)); - - xed_prefs_manager_set_display_line_numbers (gtk_toggle_button_get_active (button)); -} - -static void -highlight_current_line_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton)); - - xed_prefs_manager_set_highlight_current_line (gtk_toggle_button_get_active (button)); -} - -static void -bracket_matching_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton)); - - xed_prefs_manager_set_bracket_matching (gtk_toggle_button_get_active (button)); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_TABS_SIZE, + dlg->priv->tabs_width_spinbutton, + "value", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_INSERT_SPACES, + dlg->priv->insert_spaces_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_AUTO_INDENT, + dlg->priv->auto_indent_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_CREATE_BACKUP_COPY, + dlg->priv->backup_copy_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_BRACKET_MATCHING, + dlg->priv->bracket_matching_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_AUTO_SAVE_INTERVAL, + dlg->priv->auto_save_spinbutton, + "value", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_signal_connect (dlg->priv->editor, "changed::auto_save", + G_CALLBACK (on_auto_save_changed), dlg); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_AUTO_SAVE, + dlg->priv->auto_save_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->ui, + XED_SETTINGS_ENABLE_TAB_SCROLLING, + dlg->priv->tab_scrolling_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); } static gboolean split_button_state = TRUE; @@ -339,9 +257,11 @@ static void wrap_mode_checkbutton_toggled (GtkToggleButton *button, XedPreferencesDialog *dlg) { + GtkWrapMode mode; + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton))) { - xed_prefs_manager_set_wrap_mode (GTK_WRAP_NONE); + mode = GTK_WRAP_NONE; gtk_widget_set_sensitive (dlg->priv->split_checkbutton, FALSE); gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE); @@ -355,14 +275,16 @@ wrap_mode_checkbutton_toggled (GtkToggleButton *button, if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton))) { split_button_state = TRUE; - xed_prefs_manager_set_wrap_mode (GTK_WRAP_WORD); + mode = GTK_WRAP_WORD; } else { split_button_state = FALSE; - xed_prefs_manager_set_wrap_mode (GTK_WRAP_CHAR); + mode = GTK_WRAP_CHAR; } } + + g_settings_set_enum (dlg->priv->editor, XED_SETTINGS_WRAP_MODE, mode); } static void @@ -375,23 +297,9 @@ right_margin_checkbutton_toggled (GtkToggleButton *button, active = gtk_toggle_button_get_active (button); - xed_prefs_manager_set_display_right_margin (active); + g_settings_set_boolean (dlg->priv->editor, XED_SETTINGS_DISPLAY_RIGHT_MARGIN, active); - gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, - active && xed_prefs_manager_right_margin_position_can_set ()); -} - -static void -right_margin_position_spinbutton_value_changed (GtkSpinButton *spin_button, - XedPreferencesDialog *dlg) -{ - gint value; - - g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton)); - - value = CLAMP (gtk_spin_button_get_value_as_int (spin_button), 1, 160); - - xed_prefs_manager_set_right_margin_position (value); + gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, active); } static void @@ -399,22 +307,18 @@ setup_view_page (XedPreferencesDialog *dlg) { GtkWrapMode wrap_mode; gboolean display_right_margin; - gboolean wrap_mode_can_set; + guint right_margin_position; xed_debug (DEBUG_PREFS); + /* Get values */ + display_right_margin = g_settings_get_boolean (dlg->priv->editor, XED_SETTINGS_DISPLAY_RIGHT_MARGIN); + right_margin_position = g_settings_get_uint (dlg->priv->editor, XED_SETTINGS_RIGHT_MARGIN_POSITION); + /* Set initial state */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton), - xed_prefs_manager_get_display_line_numbers ()); + wrap_mode = g_settings_get_enum (dlg->priv->editor, XED_SETTINGS_WRAP_MODE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton), - xed_prefs_manager_get_highlight_current_line ()); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton), - xed_prefs_manager_get_bracket_matching ()); - - wrap_mode = xed_prefs_manager_get_wrap_mode (); - switch (wrap_mode ) + switch (wrap_mode) { case GTK_WRAP_WORD: gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton), TRUE); @@ -431,89 +335,55 @@ setup_view_page (XedPreferencesDialog *dlg) } - display_right_margin = xed_prefs_manager_get_display_right_margin (); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->right_margin_checkbutton), display_right_margin); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton), - (guint)CLAMP (xed_prefs_manager_get_right_margin_position (), 1, 160)); - /* Set widgets sensitivity */ - gtk_widget_set_sensitive (dlg->priv->display_line_numbers_checkbutton, - xed_prefs_manager_display_line_numbers_can_set ()); - gtk_widget_set_sensitive (dlg->priv->highlight_current_line_checkbutton, - xed_prefs_manager_highlight_current_line_can_set ()); - gtk_widget_set_sensitive (dlg->priv->bracket_matching_checkbutton, xed_prefs_manager_bracket_matching_can_set ()); - wrap_mode_can_set = xed_prefs_manager_wrap_mode_can_set (); - gtk_widget_set_sensitive (dlg->priv->wrap_text_checkbutton, wrap_mode_can_set); - gtk_widget_set_sensitive (dlg->priv->split_checkbutton, wrap_mode_can_set && (wrap_mode != GTK_WRAP_NONE)); - gtk_widget_set_sensitive (dlg->priv->right_margin_checkbutton, xed_prefs_manager_display_right_margin_can_set ()); - gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, - display_right_margin && xed_prefs_manager_right_margin_position_can_set ()); + gtk_widget_set_sensitive (dlg->priv->split_checkbutton, (wrap_mode != GTK_WRAP_NONE)); + gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, display_right_margin); /* Connect signals */ - g_signal_connect (dlg->priv->display_line_numbers_checkbutton, "toggled", - G_CALLBACK (display_line_numbers_checkbutton_toggled), dlg); - g_signal_connect (dlg->priv->highlight_current_line_checkbutton, "toggled", - G_CALLBACK (highlight_current_line_checkbutton_toggled), dlg); - g_signal_connect (dlg->priv->bracket_matching_checkbutton, "toggled", - G_CALLBACK (bracket_matching_checkbutton_toggled), dlg); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_DISPLAY_LINE_NUMBERS, + dlg->priv->display_line_numbers_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_HIGHLIGHT_CURRENT_LINE, + dlg->priv->highlight_current_line_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_RIGHT_MARGIN_POSITION, + dlg->priv->right_margin_position_spinbutton, + "value", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); g_signal_connect (dlg->priv->wrap_text_checkbutton, "toggled", G_CALLBACK (wrap_mode_checkbutton_toggled), dlg); g_signal_connect (dlg->priv->split_checkbutton, "toggled", G_CALLBACK (wrap_mode_checkbutton_toggled), dlg); g_signal_connect (dlg->priv->right_margin_checkbutton, "toggled", G_CALLBACK (right_margin_checkbutton_toggled), dlg); - g_signal_connect (dlg->priv->right_margin_position_spinbutton, "value_changed", - G_CALLBACK (right_margin_position_spinbutton_value_changed), dlg); } static void -default_font_font_checkbutton_toggled (GtkToggleButton *button, - XedPreferencesDialog *dlg) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->default_font_checkbutton)); - - if (gtk_toggle_button_get_active (button)) - { - gtk_widget_set_sensitive (dlg->priv->font_hbox, FALSE); - xed_prefs_manager_set_use_default_font (TRUE); - } - else - { - gtk_widget_set_sensitive (dlg->priv->font_hbox, xed_prefs_manager_editor_font_can_set ()); - xed_prefs_manager_set_use_default_font (FALSE); - } -} - -static void -editor_font_button_font_set (GtkFontButton *font_button, +on_use_default_font_changed (GSettings *settings, + const gchar *key, XedPreferencesDialog *dlg) { - const gchar *font_name; + gboolean value; xed_debug (DEBUG_PREFS); - g_return_if_fail (font_button == GTK_FONT_BUTTON (dlg->priv->font_button)); - - /* FIXME: Can this fail? Gtk docs are a bit terse... 21-02-2004 pbor */ - font_name = gtk_font_button_get_font_name (font_button); - if (!font_name) - { - g_warning ("Could not get font name"); - return; - } - - xed_prefs_manager_set_editor_font (font_name); + value = g_settings_get_boolean (settings, key); + gtk_widget_set_sensitive (dlg->priv->font_hbox, value); } static void setup_font_colors_page_font_section (XedPreferencesDialog *dlg) { + GSettings *settings; gboolean use_default_font; - gchar *editor_font = NULL; + gchar *system_font = NULL; gchar *label; xed_debug (DEBUG_PREFS); @@ -528,40 +398,35 @@ setup_font_colors_page_font_section (XedPreferencesDialog *dlg) dlg->priv->font_button, ATK_RELATION_CONTROLLER_FOR); - editor_font = xed_prefs_manager_get_system_font (); - label = g_strdup_printf(_("_Use the system fixed width font (%s)"), editor_font); + /* Get values */ + settings = _xed_app_get_settings (xed_app_get_default ()); + system_font = xed_settings_get_system_font (XED_SETTINGS (settings)); + use_default_font = g_settings_get_boolean (dlg->priv->editor, XED_SETTINGS_USE_DEFAULT_FONT); + + label = g_strdup_printf(_("_Use the system fixed width font (%s)"), system_font); gtk_button_set_label (GTK_BUTTON (dlg->priv->default_font_checkbutton), label); - g_free (editor_font); + g_free (system_font); g_free (label); /* read current config and setup initial state */ - use_default_font = xed_prefs_manager_get_use_default_font (); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->default_font_checkbutton), use_default_font); - editor_font = xed_prefs_manager_get_editor_font (); - if (editor_font != NULL) - { - gtk_font_button_set_font_name (GTK_FONT_BUTTON (dlg->priv->font_button), editor_font); - g_free (editor_font); - } - /* Connect signals */ - g_signal_connect (dlg->priv->default_font_checkbutton, "toggled", - G_CALLBACK (default_font_font_checkbutton_toggled), dlg); - g_signal_connect (dlg->priv->font_button, "font_set", - G_CALLBACK (editor_font_button_font_set), dlg); + g_signal_connect (dlg->priv->editor, "changed::use-default-font", + G_CALLBACK (on_use_default_font_changed), dlg); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_USE_DEFAULT_FONT, + dlg->priv->default_font_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_EDITOR_FONT, + dlg->priv->font_button, + "font-name", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); /* Set initial widget sensitivity */ - gtk_widget_set_sensitive (dlg->priv->default_font_checkbutton, xed_prefs_manager_use_default_font_can_set ()); - - if (use_default_font) - { - gtk_widget_set_sensitive (dlg->priv->font_hbox, FALSE); - } - else - { - gtk_widget_set_sensitive (dlg->priv->font_hbox, xed_prefs_manager_editor_font_can_set ()); - } + gtk_widget_set_sensitive (dlg->priv->font_hbox, use_default_font); } static void @@ -589,7 +454,7 @@ style_scheme_changed (GtkWidget *treeview, gtk_tree_path_free (path); gtk_tree_model_get (GTK_TREE_MODEL (dlg->priv->schemes_treeview_model), &iter, ID_COLUMN, &id, -1); - xed_prefs_manager_set_source_style_scheme (id); + g_settings_set_string (dlg->priv->editor, XED_SETTINGS_SCHEME, id); set_buttons_sensisitivity_according_to_scheme (dlg, id); @@ -597,7 +462,8 @@ style_scheme_changed (GtkWidget *treeview, } static const gchar * -ensure_color_scheme_id (const gchar *id) +ensure_color_scheme_id (XedPreferencesDialog *dlg, + const gchar *id) { GtkSourceStyleScheme *scheme = NULL; GtkSourceStyleSchemeManager *manager = xed_get_style_scheme_manager (); @@ -606,7 +472,7 @@ ensure_color_scheme_id (const gchar *id) { gchar *pref_id; - pref_id = xed_prefs_manager_get_source_style_scheme (); + pref_id = g_settings_get_string (dlg->priv->editor, XED_SETTINGS_SCHEME); scheme = gtk_source_style_scheme_manager_get_scheme (manager, pref_id); g_free (pref_id); } @@ -642,7 +508,7 @@ populate_color_scheme_list (XedPreferencesDialog *dlg, gtk_list_store_clear (dlg->priv->schemes_treeview_model); - def_id = ensure_color_scheme_id (def_id); + def_id = ensure_color_scheme_id (dlg, def_id); if (def_id == NULL) { g_warning ("Cannot build the list of available color schemes.\n" @@ -720,7 +586,7 @@ add_scheme_chooser_response_cb (GtkDialog *chooser, return; } - xed_prefs_manager_set_source_style_scheme (scheme_id); + g_settings_set_string (dlg->priv->editor, XED_SETTINGS_SCHEME, scheme_id); scheme_id = populate_color_scheme_list (dlg, scheme_id); @@ -852,7 +718,7 @@ uninstall_scheme_clicked (GtkButton *button, if (real_new_id != NULL) { - xed_prefs_manager_set_source_style_scheme (real_new_id); + g_settings_set_string (dlg->priv->editor, XED_SETTINGS_SCHEME, real_new_id); } } @@ -983,6 +849,8 @@ xed_preferences_dialog_init (XedPreferencesDialog *dlg) xed_debug (DEBUG_PREFS); dlg->priv = XED_PREFERENCES_DIALOG_GET_PRIVATE (dlg); + dlg->priv->editor = g_settings_new ("org.x.editor.preferences.editor"); + dlg->priv->ui = g_settings_new ("org.x.editor.preferences.ui"); gtk_dialog_add_buttons (GTK_DIALOG (dlg), _("Close"), GTK_RESPONSE_CLOSE, diff --git a/xed/xed-app.c b/xed/xed-app.c index 70c520c..a06f2be 100644 --- a/xed/xed-app.c +++ b/xed/xed-app.c @@ -39,7 +39,6 @@ #include #include "xed-app.h" -#include "xed-prefs-manager-app.h" #include "xed-commands.h" #include "xed-notebook.h" #include "xed-debug.h" @@ -48,6 +47,7 @@ #include "xed-dirs.h" #include "xed-app-activatable.h" #include "xed-plugins-engine.h" +#include "xed-settings.h" #define XED_PAGE_SETUP_FILE "xed-page-setup" #define XED_PRINT_SETTINGS_FILE "xed-print-settings" @@ -62,12 +62,15 @@ enum struct _XedAppPrivate { - GList *windows; - XedWindow *active_window; + GList *windows; + XedWindow *active_window; - GtkPageSetup *page_setup; + GtkPageSetup *page_setup; GtkPrintSettings *print_settings; + GSettings *settings; + GSettings *window_settings; + PeasExtensionSet *extensions; }; @@ -98,6 +101,8 @@ xed_app_dispose (GObject *object) { XedApp *app = XED_APP (object); + g_clear_object (&app->priv->window_settings); + g_clear_object (&app->priv->settings); g_clear_object (&app->priv->extensions); G_OBJECT_CLASS (xed_app_parent_class)->dispose (object); @@ -350,6 +355,8 @@ xed_app_init (XedApp *app) load_accels (); + app->priv->settings = xed_settings_new (); + app->priv->window_settings = g_settings_new ("org.x.editor.state.window"); app->priv->extensions = peas_extension_set_new (PEAS_ENGINE (xed_plugins_engine_get_default ()), XED_TYPE_APP_ACTIVATABLE, "app", app, NULL); @@ -525,17 +532,17 @@ xed_app_create_window_real (XedApp *app, GdkWindowState state; gint w, h; - state = xed_prefs_manager_get_window_state (); + state = g_settings_get_int (app->priv->window_settings, XED_SETTINGS_WINDOW_STATE); if ((state & GDK_WINDOW_STATE_MAXIMIZED) != 0) { - xed_prefs_manager_get_default_window_size (&w, &h); + _xed_window_get_default_size (&w, &h); gtk_window_set_default_size (GTK_WINDOW (window), w, h); gtk_window_maximize (GTK_WINDOW (window)); } else { - xed_prefs_manager_get_window_size (&w, &h); + g_settings_get (app->priv->window_settings, XED_SETTINGS_WINDOW_SIZE, "(ii)", &w, &h); gtk_window_set_default_size (GTK_WINDOW (window), w, h); gtk_window_unmaximize (GTK_WINDOW (window)); } @@ -867,3 +874,10 @@ _xed_app_set_default_print_settings (XedApp *app, app->priv->print_settings = g_object_ref (settings); } +GSettings * +_xed_app_get_settings (XedApp *app) +{ + g_return_val_if_fail (XED_IS_APP (app), NULL); + + return app->priv->settings; +} diff --git a/xed/xed-app.h b/xed/xed-app.h index 82988c1..f60acd5 100644 --- a/xed/xed-app.h +++ b/xed/xed-app.h @@ -2,7 +2,7 @@ * xed-app.h * This file is part of xed * - * Copyright (C) 2005 - Paolo Maggi + * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -37,9 +37,6 @@ G_BEGIN_DECLS -/* - * Type checking and casting macros - */ #define XED_TYPE_APP (xed_app_get_type()) #define XED_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_APP, XedApp)) #define XED_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_APP, XedAppClass)) @@ -47,69 +44,62 @@ G_BEGIN_DECLS #define XED_IS_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_APP)) #define XED_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_APP, XedAppClass)) -/* Private structure type */ -typedef struct _XedAppPrivate XedAppPrivate; +typedef struct _XedApp XedApp; +typedef struct _XedAppPrivate XedAppPrivate; +typedef struct _XedAppClass XedAppClass; -/* - * Main object structure - */ -typedef struct _XedApp XedApp; - -struct _XedApp +struct _XedApp { - GObject object; + GObject object; - /*< private > */ - XedAppPrivate *priv; + /*< private > */ + XedAppPrivate *priv; }; -/* - * Class definition - */ -typedef struct _XedAppClass XedAppClass; - -struct _XedAppClass +struct _XedAppClass { - GObjectClass parent_class; + GObjectClass parent_class; }; /* * Public methods */ -GType xed_app_get_type (void) G_GNUC_CONST; +GType xed_app_get_type (void) G_GNUC_CONST; -XedApp *xed_app_get_default (void); +XedApp *xed_app_get_default (void); -XedWindow *xed_app_create_window (XedApp *app, - GdkScreen *screen); +XedWindow *xed_app_create_window (XedApp *app, + GdkScreen *screen); -const GList *xed_app_get_windows (XedApp *app); -XedWindow *xed_app_get_active_window (XedApp *app); +const GList *xed_app_get_windows (XedApp *app); +XedWindow *xed_app_get_active_window (XedApp *app); /* Returns a newly allocated list with all the documents */ -GList *xed_app_get_documents (XedApp *app); +GList *xed_app_get_documents (XedApp *app); /* Returns a newly allocated list with all the views */ -GList *xed_app_get_views (XedApp *app); +GList *xed_app_get_views (XedApp *app); /* * Non exported functions */ -XedWindow *_xed_app_restore_window (XedApp *app, - const gchar *role); -XedWindow *_xed_app_get_window_in_viewport (XedApp *app, - GdkScreen *screen, - gint workspace, - gint viewport_x, - gint viewport_y); +XedWindow *_xed_app_restore_window (XedApp *app, + const gchar *role); +XedWindow *_xed_app_get_window_in_viewport (XedApp *app, + GdkScreen *screen, + gint workspace, + gint viewport_x, + gint viewport_y); /* global print config */ -GtkPageSetup *_xed_app_get_default_page_setup (XedApp *app); -void _xed_app_set_default_page_setup (XedApp *app, - GtkPageSetup *page_setup); -GtkPrintSettings *_xed_app_get_default_print_settings (XedApp *app); -void _xed_app_set_default_print_settings (XedApp *app, - GtkPrintSettings *settings); +GtkPageSetup *_xed_app_get_default_page_setup (XedApp *app); +void _xed_app_set_default_page_setup (XedApp *app, + GtkPageSetup *page_setup); +GtkPrintSettings *_xed_app_get_default_print_settings (XedApp *app); +void _xed_app_set_default_print_settings (XedApp *app, + GtkPrintSettings *settings); + +GSettings *_xed_app_get_settings (XedApp *app); G_END_DECLS diff --git a/xed/xed-document-loader.c b/xed/xed-document-loader.c index aaee954..3f40f2e 100644 --- a/xed/xed-document-loader.c +++ b/xed/xed-document-loader.c @@ -40,12 +40,12 @@ #include "xed-document-loader.h" #include "xed-document-output-stream.h" #include "xed-smart-charset-converter.h" -#include "xed-prefs-manager.h" #include "xed-debug.h" #include "xed-metadata-manager.h" #include "xed-utils.h" #include "xed-marshal.h" #include "xed-enum-types.h" +#include "xed-settings.h" #ifndef ENABLE_GVFS_METADATA #include "xed_metadata-manager.h" @@ -94,6 +94,8 @@ static void open_async_read (AsyncData *async); struct _XedDocumentLoaderPrivate { + GSettings *enc_settings; + XedDocument *document; gboolean used; @@ -228,6 +230,8 @@ xed_document_loader_dispose (GObject *object) priv->location = NULL; } + g_clear_object (&priv->enc_settings); + G_OBJECT_CLASS (xed_document_loader_parent_class)->dispose (object); } @@ -303,6 +307,7 @@ xed_document_loader_init (XedDocumentLoader *loader) loader->priv->auto_detected_newline_type = XED_DOCUMENT_NEWLINE_TYPE_DEFAULT; loader->priv->converter = NULL; loader->priv->error = NULL; + loader->priv->enc_settings = g_settings_new ("org.x.editor.preferences.encodings"); } XedDocumentLoader * @@ -585,9 +590,12 @@ static GSList * get_candidate_encodings (XedDocumentLoader *loader) { const XedEncoding *metadata; - GSList *encodings = NULL; + GSList *encodings; + gchar **enc_strv; - encodings = xed_prefs_manager_get_auto_detected_encodings (); + enc_strv = g_settings_get_strv (loader->priv->enc_settings, XED_SETTINGS_ENCODING_AUTO_DETECTED); + encodings = _xed_encoding_strv_to_list ((const gchar * const *)enc_strv); + g_free (enc_strv); metadata = get_metadata_encoding (loader); if (metadata != NULL) diff --git a/xed/xed-document-saver.c b/xed/xed-document-saver.c index 25718c7..0d795c4 100644 --- a/xed/xed-document-saver.c +++ b/xed/xed-document-saver.c @@ -39,10 +39,10 @@ #include "xed-document-saver.h" #include "xed-debug.h" #include "xed-document-input-stream.h" -#include "xed-prefs-manager.h" #include "xed-marshal.h" #include "xed-utils.h" #include "xed-enum-types.h" +#include "xed-settings.h" #define WRITE_CHUNK_SIZE 8192 @@ -86,6 +86,8 @@ static void check_modified_async (AsyncData *async); struct _XedDocumentSaverPrivate { + GSettings *editor_settings; + GFileInfo *info; XedDocument *document; gboolean used; @@ -219,6 +221,8 @@ xed_document_saver_dispose (GObject *object) priv->location = NULL; } + g_clear_object (&priv->editor_settings); + G_OBJECT_CLASS (xed_document_saver_parent_class)->dispose (object); } @@ -314,17 +318,16 @@ xed_document_saver_class_init (XedDocumentSaverClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - signals[SAVING] = - g_signal_new ("saving", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedDocumentSaverClass, saving), - NULL, NULL, - xed_marshal_VOID__BOOLEAN_POINTER, - G_TYPE_NONE, - 2, - G_TYPE_BOOLEAN, - G_TYPE_POINTER); + signals[SAVING] = g_signal_new ("saving", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedDocumentSaverClass, saving), + NULL, NULL, + xed_marshal_VOID__BOOLEAN_POINTER, + G_TYPE_NONE, + 2, + G_TYPE_BOOLEAN, + G_TYPE_POINTER); g_type_class_add_private (object_class, sizeof (XedDocumentSaverPrivate)); } @@ -337,6 +340,7 @@ xed_document_saver_init (XedDocumentSaver *saver) saver->priv->cancellable = g_cancellable_new (); saver->priv->error = NULL; saver->priv->used = FALSE; + saver->priv->editor_settings = g_settings_new ("org.x.editor.preferences.editor"); } XedDocumentSaver * @@ -940,7 +944,8 @@ xed_document_saver_save (XedDocumentSaver *saver, } else { - saver->priv->keep_backup = xed_prefs_manager_get_create_backup_copy (); + saver->priv->keep_backup = g_settings_get_boolean (saver->priv->editor_settings, + XED_SETTINGS_CREATE_BACKUP_COPY); } saver->priv->old_mtime = *old_mtime; diff --git a/xed/xed-document.c b/xed/xed-document.c index 51a4d15..371fa9e 100644 --- a/xed/xed-document.c +++ b/xed/xed-document.c @@ -41,7 +41,7 @@ #include #include -#include "xed-prefs-manager-app.h" +#include "xed-settings.h" #include "xed-document.h" #include "xed-debug.h" #include "xed-utils.h" @@ -102,7 +102,10 @@ static void delete_range_cb (XedDocument *doc, struct _XedDocumentPrivate { + GSettings *editor_settings; + GFile *location; + gint untitled_number; gchar *short_name; @@ -284,6 +287,8 @@ xed_document_dispose (GObject *object) doc->priv->loader = NULL; } + g_clear_object (&doc->priv->editor_settings); + if (doc->priv->metadata_info != NULL) { g_object_unref (doc->priv->metadata_info); @@ -676,8 +681,11 @@ set_language (XedDocument *doc, if (lang != NULL) { - gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (doc), - xed_prefs_manager_get_enable_syntax_highlighting ()); + gboolean syntax_hl; + + syntax_hl = g_settings_get_boolean (doc->priv->editor_settings, + XED_SETTINGS_SYNTAX_HIGHLIGHTING); + gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (doc), syntax_hl); } else { @@ -723,16 +731,15 @@ set_encoding (XedDocument *doc, } static GtkSourceStyleScheme * -get_default_style_scheme (void) +get_default_style_scheme (GSettings *editor_settings) { gchar *scheme_id; GtkSourceStyleScheme *def_style; GtkSourceStyleSchemeManager *manager; manager = xed_get_style_scheme_manager (); - scheme_id = xed_prefs_manager_get_source_style_scheme (); - def_style = gtk_source_style_scheme_manager_get_scheme (manager, - scheme_id); + scheme_id = g_settings_get_string (editor_settings, XED_SETTINGS_SCHEME); + def_style = gtk_source_style_scheme_manager_get_scheme (manager, scheme_id); if (def_style == NULL) { @@ -874,11 +881,16 @@ static void xed_document_init (XedDocument *doc) { GtkSourceStyleScheme *style_scheme; + gint undo_actions; + gboolean bracket_matching; + gboolean search_hl; xed_debug (DEBUG_DOCUMENT); doc->priv = XED_DOCUMENT_GET_PRIVATE (doc); + doc->priv->editor_settings = g_settings_new ("org.x.editor.preferences.editor"); + doc->priv->location = NULL; doc->priv->untitled_number = get_untitled_number (); @@ -904,12 +916,15 @@ xed_document_init (XedDocument *doc) doc->priv->newline_type = XED_DOCUMENT_NEWLINE_TYPE_DEFAULT; - gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (doc), xed_prefs_manager_get_undo_actions_limit ()); - gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (doc), - xed_prefs_manager_get_bracket_matching ()); - xed_document_set_enable_search_highlighting (doc, xed_prefs_manager_get_enable_search_highlighting ()); + undo_actions = g_settings_get_int (doc->priv->editor_settings, XED_SETTINGS_MAX_UNDO_ACTIONS); + bracket_matching = g_settings_get_boolean (doc->priv->editor_settings, XED_SETTINGS_BRACKET_MATCHING); + search_hl = g_settings_get_boolean (doc->priv->editor_settings, XED_SETTINGS_SEARCH_HIGHLIGHTING); - style_scheme = get_default_style_scheme (); + gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (doc), undo_actions); + gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (doc), bracket_matching); + xed_document_set_enable_search_highlighting (doc, search_hl); + + style_scheme = get_default_style_scheme (doc->priv->editor_settings); if (style_scheme != NULL) { gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (doc), style_scheme); @@ -1275,6 +1290,7 @@ document_loader_loaded (XedDocumentLoader *loader, { GtkTextIter iter; GFileInfo *info; + gboolean restore_cursor; const gchar *content_type = NULL; gboolean read_only = FALSE; GTimeVal mtime = {0, 0}; @@ -1309,6 +1325,8 @@ document_loader_loaded (XedDocumentLoader *loader, xed_document_set_newline_type (doc, xed_document_loader_get_newline_type (loader)); + restore_cursor = g_settings_get_boolean (doc->priv->editor_settings, XED_SETTINGS_RESTORE_CURSOR_POSITION); + /* move the cursor at the requested line if any */ if (doc->priv->requested_line_pos > 0) { @@ -1318,7 +1336,7 @@ document_loader_loaded (XedDocumentLoader *loader, doc->priv->requested_line_pos - 1); } /* else, if enabled, to the position stored in the metadata */ - else if (xed_prefs_manager_get_restore_cursor_position ()) + else if (restore_cursor) { gchar *pos; gint offset; diff --git a/xed/xed-encodings-combo-box.c b/xed/xed-encodings-combo-box.c index f9cf161..d11dee2 100644 --- a/xed/xed-encodings-combo-box.c +++ b/xed/xed-encodings-combo-box.c @@ -37,8 +37,9 @@ #include #include -#include #include +#include "xed-settings.h" +#include "xed-utils.h" #define ENCODING_KEY "Enconding" @@ -48,6 +49,8 @@ struct _XedEncodingsComboBoxPrivate { + GSettings *enc_settings; + GtkListStore *store; glong changed_id; @@ -248,6 +251,7 @@ update_menu (XedEncodingsComboBox *menu) gchar *str; const XedEncoding *utf8_encoding; const XedEncoding *current_encoding; + gchar **enc_strv; store = menu->priv->store; @@ -308,7 +312,9 @@ update_menu (XedEncodingsComboBox *menu) g_free (str); } - encodings = xed_prefs_manager_get_shown_in_menu_encodings (); + enc_strv = g_settings_get_strv (menu->priv->enc_settings, XED_SETTINGS_ENCODING_SHOWN_IN_MENU); + encodings = _xed_encoding_strv_to_list ((const gchar * const *)enc_strv); + g_strfreev (enc_strv); for (l = encodings; l != NULL; l = g_slist_next (l)) { @@ -331,23 +337,20 @@ update_menu (XedEncodingsComboBox *menu) g_slist_free (encodings); - if (xed_prefs_manager_shown_in_menu_encodings_can_set ()) - { - gtk_list_store_append (store, &iter); - /* separator */ - gtk_list_store_set (store, &iter, - NAME_COLUMN, "", - ENCODING_COLUMN, NULL, - ADD_COLUMN, FALSE, - -1); + gtk_list_store_append (store, &iter); + /* Separator */ + gtk_list_store_set (store, &iter, + NAME_COLUMN, "", + ENCODING_COLUMN, NULL, + ADD_COLUMN, FALSE, + -1); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - NAME_COLUMN, _("Add or Remove..."), - ENCODING_COLUMN, NULL, - ADD_COLUMN, TRUE, - -1); - } + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + NAME_COLUMN, _("Add or Remove..."), + ENCODING_COLUMN, NULL, + ADD_COLUMN, TRUE, + -1); /* set the model back */ gtk_combo_box_set_model (GTK_COMBO_BOX (menu), GTK_TREE_MODEL (menu->priv->store)); @@ -363,6 +366,7 @@ xed_encodings_combo_box_init (XedEncodingsComboBox *menu) menu->priv = XED_ENCODINGS_COMBO_BOX_GET_PRIVATE (menu); + menu->priv->enc_settings = g_settings_new ("org.x.editor.preferences.encodings"); menu->priv->store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN); /* Setup up the cells */ diff --git a/xed/xed-encodings.c b/xed/xed-encodings.c index d829578..b989e83 100644 --- a/xed/xed-encodings.c +++ b/xed/xed-encodings.c @@ -2,7 +2,7 @@ * xed-encodings.c * This file is part of xed * - * Copyright (C) 2002-2005 Paolo Maggi + * Copyright (C) 2002-2005 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2002-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2002-2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -46,8 +46,8 @@ struct _XedEncoding const gchar *name; }; -/* - * The original versions of the following tables are taken from profterm +/* + * The original versions of the following tables are taken from profterm * * Copyright (C) 2002 Red Hat, Inc. */ @@ -108,7 +108,7 @@ typedef enum XED_ENCODING_KOI8_R, XED_ENCODING_KOI8__R, XED_ENCODING_KOI8_U, - + XED_ENCODING_SHIFT_JIS, XED_ENCODING_TCVN, XED_ENCODING_TIS_620, @@ -129,7 +129,7 @@ typedef enum XED_ENCODING_UTF_8, XED_ENCODING_UNKNOWN - + } XedEncodingIndex; static const XedEncoding utf8_encoding = { @@ -141,8 +141,8 @@ static const XedEncoding utf8_encoding = { /* initialized in xed_encoding_lazy_init() */ static XedEncoding unknown_encoding = { XED_ENCODING_UNKNOWN, - NULL, - NULL + NULL, + NULL }; static const XedEncoding encodings [] = { @@ -248,7 +248,7 @@ static const XedEncoding encodings [] = { "KOI8-R", N_("Cyrillic") }, { XED_ENCODING_KOI8_U, "KOI8U", N_("Cyrillic/Ukrainian") }, - + { XED_ENCODING_SHIFT_JIS, "SHIFT_JIS", N_("Japanese") }, { XED_ENCODING_TCVN, @@ -312,12 +312,12 @@ xed_encoding_get_from_charset (const gchar *charset) if (g_ascii_strcasecmp (charset, "UTF-8") == 0) return xed_encoding_get_utf8 (); - i = 0; + i = 0; while (i < XED_ENCODING_LAST) { if (g_ascii_strcasecmp (charset, encodings[i].charset) == 0) return &encodings[i]; - + ++i; } @@ -364,17 +364,17 @@ xed_encoding_get_current (void) if (initialized != FALSE) return locale_encoding; - if (g_get_charset (&locale_charset) == FALSE) + if (g_get_charset (&locale_charset) == FALSE) { g_return_val_if_fail (locale_charset != NULL, &utf8_encoding); - + locale_encoding = xed_encoding_get_from_charset (locale_charset); } else { locale_encoding = &utf8_encoding; } - + if (locale_encoding == NULL) { locale_encoding = &unknown_encoding; @@ -391,7 +391,7 @@ gchar * xed_encoding_to_string (const XedEncoding* enc) { g_return_val_if_fail (enc != NULL, NULL); - + xed_encoding_lazy_init (); g_return_val_if_fail (enc->charset != NULL, NULL); @@ -443,7 +443,7 @@ xed_encoding_copy (const XedEncoding *enc) return (XedEncoding *) enc; } -void +void xed_encoding_free (XedEncoding *enc) { g_return_if_fail (enc != NULL); @@ -451,13 +451,13 @@ xed_encoding_free (XedEncoding *enc) /** * xed_encoding_get_type: - * + * * Retrieves the GType object which is associated with the * #XedEncoding class. - * + * * Return value: the GType associated with #XedEncoding. **/ -GType +GType xed_encoding_get_type (void) { static GType our_type = 0; @@ -469,5 +469,77 @@ xed_encoding_get_type (void) (GBoxedFreeFunc) xed_encoding_free); return our_type; -} +} +static gboolean +data_exists (GSList *list, + const gpointer data) +{ + while (list != NULL) + { + if (list->data == data) + return TRUE; + + list = g_slist_next (list); + } + + return FALSE; +} + +GSList * +_xed_encoding_strv_to_list (const gchar * const *enc_str) +{ + GSList *res = NULL; + gchar **p; + const XedEncoding *enc; + + for (p = (gchar **)enc_str; p != NULL && *p != NULL; p++) + { + const gchar *charset = *p; + + if (strcmp (charset, "CURRENT") == 0) + { + g_get_charset (&charset); + } + + g_return_val_if_fail (charset != NULL, NULL); + enc = xed_encoding_get_from_charset (charset); + + if (enc != NULL) + { + if (!data_exists (res, (gpointer)enc)) + { + res = g_slist_prepend (res, (gpointer)enc); + } + + } + } + + return g_slist_reverse (res); +} + +gchar ** +_xed_encoding_list_to_strv (const GSList *enc_list) +{ + GSList *l; + GPtrArray *array; + + array = g_ptr_array_sized_new (g_slist_length ((GSList *)enc_list) + 1); + + for (l = (GSList *)enc_list; l != NULL; l = g_slist_next (l)) + { + const XedEncoding *enc; + const gchar *charset; + + enc = (const XedEncoding *)l->data; + + charset = xed_encoding_get_charset (enc); + g_return_val_if_fail (charset != NULL, NULL); + + g_ptr_array_add (array, g_strdup (charset)); + } + + g_ptr_array_add (array, NULL); + + return (gchar **)g_ptr_array_free (array, FALSE); +} diff --git a/xed/xed-encodings.h b/xed/xed-encodings.h index eb890eb..0ba2bd0 100644 --- a/xed/xed-encodings.h +++ b/xed/xed-encodings.h @@ -2,7 +2,7 @@ * xed-encodings.h * This file is part of xed * - * Copyright (C) 2002-2005 Paolo Maggi + * Copyright (C) 2002-2005 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2002-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2002-2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -57,6 +57,9 @@ const XedEncoding *xed_encoding_get_current (void); XedEncoding *xed_encoding_copy (const XedEncoding *enc); void xed_encoding_free (XedEncoding *enc); +GSList *_xed_encoding_strv_to_list (const gchar * const *enc_str); +gchar **_xed_encoding_list_to_strv (const GSList *enc); + G_END_DECLS #endif /* __XED_ENCODINGS_H__ */ diff --git a/xed/xed-file-chooser-dialog.c b/xed/xed-file-chooser-dialog.c index b87add6..909a05b 100644 --- a/xed/xed-file-chooser-dialog.c +++ b/xed/xed-file-chooser-dialog.c @@ -44,9 +44,9 @@ #include "xed-file-chooser-dialog.h" #include "xed-encodings-combo-box.h" #include "xed-language-manager.h" -#include "xed-prefs-manager-app.h" #include "xed-debug.h" #include "xed-enum-types.h" +#include "xed-settings.h" #define XED_FILE_CHOOSER_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_FILE_CHOOSER_DIALOG, XedFileChooserDialogPrivate)) @@ -55,6 +55,8 @@ struct _XedFileChooserDialogPrivate { + GSettings *filter_settings; + GtkWidget *option_menu; GtkWidget *extra_widget; @@ -65,11 +67,23 @@ struct _XedFileChooserDialogPrivate G_DEFINE_TYPE(XedFileChooserDialog, xed_file_chooser_dialog, GTK_TYPE_FILE_CHOOSER_DIALOG) +static void +xed_file_chooser_dialog_dispose (GObject *object) +{ + XedFileChooserDialog *dialog = XED_FILE_CHOOSER_DIALOG (object); + + g_clear_object (&dialog->priv->filter_settings); + + G_OBJECT_CLASS (xed_file_chooser_dialog_parent_class)->dispose (object); +} + static void xed_file_chooser_dialog_class_init (XedFileChooserDialogClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->dispose = xed_file_chooser_dialog_dispose; + g_type_class_add_private (object_class, sizeof(XedFileChooserDialogPrivate)); } @@ -209,11 +223,6 @@ filter_changed (XedFileChooserDialog *dialog, { GtkFileFilter *filter; - if (!xed_prefs_manager_active_file_filter_can_set ()) - { - return; - } - filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)); if (filter != NULL) { @@ -230,7 +239,7 @@ filter_changed (XedFileChooserDialog *dialog, xed_debug_message (DEBUG_COMMANDS, "Active filter: %s (%d)", name, id); - xed_prefs_manager_set_active_file_filter (id); + g_settings_set_int (dialog->priv->filter_settings, XED_SETTINGS_ACTIVE_FILE_FILTER, id); } } @@ -323,6 +332,8 @@ static void xed_file_chooser_dialog_init (XedFileChooserDialog *dialog) { dialog->priv = XED_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog); + + dialog->priv->filter_settings = g_settings_new ("org.x.editor.state.file-filter"); } static GtkWidget * @@ -359,7 +370,8 @@ xed_file_chooser_dialog_new_valist (const gchar *title, XED_ENCODINGS_COMBO_BOX (XED_FILE_CHOOSER_DIALOG (result)->priv->option_menu), encoding); } - active_filter = xed_prefs_manager_get_active_file_filter (); + active_filter = g_settings_get_int (XED_FILE_CHOOSER_DIALOG (result)->priv->filter_settings, + XED_SETTINGS_ACTIVE_FILE_FILTER); xed_debug_message (DEBUG_COMMANDS, "Active filter: %d", active_filter); /* Filters */ diff --git a/xed/xed-history-entry.c b/xed/xed-history-entry.c index 2e23d9b..d0d2605 100644 --- a/xed/xed-history-entry.c +++ b/xed/xed-history-entry.c @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2006. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2006. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -38,12 +38,12 @@ #include #include "xed-history-entry.h" -#include "xed-prefs-manager.h" -enum { - PROP_0, - PROP_HISTORY_ID, - PROP_HISTORY_LENGTH +enum +{ + PROP_0, + PROP_HISTORY_ID, + PROP_HISTORY_LENGTH }; #define MIN_ITEM_LEN 3 @@ -51,494 +51,460 @@ enum { #define XED_HISTORY_ENTRY_HISTORY_LENGTH_DEFAULT 10 #define XED_HISTORY_ENTRY_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ - XED_TYPE_HISTORY_ENTRY, \ - XedHistoryEntryPrivate)) + XED_TYPE_HISTORY_ENTRY, \ + XedHistoryEntryPrivate)) struct _XedHistoryEntryPrivate { - gchar *history_id; - guint history_length; - - GtkEntryCompletion *completion; - - GSettings *settings; + gchar *history_id; + guint history_length; + GtkEntryCompletion *completion; + GSettings *settings; }; G_DEFINE_TYPE(XedHistoryEntry, xed_history_entry, GTK_TYPE_COMBO_BOX_TEXT) static void xed_history_entry_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *spec) + guint prop_id, + const GValue *value, + GParamSpec *spec) { - XedHistoryEntry *entry; + XedHistoryEntry *entry; - g_return_if_fail (XED_IS_HISTORY_ENTRY (object)); + g_return_if_fail (XED_IS_HISTORY_ENTRY (object)); - entry = XED_HISTORY_ENTRY (object); + entry = XED_HISTORY_ENTRY (object); - switch (prop_id) { - case PROP_HISTORY_ID: - entry->priv->history_id = g_value_dup_string (value); - break; - case PROP_HISTORY_LENGTH: - xed_history_entry_set_history_length (entry, - g_value_get_uint (value)); - break; - default: - break; - } + switch (prop_id) + { + case PROP_HISTORY_ID: + entry->priv->history_id = g_value_dup_string (value); + break; + case PROP_HISTORY_LENGTH: + xed_history_entry_set_history_length (entry, g_value_get_uint (value)); + break; + default: + break; + } } static void xed_history_entry_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *spec) + guint prop_id, + GValue *value, + GParamSpec *spec) { - XedHistoryEntryPrivate *priv; + XedHistoryEntryPrivate *priv; - g_return_if_fail (XED_IS_HISTORY_ENTRY (object)); + g_return_if_fail (XED_IS_HISTORY_ENTRY (object)); - priv = XED_HISTORY_ENTRY (object)->priv; + priv = XED_HISTORY_ENTRY (object)->priv; - switch (prop_id) { - case PROP_HISTORY_ID: - g_value_set_string (value, priv->history_id); - break; - case PROP_HISTORY_LENGTH: - g_value_set_uint (value, priv->history_length); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec); - } + switch (prop_id) + { + case PROP_HISTORY_ID: + g_value_set_string (value, priv->history_id); + break; + case PROP_HISTORY_LENGTH: + g_value_set_uint (value, priv->history_length); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec); + } } static void xed_history_entry_dispose (GObject *object) { - xed_history_entry_set_enable_completion (XED_HISTORY_ENTRY (object), - FALSE); + XedHistoryEntryPrivate *priv; - G_OBJECT_CLASS (xed_history_entry_parent_class)->dispose (object); + priv = XED_HISTORY_ENTRY (object)->priv; + xed_history_entry_set_enable_completion (XED_HISTORY_ENTRY (object), FALSE); + + g_clear_object (&priv->settings); + + G_OBJECT_CLASS (xed_history_entry_parent_class)->dispose (object); } static void xed_history_entry_finalize (GObject *object) { - XedHistoryEntryPrivate *priv; + XedHistoryEntryPrivate *priv; - priv = XED_HISTORY_ENTRY (object)->priv; - - g_free (priv->history_id); + priv = XED_HISTORY_ENTRY (object)->priv; - if (priv->settings != NULL) - { - g_object_unref (G_OBJECT (priv->settings)); - priv->settings = NULL; - } + g_free (priv->history_id); - G_OBJECT_CLASS (xed_history_entry_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_history_entry_parent_class)->finalize (object); } -static void +static void xed_history_entry_class_init (XedHistoryEntryClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->set_property = xed_history_entry_set_property; - object_class->get_property = xed_history_entry_get_property; - object_class->finalize = xed_history_entry_finalize; - object_class->dispose = xed_history_entry_dispose; - - g_object_class_install_property (object_class, - PROP_HISTORY_ID, - g_param_spec_string ("history-id", - "History ID", - "History ID", - NULL, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - g_object_class_install_property (object_class, - PROP_HISTORY_LENGTH, - g_param_spec_uint ("history-length", - "Max History Length", - "Max History Length", - 0, - G_MAXUINT, - XED_HISTORY_ENTRY_HISTORY_LENGTH_DEFAULT, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + object_class->set_property = xed_history_entry_set_property; + object_class->get_property = xed_history_entry_get_property; + object_class->finalize = xed_history_entry_finalize; + object_class->dispose = xed_history_entry_dispose; - /* TODO: Add enable-completion property */ + g_object_class_install_property (object_class, + PROP_HISTORY_ID, + g_param_spec_string ("history-id", + "History ID", + "History ID", + NULL, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); - g_type_class_add_private (object_class, sizeof(XedHistoryEntryPrivate)); + g_object_class_install_property (object_class, + PROP_HISTORY_LENGTH, + g_param_spec_uint ("history-length", + "Max History Length", + "Max History Length", + 0, + G_MAXUINT, + XED_HISTORY_ENTRY_HISTORY_LENGTH_DEFAULT, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); + + /* TODO: Add enable-completion property */ + + g_type_class_add_private (object_class, sizeof(XedHistoryEntryPrivate)); } static GtkListStore * get_history_store (XedHistoryEntry *entry) { - GtkTreeModel *store; + GtkTreeModel *store; - store = gtk_combo_box_get_model (GTK_COMBO_BOX (entry)); - g_return_val_if_fail (GTK_IS_LIST_STORE (store), NULL); + store = gtk_combo_box_get_model (GTK_COMBO_BOX (entry)); + g_return_val_if_fail (GTK_IS_LIST_STORE (store), NULL); - return (GtkListStore *) store; + return (GtkListStore *) store; } -static GSList * -get_history_list (XedHistoryEntry *entry) +static gchar ** +get_history_items (XedHistoryEntry *entry) { - GtkListStore *store; - GtkTreeIter iter; - gboolean valid; - GSList *list = NULL; + GtkListStore *store; + GtkTreeIter iter; + GPtrArray *array; + gboolean valid; + gint n_children; + gint text_column; - store = get_history_store (entry); + store = get_history_store (entry); + text_column = gtk_combo_box_get_entry_text_column (GTK_COMBO_BOX (entry)); + valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter); + n_children = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL); + array = g_ptr_array_sized_new (n_children + 1); - valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), - &iter); + while (valid) + { + gchar *str; - while (valid) - { - gchar *str; + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, text_column, &str, -1); - gtk_tree_model_get (GTK_TREE_MODEL (store), - &iter, - 0, &str, - -1); + g_ptr_array_add (array, str); + valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter); + } - list = g_slist_prepend (list, str); + g_ptr_array_add (array, NULL); - valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), - &iter); - } - - return g_slist_reverse (list); + return (gchar **)g_ptr_array_free (array, FALSE); } static void xed_history_entry_save_history (XedHistoryEntry *entry) { - GSList *settings_items; + gchar **items; - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); + g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - settings_items = get_history_list (entry); + items = get_history_items (entry); - xed_prefs_manager_set_gslist (entry->priv->settings, - entry->priv->history_id, - settings_items); + g_settings_set_strv (entry->priv->settings, entry->priv->history_id, (const gchar * const *)items); - g_slist_foreach (settings_items, (GFunc) g_free, NULL); - g_slist_free (settings_items); + g_strfreev (items); } static gboolean -remove_item (GtkListStore *store, - const gchar *text) +remove_item (XedHistoryEntry *entry, + const gchar *text) { - GtkTreeIter iter; + GtkListStore *store; + GtkTreeIter iter; + gint text_column; - g_return_val_if_fail (text != NULL, FALSE); + g_return_val_if_fail (text != NULL, FALSE); - if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter)) - return FALSE; + store = get_history_store (entry); + text_column = gtk_combo_box_get_entry_text_column (GTK_COMBO_BOX (entry)); - do - { - gchar *item_text; + if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter)) + { + return FALSE; + } - gtk_tree_model_get (GTK_TREE_MODEL (store), - &iter, - 0, - &item_text, - -1); + do + { + gchar *item_text; - if (item_text != NULL && - strcmp (item_text, text) == 0) - { - gtk_list_store_remove (store, &iter); - g_free (item_text); - return TRUE; - } + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, text_column, &item_text, -1); - g_free (item_text); + if (item_text != NULL && strcmp (item_text, text) == 0) + { + gtk_list_store_remove (store, &iter); + g_free (item_text); + return TRUE; + } - } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter)); + g_free (item_text); - return FALSE; + } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter)); + + return FALSE; } static void clamp_list_store (GtkListStore *store, - guint max) + guint max) { - GtkTreePath *path; - GtkTreeIter iter; + GtkTreePath *path; + GtkTreeIter iter; - /* -1 because TreePath counts from 0 */ - path = gtk_tree_path_new_from_indices (max - 1, -1); + /* -1 because TreePath counts from 0 */ + path = gtk_tree_path_new_from_indices (max - 1, -1); - if (gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path)) - { - while (1) - { - if (!gtk_list_store_remove (store, &iter)) - break; - } - } + if (gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path)) + { + while (1) + { + if (!gtk_list_store_remove (store, &iter)) + { + break; + } + } + } - gtk_tree_path_free (path); + gtk_tree_path_free (path); } static void insert_history_item (XedHistoryEntry *entry, - const gchar *text, - gboolean prepend) + const gchar *text, + gboolean prepend) { - GtkListStore *store; - GtkTreeIter iter; + GtkListStore *store; - if (g_utf8_strlen (text, -1) <= MIN_ITEM_LEN) - return; - - store = get_history_store (entry); + if (g_utf8_strlen (text, -1) <= MIN_ITEM_LEN) + { + return; + } - /* remove the text from the store if it was already - * present. If it wasn't, clamp to max history - 1 - * before inserting the new row, otherwise appending - * would not work */ + store = get_history_store (entry); - if (!remove_item (store, text)) - clamp_list_store (store, - entry->priv->history_length - 1); + /* remove the text from the store if it was already + * present. If it wasn't, clamp to max history - 1 + * before inserting the new row, otherwise appending + * would not work */ - if (prepend) - gtk_list_store_insert (store, &iter, 0); - else - gtk_list_store_append (store, &iter); + if (!remove_item (entry, text)) + { + clamp_list_store (store, entry->priv->history_length - 1); + } - gtk_list_store_set (store, - &iter, - 0, - text, - -1); + if (prepend) + { + gtk_combo_box_text_prepend_text (GTK_COMBO_BOX_TEXT (entry), text); + } + else + { + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (entry), text); + } - xed_history_entry_save_history (entry); + xed_history_entry_save_history (entry); } void xed_history_entry_prepend_text (XedHistoryEntry *entry, - const gchar *text) + const gchar *text) { - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - g_return_if_fail (text != NULL); + g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); + g_return_if_fail (text != NULL); - insert_history_item (entry, text, TRUE); + insert_history_item (entry, text, TRUE); } void xed_history_entry_append_text (XedHistoryEntry *entry, - const gchar *text) + const gchar *text) { - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - g_return_if_fail (text != NULL); + g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); + g_return_if_fail (text != NULL); - insert_history_item (entry, text, FALSE); + insert_history_item (entry, text, FALSE); } static void xed_history_entry_load_history (XedHistoryEntry *entry) { - GSList *settings_items, *l; - GtkListStore *store; - GtkTreeIter iter; - guint i; + gchar **items; + gsize i; - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); + g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - store = get_history_store (entry); + items = g_settings_get_strv (entry->priv->settings, entry->priv->history_id); + i = 0; - settings_items = xed_prefs_manager_get_gslist (entry->priv->settings, - entry->priv->history_id); + gtk_combo_box_text_remove_all (GTK_COMBO_BOX_TEXT (entry)); - gtk_list_store_clear (store); + /* Now the default value is an empty string so we have to take care of it to not + add the empty string in the search list */ + while (items[i] != NULL && *items[i] != '\0' && i < entry->priv->history_length) + { + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (entry), items[i]); + i++; + } - for (l = settings_items, i = 0; - l != NULL && i < entry->priv->history_length; - l = l->next, i++) - { - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, - &iter, - 0, - l->data, - -1); - } - - g_slist_foreach (settings_items, (GFunc) g_free, NULL); - g_slist_free (settings_items); + g_strfreev (items); } void xed_history_entry_clear (XedHistoryEntry *entry) { - GtkListStore *store; + g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); + gtk_combo_box_text_remove_all (GTK_COMBO_BOX_TEXT (entry)); - store = get_history_store (entry); - gtk_list_store_clear (store); - - xed_history_entry_save_history (entry); + xed_history_entry_save_history (entry); } static void xed_history_entry_init (XedHistoryEntry *entry) { - XedHistoryEntryPrivate *priv; + XedHistoryEntryPrivate *priv; - priv = XED_HISTORY_ENTRY_GET_PRIVATE (entry); - entry->priv = priv; + priv = XED_HISTORY_ENTRY_GET_PRIVATE (entry); + entry->priv = priv; - priv->history_id = NULL; - priv->history_length = XED_HISTORY_ENTRY_HISTORY_LENGTH_DEFAULT; + priv->history_id = NULL; + priv->history_length = XED_HISTORY_ENTRY_HISTORY_LENGTH_DEFAULT; - priv->completion = NULL; + priv->completion = NULL; - priv->settings = g_settings_new (XED_SCHEMA); + priv->settings = g_settings_new ("org.x.editor.state.history-entry"); } void xed_history_entry_set_history_length (XedHistoryEntry *entry, - guint history_length) + guint history_length) { - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - g_return_if_fail (history_length > 0); + g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); + g_return_if_fail (history_length > 0); - entry->priv->history_length = history_length; + entry->priv->history_length = history_length; - /* TODO: update if we currently have more items than max */ + /* TODO: update if we currently have more items than max */ } guint xed_history_entry_get_history_length (XedHistoryEntry *entry) { - g_return_val_if_fail (XED_IS_HISTORY_ENTRY (entry), 0); + g_return_val_if_fail (XED_IS_HISTORY_ENTRY (entry), 0); - return entry->priv->history_length; -} - -gchar * -xed_history_entry_get_history_id (XedHistoryEntry *entry) -{ - g_return_val_if_fail (XED_IS_HISTORY_ENTRY (entry), NULL); - - return g_strdup (entry->priv->history_id); + return entry->priv->history_length; } void xed_history_entry_set_enable_completion (XedHistoryEntry *entry, - gboolean enable) + gboolean enable) { - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - - if (enable) - { - if (entry->priv->completion != NULL) - return; - - entry->priv->completion = gtk_entry_completion_new (); - gtk_entry_completion_set_model (entry->priv->completion, - GTK_TREE_MODEL (get_history_store (entry))); - - /* Use model column 0 as the text column */ - gtk_entry_completion_set_text_column (entry->priv->completion, 0); + g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - gtk_entry_completion_set_minimum_key_length (entry->priv->completion, - MIN_ITEM_LEN); + if (enable) + { + if (entry->priv->completion != NULL) + { + return; + } - gtk_entry_completion_set_popup_completion (entry->priv->completion, FALSE); - gtk_entry_completion_set_inline_completion (entry->priv->completion, TRUE); - - /* Assign the completion to the entry */ - gtk_entry_set_completion (GTK_ENTRY (xed_history_entry_get_entry(entry)), - entry->priv->completion); - } - else - { - if (entry->priv->completion == NULL) - return; + entry->priv->completion = gtk_entry_completion_new (); + gtk_entry_completion_set_model (entry->priv->completion, GTK_TREE_MODEL (get_history_store (entry))); - gtk_entry_set_completion (GTK_ENTRY (xed_history_entry_get_entry (entry)), - NULL); - - g_object_unref (entry->priv->completion); - - entry->priv->completion = NULL; - } + /* Use model column 0 as the text column */ + gtk_entry_completion_set_text_column (entry->priv->completion, 0); + + gtk_entry_completion_set_minimum_key_length (entry->priv->completion, MIN_ITEM_LEN); + + gtk_entry_completion_set_popup_completion (entry->priv->completion, FALSE); + gtk_entry_completion_set_inline_completion (entry->priv->completion, TRUE); + + /* Assign the completion to the entry */ + gtk_entry_set_completion (GTK_ENTRY (xed_history_entry_get_entry(entry)), entry->priv->completion); + } + else + { + if (entry->priv->completion == NULL) + { + return; + } + + gtk_entry_set_completion (GTK_ENTRY (xed_history_entry_get_entry (entry)), NULL); + + g_object_unref (entry->priv->completion); + + entry->priv->completion = NULL; + } } - + gboolean xed_history_entry_get_enable_completion (XedHistoryEntry *entry) { - g_return_val_if_fail (XED_IS_HISTORY_ENTRY (entry), FALSE); - - return entry->priv->completion != NULL; + g_return_val_if_fail (XED_IS_HISTORY_ENTRY (entry), FALSE); + + return entry->priv->completion != NULL; } GtkWidget * xed_history_entry_new (const gchar *history_id, - gboolean enable_completion) + gboolean enable_completion) { - GtkWidget *ret; - GtkListStore *store; + GtkWidget *ret; - g_return_val_if_fail (history_id != NULL, NULL); + g_return_val_if_fail (history_id != NULL, NULL); - /* Note that we are setting the model, so - * user must be careful to always manipulate - * data in the history through xed_history_entry_ - * functions. - */ + ret = g_object_new (XED_TYPE_HISTORY_ENTRY, + "has-entry", TRUE, + "entry-text-column", 0, + "id-column", 1, + "history-id", history_id, + NULL); - store = gtk_list_store_new (1, G_TYPE_STRING); + /* loading has to happen after the model + * has been set. However the model is not a + * G_PARAM_CONSTRUCT property of GtkComboBox + * so we cannot do this in the constructor. + * For now we simply do here since this widget is + * not bound to other programming languages. + * A maybe better alternative is to override the + * model property of combobox and mark CONTRUCT_ONLY. + * This would also ensure that the model cannot be + * set explicitely at a later time. + */ + xed_history_entry_load_history (XED_HISTORY_ENTRY (ret)); - ret = g_object_new (XED_TYPE_HISTORY_ENTRY, - "history-id", history_id, - "model", store, - "has-entry", TRUE, - "entry-text-column", 0, - NULL); + xed_history_entry_set_enable_completion (XED_HISTORY_ENTRY (ret), enable_completion); - g_object_unref (store); - - /* loading has to happen after the model - * has been set. However the model is not a - * G_PARAM_CONSTRUCT property of GtkComboBox - * so we cannot do this in the constructor. - * For now we simply do here since this widget is - * not bound to other programming languages. - * A maybe better alternative is to override the - * model property of combobox and mark CONTRUCT_ONLY. - * This would also ensure that the model cannot be - * set explicitely at a later time. - */ - xed_history_entry_load_history (XED_HISTORY_ENTRY (ret)); - - xed_history_entry_set_enable_completion (XED_HISTORY_ENTRY (ret), - enable_completion); - - return ret; + return ret; } /* * Utility function to get the editable text entry internal widget. - * I would prefer to not expose this implementation detail and - * simply make the XedHistoryEntry widget implement the + * I would prefer to not expose this implementation detail and + * simply make the XedHistoryEntry widget implement the * GtkEditable interface. Unfortunately both GtkEditable and * GtkComboBox have a "changed" signal and I am not sure how to * handle the conflict. @@ -546,54 +512,58 @@ xed_history_entry_new (const gchar *history_id, GtkWidget * xed_history_entry_get_entry (XedHistoryEntry *entry) { - g_return_val_if_fail (XED_IS_HISTORY_ENTRY (entry), NULL); + g_return_val_if_fail (XED_IS_HISTORY_ENTRY (entry), NULL); - return gtk_bin_get_child (GTK_BIN (entry)); + return gtk_bin_get_child (GTK_BIN (entry)); } static void escape_cell_data_func (GtkTreeViewColumn *col, - GtkCellRenderer *renderer, - GtkTreeModel *model, - GtkTreeIter *iter, - XedHistoryEntryEscapeFunc escape_func) + GtkCellRenderer *renderer, + GtkTreeModel *model, + GtkTreeIter *iter, + XedHistoryEntryEscapeFunc escape_func) { - gchar *str; - gchar *escaped; + gchar *str; + gchar *escaped; - gtk_tree_model_get (model, iter, 0, &str, -1); - escaped = escape_func (str); - g_object_set (renderer, "text", escaped, NULL); + gtk_tree_model_get (model, iter, 0, &str, -1); + escaped = escape_func (str); + g_object_set (renderer, "text", escaped, NULL); - g_free (str); - g_free (escaped); + g_free (str); + g_free (escaped); } void xed_history_entry_set_escape_func (XedHistoryEntry *entry, - XedHistoryEntryEscapeFunc escape_func) + XedHistoryEntryEscapeFunc escape_func) { - GList *cells; + GList *cells; - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); + g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (entry)); + cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (entry)); - /* We only have one cell renderer */ - g_return_if_fail (cells->data != NULL && cells->next == NULL); + /* We only have one cell renderer */ + g_return_if_fail (cells->data != NULL && cells->next == NULL); - if (escape_func != NULL) - gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (entry), - GTK_CELL_RENDERER (cells->data), - (GtkCellLayoutDataFunc) escape_cell_data_func, - escape_func, - NULL); - else - gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (entry), - GTK_CELL_RENDERER (cells->data), - NULL, - NULL, - NULL); + if (escape_func != NULL) + { + gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (entry), + GTK_CELL_RENDERER (cells->data), + (GtkCellLayoutDataFunc) escape_cell_data_func, + escape_func, + NULL); + } + else + { + gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (entry), + GTK_CELL_RENDERER (cells->data), + NULL, + NULL, + NULL); + } - g_list_free (cells); + g_list_free (cells); } diff --git a/xed/xed-history-entry.h b/xed/xed-history-entry.h index 0fa844c..ef7447f 100644 --- a/xed/xed-history-entry.h +++ b/xed/xed-history-entry.h @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2006. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2006. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -48,48 +48,41 @@ typedef struct _XedHistoryEntryPrivate XedHistoryEntryPrivate; struct _XedHistoryEntryClass { - GtkComboBoxTextClass parent_class; + GtkComboBoxTextClass parent_class; }; struct _XedHistoryEntry { - GtkComboBoxText parent_instance; + GtkComboBoxText parent_instance; - XedHistoryEntryPrivate *priv; + XedHistoryEntryPrivate *priv; }; -GType xed_history_entry_get_type (void) G_GNUC_CONST; +GType xed_history_entry_get_type (void) G_GNUC_CONST; -GtkWidget *xed_history_entry_new (const gchar *history_id, - gboolean enable_completion); +GtkWidget *xed_history_entry_new (const gchar *history_id, + gboolean enable_completion); -void xed_history_entry_prepend_text (XedHistoryEntry *entry, - const gchar *text); +void xed_history_entry_prepend_text (XedHistoryEntry *entry, + const gchar *text); +void xed_history_entry_append_text (XedHistoryEntry *entry, + const gchar *text); -void xed_history_entry_append_text (XedHistoryEntry *entry, - const gchar *text); +void xed_history_entry_clear (XedHistoryEntry *entry); -void xed_history_entry_clear (XedHistoryEntry *entry); +void xed_history_entry_set_history_length (XedHistoryEntry *entry, + guint max_saved); +guint xed_history_entry_get_history_length (XedHistoryEntry *gentry); -void xed_history_entry_set_history_length (XedHistoryEntry *entry, - guint max_saved); +void xed_history_entry_set_enable_completion (XedHistoryEntry *entry, + gboolean enable); +gboolean xed_history_entry_get_enable_completion (XedHistoryEntry *entry); -guint xed_history_entry_get_history_length (XedHistoryEntry *gentry); - -gchar *xed_history_entry_get_history_id (XedHistoryEntry *entry); - -void xed_history_entry_set_enable_completion - (XedHistoryEntry *entry, - gboolean enable); - -gboolean xed_history_entry_get_enable_completion - (XedHistoryEntry *entry); - -GtkWidget *xed_history_entry_get_entry (XedHistoryEntry *entry); +GtkWidget *xed_history_entry_get_entry (XedHistoryEntry *entry); typedef gchar * (* XedHistoryEntryEscapeFunc) (const gchar *str); -void xed_history_entry_set_escape_func (XedHistoryEntry *entry, - XedHistoryEntryEscapeFunc escape_func); +void xed_history_entry_set_escape_func (XedHistoryEntry *entry, + XedHistoryEntryEscapeFunc escape_func); G_END_DECLS diff --git a/xed/xed-io-error-message-area.c b/xed/xed-io-error-message-area.c index c4a2fae..0362f0f 100644 --- a/xed/xed-io-error-message-area.c +++ b/xed/xed-io-error-message-area.c @@ -42,10 +42,10 @@ #include #include +#include "xed-settings.h" #include "xed-utils.h" #include "xed-document.h" #include "xed-io-error-message-area.h" -#include "xed-prefs-manager.h" #include #define MAX_URI_IN_DIALOG_LENGTH 50 @@ -856,6 +856,8 @@ xed_no_backup_saving_error_message_area_new (GFile *location, gchar *full_formatted_uri; gchar *uri_for_display; gchar *temp_uri_for_display; + gboolean create_backup_copy; + GSettings *editor_settings; g_return_val_if_fail (G_IS_FILE (location), NULL); g_return_val_if_fail (error != NULL, NULL); @@ -893,9 +895,12 @@ xed_no_backup_saving_error_message_area_new (GFile *location, vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0); - // FIXME: review this messages + editor_settings = g_settings_new ("org.x.editor.preferences.editor"); + create_backup_copy = g_settings_get_boolean (editor_settings, XED_SETTINGS_CREATE_BACKUP_COPY); + g_object_unref (editor_settings); - if (xed_prefs_manager_get_create_backup_copy ()) + // FIXME: review this messages + if (create_backup_copy) { primary_text = g_strdup_printf (_("Could not create a backup file while saving %s"), uri_for_display); } diff --git a/xed/xed-language-manager.c b/xed/xed-language-manager.c index 0871708..6ae2e44 100644 --- a/xed/xed-language-manager.c +++ b/xed/xed-language-manager.c @@ -3,7 +3,7 @@ * xed-languages-manager.c * This file is part of xed * - * Copyright (C) 2003-2006 - Paolo Maggi + * Copyright (C) 2003-2006 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,14 +17,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 2003-2006. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 2003-2006. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id$ */ @@ -33,7 +33,6 @@ #include #include #include "xed-language-manager.h" -#include "xed-prefs-manager.h" #include "xed-utils.h" #include "xed-debug.h" diff --git a/xed/xed-notebook.c b/xed/xed-notebook.c index 0b21bc0..b0ee7c1 100644 --- a/xed/xed-notebook.c +++ b/xed/xed-notebook.c @@ -56,15 +56,16 @@ struct _XedNotebookPrivate { - GList *focused_pages; - gulong motion_notify_handler_id; - gint x_start; - gint y_start; - gint drag_in_progress : 1; - gint close_buttons_sensitive : 1; - gint tab_drag_and_drop_enabled : 1; - gint tab_scrolling_enabled : 1; - guint destroy_has_run : 1; + GSettings *ui_settings; + GList *focused_pages; + gulong motion_notify_handler_id; + gint x_start; + gint y_start; + gint drag_in_progress : 1; + gint close_buttons_sensitive : 1; + gint tab_drag_and_drop_enabled : 1; + gint tab_scrolling_enabled : 1; + guint destroy_has_run : 1; }; G_DEFINE_TYPE(XedNotebook, xed_notebook, GTK_TYPE_NOTEBOOK) @@ -115,6 +116,8 @@ xed_notebook_dispose (GObject *object) notebook->priv->destroy_has_run = TRUE; } + g_clear_object (¬ebook->priv->ui_settings); + G_OBJECT_CLASS (xed_notebook_parent_class)->dispose (object); } @@ -707,7 +710,8 @@ xed_notebook_init (XedNotebook *notebook) notebook->priv->close_buttons_sensitive = TRUE; notebook->priv->tab_drag_and_drop_enabled = TRUE; - notebook->priv->tab_scrolling_enabled = TRUE; + notebook->priv->ui_settings = g_settings_new ("org.x.editor.preferences.ui"); + notebook->priv->tab_scrolling_enabled = g_settings_get_boolean (notebook->priv->ui_settings, "enable-tab-scrolling"); gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE); // gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE); diff --git a/xed/xed-plugins-engine.c b/xed/xed-plugins-engine.c index d0a6caf..6b96972 100644 --- a/xed/xed-plugins-engine.c +++ b/xed/xed-plugins-engine.c @@ -40,8 +40,9 @@ #include "xed-plugins-engine.h" #include "xed-debug.h" #include "xed-app.h" -#include "xed-prefs-manager.h" #include "xed-dirs.h" +#include "xed-settings.h" +#include "xed-utils.h" G_DEFINE_TYPE (XedPluginsEngine, xed_plugins_engine, PEAS_TYPE_ENGINE) @@ -62,7 +63,7 @@ xed_plugins_engine_init (XedPluginsEngine *engine) engine->priv = G_TYPE_INSTANCE_GET_PRIVATE (engine, XED_TYPE_PLUGINS_ENGINE, XedPluginsEnginePrivate); - engine->priv->plugin_settings = g_settings_new (XED_SCHEMA); + engine->priv->plugin_settings = g_settings_new ("org.x.editor.plugins"); peas_engine_enable_loader (PEAS_ENGINE (engine), "python3"); @@ -111,8 +112,11 @@ xed_plugins_engine_init (XedPluginsEngine *engine) xed_dirs_get_xed_plugins_dir(), xed_dirs_get_xed_plugins_data_dir()); - g_settings_bind (engine->priv->plugin_settings, GPM_ACTIVE_PLUGINS, - engine, "loaded-plugins", G_SETTINGS_BIND_DEFAULT); + g_settings_bind (engine->priv->plugin_settings, + XED_SETTINGS_ACTIVE_PLUGINS, + engine, + "loaded-plugins", + G_SETTINGS_BIND_DEFAULT); } static void diff --git a/xed/xed-prefs-manager-app.c b/xed/xed-prefs-manager-app.c deleted file mode 100644 index 741b2c1..0000000 --- a/xed/xed-prefs-manager-app.c +++ /dev/null @@ -1,1345 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * xed-prefs-manager.c - * This file is part of xed - * - * Copyright (C) 2002-2005 Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2002-2003. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include -#include "xed-prefs-manager.h" -#include "xed-prefs-manager-private.h" -#include "xed-prefs-manager-app.h" -#include "xed-app.h" -#include "xed-debug.h" -#include "xed-view.h" -#include "xed-window.h" -#include "xed-notebook.h" -#include "xed-window-private.h" -#include "xed-plugins-engine.h" -#include "xed-style-scheme-manager.h" -#include "xed-dirs.h" - -static void xed_prefs_manager_editor_font_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_system_font_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_tabs_size_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_wrap_mode_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_line_numbers_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_auto_indent_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_undo_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_right_margin_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_smart_home_end_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_enable_tab_scrolling_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_hl_current_line_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_bracket_matching_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_syntax_hl_enable_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_search_hl_enable_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_source_style_scheme_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_max_recents_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -static void xed_prefs_manager_auto_save_changed (GSettings *settings, - gchar *key, - gpointer user_data); - -/* GUI state is serialized to a .desktop file, not in GSettings */ - -#define XED_STATE_DEFAULT_WINDOW_STATE 0 -#define XED_STATE_DEFAULT_WINDOW_WIDTH 650 -#define XED_STATE_DEFAULT_WINDOW_HEIGHT 500 -#define XED_STATE_DEFAULT_SIDE_PANEL_SIZE 200 -#define XED_STATE_DEFAULT_BOTTOM_PANEL_SIZE 140 - -#define XED_STATE_FILE_LOCATION "xed.ini" - -#define XED_STATE_WINDOW_GROUP "window" -#define XED_STATE_WINDOW_STATE "state" -#define XED_STATE_WINDOW_HEIGHT "height" -#define XED_STATE_WINDOW_WIDTH "width" -#define XED_STATE_SIDE_PANEL_SIZE "side_panel_size" -#define XED_STATE_BOTTOM_PANEL_SIZE "bottom_panel_size" -#define XED_STATE_SIDE_PANEL_ACTIVE_PAGE "side_panel_active_page" -#define XED_STATE_BOTTOM_PANEL_ACTIVE_PAGE "bottom_panel_active_page" - -#define XED_STATE_FILEFILTER_GROUP "filefilter" -#define XED_STATE_FILEFILTER_ID "id" - -static gint window_state = -1; -static gint window_height = -1; -static gint window_width = -1; -static gint side_panel_size = -1; -static gint bottom_panel_size = -1; -static gint side_panel_active_page = -1; -static gint bottom_panel_active_page = -1; -static gint active_file_filter = -1; - - -static gchar * -get_state_filename (void) -{ - gchar *config_dir; - gchar *filename = NULL; - - config_dir = xed_dirs_get_user_config_dir (); - - if (config_dir != NULL) - { - filename = g_build_filename (config_dir, XED_STATE_FILE_LOCATION, NULL); - g_free (config_dir); - } - - return filename; -} - -static GKeyFile * -get_xed_state_file (void) -{ - static GKeyFile *state_file = NULL; - - if (state_file == NULL) - { - gchar *filename; - GError *err = NULL; - - state_file = g_key_file_new (); - filename = get_state_filename (); - - if (!g_key_file_load_from_file (state_file, filename, G_KEY_FILE_NONE, &err)) - { - if (err->domain != G_FILE_ERROR || err->code != G_FILE_ERROR_NOENT) - { - g_warning ("Could not load xed state file: %s\n", err->message); - } - - g_error_free (err); - } - - g_free (filename); - } - - return state_file; -} - -static void -xed_state_get_int (const gchar *group, - const gchar *key, - gint defval, - gint *result) -{ - GKeyFile *state_file; - gint res; - GError *err = NULL; - - state_file = get_xed_state_file (); - res = g_key_file_get_integer (state_file, group, key, &err); - - if (err != NULL) - { - if ((err->domain != G_KEY_FILE_ERROR) || - ((err->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND && - err->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND))) - { - g_warning ("Could not get state value %s::%s : %s\n", group, key, err->message); - } - - *result = defval; - g_error_free (err); - } - else - { - *result = res; - } -} - -static void -xed_state_set_int (const gchar *group, - const gchar *key, - gint value) -{ - GKeyFile *state_file; - - state_file = get_xed_state_file (); - g_key_file_set_integer (state_file, group, key, value); -} - -static gboolean -xed_state_file_sync (void) -{ - GKeyFile *state_file; - gchar *config_dir; - gchar *filename = NULL; - gchar *content = NULL; - gsize length; - gint res; - GError *err = NULL; - gboolean ret = FALSE; - - state_file = get_xed_state_file (); - g_return_val_if_fail (state_file != NULL, FALSE); - - config_dir = xed_dirs_get_user_config_dir (); - if (config_dir == NULL) - { - g_warning ("Could not get config directory\n"); - return ret; - } - - res = g_mkdir_with_parents (config_dir, 0755); - if (res < 0) - { - g_warning ("Could not create config directory\n"); - goto out; - } - - content = g_key_file_to_data (state_file, &length, &err); - - if (err != NULL) - { - g_warning ("Could not get data from state file: %s\n", err->message); - goto out; - } - - if (content != NULL) - { - filename = get_state_filename (); - if (!g_file_set_contents (filename, content, length, &err)) - { - g_warning ("Could not write xed state file: %s\n", err->message); - goto out; - } - } - - ret = TRUE; - - out: - if (err != NULL) - { - g_error_free (err); - } - - g_free (config_dir); - g_free (filename); - g_free (content); - - return ret; -} - -/* Window state */ -gint -xed_prefs_manager_get_window_state (void) -{ - if (window_state == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_WINDOW_STATE, - XED_STATE_DEFAULT_WINDOW_STATE, - &window_state); - } - - return window_state; -} - -void -xed_prefs_manager_set_window_state (gint ws) -{ - g_return_if_fail (ws > -1); - - window_state = ws; - - xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_WINDOW_STATE, ws); -} - -gboolean -xed_prefs_manager_window_state_can_set (void) -{ - return TRUE; -} - -/* Window size */ -void -xed_prefs_manager_get_window_size (gint *width, - gint *height) -{ - g_return_if_fail (width != NULL && height != NULL); - - if (window_width == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_WINDOW_WIDTH, - XED_STATE_DEFAULT_WINDOW_WIDTH, - &window_width); - } - - if (window_height == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_WINDOW_HEIGHT, - XED_STATE_DEFAULT_WINDOW_HEIGHT, - &window_height); - } - - *width = window_width; - *height = window_height; -} - -void -xed_prefs_manager_get_default_window_size (gint *width, - gint *height) -{ - g_return_if_fail (width != NULL && height != NULL); - - *width = XED_STATE_DEFAULT_WINDOW_WIDTH; - *height = XED_STATE_DEFAULT_WINDOW_HEIGHT; -} - -void -xed_prefs_manager_set_window_size (gint width, - gint height) -{ - g_return_if_fail (width > -1 && height > -1); - - window_width = width; - window_height = height; - - xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_WINDOW_WIDTH, width); - xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_WINDOW_HEIGHT, height); -} - -gboolean -xed_prefs_manager_window_size_can_set (void) -{ - return TRUE; -} - -/* Side panel */ -gint -xed_prefs_manager_get_side_panel_size (void) -{ - if (side_panel_size == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_SIDE_PANEL_SIZE, - XED_STATE_DEFAULT_SIDE_PANEL_SIZE, - &side_panel_size); - } - - return side_panel_size; -} - -gint -xed_prefs_manager_get_default_side_panel_size (void) -{ - return XED_STATE_DEFAULT_SIDE_PANEL_SIZE; -} - -void -xed_prefs_manager_set_side_panel_size (gint ps) -{ - g_return_if_fail (ps > -1); - - if (side_panel_size == ps) - { - return; - } - - side_panel_size = ps; - xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_SIDE_PANEL_SIZE, ps); -} - -gboolean -xed_prefs_manager_side_panel_size_can_set (void) -{ - return TRUE; -} - -gint -xed_prefs_manager_get_side_panel_active_page (void) -{ - if (side_panel_active_page == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_SIDE_PANEL_ACTIVE_PAGE, - 0, - &side_panel_active_page); - } - - return side_panel_active_page; -} - -void -xed_prefs_manager_set_side_panel_active_page (gint id) -{ - if (side_panel_active_page == id) - { - return; - } - - side_panel_active_page = id; - xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_SIDE_PANEL_ACTIVE_PAGE, id); -} - -gboolean -xed_prefs_manager_side_panel_active_page_can_set (void) -{ - return TRUE; -} - -/* Bottom panel */ -gint -xed_prefs_manager_get_bottom_panel_size (void) -{ - if (bottom_panel_size == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_BOTTOM_PANEL_SIZE, - XED_STATE_DEFAULT_BOTTOM_PANEL_SIZE, - &bottom_panel_size); - } - - return bottom_panel_size; -} - -gint -xed_prefs_manager_get_default_bottom_panel_size (void) -{ - return XED_STATE_DEFAULT_BOTTOM_PANEL_SIZE; -} - -void -xed_prefs_manager_set_bottom_panel_size (gint ps) -{ - g_return_if_fail (ps > -1); - - if (bottom_panel_size == ps) - { - return; - } - - bottom_panel_size = ps; - xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_BOTTOM_PANEL_SIZE, ps); -} - -gboolean -xed_prefs_manager_bottom_panel_size_can_set (void) -{ - return TRUE; -} - -gint -xed_prefs_manager_get_bottom_panel_active_page (void) -{ - if (bottom_panel_active_page == -1) - { - xed_state_get_int (XED_STATE_WINDOW_GROUP, - XED_STATE_BOTTOM_PANEL_ACTIVE_PAGE, - 0, - &bottom_panel_active_page); - } - - return bottom_panel_active_page; -} - -void -xed_prefs_manager_set_bottom_panel_active_page (gint id) -{ - if (bottom_panel_active_page == id) - { - return; - } - - bottom_panel_active_page = id; - xed_state_set_int (XED_STATE_WINDOW_GROUP, XED_STATE_BOTTOM_PANEL_ACTIVE_PAGE, id); -} - -gboolean -xed_prefs_manager_bottom_panel_active_page_can_set (void) -{ - return TRUE; -} - -/* File filter */ -gint -xed_prefs_manager_get_active_file_filter (void) -{ - if (active_file_filter == -1) - { - xed_state_get_int (XED_STATE_FILEFILTER_GROUP, - XED_STATE_FILEFILTER_ID, - 0, - &active_file_filter); - } - - return active_file_filter; -} - -void -xed_prefs_manager_set_active_file_filter (gint id) -{ - g_return_if_fail (id >= 0); - - if (active_file_filter == id) - { - return; - } - - active_file_filter = id; - xed_state_set_int (XED_STATE_FILEFILTER_GROUP, XED_STATE_FILEFILTER_ID, id); -} - -gboolean -xed_prefs_manager_active_file_filter_can_set (void) -{ - return TRUE; -} - -/* Normal prefs are stored in GSettings */ - -gboolean -xed_prefs_manager_app_init (void) -{ - xed_debug (DEBUG_PREFS); - - g_return_val_if_fail (xed_prefs_manager == NULL, FALSE); - - xed_prefs_manager_init (); - - if (xed_prefs_manager != NULL) - { - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_USE_DEFAULT_FONT, - G_CALLBACK (xed_prefs_manager_editor_font_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_EDITOR_FONT, - G_CALLBACK (xed_prefs_manager_editor_font_changed), NULL); - - g_signal_connect (xed_prefs_manager->interface_settings, "changed::" GPM_SYSTEM_FONT, - G_CALLBACK (xed_prefs_manager_system_font_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_TABS_SIZE, - G_CALLBACK (xed_prefs_manager_tabs_size_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_INSERT_SPACES, - G_CALLBACK (xed_prefs_manager_tabs_size_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_WRAP_MODE, - G_CALLBACK (xed_prefs_manager_wrap_mode_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_DISPLAY_LINE_NUMBERS, - G_CALLBACK (xed_prefs_manager_line_numbers_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_AUTO_INDENT, - G_CALLBACK (xed_prefs_manager_auto_indent_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_UNDO_ACTIONS_LIMIT, - G_CALLBACK (xed_prefs_manager_undo_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_DISPLAY_RIGHT_MARGIN, - G_CALLBACK (xed_prefs_manager_right_margin_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_RIGHT_MARGIN_POSITION, - G_CALLBACK (xed_prefs_manager_right_margin_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_SMART_HOME_END, - G_CALLBACK (xed_prefs_manager_smart_home_end_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_ENABLE_TAB_SCROLLING, - G_CALLBACK (xed_prefs_manager_enable_tab_scrolling_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_HIGHLIGHT_CURRENT_LINE, - G_CALLBACK (xed_prefs_manager_hl_current_line_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_BRACKET_MATCHING, - G_CALLBACK (xed_prefs_manager_bracket_matching_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_SYNTAX_HL_ENABLE, - G_CALLBACK (xed_prefs_manager_syntax_hl_enable_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_SEARCH_HIGHLIGHTING_ENABLE, - G_CALLBACK (xed_prefs_manager_search_hl_enable_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_SOURCE_STYLE_SCHEME, - G_CALLBACK (xed_prefs_manager_source_style_scheme_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_MAX_RECENTS, - G_CALLBACK (xed_prefs_manager_max_recents_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_CREATE_BACKUP_COPY, - G_CALLBACK (xed_prefs_manager_auto_save_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_AUTO_SAVE_INTERVAL, - G_CALLBACK (xed_prefs_manager_auto_save_changed), NULL); - - g_signal_connect (xed_prefs_manager->settings, "changed::" GPM_WRITABLE_VFS_SCHEMES, - G_CALLBACK (xed_prefs_manager_auto_save_changed), NULL); - } - - return xed_prefs_manager != NULL; -} - -/* This function must be called before exiting xed */ -void -xed_prefs_manager_app_shutdown (void) -{ - xed_debug (DEBUG_PREFS); - - xed_prefs_manager_shutdown (); - - xed_state_file_sync (); -} - - -static void -xed_prefs_manager_editor_font_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - GList *views; - GList *l; - gchar *font = NULL; - gboolean def = TRUE; - gint ts; - - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_USE_DEFAULT_FONT) == 0) - { - def = g_settings_get_boolean (settings, key); - - if (def) - { - font = xed_prefs_manager_get_system_font (); - } - else - { - font = xed_prefs_manager_get_editor_font (); - } - } - else if (strcmp (key, GPM_EDITOR_FONT) == 0) - { - font = g_settings_get_string (settings, key); - def = xed_prefs_manager_get_use_default_font (); - } - else - { - return; - } - - g_return_if_fail (font != NULL); - - ts = xed_prefs_manager_get_tabs_size (); - - views = xed_app_get_views (xed_app_get_default ()); - l = views; - - while (l != NULL) - { - /* Note: we use def=FALSE to avoid XedView to query GSettings */ - xed_view_set_font (XED_VIEW (l->data), FALSE, font); - gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); - - l = l->next; - } - - g_list_free (views); - g_free (font); -} - -static void -xed_prefs_manager_system_font_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - GList *views; - GList *l; - gchar *font; - gint ts; - - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_SYSTEM_FONT) != 0) - { - return; - } - - if (!xed_prefs_manager_get_use_default_font ()) - { - return; - } - - font = g_settings_get_string (settings, key); - - ts = xed_prefs_manager_get_tabs_size (); - - views = xed_app_get_views (xed_app_get_default ()); - l = views; - - while (l != NULL) - { - /* Note: we use def=FALSE to avoid XedView to query GSettings */ - xed_view_set_font (XED_VIEW (l->data), FALSE, font); - - gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); - l = l->next; - } - - g_list_free (views); - g_free (font); -} - -static void -xed_prefs_manager_tabs_size_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_TABS_SIZE) == 0) - { - gint tab_width; - GList *views; - GList *l; - - tab_width = g_settings_get_int (settings, key); - tab_width = CLAMP (tab_width, 1, 24); - - views = xed_app_get_views (xed_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), tab_width); - l = l->next; - } - - g_list_free (views); - } - else if (strcmp (key, GPM_INSERT_SPACES) == 0) - { - gboolean enable; - GList *views; - GList *l; - - enable = g_settings_get_boolean (settings, key); - - views = xed_app_get_views (xed_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_insert_spaces_instead_of_tabs (GTK_SOURCE_VIEW (l->data), enable); - l = l->next; - } - - g_list_free (views); - } -} - -static GtkWrapMode -get_wrap_mode_from_string (const gchar* str) -{ - GtkWrapMode res; - - g_return_val_if_fail (str != NULL, GTK_WRAP_WORD); - - if (strcmp (str, "GTK_WRAP_NONE") == 0) - { - res = GTK_WRAP_NONE; - } - else - { - if (strcmp (str, "GTK_WRAP_CHAR") == 0) - { - res = GTK_WRAP_CHAR; - } - else - { - res = GTK_WRAP_WORD; - } - } - - return res; -} - -static void -xed_prefs_manager_wrap_mode_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_WRAP_MODE) == 0) - { - GtkWrapMode wrap_mode; - GList *views; - GList *l; - - wrap_mode = get_wrap_mode_from_string (g_settings_get_string(settings, key)); - - views = xed_app_get_views (xed_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (l->data), wrap_mode); - l = l->next; - } - - g_list_free (views); - } -} - -static void -xed_prefs_manager_line_numbers_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_DISPLAY_LINE_NUMBERS) == 0) - { - gboolean dln; - GList *views; - GList *l; - - dln = g_settings_get_boolean (settings, key); - - views = xed_app_get_views (xed_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (l->data), dln); - l = l->next; - } - - g_list_free (views); - } -} - -static void -xed_prefs_manager_hl_current_line_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_HIGHLIGHT_CURRENT_LINE) == 0) - { - gboolean hl; - GList *views; - GList *l; - - hl = g_settings_get_boolean (settings, key); - - views = xed_app_get_views (xed_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (l->data), hl); - l = l->next; - } - - g_list_free (views); - } -} - -static void -xed_prefs_manager_bracket_matching_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_BRACKET_MATCHING) == 0) - { - gboolean enable; - GList *docs; - GList *l; - - enable = g_settings_get_boolean (settings, key); - - docs = xed_app_get_documents (xed_app_get_default ()); - l = docs; - - while (l != NULL) - { - gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (l->data), enable); - l = l->next; - } - - g_list_free (docs); - } -} - -static void -xed_prefs_manager_auto_indent_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_AUTO_INDENT) == 0) - { - gboolean enable; - GList *views; - GList *l; - - enable = g_settings_get_boolean (settings, key); - - views = xed_app_get_views (xed_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (l->data), enable); - l = l->next; - } - - g_list_free (views); - } -} - -static void -xed_prefs_manager_undo_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_UNDO_ACTIONS_LIMIT) == 0) - { - gint ul; - GList *docs; - GList *l; - - ul = g_settings_get_int (settings, key); - - ul = CLAMP (ul, -1, 250); - - docs = xed_app_get_documents (xed_app_get_default ()); - l = docs; - - while (l != NULL) - { - gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (l->data), ul); - l = l->next; - } - - g_list_free (docs); - } -} - -static void -xed_prefs_manager_right_margin_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_RIGHT_MARGIN_POSITION) == 0) - { - gint pos; - GList *views; - GList *l; - - pos = g_settings_get_int (settings, key); - - pos = CLAMP (pos, 1, 160); - - views = xed_app_get_views (xed_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_right_margin_position (GTK_SOURCE_VIEW (l->data), pos); - l = l->next; - } - - g_list_free (views); - } - else if (strcmp (key, GPM_DISPLAY_RIGHT_MARGIN) == 0) - { - gboolean display; - GList *views; - GList *l; - - display = g_settings_get_boolean (settings, key); - - views = xed_app_get_views (xed_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_show_right_margin (GTK_SOURCE_VIEW (l->data), display); - l = l->next; - } - - g_list_free (views); - } -} - -static GtkSourceSmartHomeEndType -get_smart_home_end_from_string (const gchar *str) -{ - GtkSourceSmartHomeEndType res; - - g_return_val_if_fail (str != NULL, GTK_SOURCE_SMART_HOME_END_AFTER); - - if (strcmp (str, "DISABLED") == 0) - { - res = GTK_SOURCE_SMART_HOME_END_DISABLED; - } - else if (strcmp (str, "BEFORE") == 0) - { - res = GTK_SOURCE_SMART_HOME_END_BEFORE; - } - else if (strcmp (str, "ALWAYS") == 0) - { - res = GTK_SOURCE_SMART_HOME_END_ALWAYS; - } - else - { - res = GTK_SOURCE_SMART_HOME_END_AFTER; - } - - return res; -} - -static void -xed_prefs_manager_smart_home_end_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_SMART_HOME_END) == 0) - { - GtkSourceSmartHomeEndType smart_he; - GList *views; - GList *l; - - smart_he = get_smart_home_end_from_string (g_settings_get_string (settings, key)); - - views = xed_app_get_views (xed_app_get_default ()); - l = views; - - while (l != NULL) - { - gtk_source_view_set_smart_home_end (GTK_SOURCE_VIEW (l->data), smart_he); - l = l->next; - } - - g_list_free (views); - } -} - -static void -xed_prefs_manager_enable_tab_scrolling_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_ENABLE_TAB_SCROLLING) == 0) - { - gboolean enable; - const GList *windows; - - enable = g_settings_get_boolean (settings, key); - - windows = xed_app_get_windows (xed_app_get_default ()); - while (windows != NULL) - { - XedNotebook *notebook; - - notebook = XED_NOTEBOOK (_xed_window_get_notebook (windows->data)); - xed_notebook_set_tab_scrolling_enabled (notebook, enable); - - windows = g_list_next (windows); - } - } -} - -static void -xed_prefs_manager_syntax_hl_enable_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_SYNTAX_HL_ENABLE) == 0) - { - gboolean enable; - GList *docs; - GList *l; - const GList *windows; - - enable = g_settings_get_boolean (settings, key); - - docs = xed_app_get_documents (xed_app_get_default ()); - l = docs; - - while (l != NULL) - { - g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); - - gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (l->data), enable); - l = l->next; - } - - g_list_free (docs); - - /* update the sensitivity of the Higlight Mode menu item */ - windows = xed_app_get_windows (xed_app_get_default ()); - while (windows != NULL) - { - GtkUIManager *ui; - GtkAction *a; - - ui = xed_window_get_ui_manager (XED_WINDOW (windows->data)); - a = gtk_ui_manager_get_action (ui, "/MenuBar/ViewMenu/ViewHighlightModeMenu"); - gtk_action_set_sensitive (a, enable); - - windows = g_list_next (windows); - } - } -} - -static void -xed_prefs_manager_search_hl_enable_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_SEARCH_HIGHLIGHTING_ENABLE) == 0) - { - gboolean enable; - GList *docs; - GList *l; - - enable = g_settings_get_boolean (settings, key); - - docs = xed_app_get_documents (xed_app_get_default ()); - l = docs; - - while (l != NULL) - { - g_return_if_fail (XED_IS_DOCUMENT (l->data)); - - xed_document_set_enable_search_highlighting (XED_DOCUMENT (l->data), enable); - l = l->next; - } - - g_list_free (docs); - } -} - -static void -xed_prefs_manager_source_style_scheme_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_SOURCE_STYLE_SCHEME) == 0) - { - static gchar *old_scheme = NULL; - gchar *scheme; - GtkSourceStyleScheme *style; - GList *docs; - GList *l; - - scheme = g_settings_get_string (settings, key); - - if (old_scheme != NULL && (strcmp (scheme, old_scheme) == 0)) - { - return; - } - - g_free (old_scheme); - old_scheme = scheme; - - style = gtk_source_style_scheme_manager_get_scheme (xed_get_style_scheme_manager (), scheme); - - if (style == NULL) - { - g_warning ("Default style scheme '%s' not found, falling back to 'classic'", scheme); - - style = gtk_source_style_scheme_manager_get_scheme (xed_get_style_scheme_manager (), "classic"); - - if (style == NULL) - { - g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation."); - return; - } - } - - docs = xed_app_get_documents (xed_app_get_default ()); - for (l = docs; l != NULL; l = l->next) - { - g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); - - gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (l->data), style); - } - - g_list_free (docs); - } -} - -static void -xed_prefs_manager_max_recents_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_MAX_RECENTS) == 0) - { - gint max; - - max = g_settings_get_int (settings, key); - - if (max < 0) - { - max = GPM_DEFAULT_MAX_RECENTS; - } - - /* FIXME: we have no way at the moment to trigger the - * update of the inline recents in the File menu */ - } -} - -static void -xed_prefs_manager_auto_save_changed (GSettings *settings, - gchar *key, - gpointer user_data) -{ - GList *docs; - GList *l; - - xed_debug (DEBUG_PREFS); - - if (strcmp (key, GPM_AUTO_SAVE) == 0) - { - gboolean auto_save; - - auto_save = g_settings_get_boolean (settings, key); - - docs = xed_app_get_documents (xed_app_get_default ()); - l = docs; - - while (l != NULL) - { - XedDocument *doc = XED_DOCUMENT (l->data); - XedTab *tab = xed_tab_get_from_document (doc); - - xed_tab_set_auto_save_enabled (tab, auto_save); - - l = l->next; - } - - g_list_free (docs); - } - else if (strcmp (key, GPM_AUTO_SAVE_INTERVAL) == 0) - { - gint auto_save_interval; - - auto_save_interval = g_settings_get_int (settings, key); - - if (auto_save_interval <= 0) - { - auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL; - } - - docs = xed_app_get_documents (xed_app_get_default ()); - l = docs; - - while (l != NULL) - { - XedDocument *doc = XED_DOCUMENT (l->data); - XedTab *tab = xed_tab_get_from_document (doc); - - xed_tab_set_auto_save_interval (tab, auto_save_interval); - - l = l->next; - } - - g_list_free (docs); - } -} diff --git a/xed/xed-prefs-manager-app.h b/xed/xed-prefs-manager-app.h deleted file mode 100644 index 817dc51..0000000 --- a/xed/xed-prefs-manager-app.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * xed-prefs-manager-app.h - * This file is part of xed - * - * Copyright (C) 2002-2005 Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2002-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - * - */ - -#ifndef __XED_PREFS_MANAGER_APP_H__ -#define __XED_PREFS_MANAGER_APP_H__ - -#include -#include - -/** LIFE CYCLE MANAGEMENT FUNCTIONS **/ - -gboolean xed_prefs_manager_app_init (void); - -/* This function must be called before exiting xed */ -void xed_prefs_manager_app_shutdown (void); - - -/* Window state */ -gint xed_prefs_manager_get_window_state (void); -void xed_prefs_manager_set_window_state (gint ws); -gboolean xed_prefs_manager_window_state_can_set (void); - -/* Window size */ -void xed_prefs_manager_get_window_size (gint *width, - gint *height); -void xed_prefs_manager_get_default_window_size (gint *width, - gint *height); -void xed_prefs_manager_set_window_size (gint width, - gint height); -gboolean xed_prefs_manager_window_size_can_set (void); - -/* Side panel */ -gint xed_prefs_manager_get_side_panel_size (void); -gint xed_prefs_manager_get_default_side_panel_size(void); -void xed_prefs_manager_set_side_panel_size (gint ps); -gboolean xed_prefs_manager_side_panel_size_can_set (void); -gint xed_prefs_manager_get_side_panel_active_page (void); -void xed_prefs_manager_set_side_panel_active_page (gint id); -gboolean xed_prefs_manager_side_panel_active_page_can_set (void); - -/* Bottom panel */ -gint xed_prefs_manager_get_bottom_panel_size (void); -gint xed_prefs_manager_get_default_bottom_panel_size(void); -void xed_prefs_manager_set_bottom_panel_size (gint ps); -gboolean xed_prefs_manager_bottom_panel_size_can_set (void); -gint xed_prefs_manager_get_bottom_panel_active_page (void); -void xed_prefs_manager_set_bottom_panel_active_page (gint id); -gboolean xed_prefs_manager_bottom_panel_active_page_can_set (void); - -/* File filter */ -gint xed_prefs_manager_get_active_file_filter (void); -void xed_prefs_manager_set_active_file_filter (gint id); -gboolean xed_prefs_manager_active_file_filter_can_set (void); - - -#endif /* __XED_PREFS_MANAGER_APP_H__ */ diff --git a/xed/xed-prefs-manager.c b/xed/xed-prefs-manager.c deleted file mode 100644 index 1834341..0000000 --- a/xed/xed-prefs-manager.c +++ /dev/null @@ -1,849 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * xed-prefs-manager.c - * This file is part of xed - * - * Copyright (C) 2002 Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2002. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include -#include - -#include "xed-prefs-manager.h" -#include "xed-prefs-manager-private.h" -#include "xed-debug.h" -#include "xed-encodings.h" -#include "xed-utils.h" - -#define DEFINE_BOOL_PREF(name, key) gboolean \ -xed_prefs_manager_get_ ## name (void) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - return xed_prefs_manager_get_bool (key); \ -} \ - \ -void \ -xed_prefs_manager_set_ ## name (gboolean v) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - xed_prefs_manager_set_bool (key, \ - v); \ -} \ - \ -gboolean \ -xed_prefs_manager_ ## name ## _can_set (void) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - return xed_prefs_manager_key_is_writable (key); \ -} - - - -#define DEFINE_INT_PREF(name, key) gint \ -xed_prefs_manager_get_ ## name (void) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - return xed_prefs_manager_get_int (key); \ -} \ - \ -void \ -xed_prefs_manager_set_ ## name (gint v) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - xed_prefs_manager_set_int (key, \ - v); \ -} \ - \ -gboolean \ -xed_prefs_manager_ ## name ## _can_set (void) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - return xed_prefs_manager_key_is_writable (key); \ -} - - - -#define DEFINE_STRING_PREF(name, key) gchar* \ -xed_prefs_manager_get_ ## name (void) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - return xed_prefs_manager_get_string (key); \ -} \ - \ -void \ -xed_prefs_manager_set_ ## name (const gchar* v) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - xed_prefs_manager_set_string (key, \ - v); \ -} \ - \ -gboolean \ -xed_prefs_manager_ ## name ## _can_set (void) \ -{ \ - xed_debug (DEBUG_PREFS); \ - \ - return xed_prefs_manager_key_is_writable (key); \ -} - - -XedPrefsManager *xed_prefs_manager = NULL; - - -static GtkWrapMode get_wrap_mode_from_string (const gchar* str); - -static gboolean xed_prefs_manager_get_bool (const gchar* key); - -static gint xed_prefs_manager_get_int (const gchar* key); - -static gchar *xed_prefs_manager_get_string (const gchar* key); - - -gboolean -xed_prefs_manager_init (void) -{ - xed_debug (DEBUG_PREFS); - - if (xed_prefs_manager == NULL) - { - xed_prefs_manager = g_new0 (XedPrefsManager, 1); - xed_prefs_manager->settings = g_settings_new (XED_SCHEMA); - xed_prefs_manager->interface_settings = g_settings_new (GPM_INTERFACE_SCHEMA); - } - - return xed_prefs_manager != NULL; -} - -void -xed_prefs_manager_shutdown (void) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (xed_prefs_manager != NULL); - - g_object_unref (xed_prefs_manager->settings); - xed_prefs_manager->settings = NULL; - g_object_unref (xed_prefs_manager->interface_settings); - xed_prefs_manager->interface_settings = NULL; -} - -static gboolean -xed_prefs_manager_get_bool (const gchar* key) -{ - xed_debug (DEBUG_PREFS); - - return g_settings_get_boolean (xed_prefs_manager->settings, key); -} - -static gint -xed_prefs_manager_get_int (const gchar* key) -{ - xed_debug (DEBUG_PREFS); - - return g_settings_get_int (xed_prefs_manager->settings, key); -} - -static gchar * -xed_prefs_manager_get_string (const gchar* key) -{ - xed_debug (DEBUG_PREFS); - - return g_settings_get_string (xed_prefs_manager->settings, key); -} - -static void -xed_prefs_manager_set_bool (const gchar* key, gboolean value) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (g_settings_is_writable ( - xed_prefs_manager->settings, key)); - - g_settings_set_boolean (xed_prefs_manager->settings, key, value); -} - -static void -xed_prefs_manager_set_int (const gchar* key, gint value) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (g_settings_is_writable ( - xed_prefs_manager->settings, key)); - - g_settings_set_int (xed_prefs_manager->settings, key, value); -} - -static void -xed_prefs_manager_set_string (const gchar* key, const gchar* value) -{ - xed_debug (DEBUG_PREFS); - - g_return_if_fail (value != NULL); - - g_return_if_fail (g_settings_is_writable ( - xed_prefs_manager->settings, key)); - - g_settings_set_string (xed_prefs_manager->settings, key, value); -} - -static gboolean -xed_prefs_manager_key_is_writable (const gchar* key) -{ - xed_debug (DEBUG_PREFS); - - g_return_val_if_fail (xed_prefs_manager != NULL, FALSE); - g_return_val_if_fail (xed_prefs_manager->settings != NULL, FALSE); - - return g_settings_is_writable (xed_prefs_manager->settings, key); -} - -/* Use default font */ -DEFINE_BOOL_PREF (use_default_font, - GPM_USE_DEFAULT_FONT) - -/* Editor font */ -DEFINE_STRING_PREF (editor_font, - GPM_EDITOR_FONT) - -/* System font */ -gchar * -xed_prefs_manager_get_system_font (void) -{ - xed_debug (DEBUG_PREFS); - - return g_settings_get_string (xed_prefs_manager->interface_settings, - GPM_SYSTEM_FONT); -} - -/* Create backup copy */ -DEFINE_BOOL_PREF (create_backup_copy, - GPM_CREATE_BACKUP_COPY) - -/* Auto save */ -DEFINE_BOOL_PREF (auto_save, - GPM_AUTO_SAVE) - -/* Auto save interval */ -DEFINE_INT_PREF (auto_save_interval, - GPM_AUTO_SAVE_INTERVAL) - - -/* Undo actions limit: if < 1 then no limits */ -DEFINE_INT_PREF (undo_actions_limit, - GPM_UNDO_ACTIONS_LIMIT) - -static GtkWrapMode -get_wrap_mode_from_string (const gchar* str) -{ - GtkWrapMode res; - - g_return_val_if_fail (str != NULL, GTK_WRAP_WORD); - - if (strcmp (str, "GTK_WRAP_NONE") == 0) - res = GTK_WRAP_NONE; - else - { - if (strcmp (str, "GTK_WRAP_CHAR") == 0) - res = GTK_WRAP_CHAR; - else - res = GTK_WRAP_WORD; - } - - return res; -} - -/* Wrap mode */ -GtkWrapMode -xed_prefs_manager_get_wrap_mode (void) -{ - gchar *str; - GtkWrapMode res; - - xed_debug (DEBUG_PREFS); - - str = xed_prefs_manager_get_string (GPM_WRAP_MODE); - - res = get_wrap_mode_from_string (str); - - g_free (str); - - return res; -} - -void -xed_prefs_manager_set_wrap_mode (GtkWrapMode wp) -{ - const gchar * str; - - xed_debug (DEBUG_PREFS); - - switch (wp) - { - case GTK_WRAP_NONE: - str = "GTK_WRAP_NONE"; - break; - - case GTK_WRAP_CHAR: - str = "GTK_WRAP_CHAR"; - break; - - default: /* GTK_WRAP_WORD */ - str = "GTK_WRAP_WORD"; - } - - xed_prefs_manager_set_string (GPM_WRAP_MODE, - str); -} - -gboolean -xed_prefs_manager_wrap_mode_can_set (void) -{ - xed_debug (DEBUG_PREFS); - - return xed_prefs_manager_key_is_writable (GPM_WRAP_MODE); -} - - -/* Tabs size */ -DEFINE_INT_PREF (tabs_size, - GPM_TABS_SIZE) - -/* Insert spaces */ -DEFINE_BOOL_PREF (insert_spaces, - GPM_INSERT_SPACES) - -/* Auto indent */ -DEFINE_BOOL_PREF (auto_indent, - GPM_AUTO_INDENT) - -/* Display line numbers */ -DEFINE_BOOL_PREF (display_line_numbers, - GPM_DISPLAY_LINE_NUMBERS) - -/* Toolbar visibility */ -DEFINE_BOOL_PREF (toolbar_visible, - GPM_TOOLBAR_VISIBLE) - -/* Statusbar visiblity */ -DEFINE_BOOL_PREF (statusbar_visible, - GPM_STATUSBAR_VISIBLE) - -/* Side Pane visiblity */ -DEFINE_BOOL_PREF (side_pane_visible, - GPM_SIDE_PANE_VISIBLE) - -/* Bottom Panel visiblity */ -DEFINE_BOOL_PREF (bottom_panel_visible, - GPM_BOTTOM_PANEL_VISIBLE) - -/* Tab scrolling */ -DEFINE_BOOL_PREF (enable_tab_scrolling, GPM_ENABLE_TAB_SCROLLING) - -/* Print syntax highlighting */ -DEFINE_BOOL_PREF (print_syntax_hl, - GPM_PRINT_SYNTAX) - -/* Print header */ -DEFINE_BOOL_PREF (print_header, - GPM_PRINT_HEADER) - - -/* Print Wrap mode */ -GtkWrapMode -xed_prefs_manager_get_print_wrap_mode (void) -{ - gchar *str; - GtkWrapMode res; - - xed_debug (DEBUG_PREFS); - - str = xed_prefs_manager_get_string (GPM_PRINT_WRAP_MODE); - - if (strcmp (str, "GTK_WRAP_NONE") == 0) - res = GTK_WRAP_NONE; - else - { - if (strcmp (str, "GTK_WRAP_WORD") == 0) - res = GTK_WRAP_WORD; - else - res = GTK_WRAP_CHAR; - } - - g_free (str); - - return res; -} - -void -xed_prefs_manager_set_print_wrap_mode (GtkWrapMode pwp) -{ - const gchar *str; - - xed_debug (DEBUG_PREFS); - - switch (pwp) - { - case GTK_WRAP_NONE: - str = "GTK_WRAP_NONE"; - break; - - case GTK_WRAP_WORD: - str = "GTK_WRAP_WORD"; - break; - - default: /* GTK_WRAP_CHAR */ - str = "GTK_WRAP_CHAR"; - } - - xed_prefs_manager_set_string (GPM_PRINT_WRAP_MODE, str); -} - -gboolean -xed_prefs_manager_print_wrap_mode_can_set (void) -{ - xed_debug (DEBUG_PREFS); - - return xed_prefs_manager_key_is_writable (GPM_PRINT_WRAP_MODE); -} - -/* Print line numbers */ -DEFINE_INT_PREF (print_line_numbers, - GPM_PRINT_LINE_NUMBERS) - -/* Printing fonts */ -DEFINE_STRING_PREF (print_font_body, - GPM_PRINT_FONT_BODY) - -static gchar * -xed_prefs_manager_get_default_string_value (const gchar *key) -{ - gchar *font = NULL; - g_settings_delay (xed_prefs_manager->settings); - g_settings_reset (xed_prefs_manager->settings, key); - font = g_settings_get_string (xed_prefs_manager->settings, key); - g_settings_revert (xed_prefs_manager->settings); - return font; -} - -gchar * -xed_prefs_manager_get_default_print_font_body (void) -{ - return xed_prefs_manager_get_default_string_value (GPM_PRINT_FONT_BODY); -} - -DEFINE_STRING_PREF (print_font_header, - GPM_PRINT_FONT_HEADER) - -gchar * -xed_prefs_manager_get_default_print_font_header (void) -{ - return xed_prefs_manager_get_default_string_value (GPM_PRINT_FONT_HEADER); -} - -DEFINE_STRING_PREF (print_font_numbers, - GPM_PRINT_FONT_NUMBERS) - -gchar * -xed_prefs_manager_get_default_print_font_numbers (void) -{ - return xed_prefs_manager_get_default_string_value (GPM_PRINT_FONT_NUMBERS); -} - -/* Max number of files in "Recent Files" menu. - * This is configurable only using gsettings, dconf or dconf-editor - */ -gint -xed_prefs_manager_get_max_recents (void) -{ - xed_debug (DEBUG_PREFS); - - return xed_prefs_manager_get_int (GPM_MAX_RECENTS); - -} - -/* GSettings/GSList utility functions from mate-panel */ - -GSList* -xed_prefs_manager_get_gslist (GSettings *settings, const gchar *key) -{ - gchar **array; - GSList *list = NULL; - gint i; - array = g_settings_get_strv (settings, key); - if (array != NULL) { - for (i = 0; array[i]; i++) { - list = g_slist_append (list, g_strdup (array[i])); - } - } - g_strfreev (array); - return list; -} - -void -xed_prefs_manager_set_gslist (GSettings *settings, const gchar *key, GSList *list) -{ - GArray *array; - GSList *l; - array = g_array_new (TRUE, TRUE, sizeof (gchar *)); - for (l = list; l; l = l->next) { - array = g_array_append_val (array, l->data); - } - g_settings_set_strv (settings, key, (const gchar **) array->data); - g_array_free (array, TRUE); -} - - -/* Encodings */ - -static gboolean -data_exists (GSList *list, - const gpointer data) -{ - while (list != NULL) - { - if (list->data == data) - return TRUE; - - list = g_slist_next (list); - } - - return FALSE; -} - -GSList * -xed_prefs_manager_get_auto_detected_encodings (void) -{ - GSList *strings; - GSList *res = NULL; - - xed_debug (DEBUG_PREFS); - - g_return_val_if_fail (xed_prefs_manager != NULL, NULL); - g_return_val_if_fail (xed_prefs_manager->settings != NULL, NULL); - - strings = xed_prefs_manager_get_gslist (xed_prefs_manager->settings, GPM_AUTO_DETECTED_ENCODINGS); - - if (strings != NULL) - { - GSList *tmp; - const XedEncoding *enc; - - tmp = strings; - - while (tmp) - { - const char *charset = tmp->data; - - if (strcmp (charset, "CURRENT") == 0) - g_get_charset (&charset); - - g_return_val_if_fail (charset != NULL, NULL); - enc = xed_encoding_get_from_charset (charset); - - if (enc != NULL) - { - if (!data_exists (res, (gpointer)enc)) - res = g_slist_prepend (res, (gpointer)enc); - - } - - tmp = g_slist_next (tmp); - } - - g_slist_foreach (strings, (GFunc) g_free, NULL); - g_slist_free (strings); - - res = g_slist_reverse (res); - } - - xed_debug_message (DEBUG_PREFS, "Done"); - - return res; -} - -GSList * -xed_prefs_manager_get_shown_in_menu_encodings (void) -{ - GSList *strings; - GSList *res = NULL; - - xed_debug (DEBUG_PREFS); - - g_return_val_if_fail (xed_prefs_manager != NULL, NULL); - g_return_val_if_fail (xed_prefs_manager->settings != NULL, NULL); - - strings = xed_prefs_manager_get_gslist (xed_prefs_manager->settings, GPM_SHOWN_IN_MENU_ENCODINGS); - - if (strings != NULL) - { - GSList *tmp; - const XedEncoding *enc; - - tmp = strings; - - while (tmp) - { - const char *charset = tmp->data; - - if (strcmp (charset, "CURRENT") == 0) - g_get_charset (&charset); - - g_return_val_if_fail (charset != NULL, NULL); - enc = xed_encoding_get_from_charset (charset); - - if (enc != NULL) - { - if (!data_exists (res, (gpointer)enc)) - res = g_slist_prepend (res, (gpointer)enc); - } - - tmp = g_slist_next (tmp); - } - - g_slist_foreach (strings, (GFunc) g_free, NULL); - g_slist_free (strings); - - res = g_slist_reverse (res); - } - - return res; -} - -void -xed_prefs_manager_set_shown_in_menu_encodings (const GSList *encs) -{ - GSList *list = NULL; - - g_return_if_fail (xed_prefs_manager != NULL); - g_return_if_fail (xed_prefs_manager->settings != NULL); - g_return_if_fail (xed_prefs_manager_shown_in_menu_encodings_can_set ()); - - while (encs != NULL) - { - const XedEncoding *enc; - const gchar *charset; - - enc = (const XedEncoding *)encs->data; - - charset = xed_encoding_get_charset (enc); - g_return_if_fail (charset != NULL); - - list = g_slist_prepend (list, (gpointer)charset); - - encs = g_slist_next (encs); - } - - list = g_slist_reverse (list); - - xed_prefs_manager_set_gslist (xed_prefs_manager->settings, GPM_SHOWN_IN_MENU_ENCODINGS, list); - - g_slist_free (list); -} - -gboolean -xed_prefs_manager_shown_in_menu_encodings_can_set (void) -{ - xed_debug (DEBUG_PREFS); - - return xed_prefs_manager_key_is_writable (GPM_SHOWN_IN_MENU_ENCODINGS); - -} - -/* Highlight current line */ -DEFINE_BOOL_PREF (highlight_current_line, - GPM_HIGHLIGHT_CURRENT_LINE) - -/* Highlight matching bracket */ -DEFINE_BOOL_PREF (bracket_matching, - GPM_BRACKET_MATCHING) - -/* Display Right Margin */ -DEFINE_BOOL_PREF (display_right_margin, - GPM_DISPLAY_RIGHT_MARGIN) - -/* Right Margin Position */ -DEFINE_INT_PREF (right_margin_position, - GPM_RIGHT_MARGIN_POSITION) - -static GtkSourceSmartHomeEndType -get_smart_home_end_from_string (const gchar *str) -{ - GtkSourceSmartHomeEndType res; - - g_return_val_if_fail (str != NULL, GTK_SOURCE_SMART_HOME_END_AFTER); - - if (strcmp (str, "DISABLED") == 0) - res = GTK_SOURCE_SMART_HOME_END_DISABLED; - else if (strcmp (str, "BEFORE") == 0) - res = GTK_SOURCE_SMART_HOME_END_BEFORE; - else if (strcmp (str, "ALWAYS") == 0) - res = GTK_SOURCE_SMART_HOME_END_ALWAYS; - else - res = GTK_SOURCE_SMART_HOME_END_AFTER; - - return res; -} - -GtkSourceSmartHomeEndType -xed_prefs_manager_get_smart_home_end (void) -{ - gchar *str; - GtkSourceSmartHomeEndType res; - - xed_debug (DEBUG_PREFS); - - str = xed_prefs_manager_get_string (GPM_SMART_HOME_END); - - res = get_smart_home_end_from_string (str); - - g_free (str); - - return res; -} - -void -xed_prefs_manager_set_smart_home_end (GtkSourceSmartHomeEndType smart_he) -{ - const gchar *str; - - xed_debug (DEBUG_PREFS); - - switch (smart_he) - { - case GTK_SOURCE_SMART_HOME_END_DISABLED: - str = "DISABLED"; - break; - - case GTK_SOURCE_SMART_HOME_END_BEFORE: - str = "BEFORE"; - break; - - case GTK_SOURCE_SMART_HOME_END_ALWAYS: - str = "ALWAYS"; - break; - - default: /* GTK_SOURCE_SMART_HOME_END_AFTER */ - str = "AFTER"; - } - - xed_prefs_manager_set_string (GPM_WRAP_MODE, str); -} - -gboolean -xed_prefs_manager_smart_home_end_can_set (void) -{ - xed_debug (DEBUG_PREFS); - - return xed_prefs_manager_key_is_writable (GPM_SMART_HOME_END); -} - -/* Enable syntax highlighting */ -DEFINE_BOOL_PREF (enable_syntax_highlighting, - GPM_SYNTAX_HL_ENABLE) - -/* Enable search highlighting */ -DEFINE_BOOL_PREF (enable_search_highlighting, - GPM_SEARCH_HIGHLIGHTING_ENABLE) - -/* Source style scheme */ -DEFINE_STRING_PREF (source_style_scheme, - GPM_SOURCE_STYLE_SCHEME) - -GSList * -xed_prefs_manager_get_writable_vfs_schemes (void) -{ - GSList *strings; - - xed_debug (DEBUG_PREFS); - - g_return_val_if_fail (xed_prefs_manager != NULL, NULL); - g_return_val_if_fail (xed_prefs_manager->settings != NULL, NULL); - - strings = xed_prefs_manager_get_gslist (xed_prefs_manager->settings, GPM_WRITABLE_VFS_SCHEMES); - - /* The 'file' scheme is writable by default. */ - strings = g_slist_prepend (strings, g_strdup ("file")); - - xed_debug_message (DEBUG_PREFS, "Done"); - - return strings; -} - -gboolean -xed_prefs_manager_get_restore_cursor_position (void) -{ - xed_debug (DEBUG_PREFS); - - return xed_prefs_manager_get_bool (GPM_RESTORE_CURSOR_POSITION); -} - -/* Plugins: we just store/return a list of strings, all the magic has to - * happen in the plugin engine */ - -GSList * -xed_prefs_manager_get_active_plugins (void) -{ - GSList *plugins; - - xed_debug (DEBUG_PREFS); - - g_return_val_if_fail (xed_prefs_manager != NULL, NULL); - g_return_val_if_fail (xed_prefs_manager->settings != NULL, NULL); - - plugins = xed_prefs_manager_get_gslist (xed_prefs_manager->settings, GPM_ACTIVE_PLUGINS); - - return plugins; -} - -void -xed_prefs_manager_set_active_plugins (const GSList *plugins) -{ - g_return_if_fail (xed_prefs_manager != NULL); - g_return_if_fail (xed_prefs_manager->settings != NULL); - g_return_if_fail (xed_prefs_manager_active_plugins_can_set ()); - - xed_prefs_manager_set_gslist (xed_prefs_manager->settings, GPM_ACTIVE_PLUGINS, (GSList *) plugins); -} - -gboolean -xed_prefs_manager_active_plugins_can_set (void) -{ - xed_debug (DEBUG_PREFS); - - return xed_prefs_manager_key_is_writable (GPM_ACTIVE_PLUGINS); -} diff --git a/xed/xed-prefs-manager.h b/xed/xed-prefs-manager.h deleted file mode 100644 index 600ff61..0000000 --- a/xed/xed-prefs-manager.h +++ /dev/null @@ -1,321 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * xed-prefs-manager.h - * This file is part of xed - * - * Copyright (C) 2002 Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2002. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - */ - -#ifndef __XED_PREFS_MANAGER_H__ -#define __XED_PREFS_MANAGER_H__ - -#include -#include -#include -#include "xed-app.h" - -#define XED_SCHEMA "org.x.editor" - -/* Editor */ -#define GPM_USE_DEFAULT_FONT "use-default-font" -#define GPM_EDITOR_FONT "editor-font" - -#define GPM_CREATE_BACKUP_COPY "create-backup-copy" - -#define GPM_AUTO_SAVE "auto-save" -#define GPM_AUTO_SAVE_INTERVAL "auto-save-interval" - -#define GPM_UNDO_ACTIONS_LIMIT "max-undo-actions" - -#define GPM_WRAP_MODE "wrap-mode" - -#define GPM_TABS_SIZE "tabs-size" -#define GPM_INSERT_SPACES "insert-spaces" - -#define GPM_AUTO_INDENT "auto-indent" - -#define GPM_DISPLAY_LINE_NUMBERS "display-line-numbers" - -#define GPM_HIGHLIGHT_CURRENT_LINE "highlight-current-line" - -#define GPM_BRACKET_MATCHING "bracket-matching" - -#define GPM_DISPLAY_RIGHT_MARGIN "display-right-margin" -#define GPM_RIGHT_MARGIN_POSITION "right-margin-position" - -#define GPM_SMART_HOME_END "smart-home-end" - -#define GPM_RESTORE_CURSOR_POSITION "restore-cursor-position" - -#define GPM_SEARCH_HIGHLIGHTING_ENABLE "enable-search-highlighting" - -#define GPM_SOURCE_STYLE_SCHEME "color-scheme" - -/* UI */ -#define GPM_TOOLBAR_VISIBLE "toolbar-visible" - -#define GPM_STATUSBAR_VISIBLE "statusbar-visible" - -#define GPM_SIDE_PANE_VISIBLE "side-pane-visible" - -#define GPM_BOTTOM_PANEL_VISIBLE "bottom-panel-visible" - -#define GPM_ENABLE_TAB_SCROLLING "enable-tab-scrolling" - -#define GPM_MAX_RECENTS "max-recents" - -/* Print */ -#define GPM_PRINT_SYNTAX "print-syntax-highlighting" -#define GPM_PRINT_HEADER "print-header" -#define GPM_PRINT_WRAP_MODE "print-wrap-mode" -#define GPM_PRINT_LINE_NUMBERS "print-line-numbers" - -#define GPM_PRINT_FONT_BODY "print-font-body-pango" -#define GPM_PRINT_FONT_HEADER "print-font-header-pango" -#define GPM_PRINT_FONT_NUMBERS "print-font-numbers-pango" - -/* Encodings */ -#define GPM_AUTO_DETECTED_ENCODINGS "auto-detected-encodings" -#define GPM_SHOWN_IN_MENU_ENCODINGS "shown-in-menu-encodings" - -/* Syntax highlighting */ -#define GPM_SYNTAX_HL_ENABLE "enable-syntax-highlighting" - -/* White list of writable mate-vfs methods */ -#define GPM_WRITABLE_VFS_SCHEMES "writable-vfs-schemes" - -/* Plugins */ -#define GPM_ACTIVE_PLUGINS "active-plugins" - -/* Global Interface keys */ -#define GPM_INTERFACE_SCHEMA "org.gnome.desktop.interface" -#define GPM_SYSTEM_FONT "monospace-font-name" - -/* Fallback default values. Keep in sync with org.x.editor.gschema.xml */ -#define GPM_DEFAULT_AUTO_SAVE_INTERVAL 10 /* minutes */ -#define GPM_DEFAULT_MAX_RECENTS 5 - -/** LIFE CYCLE MANAGEMENT FUNCTIONS **/ - -gboolean xed_prefs_manager_init (void); - -/* This function must be called before exiting xed */ -void xed_prefs_manager_shutdown (void); - - -/** PREFS MANAGEMENT FUNCTIONS **/ - -/* Use default font */ -gboolean xed_prefs_manager_get_use_default_font (void); -void xed_prefs_manager_set_use_default_font (gboolean udf); -gboolean xed_prefs_manager_use_default_font_can_set (void); - -/* Editor font */ -gchar *xed_prefs_manager_get_editor_font (void); -void xed_prefs_manager_set_editor_font (const gchar *font); -gboolean xed_prefs_manager_editor_font_can_set (void); - -/* System font */ -gchar *xed_prefs_manager_get_system_font (void); - -/* Create backup copy */ -gboolean xed_prefs_manager_get_create_backup_copy (void); -void xed_prefs_manager_set_create_backup_copy (gboolean cbc); -gboolean xed_prefs_manager_create_backup_copy_can_set (void); - -/* Auto save */ -gboolean xed_prefs_manager_get_auto_save (void); -void xed_prefs_manager_set_auto_save (gboolean as); -gboolean xed_prefs_manager_auto_save_can_set (void); - -/* Auto save interval */ -gint xed_prefs_manager_get_auto_save_interval (void); -void xed_prefs_manager_set_auto_save_interval (gint asi); -gboolean xed_prefs_manager_auto_save_interval_can_set (void); - -/* Undo actions limit: if < 1 then no limits */ -gint xed_prefs_manager_get_undo_actions_limit (void); -void xed_prefs_manager_set_undo_actions_limit (gint ual); -gboolean xed_prefs_manager_undo_actions_limit_can_set (void); - -/* Wrap mode */ -GtkWrapMode xed_prefs_manager_get_wrap_mode (void); -void xed_prefs_manager_set_wrap_mode (GtkWrapMode wp); -gboolean xed_prefs_manager_wrap_mode_can_set (void); - -/* Tabs size */ -gint xed_prefs_manager_get_tabs_size (void); -void xed_prefs_manager_set_tabs_size (gint ts); -gboolean xed_prefs_manager_tabs_size_can_set (void); - -/* Insert spaces */ -gboolean xed_prefs_manager_get_insert_spaces (void); -void xed_prefs_manager_set_insert_spaces (gboolean ai); -gboolean xed_prefs_manager_insert_spaces_can_set (void); - -/* Auto indent */ -gboolean xed_prefs_manager_get_auto_indent (void); -void xed_prefs_manager_set_auto_indent (gboolean ai); -gboolean xed_prefs_manager_auto_indent_can_set (void); - -/* Display line numbers */ -gboolean xed_prefs_manager_get_display_line_numbers (void); -void xed_prefs_manager_set_display_line_numbers (gboolean dln); -gboolean xed_prefs_manager_display_line_numbers_can_set (void); - -/* Toolbar visible */ -gboolean xed_prefs_manager_get_toolbar_visible (void); -void xed_prefs_manager_set_toolbar_visible (gboolean tv); -gboolean xed_prefs_manager_toolbar_visible_can_set (void); - -/* Statusbar visible */ -gboolean xed_prefs_manager_get_statusbar_visible (void); -void xed_prefs_manager_set_statusbar_visible (gboolean sv); -gboolean xed_prefs_manager_statusbar_visible_can_set (void); - -/* Side pane visible */ -gboolean xed_prefs_manager_get_side_pane_visible (void); -void xed_prefs_manager_set_side_pane_visible (gboolean tv); -gboolean xed_prefs_manager_side_pane_visible_can_set (void); - -/* Bottom panel visible */ -gboolean xed_prefs_manager_get_bottom_panel_visible (void); -void xed_prefs_manager_set_bottom_panel_visible (gboolean tv); -gboolean xed_prefs_manager_bottom_panel_visible_can_set(void); - -/* Tab scrolling enabled */ -gboolean xed_prefs_manager_get_enable_tab_scrolling (void); -void xed_prefs_manager_set_enable_tab_scrolling (gboolean tv); -gboolean xed_prefs_manager_enable_tab_scrolling_can_set (void); - -/* Print syntax highlighting */ -gboolean xed_prefs_manager_get_print_syntax_hl (void); -void xed_prefs_manager_set_print_syntax_hl (gboolean ps); -gboolean xed_prefs_manager_print_syntax_hl_can_set (void); - -/* Print header */ -gboolean xed_prefs_manager_get_print_header (void); -void xed_prefs_manager_set_print_header (gboolean ph); -gboolean xed_prefs_manager_print_header_can_set (void); - -/* Wrap mode while printing */ -GtkWrapMode xed_prefs_manager_get_print_wrap_mode (void); -void xed_prefs_manager_set_print_wrap_mode (GtkWrapMode pwm); -gboolean xed_prefs_manager_print_wrap_mode_can_set (void); - -/* Print line numbers */ -gint xed_prefs_manager_get_print_line_numbers (void); -void xed_prefs_manager_set_print_line_numbers (gint pln); -gboolean xed_prefs_manager_print_line_numbers_can_set (void); - -/* Font used to print the body of documents */ -gchar *xed_prefs_manager_get_print_font_body (void); -void xed_prefs_manager_set_print_font_body (const gchar *font); -gboolean xed_prefs_manager_print_font_body_can_set (void); -gchar *xed_prefs_manager_get_default_print_font_body (void); - -/* Font used to print headers */ -gchar *xed_prefs_manager_get_print_font_header (void); -void xed_prefs_manager_set_print_font_header (const gchar *font); -gboolean xed_prefs_manager_print_font_header_can_set (void); -gchar *xed_prefs_manager_get_default_print_font_header (void); - -/* Font used to print line numbers */ -gchar *xed_prefs_manager_get_print_font_numbers (void); -void xed_prefs_manager_set_print_font_numbers (const gchar *font); -gboolean xed_prefs_manager_print_font_numbers_can_set (void); -gchar *xed_prefs_manager_get_default_print_font_numbers (void); - -/* Max number of files in "Recent Files" menu. - * This is configurable only using gsettings, dconf or dconf-editor - */ -gint xed_prefs_manager_get_max_recents (void); - -/* Encodings */ -GSList *xed_prefs_manager_get_auto_detected_encodings (void); - -GSList *xed_prefs_manager_get_shown_in_menu_encodings (void); -void xed_prefs_manager_set_shown_in_menu_encodings (const GSList *encs); -gboolean xed_prefs_manager_shown_in_menu_encodings_can_set (void); - -/* Highlight current line */ -gboolean xed_prefs_manager_get_highlight_current_line (void); -void xed_prefs_manager_set_highlight_current_line (gboolean hl); -gboolean xed_prefs_manager_highlight_current_line_can_set (void); - -/* Highlight matching bracket */ -gboolean xed_prefs_manager_get_bracket_matching (void); -void xed_prefs_manager_set_bracket_matching (gboolean bm); -gboolean xed_prefs_manager_bracket_matching_can_set (void); - -/* Display right margin */ -gboolean xed_prefs_manager_get_display_right_margin (void); -void xed_prefs_manager_set_display_right_margin (gboolean drm); -gboolean xed_prefs_manager_display_right_margin_can_set (void); - -/* Right margin position */ -gint xed_prefs_manager_get_right_margin_position (void); -void xed_prefs_manager_set_right_margin_position (gint rmp); -gboolean xed_prefs_manager_right_margin_position_can_set (void); - -/* Smart home end */ -GtkSourceSmartHomeEndType - xed_prefs_manager_get_smart_home_end (void); -void xed_prefs_manager_set_smart_home_end (GtkSourceSmartHomeEndType smart_he); -gboolean xed_prefs_manager_smart_home_end_can_set (void); - -/* Enable syntax highlighting */ -gboolean xed_prefs_manager_get_enable_syntax_highlighting (void); -void xed_prefs_manager_set_enable_syntax_highlighting (gboolean esh); -gboolean xed_prefs_manager_enable_syntax_highlighting_can_set (void); - -/* Writable VFS schemes */ -GSList *xed_prefs_manager_get_writable_vfs_schemes (void); - -/* Restore cursor position */ -gboolean xed_prefs_manager_get_restore_cursor_position (void); - -/* Enable search highlighting */ -gboolean xed_prefs_manager_get_enable_search_highlighting (void); -void xed_prefs_manager_set_enable_search_highlighting (gboolean esh); -gboolean xed_prefs_manager_enable_search_highlighting_can_set (void); - -/* Style scheme */ -gchar *xed_prefs_manager_get_source_style_scheme (void); -void xed_prefs_manager_set_source_style_scheme (const gchar *scheme); -gboolean xed_prefs_manager_source_style_scheme_can_set(void); - -/* Plugins */ -GSList *xed_prefs_manager_get_active_plugins (void); -void xed_prefs_manager_set_active_plugins (const GSList *plugins); -gboolean xed_prefs_manager_active_plugins_can_set (void); - -/* GSettings utilities */ -GSList* xed_prefs_manager_get_gslist (GSettings *settings, const gchar *key); -void xed_prefs_manager_set_gslist (GSettings *settings, const gchar *key, GSList *list); - - -#endif /* __XED_PREFS_MANAGER_H__ */ - - diff --git a/xed/xed-print-job.c b/xed/xed-print-job.c index 9be4b00..5963b2b 100644 --- a/xed/xed-print-job.c +++ b/xed/xed-print-job.c @@ -3,7 +3,7 @@ * This file is part of xed * * Copyright (C) 2000-2001 Chema Celorio, Paolo Maggi - * Copyright (C) 2002-2008 Paolo Maggi + * Copyright (C) 2002-2008 Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,14 +17,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ - + /* - * Modified by the xed Team, 1998-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. + * Modified by the xed Team, 1998-2005. See the AUTHORS file for a + * list of people on the xed Team. + * See the ChangeLog files for a list of changes. * * $Id: xed-print.c 6022 2007-12-09 14:38:57Z pborelli $ */ @@ -38,11 +38,11 @@ #include "xed-print-job.h" #include "xed-debug.h" -#include "xed-prefs-manager.h" #include "xed-print-preview.h" #include "xed-marshal.h" #include "xed-utils.h" #include "xed-dirs.h" +#include "xed-settings.h" #define XED_PRINT_JOB_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ @@ -51,6 +51,8 @@ struct _XedPrintJobPrivate { + GSettings *print_settings; + XedView *view; XedDocument *doc; @@ -62,7 +64,7 @@ struct _XedPrintJobPrivate GtkWidget *preview; XedPrintJobStatus status; - + gchar *status_string; gdouble progress; @@ -94,7 +96,7 @@ enum PROP_VIEW }; -enum +enum { PRINTING, SHOW_PREVIEW, @@ -113,7 +115,7 @@ set_view (XedPrintJob *job, XedView *view) job->priv->doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); } -static void +static void xed_print_job_get_property (GObject *object, guint prop_id, GValue *value, @@ -132,7 +134,7 @@ xed_print_job_get_property (GObject *object, } } -static void +static void xed_print_job_set_property (GObject *object, guint prop_id, const GValue *value, @@ -157,7 +159,7 @@ xed_print_job_finalize (GObject *object) XedPrintJob *job = XED_PRINT_JOB (object); g_free (job->priv->status_string); - + if (job->priv->compositor != NULL) g_object_unref (job->priv->compositor); @@ -167,7 +169,17 @@ xed_print_job_finalize (GObject *object) G_OBJECT_CLASS (xed_print_job_parent_class)->finalize (object); } -static void +static void +xed_print_job_dispose (GObject *object) +{ + XedPrintJob *job = XED_PRINT_JOB (object); + + g_clear_object (&job->priv->print_settings); + + G_OBJECT_CLASS (xed_print_job_parent_class)->dispose (object); +} + +static void xed_print_job_class_init (XedPrintJobClass *klass) { GObjectClass *object_class; @@ -177,6 +189,7 @@ xed_print_job_class_init (XedPrintJobClass *klass) object_class->get_property = xed_print_job_get_property; object_class->set_property = xed_print_job_set_property; object_class->finalize = xed_print_job_finalize; + object_class->dispose = xed_print_job_dispose; g_object_class_install_property (object_class, PROP_VIEW, @@ -221,7 +234,7 @@ xed_print_job_class_init (XedPrintJobClass *klass) 2, G_TYPE_UINT, G_TYPE_POINTER); - + g_type_class_add_private (object_class, sizeof (XedPrintJobPrivate)); } @@ -229,15 +242,7 @@ static void line_numbers_checkbutton_toggled (GtkToggleButton *button, XedPrintJob *job) { - if (gtk_toggle_button_get_active (button)) - { - gtk_widget_set_sensitive (job->priv->line_numbers_hbox, - xed_prefs_manager_print_line_numbers_can_set ()); - } - else - { - gtk_widget_set_sensitive (job->priv->line_numbers_hbox, FALSE); - } + gtk_widget_set_sensitive (job->priv->line_numbers_hbox, gtk_toggle_button_get_active (button)); } static void @@ -246,7 +251,7 @@ wrap_mode_checkbutton_toggled (GtkToggleButton *button, { if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->text_wrapping_checkbutton))) { - gtk_widget_set_sensitive (job->priv->do_not_split_checkbutton, + gtk_widget_set_sensitive (job->priv->do_not_split_checkbutton, FALSE); gtk_toggle_button_set_inconsistent ( GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton), @@ -267,58 +272,36 @@ restore_button_clicked (GtkButton *button, XedPrintJob *job) { - if (xed_prefs_manager_print_font_body_can_set ()) - { - gchar *font; + gchar *body; + gchar *header; + gchar *numbers; - font = xed_prefs_manager_get_default_print_font_body (); + body = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_BODY_PANGO); + header = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_HEADER_PANGO); + numbers = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_NUMBERS_PANGO); - gtk_font_button_set_font_name ( - GTK_FONT_BUTTON (job->priv->body_fontbutton), - font); + gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->body_fontbutton), body); + gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->headers_fontbutton), header); + gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->numbers_fontbutton), numbers); - g_free (font); - } - - if (xed_prefs_manager_print_font_header_can_set ()) - { - gchar *font; - - font = xed_prefs_manager_get_default_print_font_header (); - - gtk_font_button_set_font_name ( - GTK_FONT_BUTTON (job->priv->headers_fontbutton), - font); - - g_free (font); - } - - if (xed_prefs_manager_print_font_numbers_can_set ()) - { - gchar *font; - - font = xed_prefs_manager_get_default_print_font_numbers (); - - gtk_font_button_set_font_name ( - GTK_FONT_BUTTON (job->priv->numbers_fontbutton), - font); - - g_free (font); - } + g_free (body); + g_free (header); + g_free (numbers); } static GObject * -create_custom_widget_cb (GtkPrintOperation *operation, +create_custom_widget_cb (GtkPrintOperation *operation, XedPrintJob *job) { gboolean ret; GtkWidget *widget; GtkWidget *error_widget; - gchar *font; - gint line_numbers; - gboolean can_set; + guint line_numbers; GtkWrapMode wrap_mode; gchar *file; + gboolean syntax_hl; + gboolean print_header; + gchar *font_body, *font_header, *font_numbers; gchar *root_objects[] = { "adjustment1", "contents", @@ -353,31 +336,27 @@ create_custom_widget_cb (GtkPrintOperation *operation, return G_OBJECT (error_widget); } + /* Get all settings values */ + syntax_hl = g_settings_get_boolean (job->priv->print_settings, XED_SETTINGS_PRINT_SYNTAX_HIGHLIGHTING); + print_header = g_settings_get_boolean (job->priv->print_settings, XED_SETTINGS_PRINT_HEADER); + line_numbers = g_settings_get_uint (job->priv->print_settings, XED_SETTINGS_PRINT_LINE_NUMBERS); + font_body = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_BODY_PANGO); + font_header = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_HEADER_PANGO); + font_numbers = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_NUMBERS_PANGO); + /* Print syntax */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->syntax_checkbutton), - xed_prefs_manager_get_print_syntax_hl ()); - gtk_widget_set_sensitive (job->priv->syntax_checkbutton, - xed_prefs_manager_print_syntax_hl_can_set ()); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->syntax_checkbutton), syntax_hl); /* Print page headers */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->page_header_checkbutton), - xed_prefs_manager_get_print_header ()); - gtk_widget_set_sensitive (job->priv->page_header_checkbutton, - xed_prefs_manager_print_header_can_set ()); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->page_header_checkbutton), print_header); /* Line numbers */ - line_numbers = xed_prefs_manager_get_print_line_numbers (); - can_set = xed_prefs_manager_print_line_numbers_can_set (); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->line_numbers_checkbutton), - line_numbers > 0); - gtk_widget_set_sensitive (job->priv->line_numbers_checkbutton, can_set); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->line_numbers_checkbutton), line_numbers > 0); if (line_numbers > 0) { - gtk_spin_button_set_value (GTK_SPIN_BUTTON (job->priv->line_numbers_spinbutton), - (guint) line_numbers); - gtk_widget_set_sensitive (job->priv->line_numbers_hbox, can_set); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (job->priv->line_numbers_spinbutton), (guint) line_numbers); + gtk_widget_set_sensitive (job->priv->line_numbers_hbox, TRUE); } else { @@ -387,7 +366,7 @@ create_custom_widget_cb (GtkPrintOperation *operation, } /* Text wrapping */ - wrap_mode = xed_prefs_manager_get_print_wrap_mode (); + wrap_mode = g_settings_get_enum (job->priv->print_settings, XED_SETTINGS_PRINT_WRAP_MODE); switch (wrap_mode) { @@ -410,39 +389,17 @@ create_custom_widget_cb (GtkPrintOperation *operation, GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton), TRUE); } - can_set = xed_prefs_manager_print_wrap_mode_can_set (); - - gtk_widget_set_sensitive (job->priv->text_wrapping_checkbutton, can_set); - gtk_widget_set_sensitive (job->priv->do_not_split_checkbutton, - can_set && (wrap_mode != GTK_WRAP_NONE)); + gtk_widget_set_sensitive (job->priv->do_not_split_checkbutton, wrap_mode != GTK_WRAP_NONE); /* Set initial values */ - font = xed_prefs_manager_get_print_font_body (); - gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->body_fontbutton), - font); - g_free (font); + gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->body_fontbutton), font_body); + g_free (font_body); - font = xed_prefs_manager_get_print_font_header (); - gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->headers_fontbutton), - font); - g_free (font); + gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->headers_fontbutton), font_header); + g_free (font_header); - font = xed_prefs_manager_get_print_font_numbers (); - gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->numbers_fontbutton), - font); - g_free (font); - - can_set = xed_prefs_manager_print_font_body_can_set (); - gtk_widget_set_sensitive (job->priv->body_fontbutton, can_set); - gtk_widget_set_sensitive (job->priv->body_font_label, can_set); - - can_set = xed_prefs_manager_print_font_header_can_set (); - gtk_widget_set_sensitive (job->priv->headers_fontbutton, can_set); - gtk_widget_set_sensitive (job->priv->headers_font_label, can_set); - - can_set = xed_prefs_manager_print_font_numbers_can_set (); - gtk_widget_set_sensitive (job->priv->numbers_fontbutton, can_set); - gtk_widget_set_sensitive (job->priv->numbers_font_label, can_set); + gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->numbers_fontbutton), font_numbers); + g_free (font_numbers); g_signal_connect (job->priv->line_numbers_checkbutton, "toggled", @@ -469,39 +426,49 @@ custom_widget_apply_cb (GtkPrintOperation *operation, GtkWidget *widget, XedPrintJob *job) { - xed_prefs_manager_set_print_syntax_hl (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->syntax_checkbutton))); + gboolean syntax, page_header; + const gchar *body, *header, *numbers; + GtkWrapMode wrap_mode; - xed_prefs_manager_set_print_header (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->page_header_checkbutton))); + syntax = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->syntax_checkbutton)); + page_header = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->page_header_checkbutton)); + body = gtk_font_button_get_font_name (GTK_FONT_BUTTON (job->priv->body_fontbutton)); + header = gtk_font_button_get_font_name (GTK_FONT_BUTTON (job->priv->headers_fontbutton)); + numbers = gtk_font_button_get_font_name (GTK_FONT_BUTTON (job->priv->numbers_fontbutton)); + + g_settings_set_boolean (job->priv->print_settings, XED_SETTINGS_PRINT_SYNTAX_HIGHLIGHTING, syntax); + g_settings_set_boolean (job->priv->print_settings, XED_SETTINGS_PRINT_HEADER, page_header); + g_settings_set_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_BODY_PANGO, body); + g_settings_set_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_HEADER_PANGO, header); + g_settings_set_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_NUMBERS_PANGO, numbers); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->line_numbers_checkbutton))) { - xed_prefs_manager_set_print_line_numbers ( - MAX (1, gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (job->priv->line_numbers_spinbutton)))); + g_settings_set_uint (job->priv->print_settings, XED_SETTINGS_PRINT_LINE_NUMBERS, + MAX (1, gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (job->priv->line_numbers_spinbutton)))); } else { - xed_prefs_manager_set_print_line_numbers (0); + g_settings_set_uint (job->priv->print_settings, XED_SETTINGS_PRINT_LINE_NUMBERS, 0); } if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->text_wrapping_checkbutton))) { - xed_prefs_manager_set_print_wrap_mode (GTK_WRAP_NONE); + wrap_mode = GTK_WRAP_NONE; } else { if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton))) { - xed_prefs_manager_set_print_wrap_mode (GTK_WRAP_WORD); + wrap_mode = GTK_WRAP_WORD; } else { - xed_prefs_manager_set_print_wrap_mode (GTK_WRAP_CHAR); - } + wrap_mode = GTK_WRAP_CHAR; + } } - xed_prefs_manager_set_print_font_body (gtk_font_button_get_font_name (GTK_FONT_BUTTON (job->priv->body_fontbutton))); - xed_prefs_manager_set_print_font_header (gtk_font_button_get_font_name (GTK_FONT_BUTTON (job->priv->headers_fontbutton))); - xed_prefs_manager_set_print_font_numbers (gtk_font_button_get_font_name (GTK_FONT_BUTTON (job->priv->numbers_fontbutton))); + g_settings_set_enum (job->priv->print_settings, XED_SETTINGS_PRINT_WRAP_MODE, wrap_mode); } static void @@ -510,21 +477,29 @@ create_compositor (XedPrintJob *job) gchar *print_font_body; gchar *print_font_header; gchar *print_font_numbers; - + gboolean syntax_hl; + GtkWrapMode wrap_mode; + guint print_line_numbers; + gboolean print_header; + /* Create and initialize print compositor */ - print_font_body = xed_prefs_manager_get_print_font_body (); - print_font_header = xed_prefs_manager_get_print_font_header (); - print_font_numbers = xed_prefs_manager_get_print_font_numbers (); - + print_font_body = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_BODY_PANGO); + print_font_header = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_HEADER_PANGO); + print_font_numbers = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_NUMBERS_PANGO); + syntax_hl = g_settings_get_boolean (job->priv->print_settings, XED_SETTINGS_PRINT_SYNTAX_HIGHLIGHTING); + print_line_numbers = g_settings_get_uint (job->priv->print_settings, XED_SETTINGS_PRINT_LINE_NUMBERS); + print_header = g_settings_get_boolean (job->priv->print_settings, XED_SETTINGS_PRINT_HEADER); + wrap_mode = g_settings_get_enum (job->priv->print_settings, XED_SETTINGS_PRINT_WRAP_MODE); + job->priv->compositor = GTK_SOURCE_PRINT_COMPOSITOR ( g_object_new (GTK_SOURCE_TYPE_PRINT_COMPOSITOR, "buffer", GTK_SOURCE_BUFFER (job->priv->doc), "tab-width", gtk_source_view_get_tab_width (GTK_SOURCE_VIEW (job->priv->view)), "highlight-syntax", gtk_source_buffer_get_highlight_syntax (GTK_SOURCE_BUFFER (job->priv->doc)) && - xed_prefs_manager_get_print_syntax_hl (), - "wrap-mode", xed_prefs_manager_get_print_wrap_mode (), - "print-line-numbers", xed_prefs_manager_get_print_line_numbers (), - "print-header", xed_prefs_manager_get_print_header (), + syntax_hl, + "wrap-mode", wrap_mode, + "print-line-numbers", print_line_numbers, + "print-header", print_header, "print-footer", FALSE, "body-font-name", print_font_body, "line-numbers-font-name", print_font_numbers, @@ -534,8 +509,8 @@ create_compositor (XedPrintJob *job) g_free (print_font_body); g_free (print_font_header); g_free (print_font_numbers); - - if (xed_prefs_manager_get_print_header ()) + + if (print_header) { gchar *doc_name; gchar *name_to_display; @@ -547,7 +522,7 @@ create_compositor (XedPrintJob *job) left = g_strdup_printf (_("File: %s"), name_to_display); /* Translators: %N is the current page number, %Q is the total - * number of pages (ex. Page 2 of 10) + * number of pages (ex. Page 2 of 10) */ gtk_source_print_compositor_set_header_format (job->priv->compositor, TRUE, @@ -558,11 +533,11 @@ create_compositor (XedPrintJob *job) g_free (doc_name); g_free (name_to_display); g_free (left); - } + } } static void -begin_print_cb (GtkPrintOperation *operation, +begin_print_cb (GtkPrintOperation *operation, GtkPrintContext *context, XedPrintJob *job) { @@ -571,7 +546,7 @@ begin_print_cb (GtkPrintOperation *operation, job->priv->status = XED_PRINT_JOB_STATUS_PAGINATING; job->priv->progress = 0.0; - + g_signal_emit (job, print_job_signals[PRINTING], 0, job->priv->status); } @@ -592,7 +567,7 @@ preview_destroyed (GtkWidget *preview, gtk_print_operation_preview_end_preview (gtk_preview); } -static gboolean +static gboolean preview_cb (GtkPrintOperation *op, GtkPrintOperationPreview *gtk_preview, GtkPrintContext *context, @@ -616,16 +591,16 @@ preview_cb (GtkPrintOperation *op, } static gboolean -paginate_cb (GtkPrintOperation *operation, +paginate_cb (GtkPrintOperation *operation, GtkPrintContext *context, XedPrintJob *job) { - gboolean res; - + gboolean res; + job->priv->status = XED_PRINT_JOB_STATUS_PAGINATING; - + res = gtk_source_print_compositor_paginate (job->priv->compositor, context); - + if (res) { gint n_pages; @@ -659,25 +634,25 @@ draw_page_cb (GtkPrintOperation *operation, if (!job->priv->is_preview) { g_free (job->priv->status_string); - + n_pages = gtk_source_print_compositor_get_n_pages (job->priv->compositor); - + job->priv->status = XED_PRINT_JOB_STATUS_DRAWING; - - job->priv->status_string = g_strdup_printf ("Rendering page %d of %d...", + + job->priv->status_string = g_strdup_printf ("Rendering page %d of %d...", page_nr + 1, n_pages); - + job->priv->progress = page_nr / (2.0 * n_pages) + 0.5; g_signal_emit (job, print_job_signals[PRINTING], 0, job->priv->status); - } + } gtk_source_print_compositor_draw_page (job->priv->compositor, context, page_nr); } static void -end_print_cb (GtkPrintOperation *operation, +end_print_cb (GtkPrintOperation *operation, GtkPrintContext *context, XedPrintJob *job) { @@ -693,7 +668,7 @@ done_cb (GtkPrintOperation *operation, GError *error = NULL; XedPrintJobResult print_result; - switch (result) + switch (result) { case GTK_PRINT_OPERATION_RESULT_CANCEL: print_result = XED_PRINT_JOB_RESULT_CANCEL; @@ -711,20 +686,20 @@ done_cb (GtkPrintOperation *operation, default: g_return_if_reached (); } - + /* Avoid job is destroyed in the handler of the "done" message */ g_object_ref (job); - + g_signal_emit (job, print_job_signals[DONE], 0, print_result, error); - + g_object_unref (operation); job->priv->operation = NULL; - + g_object_unref (job); } /* Note that xed_print_job_print can can only be called once on a given XedPrintJob */ -GtkPrintOperationResult +GtkPrintOperationResult xed_print_job_print (XedPrintJob *job, GtkPrintOperationAction action, GtkPageSetup *page_setup, @@ -765,15 +740,15 @@ xed_print_job_print (XedPrintJob *job, gtk_print_operation_set_allow_async (priv->operation, TRUE); g_signal_connect (priv->operation, - "create-custom-widget", + "create-custom-widget", G_CALLBACK (create_custom_widget_cb), job); g_signal_connect (priv->operation, - "custom-widget-apply", - G_CALLBACK (custom_widget_apply_cb), + "custom-widget-apply", + G_CALLBACK (custom_widget_apply_cb), job); g_signal_connect (priv->operation, - "begin-print", + "begin-print", G_CALLBACK (begin_print_cb), job); g_signal_connect (priv->operation, @@ -781,23 +756,23 @@ xed_print_job_print (XedPrintJob *job, G_CALLBACK (preview_cb), job); g_signal_connect (priv->operation, - "paginate", + "paginate", G_CALLBACK (paginate_cb), job); g_signal_connect (priv->operation, - "draw-page", + "draw-page", G_CALLBACK (draw_page_cb), job); g_signal_connect (priv->operation, - "end-print", + "end-print", G_CALLBACK (end_print_cb), job); g_signal_connect (priv->operation, - "done", + "done", G_CALLBACK (done_cb), - job); + job); - return gtk_print_operation_run (priv->operation, + return gtk_print_operation_run (priv->operation, action, parent, error); @@ -807,9 +782,11 @@ static void xed_print_job_init (XedPrintJob *job) { job->priv = XED_PRINT_JOB_GET_PRIVATE (job); - + + job->priv->print_settings = g_settings_new ("org.x.editor.preferences.print"); + job->priv->status = XED_PRINT_JOB_STATUS_INIT; - + job->priv->status_string = g_strdup (_("Preparing...")); } @@ -817,9 +794,9 @@ XedPrintJob * xed_print_job_new (XedView *view) { XedPrintJob *job; - + g_return_val_if_fail (XED_IS_VIEW (view), NULL); - + job = XED_PRINT_JOB (g_object_new (XED_TYPE_PRINT_JOB, "view", view, NULL)); @@ -840,7 +817,7 @@ xed_print_job_get_status_string (XedPrintJob *job) { g_return_val_if_fail (XED_IS_PRINT_JOB (job), NULL); g_return_val_if_fail (job->priv->status_string != NULL, NULL); - + return job->priv->status_string; } diff --git a/xed/xed-session.c b/xed/xed-session.c index 6067974..3f57e27 100644 --- a/xed/xed-session.c +++ b/xed/xed-session.c @@ -46,7 +46,6 @@ #include "xed-debug.h" #include "xed-plugins-engine.h" -#include "xed-prefs-manager-app.h" #include "xed-metadata-manager.h" #include "xed-window.h" #include "xed-app.h" diff --git a/xed/xed-settings.c b/xed/xed-settings.c new file mode 100644 index 0000000..02d263c --- /dev/null +++ b/xed/xed-settings.c @@ -0,0 +1,750 @@ +/* + * xed-settings.c + * This file is part of xed + * + * Copyright (C) 2002-2005 - Paolo Maggi + * 2009 - Ignacio Casal Quinteiro + * + * xed is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xed is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with xed; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#include + +#include "xed-settings.h" +#include "xed-app.h" +#include "xed-debug.h" +#include "xed-view.h" +#include "xed-window.h" +#include "xed-notebook.h" +#include "xed-plugins-engine.h" +#include "xed-style-scheme-manager.h" +#include "xed-dirs.h" +#include "xed-utils.h" +#include "xed-window-private.h" + +#define XED_SETTINGS_SYSTEM_FONT "monospace-font-name" + +#define XED_SETTINGS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), XED_TYPE_SETTINGS, XedSettingsPrivate)) + +struct _XedSettingsPrivate +{ + GSettings *interface; + GSettings *editor; + GSettings *ui; + GSettings *plugins; + + gchar *old_scheme; +}; + +G_DEFINE_TYPE (XedSettings, xed_settings, G_TYPE_SETTINGS) + +static void +xed_settings_finalize (GObject *object) +{ + XedSettings *xs = XED_SETTINGS (object); + + g_free (xs->priv->old_scheme); + + G_OBJECT_CLASS (xed_settings_parent_class)->finalize (object); +} + +static void +xed_settings_dispose (GObject *object) +{ + XedSettings *xs = XED_SETTINGS (object); + + if (xs->priv->interface != NULL) + { + g_object_unref (xs->priv->interface); + xs->priv->interface = NULL; + } + + if (xs->priv->editor != NULL) + { + g_object_unref (xs->priv->editor); + xs->priv->editor = NULL; + } + + if (xs->priv->ui != NULL) + { + g_object_unref (xs->priv->ui); + xs->priv->ui = NULL; + } + + if (xs->priv->plugins != NULL) + { + g_object_unref (xs->priv->plugins); + xs->priv->plugins = NULL; + } + + G_OBJECT_CLASS (xed_settings_parent_class)->dispose (object); +} + +static void +set_font (XedSettings *xs, + const gchar *font) +{ + GList *views, *l; + guint ts; + + ts = g_settings_get_uint (xs->priv->editor, XED_SETTINGS_TABS_SIZE); + + views = xed_app_get_views (xed_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + /* Note: we use def=FALSE to avoid XedView to query gconf */ + xed_view_set_font (XED_VIEW (l->data), FALSE, font); + + gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); + } + + g_list_free (views); +} + +static void +on_system_font_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + + gboolean use_default_font; + gchar *font; + + use_default_font = g_settings_get_boolean (xs->priv->editor, XED_SETTINGS_USE_DEFAULT_FONT); + if (!use_default_font) + { + return; + } + + font = g_settings_get_string (settings, key); + + set_font (xs, font); + + g_free (font); +} + +static void +on_use_default_font_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + gboolean def; + gchar *font; + + def = g_settings_get_boolean (settings, key); + + if (def) + { + font = g_settings_get_string (xs->priv->interface, XED_SETTINGS_SYSTEM_FONT); + } + else + { + font = g_settings_get_string (xs->priv->editor, XED_SETTINGS_EDITOR_FONT); + } + + set_font (xs, font); + + g_free (font); +} + +static void +on_editor_font_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + gboolean use_default_font; + gchar *font; + + use_default_font = g_settings_get_boolean (xs->priv->editor, XED_SETTINGS_USE_DEFAULT_FONT); + if (use_default_font) + { + return; + } + + font = g_settings_get_string (settings, key); + + set_font (xs, font); + + g_free (font); +} + +static void +on_scheme_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GtkSourceStyleScheme *style; + gchar *scheme; + GList *docs; + GList *l; + + scheme = g_settings_get_string (settings, key); + + if (xs->priv->old_scheme != NULL && (strcmp (scheme, xs->priv->old_scheme) == 0)) + { + return; + } + + g_free (xs->priv->old_scheme); + xs->priv->old_scheme = scheme; + + style = gtk_source_style_scheme_manager_get_scheme (xed_get_style_scheme_manager (), scheme); + + if (style == NULL) + { + g_warning ("Default style scheme '%s' not found, falling back to 'classic'", scheme); + + style = gtk_source_style_scheme_manager_get_scheme (xed_get_style_scheme_manager (), "classic"); + + if (style == NULL) + { + g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation."); + return; + } + } + + docs = xed_app_get_documents (xed_app_get_default ()); + for (l = docs; l != NULL; l = g_list_next (l)) + { + g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); + + gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (l->data), style); + } + + g_list_free (docs); +} + +static void +on_auto_save_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GList *docs, *l; + gboolean auto_save; + + auto_save = g_settings_get_boolean (settings, key); + + docs = xed_app_get_documents (xed_app_get_default ()); + + for (l = docs; l != NULL; l = g_list_next (l)) + { + XedTab *tab = xed_tab_get_from_document (XED_DOCUMENT (l->data)); + + xed_tab_set_auto_save_enabled (tab, auto_save); + } + + g_list_free (docs); +} + +static void +on_auto_save_interval_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GList *docs, *l; + gint auto_save_interval; + + g_settings_get (settings, key, "u", &auto_save_interval); + + docs = xed_app_get_documents (xed_app_get_default ()); + + for (l = docs; l != NULL; l = g_list_next (l)) + { + XedTab *tab = xed_tab_get_from_document (XED_DOCUMENT (l->data)); + + xed_tab_set_auto_save_interval (tab, auto_save_interval); + } + + g_list_free (docs); +} + +static void +on_undo_actions_limit_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GList *docs, *l; + gint ul; + + g_settings_get (settings, key, "u", &ul); + + ul = CLAMP (ul, -1, 250); + + docs = xed_app_get_documents (xed_app_get_default ()); + + for (l = docs; l != NULL; l = g_list_next (l)) + { + gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (l->data), ul); + } + + g_list_free (docs); +} + +static void +on_wrap_mode_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GtkWrapMode wrap_mode; + GList *views, *l; + + wrap_mode = g_settings_get_enum (settings, key); + + views = xed_app_get_views (xed_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (l->data), wrap_mode); + } + + g_list_free (views); +} + +static void +on_tabs_size_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GList *views, *l; + guint ts; + + g_settings_get (settings, key, "u", &ts); + + ts = CLAMP (ts, 1, 24); + + views = xed_app_get_views (xed_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); + } + + g_list_free (views); +} + +/* FIXME: insert_spaces and line_numbers are mostly the same it just changes + the func called, maybe typedef the func and refactorize? */ +static void +on_insert_spaces_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GList *views, *l; + gboolean spaces; + + spaces = g_settings_get_boolean (settings, key); + + views = xed_app_get_views (xed_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_source_view_set_insert_spaces_instead_of_tabs (GTK_SOURCE_VIEW (l->data), spaces); + } + + g_list_free (views); +} + +static void +on_auto_indent_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GList *views, *l; + gboolean enable; + + enable = g_settings_get_boolean (settings, key); + + views = xed_app_get_views (xed_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (l->data), enable); + } + + g_list_free (views); +} + +static void +on_display_line_numbers_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GList *views, *l; + gboolean line_numbers; + + line_numbers = g_settings_get_boolean (settings, key); + + views = xed_app_get_views (xed_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (l->data), line_numbers); + } + + g_list_free (views); +} + +static void +on_hl_current_line_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GList *views, *l; + gboolean hl; + + hl = g_settings_get_boolean (settings, key); + + views = xed_app_get_views (xed_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (l->data), hl); + } + + g_list_free (views); +} + +static void +on_bracket_matching_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GList *docs, *l; + gboolean enable; + + enable = g_settings_get_boolean (settings, key); + + docs = xed_app_get_documents (xed_app_get_default ()); + + for (l = docs; l != NULL; l = g_list_next (l)) + { + gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (l->data), enable); + } + + g_list_free (docs); +} + +static void +on_display_right_margin_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GList *views, *l; + gboolean display; + + display = g_settings_get_boolean (settings, key); + + views = xed_app_get_views (xed_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_source_view_set_show_right_margin (GTK_SOURCE_VIEW (l->data), display); + } + + g_list_free (views); +} + +static void +on_right_margin_position_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GList *views, *l; + gint pos; + + g_settings_get (settings, key, "u", &pos); + + pos = CLAMP (pos, 1, 160); + + views = xed_app_get_views (xed_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_source_view_set_right_margin_position (GTK_SOURCE_VIEW (l->data), pos); + } + + g_list_free (views); +} + +static void +on_smart_home_end_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GtkSourceSmartHomeEndType smart_he; + GList *views, *l; + + smart_he = g_settings_get_enum (settings, key); + + views = xed_app_get_views (xed_app_get_default ()); + + for (l = views; l != NULL; l = g_list_next (l)) + { + gtk_source_view_set_smart_home_end (GTK_SOURCE_VIEW (l->data), smart_he); + } + + g_list_free (views); +} + +static void +on_syntax_highlighting_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + const GList *windows; + GList *docs, *l; + gboolean enable; + + enable = g_settings_get_boolean (settings, key); + + docs = xed_app_get_documents (xed_app_get_default ()); + + for (l = docs; l != NULL; l = g_list_next (l)) + { + gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (l->data), enable); + } + + g_list_free (docs); + + /* update the sensitivity of the Higlight Mode menu item */ + windows = xed_app_get_windows (xed_app_get_default ()); + while (windows != NULL) + { + GtkUIManager *ui; + GtkAction *a; + + ui = xed_window_get_ui_manager (XED_WINDOW (windows->data)); + + a = gtk_ui_manager_get_action (ui, "/MenuBar/ViewMenu/ViewHighlightModeMenu"); + + gtk_action_set_sensitive (a, enable); + + windows = g_list_next (windows); + } +} + +static void +on_search_highlighting_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GList *docs, *l; + gboolean enable; + + enable = g_settings_get_boolean (settings, key); + + docs = xed_app_get_documents (xed_app_get_default ()); + + for (l = docs; l != NULL; l = g_list_next (l)) + { + xed_document_set_enable_search_highlighting (XED_DOCUMENT (l->data), enable); + } + + g_list_free (docs); +} + +static void +on_enable_tab_scrolling_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + const GList *windows; + gboolean enable; + + enable = g_settings_get_boolean (settings, key); + + windows = xed_app_get_windows (xed_app_get_default ()); + while (windows != NULL) + { + XedNotebook *notebook; + + notebook = XED_NOTEBOOK (_xed_window_get_notebook (windows->data)); + xed_notebook_set_tab_scrolling_enabled (notebook, enable); + + windows = g_list_next (windows); + } +} + +static void +on_max_recents_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + /* FIXME: we have no way at the moment to trigger the + * update of the inline recents in the File menu */ +} + +static void +xed_settings_init (XedSettings *xs) +{ + xs->priv = XED_SETTINGS_GET_PRIVATE (xs); + + xs->priv->old_scheme = NULL; +} + +static void +initialize (XedSettings *xs) +{ + GSettings *prefs; + + prefs = g_settings_get_child (G_SETTINGS (xs), "preferences"); + xs->priv->editor = g_settings_get_child (prefs, "editor"); + xs->priv->ui = g_settings_get_child (prefs, "ui"); + g_object_unref (prefs); + xs->priv->plugins = g_settings_get_child (G_SETTINGS (xs), "plugins"); + + /* Load settings */ + xs->priv->interface = g_settings_new ("org.gnome.desktop.interface"); + + g_signal_connect (xs->priv->interface, "changed", + G_CALLBACK (on_system_font_changed), xs); + + /* editor changes */ + g_signal_connect (xs->priv->editor, "changed::use-default-font", + G_CALLBACK (on_use_default_font_changed), xs); + g_signal_connect (xs->priv->editor, "changed::editor-font", + G_CALLBACK (on_editor_font_changed), xs); + g_signal_connect (xs->priv->editor, "changed::scheme", + G_CALLBACK (on_scheme_changed), xs); + g_signal_connect (xs->priv->editor, "changed::auto-save", + G_CALLBACK (on_auto_save_changed), xs); + g_signal_connect (xs->priv->editor, "changed::auto-save-interval", + G_CALLBACK (on_auto_save_interval_changed), xs); + g_signal_connect (xs->priv->editor, "changed::undo-actions-limit", + G_CALLBACK (on_undo_actions_limit_changed), xs); + g_signal_connect (xs->priv->editor, "changed::wrap-mode", + G_CALLBACK (on_wrap_mode_changed), xs); + g_signal_connect (xs->priv->editor, "changed::tabs-size", + G_CALLBACK (on_tabs_size_changed), xs); + g_signal_connect (xs->priv->editor, "changed::insert-spaces", + G_CALLBACK (on_insert_spaces_changed), xs); + g_signal_connect (xs->priv->editor, "changed::auto-indent", + G_CALLBACK (on_auto_indent_changed), xs); + g_signal_connect (xs->priv->editor, "changed::display-line-numbers", + G_CALLBACK (on_display_line_numbers_changed), xs); + g_signal_connect (xs->priv->editor, "changed::highlight-current-line", + G_CALLBACK (on_hl_current_line_changed), xs); + g_signal_connect (xs->priv->editor, "changed::bracket-matching", + G_CALLBACK (on_bracket_matching_changed), xs); + g_signal_connect (xs->priv->editor, "changed::display-right-margin", + G_CALLBACK (on_display_right_margin_changed), xs); + g_signal_connect (xs->priv->editor, "changed::right-margin-position", + G_CALLBACK (on_right_margin_position_changed), xs); + g_signal_connect (xs->priv->editor, "changed::smart-home-end", + G_CALLBACK (on_smart_home_end_changed), xs); + g_signal_connect (xs->priv->editor, "changed::syntax-highlighting", + G_CALLBACK (on_syntax_highlighting_changed), xs); + g_signal_connect (xs->priv->editor, "changed::search-highlighting", + G_CALLBACK (on_search_highlighting_changed), xs); + g_signal_connect (xs->priv->ui, "changed::enable-tab-scrolling", + G_CALLBACK (on_enable_tab_scrolling_changed), xs); + + /* ui changes */ + g_signal_connect (xs->priv->ui, "changed::max-recents", + G_CALLBACK (on_max_recents_changed), xs); +} + +static void +xed_settings_class_init (XedSettingsClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = xed_settings_finalize; + object_class->dispose = xed_settings_dispose; + + g_type_class_add_private (object_class, sizeof (XedSettingsPrivate)); +} + +GSettings * +xed_settings_new () +{ + XedSettings *settings; + + settings = g_object_new (XED_TYPE_SETTINGS, + "schema", "org.x.editor", + NULL); + + initialize (settings); + + return G_SETTINGS (settings); +} + +gchar * +xed_settings_get_system_font (XedSettings *xs) +{ + gchar *system_font; + + g_return_val_if_fail (XED_IS_SETTINGS (xs), NULL); + + system_font = g_settings_get_string (xs->priv->interface, "monospace-font-name"); + + return system_font; +} + +GSList * +xed_settings_get_list (GSettings *settings, + const gchar *key) +{ + GSList *list = NULL; + gchar **values; + gsize i; + + g_return_val_if_fail (G_IS_SETTINGS (settings), NULL); + g_return_val_if_fail (key != NULL, NULL); + + values = g_settings_get_strv (settings, key); + i = 0; + + while (values[i] != NULL) + { + list = g_slist_prepend (list, values[i]); + i++; + } + + g_free (values); + + return g_slist_reverse (list); +} + +void +xed_settings_set_list (GSettings *settings, + const gchar *key, + const GSList *list) +{ + gchar **values = NULL; + const GSList *l; + + g_return_if_fail (G_IS_SETTINGS (settings)); + g_return_if_fail (key != NULL); + + if (list != NULL) + { + gint i, len; + + len = g_slist_length ((GSList *)list); + values = g_new (gchar *, len + 1); + + for (l = list, i = 0; l != NULL; l = g_slist_next (l), i++) + { + values[i] = l->data; + } + values [i] = NULL; + } + + g_settings_set_strv (settings, key, (const gchar * const *)values); + g_free (values); +} diff --git a/xed/xed-settings.h b/xed/xed-settings.h new file mode 100644 index 0000000..3da7182 --- /dev/null +++ b/xed/xed-settings.h @@ -0,0 +1,132 @@ +/* + * xed-settings.h + * This file is part of xed + * + * Copyright (C) 2009 - Ignacio Casal Quinteiro + * 2002 - Paolo Maggi + * + * xed is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xed is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with xed; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + + +#ifndef __XED_SETTINGS_H__ +#define __XED_SETTINGS_H__ + +#include +#include +#include "xed-app.h" + +G_BEGIN_DECLS + +#define XED_TYPE_SETTINGS (xed_settings_get_type ()) +#define XED_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_SETTINGS, XedSettings)) +#define XED_SETTINGS_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_SETTINGS, XedSettings const)) +#define XED_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_SETTINGS, XedSettingsClass)) +#define XED_IS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_SETTINGS)) +#define XED_IS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_SETTINGS)) +#define XED_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_SETTINGS, XedSettingsClass)) + +typedef struct _XedSettings XedSettings; +typedef struct _XedSettingsClass XedSettingsClass; +typedef struct _XedSettingsPrivate XedSettingsPrivate; + +struct _XedSettings +{ + GSettings parent; + + XedSettingsPrivate *priv; +}; + +struct _XedSettingsClass +{ + GSettingsClass parent_class; +}; + +// typedef enum { +// XED_TOOLBAR_SYSTEM = 0, +// XED_TOOLBAR_ICONS, +// XED_TOOLBAR_ICONS_AND_TEXT, +// XED_TOOLBAR_ICONS_BOTH_HORIZ +// } XedToolbarSetting; + +GType xed_settings_get_type (void) G_GNUC_CONST; + +GSettings *xed_settings_new (void); + +// XedLockdownMask xed_settings_get_lockdown (XedSettings *xs); + +gchar *xed_settings_get_system_font (XedSettings *xs); + +/* Utility functions */ +GSList *xed_settings_get_list (GSettings *settings, + const gchar *key); + +void xed_settings_set_list (GSettings *settings, + const gchar *key, + const GSList *list); + +/* key constants */ +#define XED_SETTINGS_USE_DEFAULT_FONT "use-default-font" +#define XED_SETTINGS_EDITOR_FONT "editor-font" +#define XED_SETTINGS_SCHEME "scheme" +#define XED_SETTINGS_CREATE_BACKUP_COPY "create-backup-copy" +#define XED_SETTINGS_AUTO_SAVE "auto-save" +#define XED_SETTINGS_AUTO_SAVE_INTERVAL "auto-save-interval" +#define XED_SETTINGS_UNDO_ACTIONS_LIMIT "undo-actions-limit" +#define XED_SETTINGS_MAX_UNDO_ACTIONS "max-undo-actions" +#define XED_SETTINGS_WRAP_MODE "wrap-mode" +#define XED_SETTINGS_TABS_SIZE "tabs-size" +#define XED_SETTINGS_INSERT_SPACES "insert-spaces" +#define XED_SETTINGS_AUTO_INDENT "auto-indent" +#define XED_SETTINGS_DISPLAY_LINE_NUMBERS "display-line-numbers" +#define XED_SETTINGS_HIGHLIGHT_CURRENT_LINE "highlight-current-line" +#define XED_SETTINGS_BRACKET_MATCHING "bracket-matching" +#define XED_SETTINGS_DISPLAY_RIGHT_MARGIN "display-right-margin" +#define XED_SETTINGS_RIGHT_MARGIN_POSITION "right-margin-position" +#define XED_SETTINGS_SMART_HOME_END "smart-home-end" +#define XED_SETTINGS_WRITABLE_VFS_SCHEMES "writable-vfs-schemes" +#define XED_SETTINGS_RESTORE_CURSOR_POSITION "restore-cursor-position" +#define XED_SETTINGS_SYNTAX_HIGHLIGHTING "syntax-highlighting" +#define XED_SETTINGS_SEARCH_HIGHLIGHTING "search-highlighting" +#define XED_SETTINGS_ENABLE_TAB_SCROLLING "enable-tab-scrolling" +#define XED_SETTINGS_TOOLBAR_VISIBLE "toolbar-visible" +#define XED_SETTINGS_STATUSBAR_VISIBLE "statusbar-visible" +#define XED_SETTINGS_SIDE_PANEL_VISIBLE "side-panel-visible" +#define XED_SETTINGS_BOTTOM_PANEL_VISIBLE "bottom-panel-visible" +#define XED_SETTINGS_MAX_RECENTS "max-recents" +#define XED_SETTINGS_PRINT_SYNTAX_HIGHLIGHTING "print-syntax-highlighting" +#define XED_SETTINGS_PRINT_HEADER "print-header" +#define XED_SETTINGS_PRINT_WRAP_MODE "print-wrap-mode" +#define XED_SETTINGS_PRINT_LINE_NUMBERS "print-line-numbers" +#define XED_SETTINGS_PRINT_FONT_BODY_PANGO "print-font-body-pango" +#define XED_SETTINGS_PRINT_FONT_HEADER_PANGO "print-font-header-pango" +#define XED_SETTINGS_PRINT_FONT_NUMBERS_PANGO "print-font-numbers-pango" +#define XED_SETTINGS_ENCODING_AUTO_DETECTED "auto-detected" +#define XED_SETTINGS_ENCODING_SHOWN_IN_MENU "shown-in-menu" +#define XED_SETTINGS_ACTIVE_PLUGINS "active-plugins" + +/* window state keys */ +#define XED_SETTINGS_WINDOW_STATE "state" +#define XED_SETTINGS_WINDOW_SIZE "size" +#define XED_SETTINGS_SIDE_PANEL_SIZE "side-panel-size" +#define XED_SETTINGS_SIDE_PANEL_ACTIVE_PAGE "side-panel-active-page" +#define XED_SETTINGS_BOTTOM_PANEL_SIZE "bottom-panel-size" +#define XED_SETTINGS_BOTTOM_PANEL_ACTIVE_PAGE "bottom-panel-active-page" +#define XED_SETTINGS_ACTIVE_FILE_FILTER "filter-id" + +G_END_DECLS + +#endif /* __XED_SETTINGS_H__ */ diff --git a/xed/xed-style-scheme-manager.c b/xed/xed-style-scheme-manager.c index 82ea3b5..cb40bfa 100644 --- a/xed/xed-style-scheme-manager.c +++ b/xed/xed-style-scheme-manager.c @@ -42,7 +42,6 @@ #include #include "xed-style-scheme-manager.h" -#include "xed-prefs-manager.h" #include "xed-dirs.h" static GtkSourceStyleSchemeManager *style_scheme_manager = NULL; @@ -62,7 +61,7 @@ get_xed_styles_path (void) NULL); g_free (config_dir); } - + return dir; } @@ -77,7 +76,7 @@ add_xed_styles_path (GtkSourceStyleSchemeManager *mgr) { gtk_source_style_scheme_manager_append_search_path (mgr, dir); g_free (dir); - } + } } GtkSourceStyleSchemeManager * @@ -113,12 +112,12 @@ xed_style_scheme_manager_list_schemes_sorted (GtkSourceStyleSchemeManager *manag g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager), NULL); scheme_ids = gtk_source_style_scheme_manager_get_scheme_ids (manager); - + while (*scheme_ids != NULL) { GtkSourceStyleScheme *scheme; - scheme = gtk_source_style_scheme_manager_get_scheme (manager, + scheme = gtk_source_style_scheme_manager_get_scheme (manager, *scheme_ids); schemes = g_slist_prepend (schemes, scheme); @@ -365,9 +364,9 @@ _xed_style_scheme_manager_uninstall_scheme (GtkSourceStyleSchemeManager *manager if (g_unlink (filename) == -1) return FALSE; - + /* Reload the available style schemes */ gtk_source_style_scheme_manager_force_rescan (manager); - - return TRUE; + + return TRUE; } diff --git a/xed/xed-tab.c b/xed/xed-tab.c index 2fd7ebb..c090289 100644 --- a/xed/xed-tab.c +++ b/xed/xed-tab.c @@ -42,8 +42,8 @@ #include "xed-print-preview.h" #include "xed-progress-message-area.h" #include "xed-debug.h" -#include "xed-prefs-manager-app.h" #include "xed-enum-types.h" +#include "xed-settings.h" #define XED_TAB_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_TAB, XedTabPrivate)) @@ -51,6 +51,8 @@ struct _XedTabPrivate { + GSettings *editor; + XedTabState state; GtkWidget *view; @@ -73,7 +75,7 @@ struct _XedTabPrivate XedDocumentSaveFlags save_flags; - gint auto_save_interval; + guint auto_save_interval; guint auto_save_timeout; gint not_editable : 1; @@ -223,6 +225,8 @@ xed_tab_dispose (GObject *object) tab->priv->tmp_save_location = NULL; } + g_clear_object (&tab->priv->editor); + G_OBJECT_CLASS (xed_tab_parent_class)->dispose (object); } @@ -372,7 +376,9 @@ set_view_properties_according_to_state (XedTab *tab, XedTabState state) { gboolean val; + gboolean hl_current_line; + hl_current_line = g_settings_get_boolean (tab->priv->editor, XED_SETTINGS_HIGHLIGHT_CURRENT_LINE); val = ((state == XED_TAB_STATE_NORMAL) && (tab->priv->print_preview == NULL) && !tab->priv->not_editable); gtk_text_view_set_editable (GTK_TEXT_VIEW (tab->priv->view), val); @@ -381,7 +387,7 @@ set_view_properties_according_to_state (XedTab *tab, val = ((state != XED_TAB_STATE_LOADING) && (state != XED_TAB_STATE_CLOSING) && - (xed_prefs_manager_get_highlight_current_line ())); + (hl_current_line)); gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (tab->priv->view), val); } @@ -1418,15 +1424,15 @@ xed_tab_init (XedTab *tab) { GtkWidget *sw; XedDocument *doc; + gboolean auto_save; + guint auto_save_interval; tab->priv = XED_TAB_GET_PRIVATE (tab); + tab->priv->editor = g_settings_new ("org.x.editor.preferences.editor"); tab->priv->state = XED_TAB_STATE_NORMAL; - tab->priv->not_editable = FALSE; - tab->priv->save_flags = 0; - tab->priv->ask_if_externally_modified = TRUE; gtk_orientable_set_orientation (GTK_ORIENTABLE (tab), GTK_ORIENTATION_VERTICAL); @@ -1438,14 +1444,17 @@ xed_tab_init (XedTab *tab) gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); /* Manage auto save data */ - tab->priv->auto_save = xed_prefs_manager_get_auto_save (); + auto_save = g_settings_get_boolean (tab->priv->editor, XED_SETTINGS_AUTO_SAVE); + auto_save_interval = g_settings_get_uint (tab->priv->editor, XED_SETTINGS_AUTO_SAVE_INTERVAL); + tab->priv->auto_save = auto_save; tab->priv->auto_save = (tab->priv->auto_save != FALSE); - tab->priv->auto_save_interval = xed_prefs_manager_get_auto_save_interval (); + tab->priv->auto_save_interval = auto_save_interval; + /*FIXME if (tab->priv->auto_save_interval <= 0) { tab->priv->auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL; - } + }*/ /* Create the view */ doc = xed_document_new (); diff --git a/xed/xed-utils.c b/xed/xed-utils.c index 56bda94..cb74976 100644 --- a/xed/xed-utils.c +++ b/xed/xed-utils.c @@ -48,7 +48,6 @@ #include "xed-utils.h" #include "xed-document.h" -#include "xed-prefs-manager.h" #include "xed-debug.h" /* For the workspace/viewport stuff */ diff --git a/xed/xed-utils.h b/xed/xed-utils.h index abe83be..79749f5 100644 --- a/xed/xed-utils.h +++ b/xed/xed-utils.h @@ -37,6 +37,7 @@ #include #include #include +#include G_BEGIN_DECLS diff --git a/xed/xed-view.c b/xed/xed-view.c index 74cce53..76998a1 100644 --- a/xed/xed-view.c +++ b/xed/xed-view.c @@ -13,10 +13,10 @@ #include "xed-view-activatable.h" #include "xed-plugins-engine.h" #include "xed-debug.h" -#include "xed-prefs-manager.h" -#include "xed-prefs-manager-app.h" #include "xed-marshal.h" #include "xed-utils.h" +#include "xed-settings.h" +#include "xed-app.h" #define XED_VIEW_SCROLL_MARGIN 0.02 #define XED_VIEW_SEARCH_DIALOG_TIMEOUT (30*1000) /* 30 seconds */ @@ -30,6 +30,7 @@ enum struct _XedViewPrivate { + GSettings *editor_settings; GtkTextIter start_search_iter; GtkWidget *search_window; GtkWidget *search_entry; @@ -41,20 +42,9 @@ struct _XedViewPrivate guint view_realized : 1; }; -static void xed_view_dispose (GObject *object); -static void xed_view_finalize (GObject *object); -static void xed_view_realize (GtkWidget *widget); -static gint xed_view_focus_out (GtkWidget *widget, GdkEventFocus *event); -static gboolean xed_view_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint timestamp); -static void xed_view_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, - GtkSelectionData *selection_data, guint info, guint timestamp); -static gboolean xed_view_drag_drop (GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint timestamp); -static gboolean xed_view_button_press_event (GtkWidget *widget, GdkEventButton *event); + static gboolean start_interactive_goto_line (XedView *view); static void hide_search_window (XedView *view, gboolean cancel); -static gboolean xed_view_draw (GtkWidget *widget, cairo_t *cr); -static void search_highlight_updated_cb (XedDocument *doc, GtkTextIter *start, GtkTextIter *end, XedView *view); -static void xed_view_delete_from_cursor (GtkTextView *text_view, GtkDeleteType type, gint count); G_DEFINE_TYPE(XedView, xed_view, GTK_SOURCE_TYPE_VIEW) @@ -81,76 +71,52 @@ document_read_only_notify_handler (XedDocument *document, } static void -xed_view_class_init (XedViewClass *klass) +search_highlight_updated_cb (XedDocument *doc, + GtkTextIter *start, + GtkTextIter *end, + XedView *view) { - GObjectClass *object_class = G_OBJECT_CLASS(klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); - GtkTextViewClass *text_view_class = GTK_TEXT_VIEW_CLASS(klass); + GdkRectangle visible_rect; + GdkRectangle updated_rect; + GdkRectangle redraw_rect; + gint y; + gint height; + GtkTextView *text_view; - GtkBindingSet *binding_set; + text_view = GTK_TEXT_VIEW(view); - object_class->dispose = xed_view_dispose; - object_class->finalize = xed_view_finalize; + g_return_if_fail(xed_document_get_enable_search_highlighting (XED_DOCUMENT (gtk_text_view_get_buffer (text_view)))); - widget_class->focus_out_event = xed_view_focus_out; - widget_class->draw = xed_view_draw; + /* get visible area */ + gtk_text_view_get_visible_rect (text_view, &visible_rect); - /* - * Override the gtk_text_view_drag_motion and drag_drop - * functions to get URIs - * - * If the mime type is text/uri-list, then we will accept - * the potential drop, or request the data (depending on the - * function). - * - * If the drag context has any other mime type, then pass the - * information onto the GtkTextView's standard handlers. - * (widget_class->function_name). - * - * See bug #89881 for details - */ - widget_class->drag_motion = xed_view_drag_motion; - widget_class->drag_data_received = xed_view_drag_data_received; - widget_class->drag_drop = xed_view_drag_drop; - widget_class->button_press_event = xed_view_button_press_event; - widget_class->realize = xed_view_realize; - klass->start_interactive_goto_line = start_interactive_goto_line; + /* get updated rectangle */ + gtk_text_view_get_line_yrange (text_view, start, &y, &height); + updated_rect.y = y; + gtk_text_view_get_line_yrange (text_view, end, &y, &height); + updated_rect.height = y + height - updated_rect.y; + updated_rect.x = visible_rect.x; + updated_rect.width = visible_rect.width; - text_view_class->delete_from_cursor = xed_view_delete_from_cursor; + /* intersect both rectangles to see whether we need to queue a redraw */ + if (gdk_rectangle_intersect (&updated_rect, &visible_rect, &redraw_rect)) + { + GdkRectangle widget_rect; + gtk_text_view_buffer_to_window_coords (text_view, GTK_TEXT_WINDOW_WIDGET, redraw_rect.x, redraw_rect.y, + &widget_rect.x, &widget_rect.y); - view_signals[START_INTERACTIVE_GOTO_LINE] = g_signal_new ("start_interactive_goto_line", - G_TYPE_FROM_CLASS(object_class), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET(XedViewClass, start_interactive_goto_line), - NULL, NULL, xed_marshal_BOOLEAN__NONE, G_TYPE_BOOLEAN, 0); + widget_rect.width = redraw_rect.width; + widget_rect.height = redraw_rect.height; - /* A new signal DROP_URIS has been added to allow plugins to intercept - * the default dnd behaviour of 'text/uri-list'. XedView now handles - * dnd in the default handlers of drag_drop, drag_motion and - * drag_data_received. The view emits drop_uris from drag_data_received - * if valid uris have been dropped. Plugins should connect to - * drag_motion, drag_drop and drag_data_received to change this - * default behaviour. They should _NOT_ use this signal because this - * will not prevent xed from loading the uri - */ - view_signals[DROP_URIS] = g_signal_new ("drop_uris", G_TYPE_FROM_CLASS(object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET(XedViewClass, drop_uris), - NULL, NULL, g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, G_TYPE_STRV); - - g_type_class_add_private (klass, sizeof(XedViewPrivate)); - - binding_set = gtk_binding_set_by_class (klass); - - gtk_binding_entry_add_signal (binding_set, GDK_KEY_i, GDK_CONTROL_MASK, "start_interactive_goto_line", 0); - - gtk_binding_entry_add_signal (binding_set, GDK_KEY_d, GDK_CONTROL_MASK, "delete_from_cursor", 2, G_TYPE_ENUM, - GTK_DELETE_PARAGRAPHS, G_TYPE_INT, 1); + gtk_widget_queue_draw_area (GTK_WIDGET(text_view), widget_rect.x, widget_rect.y, widget_rect.width, + widget_rect.height); + } } static void current_buffer_removed (XedView *view) { - if (view->priv->current_buffer) + if (view->priv->current_buffer != NULL) { g_signal_handlers_disconnect_by_func(view->priv->current_buffer, document_read_only_notify_handler, view); g_signal_handlers_disconnect_by_func(view->priv->current_buffer, search_highlight_updated_cb, view); @@ -207,36 +173,9 @@ xed_view_init (XedView *view) xed_debug (DEBUG_VIEW); - view->priv = XED_VIEW_GET_PRIVATE(view); + view->priv = XED_VIEW_GET_PRIVATE (view); - /* - * Set tab, fonts, wrap mode, colors, etc. according - * to preferences - */ - if (!xed_prefs_manager_get_use_default_font ()) - { - gchar *editor_font; - editor_font = xed_prefs_manager_get_editor_font (); - xed_view_set_font (view, FALSE, editor_font); - g_free (editor_font); - } - else - { - xed_view_set_font (view, TRUE, NULL); - } - - g_object_set (G_OBJECT(view), - "wrap_mode", xed_prefs_manager_get_wrap_mode (), - "show_line_numbers", xed_prefs_manager_get_display_line_numbers (), - "auto_indent", xed_prefs_manager_get_auto_indent (), - "tab_width", xed_prefs_manager_get_tabs_size (), - "insert_spaces_instead_of_tabs", xed_prefs_manager_get_insert_spaces (), - "show_right_margin", xed_prefs_manager_get_display_right_margin (), - "right_margin_position", xed_prefs_manager_get_right_margin_position (), - "highlight_current_line", xed_prefs_manager_get_highlight_current_line (), - "smart_home_end", xed_prefs_manager_get_smart_home_end (), - "indent_on_tab", TRUE, - NULL); + view->priv->editor_settings = g_settings_new ("org.x.editor.preferences.editor"); view->priv->typeselect_flush_timeout = 0; @@ -263,15 +202,10 @@ xed_view_init (XedView *view) static void xed_view_dispose (GObject *object) { - XedView *view; + XedView *view = XED_VIEW (object); - view = XED_VIEW(object); - - if (view->priv->extensions != NULL) - { - g_object_unref (view->priv->extensions); - view->priv->extensions = NULL; - } + g_clear_object (&view->priv->extensions); + g_clear_object (&view->priv->editor_settings); if (view->priv->search_window != NULL) { @@ -285,30 +219,116 @@ xed_view_dispose (GObject *object) } } - /* Disconnect notify buffer because the destroy of the textview will - set the buffer to NULL, and we call get_buffer in the notify which - would reinstate a GtkTextBuffer which we don't want */ current_buffer_removed (view); - g_signal_handlers_disconnect_by_func(view, on_notify_buffer_cb, NULL); - (* G_OBJECT_CLASS (xed_view_parent_class)->dispose) (object); + /* Disconnect notify buffer because the destroy of the textview will set + * the buffer to NULL, and we call get_buffer in the notify which would + * reinstate a buffer which we don't want. + * There is no problem calling g_signal_handlers_disconnect_by_func() + * several times (if dispose() is called several times). + */ + g_signal_handlers_disconnect_by_func (view, on_notify_buffer_cb, NULL); + + G_OBJECT_CLASS (xed_view_parent_class)->dispose (object); } static void -xed_view_finalize (GObject *object) +xed_view_constructed (GObject *object) { XedView *view; - view = XED_VIEW(object); - current_buffer_removed (view); + XedViewPrivate *priv; + gboolean use_default_font; - G_OBJECT_CLASS (xed_view_parent_class)->finalize (object); + view = XED_VIEW (object); + priv = view->priv; + + /* Get setting values */ + use_default_font = g_settings_get_boolean (view->priv->editor_settings, XED_SETTINGS_USE_DEFAULT_FONT); + + /* + * Set tab, fonts, wrap mode, colors, etc. according to preferences + */ + if (!use_default_font) + { + gchar *editor_font; + + editor_font = g_settings_get_string (view->priv->editor_settings, XED_SETTINGS_EDITOR_FONT); + + xed_view_set_font (view, FALSE, editor_font); + + g_free (editor_font); + } + else + { + xed_view_set_font (view, TRUE, NULL); + } + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_DISPLAY_LINE_NUMBERS, + view, + "show-line-numbers", + G_SETTINGS_BIND_GET); + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_AUTO_INDENT, + view, + "auto-indent", + G_SETTINGS_BIND_GET); + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_TABS_SIZE, + view, + "tab-width", + G_SETTINGS_BIND_GET); + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_INSERT_SPACES, + view, + "insert-spaces-instead-of-tabs", + G_SETTINGS_BIND_GET); + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_DISPLAY_RIGHT_MARGIN, + view, + "show-right-margin", + G_SETTINGS_BIND_GET); + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_RIGHT_MARGIN_POSITION, + view, + "right-margin-position", + G_SETTINGS_BIND_GET); + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_HIGHLIGHT_CURRENT_LINE, + view, + "highlight-current-line", + G_SETTINGS_BIND_GET); + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_WRAP_MODE, + view, + "wrap-mode", + G_SETTINGS_BIND_GET); + + g_settings_bind (priv->editor_settings, + XED_SETTINGS_SMART_HOME_END, + view, + "smart-home-end", + G_SETTINGS_BIND_GET); + + g_object_set (G_OBJECT (view), + "indent_on_tab", TRUE, + NULL); + + G_OBJECT_CLASS (xed_view_parent_class)->constructed (object); } static gint -xed_view_focus_out (GtkWidget *widget, +xed_view_focus_out (GtkWidget *widget, GdkEventFocus *event) { - XedView *view = XED_VIEW(widget); + XedView *view = XED_VIEW (widget); gtk_widget_queue_draw (widget); @@ -318,11 +338,384 @@ xed_view_focus_out (GtkWidget *widget, hide_search_window (view, FALSE); } - (* GTK_WIDGET_CLASS (xed_view_parent_class)->focus_out_event) (widget, event); + GTK_WIDGET_CLASS (xed_view_parent_class)->focus_out_event (widget, event); return FALSE; } +static gboolean +xed_view_draw (GtkWidget *widget, + cairo_t *cr) +{ + GtkTextView *text_view; + XedDocument *doc; + GdkWindow *window; + + text_view = GTK_TEXT_VIEW(widget); + + doc = XED_DOCUMENT(gtk_text_view_get_buffer (text_view)); + window = gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT); + + if (gtk_cairo_should_draw_window (cr, window) && xed_document_get_enable_search_highlighting (doc)) + { + GdkRectangle visible_rect; + GtkTextIter iter1, iter2; + + gtk_text_view_get_visible_rect (text_view, &visible_rect); + gtk_text_view_get_line_at_y (text_view, &iter1, visible_rect.y, NULL); + gtk_text_view_get_line_at_y (text_view, &iter2, visible_rect.y + visible_rect.height, NULL); + gtk_text_iter_forward_line (&iter2); + + _xed_document_search_region (doc, &iter1, &iter2); + } + + return GTK_WIDGET_CLASS (xed_view_parent_class)->draw (widget, cr); +} + +static GdkAtom +drag_get_uri_target (GtkWidget *widget, + GdkDragContext *context) +{ + GdkAtom target; + GtkTargetList *tl; + + tl = gtk_target_list_new (NULL, 0); + gtk_target_list_add_uri_targets (tl, 0); + + target = gtk_drag_dest_find_target (widget, context, tl); + gtk_target_list_unref (tl); + + return target; +} + +static gboolean +xed_view_drag_motion (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint timestamp) +{ + gboolean result; + + /* Chain up to allow textview to scroll and position dnd mark, note + * that this needs to be checked if gtksourceview or gtktextview + * changes drag_motion behaviour */ + result = GTK_WIDGET_CLASS (xed_view_parent_class)->drag_motion (widget, context, x, y, timestamp); + + /* If this is a URL, deal with it here */ + if (drag_get_uri_target (widget, context) != GDK_NONE) + { + gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), timestamp); + result = TRUE; + } + + return result; +} + +static void +xed_view_drag_data_received (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *selection_data, + guint info, + guint timestamp) +{ + gchar **uri_list; + + /* If this is an URL emit DROP_URIS, otherwise chain up the signal */ + if (info == TARGET_URI_LIST) + { + uri_list = xed_utils_drop_get_uris (selection_data); + + if (uri_list != NULL) + { + g_signal_emit (widget, view_signals[DROP_URIS], 0, uri_list); + g_strfreev (uri_list); + gtk_drag_finish (context, TRUE, FALSE, timestamp); + } + } + else + { + GTK_WIDGET_CLASS (xed_view_parent_class)->drag_data_received (widget, context, x, y, selection_data, info, + timestamp); + } +} + +static gboolean +xed_view_drag_drop (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint timestamp) +{ + gboolean result; + GdkAtom target; + + /* If this is a URL, just get the drag data */ + target = drag_get_uri_target (widget, context); + + if (target != GDK_NONE) + { + gtk_drag_get_data (widget, context, target, timestamp); + result = TRUE; + } + else + { + /* Chain up */ + result = GTK_WIDGET_CLASS (xed_view_parent_class)->drag_drop (widget, context, x, y, timestamp); + } + + return result; +} + +static GtkWidget * +create_line_numbers_menu (GtkWidget *view) +{ + GtkWidget *menu; + GtkWidget *item; + + menu = gtk_menu_new (); + + item = gtk_check_menu_item_new_with_mnemonic (_("_Display line numbers")); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(item), + gtk_source_view_get_show_line_numbers (GTK_SOURCE_VIEW(view))); + + g_settings_bind (XED_VIEW (view)->priv->editor_settings, + "active", + item, + XED_SETTINGS_DISPLAY_LINE_NUMBERS, + G_SETTINGS_BIND_SET); + + gtk_menu_shell_append (GTK_MENU_SHELL(menu), item); + + gtk_widget_show_all (menu); + + return menu; +} + +static void +show_line_numbers_menu (GtkWidget *view, + GdkEventButton *event) +{ + GtkWidget *menu; + + menu = create_line_numbers_menu (view); + gtk_menu_popup (GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time); +} + +static gboolean +xed_view_button_press_event (GtkWidget *widget, + GdkEventButton *event) +{ + if ((event->type == GDK_BUTTON_PRESS) + && (event->button == 3) + && (event->window == gtk_text_view_get_window (GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_LEFT))) + { + + show_line_numbers_menu (widget, event); + + return TRUE; + } + + return GTK_WIDGET_CLASS (xed_view_parent_class)->button_press_event (widget, event); +} + +static void +xed_view_realize (GtkWidget *widget) +{ + XedView *view = XED_VIEW (widget); + + if (!view->priv->view_realized) + { + peas_extension_set_call (view->priv->extensions, "activate"); + view->priv->view_realized = TRUE; + } + + GTK_WIDGET_CLASS (xed_view_parent_class)->realize (widget); +} + +static void +delete_line (GtkTextView *text_view, + gint count) +{ + GtkTextIter start; + GtkTextIter end; + GtkTextBuffer *buffer; + + buffer = gtk_text_view_get_buffer (text_view); + + gtk_text_view_reset_im_context (text_view); + + /* If there is a selection delete the selected lines and + * ignore count */ + if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end)) + { + gtk_text_iter_order (&start, &end); + if (gtk_text_iter_starts_line (&end)) + { + /* Do no delete the line with the cursor if the cursor + * is at the beginning of the line */ + count = 0; + } + else + { + count = 1; + } + } + + gtk_text_iter_set_line_offset (&start, 0); + + if (count > 0) + { + gtk_text_iter_forward_lines (&end, count); + if (gtk_text_iter_is_end (&end)) + { + if (gtk_text_iter_backward_line (&start) && !gtk_text_iter_ends_line (&start)) + { + gtk_text_iter_forward_to_line_end (&start); + } + } + } + else if (count < 0) + { + if (!gtk_text_iter_ends_line (&end)) + { + gtk_text_iter_forward_to_line_end (&end); + } + + while (count < 0) + { + if (!gtk_text_iter_backward_line (&start)) + { + break; + } + ++count; + } + + if (count == 0) + { + if (!gtk_text_iter_ends_line (&start)) + { + gtk_text_iter_forward_to_line_end (&start); + } + } + else + { + gtk_text_iter_forward_line (&end); + } + } + + if (!gtk_text_iter_equal (&start, &end)) + { + GtkTextIter cur = start; + gtk_text_iter_set_line_offset (&cur, 0); + gtk_text_buffer_begin_user_action (buffer); + gtk_text_buffer_place_cursor (buffer, &cur); + gtk_text_buffer_delete_interactive (buffer, &start, &end, gtk_text_view_get_editable (text_view)); + gtk_text_buffer_end_user_action (buffer); + gtk_text_view_scroll_mark_onscreen (text_view, gtk_text_buffer_get_insert (buffer)); + } + else + { + gtk_widget_error_bell (GTK_WIDGET(text_view)); + } +} + +static void +xed_view_delete_from_cursor (GtkTextView *text_view, + GtkDeleteType type, + gint count) +{ + /* We override the standard handler for delete_from_cursor since + the GTK_DELETE_PARAGRAPHS case is not implemented as we like (i.e. it + does not remove the carriage return in the previous line) + */ + switch (type) + { + case GTK_DELETE_PARAGRAPHS: + delete_line (text_view, count); + break; + default: + GTK_TEXT_VIEW_CLASS (xed_view_parent_class)->delete_from_cursor (text_view, type, count); + break; + } +} + +static void +xed_view_class_init (XedViewClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); + GtkTextViewClass *text_view_class = GTK_TEXT_VIEW_CLASS(klass); + GtkBindingSet *binding_set; + + object_class->dispose = xed_view_dispose; + object_class->constructed = xed_view_constructed; + + widget_class->focus_out_event = xed_view_focus_out; + widget_class->draw = xed_view_draw; + + /* + * Override the gtk_text_view_drag_motion and drag_drop + * functions to get URIs + * + * If the mime type is text/uri-list, then we will accept + * the potential drop, or request the data (depending on the + * function). + * + * If the drag context has any other mime type, then pass the + * information onto the GtkTextView's standard handlers. + * (widget_class->function_name). + * + * See bug #89881 for details + */ + widget_class->drag_motion = xed_view_drag_motion; + widget_class->drag_data_received = xed_view_drag_data_received; + widget_class->drag_drop = xed_view_drag_drop; + widget_class->button_press_event = xed_view_button_press_event; + widget_class->realize = xed_view_realize; + klass->start_interactive_goto_line = start_interactive_goto_line; + + text_view_class->delete_from_cursor = xed_view_delete_from_cursor; + + view_signals[START_INTERACTIVE_GOTO_LINE] = + g_signal_new ("start_interactive_goto_line", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (XedViewClass, start_interactive_goto_line), + NULL, NULL, + xed_marshal_BOOLEAN__NONE, + G_TYPE_BOOLEAN, 0); + + /* A new signal DROP_URIS has been added to allow plugins to intercept + * the default dnd behaviour of 'text/uri-list'. XedView now handles + * dnd in the default handlers of drag_drop, drag_motion and + * drag_data_received. The view emits drop_uris from drag_data_received + * if valid uris have been dropped. Plugins should connect to + * drag_motion, drag_drop and drag_data_received to change this + * default behaviour. They should _NOT_ use this signal because this + * will not prevent xed from loading the uri + */ + view_signals[DROP_URIS] = + g_signal_new ("drop_uris", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (XedViewClass, drop_uris), + NULL, NULL, + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, 1, G_TYPE_STRV); + + g_type_class_add_private (klass, sizeof (XedViewPrivate)); + + binding_set = gtk_binding_set_by_class (klass); + + gtk_binding_entry_add_signal (binding_set, GDK_KEY_i, GDK_CONTROL_MASK, "start_interactive_goto_line", 0); + + gtk_binding_entry_add_signal (binding_set, GDK_KEY_d, GDK_CONTROL_MASK, "delete_from_cursor", 2, G_TYPE_ENUM, + GTK_DELETE_PARAGRAPHS, G_TYPE_INT, 1); +} + /** * xed_view_new: * @doc: a #XedDocument @@ -338,10 +731,15 @@ xed_view_new (XedDocument *doc) GtkWidget *view; xed_debug_message (DEBUG_VIEW, "START"); + g_return_val_if_fail(XED_IS_DOCUMENT (doc), NULL); + view = GTK_WIDGET(g_object_new (XED_TYPE_VIEW, "buffer", doc, NULL)); + xed_debug_message (DEBUG_VIEW, "END: %d", G_OBJECT (view)->ref_count); + gtk_widget_show_all (view); + return view; } @@ -485,8 +883,8 @@ xed_view_scroll_to_cursor (XedView *view) * otherwise sets it to @font_name. **/ void -xed_view_set_font (XedView *view, - gboolean def, +xed_view_set_font (XedView *view, + gboolean def, const gchar *font_name) { PangoFontDescription *font_desc = NULL; @@ -497,24 +895,28 @@ xed_view_set_font (XedView *view, if (def) { + GSettings *settings; gchar *font; - font = xed_prefs_manager_get_system_font (); + + settings = _xed_app_get_settings (xed_app_get_default ()); + font = xed_settings_get_system_font (XED_SETTINGS (settings)); font_desc = pango_font_description_from_string (font); + g_free (font); } else { - g_return_if_fail(font_name != NULL); + g_return_if_fail (font_name != NULL); font_desc = pango_font_description_from_string (font_name); } - g_return_if_fail(font_desc != NULL); - gtk_widget_modify_font (GTK_WIDGET(view), font_desc); + g_return_if_fail (font_desc != NULL); + gtk_widget_modify_font (GTK_WIDGET (view), font_desc); pango_font_description_free (font_desc); } static void -set_entry_state (GtkWidget *entry, +set_entry_state (GtkWidget *entry, XedSearchEntryState state) { GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET(entry)); @@ -532,7 +934,7 @@ set_entry_state (GtkWidget *entry, /* Cut and paste from gtkwindow.c */ static void send_focus_change (GtkWidget *widget, - gboolean in) + gboolean in) { GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE); @@ -614,18 +1016,18 @@ update_search_window_position (XedView *view) } static gboolean -search_window_deleted (GtkWidget *widget, +search_window_deleted (GtkWidget *widget, GdkEventAny *event, - XedView *view) + XedView *view) { hide_search_window (view, FALSE); return TRUE; } static gboolean -search_window_button_pressed (GtkWidget *widget, +search_window_button_pressed (GtkWidget *widget, GdkEventButton *event, - XedView *view) + XedView *view) { hide_search_window (view, FALSE); gtk_propagate_event (GTK_WIDGET(view), (GdkEvent *) event); @@ -633,9 +1035,9 @@ search_window_button_pressed (GtkWidget *widget, } static gboolean -search_window_key_pressed (GtkWidget *widget, +search_window_key_pressed (GtkWidget *widget, GdkEventKey *event, - XedView *view) + XedView *view) { gboolean retval = FALSE; guint modifiers; @@ -661,7 +1063,7 @@ search_window_key_pressed (GtkWidget *widget, static void search_entry_activate (GtkEntry *entry, - XedView *view) + XedView *view) { hide_search_window (view, FALSE); } @@ -692,8 +1094,8 @@ search_enable_popdown (GtkWidget *widget, static void search_entry_populate_popup (GtkEntry *entry, - GtkMenu *menu, - XedView *view) + GtkMenu *menu, + XedView *view) { GtkWidget *menu_item; view->priv->disable_popdown = TRUE; @@ -703,9 +1105,9 @@ search_entry_populate_popup (GtkEntry *entry, static void search_entry_insert_text (GtkEditable *editable, const gchar *text, - gint length, - gint *position, - XedView *view) + gint length, + gint *position, + XedView *view) { gunichar c; const gchar *p; @@ -1000,347 +1402,3 @@ start_interactive_goto_line (XedView *view) return TRUE; } - -static gboolean -xed_view_draw (GtkWidget *widget, - cairo_t *cr) -{ - GtkTextView *text_view; - XedDocument *doc; - GdkWindow *window; - - text_view = GTK_TEXT_VIEW(widget); - - doc = XED_DOCUMENT(gtk_text_view_get_buffer (text_view)); - window = gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT); - if (gtk_cairo_should_draw_window (cr, window) && xed_document_get_enable_search_highlighting (doc)) - { - GdkRectangle visible_rect; - GtkTextIter iter1, iter2; - - gtk_text_view_get_visible_rect (text_view, &visible_rect); - gtk_text_view_get_line_at_y (text_view, &iter1, visible_rect.y, NULL); - gtk_text_view_get_line_at_y (text_view, &iter2, visible_rect.y + visible_rect.height, NULL); - gtk_text_iter_forward_line (&iter2); - - _xed_document_search_region (doc, &iter1, &iter2); - } - - return GTK_WIDGET_CLASS (xed_view_parent_class)->draw (widget, cr); -} - -static GdkAtom -drag_get_uri_target (GtkWidget *widget, - GdkDragContext *context) -{ - GdkAtom target; - GtkTargetList *tl; - - tl = gtk_target_list_new (NULL, 0); - gtk_target_list_add_uri_targets (tl, 0); - target = gtk_drag_dest_find_target (widget, context, tl); - gtk_target_list_unref (tl); - - return target; -} - -static gboolean -xed_view_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint timestamp) -{ - gboolean result; - - /* Chain up to allow textview to scroll and position dnd mark, note - * that this needs to be checked if gtksourceview or gtktextview - * changes drag_motion behaviour */ - result = GTK_WIDGET_CLASS (xed_view_parent_class)->drag_motion (widget, context, x, y, timestamp); - - /* If this is a URL, deal with it here */ - if (drag_get_uri_target (widget, context) != GDK_NONE) - { - gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), timestamp); - result = TRUE; - } - - return result; -} - -static void -xed_view_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint timestamp) -{ - gchar **uri_list; - - /* If this is an URL emit DROP_URIS, otherwise chain up the signal */ - if (info == TARGET_URI_LIST) - { - uri_list = xed_utils_drop_get_uris (selection_data); - - if (uri_list != NULL) - { - g_signal_emit (widget, view_signals[DROP_URIS], 0, uri_list); - g_strfreev (uri_list); - gtk_drag_finish (context, TRUE, FALSE, timestamp); - } - } - else - { - GTK_WIDGET_CLASS (xed_view_parent_class)->drag_data_received (widget, context, x, y, selection_data, info, - timestamp); - } -} - -static gboolean -xed_view_drag_drop (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint timestamp) -{ - gboolean result; - GdkAtom target; - - /* If this is a URL, just get the drag data */ - target = drag_get_uri_target (widget, context); - - if (target != GDK_NONE) - { - gtk_drag_get_data (widget, context, target, timestamp); - result = TRUE; - } - else - { - /* Chain up */ - result = GTK_WIDGET_CLASS (xed_view_parent_class)->drag_drop (widget, context, x, y, timestamp); - } - - return result; -} - -static void -show_line_numbers_toggled (GtkMenu *menu, - XedView *view) -{ - gboolean show; - - show = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM(menu)); - xed_prefs_manager_set_display_line_numbers (show); -} - -static GtkWidget * -create_line_numbers_menu (GtkWidget *view) -{ - GtkWidget *menu; - GtkWidget *item; - - menu = gtk_menu_new (); - - item = gtk_check_menu_item_new_with_mnemonic (_("_Display line numbers")); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(item), - gtk_source_view_get_show_line_numbers (GTK_SOURCE_VIEW(view))); - g_signal_connect(item, "toggled", G_CALLBACK (show_line_numbers_toggled), view); - gtk_menu_shell_append (GTK_MENU_SHELL(menu), item); - - gtk_widget_show_all (menu); - - return menu; -} - -static void -show_line_numbers_menu (GtkWidget *view, - GdkEventButton *event) -{ - GtkWidget *menu; - - menu = create_line_numbers_menu (view); - gtk_menu_popup (GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time); -} - -static gboolean -xed_view_button_press_event (GtkWidget *widget, - GdkEventButton *event) -{ - if ((event->type == GDK_BUTTON_PRESS) - && (event->button == 3) - && (event->window == gtk_text_view_get_window (GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_LEFT))) - { - - show_line_numbers_menu (widget, event); - - return TRUE; - } - - return GTK_WIDGET_CLASS (xed_view_parent_class)->button_press_event (widget, event); -} - -static void -xed_view_realize (GtkWidget *widget) -{ - XedView *view = XED_VIEW (widget); - - if (!view->priv->view_realized) - { - peas_extension_set_call (view->priv->extensions, "activate"); - view->priv->view_realized = TRUE; - } - - GTK_WIDGET_CLASS (xed_view_parent_class)->realize (widget); -} - -static void -search_highlight_updated_cb (XedDocument *doc, - GtkTextIter *start, - GtkTextIter *end, - XedView *view) -{ - GdkRectangle visible_rect; - GdkRectangle updated_rect; - GdkRectangle redraw_rect; - gint y; - gint height; - GtkTextView *text_view; - - text_view = GTK_TEXT_VIEW(view); - - g_return_if_fail(xed_document_get_enable_search_highlighting (XED_DOCUMENT (gtk_text_view_get_buffer (text_view)))); - - /* get visible area */ - gtk_text_view_get_visible_rect (text_view, &visible_rect); - - /* get updated rectangle */ - gtk_text_view_get_line_yrange (text_view, start, &y, &height); - updated_rect.y = y; - gtk_text_view_get_line_yrange (text_view, end, &y, &height); - updated_rect.height = y + height - updated_rect.y; - updated_rect.x = visible_rect.x; - updated_rect.width = visible_rect.width; - - /* intersect both rectangles to see whether we need to queue a redraw */ - if (gdk_rectangle_intersect (&updated_rect, &visible_rect, &redraw_rect)) - { - GdkRectangle widget_rect; - gtk_text_view_buffer_to_window_coords (text_view, GTK_TEXT_WINDOW_WIDGET, redraw_rect.x, redraw_rect.y, - &widget_rect.x, &widget_rect.y); - - widget_rect.width = redraw_rect.width; - widget_rect.height = redraw_rect.height; - - gtk_widget_queue_draw_area (GTK_WIDGET(text_view), widget_rect.x, widget_rect.y, widget_rect.width, - widget_rect.height); - } -} - -static void -delete_line (GtkTextView *text_view, - gint count) -{ - GtkTextIter start; - GtkTextIter end; - GtkTextBuffer *buffer; - - buffer = gtk_text_view_get_buffer (text_view); - - gtk_text_view_reset_im_context (text_view); - - /* If there is a selection delete the selected lines and - * ignore count */ - if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end)) - { - gtk_text_iter_order (&start, &end); - if (gtk_text_iter_starts_line (&end)) - { - /* Do no delete the line with the cursor if the cursor - * is at the beginning of the line */ - count = 0; - } - else - { - count = 1; - } - } - - gtk_text_iter_set_line_offset (&start, 0); - - if (count > 0) - { - gtk_text_iter_forward_lines (&end, count); - if (gtk_text_iter_is_end (&end)) - { - if (gtk_text_iter_backward_line (&start) && !gtk_text_iter_ends_line (&start)) - { - gtk_text_iter_forward_to_line_end (&start); - } - } - } - else if (count < 0) - { - if (!gtk_text_iter_ends_line (&end)) - { - gtk_text_iter_forward_to_line_end (&end); - } - - while (count < 0) - { - if (!gtk_text_iter_backward_line (&start)) - { - break; - } - ++count; - } - - if (count == 0) - { - if (!gtk_text_iter_ends_line (&start)) - { - gtk_text_iter_forward_to_line_end (&start); - } - } - else - { - gtk_text_iter_forward_line (&end); - } - } - - if (!gtk_text_iter_equal (&start, &end)) - { - GtkTextIter cur = start; - gtk_text_iter_set_line_offset (&cur, 0); - gtk_text_buffer_begin_user_action (buffer); - gtk_text_buffer_place_cursor (buffer, &cur); - gtk_text_buffer_delete_interactive (buffer, &start, &end, gtk_text_view_get_editable (text_view)); - gtk_text_buffer_end_user_action (buffer); - gtk_text_view_scroll_mark_onscreen (text_view, gtk_text_buffer_get_insert (buffer)); - } - else - { - gtk_widget_error_bell (GTK_WIDGET(text_view)); - } -} - -static void -xed_view_delete_from_cursor (GtkTextView *text_view, - GtkDeleteType type, - gint count) -{ - /* We override the standard handler for delete_from_cursor since - the GTK_DELETE_PARAGRAPHS case is not implemented as we like (i.e. it - does not remove the carriage return in the previous line) - */ - switch (type) - { - case GTK_DELETE_PARAGRAPHS: - delete_line (text_view, count); - break; - default: - GTK_TEXT_VIEW_CLASS (xed_view_parent_class)->delete_from_cursor (text_view, type, count); - break; - } -} diff --git a/xed/xed-window-private.h b/xed/xed-window-private.h index 20ecea2..6796964 100644 --- a/xed/xed-window-private.h +++ b/xed/xed-window-private.h @@ -34,8 +34,8 @@ #include #include "xed/xed-window.h" -#include "xed-prefs-manager.h" #include "xed-message-bus.h" +#include "xed-settings.h" G_BEGIN_DECLS @@ -43,38 +43,42 @@ G_BEGIN_DECLS struct _XedWindowPrivate { - GtkWidget *notebook; + GSettings *editor_settings; + GSettings *ui_settings; + GSettings *window_settings; - GtkWidget *side_panel; - GtkWidget *bottom_panel; + GtkWidget *notebook; - GtkWidget *hpaned; - GtkWidget *vpaned; + GtkWidget *side_panel; + GtkWidget *bottom_panel; - GtkWidget *tab_width_combo; - GtkWidget *language_combo; - GtkWidget *show_side_pane_button; - GtkWidget *show_bottom_pane_button; - GtkWidget *bottom_pane_button_revealer; + GtkWidget *hpaned; + GtkWidget *vpaned; + + GtkWidget *tab_width_combo; + GtkWidget *language_combo; + GtkWidget *show_side_pane_button; + GtkWidget *show_bottom_pane_button; + GtkWidget *bottom_pane_button_revealer; XedMessageBus *message_bus; PeasExtensionSet *extensions; /* Widgets for fullscreen mode */ - GtkWidget *fullscreen_controls; - GtkWidget *fullscreen_controls_container; - guint fullscreen_animation_timeout_id; - gboolean fullscreen_animation_enter; + GtkWidget *fullscreen_controls; + GtkWidget *fullscreen_controls_container; + guint fullscreen_animation_timeout_id; + gboolean fullscreen_animation_enter; /* statusbar and context ids for statusbar messages */ - GtkWidget *statusbar; - GtkWidget *searchbar; - guint generic_message_cid; - guint tip_message_cid; - guint tab_width_id; - guint spaces_instead_of_tabs_id; - guint language_changed_id; - guint use_word_wrap_id; + GtkWidget *statusbar; + GtkWidget *searchbar; + guint generic_message_cid; + guint tip_message_cid; + guint tab_width_id; + guint spaces_instead_of_tabs_id; + guint language_changed_id; + guint use_word_wrap_id; /* Menus & Toolbars */ GtkUIManager *manager; @@ -94,28 +98,28 @@ struct _XedWindowPrivate guint recents_menu_ui_id; gulong recents_handler_id; - XedTab *active_tab; - gint num_tabs; + XedTab *active_tab; + gint num_tabs; - gint num_tabs_with_error; + gint num_tabs_with_error; gint width; gint height; GdkWindowState window_state; - gint side_panel_size; - gint bottom_panel_size; + gint side_panel_size; + gint bottom_panel_size; - XedWindowState state; + XedWindowState state; - gint bottom_panel_item_removed_handler_id; + gint bottom_panel_item_removed_handler_id; GtkWindowGroup *window_group; - GFile *default_location; + GFile *default_location; - gboolean removing_tabs : 1; - gboolean dispose_has_run : 1; + gboolean removing_tabs : 1; + gboolean dispose_has_run : 1; }; G_END_DECLS diff --git a/xed/xed-window.c b/xed/xed-window.c index 97deae0..4a10c77 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -22,7 +22,6 @@ #include "xed-commands.h" #include "xed-debug.h" #include "xed-language-manager.h" -#include "xed-prefs-manager-app.h" #include "xed-panel.h" #include "xed-documents-panel.h" #include "xed-plugins-engine.h" @@ -30,6 +29,7 @@ #include "xed-enum-types.h" #include "xed-dirs.h" #include "xed-status-combo-box.h" +#include "xed-settings.h" #define LANGUAGE_NONE (const gchar *)"LangNone" #define XED_UIFILE "xed-ui.xml" @@ -38,6 +38,9 @@ #define FULLSCREEN_ANIMATION_SPEED 4 +#define XED_WINDOW_DEFAULT_WIDTH 650 +#define XED_WINDOW_DEFAULT_HEIGHT 500 + #define XED_WINDOW_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_WINDOW, XedWindowPrivate)) /* Signals */ @@ -69,9 +72,9 @@ G_DEFINE_TYPE(XedWindow, xed_window, GTK_TYPE_WINDOW) static void recent_manager_changed (GtkRecentManager *manager, XedWindow *window); static void -xed_window_get_property (GObject *object, - guint prop_id, - GValue *value, +xed_window_get_property (GObject *object, + guint prop_id, + GValue *value, GParamSpec *pspec) { XedWindow *window = XED_WINDOW(object); @@ -90,41 +93,33 @@ xed_window_get_property (GObject *object, static void save_panes_state (XedWindow *window) { - gint pane_page; + gint panel_page; xed_debug (DEBUG_WINDOW); - if (xed_prefs_manager_window_size_can_set ()) + if (window->priv->side_panel_size > 0) { - xed_prefs_manager_set_window_size (window->priv->width, window->priv->height); + g_settings_set_int (window->priv->window_settings, XED_SETTINGS_SIDE_PANEL_SIZE, window->priv->side_panel_size); } - if (xed_prefs_manager_window_state_can_set ()) + panel_page = _xed_panel_get_active_item_id (XED_PANEL (window->priv->side_panel)); + if (panel_page != 0) { - xed_prefs_manager_set_window_state (window->priv->window_state); + g_settings_set_int (window->priv->window_settings, XED_SETTINGS_SIDE_PANEL_ACTIVE_PAGE, panel_page); } - if ((window->priv->side_panel_size > 0) && xed_prefs_manager_side_panel_size_can_set ()) + if (window->priv->bottom_panel_size > 0) { - xed_prefs_manager_set_side_panel_size (window->priv->side_panel_size); + g_settings_set_int (window->priv->window_settings, XED_SETTINGS_BOTTOM_PANEL_SIZE, window->priv->bottom_panel_size); } - pane_page = _xed_panel_get_active_item_id (XED_PANEL(window->priv->side_panel)); - if (pane_page != 0 && xed_prefs_manager_side_panel_active_page_can_set ()) + panel_page = _xed_panel_get_active_item_id (XED_PANEL(window->priv->bottom_panel)); + if (panel_page != 0) { - xed_prefs_manager_set_side_panel_active_page (pane_page); + g_settings_set_int (window->priv->window_settings, XED_SETTINGS_BOTTOM_PANEL_ACTIVE_PAGE, panel_page); } - if ((window->priv->bottom_panel_size > 0) && xed_prefs_manager_bottom_panel_size_can_set ()) - { - xed_prefs_manager_set_bottom_panel_size (window->priv->bottom_panel_size); - } - - pane_page = _xed_panel_get_active_item_id (XED_PANEL(window->priv->bottom_panel)); - if (pane_page != 0 && xed_prefs_manager_bottom_panel_active_page_can_set ()) - { - xed_prefs_manager_set_bottom_panel_active_page (pane_page); - } + g_settings_apply (window->priv->window_settings); } static gint @@ -141,6 +136,26 @@ on_key_pressed (GtkWidget *widget, return handled; } +static void +save_window_state (GtkWidget *widget) +{ + XedWindow *window = XED_WINDOW (widget); + + if ((window->priv->window_state & + (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN)) == 0) + { + GtkAllocation allocation; + + gtk_widget_get_allocation (widget, &allocation); + + window->priv->width = allocation.width; + window->priv->height = allocation.height; + + g_settings_set (window->priv->window_settings, XED_SETTINGS_WINDOW_SIZE, + "(ii)", window->priv->width, window->priv->height); + } +} + static void xed_window_dispose (GObject *object) { @@ -168,6 +183,7 @@ xed_window_dispose (GObject *object) * for this window, but only once */ if (!window->priv->dispose_has_run) { + save_window_state (GTK_WIDGET (window)); save_panes_state (window); /* Note that unreffing the extension will automatically remove @@ -204,6 +220,11 @@ xed_window_dispose (GObject *object) g_clear_object (&window->priv->window_group); g_clear_object (&window->priv->default_location); + /* We must free the settings after saving the panels */ + g_clear_object (&window->priv->editor_settings); + g_clear_object (&window->priv->ui_settings); + g_clear_object (&window->priv->window_settings); + /* Now that there have broken some reference loops, force collection again. */ peas_engine_garbage_collect (PEAS_ENGINE (xed_plugins_engine_get_default ())); @@ -219,26 +240,29 @@ xed_window_finalize (GObject *object) } static gboolean -xed_window_window_state_event (GtkWidget *widget, +xed_window_window_state_event (GtkWidget *widget, GdkEventWindowState *event) { - XedWindow *window = XED_WINDOW(widget); + XedWindow *window = XED_WINDOW (widget); + window->priv->window_state = event->new_window_state; - if (event->changed_mask & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN)) - { - gboolean show; - show = !(event->new_window_state & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN)); - } + g_settings_set_int (window->priv->window_settings, XED_SETTINGS_WINDOW_STATE, window->priv->state); + return FALSE; } static gboolean -xed_window_configure_event (GtkWidget *widget, +xed_window_configure_event (GtkWidget *widget, GdkEventConfigure *event) { - XedWindow *window = XED_WINDOW(widget); - window->priv->width = event->width; - window->priv->height = event->height; + XedWindow *window = XED_WINDOW (widget); + + if (gtk_widget_get_realized (widget) && + window->priv->state & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN) == 0) + { + save_window_state (widget); + } + return GTK_WIDGET_CLASS (xed_window_parent_class)->configure_event (widget, event); } @@ -398,7 +422,7 @@ set_toolbar_style (XedWindow *window, if (origin == NULL) { - visible = xed_prefs_manager_get_toolbar_visible (); + visible = g_settings_get_boolean (window->priv->ui_settings, XED_SETTINGS_TOOLBAR_VISIBLE); } else { @@ -417,9 +441,9 @@ set_toolbar_style (XedWindow *window, action = gtk_action_group_get_action (window->priv->always_sensitive_action_group, "ViewToolbar"); - if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION(action)) != visible) + if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) != visible) { - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION(action), visible); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible); } return visible; @@ -524,7 +548,7 @@ set_paste_sensitivity_according_to_clipboard (XedWindow *window, static void set_sensitivity_according_to_tab (XedWindow *window, - XedTab *tab) + XedTab *tab) { XedDocument *doc; XedView *view; @@ -534,11 +558,14 @@ set_sensitivity_according_to_tab (XedWindow *window, gboolean editable; XedTabState state; GtkClipboard *clipboard; + gboolean enable_syntax_hl; - g_return_if_fail(XED_TAB (tab)); + g_return_if_fail (XED_TAB (tab)); xed_debug (DEBUG_WINDOW); + enable_syntax_hl = g_settings_get_boolean (window->priv->editor_settings, XED_SETTINGS_SYNTAX_HIGHLIGHTING); + state = xed_tab_get_state (tab); state_normal = (state == XED_TAB_STATE_NORMAL); @@ -631,8 +658,7 @@ set_sensitivity_according_to_tab (XedWindow *window, gtk_action_set_sensitive (action, (state_normal || state == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION)); action = gtk_action_group_get_action (window->priv->action_group, "ViewHighlightMode"); - gtk_action_set_sensitive (action, - (state != XED_TAB_STATE_CLOSING) && xed_prefs_manager_get_enable_syntax_highlighting ()); + gtk_action_set_sensitive (action, (state != XED_TAB_STATE_CLOSING) && enable_syntax_hl); update_next_prev_doc_sensitivity (window, tab); @@ -960,11 +986,11 @@ update_recent_files_menu (XedWindow *window) gint max_recents; GList *actions, *l, *items; GList *filtered_items = NULL; - gint i; + guint i; xed_debug (DEBUG_WINDOW); - max_recents = xed_prefs_manager_get_max_recents (); + max_recents = g_settings_get_uint (window->priv->ui_settings, XED_SETTINGS_MAX_RECENTS); g_return_if_fail(p->recents_action_group != NULL); @@ -1080,10 +1106,7 @@ toolbar_visibility_changed (GtkWidget *toolbar, visible = gtk_widget_get_visible (toolbar); - if (xed_prefs_manager_toolbar_visible_can_set ()) - { - xed_prefs_manager_set_toolbar_visible (visible); - } + g_settings_set_boolean (window->priv->ui_settings, XED_SETTINGS_TOOLBAR_VISIBLE, visible); action = gtk_action_group_get_action (window->priv->always_sensitive_action_group, "ViewToolbar"); @@ -1433,9 +1456,10 @@ set_statusbar_style (XedWindow *window, { GtkAction *action; gboolean visible; + if (origin == NULL) { - visible = xed_prefs_manager_get_statusbar_visible (); + visible = g_settings_get_boolean (window->priv->ui_settings, XED_SETTINGS_STATUSBAR_VISIBLE); } else { @@ -1470,10 +1494,7 @@ statusbar_visibility_changed (GtkWidget *statusbar, visible = gtk_widget_get_visible (statusbar); - if (xed_prefs_manager_statusbar_visible_can_set ()) - { - xed_prefs_manager_set_statusbar_visible (visible); - } + g_settings_set_boolean (window->priv->ui_settings, XED_SETTINGS_STATUSBAR_VISIBLE, visible); action = gtk_action_group_get_action (window->priv->always_sensitive_action_group, "ViewStatusbar"); @@ -1730,7 +1751,7 @@ clone_window (XedWindow *origin) if ((origin->priv->window_state & GDK_WINDOW_STATE_MAXIMIZED) != 0) { gint w, h; - xed_prefs_manager_get_default_window_size (&w, &h); + _xed_window_get_default_size (&w, &h); gtk_window_set_default_size (GTK_WINDOW(window), w, h); gtk_window_maximize (GTK_WINDOW(window)); } @@ -3151,10 +3172,7 @@ side_panel_visibility_changed (GtkWidget *side_panel, visible = gtk_widget_get_visible (side_panel); - if (xed_prefs_manager_side_pane_visible_can_set ()) - { - xed_prefs_manager_set_side_pane_visible (visible); - } + g_settings_set_boolean (window->priv->ui_settings, XED_SETTINGS_SIDE_PANEL_VISIBLE, visible); action = gtk_action_group_get_action (window->priv->panes_action_group, "ViewSidePane"); @@ -3196,10 +3214,7 @@ bottom_panel_visibility_changed (XedPanel *bottom_panel, visible = gtk_widget_get_visible (GTK_WIDGET (bottom_panel)); - if (xed_prefs_manager_bottom_panel_visible_can_set ()) - { - xed_prefs_manager_set_bottom_panel_visible (visible); - } + g_settings_set_boolean (window->priv->ui_settings, XED_SETTINGS_BOTTOM_PANEL_VISIBLE, visible); action = gtk_action_group_get_action (window->priv->panes_action_group, "ViewBottomPane"); @@ -3269,13 +3284,19 @@ static void init_panels_visibility (XedWindow *window) { gint active_page; + gboolean side_panel_visible; + gboolean bottom_panel_visible; + xed_debug (DEBUG_WINDOW); /* side pane */ - active_page = xed_prefs_manager_get_side_panel_active_page (); + active_page = g_settings_get_int (window->priv->window_settings, XED_SETTINGS_SIDE_PANEL_ACTIVE_PAGE); _xed_panel_set_active_item_by_id (XED_PANEL (window->priv->side_panel), active_page); - if (xed_prefs_manager_get_side_pane_visible ()) + side_panel_visible = g_settings_get_boolean (window->priv->ui_settings, XED_SETTINGS_SIDE_PANEL_VISIBLE); + bottom_panel_visible = g_settings_get_boolean (window->priv->ui_settings, XED_SETTINGS_BOTTOM_PANEL_VISIBLE); + + if (side_panel_visible) { gtk_widget_show (window->priv->side_panel); } @@ -3283,10 +3304,10 @@ init_panels_visibility (XedWindow *window) /* bottom pane, it can be empty */ if (xed_panel_get_n_items (XED_PANEL (window->priv->bottom_panel)) > 0) { - active_page = xed_prefs_manager_get_bottom_panel_active_page (); + active_page = g_settings_get_int (window->priv->window_settings, XED_SETTINGS_BOTTOM_PANEL_ACTIVE_PAGE); _xed_panel_set_active_item_by_id (XED_PANEL(window->priv->bottom_panel), active_page); - if (xed_prefs_manager_get_bottom_panel_visible ()) + if (bottom_panel_visible) { gtk_widget_show (window->priv->bottom_panel); } @@ -3375,7 +3396,7 @@ add_notebook (XedWindow *window, gtk_paned_pack1 (GTK_PANED(window->priv->vpaned), notebook, TRUE, TRUE); gtk_widget_show (notebook); - xed_notebook_set_tab_scrolling_enabled (XED_NOTEBOOK (notebook), xed_prefs_manager_get_enable_tab_scrolling ()); + // xed_notebook_set_tab_scrolling_enabled (XED_NOTEBOOK (notebook), xed_prefs_manager_get_enable_tab_scrolling ()); connect_notebook_signals (window, notebook); } @@ -3418,6 +3439,13 @@ xed_window_init (XedWindow *window) window->priv->dispose_has_run = FALSE; window->priv->fullscreen_controls = NULL; window->priv->fullscreen_animation_timeout_id = 0; + window->priv->editor_settings = g_settings_new ("org.x.editor.preferences.editor"); + window->priv->ui_settings = g_settings_new ("org.x.editor.preferences.ui"); + + /* Window settings are applied only once the window is closed. We do not want + to keep writing to disk when the window is dragged around */ + window->priv->window_settings = g_settings_new ("org.x.editor.state.window"); + g_settings_delay (window->priv->window_settings); window->priv->message_bus = xed_message_bus_new (); @@ -3467,8 +3495,8 @@ xed_window_init (XedWindow *window) /* panes' state must be restored after panels have been mapped, * since the bottom pane position depends on the size of the vpaned. */ - window->priv->side_panel_size = xed_prefs_manager_get_side_panel_size (); - window->priv->bottom_panel_size = xed_prefs_manager_get_bottom_panel_size (); + window->priv->side_panel_size = g_settings_get_int (window->priv->window_settings, XED_SETTINGS_SIDE_PANEL_SIZE); + window->priv->bottom_panel_size = g_settings_get_int (window->priv->window_settings, XED_SETTINGS_BOTTOM_PANEL_SIZE); g_signal_connect_after(window->priv->hpaned, "map", G_CALLBACK (hpaned_restore_position), window); g_signal_connect_after(window->priv->vpaned, "map", G_CALLBACK (vpaned_restore_position), window); @@ -4211,3 +4239,13 @@ xed_window_get_message_bus (XedWindow *window) g_return_val_if_fail(XED_IS_WINDOW (window), NULL); return window->priv->message_bus; } + +void +_xed_window_get_default_size (gint *width, + gint *height) +{ + g_return_if_fail (width != NULL && height != NULL); + + *width = XED_WINDOW_DEFAULT_WIDTH; + *height = XED_WINDOW_DEFAULT_HEIGHT; +} diff --git a/xed/xed-window.h b/xed/xed-window.h index 0364e63..99e80ab 100644 --- a/xed/xed-window.h +++ b/xed/xed-window.h @@ -106,6 +106,8 @@ gboolean _xed_window_is_fullscreen (XedWindow *window); void _xed_recent_add (XedWindow *window, GFile *location, const gchar *mime); void _xed_recent_remove (XedWindow *window, GFile *location); +void _xed_window_get_default_size (gint *width, gint *height); + G_END_DECLS #endif /* __XED_WINDOW_H__ */ diff --git a/xed/xed.c b/xed/xed.c index b2eb973..24b0108 100644 --- a/xed/xed.c +++ b/xed/xed.c @@ -52,7 +52,6 @@ #include "xed-dirs.h" #include "xed-encodings.h" #include "xed-plugins-engine.h" -#include "xed-prefs-manager-app.h" #include "xed-session.h" #include "xed-utils.h" #include "xed-window.h" @@ -597,10 +596,6 @@ main (int argc, char *argv[]) /* Set the associated .desktop file */ egg_set_desktop_file (DATADIR "/applications/xed.desktop"); - /* Load user preferences */ - xed_debug_message (DEBUG_APP, "Init prefs manager"); - xed_prefs_manager_app_init (); - /* Init plugins engine */ xed_debug_message (DEBUG_APP, "Init plugins"); engine = xed_plugins_engine_get_default (); @@ -658,7 +653,6 @@ main (int argc, char *argv[]) * finalize it properly. */ g_object_unref (engine); - xed_prefs_manager_app_shutdown (); #ifndef ENABLE_GVFS_METADATA xed_metadata_manager_shutdown (); From 7a06a119b51ccd45423a1736af0053d3d6a0e152 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 16 Jan 2017 16:43:46 -0800 Subject: [PATCH 095/132] Clean up the docs a bit --- docs/reference/Makefile.am | 1 - docs/reference/xed-docs.sgml | 6 +- docs/reference/xed-sections.txt | 315 +++++--------------------------- docs/reference/xed.types | 6 + 4 files changed, 57 insertions(+), 271 deletions(-) diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am index 9321582..71b2fbf 100644 --- a/docs/reference/Makefile.am +++ b/docs/reference/Makefile.am @@ -47,7 +47,6 @@ IGNORE_HFILES= \ xed-io-error-message-area.h \ xed-languages-manager.h \ xed-plugins-engine.h \ - xed-prefs-manager-private.h \ xed-session.h \ xed-ui.h \ xed-window-private.h \ diff --git a/docs/reference/xed-docs.sgml b/docs/reference/xed-docs.sgml index 6ec388c..4500ff0 100644 --- a/docs/reference/xed-docs.sgml +++ b/docs/reference/xed-docs.sgml @@ -9,6 +9,7 @@ xed + @@ -18,19 +19,18 @@ - + + - - diff --git a/docs/reference/xed-sections.txt b/docs/reference/xed-sections.txt index 8a789f0..2e43141 100644 --- a/docs/reference/xed-sections.txt +++ b/docs/reference/xed-sections.txt @@ -19,6 +19,21 @@ XED_IS_APP_CLASS XED_APP_GET_CLASS +
+xed-app-activatable +XedAppActivatable +XedAppActivatable +xed_app_activatable_activate +xed_app_activatable_deactivate + +XED_TYPE_APP_ACTIVATABLE +XED_APP_ACTIVATABLE +XED_APP_ACTIVATABLE_IFACE +XED_IS_APP_ACTIVATABLE +XED_APP_ACTIVATABLE_GET_IFACE +xed_app_activatable_get_type +
+
xed-document XedSearchFlags @@ -29,7 +44,7 @@ XedDocumentSaveFlags XED_DOCUMENT_ERROR xed_document_error_quark xed_document_new -xed_document_get_uri +xed_document_get_location xed_document_get_uri_for_display xed_document_get_short_name_for_display xed_document_get_mime_type @@ -253,7 +268,7 @@ XED_PRINT_JOB_PREVIEW_GET_CLASS
-xed-print +xed-print-job XedPrintJob XedPrintJob xed_print_job_new @@ -360,6 +375,22 @@ XED_IS_VIEW_CLASS XED_VIEW_GET_CLASS
+
+xed-view-activatable +XedViewActivatable +XedViewActivatable +xed_view_activatable_activate +xed_view_activatable_deactivate +xed_view_activatable_update_state + +XED_TYPE_VIEW_ACTIVATABLE +XED_VIEW_ACTIVATABLE +XED_VIEW_ACTIVATABLE_IFACE +XED_IS_VIEW_ACTIVATABLE +XED_VIEW_ACTIVATABLE_GET_IFACE +xed_view_activatable_get_type +
+
xed-window XedWindowState @@ -367,7 +398,7 @@ XedWindowPrivate XedWindow XedWindow xed_window_create_tab -xed_window_create_tab_from_uri +xed_window_create_tab_from_location xed_window_close_tab xed_window_close_all_tabs xed_window_close_tabs @@ -396,6 +427,20 @@ XED_IS_WINDOW_CLASS XED_WINDOW_GET_CLASS
+xed-window-activatable +XedWindowActivatable +XedWindowActivatable +xed_window_activatable_activate +xed_window_activatable_deactivate +xed_window_activatable_update_state + +XED_TYPE_WINDOW_ACTIVATABLE +XED_WINDOW_ACTIVATABLE +XED_WINDOW_ACTIVATABLE_IFACE +XED_IS_WINDOW_ACTIVATABLE +XED_WINDOW_ACTIVATABLE_GET_IFACE +xed_window_activatable_get_type +
xed-convert XedConvertError @@ -456,270 +501,6 @@ xed_metadata_manager_get xed_metadata_manager_set
-
-xed-prefs-manager-app -xed_prefs_manager_app_init -xed_prefs_manager_app_shutdown -xed_prefs_manager_get_window_state -xed_prefs_manager_set_window_state -xed_prefs_manager_window_state_can_set -xed_prefs_manager_get_window_size -xed_prefs_manager_get_default_window_size -xed_prefs_manager_set_window_size -xed_prefs_manager_window_size_can_set -xed_prefs_manager_get_side_panel_size -xed_prefs_manager_get_default_side_panel_size -xed_prefs_manager_set_side_panel_size -xed_prefs_manager_side_panel_size_can_set -xed_prefs_manager_get_bottom_panel_size -xed_prefs_manager_get_default_bottom_panel_size -xed_prefs_manager_set_bottom_panel_size -xed_prefs_manager_bottom_panel_size_can_set -
- -
-xed-prefs-manager -XED_BASE_KEY -GPM_PREFS_DIR -GPM_FONT_DIR -GPM_USE_DEFAULT_FONT -GPM_EDITOR_FONT -GPM_COLORS_DIR -GPM_USE_DEFAULT_COLORS -GPM_BACKGROUND_COLOR -GPM_TEXT_COLOR -GPM_SELECTED_TEXT_COLOR -GPM_SELECTION_COLOR -GPM_SAVE_DIR -GPM_CREATE_BACKUP_COPY -GPM_BACKUP_COPY_EXTENSION -GPM_AUTO_SAVE -GPM_AUTO_SAVE_INTERVAL -GPM_UNDO_DIR -GPM_UNDO_ACTIONS_LIMIT -GPM_WRAP_MODE_DIR -GPM_WRAP_MODE -GPM_TABS_DIR -GPM_TABS_SIZE -GPM_INSERT_SPACES -GPM_AUTO_INDENT_DIR -GPM_AUTO_INDENT -GPM_LINE_NUMBERS_DIR -GPM_DISPLAY_LINE_NUMBERS -GPM_CURRENT_LINE_DIR -GPM_HIGHLIGHT_CURRENT_LINE -GPM_BRACKET_MATCHING_DIR -GPM_BRACKET_MATCHING -GPM_RIGHT_MARGIN_DIR -GPM_DISPLAY_RIGHT_MARGIN -GPM_RIGHT_MARGIN_POSITION -GPM_CURSOR_POSITION_DIR -GPM_RESTORE_CURSOR_POSITION -GPM_SEARCH_HIGHLIGHTING_DIR -GPM_SEARCH_HIGHLIGHTING_ENABLE -GPM_TOOLBAR_DIR -GPM_TOOLBAR_VISIBLE -GPM_TOOLBAR_BUTTONS_STYLE -GPM_STATUSBAR_DIR -GPM_STATUSBAR_VISIBLE -GPM_SIDE_PANE_DIR -GPM_SIDE_PANE_VISIBLE -GPM_BOTTOM_PANEL_DIR -GPM_BOTTOM_PANEL_VISIBLE -GPM_RECENTS_DIR -GPM_MAX_RECENTS -GPM_PRINT_PAGE_DIR -GPM_PRINT_SYNTAX -GPM_PRINT_HEADER -GPM_PRINT_WRAP_MODE -GPM_PRINT_LINE_NUMBERS -GPM_PRINT_FONT_DIR -GPM_PRINT_FONT_BODY -GPM_PRINT_FONT_BODY_PANGO -GPM_PRINT_FONT_HEADER -GPM_PRINT_FONT_HEADER_PANGO -GPM_PRINT_FONT_NUMBERS -GPM_PRINT_FONT_NUMBERS_PANGO -GPM_WINDOW_DIR -GPM_WINDOW_STATE -GPM_WINDOW_WIDTH -GPM_WINDOW_HEIGHT -GPM_SIDE_PANEL_SIZE -GPM_BOTTOM_PANEL_SIZE -GPM_ENCODINGS_DIR -GPM_AUTO_DETECTED_ENCODINGS -GPM_SHOWN_IN_MENU_ENCODINGS -GPM_SYNTAX_HL_DIR -GPM_SYNTAX_HL_ENABLE -GPM_WRITABLE_VFS_SCHEMES -GPM_DEFAULT_USE_DEFAULT_FONT -GPM_DEFAULT_EDITOR_FONT -GPM_DEFAULT_USE_DEFAULT_COLORS -GPM_DEFAULT_BACKGROUND_COLOR -GPM_DEFAULT_TEXT_COLOR -GPM_DEFAULT_SELECTED_TEXT_COLOR -GPM_DEFAULT_SELECTION_COLOR -GPM_DEFAULT_CREATE_BACKUP_COPY -GPM_DEFAULT_BACKUP_COPY_EXTENSION -GPM_DEFAULT_AUTO_SAVE -GPM_DEFAULT_AUTO_SAVE_INTERVAL -GPM_DEFAULT_UNDO_ACTIONS_LIMIT -GPM_DEFAULT_WRAP_MODE -GPM_DEFAULT_TABS_SIZE -GPM_DEFAULT_INSERT_SPACES -GPM_DEFAULT_AUTO_INDENT -GPM_DEFAULT_DISPLAY_LINE_NUMBERS -GPM_DEFAULT_AUTO_DETECTED_ENCODINGS -GPM_DEFAULT_TOOLBAR_VISIBLE -GPM_DEFAULT_TOOLBAR_BUTTONS_STYLE -GPM_DEFAULT_TOOLBAR_SHOW_TOOLTIPS -GPM_DEFAULT_STATUSBAR_VISIBLE -GPM_DEFAULT_SIDE_PANE_VISIBLE -GPM_DEFAULT_BOTTOM_PANEL_VISIBLE -GPM_DEFAULT_PRINT_SYNTAX -GPM_DEFAULT_PRINT_HEADER -GPM_DEFAULT_PRINT_WRAP_MODE -GPM_DEFAULT_PRINT_LINE_NUMBERS -GPM_DEFAULT_PRINT_FONT_BODY_PANGO -GPM_DEFAULT_PRINT_FONT_HEADER_PANGO -GPM_DEFAULT_PRINT_FONT_NUMBERS_PANGO -GPM_DEFAULT_MAX_RECENTS -GPM_DEFAULT_WINDOW_STATE -GPM_DEFAULT_WINDOW_WIDTH -GPM_DEFAULT_WINDOW_HEIGHT -GPM_DEFAULT_WINDOW_STATE_STR -GPM_DEFAULT_WINDOW_WIDTH_STR -GPM_DEFAULT_WINDOW_HEIGHT_STR -GPM_DEFAULT_SIDE_PANEL_SIZE -GPM_DEFAULT_BOTTOM_PANEL_SIZE -GPM_DEFAULT_SIDE_PANEL_SIZE_STR -GPM_DEFAULT_BOTTOM_PANEL_SIZE_STR -GPM_DEFAULT_HIGHLIGHT_CURRENT_LINE -GPM_DEFAULT_BRACKET_MATCHING -GPM_DEFAULT_DISPLAY_RIGHT_MARGIN -GPM_DEFAULT_RIGHT_MARGIN_POSITION -GPM_DEFAULT_SYNTAX_HL_ENABLE -GPM_DEFAULT_WRITABLE_VFS_SCHEMES -GPM_DEFAULT_RESTORE_CURSOR_POSITION -GPM_DEFAULT_SEARCH_HIGHLIGHTING_ENABLE -XedToolbarSetting -xed_prefs_manager_init -xed_prefs_manager_shutdown -xed_prefs_manager_get_use_default_font -xed_prefs_manager_set_use_default_font -xed_prefs_manager_use_default_font_can_set -xed_prefs_manager_get_editor_font -xed_prefs_manager_set_editor_font -xed_prefs_manager_editor_font_can_set -xed_prefs_manager_get_use_default_colors -xed_prefs_manager_set_use_default_colors -xed_prefs_manager_use_default_colors_can_set -xed_prefs_manager_get_background_color -xed_prefs_manager_set_background_color -xed_prefs_manager_background_color_can_set -xed_prefs_manager_get_text_color -xed_prefs_manager_set_text_color -xed_prefs_manager_text_color_can_set -xed_prefs_manager_get_selection_color -xed_prefs_manager_set_selection_color -xed_prefs_manager_selection_color_can_set -xed_prefs_manager_get_selected_text_color -xed_prefs_manager_set_selected_text_color -xed_prefs_manager_selected_text_color_can_set -xed_prefs_manager_get_create_backup_copy -xed_prefs_manager_set_create_backup_copy -xed_prefs_manager_create_backup_copy_can_set -xed_prefs_manager_get_backup_extension -xed_prefs_manager_get_auto_save -xed_prefs_manager_set_auto_save -xed_prefs_manager_auto_save_can_set -xed_prefs_manager_get_auto_save_interval -xed_prefs_manager_set_auto_save_interval -xed_prefs_manager_auto_save_interval_can_set -xed_prefs_manager_get_undo_actions_limit -xed_prefs_manager_set_undo_actions_limit -xed_prefs_manager_undo_actions_limit_can_set -xed_prefs_manager_get_wrap_mode -xed_prefs_manager_set_wrap_mode -xed_prefs_manager_wrap_mode_can_set -xed_prefs_manager_get_tabs_size -xed_prefs_manager_set_tabs_size -xed_prefs_manager_tabs_size_can_set -xed_prefs_manager_get_insert_spaces -xed_prefs_manager_set_insert_spaces -xed_prefs_manager_insert_spaces_can_set -xed_prefs_manager_get_auto_indent -xed_prefs_manager_set_auto_indent -xed_prefs_manager_auto_indent_can_set -xed_prefs_manager_get_display_line_numbers -xed_prefs_manager_set_display_line_numbers -xed_prefs_manager_display_line_numbers_can_set -xed_prefs_manager_get_toolbar_visible -xed_prefs_manager_set_toolbar_visible -xed_prefs_manager_toolbar_visible_can_set -xed_prefs_manager_get_toolbar_buttons_style -xed_prefs_manager_set_toolbar_buttons_style -xed_prefs_manager_toolbar_buttons_style_can_set -xed_prefs_manager_get_statusbar_visible -xed_prefs_manager_set_statusbar_visible -xed_prefs_manager_statusbar_visible_can_set -xed_prefs_manager_get_side_pane_visible -xed_prefs_manager_set_side_pane_visible -xed_prefs_manager_side_pane_visible_can_set -xed_prefs_manager_get_bottom_panel_visible -xed_prefs_manager_set_bottom_panel_visible -xed_prefs_manager_bottom_panel_visible_can_set -xed_prefs_manager_get_print_syntax_hl -xed_prefs_manager_set_print_syntax_hl -xed_prefs_manager_print_syntax_hl_can_set -xed_prefs_manager_get_print_header -xed_prefs_manager_set_print_header -xed_prefs_manager_print_header_can_set -xed_prefs_manager_get_print_wrap_mode -xed_prefs_manager_set_print_wrap_mode -xed_prefs_manager_print_wrap_mode_can_set -xed_prefs_manager_get_print_line_numbers -xed_prefs_manager_set_print_line_numbers -xed_prefs_manager_print_line_numbers_can_set -xed_prefs_manager_get_print_font_body -xed_prefs_manager_set_print_font_body -xed_prefs_manager_print_font_body_can_set -xed_prefs_manager_get_default_print_font_body -xed_prefs_manager_get_print_font_header -xed_prefs_manager_set_print_font_header -xed_prefs_manager_print_font_header_can_set -xed_prefs_manager_get_default_print_font_header -xed_prefs_manager_get_print_font_numbers -xed_prefs_manager_set_print_font_numbers -xed_prefs_manager_print_font_numbers_can_set -xed_prefs_manager_get_default_print_font_numbers -xed_prefs_manager_get_max_recents -xed_prefs_manager_get_auto_detected_encodings -xed_prefs_manager_get_shown_in_menu_encodings -xed_prefs_manager_set_shown_in_menu_encodings -xed_prefs_manager_shown_in_menu_encodings_can_set -xed_prefs_manager_get_highlight_current_line -xed_prefs_manager_set_highlight_current_line -xed_prefs_manager_highlight_current_line_can_set -xed_prefs_manager_get_bracket_matching -xed_prefs_manager_set_bracket_matching -xed_prefs_manager_bracket_matching_can_set -xed_prefs_manager_get_display_right_margin -xed_prefs_manager_set_display_right_margin -xed_prefs_manager_display_right_margin_can_set -xed_prefs_manager_get_right_margin_position -xed_prefs_manager_set_right_margin_position -xed_prefs_manager_right_margin_position_can_set -xed_prefs_manager_get_enable_syntax_highlighting -xed_prefs_manager_set_enable_syntax_highlighting -xed_prefs_manager_enable_syntax_highlighting_can_set -xed_prefs_manager_get_writable_vfs_schemes -xed_prefs_manager_get_restore_cursor_position -xed_prefs_manager_get_enable_search_highlighting -xed_prefs_manager_set_enable_search_highlighting -xed_prefs_manager_enable_search_highlighting_can_set -
-
xed-utils GBOOLEAN_TO_POINTER diff --git a/docs/reference/xed.types b/docs/reference/xed.types index ce31662..05fc227 100644 --- a/docs/reference/xed.types +++ b/docs/reference/xed.types @@ -1,4 +1,5 @@ #include "xed-app.h" +#include "xed-app-activatable.h" #include "xed-document.h" #include "xed-encodings.h" #include "xed-encodings-combo-box.h" @@ -12,8 +13,11 @@ #include "xed-statusbar.h" #include "xed-tab.h" #include "xed-view.h" +#include "xed-view-activatable.h" #include "xed-window.h" +#include "xed-window-activatable.h" xed_app_get_type +xed_app_activatable_get_type xed_document_get_type xed_encoding_get_type xed_encodings_combo_box_get_type @@ -27,4 +31,6 @@ xed_progress_message_area_get_type xed_statusbar_get_type xed_tab_get_type xed_view_get_type +xed_view_activatable_get_type xed_window_get_type +xed_window_activatable_get_type From 5d62c0c452c7496563509f6149601bfbd7bd8c00 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Thu, 19 Jan 2017 00:00:59 -0800 Subject: [PATCH 096/132] Redesign the goto line popup dialog --- xed/Makefile.am | 2 + xed/xed-commands-search.c | 16 +- xed/xed-searchbar.c | 4 +- xed/xed-tab.c | 85 +++--- xed/xed-tab.h | 1 + xed/xed-view-frame.c | 612 ++++++++++++++++++++++++++++++++++++++ xed/xed-view-frame.h | 70 +++++ xed/xed-view.c | 553 +--------------------------------- xed/xed-view.h | 3 - xed/xed-window.c | 22 +- 10 files changed, 760 insertions(+), 608 deletions(-) create mode 100644 xed/xed-view-frame.c create mode 100644 xed/xed-view-frame.h diff --git a/xed/Makefile.am b/xed/Makefile.am index 2bb2c57..7bca45b 100644 --- a/xed/Makefile.am +++ b/xed/Makefile.am @@ -64,6 +64,7 @@ NOINST_H_FILES = \ xed-tab-label.h \ xedtextregion.h \ xed-ui.h \ + xed-view-frame.h \ xed-window-private.h INST_H_FILES = \ @@ -149,6 +150,7 @@ libxed_c_files = \ xed-utils.c \ xed-view.c \ xed-view-activatable.c \ + xed-view-frame.c \ xed-window.c \ xed-window-activatable.c \ xedtextregion.c diff --git a/xed/xed-commands-search.c b/xed/xed-commands-search.c index 9050525..d5570ed 100644 --- a/xed/xed-commands-search.c +++ b/xed/xed-commands-search.c @@ -12,6 +12,7 @@ #include "xed-window.h" #include "xed-utils.h" #include "xed-searchbar.h" +#include "xed-view-frame.h" void _xed_cmd_search_find (GtkAction *action, @@ -47,7 +48,9 @@ void _xed_cmd_search_clear_highlight (XedWindow *window) { XedDocument *doc; + xed_debug (DEBUG_COMMANDS); + doc = xed_window_get_active_document (window); if (doc != NULL) { @@ -59,19 +62,22 @@ void _xed_cmd_search_goto_line (GtkAction *action, XedWindow *window) { - XedView *active_view; + XedTab *active_tab; + XedViewFrame *frame; + xed_debug (DEBUG_COMMANDS); - active_view = xed_window_get_active_view (window); - if (active_view == NULL) + active_tab = xed_window_get_active_tab (window); + if (active_tab == NULL) { return; } /* Focus the view if needed: we need to focus the view otherwise activating the binding for goto line has no effect */ - gtk_widget_grab_focus (GTK_WIDGET(active_view)); + // gtk_widget_grab_focus (GTK_WIDGET(active_view)); /* Goto line is builtin in XedView, just activate the corresponding binding. */ - gtk_bindings_activate (G_OBJECT(active_view), GDK_KEY_i, GDK_CONTROL_MASK); + frame = XED_VIEW_FRAME (_xed_tab_get_view_frame (active_tab)); + xed_view_frame_popup_goto_line (frame); } diff --git a/xed/xed-searchbar.c b/xed/xed-searchbar.c index 1dbb842..1cd1e2e 100755 --- a/xed/xed-searchbar.c +++ b/xed/xed-searchbar.c @@ -727,11 +727,13 @@ xed_searchbar_show (XedSearchbar *searchbar, void xed_searchbar_hide (XedSearchbar *searchbar) { + XedView *active_view; + gtk_revealer_set_transition_type (GTK_REVEALER (searchbar->priv->revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN); gtk_revealer_set_reveal_child (GTK_REVEALER (searchbar->priv->revealer), FALSE); // focus document - XedView *active_view = xed_window_get_active_view (searchbar->window); + active_view = xed_window_get_active_view (searchbar->window); if (active_view != NULL) { gtk_widget_grab_focus (GTK_WIDGET (active_view)); diff --git a/xed/xed-tab.c b/xed/xed-tab.c index c090289..196ba7e 100644 --- a/xed/xed-tab.c +++ b/xed/xed-tab.c @@ -44,6 +44,7 @@ #include "xed-debug.h" #include "xed-enum-types.h" #include "xed-settings.h" +#include "xed-view-frame.h" #define XED_TAB_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_TAB, XedTabPrivate)) @@ -55,8 +56,7 @@ struct _XedTabPrivate XedTabState state; - GtkWidget *view; - GtkWidget *view_scrolled_window; + XedViewFrame *frame; GtkWidget *message_area; GtkWidget *print_preview; @@ -375,20 +375,22 @@ static void set_view_properties_according_to_state (XedTab *tab, XedTabState state) { + XedView *view; gboolean val; gboolean hl_current_line; hl_current_line = g_settings_get_boolean (tab->priv->editor, XED_SETTINGS_HIGHLIGHT_CURRENT_LINE); + view = xed_view_frame_get_view (tab->priv->frame); val = ((state == XED_TAB_STATE_NORMAL) && (tab->priv->print_preview == NULL) && !tab->priv->not_editable); - gtk_text_view_set_editable (GTK_TEXT_VIEW (tab->priv->view), val); + gtk_text_view_set_editable (GTK_TEXT_VIEW (view), val); val = ((state != XED_TAB_STATE_LOADING) && (state != XED_TAB_STATE_CLOSING)); - gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (tab->priv->view), val); + gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), val); val = ((state != XED_TAB_STATE_LOADING) && (state != XED_TAB_STATE_CLOSING) && (hl_current_line)); - gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (tab->priv->view), val); + gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (view), val); } static void @@ -410,17 +412,17 @@ xed_tab_set_state (XedTab *tab, if ((state == XED_TAB_STATE_LOADING_ERROR) || /* FIXME: add other states if needed */ (state == XED_TAB_STATE_SHOWING_PRINT_PREVIEW)) { - gtk_widget_hide (tab->priv->view_scrolled_window); + gtk_widget_hide (GTK_WIDGET (tab->priv->frame)); } else { if (tab->priv->print_preview == NULL) { - gtk_widget_show (tab->priv->view_scrolled_window); + gtk_widget_show (GTK_WIDGET (tab->priv->frame)); } } - set_cursor_according_to_state (GTK_TEXT_VIEW (tab->priv->view), state); + set_cursor_according_to_state (GTK_TEXT_VIEW (xed_view_frame_get_view (tab->priv->frame)), state); g_object_notify (G_OBJECT (tab), "state"); } @@ -969,7 +971,7 @@ document_loaded (XedDocument *document, } /* Scroll to the cursor when the document is loaded */ - xed_view_scroll_to_cursor (XED_VIEW (tab->priv->view)); + xed_view_scroll_to_cursor (xed_view_frame_get_view (tab->priv->frame)); all_documents = xed_app_get_documents (xed_app_get_default ()); @@ -1408,24 +1410,13 @@ view_focused_in (GtkWidget *widget, return FALSE; } -static GMountOperation * -tab_mount_operation_factory (XedDocument *doc, - gpointer userdata) -{ - XedTab *tab = XED_TAB (userdata); - GtkWidget *window; - - window = gtk_widget_get_toplevel (GTK_WIDGET (tab)); - return gtk_mount_operation_new (GTK_WINDOW (window)); -} - static void xed_tab_init (XedTab *tab) { - GtkWidget *sw; - XedDocument *doc; gboolean auto_save; guint auto_save_interval; + XedDocument *doc; + XedView *view; tab->priv = XED_TAB_GET_PRIVATE (tab); @@ -1437,12 +1428,6 @@ xed_tab_init (XedTab *tab) gtk_orientable_set_orientation (GTK_ORIENTABLE (tab), GTK_ORIENTATION_VERTICAL); - /* Create the scrolled window */ - sw = gtk_scrolled_window_new (NULL, NULL); - tab->priv->view_scrolled_window = sw; - - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - /* Manage auto save data */ auto_save = g_settings_get_boolean (tab->priv->editor, XED_SETTINGS_AUTO_SAVE); auto_save_interval = g_settings_get_uint (tab->priv->editor, XED_SETTINGS_AUTO_SAVE_INTERVAL); @@ -1450,26 +1435,18 @@ xed_tab_init (XedTab *tab) tab->priv->auto_save = (tab->priv->auto_save != FALSE); tab->priv->auto_save_interval = auto_save_interval; - /*FIXME - if (tab->priv->auto_save_interval <= 0) - { - tab->priv->auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL; - }*/ - /* Create the view */ - doc = xed_document_new (); + /* Create the frame */ + tab->priv->frame = xed_view_frame_new (); + gtk_widget_show (GTK_WIDGET (tab->priv->frame)); + + gtk_box_pack_end (GTK_BOX (tab), GTK_WIDGET (tab->priv->frame), TRUE, TRUE, 0); + + doc = xed_view_frame_get_document (tab->priv->frame); g_object_set_data (G_OBJECT (doc), XED_TAB_KEY, tab); - _xed_document_set_mount_operation_factory (doc, tab_mount_operation_factory, tab); - - tab->priv->view = xed_view_new (doc); - g_object_unref (doc); - gtk_widget_show (tab->priv->view); - g_object_set_data (G_OBJECT (tab->priv->view), XED_TAB_KEY, tab); - - gtk_box_pack_end (GTK_BOX (tab), sw, TRUE, TRUE, 0); - gtk_container_add (GTK_CONTAINER (sw), tab->priv->view); - gtk_widget_show (sw); + view = xed_view_frame_get_view (tab->priv->frame); + g_object_set_data (G_OBJECT (view), XED_TAB_KEY, tab); g_signal_connect (doc, "notify::location", G_CALLBACK (document_location_notify_handler), tab); @@ -1486,9 +1463,9 @@ xed_tab_init (XedTab *tab) g_signal_connect (doc, "saved", G_CALLBACK (document_saved), tab); - g_signal_connect_after (tab->priv->view, "focus-in-event", + g_signal_connect_after (view, "focus-in-event", G_CALLBACK (view_focused_in), tab); - g_signal_connect_after (tab->priv->view, "realize", + g_signal_connect_after (view, "realize", G_CALLBACK (view_realized), tab); } @@ -1528,7 +1505,9 @@ _xed_tab_new_from_location (GFile *location, XedView * xed_tab_get_view (XedTab *tab) { - return XED_VIEW (tab->priv->view); + g_return_val_if_fail (XED_IS_TAB (tab), NULL); + + return xed_view_frame_get_view (tab->priv->frame); } /** @@ -1542,7 +1521,9 @@ xed_tab_get_view (XedTab *tab) XedDocument * xed_tab_get_document (XedTab *tab) { - return XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (tab->priv->view))); + g_return_val_if_fail (XED_IS_TAB (tab), NULL); + + return xed_view_frame_get_document (tab->priv->frame); } #define MAX_DOC_NAME_LENGTH 40 @@ -2631,3 +2612,9 @@ xed_tab_set_info_bar (XedTab *tab, /* FIXME: this can cause problems with the tab state machine */ set_message_area (tab, info_bar); } + +GtkWidget * +_xed_tab_get_view_frame (XedTab *tab) +{ + return GTK_WIDGET (tab->priv->frame); +} diff --git a/xed/xed-tab.h b/xed/xed-tab.h index 80f2972..885f996 100644 --- a/xed/xed-tab.h +++ b/xed/xed-tab.h @@ -132,6 +132,7 @@ void _xed_tab_print (XedTab *tab); void _xed_tab_print_preview (XedTab *tab); void _xed_tab_mark_for_closing (XedTab *tab); gboolean _xed_tab_can_close (XedTab *tab); +GtkWidget *_xed_tab_get_view_frame (XedTab *tab); G_END_DECLS diff --git a/xed/xed-view-frame.c b/xed/xed-view-frame.c new file mode 100644 index 0000000..981b0cb --- /dev/null +++ b/xed/xed-view-frame.c @@ -0,0 +1,612 @@ +/* + * xed-view-frame.c + * This file is part of xed + * + * Copyright (C) 2010 - Ignacio Casal Quinteiro + * + * xed is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xed is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with xed; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "xed-view-frame.h" +#include "xed-marshal.h" +#include "xed-debug.h" +#include "xed-utils.h" + +#include +#include +#include + +#define XED_VIEW_FRAME_SEARCH_DIALOG_TIMEOUT (30*1000) /* 30 seconds */ + +#define SEARCH_POPUP_MARGIN 12 + +#define XED_VIEW_FRAME_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), XED_TYPE_VIEW_FRAME, XedViewFramePrivate)) + +struct _XedViewFramePrivate +{ + GtkWidget *view; + GtkWidget *overlay; + + GtkTextMark *start_mark; + + GtkWidget *revealer; + GtkWidget *search_entry; + + guint flush_timeout_id; + glong search_entry_focus_out_id; + glong search_entry_changed_id; + gboolean disable_popdown; +}; + +enum +{ + PROP_0, + PROP_DOCUMENT, + PROP_VIEW +}; + +typedef enum +{ + SEARCH_STATE_NORMAL, + SEARCH_STATE_NOT_FOUND +} SearchState; + +G_DEFINE_TYPE (XedViewFrame, xed_view_frame, GTK_TYPE_BOX) + +static void +xed_view_frame_finalize (GObject *object) +{ + G_OBJECT_CLASS (xed_view_frame_parent_class)->finalize (object); +} + +static void +xed_view_frame_dispose (GObject *object) +{ + XedViewFrame *frame = XED_VIEW_FRAME (object); + + if (frame->priv->flush_timeout_id != 0) + { + g_source_remove (frame->priv->flush_timeout_id); + frame->priv->flush_timeout_id = 0; + } + + G_OBJECT_CLASS (xed_view_frame_parent_class)->dispose (object); +} + +static void +xed_view_frame_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + XedViewFrame *frame = XED_VIEW_FRAME (object); + + switch (prop_id) + { + case PROP_DOCUMENT: + g_value_set_object (value, xed_view_frame_get_document (frame)); + break; + case PROP_VIEW: + g_value_set_object (value, xed_view_frame_get_view (frame)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +hide_search_widget (XedViewFrame *frame, + gboolean cancel) +{ + GtkTextBuffer *buffer; + + g_signal_handler_block (frame->priv->search_entry, frame->priv->search_entry_focus_out_id); + + if (frame->priv->flush_timeout_id != 0) + { + g_source_remove (frame->priv->flush_timeout_id); + frame->priv->flush_timeout_id = 0; + } + + gtk_revealer_set_reveal_child (GTK_REVEALER (frame->priv->revealer), FALSE); + + if (cancel) + { + GtkTextBuffer *buffer; + GtkTextIter iter; + + buffer = GTK_TEXT_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (frame->priv->view))); + gtk_text_buffer_get_iter_at_mark (buffer, &iter, frame->priv->start_mark); + gtk_text_buffer_place_cursor (buffer, &iter); + + xed_view_scroll_to_cursor (XED_VIEW (frame->priv->view)); + } + + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (frame->priv->view)); + gtk_text_buffer_delete_mark (buffer, frame->priv->start_mark); + + /* Make sure the view is the one who has the focus when we destroy + the search widget */ + gtk_widget_grab_focus (frame->priv->view); + + g_signal_handler_unblock (frame->priv->search_entry, frame->priv->search_entry_focus_out_id); +} + +static gboolean +search_entry_flush_timeout (XedViewFrame *frame) +{ + frame->priv->flush_timeout_id = 0; + hide_search_widget (frame, FALSE); + + return FALSE; +} + +static void +set_search_state (XedViewFrame *frame, + SearchState state) +{ + GtkStyleContext *context; + + context = gtk_widget_get_style_context (GTK_WIDGET (frame->priv->search_entry)); + + if (state == SEARCH_STATE_NOT_FOUND) + { + gtk_style_context_add_class (context, GTK_STYLE_CLASS_ERROR); + } + else + { + gtk_style_context_remove_class (context, GTK_STYLE_CLASS_ERROR); + } +} + +static gboolean +search_widget_key_press_event (GtkWidget *widget, + GdkEventKey *event, + XedViewFrame *frame) +{ + if (event->keyval == GDK_KEY_Escape) + { + + hide_search_widget (frame, TRUE); + return GDK_EVENT_STOP; + } + + return GDK_EVENT_PROPAGATE; +} + +static void +search_entry_activate (GtkEntry *entry, + XedViewFrame *frame) +{ + hide_search_widget (frame, FALSE); +} + +static void +search_entry_insert_text (GtkEditable *editable, + const gchar *text, + gint length, + gint *position, + XedViewFrame *frame) +{ + gunichar c; + const gchar *p; + const gchar *end; + const gchar *next; + + p = text; + end = text + length; + + if (p == end) + return; + + c = g_utf8_get_char (p); + + if (((c == '-' || c == '+') && *position == 0) || + (c == ':' && *position != 0)) + { + gchar *s = NULL; + + if (c == ':') + { + s = gtk_editable_get_chars (editable, 0, -1); + s = g_utf8_strchr (s, -1, ':'); + } + + if (s == NULL || s == p) + { + next = g_utf8_next_char (p); + p = next; + } + + g_free (s); + } + + while (p != end) + { + next = g_utf8_next_char (p); + + c = g_utf8_get_char (p); + + if (!g_unichar_isdigit (c)) + { + g_signal_stop_emission_by_name (editable, "insert_text"); + gtk_widget_error_bell (frame->priv->search_entry); + break; + } + + p = next; + } +} + +static void +search_init (GtkWidget *entry, + XedViewFrame *frame) +{ + const gchar *entry_text; + + /* renew the flush timeout */ + if (frame->priv->flush_timeout_id != 0) + { + g_source_remove (frame->priv->flush_timeout_id); + frame->priv->flush_timeout_id = g_timeout_add (XED_VIEW_FRAME_SEARCH_DIALOG_TIMEOUT, + (GSourceFunc)search_entry_flush_timeout, frame); + } + + entry_text = gtk_entry_get_text (GTK_ENTRY (entry)); + + if (*entry_text != '\0') + { + gboolean moved, moved_offset; + gint line; + gint offset_line = 0; + gint line_offset = 0; + gchar **split_text = NULL; + const gchar *text; + GtkTextIter iter; + XedDocument *doc; + + doc = xed_view_frame_get_document (frame); + gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), &iter, frame->priv->start_mark); + split_text = g_strsplit (entry_text, ":", -1); + + if (g_strv_length (split_text) > 1) + { + text = split_text[0]; + } + else + { + text = entry_text; + } + + if (*text == '-') + { + gint cur_line = gtk_text_iter_get_line (&iter); + + if (*(text + 1) != '\0') + { + offset_line = MAX (atoi (text + 1), 0); + } + + line = MAX (cur_line - offset_line, 0); + } + else if (*entry_text == '+') + { + gint cur_line = gtk_text_iter_get_line (&iter); + + if (*(text + 1) != '\0') + { + offset_line = MAX (atoi (text + 1), 0); + } + + line = cur_line + offset_line; + } + else + { + line = MAX (atoi (text) - 1, 0); + } + + if (split_text[1] != NULL) + { + line_offset = atoi (split_text[1]); + } + + g_strfreev (split_text); + + moved = xed_document_goto_line (doc, line); + moved_offset = xed_document_goto_line_offset (doc, line, line_offset); + + xed_view_scroll_to_cursor (XED_VIEW (frame->priv->view)); + + if (!moved || !moved_offset) + { + set_search_state (frame, SEARCH_STATE_NOT_FOUND); + } + else + { + set_search_state (frame, SEARCH_STATE_NORMAL); + } + } +} + +static gboolean +search_entry_focus_out_event (GtkWidget *widget, + GdkEventFocus *event, + XedViewFrame *frame) +{ + if (frame->priv->disable_popdown) + { + return GDK_EVENT_STOP; + } + + hide_search_widget (frame, FALSE); + return GDK_EVENT_PROPAGATE; +} + +static void +search_enable_popdown (GtkWidget *widget, + XedViewFrame *frame) +{ + frame->priv->disable_popdown = FALSE; +} + +static void +search_entry_populate_popup (GtkEntry *entry, + GtkMenu *menu, + XedViewFrame *frame) +{ + frame->priv->disable_popdown = TRUE; + g_signal_connect (menu, "hide", + G_CALLBACK (search_enable_popdown), frame); +} + +static GtkWidget * +create_search_widget (XedViewFrame *frame) +{ + GtkWidget *search_widget; + GtkWidget *hbox; + GtkStyleContext *context; + + /* wrap it in a frame, so we can specify borders etc */ + search_widget = gtk_frame_new (NULL); + context = gtk_widget_get_style_context (search_widget); + gtk_style_context_add_class (context, "xed-goto-line-box"); + gtk_widget_show (search_widget); + + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_container_add (GTK_CONTAINER (search_widget), hbox); + gtk_widget_show (hbox); + + g_signal_connect (hbox, "key-press-event", + G_CALLBACK (search_widget_key_press_event), frame); + + /* add entry */ + frame->priv->search_entry = gtk_entry_new (); + gtk_widget_set_tooltip_text (frame->priv->search_entry, _("Line you want to move the cursor to")); + gtk_entry_set_icon_from_icon_name (GTK_ENTRY (frame->priv->search_entry), + GTK_ENTRY_ICON_PRIMARY, "go-jump-symbolic"); + gtk_widget_show (frame->priv->search_entry); + + g_signal_connect (frame->priv->search_entry, "activate", + G_CALLBACK (search_entry_activate), frame); + g_signal_connect (frame->priv->search_entry, "insert_text", + G_CALLBACK (search_entry_insert_text), frame); + g_signal_connect (frame->priv->search_entry, "populate-popup", + G_CALLBACK (search_entry_populate_popup), frame); + frame->priv->search_entry_changed_id = g_signal_connect (frame->priv->search_entry, "changed", + G_CALLBACK (search_init), frame); + frame->priv->search_entry_focus_out_id = g_signal_connect (frame->priv->search_entry, "focus-out-event", + G_CALLBACK (search_entry_focus_out_event), frame); + + gtk_container_add (GTK_CONTAINER (hbox), frame->priv->search_entry); + + return search_widget; +} + +static void +init_search_entry (XedViewFrame *frame) +{ + GtkTextBuffer *buffer; + gint line; + gchar *line_str; + GtkTextIter iter; + + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (frame->priv->view)); + gtk_text_buffer_get_iter_at_mark (buffer, &iter, frame->priv->start_mark); + line = gtk_text_iter_get_line (&iter); + line_str = g_strdup_printf ("%d", line + 1); + + gtk_entry_set_text (GTK_ENTRY (frame->priv->search_entry), line_str); + gtk_editable_select_region (GTK_EDITABLE (frame->priv->search_entry), 0, -1); + + g_free (line_str); + + return; +} + +static void +start_interactive_search_real (XedViewFrame *frame) +{ + GtkTextBuffer *buffer; + GtkTextIter iter; + GtkTextMark *mark; + + if (gtk_revealer_get_reveal_child (GTK_REVEALER (frame->priv->revealer))) + { + gtk_editable_select_region (GTK_EDITABLE (frame->priv->search_entry), 0, -1); + return; + } + + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (frame->priv->view)); + + mark = gtk_text_buffer_get_insert (buffer); + gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark); + + frame->priv->start_mark = gtk_text_buffer_create_mark (buffer, NULL, &iter, FALSE); + + gtk_revealer_set_reveal_child (GTK_REVEALER (frame->priv->revealer), TRUE); + + /* NOTE: we must be very careful here to not have any text before + focusing the entry because when the entry is focused the text is + selected, and gtk+ doesn't allow us to have more than one selection + active */ + g_signal_handler_block (frame->priv->search_entry, frame->priv->search_entry_changed_id); + gtk_entry_set_text (GTK_ENTRY (frame->priv->search_entry), ""); + g_signal_handler_unblock (frame->priv->search_entry, frame->priv->search_entry_changed_id); + + /* We need to grab the focus after the widget has been added */ + gtk_widget_grab_focus (frame->priv->search_entry); + + init_search_entry (frame); + + frame->priv->flush_timeout_id = g_timeout_add (XED_VIEW_FRAME_SEARCH_DIALOG_TIMEOUT, + (GSourceFunc) search_entry_flush_timeout, frame); +} + +static void +xed_view_frame_class_init (XedViewFrameClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = xed_view_frame_finalize; + object_class->dispose = xed_view_frame_dispose; + object_class->get_property = xed_view_frame_get_property; + + g_object_class_install_property (object_class, PROP_DOCUMENT, + g_param_spec_object ("document", + "Document", + "The Document", + XED_TYPE_DOCUMENT, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (object_class, PROP_VIEW, + g_param_spec_object ("view", + "View", + "The View", + XED_TYPE_VIEW, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + g_type_class_add_private (object_class, sizeof (XedViewFramePrivate)); +} + +static GMountOperation * +view_frame_mount_operation_factory (XedDocument *doc, + gpointer user_data) +{ + XedViewFrame *frame = XED_VIEW_FRAME (user_data); + GtkWidget *window; + + window = gtk_widget_get_toplevel (GTK_WIDGET (frame)); + + return gtk_mount_operation_new (GTK_WINDOW (window)); +} + +static void +xed_view_frame_init (XedViewFrame *frame) +{ + XedDocument *doc; + GtkWidget *sw; + GdkRGBA transparent = {0, 0, 0, 0}; + + frame->priv = XED_VIEW_FRAME_GET_PRIVATE (frame); + + gtk_orientable_set_orientation (GTK_ORIENTABLE (frame), GTK_ORIENTATION_VERTICAL); + + doc = xed_document_new (); + + _xed_document_set_mount_operation_factory (doc, view_frame_mount_operation_factory, frame); + + frame->priv->view = xed_view_new (doc); + gtk_widget_set_vexpand (frame->priv->view, TRUE); + gtk_widget_show (frame->priv->view); + + g_object_unref (doc); + + /* Create the scrolled window */ + sw = gtk_scrolled_window_new (NULL, NULL); + gtk_container_add (GTK_CONTAINER (sw), frame->priv->view); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_widget_show (sw); + + frame->priv->overlay = gtk_overlay_new (); + gtk_container_add (GTK_CONTAINER (frame->priv->overlay), sw); + gtk_widget_override_background_color (frame->priv->overlay, 0, &transparent); + gtk_widget_show (frame->priv->overlay); + + gtk_box_pack_start (GTK_BOX (frame), frame->priv->overlay, TRUE, TRUE, 0); + + /* Add revealer */ + frame->priv->revealer = gtk_revealer_new (); + gtk_container_add (GTK_CONTAINER (frame->priv->revealer), create_search_widget (frame)); + gtk_widget_show (frame->priv->revealer); + gtk_widget_set_halign (frame->priv->revealer, GTK_ALIGN_END); + gtk_widget_set_valign (frame->priv->revealer, GTK_ALIGN_START); + + if (gtk_widget_get_direction (frame->priv->revealer) == GTK_TEXT_DIR_LTR) + { + gtk_widget_set_margin_right (frame->priv->revealer, SEARCH_POPUP_MARGIN); + } + else + { + gtk_widget_set_margin_left (frame->priv->revealer, SEARCH_POPUP_MARGIN); + } + + gtk_overlay_add_overlay (GTK_OVERLAY (frame->priv->overlay), frame->priv->revealer); +} + +XedViewFrame * +xed_view_frame_new () +{ + return g_object_new (XED_TYPE_VIEW_FRAME, NULL); +} + +XedDocument * +xed_view_frame_get_document (XedViewFrame *frame) +{ + g_return_val_if_fail (XED_IS_VIEW_FRAME (frame), NULL); + + return XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (frame->priv->view))); +} + +XedView * +xed_view_frame_get_view (XedViewFrame *frame) +{ + g_return_val_if_fail (XED_IS_VIEW_FRAME (frame), NULL); + + return XED_VIEW (frame->priv->view); +} + +void +xed_view_frame_popup_goto_line (XedViewFrame *frame) +{ + g_return_if_fail (XED_IS_VIEW_FRAME (frame)); + + start_interactive_search_real (frame); +} + +gboolean +xed_view_frame_get_search_popup_visible (XedViewFrame *frame) +{ + g_return_val_if_fail (XED_IS_VIEW_FRAME (frame), FALSE); + + return gtk_revealer_get_child_revealed (GTK_REVEALER (frame->priv->revealer)); +} diff --git a/xed/xed-view-frame.h b/xed/xed-view-frame.h new file mode 100644 index 0000000..1383fbe --- /dev/null +++ b/xed/xed-view-frame.h @@ -0,0 +1,70 @@ +/* + * xed-view-frame.h + * This file is part of xed + * + * Copyright (C) 2010 - Ignacio Casal Quinteiro + * + * xed is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xed is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with xed; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef __XED_VIEW_FRAME_H__ +#define __XED_VIEW_FRAME_H__ + +#include +#include "xed-document.h" +#include "xed-view.h" + +G_BEGIN_DECLS + +#define XED_TYPE_VIEW_FRAME (xed_view_frame_get_type ()) +#define XED_VIEW_FRAME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_VIEW_FRAME, XedViewFrame)) +#define XED_VIEW_FRAME_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_VIEW_FRAME, XedViewFrame const)) +#define XED_VIEW_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_VIEW_FRAME, XedViewFrameClass)) +#define XED_IS_VIEW_FRAME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_VIEW_FRAME)) +#define XED_IS_VIEW_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_VIEW_FRAME)) +#define XED_VIEW_FRAME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_VIEW_FRAME, XedViewFrameClass)) + +typedef struct _XedViewFrame XedViewFrame; +typedef struct _XedViewFrameClass XedViewFrameClass; +typedef struct _XedViewFramePrivate XedViewFramePrivate; + +struct _XedViewFrame +{ + GtkBox parent; + + XedViewFramePrivate *priv; +}; + +struct _XedViewFrameClass +{ + GtkBoxClass parent_class; +}; + +GType xed_view_frame_get_type (void) G_GNUC_CONST; + +XedViewFrame *xed_view_frame_new (void); + +XedDocument *xed_view_frame_get_document (XedViewFrame *frame); + +XedView *xed_view_frame_get_view (XedViewFrame *frame); + +void xed_view_frame_popup_goto_line (XedViewFrame *frame); + +gboolean xed_view_frame_get_search_popup_visible (XedViewFrame *frame); + +G_END_DECLS + +#endif /* __XED_VIEW_FRAME_H__ */ diff --git a/xed/xed-view.c b/xed/xed-view.c index 76998a1..74022bd 100644 --- a/xed/xed-view.c +++ b/xed/xed-view.c @@ -19,7 +19,6 @@ #include "xed-app.h" #define XED_VIEW_SCROLL_MARGIN 0.02 -#define XED_VIEW_SEARCH_DIALOG_TIMEOUT (30*1000) /* 30 seconds */ #define XED_VIEW_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_VIEW, XedViewPrivate)) @@ -31,43 +30,29 @@ enum struct _XedViewPrivate { GSettings *editor_settings; - GtkTextIter start_search_iter; - GtkWidget *search_window; - GtkWidget *search_entry; - guint typeselect_flush_timeout; - guint search_entry_changed_id; - gboolean disable_popdown; GtkTextBuffer *current_buffer; PeasExtensionSet *extensions; guint view_realized : 1; }; - -static gboolean start_interactive_goto_line (XedView *view); -static void hide_search_window (XedView *view, gboolean cancel); - -G_DEFINE_TYPE(XedView, xed_view, GTK_SOURCE_TYPE_VIEW) +G_DEFINE_TYPE (XedView, xed_view, GTK_SOURCE_TYPE_VIEW) /* Signals */ enum { - START_INTERACTIVE_GOTO_LINE, DROP_URIS, LAST_SIGNAL + DROP_URIS, + LAST_SIGNAL }; static guint view_signals[LAST_SIGNAL] = { 0 }; -typedef enum -{ - XED_SEARCH_ENTRY_NORMAL, XED_SEARCH_ENTRY_NOT_FOUND -} XedSearchEntryState; - static void document_read_only_notify_handler (XedDocument *document, GParamSpec *pspec, XedView *view) { xed_debug (DEBUG_VIEW); - gtk_text_view_set_editable (GTK_TEXT_VIEW(view), !xed_document_get_readonly (document)); + gtk_text_view_set_editable (GTK_TEXT_VIEW (view), !xed_document_get_readonly (document)); } static void @@ -177,8 +162,6 @@ xed_view_init (XedView *view) view->priv->editor_settings = g_settings_new ("org.x.editor.preferences.editor"); - view->priv->typeselect_flush_timeout = 0; - /* Drag and drop support */ tl = gtk_drag_dest_get_target_list (GTK_WIDGET(view)); @@ -207,18 +190,6 @@ xed_view_dispose (GObject *object) g_clear_object (&view->priv->extensions); g_clear_object (&view->priv->editor_settings); - if (view->priv->search_window != NULL) - { - gtk_widget_destroy (view->priv->search_window); - view->priv->search_window = NULL; - view->priv->search_entry = NULL; - if (view->priv->typeselect_flush_timeout != 0) - { - g_source_remove (view->priv->typeselect_flush_timeout); - view->priv->typeselect_flush_timeout = 0; - } - } - current_buffer_removed (view); /* Disconnect notify buffer because the destroy of the textview will set @@ -328,16 +299,8 @@ static gint xed_view_focus_out (GtkWidget *widget, GdkEventFocus *event) { - XedView *view = XED_VIEW (widget); - gtk_widget_queue_draw (widget); - /* hide interactive search dialog */ - if (view->priv->search_window != NULL) - { - hide_search_window (view, FALSE); - } - GTK_WIDGET_CLASS (xed_view_parent_class)->focus_out_event (widget, event); return FALSE; @@ -508,13 +471,11 @@ static gboolean xed_view_button_press_event (GtkWidget *widget, GdkEventButton *event) { - if ((event->type == GDK_BUTTON_PRESS) - && (event->button == 3) - && (event->window == gtk_text_view_get_window (GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_LEFT))) + if ((event->type == GDK_BUTTON_PRESS) && + (event->button == 3) && + (event->window == gtk_text_view_get_window (GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_LEFT))) { - show_line_numbers_menu (widget, event); - return TRUE; } @@ -675,19 +636,9 @@ xed_view_class_init (XedViewClass *klass) widget_class->drag_drop = xed_view_drag_drop; widget_class->button_press_event = xed_view_button_press_event; widget_class->realize = xed_view_realize; - klass->start_interactive_goto_line = start_interactive_goto_line; text_view_class->delete_from_cursor = xed_view_delete_from_cursor; - view_signals[START_INTERACTIVE_GOTO_LINE] = - g_signal_new ("start_interactive_goto_line", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (XedViewClass, start_interactive_goto_line), - NULL, NULL, - xed_marshal_BOOLEAN__NONE, - G_TYPE_BOOLEAN, 0); - /* A new signal DROP_URIS has been added to allow plugins to intercept * the default dnd behaviour of 'text/uri-list'. XedView now handles * dnd in the default handlers of drag_drop, drag_motion and @@ -710,8 +661,6 @@ xed_view_class_init (XedViewClass *klass) binding_set = gtk_binding_set_by_class (klass); - gtk_binding_entry_add_signal (binding_set, GDK_KEY_i, GDK_CONTROL_MASK, "start_interactive_goto_line", 0); - gtk_binding_entry_add_signal (binding_set, GDK_KEY_d, GDK_CONTROL_MASK, "delete_from_cursor", 2, G_TYPE_ENUM, GTK_DELETE_PARAGRAPHS, G_TYPE_INT, 1); } @@ -914,491 +863,3 @@ xed_view_set_font (XedView *view, gtk_widget_modify_font (GTK_WIDGET (view), font_desc); pango_font_description_free (font_desc); } - -static void -set_entry_state (GtkWidget *entry, - XedSearchEntryState state) -{ - GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET(entry)); - - if (state == XED_SEARCH_ENTRY_NOT_FOUND) - { - gtk_style_context_add_class (context, GTK_STYLE_CLASS_ERROR); - } - else - { - gtk_style_context_remove_class (context, GTK_STYLE_CLASS_ERROR); - } -} - -/* Cut and paste from gtkwindow.c */ -static void -send_focus_change (GtkWidget *widget, - gboolean in) -{ - GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE); - - g_object_ref (widget); - - fevent->focus_change.type = GDK_FOCUS_CHANGE; - fevent->focus_change.window = g_object_ref (gtk_widget_get_window (widget)); - fevent->focus_change.in = in; - - gtk_widget_event (widget, fevent); - - g_object_notify (G_OBJECT(widget), "has-focus"); - - g_object_unref (widget); - gdk_event_free (fevent); -} - -static void -hide_search_window (XedView *view, - gboolean cancel) -{ - if (view->priv->disable_popdown) - { - return; - } - - if (view->priv->search_entry_changed_id != 0) - { - g_signal_handler_disconnect (view->priv->search_entry, view->priv->search_entry_changed_id); - view->priv->search_entry_changed_id = 0; - } - - if (view->priv->typeselect_flush_timeout != 0) - { - g_source_remove (view->priv->typeselect_flush_timeout); - view->priv->typeselect_flush_timeout = 0; - } - - /* send focus-in event */ - send_focus_change (GTK_WIDGET(view->priv->search_entry), FALSE); - gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW(view), TRUE); - gtk_widget_hide (view->priv->search_window); - - if (cancel) - { - GtkTextBuffer *buffer; - buffer = GTK_TEXT_BUFFER(gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); - gtk_text_buffer_place_cursor (buffer, &view->priv->start_search_iter); - xed_view_scroll_to_cursor (view); - } - - /* make sure a focus event is sent for the edit area */ - send_focus_change (GTK_WIDGET(view), TRUE); -} - -static gboolean -search_entry_flush_timeout (XedView *view) -{ - view->priv->typeselect_flush_timeout = 0; - hide_search_window (view, FALSE); - - return FALSE; -} - -static void -update_search_window_position (XedView *view) -{ - gint x, y; - gint view_x, view_y; - GdkWindow *view_window = gtk_widget_get_window (GTK_WIDGET(view)); - - gtk_widget_realize (view->priv->search_window); - gdk_window_get_origin (view_window, &view_x, &view_y); - - x = MAX(12, view_x + 12); - y = MAX(12, view_y - 12); - - gtk_window_move (GTK_WINDOW(view->priv->search_window), x, y); -} - -static gboolean -search_window_deleted (GtkWidget *widget, - GdkEventAny *event, - XedView *view) -{ - hide_search_window (view, FALSE); - return TRUE; -} - -static gboolean -search_window_button_pressed (GtkWidget *widget, - GdkEventButton *event, - XedView *view) -{ - hide_search_window (view, FALSE); - gtk_propagate_event (GTK_WIDGET(view), (GdkEvent *) event); - return FALSE; -} - -static gboolean -search_window_key_pressed (GtkWidget *widget, - GdkEventKey *event, - XedView *view) -{ - gboolean retval = FALSE; - guint modifiers; - - modifiers = gtk_accelerator_get_default_mod_mask (); - - /* Close window */ - if (event->keyval == GDK_KEY_Tab) - { - hide_search_window (view, FALSE); - retval = TRUE; - } - - /* Close window and cancel the search */ - if (event->keyval == GDK_KEY_Escape) - { - hide_search_window (view, TRUE); - retval = TRUE; - } - - return retval; -} - -static void -search_entry_activate (GtkEntry *entry, - XedView *view) -{ - hide_search_window (view, FALSE); -} - -static gboolean -real_search_enable_popdown (gpointer data) -{ - XedView *view = (XedView *) data; - view->priv->disable_popdown = FALSE; - return FALSE; -} - -static void -search_enable_popdown (GtkWidget *widget, - XedView *view) -{ - g_timeout_add (200, real_search_enable_popdown, view); - - /* renew the flush timeout */ - if (view->priv->typeselect_flush_timeout != 0) - { - g_source_remove (view->priv->typeselect_flush_timeout); - } - - view->priv->typeselect_flush_timeout = g_timeout_add (XED_VIEW_SEARCH_DIALOG_TIMEOUT, - (GSourceFunc) search_entry_flush_timeout, view); -} - -static void -search_entry_populate_popup (GtkEntry *entry, - GtkMenu *menu, - XedView *view) -{ - GtkWidget *menu_item; - view->priv->disable_popdown = TRUE; - g_signal_connect(menu, "hide", G_CALLBACK (search_enable_popdown), view); -} - -static void -search_entry_insert_text (GtkEditable *editable, - const gchar *text, - gint length, - gint *position, - XedView *view) -{ - gunichar c; - const gchar *p; - const gchar *end; - const gchar *next; - - p = text; - end = text + length; - - if (p == end) - { - return; - } - - c = g_utf8_get_char (p); - - if (((c == '-' || c == '+') && *position == 0) || (c == ':' && *position != 0)) - { - gchar *s = NULL; - if (c == ':') - { - s = gtk_editable_get_chars (editable, 0, -1); - s = g_utf8_strchr (s, -1, ':'); - } - if (s == NULL || s == p) - { - next = g_utf8_next_char(p); - p = next; - } - g_free (s); - } - - while (p != end) - { - next = g_utf8_next_char(p); - c = g_utf8_get_char (p); - if (!g_unichar_isdigit (c)) - { - g_signal_stop_emission_by_name (editable, "insert_text"); - gtk_widget_error_bell (view->priv->search_entry); - break; - } - p = next; - } -} - -static void -customize_for_search_mode (XedView *view) -{ - gtk_entry_set_icon_from_stock (GTK_ENTRY(view->priv->search_entry), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_JUMP_TO); - gtk_widget_set_tooltip_text (view->priv->search_entry, _("Line you want to move the cursor to")); -} - -static void -ensure_search_window (XedView *view) -{ - GtkWidget *frame; - GtkWidget *vbox; - GtkWidget *toplevel; - GtkWindowGroup *group; - GtkWindowGroup *search_group; - - toplevel = gtk_widget_get_toplevel (GTK_WIDGET(view)); - group = gtk_window_get_group (GTK_WINDOW(toplevel)); - if (view->priv->search_window != NULL) - { - search_group = gtk_window_get_group (GTK_WINDOW(view->priv->search_window)); - } - - if (view->priv->search_window != NULL) - { - if (group) - { - gtk_window_group_add_window (group, GTK_WINDOW(view->priv->search_window)); - } - else if (search_group) - { - gtk_window_group_remove_window (search_group, GTK_WINDOW(view->priv->search_window)); - } - customize_for_search_mode (view); - return; - } - - view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP); - - if (group) - { - gtk_window_group_add_window (group, GTK_WINDOW(view->priv->search_window)); - } - - gtk_window_set_modal (GTK_WINDOW(view->priv->search_window), TRUE); - - g_signal_connect(view->priv->search_window, "delete_event", G_CALLBACK (search_window_deleted), view); - g_signal_connect(view->priv->search_window, "key_press_event", G_CALLBACK (search_window_key_pressed), view); - g_signal_connect(view->priv->search_window, "button_press_event", G_CALLBACK (search_window_button_pressed), view); - - frame = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN); - gtk_widget_show (frame); - gtk_container_add (GTK_CONTAINER(view->priv->search_window), frame); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - gtk_widget_show (vbox); - gtk_container_add (GTK_CONTAINER(frame), vbox); - gtk_container_set_border_width (GTK_CONTAINER(vbox), 3); - - /* add entry */ - view->priv->search_entry = gtk_entry_new (); - gtk_widget_show (view->priv->search_entry); - - g_signal_connect(view->priv->search_entry, "populate_popup", G_CALLBACK (search_entry_populate_popup), view); - g_signal_connect(view->priv->search_entry, "activate", G_CALLBACK (search_entry_activate), view); - g_signal_connect(view->priv->search_entry, "insert_text", G_CALLBACK (search_entry_insert_text), view); - - gtk_container_add (GTK_CONTAINER(vbox), view->priv->search_entry); - gtk_widget_realize (view->priv->search_entry); - - customize_for_search_mode (view); -} - -static gboolean -get_selected_text (GtkTextBuffer *doc, - gchar **selected_text, - gint *len) -{ - GtkTextIter start, end; - - g_return_val_if_fail(selected_text != NULL, FALSE); - g_return_val_if_fail(*selected_text == NULL, FALSE); - - if (!gtk_text_buffer_get_selection_bounds (doc, &start, &end)) - { - if (len != NULL) - { - len = 0; - } - return FALSE; - } - - *selected_text = gtk_text_buffer_get_slice (doc, &start, &end, TRUE); - - if (len != NULL) - { - *len = g_utf8_strlen (*selected_text, -1); - } - - return TRUE; -} - -static void -init_search_entry (XedView *view) -{ - gint line; - gchar *line_str; - - line = gtk_text_iter_get_line (&view->priv->start_search_iter); - line_str = g_strdup_printf ("%d", line + 1); - gtk_entry_set_text (GTK_ENTRY(view->priv->search_entry), line_str); - - g_free (line_str); - return; -} - -static void -search_init (GtkWidget *entry, - XedView *view) -{ - XedDocument *doc; - const gchar *entry_text; - - /* renew the flush timeout */ - if (view->priv->typeselect_flush_timeout != 0) - { - g_source_remove (view->priv->typeselect_flush_timeout); - view->priv->typeselect_flush_timeout = g_timeout_add (XED_VIEW_SEARCH_DIALOG_TIMEOUT, - (GSourceFunc) search_entry_flush_timeout, view); - } - doc = XED_DOCUMENT(gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); - - entry_text = gtk_entry_get_text (GTK_ENTRY(entry)); - - if (*entry_text != '\0') - { - gboolean moved, moved_offset; - gint line; - gint offset_line = 0; - gint line_offset = 0; - gchar **split_text = NULL; - const gchar *text; - - split_text = g_strsplit (entry_text, ":", -1); - - if (g_strv_length (split_text) > 1) - { - text = split_text[0]; - } - else - { - text = entry_text; - } - - if (*text == '-') - { - gint cur_line = gtk_text_iter_get_line (&view->priv->start_search_iter); - - if (*(text + 1) != '\0') - { - offset_line = MAX(atoi (text + 1), 0); - } - - line = MAX(cur_line - offset_line, 0); - } - else if (*entry_text == '+') - { - gint cur_line = gtk_text_iter_get_line (&view->priv->start_search_iter); - - if (*(text + 1) != '\0') - { - offset_line = MAX(atoi (text + 1), 0); - } - - line = cur_line + offset_line; - } - else - { - line = MAX(atoi (text) - 1, 0); - } - - if (split_text[1] != NULL) - { - line_offset = atoi (split_text[1]); - } - - g_strfreev (split_text); - - moved = xed_document_goto_line (doc, line); - moved_offset = xed_document_goto_line_offset (doc, line, line_offset); - - xed_view_scroll_to_cursor (view); - - if (!moved || !moved_offset) - { - set_entry_state (view->priv->search_entry, XED_SEARCH_ENTRY_NOT_FOUND); - } - else - { - set_entry_state (view->priv->search_entry, XED_SEARCH_ENTRY_NORMAL); - } - } -} - -static gboolean -start_interactive_goto_line (XedView *view) -{ - GtkTextBuffer *buffer; - - if ((view->priv->search_window != NULL) && gtk_widget_get_visible (view->priv->search_window)) - { - return TRUE; - } - - if (!gtk_widget_has_focus (GTK_WIDGET(view))) - { - return FALSE; - } - - buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(view)); - - gtk_text_buffer_get_iter_at_mark (buffer, &view->priv->start_search_iter, gtk_text_buffer_get_insert (buffer)); - - ensure_search_window (view); - - /* done, show it */ - update_search_window_position (view); - gtk_widget_show (view->priv->search_window); - - if (view->priv->search_entry_changed_id == 0) - { - view->priv->search_entry_changed_id = g_signal_connect(view->priv->search_entry, "changed", - G_CALLBACK (search_init), view); - } - - init_search_entry (view); - - view->priv->typeselect_flush_timeout = g_timeout_add (XED_VIEW_SEARCH_DIALOG_TIMEOUT, - (GSourceFunc) search_entry_flush_timeout, view); - - gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW(view), FALSE); - gtk_widget_grab_focus (view->priv->search_entry); - - send_focus_change (view->priv->search_entry, TRUE); - - return TRUE; -} diff --git a/xed/xed-view.h b/xed/xed-view.h index 368be30..eab7295 100644 --- a/xed/xed-view.h +++ b/xed/xed-view.h @@ -46,9 +46,6 @@ struct _XedViewClass /* FIXME: Do we need placeholders ? */ /* Key bindings */ - gboolean (* start_interactive_search) (XedView *view); - gboolean (* start_interactive_goto_line)(XedView *view); - gboolean (* reset_searched_text) (XedView *view); void (* drop_uris) (XedView *view, gchar **uri_list); }; diff --git a/xed/xed-window.c b/xed/xed-window.c index 4a10c77..5b75854 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -18,6 +18,7 @@ #include "xed-notebook.h" #include "xed-statusbar.h" #include "xed-searchbar.h" +#include "xed-view-frame.h" #include "xed-utils.h" #include "xed-commands.h" #include "xed-debug.h" @@ -127,13 +128,26 @@ on_key_pressed (GtkWidget *widget, GdkEventKey *event, XedWindow *window) { - gint handled = FALSE; if (event->keyval == GDK_KEY_Escape) { - xed_searchbar_hide (XED_SEARCHBAR (window->priv->searchbar)); - handled = TRUE; + XedTab *tab; + XedViewFrame *frame; + + tab = xed_window_get_active_tab (window); + frame = XED_VIEW_FRAME (_xed_tab_get_view_frame (tab)); + + if (xed_view_frame_get_search_popup_visible (frame)) + { + return GDK_EVENT_PROPAGATE; + } + else + { + xed_searchbar_hide (XED_SEARCHBAR (window->priv->searchbar)); + return GDK_EVENT_STOP; + } } - return handled; + + return GDK_EVENT_PROPAGATE; } static void From ca082205609dc7f7235340d638e405a9952b4a7c Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Thu, 19 Jan 2017 00:13:56 -0800 Subject: [PATCH 097/132] xed-preferences-dialog: Fix a setting having the wrong sensitiviy The font chooser sensitivity was backwards --- xed/dialogs/xed-preferences-dialog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xed/dialogs/xed-preferences-dialog.c b/xed/dialogs/xed-preferences-dialog.c index 0469f17..4a4f111 100755 --- a/xed/dialogs/xed-preferences-dialog.c +++ b/xed/dialogs/xed-preferences-dialog.c @@ -375,7 +375,7 @@ on_use_default_font_changed (GSettings *settings, xed_debug (DEBUG_PREFS); value = g_settings_get_boolean (settings, key); - gtk_widget_set_sensitive (dlg->priv->font_hbox, value); + gtk_widget_set_sensitive (dlg->priv->font_hbox, !value); } static void @@ -426,7 +426,7 @@ setup_font_colors_page_font_section (XedPreferencesDialog *dlg) G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); /* Set initial widget sensitivity */ - gtk_widget_set_sensitive (dlg->priv->font_hbox, use_default_font); + gtk_widget_set_sensitive (dlg->priv->font_hbox, !use_default_font); } static void From dfa7714cc5c9feabebe14b4ff584e8f1ff7fadec Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Thu, 19 Jan 2017 00:35:42 -0800 Subject: [PATCH 098/132] tests: Fix to use GFile instead of uris --- tests/document-loader.c | 6 +----- tests/document-saver.c | 4 +--- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/document-loader.c b/tests/document-loader.c index 1ad87ff..1a10869 100644 --- a/tests/document-loader.c +++ b/tests/document-loader.c @@ -122,11 +122,7 @@ test_loader (const gchar *filename, G_CALLBACK (on_document_loaded), data); - uri = g_file_get_uri (file); - - xed_document_load (document, uri, xed_encoding_get_utf8 (), 0, FALSE); - - g_free (uri); + xed_document_load (document, file, xed_encoding_get_utf8 (), 0, FALSE); while (!test_completed) { diff --git a/tests/document-saver.c b/tests/document-saver.c index 646acff..f914730 100644 --- a/tests/document-saver.c +++ b/tests/document-saver.c @@ -215,12 +215,11 @@ test_saver (const gchar *filename_or_uri, test_completed = FALSE; file = g_file_new_for_commandline_arg (filename_or_uri); - uri = g_file_get_uri (file); existed = g_file_query_exists (file, NULL); ensure_mounted (file); - xed_document_save_as (document, uri, xed_encoding_get_utf8 (), save_flags); + xed_document_save_as (document, file, xed_encoding_get_utf8 (), save_flags); while (!test_completed) { @@ -232,7 +231,6 @@ test_saver (const gchar *filename_or_uri, g_file_delete (file, NULL, NULL); } - g_free (uri); g_object_unref (file); saver_test_data_free (data); From 28ef771d1524c66a077f77ebacb1f93a2c5fc6c2 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Thu, 19 Jan 2017 01:38:13 -0800 Subject: [PATCH 099/132] xed-document-output-stream: Clean up code style --- xed/xed-document-output-stream.c | 488 +++++++++++++++---------------- 1 file changed, 241 insertions(+), 247 deletions(-) diff --git a/xed/xed-document-output-stream.c b/xed/xed-document-output-stream.c index 55777a5..571995b 100644 --- a/xed/xed-document-output-stream.c +++ b/xed/xed-document-output-stream.c @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU General Public License * along with xed; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -35,213 +35,208 @@ * thread */ #define XED_DOCUMENT_OUTPUT_STREAM_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object),\ - XED_TYPE_DOCUMENT_OUTPUT_STREAM,\ - XedDocumentOutputStreamPrivate)) + XED_TYPE_DOCUMENT_OUTPUT_STREAM,\ + XedDocumentOutputStreamPrivate)) #define MAX_UNICHAR_LEN 6 struct _XedDocumentOutputStreamPrivate { - XedDocument *doc; - GtkTextIter pos; + XedDocument *doc; + GtkTextIter pos; - gchar *buffer; - gsize buflen; + gchar *buffer; + gsize buflen; - guint is_initialized : 1; - guint is_closed : 1; + guint is_initialized : 1; + guint is_closed : 1; }; enum { - PROP_0, - PROP_DOCUMENT + PROP_0, + PROP_DOCUMENT }; G_DEFINE_TYPE (XedDocumentOutputStream, xed_document_output_stream, G_TYPE_OUTPUT_STREAM) -static gssize xed_document_output_stream_write (GOutputStream *stream, - const void *buffer, - gsize count, - GCancellable *cancellable, - GError **error); +static gssize xed_document_output_stream_write (GOutputStream *stream, + const void *buffer, + gsize count, + GCancellable *cancellable, + GError **error); static gboolean xed_document_output_stream_flush (GOutputStream *stream, - GCancellable *cancellable, - GError **error); + GCancellable *cancellable, + GError **error); -static gboolean xed_document_output_stream_close (GOutputStream *stream, - GCancellable *cancellable, - GError **error); +static gboolean xed_document_output_stream_close (GOutputStream *stream, + GCancellable *cancellable, + GError **error); static void xed_document_output_stream_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - XedDocumentOutputStream *stream = XED_DOCUMENT_OUTPUT_STREAM (object); + XedDocumentOutputStream *stream = XED_DOCUMENT_OUTPUT_STREAM (object); - switch (prop_id) - { - case PROP_DOCUMENT: - stream->priv->doc = XED_DOCUMENT (g_value_get_object (value)); - break; + switch (prop_id) + { + case PROP_DOCUMENT: + stream->priv->doc = XED_DOCUMENT (g_value_get_object (value)); + break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_document_output_stream_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - XedDocumentOutputStream *stream = XED_DOCUMENT_OUTPUT_STREAM (object); + XedDocumentOutputStream *stream = XED_DOCUMENT_OUTPUT_STREAM (object); - switch (prop_id) - { - case PROP_DOCUMENT: - g_value_set_object (value, stream->priv->doc); - break; + switch (prop_id) + { + case PROP_DOCUMENT: + g_value_set_object (value, stream->priv->doc); + break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_document_output_stream_finalize (GObject *object) { - XedDocumentOutputStream *stream = XED_DOCUMENT_OUTPUT_STREAM (object); + XedDocumentOutputStream *stream = XED_DOCUMENT_OUTPUT_STREAM (object); - g_free (stream->priv->buffer); + g_free (stream->priv->buffer); - G_OBJECT_CLASS (xed_document_output_stream_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_document_output_stream_parent_class)->finalize (object); } static void xed_document_output_stream_constructed (GObject *object) { - XedDocumentOutputStream *stream = XED_DOCUMENT_OUTPUT_STREAM (object); + XedDocumentOutputStream *stream = XED_DOCUMENT_OUTPUT_STREAM (object); - if (!stream->priv->doc) - { - g_critical ("This should never happen, a problem happened constructing the Document Output Stream!"); - return; - } + if (!stream->priv->doc) + { + g_critical ("This should never happen, a problem happened constructing the Document Output Stream!"); + return; + } - /* Init the undoable action */ - gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (stream->priv->doc)); - /* clear the buffer */ - gtk_text_buffer_set_text (GTK_TEXT_BUFFER (stream->priv->doc), - "", 0); - gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->priv->doc), - FALSE); + /* Init the undoable action */ + gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (stream->priv->doc)); + /* clear the buffer */ + gtk_text_buffer_set_text (GTK_TEXT_BUFFER (stream->priv->doc), "", 0); + gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->priv->doc), FALSE); - gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (stream->priv->doc)); + gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (stream->priv->doc)); } static void xed_document_output_stream_class_init (XedDocumentOutputStreamClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GOutputStreamClass *stream_class = G_OUTPUT_STREAM_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GOutputStreamClass *stream_class = G_OUTPUT_STREAM_CLASS (klass); - object_class->get_property = xed_document_output_stream_get_property; - object_class->set_property = xed_document_output_stream_set_property; - object_class->finalize = xed_document_output_stream_finalize; - object_class->constructed = xed_document_output_stream_constructed; + object_class->get_property = xed_document_output_stream_get_property; + object_class->set_property = xed_document_output_stream_set_property; + object_class->finalize = xed_document_output_stream_finalize; + object_class->constructed = xed_document_output_stream_constructed; - stream_class->write_fn = xed_document_output_stream_write; - stream_class->flush = xed_document_output_stream_flush; - stream_class->close_fn = xed_document_output_stream_close; + stream_class->write_fn = xed_document_output_stream_write; + stream_class->flush = xed_document_output_stream_flush; + stream_class->close_fn = xed_document_output_stream_close; - g_object_class_install_property (object_class, - PROP_DOCUMENT, - g_param_spec_object ("document", - "Document", - "The document which is written", - XED_TYPE_DOCUMENT, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, + PROP_DOCUMENT, + g_param_spec_object ("document", + "Document", + "The document which is written", + XED_TYPE_DOCUMENT, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); - g_type_class_add_private (object_class, sizeof (XedDocumentOutputStreamPrivate)); + g_type_class_add_private (object_class, sizeof (XedDocumentOutputStreamPrivate)); } static void xed_document_output_stream_init (XedDocumentOutputStream *stream) { - stream->priv = XED_DOCUMENT_OUTPUT_STREAM_GET_PRIVATE (stream); + stream->priv = XED_DOCUMENT_OUTPUT_STREAM_GET_PRIVATE (stream); - stream->priv->buffer = NULL; - stream->priv->buflen = 0; + stream->priv->buffer = NULL; + stream->priv->buflen = 0; - stream->priv->is_initialized = FALSE; - stream->priv->is_closed = FALSE; + stream->priv->is_initialized = FALSE; + stream->priv->is_closed = FALSE; } static XedDocumentNewlineType get_newline_type (GtkTextIter *end) { - XedDocumentNewlineType res; - GtkTextIter copy; - gunichar c; + XedDocumentNewlineType res; + GtkTextIter copy; + gunichar c; - copy = *end; - c = gtk_text_iter_get_char (©); + copy = *end; + c = gtk_text_iter_get_char (©); - if (g_unichar_break_type (c) == G_UNICODE_BREAK_CARRIAGE_RETURN) - { - if (gtk_text_iter_forward_char (©) && - g_unichar_break_type (gtk_text_iter_get_char (©)) == G_UNICODE_BREAK_LINE_FEED) - { - res = XED_DOCUMENT_NEWLINE_TYPE_CR_LF; - } - else - { - res = XED_DOCUMENT_NEWLINE_TYPE_CR; - } - } - else - { - res = XED_DOCUMENT_NEWLINE_TYPE_LF; - } + if (g_unichar_break_type (c) == G_UNICODE_BREAK_CARRIAGE_RETURN) + { + if (gtk_text_iter_forward_char (©) && + g_unichar_break_type (gtk_text_iter_get_char (©)) == G_UNICODE_BREAK_LINE_FEED) + { + res = XED_DOCUMENT_NEWLINE_TYPE_CR_LF; + } + else + { + res = XED_DOCUMENT_NEWLINE_TYPE_CR; + } + } + else + { + res = XED_DOCUMENT_NEWLINE_TYPE_LF; + } - return res; + return res; } GOutputStream * xed_document_output_stream_new (XedDocument *doc) { - return G_OUTPUT_STREAM (g_object_new (XED_TYPE_DOCUMENT_OUTPUT_STREAM, - "document", doc, NULL)); + return G_OUTPUT_STREAM (g_object_new (XED_TYPE_DOCUMENT_OUTPUT_STREAM, "document", doc, NULL)); } XedDocumentNewlineType xed_document_output_stream_detect_newline_type (XedDocumentOutputStream *stream) { - XedDocumentNewlineType type; - GtkTextIter iter; + XedDocumentNewlineType type; + GtkTextIter iter; - g_return_val_if_fail (XED_IS_DOCUMENT_OUTPUT_STREAM (stream), - XED_DOCUMENT_NEWLINE_TYPE_DEFAULT); + g_return_val_if_fail (XED_IS_DOCUMENT_OUTPUT_STREAM (stream), XED_DOCUMENT_NEWLINE_TYPE_DEFAULT); - type = XED_DOCUMENT_NEWLINE_TYPE_DEFAULT; + type = XED_DOCUMENT_NEWLINE_TYPE_DEFAULT; - gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (stream->priv->doc), - &iter); + gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (stream->priv->doc), &iter); - if (gtk_text_iter_ends_line (&iter) || gtk_text_iter_forward_to_line_end (&iter)) - { - type = get_newline_type (&iter); - } + if (gtk_text_iter_ends_line (&iter) || gtk_text_iter_forward_to_line_end (&iter)) + { + type = get_newline_type (&iter); + } - return type; + return type; } /* If the last char is a newline, remove it from the buffer (otherwise @@ -249,171 +244,170 @@ xed_document_output_stream_detect_newline_type (XedDocumentOutputStream *stream) static void remove_ending_newline (XedDocumentOutputStream *stream) { - GtkTextIter end; - GtkTextIter start; + GtkTextIter end; + GtkTextIter start; - gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (stream->priv->doc), &end); - start = end; + gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (stream->priv->doc), &end); + start = end; - gtk_text_iter_set_line_offset (&start, 0); + gtk_text_iter_set_line_offset (&start, 0); - if (gtk_text_iter_ends_line (&start) && - gtk_text_iter_backward_line (&start)) - { - if (!gtk_text_iter_ends_line (&start)) - { - gtk_text_iter_forward_to_line_end (&start); - } + if (gtk_text_iter_ends_line (&start) && gtk_text_iter_backward_line (&start)) + { + if (!gtk_text_iter_ends_line (&start)) + { + gtk_text_iter_forward_to_line_end (&start); + } - /* Delete the empty line which is from 'start' to 'end' */ - gtk_text_buffer_delete (GTK_TEXT_BUFFER (stream->priv->doc), - &start, - &end); - } + /* Delete the empty line which is from 'start' to 'end' */ + gtk_text_buffer_delete (GTK_TEXT_BUFFER (stream->priv->doc), &start, &end); + } } static void end_append_text_to_document (XedDocumentOutputStream *stream) { - remove_ending_newline (stream); + remove_ending_newline (stream); - gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->priv->doc), - FALSE); + gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->priv->doc), FALSE); - gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (stream->priv->doc)); + gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (stream->priv->doc)); } static gssize -xed_document_output_stream_write (GOutputStream *stream, - const void *buffer, - gsize count, - GCancellable *cancellable, - GError **error) +xed_document_output_stream_write (GOutputStream *stream, + const void *buffer, + gsize count, + GCancellable *cancellable, + GError **error) { - XedDocumentOutputStream *ostream; - gchar *text; - gsize len; - gboolean freetext = FALSE; - const gchar *end; - gboolean valid; + XedDocumentOutputStream *ostream; + gchar *text; + gsize len; + gboolean freetext = FALSE; + const gchar *end; + gboolean valid; - if (g_cancellable_set_error_if_cancelled (cancellable, error)) - return -1; + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + { + return -1; + } - ostream = XED_DOCUMENT_OUTPUT_STREAM (stream); + ostream = XED_DOCUMENT_OUTPUT_STREAM (stream); - if (!ostream->priv->is_initialized) - { - /* Init the undoable action */ - gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (ostream->priv->doc)); + if (!ostream->priv->is_initialized) + { + /* Init the undoable action */ + gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (ostream->priv->doc)); - gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (ostream->priv->doc), - &ostream->priv->pos); - ostream->priv->is_initialized = TRUE; - } + gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (ostream->priv->doc), &ostream->priv->pos); + ostream->priv->is_initialized = TRUE; + } - if (ostream->priv->buflen > 0) - { - len = ostream->priv->buflen + count; - text = g_new (gchar , len + 1); - memcpy (text, ostream->priv->buffer, ostream->priv->buflen); - memcpy (text + ostream->priv->buflen, buffer, count); - text[len] = '\0'; - g_free (ostream->priv->buffer); - ostream->priv->buffer = NULL; - ostream->priv->buflen = 0; - freetext = TRUE; - } - else - { - text = (gchar *) buffer; - len = count; - } + if (ostream->priv->buflen > 0) + { + len = ostream->priv->buflen + count; + text = g_new (gchar , len + 1); + memcpy (text, ostream->priv->buffer, ostream->priv->buflen); + memcpy (text + ostream->priv->buflen, buffer, count); + text[len] = '\0'; + g_free (ostream->priv->buffer); + ostream->priv->buffer = NULL; + ostream->priv->buflen = 0; + freetext = TRUE; + } + else + { + text = (gchar *) buffer; + len = count; + } - /* validate */ - valid = g_utf8_validate (text, len, &end); + /* validate */ + valid = g_utf8_validate (text, len, &end); - /* Avoid keeping a CRLF across two buffers. */ - if (valid && len > 1 && end[-1] == '\r') - { - valid = FALSE; - end--; - } + /* Avoid keeping a CRLF across two buffers. */ + if (valid && len > 1 && end[-1] == '\r') + { + valid = FALSE; + end--; + } - if (!valid) - { - gsize nvalid = end - text; - gsize remainder = len - nvalid; - gunichar ch; + if (!valid) + { + gsize nvalid = end - text; + gsize remainder = len - nvalid; + gunichar ch; - if ((remainder < MAX_UNICHAR_LEN) && - ((ch = g_utf8_get_char_validated (text + nvalid, remainder)) == (gunichar)-2 || - ch == (gunichar)'\r')) - { - ostream->priv->buffer = g_strndup (end, remainder); - ostream->priv->buflen = remainder; - len -= remainder; - } - else - { - /* TODO: we could escape invalid text and tag it in red - * and make the doc readonly. - */ - g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, - _("Invalid UTF-8 sequence in input")); + if ((remainder < MAX_UNICHAR_LEN) && + ((ch = g_utf8_get_char_validated (text + nvalid, remainder)) == (gunichar)-2 || + ch == (gunichar)'\r')) + { + ostream->priv->buffer = g_strndup (end, remainder); + ostream->priv->buflen = remainder; + len -= remainder; + } + else + { + /* TODO: we could escape invalid text and tag it in red + * and make the doc readonly. + */ + g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, _("Invalid UTF-8 sequence in input")); - if (freetext) - g_free (text); + if (freetext) + { + g_free (text); + } - return -1; - } - } + return -1; + } + } - gtk_text_buffer_insert (GTK_TEXT_BUFFER (ostream->priv->doc), - &ostream->priv->pos, text, len); + gtk_text_buffer_insert (GTK_TEXT_BUFFER (ostream->priv->doc), &ostream->priv->pos, text, len); - if (freetext) - g_free (text); + if (freetext) + { + g_free (text); + } - return count; + return count; } static gboolean xed_document_output_stream_flush (GOutputStream *stream, - GCancellable *cancellable, - GError **error) + GCancellable *cancellable, + GError **error) { - XedDocumentOutputStream *ostream = XED_DOCUMENT_OUTPUT_STREAM (stream); + XedDocumentOutputStream *ostream = XED_DOCUMENT_OUTPUT_STREAM (stream); - /* Flush deferred data if some. */ - if (!ostream->priv->is_closed && ostream->priv->is_initialized && - ostream->priv->buflen > 0 && - xed_document_output_stream_write (stream, "", 0, cancellable, - error) == -1) - return FALSE; + /* Flush deferred data if some. */ + if (!ostream->priv->is_closed && ostream->priv->is_initialized && + ostream->priv->buflen > 0 && + xed_document_output_stream_write (stream, "", 0, cancellable, error) == -1) + { + return FALSE; + } - return TRUE; + return TRUE; } static gboolean -xed_document_output_stream_close (GOutputStream *stream, - GCancellable *cancellable, - GError **error) +xed_document_output_stream_close (GOutputStream *stream, + GCancellable *cancellable, + GError **error) { - XedDocumentOutputStream *ostream = XED_DOCUMENT_OUTPUT_STREAM (stream); + XedDocumentOutputStream *ostream = XED_DOCUMENT_OUTPUT_STREAM (stream); - if (!ostream->priv->is_closed && ostream->priv->is_initialized) - { - end_append_text_to_document (ostream); - ostream->priv->is_closed = TRUE; - } + if (!ostream->priv->is_closed && ostream->priv->is_initialized) + { + end_append_text_to_document (ostream); + ostream->priv->is_closed = TRUE; + } - if (ostream->priv->buflen > 0) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, - _("Incomplete UTF-8 sequence in input")); - return FALSE; - } + if (ostream->priv->buflen > 0) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, _("Incomplete UTF-8 sequence in input")); + return FALSE; + } - return TRUE; + return TRUE; } From 2fb38137933f0b21367a7d5a81b83d369f502197 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Thu, 19 Jan 2017 01:48:54 -0800 Subject: [PATCH 100/132] xed-document-output-stream: Clean up code style --- xed/xed-document-output-stream.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/xed/xed-document-output-stream.h b/xed/xed-document-output-stream.h index e63daeb..a0d4b52 100644 --- a/xed/xed-document-output-stream.h +++ b/xed/xed-document-output-stream.h @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU General Public License * along with xed; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -29,33 +29,33 @@ G_BEGIN_DECLS -#define XED_TYPE_DOCUMENT_OUTPUT_STREAM (xed_document_output_stream_get_type ()) -#define XED_DOCUMENT_OUTPUT_STREAM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_DOCUMENT_OUTPUT_STREAM, XedDocumentOutputStream)) -#define XED_DOCUMENT_OUTPUT_STREAM_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_DOCUMENT_OUTPUT_STREAM, XedDocumentOutputStream const)) -#define XED_DOCUMENT_OUTPUT_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_DOCUMENT_OUTPUT_STREAM, XedDocumentOutputStreamClass)) -#define XED_IS_DOCUMENT_OUTPUT_STREAM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_DOCUMENT_OUTPUT_STREAM)) -#define XED_IS_DOCUMENT_OUTPUT_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_DOCUMENT_OUTPUT_STREAM)) -#define XED_DOCUMENT_OUTPUT_STREAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_DOCUMENT_OUTPUT_STREAM, XedDocumentOutputStreamClass)) +#define XED_TYPE_DOCUMENT_OUTPUT_STREAM (xed_document_output_stream_get_type ()) +#define XED_DOCUMENT_OUTPUT_STREAM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_DOCUMENT_OUTPUT_STREAM, XedDocumentOutputStream)) +#define XED_DOCUMENT_OUTPUT_STREAM_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_DOCUMENT_OUTPUT_STREAM, XedDocumentOutputStream const)) +#define XED_DOCUMENT_OUTPUT_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_DOCUMENT_OUTPUT_STREAM, XedDocumentOutputStreamClass)) +#define XED_IS_DOCUMENT_OUTPUT_STREAM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_DOCUMENT_OUTPUT_STREAM)) +#define XED_IS_DOCUMENT_OUTPUT_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_DOCUMENT_OUTPUT_STREAM)) +#define XED_DOCUMENT_OUTPUT_STREAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_DOCUMENT_OUTPUT_STREAM, XedDocumentOutputStreamClass)) -typedef struct _XedDocumentOutputStream XedDocumentOutputStream; -typedef struct _XedDocumentOutputStreamClass XedDocumentOutputStreamClass; -typedef struct _XedDocumentOutputStreamPrivate XedDocumentOutputStreamPrivate; +typedef struct _XedDocumentOutputStream XedDocumentOutputStream; +typedef struct _XedDocumentOutputStreamPrivate XedDocumentOutputStreamPrivate; +typedef struct _XedDocumentOutputStreamClass XedDocumentOutputStreamClass; struct _XedDocumentOutputStream { - GOutputStream parent; + GOutputStream parent; - XedDocumentOutputStreamPrivate *priv; + XedDocumentOutputStreamPrivate *priv; }; struct _XedDocumentOutputStreamClass { - GOutputStreamClass parent_class; + GOutputStreamClass parent_class; }; -GType xed_document_output_stream_get_type (void) G_GNUC_CONST; +GType xed_document_output_stream_get_type (void) G_GNUC_CONST; -GOutputStream *xed_document_output_stream_new (XedDocument *doc); +GOutputStream *xed_document_output_stream_new (XedDocument *doc); XedDocumentNewlineType xed_document_output_stream_detect_newline_type (XedDocumentOutputStream *stream); From e3e9566570723a8f89d52c52c166ea728261bf93 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Thu, 19 Jan 2017 03:29:38 -0800 Subject: [PATCH 101/132] Merge smart converter in the document output stream Based on https://github.com/GNOME/gedit/commit/85279adad605df29244253227541d0db45b98308#diff-c243a4d5a7789c35057282ee780df3d5 --- tests/Makefile.am | 6 +- tests/document-output-stream.c | 239 ++++++++++++++++- tests/smart-converter.c | 353 ------------------------- xed/Makefile.am | 2 - xed/xed-document-loader.c | 32 +-- xed/xed-document-output-stream.c | 381 ++++++++++++++++++++++++++- xed/xed-document-output-stream.h | 8 +- xed/xed-smart-charset-converter.c | 422 ------------------------------ xed/xed-smart-charset-converter.h | 66 ----- 9 files changed, 635 insertions(+), 874 deletions(-) delete mode 100644 tests/smart-converter.c delete mode 100644 xed/xed-smart-charset-converter.c delete mode 100644 xed/xed-smart-charset-converter.h diff --git a/tests/Makefile.am b/tests/Makefile.am index afec0a6..2f468f5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,11 +3,7 @@ AM_CPPFLAGS = -g -I$(top_srcdir) -I$(top_srcdir)/xed $(XED_DEBUG_FLAGS) $(XED_CF noinst_PROGRAMS = $(TEST_PROGS) progs_ldadd = $(top_builddir)/xed/libxed.la -TEST_PROGS = smart-converter -smart_converter_SOURCES = smart-converter.c -smart_converter_LDADD = $(progs_ldadd) - -TEST_PROGS += document-input-stream +TEST_PROGS = document-input-stream document_input_stream_SOURCES = document-input-stream.c document_input_stream_LDADD = $(progs_ldadd) diff --git a/tests/document-output-stream.c b/tests/document-output-stream.c index f74036a..a136815 100644 --- a/tests/document-output-stream.c +++ b/tests/document-output-stream.c @@ -40,9 +40,11 @@ test_consecutive_write (const gchar *inbuf, GError *err = NULL; gchar *b; XedDocumentNewlineType type; + GSList *encodings = NULL; doc = xed_document_new (); - out = xed_document_output_stream_new (doc); + encodings = g_slist_prepend (encodings, (gpointer)xed_encoding_get_utf8 ()); + out = xed_document_output_stream_new (doc, encodings); n = 0; @@ -119,6 +121,237 @@ test_big_char () XED_DOCUMENT_NEWLINE_TYPE_LF); } +/* SMART CONVERSION */ + +#define TEXT_TO_CONVERT "this is some text to make the tests" +#define TEXT_TO_GUESS "hello \xe6\x96\x87 world" + +static void +print_hex (gchar *ptr, gint len) +{ + gint i; + + for (i = 0; i < len; ++i) + { + g_printf ("\\x%02x", (unsigned char)ptr[i]); + } + + g_printf ("\n"); +} + +static gchar * +get_encoded_text (const gchar *text, + gsize nread, + const XedEncoding *to, + const XedEncoding *from, + gsize *bytes_written_aux, + gboolean care_about_error) +{ + GCharsetConverter *converter; + gchar *out, *out_aux; + gsize bytes_read, bytes_read_aux; + gsize bytes_written; + GConverterResult res; + GError *err; + + converter = g_charset_converter_new (xed_encoding_get_charset (to), + xed_encoding_get_charset (from), + NULL); + + out = g_malloc (200); + out_aux = g_malloc (200); + err = NULL; + bytes_read_aux = 0; + *bytes_written_aux = 0; + + if (nread == -1) + { + nread = strlen (text); + } + + do + { + res = g_converter_convert (G_CONVERTER (converter), + text + bytes_read_aux, + nread, + out_aux, + 200, + G_CONVERTER_INPUT_AT_END, + &bytes_read, + &bytes_written, + &err); + memcpy (out + *bytes_written_aux, out_aux, bytes_written); + bytes_read_aux += bytes_read; + *bytes_written_aux += bytes_written; + nread -= bytes_read; + } while (res != G_CONVERTER_FINISHED && res != G_CONVERTER_ERROR); + + if (care_about_error) + { + g_assert_no_error (err); + } + else if (err) + { + g_printf ("** You don't care, but there was an error: %s", err->message); + return NULL; + } + + out[*bytes_written_aux] = '\0'; + + if (!g_utf8_validate (out, *bytes_written_aux, NULL) && !care_about_error) + { + if (!care_about_error) + { + return NULL; + } + else + { + g_assert_not_reached (); + } + } + + return out; +} + +static GSList * +get_all_encodings () +{ + GSList *encs = NULL; + gint i = 0; + + while (TRUE) + { + const XedEncoding *enc; + + enc = xed_encoding_get_from_index (i); + + if (enc == NULL) + break; + + encs = g_slist_prepend (encs, (gpointer)enc); + i++; + } + + return encs; +} + +static gchar * +do_test (const gchar *test_in, + const gchar *enc, + GSList *encodings, + gsize nread, + const XedEncoding **guessed) +{ + XedDocument *doc; + GOutputStream *out; + GError *err = NULL; + GtkTextIter start, end; + gchar *text; + + if (enc != NULL) + { + encodings = NULL; + encodings = g_slist_prepend (encodings, (gpointer)xed_encoding_get_from_charset (enc)); + } + + doc = xed_document_new (); + encodings = g_slist_prepend (encodings, (gpointer)xed_encoding_get_utf8 ()); + out = xed_document_output_stream_new (doc, encodings); + + g_output_stream_write (out, test_in, nread, NULL, &err); + g_assert_no_error (err); + + g_output_stream_flush (out, NULL, &err); + g_assert_no_error (err); + + g_output_stream_close (out, NULL, &err); + g_assert_no_error (err); + + if (guessed != NULL) + *guessed = xed_document_output_stream_get_guessed (XED_DOCUMENT_OUTPUT_STREAM (out)); + + gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &start, &end); + text = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (doc), + &start, + &end, + FALSE); + + g_object_unref (doc); + g_object_unref (out); + + return text; +} + +static void +test_utf8_utf8 () +{ + gchar *aux; + + aux = do_test (TEXT_TO_CONVERT, "UTF-8", NULL, strlen (TEXT_TO_CONVERT), NULL); + g_assert_cmpstr (aux, ==, TEXT_TO_CONVERT); + + aux = do_test ("foobar\xc3\xa8\xc3\xa8\xc3\xa8zzzzzz", "UTF-8", NULL, 18, NULL); + g_assert_cmpstr (aux, ==, "foobar\xc3\xa8\xc3\xa8\xc3\xa8zzzzzz"); + + aux = do_test ("foobar\xc3\xa8\xc3\xa8\xc3\xa8zzzzzz", "UTF-8", NULL, 12, NULL); + g_assert_cmpstr (aux, ==, "foobar\xc3\xa8\xc3\xa8\xc3\xa8"); + + /* FIXME: Use the utf8 stream for a fallback? */ + //do_test_with_error ("\xef\xbf\xbezzzzzz", encs, G_IO_ERROR_FAILED); +} + +static void +test_empty_conversion () +{ + const XedEncoding *guessed; + gchar *out; + GSList *encodings = NULL; + + /* testing the case of an empty file and list of encodings with no + utf-8. In this case, the smart converter cannot determine the right + encoding (because there is no input), but should still default to + utf-8 for the detection */ + encodings = g_slist_prepend (encodings, (gpointer)xed_encoding_get_from_charset ("UTF-16")); + encodings = g_slist_prepend (encodings, (gpointer)xed_encoding_get_from_charset ("ISO-8859-15")); + + out = do_test ("", NULL, encodings, 0, &guessed); + + g_assert_cmpstr (out, ==, ""); + + g_assert (guessed == xed_encoding_get_utf8 ()); +} + +static void +test_guessed () +{ + GSList *encs = NULL; + gchar *aux, *aux2, *fail; + gsize aux_len, fail_len; + const XedEncoding *guessed; + + aux = get_encoded_text (TEXT_TO_GUESS, -1, + xed_encoding_get_from_charset ("UTF-16"), + xed_encoding_get_from_charset ("UTF-8"), + &aux_len, + TRUE); + + fail = get_encoded_text (aux, aux_len, + xed_encoding_get_from_charset ("UTF-8"), + xed_encoding_get_from_charset ("ISO-8859-15"), + &fail_len, + FALSE); + + g_assert (fail == NULL); + + /* ISO-8859-15 should fail */ + encs = g_slist_append (encs, (gpointer)xed_encoding_get_from_charset ("ISO-8859-15")); + encs = g_slist_append (encs, (gpointer)xed_encoding_get_from_charset ("UTF-16")); + + aux2 = do_test (aux, NULL, encs, aux_len, &guessed); + + g_assert (guessed == xed_encoding_get_from_charset ("UTF-16")); +} + int main (int argc, char *argv[]) { @@ -130,5 +363,9 @@ int main (int argc, g_test_add_func ("/document-output-stream/consecutive_tnewline", test_consecutive_tnewline); g_test_add_func ("/document-output-stream/big-char", test_big_char); + g_test_add_func ("/document-output-stream/smart conversion: utf8-utf8", test_utf8_utf8); + g_test_add_func ("/document-output-stream/smart conversion: guessed", test_guessed); + g_test_add_func ("/document-output-stream/smart conversion: empty", test_empty_conversion); + return g_test_run (); } diff --git a/tests/smart-converter.c b/tests/smart-converter.c deleted file mode 100644 index 9dd322c..0000000 --- a/tests/smart-converter.c +++ /dev/null @@ -1,353 +0,0 @@ -/* - * smart-converter.c - * This file is part of xed - * - * Copyright (C) 2009 - Ignacio Casal Quinteiro - * - * xed is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xed is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with xed; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301 USA - */ - - -#include "xed-smart-charset-converter.h" -#include "xed-encodings.h" -#include -#include -#include -#include - -#define TEXT_TO_CONVERT "this is some text to make the tests" -#define TEXT_TO_GUESS "hello \xe6\x96\x87 world" - -static void -print_hex (gchar *ptr, gint len) -{ - gint i; - - for (i = 0; i < len; ++i) - { - g_printf ("\\x%02x", (unsigned char)ptr[i]); - } - - g_printf ("\n"); -} - -static gchar * -get_encoded_text (const gchar *text, - gsize nread, - const XedEncoding *to, - const XedEncoding *from, - gsize *bytes_written_aux, - gboolean care_about_error) -{ - GCharsetConverter *converter; - gchar *out, *out_aux; - gsize bytes_read, bytes_read_aux; - gsize bytes_written; - GConverterResult res; - GError *err; - - converter = g_charset_converter_new (xed_encoding_get_charset (to), - xed_encoding_get_charset (from), - NULL); - - out = g_malloc (200); - out_aux = g_malloc (200); - err = NULL; - bytes_read_aux = 0; - *bytes_written_aux = 0; - - if (nread == -1) - { - nread = strlen (text); - } - - do - { - res = g_converter_convert (G_CONVERTER (converter), - text + bytes_read_aux, - nread, - out_aux, - 200, - G_CONVERTER_INPUT_AT_END, - &bytes_read, - &bytes_written, - &err); - memcpy (out + *bytes_written_aux, out_aux, bytes_written); - bytes_read_aux += bytes_read; - *bytes_written_aux += bytes_written; - nread -= bytes_read; - } while (res != G_CONVERTER_FINISHED && res != G_CONVERTER_ERROR); - - if (care_about_error) - { - g_assert_no_error (err); - } - else if (err) - { - g_printf ("** You don't care, but there was an error: %s", err->message); - return NULL; - } - - out[*bytes_written_aux] = '\0'; - - if (!g_utf8_validate (out, *bytes_written_aux, NULL) && !care_about_error) - { - if (!care_about_error) - { - return NULL; - } - else - { - g_assert_not_reached (); - } - } - - return out; -} - -static GSList * -get_all_encodings () -{ - GSList *encs = NULL; - gint i = 0; - - while (TRUE) - { - const XedEncoding *enc; - - enc = xed_encoding_get_from_index (i); - - if (enc == NULL) - break; - - encs = g_slist_prepend (encs, (gpointer)enc); - i++; - } - - return encs; -} - -static gchar * -do_test (const gchar *test_in, - const gchar *enc, - GSList *encodings, - gsize nread, - const XedEncoding **guessed) -{ - XedSmartCharsetConverter *converter; - gchar *out, *out_aux; - gsize bytes_read, bytes_read_aux; - gsize bytes_written, bytes_written_aux; - GConverterResult res; - GError *err; - - if (enc != NULL) - { - encodings = NULL; - encodings = g_slist_prepend (encodings, (gpointer)xed_encoding_get_from_charset (enc)); - } - - converter = xed_smart_charset_converter_new (encodings); - - out = g_malloc (200); - out_aux = g_malloc (200); - err = NULL; - bytes_read_aux = 0; - bytes_written_aux = 0; - - do - { - res = g_converter_convert (G_CONVERTER (converter), - test_in + bytes_read_aux, - nread, - out_aux, - 200, - G_CONVERTER_INPUT_AT_END, - &bytes_read, - &bytes_written, - &err); - memcpy (out + bytes_written_aux, out_aux, bytes_written); - bytes_read_aux += bytes_read; - bytes_written_aux += bytes_written; - nread -= bytes_read; - } while (res != G_CONVERTER_FINISHED && res != G_CONVERTER_ERROR); - - g_assert_no_error (err); - out[bytes_written_aux] = '\0'; - - if (guessed != NULL) - *guessed = xed_smart_charset_converter_get_guessed (converter); - - return out; -} - -static void -do_test_roundtrip (const char *str, const char *charset) -{ - gsize len; - gchar *buf, *p; - GInputStream *in, *tmp; - GCharsetConverter *c1; - XedSmartCharsetConverter *c2; - gsize n, tot; - GError *err; - GSList *enc = NULL; - - len = strlen(str); - buf = g_new0 (char, len); - - in = g_memory_input_stream_new_from_data (str, -1, NULL); - - c1 = g_charset_converter_new (charset, "UTF-8", NULL); - - tmp = in; - in = g_converter_input_stream_new (in, G_CONVERTER (c1)); - g_object_unref (tmp); - g_object_unref (c1); - - enc = g_slist_prepend (enc, (gpointer)xed_encoding_get_from_charset (charset)); - c2 = xed_smart_charset_converter_new (enc); - g_slist_free (enc); - - tmp = in; - in = g_converter_input_stream_new (in, G_CONVERTER (c2)); - g_object_unref (tmp); - g_object_unref (c2); - - tot = 0; - p = buf; - n = len; - while (TRUE) - { - gssize res; - - err = NULL; - res = g_input_stream_read (in, p, n, NULL, &err); - g_assert_no_error (err); - if (res == 0) - break; - - p += res; - n -= res; - tot += res; - } - - g_assert_cmpint (tot, ==, len); - g_assert_cmpstr (str, ==, buf); - - g_free (buf); - g_object_unref (in); -} - -static void -test_utf8_utf8 () -{ - gchar *aux; - - aux = do_test (TEXT_TO_CONVERT, "UTF-8", NULL, strlen (TEXT_TO_CONVERT), NULL); - g_assert_cmpstr (aux, ==, TEXT_TO_CONVERT); - - aux = do_test ("foobar\xc3\xa8\xc3\xa8\xc3\xa8zzzzzz", "UTF-8", NULL, 18, NULL); - g_assert_cmpstr (aux, ==, "foobar\xc3\xa8\xc3\xa8\xc3\xa8zzzzzz"); - - aux = do_test ("foobar\xc3\xa8\xc3\xa8\xc3\xa8zzzzzz", "UTF-8", NULL, 9, NULL); - g_assert_cmpstr (aux, ==, "foobar\xc3\xa8\xc3"); - - /* FIXME: Use the utf8 stream for a fallback? */ - //do_test_with_error ("\xef\xbf\xbezzzzzz", encs, G_IO_ERROR_FAILED); -} - -static void -test_xxx_xxx () -{ - GSList *encs, *l; - - encs = get_all_encodings (); - - /* Here we just test all encodings it is just to know that the conversions - are done ok */ - for (l = encs; l != NULL; l = g_slist_next (l)) - { - do_test_roundtrip (TEXT_TO_CONVERT, xed_encoding_get_charset ((const XedEncoding *)l->data)); - } - - g_slist_free (encs); -} - -static void -test_empty () -{ - const XedEncoding *guessed; - gchar *out; - GSList *encodings = NULL; - - /* testing the case of an empty file and list of encodings with no - utf-8. In this case, the smart converter cannot determine the right - encoding (because there is no input), but should still default to - utf-8 for the detection */ - encodings = g_slist_prepend (encodings, (gpointer)xed_encoding_get_from_charset ("UTF-16")); - encodings = g_slist_prepend (encodings, (gpointer)xed_encoding_get_from_charset ("ISO-8859-15")); - - out = do_test ("", NULL, encodings, 0, &guessed); - - g_assert_cmpstr (out, ==, ""); - - g_assert (guessed == xed_encoding_get_utf8 ()); -} - -static void -test_guessed () -{ - GSList *encs = NULL; - gchar *aux, *aux2, *fail; - gsize aux_len, fail_len; - const XedEncoding *guessed; - - aux = get_encoded_text (TEXT_TO_GUESS, -1, - xed_encoding_get_from_charset ("UTF-16"), - xed_encoding_get_from_charset ("UTF-8"), - &aux_len, - TRUE); - - fail = get_encoded_text (aux, aux_len, - xed_encoding_get_from_charset ("UTF-8"), - xed_encoding_get_from_charset ("ISO-8859-15"), - &fail_len, - FALSE); - - g_assert (fail == NULL); - - /* ISO-8859-15 should fail */ - encs = g_slist_append (encs, (gpointer)xed_encoding_get_from_charset ("ISO-8859-15")); - encs = g_slist_append (encs, (gpointer)xed_encoding_get_from_charset ("UTF-16")); - - aux2 = do_test (aux, NULL, encs, aux_len, &guessed); - - g_assert (guessed == xed_encoding_get_from_charset ("UTF-16")); -} - -int main (int argc, - char *argv[]) -{ - g_test_init (&argc, &argv, NULL); - - g_test_add_func ("/smart-converter/utf8-utf8", test_utf8_utf8); - //g_test_add_func ("/smart-converter/xxx-xxx", test_xxx_xxx); - g_test_add_func ("/smart-converter/guessed", test_guessed); - g_test_add_func ("/smart-converter/empty", test_empty); - - return g_test_run (); -} diff --git a/xed/Makefile.am b/xed/Makefile.am index 7bca45b..0fb2d3b 100644 --- a/xed/Makefile.am +++ b/xed/Makefile.am @@ -59,7 +59,6 @@ NOINST_H_FILES = \ xed-print-preview.h \ xed-session.h \ xed-settings.h \ - xed-smart-charset-converter.h \ xed-style-scheme-manager.h \ xed-tab-label.h \ xedtextregion.h \ @@ -140,7 +139,6 @@ libxed_c_files = \ xed-progress-message-area.c \ xed-session.c \ xed-settings.c \ - xed-smart-charset-converter.c \ xed-searchbar.c \ xed-statusbar.c \ xed-status-combo-box.c \ diff --git a/xed/xed-document-loader.c b/xed/xed-document-loader.c index 3f40f2e..3233adf 100644 --- a/xed/xed-document-loader.c +++ b/xed/xed-document-loader.c @@ -39,7 +39,6 @@ #include "xed-document-loader.h" #include "xed-document-output-stream.h" -#include "xed-smart-charset-converter.h" #include "xed-debug.h" #include "xed-metadata-manager.h" #include "xed-utils.h" @@ -112,7 +111,6 @@ struct _XedDocumentLoaderPrivate GCancellable *cancellable; GInputStream *stream; GOutputStream *output; - XedSmartCharsetConverter *converter; gchar buffer[READ_CHUNK_SIZE]; @@ -206,12 +204,6 @@ xed_document_loader_dispose (GObject *object) priv->output = NULL; } - if (priv->converter != NULL) - { - g_object_unref (priv->converter); - priv->converter = NULL; - } - if (priv->error != NULL) { g_error_free (priv->error); @@ -305,7 +297,6 @@ xed_document_loader_init (XedDocumentLoader *loader) loader->priv->used = FALSE; loader->priv->auto_detected_newline_type = XED_DOCUMENT_NEWLINE_TYPE_DEFAULT; - loader->priv->converter = NULL; loader->priv->error = NULL; loader->priv->enc_settings = g_settings_new ("org.x.editor.preferences.encodings"); } @@ -544,7 +535,11 @@ async_read_cb (GInputStream *stream, /* end of the file, we are done! */ if (async->read == 0) { - loader->priv->auto_detected_encoding = xed_smart_charset_converter_get_guessed (loader->priv->converter); + /* flush the stream to ensure proper line ending detection */ + g_output_stream_flush (loader->priv->output, NULL, NULL); + + loader->priv->auto_detected_encoding = + xed_document_output_stream_get_guessed (XED_DOCUMENT_OUTPUT_STREAM (loader->priv->output)); loader->priv->auto_detected_newline_type = xed_document_output_stream_detect_newline_type (XED_DOCUMENT_OUTPUT_STREAM (loader->priv->output)); @@ -552,7 +547,7 @@ async_read_cb (GInputStream *stream, /* Check if we needed some fallback char, if so, check if there was a previous error and if not set a fallback used error */ /* FIXME Uncomment this when we want to manage conversion fallback */ - /*if ((xed_smart_charset_converter_get_num_fallbacks (loader->priv->converter) != 0) && + /*if ((xed_document_output_stream_get_num_fallbacks (XED_DOCUMENT_OUTPUT_STREAM (loader->priv->ouput)) != 0) && loader->priv->error == NULL) { g_set_error_literal (&loader->priv->error, @@ -631,6 +626,10 @@ finish_query_info (AsyncData *async) return; } + conv_stream = g_object_ref (loader->priv->stream); + g_object_unref (loader->priv->stream); + loader->priv->stream = conv_stream; + /* Get the candidate encodings */ if (loader->priv->encoding == NULL) { @@ -641,16 +640,9 @@ finish_query_info (AsyncData *async) candidate_encodings = g_slist_prepend (NULL, (gpointer) loader->priv->encoding); } - loader->priv->converter = xed_smart_charset_converter_new (candidate_encodings); - g_slist_free (candidate_encodings); - - conv_stream = g_converter_input_stream_new (loader->priv->stream, G_CONVERTER (loader->priv->converter)); - g_object_unref (loader->priv->stream); - - loader->priv->stream = conv_stream; - /* Output stream */ - loader->priv->output = xed_document_output_stream_new (loader->priv->document); + loader->priv->output = xed_document_output_stream_new (loader->priv->document, candidate_encodings); + g_slist_free (candidate_encodings); /* start reading */ read_file_chunk (async); diff --git a/xed/xed-document-output-stream.c b/xed/xed-document-output-stream.c index 571995b..ba11422 100644 --- a/xed/xed-document-output-stream.c +++ b/xed/xed-document-output-stream.c @@ -26,7 +26,9 @@ #include #include #include +#include #include "xed-document-output-stream.h" +#include "xed-debug.h" /* NOTE: never use async methods on this stream, the stream is just * a wrapper around GtkTextBuffer api so that we can use GIO Stream @@ -48,6 +50,16 @@ struct _XedDocumentOutputStreamPrivate gchar *buffer; gsize buflen; + /* Encoding detection */ + GIConv iconv; + GCharsetConverter *charset_conv; + + GSList *encodings; + GSList *current_encoding; + + guint is_utf8 : 1; + guint use_first : 1; + guint is_initialized : 1; guint is_closed : 1; }; @@ -114,12 +126,33 @@ xed_document_output_stream_get_property (GObject *object, } } +static void +xed_document_output_stream_dispose (GObject *object) +{ + XedDocumentOutputStream *stream = XED_DOCUMENT_OUTPUT_STREAM (object); + + if (stream->priv->iconv != NULL) + { + g_iconv_close (stream->priv->iconv); + stream->priv->iconv = NULL; + } + + if (stream->priv->charset_conv != NULL) + { + g_object_unref (stream->priv->charset_conv); + stream->priv->charset_conv = NULL; + } + + G_OBJECT_CLASS (xed_document_output_stream_parent_class)->dispose (object); +} + static void xed_document_output_stream_finalize (GObject *object) { XedDocumentOutputStream *stream = XED_DOCUMENT_OUTPUT_STREAM (object); g_free (stream->priv->buffer); + g_slist_free (stream->priv->encodings); G_OBJECT_CLASS (xed_document_output_stream_parent_class)->finalize (object); } @@ -152,6 +185,7 @@ xed_document_output_stream_class_init (XedDocumentOutputStreamClass *klass) object_class->get_property = xed_document_output_stream_get_property; object_class->set_property = xed_document_output_stream_set_property; + object_class->dispose = xed_document_output_stream_dispose; object_class->finalize = xed_document_output_stream_finalize; object_class->constructed = xed_document_output_stream_constructed; @@ -179,10 +213,194 @@ xed_document_output_stream_init (XedDocumentOutputStream *stream) stream->priv->buffer = NULL; stream->priv->buflen = 0; + stream->priv->charset_conv = NULL; + stream->priv->encodings = NULL; + stream->priv->current_encoding = NULL; + stream->priv->is_initialized = FALSE; stream->priv->is_closed = FALSE; + stream->priv->is_utf8 = FALSE; + stream->priv->use_first = FALSE; } +static const XedEncoding * +get_encoding (XedDocumentOutputStream *stream) +{ + if (stream->priv->current_encoding == NULL) + { + stream->priv->current_encoding = stream->priv->encodings; + } + else + { + stream->priv->current_encoding = g_slist_next (stream->priv->current_encoding); + } + + if (stream->priv->current_encoding != NULL) + { + return (const XedEncoding *)stream->priv->current_encoding->data; + } + + return NULL; +} + +static gboolean +try_convert (GCharsetConverter *converter, + const void *inbuf, + gsize inbuf_size) +{ + GError *err; + gsize bytes_read, nread; + gsize bytes_written, nwritten; + GConverterResult res; + gchar *out; + gboolean ret; + gsize out_size; + + if (inbuf == NULL || inbuf_size == 0) + { + return FALSE; + } + + err = NULL; + nread = 0; + nwritten = 0; + out_size = inbuf_size * 4; + out = g_malloc (out_size); + + do + { + res = g_converter_convert (G_CONVERTER (converter), + (gchar *)inbuf + nread, + inbuf_size - nread, + (gchar *)out + nwritten, + out_size - nwritten, + G_CONVERTER_INPUT_AT_END, + &bytes_read, + &bytes_written, + &err); + + nread += bytes_read; + nwritten += bytes_written; + } while (res != G_CONVERTER_FINISHED && res != G_CONVERTER_ERROR && err == NULL); + + if (err != NULL) + { + if (err->code == G_CONVERT_ERROR_PARTIAL_INPUT) + { + /* FIXME We can get partial input while guessing the + encoding because we just take some amount of text + to guess from. */ + ret = TRUE; + } + else + { + ret = FALSE; + } + + g_error_free (err); + } + else + { + ret = TRUE; + } + + /* FIXME: Check the remainder? */ + if (ret == TRUE && !g_utf8_validate (out, nwritten, NULL)) + { + ret = FALSE; + } + + g_free (out); + + return ret; +} + +static GCharsetConverter * +guess_encoding (XedDocumentOutputStream *stream, + const void *inbuf, + gsize inbuf_size) +{ + GCharsetConverter *conv = NULL; + + if (inbuf == NULL || inbuf_size == 0) + { + stream->priv->is_utf8 = TRUE; + return NULL; + } + + if (stream->priv->encodings != NULL && stream->priv->encodings->next == NULL) + { + stream->priv->use_first = TRUE; + } + + /* We just check the first block */ + while (TRUE) + { + const XedEncoding *enc; + + if (conv != NULL) + { + g_object_unref (conv); + conv = NULL; + } + + /* We get an encoding from the list */ + enc = get_encoding (stream); + + /* if it is NULL we didn't guess anything */ + if (enc == NULL) + { + break; + } + + xed_debug_message (DEBUG_UTILS, "trying charset: %s", + xed_encoding_get_charset (stream->priv->current_encoding->data)); + + if (enc == xed_encoding_get_utf8 ()) + { + gsize remainder; + const gchar *end; + + if (g_utf8_validate (inbuf, inbuf_size, &end) || stream->priv->use_first) + { + stream->priv->is_utf8 = TRUE; + break; + } + + /* Check if the end is less than one char */ + remainder = inbuf_size - (end - (gchar *)inbuf); + if (remainder < 6) + { + stream->priv->is_utf8 = TRUE; + break; + } + + continue; + } + + conv = g_charset_converter_new ("UTF-8", xed_encoding_get_charset (enc), NULL); + + /* If we tried all encodings we use the first one */ + if (stream->priv->use_first) + { + break; + } + + /* Try to convert */ + if (try_convert (conv, inbuf, inbuf_size)) + { + break; + } + } + + if (conv != NULL) + { + g_converter_reset (G_CONVERTER (conv)); + } + + return conv; + } + static XedDocumentNewlineType get_newline_type (GtkTextIter *end) { @@ -214,9 +432,16 @@ get_newline_type (GtkTextIter *end) } GOutputStream * -xed_document_output_stream_new (XedDocument *doc) +xed_document_output_stream_new (XedDocument *doc, + GSList *candidate_encodings) { - return G_OUTPUT_STREAM (g_object_new (XED_TYPE_DOCUMENT_OUTPUT_STREAM, "document", doc, NULL)); + XedDocumentOutputStream *stream; + + stream = g_object_new (XED_TYPE_DOCUMENT_OUTPUT_STREAM, "document", doc, NULL); + + stream->priv->encodings = g_slist_copy (candidate_encodings); + + return G_OUTPUT_STREAM (stream); } XedDocumentNewlineType @@ -239,6 +464,38 @@ xed_document_output_stream_detect_newline_type (XedDocumentOutputStream *stream) return type; } +const XedEncoding * +xed_document_output_stream_get_guessed (XedDocumentOutputStream *stream) +{ + g_return_val_if_fail (XED_IS_DOCUMENT_OUTPUT_STREAM (stream), NULL); + + if (stream->priv->current_encoding != NULL) + { + return (const XedEncoding *)stream->priv->current_encoding->data; + } + else if (stream->priv->is_utf8 || !stream->priv->is_initialized) + { + /* If it is not initialized we assume that we are trying to convert + the empty string */ + return xed_encoding_get_utf8 (); + } + + return NULL; +} + +guint +xed_document_output_stream_get_num_fallbacks (XedDocumentOutputStream *stream) +{ + g_return_val_if_fail (XED_IS_DOCUMENT_OUTPUT_STREAM (stream), FALSE); + + if (stream->priv->charset_conv == NULL) + { + return FALSE; + } + + return g_charset_converter_get_num_fallbacks (stream->priv->charset_conv) != 0; +} + /* If the last char is a newline, remove it from the buffer (otherwise GtkTextView shows it as an empty line). See bug #324942. */ static void @@ -287,6 +544,8 @@ xed_document_output_stream_write (GOutputStream *stream, gboolean freetext = FALSE; const gchar *end; gboolean valid; + gsize nvalid; + gsize remainder; if (g_cancellable_set_error_if_cancelled (cancellable, error)) { @@ -297,6 +556,52 @@ xed_document_output_stream_write (GOutputStream *stream, if (!ostream->priv->is_initialized) { + ostream->priv->charset_conv = guess_encoding (ostream, buffer, count); + + /* If we still have the previous case is that we didn't guess + anything */ + if (ostream->priv->charset_conv == NULL && !ostream->priv->is_utf8) + { + /* FIXME: Add a different domain when we kill xed_convert */ + g_set_error_literal (error, XED_DOCUMENT_ERROR, + XED_DOCUMENT_ERROR_ENCODING_AUTO_DETECTION_FAILED, + _("It is not possible to detect the encoding automatically")); + return -1; + } + + /* Do not initialize iconv if we are not going to conver anything */ + if (!ostream->priv->is_utf8) + { + gchar *from_charset; + + /* Initialize iconv */ + g_object_get (G_OBJECT (ostream->priv->charset_conv), "from-charset", &from_charset, NULL); + + ostream->priv->iconv = g_iconv_open ("UTF-8", from_charset); + + if (ostream->priv->iconv == (GIConv)-1) + { + if (errno == EINVAL) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, + _("Conversion from character set '%s' to 'UTF-8' is not supported"), + from_charset); + } + else + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + _("Could not open converter from '%s' to 'UTF-8'"), + from_charset); + } + + g_free (from_charset); + + return -1; + } + + g_free (from_charset); + } + /* Init the undoable action */ gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (ostream->priv->doc)); @@ -308,12 +613,17 @@ xed_document_output_stream_write (GOutputStream *stream, { len = ostream->priv->buflen + count; text = g_new (gchar , len + 1); + memcpy (text, ostream->priv->buffer, ostream->priv->buflen); memcpy (text + ostream->priv->buflen, buffer, count); + text[len] = '\0'; + g_free (ostream->priv->buffer); + ostream->priv->buffer = NULL; ostream->priv->buflen = 0; + freetext = TRUE; } else @@ -322,8 +632,71 @@ xed_document_output_stream_write (GOutputStream *stream, len = count; } + if (!ostream->priv->is_utf8) + { + gchar *conv_text; + gsize conv_read; + gsize conv_written; + GError *err = NULL; + + if (ostream->priv->iconv == NULL) + { + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_INITIALIZED, _("Invalid object, not initialized")); + + if (freetext) + { + g_free (text); + } + + return -1; + } + + /* If we reached here is because we need to convert the text so, we + convert it with the charset converter */ + conv_text = g_convert_with_iconv (text, + len, + ostream->priv->iconv, + &conv_read, + &conv_written, + &err); + + if (freetext) + { + g_free (text); + } + + if (err != NULL) + { + remainder = len - conv_read; + + /* Store the partial char for the next conversion */ + if (err->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE && + remainder < MAX_UNICHAR_LEN && + (g_utf8_get_char_validated (text + conv_read, remainder) == (gunichar)-2)) + { + ostream->priv->buffer = g_strndup (text + conv_read, remainder); + ostream->priv->buflen = remainder; + } + else + { + /* Something went wrong with the conversion, + propagate the error and finish */ + g_propagate_error (error, err); + g_free (conv_text); + + return -1; + } + } + + text = conv_text; + len = conv_written; + freetext = TRUE; + } + + /* validate */ valid = g_utf8_validate (text, len, &end); + nvalid = end - text; /* Avoid keeping a CRLF across two buffers. */ if (valid && len > 1 && end[-1] == '\r') @@ -334,8 +707,8 @@ xed_document_output_stream_write (GOutputStream *stream, if (!valid) { - gsize nvalid = end - text; - gsize remainder = len - nvalid; + // gsize nvalid = end - text; + remainder = len - nvalid; gunichar ch; if ((remainder < MAX_UNICHAR_LEN) && diff --git a/xed/xed-document-output-stream.h b/xed/xed-document-output-stream.h index a0d4b52..a0af7cb 100644 --- a/xed/xed-document-output-stream.h +++ b/xed/xed-document-output-stream.h @@ -26,6 +26,7 @@ #include #include "xed-document.h" +#include "xed-encodings.h" G_BEGIN_DECLS @@ -55,10 +56,15 @@ struct _XedDocumentOutputStreamClass GType xed_document_output_stream_get_type (void) G_GNUC_CONST; -GOutputStream *xed_document_output_stream_new (XedDocument *doc); +GOutputStream *xed_document_output_stream_new (XedDocument *doc, + GSList *candidate_encodings); XedDocumentNewlineType xed_document_output_stream_detect_newline_type (XedDocumentOutputStream *stream); +const XedEncoding *xed_document_output_stream_get_guessed (XedDocumentOutputStream *stream); + +guint xed_document_output_stream_get_num_fallbacks (XedDocumentOutputStream *stream); + G_END_DECLS #endif /* __XED_DOCUMENT_OUTPUT_STREAM_H__ */ diff --git a/xed/xed-smart-charset-converter.c b/xed/xed-smart-charset-converter.c deleted file mode 100644 index 33b02f1..0000000 --- a/xed/xed-smart-charset-converter.c +++ /dev/null @@ -1,422 +0,0 @@ -/* - * xed-smart-charset-converter.c - * This file is part of xed - * - * Copyright (C) 2009 - Ignacio Casal Quinteiro - * - * xed is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xed is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with xed; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301 USA - */ - -#include "xed-smart-charset-converter.h" -#include "xed-debug.h" -#include "xed-document.h" - -#include -#include - -#define XED_SMART_CHARSET_CONVERTER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), XED_TYPE_SMART_CHARSET_CONVERTER, XedSmartCharsetConverterPrivate)) - -struct _XedSmartCharsetConverterPrivate -{ - GCharsetConverter *charset_conv; - - GSList *encodings; - GSList *current_encoding; - - guint is_utf8 : 1; - guint use_first : 1; -}; - -static void xed_smart_charset_converter_iface_init (GConverterIface *iface); - -G_DEFINE_TYPE_WITH_CODE (XedSmartCharsetConverter, xed_smart_charset_converter, - G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (G_TYPE_CONVERTER, - xed_smart_charset_converter_iface_init)) - -static void -xed_smart_charset_converter_finalize (GObject *object) -{ - XedSmartCharsetConverter *smart = XED_SMART_CHARSET_CONVERTER (object); - - g_slist_free (smart->priv->encodings); - - xed_debug_message (DEBUG_UTILS, "finalizing smart charset converter"); - - G_OBJECT_CLASS (xed_smart_charset_converter_parent_class)->finalize (object); -} - -static void -xed_smart_charset_converter_dispose (GObject *object) -{ - XedSmartCharsetConverter *smart = XED_SMART_CHARSET_CONVERTER (object); - - if (smart->priv->charset_conv != NULL) - { - g_object_unref (smart->priv->charset_conv); - smart->priv->charset_conv = NULL; - } - - xed_debug_message (DEBUG_UTILS, "disposing smart charset converter"); - - G_OBJECT_CLASS (xed_smart_charset_converter_parent_class)->dispose (object); -} - -static void -xed_smart_charset_converter_class_init (XedSmartCharsetConverterClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = xed_smart_charset_converter_finalize; - object_class->dispose = xed_smart_charset_converter_dispose; - - g_type_class_add_private (object_class, sizeof (XedSmartCharsetConverterPrivate)); -} - -static void -xed_smart_charset_converter_init (XedSmartCharsetConverter *smart) -{ - smart->priv = XED_SMART_CHARSET_CONVERTER_GET_PRIVATE (smart); - - smart->priv->charset_conv = NULL; - smart->priv->encodings = NULL; - smart->priv->current_encoding = NULL; - smart->priv->is_utf8 = FALSE; - smart->priv->use_first = FALSE; - - xed_debug_message (DEBUG_UTILS, "initializing smart charset converter"); -} - -static const XedEncoding * -get_encoding (XedSmartCharsetConverter *smart) -{ - if (smart->priv->current_encoding == NULL) - { - smart->priv->current_encoding = smart->priv->encodings; - } - else - { - smart->priv->current_encoding = g_slist_next (smart->priv->current_encoding); - } - - if (smart->priv->current_encoding != NULL) - return (const XedEncoding *)smart->priv->current_encoding->data; - -#if 0 - FIXME: uncomment this when using fallback - /* If we tried all encodings, we return the first encoding */ - smart->priv->use_first = TRUE; - smart->priv->current_encoding = smart->priv->encodings; - - return (const XedEncoding *)smart->priv->current_encoding->data; -#endif - return NULL; -} - -static gboolean -try_convert (GCharsetConverter *converter, - const void *inbuf, - gsize inbuf_size) -{ - GError *err; - gsize bytes_read, nread; - gsize bytes_written, nwritten; - GConverterResult res; - gchar *out; - gboolean ret; - gsize out_size; - - if (inbuf == NULL || inbuf_size == 0) - { - return FALSE; - } - - err = NULL; - nread = 0; - nwritten = 0; - out_size = inbuf_size * 4; - out = g_malloc (out_size); - - do - { - res = g_converter_convert (G_CONVERTER (converter), - (void *) ((gsize) inbuf + nread), - inbuf_size - nread, - out + nwritten, - out_size - nwritten, - G_CONVERTER_INPUT_AT_END, - &bytes_read, - &bytes_written, - &err); - - nread += bytes_read; - nwritten += bytes_written; - } while (res != G_CONVERTER_FINISHED && res != G_CONVERTER_ERROR && err == NULL); - - if (err != NULL) - { - if (err->code == G_CONVERT_ERROR_PARTIAL_INPUT) - { - /* FIXME We can get partial input while guessing the - encoding because we just take some amount of text - to guess from. */ - ret = TRUE; - } - else - { - ret = FALSE; - } - - g_error_free (err); - } - else - { - ret = TRUE; - } - - /* FIXME: Check the remainder? */ - if (ret == TRUE && !g_utf8_validate (out, nwritten, NULL)) - { - ret = FALSE; - } - - g_free (out); - - return ret; -} - -static GCharsetConverter * -guess_encoding (XedSmartCharsetConverter *smart, - const void *inbuf, - gsize inbuf_size) -{ - GCharsetConverter *conv = NULL; - - if (inbuf == NULL || inbuf_size == 0) - { - smart->priv->is_utf8 = TRUE; - return NULL; - } - - if (smart->priv->encodings != NULL && - smart->priv->encodings->next == NULL) - smart->priv->use_first = TRUE; - - /* We just check the first block */ - while (TRUE) - { - const XedEncoding *enc; - - if (conv != NULL) - { - g_object_unref (conv); - conv = NULL; - } - - /* We get an encoding from the list */ - enc = get_encoding (smart); - - /* if it is NULL we didn't guess anything */ - if (enc == NULL) - { - break; - } - - xed_debug_message (DEBUG_UTILS, "trying charset: %s", - xed_encoding_get_charset (smart->priv->current_encoding->data)); - - if (enc == xed_encoding_get_utf8 ()) - { - gsize remainder; - const gchar *end; - - if (g_utf8_validate (inbuf, inbuf_size, &end) || - smart->priv->use_first) - { - smart->priv->is_utf8 = TRUE; - break; - } - - /* Check if the end is less than one char */ - remainder = inbuf_size - (end - (gchar *)inbuf); - if (remainder < 6) - { - smart->priv->is_utf8 = TRUE; - break; - } - - continue; - } - - conv = g_charset_converter_new ("UTF-8", - xed_encoding_get_charset (enc), - NULL); - - /* If we tried all encodings we use the first one */ - if (smart->priv->use_first) - { - break; - } - - /* Try to convert */ - if (try_convert (conv, inbuf, inbuf_size)) - { - break; - } - } - - if (conv != NULL) - { - g_converter_reset (G_CONVERTER (conv)); - - /* FIXME: uncomment this when we want to use the fallback - g_charset_converter_set_use_fallback (conv, TRUE);*/ - } - - return conv; -} - -static GConverterResult -xed_smart_charset_converter_convert (GConverter *converter, - const void *inbuf, - gsize inbuf_size, - void *outbuf, - gsize outbuf_size, - GConverterFlags flags, - gsize *bytes_read, - gsize *bytes_written, - GError **error) -{ - XedSmartCharsetConverter *smart = XED_SMART_CHARSET_CONVERTER (converter); - - /* Guess the encoding if we didn't make it yet */ - if (smart->priv->charset_conv == NULL && - !smart->priv->is_utf8) - { - smart->priv->charset_conv = guess_encoding (smart, inbuf, inbuf_size); - - /* If we still have the previous case is that we didn't guess - anything */ - if (smart->priv->charset_conv == NULL && - !smart->priv->is_utf8) - { - /* FIXME: Add a different domain when we kill xed_convert */ - g_set_error_literal (error, XED_DOCUMENT_ERROR, - XED_DOCUMENT_ERROR_ENCODING_AUTO_DETECTION_FAILED, - _("It is not possible to detect the encoding automatically")); - return G_CONVERTER_ERROR; - } - } - - /* Now if the encoding is utf8 just redirect the input to the output */ - if (smart->priv->is_utf8) - { - gsize size; - GConverterResult ret; - - size = MIN (inbuf_size, outbuf_size); - - memcpy (outbuf, inbuf, size); - *bytes_read = size; - *bytes_written = size; - - ret = G_CONVERTER_CONVERTED; - - if (flags & G_CONVERTER_INPUT_AT_END) - ret = G_CONVERTER_FINISHED; - else if (flags & G_CONVERTER_FLUSH) - ret = G_CONVERTER_FLUSHED; - - return ret; - } - - /* If we reached here is because we need to convert the text so, we - convert it with the charset converter */ - return g_converter_convert (G_CONVERTER (smart->priv->charset_conv), - inbuf, - inbuf_size, - outbuf, - outbuf_size, - flags, - bytes_read, - bytes_written, - error); -} - -static void -xed_smart_charset_converter_reset (GConverter *converter) -{ - XedSmartCharsetConverter *smart = XED_SMART_CHARSET_CONVERTER (converter); - - smart->priv->current_encoding = NULL; - smart->priv->is_utf8 = FALSE; - - if (smart->priv->charset_conv != NULL) - { - g_object_unref (smart->priv->charset_conv); - smart->priv->charset_conv = NULL; - } -} - -static void -xed_smart_charset_converter_iface_init (GConverterIface *iface) -{ - iface->convert = xed_smart_charset_converter_convert; - iface->reset = xed_smart_charset_converter_reset; -} - -XedSmartCharsetConverter * -xed_smart_charset_converter_new (GSList *candidate_encodings) -{ - XedSmartCharsetConverter *smart; - - g_return_val_if_fail (candidate_encodings != NULL, NULL); - - smart = g_object_new (XED_TYPE_SMART_CHARSET_CONVERTER, NULL); - - smart->priv->encodings = g_slist_copy (candidate_encodings); - - return smart; -} - -const XedEncoding * -xed_smart_charset_converter_get_guessed (XedSmartCharsetConverter *smart) -{ - g_return_val_if_fail (XED_IS_SMART_CHARSET_CONVERTER (smart), NULL); - - if (smart->priv->current_encoding != NULL) - { - return (const XedEncoding *)smart->priv->current_encoding->data; - } - else if (smart->priv->is_utf8) - { - return xed_encoding_get_utf8 (); - } - - return NULL; -} - -guint -xed_smart_charset_converter_get_num_fallbacks (XedSmartCharsetConverter *smart) -{ - g_return_val_if_fail (XED_IS_SMART_CHARSET_CONVERTER (smart), FALSE); - - if (smart->priv->charset_conv == NULL) - return FALSE; - - return g_charset_converter_get_num_fallbacks (smart->priv->charset_conv) != 0; -} - diff --git a/xed/xed-smart-charset-converter.h b/xed/xed-smart-charset-converter.h deleted file mode 100644 index 3239879..0000000 --- a/xed/xed-smart-charset-converter.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * xed-smart-charset-converter.h - * This file is part of xed - * - * Copyright (C) 2009 - Ignacio Casal Quinteiro - * - * xed is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xed is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with xed; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301 USA - */ - -#ifndef __XED_SMART_CHARSET_CONVERTER_H__ -#define __XED_SMART_CHARSET_CONVERTER_H__ - -#include - -#include "xed-encodings.h" - -G_BEGIN_DECLS - -#define XED_TYPE_SMART_CHARSET_CONVERTER (xed_smart_charset_converter_get_type ()) -#define XED_SMART_CHARSET_CONVERTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_SMART_CHARSET_CONVERTER, XedSmartCharsetConverter)) -#define XED_SMART_CHARSET_CONVERTER_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_SMART_CHARSET_CONVERTER, XedSmartCharsetConverter const)) -#define XED_SMART_CHARSET_CONVERTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_SMART_CHARSET_CONVERTER, XedSmartCharsetConverterClass)) -#define XED_IS_SMART_CHARSET_CONVERTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_SMART_CHARSET_CONVERTER)) -#define XED_IS_SMART_CHARSET_CONVERTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_SMART_CHARSET_CONVERTER)) -#define XED_SMART_CHARSET_CONVERTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_SMART_CHARSET_CONVERTER, XedSmartCharsetConverterClass)) - -typedef struct _XedSmartCharsetConverter XedSmartCharsetConverter; -typedef struct _XedSmartCharsetConverterClass XedSmartCharsetConverterClass; -typedef struct _XedSmartCharsetConverterPrivate XedSmartCharsetConverterPrivate; - -struct _XedSmartCharsetConverter -{ - GObject parent; - - XedSmartCharsetConverterPrivate *priv; -}; - -struct _XedSmartCharsetConverterClass -{ - GObjectClass parent_class; -}; - -GType xed_smart_charset_converter_get_type (void) G_GNUC_CONST; - -XedSmartCharsetConverter *xed_smart_charset_converter_new (GSList *candidate_encodings); - -const XedEncoding *xed_smart_charset_converter_get_guessed (XedSmartCharsetConverter *smart); - -guint xed_smart_charset_converter_get_num_fallbacks(XedSmartCharsetConverter *smart); - -G_END_DECLS - -#endif /* __XED_SMART_CHARSET_CONVERTER_H__ */ From 176dac188b08e104f6860cd416e7e2a85939637f Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Thu, 19 Jan 2017 03:45:06 -0800 Subject: [PATCH 102/132] xed-document-output-stream: Factor out validate_and_insert method --- xed/xed-document-output-stream.c | 125 +++++++++++++++++++------------ 1 file changed, 79 insertions(+), 46 deletions(-) diff --git a/xed/xed-document-output-stream.c b/xed/xed-document-output-stream.c index ba11422..caabf7e 100644 --- a/xed/xed-document-output-stream.c +++ b/xed/xed-document-output-stream.c @@ -496,6 +496,65 @@ xed_document_output_stream_get_num_fallbacks (XedDocumentOutputStream *stream) return g_charset_converter_get_num_fallbacks (stream->priv->charset_conv) != 0; } +static gboolean +validate_and_insert (XedDocumentOutputStream *stream, + const gchar *buffer, + gsize count) +{ + const gchar *end; + gsize nvalid; + gboolean valid; + gsize len; + + len = count; + + /* validate */ + valid = g_utf8_validate (buffer, len, &end); + nvalid = end - buffer; + + if (!valid) + { + gsize remainder; + + remainder = len - nvalid; + + if ((remainder < MAX_UNICHAR_LEN) && (g_utf8_get_char_validated (buffer + nvalid, remainder) == (gunichar)-2)) + { + stream->priv->buffer = g_strndup (end, remainder); + stream->priv->buflen = remainder; + len -= remainder; + } + else + { + return FALSE; + } + } + else + { + gchar *ptr; + + /* Note: this is a workaround for a 'bug' in GtkTextBuffer where + inserting first a \r and then in a second insert, a \n, + will result in two lines being added instead of a single + one */ + + ptr = g_utf8_find_prev_char (buffer, buffer + len); + + if (ptr && *ptr == '\r' && ptr - buffer == len - 1) + { + stream->priv->buffer = g_new (gchar, 1); + stream->priv->buffer[0] = '\r'; + stream->priv->buflen = 1; + + --len; + } + } + + gtk_text_buffer_insert (GTK_TEXT_BUFFER (stream->priv->doc), &stream->priv->pos, buffer, len); + + return TRUE; +} + /* If the last char is a newline, remove it from the buffer (otherwise GtkTextView shows it as an empty line). See bug #324942. */ static void @@ -542,10 +601,10 @@ xed_document_output_stream_write (GOutputStream *stream, gchar *text; gsize len; gboolean freetext = FALSE; - const gchar *end; - gboolean valid; - gsize nvalid; - gsize remainder; + // const gchar *end; + // gboolean valid; + // gsize nvalid; + // gsize remainder; if (g_cancellable_set_error_if_cancelled (cancellable, error)) { @@ -654,19 +713,21 @@ xed_document_output_stream_write (GOutputStream *stream, /* If we reached here is because we need to convert the text so, we convert it with the charset converter */ conv_text = g_convert_with_iconv (text, - len, - ostream->priv->iconv, - &conv_read, - &conv_written, - &err); + len, + ostream->priv->iconv, + &conv_read, + &conv_written, + &err); if (freetext) { - g_free (text); + g_free (text); } if (err != NULL) { + gsize remainder; + remainder = len - conv_read; /* Store the partial char for the next conversion */ @@ -694,49 +755,21 @@ xed_document_output_stream_write (GOutputStream *stream, } - /* validate */ - valid = g_utf8_validate (text, len, &end); - nvalid = end - text; - - /* Avoid keeping a CRLF across two buffers. */ - if (valid && len > 1 && end[-1] == '\r') + if (!validate_and_insert (ostream, text, len)) { - valid = FALSE; - end--; - } + /* TODO: we could escape invalid text and tag it in red + * and make the doc readonly. + */ + g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, _("Invalid UTF-8 sequence in input")); - if (!valid) - { - // gsize nvalid = end - text; - remainder = len - nvalid; - gunichar ch; - - if ((remainder < MAX_UNICHAR_LEN) && - ((ch = g_utf8_get_char_validated (text + nvalid, remainder)) == (gunichar)-2 || - ch == (gunichar)'\r')) + if (freetext) { - ostream->priv->buffer = g_strndup (end, remainder); - ostream->priv->buflen = remainder; - len -= remainder; + g_free (text); } - else - { - /* TODO: we could escape invalid text and tag it in red - * and make the doc readonly. - */ - g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, _("Invalid UTF-8 sequence in input")); - if (freetext) - { - g_free (text); - } - - return -1; - } + return -1; } - gtk_text_buffer_insert (GTK_TEXT_BUFFER (ostream->priv->doc), &ostream->priv->pos, text, len); - if (freetext) { g_free (text); From 1d6f119b04efd6bd6b89a9d49baf2818104e2fee Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Fri, 20 Jan 2017 12:24:07 -0800 Subject: [PATCH 103/132] Pull some upstream changes from Gedit in prep for using more of the GtkSource* backend --- xed/Makefile.am | 4 +- xed/xed-commands-file.c | 10 +- xed/xed-document-loader.c | 25 +- xed/xed-document-output-stream.c | 226 +++++++++++----- xed/xed-document.c | 447 +++++++++++++++++++++---------- xed/xed-document.h | 15 +- xed/xed-io-error-message-area.c | 109 ++++++-- xed/xed-io-error-message-area.h | 2 + xed/xed-tab.c | 64 ++++- xed/xed-utils.c | 36 --- xed/xed-utils.h | 4 - xed/xed-window.c | 2 +- 12 files changed, 643 insertions(+), 301 deletions(-) diff --git a/xed/Makefile.am b/xed/Makefile.am index 0fb2d3b..0a68f0a 100644 --- a/xed/Makefile.am +++ b/xed/Makefile.am @@ -59,10 +59,12 @@ NOINST_H_FILES = \ xed-print-preview.h \ xed-session.h \ xed-settings.h \ + xed-status-combo-box.h \ xed-style-scheme-manager.h \ xed-tab-label.h \ xedtextregion.h \ xed-ui.h \ + xed-utils.h \ xed-view-frame.h \ xed-window-private.h @@ -84,9 +86,7 @@ INST_H_FILES = \ xed-progress-message-area.h \ xed-searchbar.h \ xed-statusbar.h \ - xed-status-combo-box.h \ xed-tab.h \ - xed-utils.h \ xed-view.h \ xed-view-activatable.h \ xed-window.h \ diff --git a/xed/xed-commands-file.c b/xed/xed-commands-file.c index 5948ceb..e069444 100644 --- a/xed/xed-commands-file.c +++ b/xed/xed-commands-file.c @@ -257,11 +257,13 @@ load_file_list (XedWindow *window, /** * xed_commands_load_location: * @window: - * @uri: + * @location: * @encoding: (allow-none): * @line_pos: * - * Do nothing if location does not exist + * Ignore non-existing locations + * + * Returns: (transfer container): */ void xed_commands_load_location (XedWindow *window, @@ -290,8 +292,8 @@ xed_commands_load_location (XedWindow *window, /** * xed_commands_load_locations: * @window: - * @uris: - * @encoding: + * @locations: (element-type GLib.File) (transfer none): + * @encoding: (allow-none): * @line_pos: * * Ignore non-existing locations diff --git a/xed/xed-document-loader.c b/xed/xed-document-loader.c index 3233adf..1b21d1b 100644 --- a/xed/xed-document-loader.c +++ b/xed/xed-document-loader.c @@ -437,6 +437,18 @@ close_input_stream_ready_cb (GInputStream *stream, return; } + /* Check if we needed some fallback char, if so, check if there was + a previous error and if not set a fallback used error */ + if ((xed_document_output_stream_get_num_fallbacks (XED_DOCUMENT_OUTPUT_STREAM (async->loader->priv->output)) != 0) && + async->loader->priv->error == NULL) + { + g_set_error_literal (&async->loader->priv->error, + XED_DOCUMENT_ERROR, + XED_DOCUMENT_ERROR_CONVERSION_FALLBACK, + "There was a conversion error and it was " + "needed to use a fallback char"); + } + remote_load_completed_or_failed (async->loader, async); } @@ -544,19 +556,6 @@ async_read_cb (GInputStream *stream, loader->priv->auto_detected_newline_type = xed_document_output_stream_detect_newline_type (XED_DOCUMENT_OUTPUT_STREAM (loader->priv->output)); - /* Check if we needed some fallback char, if so, check if there was - a previous error and if not set a fallback used error */ - /* FIXME Uncomment this when we want to manage conversion fallback */ - /*if ((xed_document_output_stream_get_num_fallbacks (XED_DOCUMENT_OUTPUT_STREAM (loader->priv->ouput)) != 0) && - loader->priv->error == NULL) - { - g_set_error_literal (&loader->priv->error, - XED_DOCUMENT_ERROR, - XED_DOCUMENT_ERROR_CONVERSION_FALLBACK, - "There was a conversion error and it was " - "needed to use a fallback char"); - }*/ - write_complete (async); return; diff --git a/xed/xed-document-output-stream.c b/xed/xed-document-output-stream.c index caabf7e..9f7488a 100644 --- a/xed/xed-document-output-stream.c +++ b/xed/xed-document-output-stream.c @@ -57,6 +57,9 @@ struct _XedDocumentOutputStreamPrivate GSList *encodings; GSList *current_encoding; + gint error_offset; + guint n_fallback_errors; + guint is_utf8 : 1; guint use_first : 1; @@ -175,6 +178,8 @@ xed_document_output_stream_constructed (GObject *object) gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->priv->doc), FALSE); gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (stream->priv->doc)); + + G_OBJECT_CLASS (xed_document_output_stream_parent_class)->constructed (object); } static void @@ -217,6 +222,8 @@ xed_document_output_stream_init (XedDocumentOutputStream *stream) stream->priv->encodings = NULL; stream->priv->current_encoding = NULL; + stream->priv->error_offset = -1; + stream->priv->is_initialized = FALSE; stream->priv->is_closed = FALSE; stream->priv->is_utf8 = FALSE; @@ -240,7 +247,10 @@ get_encoding (XedDocumentOutputStream *stream) return (const XedEncoding *)stream->priv->current_encoding->data; } - return NULL; + stream->priv->use_first = TRUE; + stream->priv->current_encoding = stream->priv->encodings; + + return (const XedEncoding *)stream->priv->current_encoding->data; } static gboolean @@ -486,73 +496,131 @@ xed_document_output_stream_get_guessed (XedDocumentOutputStream *stream) guint xed_document_output_stream_get_num_fallbacks (XedDocumentOutputStream *stream) { - g_return_val_if_fail (XED_IS_DOCUMENT_OUTPUT_STREAM (stream), FALSE); + g_return_val_if_fail (XED_IS_DOCUMENT_OUTPUT_STREAM (stream), 0); - if (stream->priv->charset_conv == NULL) - { - return FALSE; - } - - return g_charset_converter_get_num_fallbacks (stream->priv->charset_conv) != 0; + return stream->priv->n_fallback_errors; } -static gboolean +static void +apply_error_tag (XedDocumentOutputStream *stream) +{ + GtkTextIter start; + + if (stream->priv->error_offset == -1) + { + return; + } + + gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (stream->priv->doc), &start, stream->priv->error_offset); + + _xed_document_apply_error_style (stream->priv->doc, &start, &stream->priv->pos); + + stream->priv->error_offset = -1; +} + +static void +insert_fallback (XedDocumentOutputStream *stream, + const gchar *buffer) +{ + guint8 out[4]; + guint8 v; + const gchar hex[] = "0123456789ABCDEF"; + + /* if we are here is because we are pointing to an invalid char + * so we substitute it by an hex value */ + v = *(guint8 *)buffer; + out[0] = '\\'; + out[1] = hex[(v & 0xf0) >> 4]; + out[2] = hex[(v & 0x0f) >> 0]; + out[3] = '\0'; + + gtk_text_buffer_insert (GTK_TEXT_BUFFER (stream->priv->doc), &stream->priv->pos, (const gchar *)out, 3); + + stream->priv->n_fallback_errors++; +} + +static void validate_and_insert (XedDocumentOutputStream *stream, const gchar *buffer, gsize count) { - const gchar *end; - gsize nvalid; - gboolean valid; + GtkTextBuffer *text_buffer; + GtkTextIter *iter; gsize len; + text_buffer = GTK_TEXT_BUFFER (stream->priv->doc); + iter = &stream->priv->pos; len = count; - /* validate */ - valid = g_utf8_validate (buffer, len, &end); - nvalid = end - buffer; - - if (!valid) + while (len != 0) { - gsize remainder; + const gchar *end; + gboolean valid; + gsize nvalid; - remainder = len - nvalid; - - if ((remainder < MAX_UNICHAR_LEN) && (g_utf8_get_char_validated (buffer + nvalid, remainder) == (gunichar)-2)) - { - stream->priv->buffer = g_strndup (end, remainder); - stream->priv->buflen = remainder; - len -= remainder; - } - else - { - return FALSE; - } - } - else - { - gchar *ptr; + /* validate */ + valid = g_utf8_validate (buffer, len, &end); + nvalid = end - buffer; /* Note: this is a workaround for a 'bug' in GtkTextBuffer where - inserting first a \r and then in a second insert, a \n, - will result in two lines being added instead of a single - one */ + inserting first a \r and then in a second insert, a \n, + will result in two lines being added instead of a single + one */ - ptr = g_utf8_find_prev_char (buffer, buffer + len); - - if (ptr && *ptr == '\r' && ptr - buffer == len - 1) + if (valid) { - stream->priv->buffer = g_new (gchar, 1); - stream->priv->buffer[0] = '\r'; - stream->priv->buflen = 1; + gchar *ptr; - --len; + ptr = g_utf8_find_prev_char (buffer, buffer + len); + + if (ptr && *ptr == '\r' && ptr - buffer == len - 1) + { + stream->priv->buffer = g_new (gchar, 1); + stream->priv->buffer[0] = '\r'; + stream->priv->buflen = 1; + + /* Decrease also the len so in the check + nvalid == len we get out of this method */ + --nvalid; + --len; + } } + + /* if we've got any valid char we must tag the invalid chars */ + if (nvalid > 0) + { + apply_error_tag (stream); + } + + gtk_text_buffer_insert (text_buffer, iter, buffer, nvalid); + + /* If we inserted all return */ + if (nvalid == len) + { + break; + } + + buffer += nvalid; + len = len - nvalid; + + if ((len < MAX_UNICHAR_LEN) && (g_utf8_get_char_validated (buffer, len) == (gunichar)-2)) + { + stream->priv->buffer = g_strndup (end, len); + stream->priv->buflen = len; + + break; + } + + /* we need the start of the chunk of invalid chars */ + if (stream->priv->error_offset == -1) + { + stream->priv->error_offset = gtk_text_iter_get_offset (&stream->priv->pos); + } + + insert_fallback (stream, buffer); + buffer++; + len--; } - - gtk_text_buffer_insert (GTK_TEXT_BUFFER (stream->priv->doc), &stream->priv->pos, buffer, len); - - return TRUE; } /* If the last char is a newline, remove it from the buffer (otherwise @@ -755,20 +823,7 @@ xed_document_output_stream_write (GOutputStream *stream, } - if (!validate_and_insert (ostream, text, len)) - { - /* TODO: we could escape invalid text and tag it in red - * and make the doc readonly. - */ - g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, _("Invalid UTF-8 sequence in input")); - - if (freetext) - { - g_free (text); - } - - return -1; - } + validate_and_insert (ostream, text, len); if (freetext) { @@ -785,14 +840,51 @@ xed_document_output_stream_flush (GOutputStream *stream, { XedDocumentOutputStream *ostream = XED_DOCUMENT_OUTPUT_STREAM (stream); - /* Flush deferred data if some. */ - if (!ostream->priv->is_closed && ostream->priv->is_initialized && - ostream->priv->buflen > 0 && - xed_document_output_stream_write (stream, "", 0, cancellable, error) == -1) + if (ostream->priv->is_closed) { - return FALSE; + return TRUE; } + if (ostream->priv->buflen > 0 && *ostream->priv->buffer != '\r') + { + /* If we reached here is because the last insertion was a half + correct char, which has to be inserted as fallback */ + gchar *text; + + if (ostream->priv->error_offset == -1) + { + ostream->priv->error_offset = gtk_text_iter_get_offset (&ostream->priv->pos); + } + + text = ostream->priv->buffer; + while (ostream->priv->buflen != 0) + { + insert_fallback (ostream, text); + text++; + ostream->priv->buflen--; + } + + g_free (ostream->priv->buffer); + ostream->priv->buffer = NULL; + } + else if (ostream->priv->buflen == 1 && *ostream->priv->buffer == '\r') + { + /* The previous chars can be invalid */ + apply_error_tag (ostream); + + /* See special case above, flush this */ + gtk_text_buffer_insert (GTK_TEXT_BUFFER (ostream->priv->doc), + &ostream->priv->pos, + "\r", + 1); + + g_free (ostream->priv->buffer); + ostream->priv->buffer = NULL; + ostream->priv->buflen = 0; + } + + apply_error_tag (ostream); + return TRUE; } diff --git a/xed/xed-document.c b/xed/xed-document.c index 371fa9e..ec0942e 100644 --- a/xed/xed-document.c +++ b/xed/xed-document.c @@ -88,9 +88,6 @@ static void xed_document_save_real (XedDocument *doc, GFile *location, const XedEncoding *encoding, XedDocumentSaveFlags flags); -static void to_search_region_range (XedDocument *doc, - GtkTextIter *start, - GtkTextIter *end); static void insert_text_cb (XedDocument *doc, GtkTextIter *pos, const gchar *text, @@ -138,15 +135,17 @@ struct _XedDocumentPrivate XedTextRegion *to_search_region; GtkTextTag *found_tag; + GtkTextTag *error_tag; + /* Mount operation factory */ XedMountOperationFactory mount_operation_factory; gpointer mount_operation_userdata; - gint readonly : 1; - gint last_save_was_manually : 1; - gint language_set_by_user : 1; - gint stop_cursor_moved_emission : 1; - gint dispose_has_run : 1; + guint readonly : 1; + guint last_save_was_manually : 1; + guint language_set_by_user : 1; + guint stop_cursor_moved_emission : 1; + guint dispose_has_run : 1; }; enum @@ -281,25 +280,10 @@ xed_document_dispose (GObject *object) g_free (position); } - if (doc->priv->loader) - { - g_object_unref (doc->priv->loader); - doc->priv->loader = NULL; - } - + g_clear_object (&doc->priv->loader); g_clear_object (&doc->priv->editor_settings); - - if (doc->priv->metadata_info != NULL) - { - g_object_unref (doc->priv->metadata_info); - doc->priv->metadata_info = NULL; - } - - if (doc->priv->location != NULL) - { - g_object_unref (doc->priv->location); - doc->priv->location = NULL; - } + g_clear_object (&doc->priv->metadata_info); + g_clear_object (&doc->priv->location); doc->priv->dispose_has_run = TRUE; @@ -383,18 +367,31 @@ xed_document_set_property (GObject *object, switch (prop_id) { - case PROP_ENABLE_SEARCH_HIGHLIGHTING: - xed_document_set_enable_search_highlighting (doc, g_value_get_boolean (value)); - break; - case PROP_NEWLINE_TYPE: - xed_document_set_newline_type (doc, g_value_get_enum (value)); + case PROP_LOCATION: + { + GFile *location; + + location = g_value_get_object (value); + + if (location != NULL) + { + xed_document_set_location (doc, location); + } + break; + } case PROP_SHORTNAME: xed_document_set_short_name_for_display (doc, g_value_get_string (value)); break; case PROP_CONTENT_TYPE: xed_document_set_content_type (doc, g_value_get_string (value)); break; + case PROP_ENABLE_SEARCH_HIGHLIGHTING: + xed_document_set_enable_search_highlighting (doc, g_value_get_boolean (value)); + break; + case PROP_NEWLINE_TYPE: + xed_document_set_newline_type (doc, g_value_get_enum (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -455,10 +452,10 @@ xed_document_class_init (XedDocumentClass *klass) g_object_class_install_property (object_class, PROP_LOCATION, g_param_spec_object ("location", - "LOCATION", + "Location", "The document's location", G_TYPE_FILE, - G_PARAM_READABLE | + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_SHORTNAME, @@ -647,7 +644,7 @@ xed_document_class_init (XedDocumentClass *klass) G_TYPE_POINTER); document_signals[SEARCH_HIGHLIGHT_UPDATED] = - g_signal_new ("search_highlight_updated", + g_signal_new ("search-highlight-updated", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (XedDocumentClass, search_highlight_updated), @@ -658,7 +655,7 @@ xed_document_class_init (XedDocumentClass *klass) GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE, GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE); - g_type_class_add_private (object_class, sizeof(XedDocumentPrivate)); + g_type_class_add_private (object_class, sizeof (XedDocumentPrivate)); } static void @@ -1097,7 +1094,7 @@ xed_document_get_uri_for_display (XedDocument *doc) } else { - return xed_utils_uri_for_display (doc->priv->location); + return g_file_get_parse_name (doc->priv->location); } } @@ -1193,9 +1190,9 @@ set_readonly (XedDocument *doc, } /** - * xed_document_set_readonly: + * _xed_document_set_readonly: * @doc: a #XedDocument - * @readonly: %TRUE to se the document as read-only + * @readonly: %TRUE to set the document as read-only * * If @readonly is %TRUE sets @doc as read-only. */ @@ -1484,6 +1481,34 @@ xed_document_load_cancel (XedDocument *doc) return xed_document_loader_cancel (doc->priv->loader); } +static gboolean +has_invalid_chars (XedDocument *doc) +{ + GtkTextBuffer *buffer; + GtkTextIter start; + + g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); + + xed_debug (DEBUG_DOCUMENT); + + if (doc->priv->error_tag == NULL) + { + return FALSE; + } + + buffer = GTK_TEXT_BUFFER (doc); + + gtk_text_buffer_get_start_iter (buffer, &start); + + if (gtk_text_iter_begins_tag (&start, doc->priv->error_tag) || + gtk_text_iter_forward_to_tag_toggle (&start, doc->priv->error_tag)) + { + return TRUE; + } + + return FALSE; +} + static void document_saver_saving (XedDocumentSaver *saver, gboolean completed, @@ -1559,14 +1584,28 @@ xed_document_save_real (XedDocument *doc, { g_return_if_fail (doc->priv->saver == NULL); - /* create a saver, it will be destroyed once saving is complete */ - doc->priv->saver = xed_document_saver_new (doc, location, encoding, doc->priv->newline_type, flags); + if (!(flags & XED_DOCUMENT_SAVE_IGNORE_INVALID_CHARS) && has_invalid_chars (doc)) + { + GError *error = NULL; - g_signal_connect (doc->priv->saver, "saving", G_CALLBACK (document_saver_saving), doc); + g_set_error_literal (&error, + XED_DOCUMENT_ERROR, + XED_DOCUMENT_ERROR_CONVERSION_FALLBACK, + "The document contains invalid characters"); - doc->priv->requested_encoding = encoding; + g_signal_emit (doc, document_signals[SAVED], 0, error); + } + else + { + /* create a saver, it will be destroyed once saving is complete */ + doc->priv->saver = xed_document_saver_new (doc, location, encoding, doc->priv->newline_type, flags); - xed_document_saver_save (doc->priv->saver, &doc->priv->mtime); + g_signal_connect (doc->priv->saver, "saving", G_CALLBACK (document_saver_saving), doc); + + doc->priv->requested_encoding = encoding; + + xed_document_saver_save (doc->priv->saver, &doc->priv->mtime); + } } /** @@ -1603,13 +1642,23 @@ xed_document_save_as (XedDocument *doc, const XedEncoding *encoding, XedDocumentSaveFlags flags) { + GError *error; + g_return_if_fail (XED_IS_DOCUMENT (doc)); g_return_if_fail (G_IS_FILE (location)); g_return_if_fail (encoding != NULL); + if (has_invalid_chars (doc)) + { + g_set_error_literal (&error, + XED_DOCUMENT_ERROR, + XED_DOCUMENT_ERROR_CONVERSION_FALLBACK, + "The document contains invalid chars"); + } + /* priv->mtime refers to the the old location (if any). Thus, it should be * ignored when saving as. */ - g_signal_emit (doc, document_signals[SAVE], 0, location, encoding, flags | XED_DOCUMENT_SAVE_IGNORE_MTIME); + g_signal_emit (doc, document_signals[SAVE], 0, location, encoding, flags | XED_DOCUMENT_SAVE_IGNORE_MTIME, error); } gboolean @@ -1647,7 +1696,7 @@ xed_document_get_deleted (XedDocument *doc) g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); /* This is done sync, maybe we should do it async? */ - return doc->priv->location && !xed_utils_location_exists (doc->priv->location); + return doc->priv->location && !g_file_query_exists (doc->priv->location, NULL); } /* @@ -1743,6 +1792,36 @@ compute_num_of_lines (const gchar *text) return n; } +static void +to_search_region_range (XedDocument *doc, + GtkTextIter *start, + GtkTextIter *end) +{ + xed_debug (DEBUG_DOCUMENT); + + if (doc->priv->to_search_region == NULL) + { + return; + } + + gtk_text_iter_set_line_offset (start, 0); + gtk_text_iter_forward_to_line_end (end); + + /* + g_print ("+ [%u (%u), %u (%u)]\n", gtk_text_iter_get_line (start), gtk_text_iter_get_offset (start), + gtk_text_iter_get_line (end), gtk_text_iter_get_offset (end)); + */ + + /* Add the region to the refresh region */ + xed_text_region_add (doc->priv->to_search_region, start, end); + + /* Notify views of the updated highlight region */ + gtk_text_iter_backward_lines (start, doc->priv->num_of_lines_search_text); + gtk_text_iter_forward_lines (end, doc->priv->num_of_lines_search_text); + + g_signal_emit (doc, document_signals [SEARCH_HIGHLIGHT_UPDATED], 0, start, end); +} + /** * xed_document_set_search_text: * @doc: @@ -1868,7 +1947,9 @@ xed_document_search_forward (XedDocument *doc, return FALSE; } else + { xed_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == \"%s\"\n", doc->priv->search_text); + } if (start == NULL) { @@ -2124,65 +2205,27 @@ xed_document_replace_all (XedDocument *doc, return cont; } -/** - * xed_document_set_language: - * @doc: - * @lang: (allow-none): - **/ -void -xed_document_set_language (XedDocument *doc, - GtkSourceLanguage *lang) -{ - g_return_if_fail (XED_IS_DOCUMENT (doc)); - - set_language (doc, lang, TRUE); -} - -/** - * xed_document_get_language: - * @doc: - * - * Return value: (transfer none): - */ -GtkSourceLanguage * -xed_document_get_language (XedDocument *doc) -{ - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - - return gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (doc)); -} - -const XedEncoding * -xed_document_get_encoding (XedDocument *doc) -{ - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - - return doc->priv->encoding; -} - -glong -_xed_document_get_seconds_since_last_save_or_load (XedDocument *doc) -{ - GTimeVal current_time; - - xed_debug (DEBUG_DOCUMENT); - - g_return_val_if_fail (XED_IS_DOCUMENT (doc), -1); - - g_get_current_time (¤t_time); - - return (current_time.tv_sec - doc->priv->time_of_last_save_or_load.tv_sec); -} - static void -get_search_match_colors (XedDocument *doc, - gboolean *foreground_set, - GdkRGBA *foreground, - gboolean *background_set, - GdkRGBA *background) +get_style_colors (XedDocument *doc, + const gchar *style_name, + gboolean *foreground_set, + GdkRGBA *foreground, + gboolean *background_set, + GdkRGBA *background, + gboolean *line_background_set, + GdkRGBA *line_background, + gboolean *bold_set, + gboolean *bold, + gboolean *italic_set, + gboolean *italic, + gboolean *underline_set, + gboolean *underline, + gboolean *strikethrough_set, + gboolean *strikethrough) { GtkSourceStyleScheme *style_scheme; GtkSourceStyle *style; + gchar *line_bg; gchar *bg; gchar *fg; @@ -2192,7 +2235,7 @@ get_search_match_colors (XedDocument *doc, goto fallback; } - style = gtk_source_style_scheme_get_style (style_scheme, "search-match"); + style = gtk_source_style_scheme_get_style (style_scheme, style_name); if (style == NULL) { goto fallback; @@ -2203,6 +2246,16 @@ get_search_match_colors (XedDocument *doc, "foreground", &fg, "background-set", background_set, "background", &bg, + "line-background-set", line_background_set, + "line-background", &line_bg, + "bold-set", bold_set, + "bold", bold, + "italic-set", italic_set, + "italic", italic, + "underline-set", underline_set, + "underline", underline, + "strikethrough-set", strikethrough_set, + "strikethrough", strikethrough, NULL); if (*foreground_set) @@ -2221,8 +2274,17 @@ get_search_match_colors (XedDocument *doc, } } + if (*line_background_set) + { + if (line_bg == NULL || !gdk_rgba_parse (background, line_bg)) + { + *line_background_set = FALSE; + } + } + g_free (fg); g_free (bg); + g_free (line_bg); return; @@ -2238,24 +2300,61 @@ get_search_match_colors (XedDocument *doc, return; } +static void +sync_tag_style (XedDocument *doc, + GtkTextTag *tag, + const gchar *style_name) +{ + GdkRGBA fg; + GdkRGBA bg; + GdkRGBA line_bg; + gboolean fg_set; + gboolean bg_set; + gboolean line_bg_set; + gboolean bold; + gboolean italic; + gboolean underline; + gboolean strikethrough; + gboolean bold_set; + gboolean italic_set; + gboolean underline_set; + gboolean strikethrough_set; + + xed_debug (DEBUG_DOCUMENT); + + g_return_if_fail (tag != NULL); + + get_style_colors (doc, + style_name, + &fg_set, &fg, + &bg_set, &bg, + &line_bg_set, &line_bg, + &bold_set, &bold, + &italic_set, &italic, + &underline_set, &underline, + &strikethrough_set, &strikethrough); + + g_object_freeze_notify (G_OBJECT (tag)); + + g_object_set (tag, + "foreground-rgba", fg_set ? &fg : NULL, + "background-rgba", bg_set ? &bg : NULL, + "paragraph-background-rgba", line_bg_set ? &line_bg : NULL, + "weight", bold_set && bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL, + "style", italic_set && italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL, + "underline", underline_set && underline ? PANGO_UNDERLINE_SINGLE : PANGO_UNDERLINE_NONE, + "strikethrough", strikethrough_set && strikethrough, + NULL); + + g_object_thaw_notify (G_OBJECT (tag)); +} + static void sync_found_tag (XedDocument *doc, GParamSpec *pspec, gpointer data) { - GdkRGBA fg; - GdkRGBA bg; - gboolean fg_set; - gboolean bg_set; - - xed_debug (DEBUG_DOCUMENT); - - g_return_if_fail (GTK_TEXT_TAG (doc->priv->found_tag)); - - get_search_match_colors (doc, &fg_set, &fg, &bg_set, &bg); - - g_object_set (doc->priv->found_tag, "foreground-rgba", fg_set ? &fg : NULL, NULL); - g_object_set (doc->priv->found_tag, "background-rgba", bg_set ? &bg : NULL, NULL); + sync_tag_style (doc, doc->priv->found_tag, "search-match"); } static void @@ -2378,36 +2477,6 @@ search_region (XedDocument *doc, } while (found); } -static void -to_search_region_range (XedDocument *doc, - GtkTextIter *start, - GtkTextIter *end) -{ - xed_debug (DEBUG_DOCUMENT); - - if (doc->priv->to_search_region == NULL) - { - return; - } - - gtk_text_iter_set_line_offset (start, 0); - gtk_text_iter_forward_to_line_end (end); - - /* - g_print ("+ [%u (%u), %u (%u)]\n", gtk_text_iter_get_line (start), gtk_text_iter_get_offset (start), - gtk_text_iter_get_line (end), gtk_text_iter_get_offset (end)); - */ - - /* Add the region to the refresh region */ - xed_text_region_add (doc->priv->to_search_region, start, end); - - /* Notify views of the updated highlight region */ - gtk_text_iter_backward_lines (start, doc->priv->num_of_lines_search_text); - gtk_text_iter_forward_lines (end, doc->priv->num_of_lines_search_text); - - g_signal_emit (doc, document_signals [SEARCH_HIGHLIGHT_UPDATED], 0, start, end); -} - void _xed_document_search_region (XedDocument *doc, const GtkTextIter *start, @@ -2494,6 +2563,56 @@ delete_range_cb (XedDocument *doc, to_search_region_range (doc, &d_start, &d_end); } +/** + * xed_document_set_language: + * @doc: + * @lang: (allow-none): + **/ +void +xed_document_set_language (XedDocument *doc, + GtkSourceLanguage *lang) +{ + g_return_if_fail (XED_IS_DOCUMENT (doc)); + + set_language (doc, lang, TRUE); +} + +/** + * xed_document_get_language: + * @doc: + * + * Return value: (transfer none): + */ +GtkSourceLanguage * +xed_document_get_language (XedDocument *doc) +{ + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + + return gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (doc)); +} + +const XedEncoding * +xed_document_get_encoding (XedDocument *doc) +{ + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + + return doc->priv->encoding; +} + +glong +_xed_document_get_seconds_since_last_save_or_load (XedDocument *doc) +{ + GTimeVal current_time; + + xed_debug (DEBUG_DOCUMENT); + + g_return_val_if_fail (XED_IS_DOCUMENT (doc), -1); + + g_get_current_time (¤t_time); + + return (current_time.tv_sec - doc->priv->time_of_last_save_or_load.tv_sec); +} + void xed_document_set_enable_search_highlighting (XedDocument *doc, gboolean enable) @@ -2598,7 +2717,7 @@ gchar * xed_document_get_metadata (XedDocument *doc, const gchar *key) { - gchar *uri; + gchar *value = NULL; g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); g_return_val_if_fail (key != NULL, NULL); @@ -2637,7 +2756,7 @@ xed_document_set_metadata (XedDocument *doc, if (doc->priv->location != NULL) { - xed_metadata_manager_set (doc->priv->uri, key, value); + xed_metadata_manager_set (doc->priv->location, key, value); } } @@ -2747,3 +2866,39 @@ xed_document_set_metadata (XedDocument *doc, g_object_unref (info); } #endif + +static void +sync_error_tag (XedDocument *doc, + GParamSpec *pspec, + gpointer data) +{ + sync_tag_style (doc, doc->priv->error_tag, "def:error"); +} + +void +_xed_document_apply_error_style (XedDocument *doc, + GtkTextIter *start, + GtkTextIter *end) +{ + GtkTextBuffer *buffer; + + xed_debug (DEBUG_DOCUMENT); + + buffer = GTK_TEXT_BUFFER (doc); + + if (doc->priv->error_tag == NULL) + { + doc->priv->error_tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (doc), "error-style", NULL); + + sync_error_tag (doc, NULL, NULL); + + g_signal_connect (doc, "notify::style-scheme", + G_CALLBACK (sync_error_tag), NULL); + } + + /* make sure the 'error' tag has the priority over + * syntax highlighting tags */ + text_tag_set_highest_priority (doc->priv->error_tag, GTK_TEXT_BUFFER (doc)); + + gtk_text_buffer_apply_tag (buffer, doc->priv->error_tag, start, end); +} diff --git a/xed/xed-document.h b/xed/xed-document.h index ae9d6ef..a8d982f 100644 --- a/xed/xed-document.h +++ b/xed/xed-document.h @@ -81,9 +81,10 @@ typedef enum */ typedef enum { - XED_DOCUMENT_SAVE_IGNORE_MTIME = 1 << 0, - XED_DOCUMENT_SAVE_IGNORE_BACKUP = 1 << 1, - XED_DOCUMENT_SAVE_PRESERVE_BACKUP = 1 << 2 + XED_DOCUMENT_SAVE_IGNORE_MTIME = 1 << 0, + XED_DOCUMENT_SAVE_IGNORE_BACKUP = 1 << 1, + XED_DOCUMENT_SAVE_PRESERVE_BACKUP = 1 << 2, + XED_DOCUMENT_SAVE_IGNORE_INVALID_CHARS = 1 << 3 } XedDocumentSaveFlags; /* Private structure type */ @@ -286,6 +287,14 @@ void _xed_document_set_readonly (XedDocument *doc, glong _xed_document_get_seconds_since_last_save_or_load (XedDocument *doc); +void _xed_document_apply_error_style (XedDocument *doc, + GtkTextIter *start, + GtkTextIter *end); + +void _xed_document_apply_error_style (XedDocument *doc, + GtkTextIter *start, + GtkTextIter *end); + /* Note: this is a sync stat: use only on local files */ gboolean _xed_document_check_externally_modified (XedDocument *doc); diff --git a/xed/xed-io-error-message-area.c b/xed/xed-io-error-message-area.c index 0362f0f..096b0e8 100644 --- a/xed/xed-io-error-message-area.c +++ b/xed/xed-io-error-message-area.c @@ -354,7 +354,7 @@ xed_unrecoverable_reverting_error_message_area_new (GFile *location, g_return_val_if_fail (error != NULL, NULL); g_return_val_if_fail ((error->domain == XED_DOCUMENT_ERROR) || (error->domain == G_IO_ERROR), NULL); - full_formatted_uri = xed_utils_uri_for_display (location); + full_formatted_uri = g_file_get_parse_name (location); /* Truncate the URI so it doesn't get insanely wide. Note that even * though the dialog uses wrapped text, if the URI doesn't contain @@ -442,19 +442,15 @@ create_conversion_error_message_area (const gchar *primary_text, different from other main menu access keys (Open, Edit, View...) */ _("Edit Any_way"), GTK_RESPONSE_YES); - gtk_info_bar_add_button (GTK_INFO_BAR (message_area), - /* Translators: the access key chosen for this string should be - different from other main menu access keys (Open, Edit, View...) */ - _("D_on't Edit"), - GTK_RESPONSE_NO); gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), GTK_MESSAGE_WARNING); } else { - gtk_info_bar_add_button (GTK_INFO_BAR (message_area), _("_Cancel"), GTK_RESPONSE_CANCEL); gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area), GTK_MESSAGE_ERROR); } + gtk_info_bar_add_button (GTK_INFO_BAR (message_area), _("_Cancel"), GTK_RESPONSE_CANCEL); + hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); image = gtk_image_new_from_icon_name ("dialog-error-symbolic", GTK_ICON_SIZE_DIALOG); @@ -516,7 +512,7 @@ xed_io_loading_error_message_area_new (GFile *location, (error->domain == XED_DOCUMENT_ERROR) || (error->domain == G_IO_ERROR), NULL); - full_formatted_uri = xed_utils_uri_for_display (location); + full_formatted_uri = g_file_get_parse_name (location); /* Truncate the URI so it doesn't get insanely wide. Note that even * though the dialog uses wrapped text, if the URI doesn't contain @@ -559,8 +555,8 @@ xed_io_loading_error_message_area_new (GFile *location, { error_message = g_strdup_printf (_("There was a problem opening the file %s."), uri_for_display); message_details = g_strconcat (_("The file you opened has some invalid characters. " - "If you continue editing this file you could make this " - "document useless."), "\n", + "If you continue editing this file you could corrupt this " + "document."), "\n", _("You can also choose another character encoding and try again."), NULL); edit_anyway = TRUE; @@ -623,7 +619,7 @@ xed_conversion_error_while_saving_message_area_new (GFile *location, error->domain == G_IO_ERROR, NULL); g_return_val_if_fail (encoding != NULL, NULL); - full_formatted_uri = xed_utils_uri_for_display (location); + full_formatted_uri = g_file_get_parse_name (location); /* Truncate the URI so it doesn't get insanely wide. Note that even * though the dialog uses wrapped text, if the URI doesn't contain @@ -686,7 +682,7 @@ xed_file_already_open_warning_message_area_new (GFile *location) g_return_val_if_fail (G_IS_FILE (location), NULL); - full_formatted_uri = xed_utils_uri_for_display (location); + full_formatted_uri = g_file_get_parse_name (location); /* Truncate the URI so it doesn't get insanely wide. Note that even * though the dialog uses wrapped text, if the URI doesn't contain @@ -776,7 +772,7 @@ xed_externally_modified_saving_error_message_area_new (GFile *location, g_return_val_if_fail (error->domain == XED_DOCUMENT_ERROR, NULL); g_return_val_if_fail (error->code == XED_DOCUMENT_ERROR_EXTERNALLY_MODIFIED, NULL); - full_formatted_uri = xed_utils_uri_for_display (location); + full_formatted_uri = g_file_get_parse_name (location); /* Truncate the URI so it doesn't get insanely wide. Note that even * though the dialog uses wrapped text, if the URI doesn't contain @@ -866,7 +862,7 @@ xed_no_backup_saving_error_message_area_new (GFile *location, (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANT_CREATE_BACKUP)), NULL); - full_formatted_uri = xed_utils_uri_for_display (location); + full_formatted_uri = g_file_get_parse_name (location); /* Truncate the URI so it doesn't get insanely wide. Note that even * though the dialog uses wrapped text, if the URI doesn't contain @@ -958,7 +954,7 @@ xed_unrecoverable_saving_error_message_area_new (GFile *location, g_return_val_if_fail (error != NULL, NULL); g_return_val_if_fail ((error->domain == XED_DOCUMENT_ERROR) || (error->domain == G_IO_ERROR), NULL); - full_formatted_uri = xed_utils_uri_for_display (location); + full_formatted_uri = g_file_get_parse_name (location); /* Truncate the URI so it doesn't get insanely wide. Note that even * though the dialog uses wrapped text, if the URI doesn't contain @@ -1067,7 +1063,7 @@ xed_externally_modified_message_area_new (GFile *location, g_return_val_if_fail (G_IS_FILE (location), NULL); - full_formatted_uri = xed_utils_uri_for_display (location); + full_formatted_uri = g_file_get_parse_name (location); /* Truncate the URI so it doesn't get insanely wide. Note that even * though the dialog uses wrapped text, if the URI doesn't contain @@ -1106,3 +1102,84 @@ xed_externally_modified_message_area_new (GFile *location, return message_area; } +GtkWidget * +xed_invalid_character_message_area_new (GFile *location) +{ + GtkWidget *info_bar; + GtkWidget *hbox_content; + GtkWidget *image; + GtkWidget *vbox; + GtkWidget *primary_label; + GtkWidget *secondary_label; + gchar *primary_markup; + gchar *secondary_markup; + gchar *primary_text; + gchar *full_formatted_uri; + gchar *uri_for_display; + gchar *temp_uri_for_display; + const gchar *secondary_text; + + g_return_val_if_fail (G_IS_FILE (location), NULL); + + full_formatted_uri = g_file_get_parse_name (location); + + /* Truncate the URI so it doesn't get insanely wide. Note that even + * though the dialog uses wrapped text, if the URI doesn't contain + * white space then the text-wrapping code is too stupid to wrap it. + */ + temp_uri_for_display = xed_utils_str_middle_truncate (full_formatted_uri, MAX_URI_IN_DIALOG_LENGTH); + g_free (full_formatted_uri); + + uri_for_display = g_markup_printf_escaped ("%s", temp_uri_for_display); + g_free (temp_uri_for_display); + + info_bar = gtk_info_bar_new (); + + info_bar_add_button_with_text (GTK_INFO_BAR (info_bar), _("S_ave Anyway"), + "document_save-symbolic", GTK_RESPONSE_YES); + gtk_info_bar_add_button (GTK_INFO_BAR (info_bar), + _("D_on't Save"), + GTK_RESPONSE_CANCEL); + gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING); + + hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); + + image = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_DIALOG); + gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0); + gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0); + + vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0); + + primary_text = g_strdup_printf (_("Some invalid chars have been detected while saving %s"), uri_for_display); + + g_free (uri_for_display); + + primary_markup = g_strdup_printf ("%s", primary_text); + g_free (primary_text); + primary_label = gtk_label_new (primary_markup); + g_free (primary_markup); + gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0); + gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); + gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (primary_label), 0, 0.5); + gtk_widget_set_can_focus (primary_label, TRUE); + gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); + + secondary_text = _("If you continue saving this file you can corrupt the document. " + " Save anyway?"); + secondary_markup = g_strdup_printf ("%s", secondary_text); + secondary_label = gtk_label_new (secondary_markup); + g_free (secondary_markup); + gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0); + gtk_widget_set_can_focus (secondary_label, TRUE); + gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); + gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); + gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (secondary_label), 0, 0.5); + + gtk_widget_show_all (hbox_content); + set_contents (info_bar, hbox_content); + + return info_bar; +} diff --git a/xed/xed-io-error-message-area.h b/xed/xed-io-error-message-area.h index a3c99dc..3bb17ec 100644 --- a/xed/xed-io-error-message-area.h +++ b/xed/xed-io-error-message-area.h @@ -63,6 +63,8 @@ GtkWidget *xed_unrecoverable_saving_error_message_area_new (GFile GtkWidget *xed_externally_modified_message_area_new (GFile *location, gboolean document_modified); +GtkWidget *xed_invalid_character_message_area_new (GFile *location); + G_END_DECLS #endif /* __XED_IO_ERROR_MESSAGE_AREA_H__ */ diff --git a/xed/xed-tab.c b/xed/xed-tab.c index 196ba7e..a74f904 100644 --- a/xed/xed-tab.c +++ b/xed/xed-tab.c @@ -530,11 +530,8 @@ io_loading_error_message_area_response (GtkWidget *message_area, break; case GTK_RESPONSE_YES: /* This means that we want to edit the document anyway */ - set_message_area (tab, NULL); - _xed_document_set_readonly (doc, FALSE); - break; - case GTK_RESPONSE_NO: - /* We don't want to edit the document just show it */ + tab->priv->not_editable = FALSE; + gtk_text_view_set_editable (GTK_TEXT_VIEW (view), TRUE); set_message_area (tab, NULL); break; default: @@ -755,7 +752,7 @@ show_saving_message_area (XedTab *tab) from = short_name; - to = xed_utils_uri_for_display (tab->priv->tmp_save_location); + to = g_file_get_parse_name (tab->priv->tmp_save_location); str = xed_utils_str_middle_truncate (to, MAX (20, MAX_MSG_LENGTH - len)); g_free (to); @@ -956,7 +953,7 @@ document_loaded (XedDocument *document, { GtkWidget *emsg; - _xed_document_set_readonly (document, TRUE); + tab->priv->not_editable = TRUE; emsg = xed_io_loading_error_message_area_new (location, tab->priv->tmp_encoding, error); @@ -1106,6 +1103,39 @@ unrecoverable_saving_error_message_area_response (GtkWidget *message_area, gtk_widget_grab_focus (GTK_WIDGET (view)); } +static void +invalid_character_message_area_response (GtkWidget *info_bar, + gint response_id, + XedTab *tab) +{ + if (response_id == GTK_RESPONSE_YES) + { + XedDocument *doc; + + doc = xed_tab_get_document (tab); + g_return_if_fail (XED_IS_DOCUMENT (doc)); + + set_message_area (tab, NULL); + + g_return_if_fail (tab->priv->tmp_save_location != NULL); + g_return_if_fail (tab->priv->tmp_encoding != NULL); + + xed_tab_set_state (tab, XED_TAB_STATE_SAVING); + + /* don't bug the user again with this... */ + tab->priv->save_flags |= XED_DOCUMENT_SAVE_IGNORE_INVALID_CHARS; + + g_return_if_fail (tab->priv->auto_save_timeout <= 0); + + /* Force saving */ + xed_document_save (doc, tab->priv->save_flags); + } + else + { + unrecoverable_saving_error_message_area_response (info_bar, response_id, tab); + } +} + static void no_backup_error_message_area_response (GtkWidget *message_area, gint response_id, @@ -1225,8 +1255,11 @@ document_saved (XedDocument *document, g_return_if_fail (tab->priv->tmp_encoding != NULL); g_return_if_fail (tab->priv->auto_save_timeout <= 0); - g_timer_destroy (tab->priv->timer); - tab->priv->timer = NULL; + if (tab->priv->timer != NULL) + { + g_timer_destroy (tab->priv->timer); + tab->priv->timer = NULL; + } tab->priv->times_called = 0; set_message_area (tab, NULL); @@ -1260,6 +1293,19 @@ document_saved (XedDocument *document, g_signal_connect (emsg, "response", G_CALLBACK (no_backup_error_message_area_response), tab); } + else if (error->domain == XED_DOCUMENT_ERROR && + error->code == XED_DOCUMENT_ERROR_CONVERSION_FALLBACK) + { + /* If we have any invalid char in the document we must warn the user + as it can make the document useless if it is saved */ + emsg = xed_invalid_character_message_area_new (tab->priv->tmp_save_location); + g_return_if_fail (emsg != NULL); + + set_message_area (tab, emsg); + + g_signal_connect (emsg, "response", + G_CALLBACK (invalid_character_message_area_response), tab); + } else if (error->domain == XED_DOCUMENT_ERROR || (error->domain == G_IO_ERROR && error->code != G_IO_ERROR_INVALID_DATA && diff --git a/xed/xed-utils.c b/xed/xed-utils.c index cb74976..148ba7e 100644 --- a/xed/xed-utils.c +++ b/xed/xed-utils.c @@ -287,25 +287,6 @@ xed_utils_set_atk_relation (GtkWidget *obj1, g_object_unref (G_OBJECT (relation)); } -gboolean -xed_utils_location_exists (GFile *location) -{ - gboolean res; - gchar *uri; - - g_return_val_if_fail (G_IS_FILE (location), FALSE); - - uri = g_file_get_uri (location); - xed_debug_message (DEBUG_UTILS, "text_uri: %s", uri); - g_free (uri); - - res = g_file_query_exists (location, NULL); - - xed_debug_message (DEBUG_UTILS, res ? "TRUE" : "FALSE"); - - return res; -} - gchar * xed_utils_escape_search_text (const gchar* text) { @@ -1344,23 +1325,6 @@ xed_utils_basename_for_display (GFile *location) return name; } -/** - * xed_utils_uri_for_display: - * @location: location to be displayed. - * - * Filter, modify, unescape and change @uri to make it appropriate - * for display to users. - * - * This function is a convenient wrapper for g_file_get_parse_name - * - * Return value: a string which represents @uri and can be displayed. - */ -gchar * -xed_utils_uri_for_display (GFile *location) -{ - return g_file_get_parse_name (location); -} - /** * xed_utils_drop_get_uris: * @selection_data: the #GtkSelectionData from drag_data_received diff --git a/xed/xed-utils.h b/xed/xed-utils.h index 79749f5..669b500 100644 --- a/xed/xed-utils.h +++ b/xed/xed-utils.h @@ -87,8 +87,6 @@ void xed_utils_set_atk_relation (GtkWidget *obj1, GtkWidget *obj2, AtkRelationType rel_type); -gboolean xed_utils_location_exists (GFile *location); - gchar *xed_utils_escape_search_text (const gchar *text); gchar *xed_utils_unescape_search_text (const gchar *text); @@ -127,8 +125,6 @@ gboolean xed_utils_file_has_parent (GFile *gfile); /* Return NULL if str is not a valid URI and/or filename */ gchar *xed_utils_make_canonical_uri_from_shell_arg (const gchar *str); -gchar *xed_utils_uri_for_display (GFile *location); - gchar *xed_utils_basename_for_display (GFile *location); gboolean xed_utils_decode_uri (const gchar *uri, diff --git a/xed/xed-window.c b/xed/xed-window.c index 5b75854..6419cbc 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -1078,7 +1078,7 @@ update_recent_files_menu (XedWindow *window) /* gtk_recent_info_get_uri_display (info) is buggy and * works only for local files */ location = g_file_new_for_uri (gtk_recent_info_get_uri (info)); - uri = xed_utils_uri_for_display (location); + uri = g_file_get_parse_name (location); g_object_unref (location); ruri = xed_utils_replace_home_dir_with_tilde (uri); g_free (uri); From 4f277063f076acfb8483d42415119b68c348ad9d Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 21 Jan 2017 01:31:05 -0800 Subject: [PATCH 104/132] Remove the xed style scheme manager instance https://github.com/GNOME/gedit/commit/f5d46ef3cce4ee9e73802815e7ec8eecbaa057ad --- xed/Makefile.am | 2 - xed/dialogs/xed-preferences-dialog.c | 288 +++++++++++++++++++-- xed/xed-app.c | 12 + xed/xed-dirs.c | 118 +++++---- xed/xed-dirs.h | 22 +- xed/xed-document.c | 6 +- xed/xed-settings.c | 9 +- xed/xed-style-scheme-manager.c | 372 --------------------------- xed/xed-style-scheme-manager.h | 56 ---- 9 files changed, 365 insertions(+), 520 deletions(-) delete mode 100644 xed/xed-style-scheme-manager.c delete mode 100644 xed/xed-style-scheme-manager.h diff --git a/xed/Makefile.am b/xed/Makefile.am index 0a68f0a..b8339aa 100644 --- a/xed/Makefile.am +++ b/xed/Makefile.am @@ -60,7 +60,6 @@ NOINST_H_FILES = \ xed-session.h \ xed-settings.h \ xed-status-combo-box.h \ - xed-style-scheme-manager.h \ xed-tab-label.h \ xedtextregion.h \ xed-ui.h \ @@ -142,7 +141,6 @@ libxed_c_files = \ xed-searchbar.c \ xed-statusbar.c \ xed-status-combo-box.c \ - xed-style-scheme-manager.c \ xed-tab.c \ xed-tab-label.c \ xed-utils.c \ diff --git a/xed/dialogs/xed-preferences-dialog.c b/xed/dialogs/xed-preferences-dialog.c index 4a4f111..68a75d3 100755 --- a/xed/dialogs/xed-preferences-dialog.c +++ b/xed/dialogs/xed-preferences-dialog.c @@ -35,17 +35,19 @@ #include #include +#include #include +#include #include #include #include +#include #include "xed-preferences-dialog.h" #include "xed-utils.h" #include "xed-debug.h" #include "xed-document.h" -#include "xed-style-scheme-manager.h" #include "xed-help.h" #include "xed-dirs.h" #include "xed-settings.h" @@ -429,14 +431,36 @@ setup_font_colors_page_font_section (XedPreferencesDialog *dlg) gtk_widget_set_sensitive (dlg->priv->font_hbox, !use_default_font); } +static gboolean +is_xed_user_style_scheme (const gchar *scheme_id) +{ + GtkSourceStyleSchemeManager *manager; + GtkSourceStyleScheme *scheme; + gboolean res = FALSE; + + manager = gtk_source_style_scheme_manager_get_default (); + scheme = gtk_source_style_scheme_manager_get_scheme (manager, scheme_id); + if (scheme != NULL) + { + const gchar *filename; + + filename = gtk_source_style_scheme_get_filename (scheme); + if (filename != NULL) + { + res = g_str_has_prefix (filename, xed_dirs_get_user_styles_dir ()); + } + } + + return res; +} + static void set_buttons_sensisitivity_according_to_scheme (XedPreferencesDialog *dlg, const gchar *scheme_id) { gboolean editable; - editable = (scheme_id != NULL) && - _xed_style_scheme_manager_scheme_is_xed_user_scheme (xed_get_style_scheme_manager (), scheme_id); + editable = ((scheme_id != NULL) && is_xed_user_style_scheme (scheme_id)); gtk_widget_set_sensitive (dlg->priv->uninstall_scheme_button, editable); } @@ -465,9 +489,10 @@ static const gchar * ensure_color_scheme_id (XedPreferencesDialog *dlg, const gchar *id) { + GtkSourceStyleSchemeManager *manager; GtkSourceStyleScheme *scheme = NULL; - GtkSourceStyleSchemeManager *manager = xed_get_style_scheme_manager (); + manager = gtk_source_style_scheme_manager_get_default (); if (id == NULL) { gchar *pref_id; @@ -496,15 +521,13 @@ ensure_color_scheme_id (XedPreferencesDialog *dlg, return gtk_source_style_scheme_get_id (scheme); } -/* If def_id is NULL, use the default scheme as returned by - * xed_style_scheme_manager_get_default_scheme. If this one returns NULL - * use the first available scheme as default */ static const gchar * populate_color_scheme_list (XedPreferencesDialog *dlg, const gchar *def_id) { - GSList *schemes; - GSList *l; + GtkSourceStyleSchemeManager *manager; + const gchar * const *ids; + gint i; gtk_list_store_clear (dlg->priv->schemes_treeview_model); @@ -516,47 +539,262 @@ populate_color_scheme_list (XedPreferencesDialog *dlg, return NULL; } - schemes = xed_style_scheme_manager_list_schemes_sorted (xed_get_style_scheme_manager ()); - l = schemes; - while (l != NULL) + manager = gtk_source_style_scheme_manager_get_default (); + ids = gtk_source_style_scheme_manager_get_scheme_ids (manager); + for (i = 0; ids[i] != NULL; i++) { GtkSourceStyleScheme *scheme; - const gchar *id; const gchar *name; const gchar *description; GtkTreeIter iter; - scheme = GTK_SOURCE_STYLE_SCHEME (l->data); - - id = gtk_source_style_scheme_get_id (scheme); + scheme = gtk_source_style_scheme_manager_get_scheme (manager, ids[i]); name = gtk_source_style_scheme_get_name (scheme); description = gtk_source_style_scheme_get_description (scheme); gtk_list_store_append (dlg->priv->schemes_treeview_model, &iter); gtk_list_store_set (dlg->priv->schemes_treeview_model, &iter, - ID_COLUMN, id, + ID_COLUMN, ids[i], NAME_COLUMN, name, DESC_COLUMN, description, -1); g_return_val_if_fail (def_id != NULL, NULL); - if (strcmp (id, def_id) == 0) + if (strcmp (ids[i], def_id) == 0) { GtkTreeSelection *selection; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->schemes_treeview)); gtk_tree_selection_select_iter (selection, &iter); } - - l = g_slist_next (l); } - g_slist_free (schemes); - return def_id; } +/* + * file_copy: + * @name: a pointer to a %NULL-terminated string, that names + * the file to be copied, in the GLib file name encoding + * @dest_name: a pointer to a %NULL-terminated string, that is the + * name for the destination file, in the GLib file name encoding + * @error: return location for a #GError, or %NULL + * + * Copies file @name to @dest_name. + * + * If the call was successful, it returns %TRUE. If the call was not + * successful, it returns %FALSE and sets @error. The error domain + * is #G_FILE_ERROR. Possible error + * codes are those in the #GFileError enumeration. + * + * Return value: %TRUE on success, %FALSE otherwise. + */ +static gboolean +file_copy (const gchar *name, + const gchar *dest_name, + GError **error) +{ + gchar *contents; + gsize length; + gchar *dest_dir; + + /* FIXME - Paolo (Aug. 13, 2007): + * Since the style scheme files are relatively small, we can implement + * file copy getting all the content of the source file in a buffer and + * then write the content to the destination file. In this way we + * can use the g_file_get_contents and g_file_set_contents and avoid to + * write custom code to copy the file (with sane error management). + * If needed we can improve this code later. */ + + g_return_val_if_fail (name != NULL, FALSE); + g_return_val_if_fail (dest_name != NULL, FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + /* Note: we allow to copy a file to itself since this is not a problem + * in our use case */ + + /* Ensure the destination directory exists */ + dest_dir = g_path_get_dirname (dest_name); + + errno = 0; + if (g_mkdir_with_parents (dest_dir, 0755) != 0) + { + gint save_errno = errno; + gchar *display_filename = g_filename_display_name (dest_dir); + + g_set_error (error, + G_FILE_ERROR, + g_file_error_from_errno (save_errno), + _("Directory '%s' could not be created: g_mkdir_with_parents() failed: %s"), + display_filename, + g_strerror (save_errno)); + + g_free (dest_dir); + g_free (display_filename); + + return FALSE; + } + + g_free (dest_dir); + + if (!g_file_get_contents (name, &contents, &length, error)) + { + return FALSE; + } + + if (!g_file_set_contents (dest_name, contents, length, error)) + { + return FALSE; + } + + g_free (contents); + + return TRUE; +} + +/* + * install_style_scheme: + * @manager: a #GtkSourceStyleSchemeManager + * @fname: the file name of the style scheme to be installed + * + * Install a new user scheme. + * This function copies @fname in #XED_STYLES_DIR and ask the style manager to + * recompute the list of available style schemes. It then checks if a style + * scheme with the right file name exists. + * + * If the call was succesful, it returns the id of the installed scheme + * otherwise %NULL. + * + * Return value: the id of the installed scheme, %NULL otherwise. + */ +static const gchar * +install_style_scheme (const gchar *fname) +{ + GtkSourceStyleSchemeManager *manager; + gchar *new_file_name = NULL; + gchar *dirname; + const gchar *styles_dir; + GError *error = NULL; + gboolean copied = FALSE; + const gchar* const *ids; + + g_return_val_if_fail (fname != NULL, NULL); + + manager = gtk_source_style_scheme_manager_get_default (); + + dirname = g_path_get_dirname (fname); + styles_dir = xed_dirs_get_user_styles_dir (); + + if (strcmp (dirname, styles_dir) != 0) + { + gchar *basename; + + basename = g_path_get_basename (fname); + new_file_name = g_build_filename (styles_dir, basename, NULL); + g_free (basename); + + /* Copy the style scheme file into GEDIT_STYLES_DIR */ + if (!file_copy (fname, new_file_name, &error)) + { + g_free (new_file_name); + + g_message ("Cannot install style scheme:\n%s", error->message); + + return NULL; + } + + copied = TRUE; + } + else + { + new_file_name = g_strdup (fname); + } + + g_free (dirname); + + /* Reload the available style schemes */ + gtk_source_style_scheme_manager_force_rescan (manager); + + /* Check the new style scheme has been actually installed */ + ids = gtk_source_style_scheme_manager_get_scheme_ids (manager); + + while (*ids != NULL) + { + GtkSourceStyleScheme *scheme; + const gchar *filename; + + scheme = gtk_source_style_scheme_manager_get_scheme (manager, *ids); + + filename = gtk_source_style_scheme_get_filename (scheme); + + if (filename && (strcmp (filename, new_file_name) == 0)) + { + /* The style scheme has been correctly installed */ + g_free (new_file_name); + + return gtk_source_style_scheme_get_id (scheme); + } + ++ids; + } + + /* The style scheme has not been correctly installed */ + if (copied) + { + g_unlink (new_file_name); + } + + g_free (new_file_name); + + return NULL; +} + +/** + * uninstall_style_scheme: + * @manager: a #GtkSourceStyleSchemeManager + * @id: the id of the style scheme to be uninstalled + * + * Uninstall a user scheme. + * + * If the call was succesful, it returns %TRUE + * otherwise %FALSE. + * + * Return value: %TRUE on success, %FALSE otherwise. + */ +static gboolean +uninstall_style_scheme (const gchar *id) +{ + GtkSourceStyleSchemeManager *manager; + GtkSourceStyleScheme *scheme; + const gchar *filename; + + g_return_val_if_fail (id != NULL, FALSE); + + manager = gtk_source_style_scheme_manager_get_default (); + + scheme = gtk_source_style_scheme_manager_get_scheme (manager, id); + if (scheme == NULL) + { + return FALSE; + } + + filename = gtk_source_style_scheme_get_filename (scheme); + if (filename == NULL) + { + return FALSE; + } + + if (g_unlink (filename) == -1) + { + return FALSE; + } + + /* Reload the available style schemes */ + gtk_source_style_scheme_manager_force_rescan (manager); + + return TRUE; +} + static void add_scheme_chooser_response_cb (GtkDialog *chooser, gint res_id, @@ -573,11 +811,13 @@ add_scheme_chooser_response_cb (GtkDialog *chooser, filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser)); if (filename == NULL) + { return; + } gtk_widget_hide (GTK_WIDGET (chooser)); - scheme_id = _xed_style_scheme_manager_install_scheme (xed_get_style_scheme_manager (), filename); + scheme_id = install_style_scheme (filename); g_free (filename); if (scheme_id == NULL) @@ -660,7 +900,7 @@ uninstall_scheme_clicked (GtkButton *button, gtk_tree_model_get (model, &iter, ID_COLUMN, &id, NAME_COLUMN, &name, -1); - if (!_xed_style_scheme_manager_uninstall_scheme (xed_get_style_scheme_manager (), id)) + if (!uninstall_style_scheme (id)) { xed_warning (GTK_WINDOW (dlg), _("Could not remove color scheme \"%s\"."), name); } diff --git a/xed/xed-app.c b/xed/xed-app.c index a06f2be..f23a567 100644 --- a/xed/xed-app.c +++ b/xed/xed-app.c @@ -37,6 +37,7 @@ #include #include +#include #include "xed-app.h" #include "xed-commands.h" @@ -351,12 +352,23 @@ extension_removed (PeasExtensionSet *extensions, static void xed_app_init (XedApp *app) { + GtkSourceStyleSchemeManager *manager; + app->priv = XED_APP_GET_PRIVATE (app); load_accels (); app->priv->settings = xed_settings_new (); app->priv->window_settings = g_settings_new ("org.x.editor.state.window"); + + /* + * We use the default gtksourceview style scheme manager so that plugins + * can obtain it easily without a xed specific api, but we need to + * add our search path at startup before the manager is actually used. + */ + manager = gtk_source_style_scheme_manager_get_default (); + gtk_source_style_scheme_manager_append_search_path (manager, xed_dirs_get_user_styles_dir ()); + app->priv->extensions = peas_extension_set_new (PEAS_ENGINE (xed_plugins_engine_get_default ()), XED_TYPE_APP_ACTIVATABLE, "app", app, NULL); diff --git a/xed/xed-dirs.c b/xed/xed-dirs.c index e125d5e..271a6cf 100644 --- a/xed/xed-dirs.c +++ b/xed/xed-dirs.c @@ -27,97 +27,115 @@ #include "xed-dirs.h" -gchar* xed_dirs_get_user_config_dir(void) +gchar * +xed_dirs_get_user_config_dir (void) { - gchar* config_dir = NULL; + gchar* config_dir = NULL; - config_dir = g_build_filename(g_get_user_config_dir(), "xed", NULL); + config_dir = g_build_filename(g_get_user_config_dir(), "xed", NULL); - return config_dir; + return config_dir; } -gchar* xed_dirs_get_user_cache_dir(void) +gchar * +xed_dirs_get_user_cache_dir (void) { - const gchar* cache_dir; + const gchar* cache_dir; - cache_dir = g_get_user_cache_dir(); + cache_dir = g_get_user_cache_dir(); - return g_build_filename(cache_dir, "xed", NULL); + return g_build_filename(cache_dir, "xed", NULL); } -gchar* xed_dirs_get_user_plugins_dir(void) +gchar * +xed_dirs_get_user_styles_dir (void) { - gchar* plugin_dir; + gchar *user_style_dir; - plugin_dir = g_build_filename(g_get_user_data_dir(), "xed", "plugins", NULL); - - return plugin_dir; + user_style_dir = g_build_filename (g_get_user_data_dir (), "xed", "styles", NULL); } -gchar* xed_dirs_get_user_accels_file(void) +gchar * +xed_dirs_get_user_plugins_dir (void) { - gchar* accels = NULL; - gchar *config_dir = NULL; + gchar* plugin_dir; - config_dir = xed_dirs_get_user_config_dir(); - accels = g_build_filename(config_dir, "accels", NULL); + plugin_dir = g_build_filename(g_get_user_data_dir(), "xed", "plugins", NULL); - g_free(config_dir); - - return accels; + return plugin_dir; } -gchar* xed_dirs_get_xed_data_dir(void) +gchar * +xed_dirs_get_user_accels_file (void) { - return g_build_filename(DATADIR, "xed", NULL); + gchar* accels = NULL; + gchar *config_dir = NULL; + + config_dir = xed_dirs_get_user_config_dir(); + accels = g_build_filename(config_dir, "accels", NULL); + + g_free(config_dir); + + return accels; } -gchar* xed_dirs_get_xed_locale_dir(void) +gchar * +xed_dirs_get_xed_data_dir (void) { - return g_build_filename(DATADIR, "locale", NULL); + return g_build_filename(DATADIR, "xed", NULL); } -gchar* xed_dirs_get_xed_lib_dir(void) +gchar * +xed_dirs_get_xed_locale_dir (void) { - return g_build_filename(LIBDIR, "xed", NULL); + return g_build_filename(DATADIR, "locale", NULL); } -gchar* xed_dirs_get_xed_plugins_dir(void) +gchar * +xed_dirs_get_xed_lib_dir (void) { - gchar* lib_dir; - gchar* plugin_dir; - - lib_dir = xed_dirs_get_xed_lib_dir(); - - plugin_dir = g_build_filename(lib_dir, "plugins", NULL); - g_free(lib_dir); - - return plugin_dir; + return g_build_filename(LIBDIR, "xed", NULL); } -gchar* xed_dirs_get_xed_plugins_data_dir (void) +gchar * +xed_dirs_get_xed_plugins_dir (void) { - gchar* data_dir; + gchar* lib_dir; + gchar* plugin_dir; + + lib_dir = xed_dirs_get_xed_lib_dir(); + + plugin_dir = g_build_filename(lib_dir, "plugins", NULL); + g_free(lib_dir); + + return plugin_dir; +} + +gchar * +xed_dirs_get_xed_plugins_data_dir (void) +{ + gchar* data_dir; gchar* plugin_data_dir; - data_dir = xed_dirs_get_xed_data_dir (); + data_dir = xed_dirs_get_xed_data_dir (); - plugin_data_dir = g_build_filename (data_dir, "plugins", NULL); + plugin_data_dir = g_build_filename (data_dir, "plugins", NULL); g_free (data_dir); - return plugin_data_dir; + return plugin_data_dir; } -gchar* xed_dirs_get_ui_file(const gchar* file) +gchar * +xed_dirs_get_ui_file (const gchar* file) { - gchar* datadir; - gchar* ui_file; + gchar* datadir; + gchar* ui_file; - g_return_val_if_fail(file != NULL, NULL); + g_return_val_if_fail(file != NULL, NULL); - datadir = xed_dirs_get_xed_data_dir(); - ui_file = g_build_filename(datadir, "ui", file, NULL); - g_free(datadir); + datadir = xed_dirs_get_xed_data_dir(); + ui_file = g_build_filename(datadir, "ui", file, NULL); + g_free(datadir); - return ui_file; + return ui_file; } diff --git a/xed/xed-dirs.h b/xed/xed-dirs.h index eb2d09f..97bcc6d 100644 --- a/xed/xed-dirs.h +++ b/xed/xed-dirs.h @@ -28,25 +28,27 @@ G_BEGIN_DECLS -gchar *xed_dirs_get_user_config_dir (void); +gchar *xed_dirs_get_user_config_dir (void); -gchar *xed_dirs_get_user_cache_dir (void); +gchar *xed_dirs_get_user_cache_dir (void); -gchar *xed_dirs_get_user_plugins_dir (void); +gchar *xed_dirs_get_user_styles_dir (void); -gchar *xed_dirs_get_user_accels_file (void); +gchar *xed_dirs_get_user_plugins_dir (void); -gchar *xed_dirs_get_xed_data_dir (void); +gchar *xed_dirs_get_user_accels_file (void); -gchar *xed_dirs_get_xed_locale_dir (void); +gchar *xed_dirs_get_xed_data_dir (void); -gchar *xed_dirs_get_xed_lib_dir (void); +gchar *xed_dirs_get_xed_locale_dir (void); -gchar *xed_dirs_get_xed_plugins_dir (void); +gchar *xed_dirs_get_xed_lib_dir (void); -gchar *xed_dirs_get_xed_plugins_data_dir (void); +gchar *xed_dirs_get_xed_plugins_dir (void); -gchar *xed_dirs_get_ui_file (const gchar *file); +gchar *xed_dirs_get_xed_plugins_data_dir (void); + +gchar *xed_dirs_get_ui_file (const gchar *file); G_END_DECLS diff --git a/xed/xed-document.c b/xed/xed-document.c index ec0942e..73d573d 100644 --- a/xed/xed-document.c +++ b/xed/xed-document.c @@ -40,13 +40,13 @@ #include #include #include +#include #include "xed-settings.h" #include "xed-document.h" #include "xed-debug.h" #include "xed-utils.h" #include "xed-language-manager.h" -#include "xed-style-scheme-manager.h" #include "xed-document-loader.h" #include "xed-document-saver.h" #include "xed-marshal.h" @@ -730,11 +730,11 @@ set_encoding (XedDocument *doc, static GtkSourceStyleScheme * get_default_style_scheme (GSettings *editor_settings) { + GtkSourceStyleSchemeManager *manager; gchar *scheme_id; GtkSourceStyleScheme *def_style; - GtkSourceStyleSchemeManager *manager; - manager = xed_get_style_scheme_manager (); + manager = gtk_source_style_scheme_manager_get_default (); scheme_id = g_settings_get_string (editor_settings, XED_SETTINGS_SCHEME); def_style = gtk_source_style_scheme_manager_get_scheme (manager, scheme_id); diff --git a/xed/xed-settings.c b/xed/xed-settings.c index 02d263c..a5052f9 100644 --- a/xed/xed-settings.c +++ b/xed/xed-settings.c @@ -23,6 +23,8 @@ #include +#include + #include "xed-settings.h" #include "xed-app.h" #include "xed-debug.h" @@ -30,7 +32,6 @@ #include "xed-window.h" #include "xed-notebook.h" #include "xed-plugins-engine.h" -#include "xed-style-scheme-manager.h" #include "xed-dirs.h" #include "xed-utils.h" #include "xed-window-private.h" @@ -187,6 +188,7 @@ on_scheme_changed (GSettings *settings, const gchar *key, XedSettings *xs) { + GtkSourceStyleSchemeManager *manager; GtkSourceStyleScheme *style; gchar *scheme; GList *docs; @@ -202,13 +204,14 @@ on_scheme_changed (GSettings *settings, g_free (xs->priv->old_scheme); xs->priv->old_scheme = scheme; - style = gtk_source_style_scheme_manager_get_scheme (xed_get_style_scheme_manager (), scheme); + manager = gtk_source_style_scheme_manager_get_default (); + style = gtk_source_style_scheme_manager_get_scheme (manager, scheme); if (style == NULL) { g_warning ("Default style scheme '%s' not found, falling back to 'classic'", scheme); - style = gtk_source_style_scheme_manager_get_scheme (xed_get_style_scheme_manager (), "classic"); + style = gtk_source_style_scheme_manager_get_scheme (manager, "classic"); if (style == NULL) { diff --git a/xed/xed-style-scheme-manager.c b/xed/xed-style-scheme-manager.c deleted file mode 100644 index cb40bfa..0000000 --- a/xed/xed-style-scheme-manager.c +++ /dev/null @@ -1,372 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * xed-source-style-manager.c - * - * Copyright (C) 2007 - Paolo Borelli and Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2007. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#include -#include - -#include -#include - -#include "xed-style-scheme-manager.h" -#include "xed-dirs.h" - -static GtkSourceStyleSchemeManager *style_scheme_manager = NULL; - -static gchar * -get_xed_styles_path (void) -{ - gchar *config_dir; - gchar *dir = NULL; - - config_dir = xed_dirs_get_user_config_dir (); - - if (config_dir != NULL) - { - dir = g_build_filename (config_dir, - "styles", - NULL); - g_free (config_dir); - } - - return dir; -} - -static void -add_xed_styles_path (GtkSourceStyleSchemeManager *mgr) -{ - gchar *dir; - - dir = get_xed_styles_path(); - - if (dir != NULL) - { - gtk_source_style_scheme_manager_append_search_path (mgr, dir); - g_free (dir); - } -} - -GtkSourceStyleSchemeManager * -xed_get_style_scheme_manager (void) -{ - if (style_scheme_manager == NULL) - { - style_scheme_manager = gtk_source_style_scheme_manager_new (); - add_xed_styles_path (style_scheme_manager); - } - - return style_scheme_manager; -} - -static gint -schemes_compare (gconstpointer a, gconstpointer b) -{ - GtkSourceStyleScheme *scheme_a = (GtkSourceStyleScheme *)a; - GtkSourceStyleScheme *scheme_b = (GtkSourceStyleScheme *)b; - - const gchar *name_a = gtk_source_style_scheme_get_name (scheme_a); - const gchar *name_b = gtk_source_style_scheme_get_name (scheme_b); - - return g_utf8_collate (name_a, name_b); -} - -GSList * -xed_style_scheme_manager_list_schemes_sorted (GtkSourceStyleSchemeManager *manager) -{ - const gchar * const * scheme_ids; - GSList *schemes = NULL; - - g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager), NULL); - - scheme_ids = gtk_source_style_scheme_manager_get_scheme_ids (manager); - - while (*scheme_ids != NULL) - { - GtkSourceStyleScheme *scheme; - - scheme = gtk_source_style_scheme_manager_get_scheme (manager, - *scheme_ids); - - schemes = g_slist_prepend (schemes, scheme); - - ++scheme_ids; - } - - if (schemes != NULL) - schemes = g_slist_sort (schemes, (GCompareFunc)schemes_compare); - - return schemes; -} - -gboolean -_xed_style_scheme_manager_scheme_is_xed_user_scheme (GtkSourceStyleSchemeManager *manager, - const gchar *scheme_id) -{ - GtkSourceStyleScheme *scheme; - const gchar *filename; - gchar *dir; - gboolean res = FALSE; - - scheme = gtk_source_style_scheme_manager_get_scheme (manager, scheme_id); - if (scheme == NULL) - return FALSE; - - filename = gtk_source_style_scheme_get_filename (scheme); - if (filename == NULL) - return FALSE; - - dir = get_xed_styles_path (); - - res = g_str_has_prefix (filename, dir); - - g_free (dir); - - return res; -} - -/** - * file_copy: - * @name: a pointer to a %NULL-terminated string, that names - * the file to be copied, in the GLib file name encoding - * @dest_name: a pointer to a %NULL-terminated string, that is the - * name for the destination file, in the GLib file name encoding - * @error: return location for a #GError, or %NULL - * - * Copies file @name to @dest_name. - * - * If the call was successful, it returns %TRUE. If the call was not - * successful, it returns %FALSE and sets @error. The error domain - * is #G_FILE_ERROR. Possible error - * codes are those in the #GFileError enumeration. - * - * Return value: %TRUE on success, %FALSE otherwise. - */ -static gboolean -file_copy (const gchar *name, - const gchar *dest_name, - GError **error) -{ - gchar *contents; - gsize length; - gchar *dest_dir; - - /* FIXME - Paolo (Aug. 13, 2007): - * Since the style scheme files are relatively small, we can implement - * file copy getting all the content of the source file in a buffer and - * then write the content to the destination file. In this way we - * can use the g_file_get_contents and g_file_set_contents and avoid to - * write custom code to copy the file (with sane error management). - * If needed we can improve this code later. */ - - g_return_val_if_fail (name != NULL, FALSE); - g_return_val_if_fail (dest_name != NULL, FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - /* Note: we allow to copy a file to itself since this is not a problem - * in our use case */ - - /* Ensure the destination directory exists */ - dest_dir = g_path_get_dirname (dest_name); - - errno = 0; - if (g_mkdir_with_parents (dest_dir, 0755) != 0) - { - gint save_errno = errno; - gchar *display_filename = g_filename_display_name (dest_dir); - - g_set_error (error, - G_FILE_ERROR, - g_file_error_from_errno (save_errno), - _("Directory '%s' could not be created: g_mkdir_with_parents() failed: %s"), - display_filename, - g_strerror (save_errno)); - - g_free (dest_dir); - g_free (display_filename); - - return FALSE; - } - - g_free (dest_dir); - - if (!g_file_get_contents (name, &contents, &length, error)) - return FALSE; - - if (!g_file_set_contents (dest_name, contents, length, error)) - return FALSE; - - g_free (contents); - - return TRUE; -} - -/** - * _xed_style_scheme_manager_install_scheme: - * @manager: a #GtkSourceStyleSchemeManager - * @fname: the file name of the style scheme to be installed - * - * Install a new user scheme. - * This function copies @fname in #XED_STYLES_DIR and ask the style manager to - * recompute the list of available style schemes. It then checks if a style - * scheme with the right file name exists. - * - * If the call was succesful, it returns the id of the installed scheme - * otherwise %NULL. - * - * Return value: the id of the installed scheme, %NULL otherwise. - */ -const gchar * -_xed_style_scheme_manager_install_scheme (GtkSourceStyleSchemeManager *manager, - const gchar *fname) -{ - gchar *new_file_name = NULL; - gchar *dirname; - gchar *styles_dir; - GError *error = NULL; - gboolean copied = FALSE; - - const gchar* const *ids; - - g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager), NULL); - g_return_val_if_fail (fname != NULL, NULL); - - dirname = g_path_get_dirname (fname); - styles_dir = get_xed_styles_path(); - - if (strcmp (dirname, styles_dir) != 0) - { - gchar *basename; - - basename = g_path_get_basename (fname); - new_file_name = g_build_filename (styles_dir, basename, NULL); - g_free (basename); - - /* Copy the style scheme file into XED_STYLES_DIR */ - if (!file_copy (fname, new_file_name, &error)) - { - g_free (new_file_name); - - g_message ("Cannot install style scheme:\n%s", - error->message); - - g_free (dirname); - g_free (styles_dir); - return NULL; - } - - copied = TRUE; - } - else - { - new_file_name = g_strdup (fname); - } - - g_free (dirname); - g_free (styles_dir); - - /* Reload the available style schemes */ - gtk_source_style_scheme_manager_force_rescan (manager); - - /* Check the new style scheme has been actually installed */ - ids = gtk_source_style_scheme_manager_get_scheme_ids (manager); - - while (*ids != NULL) - { - GtkSourceStyleScheme *scheme; - const gchar *filename; - - scheme = gtk_source_style_scheme_manager_get_scheme ( - xed_get_style_scheme_manager (), *ids); - - filename = gtk_source_style_scheme_get_filename (scheme); - - if (filename && (strcmp (filename, new_file_name) == 0)) - { - /* The style scheme has been correctly installed */ - g_free (new_file_name); - - return gtk_source_style_scheme_get_id (scheme); - } - ++ids; - } - - /* The style scheme has not been correctly installed */ - if (copied) - g_unlink (new_file_name); - - g_free (new_file_name); - - return NULL; -} - -/** - * _xed_style_scheme_manager_uninstall_scheme: - * @manager: a #GtkSourceStyleSchemeManager - * @id: the id of the style scheme to be uninstalled - * - * Uninstall a user scheme. - * - * If the call was succesful, it returns %TRUE - * otherwise %FALSE. - * - * Return value: %TRUE on success, %FALSE otherwise. - */ -gboolean -_xed_style_scheme_manager_uninstall_scheme (GtkSourceStyleSchemeManager *manager, - const gchar *id) -{ - GtkSourceStyleScheme *scheme; - const gchar *filename; - - g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager), FALSE); - g_return_val_if_fail (id != NULL, FALSE); - - scheme = gtk_source_style_scheme_manager_get_scheme (manager, id); - if (scheme == NULL) - return FALSE; - - filename = gtk_source_style_scheme_get_filename (scheme); - if (filename == NULL) - return FALSE; - - if (g_unlink (filename) == -1) - return FALSE; - - /* Reload the available style schemes */ - gtk_source_style_scheme_manager_force_rescan (manager); - - return TRUE; -} diff --git a/xed/xed-style-scheme-manager.h b/xed/xed-style-scheme-manager.h deleted file mode 100644 index 60d7718..0000000 --- a/xed/xed-style-scheme-manager.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * xed-style-scheme-manager.h - * - * Copyright (C) 2007 - Paolo Borelli - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * $Id: xed-source-style-manager.h 5598 2007-04-15 13:16:24Z pborelli $ - */ - -#ifndef __XED_STYLE_SCHEME_MANAGER_H__ -#define __XED_STYLE_SCHEME_MANAGER_H__ - -#include - -G_BEGIN_DECLS - -GtkSourceStyleSchemeManager * - xed_get_style_scheme_manager (void); - -/* Returns a sorted list of style schemes */ -GSList *xed_style_scheme_manager_list_schemes_sorted - (GtkSourceStyleSchemeManager *manager); - -/* - * Non exported functions - */ -gboolean _xed_style_scheme_manager_scheme_is_xed_user_scheme - (GtkSourceStyleSchemeManager *manager, - const gchar *scheme_id); - -const gchar *_xed_style_scheme_manager_install_scheme - (GtkSourceStyleSchemeManager *manager, - const gchar *fname); - -gboolean _xed_style_scheme_manager_uninstall_scheme - (GtkSourceStyleSchemeManager *manager, - const gchar *id); - -G_END_DECLS - -#endif /* __XED_STYLE_SCHEME_MANAGER_H__ */ From 4a6f1d02b867ea45c4b93210aaba5c78a418ebd3 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 21 Jan 2017 01:36:15 -0800 Subject: [PATCH 105/132] xed-document: Fix a couple of possible memory leaks --- xed/xed-document.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xed/xed-document.c b/xed/xed-document.c index 73d573d..3035d02 100644 --- a/xed/xed-document.c +++ b/xed/xed-document.c @@ -1259,6 +1259,8 @@ _xed_document_check_externally_modified (XedDocument *doc) (timeval.tv_sec == doc->priv->mtime.tv_sec && timeval.tv_usec > doc->priv->mtime.tv_usec); } + + g_object_unref (info); } return FALSE; @@ -1594,6 +1596,8 @@ xed_document_save_real (XedDocument *doc, "The document contains invalid characters"); g_signal_emit (doc, document_signals[SAVED], 0, error); + + g_error_free (error); } else { @@ -1659,6 +1663,11 @@ xed_document_save_as (XedDocument *doc, /* priv->mtime refers to the the old location (if any). Thus, it should be * ignored when saving as. */ g_signal_emit (doc, document_signals[SAVE], 0, location, encoding, flags | XED_DOCUMENT_SAVE_IGNORE_MTIME, error); + + if (error != NULL) + { + g_error_free (error); + } } gboolean From 6b8c07d90e28af1f319e1b481167e0f794cf4927 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 21 Jan 2017 13:51:08 -0800 Subject: [PATCH 106/132] Kill xed-language-manager and use gtksourcelanguagemanager directly --- plugins/modelines/modeline-parser.c | 3 +- xed/Makefile.am | 2 - xed/dialogs/xed-preferences-dialog.c | 1 - xed/xed-app.c | 2 +- xed/xed-document.c | 9 ++- xed/xed-file-chooser-dialog.c | 3 +- xed/xed-language-manager.c | 90 ---------------------------- xed/xed-language-manager.h | 48 --------------- xed/xed-settings.c | 2 +- xed/xed-window.c | 88 ++++++++++++++++++++------- 10 files changed, 76 insertions(+), 172 deletions(-) delete mode 100644 xed/xed-language-manager.c delete mode 100644 xed/xed-language-manager.h diff --git a/plugins/modelines/modeline-parser.c b/plugins/modelines/modeline-parser.c index c900eab..3b9133e 100644 --- a/plugins/modelines/modeline-parser.c +++ b/plugins/modelines/modeline-parser.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -752,7 +751,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) GtkSourceLanguageManager *manager; GtkSourceLanguage *language; - manager = xed_get_language_manager (); + manager = gtk_source_language_manager_get_default (); language = gtk_source_language_manager_get_language (manager, options.language_id); diff --git a/xed/Makefile.am b/xed/Makefile.am index b8339aa..0c6399e 100644 --- a/xed/Makefile.am +++ b/xed/Makefile.am @@ -53,7 +53,6 @@ NOINST_H_FILES = \ xed-documents-panel.h \ xed-history-entry.h \ xed-io-error-message-area.h \ - xed-language-manager.h \ xed-plugins-engine.h \ xed-print-job.h \ xed-print-preview.h \ @@ -126,7 +125,6 @@ libxed_c_files = \ xed-help.c \ xed-history-entry.c \ xed-io-error-message-area.c \ - xed-language-manager.c \ xed-message-bus.c \ xed-message-type.c \ xed-message.c \ diff --git a/xed/dialogs/xed-preferences-dialog.c b/xed/dialogs/xed-preferences-dialog.c index 68a75d3..7f31a51 100755 --- a/xed/dialogs/xed-preferences-dialog.c +++ b/xed/dialogs/xed-preferences-dialog.c @@ -42,7 +42,6 @@ #include #include #include -#include #include "xed-preferences-dialog.h" #include "xed-utils.h" diff --git a/xed/xed-app.c b/xed/xed-app.c index f23a567..fe71b44 100644 --- a/xed/xed-app.c +++ b/xed/xed-app.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include "xed-app.h" #include "xed-commands.h" diff --git a/xed/xed-document.c b/xed/xed-document.c index 3035d02..694b3c7 100644 --- a/xed/xed-document.c +++ b/xed/xed-document.c @@ -40,13 +40,11 @@ #include #include #include -#include #include "xed-settings.h" #include "xed-document.h" #include "xed-debug.h" #include "xed-utils.h" -#include "xed-language-manager.h" #include "xed-document-loader.h" #include "xed-document-saver.h" #include "xed-marshal.h" @@ -815,7 +813,7 @@ guess_language (XedDocument *doc, if (strcmp (data, "_NORMAL_") != 0) { - language = gtk_source_language_manager_get_language (xed_get_language_manager (), data); + language = gtk_source_language_manager_get_language (gtk_source_language_manager_get_default (), data); } g_free (data); @@ -837,7 +835,8 @@ guess_language (XedDocument *doc, basename = g_strdup (doc->priv->short_name); } - language = gtk_source_language_manager_guess_language (xed_get_language_manager (), basename, content_type); + language = gtk_source_language_manager_guess_language (gtk_source_language_manager_get_default (), + basename, content_type); g_free (basename); @@ -1646,7 +1645,7 @@ xed_document_save_as (XedDocument *doc, const XedEncoding *encoding, XedDocumentSaveFlags flags) { - GError *error; + GError *error = NULL; g_return_if_fail (XED_IS_DOCUMENT (doc)); g_return_if_fail (G_IS_FILE (location)); diff --git a/xed/xed-file-chooser-dialog.c b/xed/xed-file-chooser-dialog.c index 909a05b..bed9ea1 100644 --- a/xed/xed-file-chooser-dialog.c +++ b/xed/xed-file-chooser-dialog.c @@ -43,7 +43,6 @@ #include "xed-file-chooser-dialog.h" #include "xed-encodings-combo-box.h" -#include "xed-language-manager.h" #include "xed-debug.h" #include "xed-enum-types.h" #include "xed-settings.h" @@ -256,7 +255,7 @@ all_text_files_filter (const GtkFileFilterInfo *filter_info, GtkSourceLanguageManager *lm; const gchar * const *languages; - lm = xed_get_language_manager (); + lm = gtk_source_language_manager_get_default (); languages = gtk_source_language_manager_get_language_ids (lm); while ((languages != NULL) && (*languages != NULL)) diff --git a/xed/xed-language-manager.c b/xed/xed-language-manager.c deleted file mode 100644 index 6ae2e44..0000000 --- a/xed/xed-language-manager.c +++ /dev/null @@ -1,90 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * xed-languages-manager.c - * This file is part of xed - * - * Copyright (C) 2003-2006 - Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2003-2006. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#include -#include -#include -#include "xed-language-manager.h" -#include "xed-utils.h" -#include "xed-debug.h" - -static GtkSourceLanguageManager *language_manager = NULL; - -GtkSourceLanguageManager * -xed_get_language_manager (void) -{ - if (language_manager == NULL) - { - language_manager = gtk_source_language_manager_new (); - } - - return language_manager; -} - -static gint -language_compare (gconstpointer a, gconstpointer b) -{ - GtkSourceLanguage *lang_a = (GtkSourceLanguage *)a; - GtkSourceLanguage *lang_b = (GtkSourceLanguage *)b; - const gchar *name_a = gtk_source_language_get_name (lang_a); - const gchar *name_b = gtk_source_language_get_name (lang_b); - - return g_utf8_collate (name_a, name_b); -} - -GSList * -xed_language_manager_list_languages_sorted (GtkSourceLanguageManager *lm, - gboolean include_hidden) -{ - GSList *languages = NULL; - const gchar * const *ids; - - ids = gtk_source_language_manager_get_language_ids (lm); - if (ids == NULL) - return NULL; - - while (*ids != NULL) - { - GtkSourceLanguage *lang; - - lang = gtk_source_language_manager_get_language (lm, *ids); - g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (lang), NULL); - ++ids; - - if (include_hidden || !gtk_source_language_get_hidden (lang)) - { - languages = g_slist_prepend (languages, lang); - } - } - - return g_slist_sort (languages, (GCompareFunc)language_compare); -} - diff --git a/xed/xed-language-manager.h b/xed/xed-language-manager.h deleted file mode 100644 index 9c48bae..0000000 --- a/xed/xed-language-manager.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * xed-languages-manager.h - * This file is part of xed - * - * Copyright (C) 2003-2005 - Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -/* - * Modified by the xed Team, 2003-2005. See the AUTHORS file for a - * list of people on the xed Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#ifndef __XED_LANGUAGES_MANAGER_H__ -#define __XED_LANGUAGES_MANAGER_H__ - -#include -#include - -G_BEGIN_DECLS - -GtkSourceLanguageManager *xed_get_language_manager (void); - -GSList *xed_language_manager_list_languages_sorted - (GtkSourceLanguageManager *lm, - gboolean include_hidden); - -G_END_DECLS - -#endif /* __XED_LANGUAGES_MANAGER_H__ */ diff --git a/xed/xed-settings.c b/xed/xed-settings.c index a5052f9..64686d7 100644 --- a/xed/xed-settings.c +++ b/xed/xed-settings.c @@ -23,7 +23,7 @@ #include -#include +#include #include "xed-settings.h" #include "xed-app.h" diff --git a/xed/xed-window.c b/xed/xed-window.c index 6419cbc..c0ce65a 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -22,7 +22,6 @@ #include "xed-utils.h" #include "xed-commands.h" #include "xed-debug.h" -#include "xed-language-manager.h" #include "xed-panel.h" #include "xed-documents-panel.h" #include "xed-plugins-engine.h" @@ -707,7 +706,7 @@ language_toggled (GtkToggleAction *action, } else { - lang = gtk_source_language_manager_get_language (xed_get_language_manager (), lang_id); + lang = gtk_source_language_manager_get_language (gtk_source_language_manager_get_default (), lang_id); if (lang == NULL) { g_warning("Could not get language %s\n", lang_id); @@ -799,6 +798,54 @@ create_language_menu_item (GtkSourceLanguage *lang, g_free (escaped_section); } +static gint +language_compare (GtkSourceLanguage *lang1, + GtkSourceLanguage *lang2) +{ + const gchar *section1, *section2, *name1, *name2; + gchar *tmp1, *tmp2; + gint ret; + + section1 = gtk_source_language_get_section (lang1); + section2 = gtk_source_language_get_section (lang2); + name1 = gtk_source_language_get_name (lang1); + name2 = gtk_source_language_get_name (lang2); + + /* we collate the concatenation so that they are + * sorted first by section and then by name */ + tmp1 = g_strconcat (section1, "::", name1, NULL); + tmp2 = g_strconcat (section2, "::", name2, NULL); + + ret = g_utf8_collate (tmp1, tmp2); + + g_free(tmp1); + g_free(tmp2); + + return ret; +} + +static GSList * +get_languages_sorted_by_section (XedWindow *window) +{ + GtkSourceLanguageManager *lm; + const gchar * const *ids; + gint i; + GSList *languages = NULL; + + lm = gtk_source_language_manager_get_default (); + ids = gtk_source_language_manager_get_language_ids (lm); + + for (i = 0; ids[i] != NULL; i++) + { + GtkSourceLanguage *lang; + + lang = gtk_source_language_manager_get_language (lm, ids[i]); + languages = g_slist_prepend (languages, lang); + } + + return g_slist_sort (languages, (GCompareFunc)language_compare); +} + static void create_languages_menu (XedWindow *window) { @@ -830,9 +877,9 @@ create_languages_menu (XedWindow *window) gtk_toggle_action_set_active (GTK_TOGGLE_ACTION(action_none), TRUE); /* now add all the known languages */ - languages = xed_language_manager_list_languages_sorted (xed_get_language_manager (), FALSE); + languages = get_languages_sorted_by_section (window); - for (l = languages, i = 0; l != NULL; l = l->next, ++i) + for (l = languages, i = 0; l != NULL; l = l->next) { create_language_menu_item (l->data, i, id, window); } @@ -1625,35 +1672,36 @@ fill_tab_width_combo (XedWindow *window) static void fill_language_combo (XedWindow *window) { - GtkSourceLanguageManager *manager; - GSList *languages; - GSList *item; - GtkWidget *menu_item; + GtkSourceLanguageManager *lm; + const gchar * const *ids; const gchar *name; - - manager = xed_get_language_manager (); - languages = xed_language_manager_list_languages_sorted (manager, FALSE); + GtkWidget *menu_item; + gint i; name = _("Plain Text"); menu_item = gtk_menu_item_new_with_label (name); gtk_widget_show (menu_item); g_object_set_data (G_OBJECT(menu_item), LANGUAGE_DATA, NULL); - xed_status_combo_box_add_item (XED_STATUS_COMBO_BOX(window->priv->language_combo), GTK_MENU_ITEM(menu_item), name); + xed_status_combo_box_add_item (XED_STATUS_COMBO_BOX (window->priv->language_combo), GTK_MENU_ITEM (menu_item), name); - for (item = languages; item; item = item->next) + lm = gtk_source_language_manager_get_default (); + ids = gtk_source_language_manager_get_language_ids (lm); + + for (i = 0; ids[i] != NULL; i++) { - GtkSourceLanguage *lang = GTK_SOURCE_LANGUAGE(item->data); + GtkSourceLanguage *lang; + + lang = gtk_source_language_manager_get_language (lm, ids[i]); name = gtk_source_language_get_name (lang); menu_item = gtk_menu_item_new_with_label (name); gtk_widget_show (menu_item); - g_object_set_data_full (G_OBJECT(menu_item), LANGUAGE_DATA, g_object_ref (lang), - (GDestroyNotify) g_object_unref); - xed_status_combo_box_add_item (XED_STATUS_COMBO_BOX(window->priv->language_combo), - GTK_MENU_ITEM(menu_item), name); - } - g_slist_free (languages); + g_object_set_data_full (G_OBJECT (menu_item), LANGUAGE_DATA, g_object_ref (lang), + (GDestroyNotify) g_object_unref); + xed_status_combo_box_add_item (XED_STATUS_COMBO_BOX (window->priv->language_combo), + GTK_MENU_ITEM (menu_item), name); + } } static void From ed03c490d184a711e6e9a0a816585548ed068617 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 21 Jan 2017 14:08:11 -0800 Subject: [PATCH 107/132] xed-document: Rework externally modified/deleted check https://github.com/GNOME/gedit/commit/7c5e872ad6556c14714ffd87f8e9c235d71a9d9c --- xed/xed-document.c | 127 +++++++++++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 50 deletions(-) diff --git a/xed/xed-document.c b/xed/xed-document.c index 694b3c7..ff9be4e 100644 --- a/xed/xed-document.c +++ b/xed/xed-document.c @@ -140,6 +140,8 @@ struct _XedDocumentPrivate gpointer mount_operation_userdata; guint readonly : 1; + guint externally_modified : 1; + guint deleted : 1; guint last_save_was_manually : 1; guint language_set_by_user : 1; guint stop_cursor_moved_emission : 1; @@ -1217,54 +1219,6 @@ xed_document_get_readonly (XedDocument *doc) return doc->priv->readonly; } -gboolean -_xed_document_check_externally_modified (XedDocument *doc) -{ - GFileInfo *info; - - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - - if (doc->priv->location == NULL) - { - return FALSE; - } - - info = g_file_query_info (doc->priv->location, - G_FILE_ATTRIBUTE_TIME_MODIFIED "," \ - G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, - G_FILE_QUERY_INFO_NONE, - NULL, NULL); - - if (info != NULL) - { - /* While at it also check if permissions changed */ - if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) - { - gboolean read_only; - - read_only = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); - - _xed_document_set_readonly (doc, read_only); - } - - if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) - { - GTimeVal timeval; - - g_file_info_get_modification_time (info, &timeval); - g_object_unref (info); - - return (timeval.tv_sec > doc->priv->mtime.tv_sec) || - (timeval.tv_sec == doc->priv->mtime.tv_sec && - timeval.tv_usec > doc->priv->mtime.tv_usec); - } - - g_object_unref (info); - } - - return FALSE; -} - static void reset_temp_loading_data (XedDocument *doc) { @@ -1317,6 +1271,9 @@ document_loader_loaded (XedDocumentLoader *loader, g_get_current_time (&doc->priv->time_of_last_save_or_load); + doc->priv->externally_modified = FALSE; + doc->priv->deleted = FALSE; + set_encoding (doc, xed_document_loader_get_encoding (loader), (doc->priv->requested_encoding != NULL)); set_content_type (doc, content_type); @@ -1551,6 +1508,9 @@ document_saver_saving (XedDocumentSaver *saver, g_get_current_time (&doc->priv->time_of_last_save_or_load); + doc->priv->externally_modified = FALSE; + doc->priv->deleted = FALSE; + _xed_document_set_readonly (doc, FALSE); gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc), FALSE); @@ -1698,13 +1658,80 @@ xed_document_is_local (XedDocument *doc) return xed_utils_location_has_file_scheme (doc->priv->location); } +static void +check_file_on_disk (XedDocument *doc) +{ + GFileInfo *info; + + if (doc->priv->location == NULL) + { + return; + } + + info = g_file_query_info (doc->priv->location, + G_FILE_ATTRIBUTE_TIME_MODIFIED "," \ + G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, + G_FILE_QUERY_INFO_NONE, + NULL, NULL); + + if (info != NULL) + { + /* While at it also check if permissions changed */ + if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) + { + gboolean read_only; + + read_only = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); + + _xed_document_set_readonly (doc, read_only); + } + + if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) + { + GTimeVal timeval; + + g_file_info_get_modification_time (info, &timeval); + + if (timeval.tv_sec > doc->priv->mtime.tv_sec || + (timeval.tv_sec == doc->priv->mtime.tv_sec && + timeval.tv_usec > doc->priv->mtime.tv_usec)) + { + doc->priv->externally_modified = TRUE; + } + } + + g_object_unref (info); + } + else + { + doc->priv->deleted = TRUE; + } +} + +gboolean +_xed_document_check_externally_modified (XedDocument *doc) +{ + g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); + + if (!doc->priv->externally_modified) + { + check_file_on_disk (doc); + } + + return doc->priv->externally_modified; +} + gboolean xed_document_get_deleted (XedDocument *doc) { g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - /* This is done sync, maybe we should do it async? */ - return doc->priv->location && !g_file_query_exists (doc->priv->location, NULL); + if (!doc->priv->deleted) + { + check_file_on_disk (doc); + } + + return doc->priv->deleted; } /* From f546598d8368a959b78c6f337dab2824027450dc Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 21 Jan 2017 14:44:55 -0800 Subject: [PATCH 108/132] Remove xed_utils_location_has_file_scheme --- docs/reference/xed-sections.txt | 2 -- plugins/filebrowser/xed-file-browser-plugin.c | 4 ++-- xed/xed-document.c | 4 ++-- xed/xed-utils.c | 13 +------------ xed/xed-utils.h | 2 -- 5 files changed, 5 insertions(+), 20 deletions(-) diff --git a/docs/reference/xed-sections.txt b/docs/reference/xed-sections.txt index 2e43141..a3d5d00 100644 --- a/docs/reference/xed-sections.txt +++ b/docs/reference/xed-sections.txt @@ -506,8 +506,6 @@ xed_metadata_manager_set GBOOLEAN_TO_POINTER GPOINTER_TO_BOOLEAN IS_VALID_BOOLEAN -xed_utils_uri_has_writable_scheme -xed_utils_uri_has_file_scheme xed_utils_menu_position_under_widget xed_utils_menu_position_under_tree_view xed_gtk_button_new_with_stock_icon diff --git a/plugins/filebrowser/xed-file-browser-plugin.c b/plugins/filebrowser/xed-file-browser-plugin.c index 7319199..72e68ca 100644 --- a/plugins/filebrowser/xed-file-browser-plugin.c +++ b/plugins/filebrowser/xed-file-browser-plugin.c @@ -416,7 +416,7 @@ on_selection_changed_cb (GtkTreeSelection *selection, { gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); - sensitive = xed_utils_location_has_file_scheme (location); + sensitive = g_file_has_uri_scheme (location, "file"); } gtk_action_set_sensitive (gtk_action_group_get_action (priv->single_selection_action_group, "OpenTerminal"), sensitive); @@ -902,7 +902,7 @@ on_tab_added_cb (XedWindow *window, if (location != NULL) { - if (xed_utils_location_has_file_scheme (location)) + if (g_file_has_uri_scheme (location, "file")) { prepare_auto_root (plugin); set_root_from_doc (plugin, doc); diff --git a/xed/xed-document.c b/xed/xed-document.c index ff9be4e..f2e9195 100644 --- a/xed/xed-document.c +++ b/xed/xed-document.c @@ -1323,7 +1323,7 @@ document_loader_loaded (XedDocumentLoader *loader, /* special case creating a named new doc */ else if (doc->priv->create && (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_FOUND) && - (xed_utils_location_has_file_scheme (doc->priv->location))) + (g_file_has_uri_scheme (doc->priv->location, "file"))) { reset_temp_loading_data (doc); @@ -1655,7 +1655,7 @@ xed_document_is_local (XedDocument *doc) return FALSE; } - return xed_utils_location_has_file_scheme (doc->priv->location); + return g_file_has_uri_scheme (doc->priv->location, "file"); } static void diff --git a/xed/xed-utils.c b/xed/xed-utils.c index 148ba7e..bbf0391 100644 --- a/xed/xed-utils.c +++ b/xed/xed-utils.c @@ -60,17 +60,6 @@ #define STDIN_DELAY_MICROSECONDS 100000 -/** - * xed_utils_uris_has_file_scheme - * - * Returns: %TRUE if @location is a file: uri and is not a chained uri - */ -gboolean -xed_utils_location_has_file_scheme (GFile *location) -{ - return g_file_has_uri_scheme (location, "file"); -} - static void widget_get_origin (GtkWidget *widget, gint *x, @@ -1257,7 +1246,7 @@ xed_utils_basename_for_display (GFile *location) uri = g_file_get_uri (location); /* First, try to query the display name, but only on local files */ - if (xed_utils_location_has_file_scheme (location)) + if (g_file_has_uri_scheme (location, "file")) { GFileInfo *info; info = g_file_query_info (location, diff --git a/xed/xed-utils.h b/xed/xed-utils.h index 669b500..1c69a00 100644 --- a/xed/xed-utils.h +++ b/xed/xed-utils.h @@ -49,8 +49,6 @@ G_BEGIN_DECLS enum { XED_ALL_WORKSPACES = 0xffffffff }; -gboolean xed_utils_location_has_file_scheme (GFile *location); - void xed_utils_menu_position_under_widget (GtkMenu *menu, gint *x, gint *y, From 0a9588ef63e4f5e15245fd7af4f13d62895ba0f3 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 21 Jan 2017 18:44:15 -0800 Subject: [PATCH 109/132] Clean up our GSettings use a bit more --- xed/dialogs/xed-preferences-dialog.c | 2 +- xed/xed-app.c | 4 +- xed/xed-app.h | 2 +- xed/xed-document.c | 57 +++--- xed/xed-settings.c | 291 +-------------------------- xed/xed-settings.h | 6 +- xed/xed-view.c | 2 +- 7 files changed, 48 insertions(+), 316 deletions(-) diff --git a/xed/dialogs/xed-preferences-dialog.c b/xed/dialogs/xed-preferences-dialog.c index 7f31a51..00023db 100755 --- a/xed/dialogs/xed-preferences-dialog.c +++ b/xed/dialogs/xed-preferences-dialog.c @@ -382,7 +382,7 @@ on_use_default_font_changed (GSettings *settings, static void setup_font_colors_page_font_section (XedPreferencesDialog *dlg) { - GSettings *settings; + GObject *settings; gboolean use_default_font; gchar *system_font = NULL; gchar *label; diff --git a/xed/xed-app.c b/xed/xed-app.c index fe71b44..460fc39 100644 --- a/xed/xed-app.c +++ b/xed/xed-app.c @@ -69,7 +69,7 @@ struct _XedAppPrivate GtkPageSetup *page_setup; GtkPrintSettings *print_settings; - GSettings *settings; + GObject *settings; GSettings *window_settings; PeasExtensionSet *extensions; @@ -886,7 +886,7 @@ _xed_app_set_default_print_settings (XedApp *app, app->priv->print_settings = g_object_ref (settings); } -GSettings * +GObject * _xed_app_get_settings (XedApp *app) { g_return_val_if_fail (XED_IS_APP (app), NULL); diff --git a/xed/xed-app.h b/xed/xed-app.h index f60acd5..5266d88 100644 --- a/xed/xed-app.h +++ b/xed/xed-app.h @@ -99,7 +99,7 @@ GtkPrintSettings *_xed_app_get_default_print_settings (XedApp *app); void _xed_app_set_default_print_settings (XedApp *app, GtkPrintSettings *settings); -GSettings *_xed_app_get_settings (XedApp *app); +GObject *_xed_app_get_settings (XedApp *app); G_END_DECLS diff --git a/xed/xed-document.c b/xed/xed-document.c index f2e9195..a851666 100644 --- a/xed/xed-document.c +++ b/xed/xed-document.c @@ -878,51 +878,60 @@ get_default_content_type (void) static void xed_document_init (XedDocument *doc) { + XedDocumentPrivate *priv; GtkSourceStyleScheme *style_scheme; - gint undo_actions; - gboolean bracket_matching; - gboolean search_hl; xed_debug (DEBUG_DOCUMENT); doc->priv = XED_DOCUMENT_GET_PRIVATE (doc); + priv = doc->priv; - doc->priv->editor_settings = g_settings_new ("org.x.editor.preferences.editor"); + priv->editor_settings = g_settings_new ("org.x.editor.preferences.editor"); - doc->priv->location = NULL; - doc->priv->untitled_number = get_untitled_number (); + priv->location = NULL; + priv->untitled_number = get_untitled_number (); - doc->priv->metadata_info = NULL; + priv->metadata_info = NULL; - doc->priv->content_type = get_default_content_type (); + priv->content_type = get_default_content_type (); - doc->priv->readonly = FALSE; + priv->readonly = FALSE; - doc->priv->stop_cursor_moved_emission = FALSE; + priv->stop_cursor_moved_emission = FALSE; - doc->priv->last_save_was_manually = TRUE; - doc->priv->language_set_by_user = FALSE; + priv->last_save_was_manually = TRUE; + priv->language_set_by_user = FALSE; - doc->priv->dispose_has_run = FALSE; + priv->dispose_has_run = FALSE; - doc->priv->mtime.tv_sec = 0; - doc->priv->mtime.tv_usec = 0; + priv->mtime.tv_sec = 0; + priv->mtime.tv_usec = 0; g_get_current_time (&doc->priv->time_of_last_save_or_load); - doc->priv->encoding = xed_encoding_get_utf8 (); + priv->encoding = xed_encoding_get_utf8 (); - doc->priv->newline_type = XED_DOCUMENT_NEWLINE_TYPE_DEFAULT; + priv->newline_type = XED_DOCUMENT_NEWLINE_TYPE_DEFAULT; - undo_actions = g_settings_get_int (doc->priv->editor_settings, XED_SETTINGS_MAX_UNDO_ACTIONS); - bracket_matching = g_settings_get_boolean (doc->priv->editor_settings, XED_SETTINGS_BRACKET_MATCHING); - search_hl = g_settings_get_boolean (doc->priv->editor_settings, XED_SETTINGS_SEARCH_HIGHLIGHTING); + g_settings_bind (priv->editor_settings, + XED_SETTINGS_MAX_UNDO_ACTIONS, + doc, + "max-undo-levels", + G_SETTINGS_BIND_GET); - gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (doc), undo_actions); - gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (doc), bracket_matching); - xed_document_set_enable_search_highlighting (doc, search_hl); + g_settings_bind (priv->editor_settings, + XED_SETTINGS_BRACKET_MATCHING, + doc, + "highlight-matching-brackets", + G_SETTINGS_BIND_GET); - style_scheme = get_default_style_scheme (doc->priv->editor_settings); + g_settings_bind (priv->editor_settings, + XED_SETTINGS_SEARCH_HIGHLIGHTING, + doc, + "enable-search-highlighting", + G_SETTINGS_BIND_GET); + + style_scheme = get_default_style_scheme (priv->editor_settings); if (style_scheme != NULL) { gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (doc), style_scheme); diff --git a/xed/xed-settings.c b/xed/xed-settings.c index 64686d7..c3eac5a 100644 --- a/xed/xed-settings.c +++ b/xed/xed-settings.c @@ -45,12 +45,11 @@ struct _XedSettingsPrivate GSettings *interface; GSettings *editor; GSettings *ui; - GSettings *plugins; gchar *old_scheme; }; -G_DEFINE_TYPE (XedSettings, xed_settings, G_TYPE_SETTINGS) +G_DEFINE_TYPE (XedSettings, xed_settings, G_TYPE_OBJECT) static void xed_settings_finalize (GObject *object) @@ -85,12 +84,6 @@ xed_settings_dispose (GObject *object) xs->priv->ui = NULL; } - if (xs->priv->plugins != NULL) - { - g_object_unref (xs->priv->plugins); - xs->priv->plugins = NULL; - } - G_OBJECT_CLASS (xed_settings_parent_class)->dispose (object); } @@ -107,7 +100,7 @@ set_font (XedSettings *xs, for (l = views; l != NULL; l = g_list_next (l)) { - /* Note: we use def=FALSE to avoid XedView to query gconf */ + /* Note: we use def=FALSE to avoid XedView to query dconf */ xed_view_set_font (XED_VIEW (l->data), FALSE, font); gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); @@ -275,28 +268,6 @@ on_auto_save_interval_changed (GSettings *settings, g_list_free (docs); } -static void -on_undo_actions_limit_changed (GSettings *settings, - const gchar *key, - XedSettings *xs) -{ - GList *docs, *l; - gint ul; - - g_settings_get (settings, key, "u", &ul); - - ul = CLAMP (ul, -1, 250); - - docs = xed_app_get_documents (xed_app_get_default ()); - - for (l = docs; l != NULL; l = g_list_next (l)) - { - gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (l->data), ul); - } - - g_list_free (docs); -} - static void on_wrap_mode_changed (GSettings *settings, const gchar *key, @@ -317,192 +288,6 @@ on_wrap_mode_changed (GSettings *settings, g_list_free (views); } -static void -on_tabs_size_changed (GSettings *settings, - const gchar *key, - XedSettings *xs) -{ - GList *views, *l; - guint ts; - - g_settings_get (settings, key, "u", &ts); - - ts = CLAMP (ts, 1, 24); - - views = xed_app_get_views (xed_app_get_default ()); - - for (l = views; l != NULL; l = g_list_next (l)) - { - gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); - } - - g_list_free (views); -} - -/* FIXME: insert_spaces and line_numbers are mostly the same it just changes - the func called, maybe typedef the func and refactorize? */ -static void -on_insert_spaces_changed (GSettings *settings, - const gchar *key, - XedSettings *xs) -{ - GList *views, *l; - gboolean spaces; - - spaces = g_settings_get_boolean (settings, key); - - views = xed_app_get_views (xed_app_get_default ()); - - for (l = views; l != NULL; l = g_list_next (l)) - { - gtk_source_view_set_insert_spaces_instead_of_tabs (GTK_SOURCE_VIEW (l->data), spaces); - } - - g_list_free (views); -} - -static void -on_auto_indent_changed (GSettings *settings, - const gchar *key, - XedSettings *xs) -{ - GList *views, *l; - gboolean enable; - - enable = g_settings_get_boolean (settings, key); - - views = xed_app_get_views (xed_app_get_default ()); - - for (l = views; l != NULL; l = g_list_next (l)) - { - gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (l->data), enable); - } - - g_list_free (views); -} - -static void -on_display_line_numbers_changed (GSettings *settings, - const gchar *key, - XedSettings *xs) -{ - GList *views, *l; - gboolean line_numbers; - - line_numbers = g_settings_get_boolean (settings, key); - - views = xed_app_get_views (xed_app_get_default ()); - - for (l = views; l != NULL; l = g_list_next (l)) - { - gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (l->data), line_numbers); - } - - g_list_free (views); -} - -static void -on_hl_current_line_changed (GSettings *settings, - const gchar *key, - XedSettings *xs) -{ - GList *views, *l; - gboolean hl; - - hl = g_settings_get_boolean (settings, key); - - views = xed_app_get_views (xed_app_get_default ()); - - for (l = views; l != NULL; l = g_list_next (l)) - { - gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (l->data), hl); - } - - g_list_free (views); -} - -static void -on_bracket_matching_changed (GSettings *settings, - const gchar *key, - XedSettings *xs) -{ - GList *docs, *l; - gboolean enable; - - enable = g_settings_get_boolean (settings, key); - - docs = xed_app_get_documents (xed_app_get_default ()); - - for (l = docs; l != NULL; l = g_list_next (l)) - { - gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (l->data), enable); - } - - g_list_free (docs); -} - -static void -on_display_right_margin_changed (GSettings *settings, - const gchar *key, - XedSettings *xs) -{ - GList *views, *l; - gboolean display; - - display = g_settings_get_boolean (settings, key); - - views = xed_app_get_views (xed_app_get_default ()); - - for (l = views; l != NULL; l = g_list_next (l)) - { - gtk_source_view_set_show_right_margin (GTK_SOURCE_VIEW (l->data), display); - } - - g_list_free (views); -} - -static void -on_right_margin_position_changed (GSettings *settings, - const gchar *key, - XedSettings *xs) -{ - GList *views, *l; - gint pos; - - g_settings_get (settings, key, "u", &pos); - - pos = CLAMP (pos, 1, 160); - - views = xed_app_get_views (xed_app_get_default ()); - - for (l = views; l != NULL; l = g_list_next (l)) - { - gtk_source_view_set_right_margin_position (GTK_SOURCE_VIEW (l->data), pos); - } - - g_list_free (views); -} - -static void -on_smart_home_end_changed (GSettings *settings, - const gchar *key, - XedSettings *xs) -{ - GtkSourceSmartHomeEndType smart_he; - GList *views, *l; - - smart_he = g_settings_get_enum (settings, key); - - views = xed_app_get_views (xed_app_get_default ()); - - for (l = views; l != NULL; l = g_list_next (l)) - { - gtk_source_view_set_smart_home_end (GTK_SOURCE_VIEW (l->data), smart_he); - } - - g_list_free (views); -} - static void on_syntax_highlighting_changed (GSettings *settings, const gchar *key, @@ -540,26 +325,6 @@ on_syntax_highlighting_changed (GSettings *settings, } } -static void -on_search_highlighting_changed (GSettings *settings, - const gchar *key, - XedSettings *xs) -{ - GList *docs, *l; - gboolean enable; - - enable = g_settings_get_boolean (settings, key); - - docs = xed_app_get_documents (xed_app_get_default ()); - - for (l = docs; l != NULL; l = g_list_next (l)) - { - xed_document_set_enable_search_highlighting (XED_DOCUMENT (l->data), enable); - } - - g_list_free (docs); -} - static void on_enable_tab_scrolling_changed (GSettings *settings, const gchar *key, @@ -597,23 +362,13 @@ xed_settings_init (XedSettings *xs) xs->priv = XED_SETTINGS_GET_PRIVATE (xs); xs->priv->old_scheme = NULL; -} - -static void -initialize (XedSettings *xs) -{ - GSettings *prefs; - - prefs = g_settings_get_child (G_SETTINGS (xs), "preferences"); - xs->priv->editor = g_settings_get_child (prefs, "editor"); - xs->priv->ui = g_settings_get_child (prefs, "ui"); - g_object_unref (prefs); - xs->priv->plugins = g_settings_get_child (G_SETTINGS (xs), "plugins"); + xs->priv->editor = g_settings_new ("org.x.editor.preferences.editor"); + xs->priv->ui = g_settings_new ("org.x.editor.preferences.ui"); /* Load settings */ xs->priv->interface = g_settings_new ("org.gnome.desktop.interface"); - g_signal_connect (xs->priv->interface, "changed", + g_signal_connect (xs->priv->interface, "changed::monospace-font-name", G_CALLBACK (on_system_font_changed), xs); /* editor changes */ @@ -627,32 +382,8 @@ initialize (XedSettings *xs) G_CALLBACK (on_auto_save_changed), xs); g_signal_connect (xs->priv->editor, "changed::auto-save-interval", G_CALLBACK (on_auto_save_interval_changed), xs); - g_signal_connect (xs->priv->editor, "changed::undo-actions-limit", - G_CALLBACK (on_undo_actions_limit_changed), xs); - g_signal_connect (xs->priv->editor, "changed::wrap-mode", - G_CALLBACK (on_wrap_mode_changed), xs); - g_signal_connect (xs->priv->editor, "changed::tabs-size", - G_CALLBACK (on_tabs_size_changed), xs); - g_signal_connect (xs->priv->editor, "changed::insert-spaces", - G_CALLBACK (on_insert_spaces_changed), xs); - g_signal_connect (xs->priv->editor, "changed::auto-indent", - G_CALLBACK (on_auto_indent_changed), xs); - g_signal_connect (xs->priv->editor, "changed::display-line-numbers", - G_CALLBACK (on_display_line_numbers_changed), xs); - g_signal_connect (xs->priv->editor, "changed::highlight-current-line", - G_CALLBACK (on_hl_current_line_changed), xs); - g_signal_connect (xs->priv->editor, "changed::bracket-matching", - G_CALLBACK (on_bracket_matching_changed), xs); - g_signal_connect (xs->priv->editor, "changed::display-right-margin", - G_CALLBACK (on_display_right_margin_changed), xs); - g_signal_connect (xs->priv->editor, "changed::right-margin-position", - G_CALLBACK (on_right_margin_position_changed), xs); - g_signal_connect (xs->priv->editor, "changed::smart-home-end", - G_CALLBACK (on_smart_home_end_changed), xs); g_signal_connect (xs->priv->editor, "changed::syntax-highlighting", G_CALLBACK (on_syntax_highlighting_changed), xs); - g_signal_connect (xs->priv->editor, "changed::search-highlighting", - G_CALLBACK (on_search_highlighting_changed), xs); g_signal_connect (xs->priv->ui, "changed::enable-tab-scrolling", G_CALLBACK (on_enable_tab_scrolling_changed), xs); @@ -672,18 +403,10 @@ xed_settings_class_init (XedSettingsClass *klass) g_type_class_add_private (object_class, sizeof (XedSettingsPrivate)); } -GSettings * +GObject * xed_settings_new () { - XedSettings *settings; - - settings = g_object_new (XED_TYPE_SETTINGS, - "schema", "org.x.editor", - NULL); - - initialize (settings); - - return G_SETTINGS (settings); + return g_object_new (XED_TYPE_SETTINGS, NULL); } gchar * diff --git a/xed/xed-settings.h b/xed/xed-settings.h index 3da7182..262f10f 100644 --- a/xed/xed-settings.h +++ b/xed/xed-settings.h @@ -45,14 +45,14 @@ typedef struct _XedSettingsPrivate XedSettingsPrivate; struct _XedSettings { - GSettings parent; + GObject parent; XedSettingsPrivate *priv; }; struct _XedSettingsClass { - GSettingsClass parent_class; + GObjectClass parent_class; }; // typedef enum { @@ -64,7 +64,7 @@ struct _XedSettingsClass GType xed_settings_get_type (void) G_GNUC_CONST; -GSettings *xed_settings_new (void); +GObject *xed_settings_new (void); // XedLockdownMask xed_settings_get_lockdown (XedSettings *xs); diff --git a/xed/xed-view.c b/xed/xed-view.c index 74022bd..7363d13 100644 --- a/xed/xed-view.c +++ b/xed/xed-view.c @@ -844,7 +844,7 @@ xed_view_set_font (XedView *view, if (def) { - GSettings *settings; + GObject *settings; gchar *font; settings = _xed_app_get_settings (xed_app_get_default ()); From 511fc3dfec1c4ad0a1ddbc3d81d4724acf304857 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 28 Jan 2017 19:12:36 -0800 Subject: [PATCH 110/132] Port to the GtkSourceView search functionality This also gives us support for regex search --- docs/reference/Makefile.am | 1 - docs/reference/xed-sections.txt | 17 - plugins/spell/xed-spell-plugin.c | 20 +- plugins/spell/xed-spell-utils.c | 4 +- xed/Makefile.am | 4 +- xed/xed-commands-search.c | 13 +- xed/xed-document.c | 796 ++----------------------------- xed/xed-document.h | 74 +-- xed/xed-history-entry.c | 51 -- xed/xed-history-entry.h | 4 - xed/xed-searchbar.c | 702 +++++++++++++++------------ xed/xed-searchbar.h | 34 +- xed/xed-searchbar.ui | 26 +- xed/xed-utils.c | 137 +----- xed/xed-utils.h | 4 - xed/xed-view.c | 82 +--- xed/xed-window.c | 16 +- xed/xedtextregion.c | 646 ------------------------- xed/xedtextregion.h | 88 ---- 19 files changed, 503 insertions(+), 2216 deletions(-) delete mode 100644 xed/xedtextregion.c delete mode 100644 xed/xedtextregion.h diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am index 71b2fbf..c6e3011 100644 --- a/docs/reference/Makefile.am +++ b/docs/reference/Makefile.am @@ -64,7 +64,6 @@ IGNORE_HFILES= \ # Do not parse them to make the docs. IGNORE_HFILES += \ bacon-message-connection.h \ - xedtextregion.h \ sexy-icon-entry.h # Images to copy into HTML directory. diff --git a/docs/reference/xed-sections.txt b/docs/reference/xed-sections.txt index a3d5d00..1ff97e0 100644 --- a/docs/reference/xed-sections.txt +++ b/docs/reference/xed-sections.txt @@ -36,7 +36,6 @@ xed_app_activatable_get_type
xed-document -XedSearchFlags XedDocumentPrivate XedDocument XedDocument @@ -58,21 +57,7 @@ xed_document_is_untouched xed_document_is_untitled xed_document_get_deleted xed_document_goto_line -xed_document_set_search_text -xed_document_get_search_text -xed_document_get_can_search_again -xed_document_search_forward -xed_document_search_backward -xed_document_replace_all xed_document_set_language -xed_document_set_enable_search_highlighting -xed_document_get_enable_search_highlighting -XED_SEARCH_IS_DONT_SET_FLAGS -XED_SEARCH_SET_DONT_SET_FLAGS -XED_SEARCH_IS_ENTIRE_WORD -XED_SEARCH_SET_ENTIRE_WORD -XED_SEARCH_IS_CASE_SENSITIVE -XED_SEARCH_SET_CASE_SENSITIVE XED_DOCUMENT XED_IS_DOCUMENT @@ -517,8 +502,6 @@ g_utf8_caselessnmatch xed_utils_set_atk_name_description xed_utils_set_atk_relation xed_utils_uri_exists -xed_utils_escape_search_text -xed_utils_unescape_search_text xed_utils_get_stdin xed_warning xed_utils_make_valid_utf8 diff --git a/plugins/spell/xed-spell-plugin.c b/plugins/spell/xed-spell-plugin.c index 2765bc0..1e3bce5 100644 --- a/plugins/spell/xed-spell-plugin.c +++ b/plugins/spell/xed-spell-plugin.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "xed-spell-checker.h" #include "xed-spell-checker-dialog.h" @@ -704,7 +705,8 @@ change_all_cb (XedSpellCheckerDialog *dlg, CheckRange *range; gchar *w = NULL; GtkTextIter start, end; - gint flags = 0; + GtkSourceSearchSettings *search_settings; + GtkSourceSearchContext *search_context; xed_debug (DEBUG_PLUGINS); @@ -739,16 +741,24 @@ change_all_cb (XedSpellCheckerDialog *dlg, g_free (w); - XED_SEARCH_SET_CASE_SENSITIVE (flags, TRUE); - XED_SEARCH_SET_ENTIRE_WORD (flags, TRUE); + search_settings = gtk_source_search_settings_new (); + gtk_source_search_settings_set_case_sensitive (search_settings, TRUE); + gtk_source_search_settings_set_at_word_boundaries (search_settings, TRUE); + gtk_source_search_settings_set_search_text (search_settings, word); - /* CHECK: currently this function does escaping etc */ - xed_document_replace_all (doc, word, change, flags); + search_context = gtk_source_search_context_new (GTK_SOURCE_BUFFER (doc), search_settings); + + gtk_source_search_context_set_highlight (search_context, FALSE); + + gtk_source_search_context_replace_all (search_context, change, -1, NULL); update_current (doc, range->mw_start + g_utf8_strlen (change, -1)); /* go to next misspelled word */ ignore_cb (dlg, word, view); + + g_object_unref (search_settings); + g_object_unref (search_context); } static void diff --git a/plugins/spell/xed-spell-utils.c b/plugins/spell/xed-spell-utils.c index b9e592e..b36c736 100644 --- a/plugins/spell/xed-spell-utils.c +++ b/plugins/spell/xed-spell-utils.c @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ #include #include "xed-spell-utils.h" -#include +#include gboolean xed_spell_utils_is_digit (const char *text, gssize length) diff --git a/xed/Makefile.am b/xed/Makefile.am index 0c6399e..f1088be 100644 --- a/xed/Makefile.am +++ b/xed/Makefile.am @@ -60,7 +60,6 @@ NOINST_H_FILES = \ xed-settings.h \ xed-status-combo-box.h \ xed-tab-label.h \ - xedtextregion.h \ xed-ui.h \ xed-utils.h \ xed-view-frame.h \ @@ -146,8 +145,7 @@ libxed_c_files = \ xed-view-activatable.c \ xed-view-frame.c \ xed-window.c \ - xed-window-activatable.c \ - xedtextregion.c + xed-window-activatable.c libxed_la_SOURCES = \ $(BUILT_SOURCES) \ diff --git a/xed/xed-commands-search.c b/xed/xed-commands-search.c index d5570ed..be55793 100644 --- a/xed/xed-commands-search.c +++ b/xed/xed-commands-search.c @@ -14,18 +14,25 @@ #include "xed-searchbar.h" #include "xed-view-frame.h" +// void +// _xed_cmd_search_find (GtkAction *action, +// XedWindow *window) +// { +// xed_searchbar_show (XED_SEARCHBAR (xed_window_get_searchbar (window)), FALSE); +// } + void _xed_cmd_search_find (GtkAction *action, XedWindow *window) { - xed_searchbar_show (XED_SEARCHBAR (xed_window_get_searchbar (window)), FALSE); + xed_searchbar_show (XED_SEARCHBAR (xed_window_get_searchbar (window)), SEARCH_MODE_SEARCH); } void _xed_cmd_search_replace (GtkAction *action, XedWindow *window) { - xed_searchbar_show (XED_SEARCHBAR (xed_window_get_searchbar (window)), TRUE); + xed_searchbar_show (XED_SEARCHBAR (xed_window_get_searchbar (window)), SEARCH_MODE_REPLACE); } void @@ -54,7 +61,7 @@ _xed_cmd_search_clear_highlight (XedWindow *window) doc = xed_window_get_active_document (window); if (doc != NULL) { - xed_document_set_search_text (XED_DOCUMENT(doc), "", XED_SEARCH_DONT_SET_FLAGS); + _xed_document_set_search_context (doc, NULL); } } diff --git a/xed/xed-document.c b/xed/xed-document.c index a851666..4009aa1 100644 --- a/xed/xed-document.c +++ b/xed/xed-document.c @@ -49,7 +49,6 @@ #include "xed-document-saver.h" #include "xed-marshal.h" #include "xed-enum-types.h" -#include "xedtextregion.h" #ifndef ENABLE_GVFS_METADATA #include "xed-metadata-manager.h" @@ -86,14 +85,6 @@ static void xed_document_save_real (XedDocument *doc, GFile *location, const XedEncoding *encoding, XedDocumentSaveFlags flags); -static void insert_text_cb (XedDocument *doc, - GtkTextIter *pos, - const gchar *text, - gint length); - -static void delete_range_cb (XedDocument *doc, - GtkTextIter *start, - GtkTextIter *end); struct _XedDocumentPrivate { @@ -113,9 +104,7 @@ struct _XedDocumentPrivate GTimeVal mtime; GTimeVal time_of_last_save_or_load; - guint search_flags; - gchar *search_text; - gint num_of_lines_search_text; + GtkSourceSearchContext *search_context; XedDocumentNewlineType newline_type; @@ -129,10 +118,6 @@ struct _XedDocumentPrivate /* Saving stuff */ XedDocumentSaver *saver; - /* Search highlighting support variables */ - XedTextRegion *to_search_region; - GtkTextTag *found_tag; - GtkTextTag *error_tag; /* Mount operation factory */ @@ -158,8 +143,6 @@ enum PROP_MIME_TYPE, PROP_READ_ONLY, PROP_ENCODING, - PROP_CAN_SEARCH_AGAIN, - PROP_ENABLE_SEARCH_HIGHLIGHTING, PROP_NEWLINE_TYPE }; @@ -172,7 +155,6 @@ enum SAVE, SAVING, SAVED, - SEARCH_HIGHLIGHT_UPDATED, LAST_SIGNAL }; @@ -284,6 +266,7 @@ xed_document_dispose (GObject *object) g_clear_object (&doc->priv->editor_settings); g_clear_object (&doc->priv->metadata_info); g_clear_object (&doc->priv->location); + g_clear_object (&doc->priv->search_context); doc->priv->dispose_has_run = TRUE; @@ -303,13 +286,6 @@ xed_document_finalize (GObject *object) } g_free (doc->priv->content_type); - g_free (doc->priv->search_text); - - if (doc->priv->to_search_region != NULL) - { - /* we can't delete marks if we're finalizing the buffer */ - xed_text_region_destroy (doc->priv->to_search_region, FALSE); - } G_OBJECT_CLASS (xed_document_parent_class)->finalize (object); } @@ -342,12 +318,6 @@ xed_document_get_property (GObject *object, case PROP_ENCODING: g_value_set_boxed (value, doc->priv->encoding); break; - case PROP_CAN_SEARCH_AGAIN: - g_value_set_boolean (value, xed_document_get_can_search_again (doc)); - break; - case PROP_ENABLE_SEARCH_HIGHLIGHTING: - g_value_set_boolean (value, xed_document_get_enable_search_highlighting (doc)); - break; case PROP_NEWLINE_TYPE: g_value_set_enum (value, doc->priv->newline_type); break; @@ -386,9 +356,6 @@ xed_document_set_property (GObject *object, case PROP_CONTENT_TYPE: xed_document_set_content_type (doc, g_value_get_string (value)); break; - case PROP_ENABLE_SEARCH_HIGHLIGHTING: - xed_document_set_enable_search_highlighting (doc, g_value_get_boolean (value)); - break; case PROP_NEWLINE_TYPE: xed_document_set_newline_type (doc, g_value_get_enum (value)); break; @@ -498,22 +465,6 @@ xed_document_class_init (XedDocumentClass *klass) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (object_class, PROP_CAN_SEARCH_AGAIN, - g_param_spec_boolean ("can-search-again", - "Can search again", - "Whether it's possible to search again in the document", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property (object_class, PROP_ENABLE_SEARCH_HIGHLIGHTING, - g_param_spec_boolean ("enable-search-highlighting", - "Enable Search Highlighting", - "Whether all the occurrences of the searched string must be highlighted", - FALSE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); - /** * XedDocument:newline-type: * @@ -643,18 +594,6 @@ xed_document_class_init (XedDocumentClass *klass) 1, G_TYPE_POINTER); - document_signals[SEARCH_HIGHLIGHT_UPDATED] = - g_signal_new ("search-highlight-updated", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedDocumentClass, search_highlight_updated), - NULL, NULL, - xed_marshal_VOID__BOXED_BOXED, - G_TYPE_NONE, - 2, - GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE, - GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE); - g_type_class_add_private (object_class, sizeof (XedDocumentPrivate)); } @@ -925,20 +864,12 @@ xed_document_init (XedDocument *doc) "highlight-matching-brackets", G_SETTINGS_BIND_GET); - g_settings_bind (priv->editor_settings, - XED_SETTINGS_SEARCH_HIGHLIGHTING, - doc, - "enable-search-highlighting", - G_SETTINGS_BIND_GET); - style_scheme = get_default_style_scheme (priv->editor_settings); if (style_scheme != NULL) { gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (doc), style_scheme); } - g_signal_connect_after (doc, "insert-text", G_CALLBACK (insert_text_cb), NULL); - g_signal_connect_after (doc, "delete-range", G_CALLBACK (delete_range_cb), NULL); g_signal_connect (doc, "notify::content-type", G_CALLBACK (on_content_type_changed), NULL); g_signal_connect (doc, "notify::location", G_CALLBACK (on_location_changed), NULL); } @@ -1807,448 +1738,6 @@ xed_document_goto_line_offset (XedDocument *doc, return ret; } -static gint -compute_num_of_lines (const gchar *text) -{ - const gchar *p; - gint len; - gint n = 1; - - g_return_val_if_fail (text != NULL, 0); - - len = strlen (text); - p = text; - - while (len > 0) - { - gint del, par; - - pango_find_paragraph_boundary (p, len, &del, &par); - - if (del == par) /* not found */ - break; - - p += par; - len -= par; - ++n; - } - - return n; -} - -static void -to_search_region_range (XedDocument *doc, - GtkTextIter *start, - GtkTextIter *end) -{ - xed_debug (DEBUG_DOCUMENT); - - if (doc->priv->to_search_region == NULL) - { - return; - } - - gtk_text_iter_set_line_offset (start, 0); - gtk_text_iter_forward_to_line_end (end); - - /* - g_print ("+ [%u (%u), %u (%u)]\n", gtk_text_iter_get_line (start), gtk_text_iter_get_offset (start), - gtk_text_iter_get_line (end), gtk_text_iter_get_offset (end)); - */ - - /* Add the region to the refresh region */ - xed_text_region_add (doc->priv->to_search_region, start, end); - - /* Notify views of the updated highlight region */ - gtk_text_iter_backward_lines (start, doc->priv->num_of_lines_search_text); - gtk_text_iter_forward_lines (end, doc->priv->num_of_lines_search_text); - - g_signal_emit (doc, document_signals [SEARCH_HIGHLIGHT_UPDATED], 0, start, end); -} - -/** - * xed_document_set_search_text: - * @doc: - * @text: (allow-none): - * @flags: - **/ -void -xed_document_set_search_text (XedDocument *doc, - const gchar *text, - guint flags) -{ - gchar *converted_text; - gboolean notify = FALSE; - gboolean update_to_search_region = FALSE; - - g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail ((text == NULL) || (doc->priv->search_text != text)); - g_return_if_fail ((text == NULL) || g_utf8_validate (text, -1, NULL)); - - xed_debug_message (DEBUG_DOCUMENT, "text = %s", text); - - if (text != NULL) - { - if (*text != '\0') - { - converted_text = xed_utils_unescape_search_text (text); - notify = !xed_document_get_can_search_again (doc); - } - else - { - converted_text = g_strdup(""); - notify = xed_document_get_can_search_again (doc); - } - - g_free (doc->priv->search_text); - - doc->priv->search_text = converted_text; - doc->priv->num_of_lines_search_text = compute_num_of_lines (doc->priv->search_text); - update_to_search_region = TRUE; - } - - if (!XED_SEARCH_IS_DONT_SET_FLAGS (flags)) - { - if (doc->priv->search_flags != flags) - { - update_to_search_region = TRUE; - } - - doc->priv->search_flags = flags; - - } - - if (update_to_search_region) - { - GtkTextIter begin; - GtkTextIter end; - - gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &begin, &end); - to_search_region_range (doc, &begin, &end); - } - - if (notify) - { - g_object_notify (G_OBJECT (doc), "can-search-again"); - } -} - -/** - * xed_document_get_search_text: - * @doc: - * @flags: (allow-none): - */ -gchar * -xed_document_get_search_text (XedDocument *doc, - guint *flags) -{ - g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); - - if (flags != NULL) - { - *flags = doc->priv->search_flags; - } - - return xed_utils_escape_search_text (doc->priv->search_text); -} - -gboolean -xed_document_get_can_search_again (XedDocument *doc) -{ - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - - return ((doc->priv->search_text != NULL) && (*doc->priv->search_text != '\0')); -} - -/** - * xed_document_search_forward: - * @doc: - * @start: (allow-none): - * @end: (allow-none): - * @match_start: (allow-none): - * @match_end: (allow-none): - **/ -gboolean -xed_document_search_forward (XedDocument *doc, - const GtkTextIter *start, - const GtkTextIter *end, - GtkTextIter *match_start, - GtkTextIter *match_end) -{ - GtkTextIter iter; - GtkTextSearchFlags search_flags; - gboolean found = FALSE; - GtkTextIter m_start; - GtkTextIter m_end; - - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - g_return_val_if_fail ((start == NULL) || (gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc)), FALSE); - g_return_val_if_fail ((end == NULL) || (gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc)), FALSE); - - if (doc->priv->search_text == NULL) - { - xed_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == NULL\n"); - return FALSE; - } - else - { - xed_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == \"%s\"\n", doc->priv->search_text); - } - - if (start == NULL) - { - gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (doc), &iter); - } - else - { - iter = *start; - } - - search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY; - - if (!XED_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags)) - { - search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE; - } - - while (!found) - { - found = gtk_text_iter_forward_search (&iter, - doc->priv->search_text, - search_flags, - &m_start, - &m_end, - end); - - if (found && XED_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags)) - { - found = gtk_text_iter_starts_word (&m_start) && gtk_text_iter_ends_word (&m_end); - - if (!found) - { - iter = m_end; - } - } - else - { - break; - } - } - - if (found && (match_start != NULL)) - { - *match_start = m_start; - } - if (found && (match_end != NULL)) - { - *match_end = m_end; - } - - return found; -} - -/** - * xed_document_search_backward: - * @doc: - * @start: (allow-none): - * @end: (allow-none): - * @match_start: (allow-none): - * @match_end: (allow-none): - **/ -gboolean -xed_document_search_backward (XedDocument *doc, - const GtkTextIter *start, - const GtkTextIter *end, - GtkTextIter *match_start, - GtkTextIter *match_end) -{ - GtkTextIter iter; - GtkTextSearchFlags search_flags; - gboolean found = FALSE; - GtkTextIter m_start; - GtkTextIter m_end; - - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - g_return_val_if_fail ((start == NULL) || (gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc)), FALSE); - g_return_val_if_fail ((end == NULL) || (gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc)), FALSE); - - if (doc->priv->search_text == NULL) - { - xed_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == NULL\n"); - return FALSE; - } - else - { - xed_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == \"%s\"\n", doc->priv->search_text); - } - - if (end == NULL) - { - gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &iter); - } - else - { - iter = *end; - } - - search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY; - - if (!XED_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags)) - { - search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE; - } - - while (!found) - { - found = gtk_text_iter_backward_search (&iter, - doc->priv->search_text, - search_flags, - &m_start, - &m_end, - start); - - if (found && XED_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags)) - { - found = gtk_text_iter_starts_word (&m_start) && gtk_text_iter_ends_word (&m_end); - - if (!found) - { - iter = m_start; - } - } - else - { - break; - } - } - - if (found && (match_start != NULL)) - { - *match_start = m_start; - } - if (found && (match_end != NULL)) - { - *match_end = m_end; - } - - return found; -} - -/* FIXME this is an issue for introspection regardning @find */ -gint -xed_document_replace_all (XedDocument *doc, - const gchar *find, - const gchar *replace, - guint flags) -{ - GtkTextIter iter; - GtkTextIter m_start; - GtkTextIter m_end; - GtkTextSearchFlags search_flags = 0; - gboolean found = TRUE; - gint cont = 0; - gchar *search_text; - gchar *replace_text; - gint replace_text_len; - GtkTextBuffer *buffer; - gboolean brackets_highlighting; - gboolean search_highliting; - - g_return_val_if_fail (XED_IS_DOCUMENT (doc), 0); - g_return_val_if_fail (replace != NULL, 0); - g_return_val_if_fail ((find != NULL) || (doc->priv->search_text != NULL), 0); - - buffer = GTK_TEXT_BUFFER (doc); - - if (find == NULL) - { - search_text = g_strdup (doc->priv->search_text); - } - else - { - search_text = xed_utils_unescape_search_text (find); - } - - replace_text = xed_utils_unescape_search_text (replace); - - gtk_text_buffer_get_start_iter (buffer, &iter); - - search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY; - - if (!XED_SEARCH_IS_CASE_SENSITIVE (flags)) - { - search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE; - } - - replace_text_len = strlen (replace_text); - - /* disable cursor_moved emission until the end of the - * replace_all so that we don't spend all the time - * updating the position in the statusbar - */ - doc->priv->stop_cursor_moved_emission = TRUE; - - /* also avoid spending time matching brackets */ - brackets_highlighting = gtk_source_buffer_get_highlight_matching_brackets (GTK_SOURCE_BUFFER (buffer)); - gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (buffer), FALSE); - - /* and do search highliting later */ - search_highliting = xed_document_get_enable_search_highlighting (doc); - xed_document_set_enable_search_highlighting (doc, FALSE); - - gtk_text_buffer_begin_user_action (buffer); - - do - { - found = gtk_text_iter_forward_search (&iter, - search_text, - search_flags, - &m_start, - &m_end, - NULL); - - if (found && XED_SEARCH_IS_ENTIRE_WORD (flags)) - { - gboolean word; - - word = gtk_text_iter_starts_word (&m_start) && gtk_text_iter_ends_word (&m_end); - - if (!word) - { - iter = m_end; - continue; - } - } - - if (found) - { - ++cont; - - gtk_text_buffer_delete (buffer, &m_start, &m_end); - gtk_text_buffer_insert (buffer, &m_start, replace_text, replace_text_len); - - iter = m_start; - } - - } while (found); - - gtk_text_buffer_end_user_action (buffer); - - /* re-enable cursor_moved emission and notify - * the current position - */ - doc->priv->stop_cursor_moved_emission = FALSE; - emit_cursor_moved (doc); - - gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (buffer), brackets_highlighting); - xed_document_set_enable_search_highlighting (doc, search_highliting); - - g_free (search_text); - g_free (replace_text); - - return cont; -} - static void get_style_colors (XedDocument *doc, const gchar *style_name, @@ -2393,14 +1882,6 @@ sync_tag_style (XedDocument *doc, g_object_thaw_notify (G_OBJECT (tag)); } -static void -sync_found_tag (XedDocument *doc, - GParamSpec *pspec, - gpointer data) -{ - sync_tag_style (doc, doc->priv->found_tag, "search-match"); -} - static void text_tag_set_highest_priority (GtkTextTag *tag, GtkTextBuffer *buffer) @@ -2413,200 +1894,6 @@ text_tag_set_highest_priority (GtkTextTag *tag, gtk_text_tag_set_priority (tag, n - 1); } -static void -search_region (XedDocument *doc, - GtkTextIter *start, - GtkTextIter *end) -{ - GtkTextIter iter; - GtkTextIter m_start; - GtkTextIter m_end; - GtkTextSearchFlags search_flags = 0; - gboolean found = TRUE; - - GtkTextBuffer *buffer; - - xed_debug (DEBUG_DOCUMENT); - - buffer = GTK_TEXT_BUFFER (doc); - - if (doc->priv->found_tag == NULL) - { - doc->priv->found_tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (doc), "found", NULL); - - sync_found_tag (doc, NULL, NULL); - - g_signal_connect (doc, "notify::style-scheme", G_CALLBACK (sync_found_tag), NULL); - } - - /* make sure the 'found' tag has the priority over - * syntax highlighting tags */ - text_tag_set_highest_priority (doc->priv->found_tag, GTK_TEXT_BUFFER (doc)); - - - if (doc->priv->search_text == NULL) - { - return; - } - - g_return_if_fail (doc->priv->num_of_lines_search_text > 0); - - gtk_text_iter_backward_lines (start, doc->priv->num_of_lines_search_text); - gtk_text_iter_forward_lines (end, doc->priv->num_of_lines_search_text); - - if (gtk_text_iter_has_tag (start, doc->priv->found_tag) && - !gtk_text_iter_begins_tag (start, doc->priv->found_tag)) - { - gtk_text_iter_backward_to_tag_toggle (start, doc->priv->found_tag); - } - if (gtk_text_iter_has_tag (end, doc->priv->found_tag) && - !gtk_text_iter_ends_tag (end, doc->priv->found_tag)) - { - gtk_text_iter_forward_to_tag_toggle (end, doc->priv->found_tag); - } - /* - g_print ("[%u (%u), %u (%u)]\n", gtk_text_iter_get_line (start), gtk_text_iter_get_offset (start), - gtk_text_iter_get_line (end), gtk_text_iter_get_offset (end)); - */ - - gtk_text_buffer_remove_tag (buffer, doc->priv->found_tag, start, end); - - if (*doc->priv->search_text == '\0') - { - return; - } - - iter = *start; - - search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY; - - if (!XED_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags)) - { - search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE; - } - - do - { - if ((end != NULL) && gtk_text_iter_is_end (end)) - { - end = NULL; - } - - found = gtk_text_iter_forward_search (&iter, - doc->priv->search_text, - search_flags, - &m_start, - &m_end, - end); - - iter = m_end; - - if (found && XED_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags)) - { - gboolean word; - - word = gtk_text_iter_starts_word (&m_start) && gtk_text_iter_ends_word (&m_end); - - if (!word) - { - continue; - } - } - - if (found) - { - gtk_text_buffer_apply_tag (buffer, doc->priv->found_tag, &m_start, &m_end); - } - - } while (found); -} - -void -_xed_document_search_region (XedDocument *doc, - const GtkTextIter *start, - const GtkTextIter *end) -{ - XedTextRegion *region; - - xed_debug (DEBUG_DOCUMENT); - - g_return_if_fail (XED_IS_DOCUMENT (doc)); - g_return_if_fail (start != NULL); - g_return_if_fail (end != NULL); - - if (doc->priv->to_search_region == NULL) - { - return; - } - - /* - g_print ("U [%u (%u), %u (%u)]\n", gtk_text_iter_get_line (start), gtk_text_iter_get_offset (start), - gtk_text_iter_get_line (end), gtk_text_iter_get_offset (end)); - */ - - /* get the subregions not yet highlighted */ - region = xed_text_region_intersect (doc->priv->to_search_region, start, end); - if (region) - { - gint i; - GtkTextIter start_search; - GtkTextIter end_search; - - i = xed_text_region_subregions (region); - xed_text_region_nth_subregion (region, 0, &start_search, NULL); - xed_text_region_nth_subregion (region, i - 1, NULL, &end_search); - - xed_text_region_destroy (region, TRUE); - - gtk_text_iter_order (&start_search, &end_search); - - search_region (doc, &start_search, &end_search); - - /* remove the just highlighted region */ - xed_text_region_subtract (doc->priv->to_search_region, start, end); - } -} - -static void -insert_text_cb (XedDocument *doc, - GtkTextIter *pos, - const gchar *text, - gint length) -{ - GtkTextIter start; - GtkTextIter end; - - xed_debug (DEBUG_DOCUMENT); - - start = end = *pos; - - /* - * pos is invalidated when - * insertion occurs (because the buffer contents change), but the - * default signal handler revalidates it to point to the end of the - * inserted text - */ - gtk_text_iter_backward_chars (&start, g_utf8_strlen (text, length)); - - to_search_region_range (doc, &start, &end); -} - -static void -delete_range_cb (XedDocument *doc, - GtkTextIter *start, - GtkTextIter *end) -{ - GtkTextIter d_start; - GtkTextIter d_end; - - xed_debug (DEBUG_DOCUMENT); - - d_start = *start; - d_end = *end; - - to_search_region_range (doc, &d_start, &d_end); -} - /** * xed_document_set_language: * @doc: @@ -2657,58 +1944,6 @@ _xed_document_get_seconds_since_last_save_or_load (XedDocument *doc) return (current_time.tv_sec - doc->priv->time_of_last_save_or_load.tv_sec); } -void -xed_document_set_enable_search_highlighting (XedDocument *doc, - gboolean enable) -{ - g_return_if_fail (XED_IS_DOCUMENT (doc)); - - enable = enable != FALSE; - - if ((doc->priv->to_search_region != NULL) == enable) - { - return; - } - - if (doc->priv->to_search_region != NULL) - { - /* Disable search highlighting */ - if (doc->priv->found_tag != NULL) - { - /* If needed remove the found_tag */ - GtkTextIter begin; - GtkTextIter end; - - gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &begin, &end); - gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (doc), doc->priv->found_tag, &begin, &end); - } - - xed_text_region_destroy (doc->priv->to_search_region, TRUE); - doc->priv->to_search_region = NULL; - } - else - { - doc->priv->to_search_region = xed_text_region_new (GTK_TEXT_BUFFER (doc)); - if (xed_document_get_can_search_again (doc)) - { - /* If search_text is not empty, highligth all its occurrences */ - GtkTextIter begin; - GtkTextIter end; - - gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &begin, &end); - to_search_region_range (doc, &begin, &end); - } - } -} - -gboolean -xed_document_get_enable_search_highlighting (XedDocument *doc) -{ - g_return_val_if_fail (XED_IS_DOCUMENT (doc), FALSE); - - return (doc->priv->to_search_region != NULL); -} - void xed_document_set_newline_type (XedDocument *doc, XedDocumentNewlineType newline_type) @@ -2946,3 +2181,30 @@ _xed_document_apply_error_style (XedDocument *doc, gtk_text_buffer_apply_tag (buffer, doc->priv->error_tag, start, end); } + +void +_xed_document_set_search_context (XedDocument *doc, + GtkSourceSearchContext *search_context) +{ + g_return_if_fail (XED_IS_DOCUMENT (doc)); + + g_clear_object (&doc->priv->search_context); + doc->priv->search_context = search_context; + + if (search_context != NULL) + { + gboolean highlight = g_settings_get_boolean (doc->priv->editor_settings, XED_SETTINGS_SEARCH_HIGHLIGHTING); + + gtk_source_search_context_set_highlight (search_context, highlight); + + g_object_ref (search_context); + } +} + +GtkSourceSearchContext * +_xed_document_get_search_context (XedDocument *doc) +{ + g_return_val_if_fail (XED_IS_DOCUMENT (doc), NULL); + + return doc->priv->search_context; +} diff --git a/xed/xed-document.h b/xed/xed-document.h index a8d982f..4e4f207 100644 --- a/xed/xed-document.h +++ b/xed/xed-document.h @@ -64,15 +64,6 @@ typedef enum #define XED_DOCUMENT_NEWLINE_TYPE_DEFAULT XED_DOCUMENT_NEWLINE_TYPE_LF -typedef enum -{ - XED_SEARCH_DONT_SET_FLAGS = 1 << 0, - XED_SEARCH_ENTIRE_WORD = 1 << 1, - XED_SEARCH_CASE_SENSITIVE = 1 << 2, - XED_SEARCH_PARSE_ESCAPES = 1 << 3 - -} XedSearchFlags; - /** * XedDocumentSaveFlags: * @XED_DOCUMENT_SAVE_IGNORE_MTIME: save file despite external modifications. @@ -142,11 +133,6 @@ struct _XedDocumentClass void (* saved) (XedDocument *document, const GError *error); - - void (* search_highlight_updated) - (XedDocument *document, - GtkTextIter *start, - GtkTextIter *end); }; @@ -223,33 +209,6 @@ gboolean xed_document_goto_line_offset(XedDocument *doc, gint line, gint line_offset); -void xed_document_set_search_text (XedDocument *doc, - const gchar *text, - guint flags); - -gchar *xed_document_get_search_text (XedDocument *doc, - guint *flags); - -gboolean xed_document_get_can_search_again - (XedDocument *doc); - -gboolean xed_document_search_forward (XedDocument *doc, - const GtkTextIter *start, - const GtkTextIter *end, - GtkTextIter *match_start, - GtkTextIter *match_end); - -gboolean xed_document_search_backward (XedDocument *doc, - const GtkTextIter *start, - const GtkTextIter *end, - GtkTextIter *match_start, - GtkTextIter *match_end); - -gint xed_document_replace_all (XedDocument *doc, - const gchar *find, - const gchar *replace, - guint flags); - void xed_document_set_language (XedDocument *doc, GtkSourceLanguage *lang); GtkSourceLanguage @@ -258,13 +217,6 @@ GtkSourceLanguage const XedEncoding *xed_document_get_encoding (XedDocument *doc); -void xed_document_set_enable_search_highlighting - (XedDocument *doc, - gboolean enable); - -gboolean xed_document_get_enable_search_highlighting - (XedDocument *doc); - void xed_document_set_newline_type (XedDocument *doc, XedDocumentNewlineType newline_type); @@ -299,27 +251,6 @@ void _xed_document_apply_error_style (XedDocument *doc, gboolean _xed_document_check_externally_modified (XedDocument *doc); -void _xed_document_search_region (XedDocument *doc, - const GtkTextIter *start, - const GtkTextIter *end); - -/* Search macros */ -#define XED_SEARCH_IS_DONT_SET_FLAGS(sflags) ((sflags & XED_SEARCH_DONT_SET_FLAGS) != 0) -#define XED_SEARCH_SET_DONT_SET_FLAGS(sflags,state) ((state == TRUE) ? \ -(sflags |= XED_SEARCH_DONT_SET_FLAGS) : (sflags &= ~XED_SEARCH_DONT_SET_FLAGS)) - -#define XED_SEARCH_IS_ENTIRE_WORD(sflags) ((sflags & XED_SEARCH_ENTIRE_WORD) != 0) -#define XED_SEARCH_SET_ENTIRE_WORD(sflags,state) ((state == TRUE) ? \ -(sflags |= XED_SEARCH_ENTIRE_WORD) : (sflags &= ~XED_SEARCH_ENTIRE_WORD)) - -#define XED_SEARCH_IS_CASE_SENSITIVE(sflags) ((sflags & XED_SEARCH_CASE_SENSITIVE) != 0) -#define XED_SEARCH_SET_CASE_SENSITIVE(sflags,state) ((state == TRUE) ? \ -(sflags |= XED_SEARCH_CASE_SENSITIVE) : (sflags &= ~XED_SEARCH_CASE_SENSITIVE)) - -#define XED_SEARCH_IS_PARSE_ESCAPES(sflags) ((sflags & XED_SEARCH_PARSE_ESCAPES) != 0) -#define XED_SEARCH_SET_PARSE_ESCAPES(sflags,state) ((state == TRUE) ? \ -(sflags |= XED_SEARCH_PARSE_ESCAPES) : (sflags &= ~XED_SEARCH_PARSE_ESCAPES)) - typedef GMountOperation *(*XedMountOperationFactory)(XedDocument *doc, gpointer userdata); @@ -331,6 +262,11 @@ GMountOperation *_xed_document_create_mount_operation (XedDocument *doc); +void _xed_document_set_search_context (XedDocument *doc, + GtkSourceSearchContext *search_context); + +GtkSourceSearchContext *_xed_document_get_search_context (XedDocument *doc); + G_END_DECLS #endif /* __XED_DOCUMENT_H__ */ diff --git a/xed/xed-history-entry.c b/xed/xed-history-entry.c index d0d2605..7497faa 100644 --- a/xed/xed-history-entry.c +++ b/xed/xed-history-entry.c @@ -516,54 +516,3 @@ xed_history_entry_get_entry (XedHistoryEntry *entry) return gtk_bin_get_child (GTK_BIN (entry)); } - -static void -escape_cell_data_func (GtkTreeViewColumn *col, - GtkCellRenderer *renderer, - GtkTreeModel *model, - GtkTreeIter *iter, - XedHistoryEntryEscapeFunc escape_func) -{ - gchar *str; - gchar *escaped; - - gtk_tree_model_get (model, iter, 0, &str, -1); - escaped = escape_func (str); - g_object_set (renderer, "text", escaped, NULL); - - g_free (str); - g_free (escaped); -} - -void -xed_history_entry_set_escape_func (XedHistoryEntry *entry, - XedHistoryEntryEscapeFunc escape_func) -{ - GList *cells; - - g_return_if_fail (XED_IS_HISTORY_ENTRY (entry)); - - cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (entry)); - - /* We only have one cell renderer */ - g_return_if_fail (cells->data != NULL && cells->next == NULL); - - if (escape_func != NULL) - { - gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (entry), - GTK_CELL_RENDERER (cells->data), - (GtkCellLayoutDataFunc) escape_cell_data_func, - escape_func, - NULL); - } - else - { - gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (entry), - GTK_CELL_RENDERER (cells->data), - NULL, - NULL, - NULL); - } - - g_list_free (cells); -} diff --git a/xed/xed-history-entry.h b/xed/xed-history-entry.h index ef7447f..4ebe92b 100644 --- a/xed/xed-history-entry.h +++ b/xed/xed-history-entry.h @@ -80,10 +80,6 @@ gboolean xed_history_entry_get_enable_completion (XedHistoryEntry *entry); GtkWidget *xed_history_entry_get_entry (XedHistoryEntry *entry); -typedef gchar * (* XedHistoryEntryEscapeFunc) (const gchar *str); -void xed_history_entry_set_escape_func (XedHistoryEntry *entry, - XedHistoryEntryEscapeFunc escape_func); - G_END_DECLS #endif /* __XED_HISTORY_ENTRY_H__ */ diff --git a/xed/xed-searchbar.c b/xed/xed-searchbar.c index 1cd1e2e..ff6aca5 100755 --- a/xed/xed-searchbar.c +++ b/xed/xed-searchbar.c @@ -18,7 +18,13 @@ #define XED_SEARCHBAR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_SEARCHBAR, XedSearchbarPrivate)) -/* Signals */ +// typedef enum +// { +// SEARCH, +// REPLACE +// } SearchMode; + + enum { SHOW_REPLACE, @@ -37,6 +43,7 @@ struct _XedSearchbarPrivate GtkWidget *replace_label; GtkWidget *replace_entry; GtkWidget *replace_text_entry; + GtkWidget *regex_checkbutton; GtkWidget *match_case_checkbutton; GtkWidget *entire_word_checkbutton; GtkWidget *wrap_around_checkbutton; @@ -45,15 +52,38 @@ struct _XedSearchbarPrivate GtkWidget *replace_button; GtkWidget *replace_all_button; GtkWidget *close_button; + + GtkSourceSearchSettings *search_settings; + SearchMode search_mode; + + guint update_occurrence_count_id; }; G_DEFINE_TYPE(XedSearchbar, xed_searchbar, GTK_TYPE_BOX) +static void +xed_searchbar_dispose (GObject *object) +{ + XedSearchbar *searchbar = XED_SEARCHBAR (object); + + if (searchbar->priv->update_occurrence_count_id != 0) + { + g_source_remove (searchbar->priv->update_occurrence_count_id); + searchbar->priv->update_occurrence_count_id = 0; + } + + g_clear_object (&searchbar->priv->search_settings); + + G_OBJECT_CLASS (xed_searchbar_parent_class)->dispose (object); +} + static void xed_searchbar_class_init (XedSearchbarClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->dispose = xed_searchbar_dispose; + g_type_class_add_private (object_class, sizeof(XedSearchbarPrivate)); } @@ -91,130 +121,285 @@ text_found (XedWindow *window, } static void -text_not_found (XedWindow *window, - const gchar *text) +text_not_found (XedSearchbar *searchbar) { - gchar *searched; + const gchar *search_text; + gchar *truncated_text; - searched = xed_utils_str_end_truncate (text, MAX_MSG_LENGTH); - xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar), - window->priv->generic_message_cid, - _("\"%s\" not found"), searched); - g_free (searched); + search_text = xed_searchbar_get_search_text (searchbar); + truncated_text = xed_utils_str_end_truncate (search_text, MAX_MSG_LENGTH); + + xed_statusbar_flash_message (XED_STATUSBAR (searchbar->window->priv->statusbar), + searchbar->window->priv->generic_message_cid, + _("\"%s\" not found"), truncated_text); + + g_free (truncated_text); } static gboolean -run_search (XedView *view, - gboolean wrap_around, - gboolean search_backwards, - gboolean jump_to_next_result) +forward_search_finished (GtkSourceSearchContext *search_context, + GAsyncResult *result, + XedView *view) { - XedDocument *doc; - GtkTextIter start_iter; - GtkTextIter end_iter; + gboolean found; + GtkSourceBuffer *buffer; GtkTextIter match_start; GtkTextIter match_end; - gboolean found = FALSE; - doc = XED_DOCUMENT(gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); - gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &start_iter, &end_iter); - - if (!search_backwards) - { - if (jump_to_next_result) - { - found = xed_document_search_forward (doc, &end_iter, NULL, &match_start, &match_end); - } - else - { - found = xed_document_search_forward (doc, &start_iter, NULL, &match_start, &match_end); - } - } - else - { - found = xed_document_search_backward (doc, NULL, &start_iter, &match_start, &match_end); - } - - if (!found && wrap_around) - { - if (!search_backwards) - { - /* FIXME: set the end_inter */ - found = xed_document_search_forward (doc, NULL, NULL, &match_start, &match_end); - } - else - { - /* FIXME: set the start_inter */ - found = xed_document_search_backward (doc, NULL, NULL, &match_start, &match_end); - } - } + found = gtk_source_search_context_forward_finish (search_context, result, &match_start, &match_end, NULL); + buffer = gtk_source_search_context_get_buffer (search_context); if (found) { - gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &match_start); - gtk_text_buffer_move_mark_by_name (GTK_TEXT_BUFFER (doc), "selection_bound", &match_end); + gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &match_start, &match_end); xed_view_scroll_to_cursor (view); } else { - gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &start_iter); + GtkTextIter end_selection; + + gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer), NULL, &end_selection); + gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &end_selection, &end_selection); } return found; } +static void +run_forward_search (XedWindow *window, + gboolean jump_to_next_result) +{ + XedView *view; + GtkTextBuffer *buffer; + GtkTextIter start_at; + GtkTextIter end_at; + GtkSourceSearchContext *search_context; + + view = xed_window_get_active_view (window); + + if (view == NULL) + { + return; + } + + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); + search_context = _xed_document_get_search_context (XED_DOCUMENT (buffer)); + + if (search_context == NULL) + { + return; + } + + gtk_text_buffer_get_selection_bounds (buffer, &start_at, &end_at); + + if (jump_to_next_result) + { + gtk_source_search_context_forward_async (search_context, + &end_at, + NULL, + (GAsyncReadyCallback)forward_search_finished, + view); + } + else + { + gtk_source_search_context_forward_async (search_context, + &start_at, + NULL, + (GAsyncReadyCallback)forward_search_finished, + view); + } +} + +static gboolean +backward_search_finished (GtkSourceSearchContext *search_context, + GAsyncResult *result, + XedView *view) +{ + gboolean found; + GtkTextIter match_start; + GtkTextIter match_end; + GtkSourceBuffer *buffer; + + found = gtk_source_search_context_backward_finish (search_context, result, &match_start, &match_end, NULL); + buffer = gtk_source_search_context_get_buffer (search_context); + + if (found) + { + gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &match_start, &match_end); + xed_view_scroll_to_cursor (view); + } + else + { + GtkTextIter start_selection; + + gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer), &start_selection, NULL); + gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &start_selection, &start_selection); + } + + return found; +} + +static void +run_backward_search (XedWindow *window) +{ + XedView *view; + GtkTextBuffer *buffer; + GtkTextIter start_at; + GtkSourceSearchContext *search_context; + + view = xed_window_get_active_view (window); + + if (view == NULL) + { + return; + } + + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); + search_context = _xed_document_get_search_context (XED_DOCUMENT (buffer)); + + if (search_context == NULL) + { + return; + } + + gtk_text_buffer_get_selection_bounds (buffer, &start_at, NULL); + gtk_source_search_context_backward_async (search_context, + &start_at, + NULL, + (GAsyncReadyCallback)backward_search_finished, + view); +} + +static void +update_occurrence_count (XedSearchbar *searchbar) +{ + XedDocument *doc; + GtkSourceSearchContext *search_context; + GtkTextIter match_start; + GtkTextIter match_end; + gint count; + gint pos; + + if (searchbar->priv->search_mode == SEARCH_MODE_REPLACE) + { + return; + } + + searchbar->priv->update_occurrence_count_id = 0; + doc = xed_window_get_active_document (searchbar->window); + search_context = _xed_document_get_search_context (doc); + + if (search_context == NULL) + { + return; + } + + count = gtk_source_search_context_get_occurrences_count (search_context); + + gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &match_start, &match_end); + pos = gtk_source_search_context_get_occurrence_position (search_context, &match_start, &match_end); + + if (count == -1 || pos == -1) + { + /* Wait for the buffer to be fully scanned */ + return; + } + + if (count == 0) + { + xed_statusbar_flash_message (XED_STATUSBAR (searchbar->window->priv->statusbar), + searchbar->window->priv->generic_message_cid, + _("No matches found")); + return; + } + + if (pos == 0) + { + xed_statusbar_flash_message (XED_STATUSBAR (searchbar->window->priv->statusbar), + searchbar->window->priv->generic_message_cid, + ngettext ("%d match", "%d matches", count), count); + return; + } + + xed_statusbar_flash_message (XED_STATUSBAR (searchbar->window->priv->statusbar), + searchbar->window->priv->generic_message_cid, + ngettext ("%d of %d match", "%d of %d matches", + pos), + pos, count); +} + +static gboolean +update_occurrence_count_id_cb (XedSearchbar *searchbar) +{ + searchbar->priv->update_occurrence_count_id = 0; + update_occurrence_count (searchbar); + + return G_SOURCE_REMOVE; +} + +static void +install_occurrence_count_idle (XedSearchbar *searchbar) +{ + if (searchbar->priv->update_occurrence_count_id == 0) + { + searchbar->priv->update_occurrence_count_id = g_idle_add ((GSourceFunc)update_occurrence_count_id_cb, searchbar); + } +} + +static void +mark_set_cb (GtkTextBuffer *buffer, + GtkTextIter *location, + GtkTextMark *mark, + XedSearchbar *searchbar) +{ + GtkTextMark *insert; + GtkTextMark *selection_bound; + + insert = gtk_text_buffer_get_insert (buffer); + selection_bound = gtk_text_buffer_get_selection_bound (buffer); + + if (mark == insert || mark == selection_bound) + { + install_occurrence_count_idle (searchbar); + } +} + static void do_find (XedSearchbar *searchbar, gboolean search_backwards, gboolean jump_to_next_result) { - XedView *active_view; XedDocument *doc; - gchar *search_text; - const gchar *entry_text; - gboolean match_case; - gboolean entire_word; - gboolean wrap_around; - guint flags = 0; - guint old_flags = 0; - gboolean found; + GtkSourceSearchContext *search_context; + GtkSourceSearchSettings *search_settings; - /* TODO: make the searchbar insensitive when all the tabs are closed - * and assert here that the view is not NULL */ - active_view = xed_window_get_active_view (searchbar->window); - if (active_view == NULL) + search_settings = xed_searchbar_get_search_settings (searchbar); + doc = xed_window_get_active_document (searchbar->window); + search_context = _xed_document_get_search_context (doc); + searchbar->priv->search_mode = SEARCH_MODE_SEARCH; + + if (search_context == NULL || search_settings != gtk_source_search_context_get_settings (search_context)) { - return; + search_context = gtk_source_search_context_new (GTK_SOURCE_BUFFER (doc), search_settings); + + _xed_document_set_search_context (doc, search_context); + + g_signal_connect (GTK_TEXT_BUFFER (doc), "mark-set", + G_CALLBACK (mark_set_cb), searchbar); + + g_signal_connect_swapped (search_context, "notify::occurrences-count", + G_CALLBACK (install_occurrence_count_idle), searchbar); + + g_object_unref (search_context); } - doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view))); - - match_case = xed_searchbar_get_match_case (searchbar); - entire_word = xed_searchbar_get_entire_word (searchbar); - wrap_around = xed_searchbar_get_wrap_around (searchbar); - entry_text = xed_searchbar_get_search_text (searchbar); - - XED_SEARCH_SET_CASE_SENSITIVE (flags, match_case); - XED_SEARCH_SET_ENTIRE_WORD (flags, entire_word); - - search_text = xed_document_get_search_text (doc, &old_flags); - - if ((search_text == NULL) || (strcmp (search_text, entry_text) != 0) || (flags != old_flags)) + if (search_backwards) { - xed_document_set_search_text (doc, entry_text, flags); - } - - g_free (search_text); - - found = run_search (active_view, wrap_around, search_backwards, jump_to_next_result); - - if (found) - { - text_found (searchbar->window, 0); + run_backward_search (searchbar->window); } else { - text_not_found (searchbar->window, entry_text); + run_forward_search (searchbar->window, jump_to_next_result); } } @@ -222,21 +407,14 @@ void xed_searchbar_find_again (XedSearchbar *searchbar, gboolean backward) { - XedView *active_view; - gboolean wrap_around = TRUE; - gpointer data; - - active_view = xed_window_get_active_view (searchbar->window); - g_return_if_fail (active_view != NULL); - - data = g_object_get_data (G_OBJECT (searchbar->window), XED_SEARCHBAR_KEY); - - if (data != NULL) + if (backward) { - wrap_around = xed_searchbar_get_wrap_around (XED_SEARCHBAR (data)); + do_find (searchbar, TRUE, TRUE); + } + else + { + do_find (searchbar, FALSE, TRUE); } - - run_search (active_view, wrap_around, backward, TRUE); } static void @@ -279,69 +457,45 @@ get_selected_text (GtkTextBuffer *doc, return TRUE; } -static void -replace_selected_text (GtkTextBuffer *buffer, - const gchar *replace) -{ - g_return_if_fail (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)); - g_return_if_fail (replace != NULL); - - gtk_text_buffer_begin_user_action (buffer); - gtk_text_buffer_delete_selection (buffer, FALSE, TRUE); - gtk_text_buffer_insert_at_cursor (buffer, replace, strlen (replace)); - gtk_text_buffer_end_user_action (buffer); -} - static void do_replace (XedSearchbar *searchbar) { XedDocument *doc; - const gchar *search_entry_text; + GtkSourceSearchContext *search_context; const gchar *replace_entry_text; - gchar *unescaped_search_text; gchar *unescaped_replace_text; - gchar *selected_text = NULL; - gboolean match_case; + GtkTextIter start; + GtkTextIter end; doc = xed_window_get_active_document (searchbar->window); + if (doc == NULL) { return; } - search_entry_text = xed_searchbar_get_search_text (searchbar); - g_return_if_fail ((search_entry_text) != NULL); - g_return_if_fail ((*search_entry_text) != '\0'); + search_context = _xed_document_get_search_context (doc); + + if (search_context == NULL) + { + return; + } /* replace text may be "", we just delete */ replace_entry_text = xed_searchbar_get_replace_text (searchbar); g_return_if_fail ((replace_entry_text) != NULL); - unescaped_search_text = xed_utils_unescape_search_text (search_entry_text); + unescaped_replace_text = gtk_source_utils_unescape_search_text (replace_entry_text); + gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &start, &end); + searchbar->priv->search_mode = SEARCH_MODE_REPLACE; - get_selected_text (GTK_TEXT_BUFFER (doc), &selected_text, NULL); + gtk_source_search_context_replace (search_context, + &start, + &end, + unescaped_replace_text, + -1, + NULL); - match_case = xed_searchbar_get_match_case (searchbar); - - if ((selected_text == NULL) || - (match_case && (strcmp (selected_text, unescaped_search_text) != 0)) || - (!match_case && !g_utf8_caselessnmatch (selected_text, - unescaped_search_text, - strlen (selected_text), - strlen (unescaped_search_text)) != 0)) - { - do_find (searchbar, FALSE, TRUE ); - g_free (unescaped_search_text); - g_free (selected_text); - - return; - } - - unescaped_replace_text = xed_utils_unescape_search_text (replace_entry_text); - replace_selected_text (GTK_TEXT_BUFFER (doc), unescaped_replace_text); - - g_free (unescaped_search_text); - g_free (selected_text); g_free (unescaped_replace_text); do_find (searchbar, FALSE, TRUE); @@ -350,38 +504,35 @@ do_replace (XedSearchbar *searchbar) static void do_replace_all (XedSearchbar *searchbar) { - XedView *active_view; XedDocument *doc; - const gchar *search_entry_text; + GtkSourceSearchContext *search_context; const gchar *replace_entry_text; - gboolean match_case; - gboolean entire_word; - guint flags = 0; + gchar *unescaped_replace_text; gint count; - active_view = xed_window_get_active_view (searchbar->window); - if (active_view == NULL) + doc = xed_window_get_active_document (searchbar->window); + + if (doc == NULL) { return; } - doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view))); + search_context = _xed_document_get_search_context (doc); - search_entry_text = xed_searchbar_get_search_text (searchbar); - g_return_if_fail ((search_entry_text) != NULL); - g_return_if_fail ((*search_entry_text) != '\0'); + if (search_context == NULL) + { + return; + } /* replace text may be "", we just delete all occurrences */ replace_entry_text = xed_searchbar_get_replace_text (searchbar); g_return_if_fail ((replace_entry_text) != NULL); - match_case = xed_searchbar_get_match_case (searchbar); - entire_word = xed_searchbar_get_entire_word (searchbar); + unescaped_replace_text = gtk_source_utils_unescape_search_text (replace_entry_text); + count = gtk_source_search_context_replace_all (search_context, unescaped_replace_text, -1, NULL); + searchbar->priv->search_mode = SEARCH_MODE_REPLACE; - XED_SEARCH_SET_CASE_SENSITIVE (flags, match_case); - XED_SEARCH_SET_ENTIRE_WORD (flags, entire_word); - - count = xed_document_replace_all (doc, search_entry_text, replace_entry_text, flags); + g_free (unescaped_replace_text); if (count > 0) { @@ -389,49 +540,11 @@ do_replace_all (XedSearchbar *searchbar) } else { - text_not_found (searchbar->window, search_entry_text); + text_not_found (searchbar); } } -static void -insert_text_handler (GtkEditable *editable, - const gchar *text, - gint length, - gint *position, - gpointer data) -{ - static gboolean insert_text = FALSE; - gchar *escaped_text; - gint new_len; - - /* To avoid recursive behavior */ - if (insert_text) - { - return; - } - - escaped_text = xed_utils_escape_search_text (text); - - new_len = strlen (escaped_text); - - if (new_len == length) - { - g_free (escaped_text); - return; - } - - insert_text = TRUE; - - g_signal_stop_emission_by_name (editable, "insert_text"); - - gtk_editable_insert_text (editable, escaped_text, new_len, position); - - insert_text = FALSE; - - g_free (escaped_text); -} - static void search_text_entry_changed (GtkEditable *editable, XedSearchbar *searchbar) @@ -444,26 +557,38 @@ search_text_entry_changed (GtkEditable *editable, if (*search_string != '\0') { search_buttons_set_sensitive (searchbar, TRUE); - do_find (searchbar, FALSE, FALSE); } else { search_buttons_set_sensitive (searchbar, FALSE); - do_find (searchbar, FALSE, FALSE); } + + if (gtk_source_search_settings_get_regex_enabled (searchbar->priv->search_settings)) + { + gtk_source_search_settings_set_search_text (searchbar->priv->search_settings, search_string); + } + else + { + gchar *unescaped_search_string; + + unescaped_search_string = gtk_source_utils_unescape_search_text (search_string); + gtk_source_search_settings_set_search_text (searchbar->priv->search_settings, unescaped_search_string); + + g_free (unescaped_search_string); + } + + do_find (searchbar, FALSE, FALSE); } static void remember_search_entry (XedSearchbar *searchbar) { const gchar *str; + str = gtk_entry_get_text (GTK_ENTRY(searchbar->priv->search_text_entry)); if (*str != '\0') { - gchar *text; - text = xed_utils_unescape_search_text (str); - xed_history_entry_prepend_text (XED_HISTORY_ENTRY(searchbar->priv->search_entry), text); - g_free (text); + xed_history_entry_prepend_text (XED_HISTORY_ENTRY (searchbar->priv->search_entry), str); } } @@ -471,13 +596,11 @@ static void remember_replace_entry (XedSearchbar *searchbar) { const gchar *str; + str = gtk_entry_get_text (GTK_ENTRY(searchbar->priv->replace_text_entry)); if (*str != '\0') { - gchar *text; - text = xed_utils_unescape_search_text (str); - xed_history_entry_prepend_text (XED_HISTORY_ENTRY(searchbar->priv->replace_entry), text); - g_free (text); + xed_history_entry_prepend_text (XED_HISTORY_ENTRY(searchbar->priv->replace_entry), str); } } @@ -561,6 +684,7 @@ xed_searchbar_init (XedSearchbar *searchbar) "grid", &searchbar->priv->grid, "search_label", &searchbar->priv->search_label, "replace_with_label", &searchbar->priv->replace_label, + "regex_checkbutton", &searchbar->priv->regex_checkbutton, "match_case_checkbutton", &searchbar->priv->match_case_checkbutton, "entire_word_checkbutton", &searchbar->priv->entire_word_checkbutton, "wrap_around_checkbutton", &searchbar->priv->wrap_around_checkbutton, @@ -574,10 +698,8 @@ xed_searchbar_init (XedSearchbar *searchbar) gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (searchbar)), "xed-searchbar"); - searchbar->priv->search_entry = xed_history_entry_new ("history-search-for", TRUE); + searchbar->priv->search_entry = xed_history_entry_new ("history-search-for", FALSE); gtk_widget_set_hexpand (searchbar->priv->search_entry, TRUE); - xed_history_entry_set_escape_func (XED_HISTORY_ENTRY (searchbar->priv->search_entry), - (XedHistoryEntryEscapeFunc) xed_utils_escape_search_text); searchbar->priv->search_text_entry = xed_history_entry_get_entry (XED_HISTORY_ENTRY (searchbar->priv->search_entry)); gtk_entry_set_activates_default (GTK_ENTRY (searchbar->priv->search_text_entry), TRUE); @@ -585,9 +707,7 @@ xed_searchbar_init (XedSearchbar *searchbar) gtk_widget_show (searchbar->priv->search_entry); gtk_grid_attach (GTK_GRID (searchbar->priv->grid), searchbar->priv->search_entry, 2, 0, 1, 1); - searchbar->priv->replace_entry = xed_history_entry_new ("history-replace-with", TRUE); - xed_history_entry_set_escape_func (XED_HISTORY_ENTRY (searchbar->priv->replace_entry), - (XedHistoryEntryEscapeFunc) xed_utils_escape_search_text); + searchbar->priv->replace_entry = xed_history_entry_new ("history-replace-with", FALSE); searchbar->priv->replace_text_entry = xed_history_entry_get_entry ( XED_HISTORY_ENTRY (searchbar->priv->replace_entry)); @@ -620,12 +740,6 @@ xed_searchbar_init (XedSearchbar *searchbar) g_object_unref (content); - g_signal_connect (searchbar->priv->search_text_entry, "insert_text", - G_CALLBACK (insert_text_handler), NULL); - - g_signal_connect (searchbar->priv->replace_text_entry, "insert_text", - G_CALLBACK (insert_text_handler), NULL); - g_signal_connect (searchbar->priv->search_text_entry, "changed", G_CALLBACK (search_text_entry_changed), searchbar); @@ -653,27 +767,45 @@ xed_searchbar_init (XedSearchbar *searchbar) g_signal_connect (searchbar->priv->match_case_checkbutton, "clicked", G_CALLBACK (toggle_button_clicked_callback), searchbar); + + searchbar->priv->search_settings = gtk_source_search_settings_new (); + + g_object_bind_property (searchbar->priv->regex_checkbutton, "active", + searchbar->priv->search_settings, "regex-enabled", + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + + g_object_bind_property (searchbar->priv->match_case_checkbutton, "active", + searchbar->priv->search_settings, "case-sensitive", + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + + g_object_bind_property (searchbar->priv->entire_word_checkbutton, "active", + searchbar->priv->search_settings, "at-word-boundaries", + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + + g_object_bind_property (searchbar->priv->wrap_around_checkbutton, "active", + searchbar->priv->search_settings, "wrap-around", + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); } GtkWidget * -xed_searchbar_new (GtkWindow *parent, - gboolean show_replace) +xed_searchbar_new (GtkWindow *parent) { XedSearchbar *searchbar; + searchbar = g_object_new (XED_TYPE_SEARCHBAR, NULL); searchbar->window = XED_WINDOW (parent); + return GTK_WIDGET (searchbar); } void xed_searchbar_show (XedSearchbar *searchbar, - gboolean show_replace) + SearchMode search_mode) { XedDocument *doc; gboolean selection_exists; gchar *find_text = NULL; - const gchar *search_text = NULL; - gint sel_len; + gint sel_len = 0; doc = xed_window_get_active_document (searchbar->window); g_return_if_fail (doc != NULL); @@ -682,28 +814,28 @@ xed_searchbar_show (XedSearchbar *searchbar, if (selection_exists && find_text != NULL && sel_len < 80) { - /* - * Special case: if the currently selected text - * is the same as the unescaped search text, use the - * same old search text. (Without this, if you e.g. - * search for '\n' and then open the search searchbar again, - * you'll get an unprintable single-character literal '\n' in the "search for" box). - */ - search_text = xed_searchbar_get_search_text (XED_SEARCHBAR (searchbar)); - if (!(search_text != NULL && !strcmp (xed_utils_unescape_search_text (search_text), find_text))) + gchar *escaped_find_text; + + if (gtk_source_search_settings_get_regex_enabled (searchbar->priv->search_settings)) { - /* General case */ - xed_searchbar_set_search_text (XED_SEARCHBAR (searchbar), find_text); + escaped_find_text = g_regex_escape_string (find_text, -1); } - g_free (find_text); - } - else - { - g_free (find_text); + else + { + escaped_find_text = gtk_source_utils_escape_search_text (find_text); + } + + xed_searchbar_set_search_text (XED_SEARCHBAR (searchbar), escaped_find_text); + + g_free (escaped_find_text); } + + g_free (find_text); + gtk_revealer_set_transition_type (GTK_REVEALER (searchbar->priv->revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP); gtk_revealer_set_reveal_child (GTK_REVEALER (searchbar->priv->revealer), TRUE); - if (show_replace) + + if (search_mode == SEARCH_MODE_REPLACE) { gtk_widget_show (searchbar->priv->replace_label); gtk_widget_show (searchbar->priv->replace_entry); @@ -734,6 +866,7 @@ xed_searchbar_hide (XedSearchbar *searchbar) // focus document active_view = xed_window_get_active_view (searchbar->window); + if (active_view != NULL) { gtk_widget_grab_focus (GTK_WIDGET (active_view)); @@ -743,84 +876,35 @@ xed_searchbar_hide (XedSearchbar *searchbar) _xed_cmd_search_clear_highlight (searchbar->window); } -void -xed_searchbar_set_search_text (XedSearchbar *searchbar, - const gchar *text) -{ - g_return_if_fail (XED_IS_SEARCHBAR (searchbar)); - g_return_if_fail (text != NULL); - gtk_entry_set_text (GTK_ENTRY (searchbar->priv->search_text_entry), text); - search_buttons_set_sensitive (searchbar, (text != '\0')); -} - -/* - * The text must be unescaped before searching. - */ -const gchar * -xed_searchbar_get_search_text (XedSearchbar *searchbar) -{ - g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), NULL); - return gtk_entry_get_text (GTK_ENTRY (searchbar->priv->search_text_entry)); -} - -void -xed_searchbar_set_replace_text (XedSearchbar *searchbar, - const gchar *text) -{ - g_return_if_fail (XED_IS_SEARCHBAR (searchbar)); - g_return_if_fail (text != NULL); - - gtk_entry_set_text (GTK_ENTRY (searchbar->priv->replace_text_entry), text); -} - const gchar * xed_searchbar_get_replace_text (XedSearchbar *searchbar) { g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), NULL); + return gtk_entry_get_text (GTK_ENTRY (searchbar->priv->replace_text_entry)); } -void -xed_searchbar_set_match_case (XedSearchbar *searchbar, - gboolean match_case) +GtkSourceSearchSettings * +xed_searchbar_get_search_settings (XedSearchbar *searchbar) { - g_return_if_fail (XED_IS_SEARCHBAR (searchbar)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (searchbar->priv->match_case_checkbutton), match_case); + g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), NULL); + + return searchbar->priv->search_settings; } -gboolean -xed_searchbar_get_match_case (XedSearchbar *searchbar) +const gchar * +xed_searchbar_get_search_text (XedSearchbar *searchbar) { - g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), FALSE); - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (searchbar->priv->match_case_checkbutton)); + g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), NULL); + + return gtk_entry_get_text (GTK_ENTRY (searchbar->priv->search_text_entry)); } void -xed_searchbar_set_entire_word (XedSearchbar *searchbar, - gboolean entire_word) +xed_searchbar_set_search_text (XedSearchbar *searchbar, + const gchar *search_text) { g_return_if_fail (XED_IS_SEARCHBAR (searchbar)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (searchbar->priv->entire_word_checkbutton), entire_word); -} -gboolean -xed_searchbar_get_entire_word (XedSearchbar *searchbar) -{ - g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), FALSE); - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (searchbar->priv->entire_word_checkbutton)); -} - -void -xed_searchbar_set_wrap_around (XedSearchbar *searchbar, - gboolean wrap_around) -{ - g_return_if_fail (XED_IS_SEARCHBAR (searchbar)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (searchbar->priv->wrap_around_checkbutton), wrap_around); -} - -gboolean -xed_searchbar_get_wrap_around (XedSearchbar *searchbar) -{ - g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), FALSE); - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (searchbar->priv->wrap_around_checkbutton)); + gtk_entry_set_text (GTK_ENTRY (searchbar->priv->search_text_entry), search_text); } diff --git a/xed/xed-searchbar.h b/xed/xed-searchbar.h index 13b125d..a4d92e6 100755 --- a/xed/xed-searchbar.h +++ b/xed/xed-searchbar.h @@ -3,6 +3,7 @@ #define __XED_SEARCHBAR_H__ #include +#include #include "xed-window.h" G_BEGIN_DECLS @@ -36,38 +37,29 @@ struct _XedSearchbarClass gboolean (* show_replace) (XedSearchbar *dlg); }; -enum +typedef enum { - XED_SEARCHBAR_FIND_RESPONSE = 100, - XED_SEARCHBAR_REPLACE_RESPONSE, - XED_SEARCHBAR_REPLACE_ALL_RESPONSE -}; + SEARCH_MODE_SEARCH, + SEARCH_MODE_REPLACE +} SearchMode; GType xed_searchbar_get_type (void) G_GNUC_CONST; -GtkWidget *xed_searchbar_new (GtkWindow *parent, gboolean show_replace); +GtkWidget *xed_searchbar_new (GtkWindow *parent); void xed_searchbar_hide (XedSearchbar *searchbar); -void xed_searchbar_show (XedSearchbar *searchbar, gboolean show_replace); -void xed_searchbar_find_again (XedSearchbar *searchbar, gboolean backward); +void xed_searchbar_show (XedSearchbar *searchbar, SearchMode search_mode); +void xed_searchbar_find_again (XedSearchbar *searchbar, gboolean backward); -void xed_searchbar_set_search_text (XedSearchbar *searchbar, const gchar *text); -const gchar *xed_searchbar_get_search_text (XedSearchbar *searchbar); - -void xed_searchbar_set_replace_text (XedSearchbar *searchbar, const gchar *text); const gchar *xed_searchbar_get_replace_text (XedSearchbar *searchbar); +const gchar *xed_searchbar_get_search_text (XedSearchbar *searchbar); -void xed_searchbar_set_match_case (XedSearchbar *searchbar, gboolean match_case); -gboolean xed_searchbar_get_match_case (XedSearchbar *searchbar); - -void xed_searchbar_set_entire_word (XedSearchbar *searchbar, gboolean entire_word); -gboolean xed_searchbar_get_entire_word (XedSearchbar *searchbar); - -void xed_searchbar_set_backwards (XedSearchbar *searchbar, gboolean backwards); gboolean xed_searchbar_get_backwards (XedSearchbar *searchbar); -void xed_searchbar_set_wrap_around (XedSearchbar *searchbar, gboolean wrap_around); -gboolean xed_searchbar_get_wrap_around (XedSearchbar *searchbar); +GtkSourceSearchSettings *xed_searchbar_get_search_settings (XedSearchbar *searchbar); + +void xed_searchbar_set_search_text (XedSearchbar *searchbar, + const gchar *search_text); void xed_searchbar_set_parse_escapes (XedSearchbar *searchbar, gboolean parse_escapes); gboolean xed_searchbar_get_parse_escapes (XedSearchbar *searchbar); diff --git a/xed/xed-searchbar.ui b/xed/xed-searchbar.ui index 948001b..0ecddef 100755 --- a/xed/xed-searchbar.ui +++ b/xed/xed-searchbar.ui @@ -112,6 +112,26 @@ True False + + + True + True + True + Regular expression + + + True + False + xapp-use-regex-symbolic + + + + + False + True + 0 + + True @@ -130,7 +150,7 @@ False False - 0 + 1 @@ -151,7 +171,7 @@ False False - 1 + 2 @@ -172,7 +192,7 @@ False True - 2 + 3 + + + True + False + horizontal + + + True + True + 25 + + + + + + + + + + diff --git a/xed/resources/xed.gresource.xml b/xed/resources/xed.gresource.xml new file mode 100644 index 0000000..f960a0d --- /dev/null +++ b/xed/resources/xed.gresource.xml @@ -0,0 +1,11 @@ + + + + ui/xed-ui.xml + ui/xed-encodings-dialog.ui + ui/xed-preferences-dialog.ui + ui/xed-print-preferences.ui + ui/xed-searchbar.ui + ui/xed-view-frame.ui + + \ No newline at end of file diff --git a/xed/xed-encodings-dialog.c b/xed/xed-encodings-dialog.c index 1be461c..babc2f0 100755 --- a/xed/xed-encodings-dialog.c +++ b/xed/xed-encodings-dialog.c @@ -322,14 +322,12 @@ init_liststore_available (XedEncodingsDialog *dialog) static void xed_encodings_dialog_init (XedEncodingsDialog *dlg) { + GtkBuilder *builder; GtkWidget *content; GtkCellRenderer *cell_renderer; GtkTreeModel *sort_model; GtkTreeViewColumn *column; GtkTreeSelection *selection; - GtkWidget *error_widget; - gboolean ret; - gchar *file; gchar *root_objects[] = { "encodings-dialog-contents", NULL @@ -355,27 +353,16 @@ xed_encodings_dialog_init (XedEncodingsDialog *dlg) g_signal_connect (dlg, "response", G_CALLBACK (response_handler), dlg); - file = xed_dirs_get_ui_file ("xed-encodings-dialog.ui"); - ret = xed_utils_get_ui_objects (file, - root_objects, - &error_widget, - "encodings-dialog-contents", &content, - "add-button", &dlg->priv->add_button, - "remove-button", &dlg->priv->remove_button, - "available-treeview", &dlg->priv->available_treeview, - "displayed-treeview", &dlg->priv->displayed_treeview, - NULL); - g_free (file); - - if (!ret) - { - gtk_widget_show (error_widget); - - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), error_widget, TRUE, TRUE, 0); - gtk_container_set_border_width (GTK_CONTAINER (error_widget), 5); - - return; - } + builder = gtk_builder_new (); + gtk_builder_add_objects_from_resource (builder, "/org/x/editor/ui/xed-encodings-dialog.ui", + root_objects, NULL); + content = GTK_WIDGET (gtk_builder_get_object (builder, "encodings-dialog-contents")); + g_object_ref (content); + dlg->priv->add_button = GTK_WIDGET (gtk_builder_get_object (builder, "add-button")); + dlg->priv->remove_button = GTK_WIDGET (gtk_builder_get_object (builder, "remove-button")); + dlg->priv->available_treeview = GTK_WIDGET (gtk_builder_get_object (builder, "available-treeview")); + dlg->priv->displayed_treeview = GTK_WIDGET (gtk_builder_get_object (builder, "displayed-treeview")); + g_object_unref (builder); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), content, TRUE, TRUE, 0); g_object_unref (content); diff --git a/xed/xed-preferences-dialog.c b/xed/xed-preferences-dialog.c index 1038d8c..0046c4a 100755 --- a/xed/xed-preferences-dialog.c +++ b/xed/xed-preferences-dialog.c @@ -1070,15 +1070,12 @@ setup_plugins_page (XedPreferencesDialog *dlg) static void xed_preferences_dialog_init (XedPreferencesDialog *dlg) { - GtkWidget *error_widget; - gboolean ret; - gchar *file; + GtkBuilder *builder; gchar *root_objects[] = { "notebook", "adjustment1", "adjustment2", "adjustment3", - "install_scheme_image", NULL }; @@ -1106,52 +1103,35 @@ xed_preferences_dialog_init (XedPreferencesDialog *dlg) g_signal_connect (dlg, "response", G_CALLBACK (dialog_response_handler), NULL); - file = xed_dirs_get_ui_file ("xed-preferences-dialog.ui"); - ret = xed_utils_get_ui_objects (file, root_objects, &error_widget, - "notebook", &dlg->priv->notebook, - - "display_line_numbers_checkbutton", &dlg->priv->display_line_numbers_checkbutton, - "highlight_current_line_checkbutton", &dlg->priv->highlight_current_line_checkbutton, - "bracket_matching_checkbutton", &dlg->priv->bracket_matching_checkbutton, - "wrap_text_checkbutton", &dlg->priv->wrap_text_checkbutton, - "split_checkbutton", &dlg->priv->split_checkbutton, - - "right_margin_checkbutton", &dlg->priv->right_margin_checkbutton, - "right_margin_position_spinbutton", &dlg->priv->right_margin_position_spinbutton, - "right_margin_position_hbox", &dlg->priv->right_margin_position_hbox, - - "tabs_width_spinbutton", &dlg->priv->tabs_width_spinbutton, - "tabs_width_hbox", &dlg->priv->tabs_width_hbox, - "insert_spaces_checkbutton", &dlg->priv->insert_spaces_checkbutton, - - "auto_indent_checkbutton", &dlg->priv->auto_indent_checkbutton, - - "autosave_hbox", &dlg->priv->autosave_hbox, - "backup_copy_checkbutton", &dlg->priv->backup_copy_checkbutton, - "auto_save_checkbutton", &dlg->priv->auto_save_checkbutton, - "auto_save_spinbutton", &dlg->priv->auto_save_spinbutton, - - "tab_scrolling_checkbutton", &dlg->priv->tab_scrolling_checkbutton, - - "default_font_checkbutton", &dlg->priv->default_font_checkbutton, - "font_button", &dlg->priv->font_button, - "font_hbox", &dlg->priv->font_hbox, - - "schemes_treeview", &dlg->priv->schemes_treeview, - "install_scheme_button", &dlg->priv->install_scheme_button, - "uninstall_scheme_button", &dlg->priv->uninstall_scheme_button, - - "plugin_manager_place_holder", &dlg->priv->plugin_manager_place_holder, - - NULL); - g_free (file); - - if (!ret) - { - gtk_widget_show (error_widget); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), error_widget, TRUE, TRUE, 0); - return; - } + builder = gtk_builder_new (); + gtk_builder_add_objects_from_resource (builder, "/org/x/editor/ui/xed-preferences-dialog.ui", root_objects, NULL); + dlg->priv->notebook = GTK_WIDGET (gtk_builder_get_object (builder, "notebook")); + g_object_ref (dlg->priv->notebook); + dlg->priv->display_line_numbers_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "display_line_numbers_checkbutton")); + dlg->priv->highlight_current_line_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "highlight_current_line_checkbutton")); + dlg->priv->bracket_matching_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "bracket_matching_checkbutton")); + dlg->priv->wrap_text_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "wrap_text_checkbutton")); + dlg->priv->split_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "split_checkbutton")); + dlg->priv->right_margin_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "right_margin_checkbutton")); + dlg->priv->right_margin_position_spinbutton = GTK_WIDGET (gtk_builder_get_object (builder, "right_margin_position_spinbutton")); + dlg->priv->right_margin_position_hbox = GTK_WIDGET (gtk_builder_get_object (builder, "right_margin_position_hbox")); + dlg->priv->tabs_width_spinbutton = GTK_WIDGET (gtk_builder_get_object (builder, "tabs_width_spinbutton")); + dlg->priv->tabs_width_hbox = GTK_WIDGET (gtk_builder_get_object (builder, "tabs_width_hbox")); + dlg->priv->insert_spaces_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "insert_spaces_checkbutton")); + dlg->priv->auto_indent_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "auto_indent_checkbutton")); + dlg->priv->autosave_hbox = GTK_WIDGET (gtk_builder_get_object (builder, "autosave_hbox")); + dlg->priv->backup_copy_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "backup_copy_checkbutton")); + dlg->priv->auto_save_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "auto_save_checkbutton")); + dlg->priv->auto_save_spinbutton = GTK_WIDGET (gtk_builder_get_object (builder, "auto_save_spinbutton")); + dlg->priv->tab_scrolling_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "tab_scrolling_checkbutton")); + dlg->priv->default_font_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "default_font_checkbutton")); + dlg->priv->font_button = GTK_WIDGET (gtk_builder_get_object (builder, "font_button")); + dlg->priv->font_hbox = GTK_WIDGET (gtk_builder_get_object (builder, "font_hbox")); + dlg->priv->schemes_treeview = GTK_WIDGET (gtk_builder_get_object (builder, "schemes_treeview")); + dlg->priv->install_scheme_button = GTK_WIDGET (gtk_builder_get_object (builder, "install_scheme_button")); + dlg->priv->uninstall_scheme_button = GTK_WIDGET (gtk_builder_get_object (builder, "uninstall_scheme_button")); + dlg->priv->plugin_manager_place_holder = GTK_WIDGET (gtk_builder_get_object (builder, "plugin_manager_place_holder")); + g_object_unref (builder); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), dlg->priv->notebook, FALSE, FALSE, 0); g_object_unref (dlg->priv->notebook); diff --git a/xed/xed-print-job.c b/xed/xed-print-job.c index 5963b2b..e76d0d8 100644 --- a/xed/xed-print-job.c +++ b/xed/xed-print-job.c @@ -46,62 +46,62 @@ #define XED_PRINT_JOB_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ - XED_TYPE_PRINT_JOB, \ - XedPrintJobPrivate)) + XED_TYPE_PRINT_JOB, \ + XedPrintJobPrivate)) struct _XedPrintJobPrivate { - GSettings *print_settings; + GSettings *print_settings; - XedView *view; - XedDocument *doc; + XedView *view; + XedDocument *doc; - GtkPrintOperation *operation; - GtkSourcePrintCompositor *compositor; + GtkPrintOperation *operation; + GtkSourcePrintCompositor *compositor; - GtkPrintSettings *settings; + GtkPrintSettings *settings; - GtkWidget *preview; + GtkWidget *preview; - XedPrintJobStatus status; + XedPrintJobStatus status; - gchar *status_string; + gchar *status_string; - gdouble progress; + gdouble progress; - gboolean is_preview; + gboolean is_preview; - /* widgets part of the custom print preferences widget. - * These pointers are valid just when the dialog is displayed */ - GtkWidget *syntax_checkbutton; - GtkWidget *page_header_checkbutton; - GtkWidget *line_numbers_checkbutton; - GtkWidget *line_numbers_hbox; - GtkWidget *line_numbers_spinbutton; - GtkWidget *text_wrapping_checkbutton; - GtkWidget *do_not_split_checkbutton; - GtkWidget *fonts_table; - GtkWidget *body_font_label; - GtkWidget *headers_font_label; - GtkWidget *numbers_font_label; - GtkWidget *body_fontbutton; - GtkWidget *headers_fontbutton; - GtkWidget *numbers_fontbutton; - GtkWidget *restore_button; + /* widgets part of the custom print preferences widget. + * These pointers are valid just when the dialog is displayed */ + GtkWidget *syntax_checkbutton; + GtkWidget *page_header_checkbutton; + GtkWidget *line_numbers_checkbutton; + GtkWidget *line_numbers_hbox; + GtkWidget *line_numbers_spinbutton; + GtkWidget *text_wrapping_checkbutton; + GtkWidget *do_not_split_checkbutton; + GtkWidget *fonts_table; + GtkWidget *body_font_label; + GtkWidget *headers_font_label; + GtkWidget *numbers_font_label; + GtkWidget *body_fontbutton; + GtkWidget *headers_fontbutton; + GtkWidget *numbers_fontbutton; + GtkWidget *restore_button; }; enum { - PROP_0, - PROP_VIEW + PROP_0, + PROP_VIEW }; enum { - PRINTING, - SHOW_PREVIEW, - DONE, - LAST_SIGNAL + PRINTING, + SHOW_PREVIEW, + DONE, + LAST_SIGNAL }; static guint print_job_signals[LAST_SIGNAL] = { 0 }; @@ -109,64 +109,69 @@ static guint print_job_signals[LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE (XedPrintJob, xed_print_job, G_TYPE_OBJECT) static void -set_view (XedPrintJob *job, XedView *view) +set_view (XedPrintJob *job, + XedView *view) { - job->priv->view = view; - job->priv->doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); + job->priv->view = view; + job->priv->doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); } static void xed_print_job_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { - XedPrintJob *job = XED_PRINT_JOB (object); + XedPrintJob *job = XED_PRINT_JOB (object); - switch (prop_id) - { - case PROP_VIEW: - g_value_set_object (value, job->priv->view); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_VIEW: + g_value_set_object (value, job->priv->view); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_print_job_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - XedPrintJob *job = XED_PRINT_JOB (object); + XedPrintJob *job = XED_PRINT_JOB (object); - switch (prop_id) - { - case PROP_VIEW: - set_view (job, g_value_get_object (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + switch (prop_id) + { + case PROP_VIEW: + set_view (job, g_value_get_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void xed_print_job_finalize (GObject *object) { - XedPrintJob *job = XED_PRINT_JOB (object); + XedPrintJob *job = XED_PRINT_JOB (object); - g_free (job->priv->status_string); + g_free (job->priv->status_string); - if (job->priv->compositor != NULL) - g_object_unref (job->priv->compositor); + if (job->priv->compositor != NULL) + { + g_object_unref (job->priv->compositor); + } - if (job->priv->operation != NULL) - g_object_unref (job->priv->operation); + if (job->priv->operation != NULL) + { + g_object_unref (job->priv->operation); + } - G_OBJECT_CLASS (xed_print_job_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_print_job_parent_class)->finalize (object); } static void @@ -182,101 +187,95 @@ xed_print_job_dispose (GObject *object) static void xed_print_job_class_init (XedPrintJobClass *klass) { - GObjectClass *object_class; + GObjectClass *object_class; - object_class = G_OBJECT_CLASS (klass); + object_class = G_OBJECT_CLASS (klass); - object_class->get_property = xed_print_job_get_property; - object_class->set_property = xed_print_job_set_property; - object_class->finalize = xed_print_job_finalize; + object_class->get_property = xed_print_job_get_property; + object_class->set_property = xed_print_job_set_property; + object_class->finalize = xed_print_job_finalize; object_class->dispose = xed_print_job_dispose; - g_object_class_install_property (object_class, - PROP_VIEW, - g_param_spec_object ("view", - "Xed View", - "Xed View to print", - XED_TYPE_VIEW, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS | - G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, + PROP_VIEW, + g_param_spec_object ("view", + "Xed View", + "Xed View to print", + XED_TYPE_VIEW, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS | + G_PARAM_CONSTRUCT_ONLY)); - print_job_signals[PRINTING] = - g_signal_new ("printing", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedPrintJobClass, printing), - NULL, NULL, - g_cclosure_marshal_VOID__UINT, - G_TYPE_NONE, - 1, - G_TYPE_UINT); + print_job_signals[PRINTING] = + g_signal_new ("printing", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedPrintJobClass, printing), + NULL, NULL, + g_cclosure_marshal_VOID__UINT, + G_TYPE_NONE, + 1, + G_TYPE_UINT); - print_job_signals[SHOW_PREVIEW] = - g_signal_new ("show-preview", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedPrintJobClass, show_preview), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - GTK_TYPE_WIDGET); + print_job_signals[SHOW_PREVIEW] = + g_signal_new ("show-preview", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedPrintJobClass, show_preview), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, + GTK_TYPE_WIDGET); - print_job_signals[DONE] = - g_signal_new ("done", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedPrintJobClass, done), - NULL, NULL, - xed_marshal_VOID__UINT_POINTER, - G_TYPE_NONE, - 2, - G_TYPE_UINT, - G_TYPE_POINTER); + print_job_signals[DONE] = + g_signal_new ("done", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedPrintJobClass, done), + NULL, NULL, + xed_marshal_VOID__UINT_POINTER, + G_TYPE_NONE, + 2, + G_TYPE_UINT, + G_TYPE_POINTER); - g_type_class_add_private (object_class, sizeof (XedPrintJobPrivate)); + g_type_class_add_private (object_class, sizeof (XedPrintJobPrivate)); } static void line_numbers_checkbutton_toggled (GtkToggleButton *button, - XedPrintJob *job) + XedPrintJob *job) { - gtk_widget_set_sensitive (job->priv->line_numbers_hbox, gtk_toggle_button_get_active (button)); + gtk_widget_set_sensitive (job->priv->line_numbers_hbox, gtk_toggle_button_get_active (button)); } static void wrap_mode_checkbutton_toggled (GtkToggleButton *button, - XedPrintJob *job) + XedPrintJob *job) { - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->text_wrapping_checkbutton))) - { - gtk_widget_set_sensitive (job->priv->do_not_split_checkbutton, - FALSE); - gtk_toggle_button_set_inconsistent ( - GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton), - TRUE); - } - else - { - gtk_widget_set_sensitive (job->priv->do_not_split_checkbutton, - TRUE); - gtk_toggle_button_set_inconsistent ( - GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton), - FALSE); - } + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->text_wrapping_checkbutton))) + { + gtk_widget_set_sensitive (job->priv->do_not_split_checkbutton, FALSE); + gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton), TRUE); + } + else + { + gtk_widget_set_sensitive (job->priv->do_not_split_checkbutton, TRUE); + gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton), FALSE); + } } static void -restore_button_clicked (GtkButton *button, - XedPrintJob *job) +restore_button_clicked (GtkButton *button, + XedPrintJob *job) { - gchar *body; + gchar *body; gchar *header; gchar *numbers; - body = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_BODY_PANGO); + body = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_BODY_PANGO); header = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_HEADER_PANGO); numbers = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_NUMBERS_PANGO); @@ -291,50 +290,41 @@ restore_button_clicked (GtkButton *button, static GObject * create_custom_widget_cb (GtkPrintOperation *operation, - XedPrintJob *job) + XedPrintJob *job) { - gboolean ret; - GtkWidget *widget; - GtkWidget *error_widget; - guint line_numbers; - GtkWrapMode wrap_mode; - gchar *file; + GtkBuilder *builder; + GtkWidget *contents; + guint line_numbers; + GtkWrapMode wrap_mode; gboolean syntax_hl; gboolean print_header; gchar *font_body, *font_header, *font_numbers; - gchar *root_objects[] = { - "adjustment1", - "contents", - NULL - }; + gchar *root_objects[] = { + "adjustment1", + "contents", + NULL + }; - file = xed_dirs_get_ui_file ("xed-print-preferences.ui"); - ret = xed_utils_get_ui_objects (file, - root_objects, - &error_widget, - "contents", &widget, - "syntax_checkbutton", &job->priv->syntax_checkbutton, - "line_numbers_checkbutton", &job->priv->line_numbers_checkbutton, - "line_numbers_hbox", &job->priv->line_numbers_hbox, - "line_numbers_spinbutton", &job->priv->line_numbers_spinbutton, - "page_header_checkbutton", &job->priv->page_header_checkbutton, - "text_wrapping_checkbutton", &job->priv->text_wrapping_checkbutton, - "do_not_split_checkbutton", &job->priv->do_not_split_checkbutton, - "fonts_table", &job->priv->fonts_table, - "body_font_label", &job->priv->body_font_label, - "body_fontbutton", &job->priv->body_fontbutton, - "headers_font_label", &job->priv->headers_font_label, - "headers_fontbutton", &job->priv->headers_fontbutton, - "numbers_font_label", &job->priv->numbers_font_label, - "numbers_fontbutton", &job->priv->numbers_fontbutton, - "restore_button", &job->priv->restore_button, - NULL); - g_free (file); - - if (!ret) - { - return G_OBJECT (error_widget); - } + builder = gtk_builder_new (); + gtk_builder_add_objects_from_resource (builder, "/org/x/editor/ui/xed-print-preferences.ui", root_objects, NULL); + contents = GTK_WIDGET (gtk_builder_get_object (builder, "contents")); + g_object_ref (contents); + job->priv->syntax_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "syntax_checkbutton")); + job->priv->line_numbers_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "line_numbers_checkbutton")); + job->priv->line_numbers_hbox = GTK_WIDGET (gtk_builder_get_object (builder, "line_numbers_hbox")); + job->priv->line_numbers_spinbutton = GTK_WIDGET (gtk_builder_get_object (builder, "line_numbers_spinbutton")); + job->priv->page_header_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "page_header_checkbutton")); + job->priv->text_wrapping_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "text_wrapping_checkbutton")); + job->priv->do_not_split_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "do_not_split_checkbutton")); + job->priv->fonts_table = GTK_WIDGET (gtk_builder_get_object (builder, "fonts_table")); + job->priv->body_font_label = GTK_WIDGET (gtk_builder_get_object (builder, "body_font_label")); + job->priv->body_fontbutton = GTK_WIDGET (gtk_builder_get_object (builder, "body_fontbutton")); + job->priv->headers_font_label = GTK_WIDGET (gtk_builder_get_object (builder, "headers_font_label")); + job->priv->headers_fontbutton = GTK_WIDGET (gtk_builder_get_object (builder, "headers_fontbutton")); + job->priv->numbers_font_label = GTK_WIDGET (gtk_builder_get_object (builder, "numbers_font_label")); + job->priv->numbers_fontbutton = GTK_WIDGET (gtk_builder_get_object (builder, "numbers_fontbutton")); + job->priv->restore_button = GTK_WIDGET (gtk_builder_get_object (builder, "restore_button")); + g_object_unref (builder); /* Get all settings values */ syntax_hl = g_settings_get_boolean (job->priv->print_settings, XED_SETTINGS_PRINT_SYNTAX_HIGHLIGHTING); @@ -344,89 +334,74 @@ create_custom_widget_cb (GtkPrintOperation *operation, font_header = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_HEADER_PANGO); font_numbers = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_NUMBERS_PANGO); - /* Print syntax */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->syntax_checkbutton), syntax_hl); + /* Print syntax */ + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->syntax_checkbutton), syntax_hl); - /* Print page headers */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->page_header_checkbutton), print_header); + /* Print page headers */ + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->page_header_checkbutton), print_header); - /* Line numbers */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->line_numbers_checkbutton), line_numbers > 0); + /* Line numbers */ + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->line_numbers_checkbutton), line_numbers > 0); - if (line_numbers > 0) - { - gtk_spin_button_set_value (GTK_SPIN_BUTTON (job->priv->line_numbers_spinbutton), (guint) line_numbers); - gtk_widget_set_sensitive (job->priv->line_numbers_hbox, TRUE); - } - else - { - gtk_spin_button_set_value (GTK_SPIN_BUTTON (job->priv->line_numbers_spinbutton), - 1); - gtk_widget_set_sensitive (job->priv->line_numbers_hbox, FALSE); - } + if (line_numbers > 0) + { + gtk_spin_button_set_value (GTK_SPIN_BUTTON (job->priv->line_numbers_spinbutton), (guint) line_numbers); + gtk_widget_set_sensitive (job->priv->line_numbers_hbox, TRUE); + } + else + { + gtk_spin_button_set_value (GTK_SPIN_BUTTON (job->priv->line_numbers_spinbutton), 1); + gtk_widget_set_sensitive (job->priv->line_numbers_hbox, FALSE); + } - /* Text wrapping */ - wrap_mode = g_settings_get_enum (job->priv->print_settings, XED_SETTINGS_PRINT_WRAP_MODE); + /* Text wrapping */ + wrap_mode = g_settings_get_enum (job->priv->print_settings, XED_SETTINGS_PRINT_WRAP_MODE); - switch (wrap_mode) - { - case GTK_WRAP_WORD: - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (job->priv->text_wrapping_checkbutton), TRUE); - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton), TRUE); - break; - case GTK_WRAP_CHAR: - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (job->priv->text_wrapping_checkbutton), TRUE); - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton), FALSE); - break; - default: - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (job->priv->text_wrapping_checkbutton), FALSE); - gtk_toggle_button_set_inconsistent ( - GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton), TRUE); - } + switch (wrap_mode) + { + case GTK_WRAP_WORD: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->text_wrapping_checkbutton), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton), TRUE); + break; + case GTK_WRAP_CHAR: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->text_wrapping_checkbutton), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton), FALSE); + break; + default: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (job->priv->text_wrapping_checkbutton), FALSE); + gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton), TRUE); + } - gtk_widget_set_sensitive (job->priv->do_not_split_checkbutton, wrap_mode != GTK_WRAP_NONE); + gtk_widget_set_sensitive (job->priv->do_not_split_checkbutton, wrap_mode != GTK_WRAP_NONE); - /* Set initial values */ - gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->body_fontbutton), font_body); - g_free (font_body); + /* Set initial values */ + gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->body_fontbutton), font_body); + g_free (font_body); - gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->headers_fontbutton), font_header); - g_free (font_header); + gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->headers_fontbutton), font_header); + g_free (font_header); - gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->numbers_fontbutton), font_numbers); + gtk_font_button_set_font_name (GTK_FONT_BUTTON (job->priv->numbers_fontbutton), font_numbers); g_free (font_numbers); - g_signal_connect (job->priv->line_numbers_checkbutton, - "toggled", - G_CALLBACK (line_numbers_checkbutton_toggled), - job); - g_signal_connect (job->priv->text_wrapping_checkbutton, - "toggled", - G_CALLBACK (wrap_mode_checkbutton_toggled), - job); - g_signal_connect (job->priv->do_not_split_checkbutton, - "toggled", - G_CALLBACK (wrap_mode_checkbutton_toggled), - job); - g_signal_connect (job->priv->restore_button, - "clicked", - G_CALLBACK (restore_button_clicked), - job); + g_signal_connect (job->priv->line_numbers_checkbutton, "toggled", + G_CALLBACK (line_numbers_checkbutton_toggled), job); + g_signal_connect (job->priv->text_wrapping_checkbutton, "toggled", + G_CALLBACK (wrap_mode_checkbutton_toggled), job); + g_signal_connect (job->priv->do_not_split_checkbutton, "toggled", + G_CALLBACK (wrap_mode_checkbutton_toggled), job); + g_signal_connect (job->priv->restore_button, "clicked", + G_CALLBACK (restore_button_clicked), job); - return G_OBJECT (widget); + return G_OBJECT (contents); } static void custom_widget_apply_cb (GtkPrintOperation *operation, - GtkWidget *widget, - XedPrintJob *job) + GtkWidget *widget, + XedPrintJob *job) { - gboolean syntax, page_header; + gboolean syntax, page_header; const gchar *body, *header, *numbers; GtkWrapMode wrap_mode; @@ -442,31 +417,31 @@ custom_widget_apply_cb (GtkPrintOperation *operation, g_settings_set_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_HEADER_PANGO, header); g_settings_set_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_NUMBERS_PANGO, numbers); - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->line_numbers_checkbutton))) - { - g_settings_set_uint (job->priv->print_settings, XED_SETTINGS_PRINT_LINE_NUMBERS, + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->line_numbers_checkbutton))) + { + g_settings_set_uint (job->priv->print_settings, XED_SETTINGS_PRINT_LINE_NUMBERS, MAX (1, gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (job->priv->line_numbers_spinbutton)))); - } - else - { - g_settings_set_uint (job->priv->print_settings, XED_SETTINGS_PRINT_LINE_NUMBERS, 0); - } + } + else + { + g_settings_set_uint (job->priv->print_settings, XED_SETTINGS_PRINT_LINE_NUMBERS, 0); + } - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->text_wrapping_checkbutton))) - { - wrap_mode = GTK_WRAP_NONE; - } - else - { - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton))) - { - wrap_mode = GTK_WRAP_WORD; - } - else - { - wrap_mode = GTK_WRAP_CHAR; - } - } + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->text_wrapping_checkbutton))) + { + wrap_mode = GTK_WRAP_NONE; + } + else + { + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (job->priv->do_not_split_checkbutton))) + { + wrap_mode = GTK_WRAP_WORD; + } + else + { + wrap_mode = GTK_WRAP_CHAR; + } + } g_settings_set_enum (job->priv->print_settings, XED_SETTINGS_PRINT_WRAP_MODE, wrap_mode); } @@ -474,16 +449,16 @@ custom_widget_apply_cb (GtkPrintOperation *operation, static void create_compositor (XedPrintJob *job) { - gchar *print_font_body; - gchar *print_font_header; - gchar *print_font_numbers; + gchar *print_font_body; + gchar *print_font_header; + gchar *print_font_numbers; gboolean syntax_hl; GtkWrapMode wrap_mode; guint print_line_numbers; gboolean print_header; - /* Create and initialize print compositor */ - print_font_body = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_BODY_PANGO); + /* Create and initialize print compositor */ + print_font_body = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_BODY_PANGO); print_font_header = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_HEADER_PANGO); print_font_numbers = g_settings_get_string (job->priv->print_settings, XED_SETTINGS_PRINT_FONT_NUMBERS_PANGO); syntax_hl = g_settings_get_boolean (job->priv->print_settings, XED_SETTINGS_PRINT_SYNTAX_HIGHLIGHTING); @@ -491,356 +466,332 @@ create_compositor (XedPrintJob *job) print_header = g_settings_get_boolean (job->priv->print_settings, XED_SETTINGS_PRINT_HEADER); wrap_mode = g_settings_get_enum (job->priv->print_settings, XED_SETTINGS_PRINT_WRAP_MODE); - job->priv->compositor = GTK_SOURCE_PRINT_COMPOSITOR ( - g_object_new (GTK_SOURCE_TYPE_PRINT_COMPOSITOR, - "buffer", GTK_SOURCE_BUFFER (job->priv->doc), - "tab-width", gtk_source_view_get_tab_width (GTK_SOURCE_VIEW (job->priv->view)), - "highlight-syntax", gtk_source_buffer_get_highlight_syntax (GTK_SOURCE_BUFFER (job->priv->doc)) && - syntax_hl, - "wrap-mode", wrap_mode, - "print-line-numbers", print_line_numbers, - "print-header", print_header, - "print-footer", FALSE, - "body-font-name", print_font_body, - "line-numbers-font-name", print_font_numbers, - "header-font-name", print_font_header, - NULL)); + job->priv->compositor = GTK_SOURCE_PRINT_COMPOSITOR ( + g_object_new (GTK_SOURCE_TYPE_PRINT_COMPOSITOR, + "buffer", GTK_SOURCE_BUFFER (job->priv->doc), + "tab-width", gtk_source_view_get_tab_width (GTK_SOURCE_VIEW (job->priv->view)), + "highlight-syntax", gtk_source_buffer_get_highlight_syntax (GTK_SOURCE_BUFFER (job->priv->doc)) && + syntax_hl, + "wrap-mode", wrap_mode, + "print-line-numbers", print_line_numbers, + "print-header", print_header, + "print-footer", FALSE, + "body-font-name", print_font_body, + "line-numbers-font-name", print_font_numbers, + "header-font-name", print_font_header, + NULL)); - g_free (print_font_body); - g_free (print_font_header); - g_free (print_font_numbers); + g_free (print_font_body); + g_free (print_font_header); + g_free (print_font_numbers); - if (print_header) - { - gchar *doc_name; - gchar *name_to_display; - gchar *left; + if (print_header) + { + gchar *doc_name; + gchar *name_to_display; + gchar *left; - doc_name = xed_document_get_uri_for_display (job->priv->doc); - name_to_display = xed_utils_str_middle_truncate (doc_name, 60); + doc_name = xed_document_get_uri_for_display (job->priv->doc); + name_to_display = xed_utils_str_middle_truncate (doc_name, 60); - left = g_strdup_printf (_("File: %s"), name_to_display); + left = g_strdup_printf (_("File: %s"), name_to_display); - /* Translators: %N is the current page number, %Q is the total - * number of pages (ex. Page 2 of 10) - */ - gtk_source_print_compositor_set_header_format (job->priv->compositor, - TRUE, - left, - NULL, - _("Page %N of %Q")); + /* Translators: %N is the current page number, %Q is the total + * number of pages (ex. Page 2 of 10) + */ + gtk_source_print_compositor_set_header_format (job->priv->compositor, + TRUE, + left, + NULL, + _("Page %N of %Q")); - g_free (doc_name); - g_free (name_to_display); - g_free (left); - } + g_free (doc_name); + g_free (name_to_display); + g_free (left); + } } static void begin_print_cb (GtkPrintOperation *operation, - GtkPrintContext *context, - XedPrintJob *job) + GtkPrintContext *context, + XedPrintJob *job) { - create_compositor (job); + create_compositor (job); - job->priv->status = XED_PRINT_JOB_STATUS_PAGINATING; + job->priv->status = XED_PRINT_JOB_STATUS_PAGINATING; - job->priv->progress = 0.0; + job->priv->progress = 0.0; - g_signal_emit (job, print_job_signals[PRINTING], 0, job->priv->status); + g_signal_emit (job, print_job_signals[PRINTING], 0, job->priv->status); } static void preview_ready (GtkPrintOperationPreview *gtk_preview, - GtkPrintContext *context, - XedPrintJob *job) + GtkPrintContext *context, + XedPrintJob *job) { - job->priv->is_preview = TRUE; + job->priv->is_preview = TRUE; - g_signal_emit (job, print_job_signals[SHOW_PREVIEW], 0, job->priv->preview); + g_signal_emit (job, print_job_signals[SHOW_PREVIEW], 0, job->priv->preview); } static void preview_destroyed (GtkWidget *preview, - GtkPrintOperationPreview *gtk_preview) + GtkPrintOperationPreview *gtk_preview) { - gtk_print_operation_preview_end_preview (gtk_preview); + gtk_print_operation_preview_end_preview (gtk_preview); } static gboolean preview_cb (GtkPrintOperation *op, - GtkPrintOperationPreview *gtk_preview, - GtkPrintContext *context, - GtkWindow *parent, - XedPrintJob *job) + GtkPrintOperationPreview *gtk_preview, + GtkPrintContext *context, + GtkWindow *parent, + XedPrintJob *job) { - job->priv->preview = xed_print_preview_new (op, gtk_preview, context); + job->priv->preview = xed_print_preview_new (op, gtk_preview, context); - g_signal_connect_after (gtk_preview, - "ready", - G_CALLBACK (preview_ready), - job); + g_signal_connect_after (gtk_preview, "ready", + G_CALLBACK (preview_ready), job); - /* FIXME: should this go in the preview widget itself? */ - g_signal_connect (job->priv->preview, - "destroy", - G_CALLBACK (preview_destroyed), - gtk_preview); + /* FIXME: should this go in the preview widget itself? */ + g_signal_connect (job->priv->preview, "destroy", + G_CALLBACK (preview_destroyed), gtk_preview); - return TRUE; + return TRUE; } static gboolean paginate_cb (GtkPrintOperation *operation, - GtkPrintContext *context, - XedPrintJob *job) + GtkPrintContext *context, + XedPrintJob *job) { - gboolean res; + gboolean res; - job->priv->status = XED_PRINT_JOB_STATUS_PAGINATING; + job->priv->status = XED_PRINT_JOB_STATUS_PAGINATING; - res = gtk_source_print_compositor_paginate (job->priv->compositor, context); + res = gtk_source_print_compositor_paginate (job->priv->compositor, context); - if (res) - { - gint n_pages; + if (res) + { + gint n_pages; - n_pages = gtk_source_print_compositor_get_n_pages (job->priv->compositor); - gtk_print_operation_set_n_pages (job->priv->operation, n_pages); - } + n_pages = gtk_source_print_compositor_get_n_pages (job->priv->compositor); + gtk_print_operation_set_n_pages (job->priv->operation, n_pages); + } - job->priv->progress = gtk_source_print_compositor_get_pagination_progress (job->priv->compositor); + job->priv->progress = gtk_source_print_compositor_get_pagination_progress (job->priv->compositor); - /* When previewing, the progress is just for pagination, when printing - * it's split between pagination and rendering */ - if (!job->priv->is_preview) - job->priv->progress /= 2.0; + /* When previewing, the progress is just for pagination, when printing + * it's split between pagination and rendering */ + if (!job->priv->is_preview) + { + job->priv->progress /= 2.0; + } - g_signal_emit (job, print_job_signals[PRINTING], 0, job->priv->status); + g_signal_emit (job, print_job_signals[PRINTING], 0, job->priv->status); - return res; + return res; } static void draw_page_cb (GtkPrintOperation *operation, - GtkPrintContext *context, - gint page_nr, - XedPrintJob *job) + GtkPrintContext *context, + gint page_nr, + XedPrintJob *job) { - gint n_pages; + gint n_pages; - /* In preview, pages are drawn on the fly, so rendering is - * not part of the progress */ - if (!job->priv->is_preview) - { - g_free (job->priv->status_string); + /* In preview, pages are drawn on the fly, so rendering is + * not part of the progress */ + if (!job->priv->is_preview) + { + g_free (job->priv->status_string); - n_pages = gtk_source_print_compositor_get_n_pages (job->priv->compositor); + n_pages = gtk_source_print_compositor_get_n_pages (job->priv->compositor); - job->priv->status = XED_PRINT_JOB_STATUS_DRAWING; + job->priv->status = XED_PRINT_JOB_STATUS_DRAWING; - job->priv->status_string = g_strdup_printf ("Rendering page %d of %d...", - page_nr + 1, - n_pages); + job->priv->status_string = g_strdup_printf ("Rendering page %d of %d...", page_nr + 1, n_pages); - job->priv->progress = page_nr / (2.0 * n_pages) + 0.5; + job->priv->progress = page_nr / (2.0 * n_pages) + 0.5; - g_signal_emit (job, print_job_signals[PRINTING], 0, job->priv->status); - } + g_signal_emit (job, print_job_signals[PRINTING], 0, job->priv->status); + } - gtk_source_print_compositor_draw_page (job->priv->compositor, context, page_nr); + gtk_source_print_compositor_draw_page (job->priv->compositor, context, page_nr); } static void end_print_cb (GtkPrintOperation *operation, - GtkPrintContext *context, - XedPrintJob *job) + GtkPrintContext *context, + XedPrintJob *job) { - g_object_unref (job->priv->compositor); - job->priv->compositor = NULL; + g_object_unref (job->priv->compositor); + job->priv->compositor = NULL; } static void done_cb (GtkPrintOperation *operation, - GtkPrintOperationResult result, - XedPrintJob *job) + GtkPrintOperationResult result, + XedPrintJob *job) { - GError *error = NULL; - XedPrintJobResult print_result; + GError *error = NULL; + XedPrintJobResult print_result; - switch (result) - { - case GTK_PRINT_OPERATION_RESULT_CANCEL: - print_result = XED_PRINT_JOB_RESULT_CANCEL; - break; + switch (result) + { + case GTK_PRINT_OPERATION_RESULT_CANCEL: + print_result = XED_PRINT_JOB_RESULT_CANCEL; + break; - case GTK_PRINT_OPERATION_RESULT_APPLY: - print_result = XED_PRINT_JOB_RESULT_OK; - break; + case GTK_PRINT_OPERATION_RESULT_APPLY: + print_result = XED_PRINT_JOB_RESULT_OK; + break; - case GTK_PRINT_OPERATION_RESULT_ERROR: - print_result = XED_PRINT_JOB_RESULT_ERROR; - gtk_print_operation_get_error (operation, &error); - break; + case GTK_PRINT_OPERATION_RESULT_ERROR: + print_result = XED_PRINT_JOB_RESULT_ERROR; + gtk_print_operation_get_error (operation, &error); + break; - default: - g_return_if_reached (); - } + default: + g_return_if_reached (); + } - /* Avoid job is destroyed in the handler of the "done" message */ - g_object_ref (job); + /* Avoid job is destroyed in the handler of the "done" message */ + g_object_ref (job); - g_signal_emit (job, print_job_signals[DONE], 0, print_result, error); + g_signal_emit (job, print_job_signals[DONE], 0, print_result, error); - g_object_unref (operation); - job->priv->operation = NULL; + g_object_unref (operation); + job->priv->operation = NULL; - g_object_unref (job); + g_object_unref (job); } /* Note that xed_print_job_print can can only be called once on a given XedPrintJob */ GtkPrintOperationResult -xed_print_job_print (XedPrintJob *job, - GtkPrintOperationAction action, - GtkPageSetup *page_setup, - GtkPrintSettings *settings, - GtkWindow *parent, - GError **error) +xed_print_job_print (XedPrintJob *job, + GtkPrintOperationAction action, + GtkPageSetup *page_setup, + GtkPrintSettings *settings, + GtkWindow *parent, + GError **error) { - XedPrintJobPrivate *priv; - gchar *job_name; + XedPrintJobPrivate *priv; + gchar *job_name; - g_return_val_if_fail (job->priv->compositor == NULL, GTK_PRINT_OPERATION_RESULT_ERROR); + g_return_val_if_fail (job->priv->compositor == NULL, GTK_PRINT_OPERATION_RESULT_ERROR); - priv = job->priv; + priv = job->priv; - /* Check if we are previewing */ - priv->is_preview = (action == GTK_PRINT_OPERATION_ACTION_PREVIEW); + /* Check if we are previewing */ + priv->is_preview = (action == GTK_PRINT_OPERATION_ACTION_PREVIEW); - /* Create print operation */ - job->priv->operation = gtk_print_operation_new (); + /* Create print operation */ + job->priv->operation = gtk_print_operation_new (); - if (settings) - gtk_print_operation_set_print_settings (priv->operation, - settings); + if (settings) + { + gtk_print_operation_set_print_settings (priv->operation, settings); + } - if (page_setup != NULL) - gtk_print_operation_set_default_page_setup (priv->operation, - page_setup); + if (page_setup != NULL) + { + gtk_print_operation_set_default_page_setup (priv->operation, page_setup); + } - job_name = xed_document_get_short_name_for_display (priv->doc); - gtk_print_operation_set_job_name (priv->operation, job_name); - g_free (job_name); + job_name = xed_document_get_short_name_for_display (priv->doc); + gtk_print_operation_set_job_name (priv->operation, job_name); + g_free (job_name); - gtk_print_operation_set_embed_page_setup (priv->operation, TRUE); + gtk_print_operation_set_embed_page_setup (priv->operation, TRUE); - gtk_print_operation_set_custom_tab_label (priv->operation, - _("Text Editor")); + gtk_print_operation_set_custom_tab_label (priv->operation, _("Text Editor")); - gtk_print_operation_set_allow_async (priv->operation, TRUE); + gtk_print_operation_set_allow_async (priv->operation, TRUE); - g_signal_connect (priv->operation, - "create-custom-widget", - G_CALLBACK (create_custom_widget_cb), - job); - g_signal_connect (priv->operation, - "custom-widget-apply", - G_CALLBACK (custom_widget_apply_cb), - job); - g_signal_connect (priv->operation, - "begin-print", - G_CALLBACK (begin_print_cb), - job); - g_signal_connect (priv->operation, - "preview", - G_CALLBACK (preview_cb), - job); - g_signal_connect (priv->operation, - "paginate", - G_CALLBACK (paginate_cb), - job); - g_signal_connect (priv->operation, - "draw-page", - G_CALLBACK (draw_page_cb), - job); - g_signal_connect (priv->operation, - "end-print", - G_CALLBACK (end_print_cb), - job); - g_signal_connect (priv->operation, - "done", - G_CALLBACK (done_cb), - job); + g_signal_connect (priv->operation, "create-custom-widget", + G_CALLBACK (create_custom_widget_cb), job); + g_signal_connect (priv->operation, "custom-widget-apply", + G_CALLBACK (custom_widget_apply_cb), job); + g_signal_connect (priv->operation, "begin-print", + G_CALLBACK (begin_print_cb), job); + g_signal_connect (priv->operation, "preview", + G_CALLBACK (preview_cb), job); + g_signal_connect (priv->operation, "paginate", + G_CALLBACK (paginate_cb), job); + g_signal_connect (priv->operation, "draw-page", + G_CALLBACK (draw_page_cb), job); + g_signal_connect (priv->operation, "end-print", + G_CALLBACK (end_print_cb), job); + g_signal_connect (priv->operation, "done", + G_CALLBACK (done_cb), job); - return gtk_print_operation_run (priv->operation, - action, - parent, - error); + return gtk_print_operation_run (priv->operation, action, parent, error); } static void xed_print_job_init (XedPrintJob *job) { - job->priv = XED_PRINT_JOB_GET_PRIVATE (job); + job->priv = XED_PRINT_JOB_GET_PRIVATE (job); job->priv->print_settings = g_settings_new ("org.x.editor.preferences.print"); - job->priv->status = XED_PRINT_JOB_STATUS_INIT; + job->priv->status = XED_PRINT_JOB_STATUS_INIT; - job->priv->status_string = g_strdup (_("Preparing...")); + job->priv->status_string = g_strdup (_("Preparing...")); } XedPrintJob * xed_print_job_new (XedView *view) { - XedPrintJob *job; + XedPrintJob *job; - g_return_val_if_fail (XED_IS_VIEW (view), NULL); + g_return_val_if_fail (XED_IS_VIEW (view), NULL); - job = XED_PRINT_JOB (g_object_new (XED_TYPE_PRINT_JOB, - "view", view, - NULL)); + job = XED_PRINT_JOB (g_object_new (XED_TYPE_PRINT_JOB, "view", view, NULL)); - return job; + return job; } void xed_print_job_cancel (XedPrintJob *job) { - g_return_if_fail (XED_IS_PRINT_JOB (job)); + g_return_if_fail (XED_IS_PRINT_JOB (job)); - gtk_print_operation_cancel (job->priv->operation); + gtk_print_operation_cancel (job->priv->operation); } const gchar * xed_print_job_get_status_string (XedPrintJob *job) { - g_return_val_if_fail (XED_IS_PRINT_JOB (job), NULL); - g_return_val_if_fail (job->priv->status_string != NULL, NULL); + g_return_val_if_fail (XED_IS_PRINT_JOB (job), NULL); + g_return_val_if_fail (job->priv->status_string != NULL, NULL); - return job->priv->status_string; + return job->priv->status_string; } gdouble xed_print_job_get_progress (XedPrintJob *job) { - g_return_val_if_fail (XED_IS_PRINT_JOB (job), 0.0); + g_return_val_if_fail (XED_IS_PRINT_JOB (job), 0.0); - return job->priv->progress; + return job->priv->progress; } GtkPrintSettings * xed_print_job_get_print_settings (XedPrintJob *job) { - g_return_val_if_fail (XED_IS_PRINT_JOB (job), NULL); + g_return_val_if_fail (XED_IS_PRINT_JOB (job), NULL); - return gtk_print_operation_get_print_settings (job->priv->operation); + return gtk_print_operation_get_print_settings (job->priv->operation); } GtkPageSetup * xed_print_job_get_page_setup (XedPrintJob *job) { - g_return_val_if_fail (XED_IS_PRINT_JOB (job), NULL); + g_return_val_if_fail (XED_IS_PRINT_JOB (job), NULL); - return gtk_print_operation_get_default_page_setup (job->priv->operation); + return gtk_print_operation_get_default_page_setup (job->priv->operation); } diff --git a/xed/xed-searchbar.c b/xed/xed-searchbar.c index 474c0e2..94b33c2 100755 --- a/xed/xed-searchbar.c +++ b/xed/xed-searchbar.c @@ -18,13 +18,6 @@ #define XED_SEARCHBAR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_SEARCHBAR, XedSearchbarPrivate)) -// typedef enum -// { -// SEARCH, -// REPLACE -// } SearchMode; - - enum { SHOW_REPLACE, @@ -666,35 +659,32 @@ xed_searchbar_init (XedSearchbar *searchbar) { GtkWidget *content; GtkSizeGroup *size_group; - GtkWidget *error_widget; GtkStyleContext *context; GtkCssProvider *provider; - gchar *file; + GtkBuilder *builder; gchar *root_objects[] = { "searchbar_content", NULL }; const gchar *data = ".button {padding: 0;}"; searchbar->priv = XED_SEARCHBAR_GET_PRIVATE (searchbar); - file = xed_dirs_get_ui_file ("xed-searchbar.ui"); - xed_utils_get_ui_objects (file, - root_objects, - &error_widget, - "searchbar_content", &content, - "revealer", &searchbar->priv->revealer, - "grid", &searchbar->priv->grid, - "search_label", &searchbar->priv->search_label, - "replace_with_label", &searchbar->priv->replace_label, - "regex_checkbutton", &searchbar->priv->regex_checkbutton, - "match_case_checkbutton", &searchbar->priv->match_case_checkbutton, - "entire_word_checkbutton", &searchbar->priv->entire_word_checkbutton, - "wrap_around_checkbutton", &searchbar->priv->wrap_around_checkbutton, - "find_button", &searchbar->priv->find_button, - "find_prev_button", &searchbar->priv->find_prev_button, - "replace_button", &searchbar->priv->replace_button, - "replace_all_button", &searchbar->priv->replace_all_button, - "close_button", &searchbar->priv->close_button, - NULL); - g_free (file); + builder = gtk_builder_new (); + gtk_builder_add_objects_from_resource (builder, "/org/x/editor/ui/xed-searchbar.ui", root_objects, NULL); + content = GTK_WIDGET (gtk_builder_get_object (builder, "searchbar_content")); + g_object_ref (content); + searchbar->priv->revealer = GTK_WIDGET (gtk_builder_get_object (builder, "revealer")); + searchbar->priv->grid = GTK_WIDGET (gtk_builder_get_object (builder, "grid")); + searchbar->priv->search_label = GTK_WIDGET (gtk_builder_get_object (builder, "search_label")); + searchbar->priv->replace_label = GTK_WIDGET (gtk_builder_get_object (builder, "replace_with_label")); + searchbar->priv->regex_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "regex_checkbutton")); + searchbar->priv->match_case_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "match_case_checkbutton")); + searchbar->priv->entire_word_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "entire_word_checkbutton")); + searchbar->priv->wrap_around_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "wrap_around_checkbutton")); + searchbar->priv->find_button = GTK_WIDGET (gtk_builder_get_object (builder, "find_button")); + searchbar->priv->find_prev_button = GTK_WIDGET (gtk_builder_get_object (builder, "find_prev_button")); + searchbar->priv->replace_button = GTK_WIDGET (gtk_builder_get_object (builder, "replace_button")); + searchbar->priv->replace_all_button = GTK_WIDGET (gtk_builder_get_object (builder, "replace_all_button")); + searchbar->priv->close_button = GTK_WIDGET (gtk_builder_get_object (builder, "close_button")); + g_object_unref (builder); gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (searchbar)), "xed-searchbar"); diff --git a/xed/xed-view-frame.c b/xed/xed-view-frame.c index 60f0582..eba0299 100644 --- a/xed/xed-view-frame.c +++ b/xed/xed-view-frame.c @@ -37,12 +37,9 @@ #define SEARCH_POPUP_MARGIN 12 -#define XED_VIEW_FRAME_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), XED_TYPE_VIEW_FRAME, XedViewFramePrivate)) - struct _XedViewFramePrivate { GtkWidget *view; - GtkWidget *overlay; GtkTextMark *start_mark; @@ -68,7 +65,7 @@ typedef enum SEARCH_STATE_NOT_FOUND } SearchState; -G_DEFINE_TYPE (XedViewFrame, xed_view_frame, GTK_TYPE_BOX) +G_DEFINE_TYPE_WITH_PRIVATE (XedViewFrame, xed_view_frame, GTK_TYPE_OVERLAY) static void xed_view_frame_finalize (GObject *object) @@ -389,32 +386,18 @@ search_entry_populate_popup (GtkEntry *entry, G_CALLBACK (search_enable_popdown), frame); } -static GtkWidget * -create_search_widget (XedViewFrame *frame) +static void +setup_search_widget (XedViewFrame *frame) { - GtkWidget *search_widget; - GtkWidget *hbox; - GtkStyleContext *context; - - /* wrap it in a frame, so we can specify borders etc */ - search_widget = gtk_frame_new (NULL); - context = gtk_widget_get_style_context (search_widget); - gtk_style_context_add_class (context, "xed-goto-line-box"); - gtk_widget_show (search_widget); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - gtk_container_add (GTK_CONTAINER (search_widget), hbox); - gtk_widget_show (hbox); - - g_signal_connect (hbox, "key-press-event", + g_signal_connect (frame->priv->revealer, "key-press-event", G_CALLBACK (search_widget_key_press_event), frame); /* add entry */ - frame->priv->search_entry = gtk_entry_new (); - gtk_widget_set_tooltip_text (frame->priv->search_entry, _("Line you want to move the cursor to")); - gtk_entry_set_icon_from_icon_name (GTK_ENTRY (frame->priv->search_entry), - GTK_ENTRY_ICON_PRIMARY, "go-jump-symbolic"); - gtk_widget_show (frame->priv->search_entry); + // frame->priv->search_entry = gtk_entry_new (); + // gtk_widget_set_tooltip_text (frame->priv->search_entry, _("Line you want to move the cursor to")); + // gtk_entry_set_icon_from_icon_name (GTK_ENTRY (frame->priv->search_entry), + // GTK_ENTRY_ICON_PRIMARY, "go-jump-symbolic"); + // gtk_widget_show (frame->priv->search_entry); g_signal_connect (frame->priv->search_entry, "activate", G_CALLBACK (search_entry_activate), frame); @@ -426,10 +409,6 @@ create_search_widget (XedViewFrame *frame) G_CALLBACK (search_init), frame); frame->priv->search_entry_focus_out_id = g_signal_connect (frame->priv->search_entry, "focus-out-event", G_CALLBACK (search_entry_focus_out_event), frame); - - gtk_container_add (GTK_CONTAINER (hbox), frame->priv->search_entry); - - return search_widget; } static void @@ -496,6 +475,7 @@ static void xed_view_frame_class_init (XedViewFrameClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); object_class->finalize = xed_view_frame_finalize; object_class->dispose = xed_view_frame_dispose; @@ -517,7 +497,10 @@ xed_view_frame_class_init (XedViewFrameClass *klass) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - g_type_class_add_private (object_class, sizeof (XedViewFramePrivate)); + gtk_widget_class_set_template_from_resource (widget_class, "/org/x/editor/ui/xed-view-frame.ui"); + gtk_widget_class_bind_template_child_private (widget_class, XedViewFrame, view); + gtk_widget_class_bind_template_child_private (widget_class, XedViewFrame, revealer); + gtk_widget_class_bind_template_child_private (widget_class, XedViewFrame, search_entry); } static GMountOperation * @@ -535,47 +518,23 @@ xed_view_frame_init (XedViewFrame *frame) { XedDocument *doc; GtkSourceFile *file; - GtkWidget *sw; GdkRGBA transparent = {0, 0, 0, 0}; - frame->priv = XED_VIEW_FRAME_GET_PRIVATE (frame); + frame->priv = xed_view_frame_get_instance_private (frame); - gtk_orientable_set_orientation (GTK_ORIENTABLE (frame), GTK_ORIENTATION_VERTICAL); + gtk_widget_init_template (GTK_WIDGET (frame)); - doc = xed_document_new (); + gtk_widget_override_background_color (GTK_WIDGET (frame), 0, &transparent); + + doc = xed_view_frame_get_document (frame); file = xed_document_get_file (doc); gtk_source_file_set_mount_operation_factory (file, view_frame_mount_operation_factory, frame, NULL); - frame->priv->view = xed_view_new (doc); - gtk_widget_set_vexpand (frame->priv->view, TRUE); - gtk_widget_show (frame->priv->view); + setup_search_widget (frame); - g_object_unref (doc); - - /* Create the scrolled window */ - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_container_add (GTK_CONTAINER (sw), frame->priv->view); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_widget_show (sw); - - frame->priv->overlay = gtk_overlay_new (); - gtk_container_add (GTK_CONTAINER (frame->priv->overlay), sw); - gtk_widget_override_background_color (frame->priv->overlay, 0, &transparent); - gtk_widget_show (frame->priv->overlay); - - gtk_box_pack_start (GTK_BOX (frame), frame->priv->overlay, TRUE, TRUE, 0); - - /* Add revealer */ - frame->priv->revealer = gtk_revealer_new (); - gtk_container_add (GTK_CONTAINER (frame->priv->revealer), create_search_widget (frame)); - gtk_widget_show (frame->priv->revealer); - gtk_widget_set_halign (frame->priv->revealer, GTK_ALIGN_END); - gtk_widget_set_valign (frame->priv->revealer, GTK_ALIGN_START); gtk_widget_set_margin_end (frame->priv->revealer, SEARCH_POPUP_MARGIN); gtk_widget_set_margin_start (frame->priv->revealer, SEARCH_POPUP_MARGIN); - - gtk_overlay_add_overlay (GTK_OVERLAY (frame->priv->overlay), frame->priv->revealer); } XedViewFrame * diff --git a/xed/xed-view-frame.h b/xed/xed-view-frame.h index 1383fbe..1cb6d12 100644 --- a/xed/xed-view-frame.h +++ b/xed/xed-view-frame.h @@ -43,14 +43,14 @@ typedef struct _XedViewFramePrivate XedViewFramePrivate; struct _XedViewFrame { - GtkBox parent; + GtkOverlay parent; XedViewFramePrivate *priv; }; struct _XedViewFrameClass { - GtkBoxClass parent_class; + GtkOverlayClass parent_class; }; GType xed_view_frame_get_type (void) G_GNUC_CONST; diff --git a/xed/xed-view.c b/xed/xed-view.c index 61f49ac..01040cb 100644 --- a/xed/xed-view.c +++ b/xed/xed-view.c @@ -528,12 +528,18 @@ xed_view_delete_from_cursor (GtkTextView *text_view, } } +static GtkTextBuffer * +xed_view_create_buffer (GtkTextView *text_view) +{ + return GTK_TEXT_BUFFER (xed_document_new ()); +} + static void xed_view_class_init (XedViewClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS(klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); - GtkTextViewClass *text_view_class = GTK_TEXT_VIEW_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GtkTextViewClass *text_view_class = GTK_TEXT_VIEW_CLASS (klass); GtkBindingSet *binding_set; object_class->dispose = xed_view_dispose; @@ -562,6 +568,7 @@ xed_view_class_init (XedViewClass *klass) widget_class->realize = xed_view_realize; text_view_class->delete_from_cursor = xed_view_delete_from_cursor; + text_view_class->create_buffer = xed_view_create_buffer; /* A new signal DROP_URIS has been added to allow plugins to intercept * the default dnd behaviour of 'text/uri-list'. XedView now handles diff --git a/xed/xed-window.c b/xed/xed-window.c index a402c95..293d51b 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -30,7 +30,6 @@ #include "xed-settings.h" #define LANGUAGE_NONE (const gchar *)"LangNone" -#define XED_UIFILE "xed-ui.xml" #define TAB_WIDTH_DATA "XedWindowTabWidthData" #define LANGUAGE_DATA "XedWindowLanguageData" @@ -1263,15 +1262,12 @@ create_menu_bar_and_toolbar (XedWindow *window, g_object_unref (action_group); window->priv->panes_action_group = action_group; - /* now load the UI definition */ - ui_file = xed_dirs_get_ui_file (XED_UIFILE); - gtk_ui_manager_add_ui_from_file (manager, ui_file, &error); + gtk_ui_manager_add_ui_from_resource (manager, "/org/x/editor/ui/xed-ui.xml", &error); if (error != NULL) { - g_warning("Could not merge %s: %s", ui_file, error->message); + g_warning ("Could not add ui definition: %s", error->message); g_error_free (error); } - g_free (ui_file); /* show tooltips in the statusbar */ g_signal_connect(manager, "connect_proxy", G_CALLBACK (connect_proxy_cb), window); From 42f78a69806789f3e433b69677a308b0fad1dadf Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Thu, 9 Feb 2017 03:04:04 -0800 Subject: [PATCH 124/132] Set textdomain as soon as possible --- xed/xed-app.c | 15 +-------------- xed/xed.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/xed/xed-app.c b/xed/xed-app.c index f5a513d..aebe858 100644 --- a/xed/xed-app.c +++ b/xed/xed-app.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include @@ -156,7 +155,7 @@ static const GOptionEntry options[] = /* collects file arguments */ { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, NULL, NULL, - N_("[FILE...] [+LINE") + N_("[FILE...] [+LINE]") }, {NULL} @@ -226,18 +225,6 @@ xed_app_startup (GApplication *application) /* Setup debugging */ xed_debug_init (); xed_debug_message (DEBUG_APP, "Startup"); - - xed_dirs_init (); - - /* Setup locale/gettext */ - setlocale (LC_ALL, ""); - - dir = xed_dirs_get_xed_locale_dir (); - bindtextdomain (GETTEXT_PACKAGE, dir); - - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - xed_debug_message (DEBUG_APP, "Set icon"); dir = xed_dirs_get_xed_data_dir (); diff --git a/xed/xed.c b/xed/xed.c index 7a4ada6..6c1d4ed 100644 --- a/xed/xed.c +++ b/xed/xed.c @@ -33,7 +33,10 @@ #endif #include +#include +#include +#include "xed-dirs.h" #include "xed-app.h" int @@ -41,6 +44,18 @@ main (int argc, char *argv[]) { XedApp *app; gint status; + const gchar *dir; + + xed_dirs_init (); + + /* Setup locale/gettext */ + setlocale (LC_ALL, ""); + + dir = xed_dirs_get_xed_locale_dir (); + bindtextdomain (GETTEXT_PACKAGE, dir); + + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); app = g_object_new (XED_TYPE_APP, "application-id", "org.x.editor", From 3b9d03837b0e713d8306811587dba458d42d49d6 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Thu, 9 Feb 2017 03:30:01 -0800 Subject: [PATCH 125/132] Don't use global vars for command line parsing --- xed/xed-app.c | 106 ++++++++++++++++++++++++++++++++------------------ xed/xed.c | 2 +- 2 files changed, 70 insertions(+), 38 deletions(-) diff --git a/xed/xed-app.c b/xed/xed-app.c index aebe858..e9bd309 100644 --- a/xed/xed-app.c +++ b/xed/xed-app.c @@ -82,19 +82,20 @@ struct _XedAppPrivate GSettings *window_settings; PeasExtensionSet *extensions; + + /* command line parsing */ + gboolean new_window; + gboolean new_document; + gchar *geometry; + const GtkSourceEncoding *encoding; + GInputStream *stdin_stream; + GSList *file_list; + gint line_position; + GApplicationCommandLine *command_line; }; G_DEFINE_TYPE (XedApp, xed_app, GTK_TYPE_APPLICATION) -static gboolean new_window = FALSE; -static gboolean new_document = FALSE; -static gchar *geometry = NULL; -static const GtkSourceEncoding *encoding = NULL; -static GInputStream *stdin_stream = NULL; -static GSList *file_list = NULL; -static gint line_position = 0; -static GApplicationCommandLine *command_line = NULL; - static const GOptionEntry options[] = { /* Version */ @@ -361,16 +362,25 @@ get_active_window (GtkApplication *app) } static void -set_command_line_wait (XedTab *tab) +set_command_line_wait (XedApp *app, + XedTab *tab) { g_object_set_data_full (G_OBJECT (tab), "XedTabCommandLineWait", - g_object_ref (command_line), + g_object_ref (app->priv->command_line), (GDestroyNotify)g_object_unref); } static void -xed_app_activate (GApplication *application) +open_files (GApplication *application, + gboolean new_window, + gboolean new_document, + gchar *geometry, + gint line_position, + const GtkSourceEncoding *encoding, + GInputStream *stdin_stream, + GSList *file_list, + GApplicationCommandLine *command_line) { XedWindow *window = NULL; XedTab *tab; @@ -408,7 +418,7 @@ xed_app_activate (GApplication *application) if (doc_created && command_line) { - set_command_line_wait (tab); + set_command_line_wait (XED_APP (application), tab); } g_input_stream_close (stdin_stream, NULL, NULL); } @@ -436,7 +446,7 @@ xed_app_activate (GApplication *application) if (command_line) { - set_command_line_wait (tab); + set_command_line_wait (XED_APP (application), tab); } } @@ -444,19 +454,38 @@ xed_app_activate (GApplication *application) } static void -clear_options (void) +xed_app_activate (GApplication *application) { - g_free (geometry); - g_clear_object (&stdin_stream); - g_slist_free_full (file_list, g_object_unref); + XedAppPrivate *priv = XED_APP (application)->priv; - new_window = FALSE; - new_document = FALSE; - geometry = NULL; - encoding = NULL; - file_list = NULL; - line_position = 0; - command_line = NULL; + open_files (application, + priv->new_window, + priv->new_document, + priv->geometry, + priv->line_position, + priv->encoding, + priv->stdin_stream, + priv->file_list, + priv->command_line); +} + +static void +clear_options (XedApp *app) +{ + XedAppPrivate *priv = app->priv; + + g_free (priv->geometry); + g_clear_object (&priv->stdin_stream); + g_slist_free_full (priv->file_list, g_object_unref); + + priv->new_window = FALSE; + priv->new_document = FALSE; + priv->geometry = NULL; + priv->encoding = NULL; + priv->file_list = NULL; + priv->line_position = 0; + priv->column_position = 0; + priv->command_line = NULL; } static void @@ -470,26 +499,29 @@ static gint xed_app_command_line (GApplication *application, GApplicationCommandLine *cl) { + XedAppPrivate *priv; GVariantDict *options; const gchar *encoding_charset; const gchar **remaining_args; + priv = XED_APP (application)->priv; + options = g_application_command_line_get_options_dict (cl); - g_variant_dict_lookup (options, "new-window", "b", &new_window); - g_variant_dict_lookup (options, "new-document", "b", &new_document); - g_variant_dict_lookup (options, "geometry", "s", &geometry); + g_variant_dict_lookup (options, "new-window", "b", &priv->new_window); + g_variant_dict_lookup (options, "new-document", "b", &priv->new_document); + g_variant_dict_lookup (options, "geometry", "s", &priv->geometry); if (g_variant_dict_contains (options, "wait")) { - command_line = cl; + priv->command_line = cl; } if (g_variant_dict_lookup (options, "encoding", "&s", &encoding_charset)) { - encoding = gtk_source_encoding_get_from_charset (encoding_charset); + priv->encoding = gtk_source_encoding_get_from_charset (encoding_charset); - if (encoding == NULL) + if (priv->encoding == NULL) { g_application_command_line_printerr (cl, _("%s: invalid encoding."), encoding_charset); } @@ -507,33 +539,33 @@ xed_app_command_line (GApplication *application, if (*(remaining_args[i] + 1) == '\0') { /* goto the last line of the document */ - line_position = G_MAXINT; + priv->line_position = G_MAXINT; } else { - get_line_position (remaining_args[i] + 1, &line_position); + get_line_position (remaining_args[i] + 1, &priv->line_position); } } else if (*remaining_args[i] == '-' && *(remaining_args[i] + 1) == '\0') { - stdin_stream = g_application_command_line_get_stdin (cl); + priv->stdin_stream = g_application_command_line_get_stdin (cl); } else { GFile *file; file = g_application_command_line_create_file_for_arg (cl, remaining_args[i]); - file_list = g_slist_prepend (file_list, file); + priv->file_list = g_slist_prepend (priv->file_list, file); } } - file_list = g_slist_reverse (file_list); + priv->file_list = g_slist_reverse (priv->file_list); g_free (remaining_args); } g_application_activate (application); - clear_options (); + clear_options (XED_APP (application)); return 0; } diff --git a/xed/xed.c b/xed/xed.c index 6c1d4ed..7dc2d6c 100644 --- a/xed/xed.c +++ b/xed/xed.c @@ -59,7 +59,7 @@ main (int argc, char *argv[]) app = g_object_new (XED_TYPE_APP, "application-id", "org.x.editor", - "flags", G_APPLICATION_HANDLES_COMMAND_LINE, + "flags", G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_HANDLES_OPEN, NULL); status = g_application_run (G_APPLICATION (app), argc, argv); From 3567a8e4c9ecfef461ee1436908b5f3572c598f0 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Thu, 9 Feb 2017 03:34:02 -0800 Subject: [PATCH 126/132] xed-app: Handle also application::open --- xed/xed-app.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/xed/xed-app.c b/xed/xed-app.c index e9bd309..291e434 100644 --- a/xed/xed-app.c +++ b/xed/xed-app.c @@ -622,6 +622,41 @@ xed_app_handle_local_options (GApplication *application, return -1; } +/* Note: when launched from command line we do not reach this method + * since we manually handle the command line parameters in order to + * parse +LINE, stdin, etc. + * However this method is called when open() is called via dbus, for + * instance when double clicking on a file in nautilus + */ +static void +xed_app_open (GApplication *application, + GFile **files, + gint n_files, + const gchar *hint) +{ + gint i; + GSList *file_list = NULL; + + for (i = 0; i < n_files; i++) + { + file_list = g_slist_prepend (file_list, files[i]); + } + + file_list = g_slist_reverse (file_list); + + open_files (application, + FALSE, + FALSE, + NULL, + 0, + NULL, + NULL, + file_list, + NULL); + + g_slist_free (file_list); +} + static gboolean ensure_user_config_dir (void) { @@ -772,6 +807,7 @@ xed_app_class_init (XedAppClass *klass) app_class->activate = xed_app_activate; app_class->command_line = xed_app_command_line; app_class->handle_local_options = xed_app_handle_local_options; + app_class->open = xed_app_open; app_class->shutdown = xed_app_shutdown; g_type_class_add_private (object_class, sizeof (XedAppPrivate)); From 17837139ac368996409cde9422c40536a2202027 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Thu, 9 Feb 2017 03:47:08 -0800 Subject: [PATCH 127/132] xed-app: Shutdown metadata-manager after GTK+ --- xed/xed-app.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xed/xed-app.c b/xed/xed-app.c index 291e434..c70a422 100644 --- a/xed/xed-app.c +++ b/xed/xed-app.c @@ -785,13 +785,17 @@ xed_app_shutdown (GApplication *app) save_page_setup (XED_APP (app)); save_print_settings (XED_APP (app)); + /* GTK+ can still hold references to some xed objects, for example + * XedDocument for the clipboard. So the metadata-manager should be + * shutdown after. + */ + G_APPLICATION_CLASS (xed_app_parent_class)->shutdown (app); + #ifndef ENABLE_GVFS_METADATA xed_metadata_manager_shutdown (); #endif xed_dirs_shutdown (); - - G_APPLICATION_CLASS (xed_app_parent_class)->shutdown (app); } static void From 399fc81a41050cb05ac318f5c00a1691f3466b0a Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Thu, 9 Feb 2017 04:04:03 -0800 Subject: [PATCH 128/132] xed-app: Fix a typo --- xed/xed-app.c | 1 - 1 file changed, 1 deletion(-) diff --git a/xed/xed-app.c b/xed/xed-app.c index c70a422..930d6cf 100644 --- a/xed/xed-app.c +++ b/xed/xed-app.c @@ -484,7 +484,6 @@ clear_options (XedApp *app) priv->encoding = NULL; priv->file_list = NULL; priv->line_position = 0; - priv->column_position = 0; priv->command_line = NULL; } From 69f71de2def5d35c724006c7490b80bc72963c04 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Thu, 9 Feb 2017 10:30:52 -0800 Subject: [PATCH 129/132] xed-window: Fix getting the wrong window size when cloning a window This was mostly caused by a missing set of parens resulting in the wrong logic being used. Go ahead a clean things up just a bit while I'm here. --- xed/xed-window.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/xed/xed-window.c b/xed/xed-window.c index 293d51b..a378b01 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -268,7 +268,7 @@ xed_window_configure_event (GtkWidget *widget, XedWindow *window = XED_WINDOW (widget); if (gtk_widget_get_realized (widget) && - window->priv->state & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN) == 0) + (window->priv->state & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN)) == 0) { save_window_state (widget); } @@ -1805,20 +1805,18 @@ clone_window (XedWindow *origin) app = XED_APP (g_application_get_default ()); - screen = gtk_window_get_screen (GTK_WINDOW(origin)); + screen = gtk_window_get_screen (GTK_WINDOW (origin)); window = xed_app_create_window (app, screen); + gtk_window_set_default_size (GTK_WINDOW (window), origin->priv->width, origin->priv->height); + if ((origin->priv->window_state & GDK_WINDOW_STATE_MAXIMIZED) != 0) { - gint w, h; - _xed_window_get_default_size (&w, &h); - gtk_window_set_default_size (GTK_WINDOW(window), w, h); - gtk_window_maximize (GTK_WINDOW(window)); + gtk_window_maximize (GTK_WINDOW (window)); } else { - gtk_window_set_default_size (GTK_WINDOW(window), origin->priv->width, origin->priv->height); - gtk_window_unmaximize (GTK_WINDOW(window)); + gtk_window_unmaximize (GTK_WINDOW (window)); } if ((origin->priv->window_state & GDK_WINDOW_STATE_STICKY) != 0) @@ -3942,13 +3940,13 @@ _xed_window_move_tab_to_new_window (XedWindow *window, { XedWindow *new_window; - g_return_val_if_fail(XED_IS_WINDOW (window), NULL); - g_return_val_if_fail(XED_IS_TAB (tab), NULL); - g_return_val_if_fail(gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->priv->notebook)) > 1, NULL); + g_return_val_if_fail (XED_IS_WINDOW (window), NULL); + g_return_val_if_fail (XED_IS_TAB (tab), NULL); + g_return_val_if_fail (gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->priv->notebook)) > 1, NULL); new_window = clone_window (window); - xed_notebook_move_tab (XED_NOTEBOOK(window->priv->notebook), XED_NOTEBOOK(new_window->priv->notebook), tab, -1); - gtk_widget_show (GTK_WIDGET(new_window)); + xed_notebook_move_tab (XED_NOTEBOOK (window->priv->notebook), XED_NOTEBOOK (new_window->priv->notebook), tab, -1); + gtk_widget_show (GTK_WIDGET (new_window)); return new_window; } From 3a83594498a1f8c38423b42982d6aa977fcb1cba Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Thu, 9 Feb 2017 13:58:08 -0800 Subject: [PATCH 130/132] Add a preference to allow using the dark variant of a theme if available --- data/org.x.editor.gschema.xml.in | 6 ++++++ xed/resources/ui/xed-preferences-dialog.ui | 18 +++++++++++++++++- xed/xed-app.c | 17 +++++++++++++++++ xed/xed-preferences-dialog.c | 8 ++++++++ xed/xed-settings.c | 16 ++++++++++++++++ xed/xed-settings.h | 10 +--------- 6 files changed, 65 insertions(+), 10 deletions(-) diff --git a/data/org.x.editor.gschema.xml.in b/data/org.x.editor.gschema.xml.in index 215a150..371ebf4 100644 --- a/data/org.x.editor.gschema.xml.in +++ b/data/org.x.editor.gschema.xml.in @@ -41,6 +41,12 @@ A custom font that will be used for the editing area. This will only take effect if the "Use Default Font" option is turned off. + + false + Prefer Dark Theme + Whether xed should prefer the dark variation of the current Gtk theme if available. + + 'tango' Style Scheme diff --git a/xed/resources/ui/xed-preferences-dialog.ui b/xed/resources/ui/xed-preferences-dialog.ui index 8aa0957..7194dd4 100755 --- a/xed/resources/ui/xed-preferences-dialog.ui +++ b/xed/resources/ui/xed-preferences-dialog.ui @@ -1118,6 +1118,22 @@ 0 + + + Use dark theme variant (if available) + True + True + False + 12 + 0 + True + + + False + False + 1 + + True @@ -1216,7 +1232,7 @@ True True - 1 + 2 diff --git a/xed/xed-app.c b/xed/xed-app.c index 930d6cf..ffb202c 100644 --- a/xed/xed-app.c +++ b/xed/xed-app.c @@ -80,6 +80,7 @@ struct _XedAppPrivate GObject *settings; GSettings *window_settings; + GSettings *editor_settings; PeasExtensionSet *extensions; @@ -168,6 +169,7 @@ xed_app_dispose (GObject *object) XedApp *app = XED_APP (object); g_clear_object (&app->priv->window_settings); + g_clear_object (&app->priv->editor_settings); g_clear_object (&app->priv->settings); g_clear_object (&app->priv->page_setup); g_clear_object (&app->priv->print_settings); @@ -209,6 +211,18 @@ extension_removed (PeasExtensionSet *extensions, peas_extension_call (exten, "deactivate"); } +static void +set_initial_theme_style (XedApp *app) +{ + if (g_settings_get_boolean (app->priv->editor_settings, XED_SETTINGS_PREFER_DARK_THEME)) + { + GtkSettings *gtk_settings; + + gtk_settings = gtk_settings_get_default (); + g_object_set (G_OBJECT (gtk_settings), "gtk-application-prefer-dark-theme", TRUE, NULL); + } +} + static void xed_app_startup (GApplication *application) { @@ -248,6 +262,9 @@ xed_app_startup (GApplication *application) /* Load settings */ app->priv->settings = xed_settings_new (); app->priv->window_settings = g_settings_new ("org.x.editor.state.window"); + app->priv->editor_settings = g_settings_new ("org.x.editor.preferences.editor"); + + set_initial_theme_style (app); /* * We use the default gtksourceview style scheme manager so that plugins diff --git a/xed/xed-preferences-dialog.c b/xed/xed-preferences-dialog.c index 0046c4a..7045259 100755 --- a/xed/xed-preferences-dialog.c +++ b/xed/xed-preferences-dialog.c @@ -89,6 +89,7 @@ struct _XedPreferencesDialogPrivate GtkWidget *font_hbox; /* Style Scheme */ + GtkWidget *prefer_dark_theme_checkbutton; GtkListStore *schemes_treeview_model; GtkWidget *schemes_treeview; GtkWidget *install_scheme_button; @@ -1050,6 +1051,12 @@ setup_font_colors_page (XedPreferencesDialog *dlg) { setup_font_colors_page_font_section (dlg); setup_font_colors_page_style_scheme_section (dlg); + + g_settings_bind (dlg->priv->editor, + XED_SETTINGS_PREFER_DARK_THEME, + dlg->priv->prefer_dark_theme_checkbutton, + "active", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); } static void @@ -1127,6 +1134,7 @@ xed_preferences_dialog_init (XedPreferencesDialog *dlg) dlg->priv->default_font_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "default_font_checkbutton")); dlg->priv->font_button = GTK_WIDGET (gtk_builder_get_object (builder, "font_button")); dlg->priv->font_hbox = GTK_WIDGET (gtk_builder_get_object (builder, "font_hbox")); + dlg->priv->prefer_dark_theme_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "prefer_dark_theme_checkbutton")); dlg->priv->schemes_treeview = GTK_WIDGET (gtk_builder_get_object (builder, "schemes_treeview")); dlg->priv->install_scheme_button = GTK_WIDGET (gtk_builder_get_object (builder, "install_scheme_button")); dlg->priv->uninstall_scheme_button = GTK_WIDGET (gtk_builder_get_object (builder, "uninstall_scheme_button")); diff --git a/xed/xed-settings.c b/xed/xed-settings.c index b484aeb..3a1d02d 100644 --- a/xed/xed-settings.c +++ b/xed/xed-settings.c @@ -176,6 +176,20 @@ on_editor_font_changed (GSettings *settings, g_free (font); } +static void +on_prefer_dark_theme_changed (GSettings *settings, + const gchar *key, + XedSettings *xs) +{ + GtkSettings *gtk_settings; + gboolean prefer_dark_theme; + + prefer_dark_theme = g_settings_get_boolean (xs->priv->editor, XED_SETTINGS_PREFER_DARK_THEME); + gtk_settings = gtk_settings_get_default (); + + g_object_set (G_OBJECT (gtk_settings), "gtk-application-prefer-dark-theme", prefer_dark_theme, NULL); +} + static void on_scheme_changed (GSettings *settings, const gchar *key, @@ -375,6 +389,8 @@ xed_settings_init (XedSettings *xs) G_CALLBACK (on_use_default_font_changed), xs); g_signal_connect (xs->priv->editor, "changed::editor-font", G_CALLBACK (on_editor_font_changed), xs); + g_signal_connect (xs->priv->editor, "changed::prefer-dark-theme", + G_CALLBACK (on_prefer_dark_theme_changed), xs); g_signal_connect (xs->priv->editor, "changed::scheme", G_CALLBACK (on_scheme_changed), xs); g_signal_connect (xs->priv->editor, "changed::auto-save", diff --git a/xed/xed-settings.h b/xed/xed-settings.h index cf1b736..f65c01f 100644 --- a/xed/xed-settings.h +++ b/xed/xed-settings.h @@ -55,19 +55,10 @@ struct _XedSettingsClass GObjectClass parent_class; }; -// typedef enum { -// XED_TOOLBAR_SYSTEM = 0, -// XED_TOOLBAR_ICONS, -// XED_TOOLBAR_ICONS_AND_TEXT, -// XED_TOOLBAR_ICONS_BOTH_HORIZ -// } XedToolbarSetting; - GType xed_settings_get_type (void) G_GNUC_CONST; GObject *xed_settings_new (void); -// XedLockdownMask xed_settings_get_lockdown (XedSettings *xs); - gchar *xed_settings_get_system_font (XedSettings *xs); /* Utility functions */ @@ -81,6 +72,7 @@ void xed_settings_set_list (GSettings *settings, /* key constants */ #define XED_SETTINGS_USE_DEFAULT_FONT "use-default-font" #define XED_SETTINGS_EDITOR_FONT "editor-font" +#define XED_SETTINGS_PREFER_DARK_THEME "prefer-dark-theme" #define XED_SETTINGS_SCHEME "scheme" #define XED_SETTINGS_CREATE_BACKUP_COPY "create-backup-copy" #define XED_SETTINGS_AUTO_SAVE "auto-save" From ad31cd9e36953d1c083256121b2e2129e006684e Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Thu, 9 Feb 2017 14:15:21 -0800 Subject: [PATCH 131/132] Debian: Bring back the xed-doc package --- debian/control | 24 +++++++++++++++++++++++- debian/xed-dev.install | 1 - debian/xed-doc.install | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 debian/xed-doc.install diff --git a/debian/control b/debian/control index 0e2f191..d0ad9e8 100644 --- a/debian/control +++ b/debian/control @@ -117,4 +117,26 @@ Description: generic text editor (debugging symbols) provided to help debugging problems. . The debugging symbols are installed in /usr/lib/debug and will - automatically be used by gdb. \ No newline at end of file + automatically be used by gdb. + +Package: xed-doc +Section: doc +Architecture: all +Depends: ${misc:Depends}, +Description: generic text editor (documentation files) + Xed is a text editor which supports most standard editor features, + extending this basic functionality with other features not usually + found in simple text editors. Xed is a graphical application which + supports editing multiple text files in one window (known sometimes as + tabs or MDI). + . + Xed fully supports international text through its use of the + Unicode UTF-8 encoding in edited files. Its core feature set includes syntax + highlighting of source code, auto indentation and printing and print preview + support. + . + Xed is also extensible through its plugin system, which currently + includes support for spell checking, comparing files, viewing CVS + ChangeLogs, and adjusting indentation levels. + . + This package contains the documentation files. \ No newline at end of file diff --git a/debian/xed-dev.install b/debian/xed-dev.install index 20c7fd4..7e51a02 100644 --- a/debian/xed-dev.install +++ b/debian/xed-dev.install @@ -1,4 +1,3 @@ usr/include usr/lib/*/pkgconfig/ -usr/share/gtk-doc usr/share/xed/gir-1.0 diff --git a/debian/xed-doc.install b/debian/xed-doc.install new file mode 100644 index 0000000..95af827 --- /dev/null +++ b/debian/xed-doc.install @@ -0,0 +1 @@ +usr/share/gtk-doc From c620e48c96a4205e972e8b8cf46f163b721dbec4 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Fri, 10 Feb 2017 00:18:17 -0800 Subject: [PATCH 132/132] xed-view: Add some margin to the top and left of the text view --- xed/xed-view-gutter-renderer.c | 16 ++++++++++++++++ xed/xed-view-gutter-renderer.h | 35 ++++++++++++++++++++++++++++++++++ xed/xed-view.c | 13 +++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 xed/xed-view-gutter-renderer.c create mode 100644 xed/xed-view-gutter-renderer.h diff --git a/xed/xed-view-gutter-renderer.c b/xed/xed-view-gutter-renderer.c new file mode 100644 index 0000000..f516543 --- /dev/null +++ b/xed/xed-view-gutter-renderer.c @@ -0,0 +1,16 @@ +#include "xed-view-gutter-renderer.h" + +#define XED_VIEW_GUTTER_RENDERER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), XED_VIEW_GUTTER_RENDERER, XedViewGutterRendererPrivate)) + +G_DEFINE_TYPE (XedViewGutterRenderer, xed_view_gutter_renderer, GTK_SOURCE_TYPE_GUTTER_RENDERER) + +static void +xed_view_gutter_renderer_class_init (XedViewGutterRendererClass *klass) +{ + GtkSourceGutterRendererClass *renderer_class = GTK_SOURCE_GUTTER_RENDERER_CLASS (klass); +} + +static void +xed_view_gutter_renderer_init (XedViewGutterRenderer *self) +{ +} diff --git a/xed/xed-view-gutter-renderer.h b/xed/xed-view-gutter-renderer.h new file mode 100644 index 0000000..e863817 --- /dev/null +++ b/xed/xed-view-gutter-renderer.h @@ -0,0 +1,35 @@ +#ifndef __XED_VIEW_GUTTER_RENDERER_H__ +#define __XED_VIEW_GUTTER_RENDERER_H__ + +#include + +G_BEGIN_DECLS + +#define XED_TYPE_VIEW_GUTTER_RENDERER (xed_view_gutter_renderer_get_type ()) +#define XED_VIEW_GUTTER_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_VIEW_GUTTER_RENDERER, XedViewGutterRenderer)) +#define XED_VIEW_GUTTER_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_VIEW_GUTTER_RENDERER, XedViewGutterRendererClass)) +#define XED_IS_VIEW_GUTTER_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_VIEW_GUTTER_RENDERER)) +#define XED_IS_VIEW_GUTTER_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_VIEW_GUTTER_RENDERER)) +#define XED_VIEW_GUTTER_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_VIEW_GUTTER_RENDERER, XedViewGutterRendererClass)) + +typedef struct _XedViewGutterRenderer XedViewGutterRenderer; +typedef struct _XedViewGutterRendererClass XedViewGutterRendererClass; +typedef struct _XedViewGutterRendererPrivate XedViewGutterRendererPrivate; + +struct _XedViewGutterRenderer +{ + GtkSourceGutterRenderer parent; + + XedViewGutterRendererPrivate *priv; +}; + +struct _XedViewGutterRendererClass +{ + GtkSourceGutterRendererClass parent_instance; +}; + +GType xed_view_gutter_renderer_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* __XED_VIEW_GUTTER_RENDERER_H__ */ \ No newline at end of file diff --git a/xed/xed-view.c b/xed/xed-view.c index 01040cb..551e91a 100644 --- a/xed/xed-view.c +++ b/xed/xed-view.c @@ -10,6 +10,7 @@ #include #include "xed-view.h" +#include "xed-view-gutter-renderer.h" #include "xed-view-activatable.h" #include "xed-plugins-engine.h" #include "xed-debug.h" @@ -32,6 +33,7 @@ struct _XedViewPrivate GSettings *editor_settings; GtkTextBuffer *current_buffer; PeasExtensionSet *extensions; + GtkSourceGutterRenderer *renderer; guint view_realized : 1; }; @@ -143,6 +145,7 @@ xed_view_dispose (GObject *object) g_clear_object (&view->priv->extensions); g_clear_object (&view->priv->editor_settings); + g_clear_object (&view->priv->renderer); current_buffer_removed (view); @@ -163,6 +166,7 @@ xed_view_constructed (GObject *object) XedView *view; XedViewPrivate *priv; gboolean use_default_font; + GtkSourceGutter *gutter; view = XED_VIEW (object); priv = view->priv; @@ -246,6 +250,15 @@ xed_view_constructed (GObject *object) "indent_on_tab", TRUE, NULL); + gutter = gtk_source_view_get_gutter (GTK_SOURCE_VIEW (view), GTK_TEXT_WINDOW_LEFT); + priv->renderer = g_object_new (XED_TYPE_VIEW_GUTTER_RENDERER, + "size", 2, + NULL); + g_object_ref (priv->renderer); + gtk_source_gutter_insert (gutter, priv->renderer, 0); + + gtk_text_view_set_top_margin (GTK_TEXT_VIEW (view), 2); + G_OBJECT_CLASS (xed_view_parent_class)->constructed (object); }