Remove project strong reference from git panel's log output editor (#27496)
A readonly buffer built from a static `&str` output does not need rich project-based capabilities, and leaking projects in global git panel might be dangerous. Also adds readonly capability to the buffer, as `editor.set_read_only(true);` API is a separate thing. Release Notes: - N/A
This commit is contained in:
parent
1463b4d201
commit
0a3c8a6790
1 changed files with 6 additions and 12 deletions
|
@ -2495,7 +2495,6 @@ impl GitPanel {
|
||||||
{
|
{
|
||||||
return; // Hide the cancelled by user message
|
return; // Hide the cancelled by user message
|
||||||
} else {
|
} else {
|
||||||
let project = self.project.clone();
|
|
||||||
workspace.update(cx, |workspace, cx| {
|
workspace.update(cx, |workspace, cx| {
|
||||||
let workspace_weak = cx.weak_entity();
|
let workspace_weak = cx.weak_entity();
|
||||||
let toast =
|
let toast =
|
||||||
|
@ -2503,13 +2502,10 @@ impl GitPanel {
|
||||||
this.icon(ToastIcon::new(IconName::XCircle).color(Color::Error))
|
this.icon(ToastIcon::new(IconName::XCircle).color(Color::Error))
|
||||||
.action("View Log", move |window, cx| {
|
.action("View Log", move |window, cx| {
|
||||||
let message = message.clone();
|
let message = message.clone();
|
||||||
let project = project.clone();
|
|
||||||
let action = action.clone();
|
let action = action.clone();
|
||||||
workspace_weak
|
workspace_weak
|
||||||
.update(cx, move |workspace, cx| {
|
.update(cx, move |workspace, cx| {
|
||||||
Self::open_output(
|
Self::open_output(action, workspace, &message, window, cx)
|
||||||
project, action, workspace, &message, window, cx,
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
})
|
})
|
||||||
|
@ -2531,21 +2527,17 @@ impl GitPanel {
|
||||||
|
|
||||||
let status_toast = StatusToast::new(message, cx, move |this, _cx| {
|
let status_toast = StatusToast::new(message, cx, move |this, _cx| {
|
||||||
use remote_output::SuccessStyle::*;
|
use remote_output::SuccessStyle::*;
|
||||||
let project = self.project.clone();
|
|
||||||
match style {
|
match style {
|
||||||
Toast { .. } => this,
|
Toast { .. } => this,
|
||||||
ToastWithLog { output } => this
|
ToastWithLog { output } => this
|
||||||
.icon(ToastIcon::new(IconName::GitBranchSmall).color(Color::Muted))
|
.icon(ToastIcon::new(IconName::GitBranchSmall).color(Color::Muted))
|
||||||
.action("View Log", move |window, cx| {
|
.action("View Log", move |window, cx| {
|
||||||
let output = output.clone();
|
let output = output.clone();
|
||||||
let project = project.clone();
|
|
||||||
let output =
|
let output =
|
||||||
format!("stdout:\n{}\nstderr:\n{}", output.stdout, output.stderr);
|
format!("stdout:\n{}\nstderr:\n{}", output.stdout, output.stderr);
|
||||||
workspace_weak
|
workspace_weak
|
||||||
.update(cx, move |workspace, cx| {
|
.update(cx, move |workspace, cx| {
|
||||||
Self::open_output(
|
Self::open_output(operation, workspace, &output, window, cx)
|
||||||
project, operation, workspace, &output, window, cx,
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}),
|
}),
|
||||||
|
@ -2559,7 +2551,6 @@ impl GitPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_output(
|
fn open_output(
|
||||||
project: Entity<Project>,
|
|
||||||
operation: impl Into<SharedString>,
|
operation: impl Into<SharedString>,
|
||||||
workspace: &mut Workspace,
|
workspace: &mut Workspace,
|
||||||
output: &str,
|
output: &str,
|
||||||
|
@ -2568,8 +2559,11 @@ impl GitPanel {
|
||||||
) {
|
) {
|
||||||
let operation = operation.into();
|
let operation = operation.into();
|
||||||
let buffer = cx.new(|cx| Buffer::local(output, cx));
|
let buffer = cx.new(|cx| Buffer::local(output, cx));
|
||||||
|
buffer.update(cx, |buffer, cx| {
|
||||||
|
buffer.set_capability(language::Capability::ReadOnly, cx);
|
||||||
|
});
|
||||||
let editor = cx.new(|cx| {
|
let editor = cx.new(|cx| {
|
||||||
let mut editor = Editor::for_buffer(buffer, Some(project), window, cx);
|
let mut editor = Editor::for_buffer(buffer, None, window, cx);
|
||||||
editor.buffer().update(cx, |buffer, cx| {
|
editor.buffer().update(cx, |buffer, cx| {
|
||||||
buffer.set_title(format!("Output from git {operation}"), cx);
|
buffer.set_title(format!("Output from git {operation}"), cx);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue