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 1 commit
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
Next Next commit
implemented the creation of the .xed_session file
  • Loading branch information
tlemy committed Dec 27, 2023
commit 143f0f583e37e0835af385c51996fd39ba0558e6
67 changes: 67 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"

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

static void
export_active_docs (XedWindow *window)
{
gchar *file_name = NULL;
GFile *session_file = NULL;
GFileIOStream* iostream = NULL;
GList *docs = NULL;
XedDocument *doc = NULL;
GtkSourceFile *source_file = NULL;
GFile *docfile = NULL;
gchar *doc_file_path = NULL;

g_print ("export\n");
g_return_if_fail (XED_IS_WINDOW (window));

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

if (g_file_query_exists (session_file, NULL))
{
iostream = g_file_open_readwrite (session_file, NULL, NULL);
}
else
{
iostream = g_file_create_readwrite (session_file, G_FILE_CREATE_NONE, NULL, NULL);
}

if (iostream == NULL)
{
return;
}

docs = xed_window_get_documents (window);

g_print ("has docs: %d\n", docs != NULL);

while (docs != NULL)
{
doc = XED_DOCUMENT (docs->data);
source_file = xed_document_get_file (doc);
docfile = gtk_source_file_get_location (source_file);
doc_file_path = g_file_get_path (docfile);

// separate into smaller functions
// check if file exists
// check if null
// error when saving with warning pop up before closing
// use l variable instead of docs to free it later
// free if not null

if (doc_file_path)
{
g_print("%s\n", doc_file_path);
}

docs = g_list_next (docs);
}

g_free (file_name);
g_object_unref (session_file);
g_object_unref (iostream);
}

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

g_print ("file_quit\n");
export_active_docs(window);

file_close_all (window, TRUE);
}