[gnome-builder/wip/gtk4-port: 652/1774] plugins/ls: port to GTK 4
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 652/1774] plugins/ls: port to GTK 4
- Date: Mon, 11 Jul 2022 22:31:19 +0000 (UTC)
commit 333cfeea9dc0c6b36338c2d28df15e577bcddd5b
Author: Christian Hergert <chergert redhat com>
Date: Tue Apr 19 22:41:46 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 | 42 ++++++-------------------------
src/plugins/ls/gbp-ls-page.ui | 1 +
src/plugins/ls/gbp-ls-tree-view.c | 10 +++-----
src/plugins/ls/gbp-ls-workbench-addin.c | 36 ++++++++++----------------
src/plugins/meson.build | 2 +-
6 files changed, 37 insertions(+), 71 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..c22d4d352 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 = g_date_time_format (when, "%X %x");
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-symbolic");
g_signal_connect_object (self->tree_view,
"row-activated",
@@ -389,7 +361,7 @@ gbp_ls_page_set_directory (GbpLsPage *self,
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), title);
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..5934df3e0 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>
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/meson.build b/src/plugins/meson.build
index 2e9fef936..daae17b8b 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -90,7 +90,7 @@ subdir('intelephense')
subdir('jedi-language-server')
subdir('jhbuild')
#subdir('line-spacing')
-#subdir('ls')
+subdir('ls')
subdir('make')
subdir('maven')
subdir('meson')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]