From af47437d806484ba944338a981965b31d1bd81a6 Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Mon, 18 Oct 2010 21:32:26 -0700 Subject: Fix ddms filechooser behavior and Mac accelerator Fix a couple of issues in ddms: First, fix the code to remember the path you last opened the file chooser with; if there is nothing in $lastImageSaveDir, it should look at $imageSaveDir (which is the variable the default setting ($user.home) is initialized into). Second, and this seems to be Mac specific, the FileDialog.getFilterPath() call does not return the path you have navigated to, which means that on the Mac it never sets $lastImageSaveDir correctly - it always sets it to the original suggestion. The fix is trivial - use File#getParent instead which does the String manipulation to extract the parent portion of a string which represents a path. Finally, on Macs (only), make the keybindings use the Command key instead of the Control key since that's the norm. Change-Id: I1b0f381606f5373ddad973754e49ce07856a9bae --- ddms/app/src/com/android/ddms/Main.java | 11 +++++++++-- ddms/app/src/com/android/ddms/UIThread.java | 9 +++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'ddms/app') diff --git a/ddms/app/src/com/android/ddms/Main.java b/ddms/app/src/com/android/ddms/Main.java index cd01fc9..0c55078 100644 --- a/ddms/app/src/com/android/ddms/Main.java +++ b/ddms/app/src/com/android/ddms/Main.java @@ -57,8 +57,7 @@ public class Main { */ public static void main(String[] args) { // In order to have the AWT/SWT bridge work on Leopard, we do this little hack. - String os = System.getProperty("os.name"); //$NON-NLS-1$ - if (os.startsWith("Mac OS")) { //$NON-NLS-1$ + if (isMac()) { RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean(); System.setProperty( "JAVA_STARTED_ON_FIRST_THREAD_" + (rt.getName().split("@"))[0], //$NON-NLS-1$ @@ -109,6 +108,14 @@ public class Main { System.exit(0); } + /** Return true iff we're running on a Mac */ + static boolean isMac() { + // TODO: Replace usages of this method with + // org.eclipse.jface.util.Util#isMac() when we switch to Eclipse 3.5 + // (ddms is currently built with SWT 3.4.2 from ANDROID_SWT) + return System.getProperty("os.name").startsWith("Mac OS"); //$NON-NLS-1$ //$NON-NLS-2$ + } + public static void ping(String ddmsParentLocation) { Properties p = new Properties(); try{ diff --git a/ddms/app/src/com/android/ddms/UIThread.java b/ddms/app/src/com/android/ddms/UIThread.java index d9ea3f1..4e2bb06 100644 --- a/ddms/app/src/com/android/ddms/UIThread.java +++ b/ddms/app/src/com/android/ddms/UIThread.java @@ -718,7 +718,7 @@ public class UIThread implements IUiSelectionListener, IClientChangeListener { item = new MenuItem(fileMenu, SWT.NONE); item.setText("E&xit\tCtrl-Q"); - item.setAccelerator('Q' | SWT.CONTROL); + item.setAccelerator('Q' | (Main.isMac() ? SWT.COMMAND : SWT.CONTROL)); item.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -780,8 +780,13 @@ public class UIThread implements IUiSelectionListener, IClientChangeListener { // create Device menu items final MenuItem screenShotItem = new MenuItem(deviceMenu, SWT.NONE); + + // The \tCtrl-S "keybinding text" here isn't right for the Mac - but + // it's stripped out and replaced by the proper keyboard accelerator + // text (e.g. the unicode symbol for the command key + S) anyway + // so it's fine to leave it there for the other platforms. screenShotItem.setText("&Screen capture...\tCtrl-S"); - screenShotItem.setAccelerator('S' | SWT.CONTROL); + screenShotItem.setAccelerator('S' | (Main.isMac() ? SWT.COMMAND : SWT.CONTROL)); screenShotItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { -- cgit v1.1