mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Let LyX remember what documents 'needauth' converters have been authorized to run over by the user.
This is done by moving Converters::auth_files_ into a new SessionSection subclass, along with the same read/write paradigm, as per Enrico's hint.
This commit is contained in:
parent
309209e319
commit
830eb234be
@ -23,6 +23,7 @@
|
|||||||
#include "LaTeX.h"
|
#include "LaTeX.h"
|
||||||
#include "LyXRC.h"
|
#include "LyXRC.h"
|
||||||
#include "Mover.h"
|
#include "Mover.h"
|
||||||
|
#include "Session.h"
|
||||||
|
|
||||||
#include "frontends/alert.h"
|
#include "frontends/alert.h"
|
||||||
|
|
||||||
@ -303,12 +304,13 @@ bool Converters::checkAuth(Converter const & conv, string const & doc_fname)
|
|||||||
int choice;
|
int choice;
|
||||||
if (!doc_fname.empty()) {
|
if (!doc_fname.empty()) {
|
||||||
LYXERR(Debug::FILES, "looking up: " << doc_fname);
|
LYXERR(Debug::FILES, "looking up: " << doc_fname);
|
||||||
if (auth_files_.find(doc_fname) == auth_files_.end()) {
|
std::set<std::string> & auth_files = theSession().authFiles().authFiles();
|
||||||
|
if (auth_files.find(doc_fname) == auth_files.end()) {
|
||||||
choice = frontend::Alert::prompt(security_title,
|
choice = frontend::Alert::prompt(security_title,
|
||||||
bformat(_(security_warning), from_utf8(conv.command())),
|
bformat(_(security_warning), from_utf8(conv.command())),
|
||||||
0, 0, _("Do &NOT run"), _("&Run"), _("&Always run for this document"));
|
0, 0, _("Do &NOT run"), _("&Run"), _("&Always run for this document"));
|
||||||
if (choice == 2)
|
if (choice == 2)
|
||||||
auth_files_.insert(doc_fname);
|
auth_files.insert(doc_fname);
|
||||||
} else {
|
} else {
|
||||||
choice = 1;
|
choice = 1;
|
||||||
}
|
}
|
||||||
|
@ -225,8 +225,6 @@ private:
|
|||||||
bool copy);
|
bool copy);
|
||||||
///
|
///
|
||||||
Graph G_;
|
Graph G_;
|
||||||
/// set of document files authorized for external conversion
|
|
||||||
std::set<std::string> auth_files_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The global instance.
|
/// The global instance.
|
||||||
|
@ -34,6 +34,7 @@ string const sec_bookmarks = "[bookmarks]";
|
|||||||
string const sec_session = "[session info]";
|
string const sec_session = "[session info]";
|
||||||
string const sec_toolbars = "[toolbars]";
|
string const sec_toolbars = "[toolbars]";
|
||||||
string const sec_lastcommands = "[last commands]";
|
string const sec_lastcommands = "[last commands]";
|
||||||
|
string const sec_authfiles = "[auth files]";
|
||||||
|
|
||||||
} // anon namespace
|
} // anon namespace
|
||||||
|
|
||||||
@ -419,6 +420,8 @@ void Session::readFile()
|
|||||||
bookmarks().read(is);
|
bookmarks().read(is);
|
||||||
else if (tmp == sec_lastcommands)
|
else if (tmp == sec_lastcommands)
|
||||||
lastCommands().read(is);
|
lastCommands().read(is);
|
||||||
|
else if (tmp == sec_authfiles)
|
||||||
|
authFiles().read(is);
|
||||||
|
|
||||||
else
|
else
|
||||||
LYXERR(Debug::INIT, "LyX: Warning: unknown Session section: " << tmp);
|
LYXERR(Debug::INIT, "LyX: Warning: unknown Session section: " << tmp);
|
||||||
@ -438,9 +441,43 @@ void Session::writeFile() const
|
|||||||
lastFilePos().write(os);
|
lastFilePos().write(os);
|
||||||
lastCommands().write(os);
|
lastCommands().write(os);
|
||||||
bookmarks().write(os);
|
bookmarks().write(os);
|
||||||
|
authFiles().write(os);
|
||||||
} else
|
} else
|
||||||
LYXERR(Debug::INIT, "LyX: Warning: unable to save Session: "
|
LYXERR(Debug::INIT, "LyX: Warning: unable to save Session: "
|
||||||
<< session_file);
|
<< session_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AuthFilesSection::AuthFilesSection() { }
|
||||||
|
|
||||||
|
|
||||||
|
void AuthFilesSection::read(istream & is)
|
||||||
|
{
|
||||||
|
string tmp;
|
||||||
|
do {
|
||||||
|
char c = is.peek();
|
||||||
|
if (c == '[')
|
||||||
|
break;
|
||||||
|
getline(is, tmp);
|
||||||
|
if (tmp.empty() || tmp[0] == '#' || tmp[0] == ' ' || !FileName::isAbsolute(tmp))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// read lastfiles
|
||||||
|
FileName const file(tmp);
|
||||||
|
if (file.exists() && !file.isDirectory())
|
||||||
|
auth_files_.insert(tmp);
|
||||||
|
else
|
||||||
|
LYXERR(Debug::INIT, "LyX: Warning: Ignore auth file: " << tmp);
|
||||||
|
} while (is.good());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AuthFilesSection::write(ostream & os) const
|
||||||
|
{
|
||||||
|
os << '\n' << sec_authfiles << '\n';
|
||||||
|
copy(auth_files_.begin(), auth_files_.end(),
|
||||||
|
ostream_iterator<std::string>(os, "\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -320,6 +320,27 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class AuthFilesSection : SessionSection
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
///
|
||||||
|
explicit AuthFilesSection();
|
||||||
|
|
||||||
|
///
|
||||||
|
void read(std::istream & is);
|
||||||
|
|
||||||
|
///
|
||||||
|
void write(std::ostream & os) const;
|
||||||
|
|
||||||
|
///
|
||||||
|
std::set<std::string> & authFiles() { return auth_files_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// set of document files authorized for external conversion
|
||||||
|
std::set<std::string> auth_files_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class Session
|
class Session
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -348,6 +369,10 @@ public:
|
|||||||
LastCommandsSection & lastCommands() { return last_commands; }
|
LastCommandsSection & lastCommands() { return last_commands; }
|
||||||
///
|
///
|
||||||
LastCommandsSection const & lastCommands() const { return last_commands; }
|
LastCommandsSection const & lastCommands() const { return last_commands; }
|
||||||
|
///
|
||||||
|
AuthFilesSection & authFiles() { return auth_files; }
|
||||||
|
///
|
||||||
|
AuthFilesSection const & authFiles() const { return auth_files; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class LyX;
|
friend class LyX;
|
||||||
@ -375,6 +400,8 @@ private:
|
|||||||
BookmarksSection bookmarks_;
|
BookmarksSection bookmarks_;
|
||||||
///
|
///
|
||||||
LastCommandsSection last_commands;
|
LastCommandsSection last_commands;
|
||||||
|
///
|
||||||
|
AuthFilesSection auth_files;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This is a singleton class. Get the instance.
|
/// This is a singleton class. Get the instance.
|
||||||
|
Loading…
Reference in New Issue
Block a user