From 09b7e6e60aea3644c568212b7dd1f90c85020d2e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sat, 3 Nov 2007 17:37:37 +0000 Subject: [PATCH] some std::string -> filename changes git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21404 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 6 ++++++ src/Buffer.h | 3 +++ src/BufferList.cpp | 6 ++++-- src/BufferList.h | 8 +++++--- src/BufferView.cpp | 5 ++--- src/EmbeddedFiles.cpp | 5 ++--- src/EmbeddedFiles.h | 5 +---- src/LyXFunc.cpp | 7 ++----- src/LyXVC.cpp | 9 ++++----- src/MenuBackend.cpp | 20 +++++++++--------- src/Text3.cpp | 13 ++++++++---- src/factory.cpp | 38 +++++++++++++++-------------------- src/factory.h | 3 +-- src/frontends/qt4/GuiView.cpp | 4 ++-- src/insets/InsetInclude.cpp | 24 +++++++++++----------- src/support/FileName.cpp | 18 +++++++++++++++++ src/support/FileName.h | 11 ++++++++++ 17 files changed, 107 insertions(+), 78 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index fa6dc704f8..38ff64d333 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -1700,6 +1700,12 @@ void Buffer::markDirty() } +FileName Buffer::fileName() const +{ + return pimpl_->filename; +} + + string Buffer::absFileName() const { return pimpl_->filename.absFilename(); diff --git a/src/Buffer.h b/src/Buffer.h index 568a28d162..c3ea3ea4bd 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -236,6 +236,9 @@ public: /// Mark this buffer as dirty. void markDirty(); + /// Returns the buffer's filename. It is always an absolute path. + support::FileName fileName() const; + /// Returns the buffer's filename. It is always an absolute path. std::string absFileName() const; diff --git a/src/BufferList.cpp b/src/BufferList.cpp index e3fb568c7c..24bb2424f0 100644 --- a/src/BufferList.cpp +++ b/src/BufferList.cpp @@ -99,10 +99,12 @@ bool BufferList::quitWriteBuffer(Buffer * buf) BOOST_ASSERT(buf); docstring file; + + // FIXME: Unicode? if (buf->isUnnamed()) - file = from_utf8(onlyFilename(buf->absFileName())); + file = from_utf8(buf->fileName().onlyFileName()); else - file = makeDisplayPath(buf->absFileName(), 30); + file = buf->fileName().displayName(30); docstring const text = bformat(_("The document %1$s has unsaved changes.\n\n" diff --git a/src/BufferList.h b/src/BufferList.h index 2e62754ee7..179cc358bc 100644 --- a/src/BufferList.h +++ b/src/BufferList.h @@ -14,8 +14,6 @@ #include "support/docstring.h" -#include - #include @@ -28,7 +26,7 @@ class OutputParams; * The class holds all all open buffers, and handles construction * and deletions of new ones. */ -class BufferList : boost::noncopyable { +class BufferList { public: typedef std::vector::iterator iterator; typedef std::vector::const_iterator const_iterator; @@ -106,6 +104,10 @@ public: void setCurrentAuthor(docstring const & name, docstring const & email); private: + /// noncopiable + BufferList(BufferList const &); + void operator=(BufferList const &); + /// ask to save a buffer on quit, returns false if should cancel bool quitWriteBuffer(Buffer * buf); diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 388b0c60a9..b538fc0649 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -423,8 +423,7 @@ BufferView::~BufferView() LastFilePosSection::FilePos fp; fp.pit = d->cursor_.bottom().pit(); fp.pos = d->cursor_.bottom().pos(); - LyX::ref().session().lastFilePos().save( - support::FileName(buffer_.absFileName()), fp); + LyX::ref().session().lastFilePos().save(buffer_.fileName(), fp); delete d; } @@ -724,7 +723,7 @@ void BufferView::saveBookmark(unsigned int idx) // pit and pos will be updated with bottom level pit/pos // when lyx exits. LyX::ref().session().bookmarks().save( - FileName(buffer_.absFileName()), + buffer_.fileName(), d->cursor_.bottom().pit(), d->cursor_.bottom().pos(), d->cursor_.paragraph().id(), diff --git a/src/EmbeddedFiles.cpp b/src/EmbeddedFiles.cpp index 97f78d8302..bc7ab0b100 100644 --- a/src/EmbeddedFiles.cpp +++ b/src/EmbeddedFiles.cpp @@ -60,7 +60,6 @@ using support::FileName; using support::DocFileName; using support::makeAbsPath; using support::addName; -using support::onlyPath; using support::absolutePath; using support::onlyFilename; using support::makeRelPath; @@ -155,7 +154,7 @@ bool EmbeddedFile::extract(Buffer const * buf) const // copy file try { // need to make directory? - string path = onlyPath(ext_file); + string path = support::onlyPath(ext_file); if (!fs::is_directory(path)) makedir(const_cast(path.c_str()), 0755); fs::copy_file(emb_file, ext_file, false); @@ -197,7 +196,7 @@ bool EmbeddedFile::updateFromExternalFile(Buffer const * buf) const // copy file try { // need to make directory? - string path = onlyPath(emb_file); + string path = support::onlyPath(emb_file); if (!fs::is_directory(path)) makedir(const_cast(path.c_str()), 0755); fs::copy_file(ext_file, emb_file, false); diff --git a/src/EmbeddedFiles.h b/src/EmbeddedFiles.h index fa4f2e720d..277d9d3638 100644 --- a/src/EmbeddedFiles.h +++ b/src/EmbeddedFiles.h @@ -16,10 +16,6 @@ #include "support/FileName.h" #include -#include - -#include "ParIterator.h" -#include "Paragraph.h" /** @@ -91,6 +87,7 @@ is why external filename will exist even if a file is at "EMBEDDED" status. namespace lyx { class Buffer; +class Inset; class Lexer; class ErrorList; diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 7d369bfd70..f898ba96ca 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -97,7 +97,6 @@ #include "support/os.h" #include -#include #include @@ -110,8 +109,6 @@ using std::ostringstream; using std::find; using std::vector; -namespace fs = boost::filesystem; - namespace lyx { using frontend::LyXView; @@ -604,7 +601,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const enable = buf->lyxvc().inUse(); break; case LFUN_BUFFER_RELOAD: - enable = !buf->isUnnamed() && fs::exists(buf->absFileName()) + enable = !buf->isUnnamed() && buf->fileName().exists() && (!buf->isClean() || buf->isExternallyModified(Buffer::timestamp_method)); break; @@ -856,7 +853,7 @@ bool LyXFunc::ensureBufferClean(BufferView * bv) if (buf.isClean()) return true; - docstring const file = makeDisplayPath(buf.absFileName(), 30); + docstring const file = buf.fileName().displayName(30); docstring text = bformat(_("The document %1$s has unsaved " "changes.\n\nDo you want to save " "the document?"), file); diff --git a/src/LyXVC.cpp b/src/LyXVC.cpp index fca70971f5..af4505a14e 100644 --- a/src/LyXVC.cpp +++ b/src/LyXVC.cpp @@ -32,7 +32,6 @@ namespace lyx { using support::bformat; using support::FileName; using support::makeAbsPath; -using support::makeDisplayPath; using support::tempName; using std::endl; @@ -92,7 +91,7 @@ void LyXVC::setBuffer(Buffer * buf) void LyXVC::registrer() { - FileName const filename(owner_->absFileName()); + FileName const filename = owner_->fileName(); // there must be a file to save if (!filename.isFileReadable()) { @@ -109,14 +108,14 @@ void LyXVC::registrer() if (cvs_entries.isFileReadable()) { LYXERR(Debug::LYXVC) << "LyXVC: registering " - << to_utf8(makeDisplayPath(filename.absFilename())) + << to_utf8(filename.displayName()) << " with CVS" << endl; vcs.reset(new CVS(cvs_entries, filename)); } else { LYXERR(Debug::LYXVC) << "LyXVC: registering " - << to_utf8(makeDisplayPath(filename.absFilename())) + << to_utf8(filename.displayName()) << " with RCS" << endl; vcs.reset(new RCS(filename)); } @@ -166,7 +165,7 @@ void LyXVC::revert() { LYXERR(Debug::LYXVC) << "LyXVC: revert" << endl; - docstring const file = makeDisplayPath(owner_->absFileName(), 20); + docstring const file = owner_->fileName().displayName(20); docstring text = bformat(_("Reverting to the stored version of the " "document %1$s will lose all current changes.\n\n" "Do you want to revert to the saved version?"), file); diff --git a/src/MenuBackend.cpp b/src/MenuBackend.cpp index ac3cbfa339..25772dbde0 100644 --- a/src/MenuBackend.cpp +++ b/src/MenuBackend.cpp @@ -139,16 +139,14 @@ docstring const MenuItem::binding(bool forgui) const // first one later KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(func_); - if (bindings.size()) { + if (bindings.size()) return bindings.begin()->print(KeySequence::ForGui); - } else { - LYXERR(Debug::KBMAP) - << "No binding for " - << lyxaction.getActionName(func_.action) - << '(' << to_utf8(func_.argument()) << ')' << endl; - return docstring(); - } + LYXERR(Debug::KBMAP) + << "No binding for " + << lyxaction.getActionName(func_.action) + << '(' << to_utf8(func_.argument()) << ')' << endl; + return docstring(); } @@ -494,8 +492,9 @@ void expandDocuments(Menu & tomenu) // We cannot use a for loop as the buffer list cycles. do { - docstring label = makeDisplayPath(b->absFileName(), 20); - if (!b->isClean()) label = label + "*"; + docstring label = b->fileName().displayName(20); + if (!b->isClean()) + label = label + "*"; if (ii < 10) label = convert(ii) + ". " + label + '|' + convert(ii); tomenu.add(MenuItem(MenuItem::Command, label, @@ -507,7 +506,6 @@ void expandDocuments(Menu & tomenu) } else { tomenu.add(MenuItem(MenuItem::Command, _("No Documents Open!"), FuncRequest(LFUN_NOACTION))); - return; } } diff --git a/src/Text3.cpp b/src/Text3.cpp index f51106448f..a4dff99a90 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -186,7 +186,7 @@ static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind) static bool doInsertInset(Cursor & cur, Text * text, FuncRequest const & cmd, bool edit, bool pastesel) { - Inset * inset = createInset(&cur.bv(), cmd); + Inset * inset = createInset(cur.bv().buffer(), cmd); if (!inset) return false; @@ -687,7 +687,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) case LFUN_INSET_INSERT: { cur.recordUndo(); - Inset * inset = createInset(bv, cmd); + Inset * inset = createInset(bv->buffer(), cmd); if (inset) { // FIXME (Abdel 01/02/2006): // What follows would be a partial fix for bug 2154: @@ -1144,7 +1144,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) } case LFUN_INFO_INSERT: { - Inset * inset = createInset(&cur.bv(), cmd); + Inset * inset = createInset(cur.bv().buffer(), cmd); if (!inset) break; // if an empty inset is created (cmd.argument() is empty) @@ -1244,8 +1244,13 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) doInsertInset(cur, this, cmd, true, true); cur.posRight(); break; + case LFUN_NOMENCL_INSERT: { - Inset * inset = createInset(&cur.bv(), cmd); + FuncRequest cmd1 = cmd; + if (cmd.argument().empty()) + cmd1 = FuncRequest(cmd, + bv->cursor().innerText()->getStringToIndex(bv->cursor())); + Inset * inset = createInset(cur.bv().buffer(), cmd1); if (!inset) break; cur.recordUndo(); diff --git a/src/factory.cpp b/src/factory.cpp index f38cb450d0..8ddc41b9de 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -13,7 +13,6 @@ #include "factory.h" #include "Buffer.h" -#include "BufferView.h" #include "BufferParams.h" #include "debug.h" #include "FloatList.h" @@ -80,9 +79,9 @@ namespace Alert = frontend::Alert; using support::compare_ascii_no_case; -Inset * createInset(BufferView * bv, FuncRequest const & cmd) +Inset * createInset(Buffer & buf, FuncRequest const & cmd) { - BufferParams const & params = bv->buffer().params(); + BufferParams const & params = buf.params(); try { @@ -154,7 +153,6 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd) if (params.getTextClass().floats().typeExist(argument)) return new InsetFloat(params, argument); lyxerr << "Non-existent float type: " << argument << endl; - return 0; } case LFUN_FLOAT_WIDE_INSERT: { @@ -182,9 +180,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd) case LFUN_NOMENCL_INSERT: { InsetCommandParams icp(NOMENCL_CODE); - icp["symbol"] = cmd.argument().empty() ? - bv->cursor().innerText()->getStringToIndex(bv->cursor()) : - cmd.argument(); + icp["symbol"] = cmd.argument(); return new InsetNomencl(icp); } @@ -198,7 +194,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd) r = 2; if (c <= 0) c = 2; - return new InsetTabular(bv->buffer(), r, c); + return new InsetTabular(buf, r, c); } case LFUN_CAPTION_INSERT: { @@ -267,18 +263,16 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd) } case EXTERNAL_CODE: { - Buffer const & buffer = bv->buffer(); InsetExternalParams iep; - InsetExternalMailer::string2params(to_utf8(cmd.argument()), buffer, iep); + InsetExternalMailer::string2params(to_utf8(cmd.argument()), buf, iep); auto_ptr inset(new InsetExternal); - inset->setParams(iep, buffer); + inset->setParams(iep, buf); return inset.release(); } case GRAPHICS_CODE: { - Buffer const & buffer = bv->buffer(); InsetGraphicsParams igp; - InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer, igp); + InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buf, igp); auto_ptr inset(new InsetGraphics); inset->setParams(igp); return inset.release(); @@ -314,7 +308,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd) case REF_CODE: { InsetCommandParams icp(code); InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp); - return new InsetRef(icp, bv->buffer()); + return new InsetRef(icp, buf); } case TOC_CODE: { @@ -341,21 +335,21 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd) string const name = to_utf8(cmd.argument()); if (name == "normal") return new InsetSpace(InsetSpace::NORMAL); - else if (name == "protected") + if (name == "protected") return new InsetSpace(InsetSpace::PROTECTED); - else if (name == "thin") + if (name == "thin") return new InsetSpace(InsetSpace::THIN); - else if (name == "quad") + if (name == "quad") return new InsetSpace(InsetSpace::QUAD); - else if (name == "qquad") + if (name == "qquad") return new InsetSpace(InsetSpace::QQUAD); - else if (name == "enspace") + if (name == "enspace") return new InsetSpace(InsetSpace::ENSPACE); - else if (name == "enskip") + if (name == "enskip") return new InsetSpace(InsetSpace::ENSKIP); - else if (name == "negthinspace") + if (name == "negthinspace") return new InsetSpace(InsetSpace::NEGTHIN); - else if (name.empty()) + if (name.empty()) lyxerr << "LyX function 'space' needs an argument." << endl; else lyxerr << "Wrong argument for LyX function 'space'." << endl; diff --git a/src/factory.h b/src/factory.h index 65d33b6db0..3dd96f0683 100644 --- a/src/factory.h +++ b/src/factory.h @@ -15,14 +15,13 @@ namespace lyx { class Buffer; -class BufferView; class FuncRequest; class Inset; class Lexer; /// creates inset according to 'cmd' -Inset * createInset(BufferView * bv, FuncRequest const & cmd); +Inset * createInset(Buffer & buf, FuncRequest const & cmd); /// read inset from a file Inset * readInset(Lexer & lex, Buffer const & buf); diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 16e332c022..96b9347d62 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -544,7 +544,7 @@ void GuiViewBase::setWindowTitle(docstring const & t, docstring const & it) } if (Buffer const * buf = buffer()) d.tab_widget_->setTabText(d.tab_widget_->currentIndex(), - toqstr(makeDisplayPath(buf->absFileName(), 30))); + toqstr(buf->fileName().displayName(30))); } @@ -809,7 +809,7 @@ WorkArea * GuiViewBase::addWorkArea(Buffer & buffer) { GuiWorkArea * wa = new GuiWorkArea(buffer, *this); wa->setUpdatesEnabled(false); - d.tab_widget_->addTab(wa, toqstr(makeDisplayPath(buffer.absFileName(), 30))); + d.tab_widget_->addTab(wa, toqstr(buffer.fileName().displayName(30))); wa->bufferView().updateMetrics(false); if (d.stack_widget_) d.stack_widget_->setCurrentWidget(d.tab_widget_); diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index e236ad7036..bc23d534ae 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -67,7 +67,6 @@ using support::isLyXFilename; using support::isValidLaTeXFilename; using support::latex_path; using support::makeAbsPath; -using support::makeDisplayPath; using support::makeRelPath; using support::onlyFilename; using support::onlyPath; @@ -101,7 +100,8 @@ enum Types { }; -Types type(std::string const & s) { +Types type(std::string const & s) +{ if (s == "input") return INPUT; if (s == "verbatiminput") @@ -118,8 +118,7 @@ Types type(std::string const & s) { Types type(InsetCommandParams const & params) { - string const command_name = params.getCmdName(); - return type(command_name); + return type(params.getCmdName()); } @@ -163,8 +162,8 @@ InsetInclude::InsetInclude(InsetInclude const & other) CommandInfo const * InsetInclude::findInfo(std::string const & /* cmdName */) { - //This is only correct for the case of listings, but it'll do for now. - //In the other cases, this second parameter should just be empty. + // This is only correct for the case of listings, but it'll do for now. + // In the other cases, this second parameter should just be empty. static const char * const paramnames[] = {"filename", "lstparams", ""}; static const bool isoptional[] = {false, true}; static const CommandInfo info = {2, paramnames, isoptional}; @@ -172,7 +171,8 @@ CommandInfo const * InsetInclude::findInfo(std::string const & /* cmdName */) } -bool InsetInclude::isCompatibleCommand(std::string const & s) { +bool InsetInclude::isCompatibleCommand(std::string const & s) +{ return type(s) != NONE; } @@ -213,9 +213,9 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd) namespace { -string const masterFilename(Buffer const & buffer) +FileName const masterFileName(Buffer const & buffer) { - return buffer.masterBuffer()->absFileName(); + return buffer.masterBuffer()->fileName(); } @@ -416,7 +416,7 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os, docstring text = bformat(_("Included file `%1$s'\n" "has textclass `%2$s'\n" "while parent file has textclass `%3$s'."), - makeDisplayPath(included_file.absFilename()), + included_file.displayName(), from_utf8(tmp->params().getTextClass().name()), from_utf8(masterBuffer->params().getTextClass().name())); Alert::warning(_("Different textclasses"), text); @@ -438,7 +438,7 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os, docstring text = bformat(_("Included file `%1$s'\n" "uses module `%2$s'\n" "which is not used in parent file."), - makeDisplayPath(included_file.absFilename()), from_utf8(module)); + included_file.displayName(), from_utf8(module)); Alert::warning(_("Module not found"), text); } } @@ -454,7 +454,7 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os, Encoding const * const oldEnc = runparams.encoding; runparams.encoding = &tmp->params().encoding(); tmp->makeLaTeXFile(writefile, - onlyPath(masterFilename(buffer)), + masterFileName(buffer).onlyPath(), runparams, false); runparams.encoding = oldEnc; } else { diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp index 59b53f7fa7..4d54593682 100644 --- a/src/support/FileName.cpp +++ b/src/support/FileName.cpp @@ -116,6 +116,18 @@ bool FileName::isReadable() const } +std::string FileName::onlyFileName() const +{ + return support::onlyFilename(absFilename()); +} + + +std::string FileName::onlyPath() const +{ + return support::onlyPath(absFilename()); +} + + bool FileName::isFileReadable() const { QFileInfo const fi(toqstr(name_)); @@ -175,6 +187,12 @@ bool FileName::createDirectory(int permission) const } +docstring FileName::displayName(int threshold) const +{ + return makeDisplayPath(absFilename(), threshold); +} + + string FileName::fileContents() const { if (exists()) { diff --git a/src/support/FileName.h b/src/support/FileName.h index 33fde2a2db..188fa6bd76 100644 --- a/src/support/FileName.h +++ b/src/support/FileName.h @@ -12,6 +12,8 @@ #ifndef FILENAME_H #define FILENAME_H +#include "strfwd.h" + #include #include @@ -98,6 +100,15 @@ public: /// \p mask must be in filesystem encoding static FileName tempName(FileName const & dir = FileName(), std::string const & mask = std::string()); + + /// filename without path + std::string onlyFileName() const; + /// path without file name + std::string onlyPath() const; + /// used for display in the Gui + docstring displayName(int threshold = 1000) const; + + protected: /// The absolute file name. /// The encoding is currently unspecified, anything else than ASCII -- 2.39.5