1use gpui::{
2 div, AppContext, DismissEvent, Div, EventEmitter, FocusHandle, FocusableView, Render,
3 ViewContext,
4};
5use ui::prelude::*;
6use workspace::Workspace;
7
8use crate::feedback_editor::GiveFeedback;
9
10pub struct FeedbackModal {
11 // editor: View<FeedbackEditor>,
12 tmp_focus_handle: FocusHandle, // TODO: should be editor.focus_handle(cx)
13}
14
15impl FocusableView for FeedbackModal {
16 fn focus_handle(&self, _cx: &AppContext) -> FocusHandle {
17 self.tmp_focus_handle.clone()
18 }
19}
20impl EventEmitter<DismissEvent> for FeedbackModal {}
21
22impl FeedbackModal {
23 pub fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
24 let _handle = cx.view().downgrade();
25 workspace.register_action(move |workspace, _: &GiveFeedback, cx| {
26 workspace.toggle_modal(cx, move |cx| FeedbackModal::new(cx));
27 });
28 }
29
30 pub fn new(cx: &mut ViewContext<Self>) -> Self {
31 Self {
32 tmp_focus_handle: cx.focus_handle(),
33 }
34 }
35
36 // fn release(&mut self, cx: &mut WindowContext) {
37 // let scroll_position = self.prev_scroll_position.take();
38 // self.active_editor.update(cx, |editor, cx| {
39 // editor.highlight_rows(None);
40 // if let Some(scroll_position) = scroll_position {
41 // editor.set_scroll_position(scroll_position, cx);
42 // }
43 // cx.notify();
44 // })
45 // }
46
47 // fn on_feedback_editor_event(
48 // &mut self,
49 // _: View<Editor>,
50 // event: &editor::EditorEvent,
51 // cx: &mut ViewContext<Self>,
52 // ) {
53 // match event {
54 // // todo!() this isn't working...
55 // editor::EditorEvent::Blurred => cx.emit(DismissEvent),
56 // editor::EditorEvent::BufferEdited { .. } => self.highlight_current_line(cx),
57 // _ => {}
58 // }
59 // }
60
61 // fn highlight_current_line(&mut self, cx: &mut ViewContext<Self>) {
62 // if let Some(point) = self.point_from_query(cx) {
63 // self.active_editor.update(cx, |active_editor, cx| {
64 // let snapshot = active_editor.snapshot(cx).display_snapshot;
65 // let point = snapshot.buffer_snapshot.clip_point(point, Bias::Left);
66 // let display_point = point.to_display_point(&snapshot);
67 // let row = display_point.row();
68 // active_editor.highlight_rows(Some(row..row + 1));
69 // active_editor.request_autoscroll(Autoscroll::center(), cx);
70 // });
71 // cx.notify();
72 // }
73 // }
74
75 // fn point_from_query(&self, cx: &ViewContext<Self>) -> Option<Point> {
76 // let line_editor = self.line_editor.read(cx).text(cx);
77 // let mut components = line_editor
78 // .splitn(2, FILE_ROW_COLUMN_DELIMITER)
79 // .map(str::trim)
80 // .fuse();
81 // let row = components.next().and_then(|row| row.parse::<u32>().ok())?;
82 // let column = components.next().and_then(|col| col.parse::<u32>().ok());
83 // Some(Point::new(
84 // row.saturating_sub(1),
85 // column.unwrap_or(0).saturating_sub(1),
86 // ))
87 // }
88
89 // fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
90 // cx.emit(DismissEvent);
91 // }
92
93 // fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {
94 // if let Some(point) = self.point_from_query(cx) {
95 // self.active_editor.update(cx, |editor, cx| {
96 // let snapshot = editor.snapshot(cx).display_snapshot;
97 // let point = snapshot.buffer_snapshot.clip_point(point, Bias::Left);
98 // editor.change_selections(Some(Autoscroll::center()), cx, |s| {
99 // s.select_ranges([point..point])
100 // });
101 // editor.focus(cx);
102 // cx.notify();
103 // });
104 // self.prev_scroll_position.take();
105 // }
106
107 // cx.emit(DismissEvent);
108 // }
109}
110
111impl Render for FeedbackModal {
112 type Element = Div;
113
114 fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
115 div().elevation_3(cx).w_1_2().h_2_3().child(
116 v_stack()
117 .w_full()
118 .child(h_stack().child("header"))
119 .child("editor"),
120 // Header
121 // - has some info, maybe some links
122 // Body
123 // - Markdown Editor
124 // - Email address
125 // Footer
126 // - CTA buttons (Send, Cancel)
127 )
128
129 // div()
130 // .elevation_2(cx)
131 // .key_context(
132 // "FeedbackModal
133 // ",
134 // )
135 // .on_action(cx.listener(Self::cancel))
136 // .on_action(cx.listener(Self::confirm))
137 // .w_96()
138 // .child(
139 // v_stack()
140 // .px_1()
141 // .pt_0p5()
142 // .gap_px()
143 // .child(
144 // v_stack()
145 // .py_0p5()
146 // .px_1()
147 // .child(div().px_1().py_0p5().child(self.line_editor.clone())),
148 // )
149 // .child(
150 // div()
151 // .h_px()
152 // .w_full()
153 // .bg(cx.theme().colors().element_background),
154 // )
155 // .child(
156 // h_stack()
157 // .justify_between()
158 // .px_2()
159 // .py_1()
160 // .child(Label::new(self.current_text.clone()).color(Color::Muted)),
161 // ),
162 // )
163 }
164}