Repository navigation
Expand file tree
/
Copy pathApp.cpp
More file actions
148 lines (127 loc) · 2.79 KB
/
Copy pathApp.cpp
File metadata and controls
148 lines (127 loc) · 2.79 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Copyright 2015-2016. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Author:
* Humdinger, [email protected]
*
* A clipboard tool to manage clip history and favourites
*/
#include <Catalog.h>
#include "App.h"
#include "Constants.h"
const char* kApplicationSignature = "application/x-vnd.humdinger-clipdinger";
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Application"
App::App()
:
BApplication(kApplicationSignature)
{
}
App::~App()
{
}
bool
App::QuitRequested()
{
if (fSettingsWindow) {
BMessenger messenger(fSettingsWindow);
if (messenger.IsValid() && messenger.LockTarget())
fSettingsWindow->Quit();
}
if (fReplWindow) {
BMessenger messenger(fReplWindow);
if (messenger.IsValid() && messenger.LockTarget())
fReplWindow->Quit();
}
BApplication::QuitRequested();
return true;
}
void
App::ReadyToRun()
{
BRect rect = fSettings.GetWindowPosition();
fMainWindow = new MainWindow(rect);
fReplWindow = new ReplWindow(rect);
fSettingsWindow = new SettingsWindow(rect);
fMainWindow->MoveBy(4000, 0); // Move out of view to avoid flicker
fMainWindow->Show();
fMainWindow->Minimize(true);
fMainWindow->MoveBy(-4000, 0);
if (fMainWindow->Lock())
fMainWindow->fHistory->MakeFocus(true);
fMainWindow->Unlock();
}
void
App::MessageReceived(BMessage* msg)
{
switch (msg->what)
{
case ACTIVATE:
{
if (fMainWindow->Lock())
fMainWindow->Minimize(false);
fMainWindow->Unlock();
break;
}
case CLIPMONITOR:
{
if (fReplWindow->Lock()) {
if (fReplWindow->IsHidden())
fReplWindow->Show();
else
fReplWindow->Activate();
}
fReplWindow->Unlock();
break;
}
case SETTINGS:
{
if (fSettingsWindow->Lock()) {
if (fSettingsWindow->IsHidden())
fSettingsWindow->Show();
else
fSettingsWindow->Activate();
}
fSettingsWindow->Unlock();
break;
}
default:
{
BApplication::MessageReceived(msg);
break;
}
}
}
void
App::AboutRequested()
{
BString text = B_TRANSLATE_COMMENT(
"Clipdinger %version%\n"
"\twritten by Humdinger\n"
"\tCopyright %years%\n\n"
"Clipdinger provides a history of clippings of the system "
"clipboard and lets you create favorites.\n\n"
"Please let me know of any bugs you find or features you "
"miss. Contact info is in the ReadMe, see menu item 'Help'.",
"Don't change the variables %years% and %version%.");
text.ReplaceAll("%years%", kCopyright);
text.ReplaceAll("%version%", kVersion);
BAlert *alert = new BAlert("about", text.String(),
B_TRANSLATE("Thank you"));
BTextView *view = alert->TextView();
BFont font;
view->SetStylable(true);
view->GetFont(&font);
font.SetSize(font.Size() + 4);
font.SetFace(B_BOLD_FACE);
view->SetFontAndColor(0, 11, &font);
alert->Go();
}
int
main()
{
App app;
app.Run();
return 0;
}