Skip to content

Commit

Permalink
Added support for some optional tags
Browse files Browse the repository at this point in the history
  • Loading branch information
buresdv committed Aug 17, 2022
1 parent 18104bb commit 04d86fa
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
16 changes: 15 additions & 1 deletion TBX Scope/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct ContentView: View {

@State private var selectedFile: URL?
@State private var isShowingMoreInfo: Bool = false
@State private var searchString: String = ""

var body: some View {
VStack {
Expand All @@ -28,7 +29,7 @@ struct ContentView: View {
VStack {

if isShowingMoreInfo {

TBXInfoView(data: parsedTBX)
.padding()
.fixedSize()
Expand All @@ -42,6 +43,7 @@ struct ContentView: View {
}
}
}
//.searchable(text: $searchString)
}
}
}
Expand Down Expand Up @@ -86,4 +88,16 @@ struct ContentView: View {
.navigationTitle(Text(parsedTBX.contents.title))
.navigationSubtitle("\(parsedTBX.contents.terms.count == 1 ? 0 : parsedTBX.contents.terms.count) items loaded")
}

/*
var searchResults: ParsedTBX {
if searchString.isEmpty {
return parsedTBX
} else {
return $parsedTBX.filter {
$0.contains(searchString)
}
}
}
*/
}
4 changes: 2 additions & 2 deletions TBX Scope/Logic/Parse XML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ func parseXML(from string: String) throws -> TBX {

let parsedTermID: String = hit.attributes["id"]!

let parsedTermNote: String = hit["langSet", 0, "ntig", "termGrp", "termNote"].text!
let parsedTermNote: String? = hit["langSet", 0, "ntig", "termGrp", "termNote"].text

// Get the term's description
let parsedTermDescription: String = hit[pathToSourceDescription].text ?? ""
let parsedTermDescription: String? = hit[pathToSourceDescription].text

for hit in hit[pathToSourceTerms] {
parsedSourceTermStorage.append(hit["termGrp", "term"].text!)
Expand Down
4 changes: 2 additions & 2 deletions TBX Scope/Structs/Term.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct Term: Identifiable {
let sourceTerm: [String]
let targetTerm: [String]

let termNote: String
let termNote: String?

let description: String
let description: String?
}
5 changes: 5 additions & 0 deletions TBX Scope/Views/TBXInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import SwiftUI
import AppKit

struct TBXInfoView: NSViewRepresentable {
typealias NSViewType = NSGridView
Expand All @@ -25,6 +26,10 @@ struct TBXInfoView: NSViewRepresentable {

grid.column(at: 0).xPlacement = .trailing

/*NSLayoutConstraint.activate([
grid.centerXAnchor.constraint(equalTo: <#T##NSLayoutAnchor<NSLayoutXAxisAnchor>#>)
])*/

return grid
}

Expand Down
24 changes: 15 additions & 9 deletions TBX Scope/Views/TermItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ struct TermItem: View {
HStack(alignment: .top) {
VStack(alignment: .trailing) {
Text(term.sourceTerm.joined(separator: "\n"))
Text(term.termNote)
.font(.caption2)
.padding(.horizontal, 4)
.background(Color(NSColor.tertiaryLabelColor))
.foregroundColor(.white)
.clipShape(Capsule())

if let termNote = term.termNote {
Text(termNote)
.font(.caption2)
.padding(.horizontal, 4)
.background(Color(NSColor.tertiaryLabelColor))
.foregroundColor(.white)
.clipShape(Capsule())
}

/*ForEach(term.sourceTerm, id: \.self) { sourceTerm in
Text(sourceTerm)
}*/
Expand All @@ -36,9 +40,11 @@ struct TermItem: View {
}
}

Text(term.description)
.font(.caption)
.foregroundColor(Color(NSColor.secondaryLabelColor))
if let termDescription = term.description {
Text(termDescription)
.font(.caption)
.foregroundColor(Color(NSColor.secondaryLabelColor))
}

}
.padding()
Expand Down

0 comments on commit 04d86fa

Please sign in to comment.