Skip to content

Commit

Permalink
WIP. Creating menuItems list on demand. #5759
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpiotr-dev committed Feb 11, 2019
1 parent 9cbda79 commit 884ef85
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 25 deletions.
2 changes: 0 additions & 2 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,6 @@ export default function Core(rootElement, userSettings, rootInstanceSymbol = fal
* });
* ```
* @fires Hooks#afterCellMetaReset
* @fires Hooks#updatePlugin
* @fires Hooks#afterUpdateSettings
*/
this.updateSettings = function(settings, init = false) {
Expand Down Expand Up @@ -1807,7 +1806,6 @@ export default function Core(rootElement, userSettings, rootInstanceSymbol = fal
instance.view.wt.wtViewport.resetHasOversizedColumnHeadersMarked();
}

instance.runHooks('updatePlugin');
instance.runHooks('afterUpdateSettings', settings);
}

Expand Down
7 changes: 0 additions & 7 deletions src/pluginHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1815,13 +1815,6 @@ const REGISTERED_HOOKS = [
* @event Hooks#afterUnlisten
*/
'afterUnlisten',

/**
*
*
* @event Hooks#updatePlugin
*/
'updatePlugin',
];

class Hooks {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BasePlugin {
this.initialized = false;

this.hot.addHook('afterPluginsInitialized', () => this.onAfterPluginsInitialized());
this.hot.addHook('updatePlugin', () => this.onUpdatePlugin());
this.hot.addHook('afterUpdateSettings', newSettings => this.onUpdateSettings(newSettings));
this.hot.addHook('beforeInit', () => this.init());
}

Expand Down Expand Up @@ -142,7 +142,7 @@ class BasePlugin {
*
* @private
*/
onUpdatePlugin() {
onUpdateSettings() {
if (this.isEnabled) {
if (this.enabled && !this.isEnabled()) {
this.disablePlugin();
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/columnSorting/columnSorting.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ class ColumnSorting extends BasePlugin {
this.addHook('afterRemoveRow', (index, amount) => this.onAfterRemoveRow(index, amount));
this.addHook('afterInit', () => this.loadOrSortBySettings());
this.addHook('afterLoadData', initialLoad => this.onAfterLoadData(initialLoad));
this.addHook('afterUpdateSettings', settings => this.onAfterUpdateSettings(settings));
this.addHook('afterRemoveCol', () => this.onAfterRemoveCol());
this.addHook('afterCreateCol', () => this.onAfterCreateCol());

Expand Down Expand Up @@ -727,13 +726,13 @@ class ColumnSorting extends BasePlugin {
}

/**
* Overwriting base plugin's `onUpdatePlugin` method. Please keep in mind that `onUpdatePlugin` isn't called
* Overwriting base plugin's `onUpdateSettings` method. Please keep in mind that `onAfterUpdateSettings` isn't called
* for `updateSettings` in specific situations.
*
* @private
* @param {Object} newSettings New settings object.
*/
onAfterUpdateSettings(newSettings) {
onUpdateSettings(newSettings) {
this.columnMetaCache.clear();

if (isDefined(newSettings[this.pluginKey])) {
Expand Down
21 changes: 14 additions & 7 deletions src/plugins/contextMenu/contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,17 @@ class ContextMenu extends BasePlugin {
}
super.enablePlugin();

this.menu = new Menu(this.hot, {
className: 'htContextMenu',
keepInViewport: true
});

this.addHook('afterOnCellContextMenu', event => this.onAfterOnCellContextMenu(event));
this.addHook('afterUpdateSettings', () => this.onAfterUpdateSettings());
this.addHook('afterInit', () => this.onAfterUpdateSettings());
}

onAfterUpdateSettings() {
generateCommands() {
this.itemsFactory = new ItemsFactory(this.hot, ContextMenu.DEFAULT_ITEMS);

const settings = this.hot.getSettings().contextMenu;
const predefinedItems = {
items: this.itemsFactory.getItems(settings)
Expand All @@ -162,10 +167,6 @@ class ContextMenu extends BasePlugin {
this.itemsFactory.setPredefinedItems(predefinedItems.items);
const menuItems = this.itemsFactory.getItems(settings);

this.menu = new Menu(this.hot, {
className: 'htContextMenu',
keepInViewport: true
});
this.hot.runHooks('beforeContextMenuSetItems', menuItems);

this.menu.setMenuItems(menuItems);
Expand Down Expand Up @@ -212,9 +213,12 @@ class ContextMenu extends BasePlugin {
* compatible with native mouse event so it can be used either.
*/
open(event) {
this.generateCommands();

if (!this.menu) {
return;
}

this.menu.open();
this.menu.setPosition({
top: parseInt(pageY(event), 10) - getWindowScrollTop(this.hot.rootWindow),
Expand All @@ -233,6 +237,9 @@ class ContextMenu extends BasePlugin {
if (!this.menu) {
return;
}

this.itemsFactory = null;

this.menu.close();
}

Expand Down
6 changes: 3 additions & 3 deletions src/plugins/multiColumnSorting/multiColumnSorting.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,18 @@ class MultiColumnSorting extends ColumnSorting {
}

/**
* Overwriting base plugin's `onUpdatePlugin` method. Please keep in mind that `onUpdatePlugin` isn't called
* Overwriting base plugin's `onUpdateSettings` method. Please keep in mind that `onAfterUpdateSettings` isn't called
* for `updateSettings` in specific situations.
*
* @private
* @param {Object} newSettings New settings object.
*/
onAfterUpdateSettings(newSettings) {
onUpdateSettings(newSettings) {
if (this.hot.getSettings()[this.pluginKey] && this.hot.getSettings()[CONFLICTED_PLUGIN_KEY]) {
warnAboutPluginsConflict();
}

return super.onAfterUpdateSettings(newSettings);
return super.onUpdateSettings(newSettings);
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/tableView.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,6 @@ class TableView {
onDraw(force) {
if (force) {
// this.instance.forceFullRender = did Handsontable request full render?
console.log('tableview.onDraw');
this.instance.runHooks('afterRender', this.instance.forceFullRender);
}
}
Expand Down

0 comments on commit 884ef85

Please sign in to comment.