mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Merge remote-tracking branch 'origin/main' into nnwtheme-downloader
This commit is contained in:
@@ -1295,68 +1295,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||
}
|
||||
|
||||
func importTheme(filename: String) {
|
||||
let theme = ArticleTheme(path: filename)
|
||||
|
||||
let localizedTitleText = NSLocalizedString("Install theme “%@” by %@?", comment: "Theme message text")
|
||||
let title = NSString.localizedStringWithFormat(localizedTitleText as NSString, theme.name, theme.creatorName) as String
|
||||
|
||||
let localizedMessageText = NSLocalizedString("Author's Website:\n%@", comment: "Authors website")
|
||||
let message = NSString.localizedStringWithFormat(localizedMessageText as NSString, theme.creatorHomePage) as String
|
||||
|
||||
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
||||
|
||||
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
||||
alertController.addAction(UIAlertAction(title: cancelTitle, style: .cancel))
|
||||
|
||||
if let url = URL(string: theme.creatorHomePage) {
|
||||
let visitSiteTitle = NSLocalizedString("Show Website", comment: "Show Website")
|
||||
let visitSiteAction = UIAlertAction(title: visitSiteTitle, style: .default) { [weak self] action in
|
||||
UIApplication.shared.open(url)
|
||||
self?.importTheme(filename: filename)
|
||||
}
|
||||
alertController.addAction(visitSiteAction)
|
||||
}
|
||||
|
||||
func importTheme() {
|
||||
do {
|
||||
try ArticleThemesManager.shared.importTheme(filename: filename)
|
||||
confirmImportSuccess(themeName: theme.name)
|
||||
} catch {
|
||||
rootSplitViewController.presentError(error)
|
||||
}
|
||||
}
|
||||
|
||||
let installThemeTitle = NSLocalizedString("Install Theme", comment: "Install Theme")
|
||||
let installThemeAction = UIAlertAction(title: installThemeTitle, style: .default) { [weak self] action in
|
||||
|
||||
if ArticleThemesManager.shared.themeExists(filename: filename) {
|
||||
let title = NSLocalizedString("Duplicate Theme", comment: "Duplicate Theme")
|
||||
let localizedMessageText = NSLocalizedString("The theme “%@” already exists. Overwrite it?", comment: "Overwrite theme")
|
||||
let message = NSString.localizedStringWithFormat(localizedMessageText as NSString, theme.name) as String
|
||||
|
||||
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
||||
|
||||
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
||||
alertController.addAction(UIAlertAction(title: cancelTitle, style: .cancel))
|
||||
|
||||
let overwriteAction = UIAlertAction(title: NSLocalizedString("Overwrite", comment: "Overwrite"), style: .default) { action in
|
||||
importTheme()
|
||||
}
|
||||
alertController.addAction(overwriteAction)
|
||||
alertController.preferredAction = overwriteAction
|
||||
|
||||
self?.rootSplitViewController.present(alertController, animated: true)
|
||||
} else {
|
||||
importTheme()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
alertController.addAction(installThemeAction)
|
||||
alertController.preferredAction = installThemeAction
|
||||
|
||||
rootSplitViewController.present(alertController, animated: true)
|
||||
|
||||
ArticleThemeImporter.importTheme(controller: rootSplitViewController, filename: filename);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2363,18 +2302,4 @@ private extension SceneCoordinator {
|
||||
return true
|
||||
}
|
||||
|
||||
func confirmImportSuccess(themeName: String) {
|
||||
let title = NSLocalizedString("Theme installed", comment: "Theme installed")
|
||||
|
||||
let localizedMessageText = NSLocalizedString("The theme “%@” has been installed.", comment: "Theme installed")
|
||||
let message = NSString.localizedStringWithFormat(localizedMessageText as NSString, themeName) as String
|
||||
|
||||
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
||||
|
||||
let doneTitle = NSLocalizedString("Done", comment: "Done")
|
||||
alertController.addAction(UIAlertAction(title: doneTitle, style: .default))
|
||||
|
||||
rootSplitViewController.present(alertController, animated: true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
96
iOS/Settings/ArticleThemeImporter.swift
Normal file
96
iOS/Settings/ArticleThemeImporter.swift
Normal file
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// ArticleThemeImporter.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 9/18/21.
|
||||
// Copyright © 2021 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
struct ArticleThemeImporter {
|
||||
|
||||
static func importTheme(controller: UIViewController, filename: String) {
|
||||
let theme = ArticleTheme(path: filename)
|
||||
|
||||
let localizedTitleText = NSLocalizedString("Install theme “%@” by %@?", comment: "Theme message text")
|
||||
let title = NSString.localizedStringWithFormat(localizedTitleText as NSString, theme.name, theme.creatorName) as String
|
||||
|
||||
let localizedMessageText = NSLocalizedString("Author's Website:\n%@", comment: "Authors website")
|
||||
let message = NSString.localizedStringWithFormat(localizedMessageText as NSString, theme.creatorHomePage) as String
|
||||
|
||||
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
||||
|
||||
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
||||
alertController.addAction(UIAlertAction(title: cancelTitle, style: .cancel))
|
||||
|
||||
if let url = URL(string: theme.creatorHomePage) {
|
||||
let visitSiteTitle = NSLocalizedString("Show Website", comment: "Show Website")
|
||||
let visitSiteAction = UIAlertAction(title: visitSiteTitle, style: .default) { action in
|
||||
UIApplication.shared.open(url)
|
||||
Self.importTheme(controller: controller, filename: filename)
|
||||
}
|
||||
alertController.addAction(visitSiteAction)
|
||||
}
|
||||
|
||||
func importTheme() {
|
||||
do {
|
||||
try ArticleThemesManager.shared.importTheme(filename: filename)
|
||||
confirmImportSuccess(controller: controller, themeName: theme.name)
|
||||
} catch {
|
||||
controller.presentError(error)
|
||||
}
|
||||
}
|
||||
|
||||
let installThemeTitle = NSLocalizedString("Install Theme", comment: "Install Theme")
|
||||
let installThemeAction = UIAlertAction(title: installThemeTitle, style: .default) { action in
|
||||
|
||||
if ArticleThemesManager.shared.themeExists(filename: filename) {
|
||||
let title = NSLocalizedString("Duplicate Theme", comment: "Duplicate Theme")
|
||||
let localizedMessageText = NSLocalizedString("The theme “%@” already exists. Overwrite it?", comment: "Overwrite theme")
|
||||
let message = NSString.localizedStringWithFormat(localizedMessageText as NSString, theme.name) as String
|
||||
|
||||
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
||||
|
||||
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
||||
alertController.addAction(UIAlertAction(title: cancelTitle, style: .cancel))
|
||||
|
||||
let overwriteAction = UIAlertAction(title: NSLocalizedString("Overwrite", comment: "Overwrite"), style: .default) { action in
|
||||
importTheme()
|
||||
}
|
||||
alertController.addAction(overwriteAction)
|
||||
alertController.preferredAction = overwriteAction
|
||||
|
||||
controller.present(alertController, animated: true)
|
||||
} else {
|
||||
importTheme()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
alertController.addAction(installThemeAction)
|
||||
alertController.preferredAction = installThemeAction
|
||||
|
||||
controller.present(alertController, animated: true)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private extension ArticleThemeImporter {
|
||||
|
||||
static func confirmImportSuccess(controller: UIViewController, themeName: String) {
|
||||
let title = NSLocalizedString("Theme installed", comment: "Theme installed")
|
||||
|
||||
let localizedMessageText = NSLocalizedString("The theme “%@” has been installed.", comment: "Theme installed")
|
||||
let message = NSString.localizedStringWithFormat(localizedMessageText as NSString, themeName) as String
|
||||
|
||||
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
||||
|
||||
let doneTitle = NSLocalizedString("Done", comment: "Done")
|
||||
alertController.addAction(UIAlertAction(title: doneTitle, style: .default))
|
||||
|
||||
controller.present(alertController, animated: true)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,13 +13,26 @@ import UIKit
|
||||
class ArticleThemesTableViewController: UITableViewController {
|
||||
|
||||
override func viewDidLoad() {
|
||||
let importBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(importTheme(_:)));
|
||||
importBarButtonItem.title = NSLocalizedString("Import Theme", comment: "Import Theme");
|
||||
navigationItem.rightBarButtonItem = importBarButtonItem
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(articleThemeNamesDidChangeNotification(_:)), name: .ArticleThemeNamesDidChangeNotification, object: nil)
|
||||
}
|
||||
|
||||
// MARK: Notifications
|
||||
|
||||
@objc func articleThemeNamesDidChangeNotification(_ note: Notification) {
|
||||
tableView.reloadData()
|
||||
}
|
||||
|
||||
@objc func importTheme(_ sender: Any?) {
|
||||
let docPicker = UIDocumentPickerViewController(documentTypes: ["com.ranchero.netnewswire.theme"], in: .import)
|
||||
docPicker.delegate = self
|
||||
docPicker.modalPresentationStyle = .formSheet
|
||||
self.present(docPicker, animated: true)
|
||||
}
|
||||
|
||||
// MARK: - Table view data source
|
||||
|
||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||
@@ -92,3 +105,14 @@ class ArticleThemesTableViewController: UITableViewController {
|
||||
return UISwipeActionsConfiguration(actions: [deleteAction])
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: UIDocumentPickerDelegate
|
||||
|
||||
extension ArticleThemesTableViewController: UIDocumentPickerDelegate {
|
||||
|
||||
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
|
||||
guard let url = urls.first else { return }
|
||||
ArticleThemeImporter.importTheme(controller: self, filename: url.standardizedFileURL.path)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user