xref: /haiku/src/apps/resedit/ResWindow.cpp (revision e81a954787e50e56a7f06f72705b7859b6ab06d1)
1 /*
2  * Copyright (c) 2005-2010, Haiku, Inc.
3  * Distributed under the terms of the MIT license.
4  *
5  * Author:
6  *		DarkWyrm <darkwyrm@gmail.com>
7  */
8 #include "ResWindow.h"
9 
10 #include "App.h"
11 #include "ResView.h"
12 
13 #include <Alert.h>
14 
15 static int32 sWindowCount = 0;
16 
17 ResWindow::ResWindow(const BRect &rect, const entry_ref *ref)
18  :	BWindow(rect, "", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
19 {
20 	atomic_add(&sWindowCount, 1);
21 
22 	fView = new ResView(Bounds(), "resview", B_FOLLOW_ALL, B_WILL_DRAW, ref);
23 	AddChild(fView);
24 	Show();
25 }
26 
27 
28 ResWindow::~ResWindow(void)
29 {
30 }
31 
32 
33 bool
34 ResWindow::QuitRequested(void)
35 {
36 	if (fView->GetSaveStatus() == FILE_DIRTY) {
37 		BAlert *alert = new BAlert("ResEdit", "Save changes before closing?",
38 			"Cancel", "Don't save", "Save",
39 			B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT);
40 		alert->SetShortcut(0, B_ESCAPE);
41 		alert->SetShortcut(1, 'd');
42 		alert->SetShortcut(2, 's');
43 
44 		switch (alert->Go()) {
45 			case 0:
46 				return false;
47 			case 2: {
48 				fView->SaveAndQuit();
49 				return false;
50 			}
51 			default:
52 				break;
53 		}
54 	}
55 
56 	atomic_add(&sWindowCount, -1);
57 
58 	if (sWindowCount == 0)
59 		be_app->PostMessage(B_QUIT_REQUESTED);
60 	return true;
61 }
62 
63 
64