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/ .idea/
docs/ docs/
*.iml *.iml
db/test*.sqlite

View File

@ -32,7 +32,6 @@
win~box(0, 0) /* Draw box with default ACS characters */ win~box(0, 0) /* Draw box with default ACS characters */
win~refresh win~refresh
END END
return win return win
::METHOD DrawSubPanel ::METHOD DrawSubPanel
@ -79,9 +78,10 @@
END END
panel~bkgd(panel~color_pair(clrset+1)) panel~bkgd(panel~color_pair(clrset+1))
panel~refresh panel~refresh
RETURN
::method setupMainMenu ::method setupMainMenu
expose mainMenu win menuwin menuItems menu_keys expose mainMenu menuwin menu_items menu_keys selected
use arg win use arg win
max_y = win~lines max_y = win~lines
@ -96,66 +96,66 @@
with_box = .true with_box = .true
menuwin = self~DrawSubPanel(menu_height, menu_width, start_y, start_x, clrset, title, with_box) 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_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", "x") menu_keys = .array~of("a", "r", "e", "s", "l", "q")
/* Display menu items */ /* Display menu items */
selected = 1 .environment~selected = 1
self~DrawMenu(menuwin, menuItems, selected, win) self~DrawMenu(menuwin, menu_items, .environment~selected, win)
/* menuwin~mvaddstr(menu_height - 2, 3, "Type 'X' to exit") */
menuwin~refresh menuwin~refresh
RETURN RETURN
::method DrawMenu ::method DrawMenu
expose win menuItems selected mainwin expose win menu_items menu_keys selected mainwin
use arg win, items, selected, mainwin use arg menuwin, items, selected, mainwin
do i = 1 to items~items do i = 1 to items~items
if i = selected then do if i = .environment~selected then do
win~attron(mainwin~COLOR_PAIR(2)) menuwin~attron(menuwin~attron(menuwin~A_REVERSE))
win~attron(mainwin~A_BOLD) menuwin~attron(menuwin~A_BOLD)
win~mvaddstr(i+3, 2, items[i]) menuwin~mvaddstr(i+3, 2, items[i])
win~attroff(mainwin~COLOR_PAIR(2)) menuwin~attroff(menuwin~A_REVERSE)
win~attroff(mainwin~A_BOLD) menuwin~attroff(menuwin~A_BOLD)
end end
else do else do
win~mvaddstr(i+3, 2, items[i]) menuwin~mvaddstr(i+3, 2, items[i])
end end
end end
win~refresh menuwin~refresh
return return
/** MAIN LOOP **/ /** MAIN LOOP **/
::method mainLoop ::method mainLoop
expose win mainMenu menuwin expose win mainMenu menuwin selected menu_items menu_keys
menuwin~refresh
running = .true running = .true
do while running do while running
menuwin~refresh
key = win~getch key = win~getch
menu_keys = .array~of("a", "r", "e", "s", "l", "x") old_selected = .environment~selected
select select
when key = win~KEY_UP then do when key = menuwin~KEY_UP then do
if selected > 1 then selected = selected - 1 if .environment~selected > 1 then .environment~selected = .environment~selected - 1
call DrawMenu menuwin, menuItems, selected, win self~DrawMenu(menuwin, menu_items, .environment~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 */
menuwin~refresh menuwin~refresh
call ProcessSelection menu_keys[selected], home
return
end 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 menuwin~endwin
.environment['STOPNOW'] = 1 .environment['STOPNOW'] = 1
RETURN RETURN
end 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 otherwise do
if datatype(key) = 'CHAR' then do if datatype(key) = 'CHAR' then do
key = lower(key) key = lower(key)
@ -168,40 +168,52 @@
return return
end end
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
end /* do while running */ end /* do while running */
return return
/* Process selection */ /* Process selection */
::METHOD ProcessSelection ::METHOD ProcessSelection
expose menu_items menu_keys
use arg menuwin, key_char use arg menuwin, key_char
select select
when key_char = 'a' then do 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 menuwin~refresh
call SysWait 1 call SysWait 1
END END
when key_char = 'r' then do 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 menuwin~refresh
call SysWait 1 call SysWait 1
END END
when key_char = 'e' then do 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 menuwin~refresh
call SysWait 1 call SysWait 1
END END
when key_char = 's' then do 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 menuwin~refresh
call SysWait 1 call SysWait 1
END END
when key_char = 'l' then do 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 menuwin~refresh
call SysWait 1 call SysWait 1
END 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 otherwise nop
end end
return return