]> git.lyx.org Git - features.git/blobdiff - src/frontends/qt/GuiInclude.cpp
Show suggestions containing the input in the command buffer
[features.git] / src / frontends / qt / GuiInclude.cpp
index f2783519d9cfa91f749ec438f317265cb0a7a2fc..3d4f3dde1b9282e64fd62b94a8eea740ecdda3b1 100644 (file)
@@ -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;
        }
@@ -331,19 +315,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;
 }
 
@@ -407,9 +396,6 @@ void GuiInclude::dispatchParams()
 }
 
 
-Dialog * createGuiInclude(GuiView & lv) { return new GuiInclude(lv); }
-
-
 } // namespace frontend
 } // namespace lyx