Skip to content

Commit cdc2736

Browse files
Move the invalid encoding UI from project to workspace
1 parent f3a6930 commit cdc2736

File tree

3 files changed

+81
-74
lines changed

3 files changed

+81
-74
lines changed

crates/fs/src/fs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub mod fs_watcher;
77
use anyhow::{Context as _, Result, anyhow};
88
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
99
use ashpd::desktop::trash;
10-
use encodings::Encoding;
1110
use futures::stream::iter;
1211
use gpui::App;
1312
use gpui::BackgroundExecutor;

crates/project/src/invalid_item_view.rs

Lines changed: 14 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ impl Focusable for InvalidItemView {
7878
impl Render for InvalidItemView {
7979
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl gpui::IntoElement {
8080
let abs_path = self.abs_path.clone();
81-
let path0 = self.abs_path.clone();
82-
let path1 = self.abs_path.clone();
8381

8482
v_flex()
8583
.size_full()
@@ -103,63 +101,20 @@ impl Render for InvalidItemView {
103101
),
104102
)
105103
.when(self.is_local, |contents| {
106-
contents
107-
.child(
108-
h_flex().justify_center().child(
109-
Button::new("open-with-system", "Open in Default App")
110-
.on_click(move |_, _, cx| {
111-
cx.open_with_system(&abs_path);
112-
})
113-
.style(ButtonStyle::Outlined)
114-
.key_binding(KeyBinding::for_action(
115-
&OpenWithSystem,
116-
window,
117-
cx,
118-
)),
119-
),
120-
)
121-
.child(
122-
h_flex()
123-
.justify_center()
124-
.child(
125-
Button::new(
126-
"open-with-encoding",
127-
"Open With a Different Encoding",
128-
)
129-
.style(ButtonStyle::Outlined)
130-
.on_click(
131-
move |_, window, cx| {
132-
window.dispatch_action(
133-
Box::new(
134-
zed_actions::encodings_ui::Toggle(
135-
path0.clone(),
136-
),
137-
),
138-
cx,
139-
)
140-
},
141-
),
142-
)
143-
.child(
144-
Button::new(
145-
"accept-risk-and-open",
146-
"Accept the Risk and Open",
147-
)
148-
.style(ButtonStyle::Tinted(TintColor::Warning))
149-
.on_click(
150-
move |_, window, cx| {
151-
window.dispatch_action(
152-
Box::new(
153-
zed_actions::encodings_ui::ForceOpen(
154-
path1.clone(),
155-
),
156-
),
157-
cx,
158-
);
159-
},
160-
),
161-
),
162-
)
104+
contents.child(
105+
h_flex().justify_center().child(
106+
Button::new("open-with-system", "Open in Default App")
107+
.on_click(move |_, _, cx| {
108+
cx.open_with_system(&abs_path);
109+
})
110+
.style(ButtonStyle::Outlined)
111+
.key_binding(KeyBinding::for_action(
112+
&OpenWithSystem,
113+
window,
114+
cx,
115+
)),
116+
),
117+
)
163118
}),
164119
),
165120
)

crates/workspace/src/invalid_item_view.rs

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{path::Path, sync::Arc};
2+
use ui::TintColor;
23

3-
use gpui::{EventEmitter, FocusHandle, Focusable};
4+
use gpui::{EventEmitter, FocusHandle, Focusable, div};
45
use ui::{
56
App, Button, ButtonCommon, ButtonStyle, Clickable, Context, FluentBuilder, InteractiveElement,
67
KeyBinding, Label, LabelCommon, LabelSize, ParentElement, Render, SharedString, Styled as _,
@@ -77,6 +78,9 @@ impl Focusable for InvalidItemView {
7778
impl Render for InvalidItemView {
7879
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl gpui::IntoElement {
7980
let abs_path = self.abs_path.clone();
81+
let path0 = self.abs_path.clone();
82+
let path1 = self.abs_path.clone();
83+
8084
v_flex()
8185
.size_full()
8286
.track_focus(&self.focus_handle(cx))
@@ -91,21 +95,70 @@ impl Render for InvalidItemView {
9195
.gap_2()
9296
.child(h_flex().justify_center().child("Could not open file"))
9397
.child(
94-
h_flex()
95-
.justify_center()
96-
.child(Label::new(self.error.clone()).size(LabelSize::Small)),
98+
h_flex().justify_center().child(
99+
div()
100+
.whitespace_normal()
101+
.text_center()
102+
.child(Label::new(self.error.clone()).size(LabelSize::Small)),
103+
),
97104
)
98105
.when(self.is_local, |contents| {
99-
contents.child(
100-
h_flex().justify_center().child(
101-
Button::new("open-with-system", "Open in Default App")
102-
.on_click(move |_, _, cx| {
103-
cx.open_with_system(&abs_path);
104-
})
105-
.style(ButtonStyle::Outlined)
106-
.key_binding(KeyBinding::for_action(&OpenWithSystem, cx)),
107-
),
108-
)
106+
contents
107+
.child(
108+
h_flex().justify_center().child(
109+
Button::new("open-with-system", "Open in Default App")
110+
.on_click(move |_, _, cx| {
111+
cx.open_with_system(&abs_path);
112+
})
113+
.style(ButtonStyle::Outlined)
114+
.key_binding(KeyBinding::for_action(
115+
&OpenWithSystem,
116+
cx,
117+
)),
118+
),
119+
)
120+
.child(
121+
h_flex()
122+
.justify_center()
123+
.child(
124+
Button::new(
125+
"open-with-encoding",
126+
"Open With a Different Encoding",
127+
)
128+
.style(ButtonStyle::Outlined)
129+
.on_click(
130+
move |_, window, cx| {
131+
window.dispatch_action(
132+
Box::new(
133+
zed_actions::encodings_ui::Toggle(
134+
path0.clone(),
135+
),
136+
),
137+
cx,
138+
)
139+
},
140+
),
141+
)
142+
.child(
143+
Button::new(
144+
"accept-risk-and-open",
145+
"Accept the Risk and Open",
146+
)
147+
.style(ButtonStyle::Tinted(TintColor::Warning))
148+
.on_click(
149+
move |_, window, cx| {
150+
window.dispatch_action(
151+
Box::new(
152+
zed_actions::encodings_ui::ForceOpen(
153+
path1.clone(),
154+
),
155+
),
156+
cx,
157+
);
158+
},
159+
),
160+
),
161+
)
109162
}),
110163
),
111164
)

0 commit comments

Comments
 (0)