diff options
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 86 |
1 files changed, 57 insertions, 29 deletions
@@ -82,7 +82,7 @@ static const char *defaultDataDir_App_ = "~/Library/Application Support/fi.skyja | |||
82 | #endif | 82 | #endif |
83 | #if defined (iPlatformAppleMobile) | 83 | #if defined (iPlatformAppleMobile) |
84 | #define EMB_BIN "../../Resources/resources.lgr" | 84 | #define EMB_BIN "../../Resources/resources.lgr" |
85 | static const char *defaultDataDir_App_ = "~/config"; | 85 | static const char *defaultDataDir_App_ = "~/Library/Application Support"; |
86 | #endif | 86 | #endif |
87 | #if defined (iPlatformMsys) | 87 | #if defined (iPlatformMsys) |
88 | #define EMB_BIN "../resources.lgr" | 88 | #define EMB_BIN "../resources.lgr" |
@@ -397,6 +397,9 @@ static void saveState_App_(const iApp *d) { | |||
397 | serializeState_DocumentWidget(i.object, stream_File(f)); | 397 | serializeState_DocumentWidget(i.object, stream_File(f)); |
398 | } | 398 | } |
399 | } | 399 | } |
400 | else { | ||
401 | fprintf(stderr, "[App] failed to save state: %s\n", strerror(errno)); | ||
402 | } | ||
400 | iRelease(f); | 403 | iRelease(f); |
401 | } | 404 | } |
402 | 405 | ||
@@ -600,6 +603,39 @@ const iString *debugInfo_App(void) { | |||
600 | return msg; | 603 | return msg; |
601 | } | 604 | } |
602 | 605 | ||
606 | static void clearCache_App_(void) { | ||
607 | iForEach(ObjectList, i, iClob(listDocuments_App())) { | ||
608 | clearCache_History(history_DocumentWidget(i.object)); | ||
609 | } | ||
610 | } | ||
611 | |||
612 | void trimCache_App(void) { | ||
613 | iApp *d = &app_; | ||
614 | size_t cacheSize = 0; | ||
615 | const size_t limit = d->prefs.maxCacheSize * 1000000; | ||
616 | iObjectList *docs = listDocuments_App(); | ||
617 | iForEach(ObjectList, i, docs) { | ||
618 | cacheSize += cacheSize_History(history_DocumentWidget(i.object)); | ||
619 | } | ||
620 | init_ObjectListIterator(&i, docs); | ||
621 | iBool wasPruned = iFalse; | ||
622 | while (cacheSize > limit) { | ||
623 | iDocumentWidget *doc = i.object; | ||
624 | const size_t pruned = pruneLeastImportant_History(history_DocumentWidget(doc)); | ||
625 | if (pruned) { | ||
626 | cacheSize -= pruned; | ||
627 | wasPruned = iTrue; | ||
628 | } | ||
629 | next_ObjectListIterator(&i); | ||
630 | if (!i.value) { | ||
631 | if (!wasPruned) break; | ||
632 | wasPruned = iFalse; | ||
633 | init_ObjectListIterator(&i, docs); | ||
634 | } | ||
635 | } | ||
636 | iRelease(docs); | ||
637 | } | ||
638 | |||
603 | iLocalDef iBool isWaitingAllowed_App_(iApp *d) { | 639 | iLocalDef iBool isWaitingAllowed_App_(iApp *d) { |
604 | #if defined (LAGRANGE_IDLE_SLEEP) | 640 | #if defined (LAGRANGE_IDLE_SLEEP) |
605 | if (d->isIdling) { | 641 | if (d->isIdling) { |
@@ -631,6 +667,14 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
631 | processEvents_App(postedEventsOnly_AppEventMode); | 667 | processEvents_App(postedEventsOnly_AppEventMode); |
632 | } | 668 | } |
633 | goto backToMainLoop; | 669 | goto backToMainLoop; |
670 | case SDL_APP_LOWMEMORY: | ||
671 | clearCache_App_(); | ||
672 | break; | ||
673 | case SDL_APP_TERMINATING: | ||
674 | case SDL_APP_WILLENTERBACKGROUND: | ||
675 | savePrefs_App_(d); | ||
676 | saveState_App_(d); | ||
677 | break; | ||
634 | case SDL_DROPFILE: { | 678 | case SDL_DROPFILE: { |
635 | iBool wasUsed = processEvent_Window(d->window, &ev); | 679 | iBool wasUsed = processEvent_Window(d->window, &ev); |
636 | if (!wasUsed) { | 680 | if (!wasUsed) { |
@@ -963,6 +1007,7 @@ static iBool handlePrefsCommands_(iWidget *d, const char *cmd) { | |||
963 | postCommandf_App("prefs.dialogtab arg:%u", | 1007 | postCommandf_App("prefs.dialogtab arg:%u", |
964 | tabPageIndex_Widget(tabs, currentTabPage_Widget(tabs))); | 1008 | tabPageIndex_Widget(tabs, currentTabPage_Widget(tabs))); |
965 | destroy_Widget(d); | 1009 | destroy_Widget(d); |
1010 | postCommand_App("prefs.changed"); | ||
966 | return iTrue; | 1011 | return iTrue; |
967 | } | 1012 | } |
968 | else if (equal_Command(cmd, "quoteicon.set")) { | 1013 | else if (equal_Command(cmd, "quoteicon.set")) { |
@@ -1036,33 +1081,6 @@ iDocumentWidget *newTab_App(const iDocumentWidget *duplicateOf, iBool switchToNe | |||
1036 | return doc; | 1081 | return doc; |
1037 | } | 1082 | } |
1038 | 1083 | ||
1039 | void trimCache_App(void) { | ||
1040 | iApp *d = &app_; | ||
1041 | size_t cacheSize = 0; | ||
1042 | const size_t limit = d->prefs.maxCacheSize * 1000000; | ||
1043 | iObjectList *docs = listDocuments_App(); | ||
1044 | iForEach(ObjectList, i, docs) { | ||
1045 | cacheSize += cacheSize_History(history_DocumentWidget(i.object)); | ||
1046 | } | ||
1047 | init_ObjectListIterator(&i, docs); | ||
1048 | iBool wasPruned = iFalse; | ||
1049 | while (cacheSize > limit) { | ||
1050 | iDocumentWidget *doc = i.object; | ||
1051 | const size_t pruned = pruneLeastImportant_History(history_DocumentWidget(doc)); | ||
1052 | if (pruned) { | ||
1053 | cacheSize -= pruned; | ||
1054 | wasPruned = iTrue; | ||
1055 | } | ||
1056 | next_ObjectListIterator(&i); | ||
1057 | if (!i.value) { | ||
1058 | if (!wasPruned) break; | ||
1059 | wasPruned = iFalse; | ||
1060 | init_ObjectListIterator(&i, docs); | ||
1061 | } | ||
1062 | } | ||
1063 | iRelease(docs); | ||
1064 | } | ||
1065 | |||
1066 | static iBool handleIdentityCreationCommands_(iWidget *dlg, const char *cmd) { | 1084 | static iBool handleIdentityCreationCommands_(iWidget *dlg, const char *cmd) { |
1067 | iApp *d = &app_; | 1085 | iApp *d = &app_; |
1068 | if (equal_Command(cmd, "ident.temp.changed")) { | 1086 | if (equal_Command(cmd, "ident.temp.changed")) { |
@@ -1153,6 +1171,10 @@ iBool handleCommand_App(const char *cmd) { | |||
1153 | suffixPtr_Command(cmd, "where"))); | 1171 | suffixPtr_Command(cmd, "where"))); |
1154 | return iTrue; | 1172 | return iTrue; |
1155 | } | 1173 | } |
1174 | else if (equal_Command(cmd, "prefs.changed")) { | ||
1175 | savePrefs_App_(d); | ||
1176 | return iTrue; | ||
1177 | } | ||
1156 | else if (equal_Command(cmd, "prefs.dialogtab")) { | 1178 | else if (equal_Command(cmd, "prefs.dialogtab")) { |
1157 | d->prefs.dialogTab = arg_Command(cmd); | 1179 | d->prefs.dialogTab = arg_Command(cmd); |
1158 | return iTrue; | 1180 | return iTrue; |
@@ -1410,7 +1432,13 @@ iBool handleCommand_App(const char *cmd) { | |||
1410 | return iTrue; | 1432 | return iTrue; |
1411 | } | 1433 | } |
1412 | else if (equal_Command(cmd, "tabs.close")) { | 1434 | else if (equal_Command(cmd, "tabs.close")) { |
1413 | iWidget * tabs = findWidget_App("doctabs"); | 1435 | iWidget *tabs = findWidget_App("doctabs"); |
1436 | #if defined (iPlatformAppleMobile) | ||
1437 | /* Can't close the last on mobile. */ | ||
1438 | if (tabCount_Widget(tabs) == 1) { | ||
1439 | return iTrue; | ||
1440 | } | ||
1441 | #endif | ||
1414 | const iRangecc tabId = range_Command(cmd, "id"); | 1442 | const iRangecc tabId = range_Command(cmd, "id"); |
1415 | iWidget * doc = !isEmpty_Range(&tabId) ? findWidget_App(cstr_Rangecc(tabId)) | 1443 | iWidget * doc = !isEmpty_Range(&tabId) ? findWidget_App(cstr_Rangecc(tabId)) |
1416 | : document_App(); | 1444 | : document_App(); |