|
@@ -9,216 +9,6 @@ import Cocoa
|
|
|
|
|
|
let kHeaderFooterInfoSaveKey = "kHeaderFooterInfoSaveKey"
|
|
|
|
|
|
-class KMHeaderFooterObject: NSObject, NSCopying, NSCoding{
|
|
|
- var type: KMBatchHeaderFooterType = .HeaderFooter
|
|
|
- var leftMargin: Int = 30
|
|
|
- var rightMargin: Int = 30
|
|
|
- var bottomMargin: Int = 30
|
|
|
- var topMargin: Int = 30
|
|
|
- var topLeftString: String = ""
|
|
|
- var topCenterString: String = ""
|
|
|
- var topRightString: String = ""
|
|
|
- var bottomLeftString: String = ""
|
|
|
- var bottomCenterString: String = ""
|
|
|
- var bottomRightString: String = ""
|
|
|
- var startString: String = "1"
|
|
|
- var fontSize: CGFloat = 16.0
|
|
|
- var textColor: NSColor = .black
|
|
|
- var pagesString: String = ""
|
|
|
- var isBates: Bool = false
|
|
|
- var batesPrefixString: String = ""
|
|
|
- var batesSuffixString: String = ""
|
|
|
- var batesDigits: Int = 0
|
|
|
- var hasHeader: Bool = false
|
|
|
- var hasFooter: Bool = false
|
|
|
- var cellHeight: CGFloat = 0.0{
|
|
|
- willSet{
|
|
|
-
|
|
|
- }
|
|
|
- didSet {
|
|
|
- if cellHeight < 0.1 {
|
|
|
- var baseHeight: CGFloat = 33.0 + 24.0
|
|
|
- if self.topLeftString.count > 0 {
|
|
|
- baseHeight += 20.0
|
|
|
- }
|
|
|
-
|
|
|
- if topCenterString.count > 0 {
|
|
|
- baseHeight += 20.0
|
|
|
- }
|
|
|
-
|
|
|
- if topRightString.count > 0 {
|
|
|
- baseHeight += 20.0
|
|
|
- }
|
|
|
-
|
|
|
- if bottomLeftString.count > 0 {
|
|
|
- baseHeight += 20.0
|
|
|
- }
|
|
|
-
|
|
|
- if bottomCenterString.count > 0 {
|
|
|
- baseHeight += 20.0
|
|
|
- }
|
|
|
-
|
|
|
- if bottomRightString.count > 0 {
|
|
|
- baseHeight += 20.0
|
|
|
- }
|
|
|
-
|
|
|
- baseHeight -= 4.0
|
|
|
- cellHeight = baseHeight
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- var headerFooterID: String = ""
|
|
|
- var pageChoice: KMBatchOperatePageChoice = .All
|
|
|
- var dateFormatString: String = "m/d"
|
|
|
- var pageFormatString: String = "1"
|
|
|
-
|
|
|
- override init() {
|
|
|
- super.init()
|
|
|
- self.topLeftString = ""
|
|
|
- self.topCenterString = ""
|
|
|
- self.topRightString = ""
|
|
|
- self.bottomLeftString = ""
|
|
|
- self.bottomCenterString = ""
|
|
|
- self.bottomRightString = ""
|
|
|
- self.startString = ""
|
|
|
- self.pagesString = ""
|
|
|
- self.batesPrefixString = ""
|
|
|
- self.batesSuffixString = ""
|
|
|
- self.headerFooterID = ""
|
|
|
- self.fontSize = 16.0
|
|
|
- self.dateFormatString = "m/d"
|
|
|
- self.startString = "1"
|
|
|
- self.pageFormatString = "1"
|
|
|
- self.textColor = .black
|
|
|
- self.leftMargin = 30
|
|
|
- self.rightMargin = 30
|
|
|
- self.topMargin = 30
|
|
|
- self.bottomMargin = 30
|
|
|
- }
|
|
|
-
|
|
|
- func copy(with zone: NSZone? = nil) -> Any {
|
|
|
- var obj: KMHeaderFooterObject = KMHeaderFooterObject()
|
|
|
- obj.type = self.type
|
|
|
- obj.leftMargin = self.leftMargin
|
|
|
- obj.rightMargin = self.rightMargin
|
|
|
- obj.bottomMargin = self.bottomMargin
|
|
|
- obj.topMargin = self.topMargin
|
|
|
- obj.topLeftString = self.topLeftString
|
|
|
- obj.topCenterString = self.topCenterString
|
|
|
- obj.topRightString = self.topRightString
|
|
|
- obj.bottomLeftString = self.bottomLeftString
|
|
|
- obj.bottomCenterString = self.bottomCenterString
|
|
|
- obj.bottomRightString = self.bottomRightString
|
|
|
- obj.startString = self.startString
|
|
|
- obj.fontSize = self.fontSize
|
|
|
- obj.textColor = self.textColor
|
|
|
- obj.pagesString = self.pagesString
|
|
|
- obj.isBates = self.isBates
|
|
|
- obj.batesPrefixString = self.batesPrefixString
|
|
|
- obj.batesSuffixString = self.batesSuffixString
|
|
|
- obj.batesDigits = self.batesDigits
|
|
|
- obj.headerFooterID = self.headerFooterID
|
|
|
- obj.hasHeader = self.hasHeader
|
|
|
- obj.hasFooter = self.hasFooter
|
|
|
- obj.pageChoice = self.pageChoice
|
|
|
- obj.pageFormatString = self.pageFormatString
|
|
|
- obj.dateFormatString = self.dateFormatString
|
|
|
- return obj;
|
|
|
- }
|
|
|
-
|
|
|
- func encode(with coder: NSCoder) {
|
|
|
- coder.encode(self.type.rawValue, forKey: "type")
|
|
|
- coder.encode(self.leftMargin, forKey: "leftMargin")
|
|
|
- coder.encode(self.rightMargin, forKey: "rightMargin")
|
|
|
- coder.encode(self.bottomMargin, forKey: "bottomMargin")
|
|
|
- coder.encode(self.topMargin, forKey: "topMargin")
|
|
|
-
|
|
|
- coder.encode(self.topLeftString, forKey: "topLeftString")
|
|
|
-
|
|
|
- coder.encode(self.topCenterString, forKey: "topCenterString")
|
|
|
- coder.encode(self.topRightString, forKey: "topRightString")
|
|
|
- coder.encode(self.bottomLeftString, forKey: "bottomLeftString")
|
|
|
- coder.encode(self.bottomCenterString, forKey: "bottomCenterString")
|
|
|
- coder.encode(self.bottomRightString, forKey: "bottomRightString")
|
|
|
- coder.encode(self.startString, forKey: "startString")
|
|
|
- coder.encode(self.fontSize, forKey: "fontSize")
|
|
|
- coder.encode(self.textColor, forKey: "textColor")
|
|
|
-
|
|
|
- coder.encode(self.pagesString, forKey: "pagesString")
|
|
|
- coder.encode(self.isBates, forKey: "isBates")
|
|
|
- coder.encode(self.batesPrefixString, forKey: "batesPrefixString")
|
|
|
- coder.encode(self.batesSuffixString, forKey: "batesSuffixString")
|
|
|
- coder.encode(self.batesDigits, forKey: "batesDigits")
|
|
|
- coder.encode(self.hasHeader, forKey: "hasHeader")
|
|
|
- coder.encode(self.hasFooter, forKey: "hasFooter")
|
|
|
- coder.encode(self.cellHeight, forKey: "cellHeight")
|
|
|
- coder.encode(self.headerFooterID, forKey: "headerFooterID")
|
|
|
- coder.encode(self.pageChoice, forKey: "pageChoice")
|
|
|
- coder.encode(self.dateFormatString, forKey: "dateFormatString")
|
|
|
- coder.encode(self.pageFormatString, forKey: "pageFormatString")
|
|
|
- }
|
|
|
-
|
|
|
- required init?(coder: NSCoder) {
|
|
|
- type = KMBatchHeaderFooterType(rawValue: coder.decodeInteger(forKey: "type")) ?? .HeaderFooter
|
|
|
- leftMargin = coder.decodeInteger(forKey: "leftMargin")
|
|
|
- rightMargin = coder.decodeInteger(forKey: "rightMargin")
|
|
|
- bottomMargin = coder.decodeInteger(forKey: "bottomMargin")
|
|
|
- topMargin = coder.decodeInteger(forKey: "topMargin")
|
|
|
- topLeftString = coder.decodeObject(forKey: "topLeftString") as! String
|
|
|
- topCenterString = coder.decodeObject(forKey: "topCenterString") as! String
|
|
|
- topRightString = coder.decodeObject(forKey: "topRightString") as! String
|
|
|
-
|
|
|
- bottomLeftString = coder.decodeObject(forKey: "bottomLeftString") as! String
|
|
|
- bottomCenterString = coder.decodeObject(forKey: "bottomCenterString") as! String
|
|
|
- bottomRightString = coder.decodeObject(forKey: "bottomCenterString") as! String
|
|
|
- startString = coder.decodeObject(forKey: "startString") as! String
|
|
|
- fontSize = CGFloat(coder.decodeFloat(forKey: "fontSize"))
|
|
|
- textColor = coder.decodeObject(forKey: "textColor") as! NSColor
|
|
|
- pagesString = coder.decodeObject(forKey: "pagesString") as! String
|
|
|
- isBates = coder.decodeBool(forKey: "isBates")
|
|
|
- batesPrefixString = coder.decodeObject(forKey: "batesPrefixString") as! String
|
|
|
- batesSuffixString = coder.decodeObject(forKey: "batesSuffixString") as! String
|
|
|
- batesDigits = coder.decodeInteger(forKey: "batesDigits")
|
|
|
- hasHeader = coder.decodeBool(forKey: "hasHeader")
|
|
|
- hasFooter = coder.decodeBool(forKey: "hasFooter")
|
|
|
- cellHeight = CGFloat(coder.decodeFloat(forKey: "cellHeight"))
|
|
|
- headerFooterID = coder.decodeObject(forKey: "headerFooterID") as! String
|
|
|
- pageChoice = KMBatchOperatePageChoice(rawValue: coder.decodeInteger(forKey: "pageChoice")) ?? .All
|
|
|
- dateFormatString = coder.decodeObject(forKey: "dateFormatString") as! String
|
|
|
- pageFormatString = coder.decodeObject(forKey: "pageFormatString") as! String
|
|
|
- }
|
|
|
-
|
|
|
- func copyData(dataObj: KMHeaderFooterObject) {
|
|
|
- type = dataObj.type
|
|
|
- leftMargin = dataObj.leftMargin
|
|
|
- rightMargin = dataObj.rightMargin
|
|
|
- bottomMargin = dataObj.bottomMargin
|
|
|
- topMargin = dataObj.topMargin
|
|
|
- topLeftString = dataObj.topLeftString
|
|
|
- topCenterString = dataObj.topCenterString
|
|
|
- topRightString = dataObj.topRightString
|
|
|
- bottomLeftString = dataObj.bottomLeftString
|
|
|
- bottomCenterString = dataObj.bottomCenterString
|
|
|
- bottomRightString = dataObj.bottomRightString
|
|
|
- startString = dataObj.startString
|
|
|
- fontSize = dataObj.fontSize
|
|
|
- textColor = dataObj.textColor
|
|
|
- pagesString = dataObj.pagesString
|
|
|
- isBates = dataObj.isBates
|
|
|
- batesPrefixString = dataObj.batesPrefixString
|
|
|
- batesSuffixString = dataObj.batesSuffixString
|
|
|
- batesDigits = dataObj.batesDigits
|
|
|
- hasHeader = dataObj.hasHeader
|
|
|
- hasFooter = dataObj.hasFooter
|
|
|
- cellHeight = dataObj.cellHeight
|
|
|
- headerFooterID = dataObj.headerFooterID
|
|
|
- pageChoice = dataObj.pageChoice
|
|
|
- dateFormatString = dataObj.dateFormatString
|
|
|
- pageFormatString = dataObj.pageFormatString
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
class KMHeaderFooterManager: NSObject, NSCoding{
|
|
|
|
|
|
|
|
@@ -243,12 +33,12 @@ class KMHeaderFooterManager: NSObject, NSCoding{
|
|
|
}
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
- self.headFooterObjects = coder.decodeObject(forKey: "headFooterObjects") as? [KMHeaderFooterObject]
|
|
|
+ self.headFooterObjects = coder.decodeObject(forKey: "headFooterObjects") as? [KMHeaderFooterModel]
|
|
|
}
|
|
|
|
|
|
var datas: Array<KMHeaderFooterModel> = []
|
|
|
|
|
|
- var headFooterObjects: [KMHeaderFooterObject]?
|
|
|
+ var headFooterObjects: [KMHeaderFooterModel]?
|
|
|
|
|
|
lazy var dateFormatArray: Array = {
|
|
|
let arr = [
|
|
@@ -279,8 +69,8 @@ class KMHeaderFooterManager: NSObject, NSCoding{
|
|
|
return arr
|
|
|
}()
|
|
|
|
|
|
- lazy var onlyBatesObjects: [KMHeaderFooterObject] = {
|
|
|
- var arr: [KMHeaderFooterObject] = Array<KMHeaderFooterObject>()
|
|
|
+ lazy var onlyBatesObjects: [KMHeaderFooterModel] = {
|
|
|
+ var arr: [KMHeaderFooterModel] = Array<KMHeaderFooterModel>()
|
|
|
for i in 0..<(headFooterObjects?.count ?? 0) {
|
|
|
let obj = headFooterObjects?[i]
|
|
|
if KMDataVersionManager.updateBatesData() {
|
|
@@ -294,8 +84,8 @@ class KMHeaderFooterManager: NSObject, NSCoding{
|
|
|
}
|
|
|
return arr
|
|
|
}()
|
|
|
- lazy var onlyHeaderFooterObjects: [KMHeaderFooterObject] = {
|
|
|
- var arr: [KMHeaderFooterObject] = Array<KMHeaderFooterObject>()
|
|
|
+ lazy var onlyHeaderFooterObjects: [KMHeaderFooterModel] = {
|
|
|
+ var arr: [KMHeaderFooterModel] = Array<KMHeaderFooterModel>()
|
|
|
for i in 0..<(headFooterObjects?.count ?? 0) {
|
|
|
let obj = headFooterObjects?[i]
|
|
|
|
|
@@ -337,7 +127,7 @@ class KMHeaderFooterManager: NSObject, NSCoding{
|
|
|
|
|
|
func fetchBatesAvailableName() -> String {
|
|
|
var availableIndex = 0
|
|
|
- let nameArray = converArrType(arr: onlyBatesObjects, keyString: "headerFooterID")
|
|
|
+ let nameArray = converArrType(arr: onlyBatesObjects, keyString: "id")
|
|
|
for i in 0..<nameArray.count {
|
|
|
let string = nameArray[i]
|
|
|
if string.hasPrefix("Bates") {
|
|
@@ -352,7 +142,7 @@ class KMHeaderFooterManager: NSObject, NSCoding{
|
|
|
|
|
|
func fetchHeaderFooterAvailableName() -> String {
|
|
|
var availableIndex = 0
|
|
|
- let nameArray = converArrType(arr: onlyHeaderFooterObjects, keyString: "headerFooterID")
|
|
|
+ let nameArray = converArrType(arr: onlyHeaderFooterObjects, keyString: "id")
|
|
|
for i in 0..<nameArray.count {
|
|
|
let string = nameArray[i]
|
|
|
if string.hasPrefix("HeaderFooter") {
|
|
@@ -365,10 +155,10 @@ class KMHeaderFooterManager: NSObject, NSCoding{
|
|
|
return String(format: "HeaderFooter%ld", availableIndex)
|
|
|
}
|
|
|
|
|
|
- func converArrType(arr: Array<KMHeaderFooterObject>, keyString: String) -> [String] {
|
|
|
- var newArr = NSMutableArray()
|
|
|
+ func converArrType(arr: Array<KMHeaderFooterModel>, keyString: String) -> [String] {
|
|
|
+ let newArr = NSMutableArray()
|
|
|
for item in arr {
|
|
|
- newArr.add(item.headerFooterID)
|
|
|
+ newArr.add(item.id)
|
|
|
}
|
|
|
return newArr as! [String]
|
|
|
}
|
|
@@ -510,7 +300,7 @@ class KMHeaderFooterManager: NSObject, NSCoding{
|
|
|
|
|
|
return result
|
|
|
}
|
|
|
- func removeHeaderFooter(_ obj: KMHeaderFooterObject) {
|
|
|
+ func removeHeaderFooter(_ obj: KMHeaderFooterModel) {
|
|
|
self.headFooterObjects?.removeObject(obj)
|
|
|
self.store()
|
|
|
}
|