2 * Copyright 2015-2016, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
5 #include "SignalDispositionEditWindow.h"
10 #include <LayoutBuilder.h>
11 #include <MenuField.h>
13 #include <AutoDeleter.h>
14 #include <AutoLocker.h>
16 #include "AppMessageCodes.h"
17 #include "SignalDispositionMenu.h"
18 #include "SignalDispositionTypes.h"
21 #include "UserInterface.h"
25 MSG_SELECTED_SIGNAL_CHANGED
= 'ssic',
26 MSG_SELECTED_DISPOSITION_CHANGED
= 'sdic',
27 MSG_SAVE_SIGNAL_DISPOSITION
= 'ssid'
31 SignalDispositionEditWindow::SignalDispositionEditWindow(::Team
* team
,
32 int32 signal
, UserInterfaceListener
* listener
, BHandler
* target
)
34 BWindow(BRect(), "Edit signal disposition", B_FLOATING_WINDOW
,
35 B_AUTO_UPDATE_SIZE_LIMITS
| B_CLOSE_ON_ESCAPE
),
38 fEditMode(signal
> 0),
39 fCurrentSignal(signal
),
42 fSignalSelectionField(NULL
),
43 fDispositionSelectionField(NULL
),
49 SignalDispositionEditWindow::~SignalDispositionEditWindow()
51 BMessenger(fTarget
).SendMessage(MSG_SIGNAL_DISPOSITION_EDIT_WINDOW_CLOSED
);
55 SignalDispositionEditWindow
*
56 SignalDispositionEditWindow::Create(::Team
* team
, int32 signal
,
57 UserInterfaceListener
* listener
, BHandler
* target
)
59 SignalDispositionEditWindow
* self
= new SignalDispositionEditWindow(
60 team
, signal
, listener
, target
);
74 SignalDispositionEditWindow::MessageReceived(BMessage
* message
)
76 switch (message
->what
) {
77 case MSG_SELECTED_SIGNAL_CHANGED
:
80 if (message
->FindInt32("signal", &signal
) == B_OK
)
81 fCurrentSignal
= signal
;
84 case MSG_SELECTED_DISPOSITION_CHANGED
:
87 if (message
->FindInt32("disposition", &disposition
) == B_OK
)
88 fCurrentDisposition
= disposition
;
91 case MSG_SAVE_SIGNAL_DISPOSITION
:
93 fListener
->SetCustomSignalDispositionRequested(fCurrentSignal
,
102 BWindow::MessageReceived(message
);
110 SignalDispositionEditWindow::Show()
118 SignalDispositionEditWindow::_Init()
120 SignalDispositionMenu
* menu
= new SignalDispositionMenu("dispositionMenu",
121 new BMessage(MSG_SELECTED_DISPOSITION_CHANGED
));
123 BLayoutBuilder::Group
<>(this, B_VERTICAL
)
124 .SetInsets(B_USE_DEFAULT_SPACING
)
125 .AddGroup(B_HORIZONTAL
)
126 .Add((fSignalSelectionField
= new BMenuField("Signal:",
127 _BuildSignalSelectionMenu())))
128 .Add((fDispositionSelectionField
= new BMenuField("Disposition:",
131 .AddGroup(B_HORIZONTAL
)
133 .Add((fSaveButton
= new BButton("Save",
134 new BMessage(MSG_SAVE_SIGNAL_DISPOSITION
))))
135 .Add((fCancelButton
= new BButton("Cancel",
136 new BMessage(B_CANCEL
))))
140 fSignalSelectionField
->Menu()->SetLabelFromMarked(true);
141 fSignalSelectionField
->Menu()->SetTargetForItems(this);
142 menu
->SetLabelFromMarked(true);
143 menu
->SetTargetForItems(this);
145 AutoLocker
< ::Team
> teamLocker(fTeam
);
148 // if we're editing an existing row, don't allow changing the signal
151 fSignalSelectionField
->SetEnabled(false);
158 SignalDispositionEditWindow::_BuildSignalSelectionMenu()
160 BMenu
* menu
= new BMenu("signals");
163 #undef ADD_SIGNAL_MENU_ITEM
164 #define ADD_SIGNAL_MENU_ITEM(x) \
165 menu->AddItem((item = new BMenuItem(#x, new BMessage( \
166 MSG_SELECTED_SIGNAL_CHANGED)))); \
167 item->Message()->AddInt32("signal", x);
169 ADD_SIGNAL_MENU_ITEM(SIGHUP
)
170 ADD_SIGNAL_MENU_ITEM(SIGINT
)
171 ADD_SIGNAL_MENU_ITEM(SIGQUIT
)
172 ADD_SIGNAL_MENU_ITEM(SIGILL
)
173 ADD_SIGNAL_MENU_ITEM(SIGCHLD
)
174 ADD_SIGNAL_MENU_ITEM(SIGABRT
)
175 ADD_SIGNAL_MENU_ITEM(SIGPIPE
)
176 ADD_SIGNAL_MENU_ITEM(SIGFPE
)
177 ADD_SIGNAL_MENU_ITEM(SIGKILL
)
178 ADD_SIGNAL_MENU_ITEM(SIGSTOP
)
179 ADD_SIGNAL_MENU_ITEM(SIGSEGV
)
180 ADD_SIGNAL_MENU_ITEM(SIGCONT
)
181 ADD_SIGNAL_MENU_ITEM(SIGTSTP
)
182 ADD_SIGNAL_MENU_ITEM(SIGALRM
)
183 ADD_SIGNAL_MENU_ITEM(SIGTERM
)
184 ADD_SIGNAL_MENU_ITEM(SIGTTIN
)
185 ADD_SIGNAL_MENU_ITEM(SIGTTOU
)
186 ADD_SIGNAL_MENU_ITEM(SIGUSR1
)
187 ADD_SIGNAL_MENU_ITEM(SIGUSR2
)
188 ADD_SIGNAL_MENU_ITEM(SIGWINCH
)
189 ADD_SIGNAL_MENU_ITEM(SIGKILLTHR
)
190 ADD_SIGNAL_MENU_ITEM(SIGTRAP
)
191 ADD_SIGNAL_MENU_ITEM(SIGPOLL
)
192 ADD_SIGNAL_MENU_ITEM(SIGPROF
)
193 ADD_SIGNAL_MENU_ITEM(SIGSYS
)
194 ADD_SIGNAL_MENU_ITEM(SIGURG
)
195 ADD_SIGNAL_MENU_ITEM(SIGVTALRM
)
196 ADD_SIGNAL_MENU_ITEM(SIGXCPU
)
197 ADD_SIGNAL_MENU_ITEM(SIGXFSZ
)
198 ADD_SIGNAL_MENU_ITEM(SIGBUS
)
201 for (int32 i
= SIGRTMIN
; i
<= SIGRTMAX
; i
++) {
202 menu
->AddItem((item
= new BMenuItem(UiUtils::SignalNameToString(i
,
203 signalName
), new BMessage(MSG_SELECTED_SIGNAL_CHANGED
))));
204 item
->Message()->AddInt32("signal", i
);
212 SignalDispositionEditWindow::_UpdateState()
214 if (fCurrentSignal
<= 0)
215 fCurrentSignal
= SIGHUP
;
217 fSignalSelectionField
->Menu()->ItemAt(fCurrentSignal
- 1)->SetMarked(true);
219 fCurrentDisposition
= fTeam
->SignalDispositionFor(fCurrentSignal
);
220 fDispositionSelectionField
->Menu()->ItemAt(fCurrentDisposition
)->SetMarked(