diff --git a/crates/repl/src/repl_sessions_ui.rs b/crates/repl/src/repl_sessions_ui.rs index 1e9792b1f6fd6ab6c2ed1402b0292495251ff3c4..978d495ae74813aad652886c2f383e474f4720ed 100644 --- a/crates/repl/src/repl_sessions_ui.rs +++ b/crates/repl/src/repl_sessions_ui.rs @@ -61,94 +61,97 @@ pub fn init(cx: &mut AppContext) { return; } - let is_local_project = editor - .workspace() - .map(|workspace| workspace.read(cx).project().read(cx).is_local()) - .unwrap_or(false); + cx.defer(|editor, cx| { + let workspace = Workspace::for_window(cx); - if !is_local_project { - return; - } + let is_local_project = workspace + .map(|workspace| workspace.read(cx).project().read(cx).is_local()) + .unwrap_or(false); - let editor_handle = cx.view().downgrade(); + if !is_local_project { + return; + } - editor - .register_action({ - let editor_handle = editor_handle.clone(); - move |_: &Run, cx| { - if !JupyterSettings::enabled(cx) { - return; - } + let editor_handle = cx.view().downgrade(); - crate::run(editor_handle.clone(), true, cx).log_err(); - } - }) - .detach(); - - editor - .register_action({ - let editor_handle = editor_handle.clone(); - move |_: &RunInPlace, cx| { - if !JupyterSettings::enabled(cx) { - return; - } + editor + .register_action({ + let editor_handle = editor_handle.clone(); + move |_: &Run, cx| { + if !JupyterSettings::enabled(cx) { + return; + } - crate::run(editor_handle.clone(), false, cx).log_err(); - } - }) - .detach(); - - editor - .register_action({ - let editor_handle = editor_handle.clone(); - move |_: &ClearOutputs, cx| { - if !JupyterSettings::enabled(cx) { - return; + crate::run(editor_handle.clone(), true, cx).log_err(); } - - crate::clear_outputs(editor_handle.clone(), cx); - } - }) - .detach(); - - editor - .register_action({ - let editor_handle = editor_handle.clone(); - move |_: &Interrupt, cx| { - if !JupyterSettings::enabled(cx) { - return; + }) + .detach(); + + editor + .register_action({ + let editor_handle = editor_handle.clone(); + move |_: &RunInPlace, cx| { + if !JupyterSettings::enabled(cx) { + return; + } + + crate::run(editor_handle.clone(), false, cx).log_err(); } - - crate::interrupt(editor_handle.clone(), cx); - } - }) - .detach(); - - editor - .register_action({ - let editor_handle = editor_handle.clone(); - move |_: &Shutdown, cx| { - if !JupyterSettings::enabled(cx) { - return; + }) + .detach(); + + editor + .register_action({ + let editor_handle = editor_handle.clone(); + move |_: &ClearOutputs, cx| { + if !JupyterSettings::enabled(cx) { + return; + } + + crate::clear_outputs(editor_handle.clone(), cx); } - - crate::shutdown(editor_handle.clone(), cx); - } - }) - .detach(); - - editor - .register_action({ - let editor_handle = editor_handle.clone(); - move |_: &Restart, cx| { - if !JupyterSettings::enabled(cx) { - return; + }) + .detach(); + + editor + .register_action({ + let editor_handle = editor_handle.clone(); + move |_: &Interrupt, cx| { + if !JupyterSettings::enabled(cx) { + return; + } + + crate::interrupt(editor_handle.clone(), cx); } - - crate::restart(editor_handle.clone(), cx); - } - }) - .detach(); + }) + .detach(); + + editor + .register_action({ + let editor_handle = editor_handle.clone(); + move |_: &Shutdown, cx| { + if !JupyterSettings::enabled(cx) { + return; + } + + crate::shutdown(editor_handle.clone(), cx); + } + }) + .detach(); + + editor + .register_action({ + let editor_handle = editor_handle.clone(); + move |_: &Restart, cx| { + if !JupyterSettings::enabled(cx) { + return; + } + + crate::restart(editor_handle.clone(), cx); + } + }) + .detach(); + }); }) .detach(); } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index a289e76134c7fbead9f10b26f104ae8098f36a75..6e2ccafaa107152be2e080e801cbe646cbe4ff71 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -4540,6 +4540,11 @@ impl Workspace { .children(leader_border), ) } + + pub fn for_window(cx: &mut WindowContext) -> Option> { + let window = cx.window_handle().downcast::()?; + cx.read_window(&window, |workspace, _| workspace).ok() + } } fn leader_border_for_pane(