Skip to content

Commit

Permalink
Рефакторинг EditorManager, фикс метки начального состояния (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryzZz authored Dec 6, 2023
1 parent e07f19e commit e1445cc
Show file tree
Hide file tree
Showing 13 changed files with 321 additions and 259 deletions.
8 changes: 4 additions & 4 deletions src/renderer/src/components/Sidebar/Compiler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ export const CompilerTab: React.FC<CompilerProps> = ({

const handleSaveBinaryIntoFolder = async () => {
const preparedData = await Compiler.prepareToSave(compilerData!.binary!);
manager.saveIntoFolder(preparedData);
manager.files.saveIntoFolder(preparedData);
};

const handleCompile = async () => {
if (!name) return;

Compiler.filename = name;
manager.compile();
manager.files.compile();
};

const handleSaveSourceIntoFolder = async () => {
await manager.saveIntoFolder(compilerData!.source!);
await manager.files.saveIntoFolder(compilerData!.source!);
};

const handleAddStdoutTab = () => {
Expand Down Expand Up @@ -92,7 +92,7 @@ export const CompilerTab: React.FC<CompilerProps> = ({

useEffect(() => {
if (importData && openData) {
manager.parseImportData(importData, openData!);
manager.files.parseImportData(importData, openData!);
setImportData(undefined);
}
}, [importData]);
Expand Down
6 changes: 2 additions & 4 deletions src/renderer/src/components/Sidebar/Loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
Flasher,
} from '@renderer/components/Modules/Flasher';
import { FlasherSelectModal } from '@renderer/components/serverSelect/FlasherSelectModal';
import { EditorManager } from '@renderer/lib/data/EditorManager';
import { CompilerResult } from '@renderer/types/CompilerTypes';
import { Device } from '@renderer/types/FlasherTypes';

Expand All @@ -22,11 +21,10 @@ import { Settings } from '../Modules/Settings';
const LAPKI_FLASHER = window.api.LAPKI_FLASHER;

export interface FlasherProps {
manager: EditorManager | null;
compilerData: CompilerResult | undefined;
}

export const Loader: React.FC<FlasherProps> = ({ manager, compilerData }) => {
export const Loader: React.FC<FlasherProps> = ({ compilerData }) => {
const [currentDevice, setCurrentDevice] = useState<string | undefined>(undefined);
const [connectionStatus, setFlasherConnectionStatus] = useState<string>('Не подключен.');
const [devices, setFlasherDevices] = useState<Map<string, Device>>(new Map());
Expand Down Expand Up @@ -54,7 +52,7 @@ export const Loader: React.FC<FlasherProps> = ({ manager, compilerData }) => {
const isActive = (id: string) => currentDevice === id;

const handleGetList = async () => {
manager?.getList();
Flasher.getList();
};

const handleFlash = async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const Sidebar: React.FC<SidebarProps> = ({
const isEditorDataStale = manager.useData('isStale');

const handleImport = async () => {
await manager.import(setOpenData);
await manager.files.import(setOpenData);
};

const menus = useMemo(
Expand All @@ -75,7 +75,7 @@ export const Sidebar: React.FC<SidebarProps> = ({
setCompilerStatus={setCompilerStatus}
openImportError={openImportError}
/>,
<Loader manager={manager} compilerData={compilerData} />,
<Loader compilerData={compilerData} />,
<History editor={editor} />,
<Setting />,
],
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/src/hooks/useDiagramContextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const useDiagramContextMenu = (editor: CanvasEditor | null, manager: Edit
openTab({
type: 'code',
name: manager.data.name ?? 'Безымянная',
code: manager.getDataSerialized('JSON'),
code: manager.serializer.getAll('JSON'),
language: 'json',
});
},
Expand Down Expand Up @@ -133,7 +133,7 @@ export const useDiagramContextMenu = (editor: CanvasEditor | null, manager: Edit
openTab({
type: 'state',
name: state.data.name,
code: manager.getStateSerialized(state.id) ?? '',
code: manager.serializer.getState(state.id) ?? '',
language: 'json',
});
},
Expand Down Expand Up @@ -248,7 +248,7 @@ export const useDiagramContextMenu = (editor: CanvasEditor | null, manager: Edit
openTab({
type: 'transition',
name: transition.id,
code: manager.getTransitionSerialized(transition.id) ?? '',
code: manager.serializer.getTransition(transition.id) ?? '',
language: 'json',
});
},
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/src/hooks/useFileOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const useFileOperations = (args: useFileOperationsArgs) => {
};

const performOpenFile = async (path?: string) => {
const result = await manager?.open(openImportError, path);
const result = await manager?.files.open(openImportError, path);

if (result && isLeft(result)) {
const cause = unwrapEither(result);
Expand Down Expand Up @@ -73,12 +73,12 @@ export const useFileOperations = (args: useFileOperationsArgs) => {
};

const performNewFile = (idx: string) => {
manager?.newFile(idx);
manager?.files.newFile(idx);
clearTabs();
};

const handleSaveAsFile = async () => {
const result = await manager?.saveAs();
const result = await manager?.files.saveAs();
if (result && isLeft(result)) {
const cause = unwrapEither(result);
if (cause) {
Expand All @@ -88,7 +88,7 @@ export const useFileOperations = (args: useFileOperationsArgs) => {
};

const handleSaveFile = async () => {
const result = await manager?.save();
const result = await manager?.files.save();
if (result && isLeft(result)) {
const cause = unwrapEither(result);
if (cause) {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/lib/basic/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ export class Container extends EventEmitter<ContainerEvents> {
this.app.keyboard.on('ctrly', this.machineController.undoRedo.redo);
this.app.keyboard.on('ctrlc', this.machineController.copySelected);
this.app.keyboard.on('ctrlv', this.machineController.pasteSelected);
this.app.keyboard.on('ctrls', this.app.manager.save);
this.app.keyboard.on('ctrlshifta', this.app.manager.saveAs);
this.app.keyboard.on('ctrls', this.app.manager.files.save);
this.app.keyboard.on('ctrlshifta', this.app.manager.files.saveAs);

this.app.mouse.on('mousedown', this.handleMouseDown);
this.app.mouse.on('mouseup', this.handleMouseUp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { beforeEach, describe, expect, test } from 'vitest';

import { EditorManager } from './EditorManager';

import { emptyElements } from '../../types/diagram';
import { emptyElements } from '../../../types/diagram';

const em = new EditorManager();
em.init('basename', 'name', { ...emptyElements(), transitions: [] });
Expand Down
Loading

0 comments on commit e1445cc

Please sign in to comment.