Add load from file
This commit is contained in:
@@ -98,7 +98,7 @@
|
|||||||
"resizable": true,
|
"resizable": true,
|
||||||
"title": "BufPiv",
|
"title": "BufPiv",
|
||||||
"hiddenTitle": true,
|
"hiddenTitle": true,
|
||||||
"width": 800,
|
"width": 1200,
|
||||||
"titleBarStyle": "Overlay",
|
"titleBarStyle": "Overlay",
|
||||||
"fileDropEnabled": false
|
"fileDropEnabled": false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
<app-editor
|
<app-editor
|
||||||
[selectedMessage]="selectedMessage()!"
|
[selectedMessage]="selectedMessage()!"
|
||||||
[showRaw]="previewOpen()"
|
[showRaw]="previewOpen()"
|
||||||
|
[selectedFile]="selectedFile()"
|
||||||
></app-editor>
|
></app-editor>
|
||||||
}
|
}
|
||||||
</mat-sidenav-content>
|
</mat-sidenav-content>
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import {
|
|||||||
} from './file-tree/file-tree.component';
|
} from './file-tree/file-tree.component';
|
||||||
import { ProtoMessage } from './model/proto-message.model';
|
import { ProtoMessage } from './model/proto-message.model';
|
||||||
import { ProtoDefinitionSelectorComponent } from './proto-definition-selector/proto-definition-selector.component';
|
import { ProtoDefinitionSelectorComponent } from './proto-definition-selector/proto-definition-selector.component';
|
||||||
import { readTextFile } from '@tauri-apps/api/fs';
|
|
||||||
const mobileBreakpoints = [Breakpoints.Handset, Breakpoints.TabletPortrait];
|
const mobileBreakpoints = [Breakpoints.Handset, Breakpoints.TabletPortrait];
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -37,7 +36,7 @@ const mobileBreakpoints = [Breakpoints.Handset, Breakpoints.TabletPortrait];
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
protected selectedFileContents = signal<string | undefined>(undefined);
|
protected selectedFile = signal<string | undefined>(undefined);
|
||||||
protected selectedMessage = signal<ProtoMessage | undefined>(undefined);
|
protected selectedMessage = signal<ProtoMessage | undefined>(undefined);
|
||||||
protected rightSideOpen = signal(true);
|
protected rightSideOpen = signal(true);
|
||||||
protected leftSideOpen = signal(true);
|
protected leftSideOpen = signal(true);
|
||||||
@@ -60,7 +59,7 @@ export class AppComponent {
|
|||||||
|
|
||||||
protected async fileSelected(file: FileOrFolder) {
|
protected async fileSelected(file: FileOrFolder) {
|
||||||
try {
|
try {
|
||||||
this.selectedFileContents.set(await readTextFile(file.path));
|
this.selectedFile.set(file.path);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
alert(
|
alert(
|
||||||
|
|||||||
@@ -3,18 +3,18 @@ import {
|
|||||||
Component,
|
Component,
|
||||||
ElementRef,
|
ElementRef,
|
||||||
SecurityContext,
|
SecurityContext,
|
||||||
computed,
|
|
||||||
effect,
|
effect,
|
||||||
input,
|
input,
|
||||||
signal,
|
signal,
|
||||||
viewChild,
|
viewChild,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
|
import { DomSanitizer } from '@angular/platform-browser';
|
||||||
|
import { readTextFile } from '@tauri-apps/api/fs';
|
||||||
import hljs from 'highlight.js/lib/core';
|
import hljs from 'highlight.js/lib/core';
|
||||||
import { ProtoMessage } from '../model/proto-message.model';
|
import { ProtoMessage } from '../model/proto-message.model';
|
||||||
import { ProtoFieldComponent } from './proto-field/proto-field.component';
|
import { ProtoFieldComponent } from './proto-field/proto-field.component';
|
||||||
import { DomSanitizer } from '@angular/platform-browser';
|
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-editor',
|
selector: 'app-editor',
|
||||||
@@ -24,8 +24,7 @@ import { MatSnackBar } from '@angular/material/snack-bar';
|
|||||||
styleUrl: './editor.component.scss',
|
styleUrl: './editor.component.scss',
|
||||||
})
|
})
|
||||||
export class EditorComponent {
|
export class EditorComponent {
|
||||||
// TODO: This needs to be reworked so we have a local property and implement some kind of auto-save
|
selectedFile = input<string>();
|
||||||
fileContents = input<string>();
|
|
||||||
selectedMessage = input.required<ProtoMessage>();
|
selectedMessage = input.required<ProtoMessage>();
|
||||||
|
|
||||||
showRaw = input<boolean>(true);
|
showRaw = input<boolean>(true);
|
||||||
@@ -63,6 +62,28 @@ export class EditorComponent {
|
|||||||
},
|
},
|
||||||
{ allowSignalWrites: true }
|
{ allowSignalWrites: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
effect(async () => {
|
||||||
|
const selectedFile = this.selectedFile();
|
||||||
|
console.log('selected file' + selectedFile);
|
||||||
|
if (selectedFile) {
|
||||||
|
const fileContents = await readTextFile(selectedFile);
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(fileContents);
|
||||||
|
this.values.set(parsed);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(
|
||||||
|
`Failed to parse contents of file ${selectedFile}`,
|
||||||
|
err
|
||||||
|
);
|
||||||
|
this.snackBar.open(
|
||||||
|
`Failed to parse contents of file ${selectedFile}, please check the file is correctly formatted`,
|
||||||
|
'Dismiss',
|
||||||
|
{ duration: 5000 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected updateValue(key: string, value: any) {
|
protected updateValue(key: string, value: any) {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<h2>@if(workspaceName()) {workspaceName()} @else { No Worspace Selected}</h2>
|
<h2>
|
||||||
|
@if(workspaceName()) { {{ workspaceName() }} } @else { No Worspace Selected}
|
||||||
|
</h2>
|
||||||
@if(!selectedDirectory()) {
|
@if(!selectedDirectory()) {
|
||||||
<div>
|
<div>
|
||||||
<button mat-button (click)="selectDirectory()" style="margin: auto">
|
<button mat-button (click)="selectDirectory()" style="margin: auto">
|
||||||
|
|||||||
@@ -160,8 +160,10 @@ export class ProtoDefinitionSelectorComponent {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const parsed = JSON.parse(fileContents) as ProtoMessage[];
|
const parsed = JSON.parse(fileContents) as ProtoMessage[];
|
||||||
this.allProtoFiles.set(parsed);
|
this.allProtoFiles.set(
|
||||||
this.selectedDefinition.set(parsed);
|
parsed.sort((a, b) => a.name.localeCompare(b.name))
|
||||||
|
);
|
||||||
|
this.selectedDefinition.set(this.allProtoFiles());
|
||||||
this.currentFiles.set([]);
|
this.currentFiles.set([]);
|
||||||
for (const message of parsed) {
|
for (const message of parsed) {
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user