From 080186366ec05acd9d364908fcb89b9620a2286a Mon Sep 17 00:00:00 2001
From: solvedDev <33347616+solvedDev@users.noreply.github.com>
Date: Fri, 15 Mar 2019 13:42:05 +0100
Subject: [PATCH] v0.10.0 pt.8
- fixed sidebar separator
- fixed snippets not updating after being deleted
- updated ReactiveList design
- bridge. now keeps your settings save upon updating
- fixed snippets & file explorer not working if there was a problem with initializing the settings data
- fixed below_content of "card" UI type
- tweaks to copy & cut
---
src/main/index.js | 2 +-
.../components/sidebar/content/Explorer.vue | 4 +-
.../components/windowFactory/Window.vue | 5 ++-
.../windowFactory/WindowContent.vue | 12 +++---
src/renderer/scripts/utilities/BridgeStore.js | 15 +++----
src/renderer/store/Settings.js | 4 +-
src/renderer/store/data/settings | 1 +
src/renderer/store/modules/AppMenu.js | 6 ++-
src/renderer/windows/AddSnippet.js | 10 +++--
src/renderer/windows/Settings.js | 41 +++++++++++++------
src/renderer/windows/Snippets.js | 13 ++++--
11 files changed, 73 insertions(+), 40 deletions(-)
create mode 100644 src/renderer/store/data/settings
diff --git a/src/main/index.js b/src/main/index.js
index 71a493435..7455ace54 100644
--- a/src/main/index.js
+++ b/src/main/index.js
@@ -1,5 +1,5 @@
import { app, BrowserWindow, ipcMain, Menu } from 'electron'
-import Communicator from "./communicator.js";
+import "./communicator.js";
import "./Discord";
/**
diff --git a/src/renderer/components/sidebar/content/Explorer.vue b/src/renderer/components/sidebar/content/Explorer.vue
index 82f44edd4..bad8b668c 100644
--- a/src/renderer/components/sidebar/content/Explorer.vue
+++ b/src/renderer/components/sidebar/content/Explorer.vue
@@ -214,8 +214,10 @@
},
findDefaultProject() {
+ if(this.$store.state.Settings.default_project === undefined) return this.items[0];
+
for(let i = 0; i < this.items.length; i++) {
- if(this.items[i].toLowerCase() == this.$store.state.Settings.default_project.toLowerCase())
+ if(this.items[i].toLowerCase() === this.$store.state.Settings.default_project.toLowerCase())
return this.items[i];
}
return this.items[0];
diff --git a/src/renderer/components/windowFactory/Window.vue b/src/renderer/components/windowFactory/Window.vue
index 949436827..21857c459 100644
--- a/src/renderer/components/windowFactory/Window.vue
+++ b/src/renderer/components/windowFactory/Window.vue
@@ -53,7 +53,7 @@
v-if="has_sidebar"
:style="`
width: 59px;
- border-right: 1px solid rgba(255,255,255,0.12);
+ border-right: 1px solid rgba(${is_dark_mode ? '255' : '0'}, ${is_dark_mode ? '255' : '0'}, ${is_dark_mode ? '255' : '0'}, 0.12);
position: absolute;
height: ${(is_fullscreen ? maxHeight : height) - 20}px;
overflow-y: auto;
@@ -157,6 +157,9 @@ export default {
is_persistent() {
return !this.win.options || this.win.options.is_persistent == undefined || this.win.options.is_persistent;
},
+ is_dark_mode() {
+ return this.$store.state.Appearance.is_dark_mode;
+ },
width() {
if(!this.win.options || this.win.options.width == undefined) return 500;
return this.win.options.width;
diff --git a/src/renderer/components/windowFactory/WindowContent.vue b/src/renderer/components/windowFactory/WindowContent.vue
index 9fbc1ffad..c32f84e48 100644
--- a/src/renderer/components/windowFactory/WindowContent.vue
+++ b/src/renderer/components/windowFactory/WindowContent.vue
@@ -4,7 +4,7 @@
v-if="content.type == 'text' || content.type == undefined"
:class="`${pre_color} ${content.action != undefined ? 'click-action' : ''}`"
@click.stop="action.default"
- style="overflow-x: scroll;"
+ style="overflow-x: auto;"
>{{ content.text }}
-
-
-
+
+
+
{
- if(document.activeElement.tagName === "BODY") {
+ if(document.activeElement.tagName === "BODY" || window.getSelection().toString() == "") {
try {
let node = TabSystem.getCurrentNavObj();
let obj = { [node.key]: node.toJSON() };
@@ -190,7 +190,7 @@ const state = {
title: "Cut",
shortcut: "Ctrl + X",
action: () => {
- if(document.activeElement.tagName === "BODY") {
+ if(document.activeElement.tagName === "BODY" || window.getSelection().toString() == "") {
try {
let node = TabSystem.getCurrentNavObj();
//HISTORY
@@ -216,10 +216,12 @@ const state = {
if(document.activeElement.tagName === "BODY") {
try {
TabSystem.getCurrentNavObj().buildFromObject(JSON.parse(clipboard.readText()), undefined, true);
+ TabSystem.setCurrentUnsaved();
} catch(e) {
//Try again with a fix if the key was still in front
try {
TabSystem.getCurrentNavObj().buildFromObject(JSON.parse("{" + clipboard.readText() + "}"), undefined, true);
+ TabSystem.setCurrentUnsaved();
} catch(e) {}
}
} else {
diff --git a/src/renderer/windows/AddSnippet.js b/src/renderer/windows/AddSnippet.js
index 4f0793c7c..79845d9cc 100644
--- a/src/renderer/windows/AddSnippet.js
+++ b/src/renderer/windows/AddSnippet.js
@@ -16,7 +16,7 @@ export default class AddSnippetWindow extends ContentWindow {
}, "add_snippets.");
this.data = {
- name: "Custom Snippet",
+ name: "",
file_type: "entity",
data_path: "minecraft:entity/components",
force_scope: false
@@ -67,10 +67,12 @@ export default class AddSnippetWindow extends ContentWindow {
color: "success",
text: "Add!",
action: () => {
- let data = this.getTemplate(this.data.template)
- if(data === undefined) return new InformationWindow("Invalid Template", "\nThe provided template does not contain valid JSON.");
+ let data = this.getTemplate(this.data.template);
+ if(this.data.name === "") return new InformationWindow("Invalid Snippet Name", "\nYou need to provide a name for your snippet.");
+ if(data === undefined) return new InformationWindow("Invalid Template", "\nThe provided snippet template does not contain valid JSON.");
let s = {
+ key: "custom_" + Math.random(),
file_type: this.data.file_type,
display_name: this.data.name,
template: {
@@ -82,7 +84,7 @@ export default class AddSnippetWindow extends ContentWindow {
parent.save({ custom_snippets: parent.data.custom_snippets.concat([ s ]) });
parent.select(undefined, true);
- Snippets.addSnippet(Math.random(), s);
+ Snippets.addSnippet(s);
this.close();
}
}
diff --git a/src/renderer/windows/Settings.js b/src/renderer/windows/Settings.js
index 12c122fb0..4a2aec8e3 100644
--- a/src/renderer/windows/Settings.js
+++ b/src/renderer/windows/Settings.js
@@ -5,30 +5,32 @@ import { MINECRAFT_VERSIONS, BASE_PATH } from "../scripts/constants";
import EventBus from "../scripts/EventBus";
import fs from "fs";
import AddSnippetWindow from "./AddSnippet";
+import Snippets from "./Snippets";
class ReactiveListEntry {
constructor(text, parent, watch_key, index) {
- this.type = "container";
- this.content = [
+ this.type = "card";
+ this.below_content = [
{
- type: "icon",
+ text: text
+ },
+ {
+ type: "space"
+ },
+ {
+ type: "icon-button",
text: "mdi-delete",
color: "error",
+ only_icon: true,
action: () => {
- console.log(parent.data[watch_key].filter((e, i) => index !== i));
+ Snippets.removeSnippet(parent.data[watch_key][index]);
parent.save({
[watch_key]: parent.data[watch_key].filter((e, i) => index !== i)
});
parent.select(undefined, true);
}
- },
- {
- text: text
- },
- {
- type: "divider"
}
- ];
+ ]
}
}
class ReactiveList {
@@ -36,10 +38,19 @@ class ReactiveList {
this.parent = parent;
this.watch_key = watch_key;
}
+ get content() {
+ let arr = this.parent.data[this.watch_key];
+ let res = [];
+ for(let i = 0; i < arr.length; i++) {
+ res.push(new ReactiveListEntry(arr[i].display_name, this.parent, this.watch_key, i));
+ res.push({ text: "\n" });
+ }
+ return res;
+ }
get() {
return {
type: "container",
- content: this.parent.data[this.watch_key].map((e, i) => new ReactiveListEntry(e.display_name, this.parent, this.watch_key, i))
+ content: this.content
};
}
}
@@ -176,6 +187,12 @@ export default class SettingsWindow extends TabWindow {
only_icon: true,
action: () => new AddSnippetWindow(this)
},
+ {
+ type: "divider"
+ },
+ {
+ text: "\n"
+ },
() => new ReactiveList(this, "custom_snippets").get()
]
});
diff --git a/src/renderer/windows/Snippets.js b/src/renderer/windows/Snippets.js
index c3055d84e..0a6e97392 100644
--- a/src/renderer/windows/Snippets.js
+++ b/src/renderer/windows/Snippets.js
@@ -9,7 +9,8 @@ let SNIPPETS;
fs.readFile(__static + "/data/snippets.json", (err, data) => {
if(err) throw err;
SNIPPETS = JSON.parse(data.toString());
- Store.state.Settings.custom_snippets.forEach(s => addSnippet(Math.random(), s));
+
+ if(Store.state.Settings.custom_snippets !== undefined) Store.state.Settings.custom_snippets.forEach(s => addSnippet(s));
});
function toArr() {
@@ -39,9 +40,12 @@ function expandTemplateData(data, data_path) {
}
return return_data;
}
-function addSnippet(key, s) {
+function addSnippet(s) {
if(SNIPPETS[s.file_type] === undefined) SNIPPETS[s.file_type] = {};
- SNIPPETS[s.file_type]["custom_" + key] = s;
+ SNIPPETS[s.file_type][s.key] = s;
+}
+function removeSnippet(s) {
+ delete SNIPPETS[s.file_type][s.key];
}
class SnippetWindow extends ContentWindow {
@@ -113,5 +117,6 @@ export default {
WIN = new SnippetWindow();
}
},
- addSnippet
+ addSnippet,
+ removeSnippet
}
\ No newline at end of file