-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextInputDialog.cpp
More file actions
75 lines (63 loc) · 2.02 KB
/
Copy pathTextInputDialog.cpp
File metadata and controls
75 lines (63 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "TextInputDialog.h"
#include <Button.h>
#include <Catalog.h>
#include <LayoutBuilder.h>
#include <StringView.h>
#include <TextControl.h>
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "TextInputDialog"
static const uint32 kMsgOK = 'tiOK';
static const uint32 kMsgCancel = 'tiCn';
TextInputDialog::TextInputDialog(const char* title,
const char* label,
const char* initialText,
BMessenger target,
BMessage confirmMsg)
: BWindow(BRect(0, 0, 320, 80), title,
B_MODAL_WINDOW,
B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS),
fTarget(target),
fConfirmMsg(confirmMsg)
{
fInput = new BTextControl("input", label, initialText ? initialText : "",
nullptr);
fInput->SetModificationMessage(nullptr);
BButton* ok = new BButton("ok", B_TRANSLATE("OK"), new BMessage(kMsgOK));
BButton* cancel = new BButton("cancel", B_TRANSLATE("Cancel"), new BMessage(kMsgCancel));
SetDefaultButton(ok);
BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_DEFAULT_SPACING)
.SetInsets(B_USE_DEFAULT_SPACING)
.Add(fInput)
.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
.AddGlue()
.Add(cancel)
.Add(ok)
.End()
.End();
CenterOnScreen();
fInput->MakeFocus(true);
fInput->TextView()->SelectAll();
}
void
TextInputDialog::MessageReceived(BMessage* msg)
{
switch (msg->what) {
case kMsgOK:
{
const char* text = fInput->Text();
if (text && *text) {
BMessage reply(fConfirmMsg);
reply.AddString("name", text);
fTarget.SendMessage(&reply);
}
Quit();
break;
}
case kMsgCancel:
Quit();
break;
default:
BWindow::MessageReceived(msg);
break;
}
}