Expand project view to encompase open file
This commit is contained in:
parent
8dd38517ab
commit
7d4d25ef85
1 changed files with 43 additions and 16 deletions
59
src/main.rs
59
src/main.rs
|
|
@ -195,34 +195,61 @@ impl App {
|
||||||
.activate();
|
.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_title(&mut self) -> Command<Message> {
|
fn update_nav_bar_active(&mut self) {
|
||||||
let (title, tab_path_opt) = match self.active_tab() {
|
let tab_path_opt = match self.active_tab() {
|
||||||
Some(tab) => (tab.title(), tab.path_opt.clone()),
|
Some(tab) => tab.path_opt.clone(),
|
||||||
None => (format!("No Open File"), None),
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO: is this the best place for this?
|
// Locate tree node to activate
|
||||||
let mut active_id = segmented_button::Entity::default();
|
let mut active_id = segmented_button::Entity::default();
|
||||||
match tab_path_opt {
|
match tab_path_opt {
|
||||||
Some(tab_path) => {
|
Some(tab_path) => {
|
||||||
for id in self.nav_model.iter() {
|
// Automatically expand tree to find and select active file
|
||||||
match self.nav_model.data(id) {
|
loop {
|
||||||
Some(node) => match node {
|
let mut expand_opt = None;
|
||||||
ProjectNode::File { path, .. } => {
|
for id in self.nav_model.iter() {
|
||||||
if path == &tab_path {
|
match self.nav_model.data(id) {
|
||||||
active_id = id;
|
Some(node) => match node {
|
||||||
break;
|
ProjectNode::Folder { path, open, .. } => {
|
||||||
|
if tab_path.starts_with(path) && !*open {
|
||||||
|
expand_opt = Some(id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
ProjectNode::File { path, .. } => {
|
||||||
_ => {}
|
if path == &tab_path {
|
||||||
},
|
active_id = id;
|
||||||
None => {}
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match expand_opt {
|
||||||
|
Some(id) => {
|
||||||
|
//TODO: can this be optimized?
|
||||||
|
cosmic::Application::on_nav_select(self, id);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
self.nav_model.activate(active_id);
|
self.nav_model.activate(active_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_title(&mut self) -> Command<Message> {
|
||||||
|
self.update_nav_bar_active();
|
||||||
|
|
||||||
|
let title = match self.active_tab() {
|
||||||
|
Some(tab) => tab.title(),
|
||||||
|
None => format!("No Open File"),
|
||||||
|
};
|
||||||
|
|
||||||
let window_title = format!("{title} - COSMIC Text Editor");
|
let window_title = format!("{title} - COSMIC Text Editor");
|
||||||
self.set_header_title(title.clone());
|
self.set_header_title(title.clone());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue