[gnome-builder] gui: add API to get current file or directory for page
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] gui: add API to get current file or directory for page
- Date: Mon, 26 Oct 2020 21:25:39 +0000 (UTC)
commit 77688560060e3185ebabbb06d5c08e32897ee863
Author: Christian Hergert <chergert redhat com>
Date: Mon Oct 26 14:11:44 2020 -0700
gui: add API to get current file or directory for page
This can be used to try to guess file locations for pages when necessary.
We used to have this in the past, but lost it when moving to IdeTree for
our more memory conscious tree model.
Related #1320
src/libide/editor/ide-editor-page.c | 8 ++++++++
src/libide/gui/ide-page.c | 23 +++++++++++++++++++++++
src/libide/gui/ide-page.h | 3 +++
src/libide/terminal/ide-terminal-page.c | 18 ++++++++++++++++++
src/plugins/glade/gbp-glade-page.c | 19 +++++++++++++++----
5 files changed, 67 insertions(+), 4 deletions(-)
---
diff --git a/src/libide/editor/ide-editor-page.c b/src/libide/editor/ide-editor-page.c
index 823ed2c94..08cd60bf3 100644
--- a/src/libide/editor/ide-editor-page.c
+++ b/src/libide/editor/ide-editor-page.c
@@ -827,6 +827,13 @@ ide_editor_page_destroy (GtkWidget *widget)
GTK_WIDGET_CLASS (ide_editor_page_parent_class)->destroy (widget);
}
+static GFile *
+ide_editor_page_get_file_or_directory (IdePage *page)
+{
+ GFile *ret = ide_editor_page_get_file (IDE_EDITOR_PAGE (page));
+ return ret ? g_object_ref (ret) : NULL;
+}
+
static void
ide_editor_page_finalize (GObject *object)
{
@@ -913,6 +920,7 @@ ide_editor_page_class_init (IdeEditorPageClass *klass)
widget_class->hierarchy_changed = ide_editor_page_hierarchy_changed;
page_class->create_split = ide_editor_page_create_split;
+ page_class->get_file_or_directory = ide_editor_page_get_file_or_directory;
properties [PROP_BUFFER] =
g_param_spec_object ("buffer",
diff --git a/src/libide/gui/ide-page.c b/src/libide/gui/ide-page.c
index 6e6c40925..a52bfd89b 100644
--- a/src/libide/gui/ide-page.c
+++ b/src/libide/gui/ide-page.c
@@ -870,3 +870,26 @@ ide_page_report_error (IdePage *self,
"position", 0,
NULL);
}
+
+/**
+ * ide_page_get_file_or_directory:
+ * @self: a #IdePage
+ *
+ * Gets a #GFile representing a file or directory that best maps to this
+ * page. A terminal might use the current working directory while an editor
+ * or designer might use the backing file.
+ *
+ * Returns: (transfer full) (nullable): a #GFile or %NULL
+ *
+ * Since: 3.40
+ */
+GFile *
+ide_page_get_file_or_directory (IdePage *self)
+{
+ g_return_val_if_fail (IDE_IS_PAGE (self), NULL);
+
+ if (IDE_PAGE_GET_CLASS (self)->get_file_or_directory)
+ return IDE_PAGE_GET_CLASS (self)->get_file_or_directory (self);
+
+ return NULL;
+}
diff --git a/src/libide/gui/ide-page.h b/src/libide/gui/ide-page.h
index 3a5c34631..90a29cf7f 100644
--- a/src/libide/gui/ide-page.h
+++ b/src/libide/gui/ide-page.h
@@ -46,6 +46,7 @@ struct _IdePageClass
GAsyncResult *result,
GError **error);
IdePage *(*create_split) (IdePage *self);
+ GFile *(*get_file_or_directory) (IdePage *self);
/*< private >*/
gpointer _reserved[16];
@@ -115,5 +116,7 @@ IDE_AVAILABLE_IN_3_32
void ide_page_report_error (IdePage *self,
const gchar *format,
...) G_GNUC_PRINTF (2, 3);
+IDE_AVAILABLE_IN_3_40
+GFile *ide_page_get_file_or_directory (IdePage *self);
G_END_DECLS
diff --git a/src/libide/terminal/ide-terminal-page.c b/src/libide/terminal/ide-terminal-page.c
index f497101d5..a4d3b7459 100644
--- a/src/libide/terminal/ide-terminal-page.c
+++ b/src/libide/terminal/ide-terminal-page.c
@@ -397,6 +397,23 @@ ide_terminal_page_on_text_inserted_cb (IdeTerminalPage *self,
g_signal_emit (self, signals [TEXT_INSERTED], 0);
}
+static GFile *
+ide_terminal_page_get_file_or_directory (IdePage *page)
+{
+ IdeTerminalPage *self = (IdeTerminalPage *)page;
+ const char *uri;
+
+ g_assert (IDE_IS_TERMINAL_PAGE (self));
+
+ if (!(uri = vte_terminal_get_current_file_uri (VTE_TERMINAL (self->terminal_top))))
+ uri = vte_terminal_get_current_directory_uri (VTE_TERMINAL (self->terminal_top));
+
+ if (uri != NULL)
+ return g_file_new_for_uri (uri);
+
+ return NULL;
+}
+
static void
ide_terminal_page_finalize (GObject *object)
{
@@ -497,6 +514,7 @@ ide_terminal_page_class_init (IdeTerminalPageClass *klass)
widget_class->grab_focus = gbp_terminal_page_grab_focus;
page_class->create_split = gbp_terminal_page_create_split;
+ page_class->get_file_or_directory = ide_terminal_page_get_file_or_directory;
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/libide-terminal/ui/ide-terminal-page.ui");
gtk_widget_class_bind_template_child (widget_class, IdeTerminalPage, terminal_top);
diff --git a/src/plugins/glade/gbp-glade-page.c b/src/plugins/glade/gbp-glade-page.c
index 75798aeed..d60abcd72 100644
--- a/src/plugins/glade/gbp-glade-page.c
+++ b/src/plugins/glade/gbp-glade-page.c
@@ -407,6 +407,16 @@ gbp_glade_page_activate_signal_handler_cb (GbpGladePage *self,
IDE_EXIT;
}
+static GFile *
+gbp_glade_page_get_file_or_directory (IdePage *page)
+{
+ GbpGladePage *self = (GbpGladePage *)page;
+
+ g_assert (GBP_IS_GLADE_PAGE (self));
+
+ return self->file ? g_object_ref (self->file) : NULL;
+}
+
static void
gbp_glade_page_dispose (GObject *object)
{
@@ -448,18 +458,19 @@ gbp_glade_page_class_init (GbpGladePageClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- IdePageClass *view_class = IDE_PAGE_CLASS (klass);
+ IdePageClass *page_class = IDE_PAGE_CLASS (klass);
object_class->dispose = gbp_glade_page_dispose;
object_class->get_property = gbp_glade_page_get_property;
- view_class->agree_to_close_async = gbp_glade_page_agree_to_close_async;
- view_class->agree_to_close_finish = gbp_glade_page_agree_to_close_finish;
+ page_class->agree_to_close_async = gbp_glade_page_agree_to_close_async;
+ page_class->agree_to_close_finish = gbp_glade_page_agree_to_close_finish;
+ page_class->get_file_or_directory = gbp_glade_page_get_file_or_directory;
properties [PROP_PROJECT] =
g_param_spec_object ("project",
"Project",
- "The project for the view",
+ "The project for the page",
GLADE_TYPE_PROJECT,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]