mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
try autocomplete scheme if the request match local filename
This commit is contained in:
parent
9fe6713bc8
commit
be9e55a4cf
3 changed files with 38 additions and 30 deletions
|
|
@ -129,7 +129,7 @@ impl Window {
|
||||||
action.open.on_activate({
|
action.open.on_activate({
|
||||||
let tab = tab.clone();
|
let tab = tab.clone();
|
||||||
move |position, request| {
|
move |position, request| {
|
||||||
tab.open(position, &request, true);
|
tab.open(position, request, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ impl Open {
|
||||||
// Actions
|
// Actions
|
||||||
|
|
||||||
/// Formatted action connector for external implementation
|
/// Formatted action connector for external implementation
|
||||||
pub fn on_activate(&self, callback: impl Fn(Option<i32>, String) + 'static) -> SignalHandlerId {
|
pub fn on_activate(&self, callback: impl Fn(Option<i32>, &str) + 'static) -> SignalHandlerId {
|
||||||
use gtk::{prelude::FileExt, FileDialog, Window};
|
use gtk::{prelude::FileExt, FileDialog, Window};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
|
@ -80,7 +80,7 @@ impl Open {
|
||||||
} else {
|
} else {
|
||||||
Some(state)
|
Some(state)
|
||||||
},
|
},
|
||||||
format!("file://{}", file.path().unwrap().to_str().unwrap()),
|
file.path().unwrap().to_str().unwrap(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,34 +57,42 @@ impl Client {
|
||||||
snap_history(&self.page, None);
|
snap_history(&self.page, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
// run async resolver to detect Uri, scheme-less host, or search query
|
// try autocomplete scheme if the request match local filename
|
||||||
lookup(&self.profile, request, self.cancellable(), {
|
if std::path::Path::new(&request).exists() {
|
||||||
let driver = self.driver.clone();
|
self.page
|
||||||
let page = self.page.clone();
|
.item_action
|
||||||
move |feature, cancellable, result| {
|
.load
|
||||||
match result {
|
.activate(Some(&format!("file://{request}")), is_snap_history)
|
||||||
// route by scheme
|
} else {
|
||||||
Ok(uri) => match uri.scheme().as_str() {
|
// run async resolver to detect Uri, scheme-less host, or search query
|
||||||
"file" => driver.file.handle(uri, feature, cancellable),
|
lookup(&self.profile, request, self.cancellable(), {
|
||||||
"gemini" | "titan" => driver.gemini.handle(uri, feature, cancellable),
|
let driver = self.driver.clone();
|
||||||
scheme => {
|
let page = self.page.clone();
|
||||||
// no scheme match driver, complete with failure message
|
move |feature, cancellable, result| {
|
||||||
let status = page.content.to_status_failure();
|
match result {
|
||||||
status.set_description(Some(&format!(
|
// route by scheme
|
||||||
"Scheme `{scheme}` yet not supported"
|
Ok(uri) => match uri.scheme().as_str() {
|
||||||
)));
|
"file" => driver.file.handle(uri, feature, cancellable),
|
||||||
page.set_title(&status.title());
|
"gemini" | "titan" => driver.gemini.handle(uri, feature, cancellable),
|
||||||
page.set_progress(0.0);
|
scheme => {
|
||||||
}
|
// no scheme match driver, complete with failure message
|
||||||
},
|
let status = page.content.to_status_failure();
|
||||||
// begin redirection to new address suggested
|
status.set_description(Some(&format!(
|
||||||
Err(uri) => page
|
"Scheme `{scheme}` yet not supported"
|
||||||
.item_action
|
)));
|
||||||
.load
|
page.set_title(&status.title());
|
||||||
.activate(Some(&uri.to_string()), false),
|
page.set_progress(0.0);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// begin redirection to new address suggested
|
||||||
|
Err(uri) => page
|
||||||
|
.item_action
|
||||||
|
.load
|
||||||
|
.activate(Some(&uri.to_string()), false),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get new [Cancellable](https://docs.gtk.org/gio/class.Cancellable.html) by cancel previous one
|
/// Get new [Cancellable](https://docs.gtk.org/gio/class.Cancellable.html) by cancel previous one
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue