Bug 145745 - Create a "Duplicate sheet" option in LO Calc
Summary: Create a "Duplicate sheet" option in LO Calc
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium enhancement
Assignee: Rafael Lima
URL:
Whiteboard: target:7.4.0
Keywords: difficultyInteresting, easyHack, skillCpp, topicUI
Depends on:
Blocks: UNO-Command-New Sheet
  Show dependency treegraph
 
Reported: 2021-11-17 18:52 UTC by Rafael Lima
Modified: 2024-02-22 17:09 UTC (History)
6 users (show)

See Also:
Crash report or crash signature:


Attachments
ODG file with screenshots (95.54 KB, application/vnd.oasis.opendocument.graphics)
2021-11-17 18:52 UTC, Rafael Lima
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rafael Lima 2021-11-17 18:52:49 UTC
Created attachment 176323 [details]
ODG file with screenshots

One common task in working with spreadsheets is duplicating the current sheet (quickly create a copy of a sheet).

To do so in Calc the user has to follow a lot of steps:
1) Right click the sheet tab that will be duplicated
2) A context menu will appear. Click "Move or copy sheet"
3) Under "Action" select "Copy" (notice that "Move" is the default)
4) In the "Insert before" area, choose where the copy will be placed (optional)
5) Define a new name (optional)
6) Click OK

In Excel online and Google sheets a very handy option has been added to ease the duplication of sheets. They simply added a "Duplicate" option when the user right-clicks the sheet tab (see attached ODG file).

I would like to suggest this feature be added to LO Calc as well.

I have added an ODG file with screenshots showing the "Duplicate" options in Google Sheets and Excel Online, as well as a suggestion of where the new "Duplicate" option could be placed in the current context menu.
Comment 1 Roman Kuznetsov 2021-11-17 21:05:34 UTC
Yep, would be nice
Comment 2 Regina Henschel 2021-11-17 22:32:39 UTC
Click on the tab of the sheet, hold mouse button down and drag the tab while holding the Ctrl-key. That duplicates the sheet. Without Ctrl-key it moves the sheet.
Comment 3 Regina Henschel 2021-11-17 22:39:56 UTC
For renaming a sheet click on the tab while holding down the Alt-key. That brings the tab into edit mode.
Comment 4 Rafael Lima 2021-11-18 14:42:35 UTC
(In reply to Regina Henschel from comment #2)
> Click on the tab of the sheet, hold mouse button down and drag the tab while
> holding the Ctrl-key. That duplicates the sheet. Without Ctrl-key it moves
> the sheet.

> For renaming a sheet click on the tab while holding down the Alt-key. That
> brings the tab into edit mode.

Hi Regina. I did not know about these shortcuts. I tested them and indeed they work. However, I could not find any documentation in the online Help about them. I'll create some entries for these shortcuts in:

https://help.libreoffice.org/latest/en-US/text/scalc/04/01020000.html?DbPAR=CALC#bm_id3145801

Despite that, I believe the new "Duplicate" option should be implemented in addition to the existing shortcuts because these shortcuts are not very discoverable by new (or even somewhat experienced) users. I myself had no idea about them =)
Comment 5 Heiko Tietze 2021-11-19 08:56:01 UTC
I always have scruples with adding similar functions. The new "Duplicate" command would be the same as the current "Move or Copy", with just less options. But I see benefit from removing or cleaning-up this dialog in favor of the "Duplicate". Do we need the Move anyway? Maybe if the target is within a different document. So either kill the dialog or keep but without Copy.

Alternatively we could advertise the shift+drag interaction per static label on the "copy" radio button.
Comment 6 Eike Rathke 2021-11-24 15:55:15 UTC
(In reply to Heiko Tietze from comment #5)
> Do we need the Move anyway?
Yes. With a 200 sheets document you don't want to drag&drop over 150 sheet tabs to reach the target. And then miss.
Comment 7 Heiko Tietze 2021-11-25 09:36:16 UTC
We discussed the request in the design meeting and recommend to implement a command uno:DuplicateSheet that bypasses the dialog.

It's likely easyhackable given the existing shortcut as Regina pointed out. The challenge is to find the right code pointer.
Comment 8 Heiko Tietze 2022-02-02 11:10:27 UTC
Code pointer: the move/copy operation is done in ScViewFunc::MoveTable() after being initiated per FID_TAB_MOVE. It starts the dialog when called without parameter, so a new command would just need a parameter.
Comment 9 Rafael Lima 2022-02-02 11:48:59 UTC
Hi Heiko, Houssein,

First of all, thanks for the code pointers.

I would like to try to fix this one. However, I find it a bit complex to understand how to create new UNO commands. The relationship between SDI files and the actual code is a bit complex.

Looking though Gerrit a found this patch which I believe is a good pointer to create a new UNO command in Calc:

https://gerrit.libreoffice.org/c/core/+/114911

Do you think this is a good "template" for this bug?
Comment 10 Hossein 2022-02-03 13:55:04 UTC
I agree with Heiko. Look for FID_TAB_MOVE, .uno:Move, and also take a look at ScViewFunc::MoveTable(), as this command is more similar.

You can see more Calc commands here:
https://wiki.documentfoundation.org/Development/DispatchCommands#Calc

Look for "FID_TAB_MOVE":

  git grep FID_TAB_MOVE

You will see that it is defined and used in these files:

sc/inc/sc.hrc
sc/sdi/docsh.sdi
sc/sdi/scalc.sdi
sc/source/ui/view/tabcont.cxx
sc/source/ui/view/tabvwshf.cxx

You can go on and start from copying some parts from the tab move, and then try to be specific on this command. As you may see, the ScViewFunc::MoveTable() is invoked in the switch case inside tabvwshf.cxx.

Look for ".uno:Move":

git grep -Fw .uno:Move |grep -v .py

Look into these files:

officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
sc/uiconfig/scalc/menubar/menubar.xml
sc/uiconfig/scalc/popupmenu/sheettab.xml

You should define FID_TAB_DUPLICATE and .uno:DuplicateSheet.

BASIC is also a useful for testing. For example, I test ".uno:SheetRightToLeft" with this BASIC code snippet. It reverses the the direction of an open Calc document.

Sub Main
  document   = ThisComponent.CurrentController.Frame
  dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
  dim args(0) as new com.sun.star.beans.PropertyValue
  args(0).Name = "RightToLeft"
  args(0).Value = "true"
  dispatcher.executeDispatch(document, ".uno:SheetRightToLeft", "", 0, args())
End Sub
Comment 11 Rafael Lima 2022-02-05 23:38:56 UTC
Proposed patch available in Gerrit for review.
https://gerrit.libreoffice.org/c/core/+/129541
Comment 12 Hossein 2022-02-06 21:49:10 UTC
* Create a "Duplicate sheet" option in LO Calc
  + https://bugs.documentfoundation.org/show_bug.cgi?id=145745
  + (hidden) workflow per shift/ctrl+click (Regina)
  + solve by introducing a new function or via static label explaining
    the functionality (Heiko)
  + Move is necessary for large databases (Eike)
  + would introduce uno:DuplicateSheet (Cor)
  => do it; easyhackable

Minutes from the UX/design meeting 2021-Nov-24
https://listarchives.libreoffice.org/global/design/2021/msg00112.html
Comment 13 Commit Notification 2022-02-15 12:37:59 UTC
rafaelhlima committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/d519cbe89268ff24e2b8b05ba5124dca98f22b79

tdf#145745 Create uno:DuplicateSheet command

It will be available in 7.4.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 14 Rafael Lima 2022-02-18 01:33:14 UTC
FIXED. Tested with:

Version: 7.4.0.0.alpha0+ / LibreOffice Community
Build ID: 60f786bde4524bbba462eccc6578715f39020076
CPU threads: 16; OS: Linux 5.13; UI render: default; VCL: kf5 (cairo+xcb)
Locale: pt-BR (pt_BR.UTF-8); UI: en-US
Calc: CL