Merge pull request #711 from ToBinio/update-search
fix: update search on events
This commit is contained in:
commit
9f819454ae
1 changed files with 46 additions and 38 deletions
84
src/app.rs
84
src/app.rs
|
|
@ -879,7 +879,7 @@ impl App {
|
||||||
|
|
||||||
fn search(&mut self) -> Task<Message> {
|
fn search(&mut self) -> Task<Message> {
|
||||||
if let Some(term) = self.search_get() {
|
if let Some(term) = self.search_get() {
|
||||||
self.search_set(Some(term.to_string()))
|
self.search_set_active(Some(term.to_string()))
|
||||||
} else {
|
} else {
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
@ -894,10 +894,14 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search_set(&mut self, term_opt: Option<String>) -> Task<Message> {
|
fn search_set_active(&mut self, term_opt: Option<String>) -> Task<Message> {
|
||||||
let entity = self.tab_model.active();
|
let entity = self.tab_model.active();
|
||||||
|
self.search_set(entity, term_opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn search_set(&mut self,tab: Entity, term_opt: Option<String>) -> Task<Message> {
|
||||||
let mut title_location_opt = None;
|
let mut title_location_opt = None;
|
||||||
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
|
if let Some(tab) = self.tab_model.data_mut::<Tab>(tab) {
|
||||||
let location_opt = match term_opt {
|
let location_opt = match term_opt {
|
||||||
Some(term) => match &tab.location {
|
Some(term) => match &tab.location {
|
||||||
Location::Path(path) | Location::Search(path, ..) => Some((
|
Location::Path(path) | Location::Search(path, ..) => Some((
|
||||||
|
|
@ -922,11 +926,11 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some((title, location, focus_search)) = title_location_opt {
|
if let Some((title, location, focus_search)) = title_location_opt {
|
||||||
self.tab_model.text_set(entity, title);
|
self.tab_model.text_set(tab, title);
|
||||||
return Task::batch([
|
return Task::batch([
|
||||||
self.update_title(),
|
self.update_title(),
|
||||||
self.update_watcher(),
|
self.update_watcher(),
|
||||||
self.rescan_tab(entity, location, None),
|
self.rescan_tab(tab, location, None),
|
||||||
if focus_search {
|
if focus_search {
|
||||||
widget::text_input::focus(self.search_id.clone())
|
widget::text_input::focus(self.search_id.clone())
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1767,7 +1771,7 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
if self.search_get().is_some() {
|
if self.search_get().is_some() {
|
||||||
// Close search if open
|
// Close search if open
|
||||||
return self.search_set(None);
|
return self.search_set_active(None);
|
||||||
}
|
}
|
||||||
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
|
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
|
||||||
if tab.context_menu.is_some() {
|
if tab.context_menu.is_some() {
|
||||||
|
|
@ -2298,7 +2302,11 @@ impl Application for App {
|
||||||
|
|
||||||
let mut commands = Vec::with_capacity(needs_reload.len());
|
let mut commands = Vec::with_capacity(needs_reload.len());
|
||||||
for (entity, location) in needs_reload {
|
for (entity, location) in needs_reload {
|
||||||
commands.push(self.rescan_tab(entity, location, None));
|
if let Location::Search(_, term, ..) = location {
|
||||||
|
commands.push(self.search_set(entity, Some(term)));
|
||||||
|
} else {
|
||||||
|
commands.push(self.rescan_tab(entity, location, None));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Task::batch(commands);
|
return Task::batch(commands);
|
||||||
}
|
}
|
||||||
|
|
@ -2642,37 +2650,37 @@ impl Application for App {
|
||||||
Message::Rename(entity_opt) => {
|
Message::Rename(entity_opt) => {
|
||||||
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
|
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
|
||||||
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
|
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
|
||||||
if let Some(items) = tab.items_opt() {
|
if let Some(items) = tab.items_opt() {
|
||||||
let mut selected = Vec::new();
|
let mut selected = Vec::new();
|
||||||
for item in items.iter() {
|
for item in items.iter() {
|
||||||
if item.selected {
|
if item.selected {
|
||||||
if let Some(path) = item.path_opt() {
|
if let Some(path) = item.path_opt() {
|
||||||
selected.push(path.to_path_buf());
|
selected.push(path.to_path_buf());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !selected.is_empty() {
|
|
||||||
//TODO: batch rename
|
|
||||||
for path in selected {
|
|
||||||
let parent = match path.parent() {
|
|
||||||
Some(some) => some.to_path_buf(),
|
|
||||||
None => continue,
|
|
||||||
};
|
|
||||||
let name = match path.file_name().and_then(|x| x.to_str()) {
|
|
||||||
Some(some) => some.to_string(),
|
|
||||||
None => continue,
|
|
||||||
};
|
|
||||||
let dir = path.is_dir();
|
|
||||||
self.dialog_pages.push_back(DialogPage::RenameItem {
|
|
||||||
from: path,
|
|
||||||
parent,
|
|
||||||
name,
|
|
||||||
dir,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return widget::text_input::focus(self.dialog_text_input.clone());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if !selected.is_empty() {
|
||||||
|
//TODO: batch rename
|
||||||
|
for path in selected {
|
||||||
|
let parent = match path.parent() {
|
||||||
|
Some(some) => some.to_path_buf(),
|
||||||
|
None => continue,
|
||||||
|
};
|
||||||
|
let name = match path.file_name().and_then(|x| x.to_str()) {
|
||||||
|
Some(some) => some.to_string(),
|
||||||
|
None => continue,
|
||||||
|
};
|
||||||
|
let dir = path.is_dir();
|
||||||
|
self.dialog_pages.push_back(DialogPage::RenameItem {
|
||||||
|
from: path,
|
||||||
|
parent,
|
||||||
|
name,
|
||||||
|
dir,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return widget::text_input::focus(self.dialog_text_input.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::ReplaceResult(replace_result) => {
|
Message::ReplaceResult(replace_result) => {
|
||||||
|
|
@ -2719,16 +2727,16 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
Message::SearchActivate => {
|
Message::SearchActivate => {
|
||||||
return if self.search_get().is_none() {
|
return if self.search_get().is_none() {
|
||||||
self.search_set(Some(String::new()))
|
self.search_set_active(Some(String::new()))
|
||||||
} else {
|
} else {
|
||||||
widget::text_input::focus(self.search_id.clone())
|
widget::text_input::focus(self.search_id.clone())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Message::SearchClear => {
|
Message::SearchClear => {
|
||||||
return self.search_set(None);
|
return self.search_set_active(None);
|
||||||
}
|
}
|
||||||
Message::SearchInput(input) => {
|
Message::SearchInput(input) => {
|
||||||
return self.search_set(Some(input));
|
return self.search_set_active(Some(input));
|
||||||
}
|
}
|
||||||
Message::SetShowDetails(show_details) => {
|
Message::SetShowDetails(show_details) => {
|
||||||
config_set!(show_details, show_details);
|
config_set!(show_details, show_details);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue