Skip to content

Commit

Permalink
Basic UI <-> Service Messages Working
Browse files Browse the repository at this point in the history
  • Loading branch information
stricklandrbls committed May 7, 2024
1 parent 9974c2e commit 4e7bdc4
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 45 deletions.
3 changes: 2 additions & 1 deletion src/dataEditor/dataEditorClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,11 @@ const StandaloneInitializer: DataEditorInitializer = {
const statusBar = new StatusBar()
statusBar.update('[Data Editor]: Extracting Configuration Variables')
let configVars = editor_config.extractConfigurationVariables()
let server = new OmegaEditServer('127.0.0.1', configVars.port)

let server = new OmegaEditServer('127.0.0.1', configVars.port)
await server.start(statusBar)
statusBar.update('[Data Editor]: Server Startup Complete!')

/* Moving on w/ assumption that server is up and running */
const editor = new StandaloneEditor(params.ctx, configVars)
await editor.getServiceFrom(server)
Expand Down
7 changes: 5 additions & 2 deletions src/dataEditor/include/client/dataEditorClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { IEditServiceProvider } from '../server/Server'
import { IEditService, IServiceMediator } from '../service/editorService'
import {
IEditService,
IEditServiceProvider,
IServiceMediator,
} from '../service/editorService'
import { DataEditorUI } from './dataEditorUI'
export abstract class DataEditor implements IServiceMediator {
protected abstract fileToEdit: string
Expand Down
2 changes: 2 additions & 0 deletions src/dataEditor/include/client/dataEditorUI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface DataEditorUI {
show(): Promise<void>
sendMessage(msg: any): void
setInputHandler(handler: UIInputHandler): void
}
export type UIInputHandler = (input: any) => any
18 changes: 6 additions & 12 deletions src/dataEditor/include/omegaEdit/Session.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import {
ALL_EVENTS,
CreateSessionResponse,
EditorClient,
EventSubscriptionRequest,
ViewportDataResponse,
ViewportEvent,
ViewportEventKind,
createViewport,
getByteOrderMark,
getClient,
getContentType,
getLanguage,
getLogger,
getViewportData,
} from '@omega-edit/client'
import EventEmitter from 'events'
import { Viewport } from './Viewport'
Expand Down Expand Up @@ -48,9 +39,14 @@ export class Session {
this.onMetadataUpdate(this.metadata)
})
}

info() {
return { ...this.metadata }
}
getViewports() {
return this.viewports
}

async createViewport(
// client: EditorClient,
offset: number,
Expand Down Expand Up @@ -93,9 +89,7 @@ export class Session {
})
})
}
info() {
return { ...this.metadata }
}

private async populateAsyncMetadata() {
const contentTypeResponse = await getContentType(
this.id,
Expand Down
2 changes: 1 addition & 1 deletion src/dataEditor/include/omegaEdit/Viewport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createViewport, modifyViewport } from '@omega-edit/client'
import { modifyViewport } from '@omega-edit/client'

export class Viewport {
constructor(
Expand Down
7 changes: 5 additions & 2 deletions src/dataEditor/include/omegaEdit/omegaEditServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ import {
import assert from 'assert'
import path from 'path'
import { APP_DATA_PATH } from '../../config'
import { IEditServiceProvider, ServerProcess } from '../server/Server'
import { ServerProcess } from '../server/Server'
import { IStatusUpdater } from '../status/IStatus'

import * as fs from 'fs'
import { IServiceMediator } from '../service/editorService'
import {
IEditServiceProvider,
IServiceMediator,
} from '../service/editorService'
import { OmegaEditService } from './omegaEditService'

export class OmegaEditServer implements IEditServiceProvider {
Expand Down
15 changes: 5 additions & 10 deletions src/dataEditor/include/omegaEdit/omegaEditService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
EditorClient,
createSession,
getClient,
modifyViewport,
} from '@omega-edit/client'
import { createSession } from '@omega-edit/client'
import { IEditService, IServiceMediator } from '../service/editorService'
import { Session } from './Session'
import { Viewport } from './Viewport'
Expand All @@ -12,12 +7,12 @@ export class OmegaEditService extends IEditService {
static ViewportCapacity = 1024
private session: Session | undefined = undefined

constructor(
mediator: IServiceMediator,
private client: EditorClient
) {
constructor(mediator: IServiceMediator) {
super(mediator)
}
request(msg: { type: string; data: any }) {
console.debug(`OmegaEditService received request ${msg.type}`)
}
async set(editingFile: string) {
try {
this.session = new Session(await createSession(editingFile), (data) => {
Expand Down
8 changes: 1 addition & 7 deletions src/dataEditor/include/server/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// - getHeartbeat()

// import net from 'net'
import { IEditService, IServiceMediator } from '../service/editorService'
// import { IEditService, IServiceMediator } from '../service/editorService'

export type ServerProcess = {
pidFile: string
Expand All @@ -29,9 +29,3 @@ export type ServerProcess = {
// }, this.interval)
// }
// }
export interface IEditServiceProvider {
getService(
mediator: IServiceMediator,
targetFile: string
): Promise<IEditService>
}
10 changes: 9 additions & 1 deletion src/dataEditor/include/service/editorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ export interface IServiceMediator {
notify(notification: { id: string; data: any }): any
}
export abstract class IEditService {
constructor(readonly mediator: IServiceMediator) {}
constructor(protected mediator: IServiceMediator) {}
abstract request(data: any): any
abstract set(editingFile: string): any
abstract destroy(): void
}

export interface IEditServiceProvider {
getService(
mediator: IServiceMediator,
targetFile: string
): Promise<IEditService>
}
28 changes: 25 additions & 3 deletions src/dataEditor/standalone/standaloneEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode'
import * as editor_config from '../config'
import { DataEditor } from '../include/client/dataEditorClient'
import { OmegaEditService } from '../include/omegaEdit/omegaEditService'
import { DataEditorUI } from '../include/client/dataEditorUI'
import { DataEditorUI, UIInputHandler } from '../include/client/dataEditorUI'
import { SvelteWebviewInitializer } from '../svelteWebviewInitializer'

export class StandaloneEditor extends DataEditor implements vscode.Disposable {
Expand All @@ -23,8 +23,12 @@ export class StandaloneEditor extends DataEditor implements vscode.Disposable {
)
this.ui?.sendMessage(notification)
}

initializeUI(ui: DataEditorWebviewPanel): void {
this.ui = ui
this.ui.setInputHandler((uiMsg: any) => {
this.editService?.request(uiMsg)
})
setTimeout(() => {
// Simulate UI Request to scroll viewport
const request = {
Expand All @@ -40,6 +44,7 @@ export class StandaloneEditor extends DataEditor implements vscode.Disposable {
)
}, 4000)
}

async getFile(): Promise<void> {
const fileUri = await vscode.window.showOpenDialog({
canSelectMany: false,
Expand All @@ -51,20 +56,37 @@ export class StandaloneEditor extends DataEditor implements vscode.Disposable {
}
}

interface IDataEditorInputHandler {

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 11)

'IDataEditorInputHandler' is declared but never used.

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 8)

'IDataEditorInputHandler' is declared but never used.

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 11)

'IDataEditorInputHandler' is declared but never used.

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 17)

'IDataEditorInputHandler' is declared but never used.

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 8)

'IDataEditorInputHandler' is declared but never used.

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 17)

'IDataEditorInputHandler' is declared but never used.

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 17)

'IDataEditorInputHandler' is declared but never used.

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 17)

'IDataEditorInputHandler' is declared but never used.

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 11)

'IDataEditorInputHandler' is declared but never used.

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 8)

'IDataEditorInputHandler' is declared but never used.

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 8)

'IDataEditorInputHandler' is declared but never used.

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 11)

'IDataEditorInputHandler' is declared but never used.

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 11)

'IDataEditorInputHandler' is declared but never used.

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16, Java: 8)

'IDataEditorInputHandler' is declared but never used.

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16, Java: 11)

'IDataEditorInputHandler' is declared but never used.

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 8)

'IDataEditorInputHandler' is declared but never used.

Check failure on line 59 in src/dataEditor/standalone/standaloneEditor.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 17)

'IDataEditorInputHandler' is declared but never used.
handle(input: any): any
}

/*
UI capable inputs that need to send to service:
Viewport:
- seek
- search
- replace
- edit (delete)
Session:
- createViewport ( for multiple viewports to display? )
*/
export class DataEditorWebviewPanel implements DataEditorUI {
protected panel: vscode.WebviewPanel
private view: string = 'dataeditor'
private view: string = 'dataEditor'
private svelteWebviewInitializer: SvelteWebviewInitializer
constructor(context: vscode.ExtensionContext, title: string) {
this.svelteWebviewInitializer = new SvelteWebviewInitializer(context)
this.panel = vscode.window.createWebviewPanel(
this.view,
title,
vscode.ViewColumn.Active,
{ enableScripts: true, retainContextWhenHidden: true }
)
this.svelteWebviewInitializer = new SvelteWebviewInitializer(context)
this.svelteWebviewInitializer.initialize(this.view, this.panel.webview)
}
setInputHandler(handler: UIInputHandler): void {
this.panel.webview.onDidReceiveMessage(handler, this)
}
sendMessage(msg: any): void {
this.panel.webview.postMessage(msg)
}
Expand Down
32 changes: 26 additions & 6 deletions src/svelte/src/components/dataEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ limitations under the License.
} from './DataDisplays/CustomByteDisplay/BinaryData'
import { byte_count_divisible_offset } from '../utilities/display'
import Help from './layouts/Help.svelte'
import Button from './Inputs/Buttons/Button.svelte'
$: $UIThemeCSSClass = $darkUITheme ? CSSThemeClass.Dark : CSSThemeClass.Light
Expand Down Expand Up @@ -94,8 +95,12 @@ limitations under the License.
const nearestBPRdivisibleViewportFileOffset = byte_count_divisible_offset(
viewportStartOffset,
bytesPerRow
)
return (nearestBPRdivisibleTargetFileOffset - nearestBPRdivisibleViewportFileOffset) / bytesPerRow
)
return (
(nearestBPRdivisibleTargetFileOffset -
nearestBPRdivisibleViewportFileOffset) /
bytesPerRow
)
}
function fetchable_content(offset: number): boolean {
Expand Down Expand Up @@ -130,7 +135,13 @@ limitations under the License.
$dataFeedAwaitRefresh = true
const fetchOffset = Math.max(0, byte_count_divisible_offset(offsetArg - (VIEWPORT_SCROLL_INCREMENT-$bytesPerRow), $bytesPerRow))
const fetchOffset = Math.max(
0,
byte_count_divisible_offset(
offsetArg - (VIEWPORT_SCROLL_INCREMENT - $bytesPerRow),
$bytesPerRow
)
)
$dataFeedLineTop = offset_to_viewport_line_number(
offsetArg,
Expand Down Expand Up @@ -252,7 +263,8 @@ limitations under the License.
function handleKeyBind(event: Event) {
const kbdEvent = event as KeyboardEvent
if (key_is_mappable(kbdEvent.key)) {
if(document.activeElement) // document.activeElement is possibly undefined / null
if (document.activeElement)
// document.activeElement is possibly undefined / null
elementKeypressEventMap.run(document.activeElement.id, kbdEvent)
return
}
Expand Down Expand Up @@ -314,16 +326,24 @@ limitations under the License.
on:handleEditorEvent={handleEditorEvent}
on:traverse-file={traversalEventHandler}
on:seek={seekEventHandler}
/>
/>

<Help />
<hr />
<ServerMetrics />
<Button
description="UI Input Test"
fn={() => {
vscode.postMessage({
type: 'ui-test',
data: { viewportId: '1234', data: 0x1234 },
})
}}>Send UI Input Test</Button
>
</body>

<!-- svelte-ignore css-unused-selector -->
<style lang="scss">
div.test {
display: flex;
flex-wrap: wrap;
Expand Down

0 comments on commit 4e7bdc4

Please sign in to comment.