Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
339 changes: 163 additions & 176 deletions book/listings/Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions book/listings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
[package]
name = "gtk4-rs-book-listings"
edition = "2021"
edition = "2024"

[dependencies]
adw = { version = "0.7", package = "libadwaita", features = ["v1_5"] }
adw = { version = "0.8", package = "libadwaita", features = ["v1_8"] }
anyhow = "1.0"
async-channel = "2.0"
gtk = { version = "0.9", package = "gtk4", features = ["v4_12"] }
async-channel = "2.5"
gtk = { version = "0.10", package = "gtk4", features = ["v4_12"] }
reqwest = { version = "0.12", default-features = false, features = [
"rustls-tls",
] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.33.0", features = ["rt-multi-thread"] }
tokio = { version = "1.48.0", features = ["rt-multi-thread"] }
walkdir = "2.5"
xshell = "0.2"

[target.'cfg(target_os = "linux")'.dependencies]
ashpd = { version = "0.11", default-features = false, features = ["gtk4", "async-std"] }
ashpd = { version = "0.12", default-features = false, features = ["gtk4", "async-std"] }

[build-dependencies]
glib-build-tools = "0.20"
glib-build-tools = "0.21"

# actions
[[bin]]
Expand Down
2 changes: 1 addition & 1 deletion book/listings/todo/6/resources/resources.gresource.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gtk_rs/Todo6/">
<file compressed="true" preprocess="xml-stripblanks" alias="gtk/help-overlay.ui">shortcuts.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="shortcuts-dialog.ui">shortcuts.ui</file>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Mention that change in the book

<file compressed="true" preprocess="xml-stripblanks">window.ui</file>
</gresource>
</gresources>
57 changes: 25 additions & 32 deletions book/listings/todo/6/resources/shortcuts.ui
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkShortcutsWindow" id="help_overlay">
<property name="modal">True</property>
<object class="AdwShortcutsDialog" id="shortcuts_dialog">
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Mention the changed id in the book

<child>
<object class="GtkShortcutsSection">
<property name="section-name">shortcuts</property>
<property name="max-height">10</property>
<object class="AdwShortcutsSection">
<property name="title" translatable="yes">General</property>
<child>
<object class="GtkShortcutsGroup">
<property name="title" translatable="yes" context="shortcut window">General</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Show shortcuts</property>
<property name="action-name">win.show-help-overlay</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Filter to show all tasks</property>
<property name="action-name">win.filter('All')</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Filter to show only open tasks</property>
<property name="action-name">win.filter('Open')</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Filter to show only completed tasks</property>
<property name="action-name">win.filter('Done')</property>
</object>
</child>
<object class="AdwShortcutsItem">
<property name="title" translatable="yes">Show shortcuts</property>
<property name="action-name">app.shortcuts</property>
</object>
</child>
<child>
<object class="AdwShortcutsItem">
<property name="title" translatable="yes">Filter to show all tasks</property>
<property name="action-name">win.filter('All')</property>
</object>
</child>
<child>
<object class="AdwShortcutsItem">
<property name="title" translatable="yes">Filter to show only open tasks</property>
<property name="action-name">win.filter('Open')</property>
</object>
</child>
<child>
<object class="AdwShortcutsItem">
<property name="title" translatable="yes">Filter to show only completed tasks</property>
<property name="action-name">win.filter('Done')</property>
</object>
</child>
</object>
</child>
</object>
</interface>
</interface>
2 changes: 1 addition & 1 deletion book/listings/todo/6/resources/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</item>
<item>
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
<attribute name="action">win.show-help-overlay</attribute>
<attribute name="action">app.shortcuts</attribute>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Mention that change in the book

</item>
</menu>
<template class="TodoWindow" parent="GtkApplicationWindow">
Expand Down
2 changes: 1 addition & 1 deletion book/listings/todo/7/resources/resources.gresource.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gtk_rs/Todo7/">
<file compressed="true" preprocess="xml-stripblanks" alias="gtk/help-overlay.ui">shortcuts.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="shortcuts-dialog.ui">shortcuts.ui</file>
<file compressed="true" preprocess="xml-stripblanks">window.ui</file>
</gresource>
</gresources>
57 changes: 25 additions & 32 deletions book/listings/todo/7/resources/shortcuts.ui
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkShortcutsWindow" id="help_overlay">
<property name="modal">True</property>
<object class="AdwShortcutsDialog" id="shortcuts_dialog">
<child>
<object class="GtkShortcutsSection">
<property name="section-name">shortcuts</property>
<property name="max-height">10</property>
<object class="AdwShortcutsSection">
<property name="title" translatable="yes">General</property>
<child>
<object class="GtkShortcutsGroup">
<property name="title" translatable="yes" context="shortcut window">General</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Show shortcuts</property>
<property name="action-name">win.show-help-overlay</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Filter to show all tasks</property>
<property name="action-name">win.filter('All')</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Filter to show only open tasks</property>
<property name="action-name">win.filter('Open')</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Filter to show only completed tasks</property>
<property name="action-name">win.filter('Done')</property>
</object>
</child>
<object class="AdwShortcutsItem">
<property name="title" translatable="yes">Show shortcuts</property>
<property name="action-name">app.shortcuts</property>
</object>
</child>
<child>
<object class="AdwShortcutsItem">
<property name="title" translatable="yes">Filter to show all tasks</property>
<property name="action-name">win.filter('All')</property>
</object>
</child>
<child>
<object class="AdwShortcutsItem">
<property name="title" translatable="yes">Filter to show only open tasks</property>
<property name="action-name">win.filter('Open')</property>
</object>
</child>
<child>
<object class="AdwShortcutsItem">
<property name="title" translatable="yes">Filter to show only completed tasks</property>
<property name="action-name">win.filter('Done')</property>
</object>
</child>
</object>
</child>
</object>
</interface>
</interface>
2 changes: 1 addition & 1 deletion book/listings/todo/7/resources/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</item>
<item>
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
<attribute name="action">win.show-help-overlay</attribute>
<attribute name="action">app.shortcuts</attribute>
</item>
</menu>
<template class="TodoWindow" parent="AdwApplicationWindow">
Expand Down
2 changes: 1 addition & 1 deletion book/listings/todo/8/resources/resources.gresource.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gtk_rs/Todo8/">
<file compressed="true" preprocess="xml-stripblanks" alias="gtk/help-overlay.ui">shortcuts.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="shortcuts-dialog.ui">shortcuts.ui</file>
<file compressed="true" preprocess="xml-stripblanks">window.ui</file>
</gresource>
</gresources>
57 changes: 25 additions & 32 deletions book/listings/todo/8/resources/shortcuts.ui
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkShortcutsWindow" id="help_overlay">
<property name="modal">True</property>
<object class="AdwShortcutsDialog" id="shortcuts_dialog">
<child>
<object class="GtkShortcutsSection">
<property name="section-name">shortcuts</property>
<property name="max-height">10</property>
<object class="AdwShortcutsSection">
<property name="title" translatable="yes">General</property>
<child>
<object class="GtkShortcutsGroup">
<property name="title" translatable="yes" context="shortcut window">General</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Show shortcuts</property>
<property name="action-name">win.show-help-overlay</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Filter to show all tasks</property>
<property name="action-name">win.filter('All')</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Filter to show only open tasks</property>
<property name="action-name">win.filter('Open')</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Filter to show only completed tasks</property>
<property name="action-name">win.filter('Done')</property>
</object>
</child>
<object class="AdwShortcutsItem">
<property name="title" translatable="yes">Show shortcuts</property>
<property name="action-name">app.shortcuts</property>
</object>
</child>
<child>
<object class="AdwShortcutsItem">
<property name="title" translatable="yes">Filter to show all tasks</property>
<property name="action-name">win.filter('All')</property>
</object>
</child>
<child>
<object class="AdwShortcutsItem">
<property name="title" translatable="yes">Filter to show only open tasks</property>
<property name="action-name">win.filter('Open')</property>
</object>
</child>
<child>
<object class="AdwShortcutsItem">
<property name="title" translatable="yes">Filter to show only completed tasks</property>
<property name="action-name">win.filter('Done')</property>
</object>
</child>
</object>
</child>
</object>
</interface>
</interface>
2 changes: 1 addition & 1 deletion book/listings/todo/8/resources/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</item>
<item>
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
<attribute name="action">win.show-help-overlay</attribute>
<attribute name="action">app.shortcuts</attribute>
</item>
</menu>
<template class="TodoWindow" parent="AdwApplicationWindow">
Expand Down
10 changes: 5 additions & 5 deletions book/listings/todo/8/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ use adw::prelude::*;
use adw::subclass::prelude::*;
use adw::{ActionRow, AlertDialog, ResponseAppearance};
use gio::Settings;
use glib::{clone, Object};
use glib::{Object, clone};
use gtk::{
gio, glib, pango, Align, CheckButton, CustomFilter, Entry, FilterListModel, Label,
ListBoxRow, NoSelection,
Align, CheckButton, CustomFilter, Entry, FilterListModel, Label, ListBoxRow,
NoSelection, gio, glib, pango,
};

use crate::APP_ID;
use crate::collection_object::{CollectionData, CollectionObject};
use crate::task_object::TaskObject;
use crate::utils::data_path;
use crate::APP_ID;

glib::wrapper! {
pub struct Window(ObjectSubclass<imp::Window>)
Expand Down Expand Up @@ -423,7 +423,7 @@ impl Window {
}
));

