2 * Copyright 2006-2011, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
17 #include "MainWindow.h"
19 #undef B_TRANSLATION_CONTEXT
20 #define B_TRANSLATION_CONTEXT "LaunchBox"
24 BApplication("application/x-vnd.Haiku-LaunchBox"),
25 fSettingsChanged(false),
26 fNamePanelSize(200, 50)
28 SetPulseRate(3000000);
40 _StoreSettingsIfNeeded();
48 bool windowAdded
= false;
49 BRect
frame(50.0, 50.0, 65.0, 100.0);
52 status_t status
= load_settings(&settings
, "main_settings", "LaunchBox");
54 BMessage windowMessage
;
55 for (int32 i
= 0; settings
.FindMessage("window", i
, &windowMessage
)
59 BString
name(B_TRANSLATE("Pad %1"));
60 name
.ReplaceFirst("%1", string
);
61 BMessage
* windowSettings
= new BMessage(windowMessage
);
62 MainWindow
* window
= new MainWindow(name
.String(), frame
,
66 frame
.OffsetBy(10.0, 10.0);
67 windowMessage
.MakeEmpty();
70 if (settings
.FindSize("name panel size", &size
) == B_OK
)
71 fNamePanelSize
= size
;
75 MainWindow
* window
= new MainWindow(B_TRANSLATE("Pad 1"), frame
, true);
82 App::MessageReceived(BMessage
* message
)
84 switch (message
->what
) {
85 case MSG_ADD_WINDOW
: {
86 BMessage
* settings
= new BMessage('sett');
87 bool wasCloned
= message
->FindMessage("window", settings
) == B_OK
;
89 string
<< CountWindows() + 1;
90 BString
name(B_TRANSLATE("Pad %1"));
91 name
.ReplaceFirst("%1", string
);
92 MainWindow
* window
= new MainWindow(name
.String(),
93 BRect(50.0, 50.0, 65.0, 100.0), settings
);
95 window
->MoveBy(10, 10);
97 fSettingsChanged
= true;
100 case MSG_SETTINGS_CHANGED
:
101 fSettingsChanged
= true;
104 BApplication::MessageReceived(message
);
113 _StoreSettingsIfNeeded();
118 App::SetNamePanelSize(const BSize
& size
)
121 fNamePanelSize
= size
;
132 size
= fNamePanelSize
;
140 App::_StoreSettingsIfNeeded()
142 if (!fSettingsChanged
)
145 BMessage
settings('sett');
146 for (int32 i
= 0; BWindow
* window
= WindowAt(i
); i
++) {
147 if (MainWindow
* padWindow
= dynamic_cast<MainWindow
*>(window
)) {
148 if (padWindow
->Lock()) {
149 BMessage
* windowSettings
= padWindow
->Settings();
150 if (windowSettings
) {
151 padWindow
->SaveSettings(windowSettings
);
152 settings
.AddMessage("window", windowSettings
);
158 settings
.AddSize("name panel size", fNamePanelSize
);
160 save_settings(&settings
, "main_settings", "LaunchBox");
162 fSettingsChanged
= false;