AmendHub

Download:

jcs

/

amend

/

amendments

/

24

browser+committer: Improve Edit menu ops, add Cut+Paste in committer

Keep track of which TextEdit control was last clicked in committer and
make Edit menu operations affect that one.

jcs made amendment 24 over 3 years ago
--- amend.h Mon Oct 18 13:09:14 2021 +++ amend.h Fri Oct 29 15:19:30 2021 @@ -27,8 +27,10 @@ #define FILE_MENU_QUIT_ID 4 #define EDIT_MENU_ID 130 -#define EDIT_MENU_COPY_ID 1 -#define EDIT_MENU_SELECT_ALL_ID 2 +#define EDIT_MENU_CUT_ID 1 +#define EDIT_MENU_COPY_ID 2 +#define EDIT_MENU_PASTE_ID 3 +#define EDIT_MENU_SELECT_ALL_ID 4 #define REPO_MENU_ID 131 #define REPO_MENU_ADD_FILE_ID 1 --- browser.c Mon Oct 18 13:09:06 2021 +++ browser.c Fri Oct 29 15:21:19 2021 @@ -416,15 +416,19 @@ browser_update_menu(struct browser *browser) HLock(browser->diff_te); diff = *(browser->diff_te); - if (diff->nLines == 0) - DisableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID); - else - EnableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID); + DisableItem(edit_menu, EDIT_MENU_CUT_ID); if (diff->selStart == diff->selEnd) DisableItem(edit_menu, EDIT_MENU_COPY_ID); else EnableItem(edit_menu, EDIT_MENU_COPY_ID); + + DisableItem(edit_menu, EDIT_MENU_PASTE_ID); + + if (diff->nLines == 0) + DisableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID); + else + EnableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID); HUnlock(browser->diff_te); --- committer.c Mon Oct 18 16:47:01 2021 +++ committer.c Fri Oct 29 15:59:23 2021 @@ -38,6 +38,9 @@ static DialogPtr committer_dialog = NULL; /* so diff_* know what they're operating on */ struct committer *cur_committer = NULL; +/* the last-accessed TE to do cut/copy/paste/select operations on */ +static TEHandle committer_last_te = NULL; + void committer_generate_diff(struct committer *committer); void committer_update_menu(struct committer *committer); void committer_status(char *format, ...); @@ -134,6 +137,7 @@ committer_init(struct browser *browser) "\pCommit", true, 1, 1, 1, pushButProc, 0L); ShowWindow(committer->win); + committer_last_te = committer->log_te; committer_update_menu(committer); DrawMenuBar(); @@ -159,12 +163,15 @@ committer_close(struct committer *committer) TEDispose(committer->diff_te); free(committer); + + committer_last_te = NULL; } void committer_idle(struct committer *committer) { - TEIdle(committer->log_te); + if (committer_last_te == committer->log_te) + TEIdle(committer->log_te); } void @@ -247,6 +254,7 @@ committer_mouse_down(struct committer *committer, Even if (PtInRect(p, &r)) { TEClick(p, ((event->modifiers & shiftKey) != 0), committer->diff_te); + committer_last_te = committer->diff_te; committer_update_menu(committer); return; } @@ -255,6 +263,7 @@ committer_mouse_down(struct committer *committer, Even if (PtInRect(p, &r)) { TEClick(p, ((event->modifiers & shiftKey) != 0), committer->log_te); + committer_last_te = committer->log_te; committer_update_menu(committer); return; } @@ -304,23 +313,38 @@ committer_update_menu(struct committer *committer) HLock(committer->diff_te); HLock(committer->log_te); - if ((*(committer->diff_te))->nLines == 0 && - (*(committer->log_te))->nLines == 0) { - DisableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID); - HiliteControl(committer->commit_button, 255); - } else { - EnableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID); - if ((*(committer->log_te))->nLines > 0 && committer->ndiffed_files) - HiliteControl(committer->commit_button, 0); + if (committer_last_te == committer->diff_te) { + DisableItem(edit_menu, EDIT_MENU_CUT_ID); + if ((*(committer->diff_te))->selStart == + (*(committer->diff_te))->selEnd) + DisableItem(edit_menu, EDIT_MENU_COPY_ID); + else + EnableItem(edit_menu, EDIT_MENU_COPY_ID); + if ((*(committer->diff_te))->nLines > 0) + EnableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID); + else + DisableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID); + DisableItem(edit_menu, EDIT_MENU_PASTE_ID); + } else if (committer_last_te == committer->log_te) { + if ((*(committer->log_te))->selStart == + (*(committer->log_te))->selEnd) { + DisableItem(edit_menu, EDIT_MENU_CUT_ID); + DisableItem(edit_menu, EDIT_MENU_COPY_ID); + } else { + EnableItem(edit_menu, EDIT_MENU_CUT_ID); + EnableItem(edit_menu, EDIT_MENU_COPY_ID); + } + if ((*(committer->log_te))->nLines > 0) + EnableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID); + else + DisableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID); + EnableItem(edit_menu, EDIT_MENU_PASTE_ID); } - if ((*(committer->diff_te))->selStart == - (*(committer->diff_te))->selEnd && - (*(committer->log_te))->selStart == - (*(committer->log_te))->selEnd) - DisableItem(edit_menu, EDIT_MENU_COPY_ID); + if ((*(committer->log_te))->nLines > 0 && committer->ndiffed_files) + HiliteControl(committer->commit_button, 0); else - EnableItem(edit_menu, EDIT_MENU_COPY_ID); + HiliteControl(committer->commit_button, 255); DisableItem(repo_menu, REPO_MENU_ADD_FILE_ID); DisableItem(repo_menu, REPO_MENU_REVERT_FILE_ID); @@ -451,6 +475,37 @@ committer_commit(struct committer *committer) browser = committer->browser; browser_close_committer(committer->browser); browser->state = BROWSER_STATE_UPDATE_COMMIT_LIST; +} + +void +committer_handle_menu(struct committer *committer, long menu_id) +{ + switch (HiWord(menu_id)) { + case EDIT_MENU_ID: + switch (LoWord(menu_id)) { + case EDIT_MENU_CUT_ID: + if (committer_last_te == committer->log_te) { + TECut(committer->log_te); + committer_update_menu(committer); + } + break; + case EDIT_MENU_COPY_ID: + TECopy(committer_last_te); + committer_update_menu(committer); + break; + case EDIT_MENU_PASTE_ID: + if (committer_last_te == committer->log_te) { + TEPaste(committer->log_te); + committer_update_menu(committer); + } + break; + case EDIT_MENU_SELECT_ALL_ID: + TESetSelect(0, 1024 * 32, committer_last_te); + committer_update_menu(committer); + break; + } + break; + } } size_t --- committer.h Mon Oct 18 15:49:37 2021 +++ committer.h Fri Oct 29 15:47:29 2021 @@ -50,6 +50,7 @@ void committer_update(struct committer *committer, Eve void committer_key_down(struct committer *committer, EventRecord *event); void committer_mouse_down(struct committer *committer, EventRecord *event); void committer_generate_diff(struct committer *committer); +void committer_handle_menu(struct committer *committer, long menu_id); size_t diff_output(const char *format, ...); --- main.c Mon Oct 18 09:22:19 2021 +++ main.c Fri Oct 29 15:45:46 2021 @@ -231,20 +231,19 @@ handle_menu(long menu_id) } break; case EDIT_MENU_ID: - /* TODO: detect whether to operate on committer diff or log */ - switch (LoWord(menu_id)) { - case EDIT_MENU_COPY_ID: - if (cur_browser && cur_browser->committer) - TECopy(cur_browser->committer->diff_te); - else if (cur_browser) - TECopy(cur_browser->diff_te); - break; - case EDIT_MENU_SELECT_ALL_ID: - if (cur_browser && cur_browser->committer) - TESetSelect(0, 1024 * 32, cur_browser->committer->diff_te); - else if (cur_browser) - TESetSelect(0, 1024 * 32, cur_browser->diff_te); - break; + if (cur_browser && cur_browser->committer) + committer_handle_menu(cur_browser->committer, menu_id); + else { + switch (LoWord(menu_id)) { + case EDIT_MENU_COPY_ID: + if (cur_browser) + TECopy(cur_browser->diff_te); + break; + case EDIT_MENU_SELECT_ALL_ID: + if (cur_browser) + TESetSelect(0, 1024 * 32, cur_browser->diff_te); + break; + } } break; case REPO_MENU_ID: @@ -284,8 +283,10 @@ update_menu(void) return; } - DisableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID); + DisableItem(edit_menu, EDIT_MENU_CUT_ID); DisableItem(edit_menu, EDIT_MENU_COPY_ID); + DisableItem(edit_menu, EDIT_MENU_PASTE_ID); + DisableItem(edit_menu, EDIT_MENU_SELECT_ALL_ID); DisableItem(repo_menu, REPO_MENU_ADD_FILE_ID); DisableItem(repo_menu, REPO_MENU_REVERT_FILE_ID);