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
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* ###########################################################################
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2001-04-25 19:33:52 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#ifdef __GNUG__
|
2001-04-17 15:15:59 +00:00
|
|
|
#pragma implementation
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
#include "minibuffer.h"
|
|
|
|
|
|
|
|
#include "support/lyxalgo.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/filetools.h"
|
2001-07-29 15:34:18 +00:00
|
|
|
#include "support/lstrings.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "LyXView.h"
|
2001-07-03 15:19:04 +00:00
|
|
|
#include "XFormsView.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"
|
2001-04-17 15:15:59 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-03-16 12:08:14 +00:00
|
|
|
using SigC::slot;
|
2001-04-18 10:20:17 +00:00
|
|
|
using std::vector;
|
2000-10-30 14:56:20 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
extern LyXAction lyxaction;
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct prefix {
|
|
|
|
string p;
|
|
|
|
prefix(string const & s)
|
|
|
|
: p(s) {}
|
|
|
|
bool operator()(string const & s) const {
|
|
|
|
return prefixIs(s, p);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end of anon namespace
|
|
|
|
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
MiniBuffer::MiniBuffer(LyXView * o, FL_Coord x, FL_Coord y,
|
|
|
|
FL_Coord h, FL_Coord w)
|
2001-04-17 15:15:59 +00:00
|
|
|
: stored_(false), owner_(o), state_(spaces)
|
2000-04-04 00:19:15 +00:00
|
|
|
{
|
|
|
|
add(FL_NORMAL_INPUT, x, y, h, w);
|
2001-04-17 15:15:59 +00:00
|
|
|
timer.setTimeout(6000);
|
|
|
|
timer.timeout.connect(slot(this, &MiniBuffer::init));
|
|
|
|
stored_timer.setTimeout(1500);
|
|
|
|
stored_timer.timeout.connect(slot(this, &MiniBuffer::stored_slot));
|
|
|
|
deactivate();
|
2000-04-04 00:19:15 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
void MiniBuffer::stored_slot()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-17 15:15:59 +00:00
|
|
|
if (stored_) {
|
|
|
|
stored_ = false;
|
2001-08-04 10:26:01 +00:00
|
|
|
set_input(stored_input);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-26 00:07:20 +00:00
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
void MiniBuffer::stored_set(string const & str)
|
1999-10-25 14:18:30 +00:00
|
|
|
{
|
2001-04-17 15:15:59 +00:00
|
|
|
stored_input = str;
|
|
|
|
stored_ = true;
|
|
|
|
stored_timer.start();
|
1999-10-25 14:18:30 +00:00
|
|
|
}
|
|
|
|
|
2000-10-26 00:07:20 +00:00
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
int MiniBuffer::peek_event(FL_OBJECT * ob, int event, int key)
|
1999-10-25 14:18:30 +00:00
|
|
|
{
|
2000-10-26 00:07:20 +00:00
|
|
|
switch (event) {
|
|
|
|
case FL_KEYBOARD:
|
2001-04-17 15:15:59 +00:00
|
|
|
{
|
|
|
|
char const * tmp = fl_get_input(ob);
|
|
|
|
string input = tmp ? tmp : "";
|
|
|
|
if (stored_) {
|
|
|
|
stored_timer.stop();
|
|
|
|
input = stored_input;
|
2001-08-04 10:26:01 +00:00
|
|
|
set_input(input);
|
2001-04-17 15:15:59 +00:00
|
|
|
stored_ = false;
|
|
|
|
}
|
|
|
|
|
1999-10-25 14:18:30 +00:00
|
|
|
switch (key) {
|
|
|
|
case XK_Down:
|
2001-04-17 15:15:59 +00:00
|
|
|
if (hist_iter != history_->end()) {
|
|
|
|
++hist_iter;
|
|
|
|
}
|
|
|
|
if (hist_iter == history_->end()) {
|
|
|
|
// no further history
|
|
|
|
stored_set(input);
|
2001-08-04 10:26:01 +00:00
|
|
|
set_input(_("[End of history]"));
|
2001-04-17 15:15:59 +00:00
|
|
|
} else {
|
2001-08-04 10:26:01 +00:00
|
|
|
set_input((*hist_iter));
|
2001-04-17 15:15:59 +00:00
|
|
|
}
|
1999-10-25 14:18:30 +00:00
|
|
|
return 1;
|
|
|
|
case XK_Up:
|
2001-04-17 15:15:59 +00:00
|
|
|
if (hist_iter == history_->begin()) {
|
|
|
|
// no further history
|
|
|
|
stored_set(input);
|
2001-08-04 10:26:01 +00:00
|
|
|
set_input(_("[Beginning of history]"));
|
2001-04-17 15:15:59 +00:00
|
|
|
} else {
|
|
|
|
--hist_iter;
|
2001-08-04 10:26:01 +00:00
|
|
|
set_input((*hist_iter));
|
2001-04-17 15:15:59 +00:00
|
|
|
}
|
1999-10-25 14:18:30 +00:00
|
|
|
return 1;
|
|
|
|
case 9:
|
|
|
|
case XK_Tab:
|
|
|
|
{
|
2001-04-17 15:15:59 +00:00
|
|
|
// Completion handling.
|
|
|
|
|
|
|
|
vector<string> comp;
|
|
|
|
lyx::copy_if(completion_.begin(),
|
|
|
|
completion_.end(),
|
2001-04-18 10:20:17 +00:00
|
|
|
std::back_inserter(comp), prefix(input));
|
2001-04-17 15:15:59 +00:00
|
|
|
|
|
|
|
if (comp.empty()) {
|
|
|
|
// No matches
|
|
|
|
string const tmp = input + _(" [no match]");
|
|
|
|
stored_set(input);
|
2001-08-04 10:26:01 +00:00
|
|
|
set_input(tmp);
|
2001-04-17 15:15:59 +00:00
|
|
|
} else if (comp.size() == 1) {
|
|
|
|
// Perfect match
|
|
|
|
string const tmp =
|
|
|
|
comp[0] + _(" [sole completion]");
|
|
|
|
stored_set(comp[0]);
|
2001-08-04 10:26:01 +00:00
|
|
|
set_input(tmp);
|
2001-04-17 15:15:59 +00:00
|
|
|
} else {
|
|
|
|
// More that one match
|
|
|
|
// Find maximal avaliable prefix
|
|
|
|
string const tmp = comp[0];
|
|
|
|
string test(input);
|
|
|
|
test += tmp[test.length()];
|
|
|
|
while (test.length() < tmp.length()) {
|
|
|
|
vector<string> vtmp;
|
|
|
|
lyx::copy_if(comp.begin(),
|
|
|
|
comp.end(),
|
2001-04-18 10:20:17 +00:00
|
|
|
std::back_inserter(vtmp),
|
2001-04-17 15:15:59 +00:00
|
|
|
prefix(test));
|
|
|
|
if (vtmp.size() != comp.size()) {
|
|
|
|
test.erase(test.length() - 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
test += tmp[test.length()];
|
|
|
|
}
|
2001-08-04 10:26:01 +00:00
|
|
|
set_input(test);
|
2001-04-17 15:15:59 +00:00
|
|
|
|
|
|
|
// How should the possible matches
|
|
|
|
// be visualized?
|
|
|
|
std::copy(comp.begin(), comp.end(),
|
2001-04-18 10:20:17 +00:00
|
|
|
std::ostream_iterator<string>(std::cerr, "\n"));
|
2001-04-17 15:15:59 +00:00
|
|
|
}
|
1999-10-25 14:18:30 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case 27:
|
|
|
|
case XK_Escape:
|
|
|
|
// Abort
|
2001-04-17 15:15:59 +00:00
|
|
|
owner_->view()->focus(true);
|
|
|
|
init();
|
|
|
|
deactivate();
|
|
|
|
//escape.emit();
|
1999-10-25 14:18:30 +00:00
|
|
|
return 1;
|
|
|
|
case 13:
|
|
|
|
case XK_Return:
|
2001-04-17 15:15:59 +00:00
|
|
|
{
|
2001-05-04 10:36:36 +00:00
|
|
|
#if 0
|
|
|
|
// This will go in again in a little while
|
|
|
|
// we need to be able to declare what types
|
|
|
|
// of argumetns LFUN's should have first. (Lgb)
|
2001-04-17 15:15:59 +00:00
|
|
|
// First check for match
|
|
|
|
vector<string>::const_iterator cit =
|
|
|
|
std::find(completion_.begin(),
|
|
|
|
completion_.end(),
|
|
|
|
input);
|
|
|
|
if (cit == completion_.end()) {
|
|
|
|
// no such func/item
|
|
|
|
stored_set(input);
|
|
|
|
string const tmp = input + _(" [no match]");
|
2001-08-04 10:26:01 +00:00
|
|
|
set_input(tmp);
|
2001-04-17 15:15:59 +00:00
|
|
|
} else {
|
2001-05-04 10:36:36 +00:00
|
|
|
#endif
|
2001-04-17 15:15:59 +00:00
|
|
|
// Return the inputted string
|
|
|
|
deactivate();
|
|
|
|
owner_->view()->focus(true);
|
|
|
|
history_->push_back(input);
|
|
|
|
stringReady.emit(input);
|
2001-05-04 10:36:36 +00:00
|
|
|
# if 0
|
2001-04-17 15:15:59 +00:00
|
|
|
}
|
2001-05-04 10:36:36 +00:00
|
|
|
#endif
|
1999-10-25 14:18:30 +00:00
|
|
|
return 1;
|
2001-04-17 15:15:59 +00:00
|
|
|
}
|
|
|
|
case XK_space:
|
|
|
|
{
|
|
|
|
// Depending on the input state spaces might not
|
|
|
|
// be allowed.
|
|
|
|
switch (state_) {
|
|
|
|
case spaces:
|
|
|
|
return 0;
|
|
|
|
case nospaces:
|
|
|
|
{
|
|
|
|
stored_set(input);
|
|
|
|
string const tmp = input + _(" [no match]");
|
2001-08-04 10:26:01 +00:00
|
|
|
set_input(tmp);
|
2001-04-17 15:15:59 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-10-25 14:18:30 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2001-04-17 15:15:59 +00:00
|
|
|
}
|
2000-10-26 00:07:20 +00:00
|
|
|
default:
|
2000-10-26 17:31:11 +00:00
|
|
|
//lyxerr << "Unhandled minibuffer event!" << endl;
|
2000-10-26 00:07:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-10-25 14:18:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-26 00:07:20 +00:00
|
|
|
|
2001-09-09 22:02:19 +00:00
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
static
|
|
|
|
int C_MiniBuffer_peek_event(FL_OBJECT * ob, int event,
|
|
|
|
FL_Coord, FL_Coord,
|
|
|
|
int key, void * /*xev*/)
|
|
|
|
{
|
|
|
|
MiniBuffer * mini = static_cast<MiniBuffer*>(ob->u_vdata);
|
|
|
|
return mini->peek_event(ob, event, key);
|
|
|
|
}
|
|
|
|
|
1999-10-25 14:18:30 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
void MiniBuffer::prepare()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-05-04 10:57:00 +00:00
|
|
|
text.erase();
|
2001-08-04 10:26:01 +00:00
|
|
|
set_input("");
|
2001-04-17 15:15:59 +00:00
|
|
|
activate();
|
2001-07-03 15:19:04 +00:00
|
|
|
fl_set_focus_object(static_cast<XFormsView *>(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);
|
2001-04-17 15:15:59 +00:00
|
|
|
|
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;
|
|
|
|
|
2001-08-04 10:26:01 +00:00
|
|
|
set_input(text);
|
2000-10-26 00:07:20 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
void MiniBuffer::message(string const & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-17 15:15:59 +00:00
|
|
|
timer.restart();
|
|
|
|
string const ntext = strip(str);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!the_buffer->focus) {
|
2001-08-04 10:26:01 +00:00
|
|
|
set_input(ntext);
|
1999-09-27 18:44:28 +00:00
|
|
|
text = ntext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
void MiniBuffer::messagePush(string const & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-17 15:15:59 +00:00
|
|
|
text_stored = text;
|
|
|
|
message(str);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
void MiniBuffer::messagePop()
|
|
|
|
{
|
|
|
|
if (!text_stored.empty()) {
|
|
|
|
message(text_stored);
|
|
|
|
text_stored.erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-04-17 15:15:59 +00:00
|
|
|
}
|
2000-10-26 00:07:20 +00:00
|
|
|
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
void MiniBuffer::addSet(string const & s1, string const & s2)
|
|
|
|
{
|
|
|
|
string const str = text + ' ' + s1 + ' ' + s2;
|
|
|
|
message(str);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
void MiniBuffer::getString(State spaces,
|
|
|
|
vector<string> const & completion,
|
|
|
|
vector<string> & history)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-17 15:15:59 +00:00
|
|
|
state_ = spaces;
|
|
|
|
completion_ = completion;
|
|
|
|
history_ = &history;
|
|
|
|
hist_iter = history_->end();
|
|
|
|
prepare();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
void MiniBuffer::init()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-17 15:15:59 +00:00
|
|
|
// If we have focus, we don't want to change anything.
|
|
|
|
if (the_buffer->focus)
|
|
|
|
return;
|
|
|
|
|
|
|
|
timeout.emit();
|
|
|
|
timer.stop();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-10-26 00:07:20 +00:00
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
void MiniBuffer::activate()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
fl_activate_object(the_buffer);
|
2001-08-04 10:26:01 +00:00
|
|
|
redraw();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-10-26 00:07:20 +00:00
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
void MiniBuffer::deactivate()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-08-04 10:26:01 +00:00
|
|
|
redraw();
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_deactivate_object(the_buffer);
|
2001-08-04 10:26:01 +00:00
|
|
|
XFlush(fl_display);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-04-17 15:15:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
void MiniBuffer::redraw()
|
|
|
|
{
|
|
|
|
fl_redraw_object(the_buffer);
|
2001-08-04 10:26:01 +00:00
|
|
|
XFlush(fl_display);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MiniBuffer::set_input(string const & str)
|
|
|
|
{
|
|
|
|
fl_set_input(the_buffer, str.c_str());
|
|
|
|
XFlush(fl_display);
|
2001-04-17 15:15:59 +00:00
|
|
|
}
|