mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-05 13:26:21 +00:00
A clean-up of the minibuffer code; see xforms/ChangeLog. Qt code seems Ok
in this regard. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6678 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b92fba65e8
commit
c93bea2449
@ -49,7 +49,7 @@ LyXView::LyXView()
|
||||
autosave_timeout_(new Timeout(5000)),
|
||||
lyxfunc_(new LyXFunc(this)),
|
||||
dialogs_(new Dialogs(*this)),
|
||||
controlcommand_(new ControlCommandBuffer(getLyXFunc()))
|
||||
controlcommand_(new ControlCommandBuffer(*this))
|
||||
{
|
||||
lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
|
||||
}
|
||||
|
@ -1,3 +1,10 @@
|
||||
2003-04-02 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* ControlCommandBuffer.[Ch] (c-tor): passed a LyXView & rather than
|
||||
a LyXFunc &. Ensuing changes elsewhere.
|
||||
(getCurrentState): new method, returning bufferview_func's
|
||||
currentState (needs the currently active BufferView).
|
||||
|
||||
2003-03-31 John Levon <levon@movementarian.org>
|
||||
|
||||
* ControlPrint.C:
|
||||
|
@ -12,13 +12,14 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
||||
#include "ControlCommandBuffer.h"
|
||||
#include "bufferview_funcs.h"
|
||||
#include "debug.h"
|
||||
#include "lyxfunc.h"
|
||||
#include "LyXAction.h"
|
||||
#include "frontends/LyXView.h"
|
||||
#include "support/lyxalgo.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "LyXAction.h"
|
||||
#include "lyxfunc.h"
|
||||
#include "debug.h"
|
||||
|
||||
using std::vector;
|
||||
using std::back_inserter;
|
||||
@ -39,8 +40,8 @@ struct prefix_p {
|
||||
} // end of anon namespace
|
||||
|
||||
|
||||
ControlCommandBuffer::ControlCommandBuffer(LyXFunc & lf)
|
||||
: lyxfunc_(lf), history_pos_(history_.end())
|
||||
ControlCommandBuffer::ControlCommandBuffer(LyXView & lv)
|
||||
: lv_(lv), history_pos_(history_.end())
|
||||
{
|
||||
transform(lyxaction.func_begin(), lyxaction.func_end(),
|
||||
back_inserter(commands_), lyx::firster());
|
||||
@ -67,6 +68,12 @@ string const ControlCommandBuffer::historyDown()
|
||||
}
|
||||
|
||||
|
||||
string const ControlCommandBuffer::getCurrentState() const
|
||||
{
|
||||
return currentState(lv_.view().get());
|
||||
}
|
||||
|
||||
|
||||
vector<string> const
|
||||
ControlCommandBuffer::completions(string const & prefix, string & new_prefix)
|
||||
{
|
||||
@ -113,5 +120,5 @@ void ControlCommandBuffer::dispatch(string const & str)
|
||||
|
||||
history_.push_back(str);
|
||||
history_pos_ = history_.end();
|
||||
lyxfunc_.dispatch(str, true);
|
||||
lv_.getLyXFunc().dispatch(str, true);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include <vector>
|
||||
|
||||
|
||||
class LyXFunc;
|
||||
class LyXView;
|
||||
|
||||
/**
|
||||
* ControlCommandBuffer
|
||||
@ -29,7 +29,7 @@ class LyXFunc;
|
||||
*/
|
||||
class ControlCommandBuffer {
|
||||
public:
|
||||
ControlCommandBuffer(LyXFunc & lf);
|
||||
ControlCommandBuffer(LyXView & lv);
|
||||
|
||||
/// return the previous history entry if any
|
||||
string const historyUp();
|
||||
@ -37,6 +37,9 @@ public:
|
||||
/// return the next history entry if any
|
||||
string const historyDown();
|
||||
|
||||
/// return the font and depth in the active BufferView as a message.
|
||||
string const getCurrentState() const;
|
||||
|
||||
/// return the possible completions
|
||||
std::vector<string> const completions(string const & prefix,
|
||||
string & new_prefix);
|
||||
@ -44,8 +47,8 @@ public:
|
||||
/// dispatch a command
|
||||
void dispatch(string const & str);
|
||||
private:
|
||||
/// controlling lyxfunc
|
||||
LyXFunc & lyxfunc_;
|
||||
/// controlling LyXView
|
||||
LyXView & lv_;
|
||||
|
||||
/// available command names
|
||||
std::vector<string> commands_;
|
||||
|
@ -1,3 +1,17 @@
|
||||
2003-04-02 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* XFormsView.C (create_form_form_main): no longer pass this to the
|
||||
XMinibuffer c-tor.
|
||||
|
||||
* XMiniBuffer.[Ch]: something of a clean-up.
|
||||
(c-tor): no longer requires a XFormsView * in the argument list.
|
||||
(create_input_box): moved out of the class.
|
||||
(the_buffer_, input_obj_): replaced by a single input_. Having two
|
||||
pointers to the same FL_OBJECT was clearly barmy.
|
||||
(idle_timeout): don't access bufferview_func's currentState direct
|
||||
but rather use the new controller method. Means that XMinibuffer
|
||||
knows nothing about the LyX kernel.
|
||||
|
||||
2003-04-01 John Levon <levon@movementarian.org>
|
||||
|
||||
* Alert_pimpl.C: format error messages
|
||||
|
@ -151,7 +151,7 @@ void XFormsView::create_form_form_main(int width, int height)
|
||||
width - 3 * air, workheight));
|
||||
::current_view = bufferview_.get();
|
||||
|
||||
minibuffer_.reset(new XMiniBuffer(this, *controlcommand_,
|
||||
minibuffer_.reset(new XMiniBuffer(*controlcommand_,
|
||||
air, height - (25 + air), width - (2 * air), 25));
|
||||
|
||||
// assign an icon to main form
|
||||
|
@ -12,16 +12,13 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
||||
#include "frontends/xforms/DropDown.h"
|
||||
#include "frontends/xforms/XFormsView.h"
|
||||
#include "frontends/controllers/ControlCommandBuffer.h"
|
||||
#include "frontends/Timeout.h"
|
||||
|
||||
#include "XMiniBuffer.h"
|
||||
#include "DropDown.h"
|
||||
#include "ControlCommandBuffer.h"
|
||||
|
||||
#include "gettext.h"
|
||||
#include "debug.h"
|
||||
#include "bufferview_funcs.h"
|
||||
|
||||
#include "frontends/Timeout.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
@ -35,12 +32,21 @@ using std::endl;
|
||||
using std::vector;
|
||||
|
||||
|
||||
XMiniBuffer::XMiniBuffer(XFormsView * v, ControlCommandBuffer & control,
|
||||
FL_Coord x, FL_Coord y, FL_Coord h, FL_Coord w)
|
||||
: controller_(control), view_(v),
|
||||
info_shown_(false)
|
||||
namespace {
|
||||
|
||||
/// This creates the input widget for the minibuffer
|
||||
FL_OBJECT * create_input_box(void * parent, int type,
|
||||
FL_Coord, FL_Coord, FL_Coord, FL_Coord);
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
XMiniBuffer::XMiniBuffer(ControlCommandBuffer & control,
|
||||
FL_Coord x, FL_Coord y, FL_Coord h, FL_Coord w)
|
||||
: controller_(control),
|
||||
info_shown_(false)
|
||||
{
|
||||
input_obj_ = create_input_box(FL_NORMAL_INPUT, x, y, h, w);
|
||||
input_ = create_input_box(this, FL_NORMAL_INPUT, x, y, h, w);
|
||||
info_timer_.reset(new Timeout(1500));
|
||||
idle_timer_.reset(new Timeout(6000));
|
||||
info_con = info_timer_->timeout.connect(boost::bind(&XMiniBuffer::info_timeout, this));
|
||||
@ -58,7 +64,7 @@ XMiniBuffer::~XMiniBuffer()
|
||||
// thanks for nothing, xforms (recursive creation not allowed)
|
||||
void XMiniBuffer::dd_init()
|
||||
{
|
||||
dropdown_.reset(new DropDown(the_buffer_));
|
||||
dropdown_.reset(new DropDown(input_));
|
||||
result_con = dropdown_->result.connect(boost::bind(&XMiniBuffer::set_complete_input, this, _1));
|
||||
keypress_con = dropdown_->keypress.connect(boost::bind(&XMiniBuffer::append_char, this, _1));
|
||||
}
|
||||
@ -134,14 +140,14 @@ int XMiniBuffer::peek_event(FL_OBJECT * ob, int event,
|
||||
set_input(new_input);
|
||||
|
||||
int x,y,w,h;
|
||||
fl_get_wingeometry(fl_get_real_object_window(the_buffer_),
|
||||
fl_get_wingeometry(fl_get_real_object_window(input_),
|
||||
&x, &y, &w, &h);
|
||||
|
||||
// asynchronous completion
|
||||
int const air = the_buffer_->x;
|
||||
int const air = input_->x;
|
||||
x += air;
|
||||
y += h - (the_buffer_->h + air);
|
||||
w = the_buffer_->w;
|
||||
y += h - (input_->h + air);
|
||||
w = input_->w;
|
||||
dropdown_->select(comp, x, y, w);
|
||||
return 1;
|
||||
}
|
||||
@ -172,46 +178,11 @@ int XMiniBuffer::peek_event(FL_OBJECT * ob, int event,
|
||||
}
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
static
|
||||
int C_XMiniBuffer_peek_event(FL_OBJECT * ob, int event,
|
||||
FL_Coord, FL_Coord,
|
||||
int key, void * xev)
|
||||
{
|
||||
XMiniBuffer * mini = static_cast<XMiniBuffer*>(ob->u_vdata);
|
||||
return mini->peek_event(ob, event, key,
|
||||
static_cast<XEvent *>(xev));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FL_OBJECT * XMiniBuffer::create_input_box(int type, FL_Coord x, FL_Coord y,
|
||||
FL_Coord w, FL_Coord h)
|
||||
{
|
||||
FL_OBJECT * obj;
|
||||
|
||||
the_buffer_ = obj = fl_add_input(type, x, y, w, h, "");
|
||||
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);
|
||||
|
||||
// To intercept Up, Down, Table for history
|
||||
fl_set_object_prehandler(obj, C_XMiniBuffer_peek_event);
|
||||
obj->u_vdata = this;
|
||||
obj->wantkey = FL_KEY_TAB;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
void XMiniBuffer::freeze()
|
||||
{
|
||||
// we must prevent peek_event, or we get an unfocus() when the
|
||||
// containing form gets destroyed
|
||||
fl_set_object_prehandler(input_obj_, 0);
|
||||
fl_set_object_prehandler(input_, 0);
|
||||
}
|
||||
|
||||
|
||||
@ -229,7 +200,7 @@ void XMiniBuffer::show_info(string const & info, string const & input, bool appe
|
||||
|
||||
void XMiniBuffer::idle_timeout()
|
||||
{
|
||||
set_input(currentState(view_->view().get()));
|
||||
set_input(controller_.getCurrentState());
|
||||
}
|
||||
|
||||
|
||||
@ -242,7 +213,7 @@ void XMiniBuffer::info_timeout()
|
||||
|
||||
bool XMiniBuffer::isEditingMode() const
|
||||
{
|
||||
return the_buffer_->focus;
|
||||
return input_->focus;
|
||||
}
|
||||
|
||||
|
||||
@ -250,14 +221,14 @@ void XMiniBuffer::messageMode(bool on)
|
||||
{
|
||||
set_input("");
|
||||
if (!on) {
|
||||
fl_activate_object(the_buffer_);
|
||||
fl_set_focus_object(view_->getForm(), the_buffer_);
|
||||
fl_activate_object(input_);
|
||||
fl_set_focus_object(input_->form, input_);
|
||||
redraw();
|
||||
idle_timer_->stop();
|
||||
} else {
|
||||
if (isEditingMode()) {
|
||||
// focus back to the workarea
|
||||
fl_set_focus_object(view_->getForm(), 0);
|
||||
fl_set_focus_object(input_->form, 0);
|
||||
idle_timer_->start();
|
||||
}
|
||||
}
|
||||
@ -266,7 +237,7 @@ void XMiniBuffer::messageMode(bool on)
|
||||
|
||||
void XMiniBuffer::redraw()
|
||||
{
|
||||
fl_redraw_object(the_buffer_);
|
||||
fl_redraw_object(input_);
|
||||
XFlush(fl_display);
|
||||
}
|
||||
|
||||
@ -276,12 +247,12 @@ void XMiniBuffer::append_char(char c)
|
||||
if (!c || !isprint(c))
|
||||
return;
|
||||
|
||||
char const * tmp = fl_get_input(the_buffer_);
|
||||
char const * tmp = fl_get_input(input_);
|
||||
string str = tmp ? tmp : "";
|
||||
|
||||
str += c;
|
||||
|
||||
fl_set_input(the_buffer_, str.c_str());
|
||||
fl_set_input(input_, str.c_str());
|
||||
}
|
||||
|
||||
|
||||
@ -304,5 +275,38 @@ void XMiniBuffer::message(string const & str)
|
||||
|
||||
void XMiniBuffer::set_input(string const & str)
|
||||
{
|
||||
fl_set_input(the_buffer_, str.c_str());
|
||||
fl_set_input(input_, str.c_str());
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
extern "C"
|
||||
int C_XMiniBuffer_peek_event(FL_OBJECT * ob, int event,
|
||||
FL_Coord, FL_Coord,
|
||||
int key, void * xev)
|
||||
{
|
||||
XMiniBuffer * mini = static_cast<XMiniBuffer*>(ob->u_vdata);
|
||||
return mini->peek_event(ob, event, key, static_cast<XEvent *>(xev));
|
||||
}
|
||||
|
||||
|
||||
FL_OBJECT * create_input_box(void * parent, int type,
|
||||
FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h)
|
||||
{
|
||||
FL_OBJECT * obj = fl_add_input(type, x, y, w, h, "");
|
||||
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);
|
||||
|
||||
// To intercept Up, Down, Table for history
|
||||
fl_set_object_prehandler(obj, C_XMiniBuffer_peek_event);
|
||||
obj->u_vdata = parent;
|
||||
obj->wantkey = FL_KEY_TAB;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
@ -16,10 +16,10 @@
|
||||
|
||||
#include FORMS_H_LOCATION
|
||||
|
||||
#include "LString.h"
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/signals/connection.hpp>
|
||||
|
||||
|
||||
class DropDown;
|
||||
class ControlCommandBuffer;
|
||||
class Timeout;
|
||||
@ -28,7 +28,7 @@ class Timeout;
|
||||
class XMiniBuffer {
|
||||
public:
|
||||
///
|
||||
XMiniBuffer(XFormsView * o, ControlCommandBuffer & control,
|
||||
XMiniBuffer(ControlCommandBuffer & control,
|
||||
FL_Coord x, FL_Coord y, FL_Coord h, FL_Coord w);
|
||||
|
||||
///
|
||||
@ -74,9 +74,6 @@ private:
|
||||
/// set the minibuffer content in editing mode
|
||||
void set_input(string const &);
|
||||
|
||||
/// This creates the input widget for the minibuffer
|
||||
FL_OBJECT * create_input_box(int, FL_Coord, FL_Coord, FL_Coord, FL_Coord);
|
||||
|
||||
/// go into message mode
|
||||
void messageMode(bool on = true);
|
||||
|
||||
@ -100,18 +97,13 @@ private:
|
||||
boost::signals::connection result_con;
|
||||
///
|
||||
boost::signals::connection keypress_con;
|
||||
/// This is the input widget object
|
||||
FL_OBJECT * the_buffer_;
|
||||
|
||||
/// the input box
|
||||
FL_OBJECT * input_obj_;
|
||||
/// This is the input widget object
|
||||
FL_OBJECT * input_;
|
||||
|
||||
/// the controller we use
|
||||
ControlCommandBuffer & controller_;
|
||||
|
||||
/// the lyx view
|
||||
XFormsView * view_;
|
||||
|
||||
/// stored input when showing info
|
||||
string stored_input_;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user