mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
refactor(filemanager): remove awareness to ui behavior
This commit is contained in:
parent
4125b54c0d
commit
f69b124444
5 changed files with 1 additions and 71 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1920,7 +1920,6 @@ dependencies = [
|
||||||
"servo_url 0.0.1",
|
"servo_url 0.0.1",
|
||||||
"threadpool 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"threadpool 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
"time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"tinyfiledialogs 3.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"uuid 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"uuid 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -49,9 +49,6 @@ url = "1.2"
|
||||||
uuid = {version = "0.6", features = ["v4"]}
|
uuid = {version = "0.6", features = ["v4"]}
|
||||||
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
||||||
|
|
||||||
[target.'cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))'.dependencies]
|
|
||||||
tinyfiledialogs = "3.0"
|
|
||||||
|
|
||||||
[[test]]
|
[[test]]
|
||||||
name = "main"
|
name = "main"
|
||||||
path = "tests/main.rs"
|
path = "tests/main.rs"
|
||||||
|
|
|
@ -21,71 +21,9 @@ use std::sync::atomic::{self, AtomicBool, AtomicUsize, Ordering};
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
|
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
|
||||||
use tinyfiledialogs;
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
/// The provider of file-dialog UI should implement this trait.
|
|
||||||
/// It will be used to initialize a generic FileManager.
|
|
||||||
/// For example, we can choose a dummy UI for testing purpose.
|
|
||||||
pub trait UIProvider where Self: Sync {
|
|
||||||
fn open_file_dialog(&self, path: &str, patterns: Vec<FilterPattern>) -> Option<String>;
|
|
||||||
|
|
||||||
fn open_file_dialog_multi(&self, path: &str, patterns: Vec<FilterPattern>) -> Option<Vec<String>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct TFDProvider;
|
|
||||||
|
|
||||||
impl UIProvider for TFDProvider {
|
|
||||||
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
|
|
||||||
fn open_file_dialog(&self, path: &str, patterns: Vec<FilterPattern>) -> Option<String> {
|
|
||||||
if opts::get().headless {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut filter = vec![];
|
|
||||||
for p in patterns {
|
|
||||||
let s = "*.".to_string() + &p.0;
|
|
||||||
filter.push(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
let filter_ref = &(filter.iter().map(|s| s.as_str()).collect::<Vec<&str>>()[..]);
|
|
||||||
|
|
||||||
let filter_opt = if filter.len() > 0 { Some((filter_ref, "")) } else { None };
|
|
||||||
|
|
||||||
tinyfiledialogs::open_file_dialog("Pick a file", path, filter_opt)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
|
|
||||||
fn open_file_dialog_multi(&self, path: &str, patterns: Vec<FilterPattern>) -> Option<Vec<String>> {
|
|
||||||
if opts::get().headless {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut filter = vec![];
|
|
||||||
for p in patterns {
|
|
||||||
let s = "*.".to_string() + &p.0;
|
|
||||||
filter.push(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
let filter_ref = &(filter.iter().map(|s| s.as_str()).collect::<Vec<&str>>()[..]);
|
|
||||||
|
|
||||||
let filter_opt = if filter.len() > 0 { Some((filter_ref, "")) } else { None };
|
|
||||||
|
|
||||||
tinyfiledialogs::open_file_dialog_multi("Pick files", path, filter_opt)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
|
|
||||||
fn open_file_dialog(&self, _path: &str, _patterns: Vec<FilterPattern>) -> Option<String> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
|
|
||||||
fn open_file_dialog_multi(&self, _path: &str, _patterns: Vec<FilterPattern>) -> Option<Vec<String>> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// FileManagerStore's entry
|
/// FileManagerStore's entry
|
||||||
struct FileStoreEntry {
|
struct FileStoreEntry {
|
||||||
/// Origin of the entry's "creator"
|
/// Origin of the entry's "creator"
|
||||||
|
|
|
@ -37,8 +37,6 @@ extern crate servo_arc;
|
||||||
extern crate servo_config;
|
extern crate servo_config;
|
||||||
extern crate servo_url;
|
extern crate servo_url;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
|
|
||||||
extern crate tinyfiledialogs;
|
|
||||||
extern crate unicase;
|
extern crate unicase;
|
||||||
extern crate url;
|
extern crate url;
|
||||||
extern crate uuid;
|
extern crate uuid;
|
||||||
|
|
|
@ -11,7 +11,7 @@ use devtools_traits::DevtoolsControlMsg;
|
||||||
use embedder_traits::resources::{self, Resource};
|
use embedder_traits::resources::{self, Resource};
|
||||||
use fetch::cors_cache::CorsCache;
|
use fetch::cors_cache::CorsCache;
|
||||||
use fetch::methods::{CancellationListener, FetchContext, fetch};
|
use fetch::methods::{CancellationListener, FetchContext, fetch};
|
||||||
use filemanager_thread::{FileManager, TFDProvider};
|
use filemanager_thread::FileManager;
|
||||||
use hsts::HstsList;
|
use hsts::HstsList;
|
||||||
use http_cache::HttpCache;
|
use http_cache::HttpCache;
|
||||||
use http_loader::{HttpState, http_redirect_fetch};
|
use http_loader::{HttpState, http_redirect_fetch};
|
||||||
|
@ -47,8 +47,6 @@ use std::thread;
|
||||||
use storage_thread::StorageThreadFactory;
|
use storage_thread::StorageThreadFactory;
|
||||||
use websocket_loader;
|
use websocket_loader;
|
||||||
|
|
||||||
const TFD_PROVIDER: &'static TFDProvider = &TFDProvider;
|
|
||||||
|
|
||||||
/// Returns a tuple of (public, private) senders to the new threads.
|
/// Returns a tuple of (public, private) senders to the new threads.
|
||||||
pub fn new_resource_threads(user_agent: Cow<'static, str>,
|
pub fn new_resource_threads(user_agent: Cow<'static, str>,
|
||||||
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
|
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue