[gnome-text-editor/wip/cdavis/adaptive] window: Make adaptive with AdwAdaptiveState
- From: Christopher Davis <christopherdavis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor/wip/cdavis/adaptive] window: Make adaptive with AdwAdaptiveState
- Date: Sat, 8 Oct 2022 00:10:31 +0000 (UTC)
commit f05edf4e28c6f36653cc24d0b01d465cefaa9487
Author: Christopher Davis <christopherdavis gnome org>
Date: Fri Oct 7 20:03:50 2022 -0400
window: Make adaptive with AdwAdaptiveState
Use the new adwaita adaptive state utility in order to
implement adaptive tabs and adjust other widgetry.
org.gnome.TextEditor.Devel.json | 33 ++++
src/editor-window-private.h | 2 +
src/editor-window.c | 54 ++++++-
src/editor-window.ui | 328 ++++++++++++++++++++++------------------
4 files changed, 269 insertions(+), 148 deletions(-)
---
diff --git a/org.gnome.TextEditor.Devel.json b/org.gnome.TextEditor.Devel.json
index 5f50f8e..908c78e 100644
--- a/org.gnome.TextEditor.Devel.json
+++ b/org.gnome.TextEditor.Devel.json
@@ -30,6 +30,39 @@
"*.a"
],
"modules" : [
+ {
+ "name" : "libsass",
+ "buildsystem" : "meson",
+ "sources" : [
+ {
+ "type" : "git",
+ "url" : "https://github.com/lazka/libsass.git",
+ "branch" : "meson"
+ }
+ ]
+ },
+ {
+ "name" : "sassc",
+ "buildsystem" : "meson",
+ "sources" : [
+ {
+ "type" : "git",
+ "url" : "https://github.com/lazka/sassc.git",
+ "branch" : "meson"
+ }
+ ]
+ },
+ {
+ "name" : "libadwaita",
+ "buildsystem" : "meson",
+ "sources" : [
+ {
+ "type" : "git",
+ "url" : "https://gitlab.gnome.org/GNOME/libadwaita.git",
+ "branch" : "wip/exalm/adaptive-states"
+ }
+ ]
+ },
{
"name" : "libeditorconfig",
"buildsystem" : "cmake",
diff --git a/src/editor-window-private.h b/src/editor-window-private.h
index 9e7077e..2d7548f 100644
--- a/src/editor-window-private.h
+++ b/src/editor-window-private.h
@@ -50,12 +50,14 @@ struct _EditorWindow
EditorPositionLabel *position_label;
GtkStack *stack;
GtkMenuButton *open_menu_button;
+ GtkMenuButton *narrow_menu_button;
GtkMenuButton *primary_menu;
GtkMenuButton *options_menu;
GtkMenuButton *export_menu;
GtkWidget *zoom_label;
GMenu *options_menu_model;
EditorStatusbar *statusbar;
+ AdwAdaptiveState *narrow_state;
/* Borrowed References */
EditorPage *visible_page;
diff --git a/src/editor-window.c b/src/editor-window.c
index 40673f1..f19963e 100644
--- a/src/editor-window.c
+++ b/src/editor-window.c
@@ -134,6 +134,12 @@ restore_closed_document (EditorWindow *self)
self->closed_items->len > 0);
}
+static gboolean
+is_narrow (EditorWindow *self)
+{
+ return adw_application_window_get_current_state (ADW_APPLICATION_WINDOW (self)) == self->narrow_state;
+}
+
static void
on_undo_close_page_cb (GtkWidget *widget,
const char *action_name,
@@ -182,7 +188,8 @@ update_subtitle_visibility_cb (EditorWindow *self)
if (visible)
gtk_widget_set_visible (GTK_WIDGET (self->position_box),
- g_settings_get_boolean (self->settings, "show-line-numbers"));
+ g_settings_get_boolean (self->settings, "show-line-numbers")
+ && !is_narrow (self));
else
gtk_widget_hide (GTK_WIDGET (self->position_box));
}
@@ -303,7 +310,8 @@ editor_window_notify_selected_page_cb (EditorWindow *self,
gtk_widget_set_visible (GTK_WIDGET (self->is_modified), FALSE);
gtk_widget_set_visible (GTK_WIDGET (self->subtitle), FALSE);
gtk_widget_set_visible (GTK_WIDGET (self->position_box),
- page && g_settings_get_boolean (self->settings, "show-line-numbers"));
+ page && g_settings_get_boolean (self->settings, "show-line-numbers")
+ && !is_narrow (self));
gtk_widget_set_visible (GTK_WIDGET (self->indicator), FALSE);
self->visible_page = page;
@@ -529,6 +537,34 @@ editor_window_constructed (GObject *object)
gtk_popover_menu_add_child (GTK_POPOVER_MENU (popover), zoom_box, "zoom");
}
+static void
+on_narrow_state_entered_cb (EditorWindow *self)
+{
+ g_assert (EDITOR_IS_WINDOW (self));
+
+ gtk_menu_button_set_popover (self->open_menu_button, NULL);
+ gtk_menu_button_set_popover (self->narrow_menu_button, GTK_WIDGET (self->open_menu_popover));
+}
+
+static void
+on_narrow_state_exited_cb (EditorWindow *self)
+{
+ g_assert (EDITOR_IS_WINDOW (self));
+
+ gtk_menu_button_set_popover (self->narrow_menu_button, NULL);
+ gtk_menu_button_set_popover (self->open_menu_button, GTK_WIDGET (self->open_menu_popover));
+}
+
+static AdwTabPage *
+on_tab_overview_create_page_cb (EditorWindow *self)
+{
+ g_assert (EDITOR_IS_WINDOW (self));
+
+ gtk_widget_activate_action (GTK_WIDGET (self), "session.new-draft", NULL);
+
+ return adw_tab_view_get_selected_page (self->tab_view);
+}
+
static gboolean
on_tab_view_close_page_cb (EditorWindow *self,
AdwTabPage *page,
@@ -907,6 +943,7 @@ editor_window_class_init (EditorWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, EditorWindow, indicator);
gtk_widget_class_bind_template_child (widget_class, EditorWindow, is_modified);
gtk_widget_class_bind_template_child (widget_class, EditorWindow, open_menu_button);
+ gtk_widget_class_bind_template_child (widget_class, EditorWindow, narrow_menu_button);
gtk_widget_class_bind_template_child (widget_class, EditorWindow, open_menu_popover);
gtk_widget_class_bind_template_child (widget_class, EditorWindow, options_menu);
gtk_widget_class_bind_template_child (widget_class, EditorWindow, options_menu_model);
@@ -920,7 +957,11 @@ editor_window_class_init (EditorWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, EditorWindow, tab_bar);
gtk_widget_class_bind_template_child (widget_class, EditorWindow, tab_view);
gtk_widget_class_bind_template_child (widget_class, EditorWindow, title);
+ gtk_widget_class_bind_template_child (widget_class, EditorWindow, narrow_state);
+ gtk_widget_class_bind_template_callback (widget_class, on_narrow_state_entered_cb);
+ gtk_widget_class_bind_template_callback (widget_class, on_narrow_state_exited_cb);
+ gtk_widget_class_bind_template_callback (widget_class, on_tab_overview_create_page_cb);
gtk_widget_class_bind_template_callback (widget_class, on_tab_view_close_page_cb);
gtk_widget_class_bind_template_callback (widget_class, on_tab_view_setup_menu_cb);
gtk_widget_class_bind_template_callback (widget_class, on_tab_view_create_window_cb);
@@ -1365,7 +1406,14 @@ editor_window_get_n_pages (EditorWindow *self)
void
_editor_window_focus_search (EditorWindow *self)
{
+ GtkMenuButton *menu_button;
+
g_return_if_fail (EDITOR_IS_WINDOW (self));
- gtk_menu_button_popup (self->open_menu_button);
+ if (is_narrow (self))
+ menu_button = self->narrow_menu_button;
+ else
+ menu_button = self->open_menu_button;
+
+ gtk_menu_button_popup (menu_button);
}
diff --git a/src/editor-window.ui b/src/editor-window.ui
index a602ec7..53acb1b 100644
--- a/src/editor-window.ui
+++ b/src/editor-window.ui
@@ -3,190 +3,228 @@
<requires lib="gtk" version="4.0"/>
<requires lib="Adw" version="1.0"/>
<template class="EditorWindow" parent="AdwApplicationWindow">
+ <property name="width-request">360</property>
+ <property name="height-request">294</property>
<style>
<class name="org-gnome-TextEditor"/>
</style>
- <child>
- <object class="GtkBox">
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkHeaderBar" id="header_bar">
- <property name="show-title-buttons">True</property>
- <child type="title">
- <object class="GtkBox">
- <property name="hexpand">true</property>
- <property name="valign">center</property>
- <property name="orientation">vertical</property>
- <property name="margin-start">12</property>
- <property name="margin-end">12</property>
- <child>
- <object class="GtkCenterBox">
+ <property name="content">
+ <object class="AdwTabOverview" id="tab_overview">
+ <property name="enable-new-tab">True</property>
+ <property name="view">tab_view</property>
+ <signal name="create_tab" handler="on_tab_overview_create_page_cb" object="EditorWindow"
swapped="true"/>
+ <property name="child">
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkHeaderBar" id="header_bar">
+ <property name="show-title-buttons">True</property>
+ <child type="title">
+ <object class="GtkBox">
<property name="hexpand">true</property>
- <property name="has-tooltip">true</property>
- <signal name="query-tooltip" handler="title_query_tooltip_cb" object="EditorWindow"
swapped="true"/>
- <child type="start">
- <object class="GtkLabel" id="is_modified">
- <property name="halign">end</property>
+ <property name="valign">center</property>
+ <property name="orientation">vertical</property>
+ <property name="margin-start">12</property>
+ <property name="margin-end">12</property>
+ <child>
+ <object class="GtkCenterBox">
<property name="hexpand">true</property>
- <property name="label">•</property>
- <property name="margin-end">6</property>
- <property name="visible">false</property>
+ <property name="has-tooltip">true</property>
+ <signal name="query-tooltip" handler="title_query_tooltip_cb" object="EditorWindow"
swapped="true"/>
+ <child type="start">
+ <object class="GtkLabel" id="is_modified">
+ <property name="halign">end</property>
+ <property name="hexpand">true</property>
+ <property name="label">•</property>
+ <property name="margin-end">6</property>
+ <property name="visible">false</property>
+ </object>
+ </child>
+ <child type="center">
+ <object class="GtkLabel" id="title">
+ <property name="ellipsize">end</property>
+ <property name="width-chars">3</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ </child>
</object>
</child>
- <child type="center">
- <object class="GtkLabel" id="title">
- <property name="ellipsize">end</property>
- <property name="width-chars">3</property>
- <attributes>
- <attribute name="weight" value="bold"/>
- </attributes>
+ <child>
+ <object class="GtkCenterBox">
+ <property name="has-tooltip">true</property>
+ <signal name="query-tooltip" handler="title_query_tooltip_cb" object="EditorWindow"
swapped="true"/>
+ <child type="start">
+ <object class="GtkImage" id="indicator">
+ <property name="hexpand">true</property>
+ <property name="halign">end</property>
+ <property name="visible">false</property>
+ <property name="margin-end">6</property>
+ <property name="pixel-size">12</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ </child>
+ <child type="center">
+ <object class="GtkLabel" id="subtitle">
+ <property name="ellipsize">middle</property>
+ <attributes>
+ <attribute name="scale" value="0.8222"/>
+ <attribute name="foreground-alpha" value="32767"/>
+ </attributes>
+ </object>
+ </child>
</object>
</child>
</object>
</child>
- <child>
- <object class="GtkCenterBox">
- <property name="has-tooltip">true</property>
- <signal name="query-tooltip" handler="title_query_tooltip_cb" object="EditorWindow"
swapped="true"/>
- <child type="start">
- <object class="GtkImage" id="indicator">
- <property name="hexpand">true</property>
- <property name="halign">end</property>
- <property name="visible">false</property>
- <property name="margin-end">6</property>
- <property name="pixel-size">12</property>
- <style>
- <class name="dim-label"/>
- </style>
+ <child type="start">
+ <object class="GtkBox">
+ <property name="halign">start</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkMenuButton" id="open_menu_button">
+ <property name="label" translatable="yes">_Open</property>
+ <property name="use-underline">True</property>
+ <property name="tooltip-text" translatable="yes">Open recent document
(Ctrl+K)</property>
+ <property name="popover">
+ <object class="EditorOpenPopover" id="open_menu_popover">
+ </object>
+ </property>
</object>
</child>
- <child type="center">
- <object class="GtkLabel" id="subtitle">
- <property name="ellipsize">middle</property>
- <attributes>
- <attribute name="scale" value="0.8222"/>
- <attribute name="foreground-alpha" value="32767"/>
- </attributes>
+ <child>
+ <object class="GtkMenuButton" id="narrow_menu_button">
+ <property name="visible">False</property>
+ <property name="icon-name">document-open-symbolic</property>
+ <property name="tooltip-text" translatable="yes">Open recent document
(Ctrl+K)</property>
</object>
</child>
- </object>
- </child>
- </object>
- </child>
- <child type="start">
- <object class="GtkBox">
- <property name="halign">start</property>
- <property name="spacing">6</property>
- <child>
- <object class="GtkMenuButton" id="open_menu_button">
- <property name="label" translatable="yes">_Open</property>
- <property name="use-underline">True</property>
- <property name="tooltip-text" translatable="yes">Open recent document (Ctrl+K)</property>
- <property name="popover">
- <object class="EditorOpenPopover" id="open_menu_popover">
+ <child>
+ <object class="GtkButton" id="new_button">
+ <property name="action-name">session.new-draft</property>
+ <property name="icon-name">tab-new-symbolic</property>
+ <property name="has-tooltip">true</property>
+ <property name="tooltip-text" translatable="yes">New tab (Ctrl+T)</property>
+ <accessibility>
+ <property name="label" translatable="yes">New tab (Ctrl+T)</property>
+ </accessibility>
</object>
- </property>
- </object>
- </child>
- <child>
- <object class="GtkButton" id="new_button">
- <property name="action-name">session.new-draft</property>
- <property name="icon-name">tab-new-symbolic</property>
- <property name="has-tooltip">true</property>
- <property name="tooltip-text" translatable="yes">New tab (Ctrl+T)</property>
- <accessibility>
- <property name="label" translatable="yes">New tab (Ctrl+T)</property>
- </accessibility>
- </object>
- </child>
- </object>
- </child>
- <child type="end">
- <object class="GtkBox">
- <property name="halign">end</property>
- <property name="spacing">6</property>
- <child>
- <object class="GtkBox" id="position_box">
+ </child>
<child>
- <object class="EditorPositionLabel" id="position_label">
- <property name="hexpand">false</property>
- <property name="vexpand">false</property>
- <property name="valign">center</property>
- <style>
- <class name="dim-label"/>
- </style>
+ <object class="AdwTabButton" id="narrow_tab_button">
+ <property name="visible">False</property>
+ <property name="view">tab_view</property>
+ <property name="action-name">overview.open</property>
</object>
</child>
</object>
</child>
- <child>
- <object class="GtkMenuButton" id="options_menu">
- <property name="tooltip-text" translatable="yes">View</property>
- <property name="icon-name">document-properties-symbolic</property>
- <property name="menu-model">options_menu_model</property>
- <accessibility>
- <property name="label" translatable="yes">View</property>
- </accessibility>
- </object>
- </child>
- <child>
- <object class="GtkMenuButton" id="primary_menu">
- <property name="icon-name">open-menu-symbolic</property>
- <property name="menu-model">primary_menu_model</property>
- <accessibility>
- <property name="label" translatable="yes">Menu</property>
- </accessibility>
+ <child type="end">
+ <object class="GtkBox">
+ <property name="halign">end</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkBox" id="position_box">
+ <child>
+ <object class="EditorPositionLabel" id="position_label">
+ <property name="hexpand">false</property>
+ <property name="vexpand">false</property>
+ <property name="valign">center</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuButton" id="options_menu">
+ <property name="tooltip-text" translatable="yes">View</property>
+ <property name="icon-name">document-properties-symbolic</property>
+ <property name="menu-model">options_menu_model</property>
+ <accessibility>
+ <property name="label" translatable="yes">View</property>
+ </accessibility>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuButton" id="primary_menu">
+ <property name="icon-name">open-menu-symbolic</property>
+ <property name="menu-model">primary_menu_model</property>
+ <accessibility>
+ <property name="label" translatable="yes">Menu</property>
+ </accessibility>
+ </object>
+ </child>
</object>
</child>
</object>
</child>
- </object>
- </child>
- <child>
- <object class="GtkStack" id="stack">
- <property name="hexpand">true</property>
<child>
- <object class="GtkBox" id="pages">
- <property name="orientation">vertical</property>
+ <object class="GtkStack" id="stack">
+ <property name="hexpand">true</property>
<child>
- <object class="AdwTabBar" id="tab_bar">
- <property name="view">tab_view</property>
+ <object class="GtkBox" id="pages">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="AdwTabBar" id="tab_bar">
+ <property name="view">tab_view</property>
+ </object>
+ </child>
+ <child>
+ <object class="AdwTabView" id="tab_view">
+ <property name="hexpand">true</property>
+ <property name="vexpand">true</property>
+ <property name="menu-model">tab_menu</property>
+ <signal name="close-page" handler="on_tab_view_close_page_cb" swapped="true"/>
+ <signal name="setup-menu" handler="on_tab_view_setup_menu_cb" swapped="true"/>
+ <signal name="create-window" handler="on_tab_view_create_window_cb" swapped="true"/>
+ </object>
+ </child>
</object>
</child>
<child>
- <object class="AdwTabView" id="tab_view">
- <property name="hexpand">true</property>
- <property name="vexpand">true</property>
- <property name="menu-model">tab_menu</property>
- <signal name="close-page" handler="on_tab_view_close_page_cb" swapped="true"/>
- <signal name="setup-menu" handler="on_tab_view_setup_menu_cb" swapped="true"/>
- <signal name="create-window" handler="on_tab_view_create_window_cb" swapped="true"/>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="AdwStatusPage" id="empty">
- <property name="title" translatable="yes">Start or Open a Document</property>
- <property name="child">
- <object class="GtkLabel">
- <property name="label" translatable="yes">• Press the Open button
+ <object class="AdwStatusPage" id="empty">
+ <property name="title" translatable="yes">Start or Open a Document</property>
+ <property name="child">
+ <object class="GtkLabel">
+ <property name="label" translatable="yes">• Press the Open button
• Press the New tab button
• Press Ctrl+N to start a new document
• Press Ctrl+O to browse for a document
Or, press Ctrl+W to close the window.</property>
+ </object>
+ </property>
</object>
- </property>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="EditorStatusbar" id="statusbar">
+ <property name="visible">false</property>
</object>
</child>
</object>
- </child>
- <child>
- <object class="EditorStatusbar" id="statusbar">
- <property name="visible">false</property>
- </object>
- </child>
+ </property>
+ </object>
+ </property>
+ <child>
+ <object class="AdwAdaptiveState" id="narrow_state">
+ <conditions>
+ <condition type="max-width">500</condition>
+ </conditions>
+ <setter object="open_menu_button" property="visible">False</setter>
+ <setter object="narrow_menu_button" property="visible">True</setter>
+ <setter object="new_button" property="visible">False</setter>
+ <setter object="narrow_tab_button" property="visible">True</setter>
+ <setter object="tab_bar" property="visible">False</setter>
+ <setter object="position_box" property="visible">False</setter>
+ <signal name="enter" handler="on_narrow_state_entered_cb" object="EditorWindow" swapped="yes"/>
+ <signal name="exit" handler="on_narrow_state_exited_cb" object="EditorWindow" swapped="yes"/>
</object>
</child>
</template>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]