-
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.
[ADD] Paste toolbox: a post-paste correction tool
After pasting, a user might want to change the type of pasting they do: - only paste the value - only paste the format - ... This revision adds a 'paste toolbox' to allow the user to alter the type of paste they want to do. Task: 4385451
- Loading branch information
Showing
13 changed files
with
401 additions
and
33 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
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,96 @@ | ||
import { Component, useRef, useState } from "@odoo/owl"; | ||
import { createActions } from "../../actions/action"; | ||
import { paste, pasteSpecialFormat, pasteSpecialValue } from "../../actions/edit_actions"; | ||
import { ComponentsImportance, ICON_EDGE_LENGTH } from "../../constants"; | ||
import { DOMCoordinates, SpreadsheetChildEnv } from "../../types"; | ||
import { css, cssPropertiesToCss } from "../helpers/css"; | ||
import { Menu, MenuState } from "../menu/menu"; | ||
|
||
css/* scss */ ` | ||
.o-paste { | ||
position: absolute; | ||
height: ${ICON_EDGE_LENGTH + 10}px; | ||
border: 1px solid lightgrey; | ||
box-sizing: border-box !important; | ||
background-color: white; | ||
cursor: pointer; | ||
z-index: ${ComponentsImportance.Clipboard}; | ||
align-content: center; | ||
.o-icon { | ||
margin: auto; | ||
} | ||
} | ||
`; | ||
|
||
interface Props { | ||
position: DOMCoordinates; | ||
onClosed: () => void; | ||
} | ||
|
||
export class PasteToolbox extends Component<Props, SpreadsheetChildEnv> { | ||
static template = "o-spreadsheet-PasteToolbox"; | ||
static props = { | ||
position: Object, | ||
onClosed: Function, | ||
}; | ||
static components = { Menu }; | ||
|
||
private menuState: MenuState = useState({ | ||
isOpen: false, | ||
position: { x: 0, y: 0 }, | ||
menuItems: [], | ||
}); | ||
|
||
private toolboxRef = useRef("toolboxButton"); | ||
|
||
get style() { | ||
const { x, y } = this.props.position; | ||
return cssPropertiesToCss({ | ||
left: `${x}px`, | ||
top: `${y + 5}px`, | ||
}); | ||
} | ||
|
||
showMenu() { | ||
this.menuState.isOpen = true; | ||
const { x, y } = this.toolboxRef.el!.getBoundingClientRect(); | ||
this.menuState.menuItems = this.getMenuItems(); | ||
this.menuState.position = { x, y }; | ||
} | ||
|
||
onMenuClosed() { | ||
this.menuState.isOpen = false; | ||
this.props.onClosed(); | ||
} | ||
|
||
private getMenuItems() { | ||
return createActions([ | ||
{ | ||
...paste, | ||
icon: undefined, | ||
id: "paste", | ||
execute: (env) => { | ||
env.model.dispatch("REQUEST_UNDO"); | ||
paste.execute?.(this.env); | ||
}, | ||
}, | ||
{ | ||
name: pasteSpecialValue.name, | ||
id: "paste_special_value", | ||
execute: (env) => { | ||
env.model.dispatch("REQUEST_UNDO"); | ||
pasteSpecialValue.execute?.(env); | ||
}, | ||
}, | ||
{ | ||
name: pasteSpecialFormat.name, | ||
id: "paste_special_format", | ||
execute: (env) => { | ||
env.model.dispatch("REQUEST_UNDO"); | ||
pasteSpecialFormat.execute?.(env); | ||
}, | ||
}, | ||
]); | ||
} | ||
} |
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,18 @@ | ||
<templates> | ||
<t t-name="o-spreadsheet-PasteToolbox"> | ||
<div | ||
t-ref="toolboxButton" | ||
class="o-paste d-flex ps-1" | ||
t-att-style="style" | ||
t-on-click="showMenu"> | ||
<t t-call="o-spreadsheet-Icon.PASTE"/> | ||
<t t-call="o-spreadsheet-Icon.CARET_DOWN"/> | ||
</div> | ||
<Menu | ||
t-if="menuState.isOpen" | ||
position="menuState.position" | ||
menuItems="menuState.menuItems" | ||
onClose.bind="onMenuClosed" | ||
/> | ||
</t> | ||
</templates> |
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
Oops, something went wrong.