Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions termua/src/window/new_session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl NewSessionWindow {
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
Self::set_window_title_for_mode(mode, window);
window.set_window_title(&Self::window_title(mode, protocol));
Self::ensure_globals(cx);

let lock_overlay = crate::lock_screen::overlay::LockOverlayState::new(window, cx);
Expand Down Expand Up @@ -384,13 +384,17 @@ impl NewSessionWindow {
this
}

fn set_window_title_for_mode(mode: SessionEditorMode, window: &mut Window) {
let title = if mode.is_edit() {
t!("NewSession.WindowTitle.Edit")
fn window_title(mode: SessionEditorMode, protocol: Protocol) -> String {
if mode.is_edit() {
let protocol = match protocol {
Protocol::Shell => t!("NewSession.Tabs.Shell"),
Protocol::Ssh => t!("NewSession.Tabs.Ssh"),
Protocol::Serial => t!("NewSession.Tabs.Serial"),
};
format!("{} ({protocol})", t!("NewSession.WindowTitle.Edit"))
} else {
t!("NewSession.WindowTitle.New")
};
window.set_window_title(title.as_ref());
t!("NewSession.WindowTitle.New").to_string()
}
}

fn ensure_globals(cx: &mut Context<Self>) {
Expand Down Expand Up @@ -713,12 +717,7 @@ impl Focusable for NewSessionWindow {

impl NewSessionWindow {
fn sync_localized_strings(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let title = if self.mode.is_edit() {
t!("NewSession.WindowTitle.Edit")
} else {
t!("NewSession.WindowTitle.New")
};
window.set_window_title(title.as_ref());
window.set_window_title(&Self::window_title(self.mode, self.protocol));

self.lock_overlay.sync_localized_placeholders(window, cx);

Expand Down
68 changes: 4 additions & 64 deletions termua/src/window/new_session/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,7 @@ fn render_env_editor(
impl Render for NewSessionWindow {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let is_edit = self.mode.is_edit();
let title = if is_edit {
t!("NewSession.WindowTitle.Edit").to_string()
} else {
t!("NewSession.WindowTitle.New").to_string()
};
let title = Self::window_title(self.mode, self.protocol);

// Apply async serial port refresh results while we have access to `Window`.
if let Some(ports) = self.serial.ports_pending.take() {
Expand Down Expand Up @@ -237,7 +233,9 @@ impl Render for NewSessionWindow {
.flex_1()
.min_h_0()
.relative()
.child(self.render_protocol_tabs(window, cx))
.when(!is_edit, |this| {
this.child(self.render_protocol_tabs(window, cx))
})
.child(
h_flex()
.id("termua-new-session-main")
Expand All @@ -262,8 +260,6 @@ impl NewSessionWindow {
label: String,
protocol: Protocol,
selected_ix: usize,
is_edit: bool,
cursor: Option<gpui::CursorStyle>,
selected_tab_tint: gpui::Hsla,
tab_divider_color: gpui::Hsla,
show_divider: bool,
Expand All @@ -272,17 +268,10 @@ impl NewSessionWindow {
.relative()
.flex_1()
.debug_selector(move || format!("termua-new-session-tab-{}", protocol.debug_id()))
.when_some(cursor, |this, cursor| {
this.map(|mut this| {
this.style().mouse_cursor = Some(cursor);
this
})
})
.child(
Tab::new()
.label(label)
.selected(selected_ix == protocol.tab_index())
.disabled(cursor.is_some())
.w_full()
.justify_center(),
)
Expand All @@ -296,19 +285,9 @@ impl NewSessionWindow {
.when(selected_ix == protocol.tab_index(), |this| {
this.bg(selected_tab_tint)
})
.when_some(cursor, |this, cursor| {
this.map(|mut this| {
this.style().mouse_cursor = Some(cursor);
this
})
})
// `gpui-component::Tab` stops mouse-down propagation, so the click target
// needs to live above the visual tab instead of on a parent container.
.on_mouse_down(MouseButton::Left, move |_, window, app| {
if is_edit {
window.refresh();
return;
}
this.update(app, |this, cx| this.set_protocol(protocol, cx));
window.refresh();
}),
Expand All @@ -334,26 +313,9 @@ impl NewSessionWindow {
) -> impl IntoElement {
let this = cx.entity();
let selected_ix = self.protocol.tab_index();
let is_edit = self.mode.is_edit();
let selected_tab_tint = cx.theme().tab_active.darken(0.08).opacity(0.32);
let tab_divider_color = cx.theme().border.opacity(0.7);

let shell_cursor = Self::disabled_protocol_tab_cursor_style(
is_edit,
selected_ix,
Protocol::Shell.tab_index(),
);
let ssh_cursor = Self::disabled_protocol_tab_cursor_style(
is_edit,
selected_ix,
Protocol::Ssh.tab_index(),
);
let serial_cursor = Self::disabled_protocol_tab_cursor_style(
is_edit,
selected_ix,
Protocol::Serial.tab_index(),
);

div()
.w_full()
.debug_selector(|| "termua-new-session-protocol-tabbar".to_string())
Expand All @@ -369,8 +331,6 @@ impl NewSessionWindow {
t!("NewSession.Tabs.Shell").to_string(),
Protocol::Shell,
selected_ix,
is_edit,
shell_cursor,
selected_tab_tint,
tab_divider_color,
true,
Expand All @@ -380,8 +340,6 @@ impl NewSessionWindow {
t!("NewSession.Tabs.Ssh").to_string(),
Protocol::Ssh,
selected_ix,
is_edit,
ssh_cursor,
selected_tab_tint,
tab_divider_color,
true,
Expand All @@ -391,8 +349,6 @@ impl NewSessionWindow {
t!("NewSession.Tabs.Serial").to_string(),
Protocol::Serial,
selected_ix,
is_edit,
serial_cursor,
selected_tab_tint,
tab_divider_color,
false,
Expand All @@ -401,22 +357,6 @@ impl NewSessionWindow {
)
}

pub(super) fn disabled_protocol_tab_cursor_style(
is_edit: bool,
selected_ix: usize,
tab_ix: usize,
) -> Option<gpui::CursorStyle> {
if !is_edit {
return None;
}

if tab_ix == selected_ix {
return None;
}

Some(gpui::CursorStyle::OperationNotAllowed)
}

fn render_footer(
&self,
connect_enabled: bool,
Expand Down
47 changes: 22 additions & 25 deletions termua/src/window/new_session/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,28 @@ fn edit_session_does_not_render_connect_button(cx: &mut gpui::TestAppContext) {
win.debug_bounds("termua-edit-session-connect").is_none(),
"edit session should not render a Connect button"
);
assert_eq!(win.window_title().as_deref(), Some("Edit Session (SSH)"));
assert!(
win.debug_bounds("termua-new-session-protocol-tabbar")
.is_none(),
"edit session should identify its protocol in the title instead of rendering protocol tabs"
);
}

#[test]
fn edit_session_window_titles_include_protocol() {
assert_eq!(
NewSessionWindow::window_title(SessionEditorMode::Edit { session_id: 1 }, Protocol::Shell),
"Edit Session (Shell)"
);
assert_eq!(
NewSessionWindow::window_title(SessionEditorMode::Edit { session_id: 1 }, Protocol::Ssh),
"Edit Session (SSH)"
);
assert_eq!(
NewSessionWindow::window_title(SessionEditorMode::Edit { session_id: 1 }, Protocol::Serial),
"Edit Session (Serial)"
);
}

#[gpui::test]
Expand Down Expand Up @@ -1804,31 +1826,6 @@ fn local_terminal_env_includes_shell_term_and_locale() {
assert_eq!(env.get("LANG"), Some(&"C".to_string()));
}

#[test]
fn edit_mode_disabled_protocol_tab_uses_not_allowed_cursor() {
let selected_ix = Protocol::Ssh.tab_index();
assert_eq!(
NewSessionWindow::disabled_protocol_tab_cursor_style(
true,
selected_ix,
Protocol::Shell.tab_index()
),
Some(gpui::CursorStyle::OperationNotAllowed)
);
assert_eq!(
NewSessionWindow::disabled_protocol_tab_cursor_style(true, selected_ix, selected_ix),
None
);
assert_eq!(
NewSessionWindow::disabled_protocol_tab_cursor_style(
false,
selected_ix,
Protocol::Shell.tab_index()
),
None
);
}

#[gpui::test]
fn new_local_connect_persists_session_in_store(cx: &mut gpui::TestAppContext) {
use std::sync::{Arc, Mutex};
Expand Down
Loading