xref: /haiku/src/apps/resedit/App.cpp (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
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 "App.h"
9 #include "ResWindow.h"
10 
11 #include <Entry.h>
12 
13 int
14 main(void)
15 {
16 	App app;
17 	app.Run();
18 	return 0;
19 }
20 
21 
22 App::App(void)
23   :	BApplication("application/x-vnd.Haiku-ResEdit")
24 {
25 	fOpenPanel = new BFilePanel();
26 }
27 
28 
29 App::~App(void)
30 {
31 	delete fOpenPanel;
32 }
33 
34 
35 void
36 App::ReadyToRun(void)
37 {
38 	// CountWindows() needs to be used instead of fWindowCount because the registration
39 	// message isn't processed in time. One of the windows belong to the BFilePanels and is
40 	// counted in CountWindows().
41 	if (CountWindows() < 2)
42 		new ResWindow(BRect(50, 100, 600, 400));
43 }
44 
45 
46 void
47 App::MessageReceived(BMessage *msg)
48 {
49 	switch(msg->what) {
50 		case M_SHOW_OPEN_PANEL: {
51 			// Don't do anything if it's already open
52 			if (fOpenPanel->IsShowing())
53 				break;
54 			fOpenPanel->Show();
55 			break;
56 		}
57 		default:
58 			BApplication::MessageReceived(msg);
59 	}
60 }
61 
62 
63 void
64 App::ArgvReceived(int32 argc, char** argv)
65 {
66 	for (int32 i = 1; i < argc; i++) {
67 		BEntry entry(argv[i]);
68 		entry_ref ref;
69 		if (entry.GetRef(&ref) < B_OK)
70 			continue;
71 		new ResWindow(BRect(50, 100, 600, 400), &ref);
72 	}
73 }
74 
75 
76 void
77 App::RefsReceived(BMessage *msg)
78 {
79 	entry_ref ref;
80 	int32 i = 0;
81 	while (msg->FindRef("refs", i++, &ref) == B_OK)
82 		new ResWindow(BRect(50, 100, 600, 400), &ref);
83 }
84