Partially roll back refactoring
This commit is contained in:
parent
ba1c350dad
commit
4c92172cca
3 changed files with 8 additions and 15 deletions
|
@ -1530,9 +1530,7 @@ async fn test_host_disconnect(
|
||||||
|
|
||||||
// Ensure client B is not prompted to save edits when closing window after disconnecting.
|
// Ensure client B is not prompted to save edits when closing window after disconnecting.
|
||||||
let can_close = workspace_b
|
let can_close = workspace_b
|
||||||
.update(cx_b, |workspace, cx| {
|
.update(cx_b, |workspace, cx| workspace.prepare_to_close(true, cx))
|
||||||
workspace.prepare_to_close(true, workspace::SaveBehavior::PromptOnWrite, cx)
|
|
||||||
})
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(can_close);
|
assert!(can_close);
|
||||||
|
|
|
@ -1258,7 +1258,7 @@ impl Workspace {
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Option<Task<Result<()>>> {
|
) -> Option<Task<Result<()>>> {
|
||||||
let window = cx.window();
|
let window = cx.window();
|
||||||
let prepare = self.prepare_to_close(false, SaveBehavior::PromptOnWrite, cx);
|
let prepare = self.prepare_to_close(false, cx);
|
||||||
Some(cx.spawn(|_, mut cx| async move {
|
Some(cx.spawn(|_, mut cx| async move {
|
||||||
if prepare.await? {
|
if prepare.await? {
|
||||||
window.remove(&mut cx);
|
window.remove(&mut cx);
|
||||||
|
@ -1270,7 +1270,6 @@ impl Workspace {
|
||||||
pub fn prepare_to_close(
|
pub fn prepare_to_close(
|
||||||
&mut self,
|
&mut self,
|
||||||
quitting: bool,
|
quitting: bool,
|
||||||
save_behavior: SaveBehavior,
|
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Task<Result<bool>> {
|
) -> Task<Result<bool>> {
|
||||||
let active_call = self.active_call().cloned();
|
let active_call = self.active_call().cloned();
|
||||||
|
@ -1310,7 +1309,7 @@ impl Workspace {
|
||||||
|
|
||||||
Ok(this
|
Ok(this
|
||||||
.update(&mut cx, |this, cx| {
|
.update(&mut cx, |this, cx| {
|
||||||
this.save_all_internal(save_behavior, cx)
|
this.save_all_internal(SaveBehavior::PromptOnWrite, cx)
|
||||||
})?
|
})?
|
||||||
.await?)
|
.await?)
|
||||||
})
|
})
|
||||||
|
@ -1407,7 +1406,7 @@ impl Workspace {
|
||||||
let close_task = if is_remote || has_worktree || has_dirty_items {
|
let close_task = if is_remote || has_worktree || has_dirty_items {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(self.prepare_to_close(false, SaveBehavior::PromptOnWrite, cx))
|
Some(self.prepare_to_close(false, cx))
|
||||||
};
|
};
|
||||||
let app_state = self.app_state.clone();
|
let app_state = self.app_state.clone();
|
||||||
|
|
||||||
|
@ -4102,7 +4101,7 @@ pub fn restart(_: &Restart, cx: &mut AppContext) {
|
||||||
// If the user cancels any save prompt, then keep the app open.
|
// If the user cancels any save prompt, then keep the app open.
|
||||||
for window in workspace_windows {
|
for window in workspace_windows {
|
||||||
if let Some(should_close) = window.update_root(&mut cx, |workspace, cx| {
|
if let Some(should_close) = window.update_root(&mut cx, |workspace, cx| {
|
||||||
workspace.prepare_to_close(true, SaveBehavior::PromptOnWrite, cx)
|
workspace.prepare_to_close(true, cx)
|
||||||
}) {
|
}) {
|
||||||
if !should_close.await? {
|
if !should_close.await? {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -4292,9 +4291,7 @@ mod tests {
|
||||||
// When there are no dirty items, there's nothing to do.
|
// When there are no dirty items, there's nothing to do.
|
||||||
let item1 = window.add_view(cx, |_| TestItem::new());
|
let item1 = window.add_view(cx, |_| TestItem::new());
|
||||||
workspace.update(cx, |w, cx| w.add_item(Box::new(item1.clone()), cx));
|
workspace.update(cx, |w, cx| w.add_item(Box::new(item1.clone()), cx));
|
||||||
let task = workspace.update(cx, |w, cx| {
|
let task = workspace.update(cx, |w, cx| w.prepare_to_close(false, cx));
|
||||||
w.prepare_to_close(false, SaveBehavior::PromptOnWrite, cx)
|
|
||||||
});
|
|
||||||
assert!(task.await.unwrap());
|
assert!(task.await.unwrap());
|
||||||
|
|
||||||
// When there are dirty untitled items, prompt to save each one. If the user
|
// When there are dirty untitled items, prompt to save each one. If the user
|
||||||
|
@ -4309,9 +4306,7 @@ mod tests {
|
||||||
w.add_item(Box::new(item2.clone()), cx);
|
w.add_item(Box::new(item2.clone()), cx);
|
||||||
w.add_item(Box::new(item3.clone()), cx);
|
w.add_item(Box::new(item3.clone()), cx);
|
||||||
});
|
});
|
||||||
let task = workspace.update(cx, |w, cx| {
|
let task = workspace.update(cx, |w, cx| w.prepare_to_close(false, cx));
|
||||||
w.prepare_to_close(false, SaveBehavior::PromptOnWrite, cx)
|
|
||||||
});
|
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
window.simulate_prompt_answer(2, cx); // cancel
|
window.simulate_prompt_answer(2, cx); // cancel
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
|
|
|
@ -438,7 +438,7 @@ fn quit(_: &Quit, cx: &mut gpui::AppContext) {
|
||||||
// If the user cancels any save prompt, then keep the app open.
|
// If the user cancels any save prompt, then keep the app open.
|
||||||
for window in workspace_windows {
|
for window in workspace_windows {
|
||||||
if let Some(should_close) = window.update_root(&mut cx, |workspace, cx| {
|
if let Some(should_close) = window.update_root(&mut cx, |workspace, cx| {
|
||||||
workspace.prepare_to_close(true, workspace::SaveBehavior::PromptOnWrite, cx)
|
workspace.prepare_to_close(true, cx)
|
||||||
}) {
|
}) {
|
||||||
if !should_close.await? {
|
if !should_close.await? {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue