Skip to content

Commit 248003e

Browse files
demvladhaslinghuis
andauthored
Restore various default workspaces by using menu (betaflight#745)
* added menu (showed by Shift+W keys) to select and restore default workspaces * Code style improvement Co-authored-by: Mark Haslinghuis <[email protected]> * Code style improvement Co-authored-by: Mark Haslinghuis <[email protected]> * Code style improvement Co-authored-by: Mark Haslinghuis <[email protected]> --------- Co-authored-by: Mark Haslinghuis <[email protected]>
1 parent ac8355d commit 248003e

File tree

5 files changed

+5209
-3
lines changed

5 files changed

+5209
-3
lines changed

index.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ <h4>Log sync</h4>
437437
<li class="log-workspace-panel">
438438
<h4>Workspace</h4>
439439
<div class="log-workspace-selection"></div>
440+
<div class="flexDiv">
441+
<div class="selectWrapper">
442+
<div class="dropdown-content" id="default_workspaces_menu"></div>
443+
</div>
444+
</div>
440445
</li>
441446
</ul>
442447
<div id="screenshot-frame" class="graph-row">
@@ -2517,6 +2522,13 @@ <h4 class="modal-title">Shortcut Keys</h4>
25172522
<div class="description">Recall workspace/favourite stored in keys 0 through 9. Very fast graph configuration
25182523
swapping useful for comparing traces.</div>
25192524
</li>
2525+
<li>
2526+
<span class="keys">
2527+
<div class="key">Shift</div>
2528+
<div class="key">W</div>
2529+
</span>
2530+
<div class="description">Show the menu to load default workspace</div>
2531+
</li>
25202532
</ul>
25212533
<ul>
25222534
<li>
@@ -3199,7 +3211,6 @@ <h4 class="modal-title">Advanced User Settings</h4>
31993211
<script src="/js/webm-writer/BlobBuffer.js"></script>
32003212
<script src="/js/webm-writer/WebMWriter.js"></script>
32013213
<script type="module" src="src/main.js"></script>
3202-
32033214
<dialog class="dialogUpdate">
32043215
<h3>Notice</h4>
32053216
<div class="content">

src/main.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { SeekBar } from './seekbar.js';
1616
import { GpxExporter } from './gpx-exporter.js';
1717
import { CsvExporter } from './csv-exporter.js';
1818
import { WorkspaceSelection } from './workspace_selection.js';
19+
import { WorkspaceMenu } from './workspace_menu.js';
1920
import { GraphLegend } from './graph_legend.js';
2021
import { FlightLog } from './flightlog.js';
2122
import { FlightLogParser } from './flightlog_parser.js';
@@ -33,7 +34,6 @@ import {
3334
} from './tools.js';
3435
import { PrefStorage } from './pref_storage.js';
3536
import { makeScreenshot } from './screenshot.js';
36-
import defaultWorkspaceGraphConfigs from './workspaces-ctzsnooze.json';
3737

3838
// TODO: this is a hack, once we move to web fix this
3939
globalThis.userSettings = null;
@@ -106,6 +106,7 @@ function BlackboxLogViewer() {
106106

107107
graphLegend = null,
108108
workspaceSelection = null,
109+
workspaceMenu = null,
109110
fieldPresenter = FlightLogFieldPresenter,
110111

111112
hasVideo = false, hasLog = false, hasMarker = false, // add measure feature
@@ -1068,7 +1069,7 @@ function BlackboxLogViewer() {
10681069
if (item) {
10691070
workspaceGraphConfigs = upgradeWorkspaceFormat(item);
10701071
} else {
1071-
workspaceGraphConfigs = defaultWorkspaceGraphConfigs;
1072+
workspaceGraphConfigs = workspaceMenu.getDefaultWorkspace();
10721073
}
10731074
});
10741075

@@ -1083,6 +1084,8 @@ function BlackboxLogViewer() {
10831084

10841085
workspaceSelection = new WorkspaceSelection($(".log-workspace-selection"), workspaceGraphConfigs, onSwitchWorkspace, onSaveWorkspace);
10851086
onSwitchWorkspace(workspaceGraphConfigs, workspaceSelection);
1087+
1088+
workspaceMenu = new WorkspaceMenu($("#default_workspaces_menu"), onSwitchWorkspace);
10861089

10871090
prefs.get('log-legend-hidden', function(item) {
10881091
if (item) {
@@ -1946,6 +1949,11 @@ function BlackboxLogViewer() {
19461949
}
19471950
e.preventDefault();
19481951
break;
1952+
case "W".charCodeAt(0):
1953+
if (e.shiftKey) {
1954+
workspaceMenu.show();
1955+
}
1956+
break;
19491957
case "Z".charCodeAt(0): // Ctrl-Z key to toggle between last graph config and current one - undo
19501958
try {
19511959
if(e.ctrlKey) {

src/workspace_menu.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import ctzsnoozeWorkspace from './ws_ctzsnooze.json';
2+
import supaflyWorkspace from './ws_supafly.json';
3+
export function WorkspaceMenu(menuElem, onSwitchWorkspace) {
4+
const workspace_menu = menuElem;
5+
6+
function hideMenu() {
7+
workspace_menu.removeClass('show');
8+
workspace_menu.empty();
9+
}
10+
11+
function showMenu() {
12+
workspace_menu.addClass('show');
13+
}
14+
15+
this.show = function() {
16+
let elem = $('<div class="titleDiv bottomBorder">SELECT WORKSPACE:</div>');
17+
workspace_menu.append(elem);
18+
elem = $('<div>Ctzsnooze</div>');
19+
elem.click(1, ApplyWorkspace);
20+
workspace_menu.append(elem);
21+
elem = $('<div>SupaflyFPV</div>');
22+
elem.click(2, ApplyWorkspace);
23+
workspace_menu.append(elem);
24+
elem = $('<div class="menu-button topBorder">Close</div>');
25+
elem.click(ApplyWorkspace);
26+
workspace_menu.append(elem);
27+
showMenu();
28+
};
29+
30+
function ApplyWorkspace (e) {
31+
switch (e.data) {
32+
case 1:
33+
onSwitchWorkspace(ctzsnoozeWorkspace, 1);
34+
break;
35+
case 2:
36+
onSwitchWorkspace(supaflyWorkspace, 1);
37+
break;
38+
}
39+
hideMenu();
40+
}
41+
42+
$(document).keydown( function (e) {
43+
if (e.which === 27 && workspace_menu.length > 0) {
44+
e.preventDefault();
45+
hideMenu();
46+
}
47+
});
48+
49+
this.getDefaultWorkspace = function() {
50+
return ctzsnoozeWorkspace;
51+
};
52+
}

0 commit comments

Comments
 (0)