xref: /haiku/src/apps/text_search/Model.h (revision 0975f16f7ca94b654cb6a55b3316daae89843abb)
1 /*
2  * Copyright (c) 1998-2007 Matthijs Hollemans
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 #ifndef MODEL_H
6 #define MODEL_H
7 
8 #include <Entry.h>
9 #include <File.h>
10 #include <FindDirectory.h>
11 #include <List.h>
12 #include <Menu.h>
13 #include <Message.h>
14 #include <Rect.h>
15 #include <String.h>
16 
17 #include "GlobalDefs.h"
18 
19 
20 enum {
21 	MSG_START_CANCEL = 1000,
22 	MSG_RECURSE_LINKS,
23 	MSG_RECURSE_DIRS,
24 	MSG_SKIP_DOT_DIRS,
25 	MSG_CASE_SENSITIVE,
26 	MSG_ESCAPE_TEXT,
27 	MSG_TEXT_ONLY,
28 	MSG_INVOKE_PE,
29 	MSG_CHECKBOX_SHOW_LINES,
30 	MSG_SEARCH_TEXT,
31 	MSG_INVOKE_ITEM,
32 	MSG_SELECT_HISTORY,
33 	MSG_NODE_MONITOR_PULSE,
34 	MSG_START_NODE_MONITORING,
35 
36 	MSG_REPORT_FILE_NAME,
37 	MSG_REPORT_RESULT,
38 	MSG_REPORT_ERROR,
39 	MSG_SEARCH_FINISHED,
40 
41 	MSG_NEW_WINDOW,
42 	MSG_OPEN_PANEL,
43 	MSG_REFS_RECEIVED,
44 	MSG_TRY_QUIT,
45 	MSG_QUIT_NOW,
46 
47 	MSG_TRIM_SELECTION,
48 	MSG_COPY_TEXT,
49 	MSG_SELECT_IN_TRACKER,
50 	MSG_SELECT_ALL,
51 	MSG_OPEN_SELECTION
52 };
53 
54 enum state_t {
55 	STATE_IDLE = 0,
56 	STATE_SEARCH,
57 	STATE_CANCEL,
58 	STATE_UPDATE
59 };
60 
61 class Model {
62 public:
63 								Model();
64 
65 			status_t			LoadPrefs();
66 			status_t			SavePrefs();
67 
68 			void				AddToHistory(const char* text);
69 			void				FillHistoryMenu(BMenu* menu) const;
70 
71 public:
72 			// The directory we were invoked from.
73 			entry_ref			fDirectory;
74 
75 			// The selected files we were invoked upon.
76 			BMessage			fSelectedFiles;
77 
78 			// Whether we need to look into subdirectories.
79 			bool				fRecurseDirs;
80 
81 			// Whether we need to follow symbolic links.
82 			bool				fRecurseLinks;
83 
84 			// Whether we should skip subdirectories that start with a dot.
85 			bool				fSkipDotDirs;
86 
87 			// Whether the search is case sensitive.
88 			bool				fCaseSensitive;
89 
90 			// Whether the search pattern will be escaped.
91 			bool				fEscapeText;
92 
93 			// Whether we look at text files only.
94 			bool				fTextOnly;
95 
96 			// Whether we open the item in Pe and jump to the correct line.
97 			bool				fInvokePe;
98 
99 			// The dimensions of the window.
100 			BRect				fFrame;
101 
102 			// What are we doing.
103 			state_t				fState;
104 
105 			// Current directory of the filepanel
106 			BString				fFilePanelPath;
107 
108 			// Grep string encoding ?
109 			uint32				fEncoding;
110 
111 private:
112 			bool				_LoadHistory(BList& items) const;
113 			status_t			_SaveHistory(const BList& items) const;
114 			void				_FreeHistory(const BList& items) const;
115 			status_t			_OpenFile(BFile* file, const char* name,
116 									uint32 openMode = B_READ_ONLY,
117 									directory_which which
118 										= B_USER_SETTINGS_DIRECTORY,
119 									BVolume* volume = NULL) const;
120 };
121 
122 #endif // MODEL_H
123