From cf7e32ee8f398f8dc60f2373b8a74b1df08bcd86 Mon Sep 17 00:00:00 2001 From: Richard Kimberly Heck Date: Sat, 22 Aug 2020 15:21:53 -0400 Subject: [PATCH] Fix problem with edit button. The previous implementation relied upon the cursor being immediately in front of the inset. A bad idea. --- src/frontends/qt/GuiInclude.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/frontends/qt/GuiInclude.cpp b/src/frontends/qt/GuiInclude.cpp index 5a386547dd..f2783519d9 100644 --- a/src/frontends/qt/GuiInclude.cpp +++ b/src/frontends/qt/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,7 +293,28 @@ 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(); + FileName const absFileName(absfname); + Buffer const * buffer = theBufferList().getBuffer(absFileName); + if (!buffer) { + // The Buffer is not already open, so try to open it. + if (!absFileName.exists()) { + Alert::warning(_("File does not exist"), + bformat(_("The requested file\n\t%1$s\ndoes not exist."), + from_utf8(absfname))); + return; + } + dispatch(FuncRequest(LFUN_BUFFER_NEW, absfname)); + // Did we succeed? + if (!theBufferList().getBuffer(absFileName)) { + // We should already have had an error message. + return; + } + } + // Switch to the requested Buffer + dispatch(FuncRequest(LFUN_BUFFER_SWITCH, absfname)); } -- 2.39.5