diff --git a/arrows.sketchplugin/Contents/Sketch/links.js b/arrows.sketchplugin/Contents/Sketch/links.js index 361a785..aa00d24 100644 --- a/arrows.sketchplugin/Contents/Sketch/links.js +++ b/arrows.sketchplugin/Contents/Sketch/links.js @@ -1,5 +1,126 @@ -var that=this;function __skpm_run(t,n){that.context=n;var e=function(t){var n={};function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)e.d(r,o,function(n){return t[n]}.bind(null,o));return r},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s="./src/links.js")}({"./src/links.js": +var that = this; +function __skpm_run (key, context) { + that.context = context; + +var exports = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __webpack_require__.t = function(value, mode) { +/******/ if(mode & 1) value = __webpack_require__(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __webpack_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = "./src/links.js"); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "./src/links.js": /*!**********************!*\ !*** ./src/links.js ***! \**********************/ -/*! exports provided: default, getLibrary, joinCommunity */function(t,n,e){"use strict";function r(t){NSWorkspace.sharedWorkspace().openURL(NSURL.URLWithString("https://github.com/faridsabitov/Sketch-Interactions"))}function o(t){NSWorkspace.sharedWorkspace().openURL(NSURL.URLWithString("https://spectrum.chat/sketch-arrows"))}e.r(n),e.d(n,"getLibrary",function(){return r}),e.d(n,"joinCommunity",function(){return o}),n.default=function(t){}}});"default"===t&&"function"==typeof e?e(n):e[t](n)}that.getLibrary=__skpm_run.bind(this,"getLibrary"),that.onRun=__skpm_run.bind(this,"default"),that.joinCommunity=__skpm_run.bind(this,"joinCommunity"); \ No newline at end of file +/*! exports provided: default, getLibrary, joinCommunity */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getLibrary", function() { return getLibrary; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "joinCommunity", function() { return joinCommunity; }); +/* harmony default export */ __webpack_exports__["default"] = (function (context) {}); +function getLibrary(context) { + NSWorkspace.sharedWorkspace().openURL(NSURL.URLWithString("https://github.com/faridsabitov/Sketch-Interactions")); +} +function joinCommunity(context) { + NSWorkspace.sharedWorkspace().openURL(NSURL.URLWithString("https://spectrum.chat/sketch-arrows")); +} + +/***/ }) + +/******/ }); + if (key === 'default' && typeof exports === 'function') { + exports(context); + } else { + exports[key](context); + } +} +that['getLibrary'] = __skpm_run.bind(this, 'getLibrary'); +that['onRun'] = __skpm_run.bind(this, 'default'); +that['joinCommunity'] = __skpm_run.bind(this, 'joinCommunity') + +//# sourceMappingURL=links.js.map \ No newline at end of file diff --git a/arrows.sketchplugin/Contents/Sketch/manifest.json b/arrows.sketchplugin/Contents/Sketch/manifest.json index 3be31de..8fb9cdb 100644 --- a/arrows.sketchplugin/Contents/Sketch/manifest.json +++ b/arrows.sketchplugin/Contents/Sketch/manifest.json @@ -2,9 +2,10 @@ "compatibleVersion": 3, "bundleVersion": 1, "identifier": "me.sabitov.sketch.connectionFlowArrows", - "version": "2.5.6", + "version": "2.6.0", "icon": "icon.png", "authorEmail": "farid.sabitov.design@gmail.com", + "appcast": "https://raw.githubusercontent.com/faridsabitov/Sketch-Connection-Flow-Arrows/master/.appcast.xml", "author": "Farid Sabitov", "description": "Create auto connected connection flow arrows", "download-url": "https://github.com/faridsabitov/Sketch-user-flows/releases", @@ -127,6 +128,5 @@ ] }, "name": "arrows", - "disableCocoaScriptPreprocessor": true, - "appcast": "https://raw.githubusercontent.com/faridsabitov/Sketch-Connection-Flow-Arrows/master/.appcast.xml" + "disableCocoaScriptPreprocessor": true } \ No newline at end of file diff --git a/arrows.sketchplugin/Contents/Sketch/script.js b/arrows.sketchplugin/Contents/Sketch/script.js index 6d6a423..619299c 100644 --- a/arrows.sketchplugin/Contents/Sketch/script.js +++ b/arrows.sketchplugin/Contents/Sketch/script.js @@ -1,21 +1,1255 @@ -var that=this;function __skpm_run(e,t){that.context=t;var r=function(e){var t={};function r(a){if(t[a])return t[a].exports;var i=t[a]={i:a,l:!1,exports:{}};return e[a].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,a){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(r.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(a,i,function(t){return e[t]}.bind(null,i));return a},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s="./src/script.js")}({"./src/script.js": +var that = this; +function __skpm_run (key, context) { + that.context = context; + +var exports = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __webpack_require__.t = function(value, mode) { +/******/ if(mode & 1) value = __webpack_require__(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __webpack_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = "./src/script.js"); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "./src/script.js": /*!***********************!*\ !*** ./src/script.js ***! \***********************/ -/*! exports provided: default, updateSelectedArrows, updateArtboardArrows, updateAllArrows, deleteAllArrows, deleteArtboardArrows, deleteSelectedArrows, settings, onLayersMoved, panel */function(e,r,a){"use strict";a.r(r),a.d(r,"updateSelectedArrows",function(){return g}),a.d(r,"updateArtboardArrows",function(){return I}),a.d(r,"updateAllArrows",function(){return y}),a.d(r,"deleteAllArrows",function(){return p}),a.d(r,"deleteArtboardArrows",function(){return S}),a.d(r,"deleteSelectedArrows",function(){return w}),a.d(r,"settings",function(){return b}),a.d(r,"onLayersMoved",function(){return v}),a.d(r,"panel",function(){return T});var i,n=a(/*! sketch */"sketch"),o=a.n(n),s=a(/*! sketch/ui */"sketch/ui"),l="flowArrows",d=o.a.fromNative(t.document),c=t.document.documentData(),f=t.command.valueForKey_onLayer_forPluginIdentifier("arrowConnections",c,l),m=c.currentPage().currentArtboard()||c.currentPage(),u=P(),h=a(/*! sketch/settings */"sketch/settings");function g(e){var t=e.selection;if(t.count()>1){for(var r=N(t),a=u,n=0;n0){for(var n=i.length,s=0;s0){for(var r=t.length,a=0;a0){for(var t=0;t0){for(var n=i.length,s=0;sn?l>o?c>f?"Down":"Right":m>u?"Right":"Up":l>o?m>u?"Left":"Down":c>f?"Left":"Up";return r}(e,t):r),function(e,t,r){var a,i,n,o,s,l=d.getLayerWithID(e),c=d.getLayerWithID(t);h.settingForKey("autoAlign")&&1==h.settingForKey("autoAlign")&&("Right"!=r&&"Left"!=r||(a=l.frame.y+l.frame.height/2,i=c.frame.y+c.frame.height/2,(s=a-i)>-6&&s<6&&(c.frame.y=c.frame.y+s)),"Down"!=r&&"Up"!=r||(n=l.frame.x+l.frame.width/2,o=c.frame.x+c.frame.width/2,(s=n-o)>-6&&s<6&&(c.frame.x=c.frame.x+s)))}(e,t,i);var n=D(),o=function(e,t,r,a){var i,n,o,s,l,c,f,m,u=d.getLayerWithID(e),h=d.getLayerWithID(t);a?(f=a.frame().x(),m=a.frame().y()):(f=0,m=0);var g=NSBezierPath.bezierPath();"Up"==r&&(i=u.frame.x+u.frame.width/2-f,n=u.frame.y-m,o=h.frame.x+h.frame.width/2-f,s=h.frame.y+h.frame.height-m,l=(i+o)/2,c=(n+s)/2,g.moveToPoint(NSMakePoint(i,n)),g.lineToPoint(NSMakePoint(i,c)),g.lineToPoint(NSMakePoint(o,c)),g.lineToPoint(NSMakePoint(o,s)));"Right"==r&&(i=u.frame.x+u.frame.width-f,n=u.frame.y+u.frame.height/2-m,o=h.frame.x-f,s=h.frame.y+h.frame.height/2-m,l=(i+o)/2,c=(n+s)/2,g.moveToPoint(NSMakePoint(i,n)),g.lineToPoint(NSMakePoint(l,n)),g.lineToPoint(NSMakePoint(l,s)),g.lineToPoint(NSMakePoint(o,s)));"Down"==r&&(i=u.frame.x+u.frame.width/2-f,n=u.frame.y+u.frame.height-m,o=h.frame.x+h.frame.width/2-f,s=h.frame.y-m,l=(i+o)/2,c=(n+s)/2,g.moveToPoint(NSMakePoint(i,n)),g.lineToPoint(NSMakePoint(i,c)),g.lineToPoint(NSMakePoint(o,c)),g.lineToPoint(NSMakePoint(o,s)));"Left"==r&&(i=u.frame.x-f,n=u.frame.y+u.frame.height/2-m,o=h.frame.x+h.frame.width-f,s=h.frame.y+h.frame.height/2-m,l=(i+o)/2,c=(n+s)/2,g.moveToPoint(NSMakePoint(i,n)),g.lineToPoint(NSMakePoint(l,n)),g.lineToPoint(NSMakePoint(l,s)),g.lineToPoint(NSMakePoint(o,s)));var I=MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(g)),y=I.layers().firstObject().points();y[1].cornerRadius=20,y[2].cornerRadius=20,I.setName("Arrow");var p=I.style().addStylePartOfType(1);return p.color=MSColor.colorWithRGBADictionary({r:.89,g:.89,b:.89,a:1}),p.thickness=2,I.style().endMarkerType=2,I}(e,t,i,n);!function(e,t){if(t)t.addLayers([e]),t.fixGeometryWithOptions(1);else{var r=a(/*! sketch/dom */"sketch/dom").Group,i=new r({parent:m,name:"Arrows",locked:!0,layers:[e]});i.moveToBack(),(t=D()).fixGeometryWithOptions(1)}}(o,n);var s={firstObject:e,secondObject:t,direction:i,line:o.objectID()};u.push(s)}function D(){for(var e=null,t=0;t1){for(var r=N(t),a=u,n=0;n 1) { + // Need to find source object by ID first + var sourceObjectID = getSourceObjectFromSelection(selection); + var currentConnectionsData = newConnectionsData; + + for (var g = 0; g < selection.count(); g++) { + if (selection[g].objectID() != sourceObjectID) { + // Then need to create or update connection arrow with each selection + var connectionIndex = findConnectionData(sourceObjectID, selection[g].objectID(), currentConnectionsData); + + if (connectionIndex != null) { + // Because this is creating flow, we need to take the direction from user settings + updateArrow(currentConnectionsData[connectionIndex].firstObject, currentConnectionsData[connectionIndex].secondObject, arrowDirectionSetting, currentConnectionsData[connectionIndex].line, connectionIndex); + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("Current connection is updated 🚀"); + } else { + // There is no connection with this two objects in our database + createArrow(sourceObjectID, selection[g].objectID(), arrowDirectionSetting); + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("New connection is created 🚀"); + } + } + } + + context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, "arrowConnections", docData, pluginKey); + } else { + // When user didn't select anything + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("Please select more than two layers"); + } +}); // +// Plugin Commands +// + +function updateSelectedArrows(context) { + var selection = context.selection; + + if (selection.count() > 1) { + // Need to find source object by ID first + var sourceObjectID = getSourceObjectFromSelection(selection); + var currentConnectionsData = newConnectionsData; + + for (var g = 0; g < selection.count(); g++) { + if (selection[g].objectID() != sourceObjectID) { + // Then need to create or update connection arrow with each selection + var connectionIndex = findConnectionData(sourceObjectID, selection[g].objectID(), currentConnectionsData); + + if (connectionIndex != null) { + updateArrow(currentConnectionsData[connectionIndex].firstObject, currentConnectionsData[connectionIndex].secondObject, arrowDirectionSetting, currentConnectionsData[connectionIndex].line, connectionIndex); + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("Current connection is updated 🚀"); + } + } + } + + context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, "arrowConnections", docData, pluginKey); + } else { + // When user didn't select anything + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("Please select more than two layers"); + } +} +function updateArtboardArrows(context) { + // TODO: Need to show amount of updated arrows and deleted ones + var selection = context.selection; + var connections = getConnectionsData(); + var firstObjectArtboard; + var secondObjectArtboard; + + if (connections.length > 0) { + // We have connections in database + var updateArrowsCounter = connections.length; + + for (var i = 0; i < updateArrowsCounter; i++) { + // Need to check if the element is selected globally or from the artboard + firstObjectArtboard = document.getLayerWithID(connections[i].firstObject); + firstObjectArtboard = firstObjectArtboard.sketchObject.parentArtboard().objectID(); + secondObjectArtboard = document.getLayerWithID(connections[i].secondObject); + secondObjectArtboard = secondObjectArtboard.sketchObject.parentArtboard().objectID(); + + if (selection.count() == 1 && selection[0].class() == "MSArtboardGroup") { + // Need to go through each connection and update arrow position for specific artboard + if (firstObjectArtboard == selection[0].objectID()) { + if (secondObjectArtboard == selection[0].objectID()) { + updateArrow(connections[i].firstObject, connections[i].secondObject, connections[i].direction, connections[i].line, i); + } else { + newConnectionsData.push(connections[i]); + } + } else { + // If not just saving it + newConnectionsData.push(connections[i]); + } + } + } + + context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, "arrowConnections", docData, pluginKey); + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("All arrows are updated 🚀"); + } else { + // We don't have any connections to update + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("There is nothing to update"); + } +} +function updateAllArrows(context) { + // TODO + // TODO: Need to show amount of updated arrows and deleted ones + var selection = context.selection; + var connections = getConnectionsData(); + var firstObjectArtboard; + var secondObjectArtboard; + + if (connections.length > 0) { + // We have connections in database + var updateArrowsCounter = connections.length; + + for (var i = 0; i < updateArrowsCounter; i++) { + // Need to go through each connection and update arrow position without artboards + // Need to check if current object don't have the parrent + updateArrow(connections[i].firstObject, connections[i].secondObject, connections[i].direction, connections[i].line, i); + } + + context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, "arrowConnections", docData, pluginKey); + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("All arrows are updated 🚀"); + } else { + // We don't have any connections to update + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("There is nothing to update"); + } +} +function deleteAllArrows(context) { + if (newConnectionsData.length > 0) { + // We have connections in database + for (var i = 0; i < newConnectionsData.length; i++) { + // Need to go through each connection and update arrow position + deleteLine(newConnectionsData[i].line); + } + + context.command.setValue_forKey_onLayer_forPluginIdentifier(null, "arrowConnections", docData, pluginKey); + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("All arrows are deleted"); + } else { + // We don't have any connections to update + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("There is nothing to delete"); + } +} +function deleteArtboardArrows(context) { + var selection = context.selection; + var firstObject, secondObject; // Need to delete all the arrows only from selected artboard + + if (selection.count() == 1 && selection[0].class() == "MSArtboardGroup") { + var connections = getConnectionsData(); + + if (connections.length > 0) { + // We have connections in database + var updateArrowsCounter = connections.length; + + for (var i = 0; i < updateArrowsCounter; i++) { + // Need to go through each connection and check if it placed on selected artboard + firstObject = document.getLayerWithID(connections[i].firstObject); + secondObject = document.getLayerWithID(connections[i].secondObject); + + if (firstObject.sketchObject.parentArtboard().objectID() == selection[0].objectID()) { + if (secondObject.sketchObject.parentArtboard().objectID() == selection[0].objectID()) { + deleteLine(connections[i].line); + newConnectionsData = deleteConnectionFromData(i); + } + } + } + + context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, "arrowConnections", docData, pluginKey); + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("All arrows from selected artboard are deleted"); + } else { + // We don't have any connections to update + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("There is nothing to delete"); + } + } else { + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("Please select one artboard"); + } +} +function deleteSelectedArrows(context) { + var selection = context.selection; + var firstObject, secondObject; // Need to delete all the arrows only from selected artboard + + if (selection.count() == 2) { + for (var g = 0; g < selection.count(); g++) { + if (selection[g].objectID() != selection[0].objectID()) { + // It will never check 3rd connection + var connections = getConnectionsData(); + var connectionIndex = findConnectionData(selection[0].objectID(), selection[g].objectID(), connections); + + if (connectionIndex != null) { + // We have connections in database + deleteLine(connections[connectionIndex].line); + newConnectionsData = deleteConnectionFromData(connectionIndex); + var updateArrowsCounter = connections.length; + + for (var i = 0; i < updateArrowsCounter; i++) { + // Need to go through each connection and check if it placed on selected artboard + firstObject = document.getLayerWithID(connections[i].firstObject); + secondObject = document.getLayerWithID(connections[i].secondObject); + + if (firstObject.sketchObject.parentArtboard().objectID() == selection[0].objectID()) { + if (secondObject.sketchObject.parentArtboard().objectID() == selection[0].objectID()) { + deleteLine(connections[i].line); + newConnectionsData = deleteConnectionFromData(i); + } + } + } + + context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, "arrowConnections", docData, pluginKey); + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("All arrows from selected layers are deleted ✌ī¸"); + } + } + } + } else { + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("Select two layers, please 🧐"); + } +} +function settings(context) { + var alert = COSAlertWindow.new(); + var viewWidth = 300; + var viewHeight = 430; // Alert window settingsnp + + alert = alertSetup(alert, viewWidth, viewHeight); + var view = NSView.alloc().initWithFrame(NSMakeRect(0, 0, viewWidth, viewHeight)); + alert.addAccessoryView(view); // Label: Arrow Direction + + var arrowDirectionLabel = alertLabel("Arrow Direction", true, -1, viewHeight - 17, 330, 20); + view.addSubview(arrowDirectionLabel); // Select: Arrow Direction + + var arrowDirectionField = NSPopUpButton.alloc().initWithFrame(NSMakeRect(-2, viewHeight - 40, 300, 20)); + setActiveDirectionSetting(arrowDirectionField); + view.addSubview(arrowDirectionField); // Label: Auto Direction Info + + var arrowDirectionInfoLabel = alertLabel("Auto mode will draw arrow based on location of the second object", false, -1, viewHeight - 84, 300, 40); + view.addSubview(arrowDirectionInfoLabel); // Label: Arrow Spacing + + var arrowSpacingLabel = alertLabel("Arrow Spacing", true, -1, viewHeight - 120, 330, 20); + view.addSubview(arrowSpacingLabel); // Select: Arrow Spacing + + var arrowSpacingField = NSPopUpButton.alloc().initWithFrame(NSMakeRect(-2, viewHeight - 143, 300, 20)); + setActiveSpacingSetting(arrowSpacingField); + view.addSubview(arrowSpacingField); // Label: Auto Spacing Info + + var arrowSpacingInfoLabel = alertLabel("If you will select spacing, the second layer position will be moved closer", false, -1, viewHeight - 187, 300, 40); + view.addSubview(arrowSpacingInfoLabel); // Label: Arrow Style + + var arrowStyleLabel = alertLabel("Arrow Style", true, -1, viewHeight - 240, 280, 40); + view.addSubview(arrowStyleLabel); // Select: Arrow Style + + var arrowStylingField = NSPopUpButton.alloc().initWithFrame(NSMakeRect(-2, viewHeight - 240, 300, 20)); + setActiveStyleSetting(arrowStylingField); + view.addSubview(arrowStylingField); // Label: Arrow Style Info + + var arrowStyleInfoLabel = alertLabel("Add layer style to your document that will contain $arrow name and you will be able to specify it here ", false, -1, viewHeight - 280, 300, 40); + view.addSubview(arrowStyleInfoLabel); // Label: Other Settings + + var otherSettingsLabel = alertLabel("Other Settings", true, -1, viewHeight - 340, 280, 40); + view.addSubview(otherSettingsLabel); // Checkbox: Auto-Align + + var checkbox = alertCheckbox("Second layer auto-align", false, -1, viewHeight - 350, 260, 40); + view.addSubview(checkbox); // Label: Auto-Align Info + + var autoAlignInfoLabel = alertLabel("Align the second layer for 5px misalignment with the first one", false, -1, viewHeight - 380, 280, 40); + view.addSubview(autoAlignInfoLabel); // Label: Plugin Info + + var pluginInfoLabel = alertLabel("Made by @faridSabitov with the support of EPAM.com ❤ī¸", true, -1, viewHeight - 430, 280, 40); + view.addSubview(pluginInfoLabel); // Need to check if style is still available + // Show modal and get the results + + var modalResponse = alert.runModal(); + + if (modalResponse == NSAlertFirstButtonReturn) { + // When user clicks on "Update Settings" + // Need to save all this results into the Plugin Settings + Settings.setSettingForKey("arrowDirection", alert.views()[0].subviews()[1].title()); + Settings.setSettingForKey("arrowSpacing", alert.views()[0].subviews()[4].title()); + context.command.setValue_forKey_onLayer_forPluginIdentifier(alert.views()[0].subviews()[7].title(), "arrowStyle", docData, pluginKey); + Settings.setSettingForKey("autoAlign", alert.views()[0].subviews()[10].state()); + UI.message("Settings are updated 🚀"); + } +} +function onLayersMoved(context) { + sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("Please select more than two layers"); + var action = context.actionContext; +} +function panel(context) { + var ControlBar; + ControlBar = NSPanel.alloc().init(); + ControlBar.setStyleMask(NSTitledWindowMask + NSFullSizeContentViewWindowMask); // ControlBar.setBackgroundColor(NSColor.colorWithRed_green_blue_alpha(0.99, 0.99, 0.99, 1)); + + ControlBar.setTitleVisibility(NSWindowTitleHidden); + ControlBar.setTitlebarAppearsTransparent(true); + ControlBar.setFrame_display(NSMakeRect(0, 0, 720, 50), false); + ControlBar.setMovableByWindowBackground(true); + ControlBar.setHasShadow(true); + ControlBar.setLevel(NSFloatingWindowLevel); // contentView.addSubview(closeButton) + + ControlBar.center(); + ControlBar.makeKeyAndOrderFront(nil); // getImage = function(size, name){ + // var isRetinaDisplay = (NSScreen.mainScreen().backingScaleFactor() > 1)? true: false; + // suffix = (isRetinaDisplay)? "@2x": "", + // imageURL = NSURL.fileURLWithPath(self.pluginResources + "/icons/" + name + suffix + ".png"), + // image = NSImage.alloc().initWithContentsOfURL(imageURL); + // return image + // }, + // addButton = function(rect, name, callAction){ + // var button = NSButton.alloc().initWithFrame(rect), + // image = getImage(rect.size, name); + // button.setImage(image); + // button.setBordered(false); + // button.sizeToFit(); + // button.setButtonType(NSMomentaryChangeButton); + // button.setCOSJSTargetFunction(callAction); + // button.setAction("callAction:"); + // return button; + // }, + // addImage = function(rect, name){ + // var view = NSImageView.alloc().initWithFrame(rect), + // image = getImage(rect.size, name); + // view.setImage(image); + // return view; + // }, + // closeButton = addButton( NSMakeRect(20, 10, 30, 30), "close-control", + // function(sender){ + // coscript.setShouldKeepAround(false); + // threadDictionary.removeObjectForKey(identifier); + // ControlBar.close(); + // }), +} // +// Functions +// + +function updateArrow(firstObjectID, secondObjectID, direction, lineID, connectionIndex) { + // There might be a situation, when user deleted current group or current group stays on another artboard => In that case need to create another group + // Need to check if we have the layers with such IDs + var firstObject = document.getLayerWithID(firstObjectID); + var secondObject = document.getLayerWithID(secondObjectID); // Need to delete data first, because we will have a new line + + deleteLine(lineID); + newConnectionsData = deleteConnectionFromData(connectionIndex); + + if (firstObject && secondObject) { + // If we have all the objects, we can recreate the line + createArrow(firstObjectID, secondObjectID, direction); + } +} + +function createArrow(firstObjectID, secondObjectID, direction) { + // Process of creating new connection + var localDirection; + + if (direction == "Auto") { + // If direction is auto, we need to specify direction ourselves + localDirection = getDirection(firstObjectID, secondObjectID); + } else { + localDirection = direction; + } + + updateSpacing(firstObjectID, secondObjectID, localDirection); + autoAlignLayer(firstObjectID, secondObjectID, localDirection); + var currentGroup = checkForArrowGroup(); + var line = drawLine(firstObjectID, secondObjectID, localDirection, currentGroup); + addToArrowsGroup(line, currentGroup); // Storage for current connection + + var connection = { + firstObject: firstObjectID, + secondObject: secondObjectID, + direction: localDirection, + line: line.objectID() // Need to save this data to the global array + + }; + newConnectionsData.push(connection); +} + +function checkForArrowGroup() { + var currentGroup = null; // Checking all the groups that we have + + for (var i = 0; i < currentParentGroup.layers().count(); i++) { + if (currentParentGroup.layers()[i].name() == "Arrows") { + // If we already have "Arrow" group we need to save it's folder + currentGroup = currentParentGroup.layers()[i]; + refactorLines(currentGroup); + } + } + + return currentGroup; +} + +function getDirection(firstObjectID, secondObjectID) { + // Get direction from the source object + var firstObject = document.getLayerWithID(firstObjectID); + var secondObject = document.getLayerWithID(secondObjectID); + var firstObjectMidX = firstObject.frame.x + firstObject.frame.width / 2; + var firstObjectMidY = firstObject.frame.y + firstObject.frame.height / 2; + var secondObjectMidX = secondObject.frame.x + secondObject.frame.width / 2; + var secondObjectMidY = secondObject.frame.y + secondObject.frame.height / 2; + var diffX = firstObjectMidX - secondObjectMidX; + var diffY = firstObjectMidY - secondObjectMidY; + var absDiffX = Math.abs(diffX); + var absDiffY = Math.abs(diffY); + var direction; + + if (secondObjectMidX > firstObjectMidX) { + // Right Half + if (secondObjectMidY > firstObjectMidY) { + // Bottom quarter + if (diffX > diffY) { + direction = "Down"; + } else { + direction = "Right"; + } + } else { + // Top quarter + if (absDiffX > absDiffY) { + direction = "Right"; + } else { + direction = "Up"; + } + } + } else { + // Left Half + if (secondObjectMidY > firstObjectMidY) { + // Bottom quarter + if (absDiffX > absDiffY) { + direction = "Left"; + } else { + direction = "Down"; + } + } else { + // Top quarter + if (diffX > diffY) { + direction = "Left"; + } else { + direction = "Up"; + } + } + } + + return direction; +} + +function drawLine(firstObjectID, secondObjectID, direction, currentGroup) { + var firstLayerPosX, firstLayerPosY, secondLayerPosX, secondLayerPosY, middlePosX, middlePosY, diffX, diffY; + var firstObject = document.getLayerWithID(firstObjectID); + var secondObject = document.getLayerWithID(secondObjectID); + + if (currentGroup) { + //if we already have a group, need to specify the difference + diffX = currentGroup.frame().x(); + diffY = currentGroup.frame().y(); + } else { + diffX = 0; + diffY = 0; + } // Drawing a line + + + var path = NSBezierPath.bezierPath(); // Based on direction, we need to specify connection points + + if (direction == "Up") { + // First Layer Position Start Point Position + firstLayerPosX = firstObject.frame.x + firstObject.frame.width / 2 - diffX; + firstLayerPosY = firstObject.frame.y - diffY; // Second Layer Position End Point Position + + secondLayerPosX = secondObject.frame.x + secondObject.frame.width / 2 - diffX; + secondLayerPosY = secondObject.frame.y + secondObject.frame.height - diffY; // Middle Points + + middlePosX = (firstLayerPosX + secondLayerPosX) / 2; + middlePosY = (firstLayerPosY + secondLayerPosY) / 2; // Connecting points + + path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); + path.lineToPoint(NSMakePoint(firstLayerPosX, middlePosY)); + path.lineToPoint(NSMakePoint(secondLayerPosX, middlePosY)); + path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); + } + + if (direction == "Right") { + // First Layer Position Start Point Position + firstLayerPosX = firstObject.frame.x + firstObject.frame.width - diffX; + firstLayerPosY = firstObject.frame.y + firstObject.frame.height / 2 - diffY; // Second Layer Position End Point Position + + secondLayerPosX = secondObject.frame.x - diffX; + secondLayerPosY = secondObject.frame.y + secondObject.frame.height / 2 - diffY; // Middle Points + + middlePosX = (firstLayerPosX + secondLayerPosX) / 2; + middlePosY = (firstLayerPosY + secondLayerPosY) / 2; // Connecting points + + path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); + path.lineToPoint(NSMakePoint(middlePosX, firstLayerPosY)); + path.lineToPoint(NSMakePoint(middlePosX, secondLayerPosY)); + path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); + } + + if (direction == "Down") { + // First Layer Position Start Point Position + firstLayerPosX = firstObject.frame.x + firstObject.frame.width / 2 - diffX; + firstLayerPosY = firstObject.frame.y + firstObject.frame.height - diffY; // Second Layer Position End Point Position + + secondLayerPosX = secondObject.frame.x + secondObject.frame.width / 2 - diffX; + secondLayerPosY = secondObject.frame.y - diffY; // Middle Points + + middlePosX = (firstLayerPosX + secondLayerPosX) / 2; + middlePosY = (firstLayerPosY + secondLayerPosY) / 2; // Connecting points + + path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); + path.lineToPoint(NSMakePoint(firstLayerPosX, middlePosY)); + path.lineToPoint(NSMakePoint(secondLayerPosX, middlePosY)); + path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); + } + + if (direction == "Left") { + // First Layer Position Start Point Position + firstLayerPosX = firstObject.frame.x - diffX; + firstLayerPosY = firstObject.frame.y + firstObject.frame.height / 2 - diffY; // Second Layer Position End Point Position + + secondLayerPosX = secondObject.frame.x + secondObject.frame.width - diffX; + secondLayerPosY = secondObject.frame.y + secondObject.frame.height / 2 - diffY; // Middle Points + + middlePosX = (firstLayerPosX + secondLayerPosX) / 2; + middlePosY = (firstLayerPosY + secondLayerPosY) / 2; // Connecting points + + path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); + path.lineToPoint(NSMakePoint(middlePosX, firstLayerPosY)); + path.lineToPoint(NSMakePoint(middlePosX, secondLayerPosY)); + path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); + } //TODO: Provide a separate file with all the stylings + // Painting the line + + + var line = MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(path)); // Making middle points rounded + + var points = line.layers().firstObject().points(); + points[1].cornerRadius = 20; + points[2].cornerRadius = 20; // Providing Settings for the arrow + + line.setName("Arrow"); + + if (context.command.valueForKey_onLayer_forPluginIdentifier("arrowStyle", docData, pluginKey)) { + // if we have specified options + var style = getLayerStyles(context.command.valueForKey_onLayer_forPluginIdentifier("arrowStyle", docData, pluginKey)); + + if (style[0] == null) { + // Default Arrow Style + var border = line.style().addStylePartOfType(1); + border.color = MSColor.colorWithRGBADictionary({ + r: 0.89, + g: 0.89, + b: 0.89, + a: 1 + }); + border.thickness = 2; + line.style().endMarkerType = 2; + } else { + line.sharedStyle = style[0]; + } + } else { + // Default Arrow Style + var _border = line.style().addStylePartOfType(1); + + _border.color = MSColor.colorWithRGBADictionary({ + r: 0.89, + g: 0.89, + b: 0.89, + a: 1 + }); + _border.thickness = 2; + line.style().endMarkerType = 2; + } + + return line; +} + +function addToArrowsGroup(line, currentGroup) { + if (currentGroup) { + currentGroup.addLayers([line]); + currentGroup.fixGeometryWithOptions(1); + } else { + // If we don't have a group + var Group = __webpack_require__(/*! sketch/dom */ "sketch/dom").Group; + + var group = new Group({ + parent: currentParentGroup, + name: 'Arrows', + locked: true, + layers: [line] + }); // Moving this group to the bottom of the page + + group.moveToBack(); + currentGroup = checkForArrowGroup(); + currentGroup.fixGeometryWithOptions(1); + } +} + +function getConnectionsData() { + var dataArray = []; + var pluginDataConnections = []; + + if (pluginData) { + pluginDataConnections = context.command.valueForKey_onLayer_forPluginIdentifier("arrowConnections", docData, pluginKey); + + for (var i = 0; i < pluginDataConnections.length; i++) { + dataArray.push(pluginDataConnections[i]); + } + } + + return dataArray; +} + +function findConnectionData(firstObjectID, secondObjectID, data) { + var arrayNumber = null; + firstObjectID = String(firstObjectID); + secondObjectID = String(secondObjectID); + + if (pluginData) { + // If we have database, need to check for connections + for (var y = 0; y < data.length; y++) { + if (firstObjectID == data[y].firstObject || firstObjectID == data[y].secondObject) { + // if we found that we have this object in connection database already + if (secondObjectID == data[y].firstObject || secondObjectID == data[y].secondObject) { + // if we found that we have this object in connection database already + arrayNumber = y; + } + } + } + } + + return arrayNumber; +} + +function setActiveDirectionSetting(arrowDirectionField) { + var currentDirection = "Auto"; + + if (Settings.settingForKey("arrowDirection")) { + // if there is data in settings + currentDirection = Settings.settingForKey("arrowDirection"); + + if (currentDirection == "Auto") { + arrowDirectionField.addItemWithTitle("Auto"); + arrowDirectionField.lastItem().setState(1); + arrowDirectionField.addItemWithTitle("Right"); + arrowDirectionField.lastItem().setState(0); + arrowDirectionField.addItemWithTitle("Down"); + arrowDirectionField.lastItem().setState(0); + arrowDirectionField.addItemWithTitle("Left"); + arrowDirectionField.lastItem().setState(0); + arrowDirectionField.addItemWithTitle("Up"); + arrowDirectionField.lastItem().setState(0); + } + + if (currentDirection == "Right") { + arrowDirectionField.addItemWithTitle("Right"); + arrowDirectionField.lastItem().setState(1); + arrowDirectionField.addItemWithTitle("Down"); + arrowDirectionField.lastItem().setState(0); + arrowDirectionField.addItemWithTitle("Left"); + arrowDirectionField.lastItem().setState(0); + arrowDirectionField.addItemWithTitle("Up"); + arrowDirectionField.lastItem().setState(0); + arrowDirectionField.addItemWithTitle("Auto"); + arrowDirectionField.lastItem().setState(0); + } + + if (currentDirection == "Down") { + arrowDirectionField.addItemWithTitle("Down"); + arrowDirectionField.lastItem().setState(1); + arrowDirectionField.addItemWithTitle("Left"); + arrowDirectionField.lastItem().setState(0); + arrowDirectionField.addItemWithTitle("Up"); + arrowDirectionField.lastItem().setState(0); + arrowDirectionField.addItemWithTitle("Auto"); + arrowDirectionField.lastItem().setState(0); + arrowDirectionField.addItemWithTitle("Right"); + arrowDirectionField.lastItem().setState(0); + } + + if (currentDirection == "Left") { + arrowDirectionField.addItemWithTitle("Left"); + arrowDirectionField.lastItem().setState(1); + arrowDirectionField.addItemWithTitle("Up"); + arrowDirectionField.lastItem().setState(0); + arrowDirectionField.addItemWithTitle("Auto"); + arrowDirectionField.lastItem().setState(0); + arrowDirectionField.addItemWithTitle("Right"); + arrowDirectionField.lastItem().setState(0); + arrowDirectionField.addItemWithTitle("Down"); + arrowDirectionField.lastItem().setState(0); + } + + if (currentDirection == "Up") { + arrowDirectionField.addItemWithTitle("Up"); + arrowDirectionField.lastItem().setState(1); + arrowDirectionField.addItemWithTitle("Auto"); + arrowDirectionField.lastItem().setState(0); + arrowDirectionField.addItemWithTitle("Right"); + arrowDirectionField.lastItem().setState(0); + arrowDirectionField.addItemWithTitle("Down"); + arrowDirectionField.lastItem().setState(0); + arrowDirectionField.addItemWithTitle("Left"); + arrowDirectionField.lastItem().setState(0); + } + } else { + // Show default + arrowDirectionField.addItemWithTitle("Auto"); + arrowDirectionField.addItemWithTitle("Right"); + arrowDirectionField.addItemWithTitle("Down"); + arrowDirectionField.addItemWithTitle("Left"); + arrowDirectionField.addItemWithTitle("Up"); + } +} + +function setActiveSpacingSetting(arrowSpacingField) { + var currentSpacing = "Not selected"; + + if (Settings.settingForKey("arrowSpacing")) { + // if there is data in settings + currentSpacing = Settings.settingForKey("arrowSpacing"); + + if (currentSpacing == "Not selected") { + arrowSpacingField.addItemWithTitle("Not selected"); + arrowSpacingField.lastItem().setState(1); + arrowSpacingField.addItemWithTitle("30px"); + arrowSpacingField.lastItem().setState(0); + arrowSpacingField.addItemWithTitle("70px"); + arrowSpacingField.lastItem().setState(0); + } + + if (currentSpacing == "30px") { + arrowSpacingField.addItemWithTitle("30px"); + arrowSpacingField.lastItem().setState(1); + arrowSpacingField.addItemWithTitle("70px"); + arrowSpacingField.lastItem().setState(0); + arrowSpacingField.addItemWithTitle("Not selected"); + arrowSpacingField.lastItem().setState(0); + } + + if (currentSpacing == "70px") { + arrowSpacingField.addItemWithTitle("70px"); + arrowSpacingField.lastItem().setState(1); + arrowSpacingField.addItemWithTitle("Not selected"); + arrowSpacingField.lastItem().setState(0); + arrowSpacingField.addItemWithTitle("30px"); + arrowSpacingField.lastItem().setState(0); + } + } else { + // Show default + arrowSpacingField.addItemWithTitle("Not Selected"); + arrowSpacingField.addItemWithTitle("30px"); + arrowSpacingField.addItemWithTitle("70px"); + } +} + +function setActiveStyleSetting(arrowStylingField) { + var docSettings = context.command.valueForKey_onLayer_forPluginIdentifier("arrowStyle", docData, pluginKey); + var styles = getLayerStyles(null); + + if (docSettings) { + // We have info about the settings in the current document + if (docSettings != "Default Style") { + // if user specified own option + arrowStylingField.addItemWithTitle(docSettings); + arrowStylingField.addItemWithTitle("Default Style"); + + for (var i = 0; i < styles.length; i++) { + if (styles[i].name() != docSettings) { + arrowStylingField.addItemWithTitle(styles[i].name()); + } + } + } else { + // Need to show the default first + arrowStylingField.addItemWithTitle("Default Style"); + + for (var _i = 0; _i < styles.length; _i++) { + arrowStylingField.addItemWithTitle(styles[_i].name()); + } + } + } else { + arrowStylingField.addItemWithTitle("Default Style"); + + for (var _i2 = 0; _i2 < styles.length; _i2++) { + arrowStylingField.addItemWithTitle(styles[_i2].name()); + } + } +} + +function deleteConnectionFromData(arrayNumber) { + var newConnections = []; + + if (pluginData) { + // If we have database + var connections = context.command.valueForKey_onLayer_forPluginIdentifier("arrowConnections", docData, pluginKey); + + for (var i = 0; i < connections.length; i++) { + // Updating all connections without deleted one + if (i != arrayNumber) { + newConnections.push(connections[i]); + } + } + } + + return newConnections; +} + +function refactorLines(group) { + // Need to finish + for (var i = 0; i < group.layers().length; i++) {// Here we need to go through each data in our database and delete line if there is no data + } +} + +function deleteLine(lineID) { + var lineObject = document.getLayerWithID(lineID); + var selectedGroup; + + if (lineObject) { + selectedGroup = lineObject.parent; + lineObject.remove(); + + if (selectedGroup.layers.length == 0) { + selectedGroup.remove(); + } + } +} + +function updateSpacing(sourceObjectID, childObjectID, direction) { + var sourceObject = document.getLayerWithID(sourceObjectID); + var childObject = document.getLayerWithID(childObjectID); + + if (Settings.settingForKey("arrowSpacing")) { + var currentSpacing = Settings.settingForKey("arrowSpacing"); + + if (direction == "Right") { + if (currentSpacing == "30px") { + childObject.frame.x = sourceObject.frame.x + sourceObject.frame.width + 30; + } + + if (currentSpacing == "70px") { + childObject.frame.x = sourceObject.frame.x + sourceObject.frame.width + 70; + } + } + + if (direction == "Down") { + if (currentSpacing == "30px") { + childObject.frame.y = sourceObject.frame.y + sourceObject.frame.height + 30; + } + + if (currentSpacing == "70px") { + childObject.frame.y = sourceObject.frame.y + sourceObject.frame.height + 70; + } + } + + if (direction == "Left") { + if (currentSpacing == "30px") { + childObject.frame.x = sourceObject.frame.x - childObject.frame.width - 30; + } + + if (currentSpacing == "70px") { + childObject.frame.x = sourceObject.frame.x - childObject.frame.width - 70; + } + } + + if (direction == "Up") { + if (currentSpacing == "30px") { + childObject.frame.y = sourceObject.frame.y - childObject.frame.height - 30; + } + + if (currentSpacing == "70px") { + childObject.frame.y = sourceObject.frame.y - childObject.frame.height - 70; + } + } + } +} + +function autoAlignLayer(sourceObjectID, childObjectID, direction) { + var sourceObject = document.getLayerWithID(sourceObjectID); + var childObject = document.getLayerWithID(childObjectID); + var sourceMidY, childMidY, sourceMidX, childMidX, diff; + + if (Settings.settingForKey("autoAlign")) { + if (Settings.settingForKey("autoAlign") == true) { + // If user turned on Auto-Align settings + if (direction == "Right" || direction == "Left") { + sourceMidY = sourceObject.frame.y + sourceObject.frame.height / 2; + childMidY = childObject.frame.y + childObject.frame.height / 2; + diff = sourceMidY - childMidY; + + if (diff > -6 && diff < 6) { + childObject.frame.y = childObject.frame.y + diff; + } + } + + if (direction == "Down" || direction == "Up") { + sourceMidX = sourceObject.frame.x + sourceObject.frame.width / 2; + childMidX = childObject.frame.x + childObject.frame.width / 2; + diff = sourceMidX - childMidX; + + if (diff > -6 && diff < 6) { + childObject.frame.x = childObject.frame.x + diff; + } + } + } + } +} + +function defineSourceObject(firstObjectID, secondObjectID, direction) { + var firstObject = document.getLayerWithID(firstObjectID); + var secondObject = document.getLayerWithID(secondObjectID); + var sourceObjectID; + + if (direction == "Auto") { + sourceObjectID = firstObject.id; + } + + if (direction == "Right") { + if (firstObject.frame.x <= secondObject.frame.x) { + sourceObjectID = firstObject.id; + } else { + sourceObjectID = secondObject.id; + } + } + + if (direction == "Down") { + if (firstObject.frame.y <= secondObject.frame.y) { + sourceObjectID = firstObject.id; + } else { + sourceObjectID = secondObject.id; + } + } + + if (direction == "Left") { + if (firstObject.frame.x <= secondObject.frame.x) { + sourceObjectID = secondObject.id; + } else { + sourceObjectID = firstObject.id; + } + } + + if (direction == "Up") { + if (firstObject.frame.y <= secondObject.frame.y) { + sourceObjectID = secondObject.id; + } else { + sourceObjectID = firstObject.id; + } + } + + return sourceObjectID; +} + +function getSourceObjectFromSelection(selection) { + var sourceObjectID = selection.firstObject().objectID(); + + if (arrowDirectionSetting != "Auto") { + for (var g = 0; g < selection.count(); g++) { + sourceObjectID = defineSourceObject(sourceObjectID, selection[g].objectID(), arrowDirectionSetting); + } + } else { + sourceObjectID = defineSourceObject(sourceObjectID, selection[0].objectID(), arrowDirectionSetting); + } + + return sourceObjectID; +} + +function confirmationAlert(alert, message) { + // Title + alert.setMessageText("Would you like to delete all the arrows from " + message); // Creating dialog buttons + + alert.addButtonWithTitle("Delete Arrows"); + alert.addButtonWithTitle("Cancel"); // Creating the view + + var viewWidth = 300; + var viewHeight = 40; + var view = NSView.alloc().initWithFrame(NSMakeRect(0, 0, viewWidth, viewHeight)); + alert.addAccessoryView(view); // Label + + var infoLabel = NSTextField.alloc().initWithFrame(NSMakeRect(-1, viewHeight - 40, 330, 40)); + infoLabel.setStringValue("ℹī¸ You can select layers, artboards to delete all the arrows from selected one only"); + infoLabel.setSelectable(false); + infoLabel.setDrawsBackground(false); + infoLabel.setBezeled(false); + view.addSubview(infoLabel); + return alert; +} + +function alertSetup(alert, viewWidth, viewHeight) { + // Title + alert.setMessageText("Arrow Plugin Settings"); // Creating dialog buttons + + alert.addButtonWithTitle("Update Settings"); + alert.addButtonWithTitle("Cancel"); + return alert; +} + +function alertLabel(message, state, x, y, width, height) { + var infoLabel = NSTextField.alloc().initWithFrame(NSMakeRect(x, y, width, height)); + infoLabel.setStringValue(message); + infoLabel.setSelectable(false); + infoLabel.setDrawsBackground(false); + infoLabel.setBezeled(false); + + if (state == false) { + infoLabel.textColor = NSColor.disabledControlTextColor(); + } + + return infoLabel; +} + +function alertCheckbox(message, state, x, y, width, height) { + var checkbox = NSButton.alloc().initWithFrame(NSMakeRect(x, y, width, height)); + checkbox.setButtonType(NSSwitchButton); + checkbox.setBezelStyle(0); + checkbox.setTitle(message); + + if (Settings.settingForKey("autoAlign")) { + var currentState = Settings.settingForKey("autoAlign"); + checkbox.setState(currentState); + } else { + checkbox.setState(state); + } + + return checkbox; +} + +function getLayerStyles(name) { + var allStyles = docData.allLayerStyles(); + var keyword = "$arrow"; + var styles = []; + + if (name == null) { + for (var i = 0; i < allStyles.count(); i++) { + if (allStyles[i].name().includes(keyword)) { + styles.push(allStyles[i]); + } + } + } else { + // Searching only for name + for (var _i3 = 0; _i3 < allStyles.count(); _i3++) { + if (allStyles[_i3].name() == name) { + styles.push(allStyles[_i3]); + } + } + } + + return styles; +} // { +// "script": "./script.js", +// "name" : "onLayersMoved", +// "handlers" : { +// "actions": { +// "LayersMoved.finish": "onLayersMoved" +// } +// }, +// "identifier" : "onLayersMoved" +// } + +/***/ }), + +/***/ "sketch": /*!*************************!*\ !*** external "sketch" ***! \*************************/ -/*! no static exports found */function(e,t){e.exports=require("sketch")},"sketch/dom": +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = require("sketch"); + +/***/ }), + +/***/ "sketch/dom": /*!*****************************!*\ !*** external "sketch/dom" ***! \*****************************/ -/*! no static exports found */function(e,t){e.exports=require("sketch/dom")},"sketch/settings": +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = require("sketch/dom"); + +/***/ }), + +/***/ "sketch/settings": /*!**********************************!*\ !*** external "sketch/settings" ***! \**********************************/ -/*! no static exports found */function(e,t){e.exports=require("sketch/settings")},"sketch/ui": +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = require("sketch/settings"); + +/***/ }), + +/***/ "sketch/ui": /*!****************************!*\ !*** external "sketch/ui" ***! \****************************/ -/*! no static exports found */function(e,t){e.exports=require("sketch/ui")}});"default"===e&&"function"==typeof r?r(t):r[e](t)}that.onRun=__skpm_run.bind(this,"default"),that.updateSelectedArrows=__skpm_run.bind(this,"updateSelectedArrows"),that.updateArtboardArrows=__skpm_run.bind(this,"updateArtboardArrows"),that.updateAllArrows=__skpm_run.bind(this,"updateAllArrows"),that.deleteSelectedArrows=__skpm_run.bind(this,"deleteSelectedArrows"),that.deleteArtboardArrows=__skpm_run.bind(this,"deleteArtboardArrows"),that.deleteAllArrows=__skpm_run.bind(this,"deleteAllArrows"),that.settings=__skpm_run.bind(this,"settings"),that.panel=__skpm_run.bind(this,"panel"); \ No newline at end of file +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = require("sketch/ui"); + +/***/ }) + +/******/ }); + if (key === 'default' && typeof exports === 'function') { + exports(context); + } else { + exports[key](context); + } +} +that['onRun'] = __skpm_run.bind(this, 'default'); +that['updateSelectedArrows'] = __skpm_run.bind(this, 'updateSelectedArrows'); +that['updateArtboardArrows'] = __skpm_run.bind(this, 'updateArtboardArrows'); +that['updateAllArrows'] = __skpm_run.bind(this, 'updateAllArrows'); +that['deleteSelectedArrows'] = __skpm_run.bind(this, 'deleteSelectedArrows'); +that['deleteArtboardArrows'] = __skpm_run.bind(this, 'deleteArtboardArrows'); +that['deleteAllArrows'] = __skpm_run.bind(this, 'deleteAllArrows'); +that['settings'] = __skpm_run.bind(this, 'settings'); +that['panel'] = __skpm_run.bind(this, 'panel') + +//# sourceMappingURL=script.js.map \ No newline at end of file diff --git a/arrows.sketchplugin/Contents/Sketch/script.js.map b/arrows.sketchplugin/Contents/Sketch/script.js.map index 9378e09..cbed1d2 100644 --- a/arrows.sketchplugin/Contents/Sketch/script.js.map +++ b/arrows.sketchplugin/Contents/Sketch/script.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://exports/webpack/bootstrap","webpack://exports/./src/script.js","webpack://exports/external \"sketch\"","webpack://exports/external \"sketch/dom\"","webpack://exports/external \"sketch/settings\"","webpack://exports/external \"sketch/ui\""],"names":["UI","require","pluginKey","document","sketch","fromNative","context","docData","documentData","pluginData","command","valueForKey_onLayer_forPluginIdentifier","currentParentGroup","currentPage","currentArtboard","newConnectionsData","getConnectionsData","Settings","arrowDirectionSetting","settingForKey","selection","count","sourceObjectID","getSourceObjectFromSelection","currentConnectionsData","g","objectID","connectionIndex","findConnectionData","updateArrow","firstObject","secondObject","line","message","createArrow","setValue_forKey_onLayer_forPluginIdentifier","updateSelectedArrows","updateArtboardArrows","connections","firstObjectArtboard","secondObjectArtboard","length","updateArrowsCounter","i","getLayerWithID","sketchObject","parentArtboard","class","direction","push","updateAllArrows","deleteAllArrows","deleteLine","deleteArtboardArrows","deleteConnectionFromData","deleteSelectedArrows","settings","alert","COSAlertWindow","new","viewWidth","viewHeight","alertSetup","view","NSView","alloc","initWithFrame","NSMakeRect","addAccessoryView","arrowDirectionLabel","alertLabel","addSubview","arrowDirectionField","NSPopUpButton","setActiveDirectionSetting","arrowDirectionInfoLabel","arrowSpacingLabel","arrowSpacingField","setActiveSpacingSetting","arrowSpacingInfoLabel","otherSettingsLabel","checkbox","alertCheckbox","autoAlignInfoLabel","pluginInfoLabel","modalResponse","runModal","NSAlertFirstButtonReturn","setSettingForKey","views","subviews","title","state","onLayersMoved","action","actionContext","panel","ControlBar","NSPanel","init","setStyleMask","NSTitledWindowMask","NSFullSizeContentViewWindowMask","setTitleVisibility","NSWindowTitleHidden","setTitlebarAppearsTransparent","setFrame_display","setMovableByWindowBackground","setHasShadow","setLevel","NSFloatingWindowLevel","center","makeKeyAndOrderFront","nil","firstObjectID","secondObjectID","lineID","localDirection","getDirection","updateSpacing","autoAlignLayer","currentGroup","checkForArrowGroup","drawLine","addToArrowsGroup","connection","layers","name","refactorLines","firstObjectMidX","frame","x","width","firstObjectMidY","y","height","secondObjectMidX","secondObjectMidY","diffX","diffY","absDiffX","Math","abs","absDiffY","firstLayerPosX","firstLayerPosY","secondLayerPosX","secondLayerPosY","middlePosX","middlePosY","path","NSBezierPath","bezierPath","moveToPoint","NSMakePoint","lineToPoint","MSShapeGroup","layerWithPath","MSPath","pathWithBezierPath","points","cornerRadius","setName","border","style","addStylePartOfType","color","MSColor","colorWithRGBADictionary","r","b","a","thickness","endMarkerType","addLayers","fixGeometryWithOptions","Group","group","parent","locked","moveToBack","dataArray","pluginDataConnections","data","arrayNumber","String","currentDirection","addItemWithTitle","lastItem","setState","currentSpacing","newConnections","lineObject","selectedGroup","remove","childObjectID","sourceObject","childObject","sourceMidY","childMidY","sourceMidX","childMidX","diff","defineSourceObject","id","confirmationAlert","setMessageText","addButtonWithTitle","infoLabel","NSTextField","setStringValue","setSelectable","setDrawsBackground","setBezeled","textColor","NSColor","disabledControlTextColor","NSButton","setButtonType","NSSwitchButton","setBezelStyle","setTitle","currentState"],"mappings":";;;;;;AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,kDAA0C,gCAAgC;AAC1E;AACA;;AAEA;AACA;AACA;AACA,gEAAwD,kBAAkB;AAC1E;AACA,yDAAiD,cAAc;AAC/D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iDAAyC,iCAAiC;AAC1E,wHAAgH,mBAAmB,EAAE;AACrI;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;;AAGA;AACA;;;;;;;;;;;;;AClFA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;CACA;AAEA;AACA;AACA;;AAEA,IAAIA,EAAE,GAAGC,mBAAO,CAAC,4BAAD,CAAhB;;AACA,IAAMC,SAAS,GAAG,YAAlB;AACA,IAAMC,QAAQ,GAAGC,6CAAM,CAACC,UAAP,CAAkBC,OAAO,CAACH,QAA1B,CAAjB;AACA,IAAII,OAAO,GAAGD,OAAO,CAACH,QAAR,CAAiBK,YAAjB,EAAd;AACA,IAAIC,UAAU,GAAGH,OAAO,CAACI,OAAR,CAAgBC,uCAAhB,CAAwD,kBAAxD,EAA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B;AACD;;AAED,SAAOR,SAAP;AACD;;AAED,SAAS9H,aAAT,CAAuBjD,OAAvB,EAAgC2D,KAAhC,EAAuCuC,CAAvC,EAA0CG,CAA1C,EAA6CF,KAA7C,EAAoDG,MAApD,EAA2D;AACzD,MAAItD,QAAQ,GAAGwI,QAAQ,CAACxJ,KAAT,GAAiBC,aAAjB,CAA+BC,UAAU,CAACgE,CAAD,EAAIG,CAAJ,EAAOF,KAAP,EAAcG,MAAd,CAAzC,CAAf;AAEAtD,UAAQ,CAACyI,aAAT,CAAuBC,cAAvB;AACA1I,UAAQ,CAAC2I,aAAT,CAAuB,CAAvB;AACA3I,UAAQ,CAAC4I,QAAT,CAAkB5L,OAAlB;;AACA,MAAGhB,QAAQ,CAACE,aAAT,CAAuB,WAAvB,CAAH,EAAuC;AACrC,QAAI2M,YAAY,GAAG7M,QAAQ,CAACE,aAAT,CAAuB,WAAvB,CAAnB;AACA8D,YAAQ,CAAC4G,QAAT,CAAkBiC,YAAlB;AACD,GAHD,MAGO;AACL7I,YAAQ,CAAC4G,QAAT,CAAkBjG,KAAlB;AACD;;AAED,SAAOX,QAAP;AACD,C,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,I;;;;;;;;;;;ACvgCA,mC;;;;;;;;;;;ACAA,uC;;;;;;;;;;;ACAA,4C;;;;;;;;;;;ACAA,sC","file":"script.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./src/script.js\");\n","import sketch from 'sketch'\n// const { toArray } = require('util')\n\n//\n// Variables\n//\n\nlet UI = require('sketch/ui') \nconst pluginKey = \"flowArrows\"\nconst document = sketch.fromNative(context.document)\nlet docData = context.document.documentData()\nlet pluginData = context.command.valueForKey_onLayer_forPluginIdentifier(\"arrowConnections\", docData, pluginKey) // TODO: Need to refactor\nlet currentParentGroup = docData.currentPage().currentArtboard() || docData.currentPage() // TODO: Might be a problem for multiple artboards\nlet newConnectionsData = getConnectionsData()\n\n// Settings\nvar Settings = require('sketch/settings')\nlet arrowDirectionSetting\n\nif(Settings.settingForKey(\"arrowDirection\")) {\n arrowDirectionSetting = Settings.settingForKey('arrowDirection')\n} else {\n arrowDirectionSetting = \"Auto\"\n}\n \n\n//\n// Default Function\n//\n\nexport default function(context) {\n\n let selection = context.selection\n\n if(selection.count() > 1){\n // Need to find source object by ID first\n let sourceObjectID = getSourceObjectFromSelection(selection)\n let currentConnectionsData = newConnectionsData\n\n for(let g = 0; g < selection.count(); g++) {\n if(selection[g].objectID() != sourceObjectID){\n // Then need to create or update connection arrow with each selection\n let connectionIndex = findConnectionData(sourceObjectID, selection[g].objectID(), currentConnectionsData)\n // log(\"Index \"+connectionIndex)\n if(connectionIndex != null){\n // Because this is creating flow, we need to take the direction from user settings\n updateArrow(currentConnectionsData[connectionIndex].firstObject, currentConnectionsData[connectionIndex].secondObject, arrowDirectionSetting, currentConnectionsData[connectionIndex].line, connectionIndex)\n sketch.UI.message(\"Current connection is updated 🚀\")\n } else {\n // There is no connection with this two objects in our database\n createArrow(sourceObjectID, selection[g].objectID(), arrowDirectionSetting)\n sketch.UI.message(\"New connection is created 🚀\")\n }\n }\n }\n context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, \"arrowConnections\", docData, pluginKey)\n // log(newConnectionsData)\n } else {\n // When user didn't select anything\n sketch.UI.message(\"Please select more than two layers\")\n }\n}\n\n//\n// Plugin Commands\n//\n\nexport function updateSelectedArrows(context) {\n\n let selection = context.selection\n\n if(selection.count() > 1){\n // Need to find source object by ID first\n let sourceObjectID = getSourceObjectFromSelection(selection)\n let currentConnectionsData = newConnectionsData\n\n for(let g = 0; g < selection.count(); g++) {\n if(selection[g].objectID() != sourceObjectID){\n // Then need to create or update connection arrow with each selection\n let connectionIndex = findConnectionData(sourceObjectID, selection[g].objectID(), currentConnectionsData)\n\n if(connectionIndex != null){\n updateArrow(currentConnectionsData[connectionIndex].firstObject, currentConnectionsData[connectionIndex].secondObject, arrowDirectionSetting, currentConnectionsData[connectionIndex].line, connectionIndex)\n sketch.UI.message(\"Current connection is updated 🚀\")\n } \n }\n }\n context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, \"arrowConnections\", docData, pluginKey)\n // log(newConnectionsData)\n } else {\n // When user didn't select anything\n sketch.UI.message(\"Please select more than two layers\")\n }\n}\n\nexport function updateArtboardArrows(context) {\n // TODO: Need to show amount of updated arrows and deleted ones\n let selection = context.selection\n let connections = getConnectionsData()\n let firstObjectArtboard\n let secondObjectArtboard\n \n if(connections.length > 0){\n // We have connections in database\n const updateArrowsCounter = connections.length\n for (let i = 0; i < updateArrowsCounter; i ++) {\n // Need to check if the element is selected globally or from the artboard\n firstObjectArtboard = document.getLayerWithID(connections[i].firstObject)\n firstObjectArtboard = firstObjectArtboard.sketchObject.parentArtboard().objectID()\n\n secondObjectArtboard = document.getLayerWithID(connections[i].secondObject)\n secondObjectArtboard = secondObjectArtboard.sketchObject.parentArtboard().objectID()\n\n if(selection.count() == 1 && selection[0].class() == \"MSArtboardGroup\"){\n // Need to go through each connection and update arrow position for specific artboard\n \n if (firstObjectArtboard == selection[0].objectID()){\n if (secondObjectArtboard == selection[0].objectID()){\n updateArrow(connections[i].firstObject, connections[i].secondObject, connections[i].direction, connections[i].line, i)\n } else {newConnectionsData.push(connections[i])}\n } else {\n // If not just saving it\n newConnectionsData.push(connections[i])\n }\n }\n }\n context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, \"arrowConnections\", docData, pluginKey)\n sketch.UI.message(\"All arrows are updated 🚀\")\n } else {\n // We don't have any connections to update\n sketch.UI.message(\"There is nothing to update\")\n }\n\n // log(newConnectionsData)\n}\n\nexport function updateAllArrows(context) { // TODO\n // TODO: Need to show amount of updated arrows and deleted ones\n let selection = context.selection\n let connections = getConnectionsData()\n let firstObjectArtboard\n let secondObjectArtboard\n \n if(connections.length > 0){\n // We have connections in database\n const updateArrowsCounter = connections.length\n for (let i = 0; i < updateArrowsCounter; i ++) {\n // Need to go through each connection and update arrow position without artboards\n // Need to check if current object don't have the parrent\n updateArrow(connections[i].firstObject, connections[i].secondObject, connections[i].direction, connections[i].line, i)\n }\n context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, \"arrowConnections\", docData, pluginKey)\n sketch.UI.message(\"All arrows are updated 🚀\")\n } else {\n // We don't have any connections to update\n sketch.UI.message(\"There is nothing to update\")\n }\n}\n\nexport function deleteAllArrows(context) {\n\n if(newConnectionsData.length > 0){\n // We have connections in database\n for (let i = 0; i < newConnectionsData.length; i ++) {\n // Need to go through each connection and update arrow position\n deleteLine(newConnectionsData[i].line)\n }\n context.command.setValue_forKey_onLayer_forPluginIdentifier(null, \"arrowConnections\", docData, pluginKey)\n sketch.UI.message(\"All arrows are deleted\")\n } else {\n // We don't have any connections to update\n sketch.UI.message(\"There is nothing to delete\")\n }\n}\n\nexport function deleteArtboardArrows(context) {\n let selection = context.selection\n let firstObject, secondObject\n\n // Need to delete all the arrows only from selected artboard\n if(selection.count() == 1 && selection[0].class() == \"MSArtboardGroup\"){\n let connections = getConnectionsData()\n \n if(connections.length > 0){\n // We have connections in database\n const updateArrowsCounter = connections.length\n for (let i = 0; i < updateArrowsCounter; i ++) {\n // Need to go through each connection and check if it placed on selected artboard\n firstObject = document.getLayerWithID(connections[i].firstObject)\n secondObject = document.getLayerWithID(connections[i].secondObject)\n if (firstObject.sketchObject.parentArtboard().objectID() == selection[0].objectID()){\n if (secondObject.sketchObject.parentArtboard().objectID() == selection[0].objectID()){\n deleteLine(connections[i].line)\n newConnectionsData = deleteConnectionFromData(i)\n }\n }\n }\n context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, \"arrowConnections\", docData, pluginKey)\n sketch.UI.message(\"All arrows from selected artboard are deleted\")\n } else {\n // We don't have any connections to update\n sketch.UI.message(\"There is nothing to delete\")\n }\n } else {\n sketch.UI.message(\"Please select one artboard\")\n }\n}\n\nexport function deleteSelectedArrows(context) {\n let selection = context.selection\n let firstObject, secondObject\n\n // Need to delete all the arrows only from selected artboard\n if(selection.count() == 2){\n\n for(let g = 0; g < selection.count(); g++) {\n\n if(selection[g].objectID() != selection[0].objectID()){ // It will never check 3rd connection\n let connections = getConnectionsData()\n \n let connectionIndex = findConnectionData(selection[0].objectID(), selection[g].objectID(), connections)\n // log(connectionIndex)\n \n if(connectionIndex != null){\n // We have connections in database\n deleteLine(connections[connectionIndex].line)\n newConnectionsData = deleteConnectionFromData(connectionIndex)\n const updateArrowsCounter = connections.length\n for (let i = 0; i < updateArrowsCounter; i ++) {\n // Need to go through each connection and check if it placed on selected artboard\n firstObject = document.getLayerWithID(connections[i].firstObject)\n secondObject = document.getLayerWithID(connections[i].secondObject)\n if(firstObject.sketchObject.parentArtboard().objectID() == selection[0].objectID()){\n if(secondObject.sketchObject.parentArtboard().objectID() == selection[0].objectID()){\n deleteLine(connections[i].line)\n newConnectionsData = deleteConnectionFromData(i)\n }\n }\n }\n context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, \"arrowConnections\", docData, pluginKey)\n sketch.UI.message(\"All arrows from selected layers are deleted ✌ī¸\")\n }\n }\n }\n } else {\n sketch.UI.message(\"Select two layers, please 🧐\")\n }\n}\n\nexport function settings(context) {\n let alert = COSAlertWindow.new()\n const viewWidth = 300\n const viewHeight = 330\n \n // Alert window settingsnp\n alert = alertSetup(alert, viewWidth, viewHeight)\n let view = NSView.alloc().initWithFrame(NSMakeRect(0, 0, viewWidth, viewHeight))\n alert.addAccessoryView(view)\n\n // Label: Arrow Direction\n let arrowDirectionLabel = alertLabel(\"Arrow Direction\", true, -1, viewHeight - 17, 330, 20)\n view.addSubview(arrowDirectionLabel)\n \n // Select: Arrow Direction\n let arrowDirectionField = NSPopUpButton.alloc().initWithFrame(NSMakeRect(-2, viewHeight - 40, 300, 20))\n setActiveDirectionSetting(arrowDirectionField)\n view.addSubview(arrowDirectionField)\n\n // Label: Auto Direction Info\n let arrowDirectionInfoLabel = alertLabel(\"Auto mode will draw arrow based on location of the second object\", false, -1, viewHeight-84, 280, 40)\n view.addSubview(arrowDirectionInfoLabel)\n\n // Label: Arrow Spacing\n let arrowSpacingLabel = alertLabel(\"Arrow Spacing\", true, -1, viewHeight - 120, 330, 20)\n view.addSubview(arrowSpacingLabel)\n\n // Select: Arrow Spacing\n let arrowSpacingField = NSPopUpButton.alloc().initWithFrame(NSMakeRect(-2, viewHeight - 143, 300, 20));\n setActiveSpacingSetting(arrowSpacingField)\n view.addSubview(arrowSpacingField)\n \n // Label: Auto Spacing Info\n let arrowSpacingInfoLabel = alertLabel(\"If you will select spacing, the second layer position will be moved closer\", false, -1, viewHeight-187, 280, 40)\n view.addSubview(arrowSpacingInfoLabel)\n\n // Label: Other Settings\n let otherSettingsLabel = alertLabel(\"Other Settings\", true, -1, viewHeight-240, 280, 40)\n view.addSubview(otherSettingsLabel)\n\n // Checkbox: Auto-Align\n let checkbox = alertCheckbox(\"Second layer auto-align\", false, -1, viewHeight-250, 280, 40)\n view.addSubview(checkbox)\n\n // Label: Auto-Align Info\n let autoAlignInfoLabel = alertLabel(\"Align the second layer for 5px misalignment with the first one\", false, -1, viewHeight-280, 280, 40)\n view.addSubview(autoAlignInfoLabel)\n\n // Label: Plugin Info\n let pluginInfoLabel = alertLabel(\"Made by @faridSabitov with the support of EPAM.com ❤ī¸\", true, -1, viewHeight-330, 280, 40)\n view.addSubview(pluginInfoLabel)\n\n // Show modal and get the results\n let modalResponse = alert.runModal()\n\n if(modalResponse == NSAlertFirstButtonReturn){\n // When user clicks on \"Update Settings\"\n // Need to save all this results into the Plugin Settings\n Settings.setSettingForKey(\"arrowDirection\", alert.views()[0].subviews()[1].title())\n Settings.setSettingForKey(\"arrowSpacing\", alert.views()[0].subviews()[4].title())\n Settings.setSettingForKey(\"autoAlign\", alert.views()[0].subviews()[7].state())\n UI.message(\"Settings are updated 🚀\")\n }\n}\n\nexport function onLayersMoved(context) {\n sketch.UI.message(\"Please select more than two layers\")\n // let a = 0\n const action = context.actionContext\n // log(context.actionContext)\n // log(\"moved\")\n \n}\n\nexport function panel(context) {\n let ControlBar\n ControlBar = NSPanel.alloc().init();\n ControlBar.setStyleMask(NSTitledWindowMask + NSFullSizeContentViewWindowMask);\n // ControlBar.setBackgroundColor(NSColor.colorWithRed_green_blue_alpha(0.99, 0.99, 0.99, 1));\n ControlBar.setTitleVisibility(NSWindowTitleHidden);\n ControlBar.setTitlebarAppearsTransparent(true);\n ControlBar.setFrame_display(NSMakeRect(0, 0, 720, 50), false);\n ControlBar.setMovableByWindowBackground(true);\n ControlBar.setHasShadow(true);\n ControlBar.setLevel(NSFloatingWindowLevel);\n\n // contentView.addSubview(closeButton)\n ControlBar.center();\n ControlBar.makeKeyAndOrderFront(nil);\n\n// getImage = function(size, name){\n// var isRetinaDisplay = (NSScreen.mainScreen().backingScaleFactor() > 1)? true: false;\n// suffix = (isRetinaDisplay)? \"@2x\": \"\",\n// imageURL = NSURL.fileURLWithPath(self.pluginResources + \"/icons/\" + name + suffix + \".png\"),\n// image = NSImage.alloc().initWithContentsOfURL(imageURL);\n// return image\n// },\n// addButton = function(rect, name, callAction){\n// var button = NSButton.alloc().initWithFrame(rect),\n// image = getImage(rect.size, name);\n\n// button.setImage(image);\n// button.setBordered(false);\n// button.sizeToFit();\n// button.setButtonType(NSMomentaryChangeButton);\n// button.setCOSJSTargetFunction(callAction);\n// button.setAction(\"callAction:\");\n// return button;\n// },\n// addImage = function(rect, name){\n// var view = NSImageView.alloc().initWithFrame(rect),\n// image = getImage(rect.size, name);\n// view.setImage(image);\n// return view;\n// },\n\n// closeButton = addButton( NSMakeRect(20, 10, 30, 30), \"close-control\",\n// function(sender){\n// coscript.setShouldKeepAround(false);\n// threadDictionary.removeObjectForKey(identifier);\n// ControlBar.close();\n// }),\n\n\n\n}\n\n\n//\n// Functions\n//\n\nfunction updateArrow(firstObjectID, secondObjectID, direction, lineID, connectionIndex) {\n // There might be a situation, when user deleted current group or current group stays on another artboard => In that case need to create another group\n\n // Need to check if we have the layers with such IDs\n let firstObject = document.getLayerWithID(firstObjectID)\n let secondObject = document.getLayerWithID(secondObjectID)\n\n // Need to delete data first, because we will have a new line\n deleteLine(lineID)\n newConnectionsData = deleteConnectionFromData(connectionIndex)\n\n if(firstObject && secondObject){\n // If we have all the objects, we can recreate the line\n createArrow(firstObjectID, secondObjectID, direction)\n } \n}\n\nfunction createArrow(firstObjectID, secondObjectID, direction) {\n // Process of creating new connection\n let localDirection\n \n if(direction == \"Auto\"){\n // If direction is auto, we need to specify direction ourselves\n localDirection = getDirection(firstObjectID, secondObjectID)\n } else {\n localDirection = direction\n }\n \n updateSpacing(firstObjectID, secondObjectID, localDirection)\n autoAlignLayer(firstObjectID, secondObjectID, localDirection)\n let currentGroup = checkForArrowGroup()\n let line = drawLine(firstObjectID, secondObjectID, localDirection, currentGroup)\n addToArrowsGroup(line, currentGroup)\n\n // Storage for current connection\n let connection = {\n firstObject : firstObjectID,\n secondObject : secondObjectID,\n direction: localDirection,\n line : line.objectID()\n }\n // Need to save this data to the global array\n newConnectionsData.push(connection)\n}\n\nfunction checkForArrowGroup() {\n let currentGroup = null\n // Checking all the groups that we have\n for(let i = 0; i < currentParentGroup.layers().count(); i++){\n if(currentParentGroup.layers()[i].name() == \"Arrows\") {\n // If we already have \"Arrow\" group we need to save it's folder\n currentGroup = currentParentGroup.layers()[i]\n refactorLines(currentGroup)\n } \n }\n return currentGroup\n}\n\nfunction getDirection(firstObjectID, secondObjectID){\n // Get direction from the source object\n const firstObject = document.getLayerWithID(firstObjectID)\n const secondObject = document.getLayerWithID(secondObjectID)\n const firstObjectMidX = firstObject.frame.x+firstObject.frame.width/2\n const firstObjectMidY = firstObject.frame.y+firstObject.frame.height/2\n const secondObjectMidX = secondObject.frame.x+secondObject.frame.width/2\n const secondObjectMidY = secondObject.frame.y+secondObject.frame.height/2\n\n const diffX = firstObjectMidX - secondObjectMidX\n const diffY = firstObjectMidY - secondObjectMidY\n const absDiffX = Math.abs(diffX) \n const absDiffY = Math.abs(diffY)\n let direction\n\n if(secondObjectMidX > firstObjectMidX){\n // Right Half\n if(secondObjectMidY > firstObjectMidY){\n // Bottom quarter\n if(diffX > diffY) {\n direction = \"Down\"\n } else {\n direction = \"Right\"\n }\n } else {\n // Top quarter\n if(absDiffX > absDiffY) {\n direction = \"Right\"\n } else {\n direction = \"Up\"\n }\n }\n } else {\n // Left Half\n if(secondObjectMidY > firstObjectMidY){\n // Bottom quarter\n if(absDiffX > absDiffY) {\n direction = \"Left\"\n } else {\n direction = \"Down\"\n }\n } else {\n // Top quarter\n if(diffX > diffY) {\n direction = \"Left\"\n } else {\n direction = \"Up\"\n }\n }\n }\n return direction\n}\n\nfunction drawLine(firstObjectID, secondObjectID, direction, currentGroup){\n let firstLayerPosX, firstLayerPosY, secondLayerPosX, secondLayerPosY, middlePosX, middlePosY, diffX, diffY\n let firstObject = document.getLayerWithID(firstObjectID)\n let secondObject = document.getLayerWithID(secondObjectID)\n\n \n if(currentGroup){\n //if we already have a group, need to specify the difference\n diffX = currentGroup.frame().x()\n diffY = currentGroup.frame().y()\n } else {\n diffX = 0\n diffY = 0\n }\n\n // Drawing a line\n let path = NSBezierPath.bezierPath()\n\n \n \n // Based on direction, we need to specify connection points\n if(direction == \"Up\"){\n // First Layer Position Start Point Position\n firstLayerPosX = firstObject.frame.x+firstObject.frame.width/2-diffX\n firstLayerPosY = firstObject.frame.y-diffY\n\n // Second Layer Position End Point Position\n secondLayerPosX = secondObject.frame.x+secondObject.frame.width/2-diffX\n secondLayerPosY = secondObject.frame.y+secondObject.frame.height-diffY\n\n // Middle Points\n middlePosX = (firstLayerPosX + secondLayerPosX)/2\n middlePosY = (firstLayerPosY + secondLayerPosY)/2\n\n // Connecting points\n path.moveToPoint(NSMakePoint(firstLayerPosX,firstLayerPosY))\n path.lineToPoint(NSMakePoint(firstLayerPosX,middlePosY))\n path.lineToPoint(NSMakePoint(secondLayerPosX,middlePosY))\n path.lineToPoint(NSMakePoint(secondLayerPosX,secondLayerPosY))\n }\n\n if(direction == \"Right\"){\n // First Layer Position Start Point Position\n firstLayerPosX = firstObject.frame.x+firstObject.frame.width-diffX\n firstLayerPosY = firstObject.frame.y+firstObject.frame.height/2-diffY\n\n // Second Layer Position End Point Position\n secondLayerPosX = secondObject.frame.x-diffX\n secondLayerPosY = secondObject.frame.y+secondObject.frame.height/2-diffY\n \n // Middle Points\n middlePosX = (firstLayerPosX + secondLayerPosX)/2\n middlePosY = (firstLayerPosY + secondLayerPosY)/2\n\n // Connecting points\n path.moveToPoint(NSMakePoint(firstLayerPosX,firstLayerPosY))\n path.lineToPoint(NSMakePoint(middlePosX,firstLayerPosY))\n path.lineToPoint(NSMakePoint(middlePosX,secondLayerPosY))\n path.lineToPoint(NSMakePoint(secondLayerPosX,secondLayerPosY))\n }\n\n if(direction == \"Down\"){\n // First Layer Position Start Point Position\n firstLayerPosX = firstObject.frame.x+firstObject.frame.width/2-diffX\n firstLayerPosY = firstObject.frame.y+firstObject.frame.height-diffY\n\n // Second Layer Position End Point Position\n secondLayerPosX = secondObject.frame.x+secondObject.frame.width/2-diffX\n secondLayerPosY = secondObject.frame.y-diffY\n\n // Middle Points\n middlePosX = (firstLayerPosX + secondLayerPosX)/2\n middlePosY = (firstLayerPosY + secondLayerPosY)/2\n \n // Connecting points\n path.moveToPoint(NSMakePoint(firstLayerPosX,firstLayerPosY))\n path.lineToPoint(NSMakePoint(firstLayerPosX,middlePosY))\n path.lineToPoint(NSMakePoint(secondLayerPosX,middlePosY))\n path.lineToPoint(NSMakePoint(secondLayerPosX,secondLayerPosY))\n }\n\n if(direction == \"Left\"){\n // First Layer Position Start Point Position\n firstLayerPosX = firstObject.frame.x-diffX\n firstLayerPosY = firstObject.frame.y+firstObject.frame.height/2-diffY\n\n // Second Layer Position End Point Position\n secondLayerPosX = secondObject.frame.x+secondObject.frame.width-diffX\n secondLayerPosY = secondObject.frame.y+secondObject.frame.height/2-diffY\n\n // Middle Points\n middlePosX = (firstLayerPosX + secondLayerPosX)/2\n middlePosY = (firstLayerPosY + secondLayerPosY)/2\n\n // Connecting points\n path.moveToPoint(NSMakePoint(firstLayerPosX,firstLayerPosY))\n path.lineToPoint(NSMakePoint(middlePosX,firstLayerPosY))\n path.lineToPoint(NSMakePoint(middlePosX,secondLayerPosY))\n path.lineToPoint(NSMakePoint(secondLayerPosX,secondLayerPosY))\n }\n\n //TODO: Provide a separate file with all the stylings\n\n // Painting the line\n let line = MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(path))\n\n\n // Making middle points rounded\n let points = line.layers().firstObject().points()\n points[1].cornerRadius = 20\n points[2].cornerRadius = 20\n\n // Providing Settings for the arrow\n line.setName(\"Arrow\")\n\n // Styling Border Style\n let border = line.style().addStylePartOfType(1)\n border.color = MSColor.colorWithRGBADictionary({r: 0.89, g: 0.89, b: 0.89, a: 1})\n border.thickness = 2\n line.style().endMarkerType = 2\n\n return line\n}\n\nfunction addToArrowsGroup(line, currentGroup){\n if(currentGroup){\n currentGroup.addLayers([line])\n currentGroup.fixGeometryWithOptions(1)\n } else {\n // If we don't have a group\n let Group = require('sketch/dom').Group\n let group = new Group({\n parent: currentParentGroup,\n name: 'Arrows',\n locked: true,\n layers: [line]\n })\n // Moving this group to the bottom of the page\n group.moveToBack()\n currentGroup = checkForArrowGroup()\n currentGroup.fixGeometryWithOptions(1)\n }\n\n \n \n}\n\nfunction getConnectionsData(){\n let dataArray = []\n let pluginDataConnections = []\n if(pluginData){\n pluginDataConnections = context.command.valueForKey_onLayer_forPluginIdentifier(\"arrowConnections\", docData, pluginKey)\n \n for (let i = 0; i < pluginDataConnections.length; i ++) {\n dataArray.push(pluginDataConnections[i])\n }\n } \n return dataArray\n}\n\nfunction findConnectionData(firstObjectID, secondObjectID, data){\n let arrayNumber = null\n firstObjectID = String(firstObjectID)\n secondObjectID = String(secondObjectID)\n\n if(pluginData){\n // If we have database, need to check for connections\n\n for(let y = 0; y < data.length; y++){\n // log(\"First one \"+firstObjectID)\n // log(\"Current Index \"+y)\n\n if(firstObjectID == data[y].firstObject || firstObjectID == data[y].secondObject){\n // if we found that we have this object in connection database already\n // log(\"We have the first one\")\n // log(\"Second one \"+secondObjectID)\n if(secondObjectID == data[y].firstObject || secondObjectID == data[y].secondObject){\n // if we found that we have this object in connection database already\n arrayNumber = y\n // log(\"We have the second one as\"+arrayNumber)\n } \n }\n }\n }\n return arrayNumber\n}\n\nfunction setActiveDirectionSetting (arrowDirectionField){\n let currentDirection = \"Auto\"\n\n if(Settings.settingForKey(\"arrowDirection\")){\n // if there is data in settings\n currentDirection = Settings.settingForKey(\"arrowDirection\") \n \n if(currentDirection == \"Auto\"){\n arrowDirectionField.addItemWithTitle(\"Auto\")\n arrowDirectionField.lastItem().setState(1)\n arrowDirectionField.addItemWithTitle(\"Right\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Down\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Left\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Up\")\n arrowDirectionField.lastItem().setState(0)\n } \n \n if(currentDirection == \"Right\"){\n arrowDirectionField.addItemWithTitle(\"Right\")\n arrowDirectionField.lastItem().setState(1)\n arrowDirectionField.addItemWithTitle(\"Down\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Left\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Up\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Auto\")\n arrowDirectionField.lastItem().setState(0)\n } \n\n if(currentDirection == \"Down\"){\n arrowDirectionField.addItemWithTitle(\"Down\")\n arrowDirectionField.lastItem().setState(1)\n arrowDirectionField.addItemWithTitle(\"Left\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Up\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Auto\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Right\")\n arrowDirectionField.lastItem().setState(0)\n } \n\n if(currentDirection == \"Left\"){\n arrowDirectionField.addItemWithTitle(\"Left\")\n arrowDirectionField.lastItem().setState(1)\n arrowDirectionField.addItemWithTitle(\"Up\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Auto\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Right\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Down\")\n arrowDirectionField.lastItem().setState(0)\n } \n\n if(currentDirection == \"Up\"){\n arrowDirectionField.addItemWithTitle(\"Up\")\n arrowDirectionField.lastItem().setState(1)\n arrowDirectionField.addItemWithTitle(\"Auto\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Right\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Down\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Left\")\n arrowDirectionField.lastItem().setState(0)\n } \n\n } else {\n // Show default\n arrowDirectionField.addItemWithTitle(\"Auto\")\n arrowDirectionField.addItemWithTitle(\"Right\")\n arrowDirectionField.addItemWithTitle(\"Down\")\n arrowDirectionField.addItemWithTitle(\"Left\")\n arrowDirectionField.addItemWithTitle(\"Up\")\n }\n}\n\nfunction setActiveSpacingSetting (arrowSpacingField){\n let currentSpacing = \"Not selected\"\n\n if(Settings.settingForKey(\"arrowSpacing\")){\n // if there is data in settings\n currentSpacing = Settings.settingForKey(\"arrowSpacing\") \n \n if(currentSpacing == \"Not selected\"){\n arrowSpacingField.addItemWithTitle(\"Not selected\")\n arrowSpacingField.lastItem().setState(1)\n arrowSpacingField.addItemWithTitle(\"30px\")\n arrowSpacingField.lastItem().setState(0)\n arrowSpacingField.addItemWithTitle(\"70px\")\n arrowSpacingField.lastItem().setState(0)\n } \n \n if(currentSpacing == \"30px\"){\n arrowSpacingField.addItemWithTitle(\"30px\")\n arrowSpacingField.lastItem().setState(1)\n arrowSpacingField.addItemWithTitle(\"70px\")\n arrowSpacingField.lastItem().setState(0)\n arrowSpacingField.addItemWithTitle(\"Not selected\")\n arrowSpacingField.lastItem().setState(0)\n } \n\n if(currentSpacing == \"70px\"){\n arrowSpacingField.addItemWithTitle(\"70px\")\n arrowSpacingField.lastItem().setState(1)\n arrowSpacingField.addItemWithTitle(\"Not selected\")\n arrowSpacingField.lastItem().setState(0)\n arrowSpacingField.addItemWithTitle(\"30px\")\n arrowSpacingField.lastItem().setState(0)\n } \n } else {\n // Show default\n arrowSpacingField.addItemWithTitle(\"Not Selected\")\n arrowSpacingField.addItemWithTitle(\"30px\")\n arrowSpacingField.addItemWithTitle(\"70px\")\n }\n}\n\nfunction deleteConnectionFromData(arrayNumber){\n let newConnections = []\n if(pluginData){\n // If we have database\n let connections = context.command.valueForKey_onLayer_forPluginIdentifier(\"arrowConnections\", docData, pluginKey)\n\n for (let i = 0; i < connections.length; i ++) {\n // Updating all connections without deleted one\n if(i != arrayNumber){\n newConnections.push(connections[i])\n }\n }\n }\n return newConnections\n}\n\nfunction refactorLines(group){ // Need to finish\n // log(group.layers().length)\n for(let i = 0; i < group.layers().length; i++){\n // log(group.layers()[i].objectID())\n // Here we need to go through each data in our database and delete line if there is no data\n }\n}\n\nfunction deleteLine(lineID){\n const lineObject = document.getLayerWithID(lineID)\n let selectedGroup\n\n if(lineObject){\n selectedGroup = lineObject.parent\n lineObject.remove()\n if(selectedGroup.layers.length == 0){\n selectedGroup.remove()\n }\n }\n}\n\nfunction updateSpacing(sourceObjectID, childObjectID, direction){\n let sourceObject = document.getLayerWithID(sourceObjectID)\n let childObject = document.getLayerWithID(childObjectID)\n\n if(Settings.settingForKey(\"arrowSpacing\")){\n let currentSpacing = Settings.settingForKey(\"arrowSpacing\")\n \n if(direction == \"Right\"){\n if(currentSpacing == \"30px\"){childObject.frame.x = sourceObject.frame.x + sourceObject.frame.width + 30}\n if(currentSpacing == \"70px\"){childObject.frame.x = sourceObject.frame.x + sourceObject.frame.width + 70}\n }\n \n if(direction == \"Down\"){\n if(currentSpacing == \"30px\"){childObject.frame.y = sourceObject.frame.y + sourceObject.frame.height + 30}\n if(currentSpacing == \"70px\"){childObject.frame.y = sourceObject.frame.y + sourceObject.frame.height + 70}\n }\n \n if(direction == \"Left\"){\n if(currentSpacing == \"30px\"){childObject.frame.x = sourceObject.frame.x - childObject.frame.width - 30}\n if(currentSpacing == \"70px\"){childObject.frame.x = sourceObject.frame.x - childObject.frame.width - 70}\n }\n \n if(direction == \"Up\"){\n if(currentSpacing == \"30px\"){childObject.frame.y = sourceObject.frame.y - childObject.frame.height - 30}\n if(currentSpacing == \"70px\"){childObject.frame.y = sourceObject.frame.y - childObject.frame.height - 70}\n }\n }\n}\n\nfunction autoAlignLayer(sourceObjectID, childObjectID, direction){\n let sourceObject = document.getLayerWithID(sourceObjectID)\n let childObject = document.getLayerWithID(childObjectID)\n let sourceMidY, childMidY, sourceMidX, childMidX, diff\n\n if(Settings.settingForKey(\"autoAlign\")){\n if(Settings.settingForKey(\"autoAlign\") == true){\n // If user turned on Auto-Align settings\n \n if(direction == \"Right\" || direction == \"Left\"){\n sourceMidY = sourceObject.frame.y + sourceObject.frame.height/2\n childMidY = childObject.frame.y + childObject.frame.height/2\n diff = sourceMidY - childMidY\n if(diff > -6 && diff < 6){childObject.frame.y = childObject.frame.y + diff}\n }\n \n if(direction == \"Down\" || direction == \"Up\"){\n sourceMidX = sourceObject.frame.x + sourceObject.frame.width/2\n childMidX = childObject.frame.x + childObject.frame.width/2\n diff = sourceMidX - childMidX\n if(diff > -6 && diff < 6){childObject.frame.x = childObject.frame.x + diff}\n }\n }\n }\n}\n\nfunction defineSourceObject(firstObjectID, secondObjectID, direction){\n let firstObject = document.getLayerWithID(firstObjectID)\n let secondObject = document.getLayerWithID(secondObjectID)\n let sourceObjectID\n\n if(direction == \"Auto\"){\n sourceObjectID = firstObject.id\n }\n\n if(direction == \"Right\"){\n if(firstObject.frame.x <= secondObject.frame.x){\n sourceObjectID = firstObject.id\n } else {\n sourceObjectID = secondObject.id\n }\n }\n\n if(direction == \"Down\"){\n if(firstObject.frame.y <= secondObject.frame.y){\n sourceObjectID = firstObject.id\n } else {\n sourceObjectID = secondObject.id\n }\n }\n\n if(direction == \"Left\"){\n if(firstObject.frame.x <= secondObject.frame.x){\n sourceObjectID = secondObject.id\n } else {\n sourceObjectID = firstObject.id\n }\n }\n\n if(direction == \"Up\"){\n if(firstObject.frame.y <= secondObject.frame.y){\n sourceObjectID = secondObject.id\n } else {\n sourceObjectID = firstObject.id\n }\n }\n\n return sourceObjectID\n}\n\nfunction getSourceObjectFromSelection(selection){\n let sourceObjectID = selection.firstObject().objectID()\n \n if(arrowDirectionSetting != \"Auto\"){\n for(let g = 0; g < selection.count(); g++) {\n sourceObjectID = defineSourceObject(sourceObjectID, selection[g].objectID(), arrowDirectionSetting)\n }\n } else {\n sourceObjectID = defineSourceObject(sourceObjectID, selection[0].objectID(), arrowDirectionSetting)\n }\n \n return sourceObjectID\n}\n\nfunction confirmationAlert(alert, message) {\n // Title\n alert.setMessageText(\"Would you like to delete all the arrows from \"+message)\n\n // Creating dialog buttons\n alert.addButtonWithTitle(\"Delete Arrows\")\n alert.addButtonWithTitle(\"Cancel\")\n \n // Creating the view\n const viewWidth = 300\n const viewHeight = 40\n \n let view = NSView.alloc().initWithFrame(NSMakeRect(0, 0, viewWidth, viewHeight))\n alert.addAccessoryView(view)\n \n // Label\n var infoLabel = NSTextField.alloc().initWithFrame(NSMakeRect(-1, viewHeight - 40, 330, 40))\n \n infoLabel.setStringValue(\"ℹī¸ You can select layers, artboards to delete all the arrows from selected one only\")\n infoLabel.setSelectable(false)\n infoLabel.setDrawsBackground(false)\n infoLabel.setBezeled(false)\n \n view.addSubview(infoLabel)\n\n return alert\n}\n\nfunction alertSetup(alert, viewWidth, viewHeight){\n // Title\n alert.setMessageText(\"Arrow Plugin Settings\")\n \n // Creating dialog buttons\n alert.addButtonWithTitle(\"Update Settings\")\n alert.addButtonWithTitle(\"Cancel\")\n \n return alert\n}\n\nfunction alertLabel(message, state, x, y, width, height){\n let infoLabel = NSTextField.alloc().initWithFrame(NSMakeRect(x, y, width, height))\n\n infoLabel.setStringValue(message)\n infoLabel.setSelectable(false)\n infoLabel.setDrawsBackground(false)\n infoLabel.setBezeled(false)\n\n if(state == false){\n infoLabel.textColor = NSColor.disabledControlTextColor()\n }\n\n return infoLabel\n}\n\nfunction alertCheckbox(message, state, x, y, width, height){\n let checkbox = NSButton.alloc().initWithFrame(NSMakeRect(x, y, width, height))\n\n checkbox.setButtonType(NSSwitchButton)\n checkbox.setBezelStyle(0)\n checkbox.setTitle(message)\n if(Settings.settingForKey(\"autoAlign\")){\n let currentState = Settings.settingForKey(\"autoAlign\") \n checkbox.setState(currentState)\n } else {\n checkbox.setState(state)\n }\n\n return checkbox\n}\n\n// {\n// \"script\": \"./script.js\",\n// \"name\" : \"onLayersMoved\",\n// \"handlers\" : {\n// \"actions\": {\n// \"LayersMoved.finish\": \"onLayersMoved\"\n// }\n// },\n// \"identifier\" : \"onLayersMoved\"\n// }\n\n\n\n","module.exports = require(\"sketch\");","module.exports = require(\"sketch/dom\");","module.exports = require(\"sketch/settings\");","module.exports = require(\"sketch/ui\");"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://exports/webpack/bootstrap","webpack://exports/./src/script.js","webpack://exports/external \"sketch\"","webpack://exports/external \"sketch/dom\"","webpack://exports/external \"sketch/settings\"","webpack://exports/external \"sketch/ui\""],"names":["UI","require","SharedStyle","pluginKey","document","sketch","fromNative","context","docData","documentData","pluginData","command","valueForKey_onLayer_forPluginIdentifier","currentParentGroup","currentPage","currentArtboard","newConnectionsData","getConnectionsData","Settings","arrowDirectionSetting","settingForKey","selection","count","sourceObjectID","getSourceObjectFromSelection","currentConnectionsData","g","objectID","connectionIndex","findConnectionData","updateArrow","firstObject","secondObject","line","message","createArrow","setValue_forKey_onLayer_forPluginIdentifier","updateSelectedArrows","updateArtboardArrows","connections","firstObjectArtboard","secondObjectArtboard","length","updateArrowsCounter","i","getLayerWithID","sketchObject","parentArtboard","class","direction","push","updateAllArrows","deleteAllArrows","deleteLine","deleteArtboardArrows","deleteConnectionFromData","deleteSelectedArrows","settings","alert","COSAlertWindow","new","viewWidth","viewHeight","alertSetup","view","NSView","alloc","initWithFrame","NSMakeRect","addAccessoryView","arrowDirectionLabel","alertLabel","addSubview","arrowDirectionField","NSPopUpButton","setActiveDirectionSetting","arrowDirectionInfoLabel","arrowSpacingLabel","arrowSpacingField","setActiveSpacingSetting","arrowSpacingInfoLabel","arrowStyleLabel","arrowStylingField","setActiveStyleSetting","arrowStyleInfoLabel","otherSettingsLabel","checkbox","alertCheckbox","autoAlignInfoLabel","pluginInfoLabel","modalResponse","runModal","NSAlertFirstButtonReturn","setSettingForKey","views","subviews","title","state","onLayersMoved","action","actionContext","panel","ControlBar","NSPanel","init","setStyleMask","NSTitledWindowMask","NSFullSizeContentViewWindowMask","setTitleVisibility","NSWindowTitleHidden","setTitlebarAppearsTransparent","setFrame_display","setMovableByWindowBackground","setHasShadow","setLevel","NSFloatingWindowLevel","center","makeKeyAndOrderFront","nil","firstObjectID","secondObjectID","lineID","localDirection","getDirection","updateSpacing","autoAlignLayer","currentGroup","checkForArrowGroup","drawLine","addToArrowsGroup","connection","layers","name","refactorLines","firstObjectMidX","frame","x","width","firstObjectMidY","y","height","secondObjectMidX","secondObjectMidY","diffX","diffY","absDiffX","Math","abs","absDiffY","firstLayerPosX","firstLayerPosY","secondLayerPosX","secondLayerPosY","middlePosX","middlePosY","path","NSBezierPath","bezierPath","moveToPoint","NSMakePoint","lineToPoint","MSShapeGroup","layerWithPath","MSPath","pathWithBezierPath","points","cornerRadius","setName","style","getLayerStyles","border","addStylePartOfType","color","MSColor","colorWithRGBADictionary","r","b","a","thickness","endMarkerType","sharedStyle","addLayers","fixGeometryWithOptions","Group","group","parent","locked","moveToBack","dataArray","pluginDataConnections","data","arrayNumber","String","currentDirection","addItemWithTitle","lastItem","setState","currentSpacing","docSettings","styles","newConnections","lineObject","selectedGroup","remove","childObjectID","sourceObject","childObject","sourceMidY","childMidY","sourceMidX","childMidX","diff","defineSourceObject","id","confirmationAlert","setMessageText","addButtonWithTitle","infoLabel","NSTextField","setStringValue","setSelectable","setDrawsBackground","setBezeled","textColor","NSColor","disabledControlTextColor","NSButton","setButtonType","NSSwitchButton","setBezelStyle","setTitle","currentState","allStyles","allLayerStyles","keyword","includes"],"mappings":";;;;;;AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,kDAA0C,gCAAgC;AAC1E;AACA;;AAEA;AACA;AACA;AACA,gEAAwD,kBAAkB;AAC1E;AACA,yDAAiD,cAAc;AAC/D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iDAAyC,iCAAiC;AAC1E,wHAAgH,mBAAmB,EAAE;AACrI;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;;AAGA;AACA;;;;;;;;;;;;;AClFA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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kBmC,YAAlB;AACD,GAHD,MAGO;AACLjJ,YAAQ,CAAC8G,QAAT,CAAkBnG,KAAlB;AACD;;AAED,SAAOX,QAAP;AACD;;AAED,SAASmF,cAAT,CAAwBrC,IAAxB,EAA8B;AAC5B,MAAIoG,SAAS,GAAGhO,OAAO,CAACiO,cAAR,EAAhB;AACA,MAAIC,OAAO,GAAG,QAAd;AACA,MAAInC,MAAM,GAAG,EAAb;;AACA,MAAGnE,IAAI,IAAI,IAAX,EAAiB;AACf,SAAI,IAAIxF,CAAC,GAAG,CAAZ,EAAeA,CAAC,GAAG4L,SAAS,CAAClN,KAAV,EAAnB,EAAsCsB,CAAC,EAAvC,EAA0C;AACxC,UAAG4L,SAAS,CAAC5L,CAAD,CAAT,CAAawF,IAAb,GAAoBuG,QAApB,CAA6BD,OAA7B,CAAH,EAAyC;AACvCnC,cAAM,CAACrJ,IAAP,CAAYsL,SAAS,CAAC5L,CAAD,CAArB;AACD;AACF;AACF,GAND,MAMO;AACL;AACA,SAAI,IAAIA,GAAC,GAAG,CAAZ,EAAeA,GAAC,GAAG4L,SAAS,CAAClN,KAAV,EAAnB,EAAsCsB,GAAC,EAAvC,EAA0C;AACxC,UAAG4L,SAAS,CAAC5L,GAAD,CAAT,CAAawF,IAAb,MAAuBA,IAA1B,EAA+B;AAC7BmE,cAAM,CAACrJ,IAAP,CAAYsL,SAAS,CAAC5L,GAAD,CAArB;AACD;AACF;AACF;;AACF,SAAO2J,MAAP;AACA,C,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,I;;;;;;;;;;;AC5kCA,mC;;;;;;;;;;;ACAA,uC;;;;;;;;;;;ACAA,4C;;;;;;;;;;;ACAA,sC","file":"script.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./src/script.js\");\n","import sketch from 'sketch'\n// const { toArray } = require('util')\n\n//\n// Variables\n//\n\nlet UI = require('sketch/ui') \nvar SharedStyle = require('sketch/dom').SharedStyle\n\nconst pluginKey = \"flowArrows\"\nconst document = sketch.fromNative(context.document)\nlet docData = context.document.documentData()\nlet pluginData = context.command.valueForKey_onLayer_forPluginIdentifier(\"arrowConnections\", docData, pluginKey) // TODO: Need to refactor\nlet currentParentGroup = docData.currentPage().currentArtboard() || docData.currentPage() // TODO: Might be a problem for multiple artboards\nlet newConnectionsData = getConnectionsData()\n\n// Settings\nvar Settings = require('sketch/settings')\nlet arrowDirectionSetting\n\nif(Settings.settingForKey(\"arrowDirection\")) {\n arrowDirectionSetting = Settings.settingForKey('arrowDirection')\n} else {\n arrowDirectionSetting = \"Auto\"\n}\n \n//\n// Default Function\n//\n\nexport default function(context) {\n\n let selection = context.selection\n\n if(selection.count() > 1){\n // Need to find source object by ID first\n let sourceObjectID = getSourceObjectFromSelection(selection)\n let currentConnectionsData = newConnectionsData\n\n for(let g = 0; g < selection.count(); g++) {\n if(selection[g].objectID() != sourceObjectID){\n // Then need to create or update connection arrow with each selection\n let connectionIndex = findConnectionData(sourceObjectID, selection[g].objectID(), currentConnectionsData)\n if(connectionIndex != null){\n // Because this is creating flow, we need to take the direction from user settings\n updateArrow(currentConnectionsData[connectionIndex].firstObject, currentConnectionsData[connectionIndex].secondObject, arrowDirectionSetting, currentConnectionsData[connectionIndex].line, connectionIndex)\n sketch.UI.message(\"Current connection is updated 🚀\")\n } else {\n // There is no connection with this two objects in our database\n createArrow(sourceObjectID, selection[g].objectID(), arrowDirectionSetting)\n sketch.UI.message(\"New connection is created 🚀\")\n }\n }\n }\n context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, \"arrowConnections\", docData, pluginKey)\n } else {\n // When user didn't select anything\n sketch.UI.message(\"Please select more than two layers\")\n }\n}\n\n//\n// Plugin Commands\n//\n\nexport function updateSelectedArrows(context) {\n\n let selection = context.selection\n\n if(selection.count() > 1){\n // Need to find source object by ID first\n let sourceObjectID = getSourceObjectFromSelection(selection)\n let currentConnectionsData = newConnectionsData\n\n for(let g = 0; g < selection.count(); g++) {\n if(selection[g].objectID() != sourceObjectID){\n // Then need to create or update connection arrow with each selection\n let connectionIndex = findConnectionData(sourceObjectID, selection[g].objectID(), currentConnectionsData)\n\n if(connectionIndex != null){\n updateArrow(currentConnectionsData[connectionIndex].firstObject, currentConnectionsData[connectionIndex].secondObject, arrowDirectionSetting, currentConnectionsData[connectionIndex].line, connectionIndex)\n sketch.UI.message(\"Current connection is updated 🚀\")\n } \n }\n }\n context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, \"arrowConnections\", docData, pluginKey)\n } else {\n // When user didn't select anything\n sketch.UI.message(\"Please select more than two layers\")\n }\n}\n\nexport function updateArtboardArrows(context) {\n // TODO: Need to show amount of updated arrows and deleted ones\n let selection = context.selection\n let connections = getConnectionsData()\n let firstObjectArtboard\n let secondObjectArtboard\n \n if(connections.length > 0){\n // We have connections in database\n const updateArrowsCounter = connections.length\n for (let i = 0; i < updateArrowsCounter; i ++) {\n // Need to check if the element is selected globally or from the artboard\n firstObjectArtboard = document.getLayerWithID(connections[i].firstObject)\n firstObjectArtboard = firstObjectArtboard.sketchObject.parentArtboard().objectID()\n\n secondObjectArtboard = document.getLayerWithID(connections[i].secondObject)\n secondObjectArtboard = secondObjectArtboard.sketchObject.parentArtboard().objectID()\n\n if(selection.count() == 1 && selection[0].class() == \"MSArtboardGroup\"){\n // Need to go through each connection and update arrow position for specific artboard\n \n if (firstObjectArtboard == selection[0].objectID()){\n if (secondObjectArtboard == selection[0].objectID()){\n updateArrow(connections[i].firstObject, connections[i].secondObject, connections[i].direction, connections[i].line, i)\n } else {newConnectionsData.push(connections[i])}\n } else {\n // If not just saving it\n newConnectionsData.push(connections[i])\n }\n }\n }\n context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, \"arrowConnections\", docData, pluginKey)\n sketch.UI.message(\"All arrows are updated 🚀\")\n } else {\n // We don't have any connections to update\n sketch.UI.message(\"There is nothing to update\")\n }\n}\n\nexport function updateAllArrows(context) { // TODO\n // TODO: Need to show amount of updated arrows and deleted ones\n let selection = context.selection\n let connections = getConnectionsData()\n let firstObjectArtboard\n let secondObjectArtboard\n \n if(connections.length > 0){\n // We have connections in database\n const updateArrowsCounter = connections.length\n for (let i = 0; i < updateArrowsCounter; i ++) {\n // Need to go through each connection and update arrow position without artboards\n // Need to check if current object don't have the parrent\n updateArrow(connections[i].firstObject, connections[i].secondObject, connections[i].direction, connections[i].line, i)\n }\n context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, \"arrowConnections\", docData, pluginKey)\n sketch.UI.message(\"All arrows are updated 🚀\")\n } else {\n // We don't have any connections to update\n sketch.UI.message(\"There is nothing to update\")\n }\n}\n\nexport function deleteAllArrows(context) {\n\n if(newConnectionsData.length > 0){\n // We have connections in database\n for (let i = 0; i < newConnectionsData.length; i ++) {\n // Need to go through each connection and update arrow position\n deleteLine(newConnectionsData[i].line)\n }\n context.command.setValue_forKey_onLayer_forPluginIdentifier(null, \"arrowConnections\", docData, pluginKey)\n sketch.UI.message(\"All arrows are deleted\")\n } else {\n // We don't have any connections to update\n sketch.UI.message(\"There is nothing to delete\")\n }\n}\n\nexport function deleteArtboardArrows(context) {\n let selection = context.selection\n let firstObject, secondObject\n\n // Need to delete all the arrows only from selected artboard\n if(selection.count() == 1 && selection[0].class() == \"MSArtboardGroup\"){\n let connections = getConnectionsData()\n \n if(connections.length > 0){\n // We have connections in database\n const updateArrowsCounter = connections.length\n for (let i = 0; i < updateArrowsCounter; i ++) {\n // Need to go through each connection and check if it placed on selected artboard\n firstObject = document.getLayerWithID(connections[i].firstObject)\n secondObject = document.getLayerWithID(connections[i].secondObject)\n if (firstObject.sketchObject.parentArtboard().objectID() == selection[0].objectID()){\n if (secondObject.sketchObject.parentArtboard().objectID() == selection[0].objectID()){\n deleteLine(connections[i].line)\n newConnectionsData = deleteConnectionFromData(i)\n }\n }\n }\n context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, \"arrowConnections\", docData, pluginKey)\n sketch.UI.message(\"All arrows from selected artboard are deleted\")\n } else {\n // We don't have any connections to update\n sketch.UI.message(\"There is nothing to delete\")\n }\n } else {\n sketch.UI.message(\"Please select one artboard\")\n }\n}\n\nexport function deleteSelectedArrows(context) {\n let selection = context.selection\n let firstObject, secondObject\n\n // Need to delete all the arrows only from selected artboard\n if(selection.count() == 2){\n\n for(let g = 0; g < selection.count(); g++) {\n\n if(selection[g].objectID() != selection[0].objectID()){ // It will never check 3rd connection\n let connections = getConnectionsData()\n \n let connectionIndex = findConnectionData(selection[0].objectID(), selection[g].objectID(), connections)\n \n if(connectionIndex != null){\n // We have connections in database\n deleteLine(connections[connectionIndex].line)\n newConnectionsData = deleteConnectionFromData(connectionIndex)\n const updateArrowsCounter = connections.length\n for (let i = 0; i < updateArrowsCounter; i ++) {\n // Need to go through each connection and check if it placed on selected artboard\n firstObject = document.getLayerWithID(connections[i].firstObject)\n secondObject = document.getLayerWithID(connections[i].secondObject)\n if(firstObject.sketchObject.parentArtboard().objectID() == selection[0].objectID()){\n if(secondObject.sketchObject.parentArtboard().objectID() == selection[0].objectID()){\n deleteLine(connections[i].line)\n newConnectionsData = deleteConnectionFromData(i)\n }\n }\n }\n context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, \"arrowConnections\", docData, pluginKey)\n sketch.UI.message(\"All arrows from selected layers are deleted ✌ī¸\")\n }\n }\n }\n } else {\n sketch.UI.message(\"Select two layers, please 🧐\")\n }\n}\n\nexport function settings(context) {\n let alert = COSAlertWindow.new()\n const viewWidth = 300\n const viewHeight = 430\n \n // Alert window settingsnp\n alert = alertSetup(alert, viewWidth, viewHeight)\n let view = NSView.alloc().initWithFrame(NSMakeRect(0, 0, viewWidth, viewHeight))\n alert.addAccessoryView(view)\n\n // Label: Arrow Direction\n let arrowDirectionLabel = alertLabel(\"Arrow Direction\", true, -1, viewHeight - 17, 330, 20)\n view.addSubview(arrowDirectionLabel)\n \n // Select: Arrow Direction\n let arrowDirectionField = NSPopUpButton.alloc().initWithFrame(NSMakeRect(-2, viewHeight - 40, 300, 20))\n setActiveDirectionSetting(arrowDirectionField)\n view.addSubview(arrowDirectionField)\n\n // Label: Auto Direction Info\n let arrowDirectionInfoLabel = alertLabel(\"Auto mode will draw arrow based on location of the second object\", false, -1, viewHeight-84, 300, 40)\n view.addSubview(arrowDirectionInfoLabel)\n\n // Label: Arrow Spacing\n let arrowSpacingLabel = alertLabel(\"Arrow Spacing\", true, -1, viewHeight - 120, 330, 20)\n view.addSubview(arrowSpacingLabel)\n\n // Select: Arrow Spacing\n let arrowSpacingField = NSPopUpButton.alloc().initWithFrame(NSMakeRect(-2, viewHeight - 143, 300, 20));\n setActiveSpacingSetting(arrowSpacingField)\n view.addSubview(arrowSpacingField)\n \n // Label: Auto Spacing Info\n let arrowSpacingInfoLabel = alertLabel(\"If you will select spacing, the second layer position will be moved closer\", false, -1, viewHeight-187, 300, 40)\n view.addSubview(arrowSpacingInfoLabel)\n\n\n // Label: Arrow Style\n let arrowStyleLabel = alertLabel(\"Arrow Style\", true, -1, viewHeight-240, 280, 40)\n view.addSubview(arrowStyleLabel)\n\n // Select: Arrow Style\n let arrowStylingField = NSPopUpButton.alloc().initWithFrame(NSMakeRect(-2, viewHeight - 240, 300, 20));\n setActiveStyleSetting(arrowStylingField)\n view.addSubview(arrowStylingField)\n\n // Label: Arrow Style Info\n let arrowStyleInfoLabel = alertLabel(\"Add layer style to your document that will contain $arrow name and you will be able to specify it here \", false, -1, viewHeight-280, 300, 40)\n view.addSubview(arrowStyleInfoLabel)\n\n\n // Label: Other Settings\n let otherSettingsLabel = alertLabel(\"Other Settings\", true, -1, viewHeight-340, 280, 40)\n view.addSubview(otherSettingsLabel)\n\n // Checkbox: Auto-Align\n let checkbox = alertCheckbox(\"Second layer auto-align\", false, -1, viewHeight-350, 260, 40)\n view.addSubview(checkbox)\n\n // Label: Auto-Align Info\n let autoAlignInfoLabel = alertLabel(\"Align the second layer for 5px misalignment with the first one\", false, -1, viewHeight-380, 280, 40)\n view.addSubview(autoAlignInfoLabel)\n\n // Label: Plugin Info\n let pluginInfoLabel = alertLabel(\"Made by @faridSabitov with the support of EPAM.com ❤ī¸\", true, -1, viewHeight-430, 280, 40)\n view.addSubview(pluginInfoLabel)\n\n\n // Need to check if style is still available\n\n // Show modal and get the results\n let modalResponse = alert.runModal()\n\n if(modalResponse == NSAlertFirstButtonReturn){\n // When user clicks on \"Update Settings\"\n // Need to save all this results into the Plugin Settings\n Settings.setSettingForKey(\"arrowDirection\", alert.views()[0].subviews()[1].title())\n Settings.setSettingForKey(\"arrowSpacing\", alert.views()[0].subviews()[4].title())\n context.command.setValue_forKey_onLayer_forPluginIdentifier(alert.views()[0].subviews()[7].title(), \"arrowStyle\", docData, pluginKey)\n Settings.setSettingForKey(\"autoAlign\", alert.views()[0].subviews()[10].state())\n UI.message(\"Settings are updated 🚀\")\n }\n}\n\nexport function onLayersMoved(context) {\n sketch.UI.message(\"Please select more than two layers\")\n const action = context.actionContext \n}\n\nexport function panel(context) {\n let ControlBar\n ControlBar = NSPanel.alloc().init();\n ControlBar.setStyleMask(NSTitledWindowMask + NSFullSizeContentViewWindowMask);\n // ControlBar.setBackgroundColor(NSColor.colorWithRed_green_blue_alpha(0.99, 0.99, 0.99, 1));\n ControlBar.setTitleVisibility(NSWindowTitleHidden);\n ControlBar.setTitlebarAppearsTransparent(true);\n ControlBar.setFrame_display(NSMakeRect(0, 0, 720, 50), false);\n ControlBar.setMovableByWindowBackground(true);\n ControlBar.setHasShadow(true);\n ControlBar.setLevel(NSFloatingWindowLevel);\n\n // contentView.addSubview(closeButton)\n ControlBar.center();\n ControlBar.makeKeyAndOrderFront(nil);\n\n// getImage = function(size, name){\n// var isRetinaDisplay = (NSScreen.mainScreen().backingScaleFactor() > 1)? true: false;\n// suffix = (isRetinaDisplay)? \"@2x\": \"\",\n// imageURL = NSURL.fileURLWithPath(self.pluginResources + \"/icons/\" + name + suffix + \".png\"),\n// image = NSImage.alloc().initWithContentsOfURL(imageURL);\n// return image\n// },\n// addButton = function(rect, name, callAction){\n// var button = NSButton.alloc().initWithFrame(rect),\n// image = getImage(rect.size, name);\n\n// button.setImage(image);\n// button.setBordered(false);\n// button.sizeToFit();\n// button.setButtonType(NSMomentaryChangeButton);\n// button.setCOSJSTargetFunction(callAction);\n// button.setAction(\"callAction:\");\n// return button;\n// },\n// addImage = function(rect, name){\n// var view = NSImageView.alloc().initWithFrame(rect),\n// image = getImage(rect.size, name);\n// view.setImage(image);\n// return view;\n// },\n\n// closeButton = addButton( NSMakeRect(20, 10, 30, 30), \"close-control\",\n// function(sender){\n// coscript.setShouldKeepAround(false);\n// threadDictionary.removeObjectForKey(identifier);\n// ControlBar.close();\n// }),\n\n\n\n}\n\n//\n// Functions\n//\n\nfunction updateArrow(firstObjectID, secondObjectID, direction, lineID, connectionIndex) {\n // There might be a situation, when user deleted current group or current group stays on another artboard => In that case need to create another group\n\n // Need to check if we have the layers with such IDs\n let firstObject = document.getLayerWithID(firstObjectID)\n let secondObject = document.getLayerWithID(secondObjectID)\n\n // Need to delete data first, because we will have a new line\n deleteLine(lineID)\n newConnectionsData = deleteConnectionFromData(connectionIndex)\n\n if(firstObject && secondObject){\n // If we have all the objects, we can recreate the line\n createArrow(firstObjectID, secondObjectID, direction)\n } \n}\n\nfunction createArrow(firstObjectID, secondObjectID, direction) {\n // Process of creating new connection\n let localDirection\n \n if(direction == \"Auto\"){\n // If direction is auto, we need to specify direction ourselves\n localDirection = getDirection(firstObjectID, secondObjectID)\n } else {\n localDirection = direction\n }\n \n updateSpacing(firstObjectID, secondObjectID, localDirection)\n autoAlignLayer(firstObjectID, secondObjectID, localDirection)\n let currentGroup = checkForArrowGroup()\n let line = drawLine(firstObjectID, secondObjectID, localDirection, currentGroup)\n addToArrowsGroup(line, currentGroup)\n\n // Storage for current connection\n let connection = {\n firstObject : firstObjectID,\n secondObject : secondObjectID,\n direction: localDirection,\n line : line.objectID()\n }\n // Need to save this data to the global array\n newConnectionsData.push(connection)\n}\n\nfunction checkForArrowGroup() {\n let currentGroup = null\n // Checking all the groups that we have\n for(let i = 0; i < currentParentGroup.layers().count(); i++){\n if(currentParentGroup.layers()[i].name() == \"Arrows\") {\n // If we already have \"Arrow\" group we need to save it's folder\n currentGroup = currentParentGroup.layers()[i]\n refactorLines(currentGroup)\n } \n }\n return currentGroup\n}\n\nfunction getDirection(firstObjectID, secondObjectID){\n // Get direction from the source object\n const firstObject = document.getLayerWithID(firstObjectID)\n const secondObject = document.getLayerWithID(secondObjectID)\n const firstObjectMidX = firstObject.frame.x+firstObject.frame.width/2\n const firstObjectMidY = firstObject.frame.y+firstObject.frame.height/2\n const secondObjectMidX = secondObject.frame.x+secondObject.frame.width/2\n const secondObjectMidY = secondObject.frame.y+secondObject.frame.height/2\n\n const diffX = firstObjectMidX - secondObjectMidX\n const diffY = firstObjectMidY - secondObjectMidY\n const absDiffX = Math.abs(diffX) \n const absDiffY = Math.abs(diffY)\n let direction\n\n if(secondObjectMidX > firstObjectMidX){\n // Right Half\n if(secondObjectMidY > firstObjectMidY){\n // Bottom quarter\n if(diffX > diffY) {\n direction = \"Down\"\n } else {\n direction = \"Right\"\n }\n } else {\n // Top quarter\n if(absDiffX > absDiffY) {\n direction = \"Right\"\n } else {\n direction = \"Up\"\n }\n }\n } else {\n // Left Half\n if(secondObjectMidY > firstObjectMidY){\n // Bottom quarter\n if(absDiffX > absDiffY) {\n direction = \"Left\"\n } else {\n direction = \"Down\"\n }\n } else {\n // Top quarter\n if(diffX > diffY) {\n direction = \"Left\"\n } else {\n direction = \"Up\"\n }\n }\n }\n return direction\n}\n\nfunction drawLine(firstObjectID, secondObjectID, direction, currentGroup){\n let firstLayerPosX, firstLayerPosY, secondLayerPosX, secondLayerPosY, middlePosX, middlePosY, diffX, diffY\n let firstObject = document.getLayerWithID(firstObjectID)\n let secondObject = document.getLayerWithID(secondObjectID)\n\n \n if(currentGroup){\n //if we already have a group, need to specify the difference\n diffX = currentGroup.frame().x()\n diffY = currentGroup.frame().y()\n } else {\n diffX = 0\n diffY = 0\n }\n\n // Drawing a line\n let path = NSBezierPath.bezierPath()\n\n \n \n // Based on direction, we need to specify connection points\n if(direction == \"Up\"){\n // First Layer Position Start Point Position\n firstLayerPosX = firstObject.frame.x+firstObject.frame.width/2-diffX\n firstLayerPosY = firstObject.frame.y-diffY\n\n // Second Layer Position End Point Position\n secondLayerPosX = secondObject.frame.x+secondObject.frame.width/2-diffX\n secondLayerPosY = secondObject.frame.y+secondObject.frame.height-diffY\n\n // Middle Points\n middlePosX = (firstLayerPosX + secondLayerPosX)/2\n middlePosY = (firstLayerPosY + secondLayerPosY)/2\n\n // Connecting points\n path.moveToPoint(NSMakePoint(firstLayerPosX,firstLayerPosY))\n path.lineToPoint(NSMakePoint(firstLayerPosX,middlePosY))\n path.lineToPoint(NSMakePoint(secondLayerPosX,middlePosY))\n path.lineToPoint(NSMakePoint(secondLayerPosX,secondLayerPosY))\n }\n\n if(direction == \"Right\"){\n // First Layer Position Start Point Position\n firstLayerPosX = firstObject.frame.x+firstObject.frame.width-diffX\n firstLayerPosY = firstObject.frame.y+firstObject.frame.height/2-diffY\n\n // Second Layer Position End Point Position\n secondLayerPosX = secondObject.frame.x-diffX\n secondLayerPosY = secondObject.frame.y+secondObject.frame.height/2-diffY\n \n // Middle Points\n middlePosX = (firstLayerPosX + secondLayerPosX)/2\n middlePosY = (firstLayerPosY + secondLayerPosY)/2\n\n // Connecting points\n path.moveToPoint(NSMakePoint(firstLayerPosX,firstLayerPosY))\n path.lineToPoint(NSMakePoint(middlePosX,firstLayerPosY))\n path.lineToPoint(NSMakePoint(middlePosX,secondLayerPosY))\n path.lineToPoint(NSMakePoint(secondLayerPosX,secondLayerPosY))\n }\n\n if(direction == \"Down\"){\n // First Layer Position Start Point Position\n firstLayerPosX = firstObject.frame.x+firstObject.frame.width/2-diffX\n firstLayerPosY = firstObject.frame.y+firstObject.frame.height-diffY\n\n // Second Layer Position End Point Position\n secondLayerPosX = secondObject.frame.x+secondObject.frame.width/2-diffX\n secondLayerPosY = secondObject.frame.y-diffY\n\n // Middle Points\n middlePosX = (firstLayerPosX + secondLayerPosX)/2\n middlePosY = (firstLayerPosY + secondLayerPosY)/2\n \n // Connecting points\n path.moveToPoint(NSMakePoint(firstLayerPosX,firstLayerPosY))\n path.lineToPoint(NSMakePoint(firstLayerPosX,middlePosY))\n path.lineToPoint(NSMakePoint(secondLayerPosX,middlePosY))\n path.lineToPoint(NSMakePoint(secondLayerPosX,secondLayerPosY))\n }\n\n if(direction == \"Left\"){\n // First Layer Position Start Point Position\n firstLayerPosX = firstObject.frame.x-diffX\n firstLayerPosY = firstObject.frame.y+firstObject.frame.height/2-diffY\n\n // Second Layer Position End Point Position\n secondLayerPosX = secondObject.frame.x+secondObject.frame.width-diffX\n secondLayerPosY = secondObject.frame.y+secondObject.frame.height/2-diffY\n\n // Middle Points\n middlePosX = (firstLayerPosX + secondLayerPosX)/2\n middlePosY = (firstLayerPosY + secondLayerPosY)/2\n\n // Connecting points\n path.moveToPoint(NSMakePoint(firstLayerPosX,firstLayerPosY))\n path.lineToPoint(NSMakePoint(middlePosX,firstLayerPosY))\n path.lineToPoint(NSMakePoint(middlePosX,secondLayerPosY))\n path.lineToPoint(NSMakePoint(secondLayerPosX,secondLayerPosY))\n }\n\n //TODO: Provide a separate file with all the stylings\n\n // Painting the line\n let line = MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(path))\n\n\n // Making middle points rounded\n let points = line.layers().firstObject().points()\n points[1].cornerRadius = 20\n points[2].cornerRadius = 20\n\n // Providing Settings for the arrow\n line.setName(\"Arrow\")\n\n if(context.command.valueForKey_onLayer_forPluginIdentifier(\"arrowStyle\", docData, pluginKey)){\n // if we have specified options\n let style = getLayerStyles(context.command.valueForKey_onLayer_forPluginIdentifier(\"arrowStyle\", docData, pluginKey))\n if(style[0] == null){ \n // Default Arrow Style\n let border = line.style().addStylePartOfType(1)\n border.color = MSColor.colorWithRGBADictionary({r: 0.89, g: 0.89, b: 0.89, a: 1})\n border.thickness = 2\n line.style().endMarkerType = 2\n } else {\n line.sharedStyle = style[0]\n }\n } else {\n // Default Arrow Style\n let border = line.style().addStylePartOfType(1)\n border.color = MSColor.colorWithRGBADictionary({r: 0.89, g: 0.89, b: 0.89, a: 1})\n border.thickness = 2\n line.style().endMarkerType = 2\n }\n\n return line\n}\n\nfunction addToArrowsGroup(line, currentGroup){\n if(currentGroup){\n currentGroup.addLayers([line])\n currentGroup.fixGeometryWithOptions(1)\n } else {\n // If we don't have a group\n let Group = require('sketch/dom').Group\n let group = new Group({\n parent: currentParentGroup,\n name: 'Arrows',\n locked: true,\n layers: [line]\n })\n // Moving this group to the bottom of the page\n group.moveToBack()\n currentGroup = checkForArrowGroup()\n currentGroup.fixGeometryWithOptions(1)\n }\n\n \n \n}\n\nfunction getConnectionsData(){\n let dataArray = []\n let pluginDataConnections = []\n if(pluginData){\n pluginDataConnections = context.command.valueForKey_onLayer_forPluginIdentifier(\"arrowConnections\", docData, pluginKey)\n \n for (let i = 0; i < pluginDataConnections.length; i ++) {\n dataArray.push(pluginDataConnections[i])\n }\n } \n return dataArray\n}\n\nfunction findConnectionData(firstObjectID, secondObjectID, data){\n let arrayNumber = null\n firstObjectID = String(firstObjectID)\n secondObjectID = String(secondObjectID)\n\n if(pluginData){\n // If we have database, need to check for connections\n\n for(let y = 0; y < data.length; y++){\n\n if(firstObjectID == data[y].firstObject || firstObjectID == data[y].secondObject){\n // if we found that we have this object in connection database already\n if(secondObjectID == data[y].firstObject || secondObjectID == data[y].secondObject){\n // if we found that we have this object in connection database already\n arrayNumber = y\n } \n }\n }\n }\n return arrayNumber\n}\n\nfunction setActiveDirectionSetting(arrowDirectionField){\n let currentDirection = \"Auto\"\n\n if(Settings.settingForKey(\"arrowDirection\")){\n // if there is data in settings\n currentDirection = Settings.settingForKey(\"arrowDirection\") \n \n if(currentDirection == \"Auto\"){\n arrowDirectionField.addItemWithTitle(\"Auto\")\n arrowDirectionField.lastItem().setState(1)\n arrowDirectionField.addItemWithTitle(\"Right\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Down\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Left\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Up\")\n arrowDirectionField.lastItem().setState(0)\n } \n \n if(currentDirection == \"Right\"){\n arrowDirectionField.addItemWithTitle(\"Right\")\n arrowDirectionField.lastItem().setState(1)\n arrowDirectionField.addItemWithTitle(\"Down\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Left\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Up\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Auto\")\n arrowDirectionField.lastItem().setState(0)\n } \n\n if(currentDirection == \"Down\"){\n arrowDirectionField.addItemWithTitle(\"Down\")\n arrowDirectionField.lastItem().setState(1)\n arrowDirectionField.addItemWithTitle(\"Left\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Up\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Auto\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Right\")\n arrowDirectionField.lastItem().setState(0)\n } \n\n if(currentDirection == \"Left\"){\n arrowDirectionField.addItemWithTitle(\"Left\")\n arrowDirectionField.lastItem().setState(1)\n arrowDirectionField.addItemWithTitle(\"Up\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Auto\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Right\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Down\")\n arrowDirectionField.lastItem().setState(0)\n } \n\n if(currentDirection == \"Up\"){\n arrowDirectionField.addItemWithTitle(\"Up\")\n arrowDirectionField.lastItem().setState(1)\n arrowDirectionField.addItemWithTitle(\"Auto\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Right\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Down\")\n arrowDirectionField.lastItem().setState(0)\n arrowDirectionField.addItemWithTitle(\"Left\")\n arrowDirectionField.lastItem().setState(0)\n } \n\n } else {\n // Show default\n arrowDirectionField.addItemWithTitle(\"Auto\")\n arrowDirectionField.addItemWithTitle(\"Right\")\n arrowDirectionField.addItemWithTitle(\"Down\")\n arrowDirectionField.addItemWithTitle(\"Left\")\n arrowDirectionField.addItemWithTitle(\"Up\")\n }\n}\n\nfunction setActiveSpacingSetting(arrowSpacingField){\n let currentSpacing = \"Not selected\"\n\n if(Settings.settingForKey(\"arrowSpacing\")){\n // if there is data in settings\n currentSpacing = Settings.settingForKey(\"arrowSpacing\") \n \n if(currentSpacing == \"Not selected\"){\n arrowSpacingField.addItemWithTitle(\"Not selected\")\n arrowSpacingField.lastItem().setState(1)\n arrowSpacingField.addItemWithTitle(\"30px\")\n arrowSpacingField.lastItem().setState(0)\n arrowSpacingField.addItemWithTitle(\"70px\")\n arrowSpacingField.lastItem().setState(0)\n } \n \n if(currentSpacing == \"30px\"){\n arrowSpacingField.addItemWithTitle(\"30px\")\n arrowSpacingField.lastItem().setState(1)\n arrowSpacingField.addItemWithTitle(\"70px\")\n arrowSpacingField.lastItem().setState(0)\n arrowSpacingField.addItemWithTitle(\"Not selected\")\n arrowSpacingField.lastItem().setState(0)\n } \n\n if(currentSpacing == \"70px\"){\n arrowSpacingField.addItemWithTitle(\"70px\")\n arrowSpacingField.lastItem().setState(1)\n arrowSpacingField.addItemWithTitle(\"Not selected\")\n arrowSpacingField.lastItem().setState(0)\n arrowSpacingField.addItemWithTitle(\"30px\")\n arrowSpacingField.lastItem().setState(0)\n } \n } else {\n // Show default\n arrowSpacingField.addItemWithTitle(\"Not Selected\")\n arrowSpacingField.addItemWithTitle(\"30px\")\n arrowSpacingField.addItemWithTitle(\"70px\")\n }\n}\n\nfunction setActiveStyleSetting(arrowStylingField){\n let docSettings = context.command.valueForKey_onLayer_forPluginIdentifier(\"arrowStyle\", docData, pluginKey)\n let styles = getLayerStyles(null)\n\n if(docSettings){\n // We have info about the settings in the current document\n \n if(docSettings != \"Default Style\") {\n // if user specified own option\n arrowStylingField.addItemWithTitle(docSettings)\n arrowStylingField.addItemWithTitle(\"Default Style\")\n for(let i = 0; i < styles.length; i++){\n if(styles[i].name() != docSettings){\n arrowStylingField.addItemWithTitle(styles[i].name())\n }\n }\n\n } else {\n // Need to show the default first\n arrowStylingField.addItemWithTitle(\"Default Style\")\n for(let i = 0; i < styles.length; i++){\n arrowStylingField.addItemWithTitle(styles[i].name())\n }\n }\n } else {\n arrowStylingField.addItemWithTitle(\"Default Style\")\n for(let i = 0; i < styles.length; i++){\n arrowStylingField.addItemWithTitle(styles[i].name())\n }\n }\n}\n\nfunction deleteConnectionFromData(arrayNumber){\n let newConnections = []\n if(pluginData){\n // If we have database\n let connections = context.command.valueForKey_onLayer_forPluginIdentifier(\"arrowConnections\", docData, pluginKey)\n\n for (let i = 0; i < connections.length; i ++) {\n // Updating all connections without deleted one\n if(i != arrayNumber){\n newConnections.push(connections[i])\n }\n }\n }\n return newConnections\n}\n\nfunction refactorLines(group){ // Need to finish\n for(let i = 0; i < group.layers().length; i++){\n // Here we need to go through each data in our database and delete line if there is no data\n }\n}\n\nfunction deleteLine(lineID){\n const lineObject = document.getLayerWithID(lineID)\n let selectedGroup\n\n if(lineObject){\n selectedGroup = lineObject.parent\n lineObject.remove()\n if(selectedGroup.layers.length == 0){\n selectedGroup.remove()\n }\n }\n}\n\nfunction updateSpacing(sourceObjectID, childObjectID, direction){\n let sourceObject = document.getLayerWithID(sourceObjectID)\n let childObject = document.getLayerWithID(childObjectID)\n\n if(Settings.settingForKey(\"arrowSpacing\")){\n let currentSpacing = Settings.settingForKey(\"arrowSpacing\")\n \n if(direction == \"Right\"){\n if(currentSpacing == \"30px\"){childObject.frame.x = sourceObject.frame.x + sourceObject.frame.width + 30}\n if(currentSpacing == \"70px\"){childObject.frame.x = sourceObject.frame.x + sourceObject.frame.width + 70}\n }\n \n if(direction == \"Down\"){\n if(currentSpacing == \"30px\"){childObject.frame.y = sourceObject.frame.y + sourceObject.frame.height + 30}\n if(currentSpacing == \"70px\"){childObject.frame.y = sourceObject.frame.y + sourceObject.frame.height + 70}\n }\n \n if(direction == \"Left\"){\n if(currentSpacing == \"30px\"){childObject.frame.x = sourceObject.frame.x - childObject.frame.width - 30}\n if(currentSpacing == \"70px\"){childObject.frame.x = sourceObject.frame.x - childObject.frame.width - 70}\n }\n \n if(direction == \"Up\"){\n if(currentSpacing == \"30px\"){childObject.frame.y = sourceObject.frame.y - childObject.frame.height - 30}\n if(currentSpacing == \"70px\"){childObject.frame.y = sourceObject.frame.y - childObject.frame.height - 70}\n }\n }\n}\n\nfunction autoAlignLayer(sourceObjectID, childObjectID, direction){\n let sourceObject = document.getLayerWithID(sourceObjectID)\n let childObject = document.getLayerWithID(childObjectID)\n let sourceMidY, childMidY, sourceMidX, childMidX, diff\n\n if(Settings.settingForKey(\"autoAlign\")){\n if(Settings.settingForKey(\"autoAlign\") == true){\n // If user turned on Auto-Align settings\n \n if(direction == \"Right\" || direction == \"Left\"){\n sourceMidY = sourceObject.frame.y + sourceObject.frame.height/2\n childMidY = childObject.frame.y + childObject.frame.height/2\n diff = sourceMidY - childMidY\n if(diff > -6 && diff < 6){childObject.frame.y = childObject.frame.y + diff}\n }\n \n if(direction == \"Down\" || direction == \"Up\"){\n sourceMidX = sourceObject.frame.x + sourceObject.frame.width/2\n childMidX = childObject.frame.x + childObject.frame.width/2\n diff = sourceMidX - childMidX\n if(diff > -6 && diff < 6){childObject.frame.x = childObject.frame.x + diff}\n }\n }\n }\n}\n\nfunction defineSourceObject(firstObjectID, secondObjectID, direction){\n let firstObject = document.getLayerWithID(firstObjectID)\n let secondObject = document.getLayerWithID(secondObjectID)\n let sourceObjectID\n\n if(direction == \"Auto\"){\n sourceObjectID = firstObject.id\n }\n\n if(direction == \"Right\"){\n if(firstObject.frame.x <= secondObject.frame.x){\n sourceObjectID = firstObject.id\n } else {\n sourceObjectID = secondObject.id\n }\n }\n\n if(direction == \"Down\"){\n if(firstObject.frame.y <= secondObject.frame.y){\n sourceObjectID = firstObject.id\n } else {\n sourceObjectID = secondObject.id\n }\n }\n\n if(direction == \"Left\"){\n if(firstObject.frame.x <= secondObject.frame.x){\n sourceObjectID = secondObject.id\n } else {\n sourceObjectID = firstObject.id\n }\n }\n\n if(direction == \"Up\"){\n if(firstObject.frame.y <= secondObject.frame.y){\n sourceObjectID = secondObject.id\n } else {\n sourceObjectID = firstObject.id\n }\n }\n\n return sourceObjectID\n}\n\nfunction getSourceObjectFromSelection(selection){\n let sourceObjectID = selection.firstObject().objectID()\n \n if(arrowDirectionSetting != \"Auto\"){\n for(let g = 0; g < selection.count(); g++) {\n sourceObjectID = defineSourceObject(sourceObjectID, selection[g].objectID(), arrowDirectionSetting)\n }\n } else {\n sourceObjectID = defineSourceObject(sourceObjectID, selection[0].objectID(), arrowDirectionSetting)\n }\n \n return sourceObjectID\n}\n\nfunction confirmationAlert(alert, message) {\n // Title\n alert.setMessageText(\"Would you like to delete all the arrows from \"+message)\n\n // Creating dialog buttons\n alert.addButtonWithTitle(\"Delete Arrows\")\n alert.addButtonWithTitle(\"Cancel\")\n \n // Creating the view\n const viewWidth = 300\n const viewHeight = 40\n \n let view = NSView.alloc().initWithFrame(NSMakeRect(0, 0, viewWidth, viewHeight))\n alert.addAccessoryView(view)\n \n // Label\n var infoLabel = NSTextField.alloc().initWithFrame(NSMakeRect(-1, viewHeight - 40, 330, 40))\n \n infoLabel.setStringValue(\"ℹī¸ You can select layers, artboards to delete all the arrows from selected one only\")\n infoLabel.setSelectable(false)\n infoLabel.setDrawsBackground(false)\n infoLabel.setBezeled(false)\n \n view.addSubview(infoLabel)\n\n return alert\n}\n\nfunction alertSetup(alert, viewWidth, viewHeight){\n // Title\n alert.setMessageText(\"Arrow Plugin Settings\")\n \n // Creating dialog buttons\n alert.addButtonWithTitle(\"Update Settings\")\n alert.addButtonWithTitle(\"Cancel\")\n \n return alert\n}\n\nfunction alertLabel(message, state, x, y, width, height){\n let infoLabel = NSTextField.alloc().initWithFrame(NSMakeRect(x, y, width, height))\n\n infoLabel.setStringValue(message)\n infoLabel.setSelectable(false)\n infoLabel.setDrawsBackground(false)\n infoLabel.setBezeled(false)\n\n if(state == false){\n infoLabel.textColor = NSColor.disabledControlTextColor()\n }\n\n return infoLabel\n}\n\nfunction alertCheckbox(message, state, x, y, width, height){\n let checkbox = NSButton.alloc().initWithFrame(NSMakeRect(x, y, width, height))\n\n checkbox.setButtonType(NSSwitchButton)\n checkbox.setBezelStyle(0)\n checkbox.setTitle(message)\n if(Settings.settingForKey(\"autoAlign\")){\n let currentState = Settings.settingForKey(\"autoAlign\") \n checkbox.setState(currentState)\n } else {\n checkbox.setState(state)\n }\n\n return checkbox\n}\n\nfunction getLayerStyles(name) {\n let allStyles = docData.allLayerStyles()\n let keyword = \"$arrow\"\n let styles = []\n if(name == null) {\n for(let i = 0; i < allStyles.count(); i++){\n if(allStyles[i].name().includes(keyword)){\n styles.push(allStyles[i]);\n }\n }\n } else {\n // Searching only for name\n for(let i = 0; i < allStyles.count(); i++){\n if(allStyles[i].name() == name){\n styles.push(allStyles[i]);\n }\n }\n }\n\treturn styles\n}\n\n// {\n// \"script\": \"./script.js\",\n// \"name\" : \"onLayersMoved\",\n// \"handlers\" : {\n// \"actions\": {\n// \"LayersMoved.finish\": \"onLayersMoved\"\n// }\n// },\n// \"identifier\" : \"onLayersMoved\"\n// }\n\n\n\n","module.exports = require(\"sketch\");","module.exports = require(\"sketch/dom\");","module.exports = require(\"sketch/settings\");","module.exports = require(\"sketch/ui\");"],"sourceRoot":""} \ No newline at end of file diff --git a/src/manifest.json b/src/manifest.json index 8e2e560..d6e375f 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,7 +2,7 @@ "compatibleVersion": 3, "bundleVersion": 1, "identifier": "me.sabitov.sketch.connectionFlowArrows", - "version": "2.5.6", + "version": "2.6.0", "icon": "icon.png", "authorEmail": "farid.sabitov.design@gmail.com", "appcast": "https://raw.githubusercontent.com/faridsabitov/Sketch-Connection-Flow-Arrows/master/.appcast.xml", diff --git a/src/script.js b/src/script.js index 63ee329..212098e 100644 --- a/src/script.js +++ b/src/script.js @@ -6,6 +6,8 @@ import sketch from 'sketch' // let UI = require('sketch/ui') +var SharedStyle = require('sketch/dom').SharedStyle + const pluginKey = "flowArrows" const document = sketch.fromNative(context.document) let docData = context.document.documentData() @@ -23,7 +25,6 @@ if(Settings.settingForKey("arrowDirection")) { arrowDirectionSetting = "Auto" } - // // Default Function // @@ -41,7 +42,6 @@ export default function(context) { if(selection[g].objectID() != sourceObjectID){ // Then need to create or update connection arrow with each selection let connectionIndex = findConnectionData(sourceObjectID, selection[g].objectID(), currentConnectionsData) - // log("Index "+connectionIndex) if(connectionIndex != null){ // Because this is creating flow, we need to take the direction from user settings updateArrow(currentConnectionsData[connectionIndex].firstObject, currentConnectionsData[connectionIndex].secondObject, arrowDirectionSetting, currentConnectionsData[connectionIndex].line, connectionIndex) @@ -54,7 +54,6 @@ export default function(context) { } } context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, "arrowConnections", docData, pluginKey) - // log(newConnectionsData) } else { // When user didn't select anything sketch.UI.message("Please select more than two layers") @@ -86,7 +85,6 @@ export function updateSelectedArrows(context) { } } context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, "arrowConnections", docData, pluginKey) - // log(newConnectionsData) } else { // When user didn't select anything sketch.UI.message("Please select more than two layers") @@ -130,8 +128,6 @@ export function updateArtboardArrows(context) { // We don't have any connections to update sketch.UI.message("There is nothing to update") } - - // log(newConnectionsData) } export function updateAllArrows(context) { // TODO @@ -219,7 +215,6 @@ export function deleteSelectedArrows(context) { let connections = getConnectionsData() let connectionIndex = findConnectionData(selection[0].objectID(), selection[g].objectID(), connections) - // log(connectionIndex) if(connectionIndex != null){ // We have connections in database @@ -250,7 +245,7 @@ export function deleteSelectedArrows(context) { export function settings(context) { let alert = COSAlertWindow.new() const viewWidth = 300 - const viewHeight = 330 + const viewHeight = 430 // Alert window settingsnp alert = alertSetup(alert, viewWidth, viewHeight) @@ -267,7 +262,7 @@ export function settings(context) { view.addSubview(arrowDirectionField) // Label: Auto Direction Info - let arrowDirectionInfoLabel = alertLabel("Auto mode will draw arrow based on location of the second object", false, -1, viewHeight-84, 280, 40) + let arrowDirectionInfoLabel = alertLabel("Auto mode will draw arrow based on location of the second object", false, -1, viewHeight-84, 300, 40) view.addSubview(arrowDirectionInfoLabel) // Label: Arrow Spacing @@ -280,25 +275,43 @@ export function settings(context) { view.addSubview(arrowSpacingField) // Label: Auto Spacing Info - let arrowSpacingInfoLabel = alertLabel("If you will select spacing, the second layer position will be moved closer", false, -1, viewHeight-187, 280, 40) + let arrowSpacingInfoLabel = alertLabel("If you will select spacing, the second layer position will be moved closer", false, -1, viewHeight-187, 300, 40) view.addSubview(arrowSpacingInfoLabel) + + // Label: Arrow Style + let arrowStyleLabel = alertLabel("Arrow Style", true, -1, viewHeight-240, 280, 40) + view.addSubview(arrowStyleLabel) + + // Select: Arrow Style + let arrowStylingField = NSPopUpButton.alloc().initWithFrame(NSMakeRect(-2, viewHeight - 240, 300, 20)); + setActiveStyleSetting(arrowStylingField) + view.addSubview(arrowStylingField) + + // Label: Arrow Style Info + let arrowStyleInfoLabel = alertLabel("Add layer style to your document that will contain $arrow name and you will be able to specify it here ", false, -1, viewHeight-280, 300, 40) + view.addSubview(arrowStyleInfoLabel) + + // Label: Other Settings - let otherSettingsLabel = alertLabel("Other Settings", true, -1, viewHeight-240, 280, 40) + let otherSettingsLabel = alertLabel("Other Settings", true, -1, viewHeight-340, 280, 40) view.addSubview(otherSettingsLabel) // Checkbox: Auto-Align - let checkbox = alertCheckbox("Second layer auto-align", false, -1, viewHeight-250, 280, 40) + let checkbox = alertCheckbox("Second layer auto-align", false, -1, viewHeight-350, 260, 40) view.addSubview(checkbox) // Label: Auto-Align Info - let autoAlignInfoLabel = alertLabel("Align the second layer for 5px misalignment with the first one", false, -1, viewHeight-280, 280, 40) + let autoAlignInfoLabel = alertLabel("Align the second layer for 5px misalignment with the first one", false, -1, viewHeight-380, 280, 40) view.addSubview(autoAlignInfoLabel) // Label: Plugin Info - let pluginInfoLabel = alertLabel("Made by @faridSabitov with the support of EPAM.com ❤ī¸", true, -1, viewHeight-330, 280, 40) + let pluginInfoLabel = alertLabel("Made by @faridSabitov with the support of EPAM.com ❤ī¸", true, -1, viewHeight-430, 280, 40) view.addSubview(pluginInfoLabel) + + // Need to check if style is still available + // Show modal and get the results let modalResponse = alert.runModal() @@ -307,18 +320,15 @@ export function settings(context) { // Need to save all this results into the Plugin Settings Settings.setSettingForKey("arrowDirection", alert.views()[0].subviews()[1].title()) Settings.setSettingForKey("arrowSpacing", alert.views()[0].subviews()[4].title()) - Settings.setSettingForKey("autoAlign", alert.views()[0].subviews()[7].state()) + context.command.setValue_forKey_onLayer_forPluginIdentifier(alert.views()[0].subviews()[7].title(), "arrowStyle", docData, pluginKey) + Settings.setSettingForKey("autoAlign", alert.views()[0].subviews()[10].state()) UI.message("Settings are updated 🚀") } } export function onLayersMoved(context) { sketch.UI.message("Please select more than two layers") - // let a = 0 - const action = context.actionContext - // log(context.actionContext) - // log("moved") - + const action = context.actionContext } export function panel(context) { @@ -374,7 +384,6 @@ export function panel(context) { } - // // Functions // @@ -605,11 +614,25 @@ function drawLine(firstObjectID, secondObjectID, direction, currentGroup){ // Providing Settings for the arrow line.setName("Arrow") - // Styling Border Style - let border = line.style().addStylePartOfType(1) - border.color = MSColor.colorWithRGBADictionary({r: 0.89, g: 0.89, b: 0.89, a: 1}) - border.thickness = 2 - line.style().endMarkerType = 2 + if(context.command.valueForKey_onLayer_forPluginIdentifier("arrowStyle", docData, pluginKey)){ + // if we have specified options + let style = getLayerStyles(context.command.valueForKey_onLayer_forPluginIdentifier("arrowStyle", docData, pluginKey)) + if(style[0] == null){ + // Default Arrow Style + let border = line.style().addStylePartOfType(1) + border.color = MSColor.colorWithRGBADictionary({r: 0.89, g: 0.89, b: 0.89, a: 1}) + border.thickness = 2 + line.style().endMarkerType = 2 + } else { + line.sharedStyle = style[0] + } + } else { + // Default Arrow Style + let border = line.style().addStylePartOfType(1) + border.color = MSColor.colorWithRGBADictionary({r: 0.89, g: 0.89, b: 0.89, a: 1}) + border.thickness = 2 + line.style().endMarkerType = 2 + } return line } @@ -659,17 +682,12 @@ function findConnectionData(firstObjectID, secondObjectID, data){ // If we have database, need to check for connections for(let y = 0; y < data.length; y++){ - // log("First one "+firstObjectID) - // log("Current Index "+y) if(firstObjectID == data[y].firstObject || firstObjectID == data[y].secondObject){ // if we found that we have this object in connection database already - // log("We have the first one") - // log("Second one "+secondObjectID) if(secondObjectID == data[y].firstObject || secondObjectID == data[y].secondObject){ // if we found that we have this object in connection database already arrayNumber = y - // log("We have the second one as"+arrayNumber) } } } @@ -677,7 +695,7 @@ function findConnectionData(firstObjectID, secondObjectID, data){ return arrayNumber } -function setActiveDirectionSetting (arrowDirectionField){ +function setActiveDirectionSetting(arrowDirectionField){ let currentDirection = "Auto" if(Settings.settingForKey("arrowDirection")){ @@ -759,7 +777,7 @@ function setActiveDirectionSetting (arrowDirectionField){ } } -function setActiveSpacingSetting (arrowSpacingField){ +function setActiveSpacingSetting(arrowSpacingField){ let currentSpacing = "Not selected" if(Settings.settingForKey("arrowSpacing")){ @@ -800,6 +818,38 @@ function setActiveSpacingSetting (arrowSpacingField){ } } +function setActiveStyleSetting(arrowStylingField){ + let docSettings = context.command.valueForKey_onLayer_forPluginIdentifier("arrowStyle", docData, pluginKey) + let styles = getLayerStyles(null) + + if(docSettings){ + // We have info about the settings in the current document + + if(docSettings != "Default Style") { + // if user specified own option + arrowStylingField.addItemWithTitle(docSettings) + arrowStylingField.addItemWithTitle("Default Style") + for(let i = 0; i < styles.length; i++){ + if(styles[i].name() != docSettings){ + arrowStylingField.addItemWithTitle(styles[i].name()) + } + } + + } else { + // Need to show the default first + arrowStylingField.addItemWithTitle("Default Style") + for(let i = 0; i < styles.length; i++){ + arrowStylingField.addItemWithTitle(styles[i].name()) + } + } + } else { + arrowStylingField.addItemWithTitle("Default Style") + for(let i = 0; i < styles.length; i++){ + arrowStylingField.addItemWithTitle(styles[i].name()) + } + } +} + function deleteConnectionFromData(arrayNumber){ let newConnections = [] if(pluginData){ @@ -817,9 +867,7 @@ function deleteConnectionFromData(arrayNumber){ } function refactorLines(group){ // Need to finish - // log(group.layers().length) for(let i = 0; i < group.layers().length; i++){ - // log(group.layers()[i].objectID()) // Here we need to go through each data in our database and delete line if there is no data } } @@ -1020,6 +1068,27 @@ function alertCheckbox(message, state, x, y, width, height){ return checkbox } +function getLayerStyles(name) { + let allStyles = docData.allLayerStyles() + let keyword = "$arrow" + let styles = [] + if(name == null) { + for(let i = 0; i < allStyles.count(); i++){ + if(allStyles[i].name().includes(keyword)){ + styles.push(allStyles[i]); + } + } + } else { + // Searching only for name + for(let i = 0; i < allStyles.count(); i++){ + if(allStyles[i].name() == name){ + styles.push(allStyles[i]); + } + } + } + return styles +} + // { // "script": "./script.js", // "name" : "onLayersMoved",