Skip to content

Commit 60fc6e6

Browse files
GetToSetigorkulman
authored andcommitted
Update for better readability
1 parent dbbfc35 commit 60fc6e6

2 files changed

Lines changed: 24 additions & 21 deletions

File tree

sources/LocalizationEditor/AppDelegate.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Cocoa
1313
class AppDelegate: NSObject, NSApplicationDelegate {
1414
@IBOutlet weak var openFolderMenuItem: NSMenuItem!
1515

16-
private static var editorWindow: NSWindow? {
16+
private var editorWindow: NSWindow? {
1717
return NSApp.windows.first(where: { $0.windowController is WindowController })
1818
}
1919

@@ -28,22 +28,24 @@ class AppDelegate: NSObject, NSApplicationDelegate {
2828

2929
func application(_ sender: NSApplication, openFile filename: String) -> Bool {
3030
var isDirectory: ObjCBool = false
31-
if FileManager.default.fileExists(atPath: filename, isDirectory: &isDirectory), isDirectory.boolValue == true {
32-
showEditorWindow()
33-
let windowController = (Self.editorWindow?.windowController) as! WindowController
34-
windowController.openFolder(withPath: filename)
35-
return true
31+
guard FileManager.default.fileExists(atPath: filename, isDirectory: &isDirectory),
32+
isDirectory.boolValue == true
33+
else {
34+
return false
3635
}
37-
return false
36+
showEditorWindow()
37+
let windowController = (editorWindow?.windowController) as! WindowController
38+
windowController.openFolder(withPath: filename)
39+
return true
3840
}
3941

4042
private func showEditorWindow() {
41-
if let editorWindow = Self.editorWindow {
42-
editorWindow.makeKeyAndOrderFront(nil)
43-
} else {
43+
guard let editorWindow = editorWindow else {
4444
let mainStoryboard = NSStoryboard(name: NSStoryboard.Name("Main"), bundle: nil)
4545
let editorWindowController = mainStoryboard.instantiateInitialController() as! WindowController
4646
editorWindowController.showWindow(self)
47+
return
4748
}
49+
editorWindow.makeKeyAndOrderFront(nil)
4850
}
4951
}

sources/LocalizationEditor/UI/ViewController.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,19 @@ final class ViewController: NSViewController {
136136

137137
if let path = path {
138138
handleOpenFolder(URL(fileURLWithPath: path))
139-
} else {
140-
let openPanel = NSOpenPanel()
141-
openPanel.allowsMultipleSelection = false
142-
openPanel.canChooseDirectories = true
143-
openPanel.canCreateDirectories = true
144-
openPanel.canChooseFiles = false
145-
openPanel.begin { result -> Void in
146-
guard result.rawValue == NSApplication.ModalResponse.OK.rawValue, let url = openPanel.url else {
147-
return
148-
}
149-
handleOpenFolder(url)
139+
return
140+
}
141+
142+
let openPanel = NSOpenPanel()
143+
openPanel.allowsMultipleSelection = false
144+
openPanel.canChooseDirectories = true
145+
openPanel.canCreateDirectories = true
146+
openPanel.canChooseFiles = false
147+
openPanel.begin { result -> Void in
148+
guard result.rawValue == NSApplication.ModalResponse.OK.rawValue, let url = openPanel.url else {
149+
return
150150
}
151+
handleOpenFolder(url)
151152
}
152153
}
153154
}

0 commit comments

Comments
 (0)