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:
parent
b4422bffc4
commit
5cdf4c8030
|
@ -500,8 +500,8 @@ impl App {
|
||||||
.create_movie(&mut self.player, *options, url);
|
.create_movie(&mut self.player, *options, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
winit::event::Event::UserEvent(RuffleEvent::AskToOpenUrl(url)) => {
|
winit::event::Event::UserEvent(RuffleEvent::OpenDialog(descriptor)) => {
|
||||||
self.gui.borrow_mut().show_open_url_dialog(url);
|
self.gui.borrow_mut().open_dialog(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
winit::event::Event::UserEvent(RuffleEvent::CloseFile) => {
|
winit::event::Event::UserEvent(RuffleEvent::CloseFile) => {
|
||||||
|
|
|
@ -9,6 +9,7 @@ use url::Url;
|
||||||
use winit::event_loop::EventLoopProxy;
|
use winit::event_loop::EventLoopProxy;
|
||||||
|
|
||||||
use crate::custom_event::RuffleEvent;
|
use crate::custom_event::RuffleEvent;
|
||||||
|
use crate::gui::DialogDescriptor;
|
||||||
use crate::util::open_url;
|
use crate::util::open_url;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -36,7 +37,7 @@ impl NavigatorInterface for DesktopNavigatorInterface {
|
||||||
.event_loop
|
.event_loop
|
||||||
.lock()
|
.lock()
|
||||||
.expect("Non-poisoned event loop")
|
.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> {
|
fn open_file(&self, path: &Path) -> io::Result<File> {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Custom event type for desktop ruffle
|
//! Custom event type for desktop ruffle
|
||||||
|
|
||||||
use crate::player::LaunchOptions;
|
use crate::{gui::DialogDescriptor, player::LaunchOptions};
|
||||||
|
|
||||||
/// User-defined events.
|
/// User-defined events.
|
||||||
pub enum RuffleEvent {
|
pub enum RuffleEvent {
|
||||||
|
@ -31,6 +31,6 @@ pub enum RuffleEvent {
|
||||||
/// The user selected an item in the right-click context menu.
|
/// The user selected an item in the right-click context menu.
|
||||||
ContextMenuItemClicked(usize),
|
ContextMenuItemClicked(usize),
|
||||||
|
|
||||||
/// The movie wants to open a URL link.
|
/// The movie wants to open a dialog.
|
||||||
AskToOpenUrl(url::Url),
|
OpenDialog(DialogDescriptor),
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ mod theme;
|
||||||
mod widgets;
|
mod widgets;
|
||||||
|
|
||||||
pub use controller::GuiController;
|
pub use controller::GuiController;
|
||||||
|
pub use dialogs::DialogDescriptor;
|
||||||
pub use movie::MovieView;
|
pub use movie::MovieView;
|
||||||
pub use picker::FilePicker;
|
pub use picker::FilePicker;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
|
@ -23,7 +23,7 @@ use winit::event_loop::EventLoop;
|
||||||
use winit::keyboard::{Key, NamedKey};
|
use winit::keyboard::{Key, NamedKey};
|
||||||
use winit::window::{Theme, Window};
|
use winit::window::{Theme, Window};
|
||||||
|
|
||||||
use super::FilePicker;
|
use super::{DialogDescriptor, FilePicker};
|
||||||
|
|
||||||
/// Integration layer connecting wgpu+winit to egui.
|
/// Integration layer connecting wgpu+winit to egui.
|
||||||
pub struct GuiController {
|
pub struct GuiController {
|
||||||
|
@ -397,8 +397,8 @@ impl GuiController {
|
||||||
self.gui.dialogs.open_file_advanced()
|
self.gui.dialogs.open_file_advanced()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show_open_url_dialog(&mut self, url: Url) {
|
pub fn open_dialog(&mut self, dialog_event: DialogDescriptor) {
|
||||||
self.gui.dialogs.open_open_url(url);
|
self.gui.dialogs.open_dialog(dialog_event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,10 @@ pub struct Dialogs {
|
||||||
preferences: GlobalPreferences,
|
preferences: GlobalPreferences,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum DialogDescriptor {
|
||||||
|
OpenUrl(url::Url),
|
||||||
|
}
|
||||||
|
|
||||||
impl Dialogs {
|
impl Dialogs {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
preferences: GlobalPreferences,
|
preferences: GlobalPreferences,
|
||||||
|
@ -121,9 +125,13 @@ impl Dialogs {
|
||||||
self.is_about_visible = true;
|
self.is_about_visible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_open_url(&mut self, url: Url) {
|
pub fn open_dialog(&mut self, event: DialogDescriptor) {
|
||||||
|
match event {
|
||||||
|
DialogDescriptor::OpenUrl(url) => {
|
||||||
self.open_url_dialog = Some(OpenUrlDialog::new(url));
|
self.open_url_dialog = Some(OpenUrlDialog::new(url));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn show(
|
pub fn show(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
Loading…
Reference in New Issue