-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rename Mapping Group to Capability Group across codebase
Rename Mapping Group to Capability Group across codebase. feat: add "clear search" button feat: add "collapse/uncollapse all mapping objects" menu items feat: add basic runtime error notifications feat: add auto-migrate capabilities to framework objects fix: remove "Layout" menu fix: correct "Change Log" link fix: remove deprecated mapping statuses fix: deserialize mapping object `references` to a list of links (not characters) fix: deserialize empty strings to `null` on select mapping object fields fix: eliminate scroll glitch that occurs when moving uncollapsed mapping objects fix: eliminate scroll glitch that occurs when undeleting end-of-file mapping objects perf: improve file indexing speed perf: improve import file speed perf: improve mass cut, copy, and paste speed perf: improve mass delete speed
- Loading branch information
1 parent
d611e1f
commit 8f41917
Showing
49 changed files
with
874 additions
and
395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 61 additions & 61 deletions
122
src/mappings_editor/src/assets/scripts/Application/Commands/FileManagement/ImportFile.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,90 @@ | ||
import * as EditorCommands from "@/assets/scripts/MappingFileEditor/EditorCommands"; | ||
import { AppCommand } from "../AppCommand"; | ||
import { MappingFileEditor, Reactivity } from "@/assets/scripts/MappingFileEditor"; | ||
import type { ApplicationStore } from "@/stores/ApplicationStore"; | ||
import type { MappingFile, MappingObject } from "@/assets/scripts/MappingFile"; | ||
import type { MappingFileExport } from "@/assets/scripts/MappingFileAuthority"; | ||
import { MappingFileView, MappingObjectView } from "@/assets/scripts/MappingFileEditor"; | ||
import type { MappingFileAuthority, MappingFileExport } from "@/assets/scripts/MappingFileAuthority"; | ||
|
||
export class ImportFile extends AppCommand { | ||
|
||
/** | ||
* The file to import. | ||
/** | ||
* The editor to import into. | ||
*/ | ||
public readonly editor: MappingFileEditor; | ||
|
||
/** | ||
* The mapping file authority to use. | ||
*/ | ||
private _importedFile: MappingFileExport; | ||
public readonly fileAuthority: MappingFileAuthority; | ||
|
||
/** | ||
* The application context. | ||
* The mapping file export to import. | ||
*/ | ||
private _context: ApplicationStore; | ||
public readonly importFile: MappingFileExport; | ||
|
||
|
||
/** | ||
* Loads a new mapping objects from an imported file into the application. | ||
* Imports a mapping file export into the active editor. | ||
* @param context | ||
* The application context. | ||
* @param importedFile | ||
* The mapping file to load merge. | ||
* @param importFile | ||
* The mapping file export to import. | ||
*/ | ||
constructor(context: ApplicationStore, importedFile: MappingFileExport) { | ||
constructor(context: ApplicationStore, importFile: MappingFileExport) { | ||
super(); | ||
this._context = context; | ||
this._importedFile = importedFile; | ||
const activeEditorFile = this._context.activeEditor.file; | ||
// throw error if imported file's source framework does not match the current file's source framework | ||
if (activeEditorFile.sourceFramework !== this._importedFile.source_framework) { | ||
alert("The imported file's mapping framework must be the same as the active file's mapping framework.") | ||
throw new Error(`The imported file's mapping framework must be the same as the active file's mapping framework.`) | ||
} | ||
// throw error if imported file's target framework does not match the current file's target framework | ||
if (activeEditorFile.targetFramework !== this._importedFile.target_framework){ | ||
alert("The imported file's target framework must be the same as the active file's target framework.") | ||
throw new Error(`The imported file's target framework must be the same as the active file's target framework.`) | ||
} | ||
// if versions do not match, explicitly set the imported file's mapping objects to the version | ||
if (activeEditorFile.sourceVersion !== this._importedFile.source_version) { | ||
for (const mappingObject of this._importedFile.mapping_objects){ | ||
mappingObject.source_version = this._importedFile.source_version | ||
} | ||
this.editor = context.activeEditor as MappingFileEditor; | ||
this.fileAuthority = context.fileAuthority as MappingFileAuthority; | ||
// Validate source framework | ||
if(this.editor.file.sourceFramework !== importFile.source_framework) { | ||
throw new Error( | ||
`The imported file's source framework ('${ | ||
importFile.source_framework | ||
}') doesn't match this file's source framework ('${ | ||
this.editor.file.sourceFramework | ||
}').` | ||
); | ||
} | ||
if (activeEditorFile.targetVersion !== this._importedFile.target_version) { | ||
for (const mappingObject of this._importedFile.mapping_objects){ | ||
mappingObject.target_version = this._importedFile.target_version | ||
} | ||
// Validate target framework | ||
if(this.editor.file.targetFramework !== importFile.target_framework) { | ||
throw new Error( | ||
`The imported file's target framework ('${ | ||
importFile.target_framework | ||
}') doesn't match this file's target framework ('${ | ||
this.editor.file.targetFramework | ||
}').` | ||
); | ||
} | ||
this.importFile = importFile; | ||
} | ||
|
||
|
||
/** | ||
* Executes the command. | ||
*/ | ||
public execute(): void { | ||
// unselect any items that are currently selected | ||
this._context.activeEditor.view.setAllItemsSelect(false); | ||
|
||
let objIds: Set<string> = new Set(); | ||
let objects: MappingObject[] = []; | ||
|
||
let rawFile = MappingFileView.toRaw(this._context.activeEditor.file); | ||
let rawFileAuthority = MappingFileView.toRaw(this._context.fileAuthority) | ||
for (const mappingObj of this._importedFile.mapping_objects){ | ||
const mappingObjExport = rawFileAuthority.initializeMappingObjectExport( | ||
mappingObj, rawFile as MappingFile | ||
); | ||
objects.push(mappingObjExport) | ||
// store ids of inserted objects | ||
objIds.add(mappingObjExport.id); | ||
} | ||
rawFile.insertMappingObjectsAfter(objects); | ||
this._context.activeEditor.view.rebuildBreakouts(); | ||
|
||
// move view to the item in imported items that has the lowest headOffset | ||
const topItem = this._context.activeEditor.view.getItems(o => objIds.has(o.id)).next().value; | ||
this._context.activeEditor.view.moveToViewItem(topItem.object.id, 0, true, false); | ||
|
||
// select each inserted object | ||
for(const objId of objIds){ | ||
this._context.activeEditor.view.getItem(objId).select(true); | ||
const file = this.editor.file; | ||
const view = this.editor.view; | ||
const rawEditor = Reactivity.toRaw(this.editor); | ||
const rawFileAuthority = Reactivity.toRaw(this.fileAuthority); | ||
// Compile mapping items | ||
const objs = new Map(); | ||
for(const exp of this.importFile.mapping_objects) { | ||
const obj = rawFileAuthority.initializeMappingObjectExport(exp, rawEditor.file); | ||
objs.set(obj.id, obj); | ||
} | ||
this._context.activeEditor.reindexFile([...objIds]); | ||
// Configure view command | ||
const cmd = EditorCommands.createSplitPhaseViewCommand( | ||
EditorCommands.insertMappingObjects(file, [...objs.values()]), | ||
() => [ | ||
EditorCommands.rebuildViewBreakouts(view), | ||
EditorCommands.unselectAllMappingObjectViews(view), | ||
EditorCommands.selectMappingObjectViewsById(view, [...objs.keys()]) | ||
] | ||
) | ||
// Execute insert | ||
this.editor.execute(cmd); | ||
// Move first item into view | ||
const firstItem = view.getItems(o => objs.has(o.id)).next().value; | ||
view.moveToViewItem(firstItem.object.id, 0, true, false); | ||
} | ||
|
||
} |
Oops, something went wrong.