Repository: flxzt/rnote (language: rust)

Issue:
import txt files
Import menu to import txt files



Discussion / hints:
A feature request for importing `docx`/`odt` file already exists (#317), so I'll edit this one to track progress for `txt` file import feature

Fix patch:
diff --git a/crates/rnote-ui/src/appwindow/mod.rs b/crates/rnote-ui/src/appwindow/mod.rs
index 8ef32a9461..34b91e1f6e 100644
--- a/crates/rnote-ui/src/appwindow/mod.rs
+++ b/crates/rnote-ui/src/appwindow/mod.rs
@@ -519,6 +519,12 @@ impl RnAppWindow {
                     )
                     .await?
                 }
+                FileType::PlaintextFile => {
+                    let canvas = appwindow.active_tab_wrapper().canvas();
+                    let (bytes, _) = input_file.load_bytes_future().await?;
+                    canvas.load_in_text(String::from_utf8(bytes.to_vec())?, target_pos)?;
+                    true
+                }
                 FileType::Folder => {
                     if let Some(dir) = input_file.path() {
                         appwindow
diff --git a/crates/rnote-ui/src/dialogs/import.rs b/crates/rnote-ui/src/dialogs/import.rs
index 38739037f6..6f9f16b14c 100644
--- a/crates/rnote-ui/src/dialogs/import.rs
+++ b/crates/rnote-ui/src/dialogs/import.rs
@@ -50,13 +50,15 @@ pub(crate) async fn filedialog_import_file(appwindow: &RnAppWindow) {
     filter.add_mime_type("image/svg+xml");
     filter.add_mime_type("image/png");
     filter.add_mime_type("image/jpeg");
+    filter.add_mime_type("text/plain");
     filter.add_suffix("xopp");
     filter.add_suffix("pdf");
     filter.add_suffix("svg");
     filter.add_suffix("png");
     filter.add_suffix("jpg");
     filter.add_suffix("jpeg");
-    filter.set_name(Some(&gettext("Jpg, Pdf, Png, Svg, Xopp")));
+    filter.add_suffix("txt");
+    filter.set_name(Some(&gettext("Jpg, Pdf, Png, Svg, Xopp, Txt")));
 
     let dialog = FileDialog::builder()
         .title(gettext("Import File"))
diff --git a/crates/rnote-ui/src/filetype.rs b/crates/rnote-ui/src/filetype.rs
index 89f35a2f97..484c4aeab0 100644
--- a/crates/rnote-ui/src/filetype.rs
+++ b/crates/rnote-ui/src/filetype.rs
@@ -10,6 +10,7 @@ pub(crate) enum FileType {
     BitmapImageFile,
     XoppFile,
     PdfFile,
+    PlaintextFile,
     Unsupported,
 }
 
@@ -39,6 +40,9 @@ impl FileType {
                             "application/pdf" => {
                                 return Self::PdfFile;
                             }
+                            "text/plain" => {
+                                return Self::PlaintextFile;
+                            }
                             _ => {}
                         }
                     }
@@ -74,6 +78,9 @@ impl FileType {
                     "pdf" => {
                         return Self::PdfFile;
                     }
+                    "txt" => {
+                        return Self::PlaintextFile;
+                    }
                     _ => {}
                 }
             }


Test patch: