Merge remote-tracking branch 'github/jb55-deck-733-profile-sidebar-action-should-route-in-the-active-column'

This commit is contained in:
William Casarin
2025-07-24 12:28:06 -07:00
6 changed files with 25 additions and 23 deletions

View File

@@ -699,7 +699,7 @@ fn chrome_handle_app_action(
); );
if let Some(action) = m_action { if let Some(action) = m_action {
let col = cols.column_mut(0); let col = cols.selected_mut();
action.process(&mut col.router, &mut col.sheet_router); action.process(&mut col.router, &mut col.sheet_router);
} }
@@ -723,7 +723,7 @@ fn columns_route_to_profile(
.active_columns_mut(ctx.i18n, ctx.accounts) .active_columns_mut(ctx.i18n, ctx.accounts)
.unwrap(); .unwrap();
let router = cols.get_first_router(); let router = cols.get_selected_router();
if router.routes().iter().any(|r| { if router.routes().iter().any(|r| {
matches!( matches!(
r, r,
@@ -754,7 +754,7 @@ fn columns_route_to_profile(
); );
if let Some(action) = m_action { if let Some(action) = m_action {
let col = cols.column_mut(0); let col = cols.selected_mut();
action.process(&mut col.router, &mut col.sheet_router); action.process(&mut col.router, &mut col.sheet_router);
} }

View File

@@ -78,9 +78,7 @@ fn handle_key_events(input: &egui::InputState, columns: &mut Columns) {
columns.select_left(); columns.select_left();
} }
egui::Key::BrowserBack | egui::Key::Escape => { egui::Key::BrowserBack | egui::Key::Escape => {
if let Some(column) = columns.selected_mut() { columns.get_selected_router().go_back();
column.router_mut().go_back();
}
} }
_ => {} _ => {}
} }

View File

@@ -156,11 +156,9 @@ impl Columns {
// Get the first router in the columns if there are columns present. // Get the first router in the columns if there are columns present.
// Otherwise, create a new column picker and return the router // Otherwise, create a new column picker and return the router
pub fn get_first_router(&mut self) -> &mut Router<Route> { pub fn get_selected_router(&mut self) -> &mut Router<Route> {
if self.columns.is_empty() { self.ensure_column();
self.new_column_picker(); self.selected_mut().router_mut()
}
self.columns[0].router_mut()
} }
#[inline] #[inline]
@@ -181,19 +179,25 @@ impl Columns {
Some(&self.columns[self.selected as usize]) Some(&self.columns[self.selected as usize])
} }
#[inline] // TODO(jb55): switch to non-empty container for columns?
pub fn selected_mut(&mut self) -> Option<&mut Column> { fn ensure_column(&mut self) {
if self.columns.is_empty() { if self.columns.is_empty() {
return None; self.new_column_picker();
} }
Some(&mut self.columns[self.selected as usize]) }
/// Get the selected column. If you're looking to route something
/// and you're not sure which one to choose, use this one
#[inline]
pub fn selected_mut(&mut self) -> &mut Column {
self.ensure_column();
assert!(self.selected < self.columns.len() as i32);
&mut self.columns[self.selected as usize]
} }
#[inline] #[inline]
pub fn column_mut(&mut self, ind: usize) -> &mut Column { pub fn column_mut(&mut self, ind: usize) -> &mut Column {
if self.columns.is_empty() { self.ensure_column();
self.new_column_picker();
}
&mut self.columns[ind] &mut self.columns[ind]
} }

View File

@@ -35,7 +35,7 @@ impl DecksCache {
accounts: &notedeck::Accounts, accounts: &notedeck::Accounts,
) -> Option<&mut Column> { ) -> Option<&mut Column> {
self.active_columns_mut(i18n, accounts) self.active_columns_mut(i18n, accounts)
.and_then(|ad| ad.selected_mut()) .map(|ad| ad.selected_mut())
} }
pub fn selected_column(&self, accounts: &notedeck::Accounts) -> Option<&Column> { pub fn selected_column(&self, accounts: &notedeck::Accounts) -> Option<&Column> {

View File

@@ -771,7 +771,7 @@ fn render_nav_body(
new_deck_state.clear(); new_deck_state.clear();
get_active_columns_mut(ctx.i18n, ctx.accounts, &mut app.decks_cache) get_active_columns_mut(ctx.i18n, ctx.accounts, &mut app.decks_cache)
.get_first_router() .get_selected_router()
.go_back(); .go_back();
} }
resp resp
@@ -802,7 +802,7 @@ fn render_nav_body(
} }
} }
get_active_columns_mut(ctx.i18n, ctx.accounts, &mut app.decks_cache) get_active_columns_mut(ctx.i18n, ctx.accounts, &mut app.decks_cache)
.get_first_router() .get_selected_router()
.go_back(); .go_back();
} }

View File

@@ -187,7 +187,7 @@ impl<'a> DesktopSidePanel<'a> {
action: SidePanelAction, action: SidePanelAction,
i18n: &mut Localization, i18n: &mut Localization,
) -> Option<SwitchingAction> { ) -> Option<SwitchingAction> {
let router = get_active_columns_mut(i18n, accounts, decks_cache).get_first_router(); let router = get_active_columns_mut(i18n, accounts, decks_cache).get_selected_router();
let mut switching_response = None; let mut switching_response = None;
match action { match action {
/* /*
@@ -280,7 +280,7 @@ impl<'a> DesktopSidePanel<'a> {
{ {
edit_deck edit_deck
.columns_mut() .columns_mut()
.get_first_router() .get_selected_router()
.route_to(Route::EditDeck(index)); .route_to(Route::EditDeck(index));
} else { } else {
error!("Cannot push EditDeck route to index {}", index); error!("Cannot push EditDeck route to index {}", index);