xref: /haiku/src/apps/text_search/Model.h (revision 2775737e9d73769f19c02de8dd713840d1edb9f2)
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_REGULAR_EXPRESSION,
27 	MSG_TEXT_ONLY,
28 	MSG_INVOKE_EDITOR,
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_SET_TARGET_TO_PARENT,
45 	MSG_TRY_QUIT,
46 	MSG_QUIT_NOW,
47 
48 	MSG_TRIM_SELECTION,
49 	MSG_COPY_TEXT,
50 	MSG_SELECT_IN_TRACKER,
51 	MSG_SELECT_ALL,
52 	MSG_OPEN_SELECTION
53 };
54 
55 enum state_t {
56 	STATE_IDLE = 0,
57 	STATE_SEARCH,
58 	STATE_CANCEL,
59 	STATE_UPDATE
60 };
61 
62 class Model {
63 public:
64 								Model();
65 
66 			status_t			LoadPrefs();
67 			status_t			SavePrefs();
68 
69 			void				AddToHistory(const char* text);
70 			void				FillHistoryMenu(BMenu* menu) const;
71 
72 public:
73 			// The directory we were invoked from.
74 			entry_ref			fDirectory;
75 
76 			// The selected files we were invoked upon.
77 			BMessage			fSelectedFiles;
78 
79 			// Whether we need to look into subdirectories.
80 			bool				fRecurseDirs;
81 
82 			// Whether we need to follow symbolic links.
83 			bool				fRecurseLinks;
84 
85 			// Whether we should skip subdirectories that start with a dot.
86 			bool				fSkipDotDirs;
87 
88 			// Whether the search is case sensitive.
89 			bool				fCaseSensitive;
90 
91 			// Whether the search pattern is a regular expression.
92 			bool				fRegularExpression;
93 
94 			// Whether we look at text files only.
95 			bool				fTextOnly;
96 
97 			// Whether we open the item in the preferred code editor.
98 			bool				fInvokeEditor;
99 
100 			// The dimensions of the window.
101 			BRect				fFrame;
102 
103 			// What are we doing.
104 			state_t				fState;
105 
106 			// Current directory of the filepanel
107 			BString				fFilePanelPath;
108 
109 			// Show lines ?
110 			bool				fShowLines;
111 
112 			// Grep string encoding ?
113 			uint32				fEncoding;
114 
115 private:
116 			bool				_LoadHistory(BList& items) const;
117 			status_t			_SaveHistory(const BList& items) const;
118 			void				_FreeHistory(const BList& items) const;
119 			status_t			_OpenFile(BFile* file, const char* name,
120 									uint32 openMode = B_READ_ONLY,
121 									directory_which which
122 										= B_USER_SETTINGS_DIRECTORY,
123 									BVolume* volume = NULL) const;
124 };
125 
126 #endif // MODEL_H
127