Skip to content

Commit

Permalink
Merge branch 'update-app'
Browse files Browse the repository at this point in the history
  • Loading branch information
mustii committed Feb 4, 2021
2 parents ae4377b + 95b209f commit cfb78d7
Show file tree
Hide file tree
Showing 51 changed files with 820 additions and 1,269 deletions.
8 changes: 6 additions & 2 deletions FlatAero/FlatAero.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
DF788369244F8F9C00B818E1 /* DecodeViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF788368244F8F9C00B818E1 /* DecodeViewPresenter.swift */; };
DF78836B244F900900B818E1 /* DecodeProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF78836A244F900900B818E1 /* DecodeProtocols.swift */; };
DF78836D244F962800B818E1 /* Errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF78836C244F962800B818E1 /* Errors.swift */; };
DF7F062E25CC796000E0D3D6 /* ConvertOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF7F062D25CC796000E0D3D6 /* ConvertOperation.swift */; };
DF95C949240D77BE009FA3C5 /* FlatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF95C948240D77BE009FA3C5 /* FlatTests.swift */; };
DFA8BDB0247315750006D34D /* DecodeOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFA8BDAF247315750006D34D /* DecodeOperation.swift */; };
DFAEDE37244E56C800B8E8CA /* FlatAeroButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFAEDE36244E56C800B8E8CA /* FlatAeroButton.swift */; };
Expand Down Expand Up @@ -197,6 +198,7 @@
DF788368244F8F9C00B818E1 /* DecodeViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodeViewPresenter.swift; sourceTree = "<group>"; };
DF78836A244F900900B818E1 /* DecodeProtocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodeProtocols.swift; sourceTree = "<group>"; };
DF78836C244F962800B818E1 /* Errors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Errors.swift; sourceTree = "<group>"; };
DF7F062D25CC796000E0D3D6 /* ConvertOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConvertOperation.swift; sourceTree = "<group>"; };
DF95C948240D77BE009FA3C5 /* FlatTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlatTests.swift; sourceTree = "<group>"; };
DFA8BDAF247315750006D34D /* DecodeOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodeOperation.swift; sourceTree = "<group>"; };
DFAEDE36244E56C800B8E8CA /* FlatAeroButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlatAeroButton.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -325,6 +327,7 @@
DF03B544247312F60028FB07 /* BaseOperations */,
DF03B540247312A50028FB07 /* ValidateOperation.swift */,
DFA8BDAF247315750006D34D /* DecodeOperation.swift */,
DF7F062D25CC796000E0D3D6 /* ConvertOperation.swift */,
);
path = Operations;
sourceTree = "<group>";
Expand Down Expand Up @@ -719,6 +722,7 @@
DFF27C182442F6B30039FE42 /* ImportController.swift in Sources */,
DF78836D244F962800B818E1 /* Errors.swift in Sources */,
DFD067CD244AF8CA00173B21 /* FBSStyling.swift in Sources */,
DF7F062E25CC796000E0D3D6 /* ConvertOperation.swift in Sources */,
DF09A941243A5097003FCFE6 /* NSView+Constraints.swift in Sources */,
DF03B53F2473126A0028FB07 /* AsyncOperation.swift in Sources */,
DF03B541247312A50028FB07 /* ValidateOperation.swift in Sources */,
Expand Down Expand Up @@ -903,7 +907,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 2.0;
OTHER_LDFLAGS = (
"-Wl,-search_paths_first",
"-Wl,-headerpad_max_install_names",
Expand Down Expand Up @@ -942,7 +946,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 2.0;
OTHER_LDFLAGS = (
"-Wl,-search_paths_first",
"-Wl,-headerpad_max_install_names",
Expand Down
23 changes: 15 additions & 8 deletions FlatAero/FlatAero/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,39 @@ import Cocoa
import SwiftUI

class AppDelegate: NSObject, NSApplicationDelegate {

static let size = NSRect(x: 0, y: 0, width: 1000, height: 500)

var window: NSWindow!
var mainRouter: MainViewRouter!

func applicationDidFinishLaunching(_ aNotification: Notification) {
mainRouter = MainViewRouter()
mainRouter.start()

window = NSWindow(
contentRect: AppDelegate.size,
styleMask: [.titled, .closable, .resizable, .miniaturizable, .fullSizeContentView],
styleMask: [
.titled,
.closable,
.resizable,
.miniaturizable,
.fullSizeContentView,
],
backing: .buffered, defer: false)
window.center()
window.setFrameAutosaveName("Main Window")
window.contentViewController = mainRouter.navigation
window.makeFirstResponder(mainRouter.navigation)
window.makeKeyAndOrderFront(nil)
}

func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}

@objc func abort() {

@objc
func abort() {
NSApplication.shared.terminate(self)
}
}
30 changes: 15 additions & 15 deletions FlatAero/FlatAero/C_Link/FlatWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,53 @@
import Foundation

struct Flat {

fileprivate var parser = Wrapper()
fileprivate var schema: Schema

init(schema _s: Schema) { schema = _s }

func parser(_ array: inout [UInt8], type: ParseType = .flat) throws -> String {

guard schema.hasRoot else {
throw Errors.schemaRequiresRoot
}

guard !array.isEmpty else {
throw Errors.invalidArrayInput
}

do {
try schema.doesntInclude()
} catch {
throw error
}

var err: NSError?
var str = ""
switch type {
case .flat:
str = flat(&array, err: &err)

case .json:
str = json(&array, err: &err)
}

if let err = err {
throw Errors.libraryError(e: err)
}

return str
}

func json(_ array: inout [UInt8], err: inout NSError?) -> String {
return parser.printJSON(fromBuffer: &array, from: schema.input, error: &err)
parser.printJSON(fromBuffer: &array, from: schema.input, error: &err)
}

func flat(_ array: inout [UInt8], err: inout NSError?) -> String {
return parser.printFLAT(fromBuffer: &array, from: schema.input, error: &err)
parser.printFLAT(fromBuffer: &array, from: schema.input, error: &err)
}

enum ParseType: Int {
case flat, json
}
Expand Down
45 changes: 26 additions & 19 deletions FlatAero/FlatAero/Controllers/DecoderViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,75 +9,82 @@
import Cocoa

class DecoderViewController: NSViewController, DecodeViewControllerDelegate {

lazy var decodedLabel: NSLabel = {
let lbl = NSLabel()
lbl.stringValue = "Decoded FlatBuffer"
lbl.translatesAutoresizingMaskIntoConstraints = false
lbl.heightAnchor.constraint(equalToConstant: 20).isActive = true
return lbl
}()

lazy var decodeButton: NSButton = {
let btn = NSButton(title: "Decode", target: self, action: #selector(decode))
btn.translatesAutoresizingMaskIntoConstraints = false
btn.widthAnchor.constraint(equalToConstant: 100).isActive = true
return btn
}()

lazy var languagePopUpButton: NSPopUpButton = {
let btn = NSPopUpButton()
btn.addItems(withTitles: ["FLAT", "JSON"])
return btn
}()

lazy var decodedTextViewController: TextViewController = {
let controller = TextViewController()
controller.isEnabled = false
return controller
}()

var presenter: DecodeViewPresenterDelegate!

override func loadView() {
view = NSView()
}

override func viewDidLoad() {
super.viewDidLoad()
setupView()
}

@objc func decode() {

@objc
func decode() {
presenter.type = Flat.ParseType(rawValue: languagePopUpButton.indexOfSelectedItem) ?? .flat
decodedTextViewController.remove()
presenter.decode()
}

func parsedBuffer(_ str: String) {
decodedTextViewController.add(text: str)
}
}

extension DecoderViewController {

func setupView() {

let stackView = NSStackView(views: [languagePopUpButton, decodeButton])

stackView.spacing = 50
stackView.distribution = .fill
view.addSubview(decodedLabel)
view.addSubview(stackView)
addChild(decodedTextViewController)
view.addSubview(decodedTextViewController.view)

stackView.anchorInSuperViewDisregarding(edges: .bottom, padding: .init(top: 4, left: 4, bottom: 4, right: 4))


stackView.anchorInSuperViewDisregarding(
edges: .bottom,
padding: .init(top: 4, left: 4, bottom: 4, right: 4))

decodedLabel.anchorInSuperViewDisregarding(edges: .bottom, .top)
decodedLabel.topAnchor.constraint(equalTo: stackView.bottomAnchor, constant: 10).isActive = true

decodedLabel.topAnchor.constraint(
equalTo: stackView.bottomAnchor,
constant: 10).isActive = true

decodedTextViewController.view.anchorInSuperViewDisregarding(edges: .top)
decodedTextViewController.view.topAnchor.constraint(equalTo: decodedLabel.bottomAnchor, constant: 10).isActive = true
decodedTextViewController.view.topAnchor.constraint(
equalTo: decodedLabel.bottomAnchor,
constant: 10).isActive = true
}
}
65 changes: 41 additions & 24 deletions FlatAero/FlatAero/Controllers/ImportController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,73 +9,90 @@
import Cocoa

class ImportController: NSViewController, ImportControllerDelegate {

var presenter: ImportPresenterDelegate!

lazy var displayFromArrayOrBinaryFile: NSSegmentedControl = {
let control = NSSegmentedControl(labels: TypesOfDisplayers.types, trackingMode: .selectOne, target: self, action: #selector(handleSelection))
let control = NSSegmentedControl(
labels: TypesOfDisplayers.types,
trackingMode: .selectOne,
target: self,
action: #selector(handleSelection))
control.translatesAutoresizingMaskIntoConstraints = false
control.selectedSegment = 0
return control
}()

lazy var importUIntArrayController: ImportFromUintArrayController = {
let controller = ImportFromUintArrayController()
controller.presenter = ImportUIntArrayPresenter(controller: controller)
return controller
}()

lazy var importBinaryFileController: ImportFromFileController = {
let controller = ImportFromFileController()
controller.presenter = ImportBinaryPresenter(controller: controller)
return controller
}()

override func loadView() {
view = NSView()
}

override func viewDidLoad() {
super.viewDidLoad()

view.addSubview(displayFromArrayOrBinaryFile)
displayFromArrayOrBinaryFile.topAnchor.constraint(equalTo: view.topAnchor, constant: 4).isActive = true
displayFromArrayOrBinaryFile.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.6).isActive = true
displayFromArrayOrBinaryFile.topAnchor.constraint(
equalTo: view.topAnchor,
constant: 4).isActive = true
displayFromArrayOrBinaryFile.widthAnchor.constraint(
equalTo: view.widthAnchor,
multiplier: 0.6).isActive = true
displayFromArrayOrBinaryFile.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true

view.addSubview(importUIntArrayController.view)
importUIntArrayController.view.anchorInSuperViewDisregarding(edges: .top)
importUIntArrayController.view.topAnchor.constraint(equalTo: displayFromArrayOrBinaryFile.bottomAnchor, constant: 20).isActive = true
importUIntArrayController.view.topAnchor.constraint(
equalTo: displayFromArrayOrBinaryFile.bottomAnchor,
constant: 20).isActive = true
importUIntArrayController.view.isHidden = true

view.addSubview(importBinaryFileController.view)
importBinaryFileController.view.anchorInSuperViewDisregarding(edges: .top)
importBinaryFileController.view.topAnchor.constraint(equalTo: displayFromArrayOrBinaryFile.bottomAnchor, constant: 20).isActive = true
importBinaryFileController.view.topAnchor.constraint(
equalTo: displayFromArrayOrBinaryFile.bottomAnchor,
constant: 20).isActive = true
}

}

extension ImportController {

@objc func handleSelection() {

@objc
func handleSelection() {
Logging.logger.info("User switched between input methods")
presenter.switchDisplayedControllers(of: displayFromArrayOrBinaryFile.indexOfSelectedItem)
}

func should(displayController isHidden: Bool) {
importUIntArrayController.view.isHidden = isHidden
importBinaryFileController.view.isHidden = !isHidden
}
func fetchData() -> ImportedData {

func fetchData() -> SelectedData {
guard let selection = TypesOfDisplayers(rawValue: displayFromArrayOrBinaryFile.indexOfSelectedItem) else { fatalError("Selection has an issue!") }
switch selection {
case .array:
return importUIntArrayController.presenter.data

return SelectedData(
decoding: .array,
data: importUIntArrayController.presenter.data)

case .file:
return importBinaryFileController.presenter.data
return SelectedData(
decoding: .file,
data: importBinaryFileController.presenter.data)
}
}

}
Loading

0 comments on commit cfb78d7

Please sign in to comment.