AmendHub

Download:

jcs

/

amend

/

amendments

/

78

settings: Update TETabWidth after saving, no need for a warning


jcs made amendment 78 over 2 years ago
--- browser.c Wed Jun 15 09:04:03 2022 +++ browser.c Wed Jun 15 10:51:11 2022 @@ -164,7 +164,6 @@ browser_init(struct repo *repo) te_bounds = bounds; InsetRect(&te_bounds, 2, 2); browser->diff_te = TEStylNew(&te_bounds, &bounds); - TETabWidth = settings.tabwidth; TEAutoView(true, browser->diff_te); TETabEnable(browser->diff_te); (*(browser->diff_te))->caretHook = NullCaretHook; --- repo.c Tue Jun 14 09:53:05 2022 +++ repo.c Wed Jun 15 10:45:40 2022 @@ -110,7 +110,6 @@ repo_init(struct bile *bile, short is_new) repo = xmalloczero(sizeof(struct repo)); repo->bile = bile; - repo->tabwidth = 4; // (short)safe_GetStringAsLong(TABWIDTH_ID); repo->next_file_id = 1; repo->next_commit_id = 1; --- repo.h Sat Apr 16 13:31:24 2022 +++ repo.h Wed Jun 15 10:39:56 2022 @@ -75,7 +75,6 @@ struct repo_commit { struct repo { struct bile *bile; - short tabwidth; short nfiles; struct repo_file **files; short next_file_id; --- settings.c Wed Jun 15 09:13:11 2022 +++ settings.c Wed Jun 15 11:35:22 2022 @@ -19,6 +19,7 @@ #include "amend.h" #include "settings.h" +#include "tetab.h" #include "util.h" struct settings settings = { 0 }; @@ -40,6 +41,8 @@ settings_load(void) warn("Bogus tabwidth resource %d", settings.tabwidth); settings.tabwidth = 4; } + + TETabWidth = settings.tabwidth; } void @@ -52,25 +55,27 @@ settings_save(void) res = xGetResource('STR ', STR_AUTHOR_ID); HLock(res); l = strlen(settings.author); - SetHandleSize(res, l + 1); + xSetHandleSize(res, l + 1); memcpy(*res, settings.author, l + 1); CtoPstr(*res); - HUnlock(res); ChangedResource(res); - WriteResource(res); ReleaseResource(res); res = xGetResource('STR ', STR_TABWIDTH_ID); HLock(res); snprintf(tmp, sizeof(tmp), "%d", settings.tabwidth); l = strlen(tmp); - SetHandleSize(res, l + 1); + xSetHandleSize(res, l + 1); memcpy(*res, tmp, l + 1); CtoPstr(*res); - HUnlock(res); ChangedResource(res); - WriteResource(res); ReleaseResource(res); + + UpdateResFile(CurResFile()); + if (ResError()) + warn("UpdateResFile failed! %d", ResError()); + + TETabWidth = settings.tabwidth; } void @@ -79,7 +84,8 @@ settings_edit(void) Str255 txt; Handle ihandle; size_t len; - short done = 0, itype, hit, tabwidth; + short itype, hit; + bool done; DialogPtr dlg; Rect irect; @@ -99,14 +105,16 @@ settings_edit(void) ShowWindow(dlg); +dialog_wait: + done = false; while (!done) { ModalDialog(nil, &hit); switch (hit) { case SETTINGS_SAVE_ID: - done = 1; + done = true; break; case SETTINGS_CANCEL_ID: - goto done; + goto dialog_close; case SETTINGS_AUTHOR_ID: break; case SETTINGS_TABWIDTH_ID: @@ -120,22 +128,19 @@ settings_edit(void) if (strlen((char *)&txt) >= sizeof(settings.author)) { warn("Author setting is too long (%ld max)", sizeof(settings.author) - 1); - goto done; + goto dialog_wait; } + memcpy(settings.author, txt, strlen((char *)&txt) + 1); GetDItem(dlg, SETTINGS_TABWIDTH_ID, &itype, &ihandle, &irect); GetIText(ihandle, txt); PtoCstr(txt); - tabwidth = atoi((char *)&txt); + settings.tabwidth = atoi((char *)&txt); HUnlock(ihandle); - if (tabwidth != settings.tabwidth) { - warn("Restart Amend for new tabwidth setting to take effect"); - settings.tabwidth = tabwidth; - } settings_save(); -done: +dialog_close: DisposeDialog(dlg); }