Fix file drop bug

embed
Manos Pitsidianakis 2018-08-08 20:58:15 +03:00
parent 0c018dd544
commit a3a98f894f
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 17 additions and 6 deletions

View File

@ -150,10 +150,11 @@ impl Component for MailView {
let bottom_right = bottom_right!(area);
let (envelope_idx, y): (usize, usize) = {
let threaded = context.accounts[self.coordinates.0]
let accounts = &mut context.accounts;
let threaded = accounts[self.coordinates.0]
.runtime_settings
.threaded;
let mailbox = &mut context.accounts[self.coordinates.0][self.coordinates.1]
let mailbox = &mut accounts[self.coordinates.0][self.coordinates.1]
.as_ref()
.unwrap();
let envelope_idx: usize = if threaded {
@ -325,10 +326,11 @@ impl Component for MailView {
self.cmd_buf.clear();
{
let threaded = context.accounts[self.coordinates.0]
let accounts = &mut context.accounts;
let threaded = accounts[self.coordinates.0]
.runtime_settings
.threaded;
let mailbox = &mut context.accounts[self.coordinates.0][self.coordinates.1]
let mailbox = &mut accounts[self.coordinates.0][self.coordinates.1]
.as_ref()
.unwrap();
let envelope_idx: usize = if threaded {
@ -366,6 +368,7 @@ impl Component for MailView {
.unwrap_or_else(|_| {
panic!("Failed to start {}", binary.display())
});
context.temp_files.push(p);
} else {
context.replies.push_back(UIEvent {
id: 0,
@ -396,10 +399,11 @@ impl Component for MailView {
let lidx = self.cmd_buf.parse::<usize>().unwrap();
self.cmd_buf.clear();
let url = {
let threaded = context.accounts[self.coordinates.0]
let accounts = &mut context.accounts;
let threaded = accounts[self.coordinates.0]
.runtime_settings
.threaded;
let mailbox = &mut context.accounts[self.coordinates.0][self.coordinates.1]
let mailbox = &mut accounts[self.coordinates.0][self.coordinates.1]
.as_ref()
.unwrap();
let envelope_idx: usize = if threaded {

View File

@ -53,6 +53,7 @@ pub struct Context {
_backends: Backends,
input_thread: chan::Sender<bool>,
pub temp_files: Vec<File>,
}
impl Context {
@ -62,6 +63,9 @@ impl Context {
pub fn input_thread(&mut self) -> &mut chan::Sender<bool> {
&mut self.input_thread
}
pub fn add_temp(&mut self, f: File) -> () {
self.temp_files.push(f);
}
}
/// A State object to manage and own components and entities of the UI. `State` is responsible for
@ -159,6 +163,7 @@ impl State<std::io::Stdout> {
runtime_settings: settings,
dirty_areas: VecDeque::with_capacity(5),
replies: VecDeque::with_capacity(5),
temp_files: Vec::new(),
input_thread,
},

View File

@ -45,6 +45,8 @@ impl File {
}
}
/// Returned `File` will be deleted when dropped, so make sure to add it on `context.temp_files`
/// to reap it later.
pub fn create_temp_file(bytes: &[u8], filename: Option<&PathBuf>) -> File {
let mut dir = std::env::temp_dir();