Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick-Kladek committed Jan 8, 2018
1 parent cafc24c commit f1150e7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 54 deletions.
33 changes: 15 additions & 18 deletions Screenshot Framer CLI/Controller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<action selector="endEditingText:" target="-2" id="4hT-k0-71t"/>
</connections>
</textField>
</subviews>
<constraints>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f1150e7

Please sign in to comment.