fixed selection highlighting and key handling

This commit is contained in:
Greg Gauthier 2025-05-05 20:16:52 +01:00
parent 26d102377f
commit a45b6b6b7b
2 changed files with 96 additions and 83 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.idea/
docs/
*.iml
db/test*.sqlite

View File

@ -32,7 +32,6 @@
win~box(0, 0) /* Draw box with default ACS characters */
win~refresh
END
return win
::METHOD DrawSubPanel
@ -79,9 +78,10 @@
END
panel~bkgd(panel~color_pair(clrset+1))
panel~refresh
RETURN
::method setupMainMenu
expose mainMenu win menuwin menuItems menu_keys
expose mainMenu menuwin menu_items menu_keys selected
use arg win
max_y = win~lines
@ -96,66 +96,66 @@
with_box = .true
menuwin = self~DrawSubPanel(menu_height, menu_width, start_y, start_x, clrset, title, with_box)
menuItems = .array~of("[A]dd Contact", "[R]emove Contact", "[E]dit Contact", "[S]earch", "[L]ist All", "E[X]it")
menu_keys = .array~of("a", "r", "e", "s", "l", "x")
menu_items = .array~of("[A]dd Contact", "[R]emove Contact", "[E]dit Contact", "[S]earch", "[L]ist All", "[Q]uit")
menu_keys = .array~of("a", "r", "e", "s", "l", "q")
/* Display menu items */
selected = 1
self~DrawMenu(menuwin, menuItems, selected, win)
/* menuwin~mvaddstr(menu_height - 2, 3, "Type 'X' to exit") */
.environment~selected = 1
self~DrawMenu(menuwin, menu_items, .environment~selected, win)
menuwin~refresh
RETURN
::method DrawMenu
expose win menuItems selected mainwin
use arg win, items, selected, mainwin
expose win menu_items menu_keys selected mainwin
use arg menuwin, items, selected, mainwin
do i = 1 to items~items
if i = selected then do
win~attron(mainwin~COLOR_PAIR(2))
win~attron(mainwin~A_BOLD)
win~mvaddstr(i+3, 2, items[i])
win~attroff(mainwin~COLOR_PAIR(2))
win~attroff(mainwin~A_BOLD)
if i = .environment~selected then do
menuwin~attron(menuwin~attron(menuwin~A_REVERSE))
menuwin~attron(menuwin~A_BOLD)
menuwin~mvaddstr(i+3, 2, items[i])
menuwin~attroff(menuwin~A_REVERSE)
menuwin~attroff(menuwin~A_BOLD)
end
else do
win~mvaddstr(i+3, 2, items[i])
menuwin~mvaddstr(i+3, 2, items[i])
end
end
win~refresh
menuwin~refresh
return
/** MAIN LOOP **/
::method mainLoop
expose win mainMenu menuwin
expose win mainMenu menuwin selected menu_items menu_keys
menuwin~refresh
running = .true
do while running
menuwin~refresh
key = win~getch
menu_keys = .array~of("a", "r", "e", "s", "l", "x")
old_selected = .environment~selected
select
when key = win~KEY_UP then do
if selected > 1 then selected = selected - 1
call DrawMenu menuwin, menuItems, selected, win
end
when key = win~KEY_DOWN then do
if selected < menuItems~items then selected = selected + 1
call DrawMenu menuwin, menuItems, selected, win
end
when key = D2C(10) | key = D2C(13) then do /* Enter key - numeric codes only */
when key = menuwin~KEY_UP then do
if .environment~selected > 1 then .environment~selected = .environment~selected - 1
self~DrawMenu(menuwin, menu_items, .environment~selected, win)
menuwin~refresh
call ProcessSelection menu_keys[selected], home
return
end
when key = D2C(88) | key = D2C(120) | key = "x" | key = C2D("x") then do
when key = menuwin~KEY_DOWN then do
if .environment~selected < menu_items~items then .environment~selected = .environment~selected + 1
self~DrawMenu(menuwin, menu_items, .environment~selected, win)
menuwin~refresh
end
when key = D2C(81) | key = D2C(113) | key = "q" | key = C2D("q") then do
menuwin~endwin
.environment['STOPNOW'] = 1
RETURN
end
when key = D2C(10) | key = D2C(13) then do /* Enter key - numeric codes only */
menuwin~refresh
self~ProcessSelection(menuwin, menu_keys[.environment~selected])
return
end
otherwise do
if datatype(key) = 'CHAR' then do
key = lower(key)
@ -168,40 +168,52 @@
return
end
end
end
end /* otherwise */
end /* select */
/* Only redraw if selection changed */
if old_selected \= .environment~selected then do
self~DrawMenu(menuwin, menu_items, .environment~selected, win)
end
end /* do while running */
return
/* Process selection */
::METHOD ProcessSelection
expose menu_items menu_keys
use arg menuwin, key_char
select
when key_char = 'a' then do
menuwin~mvaddstr(19 - 3, 5, "I would launch the ADD panel ");menuwin~refresh;
menuwin~mvaddstr(19 - 3, 5, "I would launch the ADD panel ");
menuwin~refresh
call SysWait 1
END
when key_char = 'r' then do
menuwin~mvaddstr(19 - 3, 5, "I would launch the REMOVE panel ");menuwin~refresh;
menuwin~mvaddstr(19 - 3, 5, "I would launch the REMOVE panel ");
menuwin~refresh
call SysWait 1
END
when key_char = 'e' then do
menuwin~mvaddstr(19 - 3, 5, "I would launch the EDIT panel ");menuwin~refresh;
menuwin~mvaddstr(19 - 3, 5, "I would launch the EDIT panel ");
menuwin~refresh
call SysWait 1
END
when key_char = 's' then do
menuwin~mvaddstr(19 - 3, 5, "I would launch the SEARCH panel ");menuwin~refresh;
menuwin~mvaddstr(19 - 3, 5, "I would launch the SEARCH panel ");
menuwin~refresh
call SysWait 1
END
when key_char = 'l' then do
menuwin~mvaddstr(19 - 3, 5, "I would launch the LIST panel ");menuwin~refresh;
menuwin~mvaddstr(19 - 3, 5, "I would launch the LIST panel ")
menuwin~refresh
call SysWait 1
END
when key_char = 'q' then do
menuwin~mvaddstr(19 - 3, 5, "Exiting The Application... ");
menuwin~refresh
call SysWait 1
menuwin~endwin
.environment['STOPNOW'] = 1
END
otherwise nop
end
return