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
Implement file related functionalities in htmlinputelement and related #11225
Merged
+155
−30
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
| @@ -3,7 +3,9 @@ | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; | ||
| use net_traits::filemanager_thread::{FileManagerThreadMsg, FileManagerResult, FileManagerThreadError}; | ||
| use mime_guess::guess_mime_type_opt; | ||
| use net_traits::filemanager_thread::{FileManagerThreadMsg, FileManagerResult}; | ||
| use net_traits::filemanager_thread::{SelectedFile, FileManagerThreadError}; | ||
| use std::cell::RefCell; | ||
| use std::collections::HashMap; | ||
| use std::fs::File; | ||
| @@ -17,15 +19,13 @@ pub struct FileManager { | ||
| idmap: RefCell<HashMap<Uuid, PathBuf>>, | ||
| } | ||
|
|
||
| impl FileManager { | ||
| fn new(recv: IpcReceiver<FileManagerThreadMsg>) -> FileManager { | ||
| FileManager { | ||
| receiver: recv, | ||
| idmap: RefCell::new(HashMap::new()), | ||
| } | ||
| } | ||
| pub trait FileManagerThreadFactory { | ||
| fn new() -> Self; | ||
| } | ||
|
|
||
| pub fn new_thread() -> IpcSender<FileManagerThreadMsg> { | ||
| impl FileManagerThreadFactory for IpcSender<FileManagerThreadMsg> { | ||
| /// Create a FileManagerThread | ||
| fn new() -> IpcSender<FileManagerThreadMsg> { | ||
| let (chan, recv) = ipc::channel().unwrap(); | ||
|
|
||
| spawn_named("FileManager".to_owned(), move || { | ||
| @@ -34,6 +34,16 @@ impl FileManager { | ||
|
|
||
| chan | ||
| } | ||
| } | ||
|
|
||
|
|
||
| impl FileManager { | ||
| fn new(recv: IpcReceiver<FileManagerThreadMsg>) -> FileManager { | ||
| FileManager { | ||
| receiver: recv, | ||
| idmap: RefCell::new(HashMap::new()), | ||
| } | ||
| } | ||
|
|
||
| /// Start the file manager event loop | ||
| fn start(&mut self) { | ||
| @@ -49,7 +59,7 @@ impl FileManager { | ||
| } | ||
|
|
||
| impl FileManager { | ||
| fn select_file(&mut self, sender: IpcSender<FileManagerResult<(Uuid, PathBuf, u64)>>) { | ||
| fn select_file(&mut self, sender: IpcSender<FileManagerResult<SelectedFile>>) { | ||
| // TODO: Pull the dialog UI in and get selected | ||
| let selected_path = Path::new(""); | ||
|
|
||
| @@ -63,7 +73,7 @@ impl FileManager { | ||
| } | ||
| } | ||
|
|
||
| fn select_files(&mut self, sender: IpcSender<FileManagerResult<Vec<(Uuid, PathBuf, u64)>>>) { | ||
| fn select_files(&mut self, sender: IpcSender<FileManagerResult<Vec<SelectedFile>>>) { | ||
| let selected_paths = vec![Path::new("")]; | ||
|
|
||
| let mut replies = vec![]; | ||
| @@ -81,7 +91,7 @@ impl FileManager { | ||
| let _ = sender.send(Ok(replies)); | ||
| } | ||
|
|
||
| fn create_entry(&mut self, file_path: &Path) -> Option<(Uuid, PathBuf, u64)> { | ||
| fn create_entry(&mut self, file_path: &Path) -> Option<SelectedFile> { | ||
| match File::open(file_path) { | ||
| Ok(handler) => { | ||
| let id = Uuid::new_v4(); | ||
| @@ -100,7 +110,19 @@ impl FileManager { | ||
| let filename = file_path.file_name(); | ||
|
|
||
| match (epoch, filename) { | ||
| (Ok(epoch), Some(filename)) => Some((id, Path::new(filename).to_path_buf(), epoch)), | ||
| (Ok(epoch), Some(filename)) => { | ||
| let filename_path = Path::new(filename); | ||
| let mime = guess_mime_type_opt(filename_path); | ||
izgzhen
Author
Contributor
|
||
| Some(SelectedFile { | ||
| id: id, | ||
| filename: filename_path.to_path_buf(), | ||
| modified: epoch, | ||
| type_string: match mime { | ||
| Some(x) => format!("{}", x), | ||
| None => "".to_string(), | ||
| }, | ||
| }) | ||
| } | ||
| _ => None | ||
| } | ||
| }, | ||
| @@ -27,8 +27,10 @@ impl FileList { | ||
| } | ||
|
|
||
| #[allow(unrooted_must_root)] | ||
| pub fn new(window: &Window, files: Vec<JS<File>>) -> Root<FileList> { | ||
| reflect_dom_object(box FileList::new_inherited(files), GlobalRef::Window(window), FileListBinding::Wrap) | ||
| pub fn new(window: &Window, files: Vec<Root<File>>) -> Root<FileList> { | ||
| reflect_dom_object(box FileList::new_inherited(files.iter().map(|r| JS::from_rooted(&r)).collect()), | ||
Manishearth
Member
|
||
| GlobalRef::Window(window), | ||
| FileListBinding::Wrap) | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
We shouldn't be guessing the MIME here, right?