Skip to content

Commit

Permalink
Add private create method in Commands and use it in ButtonView
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Jul 11, 2018
1 parent 9c0c27f commit 6af9a98
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dist/css/grapes.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ editor.on('abort:export-template', () => console.log('Command aborted'));
```

## Layers
Another utility tool you might find useful when working with web elements is a layer manger. It's just a tree overview of the structure nodes and enables you to manage it easier. To enable it you just have to specify where to render it
Another utility tool you might find useful when working with web elements is a layer manger. It's just a tree overview of the structure nodes and enables you to manage it easier. To enable it you just have to specify where you want to render it

```html
<div id="basic-panel"></div>
Expand Down
17 changes: 15 additions & 2 deletions src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = () => {
commands = {},
defaultCommands = {},
defaults = require('./config/config'),
AbsCommands = require('./view/CommandAbstract');
CommandAbstract = require('./view/CommandAbstract');

// Need it here as it would be used below
var add = function(id, obj) {
Expand All @@ -39,11 +39,13 @@ module.exports = () => {

delete obj.initialize;
obj.id = id;
commands[id] = AbsCommands.extend(obj);
commands[id] = CommandAbstract.extend(obj);
return this;
};

return {
CommandAbstract,

/**
* Name of the module
* @type {String}
Expand Down Expand Up @@ -262,6 +264,17 @@ module.exports = () => {
}

return this;
},

/**
* Create anonymous Command instance
* @param {Object} command Command object
* @return {Command}
* @private
* */
create(command) {
const cmd = CommandAbstract.extend(command);
return new cmd(c);
}
};
};
17 changes: 9 additions & 8 deletions src/panels/view/ButtonView.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,18 @@ module.exports = Backbone.View.extend({
* @return void
* */
updateActive() {
const model = this.model;
const { model, commands, em } = this;
const context = model.get('context');
const options = model.get('options');
let command = {};
var editor = this.em && this.em.get ? this.em.get('Editor') : null;
var editor = em && em.get ? em.get('Editor') : null;
var commandName = model.get('command');
var cmdIsFunc = isFunction(commandName);

if (this.commands && isString(commandName)) {
command = this.commands.get(commandName) || {};
} else if (isFunction(commandName)) {
command = { run: commandName };
if (commands && isString(commandName)) {
command = commands.get(commandName) || {};
} else if (cmdIsFunc) {
command = commands.create({ run: commandName });
} else if (commandName !== null && isObject(commandName)) {
command = commandName;
}
Expand All @@ -92,8 +93,8 @@ module.exports = Backbone.View.extend({
command.callRun(editor, { ...options, sender: model });
}

// Disable button if there is no stop method
!command.stop && model.set('active', false);
// Disable button if the command was just a function
cmdIsFunc && model.set('active', false);
} else {
this.$el.removeClass(this.activeCls);
model.collection.deactivateAll(context);
Expand Down
2 changes: 1 addition & 1 deletion src/styles/scss/_gjs_panels.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
font-size: 18px;
margin-right: 5px;
border-radius: 2px;
padding: 5px;
padding: 4px;
position: relative;
cursor: pointer;

Expand Down

0 comments on commit 6af9a98

Please sign in to comment.