commit cf7e32ee8f398f8dc60f2373b8a74b1df08bcd86
Author: Richard Kimberly Heck <rikih...@lyx.org>
Date:   Sat Aug 22 15:21:53 2020 -0400

    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 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/frontends/qt/GuiInclude.cpp b/src/frontends/qt/GuiInclude.cpp
index 5a38654..f278351 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));
 }
 
 
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to