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));
}
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;
}
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;
}
}
-Dialog * createGuiInclude(GuiView & lv) { return new GuiInclude(lv); }
-
-
} // namespace frontend
} // namespace lyx