mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
Simplify new navigator window
This commit is contained in:
parent
23d260687c
commit
59ea1b9d95
3 changed files with 33 additions and 11 deletions
|
|
@ -59,10 +59,8 @@ impl Preferences {
|
|||
if let Some(path) = file.get_path() {
|
||||
this.music_library_path_row.set_subtitle(Some(path.to_str().unwrap()));
|
||||
|
||||
let context = glib::MainContext::default();
|
||||
let backend = this.backend.clone();
|
||||
context.spawn_local(async move {
|
||||
backend.set_music_library_path(path).await.unwrap();
|
||||
spawn!(@clone this, async move {
|
||||
this.backend.set_music_library_path(path).await.unwrap();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -87,13 +85,10 @@ impl Preferences {
|
|||
login_button.connect_clicked(clone!(@strong this => move |_| {
|
||||
let window = NavigatorWindow::new(this.backend.clone());
|
||||
window.set_transient_for(&this.window);
|
||||
window.show();
|
||||
|
||||
let context = glib::MainContext::default();
|
||||
let clone = this.clone();
|
||||
context.spawn_local(async move {
|
||||
if let Some(data) = window.navigator.replace::<_, _, LoginDialog>(()).await {
|
||||
clone.login_row.set_subtitle(Some(&data.username));
|
||||
spawn!(@clone this, async move {
|
||||
if let Some(data) = replace!(window.navigator, LoginDialog).await {
|
||||
this.login_row.set_subtitle(Some(&data.username));
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -23,6 +23,31 @@ macro_rules! push {
|
|||
};
|
||||
}
|
||||
|
||||
/// Simplification for replacing the current navigator screen.
|
||||
///
|
||||
/// This macro can be invoked in two forms.
|
||||
///
|
||||
/// 1. To replace with screens without an input value:
|
||||
///
|
||||
/// ```
|
||||
/// let result = replace!(navigator, ScreenType).await;
|
||||
/// ```
|
||||
///
|
||||
/// 2. To replace with screens with an input value:
|
||||
///
|
||||
/// ```
|
||||
/// let result = replace!(navigator, ScreenType, input).await;
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! replace {
|
||||
($navigator:expr, $screen:ty) => {
|
||||
$navigator.replace::<_, _, $screen>(())
|
||||
};
|
||||
($navigator:expr, $screen:ty, $input:ident) => {
|
||||
$navigator.replace::<_, _, $screen>($input)
|
||||
};
|
||||
}
|
||||
|
||||
/// Spawn a future on the GLib MainContext.
|
||||
///
|
||||
/// This can be invoked in the following forms:
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub struct NavigatorWindow {
|
|||
}
|
||||
|
||||
impl NavigatorWindow {
|
||||
/// Create a new navigator window.
|
||||
/// Create a new navigator window and show it.
|
||||
pub fn new(backend: Rc<Backend>) -> Rc<Self> {
|
||||
let window = libadwaita::Window::new();
|
||||
window.set_default_size(600, 424);
|
||||
|
|
@ -25,6 +25,8 @@ impl NavigatorWindow {
|
|||
this.window.close();
|
||||
}));
|
||||
|
||||
this.window.show();
|
||||
|
||||
this
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue