diff --git a/src/css/dialogs-manage-palettes.css b/src/css/dialogs-manage-palettes.css index 94cc9031..3c0318fa 100644 --- a/src/css/dialogs-manage-palettes.css +++ b/src/css/dialogs-manage-palettes.css @@ -123,15 +123,10 @@ font-weight: bold; } -.palette-manager-details-head-edit-icon { - cursor: pointer; +.palette-manager-details-head .edit-icon { width: 24px; - height: 100%; - background: url('../img/tools/pen.png'); display: inline-block; - background-size: 20px; - background-repeat: no-repeat; - background-position: 50%; + background-size: 16px; } .palette-manager-details-head-actions { diff --git a/src/css/icons.css b/src/css/icons.css new file mode 100644 index 00000000..dc1ddc1e --- /dev/null +++ b/src/css/icons.css @@ -0,0 +1,10 @@ +.action-icon { + cursor: pointer; + height: 100%; + background-repeat: no-repeat; + background-position: 50%; +} + +.action-icon.edit-icon { + background-image: url('../img/tools/pen.png'); +} \ No newline at end of file diff --git a/src/css/toolbox-layers-list.css b/src/css/toolbox-layers-list.css index 9be7c653..ae0892f0 100644 --- a/src/css/toolbox-layers-list.css +++ b/src/css/toolbox-layers-list.css @@ -19,11 +19,27 @@ .layer-item { height:24px; line-height: 24px; - padding : 0 10px; + padding : 0 0 0 10px; border-top: 1px solid #444; cursor : pointer; } +.layer-item .edit-icon { + float: right; + width: 30px; + background-size: 12px; + opacity: 0; + transition : opacity 0.2s; +} + +.layer-item:hover .edit-icon { + opacity : 0.6; +} + +.layer-item:hover .edit-icon:hover { + opacity : 1; +} + .layer-item:hover { background : #222; } diff --git a/src/js/controller/LayersListController.js b/src/js/controller/LayersListController.js index ed8c7786..b3e2a76f 100644 --- a/src/js/controller/LayersListController.js +++ b/src/js/controller/LayersListController.js @@ -23,24 +23,37 @@ layers.forEach(this.addLayerItem.bind(this)); }; - ns.LayersListController.prototype.addLayerItem = function (layer) { + ns.LayersListController.prototype.addLayerItem = function (layer, index) { + var isSelected = this.piskelController.getCurrentLayer() === layer; var layerItemHtml = pskl.utils.Template.replace(this.layerItemTemplate_, { - layername : layer.getName() + 'layername' : layer.getName(), + 'layerindex' : index, + 'isselected:current-layer-item' : isSelected }); var layerItem = pskl.utils.Template.createFromHTML(layerItemHtml); - if (this.piskelController.getCurrentLayer() === layer) { - layerItem.classList.add('current-layer-item'); - } this.layersListEl.insertBefore(layerItem, this.layersListEl.firstChild); }; ns.LayersListController.prototype.onClick_ = function (evt) { var el = evt.target || evt.srcElement; - if (el.nodeName == 'BUTTON') { + var index; + if (el.classList.contains('button')) { this.onButtonClick_(el); - } else if (el.nodeName == 'LI') { - var layerName = el.getAttribute('data-layer-name'); - this.piskelController.selectLayerByName(layerName); + } else if (el.classList.contains('layer-item')) { + index = el.dataset.layerIndex; + this.piskelController.setCurrentLayerIndex(parseInt(index, 10)); + } else if (el.classList.contains('edit-icon')) { + index = el.parentNode.dataset.layerIndex; + var layer = this.piskelController.getLayerByIndex(parseInt(index, 10)); + this.renameLayer_(layer); + } + }; + + ns.LayersListController.prototype.renameLayer_ = function (layer) { + var newName = window.prompt("Please enter the layer name", layer.getName()); + if (newName) { + layer.setName(newName); + this.renderLayerList_(); } }; diff --git a/src/js/controller/PiskelController.js b/src/js/controller/PiskelController.js index ab44d197..776f220a 100644 --- a/src/js/controller/PiskelController.js +++ b/src/js/controller/PiskelController.js @@ -161,10 +161,12 @@ } }; - ns.PiskelController.prototype.selectLayerByName = function (name) { - if (this.hasLayerForName_(name)) { - var layer = this.piskel.getLayersByName(name)[0]; - this.selectLayer(layer); + ns.PiskelController.prototype.getLayerByIndex = function (index) { + var layers = this.getLayers(); + if (layers[index]) { + return layers[index]; + } else { + return null; } }; diff --git a/src/js/controller/dialogs/PaletteManagerController.js b/src/js/controller/dialogs/PaletteManagerController.js index 9332f7b4..85e7a1ad 100644 --- a/src/js/controller/dialogs/PaletteManagerController.js +++ b/src/js/controller/dialogs/PaletteManagerController.js @@ -6,7 +6,7 @@ var SELECTED_CLASSNAME = 'selected'; var NEW_COLOR_CLASS = 'palette-manager-new-color'; var CLOSE_ICON_CLASS = 'palette-manager-delete-card'; - var EDIT_NAME_CLASS = 'palette-manager-details-head-edit-icon'; + var EDIT_NAME_CLASS = 'edit-icon'; ns.PaletteManagerController = function (piskelController) { this.piskelController = piskelController; diff --git a/src/js/model/Layer.js b/src/js/model/Layer.js index 3725622b..d55b602e 100644 --- a/src/js/model/Layer.js +++ b/src/js/model/Layer.js @@ -27,6 +27,10 @@ return this.name; }; + ns.Layer.prototype.setName = function (name) { + this.name = name; + }; + ns.Layer.prototype.getFrames = function () { return this.frames; }; diff --git a/src/piskel-style-list.js b/src/piskel-style-list.js index 40b7a651..1fd3b0b5 100644 --- a/src/piskel-style-list.js +++ b/src/piskel-style-list.js @@ -6,6 +6,7 @@ exports.styles = [ "css/forms.css", "css/settings.css", "css/tools.css", + "css/icons.css", "css/cheatsheet.css", "css/dialogs.css", "css/dialogs-manage-palettes.css", diff --git a/src/templates/dialogs/manage-palettes.html b/src/templates/dialogs/manage-palettes.html index 946a4f61..59cb296f 100644 --- a/src/templates/dialogs/manage-palettes.html +++ b/src/templates/dialogs/manage-palettes.html @@ -21,7 +21,7 @@