Skip to content

book: Second libadwaita section #1112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Sep 28, 2022
Merged
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
7 changes: 5 additions & 2 deletions book/listings/actions/7/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ impl Window {
self.imp()
.settings
.set(settings)
.expect("Could not set `Settings`.");
.expect("`settings` should not be set before calling `setup_settings`.");
}

fn settings(&self) -> &Settings {
self.imp().settings.get().expect("Could not get settings.")
self.imp()
.settings
.get()
.expect("`settings` should be set in `setup_settings`.")
}
// ANCHOR_END: settings

Expand Down
2 changes: 1 addition & 1 deletion book/listings/css/6/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ glib::wrapper! {
impl Window {
pub fn new(app: &Application) -> Self {
// Create new window
Object::new(&[("application", app)]).expect("Failed to create `Window`.")
Object::new(&[("application", app)]).expect("`Window` should be instantiable.")
}
}
2 changes: 1 addition & 1 deletion book/listings/css/7/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ glib::wrapper! {
impl Window {
pub fn new(app: &Application) -> Self {
// Create new window
Object::new(&[("application", app)]).expect("Failed to create `Window`.")
Object::new(&[("application", app)]).expect("`Window` should be instantiable.")
}
}
2 changes: 1 addition & 1 deletion book/listings/css/8/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ glib::wrapper! {
impl Window {
pub fn new(app: &Application) -> Self {
// Create new window
Object::new(&[("application", app)]).expect("Failed to create `Window`.")
Object::new(&[("application", app)]).expect("`Window` should be instantiable.")
}
}
2 changes: 1 addition & 1 deletion book/listings/css/9/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ glib::wrapper! {
impl Window {
pub fn new(app: &Application) -> Self {
// Create new window
Object::new(&[("application", app)]).expect("Failed to create `Window`.")
Object::new(&[("application", app)]).expect("`Window` should be instantiable.")
}
}
9 changes: 6 additions & 3 deletions book/listings/saving_window_state/1/custom_window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ glib::wrapper! {
impl Window {
pub fn new(app: &Application) -> Self {
// Create new window
Object::new(&[("application", app)]).expect("Failed to create `Window`.")
Object::new(&[("application", app)]).expect("`Window` should be instantiable.")
}

fn setup_settings(&self) {
let settings = Settings::new(APP_ID);
self.imp()
.settings
.set(settings)
.expect("Could not set `Settings`.");
.expect("`settings` should not be set before calling `setup_settings`.");
}

fn settings(&self) -> &Settings {
self.imp().settings.get().expect("Could not get settings.")
self.imp()
.settings
.get()
.expect("`settings` should be set in `setup_settings`.")
}

pub fn save_window_size(&self) -> Result<(), glib::BoolError> {
Expand Down
2 changes: 1 addition & 1 deletion book/listings/todo/1/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ glib::wrapper! {
impl Window {
pub fn new(app: &Application) -> Self {
// Create new window
Object::new(&[("application", app)]).expect("Failed to create `Window`.")
Object::new(&[("application", app)]).expect("`Window` should be instantiable.")
}

// ANCHOR: tasks
Expand Down
2 changes: 1 addition & 1 deletion book/listings/todo/2/window/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl WindowImpl for Window {
.map(TaskObject::task_data)
.collect();

// Save state in file
// Save state to file
let file = File::create(data_path()).expect("Could not create json file.");
serde_json::to_writer(file, &backup_data)
.expect("Could not write data to json file");
Expand Down
14 changes: 9 additions & 5 deletions book/listings/todo/2/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ glib::wrapper! {
impl Window {
pub fn new(app: &Application) -> Self {
// Create new window
Object::new(&[("application", app)]).expect("Failed to create `Window`.")
Object::new(&[("application", app)]).expect("`Window` should be instantiable.")
}

// ANCHOR: settings
Expand All @@ -35,11 +35,14 @@ impl Window {
self.imp()
.settings
.set(settings)
.expect("Could not set `Settings`.");
.expect("`settings` should not be set before calling `setup_settings`.");
}

fn settings(&self) -> &Settings {
self.imp().settings.get().expect("Could not get settings.")
self.imp()
.settings
.get()
.expect("`settings` should be set in `setup_settings`.")
}
// ANCHOR_END: settings

Expand Down Expand Up @@ -117,8 +120,9 @@ impl Window {
fn restore_data(&self) {
if let Ok(file) = File::open(data_path()) {
// Deserialize data from file to vector
let backup_data: Vec<TaskData> = serde_json::from_reader(file)
.expect("Could not get backup data from json file.");
let backup_data: Vec<TaskData> = serde_json::from_reader(file).expect(
"It should be possible to read `backup_data` from the json file.",
);

// Convert `Vec<TaskData>` to `Vec<TaskObject>`
let task_objects: Vec<TaskObject> = backup_data
Expand Down
2 changes: 1 addition & 1 deletion book/listings/todo/3/window/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl WindowImpl for Window {
.map(TaskObject::task_data)
.collect();

// Save state in file
// Save state to file
let file = File::create(data_path()).expect("Could not create json file.");
serde_json::to_writer(file, &backup_data)
.expect("Could not write data to json file");
Expand Down
14 changes: 9 additions & 5 deletions book/listings/todo/3/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,22 @@ glib::wrapper! {
impl Window {
pub fn new(app: &Application) -> Self {
// Create new window
Object::new(&[("application", app)]).expect("Failed to create `Window`.")
Object::new(&[("application", app)]).expect("`Window` should be instantiable.")
}

fn setup_settings(&self) {
let settings = Settings::new(APP_ID);
self.imp()
.settings
.set(settings)
.expect("Could not set `Settings`.");
.expect("`settings` should not be set before calling `setup_settings`.");
}

fn settings(&self) -> &Settings {
self.imp().settings.get().expect("Could not get settings.")
self.imp()
.settings
.get()
.expect("`settings` should be set in `setup_settings`.")
}

fn tasks(&self) -> gio::ListStore {
Expand Down Expand Up @@ -110,8 +113,9 @@ impl Window {
fn restore_data(&self) {
if let Ok(file) = File::open(data_path()) {
// Deserialize data from file to vector
let backup_data: Vec<TaskData> = serde_json::from_reader(file)
.expect("Could not get backup data from json file.");
let backup_data: Vec<TaskData> = serde_json::from_reader(file).expect(
"It should be possible to read `backup_data` from the json file.",
);

// Convert `Vec<TaskData>` to `Vec<TaskObject>`
let task_objects: Vec<TaskObject> = backup_data
Expand Down
2 changes: 1 addition & 1 deletion book/listings/todo/4/window/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl WindowImpl for Window {
.map(TaskObject::task_data)
.collect();

// Save state in file
// Save state to file
let file = File::create(data_path()).expect("Could not create json file.");
serde_json::to_writer(file, &backup_data)
.expect("Could not write data to json file");
Expand Down
14 changes: 9 additions & 5 deletions book/listings/todo/4/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,22 @@ glib::wrapper! {
impl Window {
pub fn new(app: &Application) -> Self {
// Create new window
Object::new(&[("application", app)]).expect("Failed to create `Window`.")
Object::new(&[("application", app)]).expect("`Window` should be instantiable.")
}

fn setup_settings(&self) {
let settings = Settings::new(APP_ID);
self.imp()
.settings
.set(settings)
.expect("Could not set `Settings`.");
.expect("`settings` should not be set before calling `setup_settings`.");
}

fn settings(&self) -> &Settings {
self.imp().settings.get().expect("Could not get settings.")
self.imp()
.settings
.get()
.expect("`settings` should be set in `setup_settings`.")
}

fn tasks(&self) -> gio::ListStore {
Expand Down Expand Up @@ -107,8 +110,9 @@ impl Window {
fn restore_data(&self) {
if let Ok(file) = File::open(data_path()) {
// Deserialize data from file to vector
let backup_data: Vec<TaskData> = serde_json::from_reader(file)
.expect("Could not get backup data from json file.");
let backup_data: Vec<TaskData> = serde_json::from_reader(file).expect(
"It should be possible to read `backup_data` from the json file.",
);

// Convert `Vec<TaskData>` to `Vec<TaskObject>`
let task_objects: Vec<TaskObject> = backup_data
Expand Down
2 changes: 1 addition & 1 deletion book/listings/todo/5/window/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl WindowImpl for Window {
.map(TaskObject::task_data)
.collect();

// Save state in file
// Save state to file
let file = File::create(data_path()).expect("Could not create json file.");
serde_json::to_writer(file, &backup_data)
.expect("Could not write data to json file");
Expand Down
14 changes: 9 additions & 5 deletions book/listings/todo/5/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Window {
// ANCHOR: new
pub fn new(app: &adw::Application) -> Self {
// Create new window
Object::new(&[("application", app)]).expect("Failed to create `Window`.")
Object::new(&[("application", app)]).expect("`Window` should be instantiable.")
}
// ANCHOR_END: new

Expand All @@ -35,11 +35,14 @@ impl Window {
self.imp()
.settings
.set(settings)
.expect("Could not set `Settings`.");
.expect("`settings` should not be set before calling `setup_settings`.");
}

fn settings(&self) -> &Settings {
self.imp().settings.get().expect("Could not get settings.")
self.imp()
.settings
.get()
.expect("`settings` should be set in `setup_settings`.")
}

fn tasks(&self) -> gio::ListStore {
Expand Down Expand Up @@ -108,8 +111,9 @@ impl Window {
fn restore_data(&self) {
if let Ok(file) = File::open(data_path()) {
// Deserialize data from file to vector
let backup_data: Vec<TaskData> = serde_json::from_reader(file)
.expect("Could not get backup data from json file.");
let backup_data: Vec<TaskData> = serde_json::from_reader(file).expect(
"It should be possible to read `backup_data` from the json file.",
);

// Convert `Vec<TaskData>` to `Vec<TaskObject>`
let task_objects: Vec<TaskObject> = backup_data
Expand Down
2 changes: 1 addition & 1 deletion book/listings/todo/6/window/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl WindowImpl for Window {
.map(TaskObject::task_data)
.collect();

// Save state in file
// Save state to file
let file = File::create(data_path()).expect("Could not create json file.");
serde_json::to_writer(file, &backup_data)
.expect("Could not write data to json file");
Expand Down
16 changes: 10 additions & 6 deletions book/listings/todo/6/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ glib::wrapper! {
impl Window {
pub fn new(app: &adw::Application) -> Self {
// Create new window
Object::new(&[("application", app)]).expect("Failed to create `Window`.")
Object::new(&[("application", app)]).expect("`Window` should be instantiable.")
}

fn setup_settings(&self) {
let settings = Settings::new(APP_ID);
self.imp()
.settings
.set(settings)
.expect("Could not set `Settings`.");
.expect("`settings` should not be set before calling `setup_settings`.");
}

fn settings(&self) -> &Settings {
self.imp().settings.get().expect("Could not get settings.")
self.imp()
.settings
.get()
.expect("`settings` should be set in `setup_settings`.")
}

fn tasks(&self) -> gio::ListStore {
Expand Down Expand Up @@ -94,7 +97,7 @@ impl Window {
self.imp().tasks_list.bind_model(
Some(&selection_model),
clone!(@weak self as window => @default-panic, move |obj| {
let task_object = obj.downcast_ref().expect("The object is not of type `TaskObject`.");
let task_object = obj.downcast_ref().expect("The object should be of type `TaskObject`.");
let row = window.create_task_row(task_object);
row.upcast()
}),
Expand Down Expand Up @@ -131,8 +134,9 @@ impl Window {
fn restore_data(&self) {
if let Ok(file) = File::open(data_path()) {
// Deserialize data from file to vector
let backup_data: Vec<TaskData> = serde_json::from_reader(file)
.expect("Could not get backup data from json file.");
let backup_data: Vec<TaskData> = serde_json::from_reader(file).expect(
"It should be possible to read `backup_data` from the json file.",
);

// Convert `Vec<TaskData>` to `Vec<TaskObject>`
let task_objects: Vec<TaskObject> = backup_data
Expand Down
13 changes: 7 additions & 6 deletions book/listings/todo/7/resources/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
<binding name="show-end-title-buttons">
<lookup name="folded">leaflet</lookup>
</binding>
<child type="start">
<object class="GtkToggleButton">
<property name="icon-name">list-add-symbolic</property>
<property name="tooltip-text" translatable="yes">New Collection</property>
<property name="action-name">win.new-collection</property>
</object>
</child>
</object>
</child>
<child>
Expand Down Expand Up @@ -74,9 +81,6 @@
<property name="hexpand">True</property>
<child>
<object class="AdwHeaderBar">
<binding name="show-start-title-buttons">
<lookup name="folded">leaflet</lookup>
</binding>
<property name="title-widget">
<object class="AdwWindowTitle" />
</property>
Expand All @@ -100,8 +104,6 @@
</child>
<child>
<object class="GtkScrolledWindow">
<property name="hscrollbar-policy">never</property>
<property name="min-content-height">420</property>
<property name="vexpand">True</property>
<property name="child">
<object class="AdwClamp">
Expand All @@ -121,7 +123,6 @@
</child>
<child>
<object class="GtkListBox" id="tasks_list">
<property name="valign">start</property>
<property name="visible">False</property>
<property name="selection-mode">none</property>
<style>
Expand Down
Loading