Get following working

Restore a single event type on Item trait, so that the workspace can
subscribe to it and handle following events.
This commit is contained in:
Max Brunsfeld 2023-12-05 12:57:23 -08:00
parent 7b4b068230
commit 863222edc5
9 changed files with 117 additions and 110 deletions

View file

@ -88,7 +88,7 @@ struct DiagnosticGroupState {
block_count: usize,
}
impl EventEmitter<ItemEvent> for ProjectDiagnosticsEditor {}
impl EventEmitter<EditorEvent> for ProjectDiagnosticsEditor {}
impl Render for ProjectDiagnosticsEditor {
type Element = Focusable<Div>;
@ -158,7 +158,7 @@ impl ProjectDiagnosticsEditor {
});
let editor_event_subscription =
cx.subscribe(&editor, |this, _editor, event: &EditorEvent, cx| {
Self::emit_item_event_for_editor_event(event, cx);
cx.emit(event.clone());
if event == &EditorEvent::Focused && this.path_states.is_empty() {
cx.focus(&this.focus_handle);
}
@ -183,40 +183,6 @@ impl ProjectDiagnosticsEditor {
this
}
fn emit_item_event_for_editor_event(event: &EditorEvent, cx: &mut ViewContext<Self>) {
match event {
EditorEvent::Closed => cx.emit(ItemEvent::CloseItem),
EditorEvent::Saved | EditorEvent::TitleChanged => {
cx.emit(ItemEvent::UpdateTab);
cx.emit(ItemEvent::UpdateBreadcrumbs);
}
EditorEvent::Reparsed => {
cx.emit(ItemEvent::UpdateBreadcrumbs);
}
EditorEvent::SelectionsChanged { local } if *local => {
cx.emit(ItemEvent::UpdateBreadcrumbs);
}
EditorEvent::DirtyChanged => {
cx.emit(ItemEvent::UpdateTab);
}
EditorEvent::BufferEdited => {
cx.emit(ItemEvent::Edit);
cx.emit(ItemEvent::UpdateBreadcrumbs);
}
EditorEvent::ExcerptsAdded { .. } | EditorEvent::ExcerptsRemoved { .. } => {
cx.emit(ItemEvent::Edit);
}
_ => {}
}
}
fn deploy(workspace: &mut Workspace, _: &Deploy, cx: &mut ViewContext<Workspace>) {
if let Some(existing) = workspace.item_of_type::<ProjectDiagnosticsEditor>(cx) {
workspace.activate_item(&existing, cx);
@ -333,8 +299,7 @@ impl ProjectDiagnosticsEditor {
this.update(&mut cx, |this, cx| {
this.summary = this.project.read(cx).diagnostic_summary(false, cx);
cx.emit(ItemEvent::UpdateTab);
cx.emit(ItemEvent::UpdateBreadcrumbs);
cx.emit(EditorEvent::TitleChanged);
})?;
anyhow::Ok(())
}
@ -649,6 +614,12 @@ impl FocusableView for ProjectDiagnosticsEditor {
}
impl Item for ProjectDiagnosticsEditor {
type Event = EditorEvent;
fn to_item_events(event: &EditorEvent, f: impl FnMut(ItemEvent)) {
Editor::to_item_events(event, f)
}
fn deactivated(&mut self, cx: &mut ViewContext<Self>) {
self.editor.update(cx, |editor, cx| editor.deactivated(cx));
}