Add a run menu (#32505)

As part of this I refactored the logic that enabled/disabled actions in
the debugger to happen at action registration time instead of using
command palette filters. This allows the menu to grey out actions correctly.

Release Notes:

- Add a "Run" menu to contain tasks and debugger
This commit is contained in:
Conrad Irwin 2025-06-10 19:57:46 -06:00 committed by GitHub
parent 444f797827
commit 00a8101016
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 296 additions and 369 deletions

View file

@ -35,7 +35,6 @@ assets.workspace = true
client.workspace = true
clock.workspace = true
collections.workspace = true
command_palette_hooks.workspace = true
convert_case.workspace = true
dap.workspace = true
db.workspace = true

View file

@ -243,6 +243,8 @@ impl_actions!(
]
);
actions!(debugger, [RunToCursor, EvaluateSelectedText]);
actions!(
editor,
[
@ -426,8 +428,6 @@ actions!(
DisableBreakpoint,
EnableBreakpoint,
EditLogBreakpoint,
DebuggerRunToCursor,
DebuggerEvaluateSelectedText,
ToggleAutoSignatureHelp,
ToggleGitBlameInline,
OpenGitBlameCommit,

View file

@ -1054,8 +1054,9 @@ pub struct Editor {
style: Option<EditorStyle>,
text_style_refinement: Option<TextStyleRefinement>,
next_editor_action_id: EditorActionId,
editor_actions:
Rc<RefCell<BTreeMap<EditorActionId, Box<dyn Fn(&mut Window, &mut Context<Self>)>>>>,
editor_actions: Rc<
RefCell<BTreeMap<EditorActionId, Box<dyn Fn(&Editor, &mut Window, &mut Context<Self>)>>>,
>,
use_autoclose: bool,
use_auto_surround: bool,
auto_replace_emoji_shortcode: bool,
@ -7541,8 +7542,7 @@ impl Editor {
"Set Breakpoint"
};
let run_to_cursor = command_palette_hooks::CommandPaletteFilter::try_global(cx)
.map_or(false, |filter| !filter.is_hidden(&DebuggerRunToCursor));
let run_to_cursor = window.is_action_available(&RunToCursor, cx);
let toggle_state_msg = breakpoint.as_ref().map_or(None, |bp| match bp.1.state {
BreakpointState::Enabled => Some("Disable"),
@ -7566,7 +7566,7 @@ impl Editor {
})
.ok();
window.dispatch_action(Box::new(DebuggerRunToCursor), cx);
window.dispatch_action(Box::new(RunToCursor), cx);
})
.separator()
})
@ -19819,6 +19819,21 @@ impl Editor {
}
}
pub fn register_action_renderer(
&mut self,
listener: impl Fn(&Editor, &mut Window, &mut Context<Editor>) + 'static,
) -> Subscription {
let id = self.next_editor_action_id.post_inc();
self.editor_actions
.borrow_mut()
.insert(id, Box::new(listener));
let editor_actions = self.editor_actions.clone();
Subscription::new(move || {
editor_actions.borrow_mut().remove(&id);
})
}
pub fn register_action<A: Action>(
&mut self,
listener: impl Fn(&A, &mut Window, &mut App) + 'static,
@ -19827,7 +19842,7 @@ impl Editor {
let listener = Arc::new(listener);
self.editor_actions.borrow_mut().insert(
id,
Box::new(move |window, _| {
Box::new(move |_, window, _| {
let listener = listener.clone();
window.on_action(TypeId::of::<A>(), move |action, phase, window, cx| {
let action = action.downcast_ref().unwrap();

View file

@ -187,7 +187,7 @@ impl EditorElement {
let editor = &self.editor;
editor.update(cx, |editor, cx| {
for action in editor.editor_actions.borrow().values() {
(action)(window, cx)
(action)(editor, window, cx)
}
});

View file

@ -1,8 +1,8 @@
use crate::{
Copy, CopyAndTrim, CopyPermalinkToLine, Cut, DebuggerEvaluateSelectedText, DisplayPoint,
DisplaySnapshot, Editor, FindAllReferences, GoToDeclaration, GoToDefinition,
GoToImplementation, GoToTypeDefinition, Paste, Rename, RevealInFileManager, SelectMode,
SelectionExt, ToDisplayPoint, ToggleCodeActions,
Copy, CopyAndTrim, CopyPermalinkToLine, Cut, DisplayPoint, DisplaySnapshot, Editor,
EvaluateSelectedText, FindAllReferences, GoToDeclaration, GoToDefinition, GoToImplementation,
GoToTypeDefinition, Paste, Rename, RevealInFileManager, SelectMode, SelectionExt,
ToDisplayPoint, ToggleCodeActions,
actions::{Format, FormatSelections},
selections_collection::SelectionsCollection,
};
@ -199,17 +199,14 @@ pub fn deploy_context_menu(
.is_some()
});
let evaluate_selection = command_palette_hooks::CommandPaletteFilter::try_global(cx)
.map_or(false, |filter| {
!filter.is_hidden(&DebuggerEvaluateSelectedText)
});
let evaluate_selection = window.is_action_available(&EvaluateSelectedText, cx);
ui::ContextMenu::build(window, cx, |menu, _window, _cx| {
let builder = menu
.on_blur_subscription(Subscription::new(|| {}))
.when(evaluate_selection && has_selections, |builder| {
builder
.action("Evaluate Selection", Box::new(DebuggerEvaluateSelectedText))
.action("Evaluate Selection", Box::new(EvaluateSelectedText))
.separator()
})
.action("Go to Definition", Box::new(GoToDefinition))