Commit 0d6792c4 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

Turn code.js into a singleton

Otherwise we would create an instance of this JS file for every delegate.
The only contextual object it uses is i18n, so pass that in for the function call.

Differential Revision: https://phabricator.kde.org/D10507
parent 0ead1a6e
......@@ -19,11 +19,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
function fillActionMenu(actionMenu, actionList, favoriteModel, favoriteId) {
.pragma library
function fillActionMenu(i18n, actionMenu, actionList, favoriteModel, favoriteId) {
// Accessing actionList can be a costly operation, so we don't
// access it until we need the menu.
var actions = createFavoriteActions(favoriteModel, favoriteId);
var actions = createFavoriteActions(i18n, favoriteModel, favoriteId);
if (actions) {
if (actionList && actionList.length > 0) {
......@@ -39,7 +41,7 @@ function fillActionMenu(actionMenu, actionList, favoriteModel, favoriteId) {
actionMenu.actionList = actionList;
}
function createFavoriteActions(favoriteModel, favoriteId) {
function createFavoriteActions(i18n, favoriteModel, favoriteId) {
if (favoriteModel === null || !favoriteModel.enabled || favoriteId == null) {
return null;
}
......
......@@ -907,7 +907,7 @@ Kicker.DashboardWindow {
onAboutToShowActionMenu: {
var actionList = hasActionList ? model.actionList : [];
Tools.fillActionMenu(actionMenu, actionList, ListView.view.model.favoritesModel, model.favoriteId);
Tools.fillActionMenu(i18n, actionMenu, actionList, ListView.view.model.favoritesModel, model.favoriteId);
}
onActionTriggered: {
......
......@@ -45,7 +45,7 @@ Item {
function openActionMenu(x, y) {
var actionList = hasActionList ? model.actionList : [];
Tools.fillActionMenu(actionMenu, actionList, GridView.view.model.favoritesModel, model.favoriteId);
Tools.fillActionMenu(i18n, actionMenu, actionList, GridView.view.model.favoritesModel, model.favoriteId);
actionMenu.visualParent = item;
actionMenu.open(x, y);
}
......
......@@ -53,7 +53,7 @@ Item {
onAboutToShowActionMenu: {
var actionList = hasActionList ? model.actionList : [];
Tools.fillActionMenu(actionMenu, actionList, ListView.view.model.favoritesModel, model.favoriteId);
Tools.fillActionMenu(i18n, actionMenu, actionList, ListView.view.model.favoritesModel, model.favoriteId);
}
onActionTriggered: {
......
......@@ -39,7 +39,7 @@ Item {
onAboutToShowActionMenu: {
var actionList = (model.hasActionList != null) ? model.actionList : [];
Tools.fillActionMenu(actionMenu, actionList, repeater.model, model.favoriteId);
Tools.fillActionMenu(i18n, actionMenu, actionList, repeater.model, model.favoriteId);
}
onActionTriggered: {
......
......@@ -19,11 +19,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
function fillActionMenu(actionMenu, actionList, favoriteModel, favoriteId) {
.pragma library
function fillActionMenu(i18n, actionMenu, actionList, favoriteModel, favoriteId) {
// Accessing actionList can be a costly operation, so we don't
// access it until we need the menu.
var actions = createFavoriteActions(favoriteModel, favoriteId);
var actions = createFavoriteActions(i18n, favoriteModel, favoriteId);
if (actions) {
if (actionList && actionList.length > 0) {
......@@ -39,7 +41,7 @@ function fillActionMenu(actionMenu, actionList, favoriteModel, favoriteId) {
actionMenu.actionList = actionList;
}
function createFavoriteActions(favoriteModel, favoriteId) {
function createFavoriteActions(i18n, favoriteModel, favoriteId) {
if (favoriteModel === null || !favoriteModel.enabled || favoriteId == null) {
return null;
}
......
......@@ -50,7 +50,7 @@ Item {
onAboutToShowActionMenu: {
var actionList = hasActionList ? model.actionList : [];
Tools.fillActionMenu(actionMenu, actionList, ListView.view.model.favoritesModel, model.favoriteId);
Tools.fillActionMenu(i18n, actionMenu, actionList, ListView.view.model.favoritesModel, model.favoriteId);
}
onActionTriggered: {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment