[gnome-characters/bilelmoussaoui/gtk4: 7/76] make it run with gtk4
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-characters/bilelmoussaoui/gtk4: 7/76] make it run with gtk4
- Date: Fri, 26 Nov 2021 08:59:03 +0000 (UTC)
commit 52971defc242dc9e649c9b1540d5570a009768b3
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date: Fri Nov 19 11:58:50 2021 +0100
make it run with gtk4
data/application.css | 9 ------
data/character.ui | 1 -
data/characterlist.ui | 1 -
data/mainview.ui | 1 -
data/mainwindow.ui | 62 ++++++++++-----------------------------
data/menu.ui | 6 ++--
src/categoryList.js | 30 +++++++++----------
src/characterList.js | 81 ++++++++++++++++++++++++++-------------------------
src/main.js | 10 +++----
src/menu.js | 6 ++--
src/util.js | 2 +-
src/window.js | 22 +++++++-------
12 files changed, 96 insertions(+), 135 deletions(-)
---
diff --git a/data/application.css b/data/application.css
index 15c1e30..f37dee7 100644
--- a/data/application.css
+++ b/data/application.css
@@ -56,12 +56,3 @@ Gjs_MenuPopover GtkScrolledWindow {
border-width: 2pt;
}
-@binding-set ScrollUnmodified {
- bind "space" { "scroll-child" (page-down, 0) };
- bind "Up" { "scroll-child" (step-up, 0) };
- bind "Down" { "scroll-child" (step-down, 0) };
-}
-
-GtkScrolledWindow.character-list-scroll {
- -gtk-key-bindings: ScrollUnmodified;
-}
diff --git a/data/character.ui b/data/character.ui
index 4bc3921..6b96612 100644
--- a/data/character.ui
+++ b/data/character.ui
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <requires lib="gtk+" version="3.12"/>
<template class="Gjs_CharacterDialog" parent="GtkDialog">
<child internal-child="vbox">
<object class="GtkBox" id="vbox1">
diff --git a/data/characterlist.ui b/data/characterlist.ui
index c335b37..eabd916 100644
--- a/data/characterlist.ui
+++ b/data/characterlist.ui
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <requires lib="gtk+" version="3.12"/>
<template class="Gjs_CharacterListView" parent="GtkStack">
<property name="visible">True</property>
<child>
diff --git a/data/mainview.ui b/data/mainview.ui
index 6737494..ccae099 100644
--- a/data/mainview.ui
+++ b/data/mainview.ui
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <requires lib="gtk+" version="3.12"/>
<template class="Gjs_MainView" parent="GtkStack">
<property name="visible">True</property>
<child>
diff --git a/data/mainwindow.ui b/data/mainwindow.ui
index 1947b0a..8cd7039 100644
--- a/data/mainwindow.ui
+++ b/data/mainwindow.ui
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <requires lib="gtk+" version="3.12"/>
<menu id="primary_menu">
<section>
<item>
@@ -18,9 +17,9 @@
<property name="default-width">800</property>
<property name="default-height">500</property>
<child>
- <object class="AdwwLeaflet" id="leaflet">
+ <object class="AdwLeaflet" id="leaflet">
<property name="visible">True</property>
- <property name="can-swipe-back">True</property>
+ <property name="can-navigate-back">True</property>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
@@ -29,8 +28,12 @@
<child>
<object class="GtkHeaderBar" id="sidebar-headerbar">
<property name="visible">True</property>
- <property name="show-close-button">True</property>
- <property name="title" translatable="yes">Characters</property>
+ <property name="show-title-buttons">True</property>
+ <property name="title-widget">
+ <object class="AdwWindowTitle">
+ <property name="title" translatable="yes">Characters</property>
+ </object>
+ </property>
<child>
<object class="GtkToggleButton" id="search-active-button">
<property name="can_focus">True</property>
@@ -43,11 +46,10 @@
</child>
</object>
</child>
- <child>
+ <child type="end">
<object class="GtkMenuButton">
<property name="visible">True</property>
<property name="menu-model">primary_menu</property>
- <property name="action_name">win.show-primary-menu</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
@@ -55,9 +57,6 @@
</object>
</child>
</object>
- <packing>
- <property name="pack-type">end</property>
- </packing>
</child>
</object>
</child>
@@ -89,17 +88,12 @@
<property name="orientation">vertical</property>
<property name="visible">True</property>
<child>
- <object class="AdwWindowHandle" id="header-separator">
+ <object class="GtkSeparator">
<property name="visible">True</property>
- <child>
- <object class="GtkSeparator">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <style>
- <class name="sidebar"/>
- </style>
- </object>
- </child>
+ <property name="orientation">vertical</property>
+ <style>
+ <class name="sidebar"/>
+ </style>
</object>
</child>
<child>
@@ -114,9 +108,6 @@
</object>
</child>
</object>
- <packing>
- <property name="navigatable">False</property>
- </packing>
</child>
<child>
<object class="GtkBox" id="container">
@@ -125,8 +116,7 @@
<child>
<object class="GtkHeaderBar" id="main-headerbar">
<property name="visible">True</property>
- <property name="show-close-button">True</property>
- <property name="has-subtitle">False</property>
+ <property name="show-title-buttons">True</property>
<child>
<object class="GtkRevealer">
<property name="transition-type">crossfade</property>
@@ -145,25 +135,13 @@
</object>
</child>
</object>
- <packing>
- <property name="pack-type">start</property>
- </packing>
</child>
<child>
<object class="GtkMenuButton" id="menu-button">
<property name="can_focus">False</property>
<property name="visible">True</property>
- <property name="use_popover">True</property>
- <child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="icon-name">view-more-symbolic</property>
- </object>
- </child>
+ <property name="icon-name">view-more-symbolic</property>
</object>
- <packing>
- <property name="pack-type">end</property>
- </packing>
</child>
</object>
</child>
@@ -177,14 +155,6 @@
<widgets>
<widget name="sidebar-headerbar"/>
<widget name="main-headerbar"/>
- <widget name="header-separator"/>
</widgets>
</object>
- <object class="HdyHeaderGroup">
- <property name="decorate-all" bind-source="leaflet" bind-property="folded" bind-flags="sync-create"/>
- <headerbars>
- <headerbar name="sidebar-headerbar"/>
- <headerbar name="main-headerbar"/>
- </headerbars>
- </object>
</interface>
diff --git a/data/menu.ui b/data/menu.ui
index 82a8f8e..651a0b0 100644
--- a/data/menu.ui
+++ b/data/menu.ui
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <requires lib="gtk+" version="3.12"/>
<template class="Gjs_MenuPopover" parent="GtkPopover">
<property name="vexpand">True</property>
<property name="width-request">250</property>
@@ -8,7 +7,10 @@
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
- <property name="margin">12</property>
+ <property name="margin-top">12</property>
+ <property name="margin-bottom">12</property>
+ <property name="margin-start">12</property>
+ <property name="margin-end">12</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel">
diff --git a/src/categoryList.js b/src/categoryList.js
index 6afbf3b..4e5a7a2 100644
--- a/src/categoryList.js
+++ b/src/categoryList.js
@@ -142,20 +142,20 @@ const CategoryListRowWidget = GObject.registerClass({
params = Params.fill(params, {});
super._init(params);
this.category = category;
- this.get_accessible().accessible_name =
- _('%s Category List Row').format(category.title);
+ /*this.get_accessible().accessible_name =
+ _('%s Category List Row').format(category.title);*/
let hbox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL });
- this.add(hbox);
+ this.set_child(hbox);
let image = Gtk.Image.new_from_icon_name(category.icon_name, Gtk.IconSize.LARGE_TOOLBAR);
image.get_style_context().add_class('category-icon');
- hbox.pack_start(image, false, false, 2);
+ hbox.append(image);
let label = new Gtk.Label({ label: Gettext.gettext(category.title),
halign: Gtk.Align.START });
label.get_style_context().add_class('category-label');
- hbox.pack_start(label, true, true, 0);
+ hbox.append(label);
}
});
@@ -367,7 +367,7 @@ const RecentCategoryListWidget = GObject.registerClass({
this.recentRow = new CategoryListRowWidget({}, this.recentCategory);
this.recentRow.get_style_context().add_class('category');
this.recentRow.get_style_context().add_class('recent-category');
- this.add(this.recentRow)
+ this.set_child(this.recentRow)
}
getCategory(name) {
@@ -387,14 +387,14 @@ var CategoryListView = GObject.registerClass({
this.get_style_context().add_class('categories-list');
this._recentCategoryList = new RecentCategoryListWidget();
- this._recentCategoryList.connect('row-selected', (list, row) => {
+ this._recentCategoryList.list.connect('row-selected', (list, row) => {
this._letterCategoryList.unselect();
this._emojiCategoryList.unselect();
this._lastSelectedList = list;
list.select_row(row);
});
- this.add(this._recentCategoryList)
- this.add(new Gtk.Separator({orientation: Gtk.Orientation.HORIZONTAL}));
+ this.append(this._recentCategoryList)
+ this.append(new Gtk.Separator({orientation: Gtk.Orientation.HORIZONTAL}));
let emojis_label = new Gtk.Label ({
label: CategoryList[0].title,
@@ -405,18 +405,18 @@ var CategoryListView = GObject.registerClass({
margin_end: 12,
});
emojis_label.get_style_context().add_class("heading");
- this.add(emojis_label);
+ this.append(emojis_label);
this._emojiCategoryList = new EmojiCategoryListWidget({
categoryList: EmojiCategoryList
});
- this._emojiCategoryList.connect('row-selected', (list, row) => {
+ this._emojiCategoryList.list.connect('row-selected', (list, row) => {
this._letterCategoryList.unselect();
this._recentCategoryList.unselect();
this._lastSelectedList = list;
list.select_row(row);
});
- this.add(this._emojiCategoryList);
+ this.append(this._emojiCategoryList);
let letters_label = new Gtk.Label ({
label: CategoryList[1].title,
@@ -427,18 +427,18 @@ var CategoryListView = GObject.registerClass({
margin_end: 12,
});
letters_label.get_style_context().add_class("heading");
- this.add(letters_label);
+ this.append(letters_label);
this._letterCategoryList = new LetterCategoryListWidget({
categoryList: LetterCategoryList
});
- this._letterCategoryList.connect('row-selected', (list, row) => {
+ this._letterCategoryList.list.connect('row-selected', (list, row) => {
this._emojiCategoryList.unselect();
this._recentCategoryList.unselect();
this._lastSelectedList = list;
list.select_row(row);
});
- this.add(this._letterCategoryList);
+ this.append(this._letterCategoryList);
this._categoryList = CategoryList.slice();
}
diff --git a/src/characterList.js b/src/characterList.js
index beb2e8b..c93d2e8 100644
--- a/src/characterList.js
+++ b/src/characterList.js
@@ -17,7 +17,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
const Params = imports.params;
-const {Gc, Gdk, GLib, Gio,GObject,Gtk, Pango, PangoCairo, Handy} = imports.gi;
+const {Adw, Gc, Gdk, GLib, Gio,GObject,Gtk, Pango, PangoCairo} = imports.gi;
const Cairo = imports.cairo;
@@ -47,7 +47,7 @@ const CharacterListRow = GObject.registerClass({
this._characters = filtered.characters;
this._fontDescription = filtered.fontDescription;
this._overlayFontDescription = filtered.overlayFontDescription;
- this._styleManager = Handy.StyleManager.get_default();
+ this._styleManager = Adw.StyleManager.get_default();
}
draw(cr, x, y, width, height, styleContext) {
@@ -210,15 +210,16 @@ const CharacterListWidget = GObject.registerClass({
this._numRows = filtered.numRows;
this._characters = [];
this._rows = [];
- this.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
+ /*this.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
Gdk.EventMask.BUTTON_RELEASE_MASK);
- this._character = null;
this.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
null,
Gdk.DragAction.COPY);
this.drag_source_add_text_targets();
+ */
+ this._character = null;
}
-
+ /*
vfunc_drag_begin(context) {
let cellSize = getCellSize(this._fontDescription);
this._dragSurface = new Cairo.ImageSurface(Cairo.Format.ARGB32,
@@ -256,16 +257,12 @@ const CharacterListWidget = GObject.registerClass({
this.emit('character-selected', this._character);
return false;
}
-
- vfunc_get_request_mode() {
- return Gtk.SizeRequestMode.HEIGHT_FOR_WIDTH;
- }
-
vfunc_get_preferred_height() {
let [minWidth, natWidth] = this.vfunc_get_preferred_width();
return this.vfunc_get_preferred_height_for_width(minWidth);
}
+
vfunc_get_preferred_height_for_width(width) {
let height = Math.max(this._rows.length, this._numRows) *
getCellSize(this._fontDescription);
@@ -282,6 +279,36 @@ const CharacterListWidget = GObject.registerClass({
let natWidth = Math.max(this._cellsPerRow, NUM_COLUMNS) * cellSize;
return [minWidth, natWidth];
}
+ vfunc_draw(cr) {
+ // Clear the canvas.
+ let context = this.get_style_context();
+ let fg = context.get_color(Gtk.StateFlags.NORMAL);
+ let bg = context.get_background_color(Gtk.StateFlags.NORMAL);
+
+ cr.setSourceRGBA(bg.red, bg.green, bg.blue, bg.alpha);
+ cr.paint();
+ cr.setSourceRGBA(fg.red, fg.green, fg.blue, fg.alpha);
+
+ // Use device coordinates directly, since PangoCairo doesn't
+ // work well with scaled matrix:
+ // https://bugzilla.gnome.org/show_bug.cgi?id=700592
+ let allocation = this.get_allocation();
+
+ // Redraw rows within the clipped region.
+ let [x1, y1, x2, y2] = cr.clipExtents();
+ let cellSize = getCellSize(this._fontDescription);
+ let start = Math.max(0, Math.floor(y1 / cellSize));
+ let end = Math.min(this._rows.length, Math.ceil(y2 / cellSize));
+ for (let index = start; index < end; index++) {
+ this._rows[index].draw(cr, 0, index * cellSize,
+ allocation.width, cellSize, context);
+ }
+ }
+ */
+
+ vfunc_get_request_mode() {
+ return Gtk.SizeRequestMode.HEIGHT_FOR_WIDTH;
+ }
vfunc_size_allocate(allocation) {
super.vfunc_size_allocate(allocation);
@@ -333,32 +360,6 @@ const CharacterListWidget = GObject.registerClass({
this.queue_resize();
this.queue_draw();
}
-
- vfunc_draw(cr) {
- // Clear the canvas.
- let context = this.get_style_context();
- let fg = context.get_color(Gtk.StateFlags.NORMAL);
- let bg = context.get_background_color(Gtk.StateFlags.NORMAL);
-
- cr.setSourceRGBA(bg.red, bg.green, bg.blue, bg.alpha);
- cr.paint();
- cr.setSourceRGBA(fg.red, fg.green, fg.blue, fg.alpha);
-
- // Use device coordinates directly, since PangoCairo doesn't
- // work well with scaled matrix:
- // https://bugzilla.gnome.org/show_bug.cgi?id=700592
- let allocation = this.get_allocation();
-
- // Redraw rows within the clipped region.
- let [x1, y1, x2, y2] = cr.clipExtents();
- let cellSize = getCellSize(this._fontDescription);
- let start = Math.max(0, Math.floor(y1 / cellSize));
- let end = Math.min(this._rows.length, Math.ceil(y2 / cellSize));
- for (let index = start; index < end; index++) {
- this._rows[index].draw(cr, 0, index * cellSize,
- allocation.width, cellSize, context);
- }
- }
});
const MAX_SEARCH_RESULTS = 100;
@@ -473,7 +474,7 @@ var CharacterListView = GObject.registerClass({
visible: true
});
- scroll.add(this._characterList);
+ scroll.set_child(this._characterList);
let context = scroll.get_style_context();
context.add_class('character-list-scroll');
@@ -493,8 +494,10 @@ var CharacterListView = GObject.registerClass({
this._characters = [];
this._updateCharacterList();
});
+ /* TODO: use listmodels & grid view hopefully
scroll.connect('edge-reached', (scrolled, pos) => this._onEdgeReached(scrolled, pos));
scroll.connect('size-allocate', (scrolled, allocation) => this._onSizeAllocate(scrolled,
allocation));
+ */
}
_startSpinner() {
@@ -629,7 +632,7 @@ var RecentCharacterListView = GObject.registerClass({
Signals: {
'character-selected': { param_types: [ GObject.TYPE_STRING ] },
},
-}, class RecentCharacterListView extends Gtk.Bin {
+}, class RecentCharacterListView extends Adw.Bin {
_init(params) {
const filtered = Params.filter(params, {
category: null,
@@ -648,7 +651,7 @@ var RecentCharacterListView = GObject.registerClass({
numRows: 0
});
this._characterList.connect('character-selected', (w, c) => this.emit('character-selected', c));
- this.add(this._characterList);
+ this.set_child(this._characterList);
this._fontFilter.connect('filter-set', () => this._updateCharacterList());
diff --git a/src/main.js b/src/main.js
index 2dcfadf..71fcca5 100644
--- a/src/main.js
+++ b/src/main.js
@@ -72,13 +72,13 @@ var MyApplication = GObject.registerClass({
vfunc_startup () {
super.vfunc_startup();
- let theme = Gtk.IconTheme.get_default();
+ /*let theme = Gtk.IconTheme.get_default();
theme.add_resource_path('/org/gnome/Characters/icons');
-
+ */
Util.loadStyleSheet('/org/gnome/Characters/application.css');
- let styleManager = Handy.StyleManager.get_default();
- styleManager.set_color_scheme(Handy.ColorScheme.PREFER_LIGHT);
+ let styleManager = Adw.StyleManager.get_default();
+ styleManager.set_color_scheme(Adw.ColorScheme.PREFER_LIGHT);
Util.initActions(this,
[{ name: 'quit',
@@ -98,10 +98,10 @@ var MyApplication = GObject.registerClass({
}
vfunc_activate() {
+ Adw.init();
if (!this._appwindow) {
this._appwindow = new Window.MainWindow({ application: this });
}
- Adw.init();
this._appwindow.present();
log("Characters Application activated");
diff --git a/src/menu.js b/src/menu.js
index d5bef92..5bdc0b2 100644
--- a/src/menu.js
+++ b/src/menu.js
@@ -32,7 +32,7 @@ var MenuPopover = GObject.registerClass({
visible: true,
halign: Gtk.Align.START });
label.get_style_context().add_class('font-label');
- row.add(label);
+ row.set_child(label);
return row;
}
@@ -40,7 +40,7 @@ var MenuPopover = GObject.registerClass({
params = Params.fill(params, {});
super._init(params);
let row = this._createFontListRow(_("None"), 'None');
- this._font_listbox.add(row);
+ this._font_listbox.append(row);
let context = this.get_pango_context();
let families = context.list_families();
@@ -50,7 +50,7 @@ var MenuPopover = GObject.registerClass({
for (let index in families) {
row = this._createFontListRow(families[index].get_name(),
families[index].get_name());
- this._font_listbox.add(row);
+ this._font_listbox.append(row);
}
this._keywords = [];
diff --git a/src/util.js b/src/util.js
index fe222ea..7ae826b 100644
--- a/src/util.js
+++ b/src/util.js
@@ -45,7 +45,7 @@ function loadUI(resourcePath, objects) {
function loadStyleSheet(resource) {
let provider = new Gtk.CssProvider();
provider.load_from_file(Gio.File.new_for_uri('resource://' + resource));
- Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),
+ Gtk.StyleContext.add_provider_for_display(Gdk.Display.get_default(),
provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}
diff --git a/src/window.js b/src/window.js
index 449a6cb..434345f 100644
--- a/src/window.js
+++ b/src/window.js
@@ -102,20 +102,19 @@ var MainWindow = GObject.registerClass({
this._categoryListView =
new CategoryList.CategoryListView({ vexpand: true });
- this._categoryListView.show_all();
let scroll = new Gtk.ScrolledWindow({
hscrollbar_policy: Gtk.PolicyType.NEVER,
hexpand: false,
visible: true,
});
- scroll.add(this._categoryListView);
- this._sidebar.add(scroll);
+ scroll.set_child(this._categoryListView);
+ this._sidebar.append(scroll);
this._mainView = new MainView({
categoryListView: this._categoryListView
});
- this._container.pack_start(this._mainView, true, true, 0);
+ this._container.append(this._mainView);
let builder = Gtk.Builder.new_from_resource('/org/gnome/Characters/shortcuts.ui');
let helpOverlay = builder.get_object("shortcuts");
@@ -123,7 +122,8 @@ var MainWindow = GObject.registerClass({
// Due to limitations of gobject-introspection wrt GdkEvent
// and GdkEventKey, this needs to be a signal handler
- this.connect('key-press-event', (self, event) => this._handleKeyPress(self, event));
+ // TODO: use EventControllerKey
+ //this.connect('key-press-event', (self, event) => this._handleKeyPress(self, event));
}
vfunc_map() {
@@ -337,17 +337,15 @@ const MainView = GObject.registerClass({
this._recentCharacterLists[category.name] = characterList;
if (i > 0) {
let separator = new Gtk.Separator({});
- recentBox.pack_start(separator, false, false, 0);
+ recentBox.append(separator);
}
- recentBox.pack_start(characterList, false, false, 0);
+ recentBox.append(characterList);
}
let scroll = new Gtk.ScrolledWindow({
hscrollbar_policy: Gtk.PolicyType.NEVER,
hexpand: false,
});
- scroll.add(recentBox);
- recentBox.show_all();
- scroll.show_all();
+ scroll.set_child(recentBox);
// FIXME: Can't use GtkContainer.child_get_property.
scroll.title = _('Recently Used');
this.add_titled(scroll, 'recent', scroll.title);
@@ -371,7 +369,7 @@ const MainView = GObject.registerClass({
const characterList = new CharacterList.CharacterListView({
fontFilter: this._fontFilter,
});
- characterList.get_accessible().accessible_name = accessible_name;
+ //characterList.get_accessible().accessible_name = accessible_name;
characterList.connect('character-selected', (widget, uc) => this._handleCharacterSelected(widget,
uc));
this._characterLists[name] = characterList;
@@ -383,7 +381,7 @@ const MainView = GObject.registerClass({
fontFilter: this._fontFilter,
category: category
});
- characterList.get_accessible().accessible_name = accessible_name;
+ //characterList.get_accessible().accessible_name = accessible_name;
characterList.connect('character-selected', (widget, uc) => this._handleCharacterSelected(widget,
uc));
this._characterLists[name] = characterList;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]