From 625122d39150a0c0f4717c3e00c2b0c3b8fd074b Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Wed, 29 Jul 2015 15:21:44 -0700 Subject: Automatically start copy mode when clicking and dragging with a mouse --- .../main/java/org/connectbot/ConsoleActivity.java | 43 ++++++++++++++-------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/org/connectbot/ConsoleActivity.java b/app/src/main/java/org/connectbot/ConsoleActivity.java index 79f1269..4e4c4e2 100644 --- a/app/src/main/java/org/connectbot/ConsoleActivity.java +++ b/app/src/main/java/org/connectbot/ConsoleActivity.java @@ -46,10 +46,12 @@ import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.preference.PreferenceManager; +import android.support.v4.view.MotionEventCompat; import android.text.ClipboardManager; import android.util.Log; import android.view.ContextMenu; import android.view.GestureDetector; +import android.view.InputDevice; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; @@ -557,6 +559,15 @@ public class ConsoleActivity extends Activity { public boolean onTouch(View v, MotionEvent event) { + // Automatically start copy mode if using a mouse. + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && + MotionEventCompat.getSource(event) == InputDevice.SOURCE_MOUSE && + event.getAction() == MotionEvent.ACTION_DOWN && + // Ignore right clicks. + event.getButtonState() == MotionEvent.BUTTON_PRIMARY) { + startCopyMode(); + } + // when copying, highlight the area if (copySource != null && copySource.isSelectingForCopy()) { int row = (int) Math.floor(event.getY() / copySource.charHeight); @@ -564,7 +575,7 @@ public class ConsoleActivity extends Activity { SelectionArea area = copySource.getSelectionArea(); - switch(event.getAction()) { + switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // recording starting area if (area.isSelectingOrigin()) { @@ -636,7 +647,6 @@ public class ConsoleActivity extends Activity { } }); - } /** @@ -711,19 +721,7 @@ public class ConsoleActivity extends Activity { copy.setEnabled(activeTerminal); copy.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { - // mark as copying and reset any previous bounds - TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip); - copySource = terminalView.bridge; - - SelectionArea area = copySource.getSelectionArea(); - area.reset(); - area.setBounds(copySource.buffer.getColumns(), copySource.buffer.getRows()); - - copySource.setSelectingForCopy(true); - - // Make sure we show the initial selection - copySource.redraw(); - + startCopyMode(); Toast.makeText(ConsoleActivity.this, getString(R.string.console_copy_start), Toast.LENGTH_LONG).show(); return true; } @@ -996,6 +994,21 @@ public class ConsoleActivity extends Activity { unbindService(connection); } + private void startCopyMode() { + // mark as copying and reset any previous bounds + TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip); + copySource = terminalView.bridge; + + SelectionArea area = copySource.getSelectionArea(); + area.reset(); + area.setBounds(copySource.buffer.getColumns(), copySource.buffer.getRows()); + + copySource.setSelectingForCopy(true); + + // Make sure we show the initial selection + copySource.redraw(); + } + protected void shiftCurrentTerminal(final int direction) { View overlay; synchronized (flip) { -- cgit v1.2.3 From 0fe8bd4b1c0f7b5971dd64dd18ebb2326ddb393e Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Wed, 29 Jul 2015 15:52:30 -0700 Subject: Make clicking the mouse wheel paste. --- .../main/java/org/connectbot/ConsoleActivity.java | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/org/connectbot/ConsoleActivity.java b/app/src/main/java/org/connectbot/ConsoleActivity.java index 4e4c4e2..179da72 100644 --- a/app/src/main/java/org/connectbot/ConsoleActivity.java +++ b/app/src/main/java/org/connectbot/ConsoleActivity.java @@ -559,13 +559,23 @@ public class ConsoleActivity extends Activity { public boolean onTouch(View v, MotionEvent event) { - // Automatically start copy mode if using a mouse. + // Handle mouse-specific actions. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && MotionEventCompat.getSource(event) == InputDevice.SOURCE_MOUSE && - event.getAction() == MotionEvent.ACTION_DOWN && - // Ignore right clicks. - event.getButtonState() == MotionEvent.BUTTON_PRIMARY) { - startCopyMode(); + event.getAction() == MotionEvent.ACTION_DOWN) { + switch(event.getButtonState()) { + case MotionEvent.BUTTON_PRIMARY: + // Automatically start copy mode if using a mouse. + startCopyMode(); + break; + case MotionEvent.BUTTON_SECONDARY: + // Let the context menu show on right click. + return false; + case MotionEvent.BUTTON_TERTIARY: + // Middle click pastes. + pasteIntoTerminal(); + return true; + } } // when copying, highlight the area -- cgit v1.2.3 From f77d364cecf8e9a77d31ba8fc1b59dff127992d0 Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Wed, 29 Jul 2015 16:33:51 -0700 Subject: Space after switch --- app/src/main/java/org/connectbot/ConsoleActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main') diff --git a/app/src/main/java/org/connectbot/ConsoleActivity.java b/app/src/main/java/org/connectbot/ConsoleActivity.java index 179da72..50c1a21 100644 --- a/app/src/main/java/org/connectbot/ConsoleActivity.java +++ b/app/src/main/java/org/connectbot/ConsoleActivity.java @@ -563,7 +563,7 @@ public class ConsoleActivity extends Activity { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && MotionEventCompat.getSource(event) == InputDevice.SOURCE_MOUSE && event.getAction() == MotionEvent.ACTION_DOWN) { - switch(event.getButtonState()) { + switch (event.getButtonState()) { case MotionEvent.BUTTON_PRIMARY: // Automatically start copy mode if using a mouse. startCopyMode(); -- cgit v1.2.3