xed/xedit/xedit-commands-file.c

1848 lines
44 KiB
C
Raw Permalink Normal View History

2011-11-07 13:46:58 -06:00
/*
2016-01-25 08:13:49 -06:00
* xedit-commands-file.c
* This file is part of xedit
2011-11-07 13:46:58 -06:00
*
* Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
* Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
* Copyright (C) 2002-2005 Paolo Maggi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2012-11-18 19:54:49 -06:00
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
2011-11-07 13:46:58 -06:00
*/
/*
2016-01-25 08:13:49 -06:00
* Modified by the xedit Team, 1998-2005. See the AUTHORS file for a
* list of people on the xedit Team.
2011-11-07 13:46:58 -06:00
* See the ChangeLog files for a list of changes.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h> /* For strlen and strcmp */
#include <glib/gi18n.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
2016-01-25 08:13:49 -06:00
#include "xedit-commands.h"
#include "xedit-window.h"
#include "xedit-window-private.h"
#include "xedit-statusbar.h"
#include "xedit-debug.h"
#include "xedit-utils.h"
#include "xedit-file-chooser-dialog.h"
#include "dialogs/xedit-close-confirmation-dialog.h"
2011-11-07 13:46:58 -06:00
/* Defined constants */
2016-01-25 08:13:49 -06:00
#define XEDIT_OPEN_DIALOG_KEY "xedit-open-dialog-key"
#define XEDIT_TAB_TO_SAVE_AS "xedit-tab-to-save-as"
#define XEDIT_LIST_OF_TABS_TO_SAVE_AS "xedit-list-of-tabs-to-save-as"
#define XEDIT_IS_CLOSING_ALL "xedit-is-closing-all"
#define XEDIT_IS_QUITTING "xedit-is-quitting"
#define XEDIT_IS_CLOSING_TAB "xedit-is-closing-tab"
#define XEDIT_IS_QUITTING_ALL "xedit-is-quitting-all"
static void tab_state_changed_while_saving (XeditTab *tab,
2011-11-07 13:46:58 -06:00
GParamSpec *pspec,
2016-01-25 08:13:49 -06:00
XeditWindow *window);
2011-11-07 13:46:58 -06:00
void
2016-01-25 08:13:49 -06:00
_xedit_cmd_file_new (GtkAction *action,
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_window_create_tab (window, TRUE);
2011-11-07 13:46:58 -06:00
}
2016-01-25 08:13:49 -06:00
static XeditTab *
2011-11-07 13:46:58 -06:00
get_tab_from_file (GList *docs, GFile *file)
{
2016-01-25 08:13:49 -06:00
XeditTab *tab = NULL;
2011-11-07 13:46:58 -06:00
while (docs != NULL)
{
2016-01-25 08:13:49 -06:00
XeditDocument *d;
2011-11-07 13:46:58 -06:00
GFile *l;
2016-01-25 08:13:49 -06:00
d = XEDIT_DOCUMENT (docs->data);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
l = xedit_document_get_location (d);
2011-11-07 13:46:58 -06:00
if (l != NULL)
{
if (g_file_equal (l, file))
{
2016-01-25 08:13:49 -06:00
tab = xedit_tab_get_from_document (d);
2011-11-07 13:46:58 -06:00
g_object_unref (l);
break;
}
g_object_unref (l);
}
docs = g_list_next (docs);
}
return tab;
}
static gboolean
is_duplicated_file (GSList *files, GFile *file)
{
while (files != NULL)
{
if (g_file_equal (files->data, file))
return TRUE;
files = g_slist_next (files);
}
return FALSE;
}
/* File loading */
static gint
2016-01-25 08:13:49 -06:00
load_file_list (XeditWindow *window,
2011-11-07 13:46:58 -06:00
GSList *files,
2016-01-25 08:13:49 -06:00
const XeditEncoding *encoding,
2011-11-07 13:46:58 -06:00
gint line_pos,
gboolean create)
{
2016-01-25 08:13:49 -06:00
XeditTab *tab;
2011-11-07 13:46:58 -06:00
gint loaded_files = 0; /* Number of files to load */
gboolean jump_to = TRUE; /* Whether to jump to the new tab */
GList *win_docs;
GSList *files_to_load = NULL;
GSList *l;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
win_docs = xedit_window_get_documents (window);
2011-11-07 13:46:58 -06:00
/* Remove the uris corresponding to documents already open
* in "window" and remove duplicates from "uris" list */
for (l = files; l != NULL; l = l->next)
{
if (!is_duplicated_file (files_to_load, l->data))
{
tab = get_tab_from_file (win_docs, l->data);
if (tab != NULL)
{
if (l == files)
{
2016-01-25 08:13:49 -06:00
xedit_window_set_active_tab (window, tab);
2011-11-07 13:46:58 -06:00
jump_to = FALSE;
if (line_pos > 0)
{
2016-01-25 08:13:49 -06:00
XeditDocument *doc;
XeditView *view;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
doc = xedit_tab_get_document (tab);
view = xedit_tab_get_view (tab);
2011-11-07 13:46:58 -06:00
/* document counts lines starting from 0 */
2016-01-25 08:13:49 -06:00
xedit_document_goto_line (doc, line_pos - 1);
xedit_view_scroll_to_cursor (view);
2011-11-07 13:46:58 -06:00
}
}
++loaded_files;
}
else
{
files_to_load = g_slist_prepend (files_to_load,
l->data);
}
}
}
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;
2016-01-25 08:13:49 -06:00
tab = xedit_window_get_active_tab (window);
2011-11-07 13:46:58 -06:00
if (tab != NULL)
{
2016-01-25 08:13:49 -06:00
XeditDocument *doc;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
doc = xedit_tab_get_document (tab);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
if (xedit_document_is_untouched (doc) &&
(xedit_tab_get_state (tab) == XEDIT_TAB_STATE_NORMAL))
2011-11-07 13:46:58 -06:00
{
gchar *uri;
// FIXME: pass the GFile to tab when api is there
uri = g_file_get_uri (l->data);
2016-01-25 08:13:49 -06:00
_xedit_tab_load (tab,
2011-11-07 13:46:58 -06:00
uri,
encoding,
line_pos,
create);
g_free (uri);
l = g_slist_next (l);
jump_to = FALSE;
++loaded_files;
}
}
while (l != NULL)
{
gchar *uri;
g_return_val_if_fail (l->data != NULL, 0);
// FIXME: pass the GFile to tab when api is there
uri = g_file_get_uri (l->data);
2016-01-25 08:13:49 -06:00
tab = xedit_window_create_tab_from_uri (window,
2011-11-07 13:46:58 -06:00
uri,
encoding,
line_pos,
create,
jump_to);
g_free (uri);
if (tab != NULL)
{
jump_to = FALSE;
++loaded_files;
}
l = g_slist_next (l);
}
if (loaded_files == 1)
{
2016-01-25 08:13:49 -06:00
XeditDocument *doc;
2011-11-07 13:46:58 -06:00
gchar *uri_for_display;
g_return_val_if_fail (tab != NULL, loaded_files);
2016-01-25 08:13:49 -06:00
doc = xedit_tab_get_document (tab);
uri_for_display = xedit_document_get_uri_for_display (doc);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_statusbar_flash_message (XEDIT_STATUSBAR (window->priv->statusbar),
2011-11-07 13:46:58 -06:00
window->priv->generic_message_cid,
_("Loading file '%s'\342\200\246"),
uri_for_display);
g_free (uri_for_display);
}
else
{
2016-01-25 08:13:49 -06:00
xedit_statusbar_flash_message (XEDIT_STATUSBAR (window->priv->statusbar),
2011-11-07 13:46:58 -06:00
window->priv->generic_message_cid,
ngettext("Loading %d file\342\200\246",
"Loading %d files\342\200\246",
loaded_files),
loaded_files);
}
/* Free uris_to_load. Note that l points to the first element of uris_to_load */
g_slist_free (files_to_load);
return loaded_files;
}
// FIXME: we should expose API with GFile and just make the uri
// variants backward compat wrappers
static gint
2016-01-25 08:13:49 -06:00
load_uri_list (XeditWindow *window,
2011-11-07 13:46:58 -06:00
const GSList *uris,
2016-01-25 08:13:49 -06:00
const XeditEncoding *encoding,
2011-11-07 13:46:58 -06:00
gint line_pos,
gboolean create)
{
GSList *files = NULL;
const GSList *u;
gint ret;
for (u = uris; u != NULL; u = u->next)
{
gchar *uri = u->data;
2016-01-25 08:13:49 -06:00
if (xedit_utils_is_valid_uri (uri))
2011-11-07 13:46:58 -06:00
files = g_slist_prepend (files, g_file_new_for_uri (uri));
else
g_warning ("invalid uri: %s", uri);
}
files = g_slist_reverse (files);
ret = load_file_list (window, files, encoding, line_pos, create);
g_slist_foreach (files, (GFunc) g_object_unref, NULL);
g_slist_free (files);
return ret;
}
/**
2016-01-25 08:13:49 -06:00
* xedit_commands_load_uri:
* @window:
* @uri:
* @encoding: (allow-none):
* @line_pos:
2011-11-07 13:46:58 -06:00
*
* Do nothing if uri does not exist
*
* Returns: (transfer container):
2011-11-07 13:46:58 -06:00
*/
void
2016-01-25 08:13:49 -06:00
xedit_commands_load_uri (XeditWindow *window,
2011-11-07 13:46:58 -06:00
const gchar *uri,
2016-01-25 08:13:49 -06:00
const XeditEncoding *encoding,
2011-11-07 13:46:58 -06:00
gint line_pos)
{
GSList *uris = NULL;
2016-01-25 08:13:49 -06:00
g_return_if_fail (XEDIT_IS_WINDOW (window));
2011-11-07 13:46:58 -06:00
g_return_if_fail (uri != NULL);
2016-01-25 08:13:49 -06:00
g_return_if_fail (xedit_utils_is_valid_uri (uri));
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_debug_message (DEBUG_COMMANDS, "Loading URI '%s'", uri);
2011-11-07 13:46:58 -06:00
uris = g_slist_prepend (uris, (gchar *)uri);
load_uri_list (window, uris, encoding, line_pos, FALSE);
g_slist_free (uris);
}
/**
2016-01-25 08:13:49 -06:00
* xedit_commands_load_uris:
* @window:
* @uris:
* @encoding:
* @line_pos:
*
* Ignore non-existing URIs
2011-11-07 13:46:58 -06:00
*
* Returns: (transfer container):
2011-11-07 13:46:58 -06:00
*/
gint
2016-01-25 08:13:49 -06:00
xedit_commands_load_uris (XeditWindow *window,
2011-11-07 13:46:58 -06:00
const GSList *uris,
2016-01-25 08:13:49 -06:00
const XeditEncoding *encoding,
2011-11-07 13:46:58 -06:00
gint line_pos)
{
2016-01-25 08:13:49 -06:00
g_return_val_if_fail (XEDIT_IS_WINDOW (window), 0);
2011-11-07 13:46:58 -06:00
g_return_val_if_fail ((uris != NULL) && (uris->data != NULL), 0);
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
return load_uri_list (window, uris, encoding, line_pos, FALSE);
}
/*
* This should become public once we convert all api to GFile:
*/
static gint
2016-01-25 08:13:49 -06:00
xedit_commands_load_files (XeditWindow *window,
2011-11-07 13:46:58 -06:00
GSList *files,
2016-01-25 08:13:49 -06:00
const XeditEncoding *encoding,
2011-11-07 13:46:58 -06:00
gint line_pos)
{
2016-01-25 08:13:49 -06:00
g_return_val_if_fail (XEDIT_IS_WINDOW (window), 0);
2011-11-07 13:46:58 -06:00
g_return_val_if_fail ((files != NULL) && (files->data != NULL), 0);
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
return load_file_list (window, files, encoding, line_pos, FALSE);
}
/*
* From the command line we can specify a line position for the
* first doc. Beside specifying a not existing uri creates a
* titled document.
*/
gint
2016-01-25 08:13:49 -06:00
_xedit_cmd_load_files_from_prompt (XeditWindow *window,
2011-11-07 13:46:58 -06:00
GSList *files,
2016-01-25 08:13:49 -06:00
const XeditEncoding *encoding,
2011-11-07 13:46:58 -06:00
gint line_pos)
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
return load_file_list (window, files, encoding, line_pos, TRUE);
}
static void
2016-01-25 08:13:49 -06:00
open_dialog_destroyed (XeditWindow *window,
XeditFileChooserDialog *dialog)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
g_object_set_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_OPEN_DIALOG_KEY,
2011-11-07 13:46:58 -06:00
NULL);
}
static void
2016-01-25 08:13:49 -06:00
open_dialog_response_cb (XeditFileChooserDialog *dialog,
2011-11-07 13:46:58 -06:00
gint response_id,
2016-01-25 08:13:49 -06:00
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
GSList *files;
2016-01-25 08:13:49 -06:00
const XeditEncoding *encoding;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
if (response_id != GTK_RESPONSE_OK)
{
gtk_widget_destroy (GTK_WIDGET (dialog));
return;
}
files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog));
g_return_if_fail (files != NULL);
2016-01-25 08:13:49 -06:00
encoding = xedit_file_chooser_dialog_get_encoding (dialog);
2011-11-07 13:46:58 -06:00
gtk_widget_destroy (GTK_WIDGET (dialog));
/* Remember the folder we navigated to */
2016-01-25 08:13:49 -06:00
_xedit_window_set_default_location (window, files->data);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_commands_load_files (window,
2011-11-07 13:46:58 -06:00
files,
encoding,
0);
g_slist_foreach (files, (GFunc) g_object_unref, NULL);
g_slist_free (files);
}
void
2016-01-25 08:13:49 -06:00
_xedit_cmd_file_open (GtkAction *action,
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
GtkWidget *open_dialog;
gpointer data;
2016-01-25 08:13:49 -06:00
XeditDocument *doc;
2011-11-07 13:46:58 -06:00
GFile *default_path = NULL;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
data = g_object_get_data (G_OBJECT (window), XEDIT_OPEN_DIALOG_KEY);
2011-11-07 13:46:58 -06:00
if (data != NULL)
{
2016-01-25 08:13:49 -06:00
g_return_if_fail (XEDIT_IS_FILE_CHOOSER_DIALOG (data));
2011-11-07 13:46:58 -06:00
gtk_window_present (GTK_WINDOW (data));
return;
}
/* Translators: "Open Files" is the title of the file chooser window */
2016-01-25 08:13:49 -06:00
open_dialog = xedit_file_chooser_dialog_new (_("Open Files"),
2011-11-07 13:46:58 -06:00
GTK_WINDOW (window),
GTK_FILE_CHOOSER_ACTION_OPEN,
NULL,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_OK,
NULL);
g_object_set_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_OPEN_DIALOG_KEY,
2011-11-07 13:46:58 -06:00
open_dialog);
g_object_weak_ref (G_OBJECT (open_dialog),
(GWeakNotify) open_dialog_destroyed,
window);
/* Set the curret folder uri */
2016-01-25 08:13:49 -06:00
doc = xedit_window_get_active_document (window);
2011-11-07 13:46:58 -06:00
if (doc != NULL)
{
GFile *file;
2016-01-25 08:13:49 -06:00
file = xedit_document_get_location (doc);
2011-11-07 13:46:58 -06:00
if (file != NULL)
{
default_path = g_file_get_parent (file);
g_object_unref (file);
}
}
if (default_path == NULL)
2016-01-25 08:13:49 -06:00
default_path = _xedit_window_get_default_location (window);
2011-11-07 13:46:58 -06:00
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);
g_free (uri);
g_object_unref (default_path);
}
g_signal_connect (open_dialog,
"response",
G_CALLBACK (open_dialog_response_cb),
window);
gtk_widget_show (open_dialog);
}
/* File saving */
2016-01-25 08:13:49 -06:00
static void file_save_as (XeditTab *tab, XeditWindow *window);
2011-11-07 13:46:58 -06:00
static gboolean
is_read_only (GFile *location)
{
gboolean ret = TRUE; /* default to read only */
GFileInfo *info;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
info = g_file_query_info (location,
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
G_FILE_QUERY_INFO_NONE,
NULL,
NULL);
if (info != NULL)
{
if (g_file_info_has_attribute (info,
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
{
ret = !g_file_info_get_attribute_boolean (info,
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
}
g_object_unref (info);
}
return ret;
}
/* FIXME: modify this dialog to be similar to the one provided by gtk+ for
* already existing files - Paolo (Oct. 11, 2005) */
static gboolean
replace_read_only_file (GtkWindow *parent, GFile *file)
{
GtkWidget *dialog;
gint ret;
gchar *parse_name;
gchar *name_for_display;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
parse_name = g_file_get_parse_name (file);
/* Truncate the name so it doesn't get insanely wide. Note that even
* though the dialog uses wrapped text, if the name doesn't contain
* white space then the text-wrapping code is too stupid to wrap it.
*/
2016-01-25 08:13:49 -06:00
name_for_display = xedit_utils_str_middle_truncate (parse_name, 50);
2011-11-07 13:46:58 -06:00
g_free (parse_name);
dialog = gtk_message_dialog_new (parent,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
_("The file \"%s\" is read-only."),
name_for_display);
g_free (name_for_display);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
_("Do you want to try to replace it "
"with the one you are saving?"));
gtk_dialog_add_button (GTK_DIALOG (dialog),
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL);
2016-01-25 08:13:49 -06:00
xedit_dialog_add_button (GTK_DIALOG (dialog),
2011-11-07 13:46:58 -06:00
_("_Replace"),
GTK_STOCK_SAVE_AS,
GTK_RESPONSE_YES);
gtk_dialog_set_default_response (GTK_DIALOG (dialog),
GTK_RESPONSE_CANCEL);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
ret = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
return (ret == GTK_RESPONSE_YES);
}
static void
2016-01-25 08:13:49 -06:00
save_dialog_response_cb (XeditFileChooserDialog *dialog,
2011-11-07 13:46:58 -06:00
gint response_id,
2016-01-25 08:13:49 -06:00
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
GFile *file;
2016-01-25 08:13:49 -06:00
const XeditEncoding *encoding;
XeditTab *tab;
2011-11-07 13:46:58 -06:00
gpointer data;
GSList *tabs_to_save_as;
2016-01-25 08:13:49 -06:00
XeditDocumentNewlineType newline_type;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
tab = XEDIT_TAB (g_object_get_data (G_OBJECT (dialog),
XEDIT_TAB_TO_SAVE_AS));
2011-11-07 13:46:58 -06:00
if (response_id != GTK_RESPONSE_OK)
{
gtk_widget_destroy (GTK_WIDGET (dialog));
goto save_next_tab;
}
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
g_return_if_fail (file != NULL);
2016-01-25 08:13:49 -06:00
encoding = xedit_file_chooser_dialog_get_encoding (dialog);
newline_type = xedit_file_chooser_dialog_get_newline_type (dialog);
2011-11-07 13:46:58 -06:00
gtk_widget_destroy (GTK_WIDGET (dialog));
if (tab != NULL)
{
2016-01-25 08:13:49 -06:00
XeditDocument *doc;
2011-11-07 13:46:58 -06:00
gchar *parse_name;
gchar *uri;
2016-01-25 08:13:49 -06:00
doc = xedit_tab_get_document (tab);
g_return_if_fail (XEDIT_IS_DOCUMENT (doc));
2011-11-07 13:46:58 -06:00
parse_name = g_file_get_parse_name (file);
2016-01-25 08:13:49 -06:00
xedit_statusbar_flash_message (XEDIT_STATUSBAR (window->priv->statusbar),
2011-11-07 13:46:58 -06:00
window->priv->generic_message_cid,
_("Saving file '%s'\342\200\246"),
parse_name);
g_free (parse_name);
/* let's remember the dir we navigated too,
* even if the saving fails... */
2016-01-25 08:13:49 -06:00
_xedit_window_set_default_location (window, file);
2011-11-07 13:46:58 -06:00
// FIXME: pass the GFile to tab when api is there
uri = g_file_get_uri (file);
2016-01-25 08:13:49 -06:00
_xedit_tab_save_as (tab, uri, encoding, newline_type);
2011-11-07 13:46:58 -06:00
g_free (uri);
}
g_object_unref (file);
save_next_tab:
data = g_object_get_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_LIST_OF_TABS_TO_SAVE_AS);
2011-11-07 13:46:58 -06:00
if (data == NULL)
return;
/* Save As the next tab of the list (we are Saving All files) */
tabs_to_save_as = (GSList *)data;
2016-01-25 08:13:49 -06:00
g_return_if_fail (tab == XEDIT_TAB (tabs_to_save_as->data));
2011-11-07 13:46:58 -06:00
/* Remove the first item of the list */
tabs_to_save_as = g_slist_delete_link (tabs_to_save_as,
tabs_to_save_as);
g_object_set_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_LIST_OF_TABS_TO_SAVE_AS,
2011-11-07 13:46:58 -06:00
tabs_to_save_as);
if (tabs_to_save_as != NULL)
{
2016-01-25 08:13:49 -06:00
tab = XEDIT_TAB (tabs_to_save_as->data);
2011-11-07 13:46:58 -06:00
if (GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (tab),
2016-01-25 08:13:49 -06:00
XEDIT_IS_CLOSING_TAB)) == TRUE)
2011-11-07 13:46:58 -06:00
{
g_object_set_data (G_OBJECT (tab),
2016-01-25 08:13:49 -06:00
XEDIT_IS_CLOSING_TAB,
2011-11-07 13:46:58 -06:00
NULL);
/* Trace tab state changes */
g_signal_connect (tab,
"notify::state",
G_CALLBACK (tab_state_changed_while_saving),
window);
}
2016-01-25 08:13:49 -06:00
xedit_window_set_active_tab (window, tab);
2011-11-07 13:46:58 -06:00
file_save_as (tab, window);
}
}
static GtkFileChooserConfirmation
confirm_overwrite_callback (GtkFileChooser *dialog,
gpointer data)
{
gchar *uri;
GFile *file;
GtkFileChooserConfirmation res;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
uri = gtk_file_chooser_get_uri (dialog);
file = g_file_new_for_uri (uri);
g_free (uri);
if (is_read_only (file))
{
if (replace_read_only_file (GTK_WINDOW (dialog), file))
res = GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME;
else
res = GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN;
}
else
{
/* fall back to the default confirmation dialog */
res = GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM;
}
g_object_unref (file);
return res;
}
static void
2016-01-25 08:13:49 -06:00
file_save_as (XeditTab *tab,
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
GtkWidget *save_dialog;
GtkWindowGroup *wg;
2016-01-25 08:13:49 -06:00
XeditDocument *doc;
2011-11-07 13:46:58 -06:00
GFile *file;
gboolean uri_set = FALSE;
2016-01-25 08:13:49 -06:00
const XeditEncoding *encoding;
XeditDocumentNewlineType newline_type;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
g_return_if_fail (XEDIT_IS_TAB (tab));
g_return_if_fail (XEDIT_IS_WINDOW (window));
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
save_dialog = xedit_file_chooser_dialog_new (_("Save As\342\200\246"),
2011-11-07 13:46:58 -06:00
GTK_WINDOW (window),
GTK_FILE_CHOOSER_ACTION_SAVE,
NULL,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
NULL);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (save_dialog),
TRUE);
g_signal_connect (save_dialog,
"confirm-overwrite",
G_CALLBACK (confirm_overwrite_callback),
NULL);
2016-01-25 08:13:49 -06:00
wg = xedit_window_get_group (window);
2011-11-07 13:46:58 -06:00
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);
/* Set the suggested file name */
2016-01-25 08:13:49 -06:00
doc = xedit_tab_get_document (tab);
file = xedit_document_get_location (doc);
2011-11-07 13:46:58 -06:00
if (file != NULL)
{
uri_set = gtk_file_chooser_set_file (GTK_FILE_CHOOSER (save_dialog),
file,
NULL);
g_object_unref (file);
}
if (!uri_set)
{
GFile *default_path;
gchar *docname;
2016-01-25 08:13:49 -06:00
default_path = _xedit_window_get_default_location (window);
docname = xedit_document_get_short_name_for_display (doc);
2011-11-07 13:46:58 -06:00
if (default_path != NULL)
{
gchar *uri;
uri = g_file_get_uri (default_path);
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (save_dialog),
uri);
g_free (uri);
g_object_unref (default_path);
}
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (save_dialog),
docname);
g_free (docname);
}
/* Set suggested encoding */
2016-01-25 08:13:49 -06:00
encoding = xedit_document_get_encoding (doc);
2011-11-07 13:46:58 -06:00
g_return_if_fail (encoding != NULL);
2016-01-25 08:13:49 -06:00
newline_type = xedit_document_get_newline_type (doc);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_file_chooser_dialog_set_encoding (XEDIT_FILE_CHOOSER_DIALOG (save_dialog),
2011-11-07 13:46:58 -06:00
encoding);
2016-01-25 08:13:49 -06:00
xedit_file_chooser_dialog_set_newline_type (XEDIT_FILE_CHOOSER_DIALOG (save_dialog),
2011-11-07 13:46:58 -06:00
newline_type);
g_object_set_data (G_OBJECT (save_dialog),
2016-01-25 08:13:49 -06:00
XEDIT_TAB_TO_SAVE_AS,
2011-11-07 13:46:58 -06:00
tab);
g_signal_connect (save_dialog,
"response",
G_CALLBACK (save_dialog_response_cb),
window);
gtk_widget_show (save_dialog);
}
static void
2016-01-25 08:13:49 -06:00
file_save (XeditTab *tab,
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
XeditDocument *doc;
2011-11-07 13:46:58 -06:00
gchar *uri_for_display;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
g_return_if_fail (XEDIT_IS_TAB (tab));
g_return_if_fail (XEDIT_IS_WINDOW (window));
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
doc = xedit_tab_get_document (tab);
g_return_if_fail (XEDIT_IS_DOCUMENT (doc));
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
if (xedit_document_is_untitled (doc) ||
xedit_document_get_readonly (doc))
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
xedit_debug_message (DEBUG_COMMANDS, "Untitled or Readonly");
2011-11-07 13:46:58 -06:00
file_save_as (tab, window);
return;
}
2016-01-25 08:13:49 -06:00
uri_for_display = xedit_document_get_uri_for_display (doc);
xedit_statusbar_flash_message (XEDIT_STATUSBAR (window->priv->statusbar),
2011-11-07 13:46:58 -06:00
window->priv->generic_message_cid,
_("Saving file '%s'\342\200\246"),
uri_for_display);
g_free (uri_for_display);
2016-01-25 08:13:49 -06:00
_xedit_tab_save (tab);
2011-11-07 13:46:58 -06:00
}
void
2016-01-25 08:13:49 -06:00
_xedit_cmd_file_save (GtkAction *action,
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
XeditTab *tab;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
tab = xedit_window_get_active_tab (window);
2011-11-07 13:46:58 -06:00
if (tab == NULL)
return;
file_save (tab, window);
}
void
2016-01-25 08:13:49 -06:00
_xedit_cmd_file_save_as (GtkAction *action,
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
XeditTab *tab;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
tab = xedit_window_get_active_tab (window);
2011-11-07 13:46:58 -06:00
if (tab == NULL)
return;
file_save_as (tab, window);
}
static gboolean
2016-01-25 08:13:49 -06:00
document_needs_saving (XeditDocument *doc)
2011-11-07 13:46:58 -06:00
{
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 */
2016-01-25 08:13:49 -06:00
if (xedit_document_is_local (doc) && xedit_document_get_deleted (doc))
2011-11-07 13:46:58 -06:00
return TRUE;
return FALSE;
}
/*
2016-01-25 08:13:49 -06:00
* The docs in the list must belong to the same XeditWindow.
2011-11-07 13:46:58 -06:00
*/
void
2016-01-25 08:13:49 -06:00
_xedit_cmd_file_save_documents_list (XeditWindow *window,
2011-11-07 13:46:58 -06:00
GList *docs)
{
GList *l;
GSList *tabs_to_save_as = NULL;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
g_return_if_fail (!(xedit_window_get_state (window) &
(XEDIT_WINDOW_STATE_PRINTING |
XEDIT_WINDOW_STATE_SAVING_SESSION)));
2011-11-07 13:46:58 -06:00
l = docs;
while (l != NULL)
{
2016-01-25 08:13:49 -06:00
XeditDocument *doc;
XeditTab *t;
XeditTabState state;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
g_return_if_fail (XEDIT_IS_DOCUMENT (l->data));
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
doc = XEDIT_DOCUMENT (l->data);
t = xedit_tab_get_from_document (doc);
state = xedit_tab_get_state (t);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
g_return_if_fail (state != XEDIT_TAB_STATE_PRINTING);
g_return_if_fail (state != XEDIT_TAB_STATE_PRINT_PREVIEWING);
g_return_if_fail (state != XEDIT_TAB_STATE_CLOSING);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
if ((state == XEDIT_TAB_STATE_NORMAL) ||
(state == XEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW) ||
(state == XEDIT_TAB_STATE_GENERIC_NOT_EDITABLE))
2011-11-07 13:46:58 -06:00
{
/* FIXME: manage the case of local readonly files owned by the
2016-01-25 08:13:49 -06:00
user is running xedit - Paolo (Dec. 8, 2005) */
if (xedit_document_is_untitled (doc) ||
xedit_document_get_readonly (doc))
2011-11-07 13:46:58 -06:00
{
if (document_needs_saving (doc))
{
tabs_to_save_as = g_slist_prepend (tabs_to_save_as,
t);
}
}
else
{
file_save (t, window);
}
}
else
{
/* If the state is:
2016-01-25 08:13:49 -06:00
- XEDIT_TAB_STATE_LOADING: we do not save since we are sure the file is unmodified
- XEDIT_TAB_STATE_REVERTING: we do not save since the user wants
2011-11-07 13:46:58 -06:00
to return back to the version of the file she previously saved
2016-01-25 08:13:49 -06:00
- XEDIT_TAB_STATE_SAVING: well, we are already saving (no need to save again)
- XEDIT_TAB_STATE_PRINTING, XEDIT_TAB_STATE_PRINT_PREVIEWING: there is not a
2011-11-07 13:46:58 -06:00
real reason for not saving in this case, we do not save to avoid to run
two operations using the message area at the same time (may be we can remove
this limitation in the future). Note that SaveAll, ClosAll
and Quit are unsensitive if the window state is PRINTING.
2016-01-25 08:13:49 -06:00
- XEDIT_TAB_STATE_GENERIC_ERROR: we do not save since the document contains
2011-11-07 13:46:58 -06:00
errors (I don't think this is a very frequent case, we should probably remove
this state)
2016-01-25 08:13:49 -06:00
- XEDIT_TAB_STATE_LOADING_ERROR: there is nothing to save
- XEDIT_TAB_STATE_REVERTING_ERROR: there is nothing to save and saving the current
2011-11-07 13:46:58 -06:00
document will overwrite the copy of the file the user wants to go back to
2016-01-25 08:13:49 -06:00
- XEDIT_TAB_STATE_SAVING_ERROR: we do not save since we just failed to save, so there is
2011-11-07 13:46:58 -06:00
no reason to automatically retry... we wait for user intervention
2016-01-25 08:13:49 -06:00
- XEDIT_TAB_STATE_CLOSING: this state is invalid in this case
2011-11-07 13:46:58 -06:00
*/
gchar *uri_for_display;
2016-01-25 08:13:49 -06:00
uri_for_display = xedit_document_get_uri_for_display (doc);
xedit_debug_message (DEBUG_COMMANDS,
2011-11-07 13:46:58 -06:00
"File '%s' not saved. State: %d",
uri_for_display,
state);
g_free (uri_for_display);
}
l = g_list_next (l);
}
if (tabs_to_save_as != NULL)
{
2016-01-25 08:13:49 -06:00
XeditTab *tab;
2011-11-07 13:46:58 -06:00
tabs_to_save_as = g_slist_reverse (tabs_to_save_as );
g_return_if_fail (g_object_get_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_LIST_OF_TABS_TO_SAVE_AS) == NULL);
2011-11-07 13:46:58 -06:00
g_object_set_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_LIST_OF_TABS_TO_SAVE_AS,
2011-11-07 13:46:58 -06:00
tabs_to_save_as);
2016-01-25 08:13:49 -06:00
tab = XEDIT_TAB (tabs_to_save_as->data);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_window_set_active_tab (window, tab);
2011-11-07 13:46:58 -06:00
file_save_as (tab, window);
}
}
void
2016-01-25 08:13:49 -06:00
xedit_commands_save_all_documents (XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
GList *docs;
2016-01-25 08:13:49 -06:00
g_return_if_fail (XEDIT_IS_WINDOW (window));
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
docs = xedit_window_get_documents (window);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
_xedit_cmd_file_save_documents_list (window, docs);
2011-11-07 13:46:58 -06:00
g_list_free (docs);
}
void
2016-01-25 08:13:49 -06:00
_xedit_cmd_file_save_all (GtkAction *action,
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
xedit_commands_save_all_documents (window);
2011-11-07 13:46:58 -06:00
}
void
2016-01-25 08:13:49 -06:00
xedit_commands_save_document (XeditWindow *window,
XeditDocument *document)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
XeditTab *tab;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
g_return_if_fail (XEDIT_IS_WINDOW (window));
g_return_if_fail (XEDIT_IS_DOCUMENT (document));
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
tab = xedit_tab_get_from_document (document);
2011-11-07 13:46:58 -06:00
file_save (tab, window);
}
/* File revert */
static void
2016-01-25 08:13:49 -06:00
do_revert (XeditWindow *window,
XeditTab *tab)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
XeditDocument *doc;
2011-11-07 13:46:58 -06:00
gchar *docname;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
doc = xedit_tab_get_document (tab);
docname = xedit_document_get_short_name_for_display (doc);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_statusbar_flash_message (XEDIT_STATUSBAR (window->priv->statusbar),
2011-11-07 13:46:58 -06:00
window->priv->generic_message_cid,
_("Reverting the document '%s'\342\200\246"),
docname);
g_free (docname);
2016-01-25 08:13:49 -06:00
_xedit_tab_revert (tab);
2011-11-07 13:46:58 -06:00
}
static void
revert_dialog_response_cb (GtkDialog *dialog,
gint response_id,
2016-01-25 08:13:49 -06:00
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
XeditTab *tab;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
/* FIXME: we are relying on the fact that the dialog is
modal so the active tab can't be changed...
not very nice - Paolo (Oct 11, 2005) */
2016-01-25 08:13:49 -06:00
tab = xedit_window_get_active_tab (window);
2011-11-07 13:46:58 -06:00
if (tab == NULL)
return;
gtk_widget_destroy (GTK_WIDGET (dialog));
if (response_id == GTK_RESPONSE_OK)
{
do_revert (window, tab);
}
}
static GtkWidget *
2016-01-25 08:13:49 -06:00
revert_dialog (XeditWindow *window,
XeditDocument *doc)
2011-11-07 13:46:58 -06:00
{
GtkWidget *dialog;
gchar *docname;
gchar *primary_msg;
gchar *secondary_msg;
glong seconds;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
docname = xedit_document_get_short_name_for_display (doc);
2011-11-07 13:46:58 -06:00
primary_msg = g_strdup_printf (_("Revert unsaved changes to document '%s'?"),
docname);
g_free (docname);
2016-01-25 08:13:49 -06:00
seconds = MAX (1, _xedit_document_get_seconds_since_last_save_or_load (doc));
2011-11-07 13:46:58 -06:00
if (seconds < 55)
{
secondary_msg = g_strdup_printf (
ngettext ("Changes made to the document in the last %ld second "
"will be permanently lost.",
"Changes made to the document in the last %ld seconds "
"will be permanently lost.",
seconds),
seconds);
}
else if (seconds < 75) /* 55 <= seconds < 75 */
{
secondary_msg = g_strdup (_("Changes made to the document in the last minute "
"will be permanently lost."));
}
else if (seconds < 110) /* 75 <= seconds < 110 */
{
secondary_msg = g_strdup_printf (
ngettext ("Changes made to the document in the last minute and "
"%ld second will be permanently lost.",
"Changes made to the document in the last minute and "
"%ld seconds will be permanently lost.",
seconds - 60 ),
seconds - 60);
}
else if (seconds < 3600)
{
secondary_msg = g_strdup_printf (
ngettext ("Changes made to the document in the last %ld minute "
"will be permanently lost.",
"Changes made to the document in the last %ld minutes "
"will be permanently lost.",
seconds / 60),
seconds / 60);
}
else if (seconds < 7200)
{
gint minutes;
seconds -= 3600;
minutes = seconds / 60;
if (minutes < 5)
{
secondary_msg = g_strdup (_("Changes made to the document in the last hour "
"will be permanently lost."));
}
else
{
secondary_msg = g_strdup_printf (
ngettext ("Changes made to the document in the last hour and "
"%d minute will be permanently lost.",
"Changes made to the document in the last hour and "
"%d minutes will be permanently lost.",
minutes),
minutes);
}
}
else
{
gint hours;
hours = seconds / 3600;
secondary_msg = g_strdup_printf (
ngettext ("Changes made to the document in the last %d hour "
"will be permanently lost.",
"Changes made to the document in the last %d hours "
"will be permanently lost.",
hours),
hours);
}
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
"%s", primary_msg);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"%s", secondary_msg);
g_free (primary_msg);
g_free (secondary_msg);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
gtk_dialog_add_button (GTK_DIALOG (dialog),
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL);
2016-01-25 08:13:49 -06:00
xedit_dialog_add_button (GTK_DIALOG (dialog),
2011-11-07 13:46:58 -06:00
_("_Revert"),
GTK_STOCK_REVERT_TO_SAVED,
GTK_RESPONSE_OK);
gtk_dialog_set_default_response (GTK_DIALOG (dialog),
GTK_RESPONSE_CANCEL);
return dialog;
}
void
2016-01-25 08:13:49 -06:00
_xedit_cmd_file_revert (GtkAction *action,
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
XeditTab *tab;
XeditDocument *doc;
2011-11-07 13:46:58 -06:00
GtkWidget *dialog;
GtkWindowGroup *wg;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
tab = xedit_window_get_active_tab (window);
2011-11-07 13:46:58 -06:00
g_return_if_fail (tab != NULL);
/* If we are already displaying a notification
* reverting will drop local modifications, do
* not bug the user further */
2016-01-25 08:13:49 -06:00
if (xedit_tab_get_state (tab) == XEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION)
2011-11-07 13:46:58 -06:00
{
do_revert (window, tab);
return;
}
2016-01-25 08:13:49 -06:00
doc = xedit_tab_get_document (tab);
2011-11-07 13:46:58 -06:00
g_return_if_fail (doc != NULL);
2016-01-25 08:13:49 -06:00
g_return_if_fail (!xedit_document_is_untitled (doc));
2011-11-07 13:46:58 -06:00
dialog = revert_dialog (window, doc);
2016-01-25 08:13:49 -06:00
wg = xedit_window_get_group (window);
2011-11-07 13:46:58 -06:00
gtk_window_group_add_window (wg, GTK_WINDOW (dialog));
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
g_signal_connect (dialog,
"response",
G_CALLBACK (revert_dialog_response_cb),
window);
gtk_widget_show (dialog);
}
/* Close tab */
static gboolean
2016-01-25 08:13:49 -06:00
really_close_tab (XeditTab *tab)
2011-11-07 13:46:58 -06:00
{
GtkWidget *toplevel;
2016-01-25 08:13:49 -06:00
XeditWindow *window;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
g_return_val_if_fail (xedit_tab_get_state (tab) == XEDIT_TAB_STATE_CLOSING,
2011-11-07 13:46:58 -06:00
FALSE);
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tab));
2016-01-25 08:13:49 -06:00
g_return_val_if_fail (XEDIT_IS_WINDOW (toplevel), FALSE);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
window = XEDIT_WINDOW (toplevel);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_window_close_tab (window, tab);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
if (xedit_window_get_active_tab (window) == NULL)
2011-11-07 13:46:58 -06:00
{
gboolean is_quitting;
is_quitting = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_IS_QUITTING));
2011-11-07 13:46:58 -06:00
if (is_quitting)
gtk_widget_destroy (GTK_WIDGET (window));
}
return FALSE;
}
static void
2016-01-25 08:13:49 -06:00
tab_state_changed_while_saving (XeditTab *tab,
2011-11-07 13:46:58 -06:00
GParamSpec *pspec,
2016-01-25 08:13:49 -06:00
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
XeditTabState ts;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
ts = xedit_tab_get_state (tab);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_debug_message (DEBUG_COMMANDS, "State while saving: %d\n", ts);
2011-11-07 13:46:58 -06:00
/* When the state become NORMAL, it means the saving operation is
finished */
2016-01-25 08:13:49 -06:00
if (ts == XEDIT_TAB_STATE_NORMAL)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
XeditDocument *doc;
2011-11-07 13:46:58 -06:00
g_signal_handlers_disconnect_by_func (tab,
G_CALLBACK (tab_state_changed_while_saving),
window);
2016-01-25 08:13:49 -06:00
doc = xedit_tab_get_document (tab);
2011-11-07 13:46:58 -06:00
g_return_if_fail (doc != NULL);
/* If the saving operation failed or was interrupted, then the
document is still "modified" -> do not close the tab */
if (document_needs_saving (doc))
return;
/* 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 */
2016-01-25 08:13:49 -06:00
_xedit_tab_mark_for_closing (tab);
2011-11-07 13:46:58 -06:00
g_idle_add_full (G_PRIORITY_HIGH_IDLE,
(GSourceFunc)really_close_tab,
tab,
NULL);
}
}
static void
2016-01-25 08:13:49 -06:00
save_and_close (XeditTab *tab,
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
/* Trace tab state changes */
g_signal_connect (tab,
"notify::state",
G_CALLBACK (tab_state_changed_while_saving),
window);
file_save (tab, window);
}
static void
2016-01-25 08:13:49 -06:00
save_as_and_close (XeditTab *tab,
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
g_object_set_data (G_OBJECT (tab),
2016-01-25 08:13:49 -06:00
XEDIT_IS_CLOSING_TAB,
2011-11-07 13:46:58 -06:00
NULL);
/* Trace tab state changes */
g_signal_connect (tab,
"notify::state",
G_CALLBACK (tab_state_changed_while_saving),
window);
2016-01-25 08:13:49 -06:00
xedit_window_set_active_tab (window, tab);
2011-11-07 13:46:58 -06:00
file_save_as (tab, window);
}
static void
save_and_close_all_documents (const GList *docs,
2016-01-25 08:13:49 -06:00
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
GList *tabs;
GList *l;
GSList *sl;
GSList *tabs_to_save_as;
GSList *tabs_to_save_and_close;
GList *tabs_to_close;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
g_return_if_fail (!(xedit_window_get_state (window) & XEDIT_WINDOW_STATE_PRINTING));
2011-11-07 13:46:58 -06:00
tabs = gtk_container_get_children (
2016-01-25 08:13:49 -06:00
GTK_CONTAINER (_xedit_window_get_notebook (window)));
2011-11-07 13:46:58 -06:00
tabs_to_save_as = NULL;
tabs_to_save_and_close = NULL;
tabs_to_close = NULL;
l = tabs;
while (l != NULL)
{
2016-01-25 08:13:49 -06:00
XeditTab *t;
XeditTabState state;
XeditDocument *doc;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
t = XEDIT_TAB (l->data);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
state = xedit_tab_get_state (t);
doc = xedit_tab_get_document (t);
2011-11-07 13:46:58 -06:00
/* If the state is: ([*] invalid states)
2016-01-25 08:13:49 -06:00
- XEDIT_TAB_STATE_NORMAL: close (and if needed save)
- XEDIT_TAB_STATE_LOADING: close, we are sure the file is unmodified
- XEDIT_TAB_STATE_REVERTING: since the user wants
2011-11-07 13:46:58 -06:00
to return back to the version of the file she previously saved, we can close
without saving (CHECK: are we sure this is the right behavior, suppose the case
the original file has been deleted)
2016-01-25 08:13:49 -06:00
- [*] XEDIT_TAB_STATE_SAVING: invalid, ClosAll
2011-11-07 13:46:58 -06:00
and Quit are unsensitive if the window state is SAVING.
2016-01-25 08:13:49 -06:00
- [*] XEDIT_TAB_STATE_PRINTING, XEDIT_TAB_STATE_PRINT_PREVIEWING: there is not a
2011-11-07 13:46:58 -06:00
real reason for not closing in this case, we do not save to avoid to run
two operations using the message area at the same time (may be we can remove
this limitation in the future). Note that ClosAll
and Quit are unsensitive if the window state is PRINTING.
2016-01-25 08:13:49 -06:00
- XEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW: close (and if needed save)
- XEDIT_TAB_STATE_LOADING_ERROR: close without saving (if the state is LOADING_ERROR then the
2011-11-07 13:46:58 -06:00
document is not modified)
2016-01-25 08:13:49 -06:00
- XEDIT_TAB_STATE_REVERTING_ERROR: we do not close since the document contains errors
- XEDIT_TAB_STATE_SAVING_ERROR: we do not close since the document contains errors
- XEDIT_TAB_STATE_GENERIC_ERROR: we do not close since the document contains
2011-11-07 13:46:58 -06:00
errors (CHECK: we should problably remove this state)
2016-01-25 08:13:49 -06:00
- [*] XEDIT_TAB_STATE_CLOSING: this state is invalid in this case
2011-11-07 13:46:58 -06:00
*/
2016-01-25 08:13:49 -06:00
g_return_if_fail (state != XEDIT_TAB_STATE_PRINTING);
g_return_if_fail (state != XEDIT_TAB_STATE_PRINT_PREVIEWING);
g_return_if_fail (state != XEDIT_TAB_STATE_CLOSING);
g_return_if_fail (state != XEDIT_TAB_STATE_SAVING);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
if ((state != XEDIT_TAB_STATE_SAVING_ERROR) &&
(state != XEDIT_TAB_STATE_GENERIC_ERROR) &&
(state != XEDIT_TAB_STATE_REVERTING_ERROR))
2011-11-07 13:46:58 -06:00
{
if ((g_list_index ((GList *)docs, doc) >= 0) &&
2016-01-25 08:13:49 -06:00
(state != XEDIT_TAB_STATE_LOADING) &&
(state != XEDIT_TAB_STATE_LOADING_ERROR) &&
(state != XEDIT_TAB_STATE_REVERTING)) /* CHECK: is this the right behavior with REVERTING ?*/
2011-11-07 13:46:58 -06:00
{
/* The document must be saved before closing */
g_return_if_fail (document_needs_saving (doc));
/* FIXME: manage the case of local readonly files owned by the
2016-01-25 08:13:49 -06:00
user is running xedit - Paolo (Dec. 8, 2005) */
if (xedit_document_is_untitled (doc) ||
xedit_document_get_readonly (doc))
2011-11-07 13:46:58 -06:00
{
g_object_set_data (G_OBJECT (t),
2016-01-25 08:13:49 -06:00
XEDIT_IS_CLOSING_TAB,
2011-11-07 13:46:58 -06:00
GBOOLEAN_TO_POINTER (TRUE));
tabs_to_save_as = g_slist_prepend (tabs_to_save_as,
t);
}
else
{
tabs_to_save_and_close = g_slist_prepend (tabs_to_save_and_close,
t);
}
}
else
{
/* The document must be closed without saving */
tabs_to_close = g_list_prepend (tabs_to_close,
t);
}
}
l = g_list_next (l);
}
g_list_free (tabs);
/* Close all tabs to close (in a sync way) */
2016-01-25 08:13:49 -06:00
xedit_window_close_tabs (window, tabs_to_close);
2011-11-07 13:46:58 -06:00
g_list_free (tabs_to_close);
/* Save and close all the files in tabs_to_save_and_close */
sl = tabs_to_save_and_close;
while (sl != NULL)
{
2016-01-25 08:13:49 -06:00
save_and_close (XEDIT_TAB (sl->data),
2011-11-07 13:46:58 -06:00
window);
sl = g_slist_next (sl);
}
g_slist_free (tabs_to_save_and_close);
/* Save As and close all the files in tabs_to_save_as */
if (tabs_to_save_as != NULL)
{
2016-01-25 08:13:49 -06:00
XeditTab *tab;
2011-11-07 13:46:58 -06:00
tabs_to_save_as = g_slist_reverse (tabs_to_save_as );
g_return_if_fail (g_object_get_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_LIST_OF_TABS_TO_SAVE_AS) == NULL);
2011-11-07 13:46:58 -06:00
g_object_set_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_LIST_OF_TABS_TO_SAVE_AS,
2011-11-07 13:46:58 -06:00
tabs_to_save_as);
2016-01-25 08:13:49 -06:00
tab = XEDIT_TAB (tabs_to_save_as->data);
2011-11-07 13:46:58 -06:00
save_as_and_close (tab, window);
}
}
static void
save_and_close_document (const GList *docs,
2016-01-25 08:13:49 -06:00
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
XeditTab *tab;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
g_return_if_fail (docs->next == NULL);
2016-01-25 08:13:49 -06:00
tab = xedit_tab_get_from_document (XEDIT_DOCUMENT (docs->data));
2011-11-07 13:46:58 -06:00
g_return_if_fail (tab != NULL);
save_and_close (tab, window);
}
static void
2016-01-25 08:13:49 -06:00
close_all_tabs (XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
gboolean is_quitting;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
/* There is no document to save -> close all tabs */
2016-01-25 08:13:49 -06:00
xedit_window_close_all_tabs (window);
2011-11-07 13:46:58 -06:00
is_quitting = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_IS_QUITTING));
2011-11-07 13:46:58 -06:00
if (is_quitting)
gtk_widget_destroy (GTK_WIDGET (window));
return;
}
static void
2016-01-25 08:13:49 -06:00
close_document (XeditWindow *window,
XeditDocument *doc)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
XeditTab *tab;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
tab = xedit_tab_get_from_document (doc);
2011-11-07 13:46:58 -06:00
g_return_if_fail (tab != NULL);
2016-01-25 08:13:49 -06:00
xedit_window_close_tab (window, tab);
2011-11-07 13:46:58 -06:00
}
static void
2016-01-25 08:13:49 -06:00
close_confirmation_dialog_response_handler (XeditCloseConfirmationDialog *dlg,
2011-11-07 13:46:58 -06:00
gint response_id,
2016-01-25 08:13:49 -06:00
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
GList *selected_documents;
gboolean is_closing_all;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
is_closing_all = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_IS_CLOSING_ALL));
2011-11-07 13:46:58 -06:00
gtk_widget_hide (GTK_WIDGET (dlg));
switch (response_id)
{
case GTK_RESPONSE_YES: /* Save and Close */
2016-01-25 08:13:49 -06:00
selected_documents = xedit_close_confirmation_dialog_get_selected_documents (dlg);
2011-11-07 13:46:58 -06:00
if (selected_documents == NULL)
{
if (is_closing_all)
{
/* There is no document to save -> close all tabs */
/* We call gtk_widget_destroy before close_all_tabs
2016-01-25 08:13:49 -06:00
* because close_all_tabs could destroy the xedit window */
2011-11-07 13:46:58 -06:00
gtk_widget_destroy (GTK_WIDGET (dlg));
close_all_tabs (window);
return;
}
else
g_return_if_reached ();
}
else
{
if (is_closing_all)
{
save_and_close_all_documents (selected_documents,
window);
}
else
{
save_and_close_document (selected_documents,
window);
}
}
g_list_free (selected_documents);
break;
case GTK_RESPONSE_NO: /* Close without Saving */
if (is_closing_all)
{
/* We call gtk_widget_destroy before close_all_tabs
2016-01-25 08:13:49 -06:00
* because close_all_tabs could destroy the xedit window */
2011-11-07 13:46:58 -06:00
gtk_widget_destroy (GTK_WIDGET (dlg));
close_all_tabs (window);
return;
}
else
{
const GList *unsaved_documents;
2016-01-25 08:13:49 -06:00
unsaved_documents = xedit_close_confirmation_dialog_get_unsaved_documents (dlg);
2011-11-07 13:46:58 -06:00
g_return_if_fail (unsaved_documents->next == NULL);
close_document (window,
2016-01-25 08:13:49 -06:00
XEDIT_DOCUMENT (unsaved_documents->data));
2011-11-07 13:46:58 -06:00
}
break;
default: /* Do not close */
/* Reset is_quitting flag */
g_object_set_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_IS_QUITTING,
2011-11-07 13:46:58 -06:00
GBOOLEAN_TO_POINTER (FALSE));
break;
}
gtk_widget_destroy (GTK_WIDGET (dlg));
}
/* Returns TRUE if the tab can be immediately closed */
static gboolean
2016-01-25 08:13:49 -06:00
tab_can_close (XeditTab *tab,
2011-11-07 13:46:58 -06:00
GtkWindow *window)
{
2016-01-25 08:13:49 -06:00
XeditDocument *doc;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
doc = xedit_tab_get_document (tab);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
if (!_xedit_tab_can_close (tab))
2011-11-07 13:46:58 -06:00
{
GtkWidget *dlg;
2016-01-25 08:13:49 -06:00
dlg = xedit_close_confirmation_dialog_new_single (
2011-11-07 13:46:58 -06:00
window,
doc,
FALSE);
g_signal_connect (dlg,
"response",
G_CALLBACK (close_confirmation_dialog_response_handler),
window);
gtk_widget_show (dlg);
return FALSE;
}
return TRUE;
}
/* CHECK: we probably need this one public for plugins...
* maybe even a _list variant. Or maybe it's better make
2016-01-25 08:13:49 -06:00
* xedit_window_close_tab always run the confirm dialog?
2011-11-07 13:46:58 -06:00
* we should not allow closing a tab without resetting the
2016-01-25 08:13:49 -06:00
* XEDIT_IS_CLOSING_ALL flag!
2011-11-07 13:46:58 -06:00
*/
void
2016-01-25 08:13:49 -06:00
_xedit_cmd_file_close_tab (XeditTab *tab,
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
g_return_if_fail (GTK_WIDGET (window) == gtk_widget_get_toplevel (GTK_WIDGET (tab)));
g_object_set_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_IS_CLOSING_ALL,
2011-11-07 13:46:58 -06:00
GBOOLEAN_TO_POINTER (FALSE));
g_object_set_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_IS_QUITTING,
2011-11-07 13:46:58 -06:00
GBOOLEAN_TO_POINTER (FALSE));
g_object_set_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_IS_QUITTING_ALL,
2011-11-07 13:46:58 -06:00
GINT_TO_POINTER (FALSE));
if (tab_can_close (tab, GTK_WINDOW (window)))
2016-01-25 08:13:49 -06:00
xedit_window_close_tab (window, tab);
2011-11-07 13:46:58 -06:00
}
void
2016-01-25 08:13:49 -06:00
_xedit_cmd_file_close (GtkAction *action,
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
XeditTab *active_tab;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
active_tab = xedit_window_get_active_tab (window);
2011-11-07 13:46:58 -06:00
if (active_tab == NULL)
{
return;
}
2016-01-25 08:13:49 -06:00
_xedit_cmd_file_close_tab (active_tab, window);
2011-11-07 13:46:58 -06:00
}
/* Close all tabs */
static void
2016-01-25 08:13:49 -06:00
file_close_all (XeditWindow *window,
2011-11-07 13:46:58 -06:00
gboolean is_quitting)
{
GList *unsaved_docs;
GtkWidget *dlg;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
g_return_if_fail (!(xedit_window_get_state (window) &
(XEDIT_WINDOW_STATE_SAVING |
XEDIT_WINDOW_STATE_PRINTING |
XEDIT_WINDOW_STATE_SAVING_SESSION)));
2011-11-07 13:46:58 -06:00
g_object_set_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_IS_CLOSING_ALL,
2011-11-07 13:46:58 -06:00
GBOOLEAN_TO_POINTER (TRUE));
g_object_set_data (G_OBJECT (window),
2016-01-25 08:13:49 -06:00
XEDIT_IS_QUITTING,
2011-11-07 13:46:58 -06:00
GBOOLEAN_TO_POINTER (is_quitting));
2016-01-25 08:13:49 -06:00
unsaved_docs = xedit_window_get_unsaved_documents (window);
2011-11-07 13:46:58 -06:00
if (unsaved_docs == NULL)
{
/* There is no document to save -> close all tabs */
2016-01-25 08:13:49 -06:00
xedit_window_close_all_tabs (window);
2011-11-07 13:46:58 -06:00
if (is_quitting)
gtk_widget_destroy (GTK_WIDGET (window));
return;
}
if (unsaved_docs->next == NULL)
{
/* There is only one unsaved document */
2016-01-25 08:13:49 -06:00
XeditTab *tab;
XeditDocument *doc;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
doc = XEDIT_DOCUMENT (unsaved_docs->data);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
tab = xedit_tab_get_from_document (doc);
2011-11-07 13:46:58 -06:00
g_return_if_fail (tab != NULL);
2016-01-25 08:13:49 -06:00
xedit_window_set_active_tab (window, tab);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
dlg = xedit_close_confirmation_dialog_new_single (
2011-11-07 13:46:58 -06:00
GTK_WINDOW (window),
doc,
FALSE);
}
else
{
2016-01-25 08:13:49 -06:00
dlg = xedit_close_confirmation_dialog_new (GTK_WINDOW (window),
2011-11-07 13:46:58 -06:00
unsaved_docs,
FALSE);
}
g_list_free (unsaved_docs);
g_signal_connect (dlg,
"response",
G_CALLBACK (close_confirmation_dialog_response_handler),
window);
gtk_widget_show (dlg);
}
void
2016-01-25 08:13:49 -06:00
_xedit_cmd_file_close_all (GtkAction *action,
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
g_return_if_fail (!(xedit_window_get_state (window) &
(XEDIT_WINDOW_STATE_SAVING |
XEDIT_WINDOW_STATE_PRINTING |
XEDIT_WINDOW_STATE_SAVING_SESSION)));
2011-11-07 13:46:58 -06:00
file_close_all (window, FALSE);
}
void
2016-01-25 08:13:49 -06:00
_xedit_cmd_file_quit (GtkAction *action,
XeditWindow *window)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_COMMANDS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
g_return_if_fail (!(xedit_window_get_state (window) &
(XEDIT_WINDOW_STATE_SAVING |
XEDIT_WINDOW_STATE_PRINTING |
XEDIT_WINDOW_STATE_SAVING_SESSION)));
2011-11-07 13:46:58 -06:00
file_close_all (window, TRUE);
}