Handle OPML file import without drag & drop
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#import "FeedDownload.h"
|
||||
#import "Preferences.h"
|
||||
#import "DrawImage.h"
|
||||
#import "SettingsFeeds+DragDrop.h"
|
||||
|
||||
@interface AppHook()
|
||||
@property (strong) NSWindowController *prefWindow;
|
||||
@@ -71,6 +72,19 @@
|
||||
// NSURLComponents *comp = [NSURLComponents componentsWithString:url];
|
||||
}
|
||||
|
||||
/// Handle opml file imports
|
||||
- (void)application:(NSApplication *)sender openFiles:(NSArray<NSString *> *)filenames {
|
||||
NSMutableArray<NSURL*> *urls = [NSMutableArray arrayWithCapacity:filenames.count];
|
||||
for (NSString *file in filenames) {
|
||||
NSURL *u = [NSURL fileURLWithPath:file];
|
||||
if (u) [urls addObject:u];
|
||||
}
|
||||
[self openPreferences];
|
||||
SettingsFeeds *sf = [(Preferences*)(self.prefWindow.window) selectFeedsTab];
|
||||
[sf importOpmlFiles:urls];
|
||||
[sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - App Preferences
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>9522</string>
|
||||
<string>9628</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||
<key>LSUIElement</key>
|
||||
|
||||
@@ -25,4 +25,5 @@
|
||||
|
||||
@interface SettingsFeeds (DragDrop) <NSOutlineViewDataSource, NSFilePromiseProviderDelegate, NSPasteboardTypeOwner, OpmlFileImportDelegate, OpmlFileExportDelegate>
|
||||
- (void)prepareOutlineViewForDragDrop:(NSOutlineView*)outline;
|
||||
- (void)importOpmlFiles:(NSArray<NSURL*>*)files;
|
||||
@end
|
||||
|
||||
@@ -99,7 +99,7 @@ const NSPasteboardType dragReorder = @"de.relikd.baRSS.drag-reorder";
|
||||
} else {
|
||||
// File import
|
||||
NSArray<NSURL*> *files = [info.draggingPasteboard readObjectsForClasses:@[NSURL.class] options:@{ NSPasteboardURLReadingContentsConformToTypesKey: @[UTI_OPML] }];
|
||||
[[OpmlFileImport withDelegate:self] importFiles:files];
|
||||
[self importOpmlFiles:files];
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
@@ -108,6 +108,11 @@ const NSPasteboardType dragReorder = @"de.relikd.baRSS.drag-reorder";
|
||||
#pragma mark - OPML File Import
|
||||
|
||||
|
||||
/// Helper method is also called from Application Delegate
|
||||
- (void)importOpmlFiles:(NSArray<NSURL*>*)files {
|
||||
[[OpmlFileImport withDelegate:self] importFiles:files];
|
||||
}
|
||||
|
||||
/// Filter out file urls that are not opml files
|
||||
- (void)outlineView:(NSOutlineView *)outlineView updateDraggingItemsForDrag:(id <NSDraggingInfo>)info {
|
||||
if ([info.draggingPasteboard canReadItemWithDataConformingToTypes:@[(NSPasteboardType)kUTTypeFileURL]]) {
|
||||
@@ -134,7 +139,7 @@ const NSPasteboardType dragReorder = @"de.relikd.baRSS.drag-reorder";
|
||||
|
||||
/// OPML import (did end). Save changes, select newly inserted, and perform web request.
|
||||
- (void)opmlFileImportDidEnd:(NSManagedObjectContext*)moc {
|
||||
if (!moc.hasChanges) { // exit early, dont need to create empty arrays
|
||||
if (moc.undoManager.groupingLevel == 1 && !moc.hasChanges) { // exit early, dont need to create empty arrays
|
||||
[self endCoreDataChangeUndoEmpty:YES forceUndo:YES];
|
||||
return;
|
||||
}
|
||||
@@ -153,7 +158,8 @@ const NSPasteboardType dragReorder = @"de.relikd.baRSS.drag-reorder";
|
||||
}
|
||||
// Persist state, because on crash we have at least inserted items (without articles & icons)
|
||||
[StoreCoordinator saveContext:moc andParent:YES];
|
||||
[self.dataStore setSelectionIndexPaths:selection];
|
||||
if (selection.count > 0)
|
||||
[self.dataStore setSelectionIndexPaths:selection];
|
||||
[FeedDownload batchDownloadFeeds:feedsList favicons:YES showErrorAlert:YES finally:^{
|
||||
[self endCoreDataChangeUndoEmpty:NO forceUndo:NO];
|
||||
[self someDatesChangedScheduleUpdateTimer];
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class SettingsFeeds;
|
||||
|
||||
@interface Preferences : NSWindow <NSWindowDelegate>
|
||||
+ (instancetype)window;
|
||||
- (SettingsFeeds*)selectFeedsTab;
|
||||
@end
|
||||
|
||||
@@ -49,9 +49,7 @@
|
||||
TabItem(NSImageNameInfo, NSLocalizedString(@"About", nil), [SettingsAbout class]),
|
||||
];
|
||||
|
||||
NSInteger index = [[NSUserDefaults standardUserDefaults] integerForKey:@"preferencesTab"];
|
||||
if (index > 0 || (NSUInteger)index < self.tabViewItems.count)
|
||||
self.selectedTabViewItemIndex = index;
|
||||
[self switchToTab:[[NSUserDefaults standardUserDefaults] integerForKey:@"preferencesTab"]];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -64,6 +62,12 @@ NS_INLINE NSTabViewItem* TabItem(NSImageName imageName, NSString *text, Class cl
|
||||
return item;
|
||||
}
|
||||
|
||||
/// Safely set selected index without out of bounds exception
|
||||
- (void)switchToTab:(NSInteger)index {
|
||||
if (index > 0 || (NSUInteger)index < self.tabViewItems.count)
|
||||
self.selectedTabViewItemIndex = index;
|
||||
}
|
||||
|
||||
/// Delegate method, store last selected tab to user preferences
|
||||
- (void)tabView:(NSTabView*)tabView didSelectTabViewItem:(nullable NSTabViewItem*)tabViewItem {
|
||||
[super tabView:tabView didSelectTabViewItem:tabViewItem];
|
||||
@@ -96,6 +100,12 @@ NS_INLINE NSTabViewItem* TabItem(NSImageName imageName, NSString *text, Class cl
|
||||
return w;
|
||||
}
|
||||
|
||||
- (SettingsFeeds*)selectFeedsTab {
|
||||
PrefTabs *pref = (PrefTabs*)self.contentViewController;
|
||||
[pref switchToTab:1];
|
||||
return (SettingsFeeds*)[pref.tabViewItems[1] viewController];
|
||||
}
|
||||
|
||||
- (void)windowWillClose:(NSNotification *)notification {
|
||||
[[NSUserDefaults standardUserDefaults] setObject:self.stringWithSavedFrame forKey:@"prefWindow"];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user