[WebEditingTester] Implement an open panel
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Feb 2015 19:59:35 +0000 (19:59 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Feb 2015 19:59:35 +0000 (19:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141829

Reviewed by Simon Fraser.

* WebEditingTester/AppDelegate.m:
(-[WebEditingAppDelegate _useWebKit1ForOpeningDocument:]):
(-[WebEditingAppDelegate _useWebKit2ForOpeningDocument:]):
(-[WebEditingAppDelegate openDocument:]):
Add an open panel (with radio buttons to pick which WebKit to open with).
Loads the file as an HTML string.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180438 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/WebEditingTester/AppDelegate.m

index dda2dac..546fd43 100644 (file)
@@ -1,3 +1,17 @@
+2015-02-20  Timothy Horton  <timothy_horton@apple.com>
+
+        [WebEditingTester] Implement an open panel
+        https://bugs.webkit.org/show_bug.cgi?id=141829
+
+        Reviewed by Simon Fraser.
+
+        * WebEditingTester/AppDelegate.m:
+        (-[WebEditingAppDelegate _useWebKit1ForOpeningDocument:]):
+        (-[WebEditingAppDelegate _useWebKit2ForOpeningDocument:]):
+        (-[WebEditingAppDelegate openDocument:]):
+        Add an open panel (with radio buttons to pick which WebKit to open with).
+        Loads the file as an HTML string.
+
 2015-02-20  Simon Fraser  <simon.fraser@apple.com>
 
         [WebEditingTester] @properties, dot syntax, and remember the window position
index 41e216c..bc75bcf 100644 (file)
 
 static NSString * const UseWebKit2ByDefaultPreferenceKey = @"UseWebKit2ByDefault";
 
-@implementation WebEditingAppDelegate
+@implementation WebEditingAppDelegate {
+    Class _openingDocumentController;
+}
+
 - (id)init
 {
     self = [super init];
@@ -139,6 +142,49 @@ static NSString * const UseWebKit2ByDefaultPreferenceKey = @"UseWebKit2ByDefault
     return YES;
 }
 
+- (void)_openDocumentWithWebKit1:(id)sender
+{
+    _openingDocumentController = [WK1WebDocumentController class];
+}
+
+- (void)_openDocumentWithWebKit2:(id)sender
+{
+    _openingDocumentController = [WK2WebDocumentController class];
+}
+
+- (IBAction)openDocument:(id)sender
+{
+    _openingDocumentController = self._defaultWebDocumentControllerClass;
+
+    NSButtonCell *radioButtonPrototype = [[NSButtonCell alloc] init];
+    radioButtonPrototype.buttonType = NSRadioButton;
+
+    NSMatrix *openPanelAccessoryView = [[NSMatrix alloc] initWithFrame:NSZeroRect mode:NSRadioModeMatrix prototype:radioButtonPrototype numberOfRows:2 numberOfColumns:1];
+    openPanelAccessoryView.autorecalculatesCellSize = YES;
+    openPanelAccessoryView.autosizesCells = YES;
+    NSArray *cells = openPanelAccessoryView.cells;
+    [[cells objectAtIndex:0] setTitle:@"Open with WebKit1"];
+    [[cells objectAtIndex:0] setAction:@selector(_openDocumentWithWebKit1:)];
+    [[cells objectAtIndex:0] setState:!self.useWebKit2ByDefault];
+    [[cells objectAtIndex:1] setTitle:@"Open with WebKit2"];
+    [[cells objectAtIndex:1] setAction:@selector(_openDocumentWithWebKit2:)];
+    [[cells objectAtIndex:1] setState:self.useWebKit2ByDefault];
+    [openPanelAccessoryView sizeToFit];
+
+    NSOpenPanel *panel = [NSOpenPanel openPanel];
+    [panel setAccessoryView:openPanelAccessoryView];
+
+    [panel beginWithCompletionHandler:^(NSInteger result) {
+        if (result != NSFileHandlingPanelOKButton)
+            return;
+
+        WebDocumentController *controller = [[_openingDocumentController alloc] init];
+        [controller.window makeKeyAndOrderFront:nil];
+        [_webDocuments addObject:controller];
+        [controller loadHTMLString:[NSString stringWithContentsOfURL:panel.URLs.lastObject encoding:NSUTF8StringEncoding error:nil]];
+    }];
+}
+
 - (void)_updateNewWindowKeyEquivalents
 {
     if (self.useWebKit2ByDefault) {