FindAndReplace: more simplification and correct focus handling.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27668 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2008-11-22 17:35:17 +00:00
parent 227dd33f2f
commit b718b83074
4 changed files with 21 additions and 63 deletions

View File

@ -50,6 +50,7 @@ FindAndReplace::FindAndReplace(GuiView & parent)
setupUi(this); setupUi(this);
find_work_area_->setGuiView(parent_view_); find_work_area_->setGuiView(parent_view_);
find_work_area_->init(); find_work_area_->init();
setFocusProxy(find_work_area_);
} }
@ -133,20 +134,11 @@ void FindAndReplace::findAdv(bool casesensitive,
// searchString, len, casesensitive, matchword, ! backwards, expandmacros); // searchString, len, casesensitive, matchword, ! backwards, expandmacros);
} }
bool FindAndReplace::initialiseParams(std::string const &)
void FindAndReplace::showEvent(QShowEvent *ev)
{ {
find_work_area_->setFocus();
selectAll(); selectAll();
QWidget::showEvent(ev); return true;
}
void FindAndReplace::hideEvent(QHideEvent *ev)
{
LYXERR(Debug::DEBUG, "FindAndReplace::hideEvent");
find_work_area_->removeEventFilter(this);
find_work_area_->disable();
this->QWidget::hideEvent(ev);
} }
@ -159,7 +151,6 @@ void FindAndReplace::find(bool backwards)
expandMacrosCB->isChecked(), expandMacrosCB->isChecked(),
ignoreFormatCB->isChecked()); ignoreFormatCB->isChecked());
parent_view_.currentMainWorkArea()->redraw(); parent_view_.currentMainWorkArea()->redraw();
parent_view_.setCurrentWorkArea(find_work_area_);
find_work_area_->setFocus(); find_work_area_->setFocus();
} }

View File

@ -36,15 +36,12 @@ class FindAndReplace : public DockView, public Ui::FindAndReplaceUi
public: public:
FindAndReplace(GuiView & parent); FindAndReplace(GuiView & parent);
bool initialiseParams(std::string const &) { return true; } bool initialiseParams(std::string const &);
void clearParams() {} void clearParams() {}
void dispatchParams() {} void dispatchParams() {}
bool isBufferDependent() const { return true; } bool isBufferDependent() const { return true; }
void selectAll(); void selectAll();
void showEvent(QShowEvent * ev);
void hideEvent(QHideEvent * ev);
/// update /// update
void updateView() {} void updateView() {}
//virtual void update_contents() {} //virtual void update_contents() {}

View File

@ -1223,13 +1223,10 @@ bool GuiWorkArea::isFullScreen()
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
EmbeddedWorkArea::EmbeddedWorkArea(QWidget * w): GuiWorkArea(w), EmbeddedWorkArea::EmbeddedWorkArea(QWidget * w): GuiWorkArea(w)
delayed_focus_timer_(this)
{ {
buffer_ = theBufferList().newBuffer( buffer_ = theBufferList().newBuffer(
support::FileName::tempName().absFilename() + "_embedded.internal"); support::FileName::tempName().absFilename() + "_embedded.internal");
LASSERT(buffer_ != 0, /* */);
buffer_->setUnnamed(true); buffer_->setUnnamed(true);
buffer_->setFullyLoaded(true); buffer_->setFullyLoaded(true);
setBuffer(*buffer_); setBuffer(*buffer_);
@ -1245,49 +1242,28 @@ EmbeddedWorkArea::~EmbeddedWorkArea()
} }
void EmbeddedWorkArea::onDelayedFocus() void EmbeddedWorkArea::closeEvent(QCloseEvent * ev)
{ {
LYXERR(Debug::DEBUG, "Delayed Focus");
view().setCurrentWorkArea(this);
setFocus();
}
void EmbeddedWorkArea::showEvent(QShowEvent *ev)
{
view().setCurrentWorkArea(this);
redraw();
setFocus();
installEventFilter(this);
connect(&delayed_focus_timer_, SIGNAL(timeout()), this,
SLOT(onDelayedFocus()));
delayed_focus_timer_.setSingleShot(true);
delayed_focus_timer_.start(100);
GuiWorkArea::showEvent(ev);
}
void EmbeddedWorkArea::closeEvent(QCloseEvent * close_event)
{
LYXERR(Debug::DEBUG, "FindAndReplace::closeEvent()");
removeEventFilter(this);
disable(); disable();
GuiWorkArea::closeEvent(ev);
}
GuiWorkArea::closeEvent(close_event);
void EmbeddedWorkArea::hideEvent(QHideEvent * ev)
{
disable();
GuiWorkArea::hideEvent(ev);
} }
void EmbeddedWorkArea::disable() void EmbeddedWorkArea::disable()
{ {
// Ok, closing the window before 100ms may be impossible, however... stopBlinkingCursor();
delayed_focus_timer_.stop(); if (view().currentWorkArea() != this)
if (view().currentWorkArea() == this) { return;
LASSERT(view().currentMainWorkArea(), /* */); LASSERT(view().currentMainWorkArea(), /* */);
view().setCurrentWorkArea(view().currentMainWorkArea()); view().setCurrentWorkArea(view().currentMainWorkArea());
} }
stopBlinkingCursor();
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// //

View File

@ -278,17 +278,11 @@ public:
protected: protected:
/// ///
void showEvent(QShowEvent * ev); void closeEvent(QCloseEvent * ev);
/// this happens when the dialog is simply closed/hidden ///
void closeEvent(QCloseEvent * e); void hideEvent(QHideEvent *ev);
private Q_SLOTS:
/// this happens 100ms after dialog showEvent()
void onDelayedFocus();
private: private:
/// @TODO: Investigate on focus issue and remove this ugly hack, please !
QTimer delayed_focus_timer_;
/// Embedded Buffer. /// Embedded Buffer.
Buffer * buffer_; Buffer * buffer_;
}; // EmbeddedWorkArea }; // EmbeddedWorkArea