Restore project workspace state

This commit is contained in:
2026-07-22 19:57:26 +02:00
parent 0753b290ad
commit fdf47da40a
17 changed files with 1004 additions and 142 deletions

View File

@@ -23,6 +23,37 @@ impl fmt::Display for SidebarView {
}
impl SidebarView {
pub fn as_str(self) -> &'static str {
match self {
Self::Posts => "posts",
Self::Pages => "pages",
Self::Media => "media",
Self::Scripts => "scripts",
Self::Templates => "templates",
Self::Tags => "tags",
Self::Chat => "chat",
Self::Import => "import",
Self::Git => "git",
Self::Settings => "settings",
}
}
pub fn from_persisted(value: &str) -> Option<Self> {
Some(match value {
"posts" => Self::Posts,
"pages" => Self::Pages,
"media" => Self::Media,
"scripts" => Self::Scripts,
"templates" => Self::Templates,
"tags" => Self::Tags,
"chat" => Self::Chat,
"import" => Self::Import,
"git" => Self::Git,
"settings" => Self::Settings,
_ => return None,
})
}
/// Returns the `activity.*` i18n key for this sidebar view.
pub fn i18n_key(&self) -> &'static str {
match self {
@@ -51,6 +82,27 @@ pub enum PanelTab {
GitLog,
}
impl PanelTab {
pub fn as_str(self) -> &'static str {
match self {
Self::Tasks => "tasks",
Self::Output => "output",
Self::PostLinks => "post_links",
Self::GitLog => "git_log",
}
}
pub fn from_persisted(value: &str) -> Option<Self> {
Some(match value {
"tasks" => Self::Tasks,
"output" => Self::Output,
"post_links" => Self::PostLinks,
"git_log" => Self::GitLog,
_ => return None,
})
}
}
/// A snapshot of a running or completed task shown in the panel.
#[derive(Debug, Clone)]
pub struct TaskSnapshot {
@@ -127,4 +179,32 @@ mod tests {
assert_eq!(SidebarView::Posts.to_string(), "activity.posts");
assert_eq!(SidebarView::Settings.to_string(), "common.settings");
}
#[test]
fn persisted_navigation_names_round_trip() {
for view in [
SidebarView::Posts,
SidebarView::Pages,
SidebarView::Media,
SidebarView::Scripts,
SidebarView::Templates,
SidebarView::Tags,
SidebarView::Chat,
SidebarView::Import,
SidebarView::Git,
SidebarView::Settings,
] {
assert_eq!(SidebarView::from_persisted(view.as_str()), Some(view));
}
for tab in [
PanelTab::Tasks,
PanelTab::Output,
PanelTab::PostLinks,
PanelTab::GitLog,
] {
assert_eq!(PanelTab::from_persisted(tab.as_str()), Some(tab));
}
assert_eq!(SidebarView::from_persisted("unknown"), None);
assert_eq!(PanelTab::from_persisted("unknown"), None);
}
}

View File

@@ -25,6 +25,55 @@ pub enum TabType {
}
impl TabType {
pub fn as_str(&self) -> &'static str {
match self {
Self::Post => "post",
Self::Media => "media",
Self::Settings => "settings",
Self::Style => "style",
Self::Tags => "tags",
Self::Chat => "chat",
Self::Import => "import",
Self::MenuEditor => "menu_editor",
Self::MetadataDiff => "metadata_diff",
Self::GitDiff => "git_diff",
Self::Scripts => "scripts",
Self::Templates => "templates",
Self::Documentation => "documentation",
Self::ApiDocumentation => "api_documentation",
Self::CliDocumentation => "cli_documentation",
Self::McpDocumentation => "mcp_documentation",
Self::SiteValidation => "site_validation",
Self::TranslationValidation => "translation_validation",
Self::FindDuplicates => "find_duplicates",
}
}
pub fn from_persisted(value: &str) -> Option<Self> {
Some(match value {
"post" => Self::Post,
"media" => Self::Media,
"settings" => Self::Settings,
"style" => Self::Style,
"tags" => Self::Tags,
"chat" => Self::Chat,
"import" => Self::Import,
"menu_editor" => Self::MenuEditor,
"metadata_diff" => Self::MetadataDiff,
"git_diff" => Self::GitDiff,
"scripts" => Self::Scripts,
"templates" => Self::Templates,
"documentation" => Self::Documentation,
"api_documentation" => Self::ApiDocumentation,
"cli_documentation" => Self::CliDocumentation,
"mcp_documentation" => Self::McpDocumentation,
"site_validation" => Self::SiteValidation,
"translation_validation" => Self::TranslationValidation,
"find_duplicates" => Self::FindDuplicates,
_ => return None,
})
}
/// Singleton tool tabs per tabs.allium: always one instance, id = type name.
///
/// Singleton types (12): settings, tags, style, menu_editor,
@@ -288,4 +337,32 @@ mod tests {
open_tab(&mut tabs, make_tab("c2", TabType::Chat, false));
assert_eq!(tabs.len(), 2);
}
#[test]
fn persisted_tab_type_names_round_trip() {
for tab_type in [
TabType::Post,
TabType::Media,
TabType::Settings,
TabType::Style,
TabType::Tags,
TabType::Chat,
TabType::Import,
TabType::MenuEditor,
TabType::MetadataDiff,
TabType::GitDiff,
TabType::Scripts,
TabType::Templates,
TabType::Documentation,
TabType::ApiDocumentation,
TabType::CliDocumentation,
TabType::McpDocumentation,
TabType::SiteValidation,
TabType::TranslationValidation,
TabType::FindDuplicates,
] {
assert_eq!(TabType::from_persisted(tab_type.as_str()), Some(tab_type));
}
assert_eq!(TabType::from_persisted("unknown"), None);
}
}