AmendHub

Download:

jcs

/

amend

/

amendments

/

253

browser: Use a custom LDEF for file list to cross out deleted files

Also sort the list with deleted files at the bottom

jcs made amendment 253 5 months ago
--- amend.π.r Thu May 4 17:13:32 2023 +++ amend.π.r Wed Nov 1 15:42:38 2023 @@ -103,6 +103,10 @@ data 'LDEF' (128, "commit list", purgeable) { $"2F3A 0004 4E75 0000 0000" /* /:..Nu.... */ }; +data 'LDEF' (129, "file list", purgeable) { + $"2F3A 0004 4E75 0000 0000" /* /:..Nu.... */ +}; + data 'DLOG' (130, "SETTINGS_DLOG_ID") { $"005C 008C 00F0 0170 0001 0100 0000 0000" /* .\.å...p........ */ $"0000 0083 00BA 280A" /* ...É.∫(. */ --- amend.h Thu May 4 15:57:37 2023 +++ amend.h Wed Nov 1 12:54:08 2023 @@ -43,6 +43,12 @@ #define AMENDMENT_MENU_EXPORT_ID 2 #define AMENDMENT_LDEF_ID 128 +#define AMENDMENT_LIST_FONT geneva +#define AMENDMENT_LIST_FONT_SIZE 9 + +#define FILE_LDEF_ID 129 +#define FILE_LIST_FONT geneva +#define FILE_LIST_FONT_SIZE 10 #define SETTINGS_DLOG_ID 130 #define SETTINGS_SAVE_ID 1 --- browser.c Thu May 4 17:36:29 2023 +++ browser.c Wed Nov 1 13:08:57 2023 @@ -30,8 +30,6 @@ #include "tetab.h" #include "util.h" -#define FILE_LIST_FONT geneva -#define FILE_LIST_FONT_SIZE 10 #define DIFF_BUTTON_FONT geneva #define DIFF_BUTTON_FONT_SIZE 12 @@ -41,6 +39,7 @@ bool browser_close(struct focusable *focusable); void browser_idle(struct focusable *focusable, EventRecord *event); void browser_update_menu(struct browser *browser); void browser_update(struct focusable *focusable, EventRecord *event); +void browser_patch_ldefs(void); void browser_show_amendment(struct browser *browser, struct repo_amendment *amendment); void browser_mouse_down(struct focusable *focusable, EventRecord *event); @@ -54,6 +53,7 @@ void browser_edit_amendment(struct browser *browser); Pattern fill_pattern; Handle amendment_list_ldef_h = NULL; +Handle file_list_ldef_h = NULL; void browser_idle(struct focusable *focusable, EventRecord *event) @@ -149,17 +149,17 @@ browser_init(struct repo *repo) err(1, "Can't create window"); SetPort(browser->win); + browser_patch_ldefs(); + /* file list */ bounds.top = bounds.left = PADDING; bounds.bottom = browser->win->portRect.bottom - (browser->win->portRect.bottom * 0.6) - 2 - 20 - PADDING - PADDING; bounds.right = 100; - TextFont(FILE_LIST_FONT); - TextFace(0); - TextSize(FILE_LIST_FONT_SIZE); - browser->file_list = LNew(&bounds, &data_bounds, cell_size, 0, - browser->win, true, true, false, true); + cell_size.v = FontHeight(FILE_LIST_FONT, FILE_LIST_FONT_SIZE); + browser->file_list = LNew(&bounds, &data_bounds, cell_size, + FILE_LDEF_ID, browser->win, true, true, false, true); if (!browser->file_list) err(1, "Can't create file list"); LAddColumn(1, 0, browser->file_list); @@ -180,14 +180,8 @@ browser_init(struct repo *repo) bounds.left = bounds.right + PADDING; bounds.right = browser->win->portRect.right - SCROLLBAR_WIDTH - PADDING; - if (amendment_list_ldef_h == NULL) { - /* dynamically patch list LDEF to point to our custom function */ - amendment_list_ldef_h = xGetResource('LDEF', AMENDMENT_LDEF_ID); - HLock(amendment_list_ldef_h); - ((tCodeStub *)*amendment_list_ldef_h)->addr = &amendment_list_ldef; - } - - cell_size.v = (FontHeight(geneva, 9) * 2) + 2; + cell_size.v = (FontHeight(AMENDMENT_LIST_FONT, + AMENDMENT_LIST_FONT_SIZE) * 2) + 2; browser->amendment_list = LNew(&bounds, &data_bounds, cell_size, AMENDMENT_LDEF_ID, browser->win, true, true, false, true); if (!browser->amendment_list) @@ -274,7 +268,6 @@ browser_close_committer(struct browser *browser) void browser_add_files(struct browser *browser) { - char filename[256]; Cell cell = { 0, 0 }; short i; @@ -282,24 +275,17 @@ browser_add_files(struct browser *browser) LDelRow(0, 0, browser->file_list); browser_show_amendment(browser, NULL); - TextFont(FILE_LIST_FONT); - TextFace(0); - TextSize(FILE_LIST_FONT_SIZE); LAddRow(1, cell.v, browser->file_list); - LSetCell("[All Files]", 11, cell, browser->file_list); + /* will become "[All Files]" */ + LSetCell(NULL, sizeof(Ptr), cell, browser->file_list); LSetSelect(true, cell, browser->file_list); cell.v++; /* fill in files */ for (i = 0; i < browser->repo->nfiles; i++) { LAddRow(1, cell.v, browser->file_list); - if (browser->repo->files[i]->flags & REPO_FILE_DELETED) - snprintf(filename, sizeof(filename), "~%s~", - browser->repo->files[i]->filename); - else - strlcpy(filename, browser->repo->files[i]->filename, - sizeof(filename)); - LSetCell(&filename, strlen(filename), cell, browser->file_list); + LSetCell(&browser->repo->files[i], sizeof(Ptr), cell, + browser->file_list); cell.v++; } @@ -519,6 +505,25 @@ browser_edit_amendment(struct browser *browser) } void +browser_patch_ldefs(void) +{ + /* dynamically patch LDEFs to point to our custom functions */ + if (file_list_ldef_h == NULL || *file_list_ldef_h == NULL || + ((tCodeStub *)*file_list_ldef_h)->addr == 0) { + file_list_ldef_h = xGetResource('LDEF', FILE_LDEF_ID); + HLock(file_list_ldef_h); + ((tCodeStub *)*file_list_ldef_h)->addr = &file_list_ldef; + } + + if (amendment_list_ldef_h == NULL || *amendment_list_ldef_h == NULL || + ((tCodeStub *)*amendment_list_ldef_h)->addr == 0) { + amendment_list_ldef_h = xGetResource('LDEF', AMENDMENT_LDEF_ID); + HLock(amendment_list_ldef_h); + ((tCodeStub *)*amendment_list_ldef_h)->addr = &amendment_list_ldef; + } +} + +void browser_update_menu(struct browser *browser) { TERec *diff; @@ -591,32 +596,24 @@ browser_update(struct focusable *focusable, EventRecor InsetRect(&r, -1, -1); FrameRect(&r); + /* + * Under heavy memory pressure, List Manager seems to close our + * custom resources and then re-open them, clearing the custom + * addrs we set during setup. Make sure they're still alive before + * doing an update or we'll jump to NULL. + */ + browser_patch_ldefs(); + r = (*(browser->file_list))->rView; InsetRect(&r, -1, -1); FillRect(&r, white); FrameRect(&r); - TextFont(FILE_LIST_FONT); - TextFace(0); - TextSize(FILE_LIST_FONT_SIZE); LUpdate(browser->win->visRgn, browser->file_list); r = (*(browser->amendment_list))->rView; InsetRect(&r, -1, -1); FillRect(&r, white); FrameRect(&r); - - /* - * Under heavy memory pressure, List Manager seems to close our - * custom resource and then re-open it, clearing the custom addr - * we set during setup. Make sure it's still alive before doing - * an update or we'll jump to NULL. - */ - if (*amendment_list_ldef_h == NULL || - ((tCodeStub *)*amendment_list_ldef_h)->addr == 0) { - amendment_list_ldef_h = xGetResource('LDEF', AMENDMENT_LDEF_ID); - HLock(amendment_list_ldef_h); - ((tCodeStub *)*amendment_list_ldef_h)->addr = &amendment_list_ldef; - } LUpdate(browser->win->visRgn, browser->amendment_list); TextFont(DIFF_BUTTON_FONT); @@ -660,11 +657,6 @@ browser_mouse_down(struct focusable *focusable, EventR if (PtInRect(p, &r)) { /* store what is selected now */ nselected = browser_selected_file_ids(browser, &selected_files); - - /* in case any new items are redrawn in LClick */ - TextFont(FILE_LIST_FONT); - TextFace(0); - TextSize(FILE_LIST_FONT_SIZE); /* possibly highlight a new cell */ LClick(p, event->modifiers, browser->file_list); --- browser.h Wed Mar 29 11:56:56 2023 +++ browser.h Tue Oct 31 13:07:23 2023 @@ -63,5 +63,8 @@ void browser_apply_diff(struct browser *browser); pascal void amendment_list_ldef(short message, Boolean selected, Rect *cellRect, Cell theCell, short dataOffset, short dataLen, ListHandle theList); - +pascal void file_list_ldef(short message, Boolean selected, + Rect *cellRect, Cell theCell, short dataOffset, short dataLen, + ListHandle theList); + #endif --- commit_list.c Thu May 4 17:11:58 2023 +++ commit_list.c Wed Nov 1 12:59:03 2023 @@ -17,13 +17,11 @@ #include <string.h> #include <stdio.h> #include <time.h> +#include "amend.h" #include "browser.h" #include "repo.h" #include "util.h" -#define LIST_FONT geneva -#define LIST_FONT_SIZE 9 - void amendment_list_draw_cell(ListHandle theList, Cell theCell, short dataLen, Rect *cellRect, Boolean selected); @@ -70,10 +68,10 @@ amendment_list_draw_cell(ListHandle theList, Cell theC EraseRect(&textRect); InsetRect(&textRect, 4, 4); - height = FontHeight(LIST_FONT, LIST_FONT_SIZE); + height = FontHeight(AMENDMENT_LIST_FONT, AMENDMENT_LIST_FONT_SIZE); TextFace(bold); - TextFont(LIST_FONT); - TextSize(LIST_FONT_SIZE); + TextFont(AMENDMENT_LIST_FONT); + TextSize(AMENDMENT_LIST_FONT_SIZE); MoveTo(textRect.left, textRect.top + 6); if (amendment == NULL) { --- file_list.c Wed Nov 1 13:19:02 2023 +++ file_list.c Wed Nov 1 13:19:02 2023 @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2021, 2023 joshua stein <jcs@jcs.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <string.h> +#include <stdio.h> +#include <time.h> +#include "amend.h" +#include "browser.h" +#include "repo.h" +#include "util.h" + +void file_list_draw_cell(ListHandle theList, Cell theCell, + short dataLen, Rect *cellRect, Boolean selected); + +pascal void +file_list_ldef(short message, Boolean selected, Rect *cellRect, + Cell theCell, short dataOffset, short dataLen, ListHandle theList) +{ + switch (message) { + case 0: + /* init */ + break; + case 1: + /* update */ + /* FALLTHROUGH */ + case 2: + /* hilight */ + file_list_draw_cell(theList, theCell, dataLen, cellRect, selected); + break; + case 3: + /* close */ + break; + } +} + +void +file_list_draw_cell(ListHandle theList, Cell theCell, short dataLen, + Rect *cellRect, Boolean selected) +{ + static char all_files_text[] = "All Files"; + Rect textRect; + char tmp[50]; + struct repo_file *file = NULL; + struct tm *ttm = NULL; + short len; + + textRect.left = cellRect->left; + textRect.right = cellRect->right; + textRect.top = cellRect->top; + textRect.bottom = cellRect->bottom + 1; + EraseRect(&textRect); + InsetRect(&textRect, 4, 4); + + TextFace(0); + TextFont(FILE_LIST_FONT); + TextSize(FILE_LIST_FONT_SIZE); + MoveTo(textRect.left, textRect.top + 6); + + if (theCell.v == 0) { + TextFace(bold); + DrawText(all_files_text, 0, strlen(all_files_text)); + } else { + LGetCell(&file, &dataLen, theCell, theList); + len = strlen(file->filename); + DrawText(file->filename, 0, len); + + if (file->flags & REPO_FILE_DELETED) { + MoveTo(textRect.left, textRect.top + 3); + LineTo(textRect.left + TextWidth(file->filename, 0, len), + textRect.top + 3); + } + } + + if (selected) + InvertRect(cellRect); +} --- repo.c Tue Sep 19 20:44:45 2023 +++ repo.c Wed Nov 1 15:35:55 2023 @@ -720,15 +720,23 @@ repo_sort_files(struct repo *repo) { struct repo_file *file; short i, j; + + for (i = 0; i < repo->nfiles; i++) { + repo->files[i]->sort_filename[0] = '0'; + if (repo->files[i]->flags & REPO_FILE_DELETED) + repo->files[i]->sort_filename[1] = 'Z'; + else + repo->files[i]->sort_filename[1] = 'A'; + } for (i = 1; i < repo->nfiles; i++) { for (j = i; j > 0; j--) { file = repo->files[j]; - if (strnatcasecmp(file->filename, - repo->files[j - 1]->filename) == 1) + if (strnatcasecmp((const char *)&file->sort_filename, + (const char *)&repo->files[j - 1]->sort_filename) == 1) break; - + repo->files[j] = repo->files[j - 1]; repo->files[j - 1] = file; } --- repo.h Thu May 4 15:58:49 2023 +++ repo.h Wed Nov 1 15:35:09 2023 @@ -38,6 +38,7 @@ struct repo_file { short id; + char sort_filename[2]; char filename[256]; OSType type; OSType creator;