summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Dywan <christian@twotoasts.de>2019-02-28 19:40:28 +0100
committerGitHub <noreply@github.com>2019-02-28 19:40:28 +0100
commitb6241c3186dee5da6ea6a294969ba31ad314de65 (patch)
tree78e6e48b0664c8dbaaebb1f76752516efa8487ed
parent72e39eef9f65ad3f47a51cd2fa6e6e4acccbcc89 (diff)
downloadmidori-git-b6241c3186dee5da6ea6a294969ba31ad314de65.tar.gz
Use a dialog to handle script confirm/ prompt (#279)
The WebKit API can't cope with asynchronously updating the result. Fixes: #276
-rw-r--r--core/browser.vala41
-rw-r--r--core/tab.vala29
-rw-r--r--ui/tab.ui4
3 files changed, 34 insertions, 40 deletions
diff --git a/core/browser.vala b/core/browser.vala
index 27096385..73d4e008 100644
--- a/core/browser.vala
+++ b/core/browser.vala
@@ -625,26 +625,41 @@ namespace Midori {
tab.print (new WebKit.PrintOperation (tab));
}
- void caret_browsing_activated () {
- var settings = CoreSettings.get_default ();
- if (!settings.enable_caret_browsing) {
- var dialog = new Gtk.Dialog.with_buttons (
- get_settings ().gtk_dialogs_use_header ? null : _("Toggle text cursor navigation"),
- this,
- get_settings ().gtk_dialogs_use_header ? Gtk.DialogFlags.USE_HEADER_BAR : 0,
- Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL,
- _("_Enable Caret Browsing"), Gtk.ResponseType.ACCEPT);
- var label = new Gtk.Label (_("Pressing F7 toggles Caret Browsing. When active, a text cursor appears in all websites."));
+ internal string? prompt (string title, string message, string confirm, string? text=null) {
+ var dialog = new Gtk.Dialog.with_buttons (
+ get_settings ().gtk_dialogs_use_header ? null : (title ?? message),
+ this,
+ get_settings ().gtk_dialogs_use_header ? Gtk.DialogFlags.USE_HEADER_BAR : 0,
+ Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL,
+ confirm, Gtk.ResponseType.ACCEPT);
+ if (message != null) {
+ var label = new Gtk.Label (message);
label.wrap = true;
label.max_width_chars = 33;
label.margin = 8;
label.show ();
dialog.get_content_area ().add (label);
- dialog.set_default_response (Gtk.ResponseType.ACCEPT);
- if (dialog.run () == Gtk.ResponseType.ACCEPT) {
+ }
+ var entry = new Gtk.Entry ();
+ if (text != null) {
+ entry.text = text;
+ entry.show ();
+ dialog.get_content_area ().add (entry);
+ }
+ dialog.set_default_response (Gtk.ResponseType.ACCEPT);
+ string? result = dialog.run () == Gtk.ResponseType.ACCEPT ? (entry.get_text () ?? "") : null;
+ dialog.close ();
+ return result;
+ }
+
+ void caret_browsing_activated () {
+ var settings = CoreSettings.get_default ();
+ if (!settings.enable_caret_browsing) {
+ if (prompt (_("Toggle text cursor navigation"),
+ _("Pressing F7 toggles Caret Browsing. When active, a text cursor appears in all websites."),
+ _("_Enable Caret Browsing")) != null) {
settings.enable_caret_browsing = true;
}
- dialog.close ();
} else {
settings.enable_caret_browsing = false;
}
diff --git a/core/tab.vala b/core/tab.vala
index fd574827..815c5be5 100644
--- a/core/tab.vala
+++ b/core/tab.vala
@@ -37,8 +37,6 @@ namespace Midori {
[GtkChild]
Gtk.Label message;
[GtkChild]
- Gtk.Entry entry;
- [GtkChild]
Gtk.Button confirm;
construct {
@@ -332,37 +330,22 @@ namespace Midori {
}
public override bool script_dialog (WebKit.ScriptDialog dialog) {
- message.label = dialog.get_message ();
-
switch (dialog.get_dialog_type ()) {
case WebKit.ScriptDialogType.ALERT:
+ message.label = dialog.get_message ();
confirm.hide ();
+ popover.show ();
break;
case WebKit.ScriptDialogType.CONFIRM:
case WebKit.ScriptDialogType.BEFORE_UNLOAD_CONFIRM:
- confirm.label = _("_Confirm");
- confirm.visible = true;
- popover.closed.connect (() => {
- dialog.confirm_set_confirmed (false);
- });
- confirm.clicked.connect (() => {
- dialog.confirm_set_confirmed (true);
- });
+ string hostname = new Soup.URI (uri).host;
+ dialog.confirm_set_confirmed(((Browser)get_toplevel ()).prompt (hostname, dialog.get_message (), _("_Confirm")) != null);
break;
case WebKit.ScriptDialogType.PROMPT:
- entry.placeholder_text = dialog.prompt_get_default_text ();
- entry.visible = true;
- confirm.label = _("_Confirm");
- confirm.visible = true;
- popover.closed.connect (() => {
- dialog.prompt_set_text ("");
- });
- confirm.clicked.connect (() => {
- dialog.prompt_set_text (entry.text);
- });
+ string hostname = new Soup.URI (uri).host;
+ dialog.prompt_set_text(((Browser)get_toplevel ()).prompt (hostname, dialog.get_message (), _("_Confirm"), dialog.prompt_get_default_text ()));
break;
}
- popover.show ();
return true;
}
diff --git a/ui/tab.ui b/ui/tab.ui
index d63b1291..f691693a 100644
--- a/ui/tab.ui
+++ b/ui/tab.ui
@@ -15,10 +15,6 @@
</object>
</child>
<child>
- <object class="GtkEntry" id="entry">
- </object>
- </child>
- <child>
<object class="GtkButton" id="confirm">
<property name="focus-on-click">no</property>
<property name="label" translatable="yes">_Confirm</property>