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 <sal/config.h>
22 #include "breakpoint.hxx"
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/sfxsids.hrc>
28 #include <svl/itemset.hxx>
34 bool lcl_ParseText(OUString
const& rText
, size_t& rLineNr
)
36 // aText should look like "# n" where n > 0
37 // All spaces are ignored, so there can even be spaces within the
38 // number n. (Maybe it would be better to ignore all whitespace instead
40 OUString
aText(rText
.replaceAll(" ", ""));
43 sal_Unicode cFirst
= aText
[0];
44 if (cFirst
!= '#' && (cFirst
< '0' || cFirst
> '9'))
47 aText
= aText
.copy(1);
48 sal_Int32 n
= aText
.toInt32();
51 rLineNr
= static_cast<size_t>(n
);
57 BreakPointDialog::BreakPointDialog(weld::Window
* pParent
, BreakPointList
& rBrkPntList
)
58 : GenericDialogController(pParent
, "modules/BasicIDE/ui/managebreakpoints.ui",
59 "ManageBreakpointsDialog")
60 , m_rOriginalBreakPointList(rBrkPntList
)
61 , m_aModifiedBreakPointList(rBrkPntList
)
62 , m_xComboBox(m_xBuilder
->weld_entry_tree_view("entriesgrid", "entries", "entrieslist"))
63 , m_xOKButton(m_xBuilder
->weld_button("ok"))
64 , m_xNewButton(m_xBuilder
->weld_button("new"))
65 , m_xDelButton(m_xBuilder
->weld_button("delete"))
66 , m_xCheckBox(m_xBuilder
->weld_check_button("active"))
67 , m_xNumericField(m_xBuilder
->weld_spin_button("pass"))
69 m_xComboBox
->set_size_request(m_xComboBox
->get_approximate_digit_width() * 20, -1);
70 m_xComboBox
->set_height_request_by_rows(12);
72 m_xComboBox
->freeze();
73 for (size_t i
= 0, n
= m_aModifiedBreakPointList
.size(); i
< n
; ++i
)
75 BreakPoint
& rBrk
= m_aModifiedBreakPointList
.at(i
);
76 OUString
aEntryStr("# " + OUString::number(rBrk
.nLine
));
77 m_xComboBox
->append_text(aEntryStr
);
81 m_xOKButton
->connect_clicked(LINK(this, BreakPointDialog
, ButtonHdl
));
82 m_xNewButton
->connect_clicked(LINK(this, BreakPointDialog
, ButtonHdl
));
83 m_xDelButton
->connect_clicked(LINK(this, BreakPointDialog
, ButtonHdl
));
85 m_xCheckBox
->connect_toggled(LINK(this, BreakPointDialog
, CheckBoxHdl
));
86 m_xComboBox
->connect_changed(LINK(this, BreakPointDialog
, EditModifyHdl
));
87 m_xComboBox
->connect_row_activated(LINK(this, BreakPointDialog
, TreeModifyHdl
));
88 m_xComboBox
->grab_focus();
90 m_xNumericField
->set_range(0, 0x7FFFFFFF);
91 m_xNumericField
->set_increments(1, 10);
92 m_xNumericField
->connect_value_changed(LINK(this, BreakPointDialog
, FieldModifyHdl
));
94 if (m_xComboBox
->get_count())
95 m_xComboBox
->set_active(0);
97 if (m_aModifiedBreakPointList
.size())
98 UpdateFields(m_aModifiedBreakPointList
.at(0));
103 BreakPointDialog::~BreakPointDialog() {}
105 void BreakPointDialog::SetCurrentBreakPoint(BreakPoint
const& rBrk
)
107 OUString
aStr("# " + OUString::number(rBrk
.nLine
));
108 m_xComboBox
->set_entry_text(aStr
);
112 void BreakPointDialog::CheckButtons()
114 // "New" button is enabled if the combo box edit contains a valid line
115 // number that is not already present in the combo box list; otherwise
116 // "OK" and "Delete" buttons are enabled:
118 if (lcl_ParseText(m_xComboBox
->get_active_text(), nLine
)
119 && m_aModifiedBreakPointList
.FindBreakPoint(nLine
) == nullptr)
121 m_xNewButton
->set_sensitive(true);
122 m_xOKButton
->set_sensitive(false);
123 m_xDelButton
->set_sensitive(false);
124 m_xDialog
->change_default_widget(m_xDelButton
.get(), m_xNewButton
.get());
128 m_xNewButton
->set_sensitive(false);
129 m_xOKButton
->set_sensitive(true);
130 m_xDelButton
->set_sensitive(true);
131 m_xDialog
->change_default_widget(m_xNewButton
.get(), m_xDelButton
.get());
135 IMPL_LINK(BreakPointDialog
, CheckBoxHdl
, weld::Toggleable
&, rButton
, void)
137 BreakPoint
* pBrk
= GetSelectedBreakPoint();
139 pBrk
->bEnabled
= rButton
.get_active();
142 IMPL_LINK(BreakPointDialog
, EditModifyHdl
, weld::ComboBox
&, rBox
, void)
146 int nEntry
= rBox
.find_text(rBox
.get_active_text());
149 BreakPoint
& rBrk
= m_aModifiedBreakPointList
.at(nEntry
);
153 IMPL_LINK(BreakPointDialog
, FieldModifyHdl
, weld::SpinButton
&, rEdit
, void)
155 BreakPoint
* pBrk
= GetSelectedBreakPoint();
157 pBrk
->nStopAfter
= rEdit
.get_value();
160 IMPL_LINK_NOARG(BreakPointDialog
, TreeModifyHdl
, weld::TreeView
&, bool)
162 if (m_xDelButton
->get_sensitive())
163 ButtonHdl(*m_xDelButton
);
167 IMPL_LINK(BreakPointDialog
, ButtonHdl
, weld::Button
&, rButton
, void)
169 if (&rButton
== m_xOKButton
.get())
171 m_rOriginalBreakPointList
.transfer(m_aModifiedBreakPointList
);
172 m_xDialog
->response(RET_OK
);
174 else if (&rButton
== m_xNewButton
.get())
176 // keep checkbox in mind!
177 OUString
aText(m_xComboBox
->get_active_text());
179 bool bValid
= lcl_ParseText(aText
, nLine
);
182 BreakPoint
aBrk(nLine
);
183 aBrk
.bEnabled
= m_xCheckBox
->get_active();
184 aBrk
.nStopAfter
= static_cast<size_t>(m_xNumericField
->get_value());
185 m_aModifiedBreakPointList
.InsertSorted(aBrk
);
186 OUString
aEntryStr("# " + OUString::number(aBrk
.nLine
));
187 m_xComboBox
->append_text(aEntryStr
);
188 if (SfxDispatcher
* pDispatcher
= GetDispatcher())
189 pDispatcher
->Execute(SID_BASICIDE_BRKPNTSCHANGED
);
193 m_xComboBox
->set_active_text(aText
);
194 m_xComboBox
->grab_focus();
198 else if (&rButton
== m_xDelButton
.get())
200 int nEntry
= m_xComboBox
->find_text(m_xComboBox
->get_active_text());
203 m_aModifiedBreakPointList
.remove(nEntry
);
204 m_xComboBox
->remove(nEntry
);
205 if (nEntry
&& nEntry
>= m_xComboBox
->get_count())
207 m_xComboBox
->set_active_text(m_xComboBox
->get_text(nEntry
));
208 if (SfxDispatcher
* pDispatcher
= GetDispatcher())
209 pDispatcher
->Execute(SID_BASICIDE_BRKPNTSCHANGED
);
215 void BreakPointDialog::UpdateFields(BreakPoint
const& rBrk
)
217 m_xCheckBox
->set_active(rBrk
.bEnabled
);
218 m_xNumericField
->set_value(rBrk
.nStopAfter
);
221 BreakPoint
* BreakPointDialog::GetSelectedBreakPoint()
223 int nEntry
= m_xComboBox
->find_text(m_xComboBox
->get_active_text());
226 return &m_aModifiedBreakPointList
.at(nEntry
);
229 } // namespace basctl
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */