1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-15 23:00:36 +02:00

Mobile: Added duplicate option when selecting notes. (#1969)

* Adding duplicate button on screen-header.js when selecting notes; Adding 'duplicateMultipleNotes' function on Note.js;

* Using for-loop like the rest of the code does

* changing from 'uniqueTitle' to 'ensureUniqueTitle'
This commit is contained in:
Alan Martins Silva
2019-10-11 23:37:16 +01:00
committed by Laurent Cozic
parent b0a4a10dcc
commit d3e9ffcaea
2 changed files with 47 additions and 0 deletions

View File

@ -163,6 +163,16 @@ class ScreenHeaderComponent extends React.PureComponent {
NavService.go('Search');
}
async duplicateButton_press() {
const noteIds = this.props.selectedNoteIds;
//Duplicate all selected notes. ensureUniqueTitle is set to true to use the
//original note's name as a root for the new unique identifier.
await Note.duplicateMultipleNotes(noteIds, {ensureUniqueTitle: true});
this.props.dispatch({ type: 'NOTE_SELECTION_END' });
}
async deleteButton_press() {
// Dialog needs to be displayed as a child of the parent component, otherwise
// it won't be visible within the header component.
@ -245,6 +255,16 @@ class ScreenHeaderComponent extends React.PureComponent {
);
}
function duplicateButton(styles, onPress) {
return (
<TouchableOpacity onPress={onPress}>
<View style={styles.iconButton}>
<Icon name="md-copy" style={styles.topIcon} />
</View>
</TouchableOpacity>
);
}
function sortButton(styles, onPress) {
return (
<TouchableOpacity onPress={onPress}>
@ -282,6 +302,12 @@ class ScreenHeaderComponent extends React.PureComponent {
<Text style={this.styles().contextMenuItemText}>{_('Delete')}</Text>
</MenuOption>
);
menuOptionComponents.push(
<MenuOption value={() => this.duplicateButton_press()} key={'menuOption_duplicate'} style={this.styles().contextMenuItem}>
<Text style={this.styles().contextMenuItemText}>{_('Duplicate')}</Text>
</MenuOption>
);
}
const createTitleComponent = () => {
@ -383,6 +409,7 @@ class ScreenHeaderComponent extends React.PureComponent {
const backButtonComp = !showBackButton ? null : backButton(this.styles(), () => this.backButton_press(), backButtonDisabled);
const searchButtonComp = !showSearchButton ? null : searchButton(this.styles(), () => this.searchButton_press());
const deleteButtonComp = this.props.noteSelectionEnabled ? deleteButton(this.styles(), () => this.deleteButton_press()) : null;
const duplicateButtonComp = this.props.noteSelectionEnabled ? duplicateButton(this.styles(), () => this.duplicateButton_press()) : null;
const sortButtonComp = !this.props.noteSelectionEnabled && this.props.sortButton_press ? sortButton(this.styles(), () => this.props.sortButton_press()) : null;
const windowHeight = Dimensions.get('window').height - 50;
@ -419,6 +446,7 @@ class ScreenHeaderComponent extends React.PureComponent {
{titleComp}
{searchButtonComp}
{deleteButtonComp}
{duplicateButtonComp}
{sortButtonComp}
{menuComp}
</View>