let response = dialog.choose_future(self).await;
let response = dialog.choose_future(Some(self)).await;

// Return if the user chose `cancel_response`
if response == cancel_response {
Expand Down
2 changes: 1 addition & 1 deletion book/src/libadwaita.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Libadwaita is a library augmenting GTK 4 which:
In order to use the Rust bindings, add the [libadwaita crate](https://crates.io/crates/libadwaita) as dependency by executing:

```
cargo add libadwaita --rename adw --features v1_5
cargo add libadwaita --rename adw --features v1_8
```

The versions of the `gtk4` and `libadwaita` crates need to be synced.
Expand Down
20 changes: 20 additions & 0 deletions book/src/todo_3.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,23 @@ Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/main/b
This is how the boxed list style looks like in our app.

<div style="text-align:center"><img src="img/todo_6.png" alt="The To-Do app using libadwaita"/></div>

## Shortcuts Dialog

Now that we are using Libadwaita, we should also update our keyboard shortcuts window to use [`adw::ShortcutsDialog`](https://world.pages.gitlab.gnome.org/Rust/libadwaita-rs/stable/latest/docs/libadwaita/struct.ShortcutsDialog.html).
This widget is the Libadwaita equivalent of [`gtk::ShortcutsWindow`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.ShortcutsWindow.html) and provides better integration with the Adwaita style.

The main differences are:

- [`adw::ShortcutsDialog`](https://world.pages.gitlab.gnome.org/Rust/libadwaita-rs/stable/latest/docs/libadwaita/struct.ShortcutsDialog.html) extends [`adw::Dialog`](https://world.pages.gitlab.gnome.org/Rust/libadwaita-rs/stable/latest/docs/libadwaita/struct.Dialog.html) rather than [`gtk::Window`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Window.html)
- It uses [`adw::ShortcutsSection`](https://world.pages.gitlab.gnome.org/Rust/libadwaita-rs/stable/latest/docs/libadwaita/struct.ShortcutsSection.html) and [`adw::ShortcutsItem`](https://world.pages.gitlab.gnome.org/Rust/libadwaita-rs/stable/latest/docs/libadwaita/struct.ShortcutsItem.html) instead of [`gtk::ShortcutsSection`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.ShortcutsSection.html), [`gtk::ShortcutsGroup`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.ShortcutsGroup.html), and [`gtk::ShortcutsShortcut`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.ShortcutsShortcut.html)
- The structure is simpler, with sections directly containing items
Comment on lines +158 to +165
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify this and add diff of changed parts


Let us update our `shortcuts.ui` file:

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/main/book/listings/todo/6/resources/shortcuts.ui">listings/todo/6/resources/shortcuts.ui</a>

```xml
{{#rustdoc_include ../listings/todo/6/resources/shortcuts.ui}}
```

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add screenshot

Loading