-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from mmuffins/dev
Update to version 3
- Loading branch information
Showing
9 changed files
with
1,009 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1 @@ | ||
"use strict"; | ||
|
||
window.actionCategories.extensions = function(){ | ||
return _('Extensions'); | ||
} | ||
|
||
// Add global section to register extension actions if it doesn't exist yet | ||
if (typeof extensions == "undefined") | ||
var extensions = {} | ||
|
||
extensions.extensionsMenu = { | ||
menuOrder: 55, | ||
menuGrouporder: 10, | ||
menu: [], | ||
|
||
refresh: async function(){ | ||
let _this = this; | ||
if (!extensions.hasOwnProperty('extensionsMenuImportQueue') || !extensions.extensionsMenuImportQueue instanceof Array) { | ||
extensions.extensionsMenuImportQueue = []; | ||
return; | ||
} | ||
|
||
if(extensions.extensionsMenuImportQueue.length == 0) | ||
return; | ||
|
||
let importItems = extensions.extensionsMenuImportQueue; | ||
extensions.extensionsMenuImportQueue = []; | ||
|
||
// filter out items with missing properties | ||
importItems = importItems.filter(menuItm => { | ||
return (menuItm.hasOwnProperty('action') | ||
&& menuItm.action.hasOwnProperty('title') | ||
&& menuItm.hasOwnProperty('order') | ||
&& menuItm.hasOwnProperty('category')); | ||
}); | ||
|
||
// filter out items with missing title function or blank title | ||
importItems = importItems.filter(menuItm => { | ||
return (menuItm.action.title instanceof Function && menuItm.action.title() != ''); | ||
}); | ||
|
||
// Add imported entries to menu, but skip duplicates | ||
importItems.forEach(extensionItm => { | ||
if (typeof (_this.menu.find(item => item.action.title() == extensionItm.action.title() && item.category == extensionItm.category)) != "undefined") { | ||
return Promise.reject('Item already exists'); | ||
} | ||
|
||
_this.menu.push({action: extensionItm.action, order: extensionItm.order, category: extensionItm.category, grouporder: 100}); | ||
}) | ||
|
||
_this.sortMenu(); | ||
await _this.pushToUi(); | ||
}, | ||
|
||
pushToUi: async function(){ | ||
// pushes the internal menu to the ui | ||
let _this = this; | ||
|
||
if(_this.menu.length == 0) | ||
return; | ||
|
||
// Check if the menu was already pushed to UI, and only update the menu items if it was | ||
for (let i = 0; i < window.mainMenuItems.length; i++) { | ||
const itm = window.mainMenuItems[i].action; | ||
|
||
if(itm.hasOwnProperty('title') && itm.title instanceof Function && itm.title() == '&Extensions'){ | ||
itm.submenu = _this.menu; | ||
return; | ||
} | ||
} | ||
|
||
let newMenu = { | ||
action: { | ||
title: function () { | ||
return _('&Extensions'); | ||
}, | ||
visible: !webApp, | ||
submenu: _this.menu | ||
}, | ||
order: _this.menuOrder, | ||
grouporder: _this.menuGrouporder, | ||
} | ||
|
||
window.mainMenuItems.push(newMenu); | ||
uitools.switchMainMenu(false); | ||
uitools.switchMainMenu(true); | ||
}, | ||
|
||
getCategories: function(){ | ||
// returns an array with all categories in the menu | ||
return [...new Set(this.menu.map(x => x.category))]; | ||
}, | ||
|
||
sortMenu: function(){ | ||
// sorts the menu by category | ||
|
||
// get list of all categories and add a sort value | ||
let cat = this.getCategories().sort(); | ||
let catOrder = {}; | ||
for (let index = 0; index < cat.length; index++) { | ||
catOrder[cat[index]] = (index + 1) * 100; | ||
} | ||
|
||
// update each menu item with the sort index | ||
this.menu.forEach(el => { | ||
el.grouporder = catOrder[el.category] | ||
}); | ||
} | ||
} | ||
|
||
extensions.extensionsMenu.refresh() | ||
actionCategories.extensions = () => _('Extensions'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div data-id="pnlCollectionsRoot" class="padding fill flex column" data-tip="Organize the displayed extension actions into groups."> | ||
<div data-id="lvTreeView" class="fill flex column hSeparatorTiny" data-control-class="ExtensionTree" data-init-params="{enableDragDrop: true}"></div> | ||
<div data-control-class="Buttons"> | ||
<div data-id='btnNewGroup' data-control-class="Button" data-position='opposite' data-tip="Add a new group.">New</div> | ||
<div data-id='btnDeleteGroup' data-control-class="Button" data-position='opposite' data-tip="Delete the selected group.">Delete</div> | ||
<div data-id='btnRenameGroup' data-control-class="Button" data-position='opposite' data-tip="Rename the selected group.">Rename</div> | ||
<div data-id='btnResetTree' data-control-class="Button" data-position='opposite' data-tip="Reset the tree to its initial state.">Reset</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"use strict"; | ||
|
||
requirejs('viewHandlers.js'); | ||
requirejs("Scripts/ExtensionsMenu/extensionsMenu") | ||
requirejs("controls/extensionTree") | ||
|
||
window.configInfo = { | ||
load: function(panel, addon){ | ||
let _this = this; | ||
panel.innerHTML = window.loadFile(addon.configFile.replace('config.js','config.html')); | ||
let pnl = panel.firstElementChild; | ||
initializeControls(pnl); | ||
|
||
let UI = getAllUIElements(qid('pnlCollectionsRoot')); | ||
let TV = UI.lvTreeView; | ||
let ds = TV.controlClass.dataSource; | ||
|
||
extensions.extensionsMenu.discardChanges(); | ||
ds.root.handlerID = 'extensionsMenuTreeRoot'; | ||
ds.root.dataSource = extensions.extensionsMenu.getEditRootNode(); | ||
|
||
TV.controlClass.expandAll() | ||
|
||
app.listen(UI.btnNewGroup, 'click', function () { | ||
let newGroupNode = extensions.extensionsMenu.newGroup("New Group"); | ||
nodeUtils.refreshNodeChildren(TV.controlClass.root); | ||
let newGroup = TV.controlClass.root.findChild(`extensionsGroupNode:${newGroupNode.id}`); | ||
|
||
// focus node and enter edit node | ||
TV.controlClass.focusNode(newGroup); | ||
TV.controlClass.editStart() | ||
}); | ||
|
||
app.listen(UI.btnDeleteGroup, 'click', function () { | ||
TV.controlClass.deleteSelected(); | ||
}); | ||
|
||
app.listen(UI.btnRenameGroup, 'click', function () { | ||
TV.controlClass.editStart() | ||
}); | ||
|
||
app.listen(UI.btnResetTree, 'click', () => { | ||
extensions.extensionsMenu.resetActionTree(); | ||
let tree = app.createTree(); | ||
tree.root.handlerID = 'extensionsMenuTreeRoot'; | ||
tree.root.dataSource = extensions.extensionsMenu.getEditRootNode(); | ||
TV.controlClass.dataSource = tree; | ||
TV.controlClass.expandAll() | ||
}); | ||
}, | ||
|
||
save: function(panel, addon){ | ||
|
||
extensions.extensionsMenu.applyChanges() | ||
extensions.extensionsMenu.saveSettings(); | ||
extensions.extensionsMenu.reloadActionTree(); | ||
|
||
// the config menu runs in a separate context from the main window | ||
let mainAppWindow = app.dialogs.getMainWindow()._window; | ||
mainAppWindow.extensions.extensionsMenu.refresh(); | ||
}, | ||
} | ||
|
||
|
Oops, something went wrong.