Bug 44081 - EDITING - A form set to open in read-only mode can never be switched back
Summary: EDITING - A form set to open in read-only mode can never be switched back
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Base (show other bugs)
Version:
(earliest affected)
3.4.5 RC1
Hardware: All All
: medium minor
Assignee: Lionel Elie Mamane
URL:
Whiteboard: target:4.4.0 target:4.3.2
Keywords:
Depends on:
Blocks: 83302
  Show dependency treegraph
 
Reported: 2011-12-22 14:38 UTC by Kurt
Modified: 2014-09-04 12:48 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
Demonstration of the bug preventing read-only forms from having the read-only setting turned off. (19.79 KB, application/vnd.sun.xml.base)
2011-12-22 14:38 UTC, Kurt
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kurt 2011-12-22 14:38:05 UTC
Created attachment 54725 [details]
Demonstration of the bug preventing read-only forms from having the read-only setting turned off.

A Base form that has had the "Open file read-only" setting turned on and saved in a Base file can never be edited again.  The "open file read-only" setting can not be turned off again.

To reproduce:
1) Create a new LibreOffice Base database.
2) Create a form in the database.
3) While editing the form, select "File->Properties" and click on the "Security" tab.  Check the "Open file read-only" checkbox and click "Ok".
4) Save the form, close it, then save the Base file, and close it.

From this point on, if you open the Base file, the form can never again be edited.

Normally, in a Writer file (which is the closest analog to a Base form) the setting can be turned off by:
1) Clicking the "Edit File" button in the "Standard" toolbar
2) Selecting "File->Properties", clicking on the "Security" tab, and unchecking "Open file read-only"
However, in Base forms, the "Edit File" button is always grayed.  And once the form is saved with the "Open file read-only" setting turned on, the form always opens with design-mode turned off and the button to turn on design-mode also grayed.  Copying the form has no effect, as the copy has the read-only setting turned on as well.

The attached database demonstrates.  There are two forms in it.  One that can be edited, one that cannot be.
Comment 1 Ulf 2012-07-27 20:24:39 UTC
I can confirm it with LibOffice 3.5.5 on WINXP and the example file.

But it could be that this function is not supported in the database component?

Normally if you create a Form, Base will open it "write protected" and you can insert data. You have to open it different "to edit"

But in my opinon if you can protcect the Form it must be possible to undo the protection.
Comment 2 Julien Nabet 2014-07-26 08:05:04 UTC
I gave a try with master sources updated yesterday, indeed I can't uncheck "Read-only" since the checkbox is disabled.
I also tried from File/properties in Edit Form in from Base (instead of from Writer).

Trying in gdb session, it seems the problem might be here:
http://opengrok.libreoffice.org/xref/core/sfx2/source/dialog/securitypage.cxx#241
SfxSecurityPage_Impl::Reset_Impl
May there be some confusion between:
- pCurDocShell->IsReadOnly()
- pCurDocShell->HasSecurityOptOpenReadOnly()
- pCurDocShell->IsSecurityOptOpenReadOnly()

I don't find the way the checkboxes could be enabled with readonly checkbox checked.

Lionel/Caolan: any idea?
Comment 3 Lionel Elie Mamane 2014-08-26 09:40:29 UTC
In a Writer file, when opening a read-only file, one can right-click on the document and the pop-up menu has "edit". A Base form does not have this in the pop-up menu.

My guess is that the "edit" entry in the contextual (pop-up) menu has been removed in Base forms to avoid the user working around the fact that a Base form is opened (as a Writer document) 'read-only' normally (not in design mode), and that one needs to use "edit" (not "open") to change it (in other words, open it in design mode).

My suggested fix would be to suppress this "edit" entry only in non-design mode, and leave it alone (leave it in the menu) in design mode.

Julien, if you feel like it, you could:

1) Track down where the "edit" in the menu is suppressed from Base forms compared to Writer documents.

2) Make this suppression conditional on "not design mode". See http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1awt_1_1XVclWindowPeer.html#a5231c997c902a2c7dbf745d1e6d4731b
http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1awt_1_1XControl.html#a5231c997c902a2c7dbf745d1e6d4731b
for APIs to ask a window / a control whether it is in design mode.
Comment 4 Julien Nabet 2014-08-26 21:08:35 UTC
Thank you Lionel for the hints.

Since keyId Language Id gaves no link (no keyid for all the entries of the popup menu), I searched "Image Off" and found this:
http://opengrok.libreoffice.org/xref/core/sw/source/uibase/docvw/docvw.src#170

Some lines above, Edit is here:
http://opengrok.libreoffice.org/xref/core/sw/source/uibase/docvw/docvw.src#40

Searching "MN_READONLY_EDITDOC" gave 3 results (see http://opengrok.libreoffice.org/search?q=MN_READONLY_EDITDOC&project=core&defs=&refs=&path=&hist=)
Best candidate seemed this one:
http://opengrok.libreoffice.org/xref/core/sw/source/uibase/docvw/romenu.cxx#216

    210     eState = pVFrame->GetBindings().QueryState( SID_EDITDOC, pState );
    211     if (
    212         eState < SFX_ITEM_DEFAULT ||
    213         (rSh.IsGlobalDoc() && rView.GetDocShell()->IsReadOnlyUI())
    214        )
    215     {
    216         EnableItem( MN_READONLY_EDITDOC, false );
    217     }

With Writer eState = SFX_ITEM_DEFAULT whereas with Base eState = SFX_ITEM_DISABLED

I must recognize I hardly understand all this. Should we try to link "not design mode" with eState? More clearly, should eState be equal to SFX_ITEM_DEFAULT when not in design mode?
Comment 5 Lionel Elie Mamane 2014-08-27 12:28:55 UTC
I found the code ultimately responsible for the disabled SID_EDITDOC:

http://opengrok.libreoffice.org/xref/core/sfx2/source/view/viewfrm.cxx#860

       if ( !pSh || !pSh->HasName() || !( pSh->Get_Impl()->nLoadedFlags &  SFX_LOADED_MAINDOCUMENT )
           || pSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
             rSet.DisableItem( SID_EDITDOC );

specifically the "|| pSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED". I would like to change that to:
 || (pSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED && !opened_in_design_mode)

but at this point I'm not sure how to do the "opened_in_design_mode"
Comment 6 Lionel Elie Mamane 2014-08-27 17:26:14 UTC
So https://gerrit.libreoffice.org/11152 is patch that works, but I'm deeply unsatisfied by it. I'm asking for input from other developpers on what an acceptable solution would be.
Comment 7 Lionel Elie Mamane 2014-08-28 14:45:35 UTC
Found what I think can be an acceptable fix. Letting some time to other developers to give their input.
Comment 8 Commit Notification 2014-09-01 08:21:49 UTC
Lionel Elie Mamane committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=15cea073e7ed4970e60967fe036fc492e2052203

fdo#44081 don't remove 'edit' pop-up menu entry from form in design mode



The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 9 Commit Notification 2014-09-01 08:45:59 UTC
Miklos Vajna committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=024f334c48bc3d6cfac91ab7499f6b2863223c24

Revert "fdo#44081 don't remove 'edit' pop-up menu entry from form in design mode"



The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 10 Commit Notification 2014-09-02 16:17:49 UTC
Lionel Elie Mamane committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=b3062ae65fc7069442cb5fc23dd68c2e8344e999

fdo#44081 don't remove 'edit' pop-up menu entry from form in design mode



The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 11 Commit Notification 2014-09-04 12:48:22 UTC
Lionel Elie Mamane committed a patch related to this issue.
It has been pushed to "libreoffice-4-3":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=9633a6592c9be5675a8636baed10fd3d1e0f70eb&h=libreoffice-4-3

fdo#44081 don't remove 'edit' pop-up menu entry from form in design mode


It will be available in LibreOffice 4.3.2.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.