Test prompting when saving while there's a conflict

This commit is contained in:
Antonio Scandurra
2021-05-12 15:21:50 +02:00
parent ac2168f1bd
commit 048bbc9da0
5 changed files with 86 additions and 2 deletions
+5
View File
@@ -27,6 +27,7 @@ use objc::{
use pathfinder_geometry::vector::vec2f;
use smol::Timer;
use std::{
any::Any,
cell::{Cell, RefCell},
convert::TryInto,
ffi::c_void,
@@ -263,6 +264,10 @@ impl Drop for Window {
}
impl platform::Window for Window {
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn on_event(&mut self, callback: Box<dyn FnMut(Event)>) {
self.0.as_ref().borrow_mut().event_callback = Some(callback);
}
+1
View File
@@ -68,6 +68,7 @@ pub trait Dispatcher: Send + Sync {
}
pub trait Window: WindowContext {
fn as_any_mut(&mut self) -> &mut dyn Any;
fn on_event(&mut self, callback: Box<dyn FnMut(Event)>);
fn on_resize(&mut self, callback: Box<dyn FnMut(&mut dyn WindowContext)>);
fn on_close(&mut self, callback: Box<dyn FnOnce()>);
+9 -1
View File
@@ -24,6 +24,7 @@ pub struct Window {
event_handlers: Vec<Box<dyn FnMut(super::Event)>>,
resize_handlers: Vec<Box<dyn FnMut(&mut dyn super::WindowContext)>>,
close_handlers: Vec<Box<dyn FnOnce()>>,
pub(crate) last_prompt: RefCell<Option<Box<dyn FnOnce(usize)>>>,
}
impl Platform {
@@ -123,6 +124,7 @@ impl Window {
close_handlers: Vec::new(),
scale_factor: 1.0,
current_scene: None,
last_prompt: RefCell::new(None),
}
}
}
@@ -152,6 +154,10 @@ impl super::WindowContext for Window {
}
impl super::Window for Window {
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn on_event(&mut self, callback: Box<dyn FnMut(crate::Event)>) {
self.event_handlers.push(callback);
}
@@ -164,7 +170,9 @@ impl super::Window for Window {
self.close_handlers.push(callback);
}
fn prompt(&self, _: crate::PromptLevel, _: &str, _: &[&str], _: Box<dyn FnOnce(usize)>) {}
fn prompt(&self, _: crate::PromptLevel, _: &str, _: &[&str], f: Box<dyn FnOnce(usize)>) {
self.last_prompt.replace(Some(f));
}
}
pub(crate) fn platform() -> Platform {