Browse Source

added file saving

master
Pixdigit 3 years ago
parent
commit
5416f4756b
  1. 5
      fileTree.go
  2. 15
      frontend/src/App.vue
  3. 6
      frontend/src/components/TopBar/TopBar.vue
  4. 11
      frontend/src/components/Workspace/Editor/Editor.vue
  5. 11
      frontend/src/components/Workspace/Workspace.vue
  6. 10
      main.go

5
fileTree.go

@ -17,10 +17,7 @@ type fileInfo struct {
}
func OpenFile(path string) (string, error) {
bytes, err := ioutil.ReadFile(path)
if err != nil {
fmt.Errorf("Error opening file: %w", err)
}
bytes, err := ioutil.ReadFile(path); if err != nil {return "", fmt.Errorf("Error opening file: %w", err)}
return string(bytes), nil
}

15
frontend/src/App.vue

@ -1,7 +1,7 @@
<template>
<div id="app">
<TopBar />
<Workspace />
<TopBar @Save="saveFile" />
<Workspace ref="Workspace" />
</div>
</template>
@ -11,6 +11,17 @@ import Workspace from "./components/Workspace/Workspace.vue";
export default {
name: "app",
methods: {
saveFile() {
const filename = this.$refs.Workspace.activeFile();
const content = this.$refs.Workspace.activeBuffer();
if (filename !== "") {
backend.SaveFile(filename, content).catch(err => {
console.error("ERROR: ", err);
});
}
}
},
components: {
TopBar,
Workspace

6
frontend/src/components/TopBar/TopBar.vue

@ -3,8 +3,8 @@
<div class="windowMenu" id="FileMenu">
<button class="dropbtn">{{ $t("file") }}</button>
<div class="dropdown-content">
<a href="#">{{ $t("save") }}</a>
<a href="#" v-on:click="quit">{{ $t("quit") }}</a>
<a href="#" @click="$emit('Save')">{{ $t("save") }}</a>
<a href="#" @click="quit">{{ $t("quit") }}</a>
</div>
</div>
</div>
@ -16,7 +16,7 @@ export default {
return {};
},
methods: {
quit: function() {
quit() {
backend.Runtime.Quit();
}
}

11
frontend/src/components/Workspace/Editor/Editor.vue

@ -8,6 +8,8 @@ import "codemirror/mode/javascript/javascript.js";
import "codemirror/lib/codemirror.css";
import "../../../assets/themes/default.sass";
var fileOpen = "";
export default {
data() {
return {
@ -20,15 +22,22 @@ export default {
};
},
methods: {
openFile: function(path) {
openFile(path) {
const vm = this;
const fail = cause => {
console.error("Backend error: ", cause);
};
backend.OpenFile(path).then(function success(buffer) {
fileOpen = path;
vm.code = buffer;
}, fail);
},
activeFile() {
return fileOpen;
},
activeBuffer() {
return this.code;
}
},
components: {

11
frontend/src/components/Workspace/Workspace.vue

@ -8,10 +8,9 @@
<VBar
id="VBar"
v-bind:style="VBarStyle"
ref="vBar"
@mousedown.native="sepDragging = true"
/>
<Editor id="Editor" ref="editor" v-bind:style="editorStyle" />
<Editor id="Editor" ref="Editor" v-bind:style="editorStyle" />
</div>
</template>
@ -31,12 +30,18 @@ export default {
},
methods: {
openFile(path) {
this.$refs.editor.openFile(path);
this.$refs.Editor.openFile(path);
},
VBarDrag(evt) {
if (this.sepDragging) {
this.sepPercent = evt.clientX / window.innerWidth;
}
},
activeFile() {
return this.$refs.Editor.activeFile();
},
activeBuffer() {
return this.$refs.Editor.activeBuffer();
}
},
computed: {

10
main.go

@ -2,6 +2,8 @@ package main
import (
"fmt"
"io/ioutil"
"path/filepath"
"github.com/leaanthony/mewn"
"github.com/wailsapp/wails"
@ -24,6 +26,13 @@ func (r *Runtime) Quit() {
r.runtime.Window.Close()
}
func SaveFile(path, content string) error {
absPath, err := filepath.Abs(path); if err != nil {return fmt.Errorf("Can not write file: %w", err)}
err = ioutil.WriteFile(absPath, []byte(content), 0774); if err != nil {return fmt.Errorf("Can not write file: %w", err)}
return nil
}
func main() {
js := mewn.String("./frontend/dist/app.js")
css := mewn.String("./frontend/dist/app.css")
@ -38,5 +47,6 @@ func main() {
app.Bind(&Runtime{})
app.Bind(LookupFilesystem)
app.Bind(OpenFile)
app.Bind(SaveFile)
app.Run()
}

Loading…
Cancel
Save