mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
Start screen: pinned folders above recent files; a Clear button on the Recent heading
This commit is contained in:
@@ -528,6 +528,10 @@ impl StartScreen<'_> {
|
||||
let _ = Row::new().gap(Gap::Tight).show(ui, |ui, _| new_and_open(&page, ui));
|
||||
}
|
||||
host_sections(ui, StartPlace::BeforeRecent);
|
||||
// The pinned folders stand above the recent files, as production's Folders section does.
|
||||
if let Some(pinned) = pinned {
|
||||
pinned_section(&page, ui, pinned);
|
||||
}
|
||||
if max_recent > 0 {
|
||||
let current_view = view.borrow_mut().reborrow().read(cx).and_then(|held| held.same().copied()).unwrap_or_default();
|
||||
let current_sort = sort.borrow_mut().reborrow().read(cx).and_then(|held| held.same().copied()).unwrap_or_default();
|
||||
@@ -535,9 +539,6 @@ impl StartScreen<'_> {
|
||||
sort_recent(&mut files, current_sort, &collator);
|
||||
recent_section(&page, ui, &view, &sort, current_view, &files);
|
||||
}
|
||||
if let Some(pinned) = pinned {
|
||||
pinned_section(&page, ui, pinned);
|
||||
}
|
||||
if !templates.is_empty() {
|
||||
templates_section(&page, ui, templates);
|
||||
}
|
||||
@@ -635,6 +636,11 @@ fn recent_section(
|
||||
.controls(|ui, _| {
|
||||
let _ = Segmented::new(words.view.clone(), view.borrow_mut().reborrowed(), &modes).show(ui);
|
||||
let _ = Select::new(words.sort.clone(), sort.borrow_mut().reborrowed(), &orders).show(ui);
|
||||
// Clear empties the list, as the menu's Clear Recent Files does; with no files there is nothing to clear.
|
||||
let clear = Button::new(words.clear_recent.clone()).icon(IconId::new("trash")).enabled(!files.is_empty()).id_salt("clear").show(ui);
|
||||
if clicked(&clear) {
|
||||
page.push(StartAction::ClearRecent);
|
||||
}
|
||||
})
|
||||
.show(ui, |ui, cx| {
|
||||
let mut lead = cx.keep::<Leads>().recent.clone().filter(|path| files.iter().any(|file| &file.path == path));
|
||||
|
||||
@@ -20,6 +20,8 @@ craft_ui::words! {
|
||||
grid_view: "startScreen.gridView" = "Grid";
|
||||
list_view: "startScreen.listView" = "List";
|
||||
sort: "startScreen.sort" = "Sort";
|
||||
/// The button at the Recent heading's end that empties the list.
|
||||
clear_recent: "startScreen.clearRecent" = "Clear";
|
||||
sort_opened: "startScreen.sortOpened" = "Last Opened";
|
||||
sort_name: "startScreen.sortName" = "Name";
|
||||
sort_created: "startScreen.sortCreated" = "Created";
|
||||
|
||||
@@ -388,3 +388,26 @@ fn a_listed_pinned_folder_folds_shows_more_and_opens_its_files() {
|
||||
fixture.key(Key::ArrowLeft, Modifiers::NONE).idle(2);
|
||||
assert_eq!(*log.borrow(), vec![StartAction::FoldPinned(PathBuf::from("/tmp/Empty"))], "an empty folder's disclosure folds it");
|
||||
}
|
||||
|
||||
/// The pinned folders stand above the recent files, as production's Folders section does, and the Recent heading carries
|
||||
/// a Clear button that asks the app to clear the list.
|
||||
#[trial]
|
||||
fn folders_come_before_recent_and_recent_has_a_clear_button() {
|
||||
let log: Log = Rc::default();
|
||||
let seen = log.clone();
|
||||
let files = vec![RecentFile::new("/tmp/work/Poster.psd", "Poster.psd")];
|
||||
let folders = vec![PinnedFolder::new("/tmp/Work", "Work")];
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let (mut view, mut sort) = (RecentView::List, RecentSort::Opened);
|
||||
let out = StartScreen::new(Bind::bound(&mut view), Bind::bound(&mut sort), &files).pinned(&folders).show(ui);
|
||||
seen.borrow_mut().extend(out.actions);
|
||||
});
|
||||
fixture.room(egui::Vec2::new(1100.0, 700.0)).settle();
|
||||
let top = |fixture: &Fixture, text: &str| fixture.texts().iter().find(|run| run.text == text).map(|run| run.rect.min.y);
|
||||
let pinned = top(&fixture, "Pinned Folders").expect("the pinned folders heading");
|
||||
let recent = top(&fixture, "Recent").expect("the recent heading");
|
||||
assert!(pinned < recent, "the folders ({pinned}) come before the recent files ({recent})");
|
||||
let clear = fixture.by_label("Clear").expect("the Recent heading's Clear button");
|
||||
fixture.click(&clear).idle(2);
|
||||
assert!(log.borrow().iter().any(|action| matches!(action, StartAction::ClearRecent)), "Clear asks the app to clear the list");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user