xref: /haiku/src/apps/resedit/App.cpp (revision a381c8a06378de22ff08adf4282b4e3f7e50d250)
1 /*
2  * Copyright (c) 2005-2006, Haiku, Inc.
3  * Distributed under the terms of the MIT license.
4  *
5  * Author:
6  *		DarkWyrm <darkwyrm@earthlink.net>
7  */
8 #include "App.h"
9 #include "ResWindow.h"
10 #include <Entry.h>
11 
12 int
13 main(void)
14 {
15 	App app;
16 	app.Run();
17 	return 0;
18 }
19 
20 
21 App::App(void)
22   :	BApplication("application/x-vnd.Haiku-ResEdit"),
23   	fWindowCount(0)
24 {
25 	fOpenPanel = new BFilePanel();
26 	fSavePanel = new BFilePanel(B_SAVE_PANEL);
27 }
28 
29 
30 App::~App(void)
31 {
32 	delete fOpenPanel;
33 	delete fSavePanel;
34 }
35 
36 
37 void
38 App::ReadyToRun(void)
39 {
40 	if (fWindowCount < 1)
41 		new ResWindow(BRect(50, 100, 600, 400));
42 }
43 
44 
45 void
46 App::MessageReceived(BMessage *msg)
47 {
48 	switch(msg->what) {
49 		case M_REGISTER_WINDOW: {
50 			fWindowCount++;
51 			break;
52 		}
53 		case M_UNREGISTER_WINDOW: {
54 			fWindowCount--;
55 			if (fWindowCount == 0)
56 				PostMessage(B_QUIT_REQUESTED);
57 			break;
58 		}
59 		case M_SHOW_OPEN_PANEL: {
60 			// Don't do anything if it's already open
61 			if (fOpenPanel->IsShowing())
62 				break;
63 			fOpenPanel->Show();
64 			break;
65 		}
66 		default:
67 			BApplication::MessageReceived(msg);
68 	}
69 }
70 
71 
72 void
73 App::ArgvReceived(int32 argc, char** argv)
74 {
75 	for (int32 i = 1; i < argc; i++) {
76 		BEntry entry(argv[i]);
77 		entry_ref ref;
78 		if (entry.GetRef(&ref) < B_OK)
79 			continue;
80 		new ResWindow(BRect(50, 100, 600, 400), &ref);
81 	}
82 }
83 
84 
85 void
86 App::RefsReceived(BMessage *msg)
87 {
88 	entry_ref ref;
89 	int32 i = 0;
90 	while (msg->FindRef("refs", i++, &ref) == B_OK)
91 		new ResWindow(BRect(50, 100, 600, 400), &ref);
92 }
93 
94 
95 bool
96 App::QuitRequested(void)
97 {
98 	for (int32 i = 0; i < CountWindows(); i++) {
99 		BWindow *win = WindowAt(i);
100 		if (fOpenPanel->Window() == win || fSavePanel->Window() == win)
101 			continue;
102 
103 		if (!win->QuitRequested())
104 			return false;
105 	}
106 
107 	return true;
108 }
109 
110