-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly extract out entity handling logic
- Loading branch information
Showing
11 changed files
with
807 additions
and
727 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use anyhow::{anyhow, Context, Result}; | ||
use fn_error_context::context; | ||
use tauri::{AppHandle, Manager}; | ||
use tryvial::try_fn; | ||
|
||
use crate::{ | ||
model::{AppState, EditorData, EditorRequest, EntityEditorRequest, EntityGeneralEvent, EntityTreeRequest, Request}, | ||
send_request | ||
}; | ||
|
||
#[try_fn] | ||
#[context("Couldn't handle update content event")] | ||
pub async fn handle(app: &AppHandle, event: EntityGeneralEvent) -> Result<()> { | ||
let app_state = app.state::<AppState>(); | ||
|
||
match event { | ||
EntityGeneralEvent::SetShowReverseParentRefs { | ||
editor_id, | ||
show_reverse_parent_refs | ||
} => { | ||
let mut editor_state = app_state.editor_states.get_mut(&editor_id).context("No such editor")?; | ||
|
||
let settings = match editor_state.data { | ||
EditorData::QNEntity { ref mut settings, .. } => settings, | ||
EditorData::QNPatch { ref mut settings, .. } => settings, | ||
|
||
_ => { | ||
Err(anyhow!("Editor {} is not a QN editor", editor_id))?; | ||
panic!(); | ||
} | ||
}; | ||
|
||
settings.show_reverse_parent_refs = show_reverse_parent_refs; | ||
} | ||
|
||
EntityGeneralEvent::SetShowChangesFromOriginal { | ||
editor_id, | ||
show_changes_from_original | ||
} => { | ||
let mut editor_state = app_state.editor_states.get_mut(&editor_id).context("No such editor")?; | ||
|
||
let settings = match editor_state.data { | ||
EditorData::QNEntity { ref mut settings, .. } => settings, | ||
EditorData::QNPatch { ref mut settings, .. } => settings, | ||
|
||
_ => { | ||
Err(anyhow!("Editor {} is not a QN editor", editor_id))?; | ||
panic!(); | ||
} | ||
}; | ||
|
||
settings.show_changes_from_original = show_changes_from_original; | ||
|
||
send_request( | ||
app, | ||
Request::Editor(EditorRequest::Entity(EntityEditorRequest::Tree( | ||
EntityTreeRequest::SetShowDiff { | ||
editor_id, | ||
show_diff: show_changes_from_original | ||
} | ||
))) | ||
)?; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use anyhow::{anyhow, Context, Result}; | ||
use fn_error_context::context; | ||
use quickentity_rs::qn_structs::{CommentEntity, Ref}; | ||
use tauri::{AppHandle, Manager}; | ||
use tryvial::try_fn; | ||
|
||
use crate::{ | ||
entity::get_local_reference, | ||
model::{ | ||
AppState, EditorData, EditorRequest, EntityEditorRequest, EntityMetaPaneEvent, EntityTreeRequest, | ||
GlobalRequest, Request | ||
}, | ||
send_request | ||
}; | ||
|
||
#[try_fn] | ||
#[context("Couldn't handle entity meta pane event")] | ||
pub async fn handle(app: &AppHandle, event: EntityMetaPaneEvent) -> Result<()> { | ||
let app_state = app.state::<AppState>(); | ||
|
||
match event { | ||
EntityMetaPaneEvent::JumpToReference { editor_id, reference } => { | ||
send_request( | ||
app, | ||
Request::Editor(EditorRequest::Entity(EntityEditorRequest::Tree( | ||
EntityTreeRequest::Select { | ||
editor_id, | ||
id: Some(reference) | ||
} | ||
))) | ||
)?; | ||
} | ||
|
||
EntityMetaPaneEvent::SetNotes { | ||
editor_id, | ||
entity_id, | ||
notes | ||
} => { | ||
let mut editor_state = app_state.editor_states.get_mut(&editor_id).context("No such editor")?; | ||
|
||
let entity = match editor_state.data { | ||
EditorData::QNEntity { ref mut entity, .. } => entity, | ||
EditorData::QNPatch { ref mut current, .. } => current, | ||
|
||
_ => { | ||
Err(anyhow!("Editor {} is not a QN editor", editor_id))?; | ||
panic!(); | ||
} | ||
}; | ||
|
||
// Remove comment referring to given entity | ||
entity | ||
.comments | ||
.retain(|x| get_local_reference(&x.parent).map(|x| x != entity_id).unwrap_or(true)); | ||
|
||
// Add new comment | ||
entity.comments.push(CommentEntity { | ||
parent: Ref::Short(Some(entity_id)), | ||
name: "Notes".into(), | ||
text: notes | ||
}); | ||
|
||
send_request( | ||
app, | ||
Request::Global(GlobalRequest::SetTabUnsaved { | ||
id: editor_id.to_owned(), | ||
unsaved: true | ||
}) | ||
)?; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use anyhow::Result; | ||
use fn_error_context::context; | ||
use tauri::AppHandle; | ||
use tryvial::try_fn; | ||
|
||
use crate::model::EntityEditorEvent; | ||
|
||
pub mod general; | ||
pub mod meta_pane; | ||
pub mod metadata; | ||
pub mod monaco; | ||
pub mod overrides; | ||
pub mod tree; | ||
|
||
#[try_fn] | ||
#[context("Couldn't handle entity editor event")] | ||
pub async fn handle(app: &AppHandle, event: EntityEditorEvent) -> Result<()> { | ||
match event { | ||
EntityEditorEvent::General(event) => { | ||
general::handle(app, event).await?; | ||
} | ||
|
||
EntityEditorEvent::Tree(event) => { | ||
tree::handle(app, event).await?; | ||
} | ||
|
||
EntityEditorEvent::Monaco(event) => { | ||
monaco::handle(app, event).await?; | ||
} | ||
|
||
EntityEditorEvent::MetaPane(event) => { | ||
meta_pane::handle(app, event).await?; | ||
} | ||
|
||
EntityEditorEvent::Metadata(event) => { | ||
metadata::handle(app, event).await?; | ||
} | ||
|
||
EntityEditorEvent::Overrides(event) => { | ||
overrides::handle(app, event).await?; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.