pub struct TabManager {
pub tabs: Vec<TabState>,
pub active: usize,
}Expand description
Manages the collection of open tabs within AppState.
There is always at least one tab. active is the index of the
currently focused tab in tabs. Invariant: active < tabs.len().
Fields§
§tabs: Vec<TabState>All open tabs; never empty.
active: usizeIndex of the active (focused) tab. Always < tabs.len().
Implementations§
Source§impl TabManager
impl TabManager
Sourcepub fn new(cwd: PathBuf, sort: SortSettings) -> Self
pub fn new(cwd: PathBuf, sort: SortSettings) -> Self
Creates a TabManager with a single initial tab rooted at cwd,
ordered by sort.
Sourcepub fn active_tab(&self) -> &TabState
pub fn active_tab(&self) -> &TabState
Returns a shared reference to the active tab.
Sourcepub fn active_tab_mut(&mut self) -> &mut TabState
pub fn active_tab_mut(&mut self) -> &mut TabState
Returns a mutable reference to the active tab.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of open tabs.
Read by the status bar for the [2/3] indicator.
Sourcepub fn is_single(&self) -> bool
pub fn is_single(&self) -> bool
Returns true when exactly one tab is open.
The status bar shows its tab indicator only when this is false — with one tab there is nothing to disambiguate — and a switch request with one tab says so rather than doing nothing.
Sourcepub fn open_tab(&mut self, cwd: PathBuf, sort: SortSettings)
pub fn open_tab(&mut self, cwd: PathBuf, sort: SortSettings)
Opens a new tab rooted at cwd, ordered by sort, and switches focus
to it.
The new tab is inserted after the currently active tab. Callers pass the
outgoing tab’s sort so a new tab inherits the order you were already
using rather than snapping back to the configured default.
Sourcepub fn close_active_tab(&mut self) -> bool
pub fn close_active_tab(&mut self) -> bool
Closes the active tab.
If this would leave zero tabs, the close is refused (returns false).
On success the active index is adjusted so it remains in bounds:
- If there are tabs to the right, the next one becomes active.
- Otherwise the previous tab becomes active.
Returns true if the tab was closed, false if it was the last one.
Sourcepub fn switch_to(&mut self, index: usize) -> bool
pub fn switch_to(&mut self, index: usize) -> bool
Switches focus to the tab at index.
Returns true if the switch happened (index was valid and different
from the current active tab), false otherwise.
Sourcepub fn switch_next(&mut self) -> bool
pub fn switch_next(&mut self) -> bool
Switches focus to the next tab, wrapping around from the last to the first.
Returns true when there is more than one tab (i.e. a switch happened).
Sourcepub fn switch_prev(&mut self) -> bool
pub fn switch_prev(&mut self) -> bool
Switches focus to the previous tab, wrapping around from the first to the last.
Returns true when there is more than one tab.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TabManager
impl RefUnwindSafe for TabManager
impl Send for TabManager
impl Sync for TabManager
impl Unpin for TabManager
impl UnsafeUnpin for TabManager
impl UnwindSafe for TabManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more