From f1150e784ff0929235710fad93180ce66bc23a12 Mon Sep 17 00:00:00 2001 From: Patrick Kladek Date: Mon, 8 Jan 2018 11:17:22 +0100 Subject: [PATCH] cleanup --- Screenshot Framer CLI/Controller.swift | 33 +++++----- .../ContentViewController.swift | 64 +++++++++---------- .../ContentViewController.xib | 3 - .../Help Controller/LayoutController.swift | 2 +- 4 files changed, 48 insertions(+), 54 deletions(-) diff --git a/Screenshot Framer CLI/Controller.swift b/Screenshot Framer CLI/Controller.swift index 62d0960..aed5e57 100644 --- a/Screenshot Framer CLI/Controller.swift +++ b/Screenshot Framer CLI/Controller.swift @@ -38,13 +38,12 @@ final class Controller { self.console.printUsage() } - self.ignoreFontToBig = self.arguments.filter { $0 == "-ignoreFontToBig" }.hasElements + self.ignoreFontToBig = self.arguments.filter { $0.lowercased() == "-ignorefonttobig" }.hasElements guard let index = self.arguments.index(of: "-project") else { parseParameterFailed(); return .wrongArguments } guard self.arguments.count >= index + 1 else { parseParameterFailed(); return .wrongArguments } - let fileManager = FileManager() - let documentURL = URL(fileURLWithPath: self.arguments[2]) + let documentURL = URL(fileURLWithPath: self.arguments[index + 1]) var isDir: ObjCBool = false fileManager.fileExists(atPath: documentURL.path, isDirectory: &isDir) @@ -75,13 +74,7 @@ final class Controller { extension Controller: ExportControllerDelegate { func exportController(_ exportController: ExportController, didUpdateProgress progress: Double, file: String, layoutErrors: [LayoutError]) { - var errors = layoutErrors - - if self.ignoreFontToBig { - errors.remove(object: .fontToBig) - } - - self.console.writeMessage("export: \(String(format: "%3.0f", progress * 100))%\t\(file)", to: errors.hasElements ? .error : .success) + self.console.writeMessage("export: \(String(format: "%3.0f", progress * 100))%\t\(file)", to: self.checkedErrors(layoutErrors).hasElements ? .error : .success) } } @@ -111,20 +104,24 @@ extension Controller { exportController.delegate = self self.console.writeMessage("Project: \(project.lastPathComponent)") + let exportErrors = exportController.saveAllImages() - var exportErrors = exportController.saveAllImages() - - if self.ignoreFontToBig { - exportErrors.remove(object: .fontToBig) - } - - if exportErrors.hasElements { + if self.checkedErrors(exportErrors).hasElements { self.console.writeMessage("Something went wrong while exporting. Please check the projects for detailed information", to: .error) self.console.writeMessage("Here are the error codes:", to: .error) self.console.writeMessage("\(exportErrors.map { $0.rawValue }.joined(separator: "\n"))") - } return .noError } + + func checkedErrors(_ errors: [LayoutError]) -> [LayoutError] { + var exportErrors = errors + + if self.ignoreFontToBig { + exportErrors.remove(object: .fontToBig) + } + + return exportErrors + } } diff --git a/Screenshot Framer/Document Window/Content View Controller/ContentViewController.swift b/Screenshot Framer/Document Window/Content View Controller/ContentViewController.swift index 58d5947..e827471 100644 --- a/Screenshot Framer/Document Window/Content View Controller/ContentViewController.swift +++ b/Screenshot Framer/Document Window/Content View Controller/ContentViewController.swift @@ -25,9 +25,8 @@ final class ContentViewController: NSViewController { lazy var languageController = LanguageController(fileCapsule: self.document.fileCapsule) lazy var exportController = ExportController(layerStateHistory: self.layerStateHistory, fileController: self.fileController, languageController: self.languageController) lazy var layoutController = LayoutController(viewStateController: self.viewStateController, languageController: self.languageController, fileController: self.fileController) - - lazy var popover = NSPopover() lazy var layoutWarningPopoverViewController = WarningPopoverViewController() + lazy var popover = NSPopover() // MARK: - Interface Builder @@ -151,34 +150,6 @@ final class ContentViewController: NSViewController { } } - @objc func addContent(_ sender: AnyObject?) { - let operation = AddContentOperation(layerStateHistory: self.layerStateHistory) - operation.apply() - self.tableView.reloadDataKeepingSelection() - } - - @objc func addDevice(_ sender: AnyObject?) { - let operation = AddDeviceOperation(layerStateHistory: self.layerStateHistory) - operation.apply() - self.tableView.reloadDataKeepingSelection() - } - - @objc func addText(_ sender: AnyObject?) { - let operation = AddTextOperation(layerStateHistory: self.layerStateHistory) - operation.apply() - self.tableView.reloadDataKeepingSelection() - } - - func removeLayoutableObject() { - let operation = RemoveLayerOperation(layerStateHistory: self.layerStateHistory, indexOfLayer: self.tableView.selectedRow) - - let firstIndex = IndexSet(integer: self.tableView.selectedRow - 1) - self.tableView.selectRowIndexes(firstIndex, byExtendingSelection: false) - - operation.apply() - self.tableView.reloadDataKeepingSelection() - } - @IBAction func toggleHighlightCurrentLayer(_ sender: AnyObject?) { self.layoutController.shouldHighlightSelectedLayer = !self.layoutController.shouldHighlightSelectedLayer self.viewStateController.newViewState(selectedLayer: self.tableView.selectedRow) @@ -245,8 +216,8 @@ final class ContentViewController: NSViewController { } } - @IBAction func endEditingText(_ sender: NSTextField?) { - guard let textField = sender else { return } + @IBAction func endEditingText(_ sender: Any?) { + guard let textField = sender as? NSTextField else { return } let row = self.tableView.row(for: textField) guard row >= 0 else { return } @@ -376,4 +347,33 @@ private extension ContentViewController { menuLocation.y += segmentedControl.bounds.size.height + 5.0 self.addMenu.popUp(positioning: nil, at: menuLocation, in: segmentedControl) } + + @objc func addContent(_ sender: AnyObject?) { + let operation = AddContentOperation(layerStateHistory: self.layerStateHistory) + operation.apply() + self.tableView.reloadDataKeepingSelection() + } + + @objc func addDevice(_ sender: AnyObject?) { + let operation = AddDeviceOperation(layerStateHistory: self.layerStateHistory) + operation.apply() + self.tableView.reloadDataKeepingSelection() + } + + @objc func addText(_ sender: AnyObject?) { + let operation = AddTextOperation(layerStateHistory: self.layerStateHistory) + operation.apply() + self.tableView.reloadDataKeepingSelection() + } + + @objc func removeLayoutableObject() { + let operation = RemoveLayerOperation(layerStateHistory: self.layerStateHistory, indexOfLayer: self.tableView.selectedRow) + + let firstIndex = IndexSet(integer: self.tableView.selectedRow - 1) + self.tableView.selectRowIndexes(firstIndex, byExtendingSelection: false) + + operation.apply() + self.tableView.reloadDataKeepingSelection() + } + } diff --git a/Screenshot Framer/Document Window/Content View Controller/ContentViewController.xib b/Screenshot Framer/Document Window/Content View Controller/ContentViewController.xib index 54673f8..97fc434 100644 --- a/Screenshot Framer/Document Window/Content View Controller/ContentViewController.xib +++ b/Screenshot Framer/Document Window/Content View Controller/ContentViewController.xib @@ -93,9 +93,6 @@ - - - diff --git a/Screenshot Framer/Document Window/Content View Controller/Help Controller/LayoutController.swift b/Screenshot Framer/Document Window/Content View Controller/Help Controller/LayoutController.swift index 5ee4845..263c501 100644 --- a/Screenshot Framer/Document Window/Content View Controller/Help Controller/LayoutController.swift +++ b/Screenshot Framer/Document Window/Content View Controller/Help Controller/LayoutController.swift @@ -55,7 +55,7 @@ class LayoutController { func layouthierarchy(layers: [LayoutableObject]) -> NSView? { self.layoutErrors = [] - guard layers.hasElements else { self.layoutErrors.append(.noLayers); return nil } + guard layers.hasElements else { self.layoutErrors = [.noLayers]; return nil } let firstLayoutableObject = layers[0] let rootView = self.view(from: firstLayoutableObject)