From d0c84b19f454ccf175e62e370030277827148261 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Fri, 27 Jun 2025 21:45:09 +0100 Subject: [PATCH] added renaming themes gonna add delete themes next --- ShhShell/Host/HostsManager.swift | 10 ++++++ ShhShell/Views/Misc/ViewModifiers.swift | 36 +++++++++++++++++++ ShhShell/Views/Themes/ThemeManagerView.swift | 37 ++++++++++++++------ 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/ShhShell/Host/HostsManager.swift b/ShhShell/Host/HostsManager.swift index 55387db..bdb3770 100644 --- a/ShhShell/Host/HostsManager.swift +++ b/ShhShell/Host/HostsManager.swift @@ -48,6 +48,16 @@ class HostsManager: ObservableObject, @unchecked Sendable { task.resume() } + func renameTheme(_ theme: Theme?, to newName: String) { + guard let theme else { return } + guard let index = themes.firstIndex(where: {$0.id == theme.id}) else { return } + var newTheme = themes[index] + newTheme.name = newName + newTheme.id = UUID() + withAnimation { themes[index] = newTheme } + saveThemes() + } + @MainActor func importTheme(name: String, data: Data?) { guard let data else { return } diff --git a/ShhShell/Views/Misc/ViewModifiers.swift b/ShhShell/Views/Misc/ViewModifiers.swift index a7a6ad1..313a2a6 100644 --- a/ShhShell/Views/Misc/ViewModifiers.swift +++ b/ShhShell/Views/Misc/ViewModifiers.swift @@ -23,3 +23,39 @@ struct foregroundColorStyle: ViewModifier { } } } + +struct scrollPaging: ViewModifier { + func body(content: Content) -> some View { + if #available(iOS 17, *) { + content.scrollTargetBehavior(.paging) + } else { + content + } + } +} + +struct scrollTargetLayoutt: ViewModifier { + func body(content: Content) -> some View { + if #available(iOS 17, *) { + content.scrollTargetLayout() + } else { + content + } + } +} + +struct contentMarginss: ViewModifier { + var length: CGFloat + + init(length: CGFloat) { + self.length = length + } + + func body(content: Content) -> some View { + if #available(iOS 17, *) { + content.contentMargins(length) + } else { + content + } + } +} diff --git a/ShhShell/Views/Themes/ThemeManagerView.swift b/ShhShell/Views/Themes/ThemeManagerView.swift index aa234e7..53033a2 100644 --- a/ShhShell/Views/Themes/ThemeManagerView.swift +++ b/ShhShell/Views/Themes/ThemeManagerView.swift @@ -14,6 +14,10 @@ struct ThemeManagerView: View { @State var importURL: String = "" @State var toImportName: String = "" + @State var showRenameAlert: Bool = false + @State var themeToRename: Theme? + @State var rename: String = "" + let grid: GridItem = GridItem( .fixed(90), spacing: 8, @@ -27,10 +31,32 @@ struct ThemeManagerView: View { LazyHGrid(rows: [grid, grid], alignment: .center, spacing: 8) { ForEach(hostsManager.themes) { theme in ThemePreview(theme: theme) + .contextMenu { + Button() { + themeToRename = theme + rename = theme.name + showRenameAlert.toggle() + } label: { + Label("Rename", systemImage: "pencil") + } + Button(role: .destructive) { + + } label: { + Label("Delete", systemImage: "trash") + } + } } } + .alert("", isPresented: $showRenameAlert) { + TextField("", text: $rename) + Button("OK") { + hostsManager.renameTheme(themeToRename, to: rename) + rename = "" + } + } + .padding(.horizontal, 8) } - .frame(height: 160) + .fixedSize(horizontal: false, vertical: true) .scrollIndicators(.hidden) .alert("Enter URL", isPresented: $showAlert) { TextField("", text: $importURL, prompt: Text("URL")) @@ -42,15 +68,6 @@ struct ThemeManagerView: View { } } .toolbar { - ToolbarItem(placement: .confirmationAction) { - Button() { - if let pasteboard = UIPasteboard().string { - hostsManager.importTheme(name: toImportName, data: pasteboard.data(using: .utf8)) - } - } label: { - Label("Import", systemImage: "plus") - } - } ToolbarItem() { Button() { UIApplication.shared.open(URL(string: "https://iterm2colorschemes.com")!)