Skip to content

Commit

Permalink
Merge pull request #819 from Sequel-Ace/bookmarks-again
Browse files Browse the repository at this point in the history
#fixed Bookmarks not being generated correctly
  • Loading branch information
Jason-Morcos committed Jan 23, 2021
2 parents 8c95998 + 07df74c commit 3083682
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 57 deletions.
2 changes: 2 additions & 0 deletions Interfaces/MainMenu.xib
Expand Up @@ -1019,6 +1019,8 @@ CQ
<customObject id="213" userLabel="SPAppController" customClass="SPAppController">
<connections>
<outlet property="staleBookmarkHelpView" destination="Ipz-ua-fp5" id="psg-8l-YU5"/>
<outlet property="staleBookmarkTextField" destination="Bea-mS-nZN" id="m3E-QZ-KCA"/>
<outlet property="staleBookmarkTextFieldCell" destination="jQo-Yb-Hvj" id="8Ts-TE-F5t"/>
</connections>
</customObject>
<menu id="956" userLabel="Dock Menu">
Expand Down
9 changes: 9 additions & 0 deletions Resources/Localization/en.lproj/Localizable.strings
Expand Up @@ -3177,6 +3177,15 @@
/* Stale Bookmarks error title */
"Stale Bookmarks" = "Stale Bookmarks";

/* App Sandbox info link text */
"App Sandbox Info" = "App Sandbox Info";

/* error while selecting file title */
"File Selection Error" = "File Selection Error";

/* error while selecting file message */
"The selected file is not a valid file.\n\nPlease try again.\n\nClass: %@" = "The selected file is not a valid file.\n\nPlease try again.\n\nClass: %@";

/* Question to user to see if they would like to re-request access */
"You have stale secure bookmarks:\n\n%@\n\nWould you like to re-request access now?" = "You have stale secure bookmarks:\n\n%@\n\nWould you like to re-request access now?";

Expand Down
35 changes: 25 additions & 10 deletions Source/Controllers/DataExport/SPExportController.m
Expand Up @@ -36,6 +36,9 @@
#import "SPExportFileNameTokenObject.h"
#import "SPDatabaseDocument.h"
#import "SPThreadAdditions.h"
#import "SPPreferenceController.h"
#import "SPGeneralPreferencePane.h"
#import "SPAppController.h"
#import "SPCustomQuery.h"
#import "SPCSVExporter.h"
#import "SPSQLExporter.h"
Expand Down Expand Up @@ -644,21 +647,33 @@ - (IBAction)changeExportOutputPath:(id)sender

[self->exportPathField setStringValue:path];

NSMutableString *classStr = [NSMutableString string];
[classStr appendStringOrNil:NSStringFromClass(self->changeExportOutputPathPanel.URL.class)];

SPLog(@"self->changeExportOutputPathPanel.URL.class: %@", classStr);

// check it's really a URL
if(![self->changeExportOutputPathPanel.URL isKindOfClass:[NSURL class]]){
NSMutableString *classStr = [NSMutableString string];
[classStr appendStringOrNil:NSStringFromClass(self->changeExportOutputPathPanel.URL.class)];

SPLog(@"self->keySelectionPanel.URL is not a URL: %@", classStr);
CLS_LOG(@"self->keySelectionPanel.URL is not a URL: %@", classStr);
// JCS - should we stop here?
SPLog(@"self->changeExportOutputPathPanel.URL is not a valid URL: %@", classStr);
CLS_LOG(@"self->changeExportOutputPathPanel.URL is not a valid URL: %@", classStr);

NSView *helpView = [[[SPAppDelegate preferenceController] generalPreferencePane] modifyAndReturnBookmarkHelpView];

NSString *alertMessage = [NSString stringWithFormat:NSLocalizedString(@"The selected file is not a valid file.\n\nPlease try again.\n\nClass: %@", @"error while selecting file message"),
classStr];

[NSAlert createAccessoryWarningAlertWithTitle:NSLocalizedString(@"File Selection Error", @"error while selecting file message") message:alertMessage accessoryView:helpView callback:^{

NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"self->changeExportOutputPathPanel.URL is not a URL",
@"class": classStr
};
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"self->changeExportOutputPathPanel.URL is not a valid URL",
@"func": [NSString stringWithFormat:@"%s", __PRETTY_FUNCTION__],
@"class": classStr
};

[FIRCrashlytics.crashlytics recordError:[NSError errorWithDomain:@"chooseFile" code:1 userInfo:userInfo]];
SPLog(@"userInfo: %@", userInfo);
[FIRCrashlytics.crashlytics recordError:[NSError errorWithDomain:@"chooseFileExportController" code:1 userInfo:userInfo]];
}];
}
else{
// this needs to be read-write
Expand Down
Expand Up @@ -467,22 +467,34 @@ - (IBAction)chooseKeyLocation:(NSButton *)sender
NSString *selectedFilePath=[[self->keySelectionPanel URL] path];
NSError *err=nil;

NSMutableString *classStr = [NSMutableString string];
[classStr appendStringOrNil:NSStringFromClass(self->keySelectionPanel.URL.class)];

SPLog(@"self->keySelectionPanel.URL.class: %@", classStr);

// check it's really a URL
if(![self->keySelectionPanel.URL isKindOfClass:[NSURL class]]){
NSMutableString *classStr = [NSMutableString string];
[classStr appendStringOrNil:NSStringFromClass(self->keySelectionPanel.URL.class)];

SPLog(@"self->keySelectionPanel.URL is not a URL: %@", classStr);
CLS_LOG(@"self->keySelectionPanel.URL is not a URL: %@", classStr);
// JCS - should we stop here?
SPLog(@"self->keySelectionPanel.URL is not a valid URL: %@", classStr);
CLS_LOG(@"self->keySelectionPanel.URL is not a valid URL: %@", classStr);

NSView *helpView = [[[SPAppDelegate preferenceController] generalPreferencePane] modifyAndReturnBookmarkHelpView];

NSString *alertMessage = [NSString stringWithFormat:NSLocalizedString(@"The selected file is not a valid file.\n\nPlease try again.\n\nClass: %@", @"error while selecting file message"),
classStr];

[NSAlert createAccessoryWarningAlertWithTitle:NSLocalizedString(@"File Selection Error", @"error while selecting file message") message:alertMessage accessoryView:helpView callback:^{

NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"self->keySelectionPanel.URL is not a URL",
@"class": classStr
};
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"self->keySelectionPanel.URL is not a valid URL",
@"func": [NSString stringWithFormat:@"%s", __PRETTY_FUNCTION__],
@"class": classStr
};

[FIRCrashlytics.crashlytics recordError:[NSError errorWithDomain:@"chooseFile" code:1 userInfo:userInfo]];
SPLog(@"userInfo: %@", userInfo);

[FIRCrashlytics.crashlytics recordError:[NSError errorWithDomain:@"chooseFileConnectionController" code:1 userInfo:userInfo]];
}];
}
else{
SPLog(@"calling addBookmarkForUrl");
Expand Down
68 changes: 48 additions & 20 deletions Source/Controllers/Preferences/Panes/SPFilePreferencePane.m
Expand Up @@ -29,6 +29,7 @@
// More info at <https://github.com/sequelpro/sequelpro>

#import "SPFilePreferencePane.h"
#import "SPAppController.h"
#import "sequel-ace-Swift.h"

@import Firebase;
Expand All @@ -41,12 +42,13 @@ - (void)_refreshBookmarks;
@property (readwrite, strong) NSMutableIndexSet *selectedRows;
@property (readwrite, assign) BOOL weHaveStaleBookmarks;
@property (readwrite, assign) BOOL userClickedCancel;
@property (readwrite, assign) BOOL userClickedAddFilesAfterCancel;

@end

@implementation SPFilePreferencePane

@synthesize bookmarks, staleBookmarks, staleLabel, weHaveStaleBookmarks, selectedRows, userClickedCancel;
@synthesize bookmarks, staleBookmarks, staleLabel, weHaveStaleBookmarks, selectedRows, userClickedCancel, userClickedAddFilesAfterCancel;

- (instancetype)init
{
Expand All @@ -59,6 +61,7 @@ - (instancetype)init
selectedRows = [NSMutableIndexSet indexSet];
weHaveStaleBookmarks = NO;
userClickedCancel = NO;
userClickedAddFilesAfterCancel = NO;

[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_refreshBookmarks) name:SPBookmarksChangedNotification object:SecureBookmarkManager.sharedInstance];
}
Expand All @@ -82,14 +85,14 @@ - (IBAction)doubleClick:(id)sender {

// what if the user clicks cancel, then double clicks just one file?
// or different files?
if (userClickedCancel == YES && (fileView.clickedColumn >= 0 && fileView.clickedRow >= 0)) {
if ((userClickedCancel == YES && (fileView.clickedColumn >= 0 && fileView.clickedRow >= 0)) || userClickedAddFilesAfterCancel == YES) {
SPLog(@"userClickedCancel == YES, set selected rows to [fileView selectedRowIndexes]");
CLS_LOG(@"userClickedCancel == YES, set selected rows to [fileView selectedRowIndexes]");
[selectedRows removeAllIndexes];
[selectedRows addIndexes:[fileView selectedRowIndexes]];
}

if((weHaveStaleBookmarks == YES && userClickedCancel == NO) || ((fileView.clickedColumn >= 0 && fileView.clickedRow >= 0) && userClickedCancel == YES )){
if((weHaveStaleBookmarks == YES && userClickedCancel == NO) || ((fileView.clickedColumn >= 0 && fileView.clickedRow >= 0) && userClickedCancel == YES ) || (weHaveStaleBookmarks == YES && userClickedAddFilesAfterCancel == YES)){

SPLog(@"IN, setting panel options");

Expand Down Expand Up @@ -379,12 +382,19 @@ - (IBAction)revokeBookmark:(id)sender
- (IBAction)addBookmark:(id)sender
{

if(weHaveStaleBookmarks == YES && userClickedCancel == YES){
SPLog(@"weHaveStaleBookmarks == YES, calling doubleClick");
CLS_LOG(@"weHaveStaleBookmarks == YES, calling doubleClick");
userClickedAddFilesAfterCancel = YES;
[self doubleClick:nil];
return;
}

PanelOptions *options = [[PanelOptions alloc] init];

options.allowsMultipleSelection = YES;
options.canChooseFiles = YES;
options.canChooseDirectories = YES;
options.isForStaleBookmark = YES;
options.isForStaleBookmark = NO;
options.title = NSLocalizedString(@"Please choose a file or folder to grant Sequel Ace access to.", "Please choose a file or folder to grant Sequel Ace access to.");
options.fileNames = nil;
Expand Down Expand Up @@ -473,32 +483,50 @@ - (void)chooseFileWithOptions:(PanelOptions*)options
return;
}


[self->_currentFilePanel orderOut:nil];

// since ssh configs are able to consist of multiple files, bookmarks
// for every selected file should be created in order to access them
// read-only.
SPLog(@"self->_currentFilePanel.URLs: %@", self->_currentFilePanel.URLs);

[self->_currentFilePanel.URLs enumerateObjectsUsingBlock:^(NSURL *url, NSUInteger idxURL, BOOL *stopURL){

NSMutableString *classStr = [NSMutableString string];
[classStr appendStringOrNil:NSStringFromClass(url.class)];

SPLog(@"Block URL class: %@", classStr);
SPLog(@"Block URL str: %@", url.absoluteString);
SPLog(@"Block URL add: %p", &url);

// check it's really a URL
if(![self->_currentFilePanel.URL isKindOfClass:[NSURL class]]){
NSMutableString *classStr = [NSMutableString string];
[classStr appendStringOrNil:NSStringFromClass(self->_currentFilePanel.URL.class)];
if(![url isKindOfClass:[NSURL class]]){
SPLog(@"selected file is not a valid URL: %@", classStr);
CLS_LOG(@"selected file is not a valid URL: %@", classStr);

NSView *helpView = [self modifyAndReturnBookmarkHelpView];

NSString *alertMessage = [NSString stringWithFormat:NSLocalizedString(@"The selected file is not a valid file.\n\nPlease try again.\n\nClass: %@", @"error while selecting file message"),
classStr];

SPLog(@"self->keySelectionPanel.URL is not a URL: %@", classStr);
CLS_LOG(@"self->keySelectionPanel.URL is not a URL: %@", classStr);
// JCS - should we stop here?
[NSAlert createAccessoryWarningAlertWithTitle:NSLocalizedString(@"File Selection Error", @"error while selecting file message") message:alertMessage accessoryView:helpView callback:^{

NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"self->keySelectionPanel.URL is not a URL",
@"class": classStr,
@"URLs" : self->_currentFilePanel.URLs
};
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"selected file is not a valid URL",
@"class": classStr,
@"func": [NSString stringWithFormat:@"%s", __PRETTY_FUNCTION__],
@"URLs" : (self->_currentFilePanel.URLs) ?: @""
};

[FIRCrashlytics.crashlytics recordError:[NSError errorWithDomain:@"chooseFile" code:1 userInfo:userInfo]];
SPLog(@"userInfo: %@", userInfo);
[FIRCrashlytics.crashlytics recordError:[NSError errorWithDomain:@"chooseFileFilePrefs" code:1 userInfo:userInfo]];
}];
}
else{
if([SecureBookmarkManager.sharedInstance addBookmarkForUrl:self->_currentFilePanel.URL options:(NSURLBookmarkCreationWithSecurityScope|NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess) isForStaleBookmark:options.isForStaleBookmark] == YES){
// use url from the block, not self->_currentFilePanel.URL
// From Apple docs: The NSOpenPanel subclass sets this property to nil
// when the selection contains multiple items.
if([SecureBookmarkManager.sharedInstance addBookmarkForUrl:url options:(NSURLBookmarkCreationWithSecurityScope|NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess) isForStaleBookmark:options.isForStaleBookmark] == YES){
SPLog(@"addBookmarkForUrl success");
CLS_LOG(@"addBookmarkForUrl success");

Expand Down Expand Up @@ -527,8 +555,8 @@ - (void)chooseFileWithOptions:(PanelOptions*)options
}
}
else{
CLS_LOG(@"addBookmarkForUrl failed: %@", self->_currentFilePanel.URL.absoluteString);
SPLog(@"addBookmarkForUrl failed: %@", self->_currentFilePanel.URL.absoluteString);
CLS_LOG(@"addBookmarkForUrl failed: %@", url.absoluteString);
SPLog(@"addBookmarkForUrl failed: %@", url.absoluteString);
}
}
}];
Expand Down
48 changes: 33 additions & 15 deletions Source/Controllers/Preferences/Panes/SPNetworkPreferencePane.m
Expand Up @@ -303,31 +303,49 @@ - (void)chooseSSHConfig
[self->_currentFilePanel.URLs enumerateObjectsUsingBlock:^(NSURL *url, NSUInteger idxURL, BOOL *stopURL){
// check if the file is out of the sandbox

NSMutableString *classStr = [NSMutableString string];
[classStr appendStringOrNil:NSStringFromClass(url.class)];

SPLog(@"Block URL class: %@", classStr);
SPLog(@"Block URL str: %@", url.absoluteString);
SPLog(@"Block URL add: %p", &url);
SPLog(@"_currentFilePanel.URL add: %p", self->_currentFilePanel.URL);

// check it's really a URL
if(![self->_currentFilePanel.URL isKindOfClass:[NSURL class]]){
NSMutableString *classStr = [NSMutableString string];
[classStr appendStringOrNil:NSStringFromClass(self->_currentFilePanel.URL.class)];
if(![url isKindOfClass:[NSURL class]]){
SPLog(@"selected file is not a valid URL: %@", classStr);
CLS_LOG(@"selected file is not a valid URL: %@", classStr);

SPLog(@"self->keySelectionPanel.URL is not a URL: %@", classStr);
CLS_LOG(@"self->keySelectionPanel.URL is not a URL: %@", classStr);
// JCS - should we stop here?
NSView *helpView = [self modifyAndReturnBookmarkHelpView];

NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"self->keySelectionPanel.URL is not a URL",
@"class": classStr,
@"URLs" : self->_currentFilePanel.URLs
};
NSString *alertMessage = [NSString stringWithFormat:NSLocalizedString(@"The selected file is not a valid file.\n\nPlease try again.\n\nClass: %@", @"error while selecting file message"),
classStr];

[FIRCrashlytics.crashlytics recordError:[NSError errorWithDomain:@"chooseFile" code:1 userInfo:userInfo]];
[NSAlert createAccessoryWarningAlertWithTitle:NSLocalizedString(@"File Selection Error", @"error while selecting file message") message:alertMessage accessoryView:helpView callback:^{

NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"selected file is not a valid URL",
@"class": classStr,
@"func": [NSString stringWithFormat:@"%s", __PRETTY_FUNCTION__],
@"URLs" : (self->_currentFilePanel.URLs) ?: @""
};

SPLog(@"userInfo: %@", userInfo);

[FIRCrashlytics.crashlytics recordError:[NSError errorWithDomain:@"chooseFileNetworkPrefs" code:1 userInfo:userInfo]];
}];
}
else{
if([SecureBookmarkManager.sharedInstance addBookmarkForUrl:self->_currentFilePanel.URL options:(NSURLBookmarkCreationWithSecurityScope|NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess) isForStaleBookmark:NO] == YES){
// use url from the block, not self->_currentFilePanel.URL
// From Apple docs: The NSOpenPanel subclass sets this property to nil
// when the selection contains multiple items.
if([SecureBookmarkManager.sharedInstance addBookmarkForUrl:url options:(NSURLBookmarkCreationWithSecurityScope|NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess) isForStaleBookmark:NO] == YES){
SPLog(@"addBookmarkForUrl success");
CLS_LOG(@"addBookmarkForUrl success");
}
else{
CLS_LOG(@"addBookmarkForUrl failed: %@", self->_currentFilePanel.URL.absoluteString);
SPLog(@"addBookmarkForUrl failed: %@", self->_currentFilePanel.URL.absoluteString);
CLS_LOG(@"addBookmarkForUrl failed: %@", url.absoluteString);
SPLog(@"addBookmarkForUrl failed: %@", url.absoluteString);
}
}

Expand Down
2 changes: 2 additions & 0 deletions Source/Controllers/Preferences/Panes/SPPreferencePane.h
Expand Up @@ -43,4 +43,6 @@
NSUserDefaults *prefs;
}
- (void)preferencePaneWillBeShown;
- (NSView *)modifyAndReturnBookmarkHelpView;

@end
18 changes: 18 additions & 0 deletions Source/Controllers/Preferences/Panes/SPPreferencePane.m
Expand Up @@ -29,6 +29,8 @@
// More info at <https://github.com/sequelpro/sequelpro>

#import "SPPreferencePane.h"
#import "SPAppController.h"
#import "sequel-ace-Swift.h"

@implementation SPPreferencePane

Expand All @@ -52,4 +54,20 @@ - (void)preferencePaneWillBeShown
// Default: do nothing. Override in subclass.
}

- (NSView *)modifyAndReturnBookmarkHelpView{

SPAppController *appCon = SPAppDelegate;

NSView *helpView = [appCon staleBookmarkHelpView];
HyperlinkTextField *helpViewTF = [appCon staleBookmarkTextField];
NSTextFieldCell *helpViewTFC = [appCon staleBookmarkTextFieldCell];

helpViewTF.href = SPDocsAppSandbox;

helpViewTFC.title = NSLocalizedString(@"App Sandbox Info", @"App Sandbox Info");

[helpViewTF reapplyAttributes];

return helpView;
}
@end
3 changes: 3 additions & 0 deletions Source/Controllers/SPAppController.h
Expand Up @@ -34,6 +34,7 @@
@class SPDatabaseDocument;
@class SPBundleEditorController;
@class SPWindowController;
@class HyperlinkTextField;

@import Firebase;

Expand All @@ -55,6 +56,8 @@
@property (readwrite, copy) NSString *lastBundleBlobFilesDirectory;

@property (weak) IBOutlet NSView *staleBookmarkHelpView;
@property (weak) IBOutlet HyperlinkTextField *staleBookmarkTextField;
@property (weak) IBOutlet NSTextFieldCell *staleBookmarkTextFieldCell;

// IBAction methods
- (IBAction)openAboutPanel:(id)sender;
Expand Down

0 comments on commit 3083682

Please sign in to comment.