aboutsummaryrefslogtreecommitdiffstats
path: root/components/net
diff options
context:
space:
mode:
Diffstat (limited to 'components/net')
-rw-r--r--components/net/Cargo.toml4
-rw-r--r--components/net/filemanager_thread.rs50
2 files changed, 34 insertions, 20 deletions
diff --git a/components/net/Cargo.toml b/components/net/Cargo.toml
index 013df85f3db..8eba3907a05 100644
--- a/components/net/Cargo.toml
+++ b/components/net/Cargo.toml
@@ -22,8 +22,8 @@ ipc-channel = {git = "https://github.com/servo/ipc-channel"}
lazy_static = "0.2"
log = "0.3.5"
matches = "0.1"
-mime = "0.2.0"
-mime_guess = "1.6.0"
+mime = "0.2.1"
+mime_guess = "1.8.0"
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
openssl = "0.7.6"
diff --git a/components/net/filemanager_thread.rs b/components/net/filemanager_thread.rs
index 6164867c794..9c1cb851dc4 100644
--- a/components/net/filemanager_thread.rs
+++ b/components/net/filemanager_thread.rs
@@ -25,37 +25,51 @@ pub trait FileManagerThreadFactory<UI: 'static + UIProvider> {
}
pub trait UIProvider where Self: Sync {
- fn open_file_dialog(&self, path: &str,
- filter: Option<(&[&str], &str)>) -> Option<String>;
+ fn open_file_dialog(&self, path: &str, patterns: Vec<FilterPattern>) -> Option<String>;
- fn open_file_dialog_multi(&self, path: &str,
- filter: Option<(&[&str], &str)>) -> Option<Vec<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"))]
- fn open_file_dialog(&self, path: &str,
- filter: Option<(&[&str], &str)>) -> Option<String> {
- tinyfiledialogs::open_file_dialog("Pick a file", path, filter)
+ fn open_file_dialog(&self, path: &str, patterns: Vec<FilterPattern>) -> Option<String> {
+ 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"))]
- fn open_file_dialog_multi(&self, path: &str,
- filter: Option<(&[&str], &str)>) -> Option<Vec<String>> {
- tinyfiledialogs::open_file_dialog_multi("Pick files", path, filter)
+ fn open_file_dialog_multi(&self, path: &str, patterns: Vec<FilterPattern>) -> Option<Vec<String>> {
+ 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")))]
- fn open_file_dialog(&self, _path: &str,
- _filter: Option<(&[&str], &str)>) -> Option<String> {
+ fn open_file_dialog(&self, path: &str, patterns: Vec<FilterPattern>) -> Option<String> {
None
}
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
- fn open_file_dialog_multi(&self, _path: &str,
- _filter: Option<(&[&str], &str)>) -> Option<Vec<String>> {
+ fn open_file_dialog_multi(&self, path: &str, patterns: Vec<FilterPattern>) -> Option<Vec<String>> {
None
}
}
@@ -116,9 +130,9 @@ impl<UI: 'static + UIProvider> FileManager<UI> {
}
}
- fn select_file(&mut self, _filter: Vec<FilterPattern>,
+ fn select_file(&mut self, patterns: Vec<FilterPattern>,
sender: IpcSender<FileManagerResult<SelectedFile>>) {
- match self.ui.open_file_dialog("", None) {
+ match self.ui.open_file_dialog("", patterns) {
Some(s) => {
let selected_path = Path::new(&s);
@@ -134,9 +148,9 @@ impl<UI: 'static + UIProvider> FileManager<UI> {
}
}
- fn select_files(&mut self, _filter: Vec<FilterPattern>,
+ fn select_files(&mut self, patterns: Vec<FilterPattern>,
sender: IpcSender<FileManagerResult<Vec<SelectedFile>>>) {
- match self.ui.open_file_dialog_multi("", None) {
+ match self.ui.open_file_dialog_multi("", patterns) {
Some(v) => {
let mut selected_paths = vec![];