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 "LyXRC.h"
|
||||
#include "Mover.h"
|
||||
#include "Session.h"
|
||||
|
||||
#include "frontends/alert.h"
|
||||
|
||||
@ -303,12 +304,13 @@ bool Converters::checkAuth(Converter const & conv, string const & doc_fname)
|
||||
int choice;
|
||||
if (!doc_fname.empty()) {
|
||||
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,
|
||||
bformat(_(security_warning), from_utf8(conv.command())),
|
||||
0, 0, _("Do &NOT run"), _("&Run"), _("&Always run for this document"));
|
||||
if (choice == 2)
|
||||
auth_files_.insert(doc_fname);
|
||||
auth_files.insert(doc_fname);
|
||||
} else {
|
||||
choice = 1;
|
||||
}
|
||||
|
@ -225,8 +225,6 @@ private:
|
||||
bool copy);
|
||||
///
|
||||
Graph G_;
|
||||
/// set of document files authorized for external conversion
|
||||
std::set<std::string> auth_files_;
|
||||
};
|
||||
|
||||
/// The global instance.
|
||||
|
@ -34,6 +34,7 @@ string const sec_bookmarks = "[bookmarks]";
|
||||
string const sec_session = "[session info]";
|
||||
string const sec_toolbars = "[toolbars]";
|
||||
string const sec_lastcommands = "[last commands]";
|
||||
string const sec_authfiles = "[auth files]";
|
||||
|
||||
} // anon namespace
|
||||
|
||||
@ -419,6 +420,8 @@ void Session::readFile()
|
||||
bookmarks().read(is);
|
||||
else if (tmp == sec_lastcommands)
|
||||
lastCommands().read(is);
|
||||
else if (tmp == sec_authfiles)
|
||||
authFiles().read(is);
|
||||
|
||||
else
|
||||
LYXERR(Debug::INIT, "LyX: Warning: unknown Session section: " << tmp);
|
||||
@ -438,9 +441,43 @@ void Session::writeFile() const
|
||||
lastFilePos().write(os);
|
||||
lastCommands().write(os);
|
||||
bookmarks().write(os);
|
||||
authFiles().write(os);
|
||||
} else
|
||||
LYXERR(Debug::INIT, "LyX: Warning: unable to save Session: "
|
||||
<< 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
|
||||
{
|
||||
public:
|
||||
@ -348,6 +369,10 @@ public:
|
||||
LastCommandsSection & lastCommands() { return last_commands; }
|
||||
///
|
||||
LastCommandsSection const & lastCommands() const { return last_commands; }
|
||||
///
|
||||
AuthFilesSection & authFiles() { return auth_files; }
|
||||
///
|
||||
AuthFilesSection const & authFiles() const { return auth_files; }
|
||||
|
||||
private:
|
||||
friend class LyX;
|
||||
@ -375,6 +400,8 @@ private:
|
||||
BookmarksSection bookmarks_;
|
||||
///
|
||||
LastCommandsSection last_commands;
|
||||
///
|
||||
AuthFilesSection auth_files;
|
||||
};
|
||||
|
||||
/// This is a singleton class. Get the instance.
|
||||
|
Loading…
Reference in New Issue
Block a user