mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-16 23:24:22 +00:00
Merge pull request #14088 from TrevorBrown-dev/fix/open-recent-after-smart-object-14053
File menu: Open Recent comes after Open as Smart Object (#14053)
This commit is contained in:
3 files changed
+60
-1
No files matched your search
@@ -65,6 +65,9 @@ pub(crate) const DOCUMENT_ITEM: &str = "window.document.";
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod open_recent_position_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod open_recent_tests {
|
||||
use super::*;
|
||||
|
||||
@@ -137,7 +137,7 @@ pub fn menu_items(app: &PhotocraftApp) -> Vec<MenuItem> {
|
||||
item.label = reveal_label().into();
|
||||
}
|
||||
// File › Open Recent: a dynamic submenu of recently opened files (inserted after "Open As…").
|
||||
if let Some(after) = items.iter().position(|i| i.id == "file.openAs") {
|
||||
if let Some(after) = items.iter().position(|i| i.id == "file.openAsSmartObject").or_else(|| items.iter().position(|i| i.id == "file.openAs")) {
|
||||
let rp: Vec<String> = vec!["File".into(), "Open Recent".into()];
|
||||
let mut recent: Vec<MenuItem> = app
|
||||
.ui
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
//! File menu: Open Recent comes directly after Open as Smart Object (#14053).
|
||||
|
||||
use super::*;
|
||||
|
||||
fn app_with(recent: &[&str]) -> PhotocraftApp {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.ui.recent_files = recent.iter().map(|s| (*s).to_string()).collect();
|
||||
app
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_recent_follows_open_as_smart_object() {
|
||||
let app = app_with(&["/tmp/a.png"]);
|
||||
let items = menu_items(&app);
|
||||
let mut flat: Vec<String> = Vec::new();
|
||||
let mut seen_recent = false;
|
||||
for item in items.iter().filter(|i| i.path.first().map(String::as_str) == Some("File")) {
|
||||
if item.path.len() == 2 && item.path[1] == "Open Recent" {
|
||||
if !seen_recent {
|
||||
flat.push("Open Recent".to_string());
|
||||
seen_recent = true;
|
||||
}
|
||||
} else if item.path.len() == 1 {
|
||||
flat.push(item.id.clone());
|
||||
}
|
||||
if flat.len() >= 8 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert_eq!(
|
||||
flat,
|
||||
vec!["file.new", "file.newFromClipboard", "file.open", "file.openAs", "file.openAsSmartObject", "Open Recent", "file.openExrParts", "---"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_recent_entries_are_unchanged() {
|
||||
let rp = vec!["File".to_string(), "Open Recent".to_string()];
|
||||
for (recent, expect) in [
|
||||
(vec![], vec![("file.clearRecent", "Clear Recent File List", false)]),
|
||||
(
|
||||
vec!["/tmp/a.png", "/dir/b.psd"],
|
||||
vec![
|
||||
("file.openRecent.0", "a.png", true),
|
||||
("file.openRecent.1", "b.psd", true),
|
||||
("---", "---", false),
|
||||
("file.clearRecent", "Clear Recent File List", true),
|
||||
],
|
||||
),
|
||||
] {
|
||||
let app = app_with(&recent);
|
||||
let got: Vec<(String, String, bool)> = menu_items(&app).into_iter().filter(|i| i.path == rp).map(|i| (i.id, i.label, i.enabled)).collect();
|
||||
let want: Vec<(String, String, bool)> = expect.into_iter().map(|(a, b, c)| (a.to_string(), b.to_string(), c)).collect();
|
||||
assert_eq!(got, want);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user