Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to open URL with UrlImageTextButton widget? #651

Open
bagomot opened this issue Apr 11, 2023 · 4 comments
Open

How to open URL with UrlImageTextButton widget? #651

bagomot opened this issue Apr 11, 2023 · 4 comments

Comments

@bagomot
Copy link
Contributor

bagomot commented Apr 11, 2023

auto testLink = new UrlImageTextButton("test_link", UIString.fromId("ui.test_link"), "https://google.com", null);

How can I use this code to open the specified url when left clicking on the mouse? I check in Windows, it does nothing by itself. But why then specify the url?

@bagomot
Copy link
Contributor Author

bagomot commented Apr 11, 2023

I solved this problem in this way:

testLink.click = (Widget source) {
import std.process : browse;
browse(source.action.stringParam);
return true;
 };

But is this the right way? I think it should work automatically.

@GrimMaple
Copy link
Collaborator

I looked at it. The code does assign the action properly, but it might not be triggered for some reason. Sounds like a bug to me.

@GrimMaple GrimMaple added the bug label Apr 12, 2023
@GrimMaple
Copy link
Collaborator

I looked at it more closely, and here's what happens:
The action itself is assigned properly and it works as the original author intended. The problem is, you need to handle those actions somewhere. Otherwise the action is dispatched, but never handled. An example can be found here:

contentLayout.onAction = delegate(Widget source, const Action a) {

I don't know what to feel about this design. If I were to try and understand the reasoning behind all this, it's to allow you to handle URL clicks in a non-specific way (eg check for malicious websites or whatnot). I'm thinking this is the intended way for it to work and not a bug.

However, I can also understand that it's expected to work in a different way. Maybe, I can kludge in a way for it to work without any special shenanigans required. This would mean a cross-platform way of opening links is required.

I'm promoting this from bug to enchancement though :)

@GrimMaple GrimMaple added enhancement and removed bug labels Apr 14, 2023
@bagomot
Copy link
Contributor Author

bagomot commented Apr 15, 2023

This would mean a cross-platform way of opening links is required.

This is available in the standard library. Works if the default browser is set in the system. I tested in Windows and Linux (ubuntu, archlinux).

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

No branches or pull requests

2 participants