btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / text_search / GrepApp.cpp
blob51048c3d3d550bec434d006207febd45f244f7e0
1 /*
2 * Copyright (c) 1998-2007 Matthijs Hollemans
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
6 #include "GrepApp.h"
8 #include <stdio.h>
10 #include <Entry.h>
12 #include "GlobalDefs.h"
13 #include "GrepWindow.h"
14 #include "Model.h"
17 GrepApp::GrepApp()
18 : BApplication(APP_SIGNATURE),
19 fGotArgvOnStartup(false),
20 fGotRefsOnStartup(false),
21 fQuitter(NULL)
26 GrepApp::~GrepApp()
28 delete fQuitter;
32 void
33 GrepApp::ArgvReceived(int32 argc, char** argv)
35 fGotArgvOnStartup = true;
37 BMessage message(B_REFS_RECEIVED);
38 int32 refCount = 0;
40 for (int32 i = 1; i < argc; i++) {
41 BEntry entry(argv[i]);
42 entry_ref ref;
43 entry.GetRef(&ref);
45 if (entry.Exists()) {
46 message.AddRef("refs", &ref);
47 refCount += 1;
48 } else
49 printf("%s: File not found: %s\n", argv[0], argv[i]);
52 if (refCount > 0)
53 RefsReceived(&message);
57 void
58 GrepApp::RefsReceived(BMessage* message)
60 if (IsLaunching())
61 fGotRefsOnStartup = true;
63 new GrepWindow(message);
67 void
68 GrepApp::ReadyToRun()
70 if (!fGotArgvOnStartup && !fGotRefsOnStartup)
71 _NewUnfocusedGrepWindow();
73 // TODO: stippi: I don't understand what this is supposed to do:
74 if (fGotArgvOnStartup && !fGotRefsOnStartup)
75 PostMessage(B_QUIT_REQUESTED);
79 void
80 GrepApp::MessageReceived(BMessage* message)
82 switch (message->what) {
83 case B_SILENT_RELAUNCH:
84 _NewUnfocusedGrepWindow();
85 break;
87 case MSG_TRY_QUIT:
88 _TryQuit();
89 break;
91 default:
92 BApplication::MessageReceived(message);
93 break;
98 void
99 GrepApp::_TryQuit()
101 if (CountWindows() == 0)
102 PostMessage(B_QUIT_REQUESTED);
104 if (CountWindows() == 1 && fQuitter == NULL) {
105 fQuitter = new BMessageRunner(be_app_messenger,
106 new BMessage(MSG_TRY_QUIT), 200000, -1);
111 void
112 GrepApp::_NewUnfocusedGrepWindow()
114 BMessage emptyMessage;
115 new GrepWindow(&emptyMessage);