finish port to libadwaita dialogs
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
using Gtk 4.0;
|
||||
using Adw 1;
|
||||
|
||||
template $NotifyPreferences : Adw.PreferencesWindow {
|
||||
template $NotifyPreferences : Adw.PreferencesDialog {
|
||||
width-request: 240;
|
||||
height-request: 360;
|
||||
Adw.PreferencesPage {
|
||||
|
||||
@ -4,13 +4,13 @@ use std::path::PathBuf;
|
||||
use std::pin::Pin;
|
||||
use std::rc::Rc;
|
||||
|
||||
use adw::prelude::*;
|
||||
use adw::subclass::prelude::*;
|
||||
use capnp_rpc::{rpc_twoparty_capnp, twoparty, RpcSystem};
|
||||
use futures::stream::Stream;
|
||||
use futures::AsyncReadExt;
|
||||
use gio::SocketClient;
|
||||
use gio::UnixSocketAddress;
|
||||
use gtk::prelude::*;
|
||||
use gtk::{gdk, gio, glib};
|
||||
use ntfy_daemon::models;
|
||||
use ntfy_daemon::ntfy_capnp::system_notifier;
|
||||
@ -217,23 +217,20 @@ impl NotifyApplication {
|
||||
}
|
||||
|
||||
fn show_about_dialog(&self) {
|
||||
let dialog = adw::AboutWindow::from_appdata(
|
||||
let dialog = adw::AboutDialog::from_appdata(
|
||||
"/com/ranfdev/Notify/com.ranfdev.Notify.metainfo.xml",
|
||||
None,
|
||||
);
|
||||
if let Some(w) = self.imp().window.borrow().upgrade() {
|
||||
dialog.set_transient_for(Some(&w));
|
||||
dialog.present(&w);
|
||||
}
|
||||
|
||||
dialog.present();
|
||||
}
|
||||
|
||||
fn show_preferences(&self) {
|
||||
let win = crate::widgets::NotifyPreferences::new(
|
||||
self.main_window().imp().notifier.get().unwrap().clone(),
|
||||
);
|
||||
win.set_transient_for(Some(&self.main_window()));
|
||||
win.present();
|
||||
win.present(&self.main_window());
|
||||
}
|
||||
|
||||
pub fn run(&self) -> glib::ExitCode {
|
||||
|
||||
@ -31,11 +31,6 @@ mod imp {
|
||||
type ParentType = adw::Dialog;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
klass.add_binding_action(
|
||||
gtk::gdk::Key::Escape,
|
||||
gtk::gdk::ModifierType::empty(),
|
||||
"window.close",
|
||||
);
|
||||
klass.install_action("default.activate", None, |this, _, _| {
|
||||
this.emit_subscribe_request();
|
||||
});
|
||||
|
||||
@ -20,30 +20,22 @@ mod imp {
|
||||
impl ObjectSubclass for AdvancedMessageDialog {
|
||||
const NAME: &'static str = "AdvancedMessageDialog";
|
||||
type Type = super::AdvancedMessageDialog;
|
||||
type ParentType = adw::Window;
|
||||
type ParentType = adw::Dialog;
|
||||
}
|
||||
|
||||
impl ObjectImpl for AdvancedMessageDialog {}
|
||||
impl WidgetImpl for AdvancedMessageDialog {}
|
||||
impl WindowImpl for AdvancedMessageDialog {}
|
||||
impl AdwWindowImpl for AdvancedMessageDialog {}
|
||||
impl AdwDialogImpl for AdvancedMessageDialog {}
|
||||
}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct AdvancedMessageDialog(ObjectSubclass<imp::AdvancedMessageDialog>)
|
||||
@extends gtk::Widget, gtk::Window, adw::Window;
|
||||
@extends gtk::Widget, adw::Dialog;
|
||||
}
|
||||
|
||||
impl AdvancedMessageDialog {
|
||||
pub fn new(
|
||||
parent: &impl IsA<gtk::Window>,
|
||||
subscription: Subscription,
|
||||
message: String,
|
||||
) -> Self {
|
||||
pub fn new(subscription: Subscription, message: String) -> Self {
|
||||
let this: Self = glib::Object::new();
|
||||
this.set_transient_for(Some(parent));
|
||||
this.set_modal(true);
|
||||
this.set_default_height(400);
|
||||
this.imp().subscription.set(subscription).unwrap();
|
||||
this.build_ui(
|
||||
this.imp().subscription.get().unwrap().topic().clone(),
|
||||
@ -52,6 +44,9 @@ impl AdvancedMessageDialog {
|
||||
this
|
||||
}
|
||||
fn build_ui(&self, topic: String, message: String) {
|
||||
self.set_title("Advanced Message");
|
||||
self.set_content_height(480);
|
||||
self.set_content_width(480);
|
||||
let this = self.clone();
|
||||
relm4_macros::view! {
|
||||
content = &adw::ToolbarView {
|
||||
@ -59,7 +54,7 @@ impl AdvancedMessageDialog {
|
||||
#[wrap(Some)]
|
||||
set_content: toast_overlay = &adw::ToastOverlay {
|
||||
#[wrap(Some)]
|
||||
set_child = &adw::Clamp {
|
||||
set_child = >k::ScrolledWindow {
|
||||
#[wrap(Some)]
|
||||
set_child = >k::Box {
|
||||
set_margin_top: 8,
|
||||
@ -82,22 +77,19 @@ impl AdvancedMessageDialog {
|
||||
set_xalign: 0.0,
|
||||
set_halign: gtk::Align::Start,
|
||||
},
|
||||
append = >k::ScrolledWindow {
|
||||
#[wrap(Some)]
|
||||
set_child: text_view = &gsv::View {
|
||||
add_css_class: "code",
|
||||
set_tab_width: 4,
|
||||
set_indent_width: 2,
|
||||
set_auto_indent: true,
|
||||
set_top_margin: 4,
|
||||
set_bottom_margin: 4,
|
||||
set_left_margin: 4,
|
||||
set_right_margin: 4,
|
||||
set_hexpand: true,
|
||||
set_vexpand: true,
|
||||
set_monospace: true,
|
||||
set_background_pattern: gsv::BackgroundPatternType::Grid
|
||||
},
|
||||
append: text_view = &gsv::View {
|
||||
add_css_class: "code",
|
||||
set_tab_width: 4,
|
||||
set_indent_width: 2,
|
||||
set_auto_indent: true,
|
||||
set_top_margin: 4,
|
||||
set_bottom_margin: 4,
|
||||
set_left_margin: 4,
|
||||
set_right_margin: 4,
|
||||
set_hexpand: true,
|
||||
set_vexpand: true,
|
||||
set_monospace: true,
|
||||
set_background_pattern: gsv::BackgroundPatternType::Grid
|
||||
},
|
||||
append = >k::Label {
|
||||
add_css_class: "heading",
|
||||
@ -166,9 +158,9 @@ impl AdvancedMessageDialog {
|
||||
add_css_class: "circular",
|
||||
add_css_class: "small",
|
||||
set_label: "?",
|
||||
connect_clicked[this] => move |_| {
|
||||
connect_clicked => move |_| {
|
||||
gtk::UriLauncher::new("https://docs.ntfy.sh/publish/#publish-as-json").launch(
|
||||
Some(&this),
|
||||
None::<>k::Window>,
|
||||
gio::Cancellable::NONE,
|
||||
|_| {}
|
||||
);
|
||||
@ -221,6 +213,6 @@ impl AdvancedMessageDialog {
|
||||
};
|
||||
let scheme = gsv::StyleSchemeManager::default().scheme(scheme_name);
|
||||
buffer.set_style_scheme(scheme.as_ref());
|
||||
this.set_content(Some(&content));
|
||||
this.set_child(Some(&content));
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ mod imp {
|
||||
impl ObjectSubclass for NotifyPreferences {
|
||||
const NAME: &'static str = "NotifyPreferences";
|
||||
type Type = super::NotifyPreferences;
|
||||
type ParentType = adw::PreferencesWindow;
|
||||
type ParentType = adw::PreferencesDialog;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
klass.bind_template();
|
||||
@ -66,16 +66,13 @@ mod imp {
|
||||
}
|
||||
|
||||
impl WidgetImpl for NotifyPreferences {}
|
||||
impl WindowImpl for NotifyPreferences {}
|
||||
|
||||
impl ApplicationWindowImpl for NotifyPreferences {}
|
||||
impl AdwWindowImpl for NotifyPreferences {}
|
||||
impl PreferencesWindowImpl for NotifyPreferences {}
|
||||
impl AdwDialogImpl for NotifyPreferences {}
|
||||
impl PreferencesDialogImpl for NotifyPreferences {}
|
||||
}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct NotifyPreferences(ObjectSubclass<imp::NotifyPreferences>)
|
||||
@extends gtk::Widget, gtk::Window, adw::Window, adw::PreferencesWindow,
|
||||
@extends gtk::Widget, adw::Dialog, adw::PreferencesDialog,
|
||||
@implements gio::ActionMap, gio::ActionGroup, gtk::Root;
|
||||
}
|
||||
|
||||
|
||||
@ -30,11 +30,6 @@ mod imp {
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
klass.bind_template();
|
||||
klass.add_binding_action(
|
||||
gtk::gdk::Key::Escape,
|
||||
gtk::gdk::ModifierType::empty(),
|
||||
"window.close",
|
||||
);
|
||||
}
|
||||
|
||||
// You must call `Widget`'s `init_template()` within `instance_init()`.
|
||||
|
||||
@ -236,8 +236,7 @@ impl NotifyWindow {
|
||||
imp.code_btn.connect_clicked(move |_| {
|
||||
let this = this.clone();
|
||||
this.selected_subscription().map(move |sub| {
|
||||
AdvancedMessageDialog::new(&this, sub, this.imp().entry.text().to_string())
|
||||
.present()
|
||||
AdvancedMessageDialog::new(sub, this.imp().entry.text().to_string()).present(&this)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user