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
17 changes: 1 addition & 16 deletions crates/okena-app/src/keybindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,22 +501,7 @@ fn create_keybinding(action: &str, keystroke: &str, context: Option<&str>) -> Op
}
}

/// Format a keystroke for display (convert to human-readable format)
pub fn format_keystroke(keystroke: &str) -> String {
keystroke
.replace("cmd", "⌘")
.replace("ctrl", "Ctrl")
.replace("alt", "Alt")
.replace("shift", "⇧")
.replace("-", "+")
.replace("pageup", "PgUp")
.replace("pagedown", "PgDn")
.replace("escape", "Esc")
.replace("left", "←")
.replace("right", "→")
.replace("up", "↑")
.replace("down", "↓")
}
pub use okena_ui::shortcuts::format_keystroke;

/// The active shortcut for an action, formatted for the current platform.
pub fn shortcut_for_action(action: &str) -> Option<String> {
Expand Down
54 changes: 52 additions & 2 deletions crates/okena-app/src/views/panels/project_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,27 @@ impl ProjectColumn {
.size(px(14.0))
.text_color(rgb(t.text_secondary)),
)
.tooltip(move |_window, cx| Tooltip::new(vis_tooltip).build(_window, cx)),
.tooltip({
let focus_manager = self.focus_manager.clone();
let project_id = self.project_id.clone();
move |window, cx| {
let fm = focus_manager.read(cx);
let matches = fm
.focused_terminal_state()
.map(|state| state.project_id)
.or_else(|| fm.focused_project_id().cloned())
.as_ref()
== Some(&project_id);
okena_ui::shortcuts::action_tooltip(
vis_tooltip,
matches.then_some(
&crate::keybindings::ToggleProjectVisibility as &dyn Action,
),
window,
cx,
)
}
}),
)
.child(
div()
Expand Down Expand Up @@ -927,7 +947,37 @@ impl ProjectColumn {
.size(px(14.0))
.text_color(rgb(t.text_secondary)),
)
.tooltip(move |_window, cx| Tooltip::new(focus_tooltip).build(_window, cx)),
.tooltip({
let focus_manager = self.focus_manager.clone();
let workspace = self.workspace.clone();
let project_id = self.project_id.clone();
let window_id = self.window_id;
move |window, cx| {
let fm = focus_manager.read(cx);
// The keyboard exit also clears the folder filter;
// the button does not. Show it only for an equal result.
let matches = if is_focused_view {
fm.focused_project_id() == Some(&project_id)
&& workspace
.read(cx)
.active_folder_filter(window_id)
.is_none()
} else {
fm.focused_project_id().is_none()
&& fm
.focused_terminal_state()
.is_some_and(|state| state.project_id == project_id)
};
okena_ui::shortcuts::action_tooltip(
focus_tooltip,
matches.then_some(
&crate::keybindings::FocusActiveProject as &dyn Action,
),
window,
cx,
)
}
}),
)
.into_any_element()
});
Expand Down
47 changes: 39 additions & 8 deletions crates/okena-files/src/file_viewer/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,43 @@ fn loading_row(depth: usize, t: &ThemeColors, cx: &App) -> Div {
}

impl FileViewer {
/// Cancel first dismisses transient UI or clears selection. Only advertise it
/// for navigation when it reaches the same Back/Close event as the button.
fn cancel_navigates(&self, window: &Window) -> bool {
let tab = self.active_tab();
self.focus_handle.is_focused(window)
&& self.selection_context_menu.is_none()
&& self.tab_context_menu.is_none()
&& self.context_menu.is_none()
&& self.rename_state.is_none()
&& self.delete_confirm.is_none()
&& self.search_state.is_none()
&& (tab.display_mode != DisplayMode::Preview
|| tab.markdown_selection.normalized_non_empty().is_none())
&& tab.selection.normalized_non_empty().is_none()
}

fn navigation_tooltip(
&self,
label: &'static str,
back: bool,
cx: &Context<Self>,
) -> impl Fn(&mut Window, &mut App) -> AnyView + use<> {
let viewer = cx.entity().downgrade();
move |window, cx| {
let matches = viewer.upgrade().is_some_and(|viewer| {
let viewer = viewer.read(cx);
viewer.can_go_back == back && viewer.cancel_navigates(window)
});
okena_ui::shortcuts::action_tooltip(
label,
matches.then_some(&Cancel as &dyn Action),
window,
cx,
)
}
}

fn render_selectable_markdown_unit(
&self,
id: ElementId,
Expand Down Expand Up @@ -1674,10 +1711,7 @@ impl Render for FileViewer {
.bg(rgb(t.bg_hover))
.text_color(rgb(t.text_primary))
})
.tooltip(|window, cx| {
gpui_component::tooltip::Tooltip::new("Back")
.build(window, cx)
})
.tooltip(self.navigation_tooltip("Back", true, cx))
.on_click(cx.listener(|_this, _, _window, cx| {
cx.emit(super::FileViewerEvent::Back);
}))
Expand Down Expand Up @@ -2068,10 +2102,7 @@ impl Render for FileViewer {
.justify_center()
.rounded(px(6.0))
.hover(|s| s.bg(rgb(t.bg_hover)))
.tooltip(|window, cx| {
gpui_component::tooltip::Tooltip::new("Close")
.build(window, cx)
})
.tooltip(self.navigation_tooltip("Close", false, cx))
.on_click(cx.listener(|this, _, _window, cx| this.close(cx)))
.child(
svg()
Expand Down
12 changes: 4 additions & 8 deletions crates/okena-ui/src/header_buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use crate::theme::ThemeColors;
use gpui::*;
use gpui_component::tooltip::Tooltip;

/// All available header actions for terminal panes.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -104,7 +103,7 @@ pub fn header_button_base(
size: ButtonSize,
t: &ThemeColors,
tooltip_override: Option<&'static str>,
gpui_action: Option<Box<dyn Action>>,
gpui_action: Option<crate::shortcuts::ActionShortcut>,
) -> Stateful<Div> {
let tooltip_text = tooltip_override.unwrap_or_else(|| action.tooltip());
let bg_hover = t.bg_hover;
Expand All @@ -127,12 +126,9 @@ pub fn header_button_base(
.size(px(size.icon))
.text_color(rgb(t.text_secondary)),
)
.tooltip(move |_window, cx| {
let mut tooltip = Tooltip::new(tooltip_text);
if let Some(ref action) = gpui_action {
tooltip = tooltip.action(action.as_ref(), None);
}
tooltip.build(_window, cx)
.tooltip(move |window, cx| match &gpui_action {
Some(shortcut) => shortcut.tooltip(tooltip_text, window, cx),
None => crate::shortcuts::action_tooltip(tooltip_text, None, window, cx),
});

// Apply hover style - red for close, normal for others
Expand Down
1 change: 1 addition & 0 deletions crates/okena-ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub mod resize_handle;
pub mod scrollbar;
pub mod selectable_list;
pub mod settings;
pub mod shortcuts;
pub mod simple_input;
pub mod submenu;
pub mod text_utils;
Expand Down
Loading
Loading