]> git.lyx.org Git - lyx.git/blobdiff - src/Session.cpp
revert erroneous previous commit.
[lyx.git] / src / Session.cpp
index 839ec38ada5a94e7892cfa5c5db1de66753d21c8..f09d2f6b73b87de539420c485d2052b792ddac90 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  * \author Bo Peng
  *
  * Full author contact details are available in file CREDITS.
 #include <config.h>
 
 #include "Session.h"
+
 #include "support/debug.h"
-#include "support/Package.h"
 #include "support/filetools.h"
+#include "support/Package.h"
 
 #include <fstream>
 #include <sstream>
 #include <algorithm>
 #include <iterator>
 
-using lyx::support::absolutePath;
-using lyx::support::addName;
-using lyx::support::FileName;
-using lyx::support::package;
-
-using std::vector;
-using std::getline;
-using std::string;
-using std::ifstream;
-using std::ofstream;
-using std::istream;
-using std::ostream;
-using std::endl;
-using std::istringstream;
-using std::copy;
-using std::find;
-using std::ostream_iterator;
+using namespace std;
+using namespace lyx::support;
 
 namespace {
 
@@ -53,6 +39,7 @@ string const sec_toolbars = "[toolbars]";
 
 namespace lyx {
 
+
 LastFilesSection::LastFilesSection(unsigned int num) :
        default_num_last_files(4),
        absolute_max_last_files(100)
@@ -69,11 +56,11 @@ void LastFilesSection::read(istream & is)
                if (c == '[')
                        break;
                getline(is, tmp);
-               if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ' || !absolutePath(tmp))
+               FileName const file(tmp);
+               if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ' || !file.isAbsolute())
                        continue;
 
                // read lastfiles
-               FileName const file(tmp);
                if (file.exists() && !file.isDirectory()
                    && lastfiles.size() < num_lastfiles)
                        lastfiles.push_back(file);
@@ -123,10 +110,10 @@ void LastOpenedSection::read(istream & is)
                if (c == '[')
                        break;
                getline(is, tmp);
-               if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ' || !absolutePath(tmp))
+               FileName const file(tmp);
+               if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ' || !file.isAbsolute())
                        continue;
 
-               FileName const file(tmp);
                if (file.exists() && !file.isDirectory())
                        lastopened.push_back(file);
                else
@@ -177,9 +164,9 @@ void LastFilePosSection::read(istream & is)
                        itmp >> filepos.pos;
                        itmp.ignore(2);  // ignore ", "
                        getline(itmp, fname);
-                       if (!absolutePath(fname))
-                               continue;
                        FileName const file(fname);
+                       if (!file.isAbsolute())
+                               continue;
                        if (file.exists() && !file.isDirectory()
                            && lastfilepos.size() < num_lastfilepos)
                                lastfilepos[file] = filepos;
@@ -254,9 +241,9 @@ void BookmarksSection::read(istream & is)
                        itmp >> pos;
                        itmp.ignore(2);  // ignore ", "
                        getline(itmp, fname);
-                       if (!absolutePath(fname))
-                               continue;
                        FileName const file(fname);
+                       if (!file.isAbsolute())
+                               continue;
                        // only load valid bookmarks
                        if (file.exists() && !file.isDirectory() && idx <= max_bookmarks)
                                bookmarks[idx] = Bookmark(file, pit, pos, 0, 0);
@@ -304,153 +291,6 @@ BookmarksSection::Bookmark const & BookmarksSection::bookmark(unsigned int i) co
 }
 
 
-void ToolbarSection::read(istream & is)
-{
-       string tmp;
-       do {
-               char c = is.peek();
-               if (c == '[')
-                       break;
-               getline(is, tmp);
-               if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ')
-                       continue;
-
-               try {
-                       // Read session info, saved as key/value pairs
-                       // would better yell if pos returns npos
-                       size_t pos = tmp.find_first_of(" = ");
-                       // silently ignore lines without " = "
-                       if (pos != string::npos) {
-                               ToolbarItem item;
-                               item.key = tmp.substr(0, pos);
-                               int state;
-                               int location;
-                               istringstream value(tmp.substr(pos + 3));
-                               value >> state;
-                               value >> location;
-                               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);
-               } catch (...) {
-                       LYXERR(Debug::INIT, "LyX: Warning: unknown Toolbar info: " << tmp);
-               }
-       } while (is.good());
-       // sort the toolbars by location, line and position
-       std::sort(toolbars.begin(), toolbars.end());
-}
-
-
-void ToolbarSection::write(ostream & os) const
-{
-       os << '\n' << sec_toolbars << '\n';
-       for (ToolbarList::const_iterator tb = toolbars.begin();
-               tb != toolbars.end(); ++tb) {
-               os << tb->key << " = "
-                 << static_cast<int>(tb->info.state) << " "
-                 << static_cast<int>(tb->info.location) << " "
-                 << tb->info.posx << " "
-                 << tb->info.posy << '\n';
-       }
-}
-
-
-ToolbarSection::ToolbarInfo & ToolbarSection::load(string const & name)
-{
-       for (ToolbarList::iterator tb = toolbars.begin();
-               tb != toolbars.end(); ++tb)
-               if (tb->key == name)
-                       return tb->info;
-
-       // add a new item
-       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.info;
-       ToolbarSection::ToolbarInfo rhs = b.info;
-       // on if before off
-       if (lhs.state != rhs.state)
-               return static_cast<int>(lhs.state) < static_cast<int>(rhs.state);
-       // order of dock does not really matter
-       if (lhs.location != rhs.location)
-               return static_cast<int>(lhs.location) < static_cast<int>(rhs.location);
-       // if the same dock, the order depends on position
-       if (lhs.location == ToolbarSection::ToolbarInfo::TOP ||
-               lhs.location == ToolbarSection::ToolbarInfo::BOTTOM)
-               return lhs.posy < rhs.posy || (lhs.posy == rhs.posy && lhs.posx < rhs.posx);
-       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);
-       return true;
-}
-
-
-void SessionInfoSection::read(istream & is)
-{
-       string tmp;
-       do {
-               char c = is.peek();
-               if (c == '[')
-                       break;
-               getline(is, tmp);
-               if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ')
-                       continue;
-
-               try {
-                       // Read session info, saved as key/value pairs
-                       // would better yell if pos returns npos
-                       string::size_type pos = tmp.find_first_of(" = ");
-                       // silently ignore lines without " = "
-                       if (pos != string::npos) {
-                               string key = tmp.substr(0, pos);
-                               string value = tmp.substr(pos + 3);
-                               sessioninfo[key] = value;
-                       } else
-                               LYXERR(Debug::INIT, "LyX: Warning: Ignore session info: " << tmp);
-               } catch (...) {
-                       LYXERR(Debug::INIT, "LyX: Warning: unknown Session info: " << tmp);
-               }
-       } while (is.good());
-}
-
-
-void SessionInfoSection::write(ostream & os) const
-{
-       os << '\n' << sec_session << '\n';
-       for (MiscInfo::const_iterator val = sessioninfo.begin();
-               val != sessioninfo.end(); ++val) {
-               os << val->first << " = " << val->second << '\n';
-       }
-}
-
-
-void SessionInfoSection::save(string const & key, string const & value)
-{
-       sessioninfo[key] = value;
-}
-
-
-string const SessionInfoSection::load(string const & key, bool release)
-{
-       MiscInfo::const_iterator pos = sessioninfo.find(key);
-       string value;
-       if (pos != sessioninfo.end())
-               value = pos->second;
-       if (release)
-               sessioninfo.erase(key);
-       return value;
-}
-
-
 Session::Session(unsigned int num) :
        last_files(num)
 {
@@ -483,10 +323,6 @@ void Session::readFile()
                        lastFilePos().read(is);
                else if (tmp == sec_bookmarks)
                        bookmarks().read(is);
-               else if (tmp == sec_toolbars)
-                       toolbars().read(is);
-               else if (tmp == sec_session)
-                       sessionInfo().read(is);
                else
                        LYXERR(Debug::INIT, "LyX: Warning: unknown Session section: " << tmp);
        }
@@ -504,8 +340,6 @@ void Session::writeFile() const
                lastOpened().write(os);
                lastFilePos().write(os);
                bookmarks().write(os);
-               toolbars().write(os);
-               sessionInfo().write(os);
        } else
                LYXERR(Debug::INIT, "LyX: Warning: unable to save Session: "
                       << session_file);