workspace: Improve error handling when dropping a file that cannot be opened into the workspace pane (#15613)
This PR can improve the UX when dropping a file that cannot be opened into the workspace pane. Previously, nothing happened without any messages when such error occurred, which could be awkward for users. Additionally the pane was being split even though the file failed to open. Here's a screen recording demonstrating the previous/updated behavior: https://github.com/user-attachments/assets/cfdf3488-9464-4568-b16a-9b87718bd729 Changes: - It now displays an error message if a file cannot be opened. - Updated the logic to first try to open the file. The pane splits only if the file opening process is successful. Release Notes: - Improved error handling when opening files in the workspace pane. An error message will now be displayed if the file cannot be opened. - Fixed an issue where unnecessary pane splitting occurred when a file fails to open.
This commit is contained in:
parent
c251a50e41
commit
b67404323c
1 changed files with 35 additions and 8 deletions
|
@ -3,6 +3,7 @@ use crate::{
|
|||
ClosePosition, Item, ItemHandle, ItemSettings, PreviewTabsSettings, TabContentParams,
|
||||
WeakItemHandle,
|
||||
},
|
||||
notifications::NotifyResultExt,
|
||||
toolbar::Toolbar,
|
||||
workspace_settings::{AutosaveSetting, TabBarSettings, WorkspaceSettings},
|
||||
CloseWindow, CopyPath, CopyRelativePath, NewFile, NewTerminal, OpenInTerminal, OpenTerminal,
|
||||
|
@ -2109,13 +2110,32 @@ impl Pane {
|
|||
.read(cx)
|
||||
.path_for_entry(project_entry_id, cx)
|
||||
{
|
||||
if let Some(split_direction) = split_direction {
|
||||
to_pane = workspace.split_pane(to_pane, split_direction, cx);
|
||||
}
|
||||
workspace
|
||||
.open_path(path, Some(to_pane.downgrade()), true, cx)
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
let load_path_task = workspace.load_path(path, cx);
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
if let Some((project_entry_id, build_item)) =
|
||||
load_path_task.await.notify_async_err(&mut cx)
|
||||
{
|
||||
workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
if let Some(split_direction) = split_direction {
|
||||
to_pane =
|
||||
workspace.split_pane(to_pane, split_direction, cx);
|
||||
}
|
||||
to_pane.update(cx, |pane, cx| {
|
||||
pane.open_item(
|
||||
project_entry_id,
|
||||
true,
|
||||
false,
|
||||
cx,
|
||||
build_item,
|
||||
)
|
||||
})
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
};
|
||||
});
|
||||
})
|
||||
.log_err();
|
||||
|
@ -2186,7 +2206,14 @@ impl Pane {
|
|||
})
|
||||
.ok()
|
||||
{
|
||||
let _opened_items: Vec<_> = open_task.await;
|
||||
let opened_items: Vec<_> = open_task.await;
|
||||
_ = workspace.update(&mut cx, |workspace, cx| {
|
||||
for item in opened_items.into_iter().flatten() {
|
||||
if let Err(e) = item {
|
||||
workspace.show_error(&e, cx);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue