Skip to content

Commit

Permalink
Fix for async open/save dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
niklauslee committed Aug 7, 2024
1 parent da89d9c commit 5dbdc8d
Show file tree
Hide file tree
Showing 6 changed files with 2,896 additions and 2,653 deletions.
52 changes: 30 additions & 22 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,55 @@
*
*/

const xmi21reader = require('./xmi21-reader')
const xmi21writer = require('./xmi21-writer')
require('./uml2-import')
require('./uml2-export')
const xmi21reader = require("./xmi21-reader");
const xmi21writer = require("./xmi21-writer");
require("./uml2-import");
require("./uml2-export");

const XMI_FILE_FILTERS = [
{name: 'XMI Files', extensions: ['xmi']},
{name: 'All Files', extensions: ['*']}
]
{ name: "XMI Files", extensions: ["xmi"] },
{ name: "All Files", extensions: ["*"] },
];

function _handleXMI21Import (fullPath) {
async function _handleXMI21Import(fullPath) {
if (fullPath) {
xmi21reader.loadFromFile(fullPath)
xmi21reader.loadFromFile(fullPath);
} else {
var files = app.dialogs.showOpenDialog('Select a XMI File (.xmi)', null, XMI_FILE_FILTERS)
var files = await app.dialogs.showOpenDialogAsync(
"Select a XMI File (.xmi)",
null,
XMI_FILE_FILTERS,
);
if (files && files.length > 0) {
try {
xmi21reader.loadFromFile(files[0])
xmi21reader.loadFromFile(files[0]);
} catch (err) {
app.dialogs.showErrorDialog('Failed to load the file.', err)
console.log(err)
app.dialogs.showErrorDialog("Failed to load the file.", err);
console.log(err);
}
}
}
}

function _handleXMI21Export (fullPath) {
async function _handleXMI21Export(fullPath) {
if (fullPath) {
xmi21writer.saveToFile(fullPath)
xmi21writer.saveToFile(fullPath);
} else {
var _filename = app.project.getProject().name
var filename = app.dialogs.showSaveDialog('Export Project As XMI', _filename + '.xmi', XMI_FILE_FILTERS)
var _filename = app.project.getProject().name;
var filename = await app.dialogs.showSaveDialogAsync(
"Export Project As XMI",
_filename + ".xmi",
XMI_FILE_FILTERS,
);
if (filename) {
xmi21writer.saveToFile(filename)
xmi21writer.saveToFile(filename);
}
}
}

function init () {
app.commands.register('xmi:import', _handleXMI21Import)
app.commands.register('xmi:export', _handleXMI21Export)
function init() {
app.commands.register("xmi:import", _handleXMI21Import);
app.commands.register("xmi:export", _handleXMI21Export);
}

exports.init = init
exports.init = init;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"description": "XMI (XML Metadata Interchange) import and export",
"homepage": "https://github.com/staruml/staruml-xmi",
"issues": "https://github.com/staruml/staruml-xmi/issues",
"version": "0.9.4",
"version": "0.9.5",
"author": {
"name": "Minkyu Lee",
"email": "[email protected]",
"url": "https://github.com/niklauslee"
},
"license": "MIT",
"engines": {
"staruml": ">=3.0.0"
"staruml": ">=6.0.0"
}
}
Loading

0 comments on commit 5dbdc8d

Please sign in to comment.