diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-08-18 12:02:45 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-08-19 10:11:30 +0200 |
commit | 44f7674ffda49257dcc1709256dfc4676d12165c (patch) | |
tree | bdc5495436058e4f153d4b5ddad22249685558db /dbaccess/source/ui/querydesign | |
parent | 1b03a449161af225302e4b4dd2bb2e69c6d8d170 (diff) |
weld OQueryTextView
its plausible with the EditEngine replacement for the SQL
editor that the undo could be integrated better than the
current check-if-the-text-has-changed timeout method. But
that's left unchanged with this commit.
Change-Id: I9b9e373044a80ee94dab4ceaad0ef2801b0b1166
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100950
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'dbaccess/source/ui/querydesign')
-rw-r--r-- | dbaccess/source/ui/querydesign/QueryTextView.cxx | 151 | ||||
-rw-r--r-- | dbaccess/source/ui/querydesign/QueryViewSwitch.cxx | 8 |
2 files changed, 121 insertions, 38 deletions
diff --git a/dbaccess/source/ui/querydesign/QueryTextView.cxx b/dbaccess/source/ui/querydesign/QueryTextView.cxx index 9633146900c6..495d447030ba 100644 --- a/dbaccess/source/ui/querydesign/QueryTextView.cxx +++ b/dbaccess/source/ui/querydesign/QueryTextView.cxx @@ -17,8 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sfx2/sfxsids.hrc> +#include <svx/svxids.hrc> #include <QueryTextView.hxx> #include <querycontainerwindow.hxx> +#include <helpids.h> #include <sqledit.hxx> #include <undosqledit.hxx> #include <QueryDesignView.hxx> @@ -28,15 +31,77 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; // end of temp classes -OQueryTextView::OQueryTextView(OQueryContainerWindow* _pParent) - :Window(_pParent) +OQueryTextView::OQueryTextView(OQueryContainerWindow* pParent, OQueryController& rController) + : InterimItemWindow(pParent, "dbaccess/ui/queryview.ui", "QueryView") + , m_rController(rController) + , m_xSQL(new SQLEditView) + , m_xSQLEd(new weld::CustomWeld(*m_xBuilder, "sql", *m_xSQL)) + , m_bStopTimer(false) { - m_pEdit = VclPtr<OSqlEdit>::Create(this); - m_pEdit->SetRightToLeft(false); - m_pEdit->ClearModifyFlag(); - m_pEdit->SaveValue(); - m_pEdit->SetPosPixel( Point( 0, 0 ) ); - m_pEdit->Show(); + m_xSQL->DisableInternalUndo(); + m_xSQL->SetHelpId(HID_CTL_QRYSQLEDIT); + m_xSQL->SetModifyHdl(LINK(this, OQueryTextView, ModifyHdl)); + + m_timerUndoActionCreation.SetTimeout(1000); + m_timerUndoActionCreation.SetInvokeHandler(LINK(this, OQueryTextView, OnUndoActionTimer)); + + m_timerInvalidate.SetTimeout(200); + m_timerInvalidate.SetInvokeHandler(LINK(this, OQueryTextView, OnInvalidateTimer)); + m_timerInvalidate.Start(); +} + +IMPL_LINK_NOARG(OQueryTextView, ModifyHdl, LinkParamNone*, void) +{ + if (m_timerUndoActionCreation.IsActive()) + m_timerUndoActionCreation.Stop(); + m_timerUndoActionCreation.Start(); + + if (!m_rController.isModified()) + m_rController.setModified( true ); + + m_rController.InvalidateFeature(SID_SBA_QRY_EXECUTE); + m_rController.InvalidateFeature(SID_CUT); + m_rController.InvalidateFeature(SID_COPY); +} + +IMPL_LINK_NOARG(OQueryTextView, OnUndoActionTimer, Timer*, void) +{ + OUString aText = m_xSQL->GetText(); + if (aText == m_strOrigText) + return; + + SfxUndoManager& rUndoMgr = m_rController.GetUndoManager(); + std::unique_ptr<OSqlEditUndoAct> xUndoAct(new OSqlEditUndoAct(*this)); + + xUndoAct->SetOriginalText(m_strOrigText); + rUndoMgr.AddUndoAction(std::move(xUndoAct)); + + m_rController.InvalidateFeature(SID_UNDO); + m_rController.InvalidateFeature(SID_REDO); + + m_strOrigText = aText; +} + +IMPL_LINK_NOARG(OQueryTextView, OnInvalidateTimer, Timer*, void) +{ + m_rController.InvalidateFeature(SID_CUT); + m_rController.InvalidateFeature(SID_COPY); + if (!m_bStopTimer) + m_timerInvalidate.Start(); +} + +void OQueryTextView::startTimer() +{ + m_bStopTimer = false; + if (!m_timerInvalidate.IsActive()) + m_timerInvalidate.Start(); +} + +void OQueryTextView::stopTimer() +{ + m_bStopTimer = true; + if (m_timerInvalidate.IsActive()) + m_timerInvalidate.Stop(); } OQueryTextView::~OQueryTextView() @@ -46,65 +111,83 @@ OQueryTextView::~OQueryTextView() void OQueryTextView::dispose() { - m_pEdit.disposeAndClear(); - vcl::Window::dispose(); -} + if (m_timerUndoActionCreation.IsActive()) + m_timerUndoActionCreation.Stop(); -void OQueryTextView::GetFocus() -{ - if ( m_pEdit ) - m_pEdit->GrabFocus(); + m_xSQLEd.reset(); + m_xSQL.reset(); + InterimItemWindow::dispose(); } -void OQueryTextView::Resize() +void OQueryTextView::GetFocus() { - Window::Resize(); - m_pEdit->SetSizePixel( GetOutputSizePixel() ); + if (m_xSQL) + { + m_xSQL->GrabFocus(); + m_strOrigText = m_xSQL->GetText(); + } + InterimItemWindow::GetFocus(); } OUString OQueryTextView::getStatement() const { - return m_pEdit->GetText(); + return m_xSQL->GetText(); } void OQueryTextView::clear() { - std::unique_ptr<OSqlEditUndoAct> pUndoAct(new OSqlEditUndoAct( m_pEdit )); + std::unique_ptr<OSqlEditUndoAct> xUndoAct(new OSqlEditUndoAct(*this)); - pUndoAct->SetOriginalText( m_pEdit->GetText() ); - getContainerWindow()->getDesignView()->getController().addUndoActionAndInvalidate( std::move(pUndoAct) ); + xUndoAct->SetOriginalText(m_xSQL->GetText()); + m_rController.addUndoActionAndInvalidate( std::move(xUndoAct) ); - m_pEdit->SetText(OUString()); + SetSQLText(OUString()); } -void OQueryTextView::setStatement(const OUString& _rsStatement) +void OQueryTextView::setStatement(const OUString& rsStatement) { - m_pEdit->SetText(_rsStatement); + SetSQLText(rsStatement); +} + +OUString OQueryTextView::GetSQLText() const +{ + return m_xSQL->GetText(); +} + +void OQueryTextView::SetSQLText(const OUString& rNewText) +{ + if (m_timerUndoActionCreation.IsActive()) + { + // create the trailing undo-actions + m_timerUndoActionCreation.Stop(); + OnUndoActionTimer(nullptr); + } + + m_xSQL->SetTextAndUpdate(rNewText); + + m_strOrigText = rNewText; } void OQueryTextView::copy() { - if(!m_pEdit->IsInAccelAct() ) - m_pEdit->Copy(); + m_xSQL->Copy(); } bool OQueryTextView::isCutAllowed() const { - return !m_pEdit->GetSelected().isEmpty(); + return m_xSQL->HasSelection(); } void OQueryTextView::cut() { - if(!m_pEdit->IsInAccelAct() ) - m_pEdit->Cut(); - getContainerWindow()->getDesignView()->getController().setModified(true); + m_xSQL->Cut(); + m_rController.setModified(true); } void OQueryTextView::paste() { - if(!m_pEdit->IsInAccelAct() ) - m_pEdit->Paste(); - getContainerWindow()->getDesignView()->getController().setModified(true); + m_xSQL->Paste(); + m_rController.setModified(true); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx b/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx index e7d6758f480f..626a1f346e44 100644 --- a/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx +++ b/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx @@ -33,7 +33,7 @@ OQueryViewSwitch::OQueryViewSwitch(OQueryContainerWindow* _pParent, OQueryContro : m_bAddTableDialogWasVisible(false) { - m_pTextView = VclPtr<OQueryTextView>::Create(_pParent); + m_pTextView = VclPtr<OQueryTextView>::Create(_pParent, _rController); m_pDesignView = VclPtr<OQueryDesignView>::Create( _pParent, _rController, _rxContext ); } @@ -154,7 +154,7 @@ void OQueryViewSwitch::impl_forceSQLView() // tell the views they're in/active m_pDesignView->stopTimer(); - m_pTextView->getSqlEdit()->startTimer(); + m_pTextView->startTimer(); // set the most recent statement at the text view m_pTextView->clear(); @@ -170,7 +170,7 @@ void OQueryViewSwitch::forceInitialView() else { // tell the text view it's inactive now - m_pTextView->getSqlEdit()->stopTimer(); + m_pTextView->stopTimer(); // update the "Add Table" dialog OAddTableDlg* pAddTabDialog( getAddTableDialog() ); @@ -199,7 +199,7 @@ bool OQueryViewSwitch::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo ) else { // tell the text view it's inactive now - m_pTextView->getSqlEdit()->stopTimer(); + m_pTextView->stopTimer(); // update the "Add Table" dialog OAddTableDlg* pAddTabDialog( getAddTableDialog() ); |