Open a new window when activating Zed from the dock w/ no windows open
This commit is contained in:
parent
7601e7902a
commit
b5f762ab25
5 changed files with 49 additions and 17 deletions
|
@ -82,6 +82,10 @@ unsafe fn build_classes() {
|
|||
sel!(applicationDidFinishLaunching:),
|
||||
did_finish_launching as extern "C" fn(&mut Object, Sel, id),
|
||||
);
|
||||
decl.add_method(
|
||||
sel!(applicationShouldHandleReopen:hasVisibleWindows:),
|
||||
should_handle_reopen as extern "C" fn(&mut Object, Sel, id, bool),
|
||||
);
|
||||
decl.add_method(
|
||||
sel!(applicationDidBecomeActive:),
|
||||
did_become_active as extern "C" fn(&mut Object, Sel, id),
|
||||
|
@ -144,6 +148,7 @@ pub struct MacForegroundPlatform(RefCell<MacForegroundPlatformState>);
|
|||
pub struct MacForegroundPlatformState {
|
||||
become_active: Option<Box<dyn FnMut()>>,
|
||||
resign_active: Option<Box<dyn FnMut()>>,
|
||||
reopen: Option<Box<dyn FnMut()>>,
|
||||
quit: Option<Box<dyn FnMut()>>,
|
||||
event: Option<Box<dyn FnMut(crate::Event) -> bool>>,
|
||||
menu_command: Option<Box<dyn FnMut(&dyn Action)>>,
|
||||
|
@ -158,15 +163,16 @@ pub struct MacForegroundPlatformState {
|
|||
impl MacForegroundPlatform {
|
||||
pub fn new(foreground: Rc<executor::Foreground>) -> Self {
|
||||
Self(RefCell::new(MacForegroundPlatformState {
|
||||
become_active: Default::default(),
|
||||
resign_active: Default::default(),
|
||||
quit: Default::default(),
|
||||
event: Default::default(),
|
||||
menu_command: Default::default(),
|
||||
validate_menu_command: Default::default(),
|
||||
will_open_menu: Default::default(),
|
||||
open_urls: Default::default(),
|
||||
finish_launching: Default::default(),
|
||||
become_active: None,
|
||||
resign_active: None,
|
||||
reopen: None,
|
||||
quit: None,
|
||||
event: None,
|
||||
menu_command: None,
|
||||
validate_menu_command: None,
|
||||
will_open_menu: None,
|
||||
open_urls: None,
|
||||
finish_launching: None,
|
||||
menu_actions: Default::default(),
|
||||
foreground,
|
||||
}))
|
||||
|
@ -332,6 +338,10 @@ impl platform::ForegroundPlatform for MacForegroundPlatform {
|
|||
self.0.borrow_mut().quit = Some(callback);
|
||||
}
|
||||
|
||||
fn on_reopen(&self, callback: Box<dyn FnMut()>) {
|
||||
self.0.borrow_mut().reopen = Some(callback);
|
||||
}
|
||||
|
||||
fn on_event(&self, callback: Box<dyn FnMut(crate::Event) -> bool>) {
|
||||
self.0.borrow_mut().event = Some(callback);
|
||||
}
|
||||
|
@ -943,6 +953,15 @@ extern "C" fn did_finish_launching(this: &mut Object, _: Sel, _: id) {
|
|||
}
|
||||
}
|
||||
|
||||
extern "C" fn should_handle_reopen(this: &mut Object, _: Sel, _: id, has_open_windows: bool) {
|
||||
if !has_open_windows {
|
||||
let platform = unsafe { get_foreground_platform(this) };
|
||||
if let Some(callback) = platform.0.borrow_mut().reopen.as_mut() {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn did_become_active(this: &mut Object, _: Sel, _: id) {
|
||||
let platform = unsafe { get_foreground_platform(this) };
|
||||
if let Some(callback) = platform.0.borrow_mut().become_active.as_mut() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue