show notification if no recent projects
This commit is contained in:
parent
2d6219ebe2
commit
b020955ac4
2 changed files with 21 additions and 10 deletions
|
@ -11,7 +11,10 @@ use highlighted_workspace_location::HighlightedWorkspaceLocation;
|
||||||
use ordered_float::OrderedFloat;
|
use ordered_float::OrderedFloat;
|
||||||
use picker::{Picker, PickerDelegate};
|
use picker::{Picker, PickerDelegate};
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
use workspace::{OpenPaths, Workspace, WorkspaceLocation, WORKSPACE_DB};
|
use workspace::{
|
||||||
|
notifications::simple_message_notification::MessageNotification, OpenPaths, Workspace,
|
||||||
|
WorkspaceLocation, WORKSPACE_DB,
|
||||||
|
};
|
||||||
|
|
||||||
actions!(projects, [OpenRecent]);
|
actions!(projects, [OpenRecent]);
|
||||||
|
|
||||||
|
@ -42,7 +45,7 @@ impl RecentProjectsView {
|
||||||
|
|
||||||
fn toggle(_: &mut Workspace, _: &OpenRecent, cx: &mut ViewContext<Workspace>) {
|
fn toggle(_: &mut Workspace, _: &OpenRecent, cx: &mut ViewContext<Workspace>) {
|
||||||
cx.spawn(|workspace, mut cx| async move {
|
cx.spawn(|workspace, mut cx| async move {
|
||||||
let workspace_locations = cx
|
let workspace_locations: Vec<_> = cx
|
||||||
.background()
|
.background()
|
||||||
.spawn(async {
|
.spawn(async {
|
||||||
WORKSPACE_DB
|
WORKSPACE_DB
|
||||||
|
@ -56,12 +59,20 @@ impl RecentProjectsView {
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
workspace.update(&mut cx, |workspace, cx| {
|
workspace.update(&mut cx, |workspace, cx| {
|
||||||
workspace.toggle_modal(cx, |_, cx| {
|
if !workspace_locations.is_empty() {
|
||||||
let view = cx.add_view(|cx| Self::new(workspace_locations, cx));
|
workspace.toggle_modal(cx, |_, cx| {
|
||||||
cx.subscribe(&view, Self::on_event).detach();
|
let view = cx.add_view(|cx| Self::new(workspace_locations, cx));
|
||||||
view
|
cx.subscribe(&view, Self::on_event).detach();
|
||||||
});
|
view
|
||||||
})
|
});
|
||||||
|
} else {
|
||||||
|
workspace.show_notification(0, cx, |cx| {
|
||||||
|
cx.add_view(|_| {
|
||||||
|
MessageNotification::new_message("No recent projects to open.")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,7 +174,7 @@ pub mod simple_message_notification {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MessageNotification {
|
impl MessageNotification {
|
||||||
pub fn new_messsage<S: AsRef<str>>(message: S) -> MessageNotification {
|
pub fn new_message<S: AsRef<str>>(message: S) -> MessageNotification {
|
||||||
Self {
|
Self {
|
||||||
message: message.as_ref().to_string(),
|
message: message.as_ref().to_string(),
|
||||||
click_action: None,
|
click_action: None,
|
||||||
|
@ -320,7 +320,7 @@ where
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
workspace.show_notification(0, cx, |cx| {
|
workspace.show_notification(0, cx, |cx| {
|
||||||
cx.add_view(|_cx| {
|
cx.add_view(|_cx| {
|
||||||
simple_message_notification::MessageNotification::new_messsage(format!(
|
simple_message_notification::MessageNotification::new_message(format!(
|
||||||
"Error: {:?}",
|
"Error: {:?}",
|
||||||
err,
|
err,
|
||||||
))
|
))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue