SUMMARY Okular throws an error if a non available file is opened, but creates an empty tab then. STEPS TO REPRODUCE 1. Open a PDF in Okular 2. Move it or delete the PDF 3. Close the tab in Okular 4. Open the deleted PDF via File->Recently Opened Files 5. Warning appears and a tab is created for the non existing PDF EXPECTED RESULT Don't create a tab, but if so, make CTRL+W available. SOFTWARE/OS VERSIONS Operating System: Manjaro Linux KDE Plasma Version: 5.16.5 KDE Frameworks Version: 5.63.0 Qt Version: 5.13.1 ADDITIONAL INFORMATION It is no longer possible to close the empty tab by CTRL+W
I was able to reproduce this. You can't close the document with CTRL+W, but you can close the tab. I will work on this.
(In reply to Andi Sardina from comment #1) > I was able to reproduce this. You can't close the document with CTRL+W, but > you can close the tab. I will work on this. Just one of the possible solutions if you are going to create an MR on gitlab: diff --git a/shell/shell.cpp b/shell/shell.cpp index 8c0c62e5b..4f397ef0b 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -675,7 +675,10 @@ void Shell::openNewTab( const QUrl& url, const QString &serializedOptions ) if( part->openUrl(url) ) m_recent->addUrl( url ); else + { setActiveTab( previousActiveTab ); + closeTab( m_tabs.size() - 1 ); + } } void Shell::applyOptionsToPart( QObject* part, const QString &serializedOptions )
Hi Yuri Chornoivan, You can create the PR if that solves the issue!!
I will suggest removing the document from the recent documents menu.
(In reply to Andi Sardina from comment #4) > I will suggest removing the document from the recent documents menu. It makes sense that, that once Okular has detected that a file no longer exists, the entry of the deleted file in the "recently opened files" panel should either be removed or (as I'd prefer) be marked as unavailable (grayed out, striked out) with a hint maybe. By the way, you can also trigger the bug by invoking > okular file_which_does_not_exist.pdf in a terminal, with the exact same effects as described above. The solution of this issue should however definitely hinder Okular to create senseless tabs.
(In reply to Andi Sardina from comment #3) > Hi Yuri Chornoivan, > > You can create the PR if that solves the issue!! https://invent.kde.org/kde/okular/merge_requests/53
Yuri Chornoivan, your solution doesn't solve the problem. Try this: * Open one document. Let's call this document A. * Now move or delete the document A. * Press CTRL+W and close the document A. * Now open a new document. Let's call it document B. * Now close document B with CTRL+W. * Try to open document A now from the recent menu. With your proposed solution the tab won't be opened. * Finally open document B again from the recent menu. You will see that two tabs are created, one for document A and one for document B.
A(In reply to Andi Sardina from comment #7) > Yuri Chornoivan, your solution doesn't solve the problem. > > Try this: With that you just have described bug #412979, which you can now confirm. :)
(In reply to Andi Sardina from comment #7) > Yuri Chornoivan, your solution doesn't solve the problem. > > Try this: > > * Open one document. Let's call this document A. > * Now move or delete the document A. > * Press CTRL+W and close the document A. > * Now open a new document. Let's call it document B. > * Now close document B with CTRL+W. > * Try to open document A now from the recent menu. With your proposed > solution the tab won't be opened. > * Finally open document B again from the recent menu. You will see that two > tabs are created, one for document A and one for document B. Ok. Now you can fix both bugs with your patch without my useless intrusion. ;)
Yuri Chornoivan, I used your idea to solve both problems. We only needed to add that line in the function Shell::openUrl.
> I used your idea to solve both problems. > We only needed to add that line > [closeTab( m_tabs.size() - 1 );] > in the function Shell::openUrl. Great that you could have resolve it. As I am not quiet familiar with the Okular shell code: To me it sounds like you implement kind of workaround with this line, as a faulty tab is created and closed. Should it not be created at all in the first place?
Postix, I notice it, but the problem is that the function to open the file is in the part (KParts::ReadWritePart), which is created and added to the tab widget before know if the file will be opened successfully or not. Maybe there is a way to do update the UI after. I am trying to write an autotest right now, and it will take me a bit because I haven't written a test in Qt before. But after I finish this, I will try to solve it!
@Postix I was wrong about what I said in my last comment. The code for updating the UI is in a different place. I have moved it to only show a tab when the file is successfully opened.
Git commit c549d28f7f963607075fb39322115d39e837d854 by Albert Astals Cid, on behalf of Andi Sardina Ramos. Committed on 10/02/2020 at 23:22. Pushed by aacid into branch 'master'. Solving the creation of an additional tab for a deleted file. Related: bug 412979 M +2 -2 autotests/CMakeLists.txt A +41 -0 autotests/closedialoghelper.cpp [License: UNKNOWN] * A +39 -0 autotests/closedialoghelper.h [License: UNKNOWN] * M +61 -1 autotests/mainshelltest.cpp M +21 -65 autotests/parttest.cpp M +1 -1 autotests/testingutils.cpp M +1 -0 autotests/testingutils.h M +21 -2 core/document.cpp M +8 -0 core/document.h M +2 -0 core/document_p.h M +3 -1 part.cpp M +20 -10 shell/shell.cpp The files marked with a * at the end have a non valid license. Please read: https://community.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page. https://invent.kde.org/kde/okular/commit/c549d28f7f963607075fb39322115d39e837d854
Thank you, Albert! :)