From f370da411306112060c52335dbd33bf28692ddd0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 2 Nov 2007 19:59:08 +0000 Subject: [PATCH] some de-boostification git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21387 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.cpp | 6 ++- src/Session.cpp | 65 +++++++++++++------------ src/Session.h | 81 ++++++++++++++----------------- src/frontends/LyXView.cpp | 7 ++- src/frontends/qt4/GuiToolbar.cpp | 2 + src/frontends/qt4/GuiToolbars.cpp | 32 ++++++------ 6 files changed, 97 insertions(+), 96 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index eee61d6b93..388b0c60a9 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -420,9 +420,11 @@ BufferView::~BufferView() // currently can only handle bottom (whole document) level pit and pos. // That is to say, if a cursor is in a nested inset, it will be // restore to the left of the top level inset. + LastFilePosSection::FilePos fp; + fp.pit = d->cursor_.bottom().pit(); + fp.pos = d->cursor_.bottom().pos(); LyX::ref().session().lastFilePos().save( - support::FileName(buffer_.absFileName()), - boost::tie(d->cursor_.bottom().pit(), d->cursor_.bottom().pos()) ); + support::FileName(buffer_.absFileName()), fp); delete d; } diff --git a/src/Session.cpp b/src/Session.cpp index dc6d0a1c0b..36161e84ea 100644 --- a/src/Session.cpp +++ b/src/Session.cpp @@ -170,13 +170,12 @@ void LastFilePosSection::read(istream & is) try { // read lastfilepos // pos, file\n - pit_type pit; - pos_type pos; + FilePos filepos; string fname; istringstream itmp(tmp); - itmp >> pit; + itmp >> filepos.pit; itmp.ignore(2); // ignore ", " - itmp >> pos; + itmp >> filepos.pos; itmp.ignore(2); // ignore ", " getline(itmp, fname); if (!absolutePath(fname)) @@ -184,7 +183,7 @@ void LastFilePosSection::read(istream & is) FileName const file(fname); if (file.exists() && !file.isDirectory() && lastfilepos.size() < num_lastfilepos) - lastfilepos[file] = boost::tie(pit, pos); + lastfilepos[file] = filepos; else LYXERR(Debug::INIT) << "LyX: Warning: Ignore pos of last file: " << fname << endl; } catch (...) { @@ -199,14 +198,13 @@ void LastFilePosSection::write(ostream & os) const os << '\n' << sec_lastfilepos << '\n'; for (FilePosMap::const_iterator file = lastfilepos.begin(); file != lastfilepos.end(); ++file) { - os << file->second.get<0>() << ", " - << file->second.get<1>() << ", " - << file->first << '\n'; + os << file->second.pit << ", " << file->second.pos << ", " + << file->first << '\n'; } } -void LastFilePosSection::save(FileName const & fname, FilePos pos) +void LastFilePosSection::save(FileName const & fname, FilePos const & pos) { lastfilepos[fname] = pos; } @@ -219,8 +217,7 @@ LastFilePosSection::FilePos LastFilePosSection::load(FileName const & fname) con if (entry != lastfilepos.end()) return entry->second; // Not found, return the first paragraph - else - return 0; + return FilePos(); } @@ -286,7 +283,8 @@ void BookmarksSection::write(ostream & os) const } -void BookmarksSection::save(FileName const & fname, pit_type bottom_pit, pos_type bottom_pos, +void BookmarksSection::save(FileName const & fname, + pit_type bottom_pit, pos_type bottom_pos, int top_id, pos_type top_pos, unsigned int idx) { // silently ignore bookmarks when idx is out of range @@ -321,20 +319,21 @@ void ToolbarSection::read(istream & is) try { // Read session info, saved as key/value pairs // would better yell if pos returns npos - string::size_type pos = tmp.find_first_of(" = "); + size_t pos = tmp.find_first_of(" = "); // silently ignore lines without " = " if (pos != string::npos) { - string key = tmp.substr(0, pos); + ToolbarItem item; + item.key = tmp.substr(0, pos); int state; int location; - int posx; - int posy; istringstream value(tmp.substr(pos + 3)); value >> state; value >> location; - value >> posx; - value >> posy; - toolbars.push_back(boost::make_tuple(key, ToolbarInfo(state, location, posx, posy))); + value >> item.info.posx; + value >> item.info.posy; + item.info.state = ToolbarInfo::State(state); + item.info.location = ToolbarInfo::Location(location); + toolbars.push_back(item); } else LYXERR(Debug::INIT) << "LyX: Warning: Ignore toolbar info: " << tmp << endl; } catch (...) { @@ -351,11 +350,11 @@ void ToolbarSection::write(ostream & os) const os << '\n' << sec_toolbars << '\n'; for (ToolbarList::const_iterator tb = toolbars.begin(); tb != toolbars.end(); ++tb) { - os << tb->get<0>() << " = " - << static_cast(tb->get<1>().state) << " " - << static_cast(tb->get<1>().location) << " " - << tb->get<1>().posx << " " - << tb->get<1>().posy << '\n'; + os << tb->key << " = " + << static_cast(tb->info.state) << " " + << static_cast(tb->info.location) << " " + << tb->info.posx << " " + << tb->info.posy << '\n'; } } @@ -364,18 +363,21 @@ ToolbarSection::ToolbarInfo & ToolbarSection::load(string const & name) { for (ToolbarList::iterator tb = toolbars.begin(); tb != toolbars.end(); ++tb) - if (tb->get<0>() == name) - return tb->get<1>(); + if (tb->key == name) + return tb->info; + // add a new item - toolbars.push_back(boost::make_tuple(name, ToolbarSection::ToolbarInfo())); - return toolbars.back().get<1>(); + ToolbarItem item; + item.key = name; + toolbars.push_back(item); + return toolbars.back().info; } bool operator<(ToolbarSection::ToolbarItem const & a, ToolbarSection::ToolbarItem const & b) { - ToolbarSection::ToolbarInfo lhs = a.get<1>(); - ToolbarSection::ToolbarInfo rhs = b.get<1>(); + ToolbarSection::ToolbarInfo lhs = a.info; + ToolbarSection::ToolbarInfo rhs = b.info; // on if before off if (lhs.state != rhs.state) return static_cast(lhs.state) < static_cast(rhs.state); @@ -389,8 +391,7 @@ bool operator<(ToolbarSection::ToolbarItem const & a, ToolbarSection::ToolbarIte else if (lhs.location == ToolbarSection::ToolbarInfo::LEFT || lhs.location == ToolbarSection::ToolbarInfo::RIGHT) return lhs.posx < rhs.posx || (lhs.posx == rhs.posx && lhs.posy < rhs.posy); - else - return true; + return true; } diff --git a/src/Session.h b/src/Session.h index 119b2a47af..8e18885259 100644 --- a/src/Session.h +++ b/src/Session.h @@ -16,15 +16,12 @@ #include "support/FileName.h" #include "support/types.h" -#include -#include - #include #include #include #include -// used by at least frontends/qt2/QPref.C +// used by at least frontends/qt4/GuiPref.cpp const long maxlastfiles = 20; /** This session file maintains @@ -36,11 +33,13 @@ const long maxlastfiles = 20; */ namespace lyx { -/** base class for all sections in the session file +/* base class for all sections in the session file */ -class SessionSection : boost::noncopyable { - +class SessionSection +{ public: + /// + SessionSection() {} /// virtual ~SessionSection() {} @@ -49,6 +48,11 @@ public: /// write to std::ostream virtual void write(std::ostream & os) const = 0; + +private: + /// uncopiable + SessionSection(SessionSection const &); + void operator=(SessionSection const &); }; @@ -135,7 +139,11 @@ class LastFilePosSection : SessionSection { public: /// - typedef boost::tuple FilePos; + struct FilePos { + FilePos() : pit(0), pos(0) {} + pit_type pit; + pos_type pos; + }; /// typedef std::map FilePosMap; @@ -154,7 +162,7 @@ public: @param fname file entry for which to save position information @param pos position of the cursor when the file is closed. */ - void save(support::FileName const & fname, FilePos pos); + void save(support::FileName const & fname, FilePos const & pos); /** load saved cursor position from the fname entry in the filepos map @param fname file entry for which to load position information @@ -265,15 +273,13 @@ public: { public: /// - ToolbarInfo() : - state(ON), location(NOTSET), posx(0), posy(0) { } + ToolbarInfo() + : state(ON), location(NOTSET), posx(0), posy(0) + {} /// - ToolbarInfo(int s, int loc, int x=0, int y=0) : - state(static_cast(s)), - location(static_cast(loc)), - posx(x), - posy(y) - { } + //ToolbarInfo(int s, int loc, int x = 0, int y = 0) + // : state(State(s)), location(Location(loc)), posx(x), posy(y) + // {} public: enum State { @@ -305,7 +311,10 @@ public: /// potentially, icons }; - typedef boost::tuple ToolbarItem; + struct ToolbarItem { + std::string key; + ToolbarInfo info; + }; /// info for each toolbar typedef std::vector ToolbarList; @@ -337,7 +346,8 @@ private: /// TOP < BOTTOM < LEFT < RIGHT /// Line at each side /// order in each line -bool operator< (ToolbarSection::ToolbarItem const & a, ToolbarSection::ToolbarItem const & b); +bool operator<(ToolbarSection::ToolbarItem const & a, + ToolbarSection::ToolbarItem const & b); class SessionInfoSection : SessionSection @@ -372,55 +382,43 @@ private: }; -class Session : boost::noncopyable { - +class Session +{ public: - /** Read the session file. - @param num length of lastfiles - */ + /// Read the session file. @param num length of lastfiles explicit Session(unsigned int num = 4); - - /** Write the session file. - */ + /// Write the session file. void writeFile() const; - /// LastFilesSection & lastFiles() { return last_files; } - /// LastFilesSection const & lastFiles() const { return last_files; } - /// LastOpenedSection & lastOpened() { return last_opened; } - /// LastOpenedSection const & lastOpened() const { return last_opened; } - /// LastFilePosSection & lastFilePos() { return last_file_pos; } - /// LastFilePosSection const & lastFilePos() const { return last_file_pos; } - /// BookmarksSection & bookmarks() { return bookmarks_; } - /// BookmarksSection const & bookmarks() const { return bookmarks_; } - /// ToolbarSection & toolbars() { return toolbars_; } - /// ToolbarSection const & toolbars() const { return toolbars_; } - /// SessionInfoSection & sessionInfo() { return session_info; } - /// SessionInfoSection const & sessionInfo() const { return session_info; } private: + /// uncopiable + Session(Session const &); + void operator=(Session const &); + /// file to save session, determined in the constructor. support::FileName session_file; @@ -433,19 +431,14 @@ private: /// LastFilesSection last_files; - /// LastOpenedSection last_opened; - /// LastFilePosSection last_file_pos; - /// BookmarksSection bookmarks_; - /// ToolbarSection toolbars_; - /// SessionInfoSection session_info; }; diff --git a/src/frontends/LyXView.cpp b/src/frontends/LyXView.cpp index 4e9157772b..9d9029dd57 100644 --- a/src/frontends/LyXView.cpp +++ b/src/frontends/LyXView.cpp @@ -142,12 +142,11 @@ Buffer * LyXView::loadLyXFile(FileName const & filename, bool tolastfiles) // scroll to the position when the file was last closed if (lyxrc.use_lastfilepos) { - pit_type pit; - pos_type pos; - boost::tie(pit, pos) = LyX::ref().session().lastFilePos().load(filename); + LastFilePosSection::FilePos filepos = + LyX::ref().session().lastFilePos().load(filename); // if successfully move to pit (returned par_id is not zero), // update metrics and reset font - wa->bufferView().moveToPosition(pit, pos, 0, 0); + wa->bufferView().moveToPosition(filepos.pit, filepos.pos, 0, 0); } if (tolastfiles) diff --git a/src/frontends/qt4/GuiToolbar.cpp b/src/frontends/qt4/GuiToolbar.cpp index 9b727beaf7..4f111e2bd7 100644 --- a/src/frontends/qt4/GuiToolbar.cpp +++ b/src/frontends/qt4/GuiToolbar.cpp @@ -43,6 +43,8 @@ #include #include +#include + static void initializeResources() { diff --git a/src/frontends/qt4/GuiToolbars.cpp b/src/frontends/qt4/GuiToolbars.cpp index c2c26cfe9f..3b3effb7bf 100644 --- a/src/frontends/qt4/GuiToolbars.cpp +++ b/src/frontends/qt4/GuiToolbars.cpp @@ -122,28 +122,32 @@ void GuiToolbars::init() initFlags(*cit); // add toolbars according the order in session - ToolbarSection::ToolbarList::const_iterator tb = LyX::ref().session().toolbars().begin(); - ToolbarSection::ToolbarList::const_iterator te = LyX::ref().session().toolbars().end(); - ToolbarSection::ToolbarInfo::Location last_loc = ToolbarSection::ToolbarInfo::NOTSET; + ToolbarSection::ToolbarList::const_iterator tb = + LyX::ref().session().toolbars().begin(); + ToolbarSection::ToolbarList::const_iterator te = + LyX::ref().session().toolbars().end(); + ToolbarSection::ToolbarInfo::Location last_loc = + ToolbarSection::ToolbarInfo::NOTSET; int last_posx = 0; int last_posy = 0; for (; tb != te; ++tb) { - LYXERR(Debug::INIT) << "Adding " << tb->get<0>() << " at position " << tb->get<1>().posx << " " << tb->get<1>().posy << endl; + LYXERR(Debug::INIT) << "Adding " << tb->key << " at position " + << tb->info.posx << " " << tb->info.posy << endl; // add toolbar break if posx or posy changes - bool newline = tb->get<1>().location == last_loc && ( + bool newline = tb->info.location == last_loc && ( // if two toolbars at the same location, assume uninitialized and add toolbar break - (tb->get<1>().posx == last_posx && tb->get<1>().posy == last_posy) || - (last_loc == ToolbarSection::ToolbarInfo::TOP && tb->get<1>().posy != last_posy) || - (last_loc == ToolbarSection::ToolbarInfo::BOTTOM && tb->get<1>().posy != last_posy) || - (last_loc == ToolbarSection::ToolbarInfo::LEFT && tb->get<1>().posx != last_posx) || - (last_loc == ToolbarSection::ToolbarInfo::RIGHT && tb->get<1>().posx != last_posx) ); + (tb->info.posx == last_posx && tb->info.posy == last_posy) || + (last_loc == ToolbarSection::ToolbarInfo::TOP && tb->info.posy != last_posy) || + (last_loc == ToolbarSection::ToolbarInfo::BOTTOM && tb->info.posy != last_posy) || + (last_loc == ToolbarSection::ToolbarInfo::LEFT && tb->info.posx != last_posx) || + (last_loc == ToolbarSection::ToolbarInfo::RIGHT && tb->info.posx != last_posx) ); // find the backend item and add for (cit = toolbarbackend.begin(); cit != end; ++cit) - if (cit->name == tb->get<0>()) { + if (cit->name == tb->key) { add(*cit, newline); - last_loc = tb->get<1>().location; - last_posx = tb->get<1>().posx; - last_posy = tb->get<1>().posy; + last_loc = tb->info.location; + last_posx = tb->info.posx; + last_posy = tb->info.posy; break; } } -- 2.39.5