Repository navigation
Expand file tree
/
Copy pathEditWindow.cpp
More file actions
125 lines (108 loc) · 2.74 KB
/
Copy pathEditWindow.cpp
File metadata and controls
125 lines (108 loc) · 2.74 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright 2015-2016. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Author:
* Humdinger, [email protected]
*/
#include <Button.h>
#include <Catalog.h>
#include <ControlLook.h>
#include <LayoutBuilder.h>
#include <SeparatorView.h>
#include "App.h"
#include "Constants.h"
#include "EditWindow.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "EditWindow"
EditWindow::EditWindow(BRect frame, BString text)
:
BWindow(BRect(), B_TRANSLATE("Edit title"),
B_MODAL_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS |
B_CLOSE_ON_ESCAPE)
{
fOriginalTitle = text;
_BuildLayout();
fTitleControl->MakeFocus(true);
frame.OffsetBy(180.0, 80.0);
MoveTo(frame.LeftTop());
}
EditWindow::~EditWindow()
{
}
void
EditWindow::MessageReceived(BMessage* message)
{
switch (message->what)
{
case CANCEL:
{
Quit();
break;
}
case OK:
{
BString title = fTitleControl->Text();
if (title != fOriginalTitle) {
BMessenger messenger(my_app->fMainWindow);
BMessage message(UPDATE_TITLE);
message.AddString("edit_title", title);
messenger.SendMessage(&message);
}
Quit();
break;
}
default:
{
BWindow::MessageReceived(message);
break;
}
}
}
void
EditWindow::_BuildLayout()
{
// Title
fTitleControl = new BTextControl("title", B_TRANSLATE("Title:"),
fOriginalTitle, NULL);
fTitleControl->SetExplicitMinSize(BSize(300.0, B_SIZE_UNSET));
// Info
BFont infoFont(*be_plain_font);
infoFont.SetFace(B_ITALIC_FACE);
rgb_color infoColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_DARKEN_4_TINT);
BTextView* infoText = new BTextView("tip", &infoFont, &infoColor,
B_WILL_DRAW | B_SUPPORTS_LAYOUT);
infoText->MakeEditable(false);
infoText->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
infoText->SetStylable(true);
infoText->SetAlignment(B_ALIGN_CENTER);
infoText->SetText(B_TRANSLATE(
"Leave title empty to return to original title."));
font_height fheight;
infoFont.GetHeight(&fheight);
infoText->SetExplicitMinSize(BSize(B_SIZE_UNSET,
(fheight.ascent + fheight.descent + fheight.leading) * 2.0));
infoText->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
// Buttons
BButton* cancel = new BButton("cancel", B_TRANSLATE("Cancel"),
new BMessage(CANCEL));
BButton* ok = new BButton("ok", B_TRANSLATE("OK"), new BMessage(OK));
ok->MakeDefault(true);
static const float spacing = be_control_look->DefaultItemSpacing();
BLayoutBuilder::Group<>(this, B_VERTICAL)
.AddGroup(B_VERTICAL, 0)
.SetInsets(spacing)
.Add(fTitleControl)
.Add(infoText)
.End()
.Add(new BSeparatorView(B_HORIZONTAL))
.AddGroup(B_HORIZONTAL)
.SetInsets(0, 0, 0, spacing / 2)
.AddGlue()
.Add(cancel)
.Add(ok)
.AddGlue()
.End();
}