document.rs - icy_draw - icy_draw is the successor to mystic draw. fork / mirror
 (HTM) git clone https://git.drkhsh.at/icy_draw.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       document.rs (2065B)
       ---
            1 use std::path::Path;
            2 
            3 use eframe::egui;
            4 use icy_engine::EngineResult;
            5 
            6 use crate::{model::Tool, AnsiEditor, Commands, Message, TerminalResult};
            7 
            8 pub trait ClipboardHandler {
            9     fn can_cut(&self) -> bool {
           10         false
           11     }
           12     fn cut(&mut self) -> EngineResult<()> {
           13         Ok(())
           14     }
           15 
           16     fn can_copy(&self) -> bool {
           17         false
           18     }
           19     fn copy(&mut self) -> EngineResult<()> {
           20         Ok(())
           21     }
           22 
           23     fn can_paste(&self) -> bool {
           24         false
           25     }
           26     fn paste(&mut self) -> EngineResult<()> {
           27         Ok(())
           28     }
           29 }
           30 
           31 pub trait UndoHandler {
           32     fn undo_description(&self) -> Option<String>;
           33     fn can_undo(&self) -> bool;
           34     /// .
           35     ///
           36     /// # Errors
           37     ///
           38     /// This function will return an error if .
           39     fn undo(&mut self) -> EngineResult<Option<Message>>;
           40 
           41     fn redo_description(&self) -> Option<String>;
           42     fn can_redo(&self) -> bool;
           43     /// .
           44     ///
           45     /// # Errors
           46     ///
           47     /// This function will return an error if .
           48     fn redo(&mut self) -> EngineResult<Option<Message>>;
           49 }
           50 
           51 pub trait Document: UndoHandler + ClipboardHandler {
           52     fn undo_stack_len(&self) -> usize;
           53 
           54     fn default_extension(&self) -> &'static str;
           55 
           56     fn get_bytes(&mut self, path: &Path) -> TerminalResult<Vec<u8>>;
           57 
           58     fn show_ui(&mut self, ui: &mut egui::Ui, cur_tool: &mut Box<dyn Tool>, selected_tool: usize, options: &DocumentOptions) -> Option<Message>;
           59 
           60     fn destroy(&self, gl: &glow::Context) -> Option<Message>;
           61 
           62     fn get_ansi_editor_mut(&mut self) -> Option<&mut AnsiEditor>;
           63     fn get_ansi_editor(&self) -> Option<&AnsiEditor>;
           64 
           65     fn can_paste_char(&self) -> bool {
           66         false
           67     }
           68     fn paste_char(&mut self, _ui: &mut eframe::egui::Ui, _ch: char) {}
           69 
           70     fn inform_save(&mut self) {}
           71 }
           72 
           73 pub struct DocumentOptions {
           74     pub commands: Commands,
           75     pub fit_width: bool,
           76 }
           77 
           78 impl DocumentOptions {
           79     pub fn new() -> Self {
           80         Self {
           81             commands: Commands::default(),
           82             fit_width: false,
           83         }
           84     }
           85 }
           86 
           87 impl Default for DocumentOptions {
           88     fn default() -> Self {
           89         Self::new()
           90     }
           91 }