1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/svxids.hrc>
21 #include <QueryTextView.hxx>
22 #include <querycontainerwindow.hxx>
24 #include <querycontroller.hxx>
25 #include <sqledit.hxx>
26 #include <undosqledit.hxx>
28 using namespace dbaui
;
30 // end of temp classes
31 OQueryTextView::OQueryTextView(OQueryContainerWindow
* pParent
, OQueryController
& rController
)
32 : InterimItemWindow(pParent
, u
"dbaccess/ui/queryview.ui"_ustr
, u
"QueryView"_ustr
)
33 , m_rController(rController
)
34 , m_xSQL(new SQLEditView(m_xBuilder
->weld_scrolled_window(u
"scrolledwindow"_ustr
, true)))
35 , m_xSQLEd(new weld::CustomWeld(*m_xBuilder
, u
"sql"_ustr
, *m_xSQL
))
36 , m_timerUndoActionCreation("dbaccess OQueryTextView m_timerUndoActionCreation")
37 , m_timerInvalidate("dbaccess OQueryTextView m_timerInvalidate")
40 m_xSQL
->DisableInternalUndo();
41 m_xSQL
->SetHelpId(HID_CTL_QRYSQLEDIT
);
42 m_xSQL
->SetModifyHdl(LINK(this, OQueryTextView
, ModifyHdl
));
43 m_xSQL
->SetAcceptsTab(true);
45 m_timerUndoActionCreation
.SetTimeout(1000);
46 m_timerUndoActionCreation
.SetInvokeHandler(LINK(this, OQueryTextView
, OnUndoActionTimer
));
48 m_timerInvalidate
.SetTimeout(200);
49 m_timerInvalidate
.SetInvokeHandler(LINK(this, OQueryTextView
, OnInvalidateTimer
));
50 m_timerInvalidate
.Start();
53 IMPL_LINK_NOARG(OQueryTextView
, ModifyHdl
, LinkParamNone
*, void)
55 if (m_timerUndoActionCreation
.IsActive())
56 m_timerUndoActionCreation
.Stop();
57 m_timerUndoActionCreation
.Start();
59 if (!m_rController
.isModified())
60 m_rController
.setModified(true);
62 m_rController
.InvalidateFeature(SID_SBA_QRY_EXECUTE
);
63 m_rController
.InvalidateFeature(SID_CUT
);
64 m_rController
.InvalidateFeature(SID_COPY
);
67 IMPL_LINK_NOARG(OQueryTextView
, OnUndoActionTimer
, Timer
*, void)
69 OUString aText
= m_xSQL
->GetText();
70 if (aText
== m_strOrigText
)
73 SfxUndoManager
& rUndoMgr
= m_rController
.GetUndoManager();
74 std::unique_ptr
<OSqlEditUndoAct
> xUndoAct(new OSqlEditUndoAct(*this));
76 xUndoAct
->SetOriginalText(m_strOrigText
);
77 rUndoMgr
.AddUndoAction(std::move(xUndoAct
));
79 m_rController
.InvalidateFeature(SID_UNDO
);
80 m_rController
.InvalidateFeature(SID_REDO
);
82 m_strOrigText
= aText
;
85 IMPL_LINK_NOARG(OQueryTextView
, OnInvalidateTimer
, Timer
*, void)
87 m_rController
.InvalidateFeature(SID_CUT
);
88 m_rController
.InvalidateFeature(SID_COPY
);
90 m_timerInvalidate
.Start();
93 void OQueryTextView::startTimer()
96 if (!m_timerInvalidate
.IsActive())
97 m_timerInvalidate
.Start();
100 void OQueryTextView::stopTimer()
103 if (m_timerInvalidate
.IsActive())
104 m_timerInvalidate
.Stop();
107 OQueryTextView::~OQueryTextView() { disposeOnce(); }
109 void OQueryTextView::dispose()
111 if (m_timerUndoActionCreation
.IsActive())
112 m_timerUndoActionCreation
.Stop();
116 InterimItemWindow::dispose();
119 void OQueryTextView::GetFocus()
124 m_strOrigText
= m_xSQL
->GetText();
126 InterimItemWindow::GetFocus();
129 OUString
OQueryTextView::getStatement() const { return m_xSQL
->GetText(); }
131 void OQueryTextView::clear()
133 std::unique_ptr
<OSqlEditUndoAct
> xUndoAct(new OSqlEditUndoAct(*this));
135 xUndoAct
->SetOriginalText(m_xSQL
->GetText());
136 m_rController
.addUndoActionAndInvalidate(std::move(xUndoAct
));
138 SetSQLText(OUString());
141 void OQueryTextView::setStatement(const OUString
& rsStatement
) { SetSQLText(rsStatement
); }
143 OUString
OQueryTextView::GetSQLText() const { return m_xSQL
->GetText(); }
145 void OQueryTextView::SetSQLText(const OUString
& rNewText
)
147 if (m_timerUndoActionCreation
.IsActive())
149 // create the trailing undo-actions
150 m_timerUndoActionCreation
.Stop();
151 OnUndoActionTimer(nullptr);
154 m_xSQL
->SetTextAndUpdate(rNewText
);
156 m_strOrigText
= rNewText
;
159 void OQueryTextView::copy() { m_xSQL
->Copy(); }
161 bool OQueryTextView::isCutAllowed() const { return m_xSQL
->HasSelection(); }
163 void OQueryTextView::cut()
166 m_rController
.setModified(true);
169 void OQueryTextView::paste()
172 m_rController
.setModified(true);
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */