LibreOffice Module basctl (master) 1
brkdlg.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 <sal/config.h>
21
22#include "breakpoint.hxx"
23#include "brkdlg.hxx"
24#include <basobj.hxx>
25
26#include <sfx2/dispatch.hxx>
27#include <sfx2/sfxsids.hrc>
28
29namespace basctl
30{
31// FIXME Why does BreakPointDialog allow only sal_uInt16 for break-point line
32// numbers, whereas BreakPoint supports sal_uLong?
33
34namespace
35{
36bool lcl_ParseText(OUString const& rText, size_t& rLineNr)
37{
38 // aText should look like "# n" where
39 // n > 0 && n < std::numeric_limits< sal_uInt16 >::max().
40 // All spaces are ignored, so there can even be spaces within the
41 // number n. (Maybe it would be better to ignore all whitespace instead
42 // of just spaces.)
43 OUString aText(rText.replaceAll(" ", ""));
44 if (aText.isEmpty())
45 return false;
46 sal_Unicode cFirst = aText[0];
47 if (cFirst != '#' && (cFirst < '0' || cFirst > '9'))
48 return false;
49 if (cFirst == '#')
50 aText = aText.copy(1);
51 // XXX Assumes that sal_uInt16 is contained within sal_Int32:
52 sal_Int32 n = aText.toInt32();
53 if (n <= 0)
54 return false;
55 rLineNr = static_cast<size_t>(n);
56 return true;
57}
58
59} // namespace
60
62 : GenericDialogController(pParent, "modules/BasicIDE/ui/managebreakpoints.ui",
63 "ManageBreakpointsDialog")
64 , m_rOriginalBreakPointList(rBrkPntList)
65 , m_aModifiedBreakPointList(rBrkPntList)
66 , m_xComboBox(m_xBuilder->weld_entry_tree_view("entriesgrid", "entries", "entrieslist"))
67 , m_xOKButton(m_xBuilder->weld_button("ok"))
68 , m_xNewButton(m_xBuilder->weld_button("new"))
69 , m_xDelButton(m_xBuilder->weld_button("delete"))
70 , m_xCheckBox(m_xBuilder->weld_check_button("active"))
71 , m_xNumericField(m_xBuilder->weld_spin_button("pass"))
72{
73 m_xComboBox->set_size_request(m_xComboBox->get_approximate_digit_width() * 20, -1);
74 m_xComboBox->set_height_request_by_rows(12);
75
76 m_xComboBox->freeze();
77 for (size_t i = 0, n = m_aModifiedBreakPointList.size(); i < n; ++i)
78 {
80 OUString aEntryStr("# " + OUString::number(rBrk.nLine));
81 m_xComboBox->append_text(aEntryStr);
82 }
83 m_xComboBox->thaw();
84
85 m_xOKButton->connect_clicked(LINK(this, BreakPointDialog, ButtonHdl));
86 m_xNewButton->connect_clicked(LINK(this, BreakPointDialog, ButtonHdl));
87 m_xDelButton->connect_clicked(LINK(this, BreakPointDialog, ButtonHdl));
88
89 m_xCheckBox->connect_toggled(LINK(this, BreakPointDialog, CheckBoxHdl));
90 m_xComboBox->connect_changed(LINK(this, BreakPointDialog, EditModifyHdl));
91 m_xComboBox->connect_row_activated(LINK(this, BreakPointDialog, TreeModifyHdl));
92 m_xComboBox->grab_focus();
93
94 m_xNumericField->set_range(0, 0x7FFFFFFF);
95 m_xNumericField->set_increments(1, 10);
96 m_xNumericField->connect_value_changed(LINK(this, BreakPointDialog, FieldModifyHdl));
97
98 if (m_xComboBox->get_count())
99 m_xComboBox->set_active(0);
100
103
104 CheckButtons();
105}
106
108
110{
111 OUString aStr("# " + OUString::number(rBrk.nLine));
112 m_xComboBox->set_entry_text(aStr);
113 UpdateFields(rBrk);
114}
115
117{
118 // "New" button is enabled if the combo box edit contains a valid line
119 // number that is not already present in the combo box list; otherwise
120 // "OK" and "Delete" buttons are enabled:
121 size_t nLine;
122 if (lcl_ParseText(m_xComboBox->get_active_text(), nLine)
123 && m_aModifiedBreakPointList.FindBreakPoint(nLine) == nullptr)
124 {
125 m_xNewButton->set_sensitive(true);
126 m_xOKButton->set_sensitive(false);
127 m_xDelButton->set_sensitive(false);
128 m_xDialog->change_default_widget(m_xDelButton.get(), m_xNewButton.get());
129 }
130 else
131 {
132 m_xNewButton->set_sensitive(false);
133 m_xOKButton->set_sensitive(true);
134 m_xDelButton->set_sensitive(true);
135 m_xDialog->change_default_widget(m_xNewButton.get(), m_xDelButton.get());
136 }
137}
138
139IMPL_LINK(BreakPointDialog, CheckBoxHdl, weld::Toggleable&, rButton, void)
140{
141 BreakPoint* pBrk = GetSelectedBreakPoint();
142 if (pBrk)
143 pBrk->bEnabled = rButton.get_active();
144}
145
146IMPL_LINK(BreakPointDialog, EditModifyHdl, weld::ComboBox&, rBox, void)
147{
148 CheckButtons();
149
150 int nEntry = rBox.find_text(rBox.get_active_text());
151 if (nEntry == -1)
152 return;
153 BreakPoint& rBrk = m_aModifiedBreakPointList.at(nEntry);
154 UpdateFields(rBrk);
155}
156
157IMPL_LINK(BreakPointDialog, FieldModifyHdl, weld::SpinButton&, rEdit, void)
158{
159 BreakPoint* pBrk = GetSelectedBreakPoint();
160 if (pBrk)
161 pBrk->nStopAfter = rEdit.get_value();
162}
163
165{
166 if (m_xDelButton->get_sensitive())
167 ButtonHdl(*m_xDelButton);
168 return true;
169}
170
171IMPL_LINK(BreakPointDialog, ButtonHdl, weld::Button&, rButton, void)
172{
173 if (&rButton == m_xOKButton.get())
174 {
175 m_rOriginalBreakPointList.transfer(m_aModifiedBreakPointList);
176 m_xDialog->response(RET_OK);
177 }
178 else if (&rButton == m_xNewButton.get())
179 {
180 // keep checkbox in mind!
181 OUString aText(m_xComboBox->get_active_text());
182 size_t nLine;
183 bool bValid = lcl_ParseText(aText, nLine);
184 if (bValid)
185 {
186 BreakPoint aBrk(nLine);
187 aBrk.bEnabled = m_xCheckBox->get_active();
188 aBrk.nStopAfter = static_cast<size_t>(m_xNumericField->get_value());
189 m_aModifiedBreakPointList.InsertSorted(aBrk);
190 OUString aEntryStr("# " + OUString::number(aBrk.nLine));
191 m_xComboBox->append_text(aEntryStr);
192 if (SfxDispatcher* pDispatcher = GetDispatcher())
193 pDispatcher->Execute(SID_BASICIDE_BRKPNTSCHANGED);
194 }
195 else
196 {
197 m_xComboBox->set_active_text(aText);
198 m_xComboBox->grab_focus();
199 }
200 CheckButtons();
201 }
202 else if (&rButton == m_xDelButton.get())
203 {
204 int nEntry = m_xComboBox->find_text(m_xComboBox->get_active_text());
205 if (nEntry != -1)
206 {
207 m_aModifiedBreakPointList.remove(nEntry);
208 m_xComboBox->remove(nEntry);
209 if (nEntry && nEntry >= m_xComboBox->get_count())
210 nEntry--;
211 m_xComboBox->set_active_text(m_xComboBox->get_text(nEntry));
212 if (SfxDispatcher* pDispatcher = GetDispatcher())
213 pDispatcher->Execute(SID_BASICIDE_BRKPNTSCHANGED);
214 CheckButtons();
215 }
216 }
217}
218
220{
221 m_xCheckBox->set_active(rBrk.bEnabled);
222 m_xNumericField->set_value(rBrk.nStopAfter);
223}
224
226{
227 int nEntry = m_xComboBox->find_text(m_xComboBox->get_active_text());
228 if (nEntry == -1)
229 return nullptr;
230 return &m_aModifiedBreakPointList.at(nEntry);
231}
232
233} // namespace basctl
234
235/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
std::unique_ptr< weld::SpinButton > m_xNumericField
Definition: brkdlg.hxx:37
BreakPointDialog(weld::Window *pParent, BreakPointList &rBrkList)
Definition: brkdlg.cxx:61
std::unique_ptr< weld::Button > m_xDelButton
Definition: brkdlg.hxx:35
std::unique_ptr< weld::Button > m_xNewButton
Definition: brkdlg.hxx:34
void SetCurrentBreakPoint(BreakPoint const &rBrk)
Definition: brkdlg.cxx:109
virtual ~BreakPointDialog() override
Definition: brkdlg.cxx:107
std::unique_ptr< weld::EntryTreeView > m_xComboBox
Definition: brkdlg.hxx:32
void UpdateFields(BreakPoint const &rBrk)
Definition: brkdlg.cxx:219
BreakPointList m_aModifiedBreakPointList
Definition: brkdlg.hxx:30
std::unique_ptr< weld::CheckButton > m_xCheckBox
Definition: brkdlg.hxx:36
std::unique_ptr< weld::Button > m_xOKButton
Definition: brkdlg.hxx:33
BreakPoint * GetSelectedBreakPoint()
Definition: brkdlg.cxx:225
size_t size() const
Definition: breakpoint.cxx:141
BreakPoint * FindBreakPoint(sal_uInt16 nLine)
Definition: breakpoint.cxx:77
BreakPoint & at(size_t i)
Definition: breakpoint.cxx:146
std::shared_ptr< weld::Dialog > m_xDialog
std::unique_ptr< weld::Button > m_xOKButton
sal_Int64 n
aStr
SfxDispatcher * GetDispatcher()
Definition: basobj3.cxx:454
IMPL_LINK(AccessibleDialogWindow, WindowEventListener, VclWindowEvent &, rEvent, void)
IMPL_LINK_NOARG(EditorWindow, SetSourceInBasicHdl, void *, void)
Definition: baside2b.cxx:987
int i
sal_uInt16 nLine
Definition: breakpoint.hxx:34
sal_uInt16 sal_Unicode
RET_OK