Use Pane::activate_item
when navigating to remove duplicated logic
This commit is contained in:
parent
1453954ef4
commit
d7342e2875
1 changed files with 11 additions and 17 deletions
|
@ -201,27 +201,19 @@ impl Pane {
|
||||||
.upgrade(cx)
|
.upgrade(cx)
|
||||||
.and_then(|v| pane.index_for_item(v.as_ref()))
|
.and_then(|v| pane.index_for_item(v.as_ref()))
|
||||||
{
|
{
|
||||||
if let Some(item) = pane.active_item() {
|
let prev_active_item_index = pane.active_item_index;
|
||||||
pane.nav_history.borrow_mut().set_mode(mode);
|
pane.nav_history.borrow_mut().set_mode(mode);
|
||||||
item.deactivated(cx);
|
pane.activate_item(index, true, cx);
|
||||||
pane.nav_history
|
pane.nav_history
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.set_mode(NavigationMode::Normal);
|
.set_mode(NavigationMode::Normal);
|
||||||
}
|
|
||||||
|
|
||||||
let prev_active_index = mem::replace(&mut pane.active_item_index, index);
|
let mut navigated = prev_active_item_index != pane.active_item_index;
|
||||||
|
|
||||||
let mut navigated = prev_active_index != pane.active_item_index;
|
|
||||||
if let Some(data) = entry.data {
|
if let Some(data) = entry.data {
|
||||||
navigated |= pane.active_item()?.navigate(data, cx);
|
navigated |= pane.active_item()?.navigate(data, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if navigated {
|
if navigated {
|
||||||
pane.focus_active_item(cx);
|
|
||||||
pane.update_toolbar(cx);
|
|
||||||
pane.activate(cx);
|
|
||||||
cx.emit(Event::ActivateItem { local: true });
|
|
||||||
cx.notify();
|
|
||||||
break None;
|
break None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -377,10 +369,12 @@ impl Pane {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn activate_item(&mut self, index: usize, local: bool, cx: &mut ViewContext<Self>) {
|
pub fn activate_item(&mut self, index: usize, local: bool, cx: &mut ViewContext<Self>) {
|
||||||
|
use NavigationMode::{GoingBack, GoingForward};
|
||||||
if index < self.items.len() {
|
if index < self.items.len() {
|
||||||
let prev_active_item_ix = mem::replace(&mut self.active_item_index, index);
|
let prev_active_item_ix = mem::replace(&mut self.active_item_index, index);
|
||||||
if prev_active_item_ix != self.active_item_index
|
if matches!(self.nav_history.borrow().mode, GoingBack | GoingForward)
|
||||||
&& prev_active_item_ix < self.items.len()
|
|| (prev_active_item_ix != self.active_item_index
|
||||||
|
&& prev_active_item_ix < self.items.len())
|
||||||
{
|
{
|
||||||
self.items[prev_active_item_ix].deactivated(cx);
|
self.items[prev_active_item_ix].deactivated(cx);
|
||||||
cx.emit(Event::ActivateItem { local });
|
cx.emit(Event::ActivateItem { local });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue