1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

VerticalTabs: Add support for creating groups

Long press on New Tab button will show menu with existing groups
and clicking on group will open new tab inside this group.
This commit is contained in:
David Rosca 2018-02-05 15:29:57 +01:00
parent e74f18e8e8
commit 5e2af2ff66
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
10 changed files with 182 additions and 2 deletions

View File

@ -9,6 +9,7 @@ set( VerticalTabs_SRCS
tabfiltermodel.cpp tabfiltermodel.cpp
tablistview.cpp tablistview.cpp
tablistdelegate.cpp tablistdelegate.cpp
verticaltabsschemehandler.cpp
) )
set( VerticalTabs_UIS set( VerticalTabs_UIS

View File

@ -0,0 +1,27 @@
<html>
<head>
<link rel="shortcut icon" href="%FAVICON%">
<style>
input { margin: 15% 25%; min-width: 50%; }
</style>
</head>
<body>
<input type="text" id="groupname" oninput="updateName();"></input>
</body>
<script>
var loaded = false;
function updateName() {
var input = document.getElementById("groupname");
if (!loaded && input.value == "") {
input.value = window.location.hash.substr(1);
if (input.value == "") {
input.value = "%NEW-GROUP%";
}
}
document.title = input.value;
window.location.replace("#" + input.value);
loaded = true;
}
updateName();
</script>
</html>

View File

@ -0,0 +1,13 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
<defs id="defs3051">
<style type="text/css" id="current-color-scheme">
.ColorScheme-Text {
color:#4d4d4d;
}
</style>
</defs>
<path style="fill:currentColor;fill-opacity:1;stroke:none"
d="M 2 2 L 2 3 L 2 6 L 2 7 L 2 13 L 2 14 L 14 14 L 14 13 L 14 6 L 14 5 L 14 4 L 9.0078125 4 L 7.0078125 2 L 7 2.0078125 L 7 2 L 3 2 L 2 2 z M 3 3 L 6.5917969 3 L 7.59375 4 L 7 4 L 7 4.0078125 L 6.9921875 4 L 4.9921875 6 L 3 6 L 3 3 z M 3 7 L 13 7 L 13 13 L 3 13 L 3 7 z "
class="ColorScheme-Text"
/>
</svg>

After

Width:  |  Height:  |  Size: 609 B

View File

@ -0,0 +1,11 @@
<html>
<head>
<title>%NAME%</title>
<style>
h1 { text-align:center; }
</style>
</head>
<body>
<h1>%NAME%</h1>
</body>
</html>

View File

@ -1,6 +1,9 @@
<RCC> <RCC>
<qresource prefix="/verticaltabs"> <qresource prefix="/verticaltabs">
<file>data/icon.svg</file> <file>data/icon.svg</file>
<file>data/group.svg</file>
<file>data/index.html</file>
<file>data/group.html</file>
<file>data/themes/default.css</file> <file>data/themes/default.css</file>
<file>data/themes/windows.css</file> <file>data/themes/windows.css</file>
<file>data/themes/windows-tab-close.svg</file> <file>data/themes/windows-tab-close.svg</file>

View File

@ -18,6 +18,7 @@
#include "verticaltabsplugin.h" #include "verticaltabsplugin.h"
#include "verticaltabssettings.h" #include "verticaltabssettings.h"
#include "verticaltabscontroller.h" #include "verticaltabscontroller.h"
#include "verticaltabsschemehandler.h"
#include "browserwindow.h" #include "browserwindow.h"
#include "pluginproxy.h" #include "pluginproxy.h"
@ -25,6 +26,7 @@
#include "tabwidget.h" #include "tabwidget.h"
#include "tabbar.h" #include "tabbar.h"
#include "sidebar.h" #include "sidebar.h"
#include "networkmanager.h"
#include "../config.h" #include "../config.h"
#include <QSettings> #include <QSettings>
@ -64,6 +66,7 @@ void VerticalTabsPlugin::init(InitState state, const QString &settingsPath)
SideBarManager::addSidebar(QSL("VerticalTabs"), m_controller); SideBarManager::addSidebar(QSL("VerticalTabs"), m_controller);
QZ_REGISTER_EVENT_HANDLER(PluginProxy::KeyPressHandler); QZ_REGISTER_EVENT_HANDLER(PluginProxy::KeyPressHandler);
mApp->networkManager()->registerExtensionSchemeHandler(QSL("verticaltabs"), new VerticalTabsSchemeHandler);
setWebTabBehavior(m_addChildBehavior); setWebTabBehavior(m_addChildBehavior);
loadStyleSheet(m_theme); loadStyleSheet(m_theme);
@ -85,6 +88,8 @@ void VerticalTabsPlugin::unload()
SideBarManager::removeSidebar(QSL("VerticalTabs")); SideBarManager::removeSidebar(QSL("VerticalTabs"));
delete m_controller; delete m_controller;
m_controller = nullptr; m_controller = nullptr;
mApp->networkManager()->unregisterExtensionSchemeHandler(QSL("verticaltabs"));
} }
bool VerticalTabsPlugin::testPlugin() bool VerticalTabsPlugin::testPlugin()

View File

@ -0,0 +1,60 @@
/* ============================================================
* VerticalTabs plugin for Falkon
* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "verticaltabsschemehandler.h"
#include "qztools.h"
#include <QIcon>
#include <QUrlQuery>
#include <QWebEngineUrlRequestJob>
VerticalTabsSchemeHandler::VerticalTabsSchemeHandler(QObject *parent)
: ExtensionSchemeHandler(parent)
{
}
void VerticalTabsSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job)
{
const auto parts = job->requestUrl().path().split(QL1C('/'), QString::SkipEmptyParts);
if (!parts.isEmpty()) {
if (parts.at(0) == QL1S("group")) {
setReply(job, QByteArrayLiteral("text/html"), groupPage());
return;
}
}
setReply(job, QByteArrayLiteral("text/html"), indexPage());
}
QByteArray VerticalTabsSchemeHandler::indexPage() const
{
QString page = QzTools::readAllFileContents(QSL(":verticaltabs/data/index.html"));
page.replace(QSL("%NAME%"), tr("Vertical Tabs"));
return page.toUtf8();
}
QByteArray VerticalTabsSchemeHandler::groupPage() const
{
QString page = QzTools::readAllFileContents(QSL(":verticaltabs/data/group.html"));
page.replace(QSL("%FAVICON%"), QzTools::pixmapToDataUrl(QIcon(QSL(":verticaltabs/data/group.svg")).pixmap(16)).toString());
page.replace(QSL("%NEW-GROUP%"), tr("New Group"));
return page.toUtf8();
}

View File

@ -0,0 +1,32 @@
/* ============================================================
* VerticalTabs plugin for Falkon
* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#pragma once
#include "schemehandlers/extensionschemehandler.h"
class VerticalTabsSchemeHandler : public ExtensionSchemeHandler
{
public:
explicit VerticalTabsSchemeHandler(QObject *parent = nullptr);
void requestStarted(QWebEngineUrlRequestJob *job) override;
private:
QByteArray indexPage() const;
QByteArray groupPage() const;
};

View File

@ -60,6 +60,10 @@ VerticalTabsWidget::VerticalTabsWidget(BrowserWindow *window)
buttonAddTab->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); buttonAddTab->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
connect(buttonAddTab, SIGNAL(clicked()), m_window, SLOT(addTab())); connect(buttonAddTab, SIGNAL(clicked()), m_window, SLOT(addTab()));
m_groupMenu = new QMenu(this);
buttonAddTab->setMenu(m_groupMenu);
connect(m_groupMenu, &QMenu::aboutToShow, this, &VerticalTabsWidget::updateGroupMenu);
layout->addWidget(m_pinnedView); layout->addWidget(m_pinnedView);
layout->addWidget(m_normalView); layout->addWidget(m_normalView);
layout->addWidget(buttonAddTab); layout->addWidget(buttonAddTab);
@ -175,3 +179,23 @@ void VerticalTabsWidget::wheelEvent(QWheelEvent *event)
} }
event->accept(); event->accept();
} }
void VerticalTabsWidget::updateGroupMenu()
{
m_groupMenu->clear();
for (int i = 0; i < m_window->tabWidget()->count(); ++i) {
WebTab *tab = m_window->tabWidget()->webTab(i);
if (tab->url().toString(QUrl::RemoveFragment) == QL1S("extension://verticaltabs/group")) {
m_groupMenu->addAction(tab->url().fragment(), this, [=]() {
QMetaObject::invokeMethod(m_window, "addTab");
m_window->tabWidget()->webTab()->setParentTab(tab);
});
}
}
m_groupMenu->addSeparator();
m_groupMenu->addAction(tr("Add New Group..."), this, [this]() {
m_window->tabWidget()->addView(QUrl(QSL("extension://verticaltabs/group")), Qz::NT_SelectedTab);
});
}

View File

@ -23,6 +23,8 @@
#include "verticaltabsplugin.h" #include "verticaltabsplugin.h"
class QMenu;
class WebTab; class WebTab;
class BrowserWindow; class BrowserWindow;
class TabTreeModel; class TabTreeModel;
@ -42,14 +44,16 @@ public:
void switchToPreviousTab(); void switchToPreviousTab();
private: private:
void wheelEvent(QWheelEvent *event) override;
WebTab *nextTab() const; WebTab *nextTab() const;
WebTab *previousTab() const; WebTab *previousTab() const;
void wheelEvent(QWheelEvent *event) override;
void updateGroupMenu();
BrowserWindow *m_window; BrowserWindow *m_window;
TabListView *m_pinnedView; TabListView *m_pinnedView;
TabTreeView *m_normalView; TabTreeView *m_normalView;
TabTreeModel *m_treeModel = nullptr; TabTreeModel *m_treeModel = nullptr;
WheelHelper m_wheelHelper; WheelHelper m_wheelHelper;
QMenu *m_groupMenu;
}; };