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
;
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::lang
;
32 // end of temp classes
33 OQueryTextView::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")
42 m_xSQL
->DisableInternalUndo();
43 m_xSQL
->SetHelpId(HID_CTL_QRYSQLEDIT
);
44 m_xSQL
->SetModifyHdl(LINK(this, OQueryTextView
, ModifyHdl
));
45 m_xSQL
->SetAcceptsTab(true);
47 m_timerUndoActionCreation
.SetTimeout(1000);
48 m_timerUndoActionCreation
.SetInvokeHandler(LINK(this, OQueryTextView
, OnUndoActionTimer
));
50 m_timerInvalidate
.SetTimeout(200);
51 m_timerInvalidate
.SetInvokeHandler(LINK(this, OQueryTextView
, OnInvalidateTimer
));
52 m_timerInvalidate
.Start();
55 IMPL_LINK_NOARG(OQueryTextView
, ModifyHdl
, LinkParamNone
*, void)
57 if (m_timerUndoActionCreation
.IsActive())
58 m_timerUndoActionCreation
.Stop();
59 m_timerUndoActionCreation
.Start();
61 if (!m_rController
.isModified())
62 m_rController
.setModified(true);
64 m_rController
.InvalidateFeature(SID_SBA_QRY_EXECUTE
);
65 m_rController
.InvalidateFeature(SID_CUT
);
66 m_rController
.InvalidateFeature(SID_COPY
);
69 IMPL_LINK_NOARG(OQueryTextView
, OnUndoActionTimer
, Timer
*, void)
71 OUString aText
= m_xSQL
->GetText();
72 if (aText
== m_strOrigText
)
75 SfxUndoManager
& rUndoMgr
= m_rController
.GetUndoManager();
76 std::unique_ptr
<OSqlEditUndoAct
> xUndoAct(new OSqlEditUndoAct(*this));
78 xUndoAct
->SetOriginalText(m_strOrigText
);
79 rUndoMgr
.AddUndoAction(std::move(xUndoAct
));
81 m_rController
.InvalidateFeature(SID_UNDO
);
82 m_rController
.InvalidateFeature(SID_REDO
);
84 m_strOrigText
= aText
;
87 IMPL_LINK_NOARG(OQueryTextView
, OnInvalidateTimer
, Timer
*, void)
89 m_rController
.InvalidateFeature(SID_CUT
);
90 m_rController
.InvalidateFeature(SID_COPY
);
92 m_timerInvalidate
.Start();
95 void OQueryTextView::startTimer()
98 if (!m_timerInvalidate
.IsActive())
99 m_timerInvalidate
.Start();
102 void OQueryTextView::stopTimer()
105 if (m_timerInvalidate
.IsActive())
106 m_timerInvalidate
.Stop();
109 OQueryTextView::~OQueryTextView() { disposeOnce(); }
111 void OQueryTextView::dispose()
113 if (m_timerUndoActionCreation
.IsActive())
114 m_timerUndoActionCreation
.Stop();
118 InterimItemWindow::dispose();
121 void OQueryTextView::GetFocus()
126 m_strOrigText
= m_xSQL
->GetText();
128 InterimItemWindow::GetFocus();
131 OUString
OQueryTextView::getStatement() const { return m_xSQL
->GetText(); }
133 void OQueryTextView::clear()
135 std::unique_ptr
<OSqlEditUndoAct
> xUndoAct(new OSqlEditUndoAct(*this));
137 xUndoAct
->SetOriginalText(m_xSQL
->GetText());
138 m_rController
.addUndoActionAndInvalidate(std::move(xUndoAct
));
140 SetSQLText(OUString());
143 void OQueryTextView::setStatement(const OUString
& rsStatement
) { SetSQLText(rsStatement
); }
145 OUString
OQueryTextView::GetSQLText() const { return m_xSQL
->GetText(); }
147 void OQueryTextView::SetSQLText(const OUString
& rNewText
)
149 if (m_timerUndoActionCreation
.IsActive())
151 // create the trailing undo-actions
152 m_timerUndoActionCreation
.Stop();
153 OnUndoActionTimer(nullptr);
156 m_xSQL
->SetTextAndUpdate(rNewText
);
158 m_strOrigText
= rNewText
;
161 void OQueryTextView::copy() { m_xSQL
->Copy(); }
163 bool OQueryTextView::isCutAllowed() const { return m_xSQL
->HasSelection(); }
165 void OQueryTextView::cut()
168 m_rController
.setModified(true);
171 void OQueryTextView::paste()
174 m_rController
.setModified(true);
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */