Introduce Application::currentWindow() and get rid of lyx_view_ member in LyXFunc.

This commit also move the Selection saving to  QEvent::WindowActivate in GuiView.cpp.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31443 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2009-09-22 21:25:32 +00:00
parent 76db6e2cc3
commit a3adb3a21b
13 changed files with 89 additions and 106 deletions

View File

@ -197,7 +197,7 @@ Change::Type lookupChangeType(DocIterator const & dit, bool outer = false)
LyXFunc::LyXFunc() LyXFunc::LyXFunc()
: lyx_view_(0), encoded_last_key(0), meta_fake_bit(NoModifier) : encoded_last_key(0), meta_fake_bit(NoModifier)
{ {
} }
@ -209,25 +209,15 @@ void LyXFunc::initKeySequences(KeyMap * kb)
} }
void LyXFunc::setLyXView(LyXView * lv)
{
if (lyx_view_ && lyx_view_->currentBufferView() && lyx_view_ != lv)
// save current selection to the selection buffer to allow
// middle-button paste in another window
cap::saveSelection(lyx_view_->currentBufferView()->cursor());
lyx_view_ = lv;
}
void LyXFunc::handleKeyFunc(FuncCode action) void LyXFunc::handleKeyFunc(FuncCode action)
{ {
char_type c = encoded_last_key; char_type c = encoded_last_key;
if (keyseq.length()) if (keyseq.length())
c = 0; c = 0;
LyXView * lv = theApp()->currentWindow();
LASSERT(lyx_view_ && lyx_view_->currentBufferView(), /**/); LASSERT(lv && lv->currentBufferView(), /**/);
BufferView * bv = lyx_view_->currentBufferView(); BufferView * bv = lv->currentBufferView();
bv->getIntl().getTransManager().deadkey( bv->getIntl().getTransManager().deadkey(
c, get_accent(action).accent, bv->cursor().innerText(), c, get_accent(action).accent, bv->cursor().innerText(),
bv->cursor()); bv->cursor());
@ -243,7 +233,8 @@ void LyXFunc::handleKeyFunc(FuncCode action)
// to GuiView and be GuiView and be window dependent. // to GuiView and be GuiView and be window dependent.
void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer) void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
{ {
LASSERT(lyx_view_, /**/); LyXView * lv = theApp()->currentWindow();
LASSERT(lv, /**/);
if (!theSession().bookmarks().isValid(idx)) if (!theSession().bookmarks().isValid(idx))
return; return;
BookmarksSection::Bookmark const & bm = theSession().bookmarks().bookmark(idx); BookmarksSection::Bookmark const & bm = theSession().bookmarks().bookmark(idx);
@ -268,15 +259,15 @@ void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0")); dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
// if the current buffer is not that one, switch to it. // if the current buffer is not that one, switch to it.
if (!lyx_view_->documentBufferView() if (!lv->documentBufferView()
|| lyx_view_->documentBufferView()->buffer().fileName() != tmp.filename) { || lv->documentBufferView()->buffer().fileName() != tmp.filename) {
if (!switchToBuffer) if (!switchToBuffer)
return; return;
dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file)); dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
} }
// moveToPosition try paragraph id first and then paragraph (pit, pos). // moveToPosition try paragraph id first and then paragraph (pit, pos).
if (!lyx_view_->documentBufferView()->moveToPosition( if (!lv->documentBufferView()->moveToPosition(
tmp.bottom_pit, tmp.bottom_pos, tmp.top_id, tmp.top_pos)) tmp.bottom_pit, tmp.bottom_pos, tmp.top_id, tmp.top_pos))
return; return;
@ -285,7 +276,7 @@ void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
return; return;
// Cursor jump succeeded! // Cursor jump succeeded!
Cursor const & cur = lyx_view_->documentBufferView()->cursor(); Cursor const & cur = lv->documentBufferView()->cursor();
pit_type new_pit = cur.pit(); pit_type new_pit = cur.pit();
pos_type new_pos = cur.pos(); pos_type new_pos = cur.pos();
int new_id = cur.paragraph().id(); int new_id = cur.paragraph().id();
@ -304,21 +295,23 @@ void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state)
{ {
LYXERR(Debug::KEY, "KeySym is " << keysym.getSymbolName()); LYXERR(Debug::KEY, "KeySym is " << keysym.getSymbolName());
LyXView * lv = theApp()->currentWindow();
// Do nothing if we have nothing (JMarc) // Do nothing if we have nothing (JMarc)
if (!keysym.isOK()) { if (!keysym.isOK()) {
LYXERR(Debug::KEY, "Empty kbd action (probably composing)"); LYXERR(Debug::KEY, "Empty kbd action (probably composing)");
lyx_view_->restartCursor(); lv->restartCursor();
return; return;
} }
if (keysym.isModifier()) { if (keysym.isModifier()) {
LYXERR(Debug::KEY, "isModifier true"); LYXERR(Debug::KEY, "isModifier true");
if (lyx_view_) if (lv)
lyx_view_->restartCursor(); lv->restartCursor();
return; return;
} }
//Encoding const * encoding = lyx_view_->documentBufferView()->cursor().getEncoding(); //Encoding const * encoding = lv->documentBufferView()->cursor().getEncoding();
//encoded_last_key = keysym.getISOEncoded(encoding ? encoding->name() : ""); //encoded_last_key = keysym.getISOEncoded(encoding ? encoding->name() : "");
// FIXME: encoded_last_key shadows the member variable of the same // FIXME: encoded_last_key shadows the member variable of the same
// name. Is that intended? // name. Is that intended?
@ -355,7 +348,7 @@ void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state)
// num_bytes == 0? (Lgb) // num_bytes == 0? (Lgb)
if (keyseq.length() > 1) if (keyseq.length() > 1)
lyx_view_->message(keyseq.print(KeySequence::ForGui)); lv->message(keyseq.print(KeySequence::ForGui));
// Maybe user can only reach the key via holding down shift. // Maybe user can only reach the key via holding down shift.
@ -376,8 +369,8 @@ void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state)
FuncRequest::KEYBOARD); FuncRequest::KEYBOARD);
} else { } else {
LYXERR(Debug::KEY, "Unknown, !isText() - giving up"); LYXERR(Debug::KEY, "Unknown, !isText() - giving up");
lyx_view_->message(_("Unknown function.")); lv->message(_("Unknown function."));
lyx_view_->restartCursor(); lv->restartCursor();
return; return;
} }
} }
@ -391,7 +384,7 @@ void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state)
} }
} else { } else {
dispatch(func); dispatch(func);
if (!lyx_view_) if (!lv)
return; return;
} }
} }
@ -411,13 +404,14 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
GuiView::getStatus), then several functions will not be GuiView::getStatus), then several functions will not be
handled correctly. handled correctly.
*/ */
frontend::LyXView * lv_current = theApp()->currentWindow();
frontend::LyXView * lv = 0; frontend::LyXView * lv = 0;
Buffer * buf = 0; Buffer * buf = 0;
if (lyx_view_ if (lv_current
&& (cmd.origin != FuncRequest::MENU || lyx_view_->hasFocus())) { && (cmd.origin != FuncRequest::MENU || lv_current->hasFocus())) {
lv = lyx_view_; lv = lv_current;
if (lyx_view_->documentBufferView()) if (lv_current->documentBufferView())
buf = &lyx_view_->documentBufferView()->buffer(); buf = &lv_current->documentBufferView()->buffer();
} }
if (cmd.action == LFUN_NOACTION) { if (cmd.action == LFUN_NOACTION) {
@ -624,8 +618,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
} }
// Are we in a DELETED change-tracking region? // Are we in a DELETED change-tracking region?
if (lyx_view_ && lyx_view_->documentBufferView() if (lv && lv->documentBufferView()
&& (lookupChangeType(lyx_view_->documentBufferView()->cursor(), true) && (lookupChangeType(lv->documentBufferView()->cursor(), true)
== Change::DELETED) == Change::DELETED)
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly) && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) { && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
@ -664,6 +658,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
//This is done unless explicitely requested otherwise //This is done unless explicitely requested otherwise
Update::flags updateFlags = Update::FitCursor; Update::flags updateFlags = Update::FitCursor;
LyXView * lv = theApp()->currentWindow();
FuncStatus const flag = getStatus(cmd); FuncStatus const flag = getStatus(cmd);
if (!flag.enabled()) { if (!flag.enabled()) {
// We cannot use this function here // We cannot use this function here
@ -671,21 +667,21 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
<< lyxaction.getActionName(action) << lyxaction.getActionName(action)
<< " [" << action << "] is disabled at this location"); << " [" << action << "] is disabled at this location");
setErrorMessage(flag.message()); setErrorMessage(flag.message());
if (lyx_view_) if (lv)
lyx_view_->restartCursor(); lv->restartCursor();
} else { } else {
Buffer * buffer = 0; Buffer * buffer = 0;
if (lyx_view_ && lyx_view_->currentBufferView()) if (lv && lv->currentBufferView())
buffer = &lyx_view_->currentBufferView()->buffer(); buffer = &lv->currentBufferView()->buffer();
switch (action) { switch (action) {
case LFUN_COMMAND_PREFIX: case LFUN_COMMAND_PREFIX:
LASSERT(lyx_view_, /**/); LASSERT(lv, /**/);
lyx_view_->message(keyseq.printOptions(true)); lv->message(keyseq.printOptions(true));
break; break;
case LFUN_CANCEL: case LFUN_CANCEL:
LASSERT(lyx_view_ && lyx_view_->currentBufferView(), /**/); LASSERT(lv && lv->currentBufferView(), /**/);
keyseq.reset(); keyseq.reset();
meta_fake_bit = NoModifier; meta_fake_bit = NoModifier;
if (buffer) if (buffer)
@ -702,12 +698,12 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
// --- Menus ----------------------------------------------- // --- Menus -----------------------------------------------
case LFUN_RECONFIGURE: case LFUN_RECONFIGURE:
// argument is any additional parameter to the configure.py command // argument is any additional parameter to the configure.py command
reconfigure(lyx_view_, argument); reconfigure(lv, argument);
break; break;
// --- lyxserver commands ---------------------------- // --- lyxserver commands ----------------------------
case LFUN_SERVER_GET_FILENAME: case LFUN_SERVER_GET_FILENAME:
LASSERT(lyx_view_ && buffer, /**/); LASSERT(lv && buffer, /**/);
setMessage(from_utf8(buffer->absFileName())); setMessage(from_utf8(buffer->absFileName()));
LYXERR(Debug::INFO, "FNAME[" LYXERR(Debug::INFO, "FNAME["
<< buffer->absFileName() << ']'); << buffer->absFileName() << ']');
@ -719,7 +715,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
break; break;
case LFUN_SERVER_GOTO_FILE_ROW: { case LFUN_SERVER_GOTO_FILE_ROW: {
LASSERT(lyx_view_, /**/); LASSERT(lv, /**/);
string file_name; string file_name;
int row; int row;
istringstream is(argument); istringstream is(argument);
@ -749,10 +745,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
if (theBufferList().exists(s)) if (theBufferList().exists(s))
buf = theBufferList().getBuffer(s); buf = theBufferList().getBuffer(s);
else if (s.exists()) { else if (s.exists()) {
buf = lyx_view_->loadDocument(s); buf = lv->loadDocument(s);
loaded = true; loaded = true;
} else } else
lyx_view_->message(bformat( lv->message(bformat(
_("File does not exist: %1$s"), _("File does not exist: %1$s"),
makeDisplayPath(file_name))); makeDisplayPath(file_name)));
} }
@ -763,8 +759,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
} }
buf->updateLabels(); buf->updateLabels();
lyx_view_->setBuffer(buf); lv->setBuffer(buf);
lyx_view_->documentBufferView()->setCursorFromRow(row); lv->documentBufferView()->setCursorFromRow(row);
if (loaded) if (loaded)
buf->errors("Parse"); buf->errors("Parse");
updateFlags = Update::FitCursor; updateFlags = Update::FitCursor;
@ -773,7 +769,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
case LFUN_DIALOG_SHOW_NEW_INSET: { case LFUN_DIALOG_SHOW_NEW_INSET: {
LASSERT(lyx_view_, /**/); LASSERT(lv, /**/);
string const name = cmd.getArg(0); string const name = cmd.getArg(0);
InsetCode code = insetCode(name); InsetCode code = insetCode(name);
string data = trim(to_utf8(cmd.argument()).substr(name.size())); string data = trim(to_utf8(cmd.argument()).substr(name.size()));
@ -879,7 +875,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
} }
case LFUN_CITATION_INSERT: { case LFUN_CITATION_INSERT: {
LASSERT(lyx_view_, /**/); LASSERT(lv, /**/);
if (!argument.empty()) { if (!argument.empty()) {
// we can have one optional argument, delimited by '|' // we can have one optional argument, delimited by '|'
// citation-insert <key>|<text_before> // citation-insert <key>|<text_before>
@ -904,7 +900,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
} }
case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE: case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
LASSERT(lyx_view_, /**/); LASSERT(lv, /**/);
lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar; lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
break; break;
@ -1057,8 +1053,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
// Nothing more to do. // Nothing more to do.
return; return;
// Everything below is only for active lyx_view_ // Everything below is only for active window
if (lyx_view_ == 0) if (lv == 0)
break; break;
// Start an undo group. This may be needed for // Start an undo group. This may be needed for
@ -1067,8 +1063,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
buffer->undo().beginUndoGroup(); buffer->undo().beginUndoGroup();
// Let the current LyXView dispatch its own actions. // Let the current LyXView dispatch its own actions.
if (lyx_view_->dispatch(cmd)) { if (lv->dispatch(cmd)) {
BufferView * bv = lyx_view_->currentBufferView(); BufferView * bv = lv->currentBufferView();
if (bv) { if (bv) {
buffer = &(bv->buffer()); buffer = &(bv->buffer());
updateFlags = bv->cursor().result().update(); updateFlags = bv->cursor().result().update();
@ -1078,7 +1074,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
break; break;
} }
BufferView * bv = lyx_view_->currentBufferView(); BufferView * bv = lv->currentBufferView();
LASSERT(bv, /**/); LASSERT(bv, /**/);
// Let the current BufferView dispatch its own actions. // Let the current BufferView dispatch its own actions.
@ -1091,7 +1087,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
break; break;
} }
BufferView * doc_bv = lyx_view_->documentBufferView(); BufferView * doc_bv = lv->documentBufferView();
// Try with the document BufferView dispatch if any. // Try with the document BufferView dispatch if any.
if (doc_bv && doc_bv->dispatch(cmd)) { if (doc_bv && doc_bv->dispatch(cmd)) {
// The BufferView took care of its own updates if needed. // The BufferView took care of its own updates if needed.
@ -1155,11 +1151,11 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
if (cmd.origin == FuncRequest::KEYBOARD) { if (cmd.origin == FuncRequest::KEYBOARD) {
if (cmd.action == LFUN_SELF_INSERT if (cmd.action == LFUN_SELF_INSERT
|| (cmd.action == LFUN_ERT_INSERT && bv->cursor().inMathed())) || (cmd.action == LFUN_ERT_INSERT && bv->cursor().inMathed()))
lyx_view_->updateCompletion(bv->cursor(), true, true); lv->updateCompletion(bv->cursor(), true, true);
else if (cmd.action == LFUN_CHAR_DELETE_BACKWARD) else if (cmd.action == LFUN_CHAR_DELETE_BACKWARD)
lyx_view_->updateCompletion(bv->cursor(), false, true); lv->updateCompletion(bv->cursor(), false, true);
else else
lyx_view_->updateCompletion(bv->cursor(), false, false); lv->updateCompletion(bv->cursor(), false, false);
} }
updateFlags = bv->cursor().result().update(); updateFlags = bv->cursor().result().update();
@ -1171,22 +1167,22 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
&& !lyxaction.funcHasFlag(action, LyXAction::ReadOnly)) && !lyxaction.funcHasFlag(action, LyXAction::ReadOnly))
buffer->markDirty(); buffer->markDirty();
if (lyx_view_ && lyx_view_->currentBufferView()) { if (lv && lv->currentBufferView()) {
// BufferView::update() updates the ViewMetricsInfo and // BufferView::update() updates the ViewMetricsInfo and
// also initializes the position cache for all insets in // also initializes the position cache for all insets in
// (at least partially) visible top-level paragraphs. // (at least partially) visible top-level paragraphs.
// We will redraw the screen only if needed. // We will redraw the screen only if needed.
lyx_view_->currentBufferView()->processUpdateFlags(updateFlags); lv->currentBufferView()->processUpdateFlags(updateFlags);
// Do we have a selection? // Do we have a selection?
theSelection().haveSelection( theSelection().haveSelection(
lyx_view_->currentBufferView()->cursor().selection()); lv->currentBufferView()->cursor().selection());
// update gui // update gui
lyx_view_->restartCursor(); lv->restartCursor();
} }
} }
if (lyx_view_) { if (lv) {
// Some messages may already be translated, so we cannot use _() // Some messages may already be translated, so we cannot use _()
sendDispatchMessage(translateIfPossible(getMessage()), cmd); sendDispatchMessage(translateIfPossible(getMessage()), cmd);
} }
@ -1199,10 +1195,11 @@ void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd
|| cmd.origin == FuncRequest::TOOLBAR || cmd.origin == FuncRequest::TOOLBAR
|| cmd.origin == FuncRequest::COMMANDBUFFER); || cmd.origin == FuncRequest::COMMANDBUFFER);
LyXView * lv = theApp()->currentWindow();
if (cmd.action == LFUN_SELF_INSERT || !verbose) { if (cmd.action == LFUN_SELF_INSERT || !verbose) {
LYXERR(Debug::ACTION, "dispatch msg is " << to_utf8(msg)); LYXERR(Debug::ACTION, "dispatch msg is " << to_utf8(msg));
if (!msg.empty()) if (!msg.empty())
lyx_view_->message(msg); lv->message(msg);
return; return;
} }
@ -1235,11 +1232,11 @@ void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd
LYXERR(Debug::ACTION, "verbose dispatch msg " << to_utf8(dispatch_msg)); LYXERR(Debug::ACTION, "verbose dispatch msg " << to_utf8(dispatch_msg));
if (!dispatch_msg.empty()) if (!dispatch_msg.empty())
lyx_view_->message(dispatch_msg); lv->message(dispatch_msg);
} }
// Each "lyx_view_" should have it's own message method. lyxview and // Each LyXView should have it's own message method. lyxview and
// the minibuffer would use the minibuffer, but lyxserver would // the minibuffer would use the minibuffer, but lyxserver would
// send an ERROR signal to its client. Alejandro 970603 // send an ERROR signal to its client. Alejandro 970603
// This function is bit problematic when it comes to NLS, to make the // This function is bit problematic when it comes to NLS, to make the
@ -1269,11 +1266,12 @@ docstring LyXFunc::viewStatusMessage()
if (keyseq.length() > 0 && !keyseq.deleted()) if (keyseq.length() > 0 && !keyseq.deleted())
return keyseq.printOptions(true); return keyseq.printOptions(true);
LASSERT(lyx_view_, /**/); LyXView * lv = theApp()->currentWindow();
if (!lyx_view_->currentBufferView()) LASSERT(lv, /**/);
if (!lv->currentBufferView())
return _("Welcome to LyX!"); return _("Welcome to LyX!");
return lyx_view_->currentBufferView()->cursor().currentState(); return lv->currentBufferView()->cursor().currentState();
} }

