Remove ViewContext::dispatch_action
This commit is contained in:
parent
d815fc88ae
commit
c4472b0786
41 changed files with 574 additions and 670 deletions
|
@ -11,24 +11,24 @@ use highlighted_workspace_location::HighlightedWorkspaceLocation;
|
|||
use ordered_float::OrderedFloat;
|
||||
use picker::{Picker, PickerDelegate, PickerEvent};
|
||||
use settings::Settings;
|
||||
use std::sync::{Arc, Weak};
|
||||
use std::sync::Arc;
|
||||
use workspace::{
|
||||
notifications::simple_message_notification::MessageNotification, AppState, Workspace,
|
||||
WorkspaceLocation, WORKSPACE_DB,
|
||||
notifications::simple_message_notification::MessageNotification, Workspace, WorkspaceLocation,
|
||||
WORKSPACE_DB,
|
||||
};
|
||||
|
||||
actions!(projects, [OpenRecent]);
|
||||
|
||||
pub fn init(cx: &mut AppContext, app_state: Weak<AppState>) {
|
||||
cx.add_async_action(
|
||||
move |_: &mut Workspace, _: &OpenRecent, cx: &mut ViewContext<Workspace>| {
|
||||
toggle(app_state.clone(), cx)
|
||||
},
|
||||
);
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.add_async_action(toggle);
|
||||
RecentProjects::init(cx);
|
||||
}
|
||||
|
||||
fn toggle(app_state: Weak<AppState>, cx: &mut ViewContext<Workspace>) -> Option<Task<Result<()>>> {
|
||||
fn toggle(
|
||||
_: &mut Workspace,
|
||||
_: &OpenRecent,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) -> Option<Task<Result<()>>> {
|
||||
Some(cx.spawn(|workspace, mut cx| async move {
|
||||
let workspace_locations: Vec<_> = cx
|
||||
.background()
|
||||
|
@ -49,11 +49,7 @@ fn toggle(app_state: Weak<AppState>, cx: &mut ViewContext<Workspace>) -> Option<
|
|||
let workspace = cx.weak_handle();
|
||||
cx.add_view(|cx| {
|
||||
RecentProjects::new(
|
||||
RecentProjectsDelegate::new(
|
||||
workspace,
|
||||
workspace_locations,
|
||||
app_state.clone(),
|
||||
),
|
||||
RecentProjectsDelegate::new(workspace, workspace_locations),
|
||||
cx,
|
||||
)
|
||||
.with_max_size(800., 1200.)
|
||||
|
@ -74,7 +70,6 @@ type RecentProjects = Picker<RecentProjectsDelegate>;
|
|||
struct RecentProjectsDelegate {
|
||||
workspace: WeakViewHandle<Workspace>,
|
||||
workspace_locations: Vec<WorkspaceLocation>,
|
||||
app_state: Weak<AppState>,
|
||||
selected_match_index: usize,
|
||||
matches: Vec<StringMatch>,
|
||||
}
|
||||
|
@ -83,12 +78,10 @@ impl RecentProjectsDelegate {
|
|||
fn new(
|
||||
workspace: WeakViewHandle<Workspace>,
|
||||
workspace_locations: Vec<WorkspaceLocation>,
|
||||
app_state: Weak<AppState>,
|
||||
) -> Self {
|
||||
Self {
|
||||
workspace,
|
||||
workspace_locations,
|
||||
app_state,
|
||||
selected_match_index: 0,
|
||||
matches: Default::default(),
|
||||
}
|
||||
|
@ -155,20 +148,16 @@ impl PickerDelegate for RecentProjectsDelegate {
|
|||
}
|
||||
|
||||
fn confirm(&mut self, cx: &mut ViewContext<RecentProjects>) {
|
||||
if let Some(((selected_match, workspace), app_state)) = self
|
||||
if let Some((selected_match, workspace)) = self
|
||||
.matches
|
||||
.get(self.selected_index())
|
||||
.zip(self.workspace.upgrade(cx))
|
||||
.zip(self.app_state.upgrade())
|
||||
{
|
||||
let workspace_location = &self.workspace_locations[selected_match.candidate_id];
|
||||
workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
workspace.open_workspace_for_paths(
|
||||
workspace_location.paths().as_ref().clone(),
|
||||
app_state,
|
||||
cx,
|
||||
)
|
||||
workspace
|
||||
.open_workspace_for_paths(workspace_location.paths().as_ref().clone(), cx)
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
cx.emit(PickerEvent::Dismiss);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue