Constructed menu; moved files to sub newton folder; WIP save system added

This commit is contained in:
2025-06-01 13:49:18 -05:00
parent ae43722881
commit 82e2afa601
10 changed files with 241 additions and 123 deletions

View File

@@ -19,6 +19,7 @@ declare global {
fs: {
getLspConfigData: () => Promise<string>,
getFileContents: (arg0: any) => Promise<string>,
openFiles: (arg0) => Promise<string>,
saveFile: (arg0: any, arg1: any) => Promise<string>,
saveFileAs: (arg0: any) => Promise<string>,
getPathForFile: any,

View File

@@ -1,6 +1,7 @@
import { Directive, ElementRef, Input, ViewChild } from '@angular/core';
import { EditorSettings } from "../../common/configs/editor.config";
import { NewtonFile } from '../../common/types/file.type';
@@ -12,6 +13,7 @@ export class AceEditorBase {
uuid!: string;
cutBuffer: string = "";
timerId: number = -1;
activeFile!: NewtonFile;
constructor(
@@ -22,9 +24,25 @@ export class AceEditorBase {
console.log(this.editor.getSession()["$modeId"])
}
protected openFiles() {
let startDir = "";
if (this.activeFile) {
let pathParts = this.activeFile.path.split("/");
pathParts.pop();
startDir = pathParts.join( '/' );
}
window.fs.openFiles(startDir);
}
protected saveFile() {
const text = this.editor.session.getValue();
// window.fs.saveFile(text);
if (!this.activeFile) {
this.saveFileAs();
return;
}
const text = this.activeFile.session.getValue();
window.fs.saveFile(this.activeFile.path, text);
}
protected saveFileAs() {

View File

@@ -109,6 +109,13 @@ export class AceEditorComponent extends AceEditorBase {
this.editor.session.destroy();
},
readOnly: true
}, {
name: "openFiles",
bindKey: {win: "ctrl-o", mac: "ctrl-o"},
exec: () => {
this.openFiles();
},
readOnly: true
}, {
name: "saveFile",
bindKey: {win: "ctrl-s", mac: "ctrl-s"},

View File

@@ -75,8 +75,8 @@ export class EditorsComponent {
this.addTab(file);
}
let session = this.files.get(paths[ paths.length - 1 ]).session;
this.setSession(session);
let file = this.files.get(paths[ paths.length - 1 ]);
this.setSession(file);
});
window.main.onMenuActions(async (action: string) => {
@@ -86,6 +86,9 @@ export class EditorsComponent {
switch ( action ) {
case "new-file":
break;
case "open-files":
editorComponent.openFiles();
break;
case "save-file":
editorComponent.saveFile();
break;
@@ -130,23 +133,25 @@ export class EditorsComponent {
}
protected onFileDropped(files: any) {
this.loadFilesList(files).then((session: EditSession | undefined | null) => {
this.setSession(session);
this.loadFilesList(files).then((file: NewtonFile | undefined | null) => {
this.setSession(file);
});
}
private async setSession(session: EditSession | undefined | null) {
if ( !session ) return;
private async setSession(file: NewtonFile | undefined | null) {
if ( !file ) return;
let editorComponent = this.getActiveEditorComponent();
let editor = editorComponent.editor;
let editor = this.getActiveEditor();
editor?.setSession(session);
editorComponent.activeFile = file;
editor.setSession(file.session);
}
private getSession() {
let editorComponent = this.editors.get(this.activeEditor)?.instance;
let editor = editorComponent.editor;
return editor?.getSession();
return editor.getSession();
}
private getActiveEditorComponent(): any {
@@ -159,7 +164,7 @@ export class EditorsComponent {
return editor;
}
private async loadFilesList(files: Array<NewtonFile>): Promise<EditSession | undefined | null> {
private async loadFilesList(files: Array<NewtonFile>): Promise<NewtonFile | undefined | null> {
for (let i = 0; i < files.length; i++) {
const file = files[i];
const path = window.fs.getPathForFile(file);
@@ -171,7 +176,7 @@ export class EditorsComponent {
this.addTab(file);
}
return files[ files.length - 1 ].session;
return files[ files.length - 1 ];
}
private async addFile(path: string, file: NewtonFile): Promise<void> {