Merge branch 'fix/f2': community issue fixes
This commit is contained in:
@@ -280,8 +280,11 @@ fn comp_content_with(project: &Project, comp: ItemId, addr: impl Fn(ItemId, &Arc
|
||||
h.finish()
|
||||
}
|
||||
|
||||
/// Hash of render options (part of [`FrameKey`] and of the disk key).
|
||||
/// Hash of render options (part of [`FrameKey`] and of the disk key). The scale counts as the
|
||||
/// key's thousandths ([`FrameKey::scale`]): a series rebuilt from the key (the cache bars) has
|
||||
/// the same options as the frames rendered at 1/3 = 0.333… (#595).
|
||||
pub fn opts_hash(o: &RenderOpts) -> u64 {
|
||||
let o = RenderOpts { scale: (o.scale * 1000.0).round() / 1000.0, ..*o };
|
||||
let mut h = disk_cache::Hash128::default();
|
||||
h.write(format!("{o:?}").as_bytes());
|
||||
h.finish() as u64
|
||||
|
||||
@@ -297,6 +297,17 @@ pub struct EffectcraftApp {
|
||||
pub(crate) template_list: Option<(Vec<String>, Vec<effectcraft_engine::templates::TemplateInfo>)>,
|
||||
}
|
||||
|
||||
/// The saved workspaces in the settings store ([`effectcraft_engine::config::ConfigStore`]).
|
||||
pub const WORKSPACES_FILE: &str = "workspaces.json";
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
struct SavedWorkspaces {
|
||||
#[serde(default)]
|
||||
workspaces: std::collections::BTreeMap<String, dock::DockNode>,
|
||||
#[serde(default)]
|
||||
floating: std::collections::BTreeMap<String, Vec<dock::Floating>>,
|
||||
}
|
||||
|
||||
impl EffectcraftApp {
|
||||
pub fn new(session: Session) -> Self {
|
||||
EffectcraftApp {
|
||||
@@ -355,6 +366,34 @@ impl EffectcraftApp {
|
||||
template_list: None,
|
||||
}
|
||||
.with_ui_commands()
|
||||
.with_saved_workspaces()
|
||||
}
|
||||
|
||||
/// The workspaces saved in an earlier session (Window ▸ Workspace ▸ Save as New Workspace,
|
||||
/// Save Changes to this Workspace), from the settings store. A file that doesn't read is
|
||||
/// ignored.
|
||||
fn with_saved_workspaces(mut self) -> Self {
|
||||
let text = self.session.config.as_ref().and_then(|c| c.read(WORKSPACES_FILE));
|
||||
match text.map(|t| serde_json::from_str::<SavedWorkspaces>(&t)) {
|
||||
Some(Ok(w)) => {
|
||||
self.ui.saved_workspaces = w.workspaces;
|
||||
self.ui.saved_floating = w.floating;
|
||||
}
|
||||
Some(Err(e)) => log::warn!("{WORKSPACES_FILE}: {e}"),
|
||||
None => {}
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// Keep the saved workspaces for the next session (see [`EffectcraftApp::new`]): After
|
||||
/// Effects' saved workspaces last until they are deleted (#320).
|
||||
pub(crate) fn store_saved_workspaces(&self) {
|
||||
let Some(c) = &self.session.config else { return };
|
||||
let w = SavedWorkspaces { workspaces: self.ui.saved_workspaces.clone(), floating: self.ui.saved_floating.clone() };
|
||||
let written = serde_json::to_string(&w).map_err(std::io::Error::other).and_then(|t| c.write(WORKSPACES_FILE, &t));
|
||||
if let Err(e) = written {
|
||||
log::warn!("{WORKSPACES_FILE}: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Offer the frontend's commands (tools, timeline navigation…) for keyboard shortcuts.
|
||||
|
||||
@@ -954,6 +954,7 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu
|
||||
let name = app.ui.workspace.clone();
|
||||
app.ui.saved_workspaces.insert(name.clone(), app.ui.dock.clone());
|
||||
app.ui.saved_floating.insert(name.clone(), app.ui.floating.clone());
|
||||
app.store_saved_workspaces();
|
||||
json!({"workspace": name})
|
||||
}
|
||||
"window.saveWorkspaceAs" => {
|
||||
@@ -970,6 +971,7 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu
|
||||
app.ui.saved_workspaces.insert(name.clone(), app.ui.dock.clone());
|
||||
app.ui.saved_floating.insert(name.clone(), app.ui.floating.clone());
|
||||
app.ui.workspace = name.clone();
|
||||
app.store_saved_workspaces();
|
||||
json!({"workspace": name})
|
||||
}
|
||||
"window.editWorkspaces" => {
|
||||
@@ -994,6 +996,7 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu
|
||||
if app.ui.saved_workspaces.remove(&name).is_none() && !builtin {
|
||||
return Err(format!("no workspace `{name}`"));
|
||||
}
|
||||
app.store_saved_workspaces();
|
||||
if app.ui.workspace == name {
|
||||
app.set_workspace("Default");
|
||||
}
|
||||
@@ -1011,6 +1014,7 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu
|
||||
if app.ui.workspace == name {
|
||||
app.ui.workspace = new.to_string();
|
||||
}
|
||||
app.store_saved_workspaces();
|
||||
return Ok(json!({"renamed": new}));
|
||||
}
|
||||
json!({"workspaces": app.workspace_names()})
|
||||
|
||||
Reference in New Issue
Block a user