X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt%2FGuiInclude.cpp;h=6120d669ef5072096cfa3fb346a249d58fc38025;hb=29a8097c3c14aad871c7e396a59542fe47e39ea1;hp=5a386547dd4399a5f730316ca998a2ad5a327500;hpb=a385b7dc2b585ff259f9a9681e5d68168d1dac66;p=lyx.git diff --git a/src/frontends/qt/GuiInclude.cpp b/src/frontends/qt/GuiInclude.cpp index 5a386547dd..6120d669ef 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" @@ -82,7 +84,9 @@ GuiInclude::GuiInclude(GuiView & lv) bc().addReadOnly(typeCO); bc().addReadOnly(listingsED); - bc().addCheckedLineEdit(filenameED, filenameLA); + // FIXME does not make sense, as we do not have a validator + // for this widget + //bc().addCheckedLineEdit(filenameED, filenameLA); } @@ -291,15 +295,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; } @@ -308,19 +317,24 @@ bool GuiInclude::isValid() int const item = typeCO->currentIndex(); // Are we inputting or including a LyX file? if (item != 0 && item != 1) { - okbutton->setText("OK"); + okbutton->setText(qt_("&OK")); return true; } + + string const bpath = buffer().filePath(); + // Path might be relative to current Buffer, so make absolute + FileName const absfname = support::makeAbsPath(fromqstr(fname), bpath); + // Do we have a LyX filename? - if (!support::isLyXFileName(fromqstr(fname))) { - okbutton->setText("OK"); - return false; + if (!isLyXFileName(fromqstr(fname))) { + okbutton->setText(qt_("&OK")); + return absfname.exists(); } - string const bpath = buffer().filePath(); - QString absfname = makeAbsPath(fname, toqstr(bpath)); - bool const fexists = QFile::exists(absfname); - okbutton->setText(fexists ? "OK" : "Create"); - editPB->setEnabled(fexists); + + // Set OK button text according to whether file already exists + okbutton->setText(absfname.exists() ? qt_("&OK") : qt_("&Create")); + // enable edit button iff file is open in some Buffer + editPB->setEnabled(theBufferList().getBuffer(absfname)); return true; } @@ -384,9 +398,6 @@ void GuiInclude::dispatchParams() } -Dialog * createGuiInclude(GuiView & lv) { return new GuiInclude(lv); } - - } // namespace frontend } // namespace lyx