xref: /haiku/src/apps/resedit/ResWindow.cpp (revision 8b671a47f1bdae0bcc40a7315d456e2c3070af0c)
108cf72ceSDarkWyrm /*
2e234c034SDarkWyrm  * Copyright (c) 2005-2010, Haiku, Inc.
308cf72ceSDarkWyrm  * Distributed under the terms of the MIT license.
408cf72ceSDarkWyrm  *
508cf72ceSDarkWyrm  * Author:
6e234c034SDarkWyrm  *		DarkWyrm <darkwyrm@gmail.com>
708cf72ceSDarkWyrm  */
808cf72ceSDarkWyrm #include "ResWindow.h"
909a03cb8SDarkWyrm 
1008cf72ceSDarkWyrm #include "App.h"
1109a03cb8SDarkWyrm #include "ResView.h"
1208cf72ceSDarkWyrm 
13*8b671a47SDarkWyrm #include <Alert.h>
14*8b671a47SDarkWyrm 
15e234c034SDarkWyrm static int32 sWindowCount = 0;
16e234c034SDarkWyrm 
1708cf72ceSDarkWyrm ResWindow::ResWindow(const BRect &rect, const entry_ref *ref)
1808cf72ceSDarkWyrm  :	BWindow(rect, "", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
1908cf72ceSDarkWyrm {
20e234c034SDarkWyrm 	atomic_add(&sWindowCount, 1);
2108cf72ceSDarkWyrm 
22*8b671a47SDarkWyrm 	fView = new ResView(Bounds(), "resview", B_FOLLOW_ALL, B_WILL_DRAW, ref);
23*8b671a47SDarkWyrm 	AddChild(fView);
243c3f84d1SStephan Aßmus 	Show();
2508cf72ceSDarkWyrm }
2608cf72ceSDarkWyrm 
2708cf72ceSDarkWyrm 
2808cf72ceSDarkWyrm ResWindow::~ResWindow(void)
2908cf72ceSDarkWyrm {
3008cf72ceSDarkWyrm }
3108cf72ceSDarkWyrm 
3208cf72ceSDarkWyrm 
3308cf72ceSDarkWyrm bool
3408cf72ceSDarkWyrm ResWindow::QuitRequested(void)
3508cf72ceSDarkWyrm {
36*8b671a47SDarkWyrm 	if (fView->GetSaveStatus() == FILE_DIRTY) {
37*8b671a47SDarkWyrm 		BAlert *alert = new BAlert("ResEdit","Save your changes?","Cancel","Don't Save","Save");
38*8b671a47SDarkWyrm 		switch (alert->Go()) {
39*8b671a47SDarkWyrm 			case 0:
40*8b671a47SDarkWyrm 				return false;
41*8b671a47SDarkWyrm 			case 2: {
42*8b671a47SDarkWyrm 				fView->SaveAndQuit();
43*8b671a47SDarkWyrm 				return false;
44*8b671a47SDarkWyrm 			}
45*8b671a47SDarkWyrm 			default:
46*8b671a47SDarkWyrm 				break;
47*8b671a47SDarkWyrm 		}
48*8b671a47SDarkWyrm 	}
49*8b671a47SDarkWyrm 
50e234c034SDarkWyrm 	atomic_add(&sWindowCount, -1);
51e234c034SDarkWyrm 
52e234c034SDarkWyrm 	if (sWindowCount == 0)
53e234c034SDarkWyrm 		be_app->PostMessage(B_QUIT_REQUESTED);
5408cf72ceSDarkWyrm 	return true;
5508cf72ceSDarkWyrm }
5608cf72ceSDarkWyrm 
5708cf72ceSDarkWyrm 
58