mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Extend tab context menu features
Add
- Close Other Tabs
- Close Tabs to Left/Right
- Move Tab to Start/End
- Show Enclosing Folder
to the tabs context menus.
Fix for bug #11963
(cherry picked from commit a114f12868
)
This commit is contained in:
parent
3c909daeea
commit
259c89f45e
@ -1959,6 +1959,75 @@ void TabWorkArea::closeCurrentBuffer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TabWorkArea::closeTabsToRight()
|
||||||
|
{
|
||||||
|
if (clicked_tab_ == -1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int const initialCurrentIndex = currentIndex();
|
||||||
|
|
||||||
|
while (count() - 1 > clicked_tab_) {
|
||||||
|
GuiWorkArea * wa = workArea(count() - 1);
|
||||||
|
LASSERT(wa, return false);
|
||||||
|
if (!wa->view().closeWorkArea(wa)) {
|
||||||
|
// closing cancelled, if possible, reset initial current tab index
|
||||||
|
if (initialCurrentIndex < count())
|
||||||
|
setCurrentIndex(initialCurrentIndex);
|
||||||
|
else
|
||||||
|
setCurrentIndex(clicked_tab_);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TabWorkArea::openEnclosingFolder()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (clicked_tab_ == -1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Buffer const & buf = workArea(clicked_tab_)->bufferView().buffer();
|
||||||
|
showDirectory(buf.fileName().onlyPath());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TabWorkArea::closeTabsToLeft()
|
||||||
|
{
|
||||||
|
if (clicked_tab_ == -1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int const initialCurrentIndex = currentIndex();
|
||||||
|
|
||||||
|
int n = clicked_tab_;
|
||||||
|
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
GuiWorkArea * wa = workArea(0);
|
||||||
|
LASSERT(wa, return false);
|
||||||
|
if (!wa->view().closeWorkArea(wa)) {
|
||||||
|
// closing cancelled, if possible, reset initial current tab index
|
||||||
|
if (initialCurrentIndex - i >= 0)
|
||||||
|
setCurrentIndex(initialCurrentIndex - i);
|
||||||
|
else
|
||||||
|
setCurrentIndex(clicked_tab_ - i);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TabWorkArea::closeOtherTabs()
|
||||||
|
{
|
||||||
|
if (clicked_tab_ == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
closeTabsToRight() && closeTabsToLeft();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void TabWorkArea::hideCurrentTab()
|
void TabWorkArea::hideCurrentTab()
|
||||||
{
|
{
|
||||||
GuiWorkArea * wa;
|
GuiWorkArea * wa;
|
||||||
@ -1986,6 +2055,22 @@ void TabWorkArea::closeTab(int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TabWorkArea::moveToStartCurrentTab()
|
||||||
|
{
|
||||||
|
if (clicked_tab_ == -1)
|
||||||
|
return;
|
||||||
|
tabBar()->moveTab(clicked_tab_, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TabWorkArea::moveToEndCurrentTab()
|
||||||
|
{
|
||||||
|
if (clicked_tab_ == -1)
|
||||||
|
return;
|
||||||
|
tabBar()->moveTab(clicked_tab_, count() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
class DisplayPath {
|
class DisplayPath {
|
||||||
public:
|
public:
|
||||||
@ -2233,19 +2318,42 @@ void TabWorkArea::showContextMenu(const QPoint & pos)
|
|||||||
|
|
||||||
// show tab popup
|
// show tab popup
|
||||||
QMenu popup;
|
QMenu popup;
|
||||||
popup.addAction(QIcon(getPixmap("images/", "hidetab", "svgz,png")),
|
popup.addAction(qt_("&Hide Tab"), this, SLOT(hideCurrentTab()));
|
||||||
qt_("&Hide Tab"), this, SLOT(hideCurrentTab()));
|
|
||||||
|
|
||||||
// we want to show the 'close' option only if this is not a child buffer.
|
// we want to show the 'close' option only if this is not a child buffer.
|
||||||
Buffer const & buf = wa->bufferView().buffer();
|
Buffer const & buf = wa->bufferView().buffer();
|
||||||
if (!buf.parent())
|
if (!buf.parent())
|
||||||
popup.addAction(QIcon(getPixmap("images/", "closetab", "svgz,png")),
|
popup.addAction(qt_("&Close Tab"), this, SLOT(closeCurrentBuffer()));
|
||||||
qt_("&Close Tab"), this, SLOT(closeCurrentBuffer()));
|
|
||||||
|
popup.addSeparator();
|
||||||
|
|
||||||
|
QAction * closeOther = popup.addAction(qt_("Close &Other Tabs"), this, SLOT(closeOtherTabs()));
|
||||||
|
closeOther->setEnabled(clicked_tab_ != 0 || hasTabsToRight(clicked_tab_));
|
||||||
|
QAction * closeRight = popup.addAction(qt_("Close Tabs to the &Right"), this, SLOT(closeTabsToRight()));
|
||||||
|
closeRight->setEnabled(hasTabsToRight(clicked_tab_));
|
||||||
|
QAction * closeLeft = popup.addAction(qt_("Close Tabs to the &Left"), this, SLOT(closeTabsToLeft()));
|
||||||
|
closeLeft->setEnabled(clicked_tab_ != 0);
|
||||||
|
|
||||||
|
popup.addSeparator();
|
||||||
|
|
||||||
|
QAction * moveStart = popup.addAction(qt_("Move Tab to &Start"), this, SLOT(moveToStartCurrentTab()));
|
||||||
|
moveStart->setEnabled(closeLeft->isEnabled());
|
||||||
|
QAction * moveEnd = popup.addAction(qt_("Move Tab to &End"), this, SLOT(moveToEndCurrentTab()));
|
||||||
|
moveEnd->setEnabled(closeRight->isEnabled());
|
||||||
|
|
||||||
|
popup.addSeparator();
|
||||||
|
|
||||||
|
popup.addAction(qt_("Open Enclosing &Folder"), this, SLOT(openEnclosingFolder()));
|
||||||
|
|
||||||
popup.exec(tabBar()->mapToGlobal(pos));
|
popup.exec(tabBar()->mapToGlobal(pos));
|
||||||
|
|
||||||
clicked_tab_ = -1;
|
clicked_tab_ = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TabWorkArea::hasTabsToRight(int index) {
|
||||||
|
return count() - 1 > index;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void TabWorkArea::moveTab(int fromIndex, int toIndex)
|
void TabWorkArea::moveTab(int fromIndex, int toIndex)
|
||||||
{
|
{
|
||||||
|
@ -242,6 +242,18 @@ public Q_SLOTS:
|
|||||||
void closeCurrentBuffer();
|
void closeCurrentBuffer();
|
||||||
/// hide current tab, or the one given by \c clicked_tab_
|
/// hide current tab, or the one given by \c clicked_tab_
|
||||||
void hideCurrentTab();
|
void hideCurrentTab();
|
||||||
|
///
|
||||||
|
bool closeTabsToRight();
|
||||||
|
///
|
||||||
|
bool closeTabsToLeft();
|
||||||
|
///
|
||||||
|
void closeOtherTabs();
|
||||||
|
///
|
||||||
|
void moveToStartCurrentTab();
|
||||||
|
///
|
||||||
|
void moveToEndCurrentTab();
|
||||||
|
///
|
||||||
|
bool openEnclosingFolder();
|
||||||
/// close the tab given by \c index
|
/// close the tab given by \c index
|
||||||
void closeTab(int index);
|
void closeTab(int index);
|
||||||
///
|
///
|
||||||
@ -269,6 +281,9 @@ private:
|
|||||||
/// true if position is a tab (rather than the blank space in tab bar)
|
/// true if position is a tab (rather than the blank space in tab bar)
|
||||||
bool posIsTab(QPoint position);
|
bool posIsTab(QPoint position);
|
||||||
|
|
||||||
|
// true if there are tabs to the right of the tab at index
|
||||||
|
bool hasTabsToRight(int index);
|
||||||
|
|
||||||
int clicked_tab_;
|
int clicked_tab_;
|
||||||
///
|
///
|
||||||
int midpressed_tab_;
|
int midpressed_tab_;
|
||||||
|
Loading…
Reference in New Issue
Block a user