xed-commands-file: Clean up code styling

This commit is contained in:
JosephMcc 2016-12-11 22:33:32 -08:00
parent 71306fa224
commit c50299ec32
1 changed files with 1101 additions and 1201 deletions

View File

@ -73,7 +73,8 @@ _xed_cmd_file_new (GtkAction *action,
}
static XedTab *
get_tab_from_file (GList *docs, GFile *file)
get_tab_from_file (GList *docs,
GFile *file)
{
XedTab *tab = NULL;
@ -104,12 +105,15 @@ get_tab_from_file (GList *docs, GFile *file)
}
static gboolean
is_duplicated_file (GSList *files, GFile *file)
is_duplicated_file (GSList *files,
GFile *file)
{
while (files != NULL)
{
if (g_file_equal (files->data, file))
{
return TRUE;
}
files = g_slist_next (files);
}
@ -177,7 +181,9 @@ load_file_list (XedWindow *window,
g_list_free (win_docs);
if (files_to_load == NULL)
{
return loaded_files;
}
files_to_load = g_slist_reverse (files_to_load);
l = files_to_load;
@ -189,18 +195,13 @@ load_file_list (XedWindow *window,
doc = xed_tab_get_document (tab);
if (xed_document_is_untouched (doc) &&
(xed_tab_get_state (tab) == XED_TAB_STATE_NORMAL))
if (xed_document_is_untouched (doc) && (xed_tab_get_state (tab) == XED_TAB_STATE_NORMAL))
{
gchar *uri;
// FIXME: pass the GFile to tab when api is there
uri = g_file_get_uri (l->data);
_xed_tab_load (tab,
uri,
encoding,
line_pos,
create);
_xed_tab_load (tab, uri, encoding, line_pos, create);
g_free (uri);
l = g_slist_next (l);
@ -218,12 +219,7 @@ load_file_list (XedWindow *window,
// FIXME: pass the GFile to tab when api is there
uri = g_file_get_uri (l->data);
tab = xed_window_create_tab_from_uri (window,
uri,
encoding,
line_pos,
create,
jump_to);
tab = xed_window_create_tab_from_uri (window, uri, encoding, line_pos, create, jump_to);
g_free (uri);
if (tab != NULL)
@ -288,10 +284,14 @@ load_uri_list (XedWindow *window,
gchar *uri = u->data;
if (xed_utils_is_valid_uri (uri))
{
files = g_slist_prepend (files, g_file_new_for_uri (uri));
}
else
{
g_warning ("invalid uri: %s", uri);
}
}
files = g_slist_reverse (files);
ret = load_file_list (window, files, encoding, line_pos, create);
@ -398,9 +398,7 @@ open_dialog_destroyed (XedWindow *window,
{
xed_debug (DEBUG_COMMANDS);
g_object_set_data (G_OBJECT (window),
XED_OPEN_DIALOG_KEY,
NULL);
g_object_set_data (G_OBJECT (window), XED_OPEN_DIALOG_KEY, NULL);
}
static void
@ -430,10 +428,7 @@ open_dialog_response_cb (XedFileChooserDialog *dialog,
/* Remember the folder we navigated to */
_xed_window_set_default_location (window, files->data);
xed_commands_load_files (window,
files,
encoding,
0);
xed_commands_load_files (window, files, encoding, 0);
g_slist_foreach (files, (GFunc) g_object_unref, NULL);
g_slist_free (files);
@ -470,13 +465,9 @@ _xed_cmd_file_open (GtkAction *action,
GTK_STOCK_OPEN, GTK_RESPONSE_OK,
NULL);
g_object_set_data (G_OBJECT (window),
XED_OPEN_DIALOG_KEY,
open_dialog);
g_object_set_data (G_OBJECT (window), XED_OPEN_DIALOG_KEY, open_dialog);
g_object_weak_ref (G_OBJECT (open_dialog),
(GWeakNotify) open_dialog_destroyed,
window);
g_object_weak_ref (G_OBJECT (open_dialog), (GWeakNotify) open_dialog_destroyed, window);
/* Set the curret folder uri */
doc = xed_window_get_active_document (window);
@ -494,24 +485,22 @@ _xed_cmd_file_open (GtkAction *action,
}
if (default_path == NULL)
{
default_path = _xed_window_get_default_location (window);
}
if (default_path != NULL)
{
gchar *uri;
uri = g_file_get_uri (default_path);
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (open_dialog),
uri);
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (open_dialog), uri);
g_free (uri);
g_object_unref (default_path);
}
g_signal_connect (open_dialog,
"response",
G_CALLBACK (open_dialog_response_cb),
window);
g_signal_connect (open_dialog, "response", G_CALLBACK (open_dialog_response_cb), window);
gtk_widget_show (open_dialog);
}
@ -535,11 +524,9 @@ is_read_only (GFile *location)
if (info != NULL)
{
if (g_file_info_has_attribute (info,
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
{
ret = !g_file_info_get_attribute_boolean (info,
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
ret = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
}
g_object_unref (info);
@ -551,7 +538,8 @@ is_read_only (GFile *location)
/* FIXME: modify this dialog to be similar to the one provided by gtk+ for
* already existing files - Paolo (Oct. 11, 2005) */
static gboolean
replace_read_only_file (GtkWindow *parent, GFile *file)
replace_read_only_file (GtkWindow *parent,
GFile *file)
{
GtkWidget *dialog;
gint ret;
@ -581,17 +569,11 @@ replace_read_only_file (GtkWindow *parent, GFile *file)
_("Do you want to try to replace it "
"with the one you are saving?"));
gtk_dialog_add_button (GTK_DIALOG (dialog),
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL);
gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
xed_dialog_add_button (GTK_DIALOG (dialog),
_("_Replace"),
GTK_STOCK_SAVE_AS,
GTK_RESPONSE_YES);
xed_dialog_add_button (GTK_DIALOG (dialog), _("_Replace"), GTK_STOCK_SAVE_AS, GTK_RESPONSE_YES);
gtk_dialog_set_default_response (GTK_DIALOG (dialog),
GTK_RESPONSE_CANCEL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
@ -616,8 +598,7 @@ save_dialog_response_cb (XedFileChooserDialog *dialog,
xed_debug (DEBUG_COMMANDS);
tab = XED_TAB (g_object_get_data (G_OBJECT (dialog),
XED_TAB_TO_SAVE_AS));
tab = XED_TAB (g_object_get_data (G_OBJECT (dialog), XED_TAB_TO_SAVE_AS));
if (response_id != GTK_RESPONSE_OK)
{
@ -666,39 +647,31 @@ save_dialog_response_cb (XedFileChooserDialog *dialog,
save_next_tab:
data = g_object_get_data (G_OBJECT (window),
XED_LIST_OF_TABS_TO_SAVE_AS);
data = g_object_get_data (G_OBJECT (window), XED_LIST_OF_TABS_TO_SAVE_AS);
if (data == NULL)
{
return;
}
/* Save As the next tab of the list (we are Saving All files) */
tabs_to_save_as = (GSList *)data;
g_return_if_fail (tab == XED_TAB (tabs_to_save_as->data));
/* Remove the first item of the list */
tabs_to_save_as = g_slist_delete_link (tabs_to_save_as,
tabs_to_save_as);
tabs_to_save_as = g_slist_delete_link (tabs_to_save_as, tabs_to_save_as);
g_object_set_data (G_OBJECT (window),
XED_LIST_OF_TABS_TO_SAVE_AS,
tabs_to_save_as);
g_object_set_data (G_OBJECT (window), XED_LIST_OF_TABS_TO_SAVE_AS, tabs_to_save_as);
if (tabs_to_save_as != NULL)
{
tab = XED_TAB (tabs_to_save_as->data);
if (GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (tab),
XED_IS_CLOSING_TAB)) == TRUE)
if (GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (tab), XED_IS_CLOSING_TAB)) == TRUE)
{
g_object_set_data (G_OBJECT (tab),
XED_IS_CLOSING_TAB,
NULL);
g_object_set_data (G_OBJECT (tab), XED_IS_CLOSING_TAB, NULL);
/* Trace tab state changes */
g_signal_connect (tab,
"notify::state",
G_CALLBACK (tab_state_changed_while_saving),
window);
g_signal_connect (tab, "notify::state", G_CALLBACK (tab_state_changed_while_saving), window);
}
xed_window_set_active_tab (window, tab);
@ -723,10 +696,14 @@ confirm_overwrite_callback (GtkFileChooser *dialog,
if (is_read_only (file))
{
if (replace_read_only_file (GTK_WINDOW (dialog), file))
{
res = GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME;
}
else
{
res = GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN;
}
}
else
{
/* fall back to the default confirmation dialog */
@ -763,17 +740,12 @@ file_save_as (XedTab *tab,
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
NULL);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (save_dialog),
TRUE);
g_signal_connect (save_dialog,
"confirm-overwrite",
G_CALLBACK (confirm_overwrite_callback),
NULL);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (save_dialog), TRUE);
g_signal_connect (save_dialog, "confirm-overwrite", G_CALLBACK (confirm_overwrite_callback), NULL);
wg = xed_window_get_group (window);
gtk_window_group_add_window (wg,
GTK_WINDOW (save_dialog));
gtk_window_group_add_window (wg, GTK_WINDOW (save_dialog));
/* Save As dialog is modal to its main window */
gtk_window_set_modal (GTK_WINDOW (save_dialog), TRUE);
@ -784,9 +756,7 @@ file_save_as (XedTab *tab,
if (file != NULL)
{
uri_set = gtk_file_chooser_set_file (GTK_FILE_CHOOSER (save_dialog),
file,
NULL);
uri_set = gtk_file_chooser_set_file (GTK_FILE_CHOOSER (save_dialog), file, NULL);
g_object_unref (file);
}
@ -805,15 +775,13 @@ file_save_as (XedTab *tab,
gchar *uri;
uri = g_file_get_uri (default_path);
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (save_dialog),
uri);
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (save_dialog), uri);
g_free (uri);
g_object_unref (default_path);
}
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (save_dialog),
docname);
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (save_dialog), docname);
g_free (docname);
}
@ -824,20 +792,13 @@ file_save_as (XedTab *tab,
newline_type = xed_document_get_newline_type (doc);
xed_file_chooser_dialog_set_encoding (XED_FILE_CHOOSER_DIALOG (save_dialog),
encoding);
xed_file_chooser_dialog_set_encoding (XED_FILE_CHOOSER_DIALOG (save_dialog), encoding);
xed_file_chooser_dialog_set_newline_type (XED_FILE_CHOOSER_DIALOG (save_dialog),
newline_type);
xed_file_chooser_dialog_set_newline_type (XED_FILE_CHOOSER_DIALOG (save_dialog), newline_type);
g_object_set_data (G_OBJECT (save_dialog),
XED_TAB_TO_SAVE_AS,
tab);
g_object_set_data (G_OBJECT (save_dialog), XED_TAB_TO_SAVE_AS, tab);
g_signal_connect (save_dialog,
"response",
G_CALLBACK (save_dialog_response_cb),
window);
g_signal_connect (save_dialog, "response", G_CALLBACK (save_dialog_response_cb), window);
gtk_widget_show (save_dialog);
}
@ -888,7 +849,9 @@ _xed_cmd_file_save (GtkAction *action,
tab = xed_window_get_active_tab (window);
if (tab == NULL)
{
return;
}
file_save (tab, window);
}
@ -903,7 +866,9 @@ _xed_cmd_file_save_as (GtkAction *action,
tab = xed_window_get_active_tab (window);
if (tab == NULL)
{
return;
}
file_save_as (tab, window);
}
@ -912,12 +877,16 @@ static gboolean
document_needs_saving (XedDocument *doc)
{
if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)))
{
return TRUE;
}
/* we check if it was deleted only for local files
* since for remote files it may hang */
if (xed_document_is_local (doc) && xed_document_get_deleted (doc))
{
return TRUE;
}
return FALSE;
}
@ -934,9 +903,7 @@ _xed_cmd_file_save_documents_list (XedWindow *window,
xed_debug (DEBUG_COMMANDS);
g_return_if_fail (!(xed_window_get_state (window) &
(XED_WINDOW_STATE_PRINTING |
XED_WINDOW_STATE_SAVING_SESSION)));
g_return_if_fail (!(xed_window_get_state (window) & (XED_WINDOW_STATE_PRINTING | XED_WINDOW_STATE_SAVING_SESSION)));
l = docs;
while (l != NULL)
@ -961,13 +928,11 @@ _xed_cmd_file_save_documents_list (XedWindow *window,
{
/* FIXME: manage the case of local readonly files owned by the
user is running xed - Paolo (Dec. 8, 2005) */
if (xed_document_is_untitled (doc) ||
xed_document_get_readonly (doc))
if (xed_document_is_untitled (doc) || xed_document_get_readonly (doc))
{
if (document_needs_saving (doc))
{
tabs_to_save_as = g_slist_prepend (tabs_to_save_as,
t);
tabs_to_save_as = g_slist_prepend (tabs_to_save_as, t);
}
}
else
@ -1017,12 +982,9 @@ _xed_cmd_file_save_documents_list (XedWindow *window,
tabs_to_save_as = g_slist_reverse (tabs_to_save_as );
g_return_if_fail (g_object_get_data (G_OBJECT (window),
XED_LIST_OF_TABS_TO_SAVE_AS) == NULL);
g_return_if_fail (g_object_get_data (G_OBJECT (window), XED_LIST_OF_TABS_TO_SAVE_AS) == NULL);
g_object_set_data (G_OBJECT (window),
XED_LIST_OF_TABS_TO_SAVE_AS,
tabs_to_save_as);
g_object_set_data (G_OBJECT (window), XED_LIST_OF_TABS_TO_SAVE_AS, tabs_to_save_as);
tab = XED_TAB (tabs_to_save_as->data);
@ -1106,7 +1068,9 @@ revert_dialog_response_cb (GtkDialog *dialog,
not very nice - Paolo (Oct 11, 2005) */
tab = xed_window_get_active_tab (window);
if (tab == NULL)
{
return;
}
gtk_widget_destroy (GTK_WIDGET (dialog));
@ -1129,16 +1093,14 @@ revert_dialog (XedWindow *window,
xed_debug (DEBUG_COMMANDS);
docname = xed_document_get_short_name_for_display (doc);
primary_msg = g_strdup_printf (_("Revert unsaved changes to document '%s'?"),
docname);
primary_msg = g_strdup_printf (_("Revert unsaved changes to document '%s'?"), docname);
g_free (docname);
seconds = MAX (1, _xed_document_get_seconds_since_last_save_or_load (doc));
if (seconds < 55)
{
secondary_msg = g_strdup_printf (
ngettext ("Changes made to the document in the last %ld second "
secondary_msg = g_strdup_printf (ngettext ("Changes made to the document in the last %ld second "
"will be permanently lost.",
"Changes made to the document in the last %ld seconds "
"will be permanently lost.",
@ -1152,8 +1114,7 @@ revert_dialog (XedWindow *window,
}
else if (seconds < 110) /* 75 <= seconds < 110 */
{
secondary_msg = g_strdup_printf (
ngettext ("Changes made to the document in the last minute and "
secondary_msg = g_strdup_printf (ngettext ("Changes made to the document in the last minute and "
"%ld second will be permanently lost.",
"Changes made to the document in the last minute and "
"%ld seconds will be permanently lost.",
@ -1162,8 +1123,7 @@ revert_dialog (XedWindow *window,
}
else if (seconds < 3600)
{
secondary_msg = g_strdup_printf (
ngettext ("Changes made to the document in the last %ld minute "
secondary_msg = g_strdup_printf (ngettext ("Changes made to the document in the last %ld minute "
"will be permanently lost.",
"Changes made to the document in the last %ld minutes "
"will be permanently lost.",
@ -1183,8 +1143,7 @@ revert_dialog (XedWindow *window,
}
else
{
secondary_msg = g_strdup_printf (
ngettext ("Changes made to the document in the last hour and "
secondary_msg = g_strdup_printf (ngettext ("Changes made to the document in the last hour and "
"%d minute will be permanently lost.",
"Changes made to the document in the last hour and "
"%d minutes will be permanently lost.",
@ -1198,8 +1157,7 @@ revert_dialog (XedWindow *window,
hours = seconds / 3600;
secondary_msg = g_strdup_printf (
ngettext ("Changes made to the document in the last %d hour "
secondary_msg = g_strdup_printf (ngettext ("Changes made to the document in the last %d hour "
"will be permanently lost.",
"Changes made to the document in the last %d hours "
"will be permanently lost.",
@ -1213,24 +1171,17 @@ revert_dialog (XedWindow *window,
GTK_BUTTONS_NONE,
"%s", primary_msg);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"%s", secondary_msg);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", secondary_msg);
g_free (primary_msg);
g_free (secondary_msg);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
gtk_dialog_add_button (GTK_DIALOG (dialog),
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL);
gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
xed_dialog_add_button (GTK_DIALOG (dialog),
_("_Revert"),
GTK_STOCK_REVERT_TO_SAVED,
GTK_RESPONSE_OK);
xed_dialog_add_button (GTK_DIALOG (dialog), _("_Revert"), GTK_STOCK_REVERT_TO_SAVED, GTK_RESPONSE_OK);
gtk_dialog_set_default_response (GTK_DIALOG (dialog),
GTK_RESPONSE_CANCEL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
return dialog;
}
@ -1270,10 +1221,7 @@ _xed_cmd_file_revert (GtkAction *action,
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
g_signal_connect (dialog,
"response",
G_CALLBACK (revert_dialog_response_cb),
window);
g_signal_connect (dialog, "response", G_CALLBACK (revert_dialog_response_cb), window);
gtk_widget_show (dialog);
}
@ -1287,8 +1235,7 @@ really_close_tab (XedTab *tab)
xed_debug (DEBUG_COMMANDS);
g_return_val_if_fail (xed_tab_get_state (tab) == XED_TAB_STATE_CLOSING,
FALSE);
g_return_val_if_fail (xed_tab_get_state (tab) == XED_TAB_STATE_CLOSING, FALSE);
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tab));
g_return_val_if_fail (XED_IS_WINDOW (toplevel), FALSE);
@ -1301,12 +1248,13 @@ really_close_tab (XedTab *tab)
{
gboolean is_quitting;
is_quitting = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window),
XED_IS_QUITTING));
is_quitting = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window), XED_IS_QUITTING));
if (is_quitting)
{
gtk_widget_destroy (GTK_WIDGET (window));
}
}
return FALSE;
}
@ -1328,9 +1276,7 @@ tab_state_changed_while_saving (XedTab *tab,
{
XedDocument *doc;
g_signal_handlers_disconnect_by_func (tab,
G_CALLBACK (tab_state_changed_while_saving),
window);
g_signal_handlers_disconnect_by_func (tab, G_CALLBACK (tab_state_changed_while_saving), window);
doc = xed_tab_get_document (tab);
g_return_if_fail (doc != NULL);
@ -1338,17 +1284,16 @@ tab_state_changed_while_saving (XedTab *tab,
/* If the saving operation failed or was interrupted, then the
document is still "modified" -> do not close the tab */
if (document_needs_saving (doc))
{
return;
}
/* Close the document only if it has been succesfully saved.
Tab state is set to CLOSING (it is a state without exiting
transitions) and the tab is closed in a idle handler */
_xed_tab_mark_for_closing (tab);
g_idle_add_full (G_PRIORITY_HIGH_IDLE,
(GSourceFunc)really_close_tab,
tab,
NULL);
g_idle_add_full (G_PRIORITY_HIGH_IDLE, (GSourceFunc)really_close_tab, tab, NULL);
}
}
@ -1359,10 +1304,7 @@ save_and_close (XedTab *tab,
xed_debug (DEBUG_COMMANDS);
/* Trace tab state changes */
g_signal_connect (tab,
"notify::state",
G_CALLBACK (tab_state_changed_while_saving),
window);
g_signal_connect (tab, "notify::state", G_CALLBACK (tab_state_changed_while_saving), window);
file_save (tab, window);
}
@ -1373,15 +1315,10 @@ save_as_and_close (XedTab *tab,
{
xed_debug (DEBUG_COMMANDS);
g_object_set_data (G_OBJECT (tab),
XED_IS_CLOSING_TAB,
NULL);
g_object_set_data (G_OBJECT (tab), XED_IS_CLOSING_TAB, NULL);
/* Trace tab state changes */
g_signal_connect (tab,
"notify::state",
G_CALLBACK (tab_state_changed_while_saving),
window);
g_signal_connect (tab, "notify::state", G_CALLBACK (tab_state_changed_while_saving), window);
xed_window_set_active_tab (window, tab);
file_save_as (tab, window);
@ -1402,8 +1339,7 @@ save_and_close_all_documents (const GList *docs,
g_return_if_fail (!(xed_window_get_state (window) & XED_WINDOW_STATE_PRINTING));
tabs = gtk_container_get_children (
GTK_CONTAINER (_xed_window_get_notebook (window)));
tabs = gtk_container_get_children (GTK_CONTAINER (_xed_window_get_notebook (window)));
tabs_to_save_as = NULL;
tabs_to_save_and_close = NULL;
@ -1464,27 +1400,21 @@ save_and_close_all_documents (const GList *docs,
/* FIXME: manage the case of local readonly files owned by the
user is running xed - Paolo (Dec. 8, 2005) */
if (xed_document_is_untitled (doc) ||
xed_document_get_readonly (doc))
if (xed_document_is_untitled (doc) || xed_document_get_readonly (doc))
{
g_object_set_data (G_OBJECT (t),
XED_IS_CLOSING_TAB,
GBOOLEAN_TO_POINTER (TRUE));
g_object_set_data (G_OBJECT (t), XED_IS_CLOSING_TAB, GBOOLEAN_TO_POINTER (TRUE));
tabs_to_save_as = g_slist_prepend (tabs_to_save_as,
t);
tabs_to_save_as = g_slist_prepend (tabs_to_save_as, t);
}
else
{
tabs_to_save_and_close = g_slist_prepend (tabs_to_save_and_close,
t);
tabs_to_save_and_close = g_slist_prepend (tabs_to_save_and_close, t);
}
}
else
{
/* The document must be closed without saving */
tabs_to_close = g_list_prepend (tabs_to_close,
t);
tabs_to_close = g_list_prepend (tabs_to_close, t);
}
}
@ -1501,8 +1431,7 @@ save_and_close_all_documents (const GList *docs,
sl = tabs_to_save_and_close;
while (sl != NULL)
{
save_and_close (XED_TAB (sl->data),
window);
save_and_close (XED_TAB (sl->data), window);
sl = g_slist_next (sl);
}
g_slist_free (tabs_to_save_and_close);
@ -1514,12 +1443,9 @@ save_and_close_all_documents (const GList *docs,
tabs_to_save_as = g_slist_reverse (tabs_to_save_as );
g_return_if_fail (g_object_get_data (G_OBJECT (window),
XED_LIST_OF_TABS_TO_SAVE_AS) == NULL);
g_return_if_fail (g_object_get_data (G_OBJECT (window), XED_LIST_OF_TABS_TO_SAVE_AS) == NULL);
g_object_set_data (G_OBJECT (window),
XED_LIST_OF_TABS_TO_SAVE_AS,
tabs_to_save_as);
g_object_set_data (G_OBJECT (window), XED_LIST_OF_TABS_TO_SAVE_AS, tabs_to_save_as);
tab = XED_TAB (tabs_to_save_as->data);
@ -1553,11 +1479,12 @@ close_all_tabs (XedWindow *window)
/* There is no document to save -> close all tabs */
xed_window_close_all_tabs (window);
is_quitting = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window),
XED_IS_QUITTING));
is_quitting = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window), XED_IS_QUITTING));
if (is_quitting)
{
gtk_widget_destroy (GTK_WIDGET (window));
}
return;
}
@ -1586,8 +1513,7 @@ close_confirmation_dialog_response_handler (XedCloseConfirmationDialog *dlg,
xed_debug (DEBUG_COMMANDS);
is_closing_all = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window),
XED_IS_CLOSING_ALL));
is_closing_all = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window), XED_IS_CLOSING_ALL));
gtk_widget_hide (GTK_WIDGET (dlg));
@ -1615,13 +1541,11 @@ close_confirmation_dialog_response_handler (XedCloseConfirmationDialog *dlg,
{
if (is_closing_all)
{
save_and_close_all_documents (selected_documents,
window);
save_and_close_all_documents (selected_documents, window);
}
else
{
save_and_close_document (selected_documents,
window);
save_and_close_document (selected_documents, window);
}
}
@ -1647,17 +1571,14 @@ close_confirmation_dialog_response_handler (XedCloseConfirmationDialog *dlg,
unsaved_documents = xed_close_confirmation_dialog_get_unsaved_documents (dlg);
g_return_if_fail (unsaved_documents->next == NULL);
close_document (window,
XED_DOCUMENT (unsaved_documents->data));
close_document (window, XED_DOCUMENT (unsaved_documents->data));
}
break;
default: /* Do not close */
/* Reset is_quitting flag */
g_object_set_data (G_OBJECT (window),
XED_IS_QUITTING,
GBOOLEAN_TO_POINTER (FALSE));
g_object_set_data (G_OBJECT (window), XED_IS_QUITTING, GBOOLEAN_TO_POINTER (FALSE));
break;
}
@ -1680,15 +1601,10 @@ tab_can_close (XedTab *tab,
{
GtkWidget *dlg;
dlg = xed_close_confirmation_dialog_new_single (
window,
doc,
FALSE);
dlg = xed_close_confirmation_dialog_new_single (window, doc, FALSE);
g_signal_connect (dlg,
"response",
G_CALLBACK (close_confirmation_dialog_response_handler),
window);
g_signal_connect (dlg, "response",
G_CALLBACK (close_confirmation_dialog_response_handler), window);
gtk_widget_show (dlg);
@ -1712,21 +1628,15 @@ _xed_cmd_file_close_tab (XedTab *tab,
g_return_if_fail (GTK_WIDGET (window) == gtk_widget_get_toplevel (GTK_WIDGET (tab)));
g_object_set_data (G_OBJECT (window),
XED_IS_CLOSING_ALL,
GBOOLEAN_TO_POINTER (FALSE));
g_object_set_data (G_OBJECT (window),
XED_IS_QUITTING,
GBOOLEAN_TO_POINTER (FALSE));
g_object_set_data (G_OBJECT (window),
XED_IS_QUITTING_ALL,
GINT_TO_POINTER (FALSE));
g_object_set_data (G_OBJECT (window), XED_IS_CLOSING_ALL, GBOOLEAN_TO_POINTER (FALSE));
g_object_set_data (G_OBJECT (window), XED_IS_QUITTING, GBOOLEAN_TO_POINTER (FALSE));
g_object_set_data (G_OBJECT (window), XED_IS_QUITTING_ALL, GINT_TO_POINTER (FALSE));
if (tab_can_close (tab, GTK_WINDOW (window)))
{
xed_window_close_tab (window, tab);
}
}
void
@ -1762,13 +1672,8 @@ file_close_all (XedWindow *window,
XED_WINDOW_STATE_PRINTING |
XED_WINDOW_STATE_SAVING_SESSION)));
g_object_set_data (G_OBJECT (window),
XED_IS_CLOSING_ALL,
GBOOLEAN_TO_POINTER (TRUE));
g_object_set_data (G_OBJECT (window),
XED_IS_QUITTING,
GBOOLEAN_TO_POINTER (is_quitting));
g_object_set_data (G_OBJECT (window), XED_IS_CLOSING_ALL, GBOOLEAN_TO_POINTER (TRUE));
g_object_set_data (G_OBJECT (window), XED_IS_QUITTING, GBOOLEAN_TO_POINTER (is_quitting));
unsaved_docs = xed_window_get_unsaved_documents (window);
@ -1778,7 +1683,9 @@ file_close_all (XedWindow *window,
xed_window_close_all_tabs (window);
if (is_quitting)
{
gtk_widget_destroy (GTK_WIDGET (window));
}
return;
}
@ -1796,24 +1703,17 @@ file_close_all (XedWindow *window,
xed_window_set_active_tab (window, tab);
dlg = xed_close_confirmation_dialog_new_single (
GTK_WINDOW (window),
doc,
FALSE);
dlg = xed_close_confirmation_dialog_new_single (GTK_WINDOW (window), doc, FALSE);
}
else
{
dlg = xed_close_confirmation_dialog_new (GTK_WINDOW (window),
unsaved_docs,
FALSE);
dlg = xed_close_confirmation_dialog_new (GTK_WINDOW (window), unsaved_docs, FALSE);
}
g_list_free (unsaved_docs);
g_signal_connect (dlg,
"response",
G_CALLBACK (close_confirmation_dialog_response_handler),
window);
g_signal_connect (dlg, "response",
G_CALLBACK (close_confirmation_dialog_response_handler), window);
gtk_widget_show (dlg);
}