View File

@ -53,9 +53,6 @@ public:
/// LyX dispatcher, executes lyx actions. /// LyX dispatcher, executes lyx actions.
void dispatch(FuncRequest const &); void dispatch(FuncRequest const &);
///
void setLyXView(frontend::LyXView * lv);
/// ///
void initKeySequences(KeyMap * kb); void initKeySequences(KeyMap * kb);
@ -93,9 +90,6 @@ public:
int cursorBeforeDispatchY() const { return cursorPosBeforeDispatchY_; } int cursorBeforeDispatchY() const { return cursorPosBeforeDispatchY_; }
private: private:
///
frontend::LyXView * lyx_view_;
/// the last character added to the key sequence, in UCS4 encoded form /// the last character added to the key sequence, in UCS4 encoded form
char_type encoded_last_key; char_type encoded_last_key;

View File

@ -167,7 +167,8 @@ public:
Application() {} Application() {}
/// ///
virtual ~Application() {} virtual ~Application() {}
///
virtual LyXView * currentWindow() = 0;
/// ///
virtual bool getStatus(FuncRequest const & cmd, FuncStatus & flag) const = 0; virtual bool getStatus(FuncRequest const & cmd, FuncStatus & flag) const = 0;
/// dispatch command. /// dispatch command.

View File

@ -63,9 +63,6 @@ void Action::action()
{ {
//LYXERR(Debug::ACTION, "calling LyXFunc::dispatch: func_: "); //LYXERR(Debug::ACTION, "calling LyXFunc::dispatch: func_: ");
if (lyxView_)
theLyXFunc().setLyXView(lyxView_);
lyx::dispatch(func_); lyx::dispatch(func_);
triggered(this); triggered(this);
} }

View File

@ -58,7 +58,6 @@ bool Dialog::canApply() const
void Dialog::dispatch(FuncRequest const & fr) const void Dialog::dispatch(FuncRequest const & fr) const
{ {
theLyXFunc().setLyXView(lyxview_);
lyx::dispatch(fr); lyx::dispatch(fr);
} }

View File

@ -800,6 +800,11 @@ docstring GuiApplication::iconName(FuncRequest const & f, bool unknown)
} }
LyXView * GuiApplication::currentWindow()
{
return current_view_;
}
bool GuiApplication::getStatus(FuncRequest const & cmd, FuncStatus & flag) const bool GuiApplication::getStatus(FuncRequest const & cmd, FuncStatus & flag) const
{ {
@ -1443,10 +1448,8 @@ void GuiApplication::unregisterView(GuiView * gv)
{ {
LASSERT(d->views_[gv->id()] == gv, /**/); LASSERT(d->views_[gv->id()] == gv, /**/);
d->views_.remove(gv->id()); d->views_.remove(gv->id());
if (current_view_ == gv) { if (current_view_ == gv)
current_view_ = 0; current_view_ = 0;
theLyXFunc().setLyXView(0);
}
} }

View File

@ -57,6 +57,7 @@ public:
/// Method inherited from \c Application class /// Method inherited from \c Application class
//@{ //@{
LyXView * currentWindow();
bool getStatus(FuncRequest const & cmd, FuncStatus & flag) const; bool getStatus(FuncRequest const & cmd, FuncStatus & flag) const;
bool dispatch(FuncRequest const &); bool dispatch(FuncRequest const &);
void dispatchDelayed(FuncRequest const &); void dispatchDelayed(FuncRequest const &);

View File

@ -304,7 +304,6 @@ docstring const GuiCommandBuffer::getCurrentState() const
void GuiCommandBuffer::hide() const void GuiCommandBuffer::hide() const
{ {
FuncRequest cmd(LFUN_COMMAND_EXECUTE, "off"); FuncRequest cmd(LFUN_COMMAND_EXECUTE, "off");
theLyXFunc().setLyXView(view_);
lyx::dispatch(cmd); lyx::dispatch(cmd);
} }
@ -359,7 +358,6 @@ void GuiCommandBuffer::dispatch(string const & str)
downPB->setEnabled(history_pos_ != history_.end()); downPB->setEnabled(history_pos_ != history_.end());
FuncRequest func = lyxaction.lookupFunc(str); FuncRequest func = lyxaction.lookupFunc(str);
func.origin = FuncRequest::COMMANDBUFFER; func.origin = FuncRequest::COMMANDBUFFER;
theLyXFunc().setLyXView(view_);
lyx::dispatch(func); lyx::dispatch(func);
} }

View File

@ -303,7 +303,7 @@ GuiView::GuiView(int id)
// set ourself as the current view. This is needed for the menu bar // set ourself as the current view. This is needed for the menu bar
// filling, at least for the static special menu item on Mac. Otherwise // filling, at least for the static special menu item on Mac. Otherwise
// they are greyed out. // they are greyed out.
theLyXFunc().setLyXView(this); guiApp->setCurrentView(this);
// Fill up the menu bar. // Fill up the menu bar.
guiApp->menus().fillMenuBar(menuBar(), this, true); guiApp->menus().fillMenuBar(menuBar(), this, true);
@ -512,7 +512,6 @@ void GuiView::setFocus()
LYXERR(Debug::DEBUG, "GuiView::setFocus()" << this); LYXERR(Debug::DEBUG, "GuiView::setFocus()" << this);
// Make sure LyXFunc points to the correct view. // Make sure LyXFunc points to the correct view.
guiApp->setCurrentView(this); guiApp->setCurrentView(this);
theLyXFunc().setLyXView(this);
QMainWindow::setFocus(); QMainWindow::setFocus();
if (d.current_work_area_) if (d.current_work_area_)
d.current_work_area_->setFocus(); d.current_work_area_->setFocus();
@ -653,7 +652,6 @@ void GuiView::clearMessage()
{ {
if (!hasFocus()) if (!hasFocus())
return; return;
theLyXFunc().setLyXView(this);
statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage())); statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
d.statusbar_timer_.stop(); d.statusbar_timer_.stop();
} }
@ -731,7 +729,6 @@ void GuiView::updateStatusBar()
if (d.statusbar_timer_.isActive()) if (d.statusbar_timer_.isActive())
return; return;
theLyXFunc().setLyXView(this);
statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage())); statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
} }
@ -762,12 +759,17 @@ bool GuiView::event(QEvent * e)
// break; // break;
case QEvent::WindowActivate: { case QEvent::WindowActivate: {
if (this == guiApp->currentView()) { GuiView * old_view = guiApp->currentView();
if (this == old_view) {
setFocus(); setFocus();
return QMainWindow::event(e); return QMainWindow::event(e);
} }
if (old_view) {
// save current selection to the selection buffer to allow
// middle-button paste in this window.
cap::saveSelection(old_view->currentBufferView()->cursor());
}
guiApp->setCurrentView(this); guiApp->setCurrentView(this);
theLyXFunc().setLyXView(this);
if (d.current_work_area_) { if (d.current_work_area_) {
BufferView & bv = d.current_work_area_->bufferView(); BufferView & bv = d.current_work_area_->bufferView();
connectBufferView(bv); connectBufferView(bv);
@ -815,7 +817,6 @@ bool GuiView::event(QEvent * e)
// Allow processing of shortcuts that are allowed even when no Buffer // Allow processing of shortcuts that are allowed even when no Buffer
// is viewed. // is viewed.
theLyXFunc().setLyXView(this);
KeySymbol sym; KeySymbol sym;
setKeySymbol(&sym, ke); setKeySymbol(&sym, ke);
theLyXFunc().processKeySym(sym, q_key_state(ke->modifiers())); theLyXFunc().processKeySym(sym, q_key_state(ke->modifiers()));
@ -1588,7 +1589,7 @@ static bool import(GuiView * lv, FileName const & filename,
formats.extension(loader_format)); formats.extension(loader_format));
lv->currentBufferView()->insertPlaintextFile(FileName(filename2), lv->currentBufferView()->insertPlaintextFile(FileName(filename2),
as_paragraphs); as_paragraphs);
theLyXFunc().setLyXView(lv); guiApp->setCurrentView(lv);
lyx::dispatch(FuncRequest(LFUN_MARK_OFF)); lyx::dispatch(FuncRequest(LFUN_MARK_OFF));
} }
@ -2877,14 +2878,14 @@ bool isValidName(string const & name)
void GuiView::resetDialogs() void GuiView::resetDialogs()
{ {
// Make sure that no LFUN uses any LyXView. // Make sure that no LFUN uses any LyXView.
theLyXFunc().setLyXView(0); guiApp->setCurrentView(0);
saveLayout(); saveLayout();
menuBar()->clear(); menuBar()->clear();
constructToolbars(); constructToolbars();
guiApp->menus().fillMenuBar(menuBar(), this, false); guiApp->menus().fillMenuBar(menuBar(), this, false);
d.layout_->updateContents(true); d.layout_->updateContents(true);
// Now update controls with current buffer. // Now update controls with current buffer.
theLyXFunc().setLyXView(this); guiApp->setCurrentView(this);
restoreLayout(); restoreLayout();
restartCursor(); restartCursor();
} }

View File

@ -455,8 +455,6 @@ void GuiWorkArea::processKeySym(KeySymbol const & key, KeyModifier mod)
// we better stop the blinking cursor... // we better stop the blinking cursor...
// the cursor gets restarted in GuiView::restartCursor() // the cursor gets restarted in GuiView::restartCursor()
stopBlinkingCursor(); stopBlinkingCursor();
theLyXFunc().setLyXView(lyx_view_);
theLyXFunc().processKeySym(key, mod); theLyXFunc().processKeySym(key, mod);
} }
@ -469,8 +467,6 @@ void GuiWorkArea::dispatch(FuncRequest const & cmd0, KeyModifier mod)
return; return;
} }
theLyXFunc().setLyXView(lyx_view_);
FuncRequest cmd; FuncRequest cmd;
if (cmd0.action == LFUN_MOUSE_PRESS) { if (cmd0.action == LFUN_MOUSE_PRESS) {

View File

@ -108,7 +108,6 @@ void InsertTableWidget::mouseReleaseEvent(QMouseEvent * /*event*/)
{ {
if (underMouse_) { if (underMouse_) {
QString const data = QString("%1 %2").arg(bottom_).arg(right_); QString const data = QString("%1 %2").arg(bottom_).arg(right_);
theLyXFunc().setLyXView(&lyxView_);
lyx::dispatch(FuncRequest(LFUN_TABULAR_INSERT, fromqstr(data))); lyx::dispatch(FuncRequest(LFUN_TABULAR_INSERT, fromqstr(data)));
} }
// emit signal // emit signal

View File

@ -687,7 +687,6 @@ void LayoutBox::selected(int index)
// find corresponding text class // find corresponding text class
if (d->text_class_->hasLayout(layoutName)) { if (d->text_class_->hasLayout(layoutName)) {
FuncRequest const func(LFUN_LAYOUT, layoutName, FuncRequest::TOOLBAR); FuncRequest const func(LFUN_LAYOUT, layoutName, FuncRequest::TOOLBAR);
theLyXFunc().setLyXView(&d->owner_);
lyx::dispatch(func); lyx::dispatch(func);
updateContents(false); updateContents(false);
d->resetFilter(); d->resetFilter();

View File

@ -1850,9 +1850,6 @@ void Menus::updateMenu(Menu * qmenu)
if (qmenu->d->name.isEmpty()) if (qmenu->d->name.isEmpty())
return; return;
// Here, We make sure that theLyXFunc points to the correct LyXView.
theLyXFunc().setLyXView(qmenu->d->view);
if (!d->hasMenu(qmenu->d->name)) { if (!d->hasMenu(qmenu->d->name)) {
qmenu->addAction(qt_("No Action Defined!")); qmenu->addAction(qt_("No Action Defined!"));
LYXERR(Debug::GUI, "\tWARNING: non existing menu: " LYXERR(Debug::GUI, "\tWARNING: non existing menu: "