diff --git a/docs/changelog.md b/docs/changelog.md index cbbf89355..2ed111fc3 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -32,6 +32,7 @@ brief notes about them may accumulate here. * Windows: the portable .zip file download now includes ANGLE EGL, just like the setup.exe installer has done since version 20201031-154415-9614e117 * Windows: Fixed [ToggleFullScreen](config/lua/keyassignment/ToggleFullScreen.md) so that it once again toggles between full screen and normal placement. [#177](https://github.com/wez/wezterm/issues/177) * New: [exit_behavior](config/lua/config/exit_behavior.md) config option to keep panes open after the program has completed. [#499](https://github.com/wez/wezterm/issues/499) +* Closing the configuration error window no longer requires confirmation ### 20210203-095643-70a364eb diff --git a/mux/src/pane.rs b/mux/src/pane.rs index bd37e5389..86eacb92a 100644 --- a/mux/src/pane.rs +++ b/mux/src/pane.rs @@ -123,6 +123,11 @@ pub trait Pane: Downcast { /// Called to advise on whether this tab has focus fn focus_changed(&self, _focused: bool) {} + /// Certain panes are OK to be closed with impunity (no prompts) + fn can_close_without_prompting(&self) -> bool { + false + } + /// Performs a search. /// If the result is empty then there are no matches. /// Otherwise, the result shall contain all possible matches. diff --git a/mux/src/tab.rs b/mux/src/tab.rs index e6b3606bd..ca1d7fec3 100644 --- a/mux/src/tab.rs +++ b/mux/src/tab.rs @@ -1200,6 +1200,16 @@ impl Tab { } } + pub fn can_close_without_prompting(&self) -> bool { + let panes = self.iter_panes(); + for pos in &panes { + if !pos.pane.can_close_without_prompting() { + return false; + } + } + true + } + pub fn is_dead(&self) -> bool { let panes = self.iter_panes(); let mut dead_count = 0; diff --git a/mux/src/termwiztermtab.rs b/mux/src/termwiztermtab.rs index cd21e835f..7b298d6fe 100644 --- a/mux/src/termwiztermtab.rs +++ b/mux/src/termwiztermtab.rs @@ -156,6 +156,10 @@ impl Pane for TermWizTerminalPane { self.terminal.borrow_mut().get_title().to_string() } + fn can_close_without_prompting(&self) -> bool { + true + } + fn send_paste(&self, text: &str) -> anyhow::Result<()> { let paste = InputEvent::Paste(text.to_string()); self.input_tx.send(paste)?; diff --git a/mux/src/window.rs b/mux/src/window.rs index aa7f81662..2057193aa 100644 --- a/mux/src/window.rs +++ b/mux/src/window.rs @@ -73,6 +73,15 @@ impl Window { self.tabs.get(idx) } + pub fn can_close_without_prompting(&self) -> bool { + for tab in &self.tabs { + if !tab.can_close_without_prompting() { + return false; + } + } + true + } + pub fn idx_by_id(&self, id: TabId) -> Option { for (idx, t) in self.tabs.iter().enumerate() { if t.tab_id() == id { diff --git a/wezterm-gui/src/gui/overlay/confirm_close_pane.rs b/wezterm-gui/src/gui/overlay/confirm_close_pane.rs index cf573bce5..2ca08ae7a 100644 --- a/wezterm-gui/src/gui/overlay/confirm_close_pane.rs +++ b/wezterm-gui/src/gui/overlay/confirm_close_pane.rs @@ -199,7 +199,7 @@ pub fn confirm_close_tab( }) .detach(); } - TermWindow::schedule_cancel_overlay(window, tab_id); + TermWindow::schedule_cancel_overlay(window, tab_id, None); Ok(()) } @@ -220,7 +220,7 @@ pub fn confirm_close_window( }) .detach(); } - TermWindow::schedule_cancel_overlay(window, tab_id); + TermWindow::schedule_cancel_overlay(window, tab_id, None); Ok(()) } @@ -238,7 +238,7 @@ pub fn confirm_quit_program( }) .detach(); } - TermWindow::schedule_cancel_overlay(window, tab_id); + TermWindow::schedule_cancel_overlay(window, tab_id, None); Ok(()) } diff --git a/wezterm-gui/src/gui/overlay/mod.rs b/wezterm-gui/src/gui/overlay/mod.rs index a45ad0576..03eeca41b 100644 --- a/wezterm-gui/src/gui/overlay/mod.rs +++ b/wezterm-gui/src/gui/overlay/mod.rs @@ -39,9 +39,11 @@ where let window = term_window.window.clone().unwrap(); + let overlay_pane_id = tw_tab.pane_id(); + let future = promise::spawn::spawn_into_new_thread(move || { let res = func(tab_id, tw_term); - TermWindow::schedule_cancel_overlay(window, tab_id); + TermWindow::schedule_cancel_overlay(window, tab_id, Some(overlay_pane_id)); res }); diff --git a/wezterm-gui/src/gui/termwindow.rs b/wezterm-gui/src/gui/termwindow.rs index 9630a20bf..b0fd96118 100644 --- a/wezterm-gui/src/gui/termwindow.rs +++ b/wezterm-gui/src/gui/termwindow.rs @@ -302,6 +302,14 @@ impl WindowCallbacks for TermWindow { }; let mux_window_id = self.mux_window_id; + + let can_close = mux + .get_window(mux_window_id) + .map_or(false, |w| w.can_close_without_prompting()); + if can_close { + mux.kill_window(self.mux_window_id); + return true; + } let window = self.window.clone().unwrap(); let (overlay, future) = start_overlay(self, &tab, move |tab_id, term| { confirm_close_window(term, mux_window_id, window, tab_id) @@ -2455,7 +2463,7 @@ impl TermWindow { }; let pane_id = pane.pane_id(); - if confirm { + if confirm && !pane.can_close_without_prompting() { let window = self.window.clone().unwrap(); let (overlay, future) = start_overlay_pane(self, &pane, move |pane_id, term| { confirm_close_pane(pane_id, term, mux_window_id, window) @@ -2475,7 +2483,7 @@ impl TermWindow { }; let tab_id = tab.tab_id(); let mux_window_id = self.mux_window_id; - if confirm { + if confirm && !tab.can_close_without_prompting() { let window = self.window.clone().unwrap(); let (overlay, future) = start_overlay(self, &tab, move |tab_id, term| { confirm_close_tab(tab_id, term, mux_window_id, window) @@ -4055,8 +4063,15 @@ impl TermWindow { } } - /// Removes any overlay for the specified tab - fn cancel_overlay_for_tab(&self, tab_id: TabId) { + /// if pane_id.is_none(), removes any overlay for the specified tab. + /// Otherwise: if the overlay is the specified pane for that tab, remove it. + fn cancel_overlay_for_tab(&self, tab_id: TabId, pane_id: Option) { + if pane_id.is_some() { + let current = self.tab_state(tab_id).overlay.as_ref().map(|o| o.pane_id()); + if current != pane_id { + return; + } + } if let Some(pane) = self.tab_state(tab_id).overlay.take() { Mux::get().unwrap().remove_pane(pane.pane_id()); } @@ -4065,10 +4080,10 @@ impl TermWindow { } } - pub fn schedule_cancel_overlay(window: Window, tab_id: TabId) { + pub fn schedule_cancel_overlay(window: Window, tab_id: TabId, pane_id: Option) { window.apply(move |myself, _| { if let Some(myself) = myself.downcast_mut::() { - myself.cancel_overlay_for_tab(tab_id); + myself.cancel_overlay_for_tab(tab_id, pane_id); } Ok(()) });