using support::changeExtension;
using support::contains;
using support::FileFilterList;
+using support::FileName;
using support::fileSearch;
using support::ForkedcallsController;
using support::i18nLibFileSearch;
Note that this code is not perfect, as bug 1941 attests:
http://bugzilla.lyx.org/show_bug.cgi?id=1941#c4
*/
- Buffer * buf;
- if (cmd.origin == FuncRequest::UI && !lyx_view_->hasFocus())
+ Buffer * buf = lyx_view_? lyx_view_->buffer() : 0;
+ if (lyx_view_ && cmd.origin == FuncRequest::MENU && !lyx_view_->hasFocus())
buf = 0;
- else
- buf = lyx_view_->buffer();
if (cmd.action == LFUN_NOACTION) {
flag.message(from_utf8(N_("Nothing to do")));
else if (name == "character" || name == "mathpanel")
enable = cur.inset().lyxCode() != InsetBase::ERT_CODE;
else if (name == "latexlog")
- enable = isFileReadable(buf->getLogName().second);
+ enable = isFileReadable(FileName(buf->getLogName().second));
#if !defined (USE_ASPELL) && !defined (USE_ISPELL) && !defined (USE_PSPELL)
else if (name == "spellchecker")
enable = false;
case LFUN_WORD_FIND_FORWARD:
case LFUN_WORD_FIND_BACKWARD: {
BOOST_ASSERT(lyx_view_ && lyx_view_->view());
- static string last_search;
- string searched_string;
+ static docstring last_search;
+ docstring searched_string;
- if (!argument.empty()) {
- last_search = argument;
- searched_string = argument;
+ if (!cmd.argument().empty()) {
+ last_search = cmd.argument();
+ searched_string = cmd.argument();
} else {
searched_string = last_search;
}
break;
bool const fw = action == LFUN_WORD_FIND_FORWARD;
- string const data =
+ docstring const data =
find2string(searched_string, true, false, fw);
find(view(), FuncRequest(LFUN_WORD_FIND, data));
break;
format->extension());
filename = addName(buffer->temppath(), filename);
- if (!buffer->writeFile(filename))
+ if (!buffer->writeFile(FileName(filename)))
break;
} else {
break;
case LFUN_LYX_QUIT:
- if (argument != "force") {
- if (!theApp->gui().closeAll())
- break;
- lyx_view_ = 0;
- }
-
- // FIXME: this code needs to be transfered somewhere else
- // as lyx_view_ will most certainly be null and a same buffer
- // might be visible in more than one LyXView.
- if (lyx_view_ && lyx_view_->view()->buffer()) {
- // save cursor Position for opened files to .lyx/session
- LyX::ref().session().lastFilePos().save(lyx_view_->buffer()->fileName(),
- boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
- }
-
- LyX::ref().quit();
+ // quitting is triggered by the gui code
+ // (leaving the event loop).
+ if (theBufferList().quitWriteAll())
+ theApp()->gui().closeAllViews();
break;
case LFUN_TOC_VIEW: {
setErrorMessage(_("Missing argument"));
break;
}
- string const fname = i18nLibFileSearch("doc", arg, "lyx");
+ FileName const fname = i18nLibFileSearch("doc", arg, "lyx");
if (fname.empty()) {
lyxerr << "LyX: unable to find documentation file `"
<< arg << "'. Bad installation?" << endl;
break;
}
lyx_view_->message(bformat(_("Opening help file %1$s..."),
- makeDisplayPath(fname)));
+ makeDisplayPath(fname.absFilename())));
lyx_view_->loadLyXFile(fname, false);
break;
}
} else {
// Must replace extension of the file to be .lyx
// and get full path
- string const s = changeExtension(file_name, ".lyx");
+ FileName const s = fileSearch(string(), changeExtension(file_name, ".lyx"), "lyx");
// Either change buffer or load the file
- if (theBufferList().exists(s)) {
- lyx_view_->setBuffer(theBufferList().getBuffer(s));
+ if (theBufferList().exists(s.absFilename())) {
+ lyx_view_->setBuffer(theBufferList().getBuffer(s.absFilename()));
} else {
lyx_view_->loadLyXFile(s);
}
name == "bibtex" ||
name == "index" ||
name == "label" ||
+ name == "nomenclature" ||
name == "ref" ||
name == "toc" ||
name == "url") {
if (theBufferList().exists(filename))
lyx_view_->setBuffer(theBufferList().getBuffer(filename));
else
- lyx_view_->loadLyXFile(filename);
+ lyx_view_->loadLyXFile(FileName(filename));
// Set the parent name of the child document.
// This makes insertion of citations and references in the child work,
// when the target is in the parent or another child document.
}
case LFUN_PREFERENCES_SAVE: {
- support::Path p(package().user_support());
- lyxrc.write("preferences", false);
+ lyxrc.write(FileName(makeAbsPath("preferences",
+ package().user_support())),
+ false);
break;
}
break;
}
- theApp->updateColor(lcolor.getFromLyXName(lyx_name));
+ theApp()->updateColor(lcolor.getFromLyXName(lyx_name));
if (graphicsbg_changed) {
#ifdef WITH_WARNINGS
<< endl;
}
- if (defaults.writeFile(defaults.fileName()))
+ if (defaults.writeFile(FileName(defaults.fileName())))
// FIXME Should use bformat
setMessage(_("Document defaults saved in ")
+ makeDisplayPath(fname));
case LFUN_WINDOW_CLOSE:
BOOST_ASSERT(lyx_view_);
- BOOST_ASSERT(theApp);
+ BOOST_ASSERT(theApp());
+ // ask the user for saving changes or cancel quit
+ if (!theBufferList().quitWriteAll())
+ break;
lyx_view_->close();
- // We return here because lyx_view does not exists anymore.
return;
case LFUN_BOOKMARK_GOTO: {
unsigned int idx = convert<unsigned int>(to_utf8(cmd.argument()));
BookmarksSection::Bookmark const bm = LyX::ref().session().bookmarks().bookmark(idx);
BOOST_ASSERT(!bm.filename.empty());
+ string const file = bm.filename.absFilename();
// if the file is not opened, open it.
- if (!theBufferList().exists(bm.filename))
- dispatch(FuncRequest(LFUN_FILE_OPEN, bm.filename));
+ if (!theBufferList().exists(file))
+ dispatch(FuncRequest(LFUN_FILE_OPEN, file));
// open may fail, so we need to test it again
- if (theBufferList().exists(bm.filename)) {
+ if (theBufferList().exists(file)) {
// if the current buffer is not that one, switch to it.
- if (lyx_view_->buffer()->fileName() != bm.filename)
- dispatch(FuncRequest(LFUN_BUFFER_SWITCH, bm.filename));
- // BOOST_ASSERT(lyx_view_->buffer()->fileName() != bm.filename);
+ if (lyx_view_->buffer()->fileName() != file)
+ dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
+ // BOOST_ASSERT(lyx_view_->buffer()->fileName() != file);
view()->moveToPosition(bm.par_id, bm.par_pos);
}
break;
}
if (lyx_view_ && view()->buffer()) {
- // Redraw screen unless explicitly told otherwise.
- // This also initializes the position cache for all insets
- // in (at least partially) visible top-level paragraphs.
- bool needSecondUpdate = false;
- if (updateFlags != Update::None)
- view()->update(updateFlags);
- else
- needSecondUpdate = view()->fitCursor();
-
- if (needSecondUpdate || updateFlags != Update::None) {
+ // BufferView::update() updates the ViewMetricsInfo and
+ // also initializes the position cache for all insets in
+ // (at least partially) visible top-level paragraphs.
+ // We will redraw the screen only if needed.
+ if (view()->update(updateFlags)) {
+ // Buffer::changed() signals that a repaint is needed.
+ // The frontend (WorkArea) knows which area to repaint
+ // thanks to the ViewMetricsInfo updated above.
view()->buffer()->changed();
}
+
lyx_view_->updateStatusBar();
// if we executed a mutating lfun, mark the buffer as dirty
}
}
}
- if (!quitting)
- // FIXME UNICODE: _() does not support anything but ascii.
- // Do we need a to_ascii() method?
+ if (!quitting) {
+ lyx_view_->updateMenubar();
+ lyx_view_->updateToolbars();
sendDispatchMessage(getMessage(), cmd);
+ }
}
void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd)
{
- /* When an action did not originate from the UI/kbd, it makes
- * sense to avoid updating the GUI. It turns out that this
- * fixes bug 1941, for reasons that are described here:
- * http://bugzilla.lyx.org/show_bug.cgi?id=1941#c4
- */
- if (cmd.origin != FuncRequest::INTERNAL) {
- lyx_view_->updateMenubar();
- lyx_view_->updateToolbars();
- }
-
- const bool verbose = (cmd.origin == FuncRequest::UI
+ const bool verbose = (cmd.origin == FuncRequest::MENU
+ || cmd.origin == FuncRequest::TOOLBAR
|| cmd.origin == FuncRequest::COMMANDBUFFER);
if (cmd.action == LFUN_SELF_INSERT || !verbose) {
void LyXFunc::menuNew(string const & name, bool fromTemplate)
{
+ // FIXME: initpath is not used. What to do?
string initpath = lyxrc.document_path;
string filename(name);
if (filename.empty()) {
filename = addName(lyxrc.document_path,
"newfile" + convert<string>(++newfile_number) + ".lyx");
- while (theBufferList().exists(filename) || fs::is_readable(filename)) {
+ while (theBufferList().exists(filename) ||
+ fs::is_readable(FileName(filename).toFilesystemEncoding())) {
++newfile_number;
filename = addName(lyxrc.document_path,
"newfile" + convert<string>(newfile_number) +
// get absolute path of file and add ".lyx" to the filename if
// necessary
- string const fullpath = fileSearch(string(), filename, "lyx");
- if (!fullpath.empty()) {
- filename = fullpath;
- }
-
- docstring const disp_fn = makeDisplayPath(filename);
+ FileName const fullname = fileSearch(string(), filename, "lyx");
+ if (!fullname.empty())
+ filename = fullname.absFilename();
// if the file doesn't exist, let the user create one
- if (!fs::exists(filename)) {
+ if (!fs::exists(fullname.toFilesystemEncoding())) {
// the user specifically chose this name. Believe him.
Buffer * const b = newFile(filename, string(), true);
if (b)
return;
}
+ docstring const disp_fn = makeDisplayPath(filename);
lyx_view_->message(bformat(_("Opening document %1$s..."), disp_fn));
docstring str2;
- if (lyx_view_->loadLyXFile(filename)) {
+ if (lyx_view_->loadLyXFile(fullname)) {
str2 = bformat(_("Document %1$s opened."), disp_fn);
} else {
str2 = bformat(_("Could not open document %1$s"), disp_fn);
return;
// get absolute path of file
- filename = makeAbsPath(filename);
+ FileName const fullname(makeAbsPath(filename));
- string const lyxfile = changeExtension(filename, ".lyx");
+ FileName const lyxfile(changeExtension(fullname.absFilename(), ".lyx"));
// Check if the document already is open
- if (use_gui && theBufferList().exists(lyxfile)) {
- if (!theBufferList().close(theBufferList().getBuffer(lyxfile), true)) {
+ if (use_gui && theBufferList().exists(lyxfile.absFilename())) {
+ if (!theBufferList().close(theBufferList().getBuffer(lyxfile.absFilename()), true)) {
lyx_view_->message(_("Canceled."));
return;
}
// if the file exists already, and we didn't do
// -i lyx thefile.lyx, warn
- if (fs::exists(lyxfile) && filename != lyxfile) {
- docstring const file = makeDisplayPath(lyxfile, 30);
+ if (fs::exists(lyxfile.toFilesystemEncoding()) && fullname != lyxfile) {
+ docstring const file = makeDisplayPath(lyxfile.absFilename(), 30);
docstring text = bformat(_("The document %1$s already exists.\n\n"
"Do you want to over-write that document?"), file);
}
ErrorList errorList;
- Importer::Import(lyx_view_, filename, format, errorList);
+ Importer::Import(lyx_view_, fullname, format, errorList);
// FIXME (Abdel 12/08/06): Is there a need to display the error list here?
}
void LyXFunc::closeBuffer()
{
// save current cursor position
- LyX::ref().session().lastFilePos().save(lyx_view_->buffer()->fileName(),
+ LyX::ref().session().lastFilePos().save(FileName(lyx_view_->buffer()->fileName()),
boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
if (theBufferList().close(lyx_view_->buffer(), true) && !quitting) {
if (theBufferList().empty()) {
case LyXRC::RC_LOADSESSION:
case LyXRC::RC_CHKTEX_COMMAND:
case LyXRC::RC_CONVERTER:
+ case LyXRC::RC_CONVERTER_CACHE_MAXAGE:
case LyXRC::RC_COPIER:
case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
case LyXRC::RC_CUSTOM_EXPORT_COMMAND:
case LyXRC::RC_DISPLAY_GRAPHICS:
case LyXRC::RC_DOCUMENTPATH:
if (lyxrc_orig.document_path != lyxrc_new.document_path) {
- if (fs::exists(lyxrc_new.document_path) &&
- fs::is_directory(lyxrc_new.document_path)) {
+ string const encoded = FileName(
+ lyxrc_new.document_path).toFilesystemEncoding();
+ if (fs::exists(encoded) && fs::is_directory(encoded))
support::package().document_dir() = lyxrc.document_path;
- }
}
case LyXRC::RC_ESC_CHARS:
case LyXRC::RC_FONT_ENCODING:
case LyXRC::RC_USER_NAME:
case LyXRC::RC_USETEMPDIR:
case LyXRC::RC_USE_ALT_LANG:
+ case LyXRC::RC_USE_CONVERTER_CACHE:
case LyXRC::RC_USE_ESC_CHARS:
case LyXRC::RC_USE_INP_ENC:
case LyXRC::RC_USE_PERS_DICT: