Skip to content
This repository has been archived by the owner on Dec 25, 2022. It is now read-only.

Context menu for links #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

elcuco
Copy link
Contributor

@elcuco elcuco commented Sep 7, 2022

This patch implements a context menu for links. In the future, we could even check for the modifiers and open links in new windows, or private windows - but not today.

Copy link

@faxe1008 faxe1008 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the commit message and title can be improved:

https://github.com/SerenityOS/serenity/blob/master/CONTRIBUTING.md#human-language-policy

I am not sure if this covered by Write in an authoritative and technical tone. but I think that the commit messages should not contain self references "I did" etc.

Tab.cpp Outdated Show resolved Hide resolved
@elcuco elcuco force-pushed the link-submenus branch 2 times, most recently from 2e33ec1 to 9d27920 Compare September 11, 2022 21:25
@huwdp
Copy link

huwdp commented Sep 13, 2022

I think something like this would be good for the back button so users can go back x number of pages in the history. A lot of pages are redirects and they stop me from going back a few pages. I'm looking at this myself but my Qt skills are very rusty.

@elcuco elcuco force-pushed the link-submenus branch 2 times, most recently from e817495 to 353c900 Compare September 19, 2022 19:41
@elcuco
Copy link
Contributor Author

elcuco commented Sep 19, 2022

Rebased against main

@elcuco
Copy link
Contributor Author

elcuco commented Sep 23, 2022

Rebased against main. Fixed the code standards.

@elcuco
Copy link
Contributor Author

elcuco commented Sep 25, 2022

Rebased against main.

@elcuco
Copy link
Contributor Author

elcuco commented Nov 11, 2022

rebased against main.

Copy link
Contributor

@ADKaster ADKaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message is missing a category, which will make it harder to pull into the serenity repo at a later date.

WebContentView.cpp Show resolved Hide resolved
Utilities.cpp Outdated
return QUrl(qstring_from_akstring(akurl.to_string()));
}

QPoint IntPoint_to_QPoint(Gfx::IntPoint const& position)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this Snakey_Camel_Case doesn't match our coding style.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d8bf10f - ammended previous commit. Got it.

Tab.cpp Outdated
Comment on lines 105 to 106
auto copy_link_action = new QAction(tr("Copy Link"));
auto open_link_in_tab_action = new QAction(tr("Open link in a new tab"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't been internationalizing anything in the serenity family of projects so far, and I don't see a reason to start now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separately, is there a way to tell Qt that we want a keyboard shortcut for these actions as well? I would expect us to have the actions for copy and paste stashed on the Tab or the BrowserWindow and just reference them here in this menu. I believe that's what the Serenity Browser implementation does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding i18n/l10n - I don't see a problem. When this project (which is not "strictly" tied to serenityOS) gets more stable - it will need. While I understand that this is not an issue now - it should not be a negative blocker.

Regarding shorthcuts, yes. Its a second argument something like QAction(tr(), "Ctrl+V") (or other overloads). But you cannot use global actions, as these actions are "per link" or per "click". I added accelerators to the actions (&New tab).

d8bf10f - ammended previous commit.

BrowserWindow.cpp Outdated Show resolved Hide resolved
Utilities.cpp Outdated Show resolved Hide resolved
BrowserWindow.cpp Outdated Show resolved Hide resolved
@elcuco
Copy link
Contributor Author

elcuco commented Nov 13, 2022

Rebased against main (upstream added full screen support)

@@ -282,9 +282,17 @@ void BrowserWindow::debug_request(String const& request, String const& argument)
}

void BrowserWindow::new_tab()
{
auto tab = make<Tab>(this, m_webdriver_fd_passing_socket);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? This will just go out of scope immediately

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is the ways its coded currently on main, I just copied into a new function. The the original context:

https://github.com/SerenityOS/ladybird/blob/e523b001bf6a66ec895350beca56e95ec6e27526/BrowserWindow.cpp#L286-L295

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is new_tab should now just be:

void BrowserWindow::new_tab()
{
    new_tab_with_url({});
}

Because new_tab_with_url is now the thing that calls make<Tab>(...) and pushes the result onto m_tabs to keep it alive. The invocation you've left here is now going to go out of scope immediately after returning and is a waste.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

38f256d - got it

Tab.cpp Outdated
if (res == copy_link_action) {
QClipboard *clipboard = QGuiApplication::clipboard();
clipboard->setText(url.toString());
qDebug() << "Copied to clipboard text:" << url.toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use dbgln if we really need this log, otherwise let's not have it at all (or put it behind a dbgln_if)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed that debug. No problem.

Tab.cpp Outdated
Comment on lines 105 to 104
auto copy_link_action = new QAction(tr("&Copy Link"));
auto open_link_in_tab_action = new QAction(tr("Open link in a &new tab"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use auto* when the type is a pointer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done,

Tab.cpp Outdated
qDebug() << "Copied to clipboard text:" << url.toString();
} else if (res == open_link_in_tab_action){
auto browser_window = static_cast<BrowserWindow*>(m_window);
return browser_window->new_tab_with_url(url);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return is useless here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I am unaware how this even compiles.

Utilities.cpp Outdated
@@ -45,3 +57,4 @@ void platform_init()
}();
#endif
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this - please be sure to always run clang-format on files, which would've removed this superfluous newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run another commit - with clang-format on all the code, This should be the second commit on this PR.

@elcuco elcuco force-pushed the link-submenus branch 2 times, most recently from b4636bd to 5da693c Compare November 15, 2022 11:34
@elcuco elcuco requested review from trflynn89 and faxe1008 and removed request for ADKaster, trflynn89 and faxe1008 November 15, 2022 11:34
@elcuco elcuco requested review from trflynn89 and ADKaster and removed request for trflynn89 November 17, 2022 05:35
This patch implements a context menu for links. In the future, we could
even check for the modifiers and open links in new windows, or private
windows - but not today.
This was too noisy IMHO - all project got cleaned up.

Will also force-close this PR: LadybirdBrowser#76
@elcuco
Copy link
Contributor Author

elcuco commented Nov 24, 2022

rebased against main

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants