Get feedback2 compiling

Co-Authored-By: Joseph T. Lyons <19867440+JosephTLyons@users.noreply.github.com>
Co-Authored-By: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
Nate Butler 2023-11-30 16:07:54 -05:00
parent 5098fafa02
commit 8b7be8f614
8 changed files with 313 additions and 206 deletions

View file

@ -0,0 +1,164 @@
use gpui::{
div, AppContext, DismissEvent, Div, EventEmitter, FocusHandle, FocusableView, Render,
ViewContext,
};
use ui::prelude::*;
use workspace::Workspace;
use crate::feedback_editor::GiveFeedback;
pub struct FeedbackModal {
// editor: View<FeedbackEditor>,
tmp_focus_handle: FocusHandle, // TODO: should be editor.focus_handle(cx)
}
impl FocusableView for FeedbackModal {
fn focus_handle(&self, _cx: &AppContext) -> FocusHandle {
self.tmp_focus_handle.clone()
}
}
impl EventEmitter<DismissEvent> for FeedbackModal {}
impl FeedbackModal {
pub fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
let _handle = cx.view().downgrade();
workspace.register_action(move |workspace, _: &GiveFeedback, cx| {
workspace.toggle_modal(cx, move |cx| FeedbackModal::new(cx));
});
}
pub fn new(cx: &mut ViewContext<Self>) -> Self {
Self {
tmp_focus_handle: cx.focus_handle(),
}
}
// fn release(&mut self, cx: &mut WindowContext) {
// let scroll_position = self.prev_scroll_position.take();
// self.active_editor.update(cx, |editor, cx| {
// editor.highlight_rows(None);
// if let Some(scroll_position) = scroll_position {
// editor.set_scroll_position(scroll_position, cx);
// }
// cx.notify();
// })
// }
// fn on_feedback_editor_event(
// &mut self,
// _: View<Editor>,
// event: &editor::EditorEvent,
// cx: &mut ViewContext<Self>,
// ) {
// match event {
// // todo!() this isn't working...
// editor::EditorEvent::Blurred => cx.emit(DismissEvent),
// editor::EditorEvent::BufferEdited { .. } => self.highlight_current_line(cx),
// _ => {}
// }
// }
// fn highlight_current_line(&mut self, cx: &mut ViewContext<Self>) {
// if let Some(point) = self.point_from_query(cx) {
// self.active_editor.update(cx, |active_editor, cx| {
// let snapshot = active_editor.snapshot(cx).display_snapshot;
// let point = snapshot.buffer_snapshot.clip_point(point, Bias::Left);
// let display_point = point.to_display_point(&snapshot);
// let row = display_point.row();
// active_editor.highlight_rows(Some(row..row + 1));
// active_editor.request_autoscroll(Autoscroll::center(), cx);
// });
// cx.notify();
// }
// }
// fn point_from_query(&self, cx: &ViewContext<Self>) -> Option<Point> {
// let line_editor = self.line_editor.read(cx).text(cx);
// let mut components = line_editor
// .splitn(2, FILE_ROW_COLUMN_DELIMITER)
// .map(str::trim)
// .fuse();
// let row = components.next().and_then(|row| row.parse::<u32>().ok())?;
// let column = components.next().and_then(|col| col.parse::<u32>().ok());
// Some(Point::new(
// row.saturating_sub(1),
// column.unwrap_or(0).saturating_sub(1),
// ))
// }
// fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
// cx.emit(DismissEvent);
// }
// fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {
// if let Some(point) = self.point_from_query(cx) {
// self.active_editor.update(cx, |editor, cx| {
// let snapshot = editor.snapshot(cx).display_snapshot;
// let point = snapshot.buffer_snapshot.clip_point(point, Bias::Left);
// editor.change_selections(Some(Autoscroll::center()), cx, |s| {
// s.select_ranges([point..point])
// });
// editor.focus(cx);
// cx.notify();
// });
// self.prev_scroll_position.take();
// }
// cx.emit(DismissEvent);
// }
}
impl Render for FeedbackModal {
type Element = Div;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
div().elevation_3(cx).w_1_2().h_2_3().child(
v_stack()
.w_full()
.child(h_stack().child("header"))
.child("editor"),
// Header
// - has some info, maybe some links
// Body
// - Markdown Editor
// - Email address
// Footer
// - CTA buttons (Send, Cancel)
)
// div()
// .elevation_2(cx)
// .key_context(
// "FeedbackModal
// ",
// )
// .on_action(cx.listener(Self::cancel))
// .on_action(cx.listener(Self::confirm))
// .w_96()
// .child(
// v_stack()
// .px_1()
// .pt_0p5()
// .gap_px()
// .child(
// v_stack()
// .py_0p5()
// .px_1()
// .child(div().px_1().py_0p5().child(self.line_editor.clone())),
// )
// .child(
// div()
// .h_px()
// .w_full()
// .bg(cx.theme().colors().element_background),
// )
// .child(
// h_stack()
// .justify_between()
// .px_2()
// .py_1()
// .child(Label::new(self.current_text.clone()).color(Color::Muted)),
// ),
// )
}
}