Revision: 18432
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=18432&view=rev
Author: hofman
Date: 2012-01-19 15:20:31 +0000 (Thu, 19 Jan 2012)
Log Message:
-----------
Run initial sheet for text import in document class, if needed. Combine methods
to show text import sheet, determine data to load from a URL argument.
Modified Paths:
--------------
trunk/bibdesk/BDSKTextImportController.h
trunk/bibdesk/BDSKTextImportController.m
trunk/bibdesk/BibDocument_Actions.m
Modified: trunk/bibdesk/BDSKTextImportController.h
===================================================================
--- trunk/bibdesk/BDSKTextImportController.h 2012-01-19 14:53:14 UTC (rev
18431)
+++ trunk/bibdesk/BDSKTextImportController.h 2012-01-19 15:20:31 UTC (rev
18432)
@@ -100,9 +100,7 @@
- (id)initWithDocument:(BibDocument *)doc;
-- (void)beginSheetForPasteboardModalForWindow:(NSWindow *)docWindow;
-- (void)beginSheetForFileModalForWindow:(NSWindow *)docWindow;
-- (void)beginSheetForWebModalForWindow:(NSWindow *)docWindow;
+- (void)beginSheetModalForWindow:(NSWindow *)aWindow forURL:(NSURL *)aURL;
- (IBAction)addItemAction:(id)sender;
- (IBAction)closeAction:(id)sender;
Modified: trunk/bibdesk/BDSKTextImportController.m
===================================================================
--- trunk/bibdesk/BDSKTextImportController.m 2012-01-19 14:53:14 UTC (rev
18431)
+++ trunk/bibdesk/BDSKTextImportController.m 2012-01-19 15:20:31 UTC (rev
18432)
@@ -79,13 +79,12 @@
- (void)loadPasteboardData;
- (void)showWebViewWithURLString:(NSString *)urlString;
+- (void)loadFromFileURL:(NSURL *)url;
- (void)setShowingWebView:(BOOL)showWebView;
- (void)setupTypeUI;
- (void)setType:(NSString *)type;
-- (void)initialOpenPanelDidEnd:(NSOpenPanel *)sheet
returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)returnCode
contextInfo:(void *)contextInfo;
-- (void)initialUrlSheetDidEnd:(BDSKURLSheetController *)urlSheetController
returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
- (void)urlSheetDidEnd:(BDSKURLSheetController *)urlSheetController
returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
- (void)savePanelDidEnd:(NSSavePanel *)sheet returnCode:(NSInteger)returnCode
contextInfo:(void *)contextInfo;
- (void)autoDiscoverFromFrameAlertDidEnd:(NSAlert *)alert
returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
@@ -195,47 +194,23 @@
#pragma mark Calling the main sheet
-- (void)beginSheetForPasteboardModalForWindow:(NSWindow *)docWindow {
- // we start with the pasteboard data, so we can directly show the main
sheet
+- (void)beginSheetModalForWindow:(NSWindow *)aWindow forURL:(NSURL *)aURL {
// make sure we loaded the nib
[self window];
- [self loadPasteboardData];
-
- [super beginSheetModalForWindow:docWindow modalDelegate:nil
didEndSelector:NULL contextInfo:NULL];
-}
-
-- (void)beginSheetForWebModalForWindow:(NSWindow *)docWindow {
- // we start with a webview, so we first ask for the URL to load
-
- [self retain]; // make sure we stay around till we are done
-
- BDSKURLSheetController *urlSheetController = [[[BDSKURLSheetController
alloc] init] autorelease];
+ if (aURL == nil)
+ [self loadPasteboardData];
+ else if ([aURL isFileURL])
+ [self loadFromFileURL:aURL];
+ else
+ [self setShowingWebView:YES];
- // now show the URL sheet. We will show the main sheet when that is
done.
- [urlSheetController beginSheetModalForWindow:docWindow
- modalDelegate:self
-
didEndSelector:@selector(initialUrlSheetDidEnd:returnCode:contextInfo:)
- contextInfo:[docWindow retain]];
+ [self beginSheetModalForWindow:aWindow];
+
+ // not sure if this could be done safely before showing the sheet
+ if (aURL && [aURL isFileURL] == NO)
+ [webView setURL:aURL];
}
-
-- (void)beginSheetForFileModalForWindow:(NSWindow *)docWindow {
- // we start with a file, so we first ask for the file to load
-
- [self retain]; // make sure we stay around till we are done
-
- NSOpenPanel *oPanel = [NSOpenPanel openPanel];
- [oPanel setAllowsMultipleSelection:NO];
- [oPanel setCanChooseDirectories:NO];
- [oPanel beginSheetForDirectory:nil
- file:nil
- types:nil
- modalForWindow:docWindow
- modalDelegate:self
-
didEndSelector:@selector(initialOpenPanelDidEnd:returnCode:contextInfo:)
- contextInfo:[docWindow retain]];
-}
-
#pragma mark Actions
- (IBAction)addItemAction:(id)sender{
@@ -729,6 +704,25 @@
}
+- (void)loadFromFileURL:(NSURL *)url {
+ NSTextStorage *text = [sourceTextView textStorage];
+ NSLayoutManager *layoutManager = [[text layoutManagers] objectAtIndex:0];
+
+ [[text mutableString] setString:@""]; // Empty the document
+
+ [self setShowingWebView:NO];
+
+ [layoutManager retain]; // Temporarily remove layout
manager so it doesn't do any work while loading
+ [text removeLayoutManager:layoutManager];
+ [text beginEditing]; // Bracket with begin/end
editing for efficiency
+ [text readFromURL:url options:nil documentAttributes:NULL]; // Read!
+ [text endEditing];
+ [text addLayoutManager:layoutManager]; // Hook layout manager back up
+ [layoutManager release];
+
+ [self autoDiscoverDataFromString:[text string]];
+}
+
- (void)setShowingWebView:(BOOL)showWebView{
if (showWebView != showingWebView) {
showingWebView = showWebView;
@@ -772,76 +766,12 @@
}
#pragma mark Sheet callbacks
-
-- (void)initialOpenPanelDidEnd:(NSOpenPanel *)sheet
returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo{
- // this is the initial file load, the main window is not yet there
- NSWindow *docWindow = [(NSWindow *)contextInfo autorelease];
-
- if (returnCode == NSFileHandlingPanelOKButton) {
- NSString *fileName = [sheet filename];
- // first try to parse the file
- NSError *error = nil;
- NSArray *newPubs = [document extractPublicationsFromFiles:[NSArray
arrayWithObject:fileName] unparseableFiles:NULL verbose:NO error:&error];
- BOOL shouldEdit = [[NSUserDefaults standardUserDefaults]
boolForKey:BDSKEditOnPasteKey];
- if ([newPubs count]) {
- [document addPublications:newPubs publicationsToAutoFile:nil
temporaryCiteKey:[[error userInfo] valueForKey:@"temporaryCiteKey"]
selectLibrary:YES edit:shouldEdit];
- // succeeded to parse the file, we return immediately
- } else {
- [sheet orderOut:nil];
-
- // show the main window
- [super beginSheetModalForWindow:docWindow modalDelegate:nil
didEndSelector:NULL contextInfo:NULL];
-
- // then load the data from the file
- [self openPanelDidEnd:sheet returnCode:returnCode
contextInfo:NULL];
- }
- }
- [self autorelease];
-}
- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)returnCode
contextInfo:(void *)contextInfo{
- if(returnCode == NSFileHandlingPanelOKButton){
- NSURL *url = [[sheet URLs] lastObject];
- NSTextStorage *text = [sourceTextView textStorage];
- NSLayoutManager *layoutManager = [[text layoutManagers]
objectAtIndex:0];
-
- [[text mutableString] setString:@""]; // Empty the document
-
- [self setShowingWebView:NO];
-
- [layoutManager retain]; // Temporarily remove
layout manager so it doesn't do any work while loading
- [text removeLayoutManager:layoutManager];
- [text beginEditing]; // Bracket with
begin/end editing for efficiency
- [text readFromURL:url options:nil documentAttributes:NULL];
// Read!
- [text endEditing];
- [text addLayoutManager:layoutManager]; // Hook layout manager
back up
- [layoutManager release];
-
- [self autoDiscoverDataFromString:[text string]];
-
- }
+ if(returnCode == NSFileHandlingPanelOKButton)
+ [self loadFromFileURL:[[sheet URLs] lastObject]];
}
-- (void)initialUrlSheetDidEnd:(BDSKURLSheetController *)urlSheetController
returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo{
- // this is the initial web load, the main window is not yet there
- NSWindow *docWindow = [(NSWindow *)contextInfo autorelease];
-
- if (returnCode == NSOKButton) {
- [[urlSheetController window] orderOut:nil];
-
- [self window];
- [self setShowingWebView:YES];
-
- // show the main window
- [super beginSheetModalForWindow:docWindow modalDelegate:nil
didEndSelector:NULL contextInfo:NULL];
-
- // then load the data from the file
- [self urlSheetDidEnd:urlSheetController returnCode:returnCode
contextInfo:NULL];
-
- }
- [self autorelease];
-}
-
- (void)urlSheetDidEnd:(BDSKURLSheetController *)urlSheetController
returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo{
if(returnCode == NSOKButton){
// setup webview and load page
Modified: trunk/bibdesk/BibDocument_Actions.m
===================================================================
--- trunk/bibdesk/BibDocument_Actions.m 2012-01-19 14:53:14 UTC (rev 18431)
+++ trunk/bibdesk/BibDocument_Actions.m 2012-01-19 15:20:31 UTC (rev 18432)
@@ -1447,24 +1447,59 @@
return; // it worked, so we're done here
}
- BDSKTextImportController *tic = [(BDSKTextImportController
*)[BDSKTextImportController alloc] initWithDocument:self];
+ BDSKTextImportController *tic = [[(BDSKTextImportController
*)[BDSKTextImportController alloc] initWithDocument:self] autorelease];
+ [tic beginSheetModalForWindow:documentWindow forURL:nil];
+}
- [tic beginSheetForPasteboardModalForWindow:documentWindow];
- [tic release];
+- (void)importOpenPanelDidEnd:(NSOpenPanel *)sheet
returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo{
+ if (returnCode == NSFileHandlingPanelOKButton) {
+ NSString *fileName = [sheet filename];
+ // first try to parse the file
+ NSError *error = nil;
+ NSArray *newPubs = [self extractPublicationsFromFiles:[NSArray
arrayWithObject:fileName] unparseableFiles:NULL verbose:NO error:&error];
+ BOOL shouldEdit = [[NSUserDefaults standardUserDefaults]
boolForKey:BDSKEditOnPasteKey];
+ if ([newPubs count]) {
+ [self addPublications:newPubs publicationsToAutoFile:nil
temporaryCiteKey:[[error userInfo] valueForKey:@"temporaryCiteKey"]
selectLibrary:YES edit:shouldEdit];
+ // succeeded to parse the file, we return immediately
+ } else {
+ [sheet orderOut:nil];
+
+ BDSKTextImportController *tic = [[(BDSKTextImportController
*)[BDSKTextImportController alloc] initWithDocument:self] autorelease];
+ [tic beginSheetModalForWindow:documentWindow forURL:[NSURL
fileURLWithPath:fileName]];
+ }
+ }
}
- (IBAction)importFromFileAction:(id)sender{
- BDSKTextImportController *tic = [(BDSKTextImportController
*)[BDSKTextImportController alloc] initWithDocument:self];
+ NSOpenPanel *oPanel = [NSOpenPanel openPanel];
+ [oPanel setAllowsMultipleSelection:NO];
+ [oPanel setCanChooseDirectories:NO];
- [tic beginSheetForFileModalForWindow:documentWindow];
- [tic release];
+ [oPanel beginSheetForDirectory:nil
+ file:nil
+ types:nil
+ modalForWindow:documentWindow
+ modalDelegate:self
+
didEndSelector:@selector(importOpenPanelDidEnd:returnCode:contextInfo:)
+ contextInfo:NULL];
}
+- (void)importFromWebSheetDidEnd:(BDSKURLSheetController *)urlSheetController
returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo{
+ if (returnCode == NSOKButton) {
+ [[urlSheetController window] orderOut:nil];
+
+ BDSKTextImportController *tic = [[(BDSKTextImportController
*)[BDSKTextImportController alloc] initWithDocument:self] autorelease];
+ [tic beginSheetModalForWindow:documentWindow
forURL:[urlSheetController URL]];
+ }
+}
+
- (IBAction)importFromWebAction:(id)sender{
- BDSKTextImportController *tic = [(BDSKTextImportController
*)[BDSKTextImportController alloc] initWithDocument:self];
-
- [tic beginSheetForWebModalForWindow:documentWindow];
- [tic release];
+ BDSKURLSheetController *urlSheetController = [[[BDSKURLSheetController
alloc] init] autorelease];
+
+ [urlSheetController beginSheetModalForWindow:documentWindow
+ modalDelegate:self
+
didEndSelector:@selector(importFromWebSheetDidEnd:returnCode:contextInfo:)
+ contextInfo:NULL];
}
#pragma mark AutoFile stuff
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit