From f8341db5520d1df0874cbd7ef1efda069a8d543d Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Tue, 22 Oct 2024 10:51:05 -0700 Subject: [PATCH] Restore the current URL text when switching tabs. https://redmine.stoutner.com/issues/1231 --- doc/index.docbook | 15 +++++++++++++++ src/helpers/FilterListHelper.h | 2 +- src/widgets/PrivacyWebEngineView.h | 1 + src/widgets/TabWidget.cpp | 16 +++++++++++----- src/widgets/TabWidget.h | 1 + src/windows/BrowserWindow.cpp | 22 ++++++++++++++++++++++ src/windows/BrowserWindow.h | 3 +++ 7 files changed, 54 insertions(+), 6 deletions(-) diff --git a/doc/index.docbook b/doc/index.docbook index f40ecc3..95c12aa 100644 --- a/doc/index.docbook +++ b/doc/index.docbook @@ -1657,6 +1657,21 @@ + + + + + &Ctrl;+&Shift;+R + + + + + + Restore the URL text (if it has been edited) to the URL that is currently displayed in the tab. + + + + diff --git a/src/helpers/FilterListHelper.h b/src/helpers/FilterListHelper.h index d6b96ad..df7477d 100644 --- a/src/helpers/FilterListHelper.h +++ b/src/helpers/FilterListHelper.h @@ -14,7 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Privacy Browser PC. If not, see . + * along with Privacy Browser PC. If not, see . */ #ifndef FILTER_LIST_HELPER_H diff --git a/src/widgets/PrivacyWebEngineView.h b/src/widgets/PrivacyWebEngineView.h index 60121cd..18f87f4 100644 --- a/src/widgets/PrivacyWebEngineView.h +++ b/src/widgets/PrivacyWebEngineView.h @@ -53,6 +53,7 @@ public: // The public variables. QVector blockedRequestsVector = {0, 0, 0, 0, 0, 0}; std::list *cookieListPointer = new std::list; + QString currentUrlText = QLatin1String(""); double defaultZoomFactor = 1.00; QString domainSettingsName = QLatin1String(""); bool easyListEnabled = true; diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index c7de220..173296b 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -14,7 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Privacy Browser PC. If not, see . + * along with Privacy Browser PC. If not, see . */ // Application headers. @@ -1141,6 +1141,12 @@ void TabWidget::stop() const currentPrivacyWebEngineViewPointer->stop(); } +void TabWidget::storeCurrentUrlText(const QString &urlText) const +{ + // Store the current URL text in the privacy WebEngine view. + currentPrivacyWebEngineViewPointer->currentUrlText = urlText; +} + void TabWidget::toggleDeveloperTools(const bool enabled) const { // Get a handle for the current developer tools WebEngine. @@ -1307,6 +1313,9 @@ void TabWidget::updateUiFromWebEngineView(const PrivacyWebEngineView *privacyWeb void TabWidget::updateUiWithTabSettings() { + // Clear the URL line edit focus. + emit clearUrlLineEditFocus(); + // Update the current WebEngine pointers. currentPrivacyWebEngineViewPointer = qTabWidgetPointer->currentWidget()->findChild(); currentWebEngineSettingsPointer = currentPrivacyWebEngineViewPointer->settings(); @@ -1315,9 +1324,6 @@ void TabWidget::updateUiWithTabSettings() currentWebEngineHistoryPointer = currentWebEnginePagePointer->history(); currentWebEngineCookieStorePointer = currentWebEngineProfilePointer->cookieStore(); - // Clear the URL line edit focus. - emit clearUrlLineEditFocus(); - // Get a handle for the development tools WebEngine view. DevToolsWebEngineView *devToolsWebEngineViewPointer = qTabWidgetPointer->currentWidget()->findChild(); @@ -1342,7 +1348,7 @@ void TabWidget::updateUiWithTabSettings() // Update the URL. emit updateWindowTitle(currentPrivacyWebEngineViewPointer->title()); emit updateDomainSettingsIndicator(currentPrivacyWebEngineViewPointer->domainSettingsName != QLatin1String("")); - emit updateUrlLineEdit(currentPrivacyWebEngineViewPointer->url()); + emit updateUrlLineEdit(currentPrivacyWebEngineViewPointer->currentUrlText); // Update the find text. emit updateFindText(currentPrivacyWebEngineViewPointer->findString, currentPrivacyWebEngineViewPointer->findCaseSensitive); diff --git a/src/widgets/TabWidget.h b/src/widgets/TabWidget.h index b445333..8963df3 100644 --- a/src/widgets/TabWidget.h +++ b/src/widgets/TabWidget.h @@ -130,6 +130,7 @@ public Q_SLOTS: void reloadAndBypassCache() const; void saveArchive(); void stop() const; + void storeCurrentUrlText(const QString &urlText) const; void toggleEasyList() const; void toggleEasyPrivacy() const; void toggleFanboysAnnoyanceList() const; diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index c101c8e..d948104 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -501,6 +501,7 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) bookmarkedActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme(QLatin1String("non-starred-symbolic")), QLineEdit::LeadingPosition); QAction *addOrEditDomainSettingsActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme(QLatin1String("settings-configure"), QIcon::fromTheme(QLatin1String("preferences-desktop"))), QLineEdit::TrailingPosition); + restoreUrlTextActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme(QLatin1String("edit-undo")), QLineEdit::TrailingPosition); // Set the bookmarked action pointer to be checkable. bookmarkedActionPointer->setCheckable(true); @@ -508,6 +509,7 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) // Connect the URL line edit actions. connect(bookmarkedActionPointer, SIGNAL(triggered()), this, SLOT(toggleBookmark())); connect(addOrEditDomainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(addOrEditDomainSettings())); + connect(restoreUrlTextActionPointer, SIGNAL(triggered()), this, SLOT(restoreUrlText())); // Create a find text label pointer. findTextLabelPointer = new QLabel(); @@ -544,6 +546,9 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) // Update the window title. connect(tabWidgetPointer, SIGNAL(updateWindowTitle(const QString)), this, SLOT(updateWindowTitle(const QString))); + // Store the URL line edit when it changes. + connect(urlLineEditPointer, SIGNAL(textChanged(const QString &)), this, SLOT(processUrlTextChanges(const QString &))); + // Get a handle for the status bar. QStatusBar *statusBarPointer = statusBar(); @@ -603,10 +608,12 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) // Create keyboard shortcuts. QShortcut *f11ShortcutPointer = new QShortcut(QKeySequence(i18nc("The toggle full screen shortcut.", "F11")), this); + QShortcut *ctrlShiftRShortcut = new QShortcut(QKeySequence(i18nc("The restore URL text key sequence.", "Ctrl+Shift+R")), this); QShortcut *escapeShortcutPointer = new QShortcut(QKeySequence::Cancel, this); // Connect the keyboard shortcuts. connect(f11ShortcutPointer, SIGNAL(activated()), fullScreenActionPointer, SLOT(trigger())); + connect(ctrlShiftRShortcut, SIGNAL(activated()), restoreUrlTextActionPointer, SLOT(trigger())); connect(escapeShortcutPointer, SIGNAL(activated()), this, SLOT(escape())); // Get a handle for the Bookmarks menu. @@ -1406,6 +1413,15 @@ void BrowserWindow::populateBookmarksToolBarSubfolders(const double folderId, QM } } +void BrowserWindow::processUrlTextChanges(const QString &newUrlText) const +{ + // Update the visibility of the restore URL text action pointer. + restoreUrlTextActionPointer->setVisible(newUrlText != tabWidgetPointer->getCurrentTabUrl()); + + // Store the new URL text in the WebEngine View. + tabWidgetPointer->storeCurrentUrlText(newUrlText); +} + void BrowserWindow::refresh() const { // Remove the focus from the URL line edit. @@ -1424,6 +1440,12 @@ void BrowserWindow::reloadAndBypassCache() const tabWidgetPointer->refresh(); } +void BrowserWindow::restoreUrlText() const +{ + // Restore the URL text to the current URL. + urlLineEditPointer->setText(tabWidgetPointer->getCurrentTabUrl()); +} + void BrowserWindow::showBookmarkContextMenu(const QPoint &point) { // Get the bookmark action. diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index 7564567..a41226c 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -76,8 +76,10 @@ private Q_SLOTS: void openWithChromium() const; void openWithFirefox() const; void populateBookmarksInAllWindows() const; + void processUrlTextChanges(const QString &newUrlText) const; void refresh() const; void reloadAndBypassCache() const; + void restoreUrlText() const; void showBookmarkContextMenu(const QPoint &point); void showCookiesDialog(); void showDomainSettingsDialog(); @@ -160,6 +162,7 @@ private: QProgressBar *progressBarPointer; QAction *refreshActionPointer; QAction *requestsActionPointer; + QAction *restoreUrlTextActionPointer; QAction *searchEngineMenuActionPointer; QAction *searchEngineMojeekActionPointer; QAction *searchEngineMonoclesActionPointer; -- 2.45.2