[squeak-dev] Merge Request: pbKeyboard.1.cs

christoph.thiede at student.hpi.uni-potsdam.de christoph.thiede at student.hpi.uni-potsdam.de
Sat Nov 27 20:32:41 UTC 2021


Hi Marcel,

thanks for merging! :-)

> Also note that MorphicEvent >> #wasHandled: is not public! It belongs to internal event-dispatching logic. Clients should never mess with this flag except when overwriting #handle*: methods.

This is a pity, can't we convert this into a public protocol? I have used this in many different situations already - it just allows you to express certain pieces of logic more compactly than repeating yourself in #handlesKey...: and #key...: (or even overriding #handleKey..., which is also private). Similar to EAFP vs LBYL.

See also Morphic-ct.1777 (inbox) for another example.

Best,
Christoph

---
Sent from Squeak Inbox Talk

On 2021-11-26T17:54:11+01:00, marcel.taeumel at hpi.de wrote:

> Merged.
> Am 06.11.2021 21:47:16 schrieb christoph.thiede at student.hpi.uni-potsdam.de <christoph.thiede at student.hpi.uni-potsdam.de>:
> ==================== Summary ====================
> 
> Change Set:        pbKeyboard
> Date:            2 November 2021
> Author:            Christoph Thiede
> 
> This changeset improves keyboard shortcut for preference button in the PreferenceBrowser. You can now select a preference in the browser and press escape to trigger the menu or cmd + (m|b | n | i | c | C) to browse senders/implementors / inspect the preference, or copy its content, resp. Also fixes up a few Law of Demeter violations in PBPreferenceView and improves multilingual support.
> 
> =============== Diff ===============
> 
> PBPreferenceButtonMorph>>handlesKeyboard: {event handling} · ct 11/1/2021 22:54
> + handlesKeyboard: anEvent
> +
> +     ^ anEvent isKeystroke
> 
> PBPreferenceButtonMorph>>highlightOn {highlighting} · ct 11/1/2021 23:14 (changed)
> highlightOn
>     
>     self color: ((UserInterfaceTheme current get: #selectionColor for: PluggableListMorph) ifNil: [Color gray alpha: 0.1]).
> 
>     self label
>         color: ((UserInterfaceTheme current get: #selectionTextColor for: PluggableListMorph) ifNil: [Color black]);
>         font: (((UserInterfaceTheme current get: #font for: PluggableListMorph) ifNil: [TextStyle defaultFont])
>             emphasized: TextEmphasis bold emphasisCode).
>     
> -     self addExtraControls.
> +     self addExtraControls.
> +     
> +     self currentHand newKeyboardFocus: self.
> 
> PBPreferenceButtonMorph>>keyStroke: {event handling} · ct 11/1/2021 23:02
> + keyStroke: anEvent
> +
> +     ^ self preferenceView keyStroke: anEvent browser: self model
> 
> PBPreferenceView>>keyStroke:browser: {user interface} · ct 11/2/2021 15:41
> + keyStroke: anEvent browser: aPreferenceBrowser
> +
> +     anEvent commandKeyPressed
> +         ifFalse: [
> +             anEvent keyCharacter = Character escape
> +                 ifTrue: [^ self offerPreferenceNameMenu: aPreferenceBrowser].
> +             ^ anEvent wasHandled: false].
> +     
> +     anEvent keyCharacter
> +         caseOf: {
> +             [$b] -> [aPreferenceBrowser findCategoryFromPreference: self preference].
> +             [$c] -> [self copyName].
> +             [$C] -> [self copyCode].
> +             [$i] -> [self preference inspect].
> +             [$m] -> [self browse].
> +             [$n] -> [self browseSenders]}
> +         otherwise: [anEvent wasHandled: false].
> 
> PBPreferenceView>>offerPreferenceNameMenu: {user interface} · ct 11/2/2021 15:44 (changed)
> offerPreferenceNameMenu: aPreferenceBrowser
>     "the user clicked on a preference name -- put up a menu"
> 
>     | aMenu readableName |
>     readableName := self preference readableName.
>     aMenu := MenuMorph new
>         defaultTarget: self preference;
>         addTitle: readableName.
> 
>     (Preferences okayToChangeProjectLocalnessOf: self preference name) ifTrue:
>         [aMenu
>             addUpdating: #isProjectLocalString target: self preference action: #toggleProjectLocalness;
> -             balloonTextForLastItem: 'Some preferences are best applied uniformly to all projects, and others are best set by each individual project. If this item is checked, then this preference will be printed in bold and will have a separate value for each project'].
> +             balloonTextForLastItem: 'Some preferences are best applied uniformly to all projects, and others are best set by each individual project. If this item is checked, then this preference will be printed in bold and will have a separate value for each project' translated].
> 
>     aMenu
>         addLine;
> -         add: 'browse senders' translated
> -             target: self systemNavigation
> -             selector: #browseAllSelect:name:autoSelect:
> -             argumentList: {
> -                 [:m | self preference selectors anySatisfy: [:sel | m hasLiteral: sel]].
> -                 'Preference senders: {1}' translated format: {self preference name}.
> -                 self preference selectors first };
> -         balloonTextForLastItem: 'This will open a method-list browser on all methods that the send the preference "'
> -             , readableName , '".'.
> +         add: 'browse senders (n)' translated
> +             action: #browseSenders;
> +         balloonTextForLastItem: ('This will open a method-list browser on all methods that the send the preference "{1}".' translated format: {readableName}).
>     self preference provider ifNotNil: [
>         aMenu
> -             add: 'browse implementation' translated
> -                 target: ToolSet
> -                 selector: #browse:selector:
> -                 argumentList: {
> -                     self preference provider class.
> -                     self preference selectors first };
> -             balloonTextForLastItem: 'This will open a browser on the method that stores the preference "' , readableName , '".'].
> +             add: 'browse implementation (m)' translated
> +                 action: #browse;
> +             balloonTextForLastItem: ('This will open a browser on the method that stores the preference "{1}".' translated format: {readableName})].
>     aMenu
> -         add: 'inspect preference' translated
> -             target: self preference
> -             selector: #inspect;
> -         balloonTextForLastItem: 'This will open an Inspector on the preference "' , readableName , '".'.
> +         add: 'inspect preference (i)' translated
> +             action: #inspect;
> +         balloonTextForLastItem: ('This will open an inspector on the preference "{1}".' translated format: {readableName}).
>     aMenu
>         addLine;
> -         add: 'show category'
> +         add: 'show category (b)' translated
>             target: aPreferenceBrowser
>             selector: #findCategoryFromPreference:
>             argument: self preference;
> -         balloonTextForLastItem: 'Allows you to find out which category, or categories, this preference belongs to.'.
> +         balloonTextForLastItem: 'Allows you to find out which category, or categories, this preference belongs to.' translated.
> 
>     Smalltalk isMorphic ifTrue:
>         [aMenu
> -             add: 'hand me a button for this preference'
> +             add: 'hand me a button for this preference' translated
>                 target: self
>                 selector: #tearOffButton;
> -             balloonTextForLastItem: 'Will give you a button that governs this preference, which you may deposit wherever you wish'].
> +             balloonTextForLastItem: 'Will give you a button that governs this preference, which you may deposit wherever you wish' translated].
> 
>     aMenu
> -         add: 'copy name to clipboard'
> -             target: self preference
> -             selector: #copyName;
> -         balloonTextForLastItem: 'Copy the name of the preference to the text clipboard, so that you can paste into code somewhere'.
> +         add: 'copy name to clipboard (c)' translated
> +             action: #copyName;
> +         balloonTextForLastItem: 'Copy the name of the preference to the text clipboard, so that you can paste into code somewhere' translated.
>     aMenu
> -         add: 'copy code to clipboard'
> -             target: self preference
> -             selector: #copyCode;
> -         balloonTextForLastItem: 'Copy the code to access the current preference value to the clipboard, so that you can paste into code somewhere'.
> +         add: 'copy code to clipboard (C)' translated
> +             action: #copyCode;
> +         balloonTextForLastItem: 'Copy the code to access the current preference value to the clipboard, so that you can paste into code somewhere' translated.
> 
>     aMenu popUpInWorld
> 
> PragmaPreference>>browse {browsing} · ct 11/1/2021 22:56
> + browse
> +
> +     ToolSet
> +         browse: self provider class
> +         selector: self selectors first.
> 
> Preference>>browse {browsing} · ct 11/1/2021 22:56
> + browse
> +
> +     ToolSet
> +         browse: Preferences class
> +         selector: self selectors first.
> 
> Preference>>browseSenders {browsing} · ct 11/1/2021 22:42
> + browseSenders
> +
> +     self systemNavigation
> +         browseAllSelect: [:m | self selectors anySatisfy: [:sel | m hasLiteral: sel]]
> +         name: ('Preference senders: {1}' translated format: {self name})
> +         autoSelect: self selectors first.
> 
> PreferenceBrowser>>findCategoryFromPreference: {find} · ct 11/2/2021 15:03 (changed)
> findCategoryFromPreference: aPreference
>     "Find all categories in which the preference occurs"
> 
> -     | aMenu|
> -     aMenu := MenuMorph new defaultTarget: self.
> +     | categories menu |
> +     categories := aPreference categoryList.
> +     categories size = 0
> +         ifTrue: [^ self].
> +     categories size = 1
> +         ifTrue: [^ self selectedCategory: categories first].
> +     
> +     menu := MenuMorph new defaultTarget: self.
>     aPreference categoryList do:
> -         [:aCategory | aMenu add: aCategory target: self selector: #selectedCategory: argument: aCategory].
> -     aMenu popUpInWorld
> +         [:aCategory | menu add: aCategory target: self selector: #selectedCategory: argument: aCategory].
> +     menu popUpInWorld
> 
> PreferenceBrowserMorph>>assureKeyboardFocus: {event handling} · ct 11/1/2021 23:14
> + assureKeyboardFocus: aHandMorph
> +
> +     aHandMorph keyboardFocus = self
> +         ifTrue: [^ self].
> +     
> +     (aHandMorph keyboardFocus notNil and: [aHandMorph keyboardFocus hasOwner: self])
> +         ifTrue: [^ self].
> +     
> +     aHandMorph newKeyboardFocus: self.
> 
> PreferenceBrowserMorph>>mouseDownOn:event: {event handling} · ct 11/1/2021 23:13 (changed)
> mouseDownOn: aPreferenceView event: anEvent
> -     anEvent hand newKeyboardFocus: self preferenceList scroller.
> +     self assureKeyboardFocus: anEvent hand.
>     anEvent yellowButtonPressed
>         ifTrue: [aPreferenceView offerPreferenceNameMenu: self model]
> 
> PreferenceView>>browse {user interface} · ct 11/1/2021 22:43
> + browse
> +
> +     ^ self preference browse
> 
> PreferenceView>>browseSenders {user interface} · ct 11/1/2021 22:42
> + browseSenders
> +
> +     ^ self preference browseSenders
> 
> 
> ---
> Sent from Squeak Inbox Talk [https://github.com/hpi-swa-lab/squeak-inbox-talk]
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20211126/aace27ea/attachment.html>
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20211127/c20d6e74/attachment-0001.html>


More information about the Squeak-dev mailing list