Skip to content

Commit

Permalink
refactor(filemanager): remove awareness to ui behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Apr 27, 2018
1 parent 4125b54 commit f69b124
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 71 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions components/net/Cargo.toml
Expand Up @@ -49,9 +49,6 @@ url = "1.2"
uuid = {version = "0.6", features = ["v4"]}
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]]
name = "main"
path = "tests/main.rs"
62 changes: 0 additions & 62 deletions components/net/filemanager_thread.rs
Expand Up @@ -21,71 +21,9 @@ use std::sync::atomic::{self, AtomicBool, AtomicUsize, Ordering};
use std::sync::mpsc::Sender;
use std::thread;
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
use tinyfiledialogs;
use url::Url;
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
struct FileStoreEntry {
/// Origin of the entry's "creator"
Expand Down
2 changes: 0 additions & 2 deletions components/net/lib.rs
Expand Up @@ -37,8 +37,6 @@ extern crate servo_arc;
extern crate servo_config;
extern crate servo_url;
extern crate time;
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
extern crate tinyfiledialogs;
extern crate unicase;
extern crate url;
extern crate uuid;
Expand Down
4 changes: 1 addition & 3 deletions components/net/resource_thread.rs
Expand Up @@ -11,7 +11,7 @@ use devtools_traits::DevtoolsControlMsg;
use embedder_traits::resources::{self, Resource};
use fetch::cors_cache::CorsCache;
use fetch::methods::{CancellationListener, FetchContext, fetch};
use filemanager_thread::{FileManager, TFDProvider};
use filemanager_thread::FileManager;
use hsts::HstsList;
use http_cache::HttpCache;
use http_loader::{HttpState, http_redirect_fetch};
Expand Down Expand Up @@ -47,8 +47,6 @@ use std::thread;
use storage_thread::StorageThreadFactory;
use websocket_loader;

const TFD_PROVIDER: &'static TFDProvider = &TFDProvider;

/// Returns a tuple of (public, private) senders to the new threads.
pub fn new_resource_threads(user_agent: Cow<'static, str>,
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
Expand Down

0 comments on commit f69b124

Please sign in to comment.