*/}}
Procházet zdrojové kódy

Warning file selector

Yiming Wu před 1 rokem
rodič
revize
823a8fcddd
5 změnil soubory, kde provedl 77 přidání a 29 odebrání
  1. 7 0
      la_interface.h
  2. 4 1
      la_kernel.c
  3. 48 12
      resources/la_operators.c
  4. 8 10
      resources/la_templates.c
  5. 10 6
      resources/la_widgets.c

+ 7 - 0
la_interface.h

@@ -234,6 +234,8 @@ STRUCTURE(laRackPageCollection){
 
 typedef laBaseNodeType* (*laGetBaseNodeTypeF)(char* str);
 
+NEED_STRUCTURE(laConfirmData);
+
 STRUCTURE(LA){
     laListItem Hyper;
 
@@ -242,6 +244,8 @@ STRUCTURE(LA){
 
     laListHandle Windows;
     laListHandle WastedPanels;
+
+    laConfirmData *InvokeConfirmData;
     
     laPreFrameF  PreFrame;
     laPreDrawF   PreDraw;
@@ -1547,6 +1551,9 @@ STRUCTURE(laFileBrowser){
     laListHandle Disks;
 
     int SelectFolder;
+    int WarnFileExists;
+    int StatusWaitingWarning;
+    char UseFormat[64];
 };
 
 STRUCTURE(laUDFPreviewExtra){

+ 4 - 1
la_kernel.c

@@ -1686,7 +1686,7 @@ void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
     }
 
     for (p = w->FadingPanels.pLast; p; p = NextP){
-        NextP = p->Item.pNext;
+        NextP = p->Item.pPrev;
         if (!p->AnimationMode){
             lstRemoveItem(&w->FadingPanels, p);
             p->AnimationMode = LA_PANEL_ANIMATION_DESTROY;
@@ -5723,6 +5723,7 @@ int laInvokeP(laOperator *From, laOperatorType *at, laEvent *e, laPropPack *This
 
     if (rev & LA_FINISH){
         a->StopNow = 1;  if(From)From->Child=0;
+        laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
     }
 
     if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
@@ -5787,6 +5788,7 @@ int laInvokePCreateThis(laOperator *From, laOperatorType *at, laEvent *e, laProp
 
     if (rev & LA_FINISH){
         a->StopNow = 1; if(From)From->Child=0;
+        laConfirmSameDataIfAny(a); la_DestroyConfirmData(&MAIN.InvokeConfirmData); MAIN.InvokeConfirmData=a->NextConfirmData;
     }
 
     if (!a->StopNow && (rev&LA_BLOCK || rev&LA_PASS_ON)){
@@ -5905,6 +5907,7 @@ void la_StopAllOperators(){
 }
 
 void la_DestroyConfirmData(laConfirmData **cd){
+    if((!cd)||!(*cd)) return;
     if ((*cd)->CustomData) (*cd)->Destroy((*cd)->CustomData);
     if ((*cd)->StrData) free((*cd)->StrData);
     FreeMem((*cd));

+ 48 - 12
resources/la_operators.c

@@ -242,9 +242,8 @@ laFileBrowser *la_FileBrowserInit(laOperator *a){
 
     strcpy(fb->Path, MAIN.WorkingDirectory->Ptr);
 
-    if (strArgumentMatch(a->ExtraInstructionsP, "select", "folder")){
-        fb->SelectFolder = LA_FILE_SELECT_FOLDER;
-    }
+    if (strArgumentMatch(a->ExtraInstructionsP, "select", "folder")){ fb->SelectFolder = LA_FILE_SELECT_FOLDER; }
+    if (strArgumentMatch(a->ExtraInstructionsP, "warn_file_exists", "true")){ fb->WarnFileExists = 1; }
 
     la_FileBrowserRebuildList(fb);
 
@@ -267,14 +266,18 @@ void laset_FileBrowserSelectFile(laFileBrowser *fb, laFileItem *fi, int State){
         fb->Active = fi;
     }
 }
-int la_FileBrowserConfirm(laOperator *a, laFileBrowser *fb){
-    char buf[2048] = {0};
+void* la_FileBrowserGetFullPath(laFileBrowser *fb,char* buf){
+    buf[0]=0;
     int plen;
-    if (!fb->SelectFolder && fb->FileName[0] == L'\0') return 0;
+    if (!fb->SelectFolder && fb->FileName[0] == L'\0') return;
     plen = strlen(fb->Path);
     if (fb->Path[plen - 1] != L'/') strcat(fb->Path, "/");
     strCopyFull(buf, fb->Path);
     strcat(buf, fb->FileName);
+}
+int la_FileBrowserConfirm(laOperator *a, laFileBrowser *fb){
+    char buf[2048];
+    la_FileBrowserGetFullPath(fb,buf);
     laConfirmString(a, buf, LA_CONFIRM_OK);
     return 1;
 }
@@ -329,14 +332,11 @@ int OPMOD_FileBrowser(laOperator *a, laEvent *e){
 
     if (a->ConfirmData){
         if (a->ConfirmData->Mode == LA_CONFIRM_CANCEL){
-            laConfirmSameDataIfAny(a);
-            return LA_FINISHED_PASS;
+            if(fb->StatusWaitingWarning){ fb->StatusWaitingWarning=0; return LA_RUNNING; }
+            laConfirmSameDataIfAny(a); return LA_FINISHED_PASS;
         }
         if (a->ConfirmData->Mode == LA_CONFIRM_OK){
-            if (la_FileBrowserConfirm(a, fb)){
-                //MessageBox(0, a->NextConfirmData->StrData, "!", 0);
-            }
-            return LA_FINISHED_PASS;
+            la_FileBrowserConfirm(a, fb); return LA_FINISHED_PASS;
         }
     }
 
@@ -359,6 +359,40 @@ int OPINV_FileBrowserUpLevel(laOperator *a, laEvent *e){
     }
     return LA_FINISHED_PASS;
 }
+int OPCHK_FileBrowserCanConfirm(laPropPack *This, laStringSplitor *ss){
+    if(!OPCHK_IsFileBrowser(This,ss)) return 0;
+    laFileBrowser* fb=This->EndInstance;
+    if(fb->SelectFolder) return 1;
+    if(fb->FileName[0]) return 1;
+    return 0;
+}
+int OPINV_FileBrowserConfirm(laOperator *a, laEvent *e){
+    if (a->This){
+        laFileBrowser* fb=a->This->LastPs->UseInstance;
+        if(fb->WarnFileExists){
+            char path[2048]; la_FileBrowserGetFullPath(fb, path);
+            if(access(path, F_OK)==0){
+                laEnableYesNoPanel(a,0,"File exists","Selected file already exists. Overwrite the file?",e->x-LA_RH,e->y-LA_RH,200,e);
+                fb->StatusWaitingWarning=1; return LA_RUNNING;
+            }
+        }
+        laConfirmInt(a, 0, LA_CONFIRM_OK); return LA_FINISHED_PASS;
+    }
+    return LA_FINISHED_PASS;
+}
+int OPMOD_FileBrowserConfirm(laOperator *a, laEvent *e){
+    laFileBrowser* fb=a->This->LastPs->UseInstance;
+    if (a->ConfirmData){
+        if (a->ConfirmData->Mode == LA_CONFIRM_CANCEL){
+            if(fb->StatusWaitingWarning){ fb->StatusWaitingWarning=0; return LA_FINISHED; }
+        }
+        if (a->ConfirmData->Mode == LA_CONFIRM_OK){
+            laConfirmInt(a, 0, LA_CONFIRM_OK); return LA_FINISHED_PASS;
+        }
+        return LA_FINISHED;
+    }
+    return LA_RUNNING;
+}
 
 int OPEXT_UDFOperation(laOperator *a, laEvent *e){
     laUDFPreviewExtra *upe = a->CustomData;
@@ -1925,6 +1959,7 @@ void la_RegisterBuiltinOperators(){
     laCreateOperatorType("LA_view_hyper_data", "View Hyper Data", "Show Properties Of Specific Data Block", OPCHK_IsHyper, 0, 0, OPINV_ViewHyperData, 0, L'🛈', LA_ACTUATOR_SYSTEM);
     
     laCreateOperatorType("LA_file_dialog_up", "Up", "Select Upper Folder Level", OPCHK_IsFileBrowser, 0, 0, OPINV_FileBrowserUpLevel, 0, L'🢰', LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
+    laCreateOperatorType("LA_file_dialog_confirm", "Confirm", "Confirm selection", OPCHK_FileBrowserCanConfirm, 0, 0, OPINV_FileBrowserConfirm, OPMOD_FileBrowserConfirm, L'✔', LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
     at = laCreateOperatorType("LA_file_dialog", "File Dialog", "Do File Operations", 0, 0, OPEXT_FileBrowser, OPINV_FileBrowser, OPMOD_FileBrowser, L'🗐', LA_ACTUATOR_SYSTEM);
     pc = laDefineOperatorProps(at, 2);
     at->UiDefine = laui_FileBrowserFileList;
@@ -1939,6 +1974,7 @@ void la_RegisterBuiltinOperators(){
         laAddEnumItemAs(ep, "folder", "Folder", "Folder", LA_FILE_SELECT_FOLDER, L'🖹');
     }
     laAddOperatorProperty(pc, "folder_up", "Up", "Select Upper Folder Level In File Browsers", "LA_file_dialog_up", L'🢰', 0);
+    laAddOperatorProperty(pc, "confirm", "Confirm", "Confirm selection", "LA_file_dialog_confirm", L'✔', 0);
     p = laAddPropertyContainer("disk_item", "Disk Item", "A Logical Drive (In Windows)", 0, laui_FileBrowserDiskItem, 0, 0, 0, 0);{
         laAddStringProperty(p, "id", "ID", "Disk Identifier", 0, 0, 0, 0, 0, 0, 0, laget_FileBrowserDiskID, 0, 0, 0);
         laAddFloatProperty(p, "total_gb", "Total", "Disk Total Compacity In Gigabytes", 0, 0, "GB", 0, 0, 0, 0, 0, offsetof(laDiskItem, Total_GB), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,LA_READ_ONLY);

+ 8 - 10
resources/la_templates.c

@@ -925,8 +925,15 @@ void laui_FileBrowserFileList(laUiList *uil, laPropPack *THIS_UNUSED, laPropPack
     cl = laLeftColumn(col, 10);
     cr = laRightColumn(col, 0);
 
-    laShowItem(uil, cr, Operator, "path");
     laShowItemFull(uil, cl, Operator, "folder_up", LA_WIDGET_BUTTON_NO_CONFIRM, 0 ,0,0);
+    laShowItem(uil, cr, Operator, "path")->Expand=1;
+
+    laUiItem* r=laBeginRow(uil,cr,0,0);
+    laShowItem(uil, cr, Operator, "file_name")->Expand=1;
+    laShowItem(uil, cr, Operator, "confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_NO_CONFIRM;
+    laEndRow(uil,r);
+
+    laShowSeparator(uil,col);
 
     u = laMakeGroup(uil, cl, "Logic Drives", 0)->Page;
     c = laFirstColumn(u);
@@ -956,15 +963,6 @@ void laui_FileBrowserFileList(laUiList *uil, laPropPack *THIS_UNUSED, laPropPack
     laShowLabel(u, clrrl, "Last Modified On", 0, 0);
     laShowLabel(u, clrrr, "File Size", 0, 0);
     laShowItem(u, c, Operator, "file_list")->Flags|=LA_UI_FLAGS_NO_DECAL;
-
-    laShowSeparator(uil, cr);
-    laUiItem*r=laBeginRow(uil,cr,0,0);
-    laShowItem(uil, cr, Operator, "file_name")->Expand=1;
-    b = laOnConditionThat(uil, cl, laOr(laAnd(laEqual(laPropExpression(Operator, "select_what"), laIntExpression(LA_FILE_SELECT_FILE)), laPropExpression(Operator, "file_name")), laEqual(laPropExpression(Operator, "select_what"), laIntExpression(LA_FILE_SELECT_FOLDER))));{
-        laShowItem(uil, cr, 0, "LA_confirm")->Flags|=LA_UI_FLAGS_HIGHLIGHT;
-    }
-    laEndCondition(uil, b);
-    laEndRow(uil,r);
 }
 void laui_LinkerPanel(laUiList *uil, laPropPack *Base, laPropPack *OperatorInst, laColumn *ExtraColumns, int context){
     laColumn *c, *cl, *cr, *cll, *clr, *crl, *crr, *crrl, *crrr, *gc;

+ 10 - 6
resources/la_widgets.c

@@ -2206,12 +2206,16 @@ int OPMOD_Button(laOperator *a, laEvent *e){
             }
         }
 
-        if (str = strGetArgumentString(ui->Instructions, "feedback")){
-            if (strSame(str, "CONFIRM")) laConfirmInt(a, 0, LA_CONFIRM_OK);
-            elif (strSame(str, "CANCEL")) laConfirmInt(a, 0, LA_CONFIRM_CANCEL);
-            else { laConfirmString(a, str, LA_CONFIRM_CUSTOM_STRING); }
-        }elif(!(ui->Flags&LA_UI_FLAGS_NO_CONFIRM)){
-            laConfirmInt(a, 0, LA_CONFIRM_OK);
+        if(MAIN.InvokeConfirmData){
+            a->ConfirmData=MAIN.InvokeConfirmData; laConfirmSameDataIfAny(a); a->ConfirmData=0;
+        }else{
+            if (str = strGetArgumentString(ui->Instructions, "feedback")){
+                if (strSame(str, "CONFIRM")) laConfirmInt(a, 0, LA_CONFIRM_OK);
+                elif (strSame(str, "CANCEL")) laConfirmInt(a, 0, LA_CONFIRM_CANCEL);
+                else { laConfirmString(a, str, LA_CONFIRM_CUSTOM_STRING); }
+            }elif(!(ui->Flags&LA_UI_FLAGS_NO_CONFIRM)){
+                laConfirmInt(a, 0, LA_CONFIRM_OK);
+            }
         }
 
         laRedrawCurrentPanel();