Source Code (Use browser search to find items of interest.)
Class Index
klyx'MiniBuffer (./klyx/src/minibuffer.h:11)
class MiniBuffer: public QObject {
Q_OBJECT
public:
///
MiniBuffer(LyXView *o);
~MiniBuffer(){};
bool eventFilter( QObject *, QEvent * );
///
bool shows_no_match;
///
void Set(LString const& = LString(),
LString const& = LString(),
LString const& = LString(),
int delay_secs=6);
///
LString GetText() const { return text; }
///
void Init();
///
void ExecCommand();
/** allows to store and reset the contents one time. Usefull
for status messages like "load font" (Matthias)
*/
void Store();
///
void Reset();
///
void Activate();
///
void Deactivate();
void execute();
protected:
void timerEvent( QTimerEvent * );
private:
///
LyXView *owner;
///
LString text;
///
LString text_stored;
///
LString cur_cmd;
///
enum{ MAX_HISTORY = 10 };
///
LString history[MAX_HISTORY];
///
int history_idx, history_cnt;
///
void addHistory(LString const &cmd) {
if (history_cnt==0 || (history_cnt>0 && cmd!=history[history_cnt-1 % MAX_HISTORY])) {
history[history_cnt % MAX_HISTORY] = cmd;
history_cnt++;
}
history_idx = history_cnt;
}
///
LString getHistory() { return history[history_idx % MAX_HISTORY]; }
};
klyx'MiniBuffer::MiniBuffer() (./klyx/src/minibuffer.C:40)
MiniBuffer::MiniBuffer(LyXView *o)
: owner(o)
{
text = i18n("Welcome to LyX!");
shows_no_match = true;
history_idx = history_cnt = 0;
owner->k_mini->installEventFilter(this);
}
klyx'MiniBuffer::execute() (./klyx/src/minibuffer.C:49)
void MiniBuffer::execute()
{
lyxerr.debug("Getting ready to execute: " + cur_cmd);
if (cur_cmd.empty()) {
Init();
return ;
}
Set(i18n("Executing:"), cur_cmd);
addHistory(cur_cmd);
// Split command into function and argument
// This is done wrong Asger. Instead of <function argument>
// it ends up as <argument function> Queer solution:
LString arg = cur_cmd;
LString function;
if (arg.contains(" ")) {
arg.split(function, ' ');
function.strip();
} else {
function = arg;
arg.clean();
}
lyxerr.print("Function: " + function);
lyxerr.print("Arg : " + arg);
// Check if the name is valid (ale)
// No, let the dispatch functions handle that.
//int action = lyxaction.LookupFunc(function.c_str());
//lyxerr.debug(LString("minibuffer action: ") + action);
//if (action>=0) {
// Dispatch only returns requested data for a few commands (ale)
LString res=owner->getLyXFunc()->Dispatch(function.c_str(),
arg.c_str());
lyxerr.print(LString("Minibuffer Res: ") + res);
/* if (!res.empty())
if(owner->getLyXFunc()->errorStat())
Set(i18n("Error:"), _(res.c_str()), "", 4);
else
Set(i18n("Result:"), _(res.c_str()), "", 4);
else
Init();
*/
//} else {
#warning Look at this.
//Set(i18n("Cannot find function"), function, "!");
shows_no_match = false;
//}
return ;
}
klyx'MiniBuffer::timerEvent() (./klyx/src/minibuffer.C:100)
void MiniBuffer::timerEvent( QTimerEvent * ){
Init();
killTimers();
}
klyx'MiniBuffer::ExecCommand() (./klyx/src/minibuffer.C:106)
void MiniBuffer::ExecCommand()
{
text.clean();
owner->k_mini->setFocus();
owner->k_mini->setText(text.c_str());
}
// Added optional arg `delay_secs', defaults to 4.
//When 0, no timeout is done. RVDK_PATCH_5
klyx'MiniBuffer::Set() (./klyx/src/minibuffer.C:117)
void MiniBuffer::Set(LString const& s1, LString const& s2,
LString const& s3, int delay_secs)
{
startTimer(1000 * delay_secs);
LString ntext = s1 + ' ' + s2 + ' ' + s3;
ntext.strip(' ');
if (!owner->k_mini->hasFocus()){
if (ntext != (const char*) owner->k_mini->text())
owner->k_mini->setText(ntext.c_str());
text = ntext;
}
}
klyx'MiniBuffer::Init() (./klyx/src/minibuffer.C:133)
void MiniBuffer::Init()
{
// If we have focus, we don't want to change anything.
if (owner->k_mini->hasFocus())
return;
// When meta-fake key is pressed, show the key sequence so far + "M-".
if (owner->getLyXFunc()->wasMetaKey()) {
text = owner->getLyXFunc()->keyseqStr();
text += " M-";
}
// Else, when a non-complete key sequence is pressed,
// show the available options.
else if (owner->getLyXFunc()->keyseqUncomplete())
text = owner->getLyXFunc()->keyseqOptions();
// Else, show the buffer state.
else {
if (owner->currentView()->available()) {
LString nicename =
MakeDisplayPath(owner->currentBuffer()->
getFileName());
// Should we do this instead? (kindo like emacs)
// leaves more room for other information
text = "LyX: ";
text += nicename;
if (owner->currentBuffer()->lyxvc.inUse()) {
text += " [RCS:";
text += owner->currentBuffer()->lyxvc.getVersion();
text += ' ';
text += owner->currentBuffer()->lyxvc.getLocker();
if (owner->currentBuffer()->isReadonly())
text += " (RO)";
text += ']';
} else if (owner->currentBuffer()->isReadonly())
text += " [RO]";
if (!owner->currentBuffer()->isLyxClean())
text += i18n(" (Changed)").data();
} else {
text = i18n("* No document open *");
}
}
owner->k_mini->setText(text.c_str());
killTimers();
QApplication::flushX();
}
// allows to store and reset the contents one time. Usefull for
// status messages like "load font" (Matthias)
klyx'MiniBuffer::Store() (./klyx/src/minibuffer.C:187)
void MiniBuffer::Store()
{
text_stored = owner->k_mini->text();
}
klyx'MiniBuffer::Reset() (./klyx/src/minibuffer.C:193)
void MiniBuffer::Reset()
{
if (!text_stored.empty()){
Set(text_stored);
text_stored.clean();
}
}
klyx'MiniBuffer::Activate() (./klyx/src/minibuffer.C:201)
void MiniBuffer::Activate()
{
}
klyx'MiniBuffer::Deactivate() (./klyx/src/minibuffer.C:205)
void MiniBuffer::Deactivate()
{
}
klyx'MiniBuffer::eventFilter() (./klyx/src/minibuffer.C:210)
bool MiniBuffer::eventFilter( QObject *o, QEvent *e )
{
if (o != owner->k_mini)
return FALSE;
// 6 is QEvent::KeyPress, works around a name clash
if (e->type() != 6)
return FALSE;
QKeyEvent* ke = (QKeyEvent*)e;
switch (ke->key()){
case Key_Down:
history_idx++;
if (!getHistory().empty()) {
owner->k_mini->setText(getHistory().c_str());
} else
history_idx--;
return TRUE;
break;
case Key_Up:
if (history_idx > 0) history_idx--;
owner->k_mini->setText(getHistory().c_str());
return TRUE;
break;
case Key_Tab:
{
// complete or increment the command
const char *s = lyxaction.getApproxFuncName(owner->k_mini->text());
if (s && s[0])
owner->k_mini->setText(s);
}
return TRUE;
break;
case Key_Escape:
// Abort
owner->currentView()->getKCanvas()->setFocus();
Init();
return TRUE;
break;
case Key_Return:
// Execute a command.
cur_cmd = LString(owner->k_mini->text());
execute();
owner->currentView()->getKCanvas()->setFocus();
return TRUE;
break;
}
return FALSE;
}
klyx'MiniBuffer::getHistory() (./klyx/src/minibuffer.h:77)
LString getHistory() { return history[history_idx % MAX_HISTORY]; }
};