Add import button to Themes listing scene

This commit is contained in:
Maurice Parker 2021-09-18 10:49:30 -05:00
parent 42bcaf7e55
commit 04d7ab188f
2 changed files with 27 additions and 3 deletions

View File

@ -2797,14 +2797,14 @@
5183CCEB227117C70010922C /* Settings */ = {
isa = PBXGroup;
children = (
51A16990235E10D600EB091F /* Settings.storyboard */,
51A16995235E10D600EB091F /* AboutViewController.swift */,
51A16992235E10D600EB091F /* AddAccountViewController.swift */,
519ED47924482AEB007F8E94 /* EnableExtensionPointViewController.swift */,
519ED455244828C3007F8E94 /* AddExtensionPointViewController.swift */,
510FFAB226EEA22C00F32265 /* ArticleThemesTableViewController.swift */,
5137C2E926F63AE6009EFEDB /* ArticleThemeImporter.swift */,
510FFAB226EEA22C00F32265 /* ArticleThemesTableViewController.swift */,
516244E2241E19F000B61C47 /* ColorPaletteTableViewController.swift */,
519ED47924482AEB007F8E94 /* EnableExtensionPointViewController.swift */,
51A16990235E10D600EB091F /* Settings.storyboard */,
516A09382360A2AE00EAE89B /* SettingsComboTableViewCell.swift */,
516A091D23609A3600EAE89B /* SettingsComboTableViewCell.xib */,
516A093A2360A4A000EAE89B /* SettingsTableViewCell.xib */,

View File

@ -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)
}
}