Show full path for file worktrees or when there is more than 1 worktree
This commit is contained in:
parent
9225629208
commit
c39de1f9dc
5 changed files with 48 additions and 27 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -727,6 +727,7 @@ dependencies = [
|
||||||
"editor",
|
"editor",
|
||||||
"gpui",
|
"gpui",
|
||||||
"language",
|
"language",
|
||||||
|
"project",
|
||||||
"search",
|
"search",
|
||||||
"theme",
|
"theme",
|
||||||
"workspace",
|
"workspace",
|
||||||
|
|
|
@ -12,6 +12,7 @@ collections = { path = "../collections" }
|
||||||
editor = { path = "../editor" }
|
editor = { path = "../editor" }
|
||||||
gpui = { path = "../gpui" }
|
gpui = { path = "../gpui" }
|
||||||
language = { path = "../language" }
|
language = { path = "../language" }
|
||||||
|
project = { path = "../project" }
|
||||||
search = { path = "../search" }
|
search = { path = "../search" }
|
||||||
theme = { path = "../theme" }
|
theme = { path = "../theme" }
|
||||||
workspace = { path = "../workspace" }
|
workspace = { path = "../workspace" }
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use editor::{Anchor, Editor};
|
use editor::{Anchor, Editor};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
elements::*, AppContext, Entity, RenderContext, Subscription, View, ViewContext, ViewHandle,
|
elements::*, AppContext, Entity, ModelHandle, RenderContext, Subscription, View, ViewContext,
|
||||||
|
ViewHandle,
|
||||||
};
|
};
|
||||||
use language::{BufferSnapshot, OutlineItem};
|
use language::{Buffer, OutlineItem};
|
||||||
|
use project::Project;
|
||||||
use search::ProjectSearchView;
|
use search::ProjectSearchView;
|
||||||
use std::borrow::Cow;
|
|
||||||
use theme::SyntaxTheme;
|
use theme::SyntaxTheme;
|
||||||
use workspace::{ItemHandle, Settings, ToolbarItemLocation, ToolbarItemView};
|
use workspace::{ItemHandle, Settings, ToolbarItemLocation, ToolbarItemView};
|
||||||
|
|
||||||
|
@ -13,14 +14,16 @@ pub enum Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Breadcrumbs {
|
pub struct Breadcrumbs {
|
||||||
|
project: ModelHandle<Project>,
|
||||||
editor: Option<ViewHandle<Editor>>,
|
editor: Option<ViewHandle<Editor>>,
|
||||||
project_search: Option<ViewHandle<ProjectSearchView>>,
|
project_search: Option<ViewHandle<ProjectSearchView>>,
|
||||||
subscriptions: Vec<Subscription>,
|
subscriptions: Vec<Subscription>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Breadcrumbs {
|
impl Breadcrumbs {
|
||||||
pub fn new() -> Self {
|
pub fn new(project: ModelHandle<Project>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
project,
|
||||||
editor: Default::default(),
|
editor: Default::default(),
|
||||||
subscriptions: Default::default(),
|
subscriptions: Default::default(),
|
||||||
project_search: Default::default(),
|
project_search: Default::default(),
|
||||||
|
@ -31,14 +34,14 @@ impl Breadcrumbs {
|
||||||
&self,
|
&self,
|
||||||
theme: &SyntaxTheme,
|
theme: &SyntaxTheme,
|
||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) -> Option<(BufferSnapshot, Vec<OutlineItem<Anchor>>)> {
|
) -> Option<(ModelHandle<Buffer>, Vec<OutlineItem<Anchor>>)> {
|
||||||
let editor = self.editor.as_ref()?.read(cx);
|
let editor = self.editor.as_ref()?.read(cx);
|
||||||
let cursor = editor.newest_anchor_selection().head();
|
let cursor = editor.newest_anchor_selection().head();
|
||||||
let (buffer, symbols) = editor
|
let multibuffer = &editor.buffer().read(cx);
|
||||||
.buffer()
|
let (buffer_id, symbols) = multibuffer
|
||||||
.read(cx)
|
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.symbols_containing(cursor, Some(theme))?;
|
.symbols_containing(cursor, Some(theme))?;
|
||||||
|
let buffer = multibuffer.buffer(buffer_id)?;
|
||||||
Some((buffer, symbols))
|
Some((buffer, symbols))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,15 +63,21 @@ impl View for Breadcrumbs {
|
||||||
} else {
|
} else {
|
||||||
return Empty::new().boxed();
|
return Empty::new().boxed();
|
||||||
};
|
};
|
||||||
|
let buffer = buffer.read(cx);
|
||||||
let filename = if let Some(path) = buffer.path() {
|
let filename = if let Some(file) = buffer.file() {
|
||||||
path.to_string_lossy()
|
if file.path().file_name().is_none()
|
||||||
|
|| self.project.read(cx).visible_worktrees(cx).count() > 1
|
||||||
|
{
|
||||||
|
file.full_path(cx).to_string_lossy().to_string()
|
||||||
|
} else {
|
||||||
|
file.path().to_string_lossy().to_string()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Cow::Borrowed("untitled")
|
"untitled".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_child(Label::new(filename.to_string(), theme.breadcrumbs.text.clone()).boxed())
|
.with_child(Label::new(filename, theme.breadcrumbs.text.clone()).boxed())
|
||||||
.with_children(symbols.into_iter().flat_map(|symbol| {
|
.with_children(symbols.into_iter().flat_map(|symbol| {
|
||||||
[
|
[
|
||||||
Label::new(" 〉 ".to_string(), theme.breadcrumbs.text.clone()).boxed(),
|
Label::new(" 〉 ".to_string(), theme.breadcrumbs.text.clone()).boxed(),
|
||||||
|
|
|
@ -1001,6 +1001,13 @@ impl MultiBuffer {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn buffer(&self, buffer_id: usize) -> Option<ModelHandle<Buffer>> {
|
||||||
|
self.buffers
|
||||||
|
.borrow()
|
||||||
|
.get(&buffer_id)
|
||||||
|
.map(|state| state.buffer.clone())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn save(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
|
pub fn save(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
|
||||||
let mut save_tasks = Vec::new();
|
let mut save_tasks = Vec::new();
|
||||||
for BufferState { buffer, .. } in self.buffers.borrow().values() {
|
for BufferState { buffer, .. } in self.buffers.borrow().values() {
|
||||||
|
@ -2268,12 +2275,12 @@ impl MultiBufferSnapshot {
|
||||||
&self,
|
&self,
|
||||||
offset: T,
|
offset: T,
|
||||||
theme: Option<&SyntaxTheme>,
|
theme: Option<&SyntaxTheme>,
|
||||||
) -> Option<(BufferSnapshot, Vec<OutlineItem<Anchor>>)> {
|
) -> Option<(usize, Vec<OutlineItem<Anchor>>)> {
|
||||||
let anchor = self.anchor_before(offset);
|
let anchor = self.anchor_before(offset);
|
||||||
let excerpt_id = anchor.excerpt_id();
|
let excerpt_id = anchor.excerpt_id();
|
||||||
let excerpt = self.excerpt(excerpt_id)?;
|
let excerpt = self.excerpt(excerpt_id)?;
|
||||||
Some((
|
Some((
|
||||||
excerpt.buffer.clone(),
|
excerpt.buffer_id,
|
||||||
excerpt
|
excerpt
|
||||||
.buffer
|
.buffer
|
||||||
.symbols_containing(anchor.text_anchor, theme)
|
.symbols_containing(anchor.text_anchor, theme)
|
||||||
|
|
|
@ -106,18 +106,21 @@ pub fn build_workspace(
|
||||||
app_state: &Arc<AppState>,
|
app_state: &Arc<AppState>,
|
||||||
cx: &mut ViewContext<Workspace>,
|
cx: &mut ViewContext<Workspace>,
|
||||||
) -> Workspace {
|
) -> Workspace {
|
||||||
cx.subscribe(&cx.handle(), |_, _, event, cx| {
|
cx.subscribe(&cx.handle(), {
|
||||||
let workspace::Event::PaneAdded(pane) = event;
|
let project = project.clone();
|
||||||
pane.update(cx, |pane, cx| {
|
move |_, _, event, cx| {
|
||||||
pane.toolbar().update(cx, |toolbar, cx| {
|
let workspace::Event::PaneAdded(pane) = event;
|
||||||
let breadcrumbs = cx.add_view(|_| Breadcrumbs::new());
|
pane.update(cx, |pane, cx| {
|
||||||
toolbar.add_item(breadcrumbs, cx);
|
pane.toolbar().update(cx, |toolbar, cx| {
|
||||||
let buffer_search_bar = cx.add_view(|cx| BufferSearchBar::new(cx));
|
let breadcrumbs = cx.add_view(|_| Breadcrumbs::new(project.clone()));
|
||||||
toolbar.add_item(buffer_search_bar, cx);
|
toolbar.add_item(breadcrumbs, cx);
|
||||||
let project_search_bar = cx.add_view(|_| ProjectSearchBar::new());
|
let buffer_search_bar = cx.add_view(|cx| BufferSearchBar::new(cx));
|
||||||
toolbar.add_item(project_search_bar, cx);
|
toolbar.add_item(buffer_search_bar, cx);
|
||||||
})
|
let project_search_bar = cx.add_view(|_| ProjectSearchBar::new());
|
||||||
});
|
toolbar.add_item(project_search_bar, cx);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue