On Sun, Apr 5, 2015 at 8:40 PM, Richard Heck <rgh...@lyx.org> wrote:
> On 04/05/2015 07:47 PM, Scott Kostyshak wrote:
>>
>> It is currently bound to buffer-begin-select. But this LFUN is also
>> bound to C-S-Home. I would like to implement buffer-move-next, which
>> will move the tab up one spot (and similar for C-S-PageDown. This
>> feature and keybinding would be consistent with tab behavior in
>> Chromium, Firefox, and Nautilus.
>
>
> Seems reasonable.

Attached is a patch. Note that in the patch there is cycling also when
moving. For example, if you are on the first tab, you can move it to
the last tab. I like this behavior and think it is consistent with tab
switching. However, it is not consistent with what chromium,
gnome-terminal, nautilus, and firefox do. They all disable such
cycling when moving.

Thoughts?

Scott
From 8fefc28c8f20b8116ef3d9ff56662a874ebf6b8c Mon Sep 17 00:00:00 2001
From: Scott Kostyshak <skost...@lyx.org>
Date: Tue, 7 Apr 2015 23:18:21 -0400
Subject: [PATCH] Implement and bind buffer-move-{next,previous}

Control + Shift + PgDn now moves a tab to the right.
Control + Shift + PgUp now moves a tab to the left.

This is consistent with Chromium, Firefox, Nautilus,
and gnome-terminal.
---
 RELEASE-NOTES                   |  9 +++++++++
 lib/bind/cua.bind               |  4 ++--
 lib/bind/emacs.bind             |  4 ++--
 lib/bind/mac.bind               |  4 ++--
 lib/bind/xemacs.bind            |  4 ++--
 src/FuncCode.h                  |  3 +++
 src/LyXAction.cpp               | 14 ++++++++++++++
 src/frontends/qt4/GuiView.cpp   | 21 +++++++++++++++++----
 src/frontends/qt4/GuiView.h     |  2 +-
 src/frontends/qt4/GuiWorkArea.h |  4 ++--
 10 files changed, 54 insertions(+), 15 deletions(-)

diff --git a/RELEASE-NOTES b/RELEASE-NOTES
index f859e48..f1999c2 100644
--- a/RELEASE-NOTES
+++ b/RELEASE-NOTES
@@ -29,6 +29,12 @@ The following new LyX functions have been introduced in 2.2:
 - buffer-view-cache
   Opens the last previewed output of the buffer, if it exists.
 
+- buffer-move-next
+  Moves the current tab one spot to the right.
+
+- buffer-move-previous
+  Moves the current tab one spot to the left.
+
 
 The following LyX functions have been changed in 2.2:
 
@@ -36,6 +42,9 @@ The following LyX functions have been changed in 2.2:
 
 The following LyX key bindings have been changed in 2.2:
 
+- For bindings where Control + {PgDn, PgUp} switches to the
+  {next, previous} tab, Control + Shift + {PgDn, PgUp} moves the current
+  tab to the {next, previous} tab.
 
 
 The following LyX documents have been moved in 2.2:
diff --git a/lib/bind/cua.bind b/lib/bind/cua.bind
index 359e1d4..71b919c 100644
--- a/lib/bind/cua.bind
+++ b/lib/bind/cua.bind
@@ -187,8 +187,8 @@ Format 2
 \bind "S-KP_Next"		"screen-down-select"
 \bind "S-C-KP_Home"		"buffer-begin-select"
 \bind "S-C-KP_End"		"buffer-end-select"
-\bind "S-C-KP_Prior"		"buffer-begin-select"
-\bind "S-C-KP_Next"		"buffer-end-select"
+\bind "S-C-KP_Prior"		"buffer-move-previous"
+\bind "S-C-KP_Next"		"buffer-move-next"
 \bind "C-KP_Insert"		"copy"
 \bind "S-KP_Insert"		"paste"
 \bind "S-KP_Delete"		"cut"
diff --git a/lib/bind/emacs.bind b/lib/bind/emacs.bind
index f0cb33e..71ce2d1 100644
--- a/lib/bind/emacs.bind
+++ b/lib/bind/emacs.bind
@@ -252,8 +252,8 @@ Format 2
 \bind "S-KP_Next"               "screen-down-select"
 \bind "S-C-KP_Home"             "buffer-begin-select"
 \bind "S-C-KP_End"              "buffer-end-select"
-\bind "S-C-KP_Prior"            "buffer-begin-select"
-\bind "S-C-KP_Next"             "buffer-end-select"
+\bind "S-C-KP_Prior"            "buffer-move-next"
+\bind "S-C-KP_Next"             "buffer-move-next"
 \bind "M-h"                     "inset-select-all"
 \bind "C-KP_Insert"             "copy"
 \bind "S-KP_Insert"             "paste"
diff --git a/lib/bind/mac.bind b/lib/bind/mac.bind
index ecdd3ad..6fcd406 100644
--- a/lib/bind/mac.bind
+++ b/lib/bind/mac.bind
@@ -314,8 +314,8 @@ Format 2
 \bind "S-KP_Next"                    "screen-down-select"
 \bind "S-C-KP_Home"                  "buffer-begin-select"
 \bind "S-C-KP_End"                   "buffer-end-select"
-\bind "S-C-KP_Prior"                 "buffer-begin-select"
-\bind "S-C-KP_Next"                  "buffer-end-select"
+\bind "S-C-KP_Prior"                 "buffer-move-previous"
+\bind "S-C-KP_Next"                  "buffer-move-next"
 \bind "C-KP_Insert"                  "copy"
 \bind "S-KP_Insert"                  "paste"
 \bind "S-KP_Delete"                  "cut"
diff --git a/lib/bind/xemacs.bind b/lib/bind/xemacs.bind
index e3d69af..32c67b1 100644
--- a/lib/bind/xemacs.bind
+++ b/lib/bind/xemacs.bind
@@ -249,8 +249,8 @@ Format 2
 \bind "S-C-KP_Down"             "paragraph-down-select"
 \bind "S-KP_Home"               "line-begin-select"
 \bind "S-KP_End"                "line-end-select"
-\bind "S-KP_Prior"              "screen-up-select"
-\bind "S-KP_Next"               "screen-down-select"
+\bind "S-KP_Prior"              "buffer-move-previous"
+\bind "S-KP_Next"               "buffer-move-next"
 \bind "S-C-KP_Home"             "buffer-begin-select"
 \bind "S-C-KP_End"              "buffer-end-select"
 \bind "S-C-KP_Prior"            "buffer-begin-select"
diff --git a/src/FuncCode.h b/src/FuncCode.h
index b590b38..91526b9 100644
--- a/src/FuncCode.h
+++ b/src/FuncCode.h
@@ -460,6 +460,9 @@ enum FuncCode
 	LFUN_SEPARATOR_INSERT,          // ef 20140502
 	LFUN_SERVER_GET_STATISTICS,     // brokenclock 20141010
 	LFUN_BUFFER_VIEW_CACHE,         // skostysh 20150401
+	LFUN_BUFFER_MOVE_NEXT,          // skostysh 20150408
+	// 340
+	LFUN_BUFFER_MOVE_PREVIOUS,      // skostysh 20150408
 	LFUN_LASTACTION                 // end of the table
 };
 
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 1ba2ef8..10d43f5 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -3290,6 +3290,13 @@ void LyXAction::init()
  */
 		{ LFUN_BUFFER_NEXT, "buffer-next", ReadOnly, Buffer },
 /*!
+ * \var lyx::FuncCode lyx::LFUN_BUFFER_MOVE_NEXT
+ * \li Action: Moves the current tab one spot to the right.
+ * \li Syntax: buffer-move-next
+ * \endvar
+ */
+		{ LFUN_BUFFER_MOVE_NEXT, "buffer-move-next", ReadOnly, Buffer },
+/*!
  * \var lyx::FuncCode lyx::LFUN_BUFFER_PREVIOUS
  * \li Action: Switch to the previous opened document.
  * \li Syntax: buffer-previous
@@ -3297,6 +3304,13 @@ void LyXAction::init()
  */
 		{ LFUN_BUFFER_PREVIOUS, "buffer-previous", ReadOnly, Buffer },
 /*!
+ * \var lyx::FuncCode lyx::LFUN_BUFFER_MOVE_PREVIOUS
+ * \li Action: Moves the current tab one spot to the left.
+ * \li Syntax: buffer-move-previous
+ * \endvar
+ */
+		{ LFUN_BUFFER_MOVE_PREVIOUS, "buffer-move-previous", ReadOnly, Buffer },
+/*!
  * \var lyx::FuncCode lyx::LFUN_MASTER_BUFFER_UPDATE
  * \li Action: Update (export) the document built from the master buffer,
                if the current buffer is part of a master/child document.
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index e85d042..618977b 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -1922,7 +1922,9 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 		break;
 
 	case LFUN_BUFFER_NEXT:
+	case LFUN_BUFFER_MOVE_NEXT:
 	case LFUN_BUFFER_PREVIOUS:
+	case LFUN_BUFFER_MOVE_PREVIOUS:
 		// because we cycle, it doesn't matter whether on first or last
 		if (d.currentTabWorkArea()->count() <= 1)
 			enable = false;
@@ -2918,7 +2920,7 @@ bool GuiView::inOtherView(Buffer & buf)
 }
 
 
-void GuiView::gotoNextOrPreviousBuffer(NextOrPrevious np)
+void GuiView::gotoNextOrPreviousBuffer(NextOrPrevious np, bool const move)
 {
 	if (!documentBufferView())
 		return;
@@ -2933,7 +2935,10 @@ void GuiView::gotoNextOrPreviousBuffer(NextOrPrevious np)
 					next_index = (i == nwa - 1 ? 0 : i + 1);
 				else
 					next_index = (i == 0 ? nwa - 1 : i - 1);
-				setBuffer(&workArea(next_index)->bufferView().buffer());
+				if (move)
+					twa->moveTab(i, next_index);
+				else
+					setBuffer(&workArea(next_index)->bufferView().buffer());
 				break;
 			}
 		}
@@ -3547,11 +3552,19 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 		}
 
 		case LFUN_BUFFER_NEXT:
-			gotoNextOrPreviousBuffer(NEXTBUFFER);
+			gotoNextOrPreviousBuffer(NEXTBUFFER, false);
+			break;
+
+		case LFUN_BUFFER_MOVE_NEXT:
+			gotoNextOrPreviousBuffer(NEXTBUFFER, true);
 			break;
 
 		case LFUN_BUFFER_PREVIOUS:
-			gotoNextOrPreviousBuffer(PREVBUFFER);
+			gotoNextOrPreviousBuffer(PREVBUFFER, false);
+			break;
+
+		case LFUN_BUFFER_MOVE_PREVIOUS:
+			gotoNextOrPreviousBuffer(PREVBUFFER, true);
 			break;
 
 		case LFUN_COMMAND_EXECUTE: {
diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h
index f7b488b..478e3a1 100644
--- a/src/frontends/qt4/GuiView.h
+++ b/src/frontends/qt4/GuiView.h
@@ -421,7 +421,7 @@ private:
 		PREVBUFFER
 	};
 	///
-	void gotoNextOrPreviousBuffer(NextOrPrevious np);
+	void gotoNextOrPreviousBuffer(NextOrPrevious np, bool const move);
 
 	/// Is the dialog currently visible?
 	bool isDialogVisible(std::string const & name) const;
diff --git a/src/frontends/qt4/GuiWorkArea.h b/src/frontends/qt4/GuiWorkArea.h
index fb6341b..5039e45 100644
--- a/src/frontends/qt4/GuiWorkArea.h
+++ b/src/frontends/qt4/GuiWorkArea.h
@@ -218,6 +218,8 @@ public Q_SLOTS:
 	/// close the tab given by \c index
 	void closeTab(int index);
 	///
+	void moveTab(int fromIndex, int toIndex);
+	///
 	void updateTabTexts();
 	
 private Q_SLOTS:
@@ -226,8 +228,6 @@ private Q_SLOTS:
 	///
 	void showContextMenu(const QPoint & pos);
 	///
-	void moveTab(int fromIndex, int toIndex);
-	///
 	void mouseDoubleClickEvent(QMouseEvent * event);
 
 private:
-- 
2.1.0

Reply via email to