libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / preferences / shortcuts / EditWindow.cpp
blob04c8f7a922781c03318a5b79164adad2c0f6cd57
1 /*
2 * Copyright 2015 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Josef Gajdusek
7 */
10 #include "EditWindow.h"
12 #include <math.h>
14 #include <Button.h>
15 #include <LayoutBuilder.h>
16 #include <TextControl.h>
17 #include <String.h>
18 #include <StringView.h>
20 #include "ShortcutsWindow.h"
23 EditWindow::EditWindow(const char* placeholder, uint32 flags)
25 BWindow(BRect(0, 0, 0, 0), "", B_MODAL_WINDOW, flags)
27 fTextControl = new BTextControl("", placeholder, NULL);
29 BButton* okButton = new BButton("Ok", new BMessage(B_CONTROL_MODIFIED));
30 okButton->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_TOP));
31 SetDefaultButton(okButton);
33 BLayoutBuilder::Group<>(this, B_VERTICAL)
34 .SetInsets(B_USE_WINDOW_INSETS)
35 .Add(fTextControl)
36 .Add(okButton);
40 void
41 EditWindow::MessageReceived(BMessage* message)
43 switch (message->what) {
44 case B_CONTROL_MODIFIED:
45 delete_sem(fSem);
46 break;
47 default:
48 BWindow::MessageReceived(message);
49 break;
54 BString
55 EditWindow::Go()
57 fSem = create_sem(0, "EditSem");
58 if (fSem < B_OK) {
59 Quit();
60 return "";
63 BSize psize = GetLayout()->PreferredSize();
64 ResizeTo(max_c(be_plain_font->StringWidth(fTextControl->Text()) * 1.5,
65 psize.Width()),
66 psize.Height());
67 Show();
68 CenterOnScreen();
70 acquire_sem(fSem);
71 BString result = fTextControl->Text();
72 if (Lock())
73 Quit();
75 return result;