|
1 | 1 | <template>
|
2 | 2 | <div id="NavBar">
|
3 | 3 | <div id="controls">
|
4 |
| - <a v-on:click="close()"><i class="fas fa-window-close"></i></a> |
| 4 | + <a v-on:click="close()"> |
| 5 | + <i class="fas fa-window-close"></i> |
| 6 | + </a> |
5 | 7 | <!-- <a v-on:click="restore()"><i class="fas fa-window-restore"></i></a> -->
|
6 |
| - <a v-on:click="minimize()"><i class="fas fa-minus-square"></i></a> |
7 |
| - <a v-on:click="pin()"><i class="fas fa-thumbtack"></i></a> |
| 8 | + <a v-on:click="minimize()"> |
| 9 | + <i class="fas fa-minus-square"></i> |
| 10 | + </a> |
| 11 | + <a v-on:click="pin()"> |
| 12 | + <i class="fas fa-thumbtack"></i> |
| 13 | + </a> |
8 | 14 | </div>
|
9 | 15 | <input v-on:change="updateFileName" v-model="fileName" type="text" name="fileName">
|
10 | 16 | <select
|
11 |
| - v-on:change="changeFile" |
| 17 | + v-on:change="changeFile()" |
12 | 18 | v-model="SelectedFile"
|
13 | 19 | id="filePicker"
|
14 | 20 | style="margin-left:20px;"
|
15 | 21 | name="selectedFile"
|
16 | 22 | >
|
17 |
| - <option v-for="file in Files()" :value="file.value" :key="file.id" :id=file.id >{{ file.value }}</option> |
| 23 | + <option |
| 24 | + v-for="file in Files()" |
| 25 | + :value="file.value" |
| 26 | + :key="file.id" |
| 27 | + :id="file.id" |
| 28 | + >{{ file.value }}</option> |
18 | 29 | </select>
|
19 |
| - <a v-on:click="newNote()"><i class="fas fa-file-medical"></i></a> |
20 |
| - <a v-on:click="deleteNote()"><i class="fas fa-trash"></i></a> |
| 30 | + <a v-on:click="newNote()"> |
| 31 | + <i class="fas fa-file-medical"></i> |
| 32 | + </a> |
| 33 | + <a v-on:click="deleteNote()"> |
| 34 | + <i class="fas fa-trash"></i> |
| 35 | + </a> |
21 | 36 | </div>
|
22 | 37 | </template>
|
23 | 38 |
|
24 | 39 | <script lang="ts">
|
25 | 40 | import { Component, Prop, Vue } from "vue-property-decorator";
|
26 |
| -import * as fs from "fs"; |
| 41 | +import {unlink, writeFile, readdirSync} from "fs"; |
27 | 42 | import * as path from "path";
|
28 |
| -import Configuration from '@/utility/Configuration'; |
29 |
| -const remote = require('electron').remote; |
| 43 | +import Configuration from "@/utility/Configuration"; |
| 44 | +import VueEmitter from "@/utility/VueEmitter"; |
| 45 | +const remote = require("electron").remote; |
| 46 | +const defaultNoteText = |
| 47 | + "# Welcome to your new note!\nLet's write something awesome."; |
30 | 48 |
|
31 | 49 | @Component
|
32 |
| -export default class NavBar extends Vue { |
| 50 | +export default class NavBar extends VueEmitter { |
33 | 51 | private fileName: string = "";
|
34 | 52 | private SelectedFile = "";
|
35 | 53 | private isMaximized = false;
|
36 |
| - updateFileName() { |
37 |
| - this.$root.$emit("fileNameUpdated", this.fileName); |
| 54 | + private configuration; |
| 55 | +
|
| 56 | + private Files() { |
| 57 | + return readdirSync("notes").map((v, i) => { |
| 58 | + return { id: i, value: v }; |
| 59 | + }); |
| 60 | + } |
| 61 | +
|
| 62 | + public mounted() { |
| 63 | + Configuration.getConfig().then(c => { |
| 64 | + this.configuration = c; |
| 65 | + this.registerEvents(); |
| 66 | + }); |
38 | 67 | }
|
39 |
| - changeFile() { |
40 |
| - this.$root.$emit("fileChange", this.SelectedFile); |
| 68 | +
|
| 69 | + private updateFileName() { |
| 70 | + this.rootEmit("fileNameUpdated", this.fileName); |
41 | 71 | }
|
42 |
| - mounted() { |
43 |
| - this.registerEvents(); |
| 72 | + private changeFile() { |
| 73 | + this.rootEmit("fileChange", this.SelectedFile); |
44 | 74 | }
|
45 |
| - |
| 75 | +
|
46 | 76 | private registerEvents() {
|
47 |
| - this.$root.$on("fileLoaded", (f: string) => { |
| 77 | + this.$root.$on("fileLoaded", f => { |
| 78 | + console.log("Test"); |
48 | 79 | this.fileName = f;
|
49 | 80 | this.SelectedFile = this.fileName + ".md";
|
50 | 81 | });
|
51 | 82 | }
|
52 | 83 |
|
53 |
| - Files(){ |
54 |
| - return fs.readdirSync("notes").map((v, i) =>{ return { id: i, value: v }}); |
| 84 | + private restore() { |
| 85 | + this.isMaximized |
| 86 | + ? remote.getCurrentWindow().unmaximize() |
| 87 | + : remote.getCurrentWindow().maximize(); |
| 88 | + this.isMaximized = !this.isMaximized; |
55 | 89 | }
|
56 |
| - // private readNotes(callback?){ |
57 |
| - // fs.readdir("notes", (e, f) => { |
58 |
| - // this.Files = f.map((v, i) => { |
59 |
| - // return { id: i, value: v }; |
60 |
| - // }); |
61 |
| - // callback() |
62 |
| - // }); |
63 |
| - // } |
64 | 90 |
|
65 |
| - close() { |
66 |
| - this.$root.$emit("closing"); |
| 91 | + private pin() { |
| 92 | + remote |
| 93 | + .getCurrentWindow() |
| 94 | + .setAlwaysOnTop(!remote.getCurrentWindow().isAlwaysOnTop()); |
67 | 95 | }
|
68 | 96 |
|
69 |
| - pin(){ |
70 |
| - const remote = require('electron').remote; |
71 |
| - let w = remote.getCurrentWindow(); |
72 |
| - w.setAlwaysOnTop(!w.isAlwaysOnTop()) |
73 |
| - } |
74 |
| - restore(){ |
75 |
| - this.isMaximized ? remote.getCurrentWindow().unmaximize() : remote.getCurrentWindow().maximize(); |
76 |
| - this.isMaximized = !this.isMaximized; |
| 97 | + private minimize() { |
| 98 | + remote.getCurrentWindow().minimize(); |
77 | 99 | }
|
78 | 100 |
|
79 |
| - minimize(){ |
80 |
| - remote.getCurrentWindow().minimize(); |
| 101 | + private close() { |
| 102 | + this.rootEmit("closing"); |
81 | 103 | }
|
82 |
| - |
83 | 104 |
|
84 |
| - newNote(){ |
85 |
| - let FileName = `${Date.now()}.md` |
86 |
| - fs.writeFile(path.join(new Configuration().notePath,FileName),"# Welcome to your new note!\nLet's write something awesome.","",_=>{ |
87 |
| - this.SelectedFile = FileName; |
88 |
| - this.fileName = FileName; |
89 |
| - this.$root.$emit("fileChange", this.SelectedFile); |
90 |
| - }); |
| 105 | + private newNote() { |
| 106 | + let FileName = `${Date.now()}.md`; |
| 107 | + writeFile( |
| 108 | + path.join(new Configuration().notePath, FileName), |
| 109 | + defaultNoteText, |
| 110 | + "", |
| 111 | + _ => { |
| 112 | + this.setFileName(FileName); |
| 113 | + } |
| 114 | + ); |
91 | 115 | }
|
92 | 116 |
|
93 |
| - deleteNote(){ |
| 117 | + private deleteNote() { |
94 | 118 | confirm(`This will permantly delete "${this.SelectedFile}". Continue?`);
|
95 |
| - fs.unlink(path.join(new Configuration().notePath,this.SelectedFile), _ =>{ |
96 |
| - this.SelectedFile = this.Files()[0].value; |
97 |
| - this.fileName = this.Files()[0].value; |
98 |
| - this.changeFile(); |
99 |
| - }); |
| 119 | + unlink(path.join(this.configuration.notePath, this.SelectedFile), _ => |
| 120 | + this.setFileName(this.Files()[0].value) |
| 121 | + ); |
| 122 | + } |
| 123 | +
|
| 124 | + private setFileName(fileName) { |
| 125 | + this.SelectedFile = fileName; |
| 126 | + this.fileName = fileName.replace(/.md$/, ""); |
| 127 | + this.changeFile(); |
100 | 128 | }
|
101 | 129 | }
|
102 | 130 | </script>
|
0 commit comments