• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoawindowspythonrubyphpgameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdombtronvb.netdirectxarduinopreviewerゲームエンジン

macOSのスクリーンショットの保存場所を変更するメニュバーエクストラ


Commit MetaInfo

Révisionb8533da3c4d5cba93e257d1048779c33cb36e0ab (tree)
l'heure2018-03-10 17:55:41
Auteurmasakih <masakih@user...>
Commitermasakih

Message de Log

ActionListenerを削除

Change Summary

Modification

--- a/GoInto.xcodeproj/project.pbxproj
+++ b/GoInto.xcodeproj/project.pbxproj
@@ -11,7 +11,6 @@
1111 F40EB6BF1EA1A55700FEE444 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = F40EB6BD1EA1A55700FEE444 /* Localizable.strings */; };
1212 F40EB6C81EA1CD7A00FEE444 /* ImageTypeItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = F40EB6C71EA1CD7A00FEE444 /* ImageTypeItem.swift */; };
1313 F40EB6CA1EA1D7B500FEE444 /* ImageType.plist in Resources */ = {isa = PBXBuildFile; fileRef = F40EB6C91EA1D7B500FEE444 /* ImageType.plist */; };
14- F40EB6D01EA26BEC00FEE444 /* ActionListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = F40EB6CF1EA26BEC00FEE444 /* ActionListener.swift */; };
1514 F40EB6D21EA2F28100FEE444 /* Screenshot.swift in Sources */ = {isa = PBXBuildFile; fileRef = F40EB6D11EA2F28100FEE444 /* Screenshot.swift */; };
1615 F414DD031EABAB7300111DA7 /* UserDefaultsExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F414DD021EABAB7300111DA7 /* UserDefaultsExtension.swift */; };
1716 F42539E01EACCEDE0083EB9D /* UserDefaultsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = F42539DF1EACCEDE0083EB9D /* UserDefaultsTest.swift */; };
@@ -44,7 +43,6 @@
4443 F40EB6C61EA1A94200FEE444 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/InfoPlist.strings; sourceTree = "<group>"; };
4544 F40EB6C71EA1CD7A00FEE444 /* ImageTypeItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageTypeItem.swift; sourceTree = "<group>"; };
4645 F40EB6C91EA1D7B500FEE444 /* ImageType.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ImageType.plist; sourceTree = "<group>"; };
47- F40EB6CF1EA26BEC00FEE444 /* ActionListener.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionListener.swift; sourceTree = "<group>"; };
4846 F40EB6D11EA2F28100FEE444 /* Screenshot.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Screenshot.swift; sourceTree = "<group>"; };
4947 F414DD021EABAB7300111DA7 /* UserDefaultsExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserDefaultsExtension.swift; sourceTree = "<group>"; };
5048 F42539DF1EACCEDE0083EB9D /* UserDefaultsTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserDefaultsTest.swift; sourceTree = "<group>"; };
@@ -113,7 +111,6 @@
113111 F47B07111EA10A3E006711D9 /* ChooseFolderItem.swift */,
114112 F40EB6C71EA1CD7A00FEE444 /* ImageTypeItem.swift */,
115113 F47B07171EA10A88006711D9 /* QuitItem.swift */,
116- F40EB6CF1EA26BEC00FEE444 /* ActionListener.swift */,
117114 F4D346931EA644170031AFB3 /* LimitedArray.swift */,
118115 F47B06EE1E9A5DF9006711D9 /* Assets.xcassets */,
119116 F47B06F31E9A5DF9006711D9 /* Info.plist */,
@@ -244,7 +241,6 @@
244241 F47B070C1E9A65FA006711D9 /* StatusItem.swift in Sources */,
245242 F47B06EB1E9A5DF9006711D9 /* AppDelegate.swift in Sources */,
246243 F47B07101EA10A1A006711D9 /* FolderItem.swift in Sources */,
247- F40EB6D01EA26BEC00FEE444 /* ActionListener.swift in Sources */,
248244 F40EB6D21EA2F28100FEE444 /* Screenshot.swift in Sources */,
249245 F47B07181EA10A88006711D9 /* QuitItem.swift in Sources */,
250246 F40EB6C81EA1CD7A00FEE444 /* ImageTypeItem.swift in Sources */,
--- a/GoInto/ActionListener.swift
+++ /dev/null
@@ -1,35 +0,0 @@
1-//
2-// ActionListener.swift
3-// GoInto
4-//
5-// Created by Hori,Masaki on 2017/04/15.
6-// Copyright © 2017年 Hori,Masaki. All rights reserved.
7-//
8-
9-import Cocoa
10-
11-/// El Capitan以前はaction targetがNSObjectを継承していなければならないため、targetとして利用する
12-///
13-/// extension ActionListener {
14-/// @IBAction func action(_ sender: Any?) {
15-/// guard let owner = owner as? Responder? else { return }
16-/// owner.operate()
17-/// }
18-/// }
19-///
20-/// class Responder {
21-/// let listener = ActionListener()
22-/// let actionSender: AnyObject
23-///
24-/// init() {
25-/// actionSender.action = #selector(ActionListener.action(_:))
26-/// actionSender.target = listener
27-/// listener.owner = self
28-/// }
29-/// func operate() {
30-/// // do something
31-/// }
32-/// }
33-class ActionListener: NSObject {
34- weak var owner: AnyObject?
35-}
--- a/GoInto/ChooseFolderItem.swift
+++ b/GoInto/ChooseFolderItem.swift
@@ -8,9 +8,18 @@
88
99 import Cocoa
1010
11-extension ActionListener {
11+class ChooseFolderItem: StatusItem {
12+ let menuItem = NSMenuItem()
13+ let urlSelector: (URL) -> Void
14+
15+ init(_ handler: @escaping ((URL) -> Void)) {
16+ urlSelector = handler
17+ menuItem.title = NSLocalizedString("Choose Folder", comment: "Choose Folder MenuItem")
18+ menuItem.action = #selector(selectFolder(_:))
19+ menuItem.target = self
20+ }
21+
1222 @IBAction func selectFolder(_ sender: Any?) {
13- guard let owner = owner as? ChooseFolderItem else { return }
1423 let panel = NSOpenPanel()
1524 panel.canChooseDirectories = true
1625 panel.allowsMultipleSelection = false
@@ -23,20 +32,6 @@ extension ActionListener {
2332 NSApplication.shared.activate(ignoringOtherApps: true)
2433 guard panel.runModal() == NSApplication.ModalResponse(NSFileHandlingPanelOKButton),
2534 let url = panel.directoryURL else { return }
26- owner.urlSelector(url)
27- }
28-}
29-
30-class ChooseFolderItem: StatusItem {
31- let menuItem = NSMenuItem()
32- let urlSelector: (URL) -> Void
33- private let listener = ActionListener()
34-
35- init(_ handler: @escaping ((URL) -> Void)) {
36- urlSelector = handler
37- menuItem.title = NSLocalizedString("Choose Folder", comment: "Choose Folder MenuItem")
38- menuItem.action = #selector(ActionListener.selectFolder(_:))
39- menuItem.target = listener
40- listener.owner = self
35+ urlSelector(url)
4136 }
4237 }
--- a/GoInto/FolderItem.swift
+++ b/GoInto/FolderItem.swift
@@ -8,17 +8,9 @@
88
99 import Cocoa
1010
11-extension ActionListener {
12- @IBAction func changeFolder(_ sender: Any?) {
13- guard let owner = owner as? FolderItem else { return }
14- owner.set()
15- }
16-}
17-
1811 final class FolderItem: StatusItem {
1912 let url: URL
2013 let menuItem = NSMenuItem()
21- private let listener = ActionListener()
2214
2315 init(_ url: URL) {
2416 self.url = url
@@ -32,9 +24,8 @@ final class FolderItem: StatusItem {
3224
3325 let work = NSWorkspace.shared
3426 menuItem.image = fitSize(work.icon(forFile: url.path))
35- menuItem.action = #selector(ActionListener.changeFolder(_:))
36- menuItem.target = listener
37- listener.owner = self
27+ menuItem.action = #selector(changeFolder(_:))
28+ menuItem.target = self
3829 }
3930 deinit {
4031 remove()
@@ -55,6 +46,10 @@ final class FolderItem: StatusItem {
5546 func update(_ url: URL) {
5647 menuItem.state = (self.url == url ? .on : .off)
5748 }
49+
50+ @IBAction func changeFolder(_ sender: Any?) {
51+ set()
52+ }
5853 }
5954
6055 func fitSize(_ image: NSImage) -> NSImage {
--- a/GoInto/ImageTypeItem.swift
+++ b/GoInto/ImageTypeItem.swift
@@ -8,16 +8,6 @@
88
99 import Cocoa
1010
11-extension ActionListener {
12- @IBAction func selectType(_ sender: Any?) {
13- guard let owner = owner as? ImageTypeItem,
14- let item = sender as? NSMenuItem,
15- let typeName = item.representedObject as? String
16- else { return }
17- owner.set(typeName)
18- }
19-}
20-
2111 private func loadImageTypes() -> [String] {
2212 guard let url = Bundle.main.url(forResource: "ImageType", withExtension: "plist"),
2313 let array = NSArray(contentsOf: url)
@@ -28,11 +18,8 @@ private func loadImageTypes() -> [String] {
2818 class ImageTypeItem: StatusItem {
2919 let menuItem = NSMenuItem()
3020 private let supportTypes = loadImageTypes()
31- private let listener = ActionListener()
3221
33- init() {
34- listener.owner = self
35-
22+ init() {
3623 menuItem.title = NSLocalizedString("Image Type", comment: "Image Type MenuItem")
3724
3825 let ws = NSWorkspace.shared
@@ -43,8 +30,8 @@ class ImageTypeItem: StatusItem {
4330 .map {
4431 let item = NSMenuItem()
4532 item.title = ws.localizedDescription(forType: $0) ?? "Never Use Default Value"
46- item.action = #selector(ActionListener.selectType(_:))
47- item.target = listener
33+ item.action = #selector(selectType(_:))
34+ item.target = self
4835 item.representedObject = ws.preferredFilenameExtension(forType: $0)
4936 return item
5037 }
@@ -68,4 +55,11 @@ class ImageTypeItem: StatusItem {
6855 Screenshot.shared.type = typeName
6956 }
7057 }
58+
59+ @IBAction func selectType(_ sender: Any?) {
60+ guard let item = sender as? NSMenuItem,
61+ let typeName = item.representedObject as? String
62+ else { return }
63+ set(typeName)
64+ }
7165 }
--- a/GoInto/QuitItem.swift
+++ b/GoInto/QuitItem.swift
@@ -8,20 +8,17 @@
88
99 import Cocoa
1010
11-extension ActionListener {
12- @IBAction func quit(_ sender: Any?) {
13- NSApplication.shared.terminate(nil)
14- }
15-}
16-
1711 class QuitItem: StatusItem {
1812 let menuItem = NSMenuItem()
19- private let listener = ActionListener()
2013
2114 init() {
2215 let format = NSLocalizedString("Quit %@", comment: "Quit Menu Item")
2316 menuItem.title = String(format: format, AppDelegate.appName)
24- menuItem.action = #selector(ActionListener.quit(_:))
25- menuItem.target = listener
17+ menuItem.action = #selector(quit(_:))
18+ menuItem.target = self
19+ }
20+
21+ @IBAction func quit(_ sender: Any?) {
22+ NSApplication.shared.terminate(nil)
2623 }
2724 }