Add zed::ToggleFullScreen bound to ctrl-cmd-f

This commit is contained in:
Antonio Scandurra 2022-08-15 11:53:37 +02:00
parent 61684e693f
commit b94366ab90
6 changed files with 31 additions and 0 deletions

View file

@ -28,6 +28,7 @@
"cmd-h": "zed::Hide", "cmd-h": "zed::Hide",
"alt-cmd-h": "zed::HideOthers", "alt-cmd-h": "zed::HideOthers",
"cmd-m": "zed::Minimize", "cmd-m": "zed::Minimize",
"ctrl-cmd-f": "zed::ToggleFullScreen",
"cmd-n": "workspace::NewFile", "cmd-n": "workspace::NewFile",
"cmd-shift-n": "workspace::NewWindow", "cmd-shift-n": "workspace::NewWindow",
"cmd-o": "workspace::Open", "cmd-o": "workspace::Open",

View file

@ -1319,6 +1319,11 @@ impl MutableAppContext {
window.zoom(); window.zoom();
} }
pub fn toggle_window_full_screen(&self, window_id: usize) {
let (_, window) = &self.presenters_and_platform_windows[&window_id];
window.toggle_full_screen();
}
fn prompt( fn prompt(
&self, &self,
window_id: usize, window_id: usize,
@ -3683,6 +3688,10 @@ impl<'a, T: View> ViewContext<'a, T> {
self.app.zoom_window(self.window_id) self.app.zoom_window(self.window_id)
} }
pub fn toggle_full_screen(&self) {
self.app.toggle_window_full_screen(self.window_id)
}
pub fn prompt( pub fn prompt(
&self, &self,
level: PromptLevel, level: PromptLevel,

View file

@ -123,6 +123,7 @@ pub trait Window: WindowContext {
fn show_character_palette(&self); fn show_character_palette(&self);
fn minimize(&self); fn minimize(&self);
fn zoom(&self); fn zoom(&self);
fn toggle_full_screen(&self);
} }
pub trait WindowContext { pub trait WindowContext {

View file

@ -601,6 +601,18 @@ impl platform::Window for Window {
}) })
.detach(); .detach();
} }
fn toggle_full_screen(&self) {
let this = self.0.borrow();
let window = this.native_window;
this.executor
.spawn(async move {
unsafe {
window.toggleFullScreen_(nil);
}
})
.detach();
}
} }
impl platform::WindowContext for Window { impl platform::WindowContext for Window {

View file

@ -294,6 +294,8 @@ impl super::Window for Window {
fn minimize(&self) {} fn minimize(&self) {}
fn zoom(&self) {} fn zoom(&self) {}
fn toggle_full_screen(&self) {}
} }
pub fn platform() -> Platform { pub fn platform() -> Platform {

View file

@ -51,6 +51,7 @@ actions!(
ShowAll, ShowAll,
Minimize, Minimize,
Zoom, Zoom,
ToggleFullScreen,
Quit, Quit,
DebugElements, DebugElements,
OpenSettings, OpenSettings,
@ -88,6 +89,11 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
cx.zoom_window(); cx.zoom_window();
}, },
); );
cx.add_action(
|_: &mut Workspace, _: &ToggleFullScreen, cx: &mut ViewContext<Workspace>| {
cx.toggle_full_screen();
},
);
cx.add_global_action(quit); cx.add_global_action(quit);
cx.add_global_action(move |action: &OpenBrowser, cx| cx.platform().open_url(&action.url)); cx.add_global_action(move |action: &OpenBrowser, cx| cx.platform().open_url(&action.url));
cx.add_global_action(move |_: &IncreaseBufferFontSize, cx| { cx.add_global_action(move |_: &IncreaseBufferFontSize, cx| {