diff --git a/Cargo.lock b/Cargo.lock index 960e417965647452d56f5cf36a81ac1f61b8acc7..73ac304cfc1d31801e91777573bff068a2605dea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,15 +7,15 @@ dependencies = [ "html5ever-atoms 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "mime_guess 1.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "orbclient 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "orbfont 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "orbimage 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", - "orbtk 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "orbtk 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "tendril 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "userutils 0.1.0 (git+https://github.com/redox-os/userutils.git)", @@ -29,7 +29,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "arg_parser" version = "0.1.0" -source = "git+https://github.com/redox-os/arg-parser.git#1b6a9505a1e9c39af1836ecbee293a987619a539" +source = "git+https://github.com/redox-os/arg-parser.git#288d2fd9ae27ed2c7a3aaf5a77cf07e2b2bd356c" [[package]] name = "argon2rs" @@ -357,7 +357,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.29" +version = "0.2.30" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -484,7 +484,7 @@ name = "num_cpus" version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -497,7 +497,7 @@ name = "orbclient" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "sdl2 0.29.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -522,7 +522,7 @@ dependencies = [ [[package]] name = "orbtk" -version = "0.2.20" +version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "orbclient 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -591,7 +591,7 @@ name = "rand" version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", "magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -619,7 +619,7 @@ dependencies = [ "coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -629,12 +629,12 @@ name = "redox_event" version = "0.1.0" source = "git+https://github.com/redox-os/event.git#42d552e4765efbfb4ec39ce174900d3f48548a70" dependencies = [ - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.30" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -642,7 +642,7 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -657,9 +657,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -676,7 +676,7 @@ dependencies = [ "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -712,7 +712,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "sdl2-sys 0.27.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -723,7 +723,7 @@ name = "sdl2-sys" version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -796,8 +796,8 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -807,8 +807,8 @@ version = "0.1.38" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -863,7 +863,7 @@ dependencies = [ [[package]] name = "untrusted" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -886,7 +886,7 @@ dependencies = [ "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", "liner 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -916,7 +916,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -924,7 +924,7 @@ name = "webpki-roots" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -982,7 +982,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" -"checksum libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "8a014d9226c2cc402676fbe9ea2e15dd5222cd1dd57f576b5b283178c944a264" +"checksum libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)" = "2370ca07ec338939e356443dac2296f581453c35fe1e3a3ed06023c49435f915" "checksum liner 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f9e406164c25b420480023985bdf65cef366855666ad4cb12cd3eaee82dcb399" "checksum linked-hash-map 0.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "f26e961e0c884309cd527b1402a5409d35db612b36915d755e1a4f5c1547a31c" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" @@ -1004,7 +1004,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum orbclient 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "9411f6bf9f60d65de1dcb601735ac0c904960f0f6ca03a13e6f02d25f842ea2c" "checksum orbfont 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "da4dfbc851e5c24c3cf1e16ec5222f868f3362d2b7493d0b53051fe2669267a2" "checksum orbimage 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "c3b031607ef7a3c562949dfb595b1ea2b2d697b14544af407242a52dce811a6f" -"checksum orbtk 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "19f5608c689e389bf96f7c3c31a179971caa58f3b8b8e494f5af80d2064f45ff" +"checksum orbtk 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)" = "dd69cce571b4a8496073e10012fb212e9e7879c9c770914d412099f3a44839bc" "checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356" "checksum phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "cb325642290f28ee14d8c6201159949a872f220c62af6e110a56ea914fbe42fc" "checksum phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "d62594c0bb54c464f633175d502038177e90309daf2e0158be42ed5f023ce88f" @@ -1017,7 +1017,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rayon 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b614fe08b6665cb9a231d07ac1364b0ef3cb3698f1239ee0c4c3a88a524f54c8" "checksum rayon-core 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7febc28567082c345f10cddc3612c6ea020fc3297a1977d472cf9fdb73e6e493" "checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "<none>" -"checksum redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)" = "8312fba776a49cf390b7b62f3135f9b294d8617f7a7592cfd0ac2492b658cd7b" +"checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum resize 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e8f5c5cf4d79776ed121e1c5052718b4bb06d2b48049144a2f0e5ad613b608e" "checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724" @@ -1047,7 +1047,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2ae5ddb18e1c92664717616dd9549dde73f539f01bd7b77c2edb2446bdff91" -"checksum untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6b65243989ef6aacd9c0d6bd2b822765c3361d8ed352185a6f3a41f3a718c673" +"checksum untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f392d7819dbe58833e26872f5f6f0d68b7bbbe90fc3667e98731c4a15ad9a7ae" "checksum url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb819346883532a271eb626deb43c4a1bb4c4dd47c519bd78137c3e72a4fe27" "checksum userutils 0.1.0 (git+https://github.com/redox-os/userutils.git)" = "<none>" "checksum utf-8 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9aee9ba280438b56d1ebc5329f2094f0ff457f811eeeff0b278d75aa99db400" diff --git a/src/editor/main.rs b/src/editor/main.rs index b888d81960ddc140e6f13d10ac0b1283e286e9c7..1615e1f60d11325533eacca7927cbcb01741fc0e 100644 --- a/src/editor/main.rs +++ b/src/editor/main.rs @@ -5,6 +5,7 @@ extern crate orbtk; use orbclient::WindowFlag; use orbtk::{Action, Button, Menu, Point, Rect, Separator, TextBox, Window}; +use orbtk::dialogs::FileDialog; use orbtk::traits::{Click, Enter, Place, Resize, Text}; use std::{cmp, env}; @@ -12,17 +13,18 @@ use std::cell::RefCell; use std::fs::File; use std::io::{Read, Write}; use std::ops::DerefMut; +use std::path::{Path, PathBuf}; use std::rc::Rc; use std::sync::Arc; pub struct Editor { - path_option: Option<String>, + path_option: Option<PathBuf>, text_box: Arc<TextBox>, window: *mut Window, } impl Editor { - pub fn new(path_option: Option<String>, width: u32, height: u32) -> Box<Window> { + pub fn new(path_option: Option<PathBuf>, width: u32, height: u32) -> Box<Window> { // DESIGN { let mut window = Box::new(Window::new_flags(Rect::new(-1, -1, width, height), "Editor", &[WindowFlag::Resizable])); @@ -75,15 +77,20 @@ impl Editor { open_action.on_click(move |_action: &Action, _point: Point| { println!("Open"); - let mut window = { - let editor_dialog = editor_cell.clone(); - editor_cell.borrow_mut().path_dialog("Open", move |path| { - println!("Open {}", path); - editor_dialog.borrow_mut().open(&path); - }) - }; + let mut dialog = FileDialog::new(); + dialog.title = "Open File".to_string(); + if let Some(ref path) = editor_cell.borrow().path_option { + if let Ok(canon) = path.canonicalize() { + if let Some(parent) = canon.parent() { + dialog.path = parent.to_owned(); + } + } + } - window.exec(); + if let Some(path) = dialog.exec() { + println!("Open {}", path.display()); + editor_cell.borrow_mut().open(&path); + } }); } @@ -179,7 +186,9 @@ impl Editor { // CODE { if let Some(ref path) = self.path_option { - text_box.text.set(path.clone()); + if let Some(path_str) = path.to_str() { + text_box.text.set(path_str.to_string()); + } } { @@ -215,7 +224,7 @@ impl Editor { fn load(&mut self) { if let Some(ref path) = self.path_option { - println!("Load {}", path); + println!("Load {}", path.display()); match File::open(path) { Ok(mut f) => { let mut contents = String::new(); @@ -224,12 +233,12 @@ impl Editor { self.text_box.text.set(contents); }, Err(e) => { - println!("Failed to read {}: {}", path, e); + println!("Failed to read {}: {}", path.display(), e); } } }, Err(e) => { - println!("Failed to open {}: {}", path, e); + println!("Failed to open {}: {}", path.display(), e); } } } else { @@ -239,37 +248,37 @@ impl Editor { fn save(&mut self) { if let Some(ref path) = self.path_option { - println!("Save {}", path); + println!("Save {}", path.display()); match File::create(path) { Ok(mut file) => { let text = self.text_box.text.borrow(); match file.write(&text.as_bytes()) { Ok(_) => match file.set_len(text.len() as u64) { - Ok(_) => println!("Successfully saved {}", path), - Err(err) => println!("Failed to truncate {}: {}", path, err) + Ok(_) => println!("Successfully saved {}", path.display()), + Err(err) => println!("Failed to truncate {}: {}", path.display(), err) }, - Err(err) => println!("Failed to write {}: {}", path, err) + Err(err) => println!("Failed to write {}: {}", path.display(), err) } }, - Err(err) => println!("Failed to open {}: {}", path, err) + Err(err) => println!("Failed to open {}: {}", path.display(), err) } } else { println!("Path not set"); } } - fn set_path(&mut self, path: &str) { - self.path_option = Some(path.to_string()); + fn set_path<P: AsRef<Path>>(&mut self, path: P) { + self.path_option = Some(path.as_ref().to_owned()); let window = unsafe { &mut *self.window }; - window.set_title(&format!("{} - Editor", path)); + window.set_title(&format!("{} - Editor", path.as_ref().display())); } - fn open(&mut self, path: &str) { + fn open<P: AsRef<Path>>(&mut self, path: P) { self.set_path(path); self.load(); } - fn save_as(&mut self, path: &str) { + fn save_as<P: AsRef<Path>>(&mut self, path: P) { self.set_path(path); self.save(); } @@ -281,7 +290,7 @@ impl Editor { } fn main(){ - let path_option = env::args().nth(1); + let path_option = env::args().nth(1).map(PathBuf::from); let (display_width, display_height) = orbclient::get_display_size().expect("viewer: failed to get display size"); let (width, height) = (cmp::min(1024, display_width * 4/5), cmp::min(768, display_height * 4/5));