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

WIP - Added prompt user for url #17062

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

# This is a combination of 2 commits.

# The first commit's message is:

Added prompt user for url

Fix Cargo.lock corrupted problem

Refactored event handler for CTRL + L

Made sanitize_and_parse_url() handle correctly parse errors

# This is the commit message #2:

Made the prompt default to the current url
  • Loading branch information
jklepatch committed Jun 4, 2017
commit e960bc1324203b44c3439e906b285d057f559642

Some generated files are not rendered by default. Learn more.

@@ -22,6 +22,7 @@ servo_geometry = {path = "../../components/geometry"}
servo_config = {path = "../../components/config"}
servo_url = {path = "../../components/url"}
style_traits = {path = "../../components/style_traits"}
tinyfiledialogs = "2.5.9"
webrender_traits = {git = "https://github.com/servo/webrender", features = ["ipc"]}

[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]
@@ -22,6 +22,7 @@ extern crate servo_config;
extern crate servo_geometry;
extern crate servo_url;
extern crate style_traits;
extern crate tinyfiledialogs;
extern crate webrender_traits;

#[cfg(target_os = "windows")] extern crate winapi;
@@ -12,6 +12,7 @@ use euclid::{Point2D, Size2D, TypedPoint2D};
use euclid::rect::TypedRect;
use euclid::scale_factor::ScaleFactor;
use euclid::size::TypedSize2D;
use tinyfiledialogs;
#[cfg(target_os = "windows")]
use gdi32;
use gleam::gl;
@@ -1268,12 +1269,33 @@ impl WindowMethods for Window {
self.event_queue.borrow_mut().push(WindowEvent::Reload);
}
}
//On windows 8.1 when pressing ctrl + anything, ch = Some('\u{unicode_value}')

This comment has been minimized.

@paulrouget

paulrouget May 27, 2017

Contributor

We need to investigate that before merging this PR.

//so matching ch with Some('l') doesn't work here
//Instead we match with what's inside the key variable
(CMD_OR_CONTROL, _, Key::L) => {
if let Some(true) = PREFS.get("shell.builtin-key-shortcuts.enabled").as_boolean() {
let fallback_url: String = if let Some(ref current_url) = *self.current_url.borrow() {
current_url.to_string()
} else {
String::from("Your URL here")
};
//TODO:
// 1) make it work when clicking on "validate" button - Currently only works when pressing enter

This comment has been minimized.

@paulrouget

paulrouget May 27, 2017

Contributor

Maybe it has to do with the fact we're blocking the main thread.
On Mac, the buttons work, but we get the beatchball.

Maybe this code should run in a different thread.

// 2) Erratic behavior - sometime the dialog reloads empty after pressing enter
// (windows 8.1)
if let Some(user_input) = tinyfiledialogs::input_box("Enter a URL", "URL:", &fallback_url) {
if let Ok(sanitized_url) = sanitize_and_parse_url(user_input) {
//Maybe need to change WindowEvent::LoadUrl() to accept a ServoUrl instead of a String?
self.event_queue.borrow_mut().push(WindowEvent::LoadUrl(sanitized_url.to_string()));
}
}

This comment has been minimized.

@paulrouget

paulrouget May 27, 2017

Contributor

You can simplify all of this with a if let Some(…) expression. No match needed, an no need to have this intermediate user_input value.

This comment has been minimized.

@paulrouget

paulrouget May 27, 2017

Contributor

Let me know if you need help here.

}
}
(CMD_OR_CONTROL, Some('q'), _) => {
if let Some(true) = PREFS.get("shell.builtin-key-shortcuts.enabled").as_boolean() {
self.event_queue.borrow_mut().push(WindowEvent::Quit);
}
}

_ => {
self.platform_handle_key(key, mods);
}
@@ -1402,6 +1424,10 @@ fn is_printable(key_code: VirtualKeyCode) -> bool {
}
}

fn sanitize_and_parse_url(url: String) -> Result<ServoUrl, ()> {

This comment has been minimized.

@paulrouget

paulrouget May 29, 2017

Contributor

Actually, we might want to use ParseError for now instead of an empty error.

ServoUrl::parse(url.trim()).map_err(|_| ())
}

#[cfg(not(target_os = "windows"))]
fn filter_nonprintable(ch: char, key_code: VirtualKeyCode) -> Option<char> {
if is_printable(key_code) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.