@@ -364,11 +364,46 @@ - (void)fatalErrorAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode
364364
365365- (void )initializeWebView
366366{
367- NSURLRequest *request = [NSURLRequest requestWithURL: self .notebookURL ];
367+ NSURLRequest *request = [NSURLRequest requestWithURL: [ self launchURL ] ];
368368 [[self .webView mainFrame ] loadRequest: request];
369369}
370370
371371
372+ - (NSURL *)launchURL
373+ {
374+ NSString *launchNotebookIdentifier = [self launchNotebookIdentifier ];
375+ if (!launchNotebookIdentifier) {
376+ return self.notebookURL ;
377+ }
378+
379+ NSURLComponents *components = [NSURLComponents componentsWithURL: self .notebookURL resolvingAgainstBaseURL: NO ];
380+ components.path = [NSString stringWithFormat: @" /%@ " , launchNotebookIdentifier];
381+
382+ return [components URL ];
383+ }
384+
385+
386+ - (NSString *)launchNotebookIdentifier
387+ {
388+ NSString *lastOpenNotebookName = [[NSUserDefaults standardUserDefaults ] stringForKey: @" CurrentNotebookName" ];
389+ if (!lastOpenNotebookName) {
390+ return nil ;
391+ }
392+
393+ [[NSUserDefaults standardUserDefaults ] removeObjectForKey: @" CurrentNotebookName" ];
394+
395+ __block NSString *notebookIdentifier = nil ;
396+ [[self notebookInfo ] enumerateKeysAndObjectsUsingBlock: ^(NSString *key, NSDictionary *notebookInfo, BOOL *stop) {
397+ if ([notebookInfo[@" name" ] isEqualToString: lastOpenNotebookName]) {
398+ *stop = YES ;
399+ notebookIdentifier = key;
400+ }
401+ }];
402+
403+ return notebookIdentifier;
404+ }
405+
406+
372407- (NSInteger )findAvailablePort
373408{
374409
@@ -521,6 +556,10 @@ - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem
521556
522557- (void )applicationWillTerminate : (NSNotification *)aNotification
523558{
559+ NSString *name = [self currentNotebookName ];
560+ if (name) {
561+ [[NSUserDefaults standardUserDefaults ] setObject: name forKey: @" CurrentNotebookName" ];
562+ }
524563 self.applicationState = ApplicationStateTerminating;
525564 if ([self .task isRunning ]) {
526565 [self .task terminate ];
@@ -846,7 +885,7 @@ - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
846885 if (![self currentPageIsNotebook ]) {
847886 return ;
848887 }
849-
888+
850889 // Disable some menu items that are undesirable in the context of an app or are redundant with the app's menus
851890 [self evaluateWebScript: @" $('#new_notebook').parent().children('li').filter(function () {return $.inArray(this.id, ['copy_notebook', 'rename_notebook', 'save_checkpoint']) == -1}).hide();" ];
852891}
0 commit comments