Move action to the workspace so I can use it from the pane

Danilo Leal created

Change summary

crates/editor/src/actions.rs      |  2 --
crates/editor/src/editor.rs       |  7 ++++++-
crates/workspace/src/workspace.rs | 10 ++++++++++
3 files changed, 16 insertions(+), 3 deletions(-)

Detailed changes

crates/editor/src/actions.rs 🔗

@@ -845,8 +845,6 @@ actions!(
         UnwrapSyntaxNode,
         /// Wraps selections in tag specified by language.
         WrapSelectionsInTag,
-        /// Toggles read-only mode for the current buffer.
-        ToggleReadOnly,
     ]
 );
 

crates/editor/src/editor.rs 🔗

@@ -11007,7 +11007,12 @@ impl Editor {
         });
     }
 
-    pub fn toggle_read_only(&mut self, _: &ToggleReadOnly, _: &mut Window, cx: &mut Context<Self>) {
+    pub fn toggle_read_only(
+        &mut self,
+        _: &workspace::ToggleReadOnlyFile,
+        _: &mut Window,
+        cx: &mut Context<Self>,
+    ) {
         if let Some(buffer) = self.buffer.read(cx).as_singleton() {
             buffer.update(cx, |buffer, cx| {
                 buffer.set_capability(

crates/workspace/src/workspace.rs 🔗

@@ -281,6 +281,8 @@ actions!(
         ToggleRightDock,
         /// Toggles zoom on the active pane.
         ToggleZoom,
+        /// Toggles read-only mode for the active item (if supported by that item).
+        ToggleReadOnlyFile,
         /// Zooms in on the active pane.
         ZoomIn,
         /// Zooms out of the active pane.
@@ -6249,6 +6251,14 @@ impl Workspace {
                     cx.propagate();
                 },
             ))
+            .on_action(
+                cx.listener(|workspace, _: &ToggleReadOnlyFile, window, cx| {
+                    let pane = workspace.active_pane().clone();
+                    if let Some(item) = pane.read(cx).active_item() {
+                        item.toggle_read_only(window, cx);
+                    }
+                }),
+            )
             .on_action(cx.listener(Workspace::cancel))
     }