LibreOffice Module dbaccess (master) 1
QueryTextView.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <svx/svxids.hrc>
21#include <QueryTextView.hxx>
23#include <helpids.h>
24#include <querycontroller.hxx>
25#include <sqledit.hxx>
26#include <undosqledit.hxx>
27
28using namespace dbaui;
29using namespace ::com::sun::star::uno;
30using namespace ::com::sun::star::lang;
31
32// end of temp classes
33OQueryTextView::OQueryTextView(OQueryContainerWindow* pParent, OQueryController& rController)
34 : InterimItemWindow(pParent, "dbaccess/ui/queryview.ui", "QueryView")
35 , m_rController(rController)
36 , m_xSQL(new SQLEditView(m_xBuilder->weld_scrolled_window("scrolledwindow", true)))
37 , m_xSQLEd(new weld::CustomWeld(*m_xBuilder, "sql", *m_xSQL))
38 , m_timerUndoActionCreation("dbaccess OQueryTextView m_timerUndoActionCreation")
39 , m_timerInvalidate("dbaccess OQueryTextView m_timerInvalidate")
40 , m_bStopTimer(false)
41{
42 m_xSQL->DisableInternalUndo();
43 m_xSQL->SetHelpId(HID_CTL_QRYSQLEDIT);
44 m_xSQL->SetModifyHdl(LINK(this, OQueryTextView, ModifyHdl));
45 m_xSQL->SetAcceptsTab(true);
46
49
51 m_timerInvalidate.SetInvokeHandler(LINK(this, OQueryTextView, OnInvalidateTimer));
53}
54
56{
57 if (m_timerUndoActionCreation.IsActive())
58 m_timerUndoActionCreation.Stop();
59 m_timerUndoActionCreation.Start();
60
61 if (!m_rController.isModified())
62 m_rController.setModified(true);
63
64 m_rController.InvalidateFeature(SID_SBA_QRY_EXECUTE);
65 m_rController.InvalidateFeature(SID_CUT);
66 m_rController.InvalidateFeature(SID_COPY);
67}
68
69IMPL_LINK_NOARG(OQueryTextView, OnUndoActionTimer, Timer*, void)
70{
71 OUString aText = m_xSQL->GetText();
72 if (aText == m_strOrigText)
73 return;
74
75 SfxUndoManager& rUndoMgr = m_rController.GetUndoManager();
76 std::unique_ptr<OSqlEditUndoAct> xUndoAct(new OSqlEditUndoAct(*this));
77
78 xUndoAct->SetOriginalText(m_strOrigText);
79 rUndoMgr.AddUndoAction(std::move(xUndoAct));
80
81 m_rController.InvalidateFeature(SID_UNDO);
82 m_rController.InvalidateFeature(SID_REDO);
83
84 m_strOrigText = aText;
85}
86
87IMPL_LINK_NOARG(OQueryTextView, OnInvalidateTimer, Timer*, void)
88{
89 m_rController.InvalidateFeature(SID_CUT);
90 m_rController.InvalidateFeature(SID_COPY);
91 if (!m_bStopTimer)
92 m_timerInvalidate.Start();
93}
94
96{
97 m_bStopTimer = false;
100}
101
103{
104 m_bStopTimer = true;
107}
108
110
112{
115
116 m_xSQLEd.reset();
117 m_xSQL.reset();
119}
120
122{
123 if (m_xSQL)
124 {
125 m_xSQL->GrabFocus();
126 m_strOrigText = m_xSQL->GetText();
127 }
129}
130
131OUString OQueryTextView::getStatement() const { return m_xSQL->GetText(); }
132
134{
135 std::unique_ptr<OSqlEditUndoAct> xUndoAct(new OSqlEditUndoAct(*this));
136
137 xUndoAct->SetOriginalText(m_xSQL->GetText());
138 m_rController.addUndoActionAndInvalidate(std::move(xUndoAct));
139
140 SetSQLText(OUString());
141}
142
143void OQueryTextView::setStatement(const OUString& rsStatement) { SetSQLText(rsStatement); }
144
145OUString OQueryTextView::GetSQLText() const { return m_xSQL->GetText(); }
146
147void OQueryTextView::SetSQLText(const OUString& rNewText)
148{
150 {
151 // create the trailing undo-actions
153 OnUndoActionTimer(nullptr);
154 }
155
156 m_xSQL->SetTextAndUpdate(rNewText);
157
158 m_strOrigText = rNewText;
159}
160
161void OQueryTextView::copy() { m_xSQL->Copy(); }
162
163bool OQueryTextView::isCutAllowed() const { return m_xSQL->HasSelection(); }
164
166{
167 m_xSQL->Cut();
168 m_rController.setModified(true);
169}
170
172{
173 m_xSQL->Paste();
174 m_rController.setModified(true);
175}
176
177/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void dispose() override
virtual void GetFocus() override
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
bool IsActive() const
void Stop()
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
virtual void Start(bool bStartTimer=true) override
OUString GetSQLText() const
std::unique_ptr< SQLEditView > m_xSQL
virtual ~OQueryTextView() override
void SetSQLText(const OUString &rNewText)
std::unique_ptr< weld::CustomWeld > m_xSQLEd
virtual void dispose() override
void setStatement(const OUString &_rsStatement)
OQueryController & m_rController
OUString getStatement() const
virtual void GetFocus() override
void addUndoActionAndInvalidate(std::unique_ptr< SfxUndoAction > pAction)
addUndoActionAndInvalidate adds an undo action to the undoManager, additionally invalidates the UNDO ...
ClassificationCategoriesController & m_rController
constexpr OUStringLiteral HID_CTL_QRYSQLEDIT
Definition: helpids.h:31
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)