*/}}
Sfoglia il codice sorgente

Remove user preference

ChengduLittleA 1 anno fa
parent
commit
e6c977a326
4 ha cambiato i file con 26 aggiunte e 7 eliminazioni
  1. 1 0
      la_interface.h
  2. 10 5
      la_kernel.c
  3. 10 0
      resources/la_operators.c
  4. 5 2
      resources/la_templates.c

+ 1 - 0
la_interface.h

@@ -1985,6 +1985,7 @@ void laProcessInitArguments(int argc, char* argv[],laInitArguments* ia);
 int laGetReady();
 int laGetReadyWith(laInitArguments* ia);
 void laShutoff(int SavePreferences);
+int laRestoreFactorySettings();
 void laSaveUserPreferences();
 void laEnsureUserPreferences();
 void laAddExtraExtension(int FileType, ...);

+ 10 - 5
la_kernel.c

@@ -1104,6 +1104,11 @@ void laShutoff(int SavePrefereces){
     memNoLonger();
 }
 
+int laRestoreFactorySettings(){
+    char path[1024]; sprintf(path, "%s%s", MAIN.WorkingDirectory->Ptr, "preferences.udf");
+    if(remove(path)){ return 0; }
+    return 1;
+}
 void laSaveUserPreferences(){
     char path[1024]; sprintf(path,"%s%s",MAIN.WorkingDirectory->Ptr,"preferences.udf");
     laUDF* udf=laPrepareUDF(path);
@@ -1723,10 +1728,10 @@ void laEnsurePanelInBound(laPanel *p, laUiList *uil){
         if ((p->X + p->W) > cw){ p->W -= (p->X + p->W - cw); }
         if ((p->Y + p->H) > ch){ p->H -= (p->Y + p->H - ch); }
     }else{
-        if (p->X+p->W < LA_RH*5) p->X = LA_RH*5-+p->W;
         if (p->Y < 0) p->Y = 0;
         if ((!p->Block)&&(!p->IsMenuPanel)){
             int cw2=cw-LA_RH*2,ch2=ch-LA_RH*2;
+            if (p->X + p->W < LA_RH * 5) p->X = LA_RH * 5 - +p->W;
             if (p->X > cw2){ p->X = cw2; } if (p->Y > ch2){ p->Y = ch2; }
             if (p->W > cw2){ p->W = cw2; } if (p->H > ch2){ p->H = ch2; }
         }
@@ -4534,13 +4539,13 @@ laUiItem *laEndCondition(laUiList *uil, laUiItem *Beginner){
 
     return ui;
 }
-laUiList *laMakeMenuPage(laUiList *uil, laColumn *c, const char *Title){
-    laUiItem *ui = memAcquireSimple(sizeof(laUiItem));
-    laUiList *muil = memAcquireSimple(sizeof(laUiList));
+laUiList* laMakeMenuPage(laUiList* uil, laColumn* c, const char* Title) {
+    laUiItem* ui = memAcquireSimple(sizeof(laUiItem));
+    laUiList* muil = memAcquireSimple(sizeof(laUiList));
 
     ui->Type = _LA_UI_MENU_ROOT;
     strSafeSet(&ui->Display, Title);
-    ui->State = LA_UI_NORMAL;
+    ui->State = LA_UI_NORMAL; ui->Flags|=LA_TEXT_ALIGN_CENTER;
     ui->C = c;
     lstAppendItem(&uil->UiItems, ui);
 

+ 10 - 0
resources/la_operators.c

@@ -723,6 +723,15 @@ int OPINV_UDFPropagate(laOperator *a, laEvent *e){
 int OPINV_SaveUserPreferences(laOperator *a, laEvent *e){
     laSaveUserPreferences(); return LA_FINISHED;
 }
+int OPINV_RestoreFactorySettings(laOperator* a, laEvent* e) {
+    if(laRestoreFactorySettings()){
+        laEnableMessagePanel(0, 0, "Success", "Restart the program for changes to take effect.", e->x, e->y, 200, 0);
+        MAIN.SavePreferenceOnExit = 0;
+    }else{
+        laEnableMessagePanel(0, 0, "Problem", "Unable to remove preference file.", e->x, e->y, 200, 0);
+    }
+    return LA_FINISHED;
+}
 
 int OPCHK_TerminateProgram(laPropPack *This, laStringSplitor *Instructions){
     return 1;
@@ -2180,6 +2189,7 @@ void la_RegisterBuiltinOperators(){
                                0, 0, 0, OPINV_RemoveResourceFolder, 0, U'❌', LA_ACTUATOR_SYSTEM);
 
     laCreateOperatorType("LA_save_user_preferences", "Save Preferences", "Save user preferences", 0, 0, 0, OPINV_SaveUserPreferences, 0, 0, LA_ACTUATOR_SYSTEM);
+    laCreateOperatorType("LA_restore_factory", "Restore Factory Settings", "Restore factory settings", 0, 0, 0, OPINV_RestoreFactorySettings, 0, 0, LA_ACTUATOR_SYSTEM);
 
     laCreateOperatorType("LA_confirm", "Confirm", "Confirm The Statement", 0, 0, 0, OPINV_DoNothing, 0, U'✔', LA_ACTUATOR_SYSTEM)
         ->ExtraInstructions = "feedback=CONFIRM;";

+ 5 - 2
resources/la_templates.c

@@ -1174,10 +1174,13 @@ void laui_UserPreference(laUiList *uil, laPropPack *Base, laPropPack *OperatorIn
     //p->Show = 0;
     //p->FastUpdate = 1;
 
-    b=laBeginRow(uil,cl,0,0); laUiItem* ui=laShowLabel(uil,cl,"Save on exit:",0,0); ui->Expand=1; ui->Flags|=LA_TEXT_ALIGN_RIGHT;
+    b=laBeginRow(uil,cl,0,0); 
+    muil = laMakeMenuPage(uil, cr, "☰"); mc = laFirstColumn(muil);
+    laShowItem(muil, mc, 0, "LA_restore_factory");
+    laUiItem* ui=laShowLabel(uil,cl,"Save on exit:",0,0); ui->Expand=1; ui->Flags|=LA_TEXT_ALIGN_RIGHT;
     laShowItemFull(uil,cl,0,"la.user_preferences.save_preferences_on_exit",LA_WIDGET_ENUM_HIGHLIGHT,"text=🞆",0,0);
     laEndRow(uil,b);
-    laShowItem(uil,cr,0,"LA_save_user_preferences");
+    laShowItem(uil, cr, 0, "LA_save_user_preferences")->Expand = 1;
 
     bracket = laMakeTab(uil, c, 0);{