Remove SplitWithItem internal action

This commit is contained in:
Antonio Scandurra 2023-04-28 12:17:31 +02:00
parent 6857426b78
commit 272039a858
2 changed files with 29 additions and 29 deletions

View file

@ -10,7 +10,7 @@ use gpui::{
use project::ProjectEntryId; use project::ProjectEntryId;
use settings::Settings; use settings::Settings;
use crate::{Pane, SplitDirection, SplitWithItem, SplitWithProjectEntry, Workspace}; use crate::{Pane, SplitDirection, SplitWithProjectEntry, Workspace};
use super::DraggedItem; use super::DraggedItem;
@ -133,12 +133,21 @@ pub fn handle_dropped_item<V: View>(
{ {
let pane_to_split = pane.clone(); let pane_to_split = pane.clone();
match action { match action {
Action::Move(from, item_id_to_move) => cx.dispatch_action(SplitWithItem { Action::Move(from, item_id_to_move) => {
from, cx.window_context().defer(move |cx| {
item_id_to_move, if let Some(workspace) = workspace.upgrade(cx) {
pane_to_split, workspace.update(cx, |workspace, cx| {
split_direction, workspace.split_pane_with_item(
}), pane_to_split,
split_direction,
from,
item_id_to_move,
cx,
);
})
}
});
}
Action::Open(project_entry) => cx.dispatch_action(SplitWithProjectEntry { Action::Open(project_entry) => cx.dispatch_action(SplitWithProjectEntry {
pane_to_split, pane_to_split,
split_direction, split_direction,

View file

@ -134,14 +134,6 @@ pub struct OpenPaths {
#[derive(Clone, Deserialize, PartialEq)] #[derive(Clone, Deserialize, PartialEq)]
pub struct ActivatePane(pub usize); pub struct ActivatePane(pub usize);
#[derive(Clone, PartialEq)]
pub struct SplitWithItem {
pane_to_split: WeakViewHandle<Pane>,
split_direction: SplitDirection,
from: WeakViewHandle<Pane>,
item_id_to_move: usize,
}
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq)]
pub struct SplitWithProjectEntry { pub struct SplitWithProjectEntry {
pane_to_split: WeakViewHandle<Pane>, pane_to_split: WeakViewHandle<Pane>,
@ -201,7 +193,7 @@ impl Clone for Toast {
pub type WorkspaceId = i64; pub type WorkspaceId = i64;
impl_internal_actions!(workspace, [SplitWithItem, SplitWithProjectEntry,]); impl_internal_actions!(workspace, [SplitWithProjectEntry]);
impl_actions!(workspace, [ActivatePane]); impl_actions!(workspace, [ActivatePane]);
pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) { pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
@ -307,7 +299,6 @@ pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
}); });
cx.add_action(Workspace::activate_pane_at_index); cx.add_action(Workspace::activate_pane_at_index);
cx.add_action(Workspace::split_pane_with_item);
cx.add_async_action(Workspace::split_pane_with_project_entry); cx.add_async_action(Workspace::split_pane_with_project_entry);
cx.add_action(|_: &mut Workspace, _: &install_cli::Install, cx| { cx.add_action(|_: &mut Workspace, _: &install_cli::Install, cx| {
@ -1735,25 +1726,25 @@ impl Workspace {
maybe_pane_handle maybe_pane_handle
} }
pub fn split_pane_with_item(&mut self, action: &SplitWithItem, cx: &mut ViewContext<Self>) { pub fn split_pane_with_item(
let Some(pane_to_split) = action.pane_to_split.upgrade(cx) else { return; }; &mut self,
let Some(from) = action.from.upgrade(cx) else { return; }; pane_to_split: WeakViewHandle<Pane>,
split_direction: SplitDirection,
from: WeakViewHandle<Pane>,
item_id_to_move: usize,
cx: &mut ViewContext<Self>,
) {
let Some(pane_to_split) = pane_to_split.upgrade(cx) else { return; };
let Some(from) = from.upgrade(cx) else { return; };
if &pane_to_split == self.dock_pane() { if &pane_to_split == self.dock_pane() {
warn!("Can't split dock pane."); warn!("Can't split dock pane.");
return; return;
} }
let new_pane = self.add_pane(cx); let new_pane = self.add_pane(cx);
Pane::move_item( Pane::move_item(self, from.clone(), new_pane.clone(), item_id_to_move, 0, cx);
self,
from.clone(),
new_pane.clone(),
action.item_id_to_move,
0,
cx,
);
self.center self.center
.split(&pane_to_split, &new_pane, action.split_direction) .split(&pane_to_split, &new_pane, split_direction)
.unwrap(); .unwrap();
cx.notify(); cx.notify();
} }