AmendHub

Download:

jcs

/

wallops

/

amendments

/

58

main+chatter: Implement menu updating for cut/copy/paste


jcs made amendment 58 3 months ago
--- chatter.c Fri Aug 30 20:08:34 2024 +++ chatter.c Sat Aug 31 20:05:57 2024 @@ -42,6 +42,7 @@ void chatter_key_down(struct focusable *focusable, Eve void chatter_mouse_down(struct focusable *focusable, EventRecord *event); void chatter_resize(struct focusable *focusable, EventRecord *event); bool chatter_menu(struct focusable *focusable, short menu, short item); +void chatter_update_menu(struct focusable *focusable); void chatter_idle(struct focusable *focusable, EventRecord *event); void chatter_update(struct focusable *focusable, EventRecord *event); void chatter_resume(struct focusable *focusable, EventRecord *event); @@ -109,6 +110,7 @@ chatter_init(const char *server, const unsigned short focusable->quit = chatter_quit; focusable->resize = chatter_resize; focusable->menu = chatter_menu; + focusable->update_menu = chatter_update_menu; focusable->resume = chatter_resume; focusable_add(focusable); chatter->focusable = focusable; @@ -809,6 +811,37 @@ chatter_menu(struct focusable *focusable, short menu, } return false; +} + +void +chatter_update_menu(struct focusable *focusable) +{ + struct chatter *chatter = (struct chatter *)(focusable->cookie); + struct chatter_tab *tab = chatter->current_tab; + + HLock(chatter->input_te); + HLock(tab->messages_te); + + EnableItem(edit_menu, EDIT_MENU_PASTE_ID); + + if ((*(chatter->input_te))->selStart != (*(chatter->input_te))->selEnd) { + EnableItem(edit_menu, EDIT_MENU_CUT_ID); + EnableItem(edit_menu, EDIT_MENU_COPY_ID); + goto done; + } + + if ((*(tab->messages_te))->selStart != (*(tab->messages_te))->selEnd) { + DisableItem(edit_menu, EDIT_MENU_CUT_ID); + EnableItem(edit_menu, EDIT_MENU_COPY_ID); + goto done; + } + + DisableItem(edit_menu, EDIT_MENU_CUT_ID); + DisableItem(edit_menu, EDIT_MENU_COPY_ID); + +done: + HUnlock(tab->messages_te); + HUnlock(chatter->input_te); } void --- chatter.h Fri Aug 30 17:22:56 2024 +++ chatter.h Fri Aug 30 21:58:59 2024 @@ -73,6 +73,8 @@ struct chatter { struct chatter_tab *current_tab; }; +extern MenuHandle apple_menu, file_menu, edit_menu; + void notify(void); void cancel_notification(void); --- focusable.h Sat Jan 7 19:16:17 2023 +++ focusable.h Fri Aug 30 21:53:59 2024 @@ -31,6 +31,7 @@ struct focusable { void (*mouse_down)(struct focusable *focusable, EventRecord *event); void (*resize)(struct focusable *focusable, EventRecord *event); bool (*menu)(struct focusable *focusable, short menu, short item); + void (*update_menu)(struct focusable *focusable); void (*suspend)(struct focusable *focusable, EventRecord *event); void (*resume)(struct focusable *focusable, EventRecord *event); bool (*close)(struct focusable *focusable); --- main.c Fri Aug 30 19:21:35 2024 +++ main.c Fri Aug 30 22:20:53 2024 @@ -21,9 +21,9 @@ #include "tcp.h" #include "util.h" -MenuHandle apple_menu, file_menu; NMRec notification = { 0 }; struct settings settings; +MenuHandle apple_menu, file_menu, edit_menu; void update_menu(void); void handle_exit(void); @@ -67,6 +67,8 @@ main(void) AddResMenu(apple_menu, 'DRVR'); if (!(file_menu = GetMHandle(FILE_MENU_ID))) panic("no file menu"); + if (!(edit_menu = GetMHandle(EDIT_MENU_ID))) + panic("no edit menu"); update_menu(); DrawMenuBar(); @@ -146,6 +148,8 @@ main(void) found_focusable->mouse_down(found_focusable, &event); break; } + + update_menu(); break; case updateEvt: case activateEvt: @@ -184,6 +188,8 @@ main(void) } break; } + + update_menu(); } break; } @@ -259,6 +265,17 @@ handle_menu(long menu_id) void update_menu(void) { + if (nfocusables) { + if (focusables[0]->visible) { + EnableItem(edit_menu, 0); + if (focusables[0]->update_menu) + focusables[0]->update_menu(focusables[0]); + } else { + DisableItem(edit_menu, 0); + } + } else { + DisableItem(edit_menu, 0); + } } void