dock: Do not active tab when drop to TabPanel right empty area. (#491)
This commit is contained in:
parent
28c072d9c6
commit
d701baed28
1 changed files with 26 additions and 6 deletions
|
|
@ -174,6 +174,15 @@ impl TabPanel {
|
||||||
|
|
||||||
/// Add a panel to the end of the tabs
|
/// Add a panel to the end of the tabs
|
||||||
pub fn add_panel(&mut self, panel: Arc<dyn PanelView>, cx: &mut ViewContext<Self>) {
|
pub fn add_panel(&mut self, panel: Arc<dyn PanelView>, cx: &mut ViewContext<Self>) {
|
||||||
|
self.add_panel_with_active(panel, true, cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_panel_with_active(
|
||||||
|
&mut self,
|
||||||
|
panel: Arc<dyn PanelView>,
|
||||||
|
active: bool,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) {
|
||||||
assert_ne!(
|
assert_ne!(
|
||||||
panel.panel_name(cx),
|
panel.panel_name(cx),
|
||||||
"StackPanel",
|
"StackPanel",
|
||||||
|
|
@ -190,7 +199,9 @@ impl TabPanel {
|
||||||
|
|
||||||
self.panels.push(panel);
|
self.panels.push(panel);
|
||||||
// set the active panel to the new panel
|
// set the active panel to the new panel
|
||||||
self.set_active_ix(self.panels.len() - 1, cx);
|
if active {
|
||||||
|
self.set_active_ix(self.panels.len() - 1, cx);
|
||||||
|
}
|
||||||
cx.emit(PanelEvent::LayoutChanged);
|
cx.emit(PanelEvent::LayoutChanged);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
@ -580,7 +591,7 @@ impl TabPanel {
|
||||||
.on_drop(cx.listener(
|
.on_drop(cx.listener(
|
||||||
move |this, drag: &DragPanel, cx| {
|
move |this, drag: &DragPanel, cx| {
|
||||||
this.will_split_placement = None;
|
this.will_split_placement = None;
|
||||||
this.on_drop(drag, Some(ix), cx)
|
this.on_drop(drag, Some(ix), true, cx)
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
@ -603,7 +614,7 @@ impl TabPanel {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
this.on_drop(drag, ix, cx)
|
this.on_drop(drag, ix, false, cx)
|
||||||
}))
|
}))
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
@ -664,7 +675,7 @@ impl TabPanel {
|
||||||
})
|
})
|
||||||
.group_drag_over::<DragPanel>("", |this| this.visible())
|
.group_drag_over::<DragPanel>("", |this| this.visible())
|
||||||
.on_drop(cx.listener(|this, drag: &DragPanel, cx| {
|
.on_drop(cx.listener(|this, drag: &DragPanel, cx| {
|
||||||
this.on_drop(drag, None, cx)
|
this.on_drop(drag, None, true, cx)
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
@ -694,7 +705,16 @@ impl TabPanel {
|
||||||
cx.notify()
|
cx.notify()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_drop(&mut self, drag: &DragPanel, ix: Option<usize>, cx: &mut ViewContext<Self>) {
|
/// Handle the drop event when dragging a panel
|
||||||
|
///
|
||||||
|
/// - `active` - When true, the panel will be active after the drop
|
||||||
|
fn on_drop(
|
||||||
|
&mut self,
|
||||||
|
drag: &DragPanel,
|
||||||
|
ix: Option<usize>,
|
||||||
|
active: bool,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) {
|
||||||
let panel = drag.panel.clone();
|
let panel = drag.panel.clone();
|
||||||
let is_same_tab = drag.tab_panel == *cx.view();
|
let is_same_tab = drag.tab_panel == *cx.view();
|
||||||
|
|
||||||
|
|
@ -729,7 +749,7 @@ impl TabPanel {
|
||||||
if let Some(ix) = ix {
|
if let Some(ix) = ix {
|
||||||
self.insert_panel_at(panel, ix, cx)
|
self.insert_panel_at(panel, ix, cx)
|
||||||
} else {
|
} else {
|
||||||
self.add_panel(panel, cx)
|
self.add_panel_with_active(panel, active, cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue