Skip to content

Commit

Permalink
Initial work on FileTree, refactor of Compile grammar service
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorthiz committed Sep 1, 2024
1 parent bf12593 commit 9da4ad4
Show file tree
Hide file tree
Showing 63 changed files with 1,349 additions and 742 deletions.
17 changes: 1 addition & 16 deletions css/app.css
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
/*.lm_content>div { height: 100%; width: 100% }*/
.lm_splitter.lm_horizontal .lm_drag_handle { left:-5px; width:15px }
.lm_splitter.lm_vertical .lm_drag_handle { top:-5px; height:15px }
.errorWindow { background: white; font-family: Courier,monospace; font-size: 12px; white-space: pre-wrap; overflow-y: scroll; }
.errorWindow>div { margin: 5px; }
#fileTree { font-family:Arial; font-size:12px }
body { line-height:normal }
#fileTree { position:absolute; top:0; bottom:28px; width:100%; /*height:100%;*/ overflow: auto; }
#fileTree .jstree-node { margin-left: 14px }
#fileTree .jstree-container-ul>.jstree-node { margin-left:0 }
#fileTree .jstree-clicked { background:initial }
#fileTree .glyphicon { font-size:12px; margin-top:-1px; color:#eee; margin-right:3px }
#fileTree .jstree-icon { margin-left:3px; margin-right:5px }
#fileTree .jstree-ocl { display:none }
#fileTreeCont .footer { position:absolute; bottom:0; width:100%; padding-left:2px }
#fileTreeCont .footer .btn { width:33.3%; border-radius:0; font-size:13px; padding:3px 10px }
body { color:#333 }
.dropdown { position: absolute; display:none; z-index:9999 }
.dropdown-menu { z-index:9999 }
Expand All @@ -22,7 +9,6 @@ body { color:#333 }
.dropdown .glyphicon-folder-open { margin-left:-1px; margin-right:6px }
.dropdown .dropdown-menu>li>a { padding:3px 15px }
.btn { padding: 5px 10px; }
.modal { color: white; }
.control-label { margin-bottom:8px }
.form-control { padding: 6px 12px; height:34px }
.modal-footer, .modal-body { padding: 15px }
Expand All @@ -35,6 +21,5 @@ body { color:#333 }
#aboutWebIde { position:absolute; bottom:10px; right:10px; font-size:12px }
#exportToJsonDiv, #parsedPathDiv, #selectionLengthDiv { font-size:13px; margin-top:5px }
#parsedPath { word-break: break-all; }
#welcomeModalLabel { text-align:center }
#welcomeModal .licenses { font-size:12px; margin-bottom:10px }

/*.marker_match { background:rgba(80, 255, 80, 0.30); }*/
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
"staticPath": "samples",
"staticOutPath": "samples"
},
{
"staticPath": "public"
},
{
"staticPath": "LICENSE-3RD-PARTY.txt"
},
Expand Down
Binary file added public/favicon.ico
Binary file not shown.
Binary file added public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 29 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
<script setup lang="ts">
import ConverterPanel from "./Components/ConverterPanel/ConverterPanel.vue";
import FileTree from "./Components/FileTree/FileTree.vue";
import InfoPanel from "./Components/InfoPanel/InfoPanel.vue";
import UnsupportedBrowser from "./Components/UnsupportedBrowser.vue";
import WelcomeModal from "./Components/WelcomeModal.vue";
import WelcomeModal from "./Components/WelcomeModal/WelcomeModal.vue";
import FileDrop from "./Components/FileDrop.vue";
import NewKsyModal from "./Components/NewKsyModal.vue";
import InputContextMenu from "./Components/InputContextMenu.vue";
import HexViewer from "./Components/HexViewer/HexViewer.vue";
import ParsedTree from "./Components/ParsedTree/ParsedTree.vue";
import FileTree from "./Components/FileTree/FileTree.vue";
import {useAppStore} from "./Stores/AppStore";
import {loadBinaryFileAction} from "./GlobalActions/LoadBinaryFile";
import {loadKsyFileAction} from "./GlobalActions/LoadKsyFile";
import {onMounted} from "vue";
import {parseAction} from "./GlobalActions/ParseAction";
const store = useAppStore();
store.$onAction(async ({name, store, args}) => {
switch (name) {
case "updateSelectedBinaryFile": {
await loadBinaryFileAction(args[0]);
await parseAction();
return;
}
case "updateSelectedKsyFile": {
await loadKsyFileAction(args[0]);
await parseAction();
return;
}
}
});
onMounted(async () => {
await loadKsyFileAction(store.selectedKsyInfo);
await loadBinaryFileAction(store.selectedBinaryInfo);
await parseAction();
});
</script>

<template>
Expand Down
93 changes: 93 additions & 0 deletions src/Components/FileTree/FileSystemVisitors/FileSystemVisitor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import {
FILE_SYSTEM_TYPE_KAITAI,
FILE_SYSTEM_TYPE_LOCAL,
IFileSystem,
IFsItem,
ITEM_MODE_DIRECTORY,
ITEM_MODE_FILE
} from "../../../v1/FileSystems/FileSystemsTypes";

export const OPEN_FOLDER = "OPEN_FOLDER";
export const CLOSED_FOLDER = "CLOSED_FOLDER";
export const EMPTY_FOLDER = "EMPTY_FOLDER";
export const BINARY_FILE = "BINARY_FILE";
export const KSY_FILE = "KSY_FILE";

export type NodeType = typeof EMPTY_FOLDER | typeof OPEN_FOLDER | typeof CLOSED_FOLDER | typeof BINARY_FILE | typeof KSY_FILE;

export interface TreeNodeDisplay {
fullPath: string;
type: NodeType;
fileName: string;
isOpen: boolean;
storeId: typeof FILE_SYSTEM_TYPE_LOCAL | typeof FILE_SYSTEM_TYPE_KAITAI;
depth: number;
}

export class FileSystemVisitor {
private openPaths: string[];
private currentPath: string[] = [];
private visibleFsItemsNew: TreeNodeDisplay[] = [];

public visit(fileSystem: IFileSystem, openPaths: string[]) {
this.openPaths = openPaths;
this.visitFileSystem(fileSystem);
return this.visibleFsItemsNew;
}

private visitFileSystem(fileSystem: IFileSystem) {
if (!fileSystem.getRootNode()) {
this.visibleFsItemsNew = [];
return;
}
this.visitNode(fileSystem.getRootNode());

}

private visitNode(fsItem: IFsItem) {
this.currentPath.push(fsItem.fn);
const newNode = this.mapToNewNode(fsItem);
this.visibleFsItemsNew.push(newNode);

if (fsItem.type === ITEM_MODE_DIRECTORY && newNode.isOpen) {
Object.entries(fsItem.children || {})
.forEach(([key, child]) => {
child.fn = key;
this.visitNode(child);
});
}
this.currentPath.pop();
}


private mapToNewNode(fsItem: IFsItem): TreeNodeDisplay {
const fullPath = this.currentPath.join("/");
const isOpen = this.isDirectoryOpen(fullPath);
return {
type: this.getNodeType(isOpen, fsItem),
storeId: fsItem.fsType,
fullPath: fullPath,
fileName: fsItem.fn,
isOpen: isOpen,
depth: this.currentPath.length - 1
};
}

private getNodeType(isOpen: boolean, fsItem: IFsItem): NodeType {
switch (fsItem.type) {
case ITEM_MODE_FILE: {
return fsItem.fn.endsWith(".ksy") ? KSY_FILE : BINARY_FILE;
}
case ITEM_MODE_DIRECTORY: {
if (Object.keys(fsItem.children).length === 0) return EMPTY_FOLDER;
else if (isOpen) return OPEN_FOLDER;
else return CLOSED_FOLDER;
}
}
}

private isDirectoryOpen(path: string) {
const tempPath = this.currentPath.join("/");
return !!this.openPaths.find(openPath => openPath === tempPath);
}
}
81 changes: 50 additions & 31 deletions src/Components/FileTree/FileTree.vue
Original file line number Diff line number Diff line change
@@ -1,43 +1,62 @@
<script setup lang="ts">
import FileTreeLanguagesDropdown from "./FileTreeGenerateParserDropdown.vue";
import FileTreeBottomActions from "./FileTreeActionButtons.vue";
import {useFileSystems} from "./Store/FileSystemsStore";
import FileTreeNodes from "./FileTreeNodes.vue";
import {onMounted} from "vue";
import {FILE_SYSTEM_TYPE_LOCAL, IFsItem, ITEM_MODE_DIRECTORY} from "../../v1/FileSystems/FileSystemsTypes";
import {LocalForageWrapper} from "../../v1/utils/LocalForageWrapper";
import {initKaitaiFs} from "../../v1/FileSystems/KaitaiFileSystem";
import {OldLocalStorageFileSystem} from "../../v1/FileSystems/OldLocalStorageFileSystem";
const store = useFileSystems();
onMounted(async () => {
const defaultItem: IFsItem = {
fsType: FILE_SYSTEM_TYPE_LOCAL,
type: ITEM_MODE_DIRECTORY,
children: {},
fn: "Local storage"
};
const storedItem = await LocalForageWrapper.getFsItem(`fs_files`);
if (storedItem) {
storedItem.fn = "Local storage";
}
store.addFileSystem(initKaitaiFs());
store.addFileSystem(new OldLocalStorageFileSystem(storedItem || defaultItem));
});
</script>

<template>
<div id="fileTreeCont">
<div id="fileTree" class="fileTree">

</div>
<div class="footer btn-group" role="group">
<button id="createLocalKsyFile" type="button" class="btn btn-default"><i
class="glyphicon glyphicon-file"></i></button>
<button id="uploadFile" type="button" class="btn btn-default"><i
class="glyphicon glyphicon-cloud-upload"></i></button>
<button id="downloadFile" type="button" class="btn btn-default disabled"><i
class="glyphicon glyphicon-cloud-download"></i></button>
<div id="fileTreeNew" class="file-tree-component">
<div class="file-tree-list-container">
<FileTreeNodes :fileSystem="fileSystem" v-for="fileSystem in store.fileSystems"/>
</div>
</div>

<div id="fileTreeContextMenu" class="dropdown clearfix">
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu"
style="display:block;position:static;margin-bottom:5px;">
<li class="openItem"><a tabindex="-1" href="#"><i class="glyphicon glyphicon-pencil"></i> Open</a></li>
<li class="createFolder"><a tabindex="-1" href="#"><i class="glyphicon glyphicon-folder-open"></i> Create
folder</a></li>
<li class="createKsyFile"><a tabindex="-1" href="#"><i class="glyphicon glyphicon-list-alt"></i> Create .ksy
file</a></li>
<li class="cloneKsyFile"><a tabindex="-1" href="#"><i class="glyphicon fa fa-clone"></i> Clone</a></li>
<li class="generateParser dropdown-submenu">
<a tabindex="-1" href="#"><i class="glyphicon glyphicon-flash"></i> Generate parser</a>
<FileTreeLanguagesDropdown/>
</li>
<li class="downloadItem"><a tabindex="-1" href="#"><i class="glyphicon glyphicon-cloud-download"></i>
Download</a></li>
<li class="deleteItem"><a tabindex="-1" href="#"><i class="glyphicon glyphicon-remove"></i> Delete</a></li>
</ul>
<FileTreeBottomActions/>
</div>
</template>

<!--font: 12px/normal "Monaco", "Menlo", "Ubuntu Mono", "Consolas", "source-code-pro", monospace;-->

<style scoped>
.file-tree-component {
width: 100%;
height: 100%;
overflow: hidden;
font-family: Arial;
font-size: 12px;
color: #ccc;
user-select: none;
display: flex;
flex-direction: column;
justify-content: space-between;
}

.file-tree-list-container {
overflow: scroll;
width: 100%;
flex-grow: 1;
}

</style>
60 changes: 60 additions & 0 deletions src/Components/FileTree/FileTreeActionButtons.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<script setup lang="ts">
import {openUploadFilesOperatingSystemModal} from "../../v1/JQueryComponents/Files/UploadFilesOSModal";
import {processUploadedFiles} from "../../GlobalActions/UploadFiles";
const addKsyFile = () => {
};
const uploadFile = () => {
openUploadFilesOperatingSystemModal(files => {
processUploadedFiles(files);
});
};
const downloadFile = () => {
};
</script>

<template>
<div class="footer btn-group" role="group">
<button type="button" class="action-button" @click="addKsyFile()">
<i class="glyphicon glyphicon-file"/>
</button>
<button type="button" class="action-button" @click="uploadFile()">
<i class="glyphicon glyphicon-cloud-upload"/>
</button>
<button type="button" class="action-button" @click="downloadFile()" disabled>
<i class="glyphicon glyphicon-cloud-download"/>
</button>
</div>
</template>

<style scoped>
.footer {
display: flex;
flex-direction: row;
width: 100%;
}
.action-button {
font-size: 13px;
padding: 7px 10px;
flex-grow: 1;
border-radius: 0;
background-color: rgb(70, 70, 70);
border: none;
}
.action-button:hover {
color: white;
background-color: rgb(30, 30, 30);
}
.action-button:disabled {
background-color: rgb(60, 60, 60);
color: inherit;
}
</style>
38 changes: 0 additions & 38 deletions src/Components/FileTree/FileTreeGenerateParserDropdown.vue

This file was deleted.

Loading

0 comments on commit 9da4ad4

Please sign in to comment.