Skip to content

Commit

Permalink
Added support for shift-tabbing to previous controls in the inspector.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjpettet committed Dec 22, 2022
1 parent fafdc88 commit 4a306b0
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/XUI.xojo_project
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ Class=XUICELine;XUI/XUICodeEditor/XUICELine.xojo_code;&h00000000691297FF;&h00000
Class=XUICEObjoScriptFormatter;XUI/XUICodeEditor/Code Editor Formatters/XUICEObjoScriptFormatter.xojo_code;&h00000000490E5FFF;&h000000000E9FB7FF;false
Folder=Inspector Items;XUI/XUIInspector/Inspector Items;&h000000002CB847FF;&h000000007F4C67FF;false
Interface=XUIInspectorItemKeyHandler;XUI/XUIInspector/Inspector Items/XUIInspectorItemKeyHandler.xojo_code;&h00000000696E17FF;&h000000002CB847FF;false
Interface=XUIInspectorItemWithMultipleTabFocusControls;XUI/XUIInspector/Inspector Items/XUIInspectorItemWithMultipleTabFocusControls.xojo_code;&h00000000524887FF;&h000000002CB847FF;false
Interface=XUIInspectorItem;XUI/XUIInspector/Inspector Items/XUIInspectorItem.xojo_code;&h000000002CCDEFFF;&h000000002CB847FF;false
Class=XUIInspectorCheckBoxItem;XUI/XUIInspector/Inspector Items/XUIInspectorCheckBoxItem.xojo_code;&h00000000271837FF;&h000000002CB847FF;false
Class=XUIInspectorSwitchItem;XUI/XUIInspector/Inspector Items/XUIInspectorSwitchItem.xojo_code;&h0000000074F607FF;&h000000002CB847FF;false
Expand All @@ -285,7 +286,6 @@ Class=XUIInspectorTextFieldRenderer;XUI/XUIInspector/XUIInspectorTextFieldRender
Folder=Inspector;Demo Windows/UI Controls/Inspector;&h00000000236ADFFF;&h0000000013F79FFF;false
DesktopWindow=WinInspector;Demo Windows/UI Controls/Inspector/WinInspector.xojo_window;&h000000007420DFFF;&h00000000236ADFFF;false
Module=XUI;XUI/Required/XUI.xojo_code;&h0000000075C34FFF;&h0000000049AEC7FF;false
Interface=XUIInspectorItemWithMultipleTabFocusControls;XUI/XUIInspector/Inspector Items/XUIInspectorItemWithMultipleTabFocusControls.xojo_code;&h00000000524887FF;&h000000002CB847FF;false
AppMenuBar=BasicMenuBar
MajorVersion=2
MinorVersion=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Implements XUIInspectorItem
#tag EndMethod

#tag Method, Flags = &h0, Description = 52657475726E7320547275652069662074686973206974656D2069732061626C6520746F206163636570742074686520666F637573207669612074686520746162206B65792E
Function CanAcceptTabFocus() As Boolean
Function CanAcceptTab() As Boolean
/// Returns True if this item is able to accept the focus via the tab key.

Return False
Expand All @@ -37,6 +37,16 @@ Implements XUIInspectorItem
End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F63757320766961207468652073686966742D746162206B657920636F6D626F202874686520226261636B2074616222292E
Sub DidReceiveBackTab()
/// This item has just received the focus via the shift-tab key combo (the "back tab").
///
/// Part of the `XUIInspectorItem` interface.

// Nothing to do since this item can't accept the focus via the back-tab key combo.
End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F637573207669612074686520746162206B65792E
Sub DidReceiveTabFocus()
/// This item has just received the focus via the tab key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Implements XUIInspectorItem
#tag EndMethod

#tag Method, Flags = &h0, Description = 52657475726E7320547275652069662074686973206974656D2069732061626C6520746F206163636570742074686520666F637573207669612074686520746162206B65792E
Function CanAcceptTabFocus() As Boolean
Function CanAcceptTab() As Boolean
/// Returns True if this item is able to accept the focus via the tab key.

Return False
Expand All @@ -39,6 +39,16 @@ Implements XUIInspectorItem
End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F63757320766961207468652073686966742D746162206B657920636F6D626F202874686520226261636B2074616222292E
Sub DidReceiveBackTab()
/// This item has just received the focus via the shift-tab key combo (the "back tab").
///
/// Part of the `XUIInspectorItem` interface.

// Nothing to do since this item can't accept the focus via the back-tab key combo.
End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F637573207669612074686520746162206B65792E
Sub DidReceiveTabFocus()
/// This item has just received the focus via the tab key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Implements XUIInspectorItem
#tag EndMethod

#tag Method, Flags = &h0, Description = 52657475726E7320547275652069662074686973206974656D2069732061626C6520746F206163636570742074686520666F637573207669612074686520746162206B65792E
Function CanAcceptTabFocus() As Boolean
Function CanAcceptTab() As Boolean
/// Returns True if this item is able to accept the focus via the tab key.

Return False
Expand All @@ -38,6 +38,16 @@ Implements XUIInspectorItem
End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F63757320766961207468652073686966742D746162206B657920636F6D626F202874686520226261636B2074616222292E
Sub DidReceiveBackTab()
/// This item has just received the focus via the shift-tab key combo (the "back tab").
///
/// Part of the `XUIInspectorItem` interface.

// Nothing to do since this item can't accept the focus via the back-tab key combo.
End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F637573207669612074686520746162206B65792E
Sub DidReceiveTabFocus()
/// This item has just received the focus via the tab key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,23 @@ Implements XUIInspectorItem,XUIInspectorItemKeyHandler,XUIInspectorItemWithMulti
End Function
#tag EndMethod

#tag Method, Flags = &h0, Description = 52657475726E732054727565206966207072657373696E672074686520226261636B2074616222206B657920636F6D626F2073686F756C64206D6F76652074686520666F63757320746F20612070726576696F757320636F6E74726F6C2077697468696E2074686973206974656D2E
Function CanAcceptBackTab() As Boolean
/// Returns True if pressing the "back tab" key combo should move the focus to a previous control within this item.
///
/// Part of the `XUIInspectorItemWithMultipleTabFocusControls` interface.

If TopHasFocus Then
Return False
Else
Return True
End If

End Function
#tag EndMethod

#tag Method, Flags = &h0, Description = 52657475726E7320547275652069662074686973206974656D2069732061626C6520746F206163636570742074686520666F637573207669612074686520746162206B65792E
Function CanAcceptTabFocus() As Boolean
Function CanAcceptTab() As Boolean
/// Returns True if this item is able to accept the focus via the tab key.

Return True
Expand All @@ -58,6 +73,25 @@ Implements XUIInspectorItem,XUIInspectorItemKeyHandler,XUIInspectorItemWithMulti
End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F63757320766961207468652073686966742D746162206B657920636F6D626F202874686520226261636B2074616222292E
Sub DidReceiveBackTab()
/// This item has just received the focus via the shift-tab key combo (the "back tab").
///
/// Part of the `XUIInspectorItem` interface.

If Not TopHasFocus And Not BottomHasFocus Then
// If nothing has the focus, give the bottom text field the focus.
LostFocus
BottomHasFocus = True
mBottomTextField.SelectAll
ElseIf BottomHasFocus Then
LostFocus
TopHasFocus = True
mTopTextField.SelectAll
End If
End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F637573207669612074686520746162206B65792E
Sub DidReceiveTabFocus()
/// This item has just received the focus via the tab key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Implements XUIInspectorItem
#tag EndMethod

#tag Method, Flags = &h0, Description = 52657475726E7320547275652069662074686973206974656D2069732061626C6520746F206163636570742074686520666F637573207669612074686520746162206B65792E
Function CanAcceptTabFocus() As Boolean
Function CanAcceptTab() As Boolean
/// Returns True if this item is able to accept the focus via the tab key.

Return False
Expand All @@ -39,6 +39,16 @@ Implements XUIInspectorItem
End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F63757320766961207468652073686966742D746162206B657920636F6D626F202874686520226261636B2074616222292E
Sub DidReceiveBackTab()
/// This item has just received the focus via the shift-tab key combo (the "back tab").
///
/// Part of the `XUIInspectorItem` interface.

// Nothing to do since this item can't accept the focus via the back-tab key combo.
End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F637573207669612074686520746162206B65792E
Sub DidReceiveTabFocus()
/// This item has just received the focus via the tab key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ Protected Interface XUIInspectorItem
#tag EndMethod

#tag Method, Flags = &h0, Description = 52657475726E7320547275652069662074686973206974656D2069732061626C6520746F206163636570742074686520666F637573207669612074686520746162206B65792E
Function CanAcceptTabFocus() As Boolean
Function CanAcceptTab() As Boolean

End Function
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F63757320766961207468652073686966742D746162206B657920636F6D626F202874686520226261636B2074616222292E
Sub DidReceiveBackTab()

End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F637573207669612074686520746162206B65792E
Sub DidReceiveTabFocus()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Protected Interface XUIInspectorItemWithMultipleTabFocusControls
End Function
#tag EndMethod

#tag Method, Flags = &h0, Description = 52657475726E732054727565206966207072657373696E672074686520226261636B2074616222206B657920636F6D626F2073686F756C64206D6F76652074686520666F63757320746F20612070726576696F757320636F6E74726F6C2077697468696E2074686973206974656D2E
Function CanAcceptBackTab() As Boolean

End Function
#tag EndMethod


#tag Note, Name = About
Items implementing this interface contain more than one control that can accept the focus via the tab key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Implements XUIInspectorItem
#tag EndMethod

#tag Method, Flags = &h0, Description = 52657475726E7320547275652069662074686973206974656D2069732061626C6520746F206163636570742074686520666F637573207669612074686520746162206B65792E
Function CanAcceptTabFocus() As Boolean
Function CanAcceptTab() As Boolean
/// Returns True if this item is able to accept the focus via the tab key.

Return False
Expand Down Expand Up @@ -53,6 +53,16 @@ Implements XUIInspectorItem
End Function
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F63757320766961207468652073686966742D746162206B657920636F6D626F202874686520226261636B2074616222292E
Sub DidReceiveBackTab()
/// This item has just received the focus via the shift-tab key combo (the "back tab").
///
/// Part of the `XUIInspectorItem` interface.

// Nothing to do since this item can't accept the focus via the back-tab key combo.
End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F637573207669612074686520746162206B65792E
Sub DidReceiveTabFocus()
/// This item has just received the focus via the tab key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Implements XUIInspectorItem
#tag EndMethod

#tag Method, Flags = &h0, Description = 52657475726E7320547275652069662074686973206974656D2069732061626C6520746F206163636570742074686520666F637573207669612074686520746162206B65792E
Function CanAcceptTabFocus() As Boolean
Function CanAcceptTab() As Boolean
/// Returns True if this item is able to accept the focus via the tab key.

Return False
Expand All @@ -37,6 +37,16 @@ Implements XUIInspectorItem
End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F63757320766961207468652073686966742D746162206B657920636F6D626F202874686520226261636B2074616222292E
Sub DidReceiveBackTab()
/// This item has just received the focus via the shift-tab key combo (the "back tab").
///
/// Part of the `XUIInspectorItem` interface.

// Nothing to do since this item can't accept the focus via the back-tab key combo.
End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F637573207669612074686520746162206B65792E
Sub DidReceiveTabFocus()
/// This item has just received the focus via the tab key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@ Implements XUIInspectorItem,XUIInspectorItemKeyHandler
End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 52657475726E732054727565206966207072657373696E672074686520226261636B2074616222206B657920636F6D626F2073686F756C64206D6F76652074686520666F63757320746F20612070726576696F757320636F6E74726F6C2077697468696E2074686973206974656D2E
Function CanAcceptBackTab() As Boolean
/// Returns True if pressing the "back tab" key combo should move the focus to a previous control within this item.
///
/// Part of the `XUIInspectorItemWithMultipleTabFocusControls` interface.

Return True
End Function
#tag EndMethod

#tag Method, Flags = &h0, Description = 52657475726E7320547275652069662074686973206974656D2069732061626C6520746F206163636570742074686520666F637573207669612074686520746162206B65792E
Function CanAcceptTabFocus() As Boolean
Function CanAcceptTab() As Boolean
/// Returns True if this item is able to accept the focus via the tab key.

Return True
Expand All @@ -46,6 +56,18 @@ Implements XUIInspectorItem,XUIInspectorItemKeyHandler
End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F63757320766961207468652073686966742D746162206B657920636F6D626F202874686520226261636B2074616222292E
Sub DidReceiveBackTab()
/// This item has just received the focus via the shift-tab key combo (the "back tab").
///
/// Part of the `XUIInspectorItem` interface.

HasFocus = True
mTextField.SelectAll

End Sub
#tag EndMethod

#tag Method, Flags = &h0, Description = 54686973206974656D20686173206A7573742072656365697665642074686520666F637573207669612074686520746162206B65792E
Sub DidReceiveTabFocus()
/// This item has just received the focus via the tab key.
Expand Down
46 changes: 46 additions & 0 deletions src/XUI/XUIInspector/XUIInspector.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Inherits NSScrollViewCanvas

If command = CmdInsertTab Then
MoveFocusToNextItem

ElseIf command = CmdInsertBacktab Then
MoveFocusToPreviousItem

Else
// Delegate to the item currently in focus.
If ItemWithFocus <> Nil And ItemWithFocus IsA XUIInspectorItemKeyHandler Then
Expand Down Expand Up @@ -641,6 +645,48 @@ Inherits NSScrollViewCanvas
End Sub
#tag EndMethod

#tag Method, Flags = &h21, Description = 4D6F7665732074686520666F63757320746F207468652070726576696F7573206974656D20746861742063616E20616363657074207468652074616220666F6375732E
Private Sub MoveFocusToPreviousItem()
/// Moves the focus to the previous item that can accept the tab focus.

If ItemWithFocus = Nil Then
// Give the focus to the first item that can accept tab focus.
MoveFocusToFirstItem
Return
End If

If SectionWithFocus = Nil Then Return

// Start at the current section and loop backwards through all visible sections
// until we get back to the current section.

Var currentSectionIndex As Integer = mSections.IndexOf(SectionWithFocus)
If currentSectionIndex < 0 Or currentSectionIndex > mSections.LastIndex Then Return
For i As Integer = currentSectionIndex DownTo 0
Var result As XUIInspectorItem = mSections(i).MoveFocusToPreviousItem(ItemWithFocus)
If result <> Nil Then
ItemWithFocus = result
ItemWithFocus.DidReceiveBackTab
Return
End If
Next i

// Haven't found an item moving up the inspector that can receive the tab focus.
// Start at the bottom of the inspector, moving up to the current section.
For i As Integer = mSections.LastIndex DownTo currentSectionIndex
Var result As XUIInspectorItem = mSections(i).MoveFocusToPreviousItem(ItemWithFocus)
If result <> Nil Then
ItemWithFocus = result
ItemWithFocus.DidReceiveBackTab
Return
End If
Next i

// If we've reached here then there is no item to move the focus to.

End Sub
#tag EndMethod

#tag Method, Flags = &h21, Description = 52656275696C64732074686520696E7465726E616C207069637475726520746861742069732072656E646572656420746F2074686520696E73706563746F72277320677261706869637320636F6E746578742E
Private Sub RebuildBackBuffer()
/// Rebuilds the internal picture that is rendered to the inspector's graphics context.
Expand Down
Loading

0 comments on commit 4a306b0

Please sign in to comment.