Revision: 22429
http://sourceforge.net/p/bibdesk/svn/22429
Author: hofman
Date: 2018-07-17 22:12:49 +0000 (Tue, 17 Jul 2018)
Log Message:
-----------
show alert as sheet when trying to close format sheet
Modified Paths:
--------------
trunk/bibdesk/BibPref_AutoFile.m
trunk/bibdesk/BibPref_CiteKey.m
Modified: trunk/bibdesk/BibPref_AutoFile.m
===================================================================
--- trunk/bibdesk/BibPref_AutoFile.m 2018-07-17 21:49:00 UTC (rev 22428)
+++ trunk/bibdesk/BibPref_AutoFile.m 2018-07-17 22:12:49 UTC (rev 22429)
@@ -375,50 +375,43 @@
[self didSelect];
}
-- (BOOL)canCloseFormatSheet{
- NSString *formatString = [formatSheetField stringValue];
- NSString *error = nil;
- NSString *otherButton = nil;
-
- if ([formatSheet makeFirstResponder:nil])
- return YES;
-
- error = [(BDSKFormatStringFormatter *)[formatSheetField formatter]
formatError];
- if (error == nil)
- return YES;
-
- formatString = [sud stringForKey:BDSKLocalFileFormatKey];
- if ([BDSKFormatParser validateFormat:&formatString
forField:BDSKLocalFileString error:NULL]) {
- // The currently set local-url format is valid, so we can keep
it
- otherButton = NSLocalizedString(@"Revert to Last", @"Button
title");
- }
-
- NSAlert *alert = [[[NSAlert alloc] init] autorelease];
- [alert setMessageText:NSLocalizedString(@"Invalid Local File Format",
@"Message in alert dialog when entering invalid Local File format")];
- [alert setInformativeText:error];
- [alert addButtonWithTitle:NSLocalizedString(@"Keep Editing", @"Button
title")];
- if (otherButton)
- [alert addButtonWithTitle:otherButton];
- [[alert addButtonWithTitle:NSLocalizedString(@"Revert to Default",
@"Button title")] setTag:NSAlertThirdButtonReturn];
- NSInteger rv = [alert runModal];
-
- if (rv == NSAlertFirstButtonReturn){
- return NO;
- } else if (rv == NSAlertThirdButtonReturn){
- formatString = [[sudc initialValues]
objectForKey:BDSKLocalFileFormatKey];
- [sud setObject:formatString forKey:BDSKLocalFileFormatKey];
- [[BDSKTypeManager sharedManager] setRequiredFieldsForLocalFile:
[BDSKFormatParser requiredFieldsForFormat:formatString]];
- }
+- (void)closeFormatSheetAlertDidEnd:(NSAlert *)alert
returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
+ if (returnCode == NSAlertFirstButtonReturn)
+ return;
+
+ if (returnCode == NSAlertThirdButtonReturn){
+ NSString *formatString = [[sudc initialValues]
objectForKey:BDSKLocalFileFormatKey];
+ [sud setObject:formatString forKey:BDSKLocalFileFormatKey];
+ [[BDSKTypeManager sharedManager] setRequiredFieldsForLocalFile:
[BDSKFormatParser requiredFieldsForFormat:formatString]];
+ }
+
// this will reset the formatSheetField string to the chosen default
[formatSheet endEditingFor:formatSheetField];
- [self updateFormatPreviewUI];
- return YES;
+ [self updateFormatPresetUI];
+
+ [formatSheet orderOut:nil];
+ [NSApp endSheet:formatSheet];
}
-- (IBAction)closeFormatSheet:(id)sender{
- if([self canCloseFormatSheet]){
- [formatSheet orderOut:sender];
+- (IBAction)closeFormatSheet:(id)sender {
+ if ([formatSheet makeFirstResponder:nil]) {
+
+ [formatSheet orderOut:nil];
[NSApp endSheet:formatSheet];
+
+ } else {
+
+ NSString *formatString = [sud stringForKey:BDSKLocalFileFormatKey];
+ BOOL currentIsValid = [BDSKFormatParser validateFormat:&formatString
forField:BDSKLocalFileString error:NULL];
+
+ NSAlert *alert = [[[NSAlert alloc] init] autorelease];
+ [alert setMessageText:NSLocalizedString(@"Invalid Local File Format",
@"Message in alert dialog when entering invalid Local File format")];
+ [alert setInformativeText:[(BDSKFormatStringFormatter
*)[formatSheetField formatter] formatError] ?: @""];
+ [alert addButtonWithTitle:NSLocalizedString(@"Keep Editing", @"Button
title")];
+ if (currentIsValid)
+ [alert addButtonWithTitle:NSLocalizedString(@"Revert to Last",
@"Button title")];
+ [[alert addButtonWithTitle:NSLocalizedString(@"Revert to Default",
@"Button title")] setTag:NSAlertThirdButtonReturn];
+ [alert beginSheetModalForWindow:formatSheet modalDelegate:self
didEndSelector:@selector(closeFormatSheetAlertDidEnd:returnCode:contextInfo:)
contextInfo:NULL];
}
}
Modified: trunk/bibdesk/BibPref_CiteKey.m
===================================================================
--- trunk/bibdesk/BibPref_CiteKey.m 2018-07-17 21:49:00 UTC (rev 22428)
+++ trunk/bibdesk/BibPref_CiteKey.m 2018-07-17 22:12:49 UTC (rev 22429)
@@ -283,50 +283,44 @@
[self didSelect];
}
-- (BOOL)canCloseFormatSheet{
- NSString *formatString = [formatSheetField stringValue];
- NSString *error = nil;
- NSString *otherButton = nil;
-
- if ([formatSheet makeFirstResponder:nil])
- return YES;
-
- error = [(BDSKFormatStringFormatter *)[formatSheetField formatter]
formatError];
-
- formatString = [sud stringForKey:BDSKCiteKeyFormatKey];
- if ([BDSKFormatParser validateFormat:&formatString
forField:BDSKCiteKeyString error:NULL]) {
- // The currently set cite-key format is valid, so we can keep
it
- otherButton = NSLocalizedString(@"Revert to Last", @"Button
title");
- }
-
- NSAlert *alert = [[[NSAlert alloc] init] autorelease];
- [alert setMessageText:NSLocalizedString(@"Invalid Cite Key Format",
@"Message in alert dialog when entering invalid cite key format")];
- [alert setInformativeText:error];
- [alert addButtonWithTitle:NSLocalizedString(@"Keep Editing", @"Button
title")];
- if (otherButton)
- [alert addButtonWithTitle:otherButton];
- [[alert addButtonWithTitle:NSLocalizedString(@"Revert to Default",
@"Button title")] setTag:NSAlertThirdButtonReturn];
- NSInteger rv = [alert runModal];
-
- if (rv == NSAlertFirstButtonReturn){
- //[formatSheet makeFirstResponder:formatSheetField];
- return NO;
- } else if (rv == NSAlertThirdButtonReturn){
- formatString = [[sudc initialValues]
objectForKey:BDSKCiteKeyFormatKey];
- [sud setObject:formatString forKey:BDSKCiteKeyFormatKey];
- [[BDSKTypeManager sharedManager] setRequiredFieldsForCiteKey:
[BDSKFormatParser requiredFieldsForFormat:formatString]];
- }
+- (void)closeFormatSheetAlertDidEnd:(NSAlert *)alert
returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
+ if (returnCode == NSAlertFirstButtonReturn)
+ return;
+
+ if (returnCode == NSAlertThirdButtonReturn){
+ NSString *formatString = [[sudc initialValues]
objectForKey:BDSKCiteKeyFormatKey];
+ [sud setObject:formatString forKey:BDSKCiteKeyFormatKey];
+ [[BDSKTypeManager sharedManager] setRequiredFieldsForCiteKey:
[BDSKFormatParser requiredFieldsForFormat:formatString]];
+ }
+
// this will reset the formatSheetField string to the chosen default
[formatSheet endEditingFor:formatSheetField];
- [self updateFormatPresetUI];
- return YES;
+ [self updateFormatPresetUI];
+
+ [formatSheet orderOut:nil];
+ [NSApp endSheet:formatSheet];
}
-- (IBAction)closeFormatSheet:(id)sender{
- if (![self canCloseFormatSheet])
- return;
- [formatSheet orderOut:sender];
- [NSApp endSheet:formatSheet];
+- (IBAction)closeFormatSheet:(id)sender {
+ if ([formatSheet makeFirstResponder:nil]) {
+
+ [formatSheet orderOut:nil];
+ [NSApp endSheet:formatSheet];
+
+ } else {
+
+ NSString *formatString = [sud stringForKey:BDSKCiteKeyFormatKey];
+ BOOL currentIsValid = [BDSKFormatParser validateFormat:&formatString
forField:BDSKCiteKeyString error:NULL];
+
+ NSAlert *alert = [[[NSAlert alloc] init] autorelease];
+ [alert setMessageText:NSLocalizedString(@"Invalid Cite Key Format",
@"Message in alert dialog when entering invalid cite key format")];
+ [alert setInformativeText:[(BDSKFormatStringFormatter
*)[formatSheetField formatter] formatError] ?: @""];
+ [alert addButtonWithTitle:NSLocalizedString(@"Keep Editing", @"Button
title")];
+ if (currentIsValid)
+ [alert addButtonWithTitle:NSLocalizedString(@"Revert to Last",
@"Button title")];
+ [[alert addButtonWithTitle:NSLocalizedString(@"Revert to Default",
@"Button title")] setTag:NSAlertThirdButtonReturn];
+ [alert beginSheetModalForWindow:formatSheet modalDelegate:self
didEndSelector:@selector(closeFormatSheetAlertDidEnd:returnCode:contextInfo:)
contextInfo:NULL];
+ }
}
#pragma mark Invalid format warning stuff
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit