2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2011-2016, Rene Gollent, rene@gollent.com.
4 * Distributed under the terms of the MIT License.
8 #include "BreakpointsView.h"
14 #include <LayoutBuilder.h>
16 #include <AutoLocker.h>
17 #include <ObjectList.h>
19 #include "AppMessageCodes.h"
20 #include "MessageCodes.h"
22 #include "UserBreakpoint.h"
25 // #pragma mark - BreakpointsView
28 BreakpointsView::BreakpointsView(Team
* team
, Listener
* listener
)
30 BGroupView(B_HORIZONTAL
, 4.0f
),
33 fToggleBreakpointButton(NULL
),
34 fEditBreakpointButton(NULL
),
35 fRemoveBreakpointButton(NULL
),
38 SetName("Breakpoints");
42 BreakpointsView::~BreakpointsView()
44 if (fListView
!= NULL
)
45 fListView
->UnsetListener();
49 /*static*/ BreakpointsView
*
50 BreakpointsView::Create(Team
* team
, Listener
* listener
)
52 BreakpointsView
* self
= new BreakpointsView(team
, listener
);
66 BreakpointsView::UnsetListener()
73 BreakpointsView::UserBreakpointChanged(UserBreakpoint
* breakpoint
)
75 fListView
->UserBreakpointChanged(breakpoint
);
82 BreakpointsView::WatchpointChanged(Watchpoint
* watchpoint
)
84 fListView
->WatchpointChanged(watchpoint
);
91 BreakpointsView::MessageReceived(BMessage
* message
)
93 switch (message
->what
) {
94 case MSG_ENABLE_BREAKPOINT
:
95 case MSG_DISABLE_BREAKPOINT
:
96 case MSG_CLEAR_BREAKPOINT
:
97 _HandleBreakpointAction(message
->what
);
100 case MSG_SHOW_BREAKPOINT_EDIT_WINDOW
:
101 message
->AddPointer("breakpoint",
102 fSelectedBreakpoints
.ItemAt(0)->GetBreakpoint());
103 Window()->PostMessage(message
);
107 BGroupView::MessageReceived(message
);
114 BreakpointsView::AttachedToWindow()
116 fEditBreakpointButton
->SetTarget(this);
117 fToggleBreakpointButton
->SetTarget(this);
118 fRemoveBreakpointButton
->SetTarget(this);
123 BreakpointsView::LoadSettings(const BMessage
& settings
)
125 BMessage breakpointListSettings
;
126 if (settings
.FindMessage("breakpointList", &breakpointListSettings
)
128 fListView
->LoadSettings(breakpointListSettings
);
133 BreakpointsView::SaveSettings(BMessage
& settings
)
135 BMessage breakpointListSettings
;
136 if (fListView
->SaveSettings(breakpointListSettings
) != B_OK
)
139 if (settings
.AddMessage("breakpointList", &breakpointListSettings
) != B_OK
)
147 BreakpointsView::BreakpointSelectionChanged(BreakpointProxyList
& proxies
)
149 if (fListener
!= NULL
)
150 fListener
->BreakpointSelectionChanged(proxies
);
152 _SetSelection(proxies
);
157 BreakpointsView::_Init()
159 BLayoutBuilder::Group
<>(this, B_VERTICAL
, 0.0f
)
160 .Add(fListView
= BreakpointListView::Create(fTeam
, this, this))
161 .AddGroup(B_HORIZONTAL
, B_USE_SMALL_SPACING
)
162 .SetInsets(B_USE_SMALL_SPACING
)
164 .Add(fRemoveBreakpointButton
= new BButton("Remove"))
165 .Add(fEditBreakpointButton
= new BButton("Edit" B_UTF8_ELLIPSIS
))
166 .Add(fToggleBreakpointButton
= new BButton("Toggle"))
169 fToggleBreakpointButton
->SetMessage(new BMessage(MSG_ENABLE_BREAKPOINT
));
170 fRemoveBreakpointButton
->SetMessage(new BMessage(MSG_CLEAR_BREAKPOINT
));
171 fEditBreakpointButton
->SetMessage(
172 new BMessage(MSG_SHOW_BREAKPOINT_EDIT_WINDOW
));
179 BreakpointsView::_UpdateButtons()
181 AutoLocker
<Team
> teamLocker(fTeam
);
183 bool hasEnabled
= false;
184 bool hasDisabled
= false;
187 for (int32 i
= 0; i
< fSelectedBreakpoints
.CountItems(); i
++) {
188 BreakpointProxy
* proxy
= fSelectedBreakpoints
.ItemAt(i
);
189 switch (proxy
->Type()) {
190 case BREAKPOINT_PROXY_TYPE_BREAKPOINT
:
192 UserBreakpoint
* breakpoint
= proxy
->GetBreakpoint();
193 if (breakpoint
->IsValid()) {
195 if (breakpoint
->IsEnabled())
203 case BREAKPOINT_PROXY_TYPE_WATCHPOINT
:
205 Watchpoint
* watchpoint
= proxy
->GetWatchpoint();
207 if (watchpoint
->IsEnabled())
219 // only allow condition editing if we have a single
220 // actual breakpoint selected.
221 // TODO: allow using this to modify watchpoints as
223 if (fSelectedBreakpoints
.CountItems() == 1
224 && fSelectedBreakpoints
.ItemAt(0)->Type()
225 == BREAKPOINT_PROXY_TYPE_BREAKPOINT
) {
226 fEditBreakpointButton
->SetEnabled(true);
228 fEditBreakpointButton
->SetEnabled(false);
230 // if we have at least one disabled breakpoint in the
231 // selection, we leave the button as an Enable button
232 if (hasEnabled
&& !hasDisabled
) {
233 fToggleBreakpointButton
->SetLabel("Disable");
234 fToggleBreakpointButton
->SetMessage(
235 new BMessage(MSG_DISABLE_BREAKPOINT
));
237 fToggleBreakpointButton
->SetLabel("Enable");
238 fToggleBreakpointButton
->SetMessage(
239 new BMessage(MSG_ENABLE_BREAKPOINT
));
242 fToggleBreakpointButton
->SetEnabled(true);
243 fRemoveBreakpointButton
->SetEnabled(true);
245 fToggleBreakpointButton
->SetLabel("Enable");
246 fToggleBreakpointButton
->SetEnabled(false);
247 fEditBreakpointButton
->SetEnabled(false);
248 fRemoveBreakpointButton
->SetEnabled(false);
254 BreakpointsView::_SetSelection(BreakpointProxyList
& proxies
)
256 for (int32 i
= 0; i
< fSelectedBreakpoints
.CountItems(); i
++)
257 fSelectedBreakpoints
.ItemAt(i
)->ReleaseReference();
259 fSelectedBreakpoints
.MakeEmpty();
261 for (int32 i
= 0; i
< proxies
.CountItems(); i
++) {
262 BreakpointProxy
* proxy
= proxies
.ItemAt(i
);
263 if (!fSelectedBreakpoints
.AddItem(proxy
))
265 proxy
->AcquireReference();
273 BreakpointsView::_HandleBreakpointAction(uint32 action
)
275 if (fListener
== NULL
)
278 for (int32 i
= 0; i
< fSelectedBreakpoints
.CountItems(); i
++) {
279 BreakpointProxy
* proxy
= fSelectedBreakpoints
.ItemAt(i
);
280 if (proxy
->Type() == BREAKPOINT_PROXY_TYPE_BREAKPOINT
) {
281 UserBreakpoint
* breakpoint
= proxy
->GetBreakpoint();
282 if (action
== MSG_ENABLE_BREAKPOINT
&& !breakpoint
->IsEnabled())
283 fListener
->SetBreakpointEnabledRequested(breakpoint
, true);
284 else if (action
== MSG_DISABLE_BREAKPOINT
285 && breakpoint
->IsEnabled()) {
286 fListener
->SetBreakpointEnabledRequested(breakpoint
, false);
287 } else if (action
== MSG_CLEAR_BREAKPOINT
)
288 fListener
->ClearBreakpointRequested(breakpoint
);
290 Watchpoint
* watchpoint
= proxy
->GetWatchpoint();
291 if (action
== MSG_ENABLE_BREAKPOINT
&& !watchpoint
->IsEnabled())
292 fListener
->SetWatchpointEnabledRequested(watchpoint
, true);
293 else if (action
== MSG_DISABLE_BREAKPOINT
294 && watchpoint
->IsEnabled()) {
295 fListener
->SetWatchpointEnabledRequested(watchpoint
, false);
296 } else if (action
== MSG_CLEAR_BREAKPOINT
)
297 fListener
->ClearWatchpointRequested(watchpoint
);
303 // #pragma mark - Listener
306 BreakpointsView::Listener::~Listener()