From baea0e93b91314fd498ba16ba6ec13a96e6a39ad Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 1 Jan 2017 18:20:19 -0800 Subject: [PATCH] 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); }