Close current browser tab

This commit is contained in:
2026-05-07 18:58:49 -04:00
parent e9ef92c41b
commit 510af7a9b2
3 changed files with 124 additions and 19 deletions
+20 -10
View File
@@ -6,21 +6,31 @@ use gpui::{
};
use shell::ElyShell;
actions!(ely_app, [Quit]);
actions!(ely_app, [CloseCurrentTab, Quit]);
fn main() {
Application::new().run(|cx: &mut App| {
gpui_component::init(cx);
cx.on_action(quit);
cx.bind_keys([KeyBinding::new("cmd-q", Quit, None)]);
cx.set_menus(vec![Menu {
name: "ELY Browser".into(),
items: vec![
MenuItem::os_submenu("Services", SystemMenuType::Services),
MenuItem::separator(),
MenuItem::action("Quit ELY Browser", Quit),
],
}]);
cx.bind_keys([
KeyBinding::new("cmd-w", CloseCurrentTab, None),
KeyBinding::new("ctrl-w", CloseCurrentTab, None),
KeyBinding::new("cmd-q", Quit, None),
]);
cx.set_menus(vec![
Menu {
name: "ELY Browser".into(),
items: vec![
MenuItem::os_submenu("Services", SystemMenuType::Services),
MenuItem::separator(),
MenuItem::action("Quit ELY Browser", Quit),
],
},
Menu {
name: "File".into(),
items: vec![MenuItem::action("Close Tab", CloseCurrentTab)],
},
]);
let bounds = Bounds::centered(None, size(px(1240.0), px(780.0)), cx);
let opened = cx.open_window(
+21
View File
@@ -11,6 +11,8 @@ use gpui_component::{
input::{Input, InputEvent, InputState},
};
use crate::CloseCurrentTab;
enum ShellState {
Ready(BrowserCore),
StartupError(String),
@@ -81,6 +83,24 @@ impl ElyShell {
}
}
fn close_active_tab(&mut self, window: &mut Window, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state
&& core.close_active_tab().is_ok()
{
self.sync_address_input(window, cx);
cx.notify();
}
}
fn on_close_current_tab(
&mut self,
_: &CloseCurrentTab,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.close_active_tab(window, cx);
}
fn sync_address_input(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let ShellState::Ready(core) = &mut self.state else {
return;
@@ -116,6 +136,7 @@ impl ElyShell {
) -> AnyElement {
div()
.size_full()
.on_action(cx.listener(Self::on_close_current_tab))
.bg(rgb(ELY_THEME.canvas))
.text_color(rgb(ELY_THEME.ink))
.flex()