2 * Copyright 2007-2009, Haiku, Inc. All rights reserved.
3 * Copyright 2003-2004 Kian Duffy, myob@users.sourceforge.net
4 * Parts Copyright 1998-1999 Kazuho Okui and Takashi Murai.
5 * All rights reserved. Distributed under the terms of the MIT license.
9 #include "AppearPrefView.h"
10 #include "PrefHandler.h"
11 #include "PrefWindow.h"
12 #include "TermConst.h"
18 #include <FilePanel.h>
19 #include <GroupLayoutBuilder.h>
20 #include <LayoutBuilder.h>
26 #undef B_TRANSLATION_CONTEXT
27 #define B_TRANSLATION_CONTEXT "Terminal PrefWindow"
29 PrefWindow::PrefWindow(const BMessenger
& messenger
)
31 BWindow(BRect(0, 0, 375, 185), "Terminal settings",
32 B_TITLED_WINDOW_LOOK
, B_NORMAL_WINDOW_FEEL
,
33 B_NOT_RESIZABLE
| B_NOT_ZOOMABLE
| B_AUTO_UPDATE_SIZE_LIMITS
),
34 fPreviousPref(new PrefHandler(PrefHandler::Default())),
37 fTerminalMessenger(messenger
)
39 BString app
= B_TRANSLATE_SYSTEM_NAME("Terminal");
40 BString title
= B_TRANSLATE_COMMENT("%app% settings", "window title");
41 title
.ReplaceFirst("%app%", app
);
44 BLayoutBuilder::Group
<>(this, B_VERTICAL
)
46 .SetInsets(B_USE_WINDOW_SPACING
)
47 .Add(fAppearanceView
= new AppearancePrefView(
48 B_TRANSLATE("Appearance"), fTerminalMessenger
))
49 .AddGroup(B_HORIZONTAL
)
50 .Add(fDefaultsButton
= new BButton("defaultsbutton",
51 B_TRANSLATE("Defaults"), new BMessage(MSG_DEFAULTS_PRESSED
),
53 .Add(fRevertButton
= new BButton("revertbutton",
54 B_TRANSLATE("Revert"), new BMessage(MSG_REVERT_PRESSED
),
57 .Add(fSaveAsFileButton
= new BButton("savebutton",
58 B_TRANSLATE("Save to file" B_UTF8_ELLIPSIS
),
59 new BMessage(MSG_SAVEAS_PRESSED
), B_WILL_DRAW
))
63 fRevertButton
->SetEnabled(fDirty
);
65 AddShortcut('Q', B_COMMAND_KEY
, new BMessage(B_QUIT_REQUESTED
));
66 AddShortcut('W', B_COMMAND_KEY
, new BMessage(B_QUIT_REQUESTED
));
73 PrefWindow::~PrefWindow()
81 fTerminalMessenger
.SendMessage(MSG_PREF_CLOSED
);
89 PrefWindow::QuitRequested()
102 BMessenger
messenger(this);
103 fSavePanel
= new BFilePanel(B_SAVE_PANEL
, &messenger
);
111 PrefWindow::_SaveRequested(BMessage
*msg
)
114 const char* filename
;
116 msg
->FindRef("directory", &dirref
);
117 msg
->FindString("name", &filename
);
119 BDirectory
dir(&dirref
);
120 BPath
path(&dir
, filename
);
122 PrefHandler::Default()->SaveAsText(path
.Path(), PREFFILE_MIMETYPE
,
130 delete fPreviousPref
;
131 fPreviousPref
= new PrefHandler(PrefHandler::Default());
133 PrefHandler::Default()->SaveDefaultAsText();
139 PrefWindow::_Revert()
142 PrefHandler::SetDefault(new PrefHandler(fPreviousPref
));
144 fTerminalMessenger
.SendMessage(MSG_HALF_FONT_CHANGED
);
145 fTerminalMessenger
.SendMessage(MSG_COLOR_CHANGED
);
146 fTerminalMessenger
.SendMessage(MSG_TAB_TITLE_SETTING_CHANGED
);
147 fTerminalMessenger
.SendMessage(MSG_WINDOW_TITLE_SETTING_CHANGED
);
149 fAppearanceView
->Revert();
152 fRevertButton
->SetEnabled(fDirty
);
158 PrefWindow::MessageReceived(BMessage
* msg
)
161 case MSG_SAVEAS_PRESSED
:
165 case MSG_REVERT_PRESSED
:
169 case MSG_DEFAULTS_PRESSED
:
170 PrefHandler::SetDefault(new PrefHandler(false));
171 fTerminalMessenger
.SendMessage(MSG_HALF_FONT_CHANGED
);
172 fTerminalMessenger
.SendMessage(MSG_COLOR_CHANGED
);
173 fTerminalMessenger
.SendMessage(MSG_TAB_TITLE_SETTING_CHANGED
);
174 fTerminalMessenger
.SendMessage(MSG_WINDOW_TITLE_SETTING_CHANGED
);
175 fAppearanceView
->Revert();
178 case MSG_PREF_MODIFIED
:
180 fRevertButton
->SetEnabled(fDirty
);
183 case B_SAVE_REQUESTED
:
188 BWindow::MessageReceived(msg
);