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
138b671a47SDarkWyrm #include <Alert.h>
148b671a47SDarkWyrm
15e234c034SDarkWyrm static int32 sWindowCount = 0;
16e234c034SDarkWyrm
ResWindow(const BRect & rect,const entry_ref * ref)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
228b671a47SDarkWyrm fView = new ResView(Bounds(), "resview", B_FOLLOW_ALL, B_WILL_DRAW, ref);
238b671a47SDarkWyrm AddChild(fView);
243c3f84d1SStephan Aßmus Show();
2508cf72ceSDarkWyrm }
2608cf72ceSDarkWyrm
2708cf72ceSDarkWyrm
~ResWindow(void)2808cf72ceSDarkWyrm ResWindow::~ResWindow(void)
2908cf72ceSDarkWyrm {
3008cf72ceSDarkWyrm }
3108cf72ceSDarkWyrm
3208cf72ceSDarkWyrm
3308cf72ceSDarkWyrm bool
QuitRequested(void)3408cf72ceSDarkWyrm ResWindow::QuitRequested(void)
3508cf72ceSDarkWyrm {
368b671a47SDarkWyrm if (fView->GetSaveStatus() == FILE_DIRTY) {
37*776c58b2SHumdinger BAlert *alert = new BAlert("ResEdit", "Save changes before closing?",
38*776c58b2SHumdinger "Cancel", "Don't save", "Save",
39*776c58b2SHumdinger B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT);
40aed35104SHumdinger alert->SetShortcut(0, B_ESCAPE);
41*776c58b2SHumdinger alert->SetShortcut(1, 'd');
42*776c58b2SHumdinger alert->SetShortcut(2, 's');
43aed35104SHumdinger
448b671a47SDarkWyrm switch (alert->Go()) {
458b671a47SDarkWyrm case 0:
468b671a47SDarkWyrm return false;
478b671a47SDarkWyrm case 2: {
488b671a47SDarkWyrm fView->SaveAndQuit();
498b671a47SDarkWyrm return false;
508b671a47SDarkWyrm }
518b671a47SDarkWyrm default:
528b671a47SDarkWyrm break;
538b671a47SDarkWyrm }
548b671a47SDarkWyrm }
558b671a47SDarkWyrm
56e234c034SDarkWyrm atomic_add(&sWindowCount, -1);
57e234c034SDarkWyrm
58e234c034SDarkWyrm if (sWindowCount == 0)
59e234c034SDarkWyrm be_app->PostMessage(B_QUIT_REQUESTED);
6008cf72ceSDarkWyrm return true;
6108cf72ceSDarkWyrm }
6208cf72ceSDarkWyrm
6308cf72ceSDarkWyrm
64