From a45b6b6b7b4a9b2730efde70855321d3d9c8ffdf Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Mon, 5 May 2025 20:16:52 +0100 Subject: [PATCH] fixed selection highlighting and key handling --- .gitignore | 1 + app/appui.cls | 178 +++++++++++++++++++++++++++----------------------- 2 files changed, 96 insertions(+), 83 deletions(-) diff --git a/.gitignore b/.gitignore index d014078..2d25885 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ docs/ *.iml +db/test*.sqlite diff --git a/app/appui.cls b/app/appui.cls index 734ffbc..51a83f1 100644 --- a/app/appui.cls +++ b/app/appui.cls @@ -29,11 +29,10 @@ self~SetPanelColor(win, clrset) if with_box = .true then DO - win~box(0, 0) /* Draw box with default ACS characters */ - win~refresh + win~box(0, 0) /* Draw box with default ACS characters */ + win~refresh END - - return win + return win ::METHOD DrawSubPanel use arg height, width, starty, startx, clrset, title, with_box @@ -52,7 +51,7 @@ new_win~box(0,0) new_win~refresh END - return new_win + return new_win ::METHOD SetPanelColor use arg panel, clrset @@ -79,83 +78,84 @@ END panel~bkgd(panel~color_pair(clrset+1)) panel~refresh + RETURN ::method setupMainMenu - expose mainMenu win menuwin menuItems menu_keys - use arg win + expose mainMenu menuwin menu_items menu_keys selected + use arg win - max_y = win~lines - max_x = win~cols + max_y = win~lines + max_x = win~cols - menu_height = 21 - menu_width = 40 - start_y = (max_y - menu_height) % 2 - start_x = (max_x - menu_width) % 2 - clrset=1 - title = "Rexx Address Book" - with_box = .true + menu_height = 21 + menu_width = 40 + start_y = (max_y - menu_height) % 2 + start_x = (max_x - menu_width) % 2 + clrset=1 + title = "Rexx Address Book" + 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") + menuwin = self~DrawSubPanel(menu_height, menu_width, start_y, start_x, clrset, title, with_box) + 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") */ - menuwin~refresh - RETURN + /* Display menu items */ + .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,43 +168,55 @@ 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 + return /* Process selection */ ::METHOD ProcessSelection - 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~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~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~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~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~refresh - call SysWait 1 - END - otherwise nop - end - return + 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 + call SysWait 1 + END + when key_char = 'r' then do + 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 + call SysWait 1 + END + when key_char = 's' then do + 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 + 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 ::METHOD findInArray use arg array, item