diff options
author | Siva Velusamy <vsiva@google.com> | 2011-08-18 15:12:38 -0700 |
---|---|---|
committer | Siva Velusamy <vsiva@google.com> | 2011-08-18 15:54:20 -0700 |
commit | 4f7dbc53dbf6879365e54ffd1f8d13de69fec3ac (patch) | |
tree | 144b83cb4ba4ec844caea738d9b5f737d0d50755 /ddms | |
parent | 0f72f32f6058d3ed11639c4353f37b67424333ed (diff) | |
download | sdk-4f7dbc53dbf6879365e54ffd1f8d13de69fec3ac.zip sdk-4f7dbc53dbf6879365e54ffd1f8d13de69fec3ac.tar.gz sdk-4f7dbc53dbf6879365e54ffd1f8d13de69fec3ac.tar.bz2 |
Add support for Select All and Copy to Clipboard actions.
Change-Id: Idbf3bc093f2a049b5e0e0cd9605a6f8bdc8f7723
Diffstat (limited to 'ddms')
-rw-r--r-- | ddms/app/src/com/android/ddms/UIThread.java | 12 | ||||
-rw-r--r-- | ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java | 59 |
2 files changed, 66 insertions, 5 deletions
diff --git a/ddms/app/src/com/android/ddms/UIThread.java b/ddms/app/src/com/android/ddms/UIThread.java index ecc3b3f..dfe1b9a 100644 --- a/ddms/app/src/com/android/ddms/UIThread.java +++ b/ddms/app/src/com/android/ddms/UIThread.java @@ -733,7 +733,7 @@ public class UIThread implements IUiSelectionListener, IClientChangeListener { item = new MenuItem(fileMenu, SWT.NONE); item.setText("E&xit\tCtrl-Q"); - item.setAccelerator('Q' | (Main.isMac() ? SWT.COMMAND : SWT.CONTROL)); + item.setAccelerator('Q' | SWT.MOD1); item.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -745,7 +745,7 @@ public class UIThread implements IUiSelectionListener, IClientChangeListener { // create edit menu items mCopyMenuItem = new MenuItem(editMenu, SWT.NONE); mCopyMenuItem.setText("&Copy\tCtrl-C"); - mCopyMenuItem.setAccelerator('C' | SWT.COMMAND); + mCopyMenuItem.setAccelerator('C' | SWT.MOD1); mCopyMenuItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -757,7 +757,7 @@ public class UIThread implements IUiSelectionListener, IClientChangeListener { mSelectAllMenuItem = new MenuItem(editMenu, SWT.NONE); mSelectAllMenuItem.setText("Select &All\tCtrl-A"); - mSelectAllMenuItem.setAccelerator('A' | SWT.COMMAND); + mSelectAllMenuItem.setAccelerator('A' | SWT.MOD1); mSelectAllMenuItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -815,7 +815,7 @@ public class UIThread implements IUiSelectionListener, IClientChangeListener { // 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' | (Main.isMac() ? SWT.COMMAND : SWT.CONTROL)); + screenShotItem.setAccelerator('S' | SWT.MOD1); screenShotItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -961,6 +961,7 @@ public class UIThread implements IUiSelectionListener, IClientChangeListener { createTopPanel(topPanel, darkGray); + mClipboard = new Clipboard(panelArea.getDisplay()); if (useOldLogCatView()) { createBottomPanel(bottomPanel); } else { @@ -1016,6 +1017,8 @@ public class UIThread implements IUiSelectionListener, IClientChangeListener { // now set up the listener in the various panels if (useOldLogCatView()) { mLogPanel.setTableFocusListener(mTableListener); + } else { + mLogCatPanel.setTableFocusListener(mTableListener); } mEventLogPanel.setTableFocusListener(mTableListener); for (TablePanel p : mPanels) { @@ -1212,7 +1215,6 @@ public class UIThread implements IUiSelectionListener, IClientChangeListener { // create clipboard Display display = comp.getDisplay(); - mClipboard = new Clipboard(display); LogColors colors = new LogColors(); diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java index 1915f7e..318240e 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java @@ -18,9 +18,11 @@ package com.android.ddmuilib.logcat; import com.android.ddmlib.DdmConstants; import com.android.ddmlib.Log.LogLevel; +import com.android.ddmuilib.ITableFocusListener; import com.android.ddmuilib.ImageLoader; import com.android.ddmuilib.SelectionDependentPanel; import com.android.ddmuilib.TableHelper; +import com.android.ddmuilib.ITableFocusListener.IFocusedTableActivator; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.IPreferenceStore; @@ -31,6 +33,11 @@ import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; @@ -745,4 +752,56 @@ public final class LogCatPanel extends SelectionDependentPanel public void addLogCatMessageSelectionListener(ILogCatMessageSelectionListener l) { mMessageSelectionListeners.add(l); } + + private ITableFocusListener mTableFocusListener; + + /** + * Specify the listener to be called when the logcat view gets focus. This interface is + * required by DDMS to hook up the menu items for Copy and Select All. + * @param listener listener to be notified when logcat view is in focus + */ + public void setTableFocusListener(ITableFocusListener listener) { + mTableFocusListener = listener; + + final Table table = mViewer.getTable(); + final IFocusedTableActivator activator = new IFocusedTableActivator() { + public void copy(Clipboard clipboard) { + copySelectionToClipboard(clipboard); + } + + public void selectAll() { + table.selectAll(); + } + }; + + table.addFocusListener(new FocusListener() { + public void focusGained(FocusEvent e) { + mTableFocusListener.focusGained(activator); + } + + public void focusLost(FocusEvent e) { + mTableFocusListener.focusLost(activator); + } + }); + } + + /** Copy all selected messages to clipboard. */ + public void copySelectionToClipboard(Clipboard clipboard) { + StringBuilder sb = new StringBuilder(); + + for (LogCatMessage m : getSelectedLogCatMessages()) { + sb.append(m.toString()); + sb.append('\n'); + } + + clipboard.setContents( + new Object[] {sb.toString()}, + new Transfer[] {TextTransfer.getInstance()} + ); + } + + /** Select all items in the logcat table. */ + public void selectAll() { + mViewer.getTable().selectAll(); + } } |