Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 603 sessions #631

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions xed/xed-commands-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#define XED_IS_CLOSING_ALL "xed-is-closing-all"
#define XED_IS_QUITTING "xed-is-quitting"
#define XED_IS_QUITTING_ALL "xed-is-quitting-all"
#define XED_SESSION_FILE_NAME ".xed-session-save"

static void tab_state_changed_while_saving (XedTab *tab,
GParamSpec *pspec,
Expand Down Expand Up @@ -1377,6 +1378,76 @@ _xed_cmd_file_revert (GtkAction *action,
gtk_widget_show (dialog);
}

GFileOutputStream *
xed_session_get_output_stream ()
{
gchar *file_name = NULL;
GFile *session_file = NULL;
GFileOutputStream *ostream = NULL;

file_name = g_strconcat (g_get_home_dir(), "/", XED_SESSION_FILE_NAME, NULL);
session_file = g_file_new_for_path (file_name);
ostream = g_file_replace (session_file, NULL, 0, 0, NULL, NULL);

g_free (file_name);
g_object_unref (session_file);

return ostream;
}

static void
xed_session_save_file_paths (GList *docs, GFileOutputStream* ostream)
{
XedDocument *doc = NULL;
GtkSourceFile *source_file = NULL;
GFile *location = NULL;
gchar *file_path = NULL;
gchar *file_path_list = NULL;
gssize written, to_write;

for (GList *l = docs; l != NULL; l = g_list_next (l))
{
doc = XED_DOCUMENT (l->data);
source_file = xed_document_get_file (doc);
location = gtk_source_file_get_location (source_file);

if (location != NULL)
{
file_path = g_file_get_path (location);
file_path_list = g_strconcat (file_path, "\n", file_path_list, NULL);
}
}

to_write = sizeof (gchar) * strlen (file_path_list);
written = g_output_stream_write (G_OUTPUT_STREAM (ostream), file_path_list, to_write, NULL, NULL);

g_output_stream_close (G_OUTPUT_STREAM (ostream), NULL, NULL);
g_object_unref (location);
g_free (file_path);
g_free (file_path_list);
g_return_if_fail (to_write == written);
}

static void
xed_session_save_path_active_docs (XedWindow *window)
{
GFileOutputStream* ostream = NULL;
GList *docs = NULL;

g_return_if_fail (XED_IS_WINDOW (window));

ostream = xed_session_get_output_stream ();
docs = xed_window_get_documents (window);

g_return_if_fail (ostream != NULL);
g_return_if_fail (docs != NULL);

xed_session_save_file_paths (docs, ostream);

g_object_unref (ostream);
g_list_free (docs);
}

static void
tab_state_changed_while_saving (XedTab *tab,
GParamSpec *pspec,
Expand Down Expand Up @@ -1822,5 +1893,7 @@ _xed_cmd_file_quit (GtkAction *action,
XED_WINDOW_STATE_PRINTING |
XED_WINDOW_STATE_SAVING_SESSION)));

xed_session_save_path_active_docs (window);

file_close_all (window, TRUE);
}
Loading