Skip to content

Commit

Permalink
Generify rename into common RenameView
Browse files Browse the repository at this point in the history
  • Loading branch information
divadretlaw committed Dec 2, 2023
1 parent 6f5a920 commit a08202a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 82 deletions.
12 changes: 4 additions & 8 deletions Whisky.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
objects = {

/* Begin PBXBuildFile section */
6330DD962B1B0EA4007A625A /* RenameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6330DD952B1B0EA4007A625A /* RenameView.swift */; };
6365C4C12B1AA69D00AAE1FD /* Animation+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6365C4C02B1AA69D00AAE1FD /* Animation+Extensions.swift */; };
6365C4C32B1AA8CD00AAE1FD /* BottleListEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6365C4C22B1AA8CD00AAE1FD /* BottleListEntry.swift */; };
63FFDE862ADF0C7700178665 /* BottomBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63FFDE852ADF0C7700178665 /* BottomBar.swift */; };
6E064B1229DD32A200D9A2D2 /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = 6E064B1129DD32A200D9A2D2 /* Sparkle */; };
6E064B1429DD331F00D9A2D2 /* SparkleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E064B1329DD331F00D9A2D2 /* SparkleView.swift */; };
6E17B6442AF3FD9600831173 /* PinRenameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E17B6432AF3FD9600831173 /* PinRenameView.swift */; };
6E17B6462AF3FDC100831173 /* PinView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E17B6452AF3FDC100831173 /* PinView.swift */; };
6E17B6492AF4118F00831173 /* EnvironmentArgView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E17B6482AF4118F00831173 /* EnvironmentArgView.swift */; };
6E182FCA2B0BF64E00AADE81 /* WinetricksView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E182FC92B0BF64E00AADE81 /* WinetricksView.swift */; };
Expand Down Expand Up @@ -44,7 +44,6 @@
6E95F66D2AB3EF3A00D585D1 /* WhiskyCmd in Embed WhiskyCmd */ = {isa = PBXBuildFile; fileRef = 6E70A4982A9A2197007799E9 /* WhiskyCmd */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
6E95F6702AB3F33C00D585D1 /* SwiftyTextTable in Frameworks */ = {isa = PBXBuildFile; productRef = 6E95F66F2AB3F33C00D585D1 /* SwiftyTextTable */; };
6E95F6732AB3F67200D585D1 /* Progress in Frameworks */ = {isa = PBXBuildFile; productRef = 6E95F6722AB3F67200D585D1 /* Progress */; };
6EA2D47E29DDAE5E00C84668 /* BottleRenameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EA2D47D29DDAE5E00C84668 /* BottleRenameView.swift */; };
6EB58AC92AEACE5E00B1ED3F /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 6EB58AC82AEACE5E00B1ED3F /* Localizable.xcstrings */; };
6EF557982A410599001A4F09 /* SetupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EF557972A410599001A4F09 /* SetupView.swift */; };
6EFDF64C2AAE2DA800EF622F /* QuickLookThumbnailing.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6EFDF64B2AAE2DA800EF622F /* QuickLookThumbnailing.framework */; };
Expand Down Expand Up @@ -107,11 +106,11 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
6330DD952B1B0EA4007A625A /* RenameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RenameView.swift; sourceTree = "<group>"; };
6365C4C02B1AA69D00AAE1FD /* Animation+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Animation+Extensions.swift"; sourceTree = "<group>"; };
6365C4C22B1AA8CD00AAE1FD /* BottleListEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottleListEntry.swift; sourceTree = "<group>"; };
63FFDE852ADF0C7700178665 /* BottomBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BottomBar.swift; sourceTree = "<group>"; };
6E064B1329DD331F00D9A2D2 /* SparkleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SparkleView.swift; sourceTree = "<group>"; };
6E17B6432AF3FD9600831173 /* PinRenameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PinRenameView.swift; sourceTree = "<group>"; };
6E17B6452AF3FDC100831173 /* PinView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PinView.swift; sourceTree = "<group>"; };
6E17B6482AF4118F00831173 /* EnvironmentArgView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnvironmentArgView.swift; sourceTree = "<group>"; };
6E182FC92B0BF64E00AADE81 /* WinetricksView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WinetricksView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -142,7 +141,6 @@
6E7C07BD2AAE7B0100F6E66B /* ProgramShortcut.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgramShortcut.swift; sourceTree = "<group>"; };
6E7C07BF2AAF570100F6E66B /* FileOpenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileOpenView.swift; sourceTree = "<group>"; };
6E899D1129CFC41D00A4A083 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
6EA2D47D29DDAE5E00C84668 /* BottleRenameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottleRenameView.swift; sourceTree = "<group>"; };
6EB58AC82AEACE5E00B1ED3F /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
6EF557972A410599001A4F09 /* SetupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetupView.swift; sourceTree = "<group>"; };
6EFDF64A2AAE2DA800EF622F /* WhiskyThumbnail.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = WhiskyThumbnail.appex; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -206,6 +204,7 @@
isa = PBXGroup;
children = (
63FFDE852ADF0C7700178665 /* BottomBar.swift */,
6330DD952B1B0EA4007A625A /* RenameView.swift */,
);
path = Common;
sourceTree = "<group>";
Expand All @@ -216,7 +215,6 @@
6E17B6452AF3FDC100831173 /* PinView.swift */,
6E2B25C02B0E20F50084A67A /* PinAddView.swift */,
DB696FC72AFAE5DA0037EB2F /* PinCreationView.swift */,
6E17B6432AF3FD9600831173 /* PinRenameView.swift */,
);
path = Pins;
sourceTree = "<group>";
Expand All @@ -237,7 +235,6 @@
children = (
6E40498029CCA8B0006E3F1B /* BottleView.swift */,
6E50D98429CDF25B008C39F6 /* BottleCreationView.swift */,
6EA2D47D29DDAE5E00C84668 /* BottleRenameView.swift */,
6E355E5729D78249002D83BE /* ConfigView.swift */,
6E182FC92B0BF64E00AADE81 /* WinetricksView.swift */,
6E17B6422AF3FD6E00831173 /* Pins */,
Expand Down Expand Up @@ -584,12 +581,12 @@
DB696FC82AFAE5DA0037EB2F /* PinCreationView.swift in Sources */,
6E7C07BE2AAE7B0100F6E66B /* ProgramShortcut.swift in Sources */,
6E355E5829D78249002D83BE /* ConfigView.swift in Sources */,
6EA2D47E29DDAE5E00C84668 /* BottleRenameView.swift in Sources */,
63FFDE862ADF0C7700178665 /* BottomBar.swift in Sources */,
6E6C0CF62A419A8300356232 /* GPTKDownloadView.swift in Sources */,
6365C4C32B1AA8CD00AAE1FD /* BottleListEntry.swift in Sources */,
6E50D98529CDF25B008C39F6 /* BottleCreationView.swift in Sources */,
6E182FCA2B0BF64E00AADE81 /* WinetricksView.swift in Sources */,
6330DD962B1B0EA4007A625A /* RenameView.swift in Sources */,
6E17B6492AF4118F00831173 /* EnvironmentArgView.swift in Sources */,
6E6C0CF42A419A7600356232 /* RosettaView.swift in Sources */,
6E6C0CF82A419A8C00356232 /* GPTKInstallView.swift in Sources */,
Expand All @@ -605,7 +602,6 @@
6E49E0212AECB7DB00009CAC /* SettingsView.swift in Sources */,
6E7C07C02AAF570100F6E66B /* FileOpenView.swift in Sources */,
6E355E6029D7D8BD002D83BE /* Program+Extensions.swift in Sources */,
6E17B6442AF3FD9600831173 /* PinRenameView.swift in Sources */,
6E6C0CF22A419A6800356232 /* WelcomeView.swift in Sources */,
6E40498129CCA8B0006E3F1B /* BottleView.swift in Sources */,
6E355E5E29D7D85D002D83BE /* ProgramView.swift in Sources */,
Expand Down
5 changes: 4 additions & 1 deletion Whisky/Views/Bottle/BottleListEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ struct BottleListEntry: View {
name = bottle.settings.name
}
.sheet(isPresented: $showBottleRename) {
BottleRenameView(bottle: bottle, name: $name)
RenameView("rename.bottle.title", name: name) { newName in
name = newName
bottle.rename(newName: newName)
}
}
.contextMenu {
Button("button.rename", systemImage: "pencil.line") {
Expand Down
63 changes: 0 additions & 63 deletions Whisky/Views/Bottle/BottleRenameView.swift

This file was deleted.

4 changes: 3 additions & 1 deletion Whisky/Views/Bottle/Pins/PinView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ struct PinView: View {
runProgram()
}
.sheet(isPresented: $showRenameSheet) {
PinRenameView(name: $name)
RenameView("rename.pin.title", name: name) { newName in
name = newName
}
}
.onAppear {
name = pin.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,38 @@

import SwiftUI

struct PinRenameView: View {
@Binding var name: String
struct RenameView: View {
let title: Text
var renameAction: (String) -> Void

@State private var newPinName: String = ""
@State private var name: String = ""
@Environment(\.dismiss) private var dismiss

init(_ title: Text, name: String, renameAction: @escaping (String) -> Void) {
self.title = title
self._name = State(initialValue: name)
self.renameAction = renameAction
}

init(_ title: LocalizedStringKey, name: String, renameAction: @escaping (String) -> Void) {
self.title = Text(title)
self._name = State(initialValue: name)
self.renameAction = renameAction
}

init(verbatim title: String, name: String, renameAction: @escaping (String) -> Void) {
self.title = Text(verbatim: title)
self._name = State(initialValue: name)
self.renameAction = renameAction
}

var body: some View {
NavigationStack {
Form {
TextField("rename.name", text: $newPinName)
TextField("rename.name", text: $name)
}
.formStyle(.grouped)
.navigationTitle("rename.pin.title")
.navigationTitle(title)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("create.cancel") {
Expand All @@ -40,7 +59,7 @@ struct PinRenameView: View {
}
ToolbarItem(placement: .primaryAction) {
Button("rename.rename") {
name = newPinName
renameAction(name)
dismiss()
}
.keyboardShortcut(.defaultAction)
Expand All @@ -49,9 +68,6 @@ struct PinRenameView: View {
}
}
.frame(width: 350, height: 120)
.onAppear {
newPinName = name
}
}

var isNameValid: Bool {
Expand Down

0 comments on commit a08202a

Please sign in to comment.