Skip to content

Commit a118b69

Browse files
authored
Merge pull request #499 from vcync/next
Next
2 parents 9cd0f17 + ce2d6b5 commit a118b69

8 files changed

Lines changed: 149 additions & 34 deletions

File tree

src/App.vue

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
:showMaximiseIcon="false"
88
:state.sync="layoutState"
99
@state="updateLayoutState"
10-
@creation-error="reset"
10+
@creation-error="creationError"
1111
:headerHeight="18"
12+
:key="triggerUiRestart"
1213
>
1314
<gl-col>
1415
<gl-row>
@@ -97,7 +98,9 @@ import Search from "@/components/Search";
9798
9899
import getNextName from "@/application/utils/get-next-name";
99100
import constants from "@/application/constants";
101+
100102
import * as GoldenLayout from "golden-layout";
103+
import { ipcRenderer } from "electron";
101104
102105
export default {
103106
name: "app",
@@ -127,7 +130,8 @@ export default {
127130
128131
showUi: true,
129132
mouseTimer: null,
130-
cursor: "none"
133+
cursor: "none",
134+
triggerUiRestart: 0
131135
};
132136
},
133137
@@ -153,21 +157,19 @@ export default {
153157
},
154158
155159
created() {
156-
const layoutErroredLastLoad = window.localStorage.getItem(
157-
constants.LAYOUT_LOAD_ERROR_KEY
158-
);
159-
160-
if (layoutErroredLastLoad) {
161-
console.warn(
162-
"Layout could not be restored. Default layout loaded and old layout was saved to a backup local storage key"
163-
);
164-
window.localStorage.removeItem(constants.LAYOUT_LOAD_ERROR_KEY);
165-
}
166-
167160
const layoutState = window.localStorage.getItem(constants.LAYOUT_STATE_KEY);
168161
if (layoutState) {
169-
this.layoutState = JSON.parse(layoutState);
162+
try {
163+
this.layoutState = JSON.parse(layoutState);
164+
} catch (e) {
165+
this.creationError();
166+
}
170167
}
168+
169+
ipcRenderer.on("reset-layout", () => {
170+
this.resetGoldenLayoutState();
171+
this.restartLayout();
172+
});
171173
},
172174
173175
async mounted() {
@@ -328,8 +330,7 @@ export default {
328330
);
329331
},
330332
331-
async reset() {
332-
console.log("golden layout creation error");
333+
async creationError() {
333334
const localStorageKeys = Object.keys(window.localStorage);
334335
335336
const nextKey = await getNextName(
@@ -338,14 +339,27 @@ export default {
338339
);
339340
window.localStorage.setItem(nextKey, JSON.stringify(this.layoutState));
340341
341-
window.localStorage.removeItem(constants.LAYOUT_STATE_KEY);
342-
343-
window.localStorage.setItem(
344-
constants.LAYOUT_LOAD_ERROR_KEY,
345-
JSON.stringify(true)
342+
console.warn(
343+
"Layout could not be restored. Default layout loaded and old layout was saved to a backup local storage key"
346344
);
347345
348-
window.location.reload();
346+
this.resetGoldenLayoutState();
347+
this.restartLayout();
348+
},
349+
350+
resetGoldenLayoutState() {
351+
window.localStorage.removeItem(constants.LAYOUT_STATE_KEY);
352+
this.layoutState = undefined;
353+
},
354+
355+
/**
356+
* @description Restarts Golden Layout.
357+
* We increment a variable which is assigned to the key of the root Golden Layout element.
358+
* If the key is updated, the element is forced to dismount and mount again.
359+
*/
360+
restartLayout() {
361+
this.resetGoldenLayoutState();
362+
this.triggerUiRestart++;
349363
}
350364
},
351365

src/application/worker/store/modules/inputs.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ const actions = {
2121
commit("SET_FOCUSED_INPUT", { id, title, writeToSwap });
2222
},
2323

24+
clearFocusedInput({ commit }) {
25+
commit("SET_FOCUSED_INPUT", { id: null, title: null });
26+
},
27+
2428
addInput({ commit }, { type, location, data, id = uuidv4(), writeToSwap }) {
2529
const input = { type, location, data, id };
2630
commit("ADD_INPUT", { input, writeToSwap });

src/background.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,26 @@ function generateMenuTemplate() {
341341
{ role: "zoomin" },
342342
{ role: "zoomout" },
343343
{ type: "separator" },
344-
{ role: "togglefullscreen" }
344+
{ role: "togglefullscreen" },
345+
{ type: "separator" },
346+
{
347+
label: "Reset layout",
348+
async click() {
349+
const { response } = await dialog.showMessageBox(
350+
windows["mainWindow"],
351+
{
352+
type: "question",
353+
buttons: ["Yes", "No"],
354+
message: "modV",
355+
detail: "Are you sure you want to reset the current layout?"
356+
}
357+
);
358+
359+
if (response === 0) {
360+
windows["mainWindow"].webContents.send("reset-layout");
361+
}
362+
}
363+
}
345364
]
346365
},
347366
// { role: 'windowMenu' }

src/components/ActiveModule.vue

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
class="active-module"
44
tabindex="0"
55
@keydown="removeModule"
6+
@focus="clickActiveModule"
67
ref="activeModule"
8+
:class="{ focused }"
79
>
810
<div class="active-module__title handle">
911
{{ name }}
@@ -13,7 +15,7 @@
1315
<grid
1416
columns="6"
1517
@mousedown="
16-
clickActiveModule(module && module.meta.enabledInputId, 'Enable')
18+
focusInput(module && module.meta.enabledInputId, 'Enable')
1719
"
1820
:class="{
1921
'has-link': hasLink(module && module.meta.enabledInputId),
@@ -161,6 +163,14 @@ export default {
161163
}
162164
163165
return this.module.meta.name;
166+
},
167+
168+
focusedModule() {
169+
return this.$store.state["focus"].type === "module";
170+
},
171+
172+
focused() {
173+
return this.focusedModule && this.id === this.$store.state["focus"].id;
164174
}
165175
},
166176
@@ -191,9 +201,12 @@ export default {
191201
});
192202
},
193203
194-
clickActiveModule(inputId, title) {
195-
this.focusInput(inputId, title);
196-
this.$refs.activeModule.focus();
204+
async clickActiveModule() {
205+
await this.$store.dispatch("focus/setFocus", {
206+
id: this.id,
207+
type: "module"
208+
});
209+
197210
this.$store.commit("ui-modules/SET_FOCUSED", this.id);
198211
},
199212
@@ -205,9 +218,11 @@ export default {
205218
return this.$modV.store.state.inputs.focusedInput.id === id;
206219
},
207220
208-
removeModule(e) {
221+
async removeModule(e) {
209222
if (e.keyCode === 8 || e.keyCode === 46) {
210223
this.$store.commit("ui-modules/SET_FOCUSED", null);
224+
await this.$modV.store.dispatch("inputs/clearFocusedInput");
225+
211226
this.$emit("remove-module", this.id);
212227
}
213228
}
@@ -222,7 +237,8 @@ export default {
222237
font-size: 14px;
223238
}
224239
225-
.active-module:focus {
240+
.active-module:focus,
241+
.active-module.focused {
226242
outline: #c4c4c4 2px solid;
227243
}
228244

src/components/GalleryItem.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ export default {
122122
},
123123
124124
async doubleClick() {
125-
const groupId = this.$store.state["ui-groups"].focused;
125+
if (this.$store.state.focus.type !== "group") {
126+
return;
127+
}
128+
129+
const groupId = this.$store.state.focus.id;
126130
if (!groupId) {
127131
return;
128132
}

src/components/Group.vue

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
focusElement: true
99
}"
1010
tabindex="0"
11-
@keydown="removeGroup"
11+
@keydown.self="removeGroup"
12+
@focus.self="focus"
13+
@mousedown.self="focus"
14+
:class="{ focused }"
1215
>
1316
<div
1417
class="group__controls"
@@ -322,6 +325,10 @@ export default {
322325
323326
created() {
324327
this.localName = this.name;
328+
329+
if (!this.focusedGroup) {
330+
this.focus();
331+
}
325332
},
326333
327334
computed: {
@@ -348,6 +355,16 @@ export default {
348355
}
349356
},
350357
358+
focusedGroup() {
359+
return this.$store.state["focus"].type === "group";
360+
},
361+
362+
focused() {
363+
return (
364+
this.focusedGroup && this.groupId === this.$store.state["focus"].id
365+
);
366+
},
367+
351368
enabled: {
352369
get() {
353370
return this.group.enabled;
@@ -470,6 +487,15 @@ export default {
470487
return { moduleId, collection: "layer" };
471488
},
472489
490+
focus() {
491+
if (!this.focused) {
492+
this.$store.dispatch("focus/setFocus", {
493+
id: this.groupId,
494+
type: "group"
495+
});
496+
}
497+
},
498+
473499
removeModule(moduleId) {
474500
const { groupId } = this;
475501
@@ -506,7 +532,7 @@ export default {
506532
},
507533
508534
focusInput(id, title) {
509-
this.$modV.store.dispatch("inputs/setFocusedInput", {
535+
this.store.dispatch("inputs/setFocusedInput", {
510536
id,
511537
title: `${this.name}: ${title}`
512538
});
@@ -543,7 +569,8 @@ export default {
543569
margin-bottom: 8px;
544570
}
545571
546-
.group:focus {
572+
.group:focus,
573+
.group.focused {
547574
outline: #c4c4c4 2px solid;
548575
}
549576

src/components/Groups.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ export default {
9494
},
9595
9696
onDrop(e) {
97-
console.log("drop");
9897
this.groups = applyDrag(this.groups, e);
9998
}
10099
}

src/ui-store/modules/focus.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const state = {
2+
id: null,
3+
type: null
4+
};
5+
6+
const actions = {
7+
setFocus({ commit }, args) {
8+
if (!args.id) {
9+
throw new Error("Missing ID");
10+
}
11+
12+
if (!args.type) {
13+
throw new Error("Missing type");
14+
}
15+
16+
commit("SET_FOCUS", args);
17+
}
18+
};
19+
20+
const mutations = {
21+
SET_FOCUS(state, { id, type }) {
22+
state.id = id;
23+
state.type = type;
24+
}
25+
};
26+
27+
export default {
28+
namespaced: true,
29+
state,
30+
actions,
31+
mutations
32+
};

0 commit comments

Comments
 (0)