desktop: Add OpenDialog event for opening dialogs

This event replaces AskToOpenUrl and is more generic, because
it may open any dialog (specified as an argument).
This commit is contained in:
Kamil Jarosz 2024-08-29 22:09:56 +02:00
parent b4422bffc4
commit 5cdf4c8030
6 changed files with 21 additions and 11 deletions

View File

@ -500,8 +500,8 @@ impl App {
.create_movie(&mut self.player, *options, url);
}
winit::event::Event::UserEvent(RuffleEvent::AskToOpenUrl(url)) => {
self.gui.borrow_mut().show_open_url_dialog(url);
winit::event::Event::UserEvent(RuffleEvent::OpenDialog(descriptor)) => {
self.gui.borrow_mut().open_dialog(descriptor);
}
winit::event::Event::UserEvent(RuffleEvent::CloseFile) => {

View File

@ -9,6 +9,7 @@ use url::Url;
use winit::event_loop::EventLoopProxy;
use crate::custom_event::RuffleEvent;
use crate::gui::DialogDescriptor;
use crate::util::open_url;
#[derive(Clone)]
@ -36,7 +37,7 @@ impl NavigatorInterface for DesktopNavigatorInterface {
.event_loop
.lock()
.expect("Non-poisoned event loop")
.send_event(RuffleEvent::AskToOpenUrl(url));
.send_event(RuffleEvent::OpenDialog(DialogDescriptor::OpenUrl(url)));
}
fn open_file(&self, path: &Path) -> io::Result<File> {

View File

@ -1,6 +1,6 @@
//! Custom event type for desktop ruffle
use crate::player::LaunchOptions;
use crate::{gui::DialogDescriptor, player::LaunchOptions};
/// User-defined events.
pub enum RuffleEvent {
@ -31,6 +31,6 @@ pub enum RuffleEvent {
/// The user selected an item in the right-click context menu.
ContextMenuItemClicked(usize),
/// The movie wants to open a URL link.
AskToOpenUrl(url::Url),
/// The movie wants to open a dialog.
OpenDialog(DialogDescriptor),
}

View File

@ -8,6 +8,7 @@ mod theme;
mod widgets;
pub use controller::GuiController;
pub use dialogs::DialogDescriptor;
pub use movie::MovieView;
pub use picker::FilePicker;
use std::borrow::Cow;

View File

@ -23,7 +23,7 @@ use winit::event_loop::EventLoop;
use winit::keyboard::{Key, NamedKey};
use winit::window::{Theme, Window};
use super::FilePicker;
use super::{DialogDescriptor, FilePicker};
/// Integration layer connecting wgpu+winit to egui.
pub struct GuiController {
@ -397,8 +397,8 @@ impl GuiController {
self.gui.dialogs.open_file_advanced()
}
pub fn show_open_url_dialog(&mut self, url: Url) {
self.gui.dialogs.open_open_url(url);
pub fn open_dialog(&mut self, dialog_event: DialogDescriptor) {
self.gui.dialogs.open_dialog(dialog_event);
}
}

View File

@ -41,6 +41,10 @@ pub struct Dialogs {
preferences: GlobalPreferences,
}
pub enum DialogDescriptor {
OpenUrl(url::Url),
}
impl Dialogs {
pub fn new(
preferences: GlobalPreferences,
@ -121,8 +125,12 @@ impl Dialogs {
self.is_about_visible = true;
}
pub fn open_open_url(&mut self, url: Url) {
self.open_url_dialog = Some(OpenUrlDialog::new(url));
pub fn open_dialog(&mut self, event: DialogDescriptor) {
match event {
DialogDescriptor::OpenUrl(url) => {
self.open_url_dialog = Some(OpenUrlDialog::new(url));
}
}
}
pub fn show(