From 399ad9ad88c52369c38d553ea685b09e3c457d6f Mon Sep 17 00:00:00 2001 From: Pascal Muetschard Date: Thu, 26 Oct 2017 11:33:28 -0700 Subject: [PATCH] Handle the OpenDocument event in GAPIC. This event is sent on OSX if the user requests GAPID to open a gfxtrace file, for example via double-clicking on a gfxtrace file in the Finder. This event is sent if the application is already running, or if it just has been started in response to opening a file. --- gapic/src/main/com/google/gapid/MainWindow.java | 3 ++- gapic/src/main/com/google/gapid/util/MacApplication.java | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/gapic/src/main/com/google/gapid/MainWindow.java b/gapic/src/main/com/google/gapid/MainWindow.java index 32225b7c2b..195b15bff0 100644 --- a/gapic/src/main/com/google/gapid/MainWindow.java +++ b/gapic/src/main/com/google/gapid/MainWindow.java @@ -184,7 +184,8 @@ public void onCopyEnabled(boolean enabled) { if (OS.isMac) { MacApplication.init(shell.getDisplay(), () -> showAbout(shell, widgets().theme), - () -> showSettingsDialog(shell, models().settings)); + () -> showSettingsDialog(shell, models().settings), + file -> models().capture.loadCapture(new File(file))); } } diff --git a/gapic/src/main/com/google/gapid/util/MacApplication.java b/gapic/src/main/com/google/gapid/util/MacApplication.java index 13535416b6..c21333ecc7 100644 --- a/gapic/src/main/com/google/gapid/util/MacApplication.java +++ b/gapic/src/main/com/google/gapid/util/MacApplication.java @@ -20,6 +20,8 @@ import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; +import java.util.function.Consumer; + /** * Special handling for OSX application menus. */ @@ -30,7 +32,8 @@ private MacApplication() { /** * Initializes the OSX application menus. */ - public static void init(Display display, Runnable onAbout, Runnable onSettings) { + public static void init( + Display display, Runnable onAbout, Runnable onSettings, Consumer onOpen) { Menu menu = display.getSystemMenu(); if (menu == null) { return; @@ -46,5 +49,7 @@ public static void init(Display display, Runnable onAbout, Runnable onSettings) break; } } + + display.addListener(SWT.OpenDocument, e -> onOpen.accept(e.text)); } }