full auto conversion
This commit is contained in:
@@ -19,6 +19,11 @@
|
||||
"command": "tct-vscode-editor.importTCTInputFile",
|
||||
"mac": "Cmd+; Cmd+i",
|
||||
"key": "Ctrl+; Ctrl+i"
|
||||
},
|
||||
{
|
||||
"command": "tct-vscode-editor.fullAutoConvert",
|
||||
"mac": "Cmd+; Cmd+a",
|
||||
"key": "Ctrl+; Ctrl+a"
|
||||
}
|
||||
],
|
||||
"customEditors": [
|
||||
@@ -37,6 +42,10 @@
|
||||
{
|
||||
"title": "tct-vscode-editor: Import a file to a new TCT file",
|
||||
"command": "tct-vscode-editor.importTCTInputFile"
|
||||
},
|
||||
{
|
||||
"title": "tct-vscode-editor: Convert as many blocks as possible automatically",
|
||||
"command": "tct-vscode-editor.fullAutoConvert"
|
||||
}
|
||||
],
|
||||
"configuration": {
|
||||
|
@@ -7,9 +7,14 @@
|
||||
(let [provider (new EditorProvider context)]
|
||||
(Vscode.window.registerCustomEditorProvider "tct.splitView" provider)))
|
||||
|
||||
(var &mut :String currentFilename null)
|
||||
(var :Map<String,FileConversionProject> conversionProjects (new Map))
|
||||
(var :Map<String,Void->Void> fullUpdateFunctions (new Map))
|
||||
|
||||
(defNew [&prop :ExtensionContext context])
|
||||
|
||||
(method :Promise<Void> resolveCustomTextEditor [:TextDocument document :WebviewPanel webviewPanel :CancellationToken _token]
|
||||
(set currentFilename document.fileName)
|
||||
(set webviewPanel.webview.options (object enableScripts true))
|
||||
(set webviewPanel.webview.html (htmlForWebview webviewPanel.webview))
|
||||
|
||||
@@ -17,7 +22,11 @@
|
||||
|
||||
(let [project (FileConversionProject.loadDirectory (document.fileName.directory))
|
||||
postMessage ->[:Message message] (webviewPanel.webview.postMessage (Json.stringify message))
|
||||
requestFullUpdate ->:Void (postMessage (Initialize project.blocks))
|
||||
reportRequest ->:Void [:Bool result] (postMessage (if result RequestSuccess RequestFailure))]
|
||||
|
||||
(dictSet conversionProjects document.fileName project)
|
||||
(dictSet fullUpdateFunctions document.fileName requestFullUpdate)
|
||||
|
||||
(localFunction :Void chooseConversion [blockIdx]
|
||||
(let [validConversions (project.validConversions blockIdx ->m (errorMessage m))]
|
||||
@@ -73,7 +82,7 @@
|
||||
(RequestRedo
|
||||
(reportRequest (project.redoChange)))
|
||||
(RequestFullUpdate
|
||||
(postMessage (Initialize project.blocks)))
|
||||
(requestFullUpdate))
|
||||
(otherwise
|
||||
(errorMessage "Unhandled message from editor: $message")))))
|
||||
|
||||
|
@@ -26,6 +26,13 @@
|
||||
(let [project (FileConversionProject.importFile file outputType splitBy outBlockTerminator)]
|
||||
(executeCommand "workbench.action.quickOpen" "${dir}/${project.tctFile}"))))))))
|
||||
|
||||
(defCommand context fullAutoConvert "Convert as many blocks as possible automatically" "C-; C-a" []
|
||||
(let [filename EditorProvider.currentFilename
|
||||
project (dictGet EditorProvider.conversionProjects filename)
|
||||
requestFullUpdate (dictGet EditorProvider.fullUpdateFunctions filename)]
|
||||
(project.fullAutoConvert ->message (errorMessage message))
|
||||
(requestFullUpdate)))
|
||||
|
||||
// Add your extension's configuration here with (defConfiguration <...>):
|
||||
(defConfiguration
|
||||
:Array<String> nameExceptions
|
||||
|
@@ -219,4 +219,13 @@
|
||||
(try (convert source)
|
||||
(catch [e] (reportError "Conversion error: $e") "Conversion error: $e"))))
|
||||
(otherwise)))
|
||||
validMap))
|
||||
validMap))
|
||||
|
||||
(method :Void fullAutoConvert [:String->Dynamic reportError]
|
||||
(doFor [idx block] (enumerate blocks)
|
||||
(print "Converting block $(+ idx 1)/${blocks.length}")
|
||||
(when block.locked (continue))
|
||||
(let [vc (validConversions idx reportError)]
|
||||
(when (= 1 (count vc))
|
||||
(doFor =>conversionName text vc
|
||||
(editBlock idx null text null))))))
|
Reference in New Issue
Block a user