Skip to content

Commit

Permalink
Bump SwiftBeanCountImporter to 0.8.1
Browse files Browse the repository at this point in the history
Adjust App for changed delegate, add boolean and otp input options
  • Loading branch information
Nef10 committed Oct 21, 2024
1 parent ec65357 commit a36ee07
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 40 deletions.
2 changes: 1 addition & 1 deletion SwiftBeanCountImporterApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@
repositoryURL = "https://github.com/Nef10/SwiftBeanCountImporter.git";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 0.7.4;
minimumVersion = 0.8.1;
};
};
F9C329FC2488D1770055EB90 /* XCRemoteSwiftPackageReference "SwiftBeanCountModel" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Nef10/SwiftBeanCountImporter.git",
"state" : {
"revision" : "5f3419102c5e04a24c4aa0462f6bbcdfb31fb16b",
"version" : "0.7.4"
"revision" : "733a1733a7a06684bc7c8b2b95c6116ddbb55f0a",
"version" : "0.8.1"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1520"
LastUpgradeVersion = "1600"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
15 changes: 7 additions & 8 deletions SwiftBeanCountImporterApp/Controller/ImportViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ImportViewController: NSViewController {
private var importers = [Importer]()
private var currentImporter: Importer!
private var errors = [String]()
private var inputRequest: (String, [String], Bool, (String) -> Bool)! // swiftlint:disable:this large_tuple
private var inputRequest: (String, ImporterInputRequestType, (String) -> Bool)! // swiftlint:disable:this large_tuple

private weak var loadingIndicatorSheet: LoadingIndicatorViewController?

Expand Down Expand Up @@ -88,12 +88,11 @@ class ImportViewController: NSViewController {
if let window = self.loadingIndicatorSheet?.view.window {
self.view.window?.endSheet(window)
}
let (name, suggestions, isSecure, _) = inputRequest
controller.delegate = self
controller.suggestions = suggestions
let (name, type, _) = inputRequest
controller.importName = currentImporter.importName
controller.name = name
controller.isSecure = isSecure
controller.type = type
controller.delegate = self
default:
break
}
Expand Down Expand Up @@ -299,7 +298,7 @@ extension ImportViewController: DataEntryViewControllerDelegate, DuplicateTransa

func finished(_ sheet: NSWindow, input: String) {
view.window?.endSheet(sheet)
let (_, _, _, completion) = inputRequest
let (_, _, completion) = inputRequest
if !completion(input) {
showInputRequest()
}
Expand Down Expand Up @@ -335,8 +334,8 @@ extension ImportViewController: ImporterDelegate {
importerWindowController = nil
}

func requestInput(name: String, suggestions: [String], isSecret: Bool, completion: @escaping (String) -> Bool) {
inputRequest = (name, suggestions, isSecret, completion)
func requestInput(name: String, type: ImporterInputRequestType, completion: @escaping (String) -> Bool) {
inputRequest = (name, type, completion)
showInputRequest()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Cocoa
import Foundation
import SwiftBeanCountImporter

protocol ImporterInputViewControllerDelegate: AnyObject {

Expand All @@ -18,17 +19,14 @@ protocol ImporterInputViewControllerDelegate: AnyObject {

class ImporterInputViewController: NSViewController {

/// Suggestions which should be provided to the user
var suggestions = [String]()

/// Name describing the import, to tell the user for which import info is requested
var importName: String?

/// Name describing the input
var name: String?

/// Should the input be in a secure text field
var isSecure = false
/// Type of the input
var type: ImporterInputRequestType!

/// Delegate to send finish and cancel message to
weak var delegate: ImporterInputViewControllerDelegate?
Expand All @@ -37,44 +35,82 @@ class ImporterInputViewController: NSViewController {
@IBOutlet private var label: NSTextField!
@IBOutlet private var textField: NSTextField!
@IBOutlet private var secureTextField: NSSecureTextField!
@IBOutlet private var cancelButton: NSButton!
@IBOutlet private var okButton: NSButton!

// swiftlint:disable:next function_body_length
override func viewDidLoad() {
super.viewDidLoad()
guard let importName, let name else {
fatalError("importName and name are required to create an AccountSelectionViewController")
}
label.stringValue = "Please enter \(name) for the following import: \(importName)"
if isSecure {
label.stringValue = "\(type == .bool ? "" : "Please enter ")\(name) for the following import: \(importName)"
switch type {
case .text(let suggestions):
secureTextField.isHidden = true
okButton.title = "Ok"
cancelButton.title = "Cancel"
if suggestions.isEmpty {
comboBox.isHidden = true
textField.contentType = nil
textField.isHidden = false
} else {
comboBox.isHidden = false
textField.isHidden = true
comboBox.removeAllItems()
comboBox.addItems(withObjectValues: suggestions)
}
case .secret:
comboBox.isHidden = true
textField.isHidden = true
secureTextField.isHidden = false
} else if !suggestions.isEmpty {
comboBox.isHidden = false
textField.isHidden = true
secureTextField.isHidden = true
comboBox.removeAllItems()
comboBox.addItems(withObjectValues: suggestions)
} else {
okButton.title = "Ok"
cancelButton.title = "Cancel"
case .otp:
comboBox.isHidden = true
textField.contentType = .oneTimeCode
textField.isHidden = false
secureTextField.isHidden = true
okButton.title = "Ok"
cancelButton.title = "Cancel"
case .bool:
comboBox.isHidden = true
textField.isHidden = true
secureTextField.isHidden = true
okButton.title = "Yes"
cancelButton.title = "No"
case .none:
fatalError("No type configured in ImporterInputViewController")
}
}

@IBAction private func okButtonPressed(_: NSButton) {
let input: String
if isSecure {
switch type {
case .text(let suggestions):
if suggestions.isEmpty {
input = textField.stringValue
} else {
input = comboBox.stringValue
}
case .secret:
input = secureTextField.stringValue
} else if !suggestions.isEmpty {
input = comboBox.stringValue
} else {
case .otp:
input = textField.stringValue
case .bool:
input = "true"
case .none:
fatalError("No type configured in ImporterInputViewController")
}
delegate?.finished(view.window!, input: input)
}

@IBAction private func cancelButtonPressed(_: NSButton) {
delegate?.cancel(view.window!)
if case .bool = type {
delegate?.finished(view.window!, input: "false")
} else {
delegate?.cancel(view.window!)
}
}

}
20 changes: 11 additions & 9 deletions SwiftBeanCountImporterApp/Views/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="22154" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="23094" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22154"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="23094"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -1054,7 +1054,7 @@ DQ
<scene sceneID="Wxf-LG-kLq">
<objects>
<viewController title="Description Mapping" id="6Ey-ad-GT5" customClass="DescriptionMappingViewController" customModule="SwiftBeanCountImporterApp" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" misplaced="YES" id="qAt-h5-3eG">
<view key="view" id="qAt-h5-3eG">
<rect key="frame" x="0.0" y="0.0" width="739" height="131"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
Expand Down Expand Up @@ -1751,9 +1751,8 @@ Gw
<scene sceneID="0ca-QV-gtx">
<objects>
<viewController id="8fJ-R1-fPR" customClass="ImporterInputViewController" customModule="SwiftBeanCountImporterApp" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="Did-RG-Ug4">
<view key="view" translatesAutoresizingMaskIntoConstraints="NO" id="Did-RG-Ug4">
<rect key="frame" x="0.0" y="0.0" width="450" height="125"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<comboBox focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="X0J-jp-7R7">
<rect key="frame" x="19" y="59" width="414" height="23"/>
Expand All @@ -1770,7 +1769,7 @@ Gw
</comboBox>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="pLg-dD-60o">
<rect key="frame" x="20" y="89" width="206" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Please select the account for file:" id="i6t-Zl-2mW">
<textFieldCell key="cell" title="Please select the account for file:" id="i6t-Zl-2mW">
<font key="font" metaFont="menu"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
Expand Down Expand Up @@ -1843,11 +1842,14 @@ Gw
<constraint firstItem="xsI-Fk-O5s" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="Did-RG-Ug4" secondAttribute="leading" constant="20" id="jUZ-eG-EtW"/>
<constraint firstItem="EPh-6Y-UUH" firstAttribute="leading" secondItem="Did-RG-Ug4" secondAttribute="leading" constant="20" id="jvB-Dg-03d"/>
<constraint firstAttribute="trailing" secondItem="X0J-jp-7R7" secondAttribute="trailing" constant="20" id="my9-NM-AiX"/>
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="530" id="p4W-fi-ZRd"/>
</constraints>
</view>
<connections>
<outlet property="cancelButton" destination="xsI-Fk-O5s" id="Ybh-nT-xiM"/>
<outlet property="comboBox" destination="X0J-jp-7R7" id="nVL-fV-WG8"/>
<outlet property="label" destination="pLg-dD-60o" id="bKb-rN-OFs"/>
<outlet property="okButton" destination="7mF-t7-VMk" id="GNk-fL-pID"/>
<outlet property="secureTextField" destination="dNs-PA-HHE" id="2Qe-cb-Drs"/>
<outlet property="textField" destination="EPh-6Y-UUH" id="gdx-y0-Meo"/>
</connections>
Expand Down Expand Up @@ -2070,7 +2072,7 @@ Gw
<objects>
<viewController title="Account Mapping" id="3mc-Me-KIb" customClass="AccountMappingViewController" customModule="SwiftBeanCountImporterApp" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" misplaced="YES" id="ius-LY-aMc">
<rect key="frame" x="0.0" y="0.0" width="838" height="106"/>
<rect key="frame" x="0.0" y="0.0" width="838" height="131"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<scrollView autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fJ7-vb-V3X">
Expand Down Expand Up @@ -2138,11 +2140,11 @@ Gw
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="AccountCellID" id="7om-dq-sHE">
<rect key="frame" x="231" y="1" width="419" height="16"/>
<rect key="frame" x="231" y="1" width="418" height="16"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="pkC-Y2-1TS">
<rect key="frame" x="0.0" y="0.0" width="419" height="16"/>
<rect key="frame" x="0.0" y="0.0" width="418" height="16"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" title="Table View Cell" id="GhZ-xN-Mdz">
<font key="font" metaFont="menu"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
Expand Down

0 comments on commit a36ee07

Please sign in to comment.