Browse Source

handle files with click

b3z 6 months ago
parent
commit
bbe982df65
6 changed files with 16 additions and 7 deletions
  1. BIN
      .DS_Store
  2. 2 0
      index.js
  3. 2 1
      src/database.ts
  4. 2 1
      src/fileHandler.ts
  5. 1 1
      src/htmlRenderer.ts
  6. 9 4
      src/index.ts

BIN
.DS_Store


+ 2 - 0
index.js

@@ -98,8 +98,10 @@ function handleFileDrop(evt) {
     let fileArr = []
     for (let i = 0; i < files.length; i++) {
         fileArr.push(files.item(i).path)
+        editor.value = editor.value + "\nfile://" + files.item(i).name.replace(/ /g, "_")
     }
     ipcRenderer.send('editor:files:save', fileArr);
+
 }
 
 function handleDragOver(evt) {

+ 2 - 1
src/database.ts

@@ -79,7 +79,8 @@ export class Database {
 
     private applyRegex(s: string): string {
         s = s.toLowerCase();
-        s = s.replace(/[.,?!]+/g, "");
+        s = s.replace(/[,?!]+/g, "");
+        //s = s.replace(/.(?!(S[^. ])|d)/, "");
         // s = s.replace(/[\n]+/g, " ");
         console.log(s);
         return s;

+ 2 - 1
src/fileHandler.ts

@@ -11,7 +11,8 @@ import { get } from "config";
 export function copy2archive(filePath: string) {
     // destination.txt will be created or overwritten by default.
     let filePathArr = filePath.split("/");
-    let destination = get("file.archive") + "/" + filePathArr[filePathArr.length - 1];
+    let destination = (get("file.archive") + "/" + filePathArr[filePathArr.length - 1]).replace(/ /g, "_");
+    console.log(destination);
     copyFile(filePath, destination, (err) => {
         if (err) {
             console.log("A copy error accured. Trying again with fixed dir.");

+ 1 - 1
src/htmlRenderer.ts

@@ -10,7 +10,7 @@ export function translate(md: string): string {
 
     md = newline(md);
     md = linkHTTP(md);
-    //md = linkFILE(md);
+    md = linkFILE(md);
     //md = linkHASH(md);
     return md;
 }

+ 9 - 4
src/index.ts

@@ -5,6 +5,7 @@ import { startServer } from "./redisServer";
 import { translate } from "./htmlRenderer";
 import { isValid } from "./validateConfig";
 import { copy2archive } from "./fileHandler";
+import * as config from "config";
 //import { Controller } from "./controller"; // this is how we wanna import dude.
 
 let mainWindow: Electron.BrowserWindow;
@@ -56,13 +57,17 @@ function createWindow() {
     // make links open in os browser by default.
     const handleRedirect = (e: any, url: string) => {
         if (url != mainWindow.webContents.getURL()) {
+            let link = (config.get("file.archive") + "/" + url).replace("file://", "");
             try {
                 e.preventDefault();
-                shell.openExternal(url);
+                if (url.indexOf("http") !== -1) {
+                    shell.openExternal(url);
+                } else {
+                    console.log(link);
+                    shell.openItem(link);
+                }
             } catch (e) {
-                shell.openItem(url);
-            } finally {
-                shell.showItemInFolder(url);
+                console.log(e);
             }
         }
     };