Integrate adding files with the file manager
[anjuta-git-plugin.git] / plugins / search / search-replace_backend.h
blob8156ce7d900ac45245a8b7762d6528aac2a59dcc
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #ifndef _SEARCH_REPLACE_BACKEND_H
18 #define _SEARCH_REPLACE_BACKEND_H
20 #ifdef __cplusplus
21 extern "C"
23 #endif
25 #include <libanjuta/interfaces/ianjuta-document-manager.h>
26 #include <libanjuta/interfaces/ianjuta-editor.h>
28 /* Search expression options */
29 typedef struct _SearchExpression
31 gchar *search_str;
32 gboolean regex;
33 gboolean greedy;
34 gboolean ignore_case;
35 gboolean whole_word;
36 gboolean whole_line;
37 gboolean word_start;
38 gboolean no_limit;
39 gint actions_max;
40 GRegex* regex_info;
41 } SearchExpression;
44 /* Direction to search (only valid for the current buffer). Note that backward
45 search does not work for regular expressions. */
46 typedef enum _SearchDirection
48 SD_FORWARD, /* Forward from the cursor */
49 SD_BACKWARD, /* Backward from the cursor */
50 SD_BEGINNING /* From the beginning of the buffer */
51 } SearchDirection;
53 /* Where to search - type */
54 typedef enum _SearchRangeType
56 SR_BUFFER, /* Current buffer */
57 SR_SELECTION, /* Selected text only */
58 SR_BLOCK, /* Current block */
59 SR_FUNCTION, /* Current function */
60 SR_OPEN_BUFFERS, /* All open buffers */
61 SR_PROJECT, /* All project files */
62 SR_FILES /* A set of patterns specifying which files to search */
63 } SearchRangeType;
66 ** Search variable is a string which is expanded using the properties interface
68 typedef gchar *SearchVar;
70 /* Specify files to search in. Note that each GList is a list of strings which
71 can be fixed strings or contain globbing patterns (the type used by ls). */
72 typedef struct _SearchFiles
74 gchar *top_dir;
75 GList *match_files;
76 GList *match_dirs;
77 GList *ignore_files;
78 GList *ignore_dirs;
79 gboolean ignore_hidden_files;
80 gboolean ignore_hidden_dirs;
81 gboolean recurse;
82 } SearchFiles;
84 /* Search range - used to create search list of files */
85 typedef struct _SearchRange
87 SearchRangeType type;
88 SearchDirection direction; /* type = SR_BUFFER */
89 gboolean whole;
90 SearchVar var; /* type = SR_VARIABLE */
91 SearchFiles files; /* type = SR_FILES */
92 } SearchRange;
94 /* What to do with the result of the search */
95 typedef enum _SearchAction
97 SA_SELECT, /* Jump to the next match and select it (current buffer only)*/
98 SA_BOOKMARK, /* Bookmark all lines containing a match (open buffers only) */
99 SA_HIGHLIGHT, /* Highlight all matched strings (open buffers only) */
100 SA_FIND_PANE, /* Show result in find pane */
101 SA_REPLACE, /* Replace next match with specified string */
102 SA_REPLACEALL /* Replace all matches with specified string */
103 } SearchAction;
105 /* Search master option structure */
106 typedef struct _Search
108 SearchExpression expr;
109 SearchRange range;
110 SearchAction action;
111 GList *expr_history;
112 gint incremental_pos;
113 gboolean incremental_wrap;
114 gboolean basic_search;
115 } Search;
117 /* Contains information about replacement */
118 typedef struct _Replace
120 gchar *repl_str;
121 gboolean regex;
122 gboolean confirm;
123 gboolean load_file;
124 GList *expr_history;
125 } Replace;
127 typedef struct _SearchReplace
129 Search search;
130 Replace replace;
131 IAnjutaDocumentManager *docman;
133 } SearchReplace;
135 typedef enum _FileBufferType
137 FB_NONE,
138 FB_FILE, /* File loaded from disk */
139 FB_EDITOR /* Corresponding to a TextEditor structure */
140 } FileBufferType;
142 typedef struct _FileBuffer
144 FileBufferType type;
145 /* The following are valid only for files loaded from disk */
146 gchar *name; /* Name of the file */
147 gchar *path; /* Full path to the file */
148 gchar *uri; /* URI to the file */
149 gchar *buf; /* Contents of the file */
150 gint len; /* Length of the buffer */
151 gint pos; /* Current position */
152 gint endpos; /* Restrict action upto this position */
153 gint line; /* Current line */
154 GList *lines; /* List of integers specifying line start positions */
155 /* The following are valid only for files corresponding to a TextEditor */
156 IAnjutaEditor *te;
157 } FileBuffer;
160 /* A search entry is a file or buffer to search. This can be a file,
161 a buffer or part of a buffer (such as selected text) */
162 typedef enum _SearchEntryType
164 SE_FILE,
165 SE_BUFFER,
166 } SearchEntryType;
168 typedef struct _SearchEntry
170 SearchEntryType type;
171 gchar *path;
172 IAnjutaEditor *te;
173 SearchDirection direction;
174 gint start_pos;
175 gint end_pos;
176 } SearchEntry;
178 typedef struct _MatchInfo
180 gint pos;
181 gint len;
182 gint line;
183 GList *subs; /* <MatchSubStr *> */
184 } MatchInfo;
187 // void search_and_replace_backend_init (AnjutaDocman *dm);
189 void function_select (IAnjutaEditor *te);
191 GList *create_search_entries(Search *s);
193 FileBuffer *file_buffer_new_from_te (IAnjutaEditor *te);
195 FileBuffer *
196 file_buffer_new_from_path(const char *path, const char *buf, int len, int pos);
198 FileBuffer *
199 file_buffer_new_from_path(const char *path, const char *buf, int len, int pos);
201 gchar *file_match_line_from_pos(FileBuffer *fb, int pos);
203 MatchInfo *get_next_match(FileBuffer *fb, SearchDirection direction, SearchExpression *s);
205 gchar *regex_backref(MatchInfo *mi, FileBuffer *fb);
207 void match_info_free (MatchInfo *mi);
209 void file_buffer_free (FileBuffer *fb);
211 SearchReplace *create_search_replace_instance(IAnjutaDocumentManager *docman);
213 #ifdef __cplusplus
215 #endif
217 #endif /* _SEARCH_REPLACE_H */