Skip to content

Commit

Permalink
v0.10.0 pt.8
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
solvedDev committed Mar 15, 2019
1 parent a9dd8d2 commit 0801863
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/main/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app, BrowserWindow, ipcMain, Menu } from 'electron'
import Communicator from "./communicator.js";
import "./communicator.js";
import "./Discord";

/**
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/components/sidebar/content/Explorer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/components/windowFactory/Window.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/renderer/components/windowFactory/WindowContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}</pre>
<v-subheader
v-else-if="content.type == 'header'"
Expand Down Expand Up @@ -56,9 +56,9 @@
<window-content v-for="(c, i) in content.content" :key="`card-window-content-${i}`" :content="c"/>
</v-card-text>

<v-card-action v-if="content.below_content">
<window-content v-for="(b_c, i) in content.below_content" :key="`card-window-below-content-${i}`" :content="_bc"/>
</v-card-action>
<v-card-actions v-if="content.below_content">
<window-content v-for="(b_c, i) in content.below_content" :key="`card-window-below-content-${i}`" :content="b_c"/>
</v-card-actions>
</v-card>
<!-- LOADER -->
<v-progress-linear
Expand Down Expand Up @@ -197,7 +197,7 @@ export default {
content: Object
},
mounted() {
if(this.content.focus && this.$refs.input) {
if(this.content && this.content.focus && this.$refs.input) {
this.$refs.input.focus();
}
},
Expand Down Expand Up @@ -231,7 +231,7 @@ export default {
return this.content.enter;
},
pre_color() {
if(!this.content.color) return undefined;
if(!this.content.color) return "";
if(this.content.color.includes(" ")) {
let tmp = this.content.color.split(" ");
return `${tmp[0]}--text text--${tmp[1]}`;
Expand Down
15 changes: 8 additions & 7 deletions src/renderer/scripts/utilities/BridgeStore.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import fs from "fs";
import mkdirp from "mkdirp";

export default class BridgeStore {
constructor(path, namespace) {
this.namespace = namespace + "/";
this.namespace = namespace + "\\";
this.path = path;
}

setup(namespace) {
if(namespace == undefined) throw new Error("You need to define a namespace");
this.namespace = namespace + "/";
fs.mkdirSync(this.path + this.namespace);
if(namespace === undefined) throw new Error("You need to define a namespace");
this.namespace = namespace + "\\";
mkdirp.sync(this.path + this.namespace);
}
load(name) {
if(this.namespace == undefined) throw new Error("You need to define a namespace using Bridge.Store.setup(namespace)");
if(this.namespace === undefined) throw new Error("You need to define a namespace using Bridge.Store.setup(namespace)");
return JSON.parse(fs.readFileSync(this.path + this.namespace + name));
}
save(name, data) {
if(this.namespace == undefined) throw new Error("You need to define a namespace using Bridge.Store.setup(namespace)");
if(this.namespace === undefined) throw new Error("You need to define a namespace using Bridge.Store.setup(namespace)");

let tmp = {};
try {
Expand All @@ -27,7 +28,7 @@ export default class BridgeStore {
return fs.writeFileSync(this.path + this.namespace + name, tmp);
}
exists(name) {
if(this.namespace == undefined) throw new Error("You need to define a namespace using Bridge.Store.setup(namespace)");
if(this.namespace === undefined) throw new Error("You need to define a namespace using Bridge.Store.setup(namespace)");
console.log(this.path + this.namespace + name);

return fs.existsSync(this.path + this.namespace + name);
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/store/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import BridgeStore from "../scripts/utilities/BridgeStore";
import VueStore from "./index";

let STORE;
if(process.env.NODE_ENV == "development") STORE = new BridgeStore(__dirname + "/", "data");
else STORE = new BridgeStore(__dirname.split("app.asar\\")[0], "data");
if(process.env.NODE_ENV === "development") STORE = new BridgeStore(__dirname + "/", "data");
else STORE = new BridgeStore(`C:\\Users\\${process.env.USERNAME}\\.bridge\\`, "data");
let DATA;

function setup() {
Expand Down
1 change: 1 addition & 0 deletions src/renderer/store/data/settings
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"is_dev_mode":false,"is_dark_mode":false,"inversed_arrows":false,"use_tabs":true,"line_wraps":false,"auto_completions":true,"auto_fill_inputs":false,"open_all_nodes":false,"default_project":"MysticBP","target_version":"v1.11","snippet_scope":"Default","custom_snippets":[{"key":"custom_0.7215414988207944","file_type":"entity","display_name":"Annotations","template":{"data_path":"minecraft:entity/components","force_default_scope":false,"data":{"minecraft:annotation.open_door":{},"minecraft:annotation.break_door":{}}}}]}
6 changes: 4 additions & 2 deletions src/renderer/store/modules/AppMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const state = {
title: "Copy",
shortcut: "Ctrl + C",
action: () => {
if(document.activeElement.tagName === "BODY") {
if(document.activeElement.tagName === "BODY" || window.getSelection().toString() == "") {
try {
let node = TabSystem.getCurrentNavObj();
let obj = { [node.key]: node.toJSON() };
Expand All @@ -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
Expand All @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions src/renderer/windows/AddSnippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand All @@ -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();
}
}
Expand Down
41 changes: 29 additions & 12 deletions src/renderer/windows/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,52 @@ 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 {
constructor(parent, watch_key) {
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
};
}
}
Expand Down Expand Up @@ -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()
]
});
Expand Down
13 changes: 9 additions & 4 deletions src/renderer/windows/Snippets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -113,5 +117,6 @@ export default {
WIN = new SnippetWindow();
}
},
addSnippet
addSnippet,
removeSnippet
}

0 comments on commit 0801863

Please sign in to comment.