2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
7 #include "SetTitleDialog.h"
11 #include <LayoutBuilder.h>
12 #include <TextControl.h>
15 static const uint32 kMessageOK
= 'okok';
16 static const uint32 kMessageDefault
= 'dflt';
17 static const uint32 kMessageTitleChanged
= 'chng';
20 #undef B_TRANSLATION_CONTEXT
21 #define B_TRANSLATION_CONTEXT "Terminal SetTitleWindow"
24 // #pragma mark - SetTitleDialog
27 SetTitleDialog::SetTitleDialog(const char* dialogTitle
, const char* label
,
30 BWindow(BRect(0, 0, 0, 0), dialogTitle
, B_BORDERED_WINDOW_LOOK
,
31 B_FLOATING_APP_WINDOW_FEEL
,
32 B_AUTO_UPDATE_SIZE_LIMITS
| B_CLOSE_ON_ESCAPE
),
35 fOldTitleUserDefined(false),
36 fTitleUserDefined(false)
38 BLayoutBuilder::Group
<>(this, B_VERTICAL
)
39 .SetInsets(10, 10, 10, 10)
40 .Add(fTitleTextControl
= new BTextControl("title", label
, "", NULL
))
41 .AddGroup(B_HORIZONTAL
)
42 .Add(fDefaultButton
= new BButton("defaultButton",
43 B_TRANSLATE("Use default"), new BMessage(kMessageDefault
)))
45 .Add(fCancelButton
= new BButton("cancelButton",
46 B_TRANSLATE("Cancel"), new BMessage(B_QUIT_REQUESTED
)))
47 .Add(fOKButton
= new BButton("okButton", B_TRANSLATE("OK"),
48 new BMessage(kMessageOK
)));
50 fTitleTextControl
->SetToolTip(toolTip
);
52 fOKButton
->MakeDefault(true);
55 // as a courtesy to our creator, who might want to place us
59 SetTitleDialog::~SetTitleDialog()
61 if (fListener
!= NULL
) {
63 fListener
->TitleChanged(this, fOldTitle
, fOldTitleUserDefined
);
65 Listener
* listener
= fListener
;
67 listener
->SetTitleDialogDone(this);
73 SetTitleDialog::Go(const BString
& title
, bool titleUserDefined
,
76 fTitle
= fOldTitle
= title
;
77 fTitleUserDefined
= fOldTitleUserDefined
= titleUserDefined
;
79 fDefaultButton
->SetEnabled(titleUserDefined
);
81 fTitleTextControl
->SetText(fTitle
);
82 fTitleTextControl
->SetModificationMessage(
83 new BMessage(kMessageTitleChanged
));
84 fTitleTextControl
->MakeFocus(true);
93 SetTitleDialog::Finish()
95 if (Listener
* listener
= fListener
) {
97 listener
->SetTitleDialogDone(this);
100 PostMessage(B_QUIT_REQUESTED
);
105 SetTitleDialog::MessageReceived(BMessage
* message
)
107 switch (message
->what
) {
108 case kMessageDefault
:
109 if (fListener
!= NULL
)
110 fListener
->TitleChanged(this, BString(), false);
111 // We're done now, fall through...
117 case kMessageTitleChanged
:
118 fTitle
= fTitleTextControl
->Text();
119 fTitleUserDefined
= true;
121 fDefaultButton
->SetEnabled(true);
123 if (fListener
!= NULL
)
124 fListener
->TitleChanged(this, fTitle
, fTitleUserDefined
);
128 BWindow::MessageReceived(message
);
135 // #pragma mark - SetTitleDialog
138 SetTitleDialog::Listener::~Listener()