@@ -20,7 +20,12 @@ in the source distribution for its full text.
2020#include "ProvideCurses.h"
2121
2222
23- static const char * const DisplayOptionsFunctions [] = {" " , " " , " " , " " , " " , " " , " " , " " , " " , "Done " , NULL };
23+ static const char * const BooleanDisplayOptionsFunctions [] = {"Select " , "Done " , NULL };
24+ static const char * const BooleanDisplayOptionsKeys [] = {"Enter" , "F10" , "Esc" };
25+ static const int BooleanDisplayOptionsEvents [] = {KEY_ENTER , KEY_F (10 ), 27 };
26+ static const char * const NumericDisplayOptionsFunctions [] = {"Decrement " , "Increment " , "Done " , NULL };
27+ static const char * const NumericDisplayOptionsKeys [] = {"-" , "+" , "F10" , "Esc" };
28+ static const int NumericDisplayOptionsEvents [] = {'-' , '+' , KEY_F (10 ), 27 };
2429
2530static void DisplayOptionsPanel_delete (Object * object ) {
2631 Panel * super = (Panel * ) object ;
@@ -29,13 +34,41 @@ static void DisplayOptionsPanel_delete(Object* object) {
2934 free (this );
3035}
3136
37+ static void DisplayOptionsPanel_setFunctionBar (Panel * super , OptionItem * item ) {
38+ if (OptionItem_kind (item ) == OPTION_ITEM_NUMBER ) {
39+ FunctionBar * fuBar = FunctionBar_new (NumericDisplayOptionsFunctions , NumericDisplayOptionsKeys , NumericDisplayOptionsEvents );
40+ super -> currentBar = fuBar ;
41+ } else {
42+ FunctionBar * fuBar = FunctionBar_new (BooleanDisplayOptionsFunctions , BooleanDisplayOptionsKeys , BooleanDisplayOptionsEvents );
43+ super -> currentBar = fuBar ;
44+ }
45+ FunctionBar_draw (super -> currentBar );
46+ }
47+
3248static HandlerResult DisplayOptionsPanel_eventHandler (Panel * super , int ch ) {
3349 DisplayOptionsPanel * this = (DisplayOptionsPanel * ) super ;
3450
3551 HandlerResult result = IGNORED ;
3652 OptionItem * selected = (OptionItem * ) Panel_getSelected (super );
3753
3854 switch (ch ) {
55+
56+ case KEY_UP : {
57+ int selected_index = Panel_getSelectedIndex (super );
58+ if (selected_index > 1 ) {
59+ OptionItem * next_to_select = (OptionItem * ) Panel_get (super , selected_index - 1 );
60+ DisplayOptionsPanel_setFunctionBar (super , next_to_select );
61+ }
62+ break ;
63+ }
64+ case KEY_DOWN : {
65+ int selected_index = Panel_getSelectedIndex (super );
66+ if (selected_index < Panel_size (super ) - 1 ) {
67+ OptionItem * next_to_select = (OptionItem * ) Panel_get (super , selected_index + 1 );
68+ DisplayOptionsPanel_setFunctionBar (super , next_to_select );
69+ }
70+ break ;
71+ }
3972 case '\n' :
4073 case '\r' :
4174 case KEY_ENTER :
@@ -90,8 +123,8 @@ const PanelClass DisplayOptionsPanel_class = {
90123DisplayOptionsPanel * DisplayOptionsPanel_new (Settings * settings , ScreenManager * scr ) {
91124 DisplayOptionsPanel * this = AllocThis (DisplayOptionsPanel );
92125 Panel * super = (Panel * ) this ;
93- FunctionBar * fuBar = FunctionBar_new (DisplayOptionsFunctions , NULL , NULL );
94- Panel_init (super , 1 , 1 , 1 , 1 , Class (OptionItem ), true, fuBar );
126+ FunctionBar * emptyFuBar = FunctionBar_new (NULL , NULL , NULL );
127+ Panel_init (super , 1 , 1 , 1 , 1 , Class (OptionItem ), true, emptyFuBar );
95128
96129 this -> settings = settings ;
97130 this -> scr = scr ;
@@ -141,5 +174,9 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
141174 #ifdef HAVE_LIBHWLOC
142175 Panel_add (super , (Object * ) CheckItem_newByRef ("Show topology when selecting affinity by default" , & (settings -> topologyAffinity )));
143176 #endif
177+
178+ OptionItem * defaultSelected = (OptionItem * ) Panel_getSelected (super );
179+ DisplayOptionsPanel_setFunctionBar (super , defaultSelected );
180+
144181 return this ;
145182}
0 commit comments