mirror of https://github.com/lapce/lapce.git
Display the workspace file and path in the `File Explorer` panel. (#3563)
* Display the workspace file and path in the `File Explorer` panel. * Fix folder display when the workspace is null
This commit is contained in:
parent
3c73763b2e
commit
c826f94ec1
|
@ -17,7 +17,10 @@ pub fn new(file_node_item: FileNodeItem, naming: Naming) -> Self {
|
|||
|
||||
impl VirtualVector<FileNodeViewData> for FileNodeVirtualList {
|
||||
fn total_len(&self) -> usize {
|
||||
self.file_node_item.children_open_count
|
||||
if !self.file_node_item.path.exists() {
|
||||
return 0;
|
||||
}
|
||||
self.file_node_item.children_open_count + 1
|
||||
}
|
||||
|
||||
fn slice(
|
||||
|
@ -27,11 +30,14 @@ fn slice(
|
|||
let naming = &self.naming;
|
||||
let root = &self.file_node_item;
|
||||
|
||||
if !root.path.exists() {
|
||||
return Vec::new().into_iter();
|
||||
}
|
||||
let min = range.start;
|
||||
let max = range.end;
|
||||
let mut view_items = Vec::new();
|
||||
|
||||
root.append_children_view_slice(&mut view_items, naming, min, max, 0, 0);
|
||||
root.append_view_slice(&mut view_items, naming, min, max, 0, 1);
|
||||
|
||||
view_items.into_iter()
|
||||
}
|
||||
|
|
|
@ -175,22 +175,56 @@ fn file_node_text_view(
|
|||
let ui_line_height = data.common.ui_line_height;
|
||||
|
||||
match node.kind.clone() {
|
||||
FileNodeViewKind::Path(path) => container(
|
||||
label(move || {
|
||||
path.file_name()
|
||||
.map(|f| f.to_string_lossy().to_string())
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.style(move |s| {
|
||||
s.height(ui_line_height.get())
|
||||
.color(file_node_text_color(
|
||||
config,
|
||||
node.clone(),
|
||||
source_control.clone(),
|
||||
))
|
||||
.selectable(false)
|
||||
}),
|
||||
),
|
||||
FileNodeViewKind::Path(path) => {
|
||||
if node.is_root {
|
||||
let file = path.clone();
|
||||
container((
|
||||
label(move || {
|
||||
file.file_name()
|
||||
.map(|f| f.to_string_lossy().to_string())
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.style(move |s| {
|
||||
s.height(ui_line_height.get())
|
||||
.color(file_node_text_color(
|
||||
config,
|
||||
node.clone(),
|
||||
source_control.clone(),
|
||||
))
|
||||
.padding_right(5.0)
|
||||
.selectable(false)
|
||||
}),
|
||||
label(move || path.to_string_lossy().to_string()).style(
|
||||
move |s| {
|
||||
s.height(ui_line_height.get())
|
||||
.color(
|
||||
config
|
||||
.get()
|
||||
.color(LapceColor::PANEL_FOREGROUND_DIM),
|
||||
)
|
||||
.selectable(false)
|
||||
},
|
||||
),
|
||||
))
|
||||
} else {
|
||||
container(
|
||||
label(move || {
|
||||
path.file_name()
|
||||
.map(|f| f.to_string_lossy().to_string())
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.style(move |s| {
|
||||
s.height(ui_line_height.get())
|
||||
.color(file_node_text_color(
|
||||
config,
|
||||
node.clone(),
|
||||
source_control.clone(),
|
||||
))
|
||||
.selectable(false)
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
FileNodeViewKind::Renaming { path, err } => {
|
||||
if data.naming.with_untracked(Naming::editor_needs_reset) {
|
||||
initialize_naming_editor_with_path(&data, &path);
|
||||
|
|
|
@ -232,6 +232,7 @@ pub fn extra_node(
|
|||
err: n.state.err().map(ToString::to_string),
|
||||
},
|
||||
is_dir: n.is_dir,
|
||||
is_root: false,
|
||||
open: false,
|
||||
level: level + 1,
|
||||
}),
|
||||
|
@ -241,6 +242,7 @@ pub fn extra_node(
|
|||
err: d.state.err().map(ToString::to_string),
|
||||
},
|
||||
is_dir,
|
||||
is_root: false,
|
||||
open: false,
|
||||
level: level + 1,
|
||||
}),
|
||||
|
@ -253,6 +255,7 @@ pub fn extra_node(
|
|||
pub struct FileNodeViewData {
|
||||
pub kind: FileNodeViewKind,
|
||||
pub is_dir: bool,
|
||||
pub is_root: bool,
|
||||
pub open: bool,
|
||||
pub level: usize,
|
||||
}
|
||||
|
@ -472,6 +475,7 @@ pub fn append_view_slice(
|
|||
view_items.push(FileNodeViewData {
|
||||
kind,
|
||||
is_dir: self.is_dir,
|
||||
is_root: level == 1,
|
||||
open: self.open,
|
||||
level,
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue