mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-02 20:16:54 +01:00
Prevent app themes from attempting to be deleted
This commit is contained in:
parent
a1bfa4afdc
commit
0c183f4bdf
@ -49,10 +49,6 @@ final class ArticleThemesManager: NSObject, NSFilePresenter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var themes: [ArticleTheme] {
|
|
||||||
return themeNames.compactMap { articleThemeWithThemeName($0) }
|
|
||||||
}
|
|
||||||
|
|
||||||
init(folderPath: String) {
|
init(folderPath: String) {
|
||||||
self.folderPath = folderPath
|
self.folderPath = folderPath
|
||||||
self.currentTheme = ArticleTheme.defaultTheme
|
self.currentTheme = ArticleTheme.defaultTheme
|
||||||
@ -96,32 +92,6 @@ final class ArticleThemesManager: NSObject, NSFilePresenter {
|
|||||||
try FileManager.default.copyItem(atPath: filename, toPath: toFilename)
|
try FileManager.default.copyItem(atPath: filename, toPath: toFilename)
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteTheme(themeName: String) {
|
|
||||||
if let filename = pathForThemeName(themeName, folder: folderPath) {
|
|
||||||
try? FileManager.default.removeItem(atPath: filename)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK : Private
|
|
||||||
|
|
||||||
private extension ArticleThemesManager {
|
|
||||||
|
|
||||||
func updateThemeNames() {
|
|
||||||
let appThemeFilenames = Bundle.main.paths(forResourcesOfType: ArticleTheme.nnwThemeSuffix, inDirectory: nil)
|
|
||||||
let appThemeNames = Set(appThemeFilenames.map { ArticleTheme.themeNameForPath($0) })
|
|
||||||
|
|
||||||
let installedThemeNames = Set(allThemePaths(folderPath).map { ArticleTheme.themeNameForPath($0) })
|
|
||||||
|
|
||||||
let allThemeNames = appThemeNames.union(installedThemeNames)
|
|
||||||
|
|
||||||
let sortedThemeNames = allThemeNames.sorted(by: { $0.compare($1, options: .caseInsensitive) == .orderedAscending })
|
|
||||||
if sortedThemeNames != themeNames {
|
|
||||||
themeNames = sortedThemeNames
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func articleThemeWithThemeName(_ themeName: String) -> ArticleTheme? {
|
func articleThemeWithThemeName(_ themeName: String) -> ArticleTheme? {
|
||||||
if themeName == AppDefaults.defaultThemeName {
|
if themeName == AppDefaults.defaultThemeName {
|
||||||
return ArticleTheme.defaultTheme
|
return ArticleTheme.defaultTheme
|
||||||
@ -148,6 +118,32 @@ private extension ArticleThemesManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteTheme(themeName: String) {
|
||||||
|
if let filename = pathForThemeName(themeName, folder: folderPath) {
|
||||||
|
try? FileManager.default.removeItem(atPath: filename)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK : Private
|
||||||
|
|
||||||
|
private extension ArticleThemesManager {
|
||||||
|
|
||||||
|
func updateThemeNames() {
|
||||||
|
let appThemeFilenames = Bundle.main.paths(forResourcesOfType: ArticleTheme.nnwThemeSuffix, inDirectory: nil)
|
||||||
|
let appThemeNames = Set(appThemeFilenames.map { ArticleTheme.themeNameForPath($0) })
|
||||||
|
|
||||||
|
let installedThemeNames = Set(allThemePaths(folderPath).map { ArticleTheme.themeNameForPath($0) })
|
||||||
|
|
||||||
|
let allThemeNames = appThemeNames.union(installedThemeNames)
|
||||||
|
|
||||||
|
let sortedThemeNames = allThemeNames.sorted(by: { $0.compare($1, options: .caseInsensitive) == .orderedAscending })
|
||||||
|
if sortedThemeNames != themeNames {
|
||||||
|
themeNames = sortedThemeNames
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func defaultArticleTheme() -> ArticleTheme {
|
func defaultArticleTheme() -> ArticleTheme {
|
||||||
return articleThemeWithThemeName(AppDefaults.defaultThemeName)!
|
return articleThemeWithThemeName(AppDefaults.defaultThemeName)!
|
||||||
}
|
}
|
||||||
|
@ -70,9 +70,10 @@ class ArticleThemesTableViewController: UITableViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
||||||
guard indexPath.row != 0,
|
guard let cell = tableView.cellForRow(at: indexPath),
|
||||||
let cell = tableView.cellForRow(at: indexPath),
|
let themeName = cell.textLabel?.text,
|
||||||
let themeName = cell.textLabel?.text else { return nil }
|
let theme = ArticleThemesManager.shared.articleThemeWithThemeName(themeName),
|
||||||
|
!theme.isAppTheme else { return nil }
|
||||||
|
|
||||||
let deleteTitle = NSLocalizedString("Delete", comment: "Delete")
|
let deleteTitle = NSLocalizedString("Delete", comment: "Delete")
|
||||||
let deleteAction = UIContextualAction(style: .normal, title: deleteTitle) { [weak self] (action, view, completion) in
|
let deleteAction = UIContextualAction(style: .normal, title: deleteTitle) { [weak self] (action, view, completion) in
|
||||||
|
Loading…
x
Reference in New Issue
Block a user