Skip to content

Commit

Permalink
misc: port to adw dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaDve committed Feb 5, 2024
1 parent e842654 commit 8caa22d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 38 deletions.
18 changes: 0 additions & 18 deletions data/resources/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,3 @@ dragoverlay .drag-area-highlight {
margin-top: 3px;
margin-bottom: 3px;
}

/* SaveChangesDialog */

.save-changes-dialog > windowhandle > box.vertical > box.message-area.vertical {
padding-bottom: 0;
}

.save-changes-dialog > windowhandle > box.vertical > box.message-area.vertical > preferencespage {
margin-left: -30px;
margin-right: -30px;
}

.save-changes-dialog > windowhandle > box.vertical > box.message-area.vertical > preferencespage > scrolledwindow > viewport {
padding-left: 30px;
padding-right: 30px;
padding-bottom: 10px;
}

2 changes: 1 addition & 1 deletion data/resources/ui/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<object class="AdwToolbarView">
<property name="top-bar-style">raised</property>
<child type="top">
<object class="GtkHeaderBar">
<object class="AdwHeaderBar">
<child>
<object class="AdwSplitButton">
<property name="label" translatable="yes">Open</property>
Expand Down
11 changes: 5 additions & 6 deletions src/about.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use adw::prelude::*;
use gettextrs::gettext;
use gtk::{glib, prelude::*};
use gtk::glib;

use std::{env, path::Path};

Expand All @@ -8,9 +9,8 @@ use crate::{
utils,
};

pub fn present_window(transient_for: Option<&impl IsA<gtk::Window>>) {
let win = adw::AboutWindow::builder()
.modal(true)
pub fn present_window(parent: &impl IsA<gtk::Widget>) {
let win = adw::AboutDialog::builder()
.application_icon(APP_ID)
.application_name(utils::application_name())
.developer_name(gettext("Dave Patrick Caberto"))
Expand Down Expand Up @@ -38,8 +38,7 @@ pub fn present_window(transient_for: Option<&impl IsA<gtk::Window>>) {
"https://hosted.weblate.org/projects/seadve/delineate",
);

win.set_transient_for(transient_for);
win.present();
win.present(parent);
}

fn debug_info() -> String {
Expand Down
6 changes: 5 additions & 1 deletion src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ impl Application {
.build();
let action_about = gio::ActionEntry::builder("about")
.activate(|obj: &Self, _, _| {
about::present_window(obj.active_window().as_ref());
if let Some(window) = obj.active_window() {
about::present_window(&window);
} else {
tracing::warn!("Can't present about dialog without an active window");
}
})
.build();
self.add_action_entries([action_new_window, action_quit, action_about]);
Expand Down
19 changes: 7 additions & 12 deletions src/save_changes_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,15 @@ pub async fn run(window: &Window, unsaved: &[Document]) -> glib::Propagation {

/// Returns `Ok` if unsaved changes are handled and can proceed, `Err` if
/// the next operation should be aborted.
async fn run_inner(parent: &impl IsA<gtk::Window>, unsaved: &[Document]) -> Result<()> {
async fn run_inner(parent: &impl IsA<gtk::Widget>, unsaved: &[Document]) -> Result<()> {
debug_assert!(!unsaved.is_empty());

let dialog = adw::MessageDialog::builder()
.modal(true)
.transient_for(parent)
let dialog = adw::AlertDialog::builder()
.heading(gettext("Save Changes?"))
.body(gettext("Open documents contain unsaved changes. Changes which are not saved will be permanently lost."))
.close_response(CANCEL_RESPONSE_ID)
.default_response(SAVE_RESPONSE_ID)
.build();
dialog.add_css_class("save-changes-dialog");

dialog.add_response(CANCEL_RESPONSE_ID, &gettext("Cancel"));
dialog.add_response(
Expand All @@ -76,19 +73,17 @@ async fn run_inner(parent: &impl IsA<gtk::Window>, unsaved: &[Document]) -> Resu
dialog.set_response_appearance(DISCARD_RESPONSE_ID, adw::ResponseAppearance::Destructive);
dialog.set_response_appearance(SAVE_RESPONSE_ID, adw::ResponseAppearance::Suggested);

let page = adw::PreferencesPage::new();
dialog.set_extra_child(Some(&page));

let group = adw::PreferencesGroup::new();
page.add(&group);
let list_box = gtk::ListBox::new();
list_box.add_css_class("boxed-list");
dialog.set_extra_child(Some(&list_box));

let mut items = Vec::new();
let check_buttons = Rc::new(RefCell::new(Vec::new()));
for document in unsaved {
debug_assert!(document.is_modified());

let row = adw::ActionRow::new();
group.add(&row);
list_box.append(&row);

let check_button = gtk::CheckButton::builder()
.valign(gtk::Align::Center)
Expand Down Expand Up @@ -149,7 +144,7 @@ async fn run_inner(parent: &impl IsA<gtk::Window>, unsaved: &[Document]) -> Resu
}));
}

match dialog.choose_future().await.as_str() {
match dialog.choose_future(parent).await.as_str() {
CANCEL_RESPONSE_ID => Err(Cancelled.into()),
DISCARD_RESPONSE_ID => Ok(()),
SAVE_RESPONSE_ID => {
Expand Down

0 comments on commit 8caa22d

Please sign in to comment.