Browse Source

综合-页面编辑下拉框更新数据

tangchao 1 year ago
parent
commit
7ac5c92cb5

BIN
PDF Office/PDF Office.xcodeproj/project.xcworkspace/xcuserdata/kdanmobile.xcuserdatad/UserInterfaceState.xcuserstate


+ 6 - 5
PDF Office/PDF Office/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController.swift

@@ -113,17 +113,18 @@ class KMPDFEditViewController: NSViewController {
                     continue
                 }
                 
-                if (indexs.contains(pageIndex+1)) {
+                if (indexs.contains(pageIndex)) {
                     continue
                 }
-                indexs.append(pageIndex+1)
+                indexs.append(pageIndex)
             }
             
             self.thumbnailView.selectPages(at: indexs)
             
             indexs.sort(){$0 < $1}
             self.pageRangeView?.editable = true
-            self.pageRangeView?.stringValue = KMPageRangeTools.parseSelectedIndexs(selectedIndex: indexs)
+            self.pageRangeView?.stringValue = KMPageRangeTools.newParseSelectedIndexs(selectedIndex: indexs)
+            
         }
         
         self.view.window?.makeFirstResponder(self)
@@ -190,13 +191,13 @@ class KMPDFEditViewController: NSViewController {
             
             var indexs: Array<Int> = []
             for indexPath in selectedIndexs {
-                indexs.append(indexPath.item+1)
+                indexs.append(indexPath.item)
             }
             
             indexs.sort(){$0 < $1}
             
             self?.pageRangeView?.editable = true;
-            self?.pageRangeView?.stringValue = KMPageRangeTools.parseSelectedIndexs(selectedIndex: indexs)
+            self?.pageRangeView?.stringValue = KMPageRangeTools.newParseSelectedIndexs(selectedIndex: indexs)
         }
         
         self.thumbnailView.doubleClickItem = {

+ 92 - 59
PDF Office/PDF Office/Class/PDFTools/Watermark/Tools/KMPageRangeTools.swift

@@ -81,7 +81,18 @@ class KMPageRangeTools: NSObject {
         return result
     }
 
-    class func parseSelectedIndexs(selectedIndex: Array<Int>) -> String {
+    private class func parseSelectedIndexs(selectedIndex: Array<Int>) -> String {
+        if (selectedIndex.count <= 0) {
+            return ""
+        }
+        if (selectedIndex.count == 1) {
+            return "\((selectedIndex.first)!)"
+        }
+        if (selectedIndex.count == 2) {
+            return "\((selectedIndex.first)!),\((selectedIndex.last)!)"
+        }
+        
+        // 元素大于2个
         var string: String = ""
         var index = 0
         var prePage = 0
@@ -89,79 +100,101 @@ class KMPageRangeTools: NSObject {
         var cubeStart = NSNotFound
         var cubeEnd = NSNotFound
         for i in selectedIndex {
-            if selectedIndex.count == 1 {
-                string.append(String(i))
-            } else if selectedIndex.count == 2 {
+            if index == 0 {
                 string.append(String(i))
-                if index != selectedIndex.count-1 {
-                    string.append(",")
-                }
             } else {
-                if index == 0 {
-                    string.append(String(i))
+                if i - prePage == 1 {
+                    if count == 0 {
+                        cubeStart = prePage
+                    }
+                    
+                    count += 1
                 } else {
-                    if i - prePage == 1 {
-                        if count == 0 {
-                            cubeStart = prePage
+                    count = 0
+                }
+                
+                // 最后一个元素
+                if (index == selectedIndex.count-1) {
+                    if cubeStart != NSNotFound && cubeEnd != NSNotFound { /// 有效块
+                        if cubeStart == selectedIndex.first {
+                            string.removeFirst()
+                        } else {
+                            string.append(",")
                         }
                         
-                        count += 1
-                    } else {
-                        count = 0
-                    }
-                    
-                    if count == 0 || index == selectedIndex.count-1 { /// 块结束
-                        if cubeStart != NSNotFound && cubeEnd != NSNotFound { /// 有效块
-                            if cubeStart == selectedIndex.first {
-                                string.removeFirst()
-                            } else {
+                        if index == selectedIndex.count-1 {
+                            if count == 0 {
+                                string.append(String(cubeStart))
+                                string.append("-")
+                                string.append(String(cubeEnd))
+                                
                                 string.append(",")
-                            }
-                            
-                            
-                            if index == selectedIndex.count-1 {
-                                if count == 0 {
-                                    string.append(String(cubeStart))
-                                    string.append("-")
-                                    string.append(String(cubeEnd))
-                                    
-                                    string.append(",")
-                                    string.append(String(i))
-                                } else {
-                                    string.append(String(cubeStart))
-                                    string.append("-")
-                                    string.append(String(i))
-                                }
+                                string.append(String(i))
                             } else {
                                 string.append(String(cubeStart))
                                 string.append("-")
-                                string.append(String(cubeEnd))
+                                string.append(String(i))
                             }
                         } else {
-                            if prePage == selectedIndex.first {
-                                //                                    string.append(",")
-                            } else {
-                                string.append(",")
-                                string.append(String(prePage))
-                            }
+                            string.append(String(cubeStart))
+                            string.append("-")
+                            string.append(String(cubeEnd))
+                        }
+                    } else {
+                        if prePage == selectedIndex.first {
                             
-                            cubeStart = NSNotFound
-                            cubeEnd = NSNotFound
+                        } else {
+                            string.append(",")
+                            string.append(String(prePage))
                         }
+                        
+                        cubeStart = NSNotFound
+                        cubeEnd = NSNotFound
                     }
-                    //                        else if count == 1 {
-                    //                            if index == selectedPages.count-1 {
-                    //                                if prePage == selectedPages.first {
-                    ////                                    string.append(",")
-                    //                                } else {
-                    //                                    string.append(",")
-                    //                                    string.append(String(prePage))
-                    //                                }
-                    //                            }
-                    //                        }
-                    else if count >= 2 { /// 可成块
-                        cubeEnd = i
+                    break
+                }
+                
+                // 不是最后一个元素
+                if count == 0 { /// 块结束
+                    if cubeStart != NSNotFound && cubeEnd != NSNotFound { /// 有效块
+                        if cubeStart == selectedIndex.first {
+                            string.removeFirst()
+                        } else {
+                            string.append(",")
+                        }
+                        
+                        
+                        if index == selectedIndex.count-1 {
+                            if count == 0 {
+                                string.append(String(cubeStart))
+                                string.append("-")
+                                string.append(String(cubeEnd))
+                                
+                                string.append(",")
+                                string.append(String(i))
+                            } else {
+                                string.append(String(cubeStart))
+                                string.append("-")
+                                string.append(String(i))
+                            }
+                        } else {
+                            string.append(String(cubeStart))
+                            string.append("-")
+                            string.append(String(cubeEnd))
+                        }
+                    } else {
+                        if prePage == selectedIndex.first {
+                            //                                    string.append(",")
+                        } else {
+                            string.append(",")
+                            string.append(String(prePage))
+                        }
+                        
+                        cubeStart = NSNotFound
+                        cubeEnd = NSNotFound
                     }
+                } else if count >= 2 { /// 可成块
+                    cubeEnd = i
                 }
             }