1999-09-27 18:44:28 +00:00
|
|
|
/* ###########################################################################
|
|
|
|
*
|
|
|
|
* The MiniBuffer Class
|
|
|
|
* read minibuffer.h for more
|
|
|
|
* information.
|
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
2000-03-16 04:29:22 +00:00
|
|
|
* Copyright 1995-2000 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* ###########################################################################
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation "minibuffer.h"
|
|
|
|
#endif
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/filetools.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyx_main.h"
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
#include "minibuffer.h"
|
|
|
|
#include "LyXView.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "gettext.h"
|
1999-11-22 16:19:48 +00:00
|
|
|
#include "LyXAction.h"
|
2000-04-08 17:02:02 +00:00
|
|
|
#include "BufferView.h"
|
|
|
|
#include "buffer.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
extern bool keyseqUncomplete();
|
1999-11-15 12:01:38 +00:00
|
|
|
extern string keyseqOptions(int l= 190);
|
|
|
|
extern string keyseqStr(int l= 190);
|
1999-09-27 18:44:28 +00:00
|
|
|
extern LyXAction lyxaction;
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
MiniBuffer::MiniBuffer(LyXView * o, FL_Coord x, FL_Coord y,
|
|
|
|
FL_Coord h, FL_Coord w)
|
|
|
|
: owner(o)
|
|
|
|
{
|
|
|
|
text = _("Welcome to LyX!");
|
|
|
|
shows_no_match = true;
|
|
|
|
history_idx = history_cnt = 0;
|
|
|
|
add(FL_NORMAL_INPUT, x, y, h, w);
|
|
|
|
}
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
void MiniBuffer::TimerCB(FL_OBJECT * ob, long)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
MiniBuffer * obj = static_cast<MiniBuffer*>(ob->u_vdata);
|
1999-09-27 18:44:28 +00:00
|
|
|
obj->Init();
|
|
|
|
}
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
extern "C" void C_MiniBuffer_TimerCB(FL_OBJECT * ob, long data)
|
1999-10-25 14:18:30 +00:00
|
|
|
{
|
|
|
|
MiniBuffer::TimerCB(ob, data);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
void MiniBuffer::ExecutingCB(FL_OBJECT * ob, long)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
MiniBuffer * obj = static_cast<MiniBuffer*>(ob->u_vdata);
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "Getting ready to execute: " << obj->cur_cmd << endl;
|
2000-02-10 17:53:36 +00:00
|
|
|
obj->owner->view()->focus(true);
|
2000-02-15 14:28:15 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
if (obj->cur_cmd.empty()) {
|
|
|
|
obj->Init();
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
obj->Set(_("Executing:"), obj->cur_cmd);
|
|
|
|
obj->addHistory(obj->cur_cmd);
|
|
|
|
|
1999-10-24 00:57:04 +00:00
|
|
|
// Dispatch only returns requested data for a few commands (ale)
|
1999-11-18 14:12:19 +00:00
|
|
|
string res = obj->owner->getLyXFunc()->Dispatch(obj->cur_cmd);
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "Minibuffer Res: " << res << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
obj->shows_no_match = false;
|
|
|
|
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
extern "C" void C_MiniBuffer_ExecutingCB(FL_OBJECT * ob, long data)
|
1999-10-25 14:18:30 +00:00
|
|
|
{
|
|
|
|
MiniBuffer::TimerCB(ob, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is not as dirty as it seems, the hidden buttons removed by this
|
|
|
|
// function were just kludges for an uncomplete keyboard callback (ale)
|
1999-11-09 23:52:04 +00:00
|
|
|
int MiniBuffer::peek_event(FL_OBJECT * ob, int event, FL_Coord, FL_Coord,
|
1999-10-25 14:18:30 +00:00
|
|
|
int key, void */*xev*/)
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
MiniBuffer * mini = static_cast<MiniBuffer*>(ob->u_vdata);
|
1999-10-25 14:18:30 +00:00
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
if (event == FL_KEYBOARD){
|
1999-10-25 14:18:30 +00:00
|
|
|
switch (key) {
|
|
|
|
case XK_Down:
|
|
|
|
mini->history_idx++;
|
|
|
|
if (!mini->getHistory().empty()) {
|
|
|
|
fl_set_input(ob, mini->getHistory().c_str());
|
|
|
|
} else
|
|
|
|
mini->history_idx--;
|
|
|
|
return 1;
|
|
|
|
case XK_Up:
|
|
|
|
if (mini->history_idx > 0) mini->history_idx--;
|
|
|
|
fl_set_input(ob, mini->getHistory().c_str());
|
|
|
|
return 1;
|
|
|
|
case 9:
|
|
|
|
case XK_Tab:
|
|
|
|
{
|
|
|
|
// complete or increment the command
|
1999-11-22 16:19:48 +00:00
|
|
|
string s = lyxaction.getApproxFuncName(fl_get_input(ob));
|
|
|
|
if (!s.empty())
|
|
|
|
fl_set_input(ob, s.c_str());
|
1999-10-25 14:18:30 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case 27:
|
|
|
|
case XK_Escape:
|
|
|
|
// Abort
|
2000-02-10 17:53:36 +00:00
|
|
|
mini->owner->view()->focus(true);
|
1999-10-25 14:18:30 +00:00
|
|
|
mini->Init();
|
|
|
|
return 1;
|
|
|
|
case 13:
|
|
|
|
case XK_Return:
|
|
|
|
// Execute a command.
|
|
|
|
mini->cur_cmd = string(fl_get_input(ob));
|
|
|
|
ExecutingCB(ob, 0);
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
extern "C" int C_MiniBuffer_peek_event(FL_OBJECT * ob, int event,
|
1999-10-25 14:18:30 +00:00
|
|
|
FL_Coord, FL_Coord,
|
1999-11-09 23:52:04 +00:00
|
|
|
int key, void * xev)
|
1999-10-25 14:18:30 +00:00
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
return MiniBuffer::peek_event(ob, event, 0, 0, key, xev);
|
1999-10-25 14:18:30 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
void MiniBuffer::ExecCommand()
|
|
|
|
{
|
1999-10-19 20:59:27 +00:00
|
|
|
text.clear();
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_input(the_buffer, "");
|
1999-11-15 12:01:38 +00:00
|
|
|
fl_set_focus_object(owner->getForm(), the_buffer);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
FL_OBJECT * MiniBuffer::add(int type, FL_Coord x, FL_Coord y,
|
1999-09-27 18:44:28 +00:00
|
|
|
FL_Coord w, FL_Coord h)
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
FL_OBJECT * obj;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
the_buffer = obj = fl_add_input(type, x, y, w, h, text.c_str());
|
|
|
|
fl_set_object_boxtype(obj, FL_DOWN_BOX);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_object_resize(obj, FL_RESIZE_ALL);
|
|
|
|
fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
|
1999-11-15 12:01:38 +00:00
|
|
|
fl_set_object_color(obj, FL_MCOL, FL_MCOL);
|
|
|
|
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
|
|
|
|
fl_set_object_callback(obj, C_MiniBuffer_ExecutingCB, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// To intercept Up, Down, Table for history
|
1999-10-25 14:18:30 +00:00
|
|
|
fl_set_object_prehandler(obj, C_MiniBuffer_peek_event);
|
1999-11-09 23:52:04 +00:00
|
|
|
obj->u_vdata = this;
|
1999-09-27 18:44:28 +00:00
|
|
|
obj->wantkey = FL_KEY_TAB;
|
|
|
|
|
|
|
|
// timer
|
1999-11-15 12:01:38 +00:00
|
|
|
timer = fl_add_timer(FL_HIDDEN_TIMER, 0, 0, 0, 0, "Timer");
|
1999-11-09 23:52:04 +00:00
|
|
|
fl_set_object_callback(timer, C_MiniBuffer_TimerCB, 0);
|
|
|
|
timer->u_vdata = this;
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_input(the_buffer, text.c_str());
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Added optional arg `delay_secs', defaults to 4.
|
|
|
|
//When 0, no timeout is done. RVDK_PATCH_5
|
1999-10-02 16:21:10 +00:00
|
|
|
void MiniBuffer::Set(string const& s1, string const& s2,
|
|
|
|
string const& s3, int delay_secs)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
setTimer(delay_secs);
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string ntext = strip(s1 + ' ' + s2 + ' ' + s3);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!the_buffer->focus) {
|
|
|
|
fl_set_input(the_buffer, ntext.c_str());
|
|
|
|
XFlush(fl_display);
|
|
|
|
text = ntext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MiniBuffer::Init()
|
|
|
|
{
|
|
|
|
// If we have focus, we don't want to change anything.
|
|
|
|
if (the_buffer->focus)
|
|
|
|
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.
|
1999-11-22 16:19:48 +00:00
|
|
|
else if (owner->view()->available()) {
|
1999-11-15 12:01:38 +00:00
|
|
|
string nicename =
|
1999-11-09 23:52:04 +00:00
|
|
|
MakeDisplayPath(owner->buffer()->
|
1999-12-10 00:07:59 +00:00
|
|
|
fileName());
|
1999-09-27 18:44:28 +00:00
|
|
|
// Should we do this instead? (kindo like emacs)
|
|
|
|
// leaves more room for other information
|
|
|
|
text = "LyX: ";
|
|
|
|
text += nicename;
|
1999-11-09 23:52:04 +00:00
|
|
|
if (owner->buffer()->lyxvc.inUse()) {
|
|
|
|
text += " [";
|
|
|
|
text += owner->buffer()->lyxvc.version();
|
1999-09-27 18:44:28 +00:00
|
|
|
text += ' ';
|
1999-11-09 23:52:04 +00:00
|
|
|
text += owner->buffer()->lyxvc.locker();
|
|
|
|
if (owner->buffer()->isReadonly())
|
1999-09-27 18:44:28 +00:00
|
|
|
text += " (RO)";
|
|
|
|
text += ']';
|
1999-11-09 23:52:04 +00:00
|
|
|
} else if (owner->buffer()->isReadonly())
|
1999-09-27 18:44:28 +00:00
|
|
|
text += " [RO]";
|
1999-11-09 23:52:04 +00:00
|
|
|
if (!owner->buffer()->isLyxClean())
|
1999-09-27 18:44:28 +00:00
|
|
|
text += _(" (Changed)");
|
|
|
|
} else {
|
1999-10-05 09:17:15 +00:00
|
|
|
if (text != _("Welcome to LyX!")) // this is a hack
|
1999-09-27 18:44:28 +00:00
|
|
|
text = _("* No document open *");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fl_set_input(the_buffer, text.c_str());
|
|
|
|
setTimer(0);
|
|
|
|
XFlush(fl_display);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// allows to store and reset the contents one time. Usefull for
|
|
|
|
// status messages like "load font" (Matthias)
|
|
|
|
void MiniBuffer::Store()
|
|
|
|
{
|
|
|
|
text_stored = fl_get_input(the_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MiniBuffer::Reset()
|
|
|
|
{
|
|
|
|
if (!text_stored.empty()){
|
|
|
|
Set(text_stored);
|
1999-10-19 20:59:27 +00:00
|
|
|
text_stored.clear();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MiniBuffer::Activate()
|
|
|
|
{
|
|
|
|
fl_activate_object(the_buffer);
|
|
|
|
fl_redraw_object(the_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MiniBuffer::Deactivate()
|
|
|
|
{
|
|
|
|
fl_deactivate_object(the_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|