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