Rework close_inactive_items to await all tasks
Update action name to be more accurate
This commit is contained in:
parent
1610e270d6
commit
a0fc515cfc
3 changed files with 32 additions and 16 deletions
|
@ -22,7 +22,7 @@
|
||||||
"alt-cmd-right": "pane::ActivateNextItem",
|
"alt-cmd-right": "pane::ActivateNextItem",
|
||||||
"cmd-w": "pane::CloseActiveItem",
|
"cmd-w": "pane::CloseActiveItem",
|
||||||
"alt-cmd-t": "pane::CloseInactiveItems",
|
"alt-cmd-t": "pane::CloseInactiveItems",
|
||||||
"ctrl-alt-cmd-w": "workspace::CloseInactiveEditors",
|
"ctrl-alt-cmd-w": "workspace::CloseInactiveTabsAndPanes",
|
||||||
"cmd-k u": "pane::CloseCleanItems",
|
"cmd-k u": "pane::CloseCleanItems",
|
||||||
"cmd-k cmd-w": "pane::CloseAllItems",
|
"cmd-k cmd-w": "pane::CloseAllItems",
|
||||||
"cmd-shift-w": "workspace::CloseWindow",
|
"cmd-shift-w": "workspace::CloseWindow",
|
||||||
|
|
|
@ -746,6 +746,10 @@ impl Pane {
|
||||||
_: &CloseAllItems,
|
_: &CloseAllItems,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Option<Task<Result<()>>> {
|
) -> Option<Task<Result<()>>> {
|
||||||
|
if self.items.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
Some(self.close_items(cx, move |_| true))
|
Some(self.close_items(cx, move |_| true))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ use drag_and_drop::DragAndDrop;
|
||||||
use futures::{
|
use futures::{
|
||||||
channel::{mpsc, oneshot},
|
channel::{mpsc, oneshot},
|
||||||
future::try_join_all,
|
future::try_join_all,
|
||||||
|
stream::FuturesUnordered,
|
||||||
FutureExt, StreamExt,
|
FutureExt, StreamExt,
|
||||||
};
|
};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
|
@ -122,7 +123,7 @@ actions!(
|
||||||
NewFile,
|
NewFile,
|
||||||
NewWindow,
|
NewWindow,
|
||||||
CloseWindow,
|
CloseWindow,
|
||||||
CloseInactiveEditors,
|
CloseInactiveTabsAndPanes,
|
||||||
AddFolderToProject,
|
AddFolderToProject,
|
||||||
Unfollow,
|
Unfollow,
|
||||||
Save,
|
Save,
|
||||||
|
@ -240,7 +241,7 @@ pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
|
||||||
|
|
||||||
cx.add_async_action(Workspace::follow_next_collaborator);
|
cx.add_async_action(Workspace::follow_next_collaborator);
|
||||||
cx.add_async_action(Workspace::close);
|
cx.add_async_action(Workspace::close);
|
||||||
cx.add_async_action(Workspace::close_inactive_editors);
|
cx.add_async_action(Workspace::close_inactive_items_and_panes);
|
||||||
cx.add_global_action(Workspace::close_global);
|
cx.add_global_action(Workspace::close_global);
|
||||||
cx.add_global_action(restart);
|
cx.add_global_action(restart);
|
||||||
cx.add_async_action(Workspace::save_all);
|
cx.add_async_action(Workspace::save_all);
|
||||||
|
@ -1635,32 +1636,43 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close_inactive_editors(
|
pub fn close_inactive_items_and_panes(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: &CloseInactiveEditors,
|
_: &CloseInactiveTabsAndPanes,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Option<Task<Result<()>>> {
|
) -> Option<Task<Result<()>>> {
|
||||||
let current_pane = self.active_pane();
|
let current_pane = self.active_pane();
|
||||||
|
|
||||||
// let mut tasks: Vec<Task<Result<()>>> = Vec::new();
|
let mut tasks = Vec::new();
|
||||||
current_pane
|
|
||||||
.update(cx, |pane, cx| {
|
if let Some(current_pane_close) = current_pane.update(cx, |pane, cx| {
|
||||||
pane.close_inactive_items(&CloseInactiveItems, cx).unwrap()
|
pane.close_inactive_items(&CloseInactiveItems, cx)
|
||||||
})
|
}) {
|
||||||
.detach_and_log_err(cx);
|
tasks.push(current_pane_close);
|
||||||
|
};
|
||||||
|
|
||||||
for pane in self.panes() {
|
for pane in self.panes() {
|
||||||
if pane.id() == current_pane.id() {
|
if pane.id() == current_pane.id() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pane.update(cx, |pane: &mut Pane, cx| {
|
if let Some(close_pane_items) = pane.update(cx, |pane: &mut Pane, cx| {
|
||||||
pane.close_all_items(&CloseAllItems, cx).unwrap()
|
pane.close_all_items(&CloseAllItems, cx)
|
||||||
})
|
}) {
|
||||||
.detach_and_log_err(cx);
|
tasks.push(close_pane_items)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(Task::ready(Ok(())))
|
if tasks.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(cx.spawn(|_, _| async move {
|
||||||
|
for task in tasks {
|
||||||
|
task.await?
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_dock(&mut self, dock_side: DockPosition, cx: &mut ViewContext<Self>) {
|
pub fn toggle_dock(&mut self, dock_side: DockPosition, cx: &mut ViewContext<Self>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue