mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
CmdDef:
- deboostification - correct comments git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21931 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
0743f576cb
commit
4cd6123095
@ -13,7 +13,6 @@
|
|||||||
# DO NOT CHANGE THIS DEFAULT COMMAND DEFINITION FILE! It will be replaced
|
# DO NOT CHANGE THIS DEFAULT COMMAND DEFINITION FILE! It will be replaced
|
||||||
# with every new install of LyX and your changes will be lost.
|
# with every new install of LyX and your changes will be lost.
|
||||||
# Instead, customize a copy of this file placed in
|
# Instead, customize a copy of this file placed in
|
||||||
# ~/.lyx/commands/default.bind
|
# ~/.lyx/commands/default.def
|
||||||
#
|
#
|
||||||
# Happy tuning!
|
# Happy tuning!
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::string;
|
using std::string;
|
||||||
@ -62,8 +63,6 @@ bool CmdDef::read(string const & def_file)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//LYXERR(Debug::KBMAP, "Reading def file:" << tmp);
|
|
||||||
|
|
||||||
bool error = false;
|
bool error = false;
|
||||||
while (lexrc.isOK()) {
|
while (lexrc.isOK()) {
|
||||||
switch (lexrc.lex()) {
|
switch (lexrc.lex()) {
|
||||||
@ -133,47 +132,36 @@ bool CmdDef::read(string const & def_file)
|
|||||||
|
|
||||||
bool CmdDef::lock(string const & name, FuncRequest & func)
|
bool CmdDef::lock(string const & name, FuncRequest & func)
|
||||||
{
|
{
|
||||||
if (cmdDefMap.empty())
|
if (cmdDefMap.empty()) {
|
||||||
{
|
|
||||||
func = FuncRequest::unknown;
|
func = FuncRequest::unknown;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string const name2 = trim(name);
|
string const name2 = trim(name);
|
||||||
|
|
||||||
CmdDefMap::const_iterator pos = cmdDefMap.find(name2);
|
if (lockSet.find(name2) != lockSet.end()) {
|
||||||
|
|
||||||
if (pos == cmdDefMap.end())
|
|
||||||
{
|
|
||||||
func = FuncRequest::unknown;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pos->second->locked)
|
|
||||||
{
|
|
||||||
func = FuncRequest::noaction;
|
func = FuncRequest::noaction;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos->second->locked = true;
|
CmdDefMap::const_iterator pos = cmdDefMap.find(name2);
|
||||||
func = pos->second->func;
|
|
||||||
|
if (pos == cmdDefMap.end()) {
|
||||||
|
func = FuncRequest::unknown;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
lockSet.insert(name2);
|
||||||
|
func = pos->second;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CmdDef::release(string const & name)
|
void CmdDef::release(string const & name)
|
||||||
{
|
{
|
||||||
if (cmdDefMap.empty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
string const name2 = trim(name);
|
string const name2 = trim(name);
|
||||||
|
|
||||||
CmdDefMap::const_iterator pos = cmdDefMap.find(name2);
|
lockSet.erase(name2);
|
||||||
|
|
||||||
if (pos == cmdDefMap.end())
|
|
||||||
return;
|
|
||||||
|
|
||||||
pos->second->locked = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CmdDef::newCmdDefResult CmdDef::newCmdDef(string const & name,
|
CmdDef::newCmdDefResult CmdDef::newCmdDef(string const & name,
|
||||||
@ -193,9 +181,7 @@ CmdDef::newCmdDefResult CmdDef::newCmdDef(string const & name,
|
|||||||
return CmdDefInvalid;
|
return CmdDefInvalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::shared_ptr<CmdDefInfo> info;
|
cmdDefMap[name2] = func;
|
||||||
info.reset(new CmdDefInfo(func));
|
|
||||||
cmdDefMap[name2] = info;
|
|
||||||
|
|
||||||
return CmdDefOk;
|
return CmdDefOk;
|
||||||
}
|
}
|
||||||
|
24
src/CmdDef.h
24
src/CmdDef.h
@ -16,30 +16,18 @@
|
|||||||
|
|
||||||
#include "support/strfwd.h"
|
#include "support/strfwd.h"
|
||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <set>
|
||||||
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
/// Creates command definitions
|
/// Creates command definitions
|
||||||
class CmdDef {
|
class CmdDef {
|
||||||
private:
|
private:
|
||||||
/// information for a definition
|
|
||||||
struct CmdDefInfo {
|
|
||||||
CmdDefInfo(FuncRequest const & f): func(f), locked(false) {}
|
|
||||||
/// the expanded FuncRequest
|
|
||||||
FuncRequest func;
|
|
||||||
/// to avoid recursive calls
|
|
||||||
bool locked;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// type for map between a macro name and its info
|
/// type for map between a macro name and its info
|
||||||
typedef std::map<std::string, boost::shared_ptr<CmdDefInfo> > CmdDefMap;
|
typedef std::map<std::string, FuncRequest> CmdDefMap;
|
||||||
|
/// type for a set containing all locked definitions
|
||||||
|
typedef std::set<std::string> LockSet;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Parse a def file
|
/// Parse a def file
|
||||||
@ -72,10 +60,12 @@ private:
|
|||||||
* @param name internal recursion level
|
* @param name internal recursion level
|
||||||
*/
|
*/
|
||||||
newCmdDefResult newCmdDef(std::string const & name,
|
newCmdDefResult newCmdDef(std::string const & name,
|
||||||
std::string const & def);
|
std::string const & def);
|
||||||
|
|
||||||
///
|
///
|
||||||
CmdDefMap cmdDefMap;
|
CmdDefMap cmdDefMap;
|
||||||
|
///
|
||||||
|
LockSet lockSet;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Implementation is in LyX.cpp
|
/// Implementation is in LyX.cpp
|
||||||
|
@ -2398,8 +2398,7 @@ string const LyXRC::getDescription(LyXRCTags tag)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case RC_DEFFILE:
|
case RC_DEFFILE:
|
||||||
//FIXME: fix description.
|
str = _("Command definition file. Can either specify an absolute path, or LyX will look in its global and local commands/ directories.");
|
||||||
str = _("Command definition file.");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RC_DEFAULT_LANGUAGE:
|
case RC_DEFAULT_LANGUAGE:
|
||||||
|
Loading…
Reference in New Issue
Block a user