Skip to content

Fix: edit a date picker from the keyboard - #859

Open
DTW-Thalion wants to merge 3 commits into
gnustep:masterfrom
DTW-Thalion:feature/datepicker-keyboard
Open

Fix: edit a date picker from the keyboard#859
DTW-Thalion wants to merge 3 commits into
gnustep:masterfrom
DTW-Thalion:feature/datepicker-keyboard

Conversation

@DTW-Thalion

Copy link
Copy Markdown
Contributor

A date picker took no keys at all, so the date it held could only be changed in code.

The pattern the cell shows is split into the parts the locale writes. The left and right arrow keys move between those parts, the up and down arrow keys step the part they are on, and a digit types into it. A step is a step of the calendar, so it carries into the parts above it, a day the next month is too short for moves back to that month's last day, and the result stays inside the minimum and maximum dates. The part being edited is drawn the way selected text is while the picker holds the keyboard. An edit sends the action of the control, and the delegate is asked to validate the proposed date. The values are those AppKit produces for the same keys.

NSDatePickerCell holds three more ivars. Clicking a part, the stepper, and the clock and calendar style are not part of this. The branch is cut off #858 and needs it.

Tests/gui/NSDatePicker/keyboard.m and selection.m: 24 assertions fail before the change and 0 after, 77 green across the two picker directories.

Refers to #95

NSDatePickerCell gave its formatter no format, so the cell had nothing
to draw from and fell back to the description of the date object. The
picker showed a full date and time whatever its datePickerElements were,
in the local time zone rather than the one it was set to, and in a form
no locale writes.

Build the format from the elements. Each element contributes a letter to
a template, and the pattern generator returns the pattern that locale
writes those elements in; a build without ICU has no generator and gets
a fixed order instead. The format is rebuilt whenever the elements or
the locale change.

NSCell keeps the text its formatter made at the time the value was set,
and -[NSDateFormatter stringForObjectValue:] builds that text from a
%-style format rather than from the pattern, so take -stringValue from
-stringFromDate: instead. A cell decoded without a formatter gets one,
as a cell built in code does.
A date picker took no keys at all, so the date it held could only be
changed in code.

The pattern the cell shows is split into the parts the locale writes.
The left and right arrow keys move between those parts, the up and down
arrow keys step the part they are on, and a digit types into it. A step
is a step of the calendar, so it carries into the parts above it, a day
the next month is too short for moves back to that month's last day, and
the result stays inside the minimum and maximum dates. A digit joins the
digits already typed while the number they make can still grow, and is
taken on its own once it cannot.

The part being edited is drawn the way selected text is, while the
picker holds the keyboard of a key window. An edit sends the action of
the control. The delegate is asked to validate the proposed date, both
for an edit and for a date set in code, and the date it hands back is
the one the picker takes.

NSDatePickerCell holds three more ivars, for the part being edited and
for the digits typed into it.
START_SET creates an autorelease pool and END_SET releases it, so the pool
these tests create around the set is redundant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant