1- // ignore_for_file: public_member_api_docs, sort_constructors_first
21import 'package:command_palette/src/controller/command_palette_controller.dart' ;
32import 'package:command_palette/src/widgets/options/command_palette_body.dart' ;
43import 'package:flutter/foundation.dart' ;
@@ -87,18 +86,15 @@ class CommandPaletteConfig {
8786
8887 /// Whether or not to show the instructions bar at the bottom of the command
8988 /// palette modal, under all the options.
90- /// The current instructions tell the user how to user the modal with their
91- /// keyboard
9289 ///
93- /// The current instructions are:
94- /// * enter/return: to select, (or if an input action) to confirm
95- /// * up/down arrow: to navigate
96- /// * escape: to close
97- ///
98- /// When a nested action is selected:
99- /// * backspace: to cancel selected action
90+ /// This option is deprecated, prefer to use [instructionConfig] and set its
91+ /// property [CommandPaletteInstructionConfig.showInstructions]
10092 final bool showInstructions;
10193
94+ /// Configuration options for the instructions bar at the bottom of the
95+ /// command palette
96+ final CommandPaletteInstructionConfig instructionConfig;
97+
10298 CommandPaletteConfig ({
10399 ActionFilter ? filter,
104100 Key ? key,
@@ -115,11 +111,15 @@ class CommandPaletteConfig {
115111 this .right,
116112 this .height,
117113 this .width,
114+ @Deprecated ("Use CommandPaletteInstructionConfig.showInstructions instead" )
118115 this .showInstructions = false ,
116+ CommandPaletteInstructionConfig ? instructionConfig,
119117 }) : filter = filter ?? kDefaultFilter,
120118 builder = builder ?? kDefaultBuilder,
121119 openKeySet = openKeySet ?? _defaultOpenKeySet,
122- closeKeySet = closeKeySet ?? _defaultCloseKeySet;
120+ closeKeySet = closeKeySet ?? _defaultCloseKeySet,
121+ instructionConfig = instructionConfig ??
122+ CommandPaletteInstructionConfig (showInstructions: showInstructions);
123123
124124 @override
125125 bool operator == (Object other) {
@@ -139,7 +139,9 @@ class CommandPaletteConfig {
139139 other.left == left &&
140140 other.right == right &&
141141 other.height == height &&
142- other.width == width;
142+ other.width == width &&
143+ other.showInstructions == showInstructions &&
144+ other.instructionConfig == instructionConfig;
143145 }
144146
145147 @override
@@ -157,6 +159,85 @@ class CommandPaletteConfig {
157159 left.hashCode ^
158160 right.hashCode ^
159161 height.hashCode ^
160- width.hashCode;
162+ width.hashCode ^
163+ showInstructions.hashCode ^
164+ instructionConfig.hashCode;
165+ }
166+ }
167+
168+ /// Configures the text and visibility of the instructions bar at the bottom of
169+ /// the command palette
170+ /// The current instructions tell the user how to user the modal with their
171+ /// keyboard
172+ ///
173+ /// The current instructions are:
174+ /// * enter/return: to select, (or if an input action) to confirm
175+ /// * up/down arrow: to navigate
176+ /// * escape: to close
177+ ///
178+ /// When a nested action is selected:
179+ /// * backspace: to cancel selected action
180+ class CommandPaletteInstructionConfig {
181+ /// Default value is "to confirm".
182+ /// Used with [CommandPaletteActionType.input] type actions to indicate to the
183+ /// user that the currently entered text can be submitted with the
184+ /// return/enter key
185+ final String confirmLabel;
186+
187+ /// Default value is "to select"
188+ /// Appears for all non input type action to indicate to the user that hitting
189+ /// the return/enter key will select the currently highlighted action
190+ final String selectLabel;
191+
192+ /// Default value is "to navigate"
193+ /// Tells the user the the up and down arrow keys can be used to highlight
194+ /// different actions in the command palette
195+ final String navigationLabel;
196+
197+ /// Default value is "to cancel selected action".
198+ /// Used with [CommandPaletteActionType.input] and
199+ /// [CommandPaletteActionType.nested] type actions, after that action has been
200+ /// select. Tells the user that pressing back-space will unselect the
201+ /// currently selected action
202+ final String cancelSelectedLabel;
203+
204+ /// Default value is "to close"
205+ /// Tells the user that the ESC key will close the command palette
206+ final String closeLabel;
207+
208+ /// Whether or not to show the instructions bar at the bottom of the command
209+ /// palette modal, under all the options.
210+ final bool showInstructions;
211+
212+ const CommandPaletteInstructionConfig ({
213+ this .confirmLabel = "to confirm" ,
214+ this .selectLabel = "to select" ,
215+ this .navigationLabel = "to navigate" ,
216+ this .cancelSelectedLabel = "to cancel selected action" ,
217+ this .closeLabel = "to close" ,
218+ this .showInstructions = false ,
219+ });
220+
221+ @override
222+ bool operator == (Object other) {
223+ if (identical (this , other)) return true ;
224+
225+ return other is CommandPaletteInstructionConfig &&
226+ other.confirmLabel == confirmLabel &&
227+ other.selectLabel == selectLabel &&
228+ other.navigationLabel == navigationLabel &&
229+ other.cancelSelectedLabel == cancelSelectedLabel &&
230+ other.closeLabel == closeLabel &&
231+ other.showInstructions == showInstructions;
232+ }
233+
234+ @override
235+ int get hashCode {
236+ return confirmLabel.hashCode ^
237+ selectLabel.hashCode ^
238+ navigationLabel.hashCode ^
239+ cancelSelectedLabel.hashCode ^
240+ closeLabel.hashCode ^
241+ showInstructions.hashCode;
161242 }
162243}
0 commit comments