[gnome-builder] plugins/ls: port to GTK 4
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/ls: port to GTK 4
- Date: Tue, 12 Jul 2022 06:39:17 +0000 (UTC)
commit fe3d5db9a7abeb45b1422dd5ea4cbe8e059a5997
Author: Christian Hergert <chergert redhat com>
Date: Mon Jul 11 22:58:09 2022 -0700
plugins/ls: port to GTK 4
src/plugins/ls/gbp-ls-editor-page-addin.c | 17 +++++++-----
src/plugins/ls/gbp-ls-page.c | 44 +++++--------------------------
src/plugins/ls/gbp-ls-page.ui | 5 ++++
src/plugins/ls/gbp-ls-tree-view.c | 10 +++----
src/plugins/ls/gbp-ls-workbench-addin.c | 36 +++++++++----------------
src/plugins/ls/gtk/menus.ui | 41 ++++++++++++++--------------
src/plugins/ls/ls.plugin | 2 +-
7 files changed, 62 insertions(+), 93 deletions(-)
---
diff --git a/src/plugins/ls/gbp-ls-editor-page-addin.c b/src/plugins/ls/gbp-ls-editor-page-addin.c
index e4e6423f9..fbc0856a9 100644
--- a/src/plugins/ls/gbp-ls-editor-page-addin.c
+++ b/src/plugins/ls/gbp-ls-editor-page-addin.c
@@ -22,7 +22,7 @@
#include "config.h"
-#include <dazzle.h>
+#include <libide-gtk.h>
#include <libide-editor.h>
#include "gbp-ls-editor-page-addin.h"
@@ -40,17 +40,19 @@ open_directory_cb (GSimpleAction *action,
{
IdeEditorPage *editor = user_data;
g_autoptr(GFile) directory = NULL;
- GtkWidget *stack;
GbpLsPage *page;
+ IdeBuffer *buffer;
+ IdeFrame *frame;
GFile *file;
g_assert (G_IS_SIMPLE_ACTION (action));
g_assert (IDE_IS_EDITOR_PAGE (editor));
- file = ide_editor_page_get_file (editor);
+ buffer = ide_editor_page_get_buffer (editor);
+ file = ide_buffer_get_file (buffer);
directory = g_file_get_parent (file);
- stack = gtk_widget_get_ancestor (GTK_WIDGET (editor), GTK_TYPE_STACK);
+ frame = IDE_FRAME (gtk_widget_get_ancestor (GTK_WIDGET (editor), IDE_TYPE_FRAME));
/* When used from an editor view right click menu, the folder browser acts like vim's directory
* listing, where it closes once a file is choosen.
*/
@@ -58,8 +60,9 @@ open_directory_cb (GSimpleAction *action,
"close-on-activate", TRUE,
"visible", TRUE,
NULL);
- gtk_container_add (GTK_CONTAINER (stack), GTK_WIDGET (page));
+ panel_frame_add (PANEL_FRAME (frame), PANEL_WIDGET (page));
gbp_ls_page_set_directory (page, directory);
+ panel_widget_raise (PANEL_WIDGET (page));
}
static void
@@ -68,11 +71,13 @@ open_in_files_cb (GSimpleAction *action,
gpointer user_data)
{
IdeEditorPage *editor = user_data;
+ IdeBuffer *buffer;
g_assert (G_IS_SIMPLE_ACTION (action));
g_assert (IDE_IS_EDITOR_PAGE (editor));
- dzl_file_manager_show (ide_editor_page_get_file (editor), NULL);
+ buffer = ide_editor_page_get_buffer (editor);
+ ide_file_manager_show (ide_buffer_get_file (buffer), NULL);
}
static void
diff --git a/src/plugins/ls/gbp-ls-page.c b/src/plugins/ls/gbp-ls-page.c
index a83f65590..17f7e5805 100644
--- a/src/plugins/ls/gbp-ls-page.c
+++ b/src/plugins/ls/gbp-ls-page.c
@@ -23,6 +23,7 @@
#include "config.h"
#include <glib/gi18n.h>
+
#include <libide-io.h>
#include "gbp-ls-model.h"
@@ -86,14 +87,12 @@ gbp_ls_page_row_activated_cb (GbpLsPage *self,
{
IdeWorkbench *workbench = ide_widget_get_workbench (GTK_WIDGET (self));
- ide_workbench_open_async (workbench,
- file,
- NULL,
+ ide_workbench_open_async (workbench, file, NULL,
IDE_BUFFER_OPEN_FLAGS_NONE,
- NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL);
if (self->close_on_activate)
- dzl_gtk_widget_action (GTK_WIDGET (self), "frame", "close-page", NULL);
+ panel_widget_close (PANEL_WIDGET (self));
}
}
}
@@ -113,7 +112,7 @@ modified_cell_data_func (GtkCellLayout *cell_layout,
-1);
if (when != NULL)
- format = dzl_g_date_time_format_for_display (when);
+ format = ide_g_date_time_format_for_display (when);
g_object_set (cell, "text", format, NULL);
}
@@ -135,31 +134,6 @@ size_cell_data_func (GtkCellLayout *cell_layout,
g_object_set (cell, "text", format, NULL);
}
-static void
-gbp_ls_page_style_updated (GtkWidget *widget)
-{
- GbpLsPage *self = (GbpLsPage *)widget;
- GtkStyleContext *style_context;
- GtkStateFlags state;
- GdkRGBA bg, fg;
-
- g_assert (GBP_IS_LS_PAGE (self));
-
- if (GTK_WIDGET_CLASS (gbp_ls_page_parent_class)->style_updated)
- GTK_WIDGET_CLASS (gbp_ls_page_parent_class)->style_updated (widget);
-
- style_context = gtk_widget_get_style_context (GTK_WIDGET (self->tree_view));
- state = gtk_style_context_get_state (style_context);
-
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
- gtk_style_context_get_color (style_context, state, &fg);
- gtk_style_context_get_background_color (style_context, state, &bg);
- G_GNUC_END_IGNORE_DEPRECATIONS;
-
- ide_page_set_primary_color_bg (IDE_PAGE (self), &bg);
- ide_page_set_primary_color_fg (IDE_PAGE (self), &fg);
-}
-
static void
gbp_ls_page_finalize (GObject *object)
{
@@ -227,8 +201,6 @@ gbp_ls_page_class_init (GbpLsPageClass *klass)
object_class->get_property = gbp_ls_page_get_property;
object_class->set_property = gbp_ls_page_set_property;
- widget_class->style_updated = gbp_ls_page_style_updated;
-
properties [PROP_DIRECTORY] =
g_param_spec_object ("directory",
"Directory",
@@ -259,7 +231,7 @@ gbp_ls_page_init (GbpLsPage *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
- ide_page_set_icon_name (IDE_PAGE (self), "folder-symbolic");
+ panel_widget_set_icon_name (PANEL_WIDGET (self), "folder-open-symbolic");
g_signal_connect_object (self->tree_view,
"row-activated",
@@ -338,7 +310,6 @@ void
gbp_ls_page_set_directory (GbpLsPage *self,
GFile *directory)
{
- g_autofree gchar *title = NULL;
g_autofree gchar *name = NULL;
g_autoptr(GFile) workdir = NULL;
g_autoptr(GFile) home = NULL;
@@ -388,8 +359,7 @@ gbp_ls_page_set_directory (GbpLsPage *self,
else
name = ide_path_collapse (g_file_peek_path (directory));
- title = g_strdup_printf (_("%s — Directory"), name);
- ide_page_set_title (IDE_PAGE (self), title);
+ panel_widget_set_title (PANEL_WIDGET (self), name);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_DIRECTORY]);
}
diff --git a/src/plugins/ls/gbp-ls-page.ui b/src/plugins/ls/gbp-ls-page.ui
index 6493e4612..fd79ea999 100644
--- a/src/plugins/ls/gbp-ls-page.ui
+++ b/src/plugins/ls/gbp-ls-page.ui
@@ -3,6 +3,7 @@
<template class="GbpLsPage" parent="IdePage">
<child>
<object class="GtkScrolledWindow" id="scroller">
+ <property name="hexpand">true</property>
<property name="vexpand">true</property>
<property name="visible">true</property>
<child>
@@ -15,6 +16,7 @@
<object class="GtkTreeViewColumn" id="name_column">
<property name="title" translatable="yes">Name</property>
<property name="expand">true</property>
+ <property name="resizable">true</property>
<property name="visible">true</property>
<child>
<object class="GtkCellRendererPixbuf" id="pixbuf_cell">
@@ -31,6 +33,7 @@
<child>
<object class="GtkCellRendererText" id="name_cell">
<property name="ellipsize">end</property>
+ <property name="ypad">2</property>
</object>
<attributes>
<attribute name="text">1</attribute>
@@ -44,6 +47,7 @@
<child>
<object class="GtkTreeViewColumn" id="size_column">
<property name="title" translatable="yes">Size</property>
+ <property name="resizable">true</property>
<property name="visible">true</property>
<child>
<object class="GtkCellRendererText" id="size_cell">
@@ -57,6 +61,7 @@
<child>
<object class="GtkTreeViewColumn" id="modified_column">
<property name="title" translatable="yes">Modified</property>
+ <property name="resizable">true</property>
<property name="visible">true</property>
<child>
<object class="GtkCellRendererText" id="modified_cell">
diff --git a/src/plugins/ls/gbp-ls-tree-view.c b/src/plugins/ls/gbp-ls-tree-view.c
index 372edb87a..2c214262a 100644
--- a/src/plugins/ls/gbp-ls-tree-view.c
+++ b/src/plugins/ls/gbp-ls-tree-view.c
@@ -78,7 +78,7 @@ static void
gbp_ls_tree_view_class_init (GbpLsTreeViewClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GtkBindingSet *binding_set = gtk_binding_set_by_class (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = gbp_ls_tree_view_finalize;
@@ -87,12 +87,10 @@ gbp_ls_tree_view_class_init (GbpLsTreeViewClass *klass)
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_CALLBACK (gbp_ls_tree_view_go_up),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
+ NULL, NULL, NULL, G_TYPE_NONE, 0);
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, GDK_MOD1_MASK, "go-up", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0, "go-up", 0);
+ gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Up, GDK_ALT_MASK, "go-up", 0);
+ gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_BackSpace, 0, "go-up", 0);
}
static void
diff --git a/src/plugins/ls/gbp-ls-workbench-addin.c b/src/plugins/ls/gbp-ls-workbench-addin.c
index 767fde568..48e11b46c 100644
--- a/src/plugins/ls/gbp-ls-workbench-addin.c
+++ b/src/plugins/ls/gbp-ls-workbench-addin.c
@@ -63,8 +63,8 @@ gbp_ls_workbench_addin_can_open (IdeWorkbenchAddin *addin,
}
static void
-locate_view (GtkWidget *view,
- gpointer user_data)
+locate_view (IdePage *view,
+ gpointer user_data)
{
LocateView *locate = user_data;
GFile *file;
@@ -87,7 +87,10 @@ static void
gbp_ls_workbench_addin_open_async (IdeWorkbenchAddin *addin,
GFile *file,
const gchar *content_type,
+ int at_line,
+ int at_line_offset,
IdeBufferOpenFlags flags,
+ IdePanelPosition *position,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -96,11 +99,8 @@ gbp_ls_workbench_addin_open_async (IdeWorkbenchAddin *addin,
g_autoptr(IdeTask) task = NULL;
g_autoptr(GFile) parent = NULL;
IdeWorkspace *workspace;
- IdeSurface *surface;
- GtkWidget *current_frame;
GbpLsPage *view;
- IdePage *current_page;
- LocateView locate = { 0 };
+ LocateView locate = {0};
g_assert (GBP_IS_LS_WORKBENCH_ADDIN (self));
g_assert (!self->workbench || IDE_IS_WORKBENCH (self->workbench));
@@ -119,10 +119,6 @@ gbp_ls_workbench_addin_open_async (IdeWorkbenchAddin *addin,
return;
}
- workspace = ide_workbench_get_current_workspace (self->workbench);
- if (!(surface = ide_workspace_get_surface_by_name (workspace, "editor")))
- surface = ide_workspace_get_surface_by_name (workspace, "terminal");
-
/* If this isn't a directory, get the parent */
if (!ide_str_equal0 (content_type, "inode/directory"))
file = parent = g_file_get_parent (file);
@@ -132,27 +128,21 @@ gbp_ls_workbench_addin_open_async (IdeWorkbenchAddin *addin,
ide_workbench_foreach_page (self->workbench, locate_view, &locate);
if (locate.view != NULL)
{
- ide_widget_reveal_and_grab (GTK_WIDGET (locate.view));
+ panel_widget_raise (PANEL_WIDGET (locate.view));
ide_task_return_boolean (task, TRUE);
return;
}
- current_page = ide_workspace_get_most_recent_page (workspace);
- current_frame = gtk_widget_get_ancestor (GTK_WIDGET (current_page), IDE_TYPE_FRAME);
-
- /* When opening from the project tree, it acts like a persistent folder browser, which doesn't
- * disappear when opening one of the files.
+ /* When opening from the project tree, it acts like a persistent folder
+ * browser, which doesn't disappear when opening one of the files.
*/
+ workspace = ide_workbench_get_current_workspace (self->workbench);
view = g_object_new (GBP_TYPE_LS_PAGE,
"close-on-activate", FALSE,
- "visible", TRUE,
NULL);
- if (current_frame != NULL)
- gtk_container_add (GTK_CONTAINER (current_frame), GTK_WIDGET (view));
- else
- gtk_container_add (GTK_CONTAINER (surface), GTK_WIDGET (view));
- ide_widget_reveal_and_grab (GTK_WIDGET (view));
+ ide_workspace_add_page (workspace, IDE_PAGE (view), position);
gbp_ls_page_set_directory (view, file);
+ panel_widget_raise (PANEL_WIDGET (view));
ide_task_return_boolean (task, TRUE);
}
@@ -193,7 +183,7 @@ workbench_addin_iface_init (IdeWorkbenchAddinInterface *iface)
}
G_DEFINE_FINAL_TYPE_WITH_CODE (GbpLsWorkbenchAddin, gbp_ls_workbench_addin, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKBENCH_ADDIN, workbench_addin_iface_init))
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKBENCH_ADDIN, workbench_addin_iface_init))
static void
gbp_ls_workbench_addin_class_init (GbpLsWorkbenchAddinClass *klass)
diff --git a/src/plugins/ls/gtk/menus.ui b/src/plugins/ls/gtk/menus.ui
index 37d28eebf..75022cc4d 100644
--- a/src/plugins/ls/gtk/menus.ui
+++ b/src/plugins/ls/gtk/menus.ui
@@ -1,28 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <menu id="project-tree-menu">
- <section id="project-tree-menu-open-section">
- <item>
- <attribute name="id">project-tree-menu-open-editor</attribute>
- <attribute name="hidden-when">action-disabled</attribute>
- <attribute name="label" translatable="yes">_Browse Folder</attribute>
- <attribute name="action">project-tree.open-with-hint</attribute>
- <attribute name="target" type="s">'ls'</attribute>
- </item>
- </section>
+ <menu id="project-tree-menu-open-containing-folder-menu">
+ <item>
+ <attribute name="id">project-tree-menu-open-editor</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ <attribute name="label" translatable="yes">With _Folder Listing</attribute>
+ <attribute name="action">project-tree.open-with-hint</attribute>
+ <attribute name="target" type="s">'ls'</attribute>
+ </item>
</menu>
<menu id="ide-source-view-popup-menu">
<section id="ide-source-view-popup-menu-files-section">
- <item>
- <attribute name="id">source-view-open-directory</attribute>
- <attribute name="label" translatable="yes">S_witch to Folder</attribute>
- <attribute name="action">ls.open-directory</attribute>
- </item>
- <item>
- <attribute name="id">source-view-open-in-files</attribute>
- <attribute name="label" translatable="yes">_Open Containing Folder</attribute>
- <attribute name="action">ls.open-in-files</attribute>
- </item>
+ <submenu id="ide-source-view-popup-menu-open-containing-folder-section">
+ <attribute name="label" translatable="yes">Open Containing Folder</attribute>
+ <item>
+ <attribute name="id">source-view-open-directory</attribute>
+ <attribute name="label" translatable="yes">With _Folder Listing</attribute>
+ <attribute name="action">ls.open-directory</attribute>
+ </item>
+ <item>
+ <attribute name="id">source-view-open-in-files</attribute>
+ <attribute name="label" translatable="yes">With File _Browser…</attribute>
+ <attribute name="action">ls.open-in-files</attribute>
+ </item>
+ </submenu>
</section>
</menu>
</interface>
diff --git a/src/plugins/ls/ls.plugin b/src/plugins/ls/ls.plugin
index c7bf0b0d9..37db84d12 100644
--- a/src/plugins/ls/ls.plugin
+++ b/src/plugins/ls/ls.plugin
@@ -2,7 +2,7 @@
Authors=Christian Hergert <christian hergert me>
Builtin=true
Copyright=Copyright © 2018 Christian Hergert
-Depends=editor;
+Depends=project-tree;
Description=List files in a directory as a view
Embedded=_gbp_ls_register_types
Hidden=true
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]