|
1 |
| -define(function (require, exports, module) { |
2 |
| - 'use strict'; |
| 1 | +/* |
| 2 | + * Copyright (c) 2016-2018 Andrias Meisyal. All rights reserved. |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | + * copy of this software and associated documentation files (the "Software"), |
| 6 | + * to deal in the Software without restriction, including without limitation |
| 7 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | + * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | + * Software is furnished to do so, subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in |
| 12 | + * all copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 19 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 20 | + * IN THE SOFTWARE. |
| 21 | + */ |
3 | 22 |
|
4 |
| - var Commands = app.getModule('command/Commands'); |
5 |
| - var CommandManager = app.getModule('command/CommandManager'); |
6 |
| - var MenuManager = app.getModule('menu/MenuManager'); |
7 |
| - var Dialogs = app.getModule('dialogs/Dialogs'); |
8 |
| - var ElementPickerDialog = app.getModule('dialogs/ElementPickerDialog'); |
9 |
| - var FileSystem = app.getModule('filesystem/FileSystem'); |
| 23 | +const RubyCodeGenerator = require('./ruby-code-generator') |
10 | 24 |
|
11 |
| - var CodeGenUtils = require('code-generator-utils'); |
12 |
| - var RubyCodeGenerator = require('ruby-code-generator'); |
13 |
| - var RubyPreferences = require('ruby-preferences'); |
14 |
| - |
15 |
| - var CMD_RUBY = 'ruby'; |
16 |
| - var CMD_RUBY_GENERATE = 'ruby.generate'; |
17 |
| - var CMD_RUBY_CONFIGURE = 'ruby.configure'; |
18 |
| - |
19 |
| - function _handleGenerate(base, path, options) { |
20 |
| - var result = new $.Deferred(); |
21 |
| - options = options || RubyPreferences.getGenerateOptions(); |
| 25 | +function getGeneratorOptions () { |
| 26 | + return { |
| 27 | + useTab: app.preferences.get('ruby.generator.useTab'), |
| 28 | + indentSpaces: app.preferences.get('ruby.generator.indentSpaces'), |
| 29 | + initializeMethod: app.preferences.get('ruby.generator.initializeMethod'), |
| 30 | + toStringMethod: app.preferences.get('ruby.generator.toStringMethod'), |
| 31 | + documentation: app.preferences.get('ruby.generator.documentation') |
| 32 | + } |
| 33 | +} |
22 | 34 |
|
23 |
| - if (!base) { |
24 |
| - ElementPickerDialog.showDialog('Select a base model to generate codes', null, type.UMLPackage) |
25 |
| - .done(function (buttonId, selected) { |
26 |
| - if (buttonId === Dialogs.DIALOG_BTN_OK && selected) { |
27 |
| - base = selected; |
28 |
| - if (!path) { |
29 |
| - FileSystem.showOpenDialog(false, true, 'Select a folder where generated codes to be located', null, null, function (error, files) { |
30 |
| - if (!error) { |
31 |
| - if (files) { |
32 |
| - path = files[0]; |
33 |
| - RubyCodeGenerator.generate(base, path, options).then(result.resolve, result.reject); |
34 |
| - } else { |
35 |
| - result.reject(FileSystem.USER_CANCELED); |
36 |
| - } |
37 |
| - } else { |
38 |
| - result.reject(error); |
39 |
| - } |
40 |
| - }); |
41 |
| - } else { |
42 |
| - RubyCodeGenerator.generate(base, path, options).then(result.resolve, result.reject); |
43 |
| - } |
44 |
| - } else { |
45 |
| - result.reject(); |
| 35 | +/* |
| 36 | + * Command Handler for Ruby Generate |
| 37 | + * |
| 38 | + * @param {Element} base |
| 39 | + * @param {string} path |
| 40 | + * @param {Object} options |
| 41 | + * @return {$.Promise} |
| 42 | + */ |
| 43 | +function _handleGenerate (base, path, options) { |
| 44 | + // If options is not passed, get from preference |
| 45 | + options = options || getGeneratorOptions() |
| 46 | + // If base is not assigned, popup ElementPicker |
| 47 | + if (!base) { |
| 48 | + app.elementPickerDialog.showDialog('Select a base model to generate codes', null, type.UMLPackage).then(function ({buttonId, returnValue}) { |
| 49 | + if (buttonId === 'ok') { |
| 50 | + base = returnValue |
| 51 | + // If path is not assigned, popup Open Dialog to select a folder |
| 52 | + if (!path) { |
| 53 | + var files = app.dialogs.showOpenDialog('Select a folder where generated codes to be located', null, null, { properties: ['openDirectory']}) |
| 54 | + if (files && files.length > 0) { |
| 55 | + path = files[0] |
| 56 | + RubyCodeGenerator.generate(base, path, options) |
46 | 57 | }
|
47 |
| - }); |
| 58 | + } else { |
| 59 | + RubyCodeGenerator.generate(base, path, options) |
| 60 | + } |
| 61 | + } |
| 62 | + }) |
| 63 | + } else { |
| 64 | + // If path is not assigned, popup Open Dialog to select a folder |
| 65 | + if (!path) { |
| 66 | + var files = app.dialogs.showOpenDialog('Select a folder where generated codes to be located', null, null, { properties: ['openDirectory']}) |
| 67 | + if (files && files.length > 0) { |
| 68 | + path = files[0] |
| 69 | + RubyCodeGenerator.generate(base, path, options) |
| 70 | + } |
48 | 71 | } else {
|
49 |
| - window.alert('NotImplementedError'); |
| 72 | + RubyCodeGenerator.generate(base, path, options) |
50 | 73 | }
|
51 |
| - |
52 |
| - return result.promise(); |
53 | 74 | }
|
| 75 | +} |
54 | 76 |
|
55 |
| - function _handleConfigure() { |
56 |
| - CommandManager.execute(Commands.FILE_PREFERENCES, RubyPreferences.getId()); |
57 |
| - } |
| 77 | +/* |
| 78 | + * Popup PreferenceDialog with Ruby Preference Schema |
| 79 | + */ |
| 80 | +function _handleConfigure () { |
| 81 | + app.commands.execute('application:preferences', 'ruby') |
| 82 | +} |
58 | 83 |
|
59 |
| - CommandManager.register('Ruby', CMD_RUBY, CommandManager.doNothing); |
60 |
| - CommandManager.register('Generate Code...', CMD_RUBY_GENERATE, _handleGenerate); |
61 |
| - CommandManager.register('Configure...', CMD_RUBY_CONFIGURE, _handleConfigure); |
| 84 | +function init () { |
| 85 | + app.commands.register('ruby:generate', _handleGenerate) |
| 86 | + app.commands.register('ruby:configure', _handleConfigure) |
| 87 | +} |
62 | 88 |
|
63 |
| - var menu = MenuManager.getMenu(Commands.TOOLS); |
64 |
| - var menuItem = menu.addMenuItem(CMD_RUBY); |
65 |
| - menuItem.addMenuItem(CMD_RUBY_GENERATE); |
66 |
| - menuItem.addMenuDivider(); |
67 |
| - menuItem.addMenuItem(CMD_RUBY_CONFIGURE); |
68 |
| -}); |
| 89 | +exports.init = init |
0 commit comments