Register repl actions with editor after session started (#20396)
Makes repl actions that are specific to running kernels only come up after a session has been started at least once for the editor. Release Notes: - Only show session oriented `repl::` actions for editors after a session has been created
This commit is contained in:
parent
edb89d8d11
commit
706c385c24
3 changed files with 66 additions and 53 deletions
|
@ -10,7 +10,9 @@ use language::{BufferSnapshot, Language, LanguageName, Point};
|
||||||
|
|
||||||
use crate::repl_store::ReplStore;
|
use crate::repl_store::ReplStore;
|
||||||
use crate::session::SessionEvent;
|
use crate::session::SessionEvent;
|
||||||
use crate::{KernelSpecification, Session};
|
use crate::{
|
||||||
|
ClearOutputs, Interrupt, JupyterSettings, KernelSpecification, Restart, Session, Shutdown,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn assign_kernelspec(
|
pub fn assign_kernelspec(
|
||||||
kernel_specification: KernelSpecification,
|
kernel_specification: KernelSpecification,
|
||||||
|
@ -240,6 +242,60 @@ pub fn restart(editor: WeakView<Editor>, cx: &mut WindowContext) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn setup_editor_session_actions(editor: &mut Editor, editor_handle: WeakView<Editor>) {
|
||||||
|
editor
|
||||||
|
.register_action({
|
||||||
|
let editor_handle = editor_handle.clone();
|
||||||
|
move |_: &ClearOutputs, cx| {
|
||||||
|
if !JupyterSettings::enabled(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
crate::interrupt(editor_handle.clone(), cx);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.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();
|
||||||
|
}
|
||||||
|
|
||||||
fn cell_range(buffer: &BufferSnapshot, start_row: u32, end_row: u32) -> Range<Point> {
|
fn cell_range(buffer: &BufferSnapshot, start_row: u32, end_row: u32) -> Range<Point> {
|
||||||
let mut snippet_end_row = end_row;
|
let mut snippet_end_row = end_row;
|
||||||
while buffer.is_line_blank(snippet_end_row) && snippet_end_row > start_row {
|
while buffer.is_line_blank(snippet_end_row) && snippet_end_row > start_row {
|
||||||
|
|
|
@ -97,58 +97,6 @@ pub fn init(cx: &mut AppContext) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.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);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
|
|
||||||
editor
|
|
||||||
.register_action({
|
|
||||||
let editor_handle = editor_handle.clone();
|
|
||||||
move |_: &Interrupt, cx| {
|
|
||||||
if !JupyterSettings::enabled(cx) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
crate::interrupt(editor_handle.clone(), cx);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.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();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::components::KernelListItem;
|
use crate::components::KernelListItem;
|
||||||
|
use crate::setup_editor_session_actions;
|
||||||
use crate::{
|
use crate::{
|
||||||
kernels::{Kernel, KernelSpecification, RunningKernel},
|
kernels::{Kernel, KernelSpecification, RunningKernel},
|
||||||
outputs::{ExecutionStatus, ExecutionView},
|
outputs::{ExecutionStatus, ExecutionView},
|
||||||
|
@ -207,6 +208,14 @@ impl Session {
|
||||||
None => Subscription::new(|| {}),
|
None => Subscription::new(|| {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let editor_handle = editor.clone();
|
||||||
|
|
||||||
|
editor
|
||||||
|
.update(cx, |editor, _cx| {
|
||||||
|
setup_editor_session_actions(editor, editor_handle);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
|
||||||
let mut session = Self {
|
let mut session = Self {
|
||||||
fs,
|
fs,
|
||||||
editor,
|
editor,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue