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
8 changes: 8 additions & 0 deletions apps/desktop/src/dialogs/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,14 @@ impl SettingsHost for App {
}
}

fn open_navigation_layout_editor(&mut self, tx: &mut Tx) {
crate::shell::navigation::layout_editor::open(self, tx);
}

fn migrate_new_navigation(&mut self) {
crate::shell::navigation::migrate::run(self);
}

fn on_settings_changed(&mut self) {
crate::background_notice::sync_keep_running(self.settings.keep_service_running);
if !self.window.id.is_empty() {
Expand Down
9 changes: 6 additions & 3 deletions apps/desktop/src/shell/navigation/customize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ fn build_menu(s: &App, projects: &[NavProject], servers: &[NavServer]) -> Menu {
group_sub = group_sub.item(Item::new(format!("navc:group:{}", g.name()), g.label()).checked(nav.group_by == g));
}

let cur_detail = if nav.row_details == RowDetails::Compact { RowDetails::Compact } else { RowDetails::Detailed };
let mut detail_sub = Menu::new(t!("navigation.setting.rowDetails.title")).min_width(172.0);
for d in RowDetails::CHOICES {
detail_sub = detail_sub.item(Item::new(format!("navc:detail:{}", d.name()), d.label()).checked(cur_detail == d));
for d in RowDetails::ALL {
detail_sub = detail_sub.item(Item::new(format!("navc:detail:{}", d.name()), d.label()).checked(nav.row_details == d));
}

let mut filter_sub = Menu::new(t!("navigation.customize.filter")).min_width(180.0);
Expand Down Expand Up @@ -88,6 +87,10 @@ fn handle_pick(s: &mut App, picked: &str, tx: &mut Tx) {
}
if let Some(d) = rest.strip_prefix("detail:") {
let next = RowDetails::parse(Some(d));
if next == RowDetails::Custom {
super::layout_editor::open(s, tx);
return;
}
s.change_settings(|x| x.new_navigation.row_details = next);
return;
}
Expand Down
294 changes: 294 additions & 0 deletions apps/desktop/src/shell/navigation/layout_editor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
//! Row layout editor modal for New navigation's `Row details -> Custom`
//! (`packages/app/src/shell/navigation/layout-editor.tsx`, `opencode#67795`).

use opencode_feature_settings::new_navigation::RowDetails;
use opencode_feature_settings::row_layout::{FormItem, ItemForm, Lane, RowItem, RowLayout};
use opencode_i18n::t;
use opencode_ui::focus::FocusExt;
use opencode_kernel::AppOverlays as _;
use opencode_ui::palette::{Pal, kit};
use opencode_ui::popup::{self, Item, Menu, MenuButton as _};
use opencode_ui::widgets::{BODY, DialogSize, Fit, button, dialog_window, sized_modal};
use rune::{Align, Color, Cx, El, TextStyle, Tx, col, el, icon, row, spacer, text};
use rune_kit::ButtonVariant;
use rune_theme_opencode::icons as ic;

use crate::App;
use crate::view::{UI, UI_MED, UI_SMALL};

pub const OVERLAY_ID: &str = "dialog.navigation_layout";
const TITLE_FONT: TextStyle = TextStyle::new(15.0, 500.0).lh(20.0);
const LANE_HEAD: TextStyle = TextStyle::new(12.0, 500.0).lh(16.0);
const SUB_META: TextStyle = TextStyle::new(11.0, 440.0).lh(16.0);

pub fn open(s: &mut App, tx: &mut Tx) {
let initial = s.settings.new_navigation.row_layout.clone().unwrap_or_default();
super::state_mut(s).layout_editor = Some(initial);
s.on_overlay_opened(OVERLAY_ID, None);
tx.instant();
}

pub fn close(s: &mut App, tx: &mut Tx) {
super::state_mut(s).layout_editor = None;
s.on_overlay_closed(OVERLAY_ID);
tx.instant();
}

fn save(s: &mut App, tx: &mut Tx) {
let Some(layout) = super::state_mut(s).layout_editor.take() else { return };
let normalized = layout.normalize();
s.change_settings(|x| {
x.new_navigation.row_details = RowDetails::Custom;
x.new_navigation.row_layout = Some(normalized);
});
s.on_overlay_closed(OVERLAY_ID);
tx.instant();
}

fn sample_item_el(p: &Pal, item: RowItem, layout: &RowLayout, title: &str, branch: &str, server: Option<&str>, age: &str, subagents: usize) -> Option<El> {
match item {
RowItem::ProjectIcon => Some(el().size(14.0, 14.0).radius(3.0).fill(p.layer2)),
RowItem::Title => Some(text(title.to_owned()).font(UI_MED).color(p.text).grow(1.0).shrink().min_w(0.0).truncate()),
RowItem::Time => Some(text(age.to_owned()).font(SUB_META).color(p.faint)),
RowItem::ProjectName => Some(text("opencode".to_owned()).font(SUB_META).color(p.faint).truncate()),
RowItem::Branch => {
let mut r = row().gap(3.0).center_y().child(icon(&ic::BRANCH, 12.0).color(p.icon_muted));
if layout.form(FormItem::Branch) == ItemForm::Name {
r = r.child(text(branch.to_owned()).font(SUB_META).color(p.faint).truncate());
}
Some(r)
}
RowItem::Worktree => Some(text("opencode-sidebar".to_owned()).font(SUB_META).color(p.faint).truncate()),
RowItem::Server => {
let name = server?;
let mut r = row().gap(3.0).center_y().child(icon(&ic::SERVER, 12.0).color(p.icon_muted));
if layout.form(FormItem::Server) == ItemForm::Name {
r = r.child(text(name.to_owned()).font(SUB_META).color(p.faint).truncate());
}
Some(r)
}
RowItem::Subagents => (subagents > 0).then(|| text(format!("+{subagents}")).font(SUB_META).color(p.faint)),
}
}

fn preview_row(p: &Pal, layout: &RowLayout, key: &'static str, title: &str, branch: &str, server: Option<&str>, age: &str, subagents: usize, dot: Option<Color>) -> El {
let mut c = col().key(key).w_full().px(8.0).py(5.0).gap(2.0).radius(6.0);
for (idx, lane) in [&layout.line1, &layout.line2].into_iter().enumerate() {
if lane.is_empty() {
continue;
}
let mut line = row().w_full().gap(6.0).center_y();
if idx == 0
&& let Some(col) = dot
{
line = line.child(el().size(6.0, 6.0).radius(3.0).fill(col));
}
for &item in lane {
if let Some(node) = sample_item_el(p, item, layout, title, branch, server, age, subagents) {
line = line.child(node);
}
}
c = c.child(line);
}
c
}

fn build_item_menu(layout: &RowLayout, item: RowItem) -> Menu {
let lane = layout.lane_of(item);
let items = layout.lane(lane);
let pos = items.iter().position(|&x| x == item).unwrap_or(0);
let mut menu = Menu::new(t!("navigation.layout.itemOptions", item = item.label()))
.align(Align::Start)
.min_width(176.0)
.item(Item::new("nle:left", t!("navigation.layout.moveLeft")).enabled(pos > 0))
.item(Item::new("nle:right", t!("navigation.layout.moveRight")).enabled(pos + 1 < items.len()))
.separator();
for target in Lane::ALL {
if target == lane {
continue;
}
if item == RowItem::Title && target == Lane::Hidden {
continue;
}
let lbl = match target {
Lane::Line1 => t!("navigation.layout.moveTo.line1"),
Lane::Line2 => t!("navigation.layout.moveTo.line2"),
Lane::Hidden => t!("navigation.layout.moveTo.hidden"),
};
menu = menu.item(Item::new(format!("nle:to:{}", target.name()), lbl));
}
if let Some(fi) = item.form_item() {
let cur = layout.form(fi);
menu = menu
.separator()
.item(Item::new("nle:form:icon", t!("navigation.layout.form.icon")).checked(cur == ItemForm::Icon))
.item(Item::new("nle:form:name", t!("navigation.layout.form.name")).checked(cur == ItemForm::Name));
}
menu
}

fn apply_item_menu(s: &mut App, item: RowItem, picked: &str) {
let Some(cur) = super::state(s).layout_editor.clone() else { return };
let next = match picked {
"nle:left" => cur.nudge_item(item, -1),
"nle:right" => cur.nudge_item(item, 1),
"nle:to:line1" => cur.move_item(item, Lane::Line1, None),
"nle:to:line2" => cur.move_item(item, Lane::Line2, None),
"nle:to:hidden" => cur.move_item(item, Lane::Hidden, None),
"nle:form:icon" => item.form_item().map_or(cur.clone(), |fi| cur.set_form(fi, ItemForm::Icon)),
"nle:form:name" => item.form_item().map_or(cur.clone(), |fi| cur.set_form(fi, ItemForm::Name)),
_ => cur,
};
super::state_mut(s).layout_editor = Some(next);
}

fn lane_view(s: &App, p: &Pal, layout: &RowLayout, lane: Lane) -> El {
let items = layout.lane(lane);
let mut chips = row().w_full().gap(6.0).wrap().center_y();
if items.is_empty() {
let msg = if lane == Lane::Hidden {
t!("navigation.layout.emptyLane")
} else {
t!("navigation.layout.emptyLine")
};
chips = chips.child(text(msg).font(UI_SMALL).color(p.faint));
} else {
for &item in items {
let anchor = format!("nle-chip-{}", item.name());
let open = s.popup.open_at(&anchor);
let mut chip = row()
.key(anchor.clone())
.role("button")
.label(item.label())
.expanded(open)
.h(28.0)
.px(10.0)
.gap(6.0)
.center_y()
.radius(6.0)
.border(0.5, p.border_muted)
.fill(if open { p.pressed } else { p.layer1 })
.hover(if open { p.pressed } else { p.hover })
.press(p.pressed)
.focus_inset(p)
.menu_button(anchor.clone(), move |s: &mut App, tx: &mut Tx| {
let Some(cur) = super::state(s).layout_editor.clone() else { return };
let menu = build_item_menu(&cur, item);
popup::open(s, menu, anchor.clone(), tx, move |s: &mut App, picked, tx| {
if let Some(id) = picked {
tx.instant();
apply_item_menu(s, item, id);
}
});
})
.child(text(item.label()).font(UI_SMALL).color(p.text));
if item == RowItem::Title {
chip = chip.child(text(t!("navigation.layout.required")).font(SUB_META).color(p.faint));
}
chips = chips.child(chip);
}
}
col()
.key(format!("nle-lane-{}", lane.name()))
.w_full()
.gap(6.0)
.child(text(lane.label()).font(LANE_HEAD).color(p.muted))
.child(
el()
.w_full()
.min_h(44.0)
.padding(8.0)
.radius(8.0)
.border(0.5, p.border_muted)
.fill(p.bg_deep)
.child(chips),
)
}

pub fn view(s: &App, p: &Pal, cx: &Cx<App>) -> Vec<El> {
let Some(layout) = super::state(s).layout_editor.as_ref() else {
return Vec::new();
};
let is_default = *layout == RowLayout::default();

let preview = col()
.key("navigation-layout-preview")
.w_full()
.padding(12.0)
.gap(4.0)
.radius(8.0)
.border(0.5, p.border_muted)
.fill(p.bg_deep)
.child(preview_row(p, layout, "nle-sample-1", t!("navigation.status.working"), "dev", None, "now", 2, Some(p.accent)))
.child(preview_row(p, layout, "nle-sample-2", t!("navigation.status.approval"), "sidebar-tests", None, "2m", 0, Some(p.v1_icon_warning)))
.child(preview_row(p, layout, "nle-sample-3", t!("navigation.status.unread"), "dev", Some("devbox"), "14m", 0, Some(p.bg_accent)))
.child(preview_row(p, layout, "nle-sample-4", t!("navigation.status.failed"), "redirects", None, "3h", 0, Some(p.danger)));

let mut lanes = col().w_full().gap(12.0);
for lane in Lane::ALL {
lanes = lanes.child(lane_view(s, p, layout, lane));
}

let header = col()
.w_full()
.px(20.0)
.pt(16.0)
.pb(12.0)
.gap(4.0)
.child(text(t!("navigation.layout.title")).font(TITLE_FONT).color(p.text))
.child(text(t!("navigation.layout.description")).font(BODY).color(p.muted));

let content = opencode_ui::scroller::scroller("nle-scroll").hidden(
col().w_full().grow(1.0).shrink().min_h(0.0),
col().w_full().px(20.0).pb(16.0).gap(16.0).child(preview).child(lanes),
);

let reset_btn = row()
.key("nle-reset")
.role("button")
.label_static(t!("navigation.layout.reset"))
.h(28.0)
.px(10.0)
.radius(6.0)
.center()
.hover(if is_default { Color::TRANSPARENT } else { p.hover })
.focus_inset(p)
.on_press_tx(move |s: &mut App, tx: &mut Tx| {
if !is_default {
tx.instant();
super::state_mut(s).layout_editor = Some(RowLayout::default());
}
})
.child(text(t!("navigation.layout.reset")).font(UI).color(if is_default { p.faint } else { p.muted }));

let k = kit(p);
let cancel_btn = button(t!("common.cancel"), ButtonVariant::Ghost).on_press_tx(close).build(k).key("nle-cancel");
let done_btn = button(t!("navigation.layout.done"), ButtonVariant::Submit).on_press_tx(save).build(k).key("nle-done");
let footer = row()
.w_full()
.px(20.0)
.py(12.0)
.gap(8.0)
.center_y()
.border_sides([0.5, 0.0, 0.0, 0.0], p.border_muted)
.child(reset_btn)
.child(spacer())
.child(cancel_btn)
.child(done_btn);

let card = col()
.key("navigation-layout-dialog")
.role("dialog")
.label_static(t!("navigation.layout.title"))
.w_full()
.h_full()
.radius(12.0)
.fill(p.bg_base)
.border(0.5, p.border_muted)
.modal_tx(true, close)
.child(header)
.child(content)
.child(footer);

sized_modal("navigation-layout-modal", p, DialogSize::XLarge, Fit::Fixed, dialog_window(cx, *s.zoom), card)
}
12 changes: 3 additions & 9 deletions apps/desktop/src/shell/navigation/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,9 @@ pub fn view(s: &App, p: &Pal) -> El {
action_btn(p, "nav-new", &ic::EDIT, t!("command.session.new"), false)
.on_press_tx(|s: &mut App, tx: &mut Tx| s.new_session(tx)),
)
// Under New navigation Sessions mode, Home hosts inline search (`homeSearch`, `opencode#67795`).
.child(
action_btn(p, "nav-search", &ic::MAGNIFYING_GLASS, t!("navigation.search.placeholder"), false)
.on_press_tx(|s: &mut App, tx: &mut Tx| {
s.close_settings();
s.open_session_search(tx);
}),
)
.child(
action_btn(p, "nav-home", home_glyph, t!("home.title"), home_active)
action_btn(p, "nav-home", home_glyph, t!("navigation.allSessions"), home_active)
.on_press_tx(|s: &mut App, tx: &mut Tx| {
s.toggle_home(tx);
}),
Expand Down Expand Up @@ -420,7 +414,7 @@ fn inline_actions(p: &Pal, sr: &SessionRow, actions: &[RowAction]) -> Option<El>
return None;
}
let mut bar = row().gap(2.0).center_y().group_opacity(0.0, 1.0);
for &act in actions.iter().take(2) {
for &act in actions {
let (srv, id, pinned, archived) = (sr.session.server.clone(), sr.session.id.clone(), sr.pinned, sr.archived);
let (glyph, label) = match act {
RowAction::Archive => (&ic::ARCHIVE, if archived { t!("navigation.rowAction.undo.archive") } else { t!("navigation.rowAction.archive") }),
Expand Down
Loading
Loading