X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fminibuffer.C;h=f365325f3141da1a1ae92256223e435858313b42;hb=91a2ea274e9c27f571a3cd4798d2e8ecc1b982a7;hp=5aff9a4aff236c206739fc1d1cfde934a2cd5238;hpb=0eccdd1c3613e5170deb77b22174dd0afde833e9;p=lyx.git diff --git a/src/minibuffer.C b/src/minibuffer.C index 5aff9a4aff..f365325f31 100644 --- a/src/minibuffer.C +++ b/src/minibuffer.C @@ -5,7 +5,7 @@ * information. * * Copyright 1995 Matthias Ettrich - * Copyright 1995-1999 The LyX Team. + * Copyright 1995-2000 The LyX Team. * * ########################################################################### */ @@ -22,27 +22,32 @@ #include FORMS_H_LOCATION #include "minibuffer.h" #include "LyXView.h" -#include "error.h" +#include "debug.h" #include "gettext.h" +#include "LyXAction.h" extern bool keyseqUncomplete(); -extern string keyseqOptions(int l=190); -extern string keyseqStr(int l=190); +extern string keyseqOptions(int l= 190); +extern string keyseqStr(int l= 190); extern LyXAction lyxaction; -void MiniBuffer::TimerCB(FL_OBJECT *, long tmp) +void MiniBuffer::TimerCB(FL_OBJECT * ob, long) { - MiniBuffer *obj= (MiniBuffer*)tmp; + MiniBuffer * obj = static_cast(ob->u_vdata); obj->Init(); } +extern "C" void C_MiniBuffer_TimerCB(FL_OBJECT * ob, long data) +{ + MiniBuffer::TimerCB(ob, data); +} -void MiniBuffer::ExecutingCB(FL_OBJECT *ob, long) +void MiniBuffer::ExecutingCB(FL_OBJECT * ob, long) { - MiniBuffer *obj = (MiniBuffer*)ob->u_vdata; - lyxerr.debug("Getting ready to execute: " + obj->cur_cmd); - fl_set_focus_object(obj->owner->getForm(), - obj->owner->currentView()->getWorkArea()); + MiniBuffer * obj = static_cast(ob->u_vdata); + lyxerr.debug() << "Getting ready to execute: " << obj->cur_cmd << endl; + obj->owner->view()->focus(true); + if (obj->cur_cmd.empty()) { obj->Init(); return ; @@ -50,78 +55,105 @@ void MiniBuffer::ExecutingCB(FL_OBJECT *ob, long) obj->Set(_("Executing:"), obj->cur_cmd); obj->addHistory(obj->cur_cmd); - // Split command into function and argument - // This is done wrong Asger. Instead of - // it ends up as Queer solution: - string arg = obj->cur_cmd; - string function; - if (contains(arg, " ")) { - arg = split(arg, function, ' '); - function = strip(function); - } else { - function = arg; - arg.erase(); - } - lyxerr.debug("Function: " + function); - lyxerr.debug("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(string("minibuffer action: ") + action); - //if (action>=0) { - // Dispatch only returns requested data for a few commands (ale) - string res=obj->owner->getLyXFunc()->Dispatch(function.c_str(), - arg.c_str()); - lyxerr.debug(string("Minibuffer Res: ") + res); -/* if (!res.empty()) - if(obj->owner->getLyXFunc()->errorStat()) - obj->Set(_("Error:"), _(res.c_str()), string(), 4); - else - obj->Set(_("Result:"), _(res.c_str()), string(), 4); - else - obj->Init(); -*/ - //} else { -#ifdef WITH_WARNINGS -#warning Look at this. -#endif - //obj->Set(_("Cannot find function"), function, "!"); + // Dispatch only returns requested data for a few commands (ale) + string res = obj->owner->getLyXFunc()->Dispatch(obj->cur_cmd); + lyxerr.debug() << "Minibuffer Res: " << res << endl; obj->shows_no_match = false; - //} return ; } +extern "C" void C_MiniBuffer_ExecutingCB(FL_OBJECT * ob, long data) +{ + 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) +int MiniBuffer::peek_event(FL_OBJECT * ob, int event, FL_Coord, FL_Coord, + int key, void */*xev*/) +{ + MiniBuffer * mini = static_cast(ob->u_vdata); + + if (event == FL_KEYBOARD){ + 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 + string s = lyxaction.getApproxFuncName(fl_get_input(ob)); + if (!s.empty()) + fl_set_input(ob, s.c_str()); + return 1; + } + case 27: + case XK_Escape: + // Abort + mini->owner->view()->focus(true); + 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; +} + +extern "C" int C_MiniBuffer_peek_event(FL_OBJECT * ob, int event, + FL_Coord, FL_Coord, + int key, void * xev) +{ + return MiniBuffer::peek_event(ob, event, 0, 0, key, xev); +} + void MiniBuffer::ExecCommand() { - text.erase(); + text.clear(); fl_set_input(the_buffer, ""); - fl_set_focus_object(owner->getForm(),the_buffer); + fl_set_focus_object(owner->getForm(), the_buffer); } -FL_OBJECT *MiniBuffer::add(int type, FL_Coord x, FL_Coord y, +FL_OBJECT * MiniBuffer::add(int type, FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h) { - FL_OBJECT *obj; + FL_OBJECT * obj; - the_buffer = obj = fl_add_input(type,x,y,w,h,text.c_str()); - fl_set_object_boxtype(obj,FL_DOWN_BOX); + the_buffer = obj = fl_add_input(type, x, y, w, h, text.c_str()); + fl_set_object_boxtype(obj, FL_DOWN_BOX); fl_set_object_resize(obj, FL_RESIZE_ALL); fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity); - fl_set_object_color(obj,FL_MCOL,FL_MCOL); - fl_set_object_lsize(obj,FL_NORMAL_SIZE); - fl_set_object_callback(obj,ExecutingCB, 0); + 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); // To intercept Up, Down, Table for history - fl_set_object_prehandler(obj, peek_event); - obj->u_vdata = (void*)this; + fl_set_object_prehandler(obj, C_MiniBuffer_peek_event); + obj->u_vdata = this; obj->wantkey = FL_KEY_TAB; // timer - timer = fl_add_timer(FL_HIDDEN_TIMER, 0,0,0,0, "Timer"); - fl_set_object_callback(timer, TimerCB, (long)this); + timer = fl_add_timer(FL_HIDDEN_TIMER, 0, 0, 0, 0, "Timer"); + fl_set_object_callback(timer, C_MiniBuffer_TimerCB, 0); + timer->u_vdata = this; fl_set_input(the_buffer, text.c_str()); return obj; @@ -163,28 +195,28 @@ void MiniBuffer::Init() text = owner->getLyXFunc()->keyseqOptions(); // Else, show the buffer state. - else if (owner->currentView()->available()) { - string nicename = - MakeDisplayPath(owner->currentBuffer()-> - getFileName()); + else if (owner->view()->available()) { + string nicename = + MakeDisplayPath(owner->buffer()-> + fileName()); // 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(); + if (owner->buffer()->lyxvc.inUse()) { + text += " ["; + text += owner->buffer()->lyxvc.version(); text += ' '; - text += owner->currentBuffer()->lyxvc.getLocker(); - if (owner->currentBuffer()->isReadonly()) + text += owner->buffer()->lyxvc.locker(); + if (owner->buffer()->isReadonly()) text += " (RO)"; text += ']'; - } else if (owner->currentBuffer()->isReadonly()) + } else if (owner->buffer()->isReadonly()) text += " [RO]"; - if (!owner->currentBuffer()->isLyxClean()) + if (!owner->buffer()->isLyxClean()) text += _(" (Changed)"); } else { - if (text != "Welcome to LyX!") // this is a hack + if (text != _("Welcome to LyX!")) // this is a hack text = _("* No document open *"); } @@ -207,7 +239,7 @@ void MiniBuffer::Reset() { if (!text_stored.empty()){ Set(text_stored); - text_stored.erase(); + text_stored.clear(); } } @@ -223,52 +255,3 @@ void MiniBuffer::Deactivate() } -// This is not as dirty as it seems, the hidden buttons removed by this -// function were just kludges for an uncomplete keyboard callback (ale) -int MiniBuffer::peek_event(FL_OBJECT *ob, int event, FL_Coord, FL_Coord, - int key, void */*xev*/) -{ - MiniBuffer *mini = (MiniBuffer*)ob->u_vdata; - - if (event==FL_KEYBOARD){ - 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 - const char *s = lyxaction.getApproxFuncName(fl_get_input(ob)); - if (s && s[0]) - fl_set_input(ob, s); - return 1; - } - case 27: - case XK_Escape: - // Abort - fl_set_focus_object(mini->owner->getForm(), - mini->owner->currentView()->getWorkArea()); - 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; -} -