]> git.lyx.org Git - features.git/commitdiff
Fix problem with edit button.
authorRichard Kimberly Heck <rikiheck@lyx.org>
Sat, 22 Aug 2020 19:21:53 +0000 (15:21 -0400)
committerRichard Kimberly Heck <rikiheck@lyx.org>
Mon, 31 Aug 2020 15:53:02 +0000 (11:53 -0400)
The previous implementation relied upon the cursor being immediately
in front of the inset. A bad idea.

(cherry picked from commit cf7e32ee8f398f8dc60f2373b8a74b1df08bcd86)

src/frontends/qt4/GuiInclude.cpp
status.23x

index d87f78c40939105030579d57c17a8bb152d30b00..7bc512bb19adb04218854e714867b64346d0edf0 100644 (file)
 #include "GuiInclude.h"
 
 #include "Buffer.h"
+#include "BufferList.h"
 #include "BufferParams.h"
 #include "FuncRequest.h"
 #include "LyXRC.h"
 
 #include "qt_helpers.h"
-#include "LyXRC.h"
 
 #include "support/gettext.h"
 #include "support/lstrings.h"
@@ -28,6 +28,8 @@
 #include "support/FileName.h"
 #include "support/filetools.h"
 
+#include "frontends/alert.h"
+
 #include "insets/InsetListingsParams.h"
 #include "insets/InsetInclude.h"
 
@@ -291,15 +293,20 @@ void GuiInclude::edit()
                applyView();
        } else
                hideView();
-       dispatch(FuncRequest(LFUN_INSET_EDIT));
+       QString const fname = filenameED->text();
+       string const bpath = buffer().filePath();
+       string const absfname = support::makeAbsPath(fromqstr(fname), bpath).absFileName();
+       // The button is enabled only if the document is already open.
+       // If something goes wrong and it is not, we'll get an error
+       // message from the dispatch. So no need for one here.
+       dispatch(FuncRequest(LFUN_BUFFER_SWITCH, absfname));
 }
 
 
 bool GuiInclude::isValid()
 {
        QString fname = filenameED->text();
-       bool fempty = fname.isEmpty();
-       if (fempty || !validate_listings_params().empty()) {
+       if (fname.isEmpty() || !validate_listings_params().empty()) {
                editPB->setEnabled(false);
                return false;
        }
@@ -311,15 +318,17 @@ bool GuiInclude::isValid()
                return true;
        }
        // Do we have a LyX filename?
-       if (!support::isLyXFileName(fromqstr(fname))) {
+       if (!isLyXFileName(fromqstr(fname))) {
                okPB->setText("OK");
                return false;
        }
        string const bpath = buffer().filePath();
-       QString absfname = makeAbsPath(fname, toqstr(bpath));
-       bool const fexists = QFile::exists(absfname);
-       okPB->setText(fexists ? "OK" : "Create");
-       editPB->setEnabled(fexists);
+       // Path might be relative to current Buffer, so make absolute
+       FileName const absfname = support::makeAbsPath(fromqstr(fname), bpath);
+       // Set OK button text according to whether file already exists
+       okPB->setText(absfname.exists() ? "OK" : "Create");
+       // enable edit button iff file is open in some Buffer
+       editPB->setEnabled(theBufferList().getBuffer(absfname));
        return true;
 }
 
index b5e54b41c6a0a008d076fe92cc68b4cd51a57ac7..552ccd7968e4b8cec0ef103a81fcee7e8c5064de 100644 (file)
@@ -98,6 +98,8 @@ What's new
 - Prevent permanent disabling of widgets in Vertical/Horizontal Space dialogs
   (bug 11952).
 
+- Fix behavior of Edit button in Include dialog.
+
 
 * INTERNALS