Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the editor window more like document for better user experience #92

Merged
merged 3 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions sources/LocalizationEditor/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,39 @@ import Cocoa
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var openFolderMenuItem: NSMenuItem!

private var editorWindow: NSWindow? {
return NSApp.windows.first(where: { $0.windowController is WindowController })
}

func applicationDidFinishLaunching(_: Notification) {}

func applicationWillTerminate(_: Notification) {}

func applicationOpenUntitledFile(_ sender: NSApplication) -> Bool {
showEditorWindow()
return true
}

func application(_ sender: NSApplication, openFile filename: String) -> Bool {
var isDirectory: ObjCBool = false
guard FileManager.default.fileExists(atPath: filename, isDirectory: &isDirectory),
isDirectory.boolValue == true
else {
return false
}
showEditorWindow()
let windowController = (editorWindow?.windowController) as! WindowController
windowController.openFolder(withPath: filename)
return true
}

private func showEditorWindow() {
guard let editorWindow = editorWindow else {
let mainStoryboard = NSStoryboard(name: NSStoryboard.Name("Main"), bundle: nil)
let editorWindowController = mainStoryboard.instantiateInitialController() as! WindowController
editorWindowController.showWindow(self)
return
}
editorWindow.makeKeyAndOrderFront(nil)
}
}
15 changes: 15 additions & 0 deletions sources/LocalizationEditor/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Localization Folder</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>LSItemContentTypes</key>
<array>
<string>public.folder</string>
</array>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"view" = "Ansicht";
"file" = "Datei";
"open_folder_with" = "Öffne einen Ordner mit Übersetzungsdateien …";
"close" = "Schließen";
"edit" = "Bearbeiten";
"cut" = "Ausschneiden";
"copy" = "Kopieren";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"view" = "View";
"file" = "File";
"open_folder_with" = "Open folder with localization files...";
"close" = "Close";
"edit" = "Edit";
"cut" = "Cut";
"copy" = "Copy";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"view" = "Vista";
"file" = "Fichero";
"open_folder_with" = "Abrir carpeta con ficheros de traducción...";
"close" = "Cerrar";
"edit" = "Editar";
"cut" = "Cortar";
"copy" = "Copiar";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"view" = "Prikaz";
"file" = "Datoteka";
"open_folder_with" = "Otvori mapu s prevodilačkim datotekama …";
"close" = "Zatvori";
"edit" = "Uredi";
"cut" = "Izreži";
"copy" = "Kopiraj";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"view" = "Вид";
"file" = "Файл";
"open_folder_with" = "Открыть папку с файлами локализации ...";
"close" = "Закрыть";
"edit" = "Правка";
"cut" = "Вырезать";
"copy" = "Скопировать";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"view" = "视图";
"file" = "文件";
"open_folder_with" = "打开带有本地化文件的文件夹...";
"close" = "关闭";
"edit" = "编辑";
"cut" = "剪切";
"copy" = "复制";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"add" = "增加";
"all" = "全部語言";
"bring_all_to_front" = "全部視窗往前";
"close" = "關閉";
"cancel" = "取消";
"comment" = "註解";
"copy" = "複製";
Expand Down
9 changes: 9 additions & 0 deletions sources/LocalizationEditor/UI/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@
<userDefinedRuntimeAttribute type="string" keyPath="localizableString" value="open_folder_with"/>
</userDefinedRuntimeAttributes>
</menuItem>
<menuItem isSeparatorItem="YES" id="LVj-0e-nvV"/>
<menuItem title="Close" keyEquivalent="w" id="v5v-W3-iIa">
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="localizableString" value="close"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="performClose:" target="Ady-hI-5gd" id="VLN-3G-rEe"/>
</connections>
</menuItem>
</items>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="localizableString" value="file"/>
Expand Down
37 changes: 26 additions & 11 deletions sources/LocalizationEditor/UI/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,8 @@ final class ViewController: NSViewController {
tableView.reloadData()
}

private func openFolder() {
let openPanel = NSOpenPanel()
openPanel.allowsMultipleSelection = false
openPanel.canChooseDirectories = true
openPanel.canCreateDirectories = true
openPanel.canChooseFiles = false
openPanel.begin { [unowned self] result -> Void in
guard result.rawValue == NSApplication.ModalResponse.OK.rawValue, let url = openPanel.url else {
return
}

private func openFolder(forPath path: String? = nil) {
let handleOpenFolder: (URL) -> Void = { url in
self.progressIndicator.startAnimation(self)
self.dataSource.load(folder: url) { [unowned self] languages, title, localizationFiles in
self.reloadData(with: languages, title: title)
Expand All @@ -142,6 +133,23 @@ final class ViewController: NSViewController {
}
}
}

if let path = path {
handleOpenFolder(URL(fileURLWithPath: path))
GetToSet marked this conversation as resolved.
Show resolved Hide resolved
return
}

let openPanel = NSOpenPanel()
openPanel.allowsMultipleSelection = false
openPanel.canChooseDirectories = true
openPanel.canCreateDirectories = true
openPanel.canChooseFiles = false
openPanel.begin { result -> Void in
guard result.rawValue == NSApplication.ModalResponse.OK.rawValue, let url = openPanel.url else {
return
}
handleOpenFolder(url)
}
}
}

Expand Down Expand Up @@ -253,6 +261,13 @@ extension ViewController: WindowControllerToolbarDelegate {
func userDidRequestFolderOpen() {
openFolder()
}

/**
Invoked when user requests opening a folder for specific path
*/
func userDidRequestFolderOpen(withPath path: String) {
openFolder(forPath: path)
}
}

// MARK: - AddViewControllerDelegate
Expand Down
11 changes: 11 additions & 0 deletions sources/LocalizationEditor/UI/WindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ protocol WindowControllerToolbarDelegate: AnyObject {
*/
func userDidRequestFolderOpen()

/**
Invoked when user requests opening a folder for a specific path
*/
func userDidRequestFolderOpen(withPath: String)

/**
Invoked when user requests filter change

Expand Down Expand Up @@ -68,6 +73,12 @@ final class WindowController: NSWindowController {
setupDelegates()
}

// MAKR: - Interfaces

func openFolder(withPath path: String) {
delegate?.userDidRequestFolderOpen(withPath: path)
}

// MARK: - Setup

private func setupDelegates() {
Expand Down