mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 02:54:25 +00:00
Camera Raw workspace: a held OK files its answer for the app (OK and Done); trial
This commit is contained in:
@@ -519,7 +519,7 @@ impl FullWindowWorkspace for RawDevelopWorkspace {
|
||||
const KEY: &'static str = "filter.cameraRaw";
|
||||
|
||||
fn show(&mut self, ui: &mut Ui, cx: WorkspaceCx<'_, Self::Source>) -> WorkspacePass<Self::Event, Self::Result> {
|
||||
let WorkspaceCx { source, revision, open, .. } = cx;
|
||||
let WorkspaceCx { source, revision, open, hold_ok, ok_waits, .. } = cx;
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<RawDevelopWords>();
|
||||
let common = env.words::<CommonWords>();
|
||||
@@ -529,9 +529,11 @@ impl FullWindowWorkspace for RawDevelopWorkspace {
|
||||
|
||||
let name = if self.target == RawTarget::OpenRaw { words.name.clone() } else { words.name_filter.clone() };
|
||||
let title: Label = FullWindowTitle::new(name).subject(self.subject.clone()).zoom(self.view.zoom_percent()).label(&env);
|
||||
let mut plan = vec![(Footer::Finish(self.target.accept()), FooterButton::new(self.target_label(&words, &common), DialogRole::Accept))];
|
||||
// A held OK files its answer for the app and keeps the workspace open until the app answers; the buttons that finish wait meanwhile.
|
||||
let finishing = |button: FooterButton| button.stays_open(hold_ok).enabled(!ok_waits);
|
||||
let mut plan = vec![(Footer::Finish(self.target.accept()), finishing(FooterButton::new(self.target_label(&words, &common), DialogRole::Accept)))];
|
||||
if self.target == RawTarget::OpenRaw {
|
||||
plan.push((Footer::Finish(RawFinish::Done), FooterButton::new(words.done.clone(), DialogRole::Other)));
|
||||
plan.push((Footer::Finish(RawFinish::Done), finishing(FooterButton::new(words.done.clone(), DialogRole::Other))));
|
||||
}
|
||||
plan.push((Footer::Save, FooterButton::new(words.save_settings.clone(), DialogRole::Other).stays_open(true)));
|
||||
plan.push((Footer::Load, FooterButton::new(words.load_settings.clone(), DialogRole::Other).stays_open(true)));
|
||||
@@ -804,11 +806,14 @@ impl FullWindowWorkspace for RawDevelopWorkspace {
|
||||
Some(Footer::Finish(finish)) => finish,
|
||||
_ => self.target.accept(),
|
||||
};
|
||||
let result = match self.requested.take() {
|
||||
Some(finish) => Some(DialogResult::Ok(self.result(finish))),
|
||||
None => output.result(|| self.result(finish)),
|
||||
let (result, held) = match (self.requested.take(), hold_ok) {
|
||||
(Some(finish), true) => (None, Some(self.result(finish))),
|
||||
(Some(finish), false) => (Some(DialogResult::Ok(self.result(finish))), None),
|
||||
// Esc and Cancel close the workspace either way.
|
||||
(None, true) => (output.closed.map(|_| DialogResult::Cancel), matches!(footer, Some(Footer::Finish(_))).then(|| self.result(finish))),
|
||||
(None, false) => (output.result(|| self.result(finish)), None),
|
||||
};
|
||||
WorkspacePass::new(output.response, events).result(result)
|
||||
WorkspacePass::new(output.response, events).held(held).result(result)
|
||||
}
|
||||
|
||||
fn json_fields(&self, source: &Self::Source) -> Option<serde_json::Value> {
|
||||
|
||||
@@ -218,6 +218,22 @@ fn raw_develop_switches_raws_and_finishes_with_each_footer_button() {
|
||||
assert_eq!(finish(&host), Some(RawFinish::Ok));
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_held_ok_files_its_answer_and_keeps_the_workspace_open_until_the_app_answers() {
|
||||
let host = Rc::new(RefCell::new(DialogHost::new()));
|
||||
let mut fixture = fixture(&host, &Rc::new(Cell::new(false)));
|
||||
host.borrow_mut().open(HostedWorkspace::new(RawDevelopWorkspace::new(open(RawTarget::OpenRaw)), Source::new()).held_ok());
|
||||
fixture.idle(10);
|
||||
let done = fixture.by_label("Done").expect("Done");
|
||||
fixture.click(&done).idle(4);
|
||||
let held = host.borrow_mut().get_mut::<Hosted>().expect("Done keeps the workspace open").take_ok();
|
||||
assert_eq!(held.map(|result| result.finish), Some(RawFinish::Done), "Done files its answer for the app");
|
||||
|
||||
host.borrow_mut().get_mut::<Hosted>().expect("open").answer_ok(Ok(()));
|
||||
fixture.idle(4);
|
||||
assert_eq!(finish(&host), Some(RawFinish::Done), "the app's answer closes the workspace with the filed result");
|
||||
}
|
||||
|
||||
/// The key `key` going down or up, as a keyboard reports it.
|
||||
fn key_event(key: Key, pressed: bool) -> Event {
|
||||
Event::Key { key, physical_key: Some(key), pressed, repeat: false, modifiers: Modifiers::NONE }
|
||||
|
||||
Reference in New Issue
Block a user