Skip to content

Commit

Permalink
fix: Separate fields for setting the rule destination folder and file…
Browse files Browse the repository at this point in the history
…name (#476)
  • Loading branch information
jbmorley authored Nov 22, 2022
1 parent 78e1fad commit 904d084
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion core/Sources/FileawayCore/Model/ComponentModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ComponentModel: ObservableObject, Identifiable, Hashable {
@Published public var type: ComponentType
public var variable: VariableModel? = nil

public init(value: String, type: ComponentType, variable: VariableModel?) {
public init(value: String, type: ComponentType, variable: VariableModel? = nil) {
self.id = UUID()
self.value = value
self.type = type
Expand Down
22 changes: 22 additions & 0 deletions core/Sources/FileawayCore/Model/RuleModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ public class RuleModel: ObservableObject, Identifiable, CustomStringConvertible,
return self.name
}

public var folder: ComponentModel {
get {
return destination.first ?? ComponentModel(value: "", type: .text)
}
set {
if destination.isEmpty {
destination.append(newValue)
} else {
destination[0] = newValue
}
}
}

public var filename: [ComponentModel] {
get {
return Array(destination[1...])
}
set {
destination = [destination[0]] + newValue
}
}

public init(id: UUID, rootUrl: URL, name: String, variables: [VariableModel], destination: [ComponentModel]) {
self.id = id
self.rootUrl = rootUrl
Expand Down
12 changes: 8 additions & 4 deletions ios/Fileaway/Views/Editor/RuleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,20 @@ struct RuleView: View {
ErrorText(text: editingRuleModel.validate() ? nil : "Variable names must be unique.")
}

Section("Destination") {
ComponentItem(ruleModel: self.editingRuleModel, component: self.editingRuleModel.folder)
}

Section {
ForEach(editingRuleModel.destination) { component in
ForEach(editingRuleModel.filename) { component in
ComponentItem(ruleModel: self.editingRuleModel, component: component)
}
.onMove { (fromOffsets, toOffset) in
self.editingRuleModel.destination.move(fromOffsets: fromOffsets, toOffset: toOffset)
self.editingRuleModel.filename.move(fromOffsets: fromOffsets, toOffset: toOffset)
}
.onDelete { self.editingRuleModel.destination.remove(atOffsets: $0) }
.onDelete { self.editingRuleModel.filename.remove(atOffsets: $0) }
} header: {
Text("Destination")
Text("Filename")
} footer: {
DestinationFooter(ruleModel: editingRuleModel)
}
Expand Down
9 changes: 3 additions & 6 deletions macos/Fileaway/Views/Settings/DestinationTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,20 @@ struct DestinationTable: View {
Table(selection: $selection) {
TableColumn("Component") { componentModel in
if componentModel.type == .text {
HStack {
ComponentValueTextField(componentModel: componentModel)
SetFolderButton(ruleModel: ruleModel, componentModel: componentModel)
}
ComponentValueTextField(componentModel: componentModel)
} else {
Text(ruleModel.name(for: componentModel))
.tokenAppearance()
.tint(componentModel.variable!.color)
}
}
} rows: {
ForEach(ruleModel.destination) { componentModel in
ForEach(ruleModel.filename) { componentModel in
TableRow(componentModel)
.itemProvider(componentModel.id, as: .component)
}
.onInsert(ComponentModel.ID.self, as: .component) { index, ids in
self.ruleModel.destination.move(ids: ids, toOffset: index)
self.ruleModel.filename.move(ids: ids, toOffset: index)
}
}
.frame(minWidth: 500, minHeight: 200)
Expand Down
7 changes: 7 additions & 0 deletions macos/Fileaway/Views/Settings/RuleDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@ struct RuleDetailView: View {
VariablesTable(ruleModel: ruleModel)
Text("Destination")
.font(.headline)
HStack {
TextField("", text: $ruleModel.folder.value)
SetFolderButton(ruleModel: ruleModel, componentModel: ruleModel.folder)
}
Text("Filename")
.font(.headline)
DestinationTable(ruleModel: ruleModel)
Spacer()
.layoutPriority(1)
}
.padding()
}
Expand Down
2 changes: 1 addition & 1 deletion macos/Fileaway/Views/Settings/VariablesTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct VariablesTable: View {
.onDeleteCommand {
ruleModel.remove(variableIds: selection)
}
.frame(minWidth: 500, minHeight: 200)
.frame(minWidth: 500, minHeight: 160)

VStack {
VStack {
Expand Down

0 comments on commit 904d084

Please sign in to comment.