diff --git a/src/frontends/qt/GuiInclude.cpp b/src/frontends/qt/GuiInclude.cpp index f2783519d9..5949d17153 100644 --- a/src/frontends/qt/GuiInclude.cpp +++ b/src/frontends/qt/GuiInclude.cpp @@ -296,24 +296,9 @@ void GuiInclude::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 + // 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)); } @@ -321,8 +306,7 @@ void GuiInclude::edit() 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; } @@ -335,15 +319,17 @@ bool GuiInclude::isValid() return true; } // Do we have a LyX filename? - if (!support::isLyXFileName(fromqstr(fname))) { + if (!isLyXFileName(fromqstr(fname))) { okbutton->setText("OK"); return false; } 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); + // 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 + okbutton->setText(absfname.exists() ? "OK" : "Create"); + // enable edit button iff file is open in some Buffer + editPB->setEnabled(theBufferList().getBuffer(absfname)); return true; }