|
@@ -28,9 +28,10 @@ class CustomStampLeftToolbar: NSView, NibLoadable {
|
|
|
@IBOutlet var stampBox: NSBox!
|
|
|
@IBOutlet var stampButton: KMButton!
|
|
|
|
|
|
+ var originalType: CSToolbarType = .none
|
|
|
var toolbarType: CSToolbarType = .move
|
|
|
|
|
|
- var clickHandle: ((_ view: CustomStampLeftToolbar, _ actionType: CSToolbarType)->Void)?
|
|
|
+ var clickHandle: ((_ view: CustomStampLeftToolbar, _ actionType: CSToolbarType, _ string: String)->Void)?
|
|
|
|
|
|
override func draw(_ dirtyRect: NSRect) {
|
|
|
super.draw(dirtyRect)
|
|
@@ -70,16 +71,6 @@ class CustomStampLeftToolbar: NSView, NibLoadable {
|
|
|
self.dateBox?.menu = dateMenu
|
|
|
|
|
|
|
|
|
- var idNames = ["名称", "登录名", "电子邮件", "组织名称"]
|
|
|
- let idMenu = NSMenu.init()
|
|
|
- for idx in 0...idNames.count-1 {
|
|
|
- let string = idNames[idx]
|
|
|
- let menuItem = NSMenuItem.init(title: string, action: #selector(menuItemClick(_:)), keyEquivalent: "")
|
|
|
- menuItem.tag = 1000 + idx
|
|
|
- menuItem.target = self
|
|
|
- idMenu.addItem(menuItem)
|
|
|
- }
|
|
|
- self.peopleBox?.menu = idMenu
|
|
|
|
|
|
|
|
|
}
|
|
@@ -109,45 +100,103 @@ class CustomStampLeftToolbar: NSView, NibLoadable {
|
|
|
//MARK: IBAction
|
|
|
@IBAction func buttonAction(_ sender: NSButton) {
|
|
|
|
|
|
- let originalType = self.toolbarType
|
|
|
+ originalType = self.toolbarType
|
|
|
|
|
|
if sender == self.arrowBtn {
|
|
|
self.toolbarType = .move
|
|
|
+
|
|
|
+ self.reloadData()
|
|
|
+
|
|
|
+ guard let callBack = self.clickHandle else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ callBack(self, self.toolbarType, "")
|
|
|
+
|
|
|
} else if sender == self.textButton {
|
|
|
self.toolbarType = .text
|
|
|
- } else if sender == self.dateButton {
|
|
|
- self.toolbarType = .dateText
|
|
|
|
|
|
+ self.reloadData()
|
|
|
+
|
|
|
+ guard let callBack = self.clickHandle else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ callBack(self, self.toolbarType, "")
|
|
|
+
|
|
|
+ } else if sender == self.dateButton {
|
|
|
let menu = self.dateBox?.menu
|
|
|
menu?.popUp(positioning: menu?.item(at: 0), at: CGPoint(x: 0, y: 15), in: sender)
|
|
|
|
|
|
} else if sender == self.peopleButton {
|
|
|
- self.toolbarType = .idText
|
|
|
|
|
|
+
|
|
|
+ var idNames = ["名称", "登录名", "电子邮件", "组织名称"]
|
|
|
+ let idMenu = NSMenu.init()
|
|
|
+ for idx in 0...idNames.count-1 {
|
|
|
+ let string = idNames[idx]
|
|
|
+ let menuItem = NSMenuItem.init(title: string, action: #selector(idMenuItemClick(_:)), keyEquivalent: "")
|
|
|
+ menuItem.tag = 1000 + idx
|
|
|
+
|
|
|
+ if idx == 0 {
|
|
|
+ if KMProfileInfo.shared().fullName.isEmpty == false {
|
|
|
+ menuItem.target = self
|
|
|
+ }
|
|
|
+ } else if idx == 1 {
|
|
|
+ if NSFullUserName().isEmpty == false {
|
|
|
+ menuItem.target = self
|
|
|
+ }
|
|
|
+ } else if idx == 2 {
|
|
|
+ if KMProfileInfo.shared().email.isEmpty == false {
|
|
|
+ menuItem.target = self
|
|
|
+ }
|
|
|
+ } else if idx == 3 {
|
|
|
+ if KMProfileInfo.shared().OrganizeName.isEmpty == false {
|
|
|
+ menuItem.target = self
|
|
|
+ }
|
|
|
+ }
|
|
|
+ idMenu.addItem(menuItem)
|
|
|
+ }
|
|
|
+ self.peopleBox?.menu = idMenu
|
|
|
let menu = self.peopleBox?.menu
|
|
|
menu?.popUp(positioning: menu?.item(at: 0), at: CGPoint(x: 0, y: 15), in: sender)
|
|
|
|
|
|
} else if sender == self.imageButton {
|
|
|
self.toolbarType = .image
|
|
|
+ self.reloadData()
|
|
|
+ guard let callBack = self.clickHandle else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ callBack(self, self.toolbarType, "")
|
|
|
|
|
|
} else if sender == self.stampButton {
|
|
|
self.toolbarType = .stamp
|
|
|
-
|
|
|
+ self.reloadData()
|
|
|
+ guard let callBack = self.clickHandle else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ callBack(self, self.toolbarType, "")
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func idMenuItemClick(_ item: NSMenuItem) {
|
|
|
+ var string = item.title
|
|
|
+ if item.tag == 1000 {
|
|
|
+ string = KMProfileInfo.shared().fullName
|
|
|
+ } else if item.tag == 1001 {
|
|
|
+ string = NSFullUserName()
|
|
|
+ } else if item.tag == 1002 {
|
|
|
+ string = KMProfileInfo.shared().email
|
|
|
+ } else if item.tag == 1003 {
|
|
|
+ string = KMProfileInfo.shared().OrganizeName
|
|
|
}
|
|
|
+
|
|
|
+ self.toolbarType = .idText
|
|
|
self.reloadData()
|
|
|
|
|
|
guard let callBack = self.clickHandle else {
|
|
|
return
|
|
|
}
|
|
|
- callBack(self, self.toolbarType)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @objc func menuItemClick(_ item: NSMenuItem) {
|
|
|
- let string = item.title
|
|
|
-
|
|
|
+ callBack(self, self.toolbarType, string)
|
|
|
}
|
|
|
|
|
|
@objc func dateMenuItemClick(_ item: NSMenuItem) {
|
|
@@ -160,6 +209,14 @@ class CustomStampLeftToolbar: NSView, NibLoadable {
|
|
|
|
|
|
let dateString = dateFormatter.string(from: date)
|
|
|
print(dateString)
|
|
|
+
|
|
|
+ self.toolbarType = .dateText
|
|
|
+ self.reloadData()
|
|
|
+
|
|
|
+ guard let callBack = self.clickHandle else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ callBack(self, self.toolbarType, dateString)
|
|
|
}
|
|
|
|
|
|
}
|