[gnome-text-editor] session: add API to clear history
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] session: add API to clear history
- Date: Fri, 28 Jan 2022 20:36:00 +0000 (UTC)
commit 92e5eb69a9f1c5765a592e436d23909e5defce61
Author: Christian Hergert <chergert redhat com>
Date: Fri Jan 28 12:33:58 2022 -0800
session: add API to clear history
src/editor-session-private.h | 1 +
src/editor-session.c | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+)
---
diff --git a/src/editor-session-private.h b/src/editor-session-private.h
index 750c1cf..5080bff 100644
--- a/src/editor-session-private.h
+++ b/src/editor-session-private.h
@@ -81,5 +81,6 @@ void _editor_session_forget (EditorSession *self,
void _editor_session_mark_dirty (EditorSession *self);
void _editor_session_set_restore_pages (EditorSession *self,
gboolean restore_pages);
+void _editor_session_clear_history (EditorSession *self);
G_END_DECLS
diff --git a/src/editor-session.c b/src/editor-session.c
index a77b2c3..7b0d0aa 100644
--- a/src/editor-session.c
+++ b/src/editor-session.c
@@ -28,6 +28,7 @@
#include "editor-document-private.h"
#include "editor-page-private.h"
#include "editor-session-private.h"
+#include "editor-sidebar-item-private.h"
#include "editor-window-private.h"
#define DEFAULT_AUTO_SAVE_TIMEOUT_SECONDS 3
@@ -2305,3 +2306,44 @@ _editor_session_set_restore_pages (EditorSession *self,
self->restore_pages = !!restore_pages;
}
+
+/**
+ * _editor_session_clear_history:
+ * @self: an #EditorSession
+ *
+ * This clears the history (recently-used.xbel) and clears the
+ * panel of those items but will not clear/remove unsaved drafts
+ * as we don't want to lose that data, only history.
+ */
+void
+_editor_session_clear_history (EditorSession *self)
+{
+ g_autofree char *filename = NULL;
+ guint n_items;
+
+ g_return_if_fail (EDITOR_IS_SESSION (self));
+
+ filename = get_bookmarks_filename ();
+ g_unlink (filename);
+
+ n_items = g_list_model_get_n_items (G_LIST_MODEL (self->recents));
+
+ for (guint i = n_items; i > 0; i--)
+ {
+ g_autoptr(EditorSidebarItem) item = g_list_model_get_item (G_LIST_MODEL (self->recents), i-1);
+ const char *draft_id;
+ GFile *file;
+
+ /* Ignore modified files to avoid losing data */
+ if (_editor_sidebar_item_get_is_modified (item))
+ continue;
+
+ file = _editor_sidebar_item_get_file (item);
+ draft_id = _editor_sidebar_item_get_draft_id (item);
+
+ if (file != NULL)
+ _editor_sidebar_model_remove_file (self->recents, file);
+ else
+ _editor_sidebar_model_remove_draft (self->recents, draft_id);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]