mirror of https://codeberg.org/topola/topola.git
egui: get rid of overabstraction file_handler::push_file_to_read
This commit is contained in:
parent
25a692aab9
commit
4fef94a5c5
|
|
@ -46,19 +46,7 @@ impl io::BufRead for FileHandlerData {
|
|||
fhd_forward!(fn consume(&mut self, amt: usize));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn push_file_to_read<R, E, C>(
|
||||
file_handle: &rfd::FileHandle,
|
||||
sender: Sender<Result<R, E>>,
|
||||
callback: C,
|
||||
) where
|
||||
E: From<std::io::Error>,
|
||||
C: FnOnce(FileHandlerData) -> Result<R, E>,
|
||||
{
|
||||
let _ = sender.send(handle_text(&file_handle, callback).await);
|
||||
}
|
||||
|
||||
async fn handle_text<R, E, C>(file_handle: &rfd::FileHandle, callback: C) -> Result<R, E>
|
||||
pub async fn handle_file<R, E, C>(file_handle: &rfd::FileHandle, callback: C) -> Result<R, E>
|
||||
where
|
||||
E: From<std::io::Error>,
|
||||
C: FnOnce(FileHandlerData) -> Result<R, E>,
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use crate::{
|
|||
action::{Action, Switch, Trigger},
|
||||
activity::{ActivityStatus, ActivityStepperWithStatus},
|
||||
app::execute,
|
||||
file_handler::{push_file_to_read, FileHandlerData},
|
||||
file_handler::{handle_file, FileHandlerData},
|
||||
overlay::Overlay,
|
||||
translator::Translator,
|
||||
viewport::Viewport,
|
||||
|
|
@ -243,10 +243,9 @@ impl MenuBar {
|
|||
|
||||
execute(async move {
|
||||
if let Some(file_handle) = task.await {
|
||||
push_file_to_read(&file_handle, content_sender, |data| {
|
||||
content_sender.send(handle_file(&file_handle, |data| {
|
||||
SpecctraDesign::load(data)
|
||||
})
|
||||
.await;
|
||||
}).await);
|
||||
ctx.request_repaint();
|
||||
}
|
||||
});
|
||||
|
|
@ -285,14 +284,13 @@ impl MenuBar {
|
|||
|
||||
execute(async move {
|
||||
if let Some(file_handle) = task.await {
|
||||
push_file_to_read(&file_handle, history_sender, |data| {
|
||||
history_sender.send(handle_file(&file_handle, |data| {
|
||||
match serde_json::from_reader(data) {
|
||||
Ok(history) => Ok(Ok(history)),
|
||||
Err(err) if err.is_io() => Err(err.into()),
|
||||
Err(err) => Ok(Err(err)),
|
||||
}
|
||||
})
|
||||
.await;
|
||||
}).await);
|
||||
ctx.request_repaint();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue