Pull up diagnostic and cursor position status bar items creation

This commit is contained in:
Antonio Scandurra 2021-11-24 16:04:24 +01:00
parent 9bb195e177
commit 03bd6d6c33
3 changed files with 18 additions and 12 deletions

View file

@ -27,6 +27,7 @@ tree-sitter-rust = { version = "0.19.0", optional = true }
[dev-dependencies]
client = { path = "../client", features = ["test-support"] }
gpui = { path = "../gpui", features = ["test-support"] }
project = { path = "../project", features = ["test-support"] }
serde_json = { version = "1.0.64", features = ["preserve_order"] }
tree-sitter = "0.19.5"

View file

@ -1,4 +1,4 @@
mod items;
pub mod items;
pub mod pane;
pub mod pane_group;
pub mod settings;
@ -20,6 +20,7 @@ use postage::{prelude::Stream, watch};
use project::{Fs, Project, ProjectPath, Worktree};
pub use settings::Settings;
use sidebar::{Side, Sidebar, SidebarItemId, ToggleSidebarItem, ToggleSidebarItemFocus};
use status_bar::StatusBar;
use std::{
collections::{hash_map::Entry, HashMap},
future::Future,
@ -27,8 +28,6 @@ use std::{
sync::Arc,
};
use crate::status_bar::StatusBar;
action!(OpenNew, WorkspaceParams);
action!(Save);
action!(DebugElements);
@ -382,15 +381,7 @@ impl Workspace {
.detach();
cx.focus(&pane);
let cursor_position = cx.add_view(|_| items::CursorPosition::new(params.settings.clone()));
let diagnostic = cx.add_view(|_| items::DiagnosticMessage::new(params.settings.clone()));
let status_bar = cx.add_view(|cx| {
let mut status_bar = StatusBar::new(&pane, params.settings.clone(), cx);
status_bar.add_left_item(diagnostic, cx);
status_bar.add_right_item(cursor_position, cx);
status_bar
});
let status_bar = cx.add_view(|cx| StatusBar::new(&pane, params.settings.clone(), cx));
let mut current_user = params.user_store.read(cx).watch_current_user().clone();
let mut connection_status = params.client.status().clone();
let _observe_current_user = cx.spawn_weak(|this, mut cx| async move {
@ -436,6 +427,10 @@ impl Workspace {
&mut self.right_sidebar
}
pub fn status_bar(&self) -> &ViewHandle<StatusBar> {
&self.status_bar
}
pub fn project(&self) -> &ModelHandle<Project> {
&self.project
}

View file

@ -161,6 +161,16 @@ fn build_workspace(params: &WorkspaceParams, cx: &mut ViewContext<Workspace>) ->
})
.into(),
);
let diagnostic =
cx.add_view(|_| workspace::items::DiagnosticMessage::new(params.settings.clone()));
let cursor_position =
cx.add_view(|_| workspace::items::CursorPosition::new(params.settings.clone()));
workspace.status_bar().update(cx, |status_bar, cx| {
status_bar.add_left_item(diagnostic, cx);
status_bar.add_right_item(cursor_position, cx);
});
workspace
}