use super::super::events::{ContentPayload, ContentType, EventSource, SideEffect};
use super::super::history::{ContentData, History};
use super::super::state::{Mode, Notification, StudioState};
pub fn update_content(
state: &mut StudioState,
history: &mut History,
content_type: ContentType,
content: ContentPayload,
) {
match (content_type, content) {
(ContentType::CommitMessage, ContentPayload::Commit(msg)) => {
if state.modes.commit.messages.is_empty() {
state.modes.commit.messages = vec![msg.clone()];
state
.modes
.commit
.message_editor
.set_messages(vec![msg.clone()]);
} else {
let idx = state.modes.commit.current_index;
state.modes.commit.messages[idx] = msg.clone();
state
.modes
.commit
.message_editor
.set_messages(state.modes.commit.messages.clone());
}
history.record_content(
Mode::Commit,
content_type,
&ContentData::Commit(msg),
EventSource::Tool,
"tool_update",
);
}
(ContentType::PRDescription, ContentPayload::Markdown(content)) => {
state.modes.pr.pr_content.clone_from(&content);
history.record_content(
Mode::PR,
content_type,
&ContentData::Markdown(content),
EventSource::Tool,
"tool_update",
);
}
(ContentType::CodeReview, ContentPayload::Markdown(content)) => {
state.modes.review.review_content.clone_from(&content);
history.record_content(
Mode::Review,
content_type,
&ContentData::Markdown(content),
EventSource::Tool,
"tool_update",
);
}
(ContentType::Changelog, ContentPayload::Markdown(content)) => {
state.modes.changelog.changelog_content.clone_from(&content);
history.record_content(
Mode::Changelog,
content_type,
&ContentData::Markdown(content),
EventSource::Tool,
"tool_update",
);
}
(ContentType::ReleaseNotes, ContentPayload::Markdown(content)) => {
state
.modes
.release_notes
.release_notes_content
.clone_from(&content);
history.record_content(
Mode::ReleaseNotes,
content_type,
&ContentData::Markdown(content),
EventSource::Tool,
"tool_update",
);
}
_ => {
state.notify(Notification::warning("Received mismatched content update"));
}
}
state.mark_dirty();
}
pub fn stage_file(path: std::path::PathBuf) -> SideEffect {
SideEffect::GitStage(path)
}
pub fn unstage_file(path: std::path::PathBuf) -> SideEffect {
SideEffect::GitUnstage(path)
}