forked from sdiemert/StarUMLJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
101 lines (82 loc) · 3.89 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
*
* Created by sdiemert on 15-07-10.
*/
define(function (require, exports, module) {
var Commands = app.getModule('command/Commands');
var CommandManager = app.getModule("command/CommandManager");
var MenuManager = app.getModule("menu/MenuManager");
var ElementPickerDialog = app.getModule("dialogs/ElementPickerDialog");
var FileSystem = app.getModule("filesystem/FileSystem");
var Dialogs = app.getModule("dialogs/Dialogs");
var JSGen = require("JSCodeGenerator");
var JavaScriptConfigure = require("JavaScriptConfigure");
function handleGenerate(base, path, opts) {
var result = new $.Deferred();
opts = JavaScriptConfigure.getGenOptions();
console.log(opts);
// If base is not assigned, popup ElementPicker
if (!base) {
ElementPickerDialog.showDialog("Select a base model to generate codes", null, type.UMLPackage)
.done(function (buttonId, selected) {
if (buttonId === Dialogs.DIALOG_BTN_OK && selected) {
base = selected;
// If path is not assigned, popup Open Dialog to select a folder
if (!path) {
FileSystem.showOpenDialog(false, true, "Select a folder where generated codes to be located", null, null, function (err, files) {
if (!err) {
if (files.length > 0) {
path = files[0];
console.log("path: " + path);
JSGen.generate(base, path, opts).then(result.resolve, result.reject);
} else {
result.reject(FileSystem.USER_CANCELED);
}
} else {
result.reject(err);
}
});
} else {
JSGen.generate(base, path, opts).then(result.resolve, result.reject);
}
} else {
result.reject();
}
});
} else {
// If path is not assigned, popup Open Dialog to select a folder
if (!path) {
FileSystem.showOpenDialog(false, true, "Select a folder where generated codes to be located", null, null, function (err, files) {
if (!err) {
if (files.length > 0) {
path = files[0];
JSGen.generate(base, path, opts).then(result.resolve, result.reject);
} else {
result.reject(FileSystem.USER_CANCELED);
}
} else {
result.reject(err);
}
});
} else {
JSGen.generate(base, path, opts).then(result.resolve, result.reject);
}
}
return result.promise();
}
function _handleConfigure() {
CommandManager.execute(Commands.FILE_PREFERENCES, JavaScriptConfigure.getId());
}
var OUTER_CMD = "javascript";
var CMD_GENERATE = "javascript.generate";
var CMD_CONFIG = "javascript.configure";
CommandManager.register("JavaScript", OUTER_CMD, CommandManager.doNothing);
CommandManager.register("Generate...", CMD_GENERATE, handleGenerate);
CommandManager.register("Configure...", CMD_CONFIG, _handleConfigure);
var menu, jsMenu;
menu = MenuManager.getMenu(Commands.TOOLS);
jsMenu = menu.addMenuItem(OUTER_CMD);
jsMenu.addMenuItem(CMD_GENERATE);
jsMenu.addMenuDivider();
jsMenu.addMenuItem(CMD_CONFIG);
});