From: Richard Kimberly Heck Date: Sat, 22 Aug 2020 19:21:53 +0000 (-0400) Subject: Fix problem with edit button. X-Git-Tag: 2.3.6~44 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=7f69fb3b3c6b1628e3ea2f881229f9ad5fa1506f;p=features.git Fix problem with edit button. The previous implementation relied upon the cursor being immediately in front of the inset. A bad idea. (cherry picked from commit cf7e32ee8f398f8dc60f2373b8a74b1df08bcd86) --- diff --git a/src/frontends/qt4/GuiInclude.cpp b/src/frontends/qt4/GuiInclude.cpp index d87f78c409..7bc512bb19 100644 --- a/src/frontends/qt4/GuiInclude.cpp +++ b/src/frontends/qt4/GuiInclude.cpp @@ -15,12 +15,12 @@ #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; } diff --git a/status.23x b/status.23x index b5e54b41c6..552ccd7968 100644 --- a/status.23x +++ b/status.23x @@ -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