-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REF] menu registry: factorize menu registries by menu items
Part-of: #2046
- Loading branch information
1 parent
c02a7e9
commit 950abc4
Showing
14 changed files
with
1,029 additions
and
574 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
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,112 +1,81 @@ | ||
import { _lt } from "../../translation"; | ||
import { SpreadsheetChildEnv } from "../../types"; | ||
import { MenuItemRegistry } from "../menu_items_registry"; | ||
import * as ACTIONS from "./menu_items_actions"; | ||
import * as ACTION_DATA from "./items/data_menu_items"; | ||
import * as ACTION_EDIT from "./items/edit_menu_items"; | ||
import * as ACTION_FORMAT from "./items/format_menu_items"; | ||
import * as ACTION_INSERT from "./items/insert_menu_items"; | ||
import * as ACTION_VIEW from "./items/view_menu_items"; | ||
|
||
export const colMenuRegistry = new MenuItemRegistry(); | ||
|
||
colMenuRegistry | ||
.add("cut", { | ||
name: _lt("Cut"), | ||
description: "Ctrl+X", | ||
...ACTION_EDIT.cutMenuItem, | ||
sequence: 10, | ||
action: ACTIONS.CUT_ACTION, | ||
}) | ||
.add("copy", { | ||
name: _lt("Copy"), | ||
description: "Ctrl+C", | ||
...ACTION_EDIT.copyMenuItem, | ||
sequence: 20, | ||
isReadonlyAllowed: true, | ||
action: ACTIONS.COPY_ACTION, | ||
}) | ||
.add("paste", { | ||
name: _lt("Paste"), | ||
description: "Ctrl+V", | ||
...ACTION_EDIT.pasteMenuItem, | ||
sequence: 30, | ||
action: ACTIONS.PASTE_ACTION, | ||
}) | ||
.add("paste_special", { | ||
name: _lt("Paste special"), | ||
...ACTION_EDIT.pasteSpecialMenuItem, | ||
sequence: 40, | ||
separator: true, | ||
isVisible: ACTIONS.IS_NOT_CUT_OPERATION, | ||
}) | ||
.addChild("paste_value_only", ["paste_special"], { | ||
name: _lt("Paste value only"), | ||
...ACTION_EDIT.pasteSpecialValueMenuItem, | ||
sequence: 10, | ||
action: ACTIONS.PASTE_VALUE_ACTION, | ||
}) | ||
.addChild("paste_format_only", ["paste_special"], { | ||
name: _lt("Paste format only"), | ||
...ACTION_EDIT.pasteSpecialFormatMenuItem, | ||
sequence: 20, | ||
action: ACTIONS.PASTE_FORMAT_ACTION, | ||
}) | ||
.add("sort_columns", { | ||
...ACTION_DATA.sortRangeMenuItem, | ||
name: (env) => | ||
env.model.getters.getActiveCols().size > 1 ? _lt("Sort columns") : _lt("Sort column"), | ||
sequence: 50, | ||
isVisible: ACTIONS.IS_ONLY_ONE_RANGE, | ||
separator: true, | ||
}) | ||
.addChild("sort_ascending", ["sort_columns"], { | ||
name: _lt("Ascending (A ⟶ Z)"), | ||
...ACTION_DATA.sortAscendingenuItem, | ||
sequence: 10, | ||
action: ACTIONS.SORT_CELLS_ASCENDING, | ||
}) | ||
.addChild("sort_descending", ["sort_columns"], { | ||
name: _lt("Descending (Z ⟶ A)"), | ||
...ACTION_DATA.sortDescendingMenuItem, | ||
sequence: 20, | ||
action: ACTIONS.SORT_CELLS_DESCENDING, | ||
}) | ||
.add("add_column_before", { | ||
name: ACTIONS.COLUMN_INSERT_COLUMNS_BEFORE_NAME, | ||
...ACTION_INSERT.colInsertColsBeforeMenuItem, | ||
sequence: 70, | ||
action: ACTIONS.INSERT_COLUMNS_BEFORE_ACTION, | ||
}) | ||
.add("add_column_after", { | ||
name: ACTIONS.COLUMN_INSERT_COLUMNS_AFTER_NAME, | ||
...ACTION_INSERT.colInsertColsAfterMenuItem, | ||
sequence: 80, | ||
action: ACTIONS.INSERT_COLUMNS_AFTER_ACTION, | ||
}) | ||
.add("delete_column", { | ||
name: ACTIONS.REMOVE_COLUMNS_NAME, | ||
...ACTION_EDIT.deleteColsMenuItem, | ||
sequence: 90, | ||
action: ACTIONS.REMOVE_COLUMNS_ACTION, | ||
}) | ||
.add("clear_column", { | ||
name: ACTIONS.DELETE_CONTENT_COLUMNS_NAME, | ||
...ACTION_EDIT.clearColsMenuItem, | ||
sequence: 100, | ||
action: ACTIONS.DELETE_CONTENT_COLUMNS_ACTION, | ||
}) | ||
.add("hide_columns", { | ||
name: ACTIONS.HIDE_COLUMNS_NAME, | ||
...ACTION_VIEW.hideColsMenuItem, | ||
sequence: 85, | ||
action: ACTIONS.HIDE_COLUMNS_ACTION, | ||
isVisible: (env: SpreadsheetChildEnv) => { | ||
const sheetId = env.model.getters.getActiveSheetId(); | ||
const hiddenCols = env.model.getters.getHiddenColsGroups(sheetId).flat(); | ||
return ( | ||
env.model.getters.getNumberCols(sheetId) > | ||
hiddenCols.length + env.model.getters.getElementsFromSelection("COL").length | ||
); | ||
}, | ||
separator: true, | ||
}) | ||
.add("unhide_columns", { | ||
name: _lt("Unhide columns"), | ||
...ACTION_VIEW.unhideColsMenuItem, | ||
sequence: 86, | ||
action: ACTIONS.UNHIDE_COLUMNS_ACTION, | ||
isVisible: (env: SpreadsheetChildEnv) => { | ||
const hiddenCols = env.model.getters | ||
.getHiddenColsGroups(env.model.getters.getActiveSheetId()) | ||
.flat(); | ||
const currentCols = env.model.getters.getElementsFromSelection("COL"); | ||
return currentCols.some((col) => hiddenCols.includes(col)); | ||
}, | ||
separator: true, | ||
}) | ||
.add("conditional_formatting", { | ||
name: _lt("Conditional formatting"), | ||
...ACTION_FORMAT.formatCFMenuItem, | ||
sequence: 110, | ||
action: ACTIONS.OPEN_CF_SIDEPANEL_ACTION, | ||
}); |
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,33 @@ | ||
import { _lt } from "../../../translation"; | ||
import { MenuItemSpec } from "../../menu_items_registry"; | ||
import * as ACTIONS from "./../menu_items_actions"; | ||
|
||
export const sortRangeMenuItem: MenuItemSpec = { | ||
name: _lt("Sort range"), | ||
isVisible: ACTIONS.IS_ONLY_ONE_RANGE, | ||
}; | ||
|
||
export const sortAscendingenuItem: MenuItemSpec = { | ||
name: _lt("Ascending (A ⟶ Z)"), | ||
action: ACTIONS.SORT_CELLS_ASCENDING, | ||
}; | ||
|
||
export const sortDescendingMenuItem: MenuItemSpec = { | ||
name: _lt("Descending (Z ⟶ A)"), | ||
action: ACTIONS.SORT_CELLS_DESCENDING, | ||
}; | ||
|
||
export const addDataFilterMenuItem: MenuItemSpec = { | ||
name: _lt("Create filter"), | ||
action: ACTIONS.FILTERS_CREATE_FILTER_TABLE, | ||
isVisible: (env) => !ACTIONS.SELECTION_CONTAINS_FILTER(env), | ||
isEnabled: (env) => ACTIONS.SELECTION_IS_CONTINUOUS(env), | ||
icon: "o-spreadsheet-Icon.FILTER_ICON_INACTIVE", | ||
}; | ||
|
||
export const removeDataFilterMenuItem: MenuItemSpec = { | ||
name: _lt("Remove filter"), | ||
action: ACTIONS.FILTERS_REMOVE_FILTER_TABLE, | ||
isVisible: ACTIONS.SELECTION_CONTAINS_FILTER, | ||
icon: "o-spreadsheet-Icon.FILTER_ICON_INACTIVE", | ||
}; |
Oops, something went wrong.