Refactor mode indicator to remove itself

One of the problems we had is that the status_bar shows a gap between
items, and we want to not add an additional gap for an invisible status
indicator.
This commit is contained in:
Conrad Irwin 2023-07-24 09:37:48 -06:00
parent d14a484a20
commit 43d94e37ec
7 changed files with 142 additions and 41 deletions

View file

@ -1,4 +1,4 @@
use std::{any::TypeId, ops::Range};
use std::ops::Range;
use crate::{ItemHandle, Pane};
use gpui::{
@ -96,14 +96,21 @@ impl StatusBar {
cx.notify();
}
pub fn position_of_item<T>(&mut self) -> Option<usize>
pub fn position_of_item<T>(&self) -> Option<usize>
where
T: StatusItemView,
{
self.position_of_named_item(T::ui_name())
}
pub fn position_of_named_item(&mut self, name: &str) -> Option<usize> {
pub fn item_of_type<T: StatusItemView>(&self) -> Option<ViewHandle<T>> {
self.left_items
.iter()
.chain(self.right_items.iter())
.find_map(|item| item.as_any().clone().downcast())
}
pub fn position_of_named_item(&self, name: &str) -> Option<usize> {
for (index, item) in self.left_items.iter().enumerate() {
if item.as_ref().ui_name() == name {
return Some(index);
@ -126,10 +133,10 @@ impl StatusBar {
T: 'static + StatusItemView,
{
if position < self.left_items.len() {
self.left_items.insert(position, Box::new(item))
self.left_items.insert(position + 1, Box::new(item))
} else {
self.right_items
.insert(position - self.left_items.len(), Box::new(item))
.insert(position + 1 - self.left_items.len(), Box::new(item))
}
cx.notify()
}